web/drupal/modules/xmlsitemap/xmlsitemap.admin.inc
branchdrupal
changeset 74 0ff3ba646492
equal deleted inserted replaced
73:fcf75e232c5b 74:0ff3ba646492
       
     1 <?php
       
     2 // $Id: xmlsitemap.admin.inc,v 1.1.4.2 2009/06/22 15:06:06 earnie Exp $
       
     3 
       
     4 
       
     5 /**
       
     6  * @file
       
     7  * XML sitemap settings UI.
       
     8  */
       
     9 
       
    10 /**
       
    11  * @addtogroup xmlsitemap
       
    12  * @{
       
    13  */
       
    14 
       
    15 /*****************************************************************************
       
    16  * Menu callbacks / form builders, submit/validate functions.
       
    17  ****************************************************************************/
       
    18 
       
    19 /**
       
    20  * Form builder; return the sitemap settings form.
       
    21  */
       
    22 function xmlsitemap_settings() {
       
    23   $form['general'] = array(
       
    24     '#type' => 'fieldset',
       
    25     '#title' => t('Settings'),
       
    26     '#collapsible' => TRUE,
       
    27     '#weight' => -1,
       
    28   );
       
    29   $form['general']['xmlsitemap_all_links_to_default_language'] = array(
       
    30     '#type' => 'checkbox',
       
    31     '#title' => t('Add all the links to the default language sitemap'),
       
    32     '#default_value' => variable_get('xmlsitemap_all_links_to_default_language', 0),
       
    33     '#description' => t('This option will be used only when the language negotiation uses a path prefix mechanism.'),
       
    34   );
       
    35   $form['general']['xmlsitemap_cron_limit'] = array(
       
    36     '#type' => 'select',
       
    37     '#title' => t('Cron limit'),
       
    38     '#description' => t('The number of links that are updated in each pass of a <a href="@cron">cron maintenance task</a>.', array('@cron' => url('admin/reports/status'))),
       
    39     '#default_value' => variable_get('xmlsitemap_cron_limit', 100),
       
    40     '#options' => xmlsitemap_cron_options(),
       
    41   );
       
    42   $form['general']['xmlsitemap_cache_directory'] = array(
       
    43     '#type' => 'textfield',
       
    44     '#title' => t('Cache directory'),
       
    45     '#default_value' => variable_get('xmlsitemap_cache_directory', file_directory_path() .'/xmlsitemap'),
       
    46     '#size' => 60,
       
    47     '#maxlength' => 150,
       
    48     '#description' => t('The directory where the cache files are created; change it only if you are having problems with the default setting.'),
       
    49   );
       
    50   $form['general']['xmlsitemap_use_stylesheet'] = array(
       
    51     '#type' => 'checkbox',
       
    52     '#title' => t('Use stylesheet'),
       
    53     '#default_value' => variable_get('xmlsitemap_use_stylesheet', FALSE),
       
    54     '#description' => t('Specify a xml stylesheet for the sitemap?'),
       
    55   );
       
    56   $form['frontpage'] = array(
       
    57     '#type' => 'fieldset',
       
    58     '#title' => t('Front page'),
       
    59     '#collapsible' => TRUE,
       
    60   );
       
    61   $form['frontpage']['xmlsitemap_front_page_changefreq'] = array(
       
    62     '#type' => 'select',
       
    63     '#title' => t('Front page change frequency'),
       
    64     '#description' => t('The change frequency associated with the front page.'),
       
    65     '#default_value' => variable_get('xmlsitemap_front_page_changefreq', 3600),
       
    66     '#options' => array(
       
    67       '3600' => t('Hourly'),
       
    68       '86400' => t('Daily'),
       
    69       '604800' => t('Weekly'),
       
    70       '2419200' => t('Monthly'),
       
    71       '29030400' => t('Yearly'),
       
    72     ),
       
    73   );
       
    74   $form['frontpage']['xmlsitemap_front_page_priority'] = array(
       
    75     '#type' => 'select',
       
    76     '#title' => t('Front page priority'),
       
    77     '#description' => t('The absolute priority for the front page.'),
       
    78     '#default_value' => variable_get('xmlsitemap_front_page_priority', 1),
       
    79     '#options' => xmlsitemap_priority_options(),
       
    80   );
       
    81   $form = system_settings_form($form);
       
    82   $form['buttons']['#weight'] = 10;
       
    83   $form['#submit'][] = 'xmlsitemap_settings_submit';
       
    84   $form['#validate'][] = 'xmlsitemap_settings_validate';
       
    85   return $form;
       
    86 }
       
    87 
       
    88 /**
       
    89  * Validate the sitemap settings form.
       
    90  */
       
    91 function xmlsitemap_settings_validate($form, &$form_state) {
       
    92   $directory = $form_state['values']['xmlsitemap_cache_directory'];
       
    93   file_check_directory($directory, FILE_CREATE_DIRECTORY, 'xmlsitemap_cache_directory');
       
    94   $form_state['values']['xmlsitemap_cache_directory'] = $directory;
       
    95 }
       
    96 
       
    97 /**
       
    98  * Submit the settings form.
       
    99  */
       
   100 function xmlsitemap_settings_submit($form, &$form_state) {
       
   101   xmlsitemap_flag_sitemap();
       
   102 }
       
   103 
       
   104 /**
       
   105  * Form builder; return the tools form.
       
   106  */
       
   107 function xmlsitemap_tools() {
       
   108   $form['options'] = array(
       
   109     '#type' => 'fieldset',
       
   110     '#title' => t('Operations'),
       
   111     '#collapsible' => FALSE,
       
   112     '#collapsed' => FALSE,
       
   113     '#prefix' => '<div class="container-inline">',
       
   114     '#suffix' => '</div>',
       
   115   );
       
   116   $options = array();
       
   117   foreach (module_invoke_all('xmlsitemap_operations') as $operation => $info) {
       
   118     $options[$operation] = $info['label'];
       
   119   }
       
   120   reset($options);
       
   121   $form['options']['operation'] = array(
       
   122     '#type' => 'select',
       
   123     '#options' => $options,
       
   124     '#default_value' => key($options),
       
   125   );
       
   126   $form['options']['submit'] = array(
       
   127     '#type' => 'submit',
       
   128     '#value' => t('Apply'),
       
   129     '#submit' => array('xmlsitemap_tools_submit'),
       
   130   );
       
   131   return $form;
       
   132 }
       
   133 
       
   134 /**
       
   135  * Submit the tools form.
       
   136  */
       
   137 function xmlsitemap_tools_submit($form, &$form_state) {
       
   138   $operations = module_invoke_all('xmlsitemap_operations');
       
   139   $operation  = $operations[$form_state['values']['operation']];
       
   140   $function   = $operation['callback'];
       
   141   if (isset($operation['callback arguments'])) {
       
   142     call_user_func_array($function, $operation['callback arguments']);
       
   143   }
       
   144   else {
       
   145     call_user_func($function, NULL);
       
   146   }
       
   147   $form_state['redirect'] = 'admin/settings/xmlsitemap/tools';
       
   148 }
       
   149 
       
   150 /**
       
   151  * @} End of "addtogroup xmlsitemap".
       
   152  */
       
   153