You are here

function notifications_content_nodeapi in Notifications 6

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.2 notifications_content/notifications_content.module \notifications_content_nodeapi()
  4. 6.3 notifications_content/notifications_content.module \notifications_content_nodeapi()

Implementation of hook_nodeapi()

File

notifications_content/notifications_content.module, line 622
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',
          'uid' => $node->uid,
          '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)
          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) {
            $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);
  }
}