You are here

function xmlsitemap_node_nodeapi in XML sitemap 5

Same name and namespace in other branches
  1. 5.2 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()

Implmentation of hook_nodeapi().

Related topics

File

xmlsitemap_node/xmlsitemap_node.module, line 255
Adds nodes to the site map.

Code

function xmlsitemap_node_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  switch ($op) {
    case 'prepare':
      $priority = db_result(db_query("SELECT priority_override FROM {xmlsitemap_node} WHERE nid = %d", $node->nid));
      $node->priority_override = isset($priority) && $priority !== FALSE ? $priority : 'NULL';
      break;
    case 'insert':
      $node->priority_override = isset($node->priority_override) ? $node->priority_override : 'NULL';
      $query = "\n        INSERT INTO {xmlsitemap_node} (nid, pid, last_changed, priority_override)\n        SELECT %d, ua.pid, %d, %s\n        FROM {node} n";
      switch ($GLOBALS['db_type']) {
        case 'mysql':
        case 'mysqli':
          $query .= "\n        LEFT JOIN {url_alias} ua ON ua.src = CONCAT('node/', CAST(%d AS CHAR))";
          break;
        case 'pgsql':
          $query .= "\n        LEFT JOIN {url_alias} ua ON ua.src = CONCAT('node/', CAST(%d AS VARCHAR))";
          break;
      }
      $query .= "\n        LIMIT 1";
      db_query($query, $node->nid, $node->changed, $node->priority_override, $node->nid);
      if ($node->status) {
        xmlsitemap_update_sitemap();
      }
      break;
    case 'update':
      if (!isset($node->priority_override)) {
        $priority = db_result(db_query("SELECT priority_override FROM {xmlsitemap_node} WHERE nid = %d", $node->nid));
        $node->priority_override = isset($priority) && $priority !== FALSE ? $priority : 'NULL';
      }
      switch ($GLOBALS['db_type']) {
        case 'mysql':
        case 'mysqli':
          db_query("\n            UPDATE {xmlsitemap_node} xn LEFT JOIN {url_alias} ua ON ua.src = CONCAT('node/', CAST(xn.nid AS CHAR))\n            SET xn.pid = ua.pid, xn.previously_changed = xn.last_changed, xn.last_changed = %d, xn.priority_override = %s\n            WHERE xn.nid = %d\n          ", $node->changed, $node->priority_override, $node->nid);
          break;
        case 'pgsql':
          db_query("\n            UPDATE {xmlsitemap_node}\n            SET pid = {url_alias}.pid, previously_changed = last_changed, last_changed = %d, priority_override = %s\n            FROM {url_alias} WHERE nid = %d AND ({url_alias}.src = CONCAT('node/', CAST(nid AS VARCHAR)) OR {url_alias}.src IS NULL)\n          ", $node->changed, $node->priority_override, $node->nid);
          break;
      }
      if ($node->status || $node->xmlsitemap_node_status) {
        xmlsitemap_update_sitemap();
      }
      break;
    case 'delete':
      db_query("DELETE FROM {xmlsitemap_node} WHERE nid = %d", $node->nid);
      if ($node->status) {
        xmlsitemap_update_sitemap();
      }
      break;
  }
}