Index: xmlsitemap.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- xmlsitemap.js (date 1464190546000) +++ xmlsitemap.js (revision ) @@ -14,6 +14,9 @@ var priority = $('#edit-xmlsitemap-priority option:selected').text(); vals.push(Drupal.t('Priority: @value', { '@value': priority })); + var changefreq = $('#edit-xmlsitemap-changefreq option:selected').text(); + vals.push(Drupal.t('Change frequency: @value', { '@value': changefreq })); + return vals.join('
'); }); } Index: xmlsitemap_taxonomy/xmlsitemap_taxonomy.module IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- xmlsitemap_taxonomy/xmlsitemap_taxonomy.module (date 1464190546000) +++ xmlsitemap_taxonomy/xmlsitemap_taxonomy.module (revision ) @@ -169,6 +169,9 @@ '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. Index: xmlsitemap_user/xmlsitemap_user.module IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- xmlsitemap_user/xmlsitemap_user.module (date 1464190546000) +++ xmlsitemap_user/xmlsitemap_user.module (revision ) @@ -144,6 +144,9 @@ '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. Index: xmlsitemap.install IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- xmlsitemap.install (date 1464190546000) +++ xmlsitemap.install (revision ) @@ -231,6 +231,13 @@ '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', @@ -567,4 +574,12 @@ xmlsitemap_sitemap_save($sitemap); } } +} + +/** + * Add {xmlsitemap}.changefreq_override column. + */ +function xmlsitemap_update_7205() { + $schema = xmlsitemap_schema(); + db_add_field('xmlsitemap', 'changefreq_override', $schema['xmlsitemap']['fields']['changefreq_override']); } Index: xmlsitemap.generate.inc IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- xmlsitemap.generate.inc (date 1464190546000) +++ xmlsitemap.generate.inc (revision ) @@ -169,7 +169,7 @@ $link_count = 0; $query = db_select('xmlsitemap', 'x'); - $query->fields('x', array('id', 'type', 'subtype', 'loc', 'lastmod', 'changefreq', 'changecount', 'priority', 'language', 'access', 'status')); + $query->fields('x', array('id', 'type', 'subtype', 'loc', 'lastmod', 'changefreq', 'changefreq_override', 'changecount', 'priority', 'language', 'access', 'status')); $query->condition('x.access', 1); $query->condition('x.status', 1); $query->orderBy('x.language', 'DESC'); @@ -217,11 +217,13 @@ // 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. + if (empty($link['changefreq_override'])) { - $link['changefreq'] = (abs(REQUEST_TIME - $link['lastmod']) + $link['changefreq']) / 2; - } + $link['changefreq'] = (abs(REQUEST_TIME - $link['lastmod']) + $link['changefreq']) / 2; + } - if (!empty($output_elements['changefreq']) && $link['changefreq']) { - $element['changefreq'] = xmlsitemap_get_changefreq($link['changefreq']); } + if (!empty($output_elements['changefreq'])) { + $element['changefreq'] = xmlsitemap_get_changefreq($link['changefreq'] ?: XMLSITEMAP_FREQUENCY_DEFAULT); + } 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 @@ -545,6 +547,7 @@ if ($save_custom) { $query->condition('status_override', 0); $query->condition('priority_override', 0); + $query->condition('changefreq_override', 0); } return $query->execute(); Index: xmlsitemap_menu/xmlsitemap_menu.module IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- xmlsitemap_menu/xmlsitemap_menu.module (date 1464190546000) +++ xmlsitemap_menu/xmlsitemap_menu.module (revision ) @@ -254,6 +254,9 @@ '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. Index: xmlsitemap_user/xmlsitemap_user.test IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- xmlsitemap_user/xmlsitemap_user.test (date 1464190546000) +++ xmlsitemap_user/xmlsitemap_user.test (revision ) @@ -22,7 +22,7 @@ parent::setUp($modules); // Save the user settings before creating the users. - xmlsitemap_link_bundle_settings_save('user', 'user', array('status' => 1, 'priority' => 0.5)); + xmlsitemap_link_bundle_settings_save('user', 'user', array('status' => 1, 'priority' => 0.5, 'changefreq' => 3600)); // Create the users $this->admin_user = $this->drupalCreateUser(array('administer users', 'administer permissions', 'administer xmlsitemap')); Index: xmlsitemap.admin.inc IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- xmlsitemap.admin.inc (date 1464190546000) +++ xmlsitemap.admin.inc (revision ) @@ -499,6 +499,7 @@ $priorities = xmlsitemap_get_priority_options(NULL, FALSE); $statuses = xmlsitemap_get_status_options(NULL); $destination = drupal_get_destination(); + $changefreqs = xmlsitemap_get_changefreq_options(); $rows = array(); $totals = array('total' => 0, 'indexed' => 0, 'visible' => 0); @@ -520,6 +521,7 @@ } $row[] = $statuses[$bundle_info['xmlsitemap']['status'] ? 1 : 0]; $row[] = $priorities[number_format($bundle_info['xmlsitemap']['priority'], 1)]; + $row[] = $changefreqs[$bundle_info['xmlsitemap']['changefreq']]; $row[] = $status['total']; $row[] = $status['indexed']; $row[] = $status['visible']; @@ -531,6 +533,7 @@ isset($entity_info['bundle label']) ? $entity_info['bundle label'] : '', t('Inclusion'), t('Priority'), + t('Change frequency'), t('Available'), t('Indexed'), t('Visible'), @@ -538,7 +541,7 @@ $rows[] = array( array( 'data' => t('Totals'), - 'colspan' => 3, + 'colspan' => 4, 'header' => TRUE, ), array( @@ -629,6 +632,17 @@ ), ), ); + $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 +713,9 @@ '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 +723,7 @@ '#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 +802,35 @@ '#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.'), + '#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', @@ -872,6 +918,37 @@ } $options += $statuses; + + return $options; +} + + +/** + * Get a list of change frequency options. + * + * @param $default + * Include a 'default' option. + * @return + * An array of options. + * + * @see xmlsitemap_get_changefreq_values(). + * The values are translated here. + */ +function xmlsitemap_get_changefreq_options($default = NULL) { + $options = array(); + + $changefreqs = xmlsitemap_get_changefreq_values(); + foreach ($changefreqs as $key => $label) { + $changefreqs[$key] = t(drupal_ucfirst($label)); + } + + 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; } Index: xmlsitemap_node/xmlsitemap_node.module IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- xmlsitemap_node/xmlsitemap_node.module (date 1464190546000) +++ xmlsitemap_node/xmlsitemap_node.module (revision ) @@ -112,6 +112,24 @@ } /** + * Implements hook_xmlsitemap_element_alter(). + */ +function xmlsitemap_node_xmlsitemap_element_alter(array &$element, array $link, $sitemap) { + if ($link['type'] == 'node') { + if ($link['changefreq_override']) { + $element['changefreq'] = xmlsitemap_get_changefreq($link['changefreq']); + } + else { + module_load_include('inc', 'xmlsitemap', 'xmlsitemap.admin'); + $settings = xmlsitemap_link_bundle_load('node', $link['subtype']); + $changefreqs = xmlsitemap_get_changefreq_options(); + + $element['changefreq'] = drupal_strtolower($changefreqs[$settings['changefreq']]); + } + } +} + +/** * Implements hook_form_FORM_ID_alter(). * * @see node_type_form() @@ -188,12 +206,20 @@ '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); + 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; + $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'); Index: xmlsitemap.module IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- xmlsitemap.module (date 1464190546000) +++ xmlsitemap.module (revision ) @@ -25,6 +25,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 @@ 'priority' => XMLSITEMAP_PRIORITY_DEFAULT, 'priority_override' => 0, 'changefreq' => 0, + 'changefreq_override' => 0, 'changecount' => 0, 'language' => LANGUAGE_NONE, ); @@ -1036,7 +1038,10 @@ 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); cache_clear_all('xmlsitemap:link_info:', 'cache', TRUE); @@ -1085,6 +1090,7 @@ $info += array( 'status' => XMLSITEMAP_STATUS_DEFAULT, 'priority' => XMLSITEMAP_PRIORITY_DEFAULT, + 'changefreq' => XMLSITEMAP_FREQUENCY_DEFAULT, ); return $info; } @@ -1164,7 +1170,7 @@ return FALSE; } - foreach (xmlsitemap_get_changefreq_options() as $value => $frequency) { + foreach (xmlsitemap_get_changefreq_values() as $value => $frequency) { if ($interval <= $value) { return $frequency; } @@ -1337,7 +1343,7 @@ 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') { @@ -1381,10 +1387,12 @@ } /** - * @todo Document this function. - * @todo Make these translatable + * Get a list of change frequency values. + * + * @return + * An array of options. */ -function xmlsitemap_get_changefreq_options() { +function xmlsitemap_get_changefreq_values() { return array( XMLSITEMAP_FREQUENCY_ALWAYS => 'always', XMLSITEMAP_FREQUENCY_HOURLY => 'hourly', Index: xmlsitemap_node/xmlsitemap_node.test IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- xmlsitemap_node/xmlsitemap_node.test (date 1464190546000) +++ xmlsitemap_node/xmlsitemap_node.test (revision ) @@ -24,7 +24,7 @@ $this->admin_user = $this->drupalCreateUser(array('administer nodes', 'bypass node access', 'administer content types', 'administer xmlsitemap')); $this->normal_user = $this->drupalCreateUser(array('create page content', 'edit any page content', 'access content', 'view own unpublished content')); - xmlsitemap_link_bundle_settings_save('node', 'page', array('status' => 1, 'priority' => 0.5)); + xmlsitemap_link_bundle_settings_save('node', 'page', array('status' => 1, 'priority' => 0.5, 'changefreq' => 3600)); } function testNodeSettings() {