diff --git a/xmlsitemap.admin.inc b/xmlsitemap.admin.inc index 36b762ff10deb2b01d0ca315f1cdb01d163d616e..492858666c99f864bddddcf7cb09dccef1d377b7 100644 --- a/xmlsitemap.admin.inc +++ b/xmlsitemap.admin.inc @@ -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', diff --git a/xmlsitemap.generate.inc b/xmlsitemap.generate.inc index 3072fac53913c90058c8a604a7c0409d19daa1bf..febe244cdce181d535cbf0f7a07c0bf262abd583 100644 --- a/xmlsitemap.generate.inc +++ b/xmlsitemap.generate.inc @@ -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. diff --git a/xmlsitemap.module b/xmlsitemap.module index b65897678b1e59840694b635569eb0d4a0a728f1..372c622004242135cb3928a8ae1159da1c44db83 100644 --- a/xmlsitemap.module +++ b/xmlsitemap.module @@ -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,