'fieldset', '#title' => t('Settings'), '#collapsible' => TRUE, '#collapsed' => FALSE, ); $form['xmlsitemap']['xmlsitemap_minimum_lifetime'] = array( '#type' => 'select', '#title' => t('Minimum sitemap lifetime'), '#options' => array(0 => t('No minimum')) + drupal_map_assoc(array(300, 900, 1800, 3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800), 'format_interval'), '#default_value' => xmlsitemap_var('minimum_lifetime') ); $form['xmlsitemap']['xmlsitemap_xsl'] = array( '#type' => 'checkbox', '#title' => t('Include a stylesheet in the sitemaps.'), '#default_value' => xmlsitemap_var('xsl'), '#description' => t('Using the stylesheet will make it easier for actual people to view your XML sitemap since it will not be raw XML output.') ); $form['xmlsitemap']['xmlsitemap_languages'] = array( '#type' => 'checkboxes', '#title' => t('Generate sitemaps for the following languages'), '#options' => module_exists('locale') ? locale_language_list() : array(language_default('language') => language_default('name')), '#default_value' => xmlsitemap_var('languages'), '#process' => array('expand_checkboxes', '_xmlsitemap_process_language_checkboxes'), '#description' => module_exists('i18n') ? t("If the XML sitemap internationalization module is enabled, the each language's sitemap will respect the content selection mode.", array('@i18n-settings' => url('admin/settings/language/i18n'))) : '', ); $form['advanced'] = array( '#type' => 'fieldset', '#title' => t('Advanced settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#weight' => 10, ); //$form['advanced']['xmlsitemap_gz'] = array( // '#type' => 'checkbox', // '#title' => t('Generate additional compressed sitemaps using gzip.'), // '#default_value' => xmlsitemap_var('gz'), // '#disabled' => !function_exists('gzencode'), //); $form['advanced']['xmlsitemap_chunk_size'] = array( '#type' => 'select', '#title' => t('Number of links in each sitemap page'), '#options' => array('auto' => t('Automatic (recommended)')) + drupal_map_assoc(array(100, 500, 1000, 2500, 5000, 10000, 25000, 50000)), '#default_value' => xmlsitemap_var('chunk_size'), // @todo This description is not clear. '#description' => t('If there are problems with rebuilding the sitemap, you may want to manually set this value. If you have more than 50,000 links, an index with multiple sitemap pages will be generated. There is a maximum of 1000 sitemap pages.'), ); $form['advanced']['xmlsitemap_batch_limit'] = array( '#type' => 'select', '#title' => t('Maximum number of sitemap links to process at once'), '#options' => drupal_map_assoc(array(5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000)), '#default_value' => xmlsitemap_var('batch_limit'), '#description' => t('If you have problems running cron or rebuilding the sitemap, you may want to lower this value.'), ); $form['advanced']['xmlsitemap_path'] = array( '#type' => 'textfield', '#title' => t('Sitemap cache directory'), '#default_value' => xmlsitemap_var('path'), '#size' => 30, '#maxlength' => 255, '#description' => t('Subdirectory in the directory %dir where the sitemap data will be stored. This folder must not be shared with any other Drupal site or install using XML sitemap.', array('%dir' => file_directory_path() .'/')), '#required' => TRUE, ); $form['advanced']['xmlsitemap_base_url'] = array( '#type' => 'textfield', '#title' => t('Base URL'), '#default_value' => xmlsitemap_var('base_url'), '#description' => t('This is the base URL for links generated in the sitemap.'), '#required' => TRUE, ); $form['frontpage'] = array( '#type' => 'fieldset', '#title' => t('Front page'), '#description' => t('The front page path can be changed at @url-frontpage.', array('@url-frontpage' => url('admin/settings/site-information'))), '#collapsible' => TRUE, '#collapsed' => TRUE, '#weight' => 20, ); $form['frontpage']['xmlsitemap_frontpage_priority'] = array( '#type' => 'select', '#title' => t('Priority'), '#options' => xmlsitemap_get_priority_options(), '#default_value' => xmlsitemap_var('frontpage_priority'), ); $form['frontpage']['xmlsitemap_frontpage_changefreq'] = array( '#type' => 'select', '#title' => t('Change frequency'), '#options' => xmlsitemap_get_changefreq_options(), '#default_value' => xmlsitemap_var('frontpage_changefreq'), ); $form['#validate'][] = 'xmlsitemap_settings_form_validate'; $form['#submit'][] = 'xmlsitemap_form_submit_flag_regenerate'; $form['#submit'][] = 'xmlsitemap_settings_form_submit'; $form['array_filter'] = array('#type' => 'value', '#value' => TRUE); $form = system_settings_form($form); $form['buttons']['#weight'] = 100; return $form; } /** * Show a link to each languages' sitemap and disable the default language * checkbox. */ function _xmlsitemap_process_language_checkboxes($element) { $sitemaps = xmlsitemap_get_sitemaps(TRUE); foreach (element_children($element) as $key) { if ($key == language_default('language')) { $element[$key]['#disabled'] = TRUE; $element[$key]['#default_value'] = TRUE; $element[$key]['#weight'] = -1; } if (isset($sitemaps[$key])) { $element[$key]['#description'] = $sitemaps[$key]; } } return $element; } /** * Create a list of items that can be included in the sitemap. * * @param $item_type * A translated string of the item type. * @param $items * An array of items with the following keys: * 'name': The translated name of the item. * 'link': The path to edit the item. * 'status': The item's sitemap status. * 'priority': The items default sitemap priority. * @param $form_item * The form item to add the list to. */ function xmlsitemap_settings_list($item_title, $items, &$form_item, $item_type = '') { $header = array( $item_title, t('Included'), t('Default priority'), ); $rows = array(); foreach ($items as $item) { $rows[] = array( l($item['name'], $item['link'], array('query' => drupal_get_destination())), $item['status'] ? t('Yes') : t('No'), $item['priority'] == 'default' ? t('Default') : t(number_format($item['priority'], 1)), ); } $form_item['list'] = array( '#value' => theme('table', $header, $rows), ); //if ($item_type) { // $count = db_result(db_query("SELECT COUNT(id) FROM {xmlsitemap} WHERE type = '%s' AND access = 1 AND status = 1", $item_type)); // $form_item['count'] = array( // '#type' => 'item', // '#value' => format_plural($count, 'There is @count @type link in the sitemap.', 'There are @count @type links in the sitemap', array('@type' => drupal_strtolower($item_title))), // ); //} } /** * Submit handler; Set the regenerate needed flag if variables have changed. * * This function needs to be called before system_settings_form_submit() or any * calls to variable_set(). */ function xmlsitemap_form_submit_flag_regenerate($form, $form_state) { foreach ($form_state['values'] as $variable => $value) { $stored_value = variable_get($variable, 'xmlsitemap_not_a_variable'); if (is_array($value) && isset($form_state['values']['array_filter'])) { $value = array_keys(array_filter($value)); } if ($stored_value != 'xmlsitemap_not_a_variable' && $stored_value != $value) { variable_set('xmlsitemap_regenerate_needed', TRUE); return; } } } /** * Form validator; Check the sitemap files directory. * * @see xmlsitemap_settings_form() */ function xmlsitemap_settings_form_validate($form, &$form_state) { // Check if the xmlsitemap files directory has changed. $path_new = file_create_path($form_state['values']['xmlsitemap_path']); $path_old = file_create_path(xmlsitemap_var('path')); if ($path_new != $path_old && file_check_directory($path_new, FILE_CREATE_DIRECTORY, 'xmlsitemap_path')) { // If creating the new directory was successful, remove the old directory. xmlsitemap_clear_cache(TRUE, $path_old); } // Check that the chunk size will not create more than 1000 chunks. $chunk_size = $form_state['values']['xmlsitemap_chunk_size']; if ($chunk_size != 'auto' && $chunk_size != 50000 && (xmlsitemap_get_link_count() / $chunk_size) > 1000) { form_set_error('xmlsitemap_chunk_size', t('The sitemap page link count of @size will create more than 1,000 sitemap pages. Please increase the link count.', array('@size' => $chunk_size))); } $base_url = &$form_state['values']['xmlsitemap_base_url']; $base_url = rtrim($base_url, '/'); if ($base_url != '' && !valid_url($base_url, TRUE)) { form_set_error('xmlsitemap_base_url', t('Invalid base URL.')); } } /** * Submit handler; * * @see xmlsitemap_settings_form() */ function xmlsitemap_settings_form_submit($form, $form_state) { // Save any changes to the frontpage link. xmlsitemap_save_link(array('type' => 'frontpage', 'id' => 0, 'loc' => '')); } /** * Menu callback; Confirm rebuilding of the sitemap. * * @see xmlsitemap_rebuild_confirm_submit() */ function xmlsitemap_rebuild_confirm() { if (!$_POST && !xmlsitemap_var('rebuild_needed')) { if (!xmlsitemap_var('regenerate_needed')) { drupal_set_message(t('Your sitemap is up to date and does not need to be rebuilt.'), 'warning'); } else { drupal_set_message(t('A rebuild is not necessary. If you are just wanting to re-create the sitemap files, you can run cron manually.', array('@link-cron' => url('admin/reports/status/run-cron'))), 'warning'); } } $form['warning'] = array( '#type' => 'markup', '#value' => t('If you have just installed the module, this can be helpful to import all your site\'s content into the sitemap. Otherwise, this should be considered a last-resort method. This will result in the loss of all your custom inclusion/exclusion and priorty values.'), ); // Show only the modules that implement the 6.x-2.x hooks. $modules = module_implements('xmlsitemap_links_clear', TRUE); $form['modules'] = array( '#type' => 'select', '#title' => t("Select which modules' links you would like to rebuild"), '#description' => t('If no modules are selected, the sitemap files will just be regenerated.'), '#multiple' => TRUE, '#options' => drupal_map_assoc($modules), '#default_value' => xmlsitemap_var('rebuild_needed') ? $modules : array(), ); return confirm_form( $form, t('Are you sure you want to rebuild the sitemap?'), 'admin/settings/xmlsitemap', t("This action rebuilds your site's XML sitemap, and may be a lengthy process. This will also re-create the XML sitemap files."), t('Rebuild sitemap'), t('Cancel') ); } /** * Submit handler; Starts the sitemap rebuild batch. * * @see xmlsitemap_rebuild_confirm() * @see xmlsitemap_rebuild_batch() */ function xmlsitemap_rebuild_confirm_submit($form, &$form_state) { // Set the rebuild flag incase something fails during the rebuild. variable_set('xmlsitemap_rebuild_needed', TRUE); module_load_include('inc', 'xmlsitemap'); batch_set(xmlsitemap_rebuild_batch($form_state)); $form_state['redirect'] = 'admin/settings/xmlsitemap'; } /** * Add the link type XML sitemap options to the link type's form. */ function xmlsitemap_add_form_type_options(&$form, $module, $options) { $form['xmlsitemap'] = array( '#type' => 'fieldset', '#title' => t('XML sitemap'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#access' => user_access('administer xmlsitemap'), ); $form['xmlsitemap']['xmlsitemap_' . $module . '_status'] = array( '#type' => 'checkbox', '#title' => t('Include in the sitemap'), '#default_value' => $options['status'], ); $form['xmlsitemap']['xmlsitemap_' . $module . '_priority'] = array( '#type' => 'select', '#title' => t('Default priority'), '#options' => xmlsitemap_get_priority_options(), '#default_value' => $options['priority'], ); } /** * Add a link's XML sitemap options to the link's form. */ function xmlsitemap_add_form_link_options(&$form, $link) { $form['xmlsitemap'] = array( '#type' => 'fieldset', '#tree' => TRUE, '#title' => t('XML sitemap'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#access' => user_access('administer xmlsitemap'), ); // Show a warning if the link is not accessible and will not be included in // the sitemap. if (!$link['access']) { $form['xmlsitemap']['warning'] = array( '#type' => 'markup', '#prefix' => '
', '#suffix' => '
', '#value' => ('This item is not currently visible to anonymous users, so it will not be included in the sitemap.'), ); } // Status field (inclusion/exclusion) $form['xmlsitemap']['status'] = array( '#type' => 'select', '#title' => t('Inclusion'), '#options' => xmlsitemap_get_status_options($link['status_default']), '#default_value' => $link['status_override'] ? $link['status'] : 'default', ); $form['xmlsitemap']['status_default'] = array( '#type' => 'value', '#value' => $link['status_default'], ); $form['xmlsitemap']['status_override'] = array( '#type' => 'value', '#value' => $link['status_override'], ); // Priority field $form['xmlsitemap']['priority'] = array( '#type' => 'select', '#title' => t('Priority'), '#options' => xmlsitemap_get_priority_options($link['priority_default']), '#default_value' => $link['priority_override'] ? number_format($link['priority'], 1) : 'default', '#description' => t('The priority of this URL relative to other URLs on your site.'), ); $form['xmlsitemap']['priority_default'] = array( '#type' => 'value', '#value' => $link['priority_default'], ); $form['xmlsitemap']['priority_override'] = array( '#type' => 'value', '#value' => $link['priority_override'], ); // Other persistent fields. //$form['xmlsitemap']['lastmod'] = array( // '#type' => 'value', // '#value' => $node->xmlsitemap['lastmod'], //); //$form['xmlsitemap']['changefreq'] = array( // '#type' => 'value', // '#value' => $node->xmlsitemap['changefreq'], //); //$form['xmlsitemap']['changecount'] = array( // '#type' => 'value', // '#value' => $node->xmlsitemap['changecount'], //); // Add the submit handler to adjust the default values if selected. if (!in_array('xmlsitemap_process_form_link_options', $form['#submit'])) { array_unshift($form['#submit'], 'xmlsitemap_process_form_link_options'); } } /** * Get a list of priority options. * * @param $default * Include a 'default' option. * @return * An array of options. * * @see _xmlsitemap_translation_strings() */ function xmlsitemap_get_priority_options($default = NULL) { $options = array(); if (isset($default)) { if ($default === TRUE) { $options['default'] = t('Default'); } elseif (is_numeric($default)) { $options['default'] = t('Default (@value)', array('@value' => number_format($default, 1))); } } foreach (range(1, 0, 0.1) as $option) { $option = number_format($option, 1); // Sorry, we pass a variable through t() since we have provided all the // possible values in _xmlsitemap_translation_strings(). $options[$option] = t($option); } // Add some helpful indicators for the highest, middle, and lowest values. $options['1.0'] .= ' ' . t('(highest)'); $options['0.5'] .= ' ' . t('(normal)'); $options['0.0'] .= ' ' . t('(lowest)'); return $options; } /** * Get a list of priority options. * * @param $default * Include a 'default' option. * @return * An array of options. * * @see _xmlsitemap_translation_strings() */ function xmlsitemap_get_status_options($default = NULL) { $options = array(); if (isset($default)) { //if ($default === TRUE) { // $options['default'] = t('Default'); //} //else { $options['default'] = t('Default (@value)', array('@value' => $default ? t('included') : t('excluded'))); //} } $options += array( 1 => t('Included'), 0 => t('Excluded'), ); return $options; }