You are here

function _xmlsitemap_create_cache_chunk in XML sitemap 6

Create a sitemap chunk cache file.

Parameters

$fp: A file resource used to write in.

$chunk_size: The number of links the chunk must cointain.

$chunk: The progressive number associated with the sitemap chunk (starting from 0).

1 call to _xmlsitemap_create_cache_chunk()
_xmlsitemap_create_cache_files in ./xmlsitemap.pages.inc
Create the cache files containing the sitemap.

File

./xmlsitemap.pages.inc, line 167
XML sitemap page callbacks.

Code

function _xmlsitemap_create_cache_chunk($fp, $chunk_size, $chunk = 0) {
  fwrite($fp, '<?xml version="1.0" encoding="UTF-8"?>' . "\n");
  if (variable_get('xmlsitemap_use_stylesheet', FALSE)) {
    fwrite($fp, '<?xml-stylesheet type="text/xsl" href="' . url('sitemap.xsl') . '" ?>' . "\n");
  }
  fwrite($fp, '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"' . "\n");
  fwrite($fp, '  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' . "\n");
  fwrite($fp, '  xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9' . "\n");
  fwrite($fp, '  http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">' . "\n");
  $start = $chunk * $chunk_size;
  $links = db_query_range("SELECT xsm.loc, xsm.module, xsm.type, xsm.id, xsm.sid, xsm.changed, xsm.changefreq, xsm.priority" . xmlsitemap_sitemap_query() . "ORDER BY xsm.priority DESC, xsm.changed DESC, xsm.changefreq, xsm.loc", $start, $chunk_size);
  while ($link = db_fetch_object($links)) {
    if ($link->type == 'frontpage') {
      $url = url(NULL, array(
        'absolute' => TRUE,
      ));
    }
    else {
      $url = url($link->loc, array(
        'absolute' => TRUE,
      ));
    }
    $link->url = $url;
    if ($link->module && function_exists($link->module . '_xmlsitemap_link_status')) {
      $function = $link->module . '_xmlsitemap_link_status';
      $link->status = $function($link->type, $link->id, $link->sid);
    }
    else {
      $link->status = 0;
    }
    drupal_alter('xmlsitemap_data', $link);
    if (($link->status & XMLSITEMAP_LINK_DISABLED) != XMLSITEMAP_LINK_DISABLED) {
      $link->output = "<url>\n";
      $link->output .= "\t<loc>" . check_url($link->url) . "</loc>\n";
      $link->output .= "\t<lastmod>" . gmdate(DATE_W3C, $link->changed) . "</lastmod>\n";
      $link->output .= "\t<changefreq>" . xmlsitemap_sitemap_frequency($link->changefreq) . "</changefreq>\n";
      $link->output .= "\t<priority>" . number_format($link->priority, 1) . "</priority>\n";
      $link->output .= "</url>\n";
      fwrite($fp, $link->output);
    }
  }
  fwrite($fp, '</urlset>');
}