You are here

function notifications_content_nodeapi in Notifications 6.4

Same name and namespace in other branches
  1. 5 notifications_content/notifications_content.module \notifications_content_nodeapi()
  2. 6 notifications_content/notifications_content.module \notifications_content_nodeapi()
  3. 6.2 notifications_content/notifications_content.module \notifications_content_nodeapi()
  4. 6.3 notifications_content/notifications_content.module \notifications_content_nodeapi()

Implementation of hook_nodeapi()

1 string reference to 'notifications_content_nodeapi'
NotificationsContentTests::testNotificationsContent in tests/notifications_content.test
Play with creating, retrieving, deleting a pair subscriptions

File

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

Code

function notifications_content_nodeapi(&$node, $op, $arg = 0) {
  global $user;

  // Keep track of nodes so we don't send notifications twice for the same node. See http://drupal.org/node/722432
  $done =& messaging_static(__FUNCTION__);
  switch ($op) {
    case 'load':

      // Store current status for later reference
      $node->old_status = $node->status;
      break;
    case 'update':
    case 'insert':

      // Notifications just for published nodes. If we don't have any option enabled for this content type, skip the event
      if (!isset($done[$node->nid]) && $node->status && empty($node->notifications_content_disable) && notifications_content_type_enabled($node->type)) {
        $done[$node->nid] = TRUE;
        $event = array(
          'module' => 'node',
          'oid' => $node->nid,
          'type' => 'node',
          'action' => $op,
          //'node' => $node,
          'params' => array(
            'nid' => $node->nid,
          ),
        );
        if ($op == 'update') {

          // If the node has been published the 'update' will become a 'insert' (first post)
          // In this case the event user will be the node author instead of the current user
          if (!isset($node->old_status)) {

            // We try to find out previous status with the cached node.
            $oldnode = node_load($node->nid);
            $node->old_status = $oldnode->status;
          }
          if (!$node->old_status) {

            // The node has gone from unpublished to published, adjust event parameters
            $event['uid'] = $node->uid;
            $event['action'] = 'insert';
          }

          // If immediate sending is active, need to reset the node cache so we don't send old versions of the node
          if (variable_get('notifications_send_immediate', 0)) {
            node_load(0, NULL, TRUE);
          }
        }

        // Build and trigger the event
        notifications_event($event, array(
          'node' => $node,
        ));
      }
      break;
    case 'delete':

      // Remove all subscriptions for this node
      notifications_delete_subscriptions(array(
        'event_type' => 'node',
      ), array(
        'nid' => $node->nid,
      ), FALSE);
  }
}