You are here

function xmlsitemap_term_taxonomy in XML sitemap 5

Same name and namespace in other branches
  1. 5.2 xmlsitemap_term/xmlsitemap_term.module \xmlsitemap_term_taxonomy()

Implementation of hook_taxonomy().

Related topics

File

xmlsitemap_term/xmlsitemap_term.module, line 176
Adds terms to the site map.

Code

function xmlsitemap_term_taxonomy($op, $type, $array = NULL) {
  if ($type == 'vocabulary') {
    switch ($op) {
      case 'delete':
        variable_del("xmlsitemap_term_vocabulary_priority_{$array['vid']}");
        xmlsitemap_update_sitemap();
        break;
      case 'insert':
      case 'update':
        if (variable_get("xmlsitemap_term_vocabulary_priority_{$array['vid']}", 0.5) != $array['xmlsitemap_term_vocabulary_priority']) {
          variable_set("xmlsitemap_term_vocabulary_priority_{$array['vid']}", $array['xmlsitemap_term_vocabulary_priority']);
          xmlsitemap_update_sitemap();
        }
        break;
    }
  }
  else {
    if ($op != 'delete') {
      $module = db_result(db_query("SELECT module FROM {vocabulary} WHERE vid = %d", $array['vid']));
      if ($module == 'forum') {
        $pid = db_result(db_query("SELECT pid FROM {url_alias} WHERE src = '%s'", "forum/{$array['tid']}"));
      }
      elseif ($module != 'taxonomy' && ($path = module_invoke($module, 'term_path', (object) $array))) {
        $pid = db_result(db_query("SELECT pid FROM {url_alias} WHERE src = '%s'", $path));
      }
      else {
        $pid = db_result(db_query("SELECT pid FROM {url_alias} WHERE src = '%s'", "taxonomy/term/{$array['tid']}"));
      }
      $pid = empty($pid) ? 'NULL' : $pid;
    }
    switch ($op) {
      case 'insert':
        $priority = isset($array['xmlsitemap_term_priority']) ? $array['xmlsitemap_term_priority'] : 'NULL';
        db_query("\n          INSERT INTO {xmlsitemap_term} (tid, pid, last_changed, priority_override) VALUES (%d, %s, %d, %s)\n        ", $array['tid'], $pid, time(), $priority);
        break;
      case 'update':
        if (!isset($array['xmlsitemap_term_priority'])) {
          $priority = db_result(db_query("SELECT priority_override FROM {xmlsitemap_term} WHERE tid = %d", $array['tid']));
          $array['xmlsitemap_term_priority'] = isset($priority) && $priority !== FALSE ? $priority : 'NULL';
        }
        db_query("\n          UPDATE {xmlsitemap_term}\n          SET pid = %s, last_changed = %d, previously_changed = last_changed, priority_override = %s\n          WHERE tid = %d\n        ", $pid, time(), $array['xmlsitemap_term_priority'], $array['tid']);
        break;
      case 'delete':
        db_query("DELETE FROM {xmlsitemap_term} WHERE tid = %d", $array['tid']);
        break;
    }
    xmlsitemap_update_sitemap();
  }
}