function _xmlsitemap_output in XML sitemap 5
Menu callback; display the site map.
Parameters
$chunk:: An integer specifying which chunk of the site map is being requested. If not set and there is more than one chunk, display the site map index.
Return value
None
Related topics
1 string reference to '_xmlsitemap_output'
- xmlsitemap_menu in ./
xmlsitemap.module - Implementation of hook_menu().
File
- ./
xmlsitemap.module, line 334 - Creates a site map compatible with the sitemaps.org schema.
Code
function _xmlsitemap_output($chunk = NULL) {
drupal_set_header('Content-type: text/xml; charset=utf-8');
global $user;
$dest = file_directory_path() . '/xmlsitemap';
file_check_directory($dest, FILE_CREATE_DIRECTORY);
if (isset($chunk)) {
$dest .= "/sitemap{$chunk}.xml.gz";
$type = t('Site map @chunk', array(
'@chunk' => $chunk,
));
}
else {
$dest .= '/sitemap.xml.gz';
$link_count = _xmlsitemap_link_count();
$chunk_size = variable_get('xmlsitemap_chunk_size', 50000);
$type = $link_count > $chunk_size ? t('Site map index') : t('Site map');
}
$status = TRUE;
if (!file_exists($dest) || variable_get('xmlsitemap_update', FALSE)) {
$page = isset($chunk) ? $chunk : 'index';
$status = _xmlsitemap_update_cache($page);
}
if ($status) {
if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') === FALSE || zlib_get_coding_type() !== FALSE || extension_loaded('eAccelerator') || variable_get('cache', CACHE_DISABLED) != CACHE_DISABLED && empty($user->uid)) {
readgzfile($dest);
}
else {
drupal_set_header('Content-Encoding: gzip');
print file_get_contents($dest);
}
if (variable_get('xmlsitemap_log_access', FALSE)) {
$message = array_shift(module_invoke_all('xmlsitemap_engines', 'access', $type));
$message = isset($message) ? $message : t('!sitemap downloaded by @user-agent at @address.', array(
'!sitemap' => $type,
'@user-agent' => $_SERVER['HTTP_USER_AGENT'],
'@address' => $_SERVER['REMOTE_ADDR'],
));
watchdog('xmlsitemap', $message);
}
}
else {
drupal_not_found();
}
}