You are here

function notifications_feed_notifications in Notifications 6

Same name and namespace in other branches
  1. 5 notifications_feed/notifications_feed.module \notifications_feed_notifications()

Implementation of hook_notifications().

File

notifications_feed/notifications_feed.module, line 38
Subscriptions to FeedAPI feeds

Code

function notifications_feed_notifications($op, &$arg0, $arg1 = NULL, $arg2 = NULL) {
  switch ($op) {
    case 'names':
      $subs =& $arg0;
      if ($subs->event_type == 'feed') {
        if (!empty($subs->fields['feed-nid'])) {
          $feed = node_load($subs->fields['feed-nid']);
          $subs->names['feed-nid'] = t('Feed: %name', array(
            '%name' => $feed->title,
          ));
        }
      }
      break;
    case 'subscription types':
      $types['feed'] = array(
        'event_type' => 'feed',
        'title' => t('Feed'),
        'access' => 'subscribe to feeds',
        'fields' => array(
          'feed-nid',
        ),
        'page callback' => 'notifications_feed_user_page',
      );
      return $types;
    case 'subscription fields':

      // Information about available fields for subscriptions
      $fields['feed-nid'] = array(
        'name' => t('Feed'),
        'field' => 'feed-nid',
        'type' => 'int',
        'format callback' => 'notifications_node_nid2title',
      );

      // If available node types, add autocomplete information
      if ($node_types = feedapi_get_types()) {
        $fields['feed-nid'] += array(
          'value callback' => 'notifications_feed_title2nid',
          'autocomplete path' => 'notifications/autocomplete/node/type/' . implode(',', array_keys($node_types)),
          'autocomplete callback' => 'notifications_feed_nid2autocomplete',
        );
      }
      return $fields;
    case 'query':
      if ($arg0 == 'event' && $arg1 == 'feed' && ($node = $arg2->feed) || $arg0 == 'user' && $arg1 == 'feed' && ($node = $arg2)) {
        $query[]['fields'] = array(
          'feed-nid' => $node->nid,
        );
        return $query;
      }
      break;
    case 'event types':
      $types[] = array(
        'type' => 'feed',
        'action' => 'update',
        'name' => 'Feed: [title]',
        'line' => "The feed [title] has been updated\n[feed-updated-items]",
        'digest' => array(
          'feed',
          'type',
        ),
      );
      return $types;
    case 'event objects':
      return array(
        'feed' => t('FeedAPI feed'),
      );
    case 'event load':
      $event =& $arg0;
      if ($event->type == 'feed') {
        if (!empty($event->params['nid'])) {

          // For practical reasons like tokens we pass it as node too
          $event->objects['node'] = $feed = node_load($event->params['nid']);

          // Add some more data and we have the feed
          $feed->items_new = $event->params['items_new'];
          $feed->items_updated = $event->params['items_updated'];
          $event->objects['feed'] = $feed;
        }
      }
      break;
    case 'node options':
      return _notifications_feed_node_options($arg0, $arg1);
  }
}