diff --git a/main/inc/lib/hook/HookEvent.php b/main/inc/lib/hook/HookEvent.php index 759fb35206..c4755f6fb9 100644 --- a/main/inc/lib/hook/HookEvent.php +++ b/main/inc/lib/hook/HookEvent.php @@ -126,7 +126,9 @@ abstract class HookEvent implements HookEventInterface */ public function setEventData(array $data) { - $this->eventData = $data; + foreach ($data as $key => $value) { + $this->eventData[$key] = $value; + } return $this; } diff --git a/main/inc/lib/hook/HookNotificationContent.php b/main/inc/lib/hook/HookNotificationContent.php new file mode 100644 index 0000000000..cbef32b58d --- /dev/null +++ b/main/inc/lib/hook/HookNotificationContent.php @@ -0,0 +1,42 @@ +eventData['content'])) { + $this->eventData['type'] = $type; + foreach ($this->observers as $observer) { + $data = $observer->hookNotificationContent($this); + if (isset($data['content'])) { + $this->setEventData($data); + } + } + + return $this->eventData; + } + + return null; + } +} \ No newline at end of file diff --git a/main/inc/lib/hook/HookNotificationTitle.php b/main/inc/lib/hook/HookNotificationTitle.php new file mode 100644 index 0000000000..8df6fe31cd --- /dev/null +++ b/main/inc/lib/hook/HookNotificationTitle.php @@ -0,0 +1,42 @@ +eventData['title'])) { + $this->eventData['type'] = $type; + foreach ($this->observers as $observer) { + $data = $observer->hookNotificationTitle($this); + if (isset($data['title'])) { + $this->setEventData($data); + } + } + + return $this->eventData; + } + + return null; + } +} \ No newline at end of file diff --git a/main/inc/lib/hook/interfaces/HookNotificationContentEventInterface.php b/main/inc/lib/hook/interfaces/HookNotificationContentEventInterface.php new file mode 100644 index 0000000000..a4b931a151 --- /dev/null +++ b/main/inc/lib/hook/interfaces/HookNotificationContentEventInterface.php @@ -0,0 +1,14 @@ +setEventData(array('title' => $title)); + $data = $hook->notifyNotificationTitle(HOOK_TYPE_PRE); + if (isset($data['title'])) { + $title = $data['title']; + } + } $newTitle = $this->getTitlePrefix(); switch ($this->type) { @@ -184,6 +192,14 @@ class Notification extends Model break; } + if (!empty($hook)) { + $hook->setEventData(array('title' => $newTitle)); + $data = $hook->notifyNotificationTitle(HOOK_TYPE_POST); + if (isset($data['title'])) { + $newTitle = $data['title']; + } + } + return $newTitle; } @@ -309,6 +325,14 @@ class Notification extends Model * */ public function formatContent($content, $sender_info) { + $hook = HookNotificationContent::create(); + if (!empty($hook)) { + $hook->setEventData(array('content' => $content)); + $data = $hook->notifyNotificationContent(HOOK_TYPE_PRE); + if (isset($data['content'])) { + $content = $data['content']; + } + } $new_message_text = $link_to_new_message = ''; switch ($this->type) { @@ -382,6 +406,14 @@ class Notification extends Model Display::url($preference_url, $preference_url) ).''; + if (!empty($hook)) { + $hook->setEventData(array('content' => $content)); + $data = $hook->notifyNotificationContent(HOOK_TYPE_POST); + if (isset($data['content'])) { + $content = $data['content']; + } + } + return $content; } }