1 node.module node_tag_new($node = NULL, $save_for_later = FALSE)

Updates the 'last viewed' timestamp of the specified node for current user.

@since 1.10 $save_for_later parameter added.

Parameters

Node $node: A node entity.

bool $save_for_later: Save the given node ID to save its marking for at the end of the request.

File

core/modules/node/node.module, line 280
The core module that allows content to be submitted to the site.

Code

function node_tag_new($node = NULL, $save_for_later = FALSE) {
  $nids_viewed = &backdrop_static(__FUNCTION__, array());
  if ($node) {
    $nids_viewed[] = $node->nid;
  }

  // Node IDs saved for later are then actually updated in a shutdown function.
  if ($save_for_later || empty($nids_viewed)) {
    return;
  }

  global $user;
  if ($user->uid) {
    foreach ($nids_viewed as $nid) {
      db_merge('history')
        ->key(array(
          'uid' => $user->uid,
          'nid' => $nid,
        ))
        ->fields(array('timestamp' => REQUEST_TIME))
        ->execute();
    }
  }

  // Clear out the saved list so we don't update the same nodes again..
  $nids_viewed = array();
}