You are here

function xmlsitemap_node_nodeapi in XML sitemap 6

Same name and namespace in other branches
  1. 5.2 xmlsitemap_node/xmlsitemap_node.module \xmlsitemap_node_nodeapi()
  2. 5 xmlsitemap_node/xmlsitemap_node.module \xmlsitemap_node_nodeapi()
  3. 6.2 xmlsitemap_node/xmlsitemap_node.module \xmlsitemap_node_nodeapi()

Implementation of hook_nodeapi().

File

xmlsitemap_node/xmlsitemap_node.module, line 219
Adds nodes to the sitemap.

Code

function xmlsitemap_node_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  switch ($op) {
    case 'prepare':
      if (isset($node->nid)) {
        $priority_override = db_result(db_query("SELECT priority_override\n          FROM {xmlsitemap_node} WHERE nid = %d", $node->nid));
        $node->priority_override = $priority_override !== FALSE ? $priority_override : -2.0;
      }
      break;
    case 'insert':
      $row = new stdClass();
      $row->nid = $node->nid;
      $row->changed = $node->changed;
      $row->previously_changed = $node->created;
      $row->priority_override = isset($node->priority_override) ? $node->priority_override : -2.0;
      drupal_write_record('xmlsitemap_node', $row);
      if ($node->status) {
        xmlsitemap_flag_sitemap();
      }
      break;
    case 'update':
      if (($result = db_fetch_object(db_query("SELECT nid, changed, previously_changed, comment_ratio, priority_override FROM {xmlsitemap_node} WHERE nid = %d", $node->nid))) === FALSE) {
        $row = new stdClass();
        $row->nid = $node->nid;
        $row->changed = $node->changed;
        $row->previously_changed = $node->created;
        $row->priority_override = isset($node->priority_override) ? $node->priority_override : -2.0;
      }
      else {
        $row = $result;
        $row->previously_changed = $row->changed;
        $row->changed = $node->changed;
        if (isset($node->priority_override)) {
          $row->priority_override = $node->priority_override;
        }
      }
      drupal_write_record('xmlsitemap_node', $row, $result === FALSE ? NULL : 'nid');
      xmlsitemap_flag_sitemap();
      break;
    case 'delete':
      db_query("DELETE FROM {xmlsitemap_node} WHERE nid = %d", $node->nid);
      db_query("DELETE FROM {xmlsitemap} WHERE type = 'node' AND id = %d", $node->nid);
      if ($node->status) {
        xmlsitemap_flag_sitemap();
      }
      break;
  }
}