diff --git a/xmlsitemap.admin.inc b/xmlsitemap.admin.inc index 496dd2c..f7887a7 100644 --- a/xmlsitemap.admin.inc +++ b/xmlsitemap.admin.inc @@ -629,6 +629,17 @@ function xmlsitemap_add_link_bundle_settings(array &$form, array &$form_state, $ ), ), ); + $form['xmlsitemap']['changefreq'] = array( + '#type' => 'select', + '#title' => t('Default change frequency'), + '#options' => xmlsitemap_get_changefreq_options(), + '#default_value' => $bundle_info['changefreq'], + '#states' => array( + 'invisible' => array( + 'select[name="xmlsitemap[status]"]' => array('value' => '0'), + ), + ), + ); $form += array('#submit' => array()); array_unshift($form['#submit'], 'xmlsitemap_link_bundle_settings_form_submit'); @@ -699,6 +710,9 @@ function xmlsitemap_add_form_link_options(array &$form, $entity, $bundle, $id) { 'priority' => $bundle_info['priority'], 'priority_default' => $bundle_info['priority'], 'priority_override' => 0, + 'changefreq' => $bundle_info['changefreq'], + 'changefreq_default' => $bundle_info['changefreq'], + 'changefreq_override' => 0, ); $form['xmlsitemap'] = array( @@ -706,7 +720,7 @@ function xmlsitemap_add_form_link_options(array &$form, $entity, $bundle, $id) { '#tree' => TRUE, '#title' => t('XML sitemap'), '#collapsible' => TRUE, - '#collapsed' => !$link['status_override'] && !$link['priority_override'], + '#collapsed' => !$link['status_override'] && !$link['priority_override'] && !$link['changefreq_override'], '#access' => user_access('administer xmlsitemap') || xmlsitemap_link_bundle_access($bundle_info), '#group' => 'additional_settings', '#attached' => array( @@ -785,6 +799,35 @@ function xmlsitemap_add_form_link_options(array &$form, $entity, $bundle, $id) { '#value' => $link['priority_override'], ); + // Changefreq field + $form['xmlsitemap']['changefreq'] = array( + '#type' => 'select', + '#title' => t('Change frequency'), + '#options' => xmlsitemap_get_changefreq_options($link['changefreq_default']), + '#default_value' => $link['changefreq_override'] ? $link['changefreq'] : 'default', + '#description' => t('The change frequency of this URL relative to other URLs on your site.'), + '#states' => array( + 'invisible' => array( + 'select[name="xmlsitemap[status]"]' => array('value' => '0'), + ), + ), + ); + if (!$link['status_default']) { + // If the default status is excluded, add a visible state on the include + // override option. + $form['xmlsitemap']['changefreq']['#states']['visible'] = array( + 'select[name="xmlsitemap[status]"]' => array('value' => '1'), + ); + } + $form['xmlsitemap']['changefreq_default'] = array( + '#type' => 'value', + '#value' => $link['changefreq_default'], + ); + $form['xmlsitemap']['changefreq_override'] = array( + '#type' => 'value', + '#value' => $link['changefreq_override'], + ); + // Other persistent fields. //$form['xmlsitemap']['lastmod'] = array( // '#type' => 'value', diff --git a/xmlsitemap.generate.inc b/xmlsitemap.generate.inc index 57c3bc1..0d6e9b9 100644 --- a/xmlsitemap.generate.inc +++ b/xmlsitemap.generate.inc @@ -545,6 +545,7 @@ function xmlsitemap_rebuild_clear(array $types, $save_custom) { if ($save_custom) { $query->condition('status_override', 0); $query->condition('priority_override', 0); + $query->condition('changefreq_override', 0); } return $query->execute(); diff --git a/xmlsitemap.install b/xmlsitemap.install index 916ebec..368099a 100644 --- a/xmlsitemap.install +++ b/xmlsitemap.install @@ -231,6 +231,13 @@ function xmlsitemap_schema() { 'not null' => TRUE, 'default' => 0, ), + 'changefreq_override' => array( + 'description' => 'A boolean that if TRUE means that the changefreq field has been overridden from its default value.', + 'type' => 'int', + 'size' => 'tiny', + 'not null' => TRUE, + 'default' => 0, + ), 'changecount' => array( 'description' => 'The number of times this item has been changed. Used to help calculate the next changefreq value.', 'type' => 'int', @@ -568,3 +575,11 @@ function _xmlsitemap_sitemap_rehash_all() { } } } + +/** + * Add {xmlsitemap}.changefreq_override column. + */ +function xmlsitemap_update_7204() { + $schema = xmlsitemap_schema(); + db_add_field('xmlsitemap', 'changefreq_override', $schema['xmlsitemap']['fields']['changefreq_override']); +} diff --git a/xmlsitemap.module b/xmlsitemap.module index 09d02ea..5861430 100644 --- a/xmlsitemap.module +++ b/xmlsitemap.module @@ -25,6 +25,7 @@ define('XMLSITEMAP_FREQUENCY_WEEKLY', 604800); // 60 * 60 * 24 * 7 define('XMLSITEMAP_FREQUENCY_DAILY', 86400); // 60 * 60 * 24 define('XMLSITEMAP_FREQUENCY_HOURLY', 3600); // 60 * 60 define('XMLSITEMAP_FREQUENCY_ALWAYS', 60); +define('XMLSITEMAP_FREQUENCY_DEFAULT', XMLSITEMAP_FREQUENCY_MONTHLY); /** * Short lastmod timestamp format. @@ -586,6 +587,7 @@ function xmlsitemap_link_save(array $link, array $context = array()) { 'priority' => XMLSITEMAP_PRIORITY_DEFAULT, 'priority_override' => 0, 'changefreq' => 0, + 'changefreq_override' => 0, 'changecount' => 0, 'language' => LANGUAGE_NONE, ); @@ -1036,6 +1038,9 @@ function xmlsitemap_link_bundle_settings_save($entity, $bundle, array $settings, if ($settings['priority'] != $old_settings['priority']) { xmlsitemap_link_update_multiple(array('priority' => $settings['priority']), array('type' => $entity, 'subtype' => $bundle, 'priority_override' => 0)); } + if ($settings['changefreq'] != $old_settings['changefreq']) { + xmlsitemap_link_update_multiple(array('changefreq' => $settings['changefreq']), array('type' => $entity, 'subtype' => $bundle, 'changefreq_override' => 0)); + } } variable_set("xmlsitemap_settings_{$entity}_{$bundle}", $settings); @@ -1085,6 +1090,7 @@ function xmlsitemap_link_bundle_load($entity, $bundle, $load_bundle_info = TRUE) $info += array( 'status' => XMLSITEMAP_STATUS_DEFAULT, 'priority' => XMLSITEMAP_PRIORITY_DEFAULT, + 'changefreq' => XMLSITEMAP_FREQUENCY_DEFAULT, ); return $info; } @@ -1337,7 +1343,7 @@ function xmlsitemap_restore_user() { function xmlsitemap_process_form_link_options($form, &$form_state) { $link = &$form_state['values']['xmlsitemap']; - $fields = array('status' => XMLSITEMAP_STATUS_DEFAULT, 'priority' => XMLSITEMAP_PRIORITY_DEFAULT); + $fields = array('status' => XMLSITEMAP_STATUS_DEFAULT, 'priority' => XMLSITEMAP_PRIORITY_DEFAULT, 'changefreq' => XMLSITEMAP_FREQUENCY_DEFAULT); foreach ($fields as $field => $default) { if ($link[$field] === 'default') { @@ -1384,8 +1390,9 @@ function xmlsitemap_link_bundle_settings_form_submit($form, &$form_state) { * @todo Document this function. * @todo Make these translatable */ -function xmlsitemap_get_changefreq_options() { - return array( +function xmlsitemap_get_changefreq_options($default = NULL) { + $options = array(); + $changefreqs = array( XMLSITEMAP_FREQUENCY_ALWAYS => 'always', XMLSITEMAP_FREQUENCY_HOURLY => 'hourly', XMLSITEMAP_FREQUENCY_DAILY => 'daily', @@ -1393,6 +1400,16 @@ function xmlsitemap_get_changefreq_options() { XMLSITEMAP_FREQUENCY_MONTHLY => 'monthly', XMLSITEMAP_FREQUENCY_YEARLY => 'yearly', ); + + if (isset($default)) { + $default = (int)$default; + $options['default'] = t('Default (@value)', array('@value' => $changefreqs[$default])); + } + + // Add the rest of the options. + $options += $changefreqs; + + return $options; } /** diff --git a/xmlsitemap_menu/xmlsitemap_menu.module b/xmlsitemap_menu/xmlsitemap_menu.module index f0ba9e2..946bc96 100644 --- a/xmlsitemap_menu/xmlsitemap_menu.module +++ b/xmlsitemap_menu/xmlsitemap_menu.module @@ -254,6 +254,9 @@ function xmlsitemap_menu_create_link(array $menu_item) { 'priority' => $settings['priority'], 'priority_default' => $settings['priority'], 'priority_override' => 0, + 'changefreq' => $settings['changefreq'], + 'changefreq_default' => $settings['changefreq'], + 'changefreq_override' => 0, ); // The following values must always be checked because they are volatile. diff --git a/xmlsitemap_node/xmlsitemap_node.module b/xmlsitemap_node/xmlsitemap_node.module index 3d0e534..5464073 100644 --- a/xmlsitemap_node/xmlsitemap_node.module +++ b/xmlsitemap_node/xmlsitemap_node.module @@ -188,12 +188,20 @@ function xmlsitemap_node_create_link(stdClass $node) { 'priority' => $settings['priority'], 'priority_default' => $settings['priority'], 'priority_override' => 0, + 'changefreq' => $settings['changefreq'], + 'changefreq_default' => $settings['changefreq'], + 'changefreq_override' => 0, ); - // Always recalculate changefreq and changecount. + // Only recalculate changefreq and changecount when not overridden. $timestamps = xmlsitemap_node_get_timestamps($node); - $node->xmlsitemap['changefreq'] = $node->nid ? xmlsitemap_calculate_changefreq($timestamps) : 0; - $node->xmlsitemap['changecount'] = $node->nid ? count($timestamps) - 1 : 0; + if ($node->xmlsitemap['changefreq_override'] == 0) { + $node->xmlsitemap['changefreq'] = $node->nid ? xmlsitemap_calculate_changefreq($timestamps) : 0; + $node->xmlsitemap['changecount'] = $node->nid ? count($timestamps) - 1 : 0; + } + else { + $node->xmlsitemap['changecount'] = 0; + } // Node access must be reset since it a user may have changed published status, etc. //$access = &drupal_static('node_access'); diff --git a/xmlsitemap_taxonomy/xmlsitemap_taxonomy.module b/xmlsitemap_taxonomy/xmlsitemap_taxonomy.module index 88f6a60..188261a 100644 --- a/xmlsitemap_taxonomy/xmlsitemap_taxonomy.module +++ b/xmlsitemap_taxonomy/xmlsitemap_taxonomy.module @@ -169,6 +169,9 @@ function xmlsitemap_taxonomy_create_link(stdClass &$term) { 'priority' => $settings['priority'], 'priority_default' => $settings['priority'], 'priority_override' => 0, + 'changefreq' => $settings['changefreq'], + 'changefreq_default' => $settings['changefreq'], + 'changefreq_override' => 0, ); // The following values must always be checked because they are volatile. diff --git a/xmlsitemap_user/xmlsitemap_user.module b/xmlsitemap_user/xmlsitemap_user.module index d441570..ae2762f 100644 --- a/xmlsitemap_user/xmlsitemap_user.module +++ b/xmlsitemap_user/xmlsitemap_user.module @@ -144,6 +144,9 @@ function xmlsitemap_user_create_link(stdClass &$account) { 'priority' => $settings['priority'], 'priority_default' => $settings['priority'], 'priority_override' => 0, + 'changefreq' => $settings['changefreq'], + 'changefreq_default' => $settings['changefreq'], + 'changefreq_override' => 0, ); // The following values must always be checked because they are volatile.