You are here

function notifications_content_messaging in Notifications 6

Same name and namespace in other branches
  1. 5 notifications_content/notifications_content.module \notifications_content_messaging()
  2. 6.2 notifications_content/notifications_content.module \notifications_content_messaging()

Implementation of hook_messaging()

File

notifications_content/notifications_content.module, line 399
Subscriptions to content events

Code

function notifications_content_messaging($op, $arg1 = NULL, $arg2 = NULL, $arg3 = NULL, $arg4 = NULL) {
  switch ($op) {
    case 'message groups':
      $help = t('The <em>Header</em> and <em>Footer</em> will be taken from Notification events.');
      $help_digest = $help . ' ' . t('The <em>Digest line</em> will be used when composing Short digests on which each event will be just a line.');

      // Generic notifications event
      $info['notifications-event-node'] = array(
        'module' => 'notifications_content',
        'name' => t('Notifications for node events'),
        'description' => t('Defaults for all notifications related to node events.'),
        'help' => $help_digest,
        'fallback' => 'notifications-event',
      );
      $info['notifications-event-node-insert'] = array(
        'module' => 'notifications_content',
        'name' => t('Notifications for node creation'),
        'description' => t('Notifications produced when a new node is created.'),
        'help' => $help_digest,
        'fallback' => 'notifications-event-node',
      );
      $info['notifications-event-node-update'] = array(
        'module' => 'notifications_content',
        'name' => t('Notifications for node updates'),
        'description' => t('Notifications produced when a node is updated.'),
        'help' => $help_digest,
        'fallback' => 'notifications-event-node',
      );
      $info['notifications-event-node-comment'] = array(
        'module' => 'notifications_content',
        'name' => t('Notifications for node comments'),
        'description' => t('Notifications produced when a comment is posted to a node.'),
        'help' => $help_digest,
        'fallback' => 'notifications-event-node',
      );

      // Node group digests, will have specific help text in hook_help()
      $info['notifications-digest-node-nid'] = array(
        'module' => 'notifications-content',
        'name' => t('Groups digests per node'),
        'description' => t('Group of events digested for each node.'),
        'fallback' => 'notifications-digest',
      );
      $info['notifications-digest-node-type'] = array(
        'module' => 'notifications-content',
        'name' => t('Groups digests per node type'),
        'description' => t('Group of events digested for each node type.'),
        'fallback' => 'notifications-digest',
      );
      return $info;
    case 'message keys':
      $type = $arg1;
      switch ($type) {
        case 'notifications-event-node':
        case 'notifications-event-node-insert':
        case 'notifications-event-node-update':
        case 'notifications-event-node-comment':

          // Some parts will be re-used from 'notifications-event' group
          // So we specify only subject and main message
          return array(
            'subject' => t('Subject'),
            'main' => t('Content'),
            'digest' => t('Digest line'),
          );
        case 'notifications-digest-node-nid':
        case 'notifications-digest-node-type':
          $parts['title'] = t('Group title');
          $parts['footer'] = t('Group footer');
          return $parts;
      }
      break;
    case 'messages':
      $type = $arg1;

      // Event notifications
      switch ($type) {
        case 'notifications-event-node':
        case 'notifications-event-node-update':
          return array(
            'subject' => t('Update for [type-name]: [title]'),
            'main' => array(
              '[node-teaser]',
              t('Read more [node-url]'),
            ),
            'digest' => array(
              '[title]',
              'Read more [node-url]',
            ),
          );
        case 'notifications-event-node-insert':
          return array(
            'subject' => t('New [type-name]: [title]'),
            'main' => array(
              '[node-teaser]',
              t('Read more [node-url]'),
            ),
            'digest' => array(
              '[title]',
              'Read more [node-url]',
            ),
          );
        case 'notifications-event-node-comment':
          return array(
            'subject' => t('Comment for [type-name]: [title]'),
            'main' => array(
              t('Comment by [comment-author-name]: [comment-title]'),
              '[comment-body]',
              t('Read more [comment-url]'),
            ),
            'digest' => array(
              t('New Comment on [title] by [comment-author-name] titled [comment-title]'),
              t('Read more [comment-url]'),
            ),
          );
        case 'notifications-digest-node-nid':
          return array(
            'title' => t('Updates for [type-name]: [title]'),
            'footer' => t('Read more [node-url]'),
          );
        case 'notifications-digest-node-type':
          return array(
            'title' => t('New content of type [type-name] has been submitted'),
            'footer' => '<none>',
          );
      }
      break;
    case 'tokens':
      $type = explode('-', $arg1);
      $tokens = array();

      // These are the token groups that will be used for this module's messages
      if ($type[0] == 'notifications' && $type[2] == 'node') {
        if ($type[1] == 'event') {
          $tokens[] = 'node';
          if ($type[3] == 'comment') {
            $tokens[] = 'comment';
          }
        }
        elseif ($type[1] == 'digest') {
          if ($type[3] == 'nid') {
            $tokens[] = 'node';
          }
          elseif ($type[3] == 'type') {

            // Special format for isolated tokens: array('token type', 'token id').
            // In this case, as messages are digested by node type the only common element will be node-type
            $tokens[] = array(
              'node',
              'type-name',
            );
          }
        }
      }
      return $tokens;
  }
}