Add hook for notification content and notification title formats - refs BT#9092

Conflicts:
	main/inc/lib/hook/HookEvent.class.php
1.10.x
Daniel Barreto 10 years ago
parent bedb3b01e9
commit dd2fc3f2d8
  1. 4
      main/inc/lib/hook/HookEvent.php
  2. 42
      main/inc/lib/hook/HookNotificationContent.php
  3. 42
      main/inc/lib/hook/HookNotificationTitle.php
  4. 14
      main/inc/lib/hook/interfaces/HookNotificationContentEventInterface.php
  5. 14
      main/inc/lib/hook/interfaces/HookNotificationContentObserverInterface.php
  6. 14
      main/inc/lib/hook/interfaces/HookNotificationTitleEventInterface.php
  7. 14
      main/inc/lib/hook/interfaces/HookNotificationTitleObserverInterface.php
  8. 32
      main/inc/lib/notification.lib.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;
}

@ -0,0 +1,42 @@
<?php
/* For licensing terms, see /license.txt */
/**
* This file contains the Hook Event class for Content of Notifications
*/
/**
* Class HookNotificationContent
*/
class HookNotificationContent extends HookEvent implements HookNotificationContentEventInterface
{
/**
* Construct
*/
protected function __construct()
{
parent::__construct('HookNotificationContent');
}
/**
* @param int $type
* @return int
*/
public function notifyNotificationContent($type)
{
/** @var \HookNotificationContentObserverInterface $observer */
if (isset($this->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;
}
}

@ -0,0 +1,42 @@
<?php
/* For licensing terms, see /license.txt */
/**
* This file contains the Hook Event class for Title of Notifications
*/
/**
* Class HookNotificationTitle
*/
class HookNotificationTitle extends HookEvent implements HookNotificationTitleEventInterface
{
/**
* Construct
*/
protected function __construct()
{
parent::__construct('HookNotificationTitle');
}
/**
* @param int $type
* @return int
*/
public function notifyNotificationTitle($type)
{
/** @var \HookNotificationTitleObserverInterface $observer */
if (isset($this->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;
}
}

@ -0,0 +1,14 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Interface HookNotificationContentEventInterface
*/
interface HookNotificationContentEventInterface extends HookEventInterface
{
/**
* @param int $type
* @return int
*/
public function notifyNotificationContent($type);
}

@ -0,0 +1,14 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Interface HookNotificationContentObserverInterface
*/
interface HookNotificationContentObserverInterface extends HookObserverInterface
{
/**
* @param HookNotificationContentEventInterface $hook
* @return int
*/
public function hookNotificationContent(HookNotificationContentEventInterface $hook);
}

@ -0,0 +1,14 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Interface HookNotificationTitleEventInterface
*/
interface HookNotificationTitleEventInterface extends HookEventInterface
{
/**
* @param int $type
* @return int
*/
public function notifyNotificationTitle($type);
}

@ -0,0 +1,14 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Interface HookNotificationTitleObserverInterface
*/
interface HookNotificationTitleObserverInterface extends HookObserverInterface
{
/**
* @param HookNotificationTitleEventInterface $hook
* @return int
*/
public function hookNotificationTitle(HookNotificationTitleEventInterface $hook);
}

@ -144,6 +144,14 @@ class Notification extends Model
*/
public function formatTitle($title, $senderInfo)
{
$hook = HookNotificationTitle::create();
if (!empty($hook)) {
$hook->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)
).'</i>';
if (!empty($hook)) {
$hook->setEventData(array('content' => $content));
$data = $hook->notifyNotificationContent(HOOK_TYPE_POST);
if (isset($data['content'])) {
$content = $data['content'];
}
}
return $content;
}
}

Loading…
Cancel
Save