Commit cd45c8be authored by Dave Reid's avatar Dave Reid Committed by Dave Reid

Issue #2416897 by Dave Reid: Allow disabling output of lastmod, changefreq,...

Issue #2416897 by Dave Reid: Allow disabling output of lastmod, changefreq, and priority in <loc> elements.
parent d602b021
......@@ -354,6 +354,16 @@ function xmlsitemap_settings_form($form, &$form_state) {
'#default_value' => variable_get('xmlsitemap_disable_cron_regeneration', 0),
'#description' => t('This can be disabled if other methods are being used to generate the sitemap files, like <em>drush xmlsitemap-regenerate</em>.'),
);
$form['advanced']['xmlsitemap_output_elements'] = array(
'#type' => 'checkboxes',
'#title' => t('Enable or disable the individual @loc elements from output', array('@loc' => '<loc>')),
'#options' => array(
'lastmod' => t('Last modification date: @lastmod', array('@lastmod' => '<lastmod>')),
'changefreq' => t('Change frequency: @changfreq', array('@changfreq' => '<changefreq>')),
'priority' => t('Priority: @priority', array('@priority' => '<priority>')),
),
'#default_value' => drupal_map_assoc(variable_get('xmlsitemap_output_elements', array('lastmod', 'changefreq', 'priority'))),
);
$form['xmlsitemap_settings'] = array(
'#type' => 'vertical_tabs',
......
......@@ -154,6 +154,7 @@ function xmlsitemap_generate_page(stdClass $sitemap, $page) {
}
function xmlsitemap_generate_chunk(stdClass $sitemap, XMLSitemapWriter $writer, $chunk) {
$output_elements = drupal_map_assoc(variable_get('xmlsitemap_output_elements', array('lastmod', 'changefreq', 'priority')));
$lastmod_format = variable_get('xmlsitemap_lastmod_format', XMLSITEMAP_LASTMOD_MEDIUM);
$url_options = $sitemap->uri['options'];
......@@ -209,17 +210,19 @@ function xmlsitemap_generate_chunk(stdClass $sitemap, XMLSitemapWriter $writer,
$element = array();
$element['loc'] = $link_url;
if ($link['lastmod']) {
$element['lastmod'] = gmdate($lastmod_format, $link['lastmod']);
if (!empty($output_elements['lastmod'])) {
$element['lastmod'] = gmdate($lastmod_format, $link['lastmod']);
}
// If the link has a lastmod value, update the changefreq so that links
// with a short changefreq but updated two years ago show decay.
// We use abs() here just incase items were created on this same cron run
// because lastmod would be greater than REQUEST_TIME.
$link['changefreq'] = (abs(REQUEST_TIME - $link['lastmod']) + $link['changefreq']) / 2;
}
if ($link['changefreq']) {
if (!empty($output_elements['changefreq']) && $link['changefreq']) {
$element['changefreq'] = xmlsitemap_get_changefreq($link['changefreq']);
}
if (isset($link['priority']) && $link['priority'] != 0.5) {
if (!empty($output_elements['priority']) && isset($link['priority']) && $link['priority'] != 0.5) {
// Don't output the priority value for links that have 0.5 priority. This
// is the default 'assumed' value if priority is not included as per the
// sitemaps.org specification.
......
......@@ -297,6 +297,7 @@ function xmlsitemap_variables() {
'xmlsitemap_lastmod_format' => XMLSITEMAP_LASTMOD_MEDIUM,
'xmlsitemap_gz' => FALSE,
'xmlsitemap_disable_cron_regeneration' => 0,
'xmlsitemap_output_elements' => array('lastmod', 'changefreq', 'priority'),
// Removed variables are set to NULL so they can still be deleted.
'xmlsitemap_regenerate_last' => NULL,
'xmlsitemap_custom_links' => NULL,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment