You are here

function xmlsitemap_node_nodeapi in XML sitemap 5.2

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

Implementation of hook_nodeapi().

File

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

Code

function xmlsitemap_node_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  switch ($op) {
    case 'prepare':
      $priority_override = db_result(db_query("SELECT priority_override\n        FROM {xmlsitemap_node}\n        WHERE nid = %d", $node->nid));
      $node->priority_override = $priority_override === FALSE ? 'NULL' : $priority_override;
      break;
    case 'insert':
      $node->priority_override = isset($node->priority_override) ? $node->priority_override : 'NULL';
      db_query("INSERT INTO {xmlsitemap_node} (nid, last_changed, priority_override) VALUES (%d, %d, %s)", $node->nid, $node->changed, $node->priority_override);
      if ($node->status) {
        xmlsitemap_flag_sitemap();
      }
      break;
    case 'update':
      if (!isset($node->priority_override)) {
        $priority_override = db_result(db_query("SELECT priority_override FROM {xmlsitemap_node} WHERE nid = %d", $node->nid));
        $node->priority_override = $priority_override !== FALSE ? $priority_override : 'NULL';
      }
      db_query("UPDATE {xmlsitemap_node}\n        SET previously_changed = last_changed, last_changed = %d, priority_override = %s\n        WHERE nid = %d", $node->changed, $node->priority_override, $node->nid);
      xmlsitemap_flag_sitemap();
      break;
    case 'delete':
      db_query("DELETE FROM {xmlsitemap_node} WHERE nid = %d", $node->nid);
      if ($node->status) {
        xmlsitemap_flag_sitemap();
      }
      break;
  }
}