You are here

function xmlsitemap_taxonomy_taxonomy in XML sitemap 6

Same name and namespace in other branches
  1. 6.2 xmlsitemap_taxonomy/xmlsitemap_taxonomy.module \xmlsitemap_taxonomy_taxonomy()

Implementation of hook_taxonomy().

File

xmlsitemap_taxonomy/xmlsitemap_taxonomy.module, line 139
Adds taxonomy terms to the sitemap.

Code

function xmlsitemap_taxonomy_taxonomy($op, $type, $array = NULL) {
  if ($type == 'vocabulary') {
    switch ($op) {
      case 'delete':
        db_query("DELETE FROM {xmlsitemap_taxonomy} WHERE vid = %d", $array['vid']);
        variable_del('xmlsitemap_taxonomy_vocabulary_priority_' . $array['vid']);
        xmlsitemap_flag_sitemap();
        break;
      case 'insert':
      case 'update':
        if (isset($array['vid']) && isset($array['xmlsitemap_taxonomy_vocabulary_priority'])) {
          if (variable_get('xmlsitemap_taxonomy_vocabulary_priority_' . $array['vid'], 0.5) != $array['xmlsitemap_taxonomy_vocabulary_priority']) {
            variable_set('xmlsitemap_taxonomy_vocabulary_priority_' . $array['vid'], $array['xmlsitemap_taxonomy_vocabulary_priority']);
            xmlsitemap_flag_sitemap();
          }
        }
        break;
    }
  }
  else {
    switch ($op) {
      case 'delete':
        db_query("DELETE FROM {xmlsitemap_taxonomy} WHERE tid = %d", $array['tid']);
        db_query("DELETE FROM {xmlsitemap} WHERE type = 'taxonomy' AND id = %d", $array['tid']);
        break;
      case 'insert':
        if (isset($array['tid']) && isset($array['vid'])) {
          $row = new stdClass();
          $row->tid = $array['tid'];
          $row->vid = $array['vid'];
          $row->changed = REQUEST_TIME;
          $row->priority_override = isset($array['xmlsitemap_taxonomy_priority']) ? $array['xmlsitemap_taxonomy_priority'] : -2.0;
          drupal_write_record('xmlsitemap_taxonomy', $row);
        }
        break;
      case 'update':
        $result = db_fetch_object(db_query("SELECT tid, vid, changed, previously_changed, priority_override\n          FROM {xmlsitemap_taxonomy}\n          WHERE tid = %d", $array['tid']));
        if ($result === FALSE) {
          $row = new stdClass();
          $row->tid = $array['tid'];
          $row->vid = $array['vid'];
          $row->changed = REQUEST_TIME;
          $row->priority_override = isset($array['xmlsitemap_taxonomy_priority']) ? $array['xmlsitemap_taxonomy_priority'] : -2.0;
        }
        else {
          $row = $result;
          if (isset($array['xmlsitemap_taxonomy_priority'])) {
            $row->priority_override = $array['xmlsitemap_taxonomy_priority'];
          }
        }
        drupal_write_record('xmlsitemap_taxonomy', $row, $result === FALSE ? NULL : 'tid');
        break;
    }
    xmlsitemap_flag_sitemap();
  }
}