You are here

function notifications_content_nodeapi in Notifications 6.3

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

Implementation of hook_nodeapi()

File

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

Code

function notifications_content_nodeapi(&$node, $op, $arg = 0) {
  global $user;
  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 ($node->status && empty($node->notifications_content_disable) && notifications_content_type_enabled($node->type)) {
        $event = array(
          'module' => 'node',
          'oid' => $node->nid,
          'type' => 'node',
          'subtype' => $node->type,
          '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);
          }
        }
        notifications_event($event);
      }
      break;
    case 'delete':

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