You are here

function xmlsitemap_taxonomy_xmlsitemap_links in XML sitemap 6

Implementation of hook_xmlsitemap_links().

File

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

Code

function xmlsitemap_taxonomy_xmlsitemap_links() {
  $anon_account = drupal_anonymous_user();
  $user_access = user_access('access content', $anon_account);
  $result = db_query(db_rewrite_sql("SELECT t.tid, t.vid, t.name, xt.changed, xt.previously_changed, xt.priority_override\n        FROM {term_data} t\n        LEFT JOIN {xmlsitemap_taxonomy} xt ON t.tid = xt.tid", 't', 'tid'));
  $row = new stdClass();
  $row->module = 'xmlsitemap_taxonomy';
  $row->type = 'taxonomy';
  while ($term = db_fetch_object($result)) {
    $row->loc = taxonomy_term_path($term);
    $row->id = $term->tid;
    $row->changed = $term->changed;
    $row->changefreq = max(REQUEST_TIME - $term->changed, empty($term->previously_changed) ? 0 : $term->changed - $term->previously_changed);
    if ($term->priority_override != -2.0) {
      $priority = $term->priority_override;
    }
    else {
      $priority = variable_get('xmlsitemap_taxonomy_vocabulary_priority_' . $term->vid, 0.5);
    }
    $row->priority = $user_access ? $priority == -1.0 ? $priority : min(max(round($priority, 1), 0.0), 1.0) : -1;
    $old_row = db_fetch_object(db_query("SELECT lid, type, priority FROM {xmlsitemap} WHERE loc = '%s'", $row->loc));
    if ($old_row === FALSE) {
      drupal_write_record('xmlsitemap', $row);
    }
    elseif ($old_row->type = 'taxonomy' && ($old_row->priority != $row->priority || $old_row->changed != $row->changed || $old_row->changefreq != $row->changefreq)) {
      $row->lid = $old_row->lid;
      drupal_write_record('xmlsitemap', $row, 'lid');
    }
  }
}