You are here

function _node_expire_node_load in Node expire 7

Same name and namespace in other branches
  1. 8 node_expire.nodeapi.inc \_node_expire_node_load()

Implements hook_node_load().

1 call to _node_expire_node_load()
node_expire_node_load in ./node_expire.module
Implements hook_node_load().

File

./node_expire.nodeapi.inc, line 11
Node API integration.

Code

function _node_expire_node_load($nodes, $types) {

  // Only deal with node types that have the Node expire feature enabled.
  $ntypes = variable_get('node_expire_ntypes', array());
  $node_expire_enabled = array();

  // Check if node_expire are enabled for each node.
  // If node_expires are not enabled, do nothing.
  foreach ($nodes as $node) {

    // Store whether node_expires are enabled for this node.
    if (isset($ntypes[$node->type]) and $ntypes = $ntypes[$node->type]) {
      $node_expire_enabled[] = $node->nid;
    }
  }

  // For nodes with node_expire enabled, fetch information from the database.
  if (!empty($node_expire_enabled)) {
    $handle_content_expiry = variable_get('node_expire_handle_content_expiry', 2);
    $result = db_query('SELECT n.nid, n.type, expire, expired, lastnotify
       FROM {node} n
         INNER JOIN {node_expire} ne
           ON n.nid = ne.nid
       WHERE n.nid
         IN (:node_expire_enabled)', array(
      ':node_expire_enabled' => $node_expire_enabled,
    ));
    foreach ($result as $record) {
      if ($handle_content_expiry == 0) {
        $nodes[$record->nid]->expire = $record->expire;
      }
      else {
        $ntype = isset($ntypes[$record->type]) ? $ntypes[$record->type] : NULL;
        $nodes[$record->nid]->expire = _node_expire_date_db_to_str($record->expire, $ntype);
      }
      $nodes[$record->nid]->expired = $record->expired;
      $nodes[$record->nid]->lastnotify = $record->lastnotify;
    }
  }
}