| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: pathauto.admin.inc,v 1.10.2.7 2010/08/10 03:24:00 davereid Exp $ 3 4 /** 5 * @file 6 * Admin page callbacks for the Pathauto module. 7 * 8 * @ingroup pathauto 9 */ 10 11 /** 12 * Form builder; Configure the Pathauto system. 13 * 14 * @ingroup forms 15 * @see system_settings_form() 16 */ 17 function pathauto_admin_settings() { 18 _pathauto_include(); 19 20 // Generate the form - settings applying to all patterns first 21 $form['general'] = array( 22 '#type' => 'fieldset', 23 '#weight' => -20, 24 '#title' => t('General settings'), 25 '#collapsible' => TRUE, 26 '#collapsed' => TRUE, 27 ); 28 29 $form['general']['pathauto_verbose'] = array( 30 '#type' => 'checkbox', 31 '#title' => t('Verbose'), 32 '#default_value' => variable_get('pathauto_verbose', FALSE), 33 '#description' => t('Display alias changes (except during bulk updates).'), 34 ); 35 36 $form['general']['pathauto_separator'] = array( 37 '#type' => 'textfield', 38 '#title' => t('Separator'), 39 '#size' => 1, 40 '#maxlength' => 1, 41 '#default_value' => variable_get('pathauto_separator', '-'), 42 '#description' => t('Character used to separate words in titles. This will replace any spaces and punctuation characters. Using a space or + character can cause unexpected results.'), 43 ); 44 45 $form['general']['pathauto_case'] = array( 46 '#type' => 'radios', 47 '#title' => t('Character case'), 48 '#default_value' => variable_get('pathauto_case', 1), 49 '#options' => array(t('Leave case the same as source token values.'), t('Change to lower case')), 50 ); 51 52 $max_length = _pathauto_get_schema_alias_maxlength(); 53 54 $form['general']['pathauto_max_length'] = array( 55 '#type' => 'textfield', 56 '#title' => t('Maximum alias length'), 57 '#size' => 3, 58 '#maxlength' => 3, 59 '#default_value' => variable_get('pathauto_max_length', 100), 60 '#min_value' => 1, 61 '#max_value' => $max_length, 62 '#description' => t('Maximum length of aliases to generate. 100 is recommended. See <a href="@pathauto-help">Pathauto help</a> for details.', array('@pathauto-help' => url('admin/help/pathauto'))), 63 '#element_validate' => array('_pathauto_validate_numeric_element'), 64 ); 65 66 $form['general']['pathauto_max_component_length'] = array( 67 '#type' => 'textfield', 68 '#title' => t('Maximum component length'), 69 '#size' => 3, 70 '#maxlength' => 3, 71 '#default_value' => variable_get('pathauto_max_component_length', 100), 72 '#min_value' => 1, 73 '#max_value' => $max_length, 74 '#description' => t('Maximum text length of any component in the alias (e.g., [title]). 100 is recommended. See <a href="@pathauto-help">Pathauto help</a> for details.', array('@pathauto-help' => url('admin/help/pathauto'))), 75 '#element_validate' => array('_pathauto_validate_numeric_element'), 76 ); 77 78 $form['general']['pathauto_max_bulk_update'] = array( 79 '#type' => 'textfield', 80 '#title' => t('Maximum number of objects to alias in a bulk update'), 81 '#size' => 4, 82 '#maxlength' => 4, 83 '#default_value' => variable_get('pathauto_max_bulk_update', 50), 84 '#min_value' => 0, 85 '#description' => t('Maximum number of objects of a given type which should be aliased during a bulk update. The default is 50 and the recommended number depends on the speed of your server. If bulk updates "time out" or result in a "white screen" then reduce the number.'), 86 '#element_validate' => array('_pathauto_validate_numeric_element'), 87 ); 88 89 $actions = array( 90 t('Do nothing. Leave the old alias intact.'), 91 t('Create a new alias. Leave the existing alias functioning.'), 92 t('Create a new alias. Delete the old alias.')); 93 94 if (function_exists('path_redirect_save')) { 95 $actions[] = t('Create a new alias. Redirect from old alias.'); 96 } 97 elseif (variable_get('pathauto_update_action', 2) == 3) { 98 // the redirect action is selected, but path_redirect is not enabled 99 // let's set the variable back to the default 100 variable_set('pathauto_update_action', 2); 101 } 102 103 $form['general']['pathauto_update_action'] = array( 104 '#type' => 'radios', 105 '#title' => t('Update action'), 106 '#default_value' => variable_get('pathauto_update_action', 2), 107 '#options' => $actions, 108 '#description' => t('What should pathauto do when updating an existing content item which already has an alias?'), 109 ); 110 111 $form['general']['pathauto_transliterate'] = array( 112 '#type' => 'checkbox', 113 '#title' => t('Transliterate prior to creating alias'), 114 '#default_value' => variable_get('pathauto_transliterate', FALSE), 115 '#description' => t('When a pattern includes certain characters (such as those with accents) should Pathauto attempt to transliterate them into the ASCII-96 alphabet?'), 116 '#disabled' => !_pathauto_get_i18n_file(), 117 ); 118 $i18n_locations = _pathauto_get_i18n_possible_files(); 119 foreach ($i18n_locations as $key => $file) { 120 $i18n_locations[$key] = check_plain($file); 121 if (file_exists($file)) { 122 $i18n_locations[$key] .= ' - <span class="admin-enabled">' . t('File exists') . '</span>'; 123 } 124 else { 125 $i18n_locations[$key] .= ' - <span class="admin-disabled">' . t('Does not exist') . '</span>'; 126 } 127 } 128 $form['general']['pathauto_transliterate']['#description'] .= ' ' . t('Transliteration is determined by the i18n-ascii.txt file in the following possible locations, in order of precedence: !locations', array('!locations' => theme('item_list', $i18n_locations))); 129 if ($form['general']['pathauto_transliterate']['#disabled']) { 130 // Perhaps they've removed the file, set the transliterate option to FALSE 131 variable_set('pathauto_transliterate', FALSE); 132 } 133 134 $form['general']['pathauto_reduce_ascii'] = array( 135 '#type' => 'checkbox', 136 '#title' => t('Reduce strings to letters and numbers from ASCII-96'), 137 '#default_value' => variable_get('pathauto_reduce_ascii', FALSE), 138 '#description' => t('Filters the new alias to only letters and numbers found in the ASCII-96 set.'), 139 ); 140 141 // Default words to ignore 142 $ignore_words = array( 143 'a', 'an', 'as', 'at', 'before', 'but', 'by', 'for', 'from', 'is', 'in', 144 'into', 'like', 'of', 'off', 'on', 'onto', 'per', 'since', 'than', 'the', 145 'this', 'that', 'to', 'up', 'via', 'with', 146 ); 147 $form['general']['pathauto_ignore_words'] = array( 148 '#type' => 'textarea', 149 '#title' => t('Strings to Remove'), 150 '#default_value' => variable_get('pathauto_ignore_words', implode(',', $ignore_words)), 151 '#description' => t('Words to strip out of the URL alias, separated by commas. Do not place punctuation in here and do not use WYSIWYG editors on this field.'), 152 '#wysiwyg' => FALSE, 153 ); 154 155 $form['punctuation'] = array( 156 '#type' => 'fieldset', 157 '#weight' => -10, 158 '#title' => t('Punctuation settings'), '#collapsible' => TRUE, 159 '#collapsed' => TRUE, 160 ); 161 162 $punctuation = pathauto_punctuation_chars(); 163 foreach ($punctuation as $name => $details) { 164 $details['default'] = 0; 165 if ($details['value'] == variable_get('pathauto_separator', '-')) { 166 $details['default'] = 1; 167 } 168 $form['punctuation']['pathauto_punctuation_'. $name] = array( 169 '#type' => 'select', 170 '#title' => $details['name'], 171 '#default_value' => variable_get('pathauto_punctuation_'. $name, $details['default']), 172 '#options' => array( 173 '0' => t('Remove'), 174 '1' => t('Replace by separator'), 175 '2' => t('No action (do not replace)'), 176 ), 177 ); 178 } 179 180 // Call the hook on all modules - an array of 'settings' objects is returned 181 $all_settings = module_invoke_all('pathauto', 'settings'); 182 foreach ($all_settings as $settings) { 183 $module = $settings->module; 184 $patterndescr = $settings->patterndescr; 185 $patterndefault = $settings->patterndefault; 186 $groupheader = $settings->groupheader; 187 $supportsfeeds = isset($settings->supportsfeeds) ? $settings->supportsfeeds : NULL; 188 variable_set('pathauto_' . $module . '_supportsfeeds', $supportsfeeds); 189 190 $form[$module] = array( 191 '#type' => 'fieldset', 192 '#title' => $groupheader, 193 '#collapsible' => TRUE, 194 '#collapsed' => TRUE, 195 ); 196 197 // Prompt for the default pattern for this module 198 $variable = 'pathauto_' . $module . '_pattern'; 199 $form[$module][$variable] = array( 200 '#type' => 'textfield', 201 '#title' => $patterndescr, 202 '#default_value' => variable_get($variable, $patterndefault), 203 '#size' => 65, 204 '#maxlength' => 1280, 205 '#element_validate' => array('_pathauto_validate_pattern_element'), 206 '#after_build' => array('_pathauto_validate_pattern_element'), 207 '#token_types' => array($settings->token_type), 208 '#parents' => array($variable), 209 ); 210 211 // If the module supports a set of specialized patterns, set 212 // them up here 213 if (isset($settings->patternitems)) { 214 foreach ($settings->patternitems as $itemname => $itemlabel) { 215 $variable = 'pathauto_' . $module . '_' . $itemname . '_pattern'; 216 $form[$module][$variable] = array( 217 '#type' => 'textfield', 218 '#title' => $itemlabel, 219 '#default_value' => variable_get($variable, ''), 220 '#size' => 65, 221 '#maxlength' => 1280, 222 '#element_validate' => array('_pathauto_validate_pattern_element'), 223 '#after_build' => array('_pathauto_validate_pattern_element'), 224 '#token_types' => array($settings->token_type), 225 '#parents' => array($variable), 226 ); 227 } 228 } 229 230 // Display the user documentation of placeholders supported by 231 // this module, as a description on the last pattern 232 $form[$module]['token_help'] = array( 233 '#title' => t('Replacement patterns'), 234 '#type' => 'fieldset', 235 '#collapsible' => TRUE, 236 '#collapsed' => TRUE, 237 '#description' => t('Use -raw replacements for text to avoid problems with HTML entities.'), 238 ); 239 240 // Use the token tree if available. 241 $doc = theme('token_tree', array($settings->token_type), FALSE); 242 if (empty($doc)) { 243 $doc = "<dl>\n"; 244 foreach ($settings->placeholders as $name => $description) { 245 $doc .= '<dt>'. $name .'</dt>'; 246 $doc .= '<dd>'. $description .'</dd>'; 247 } 248 $doc .= "</dl>\n"; 249 } 250 $form[$module]['token_help']['help'] = array( 251 '#type' => 'markup', 252 '#value' => $doc, 253 ); 254 255 // If the module supports bulk updates, offer the update action here 256 if ($settings->bulkname) { 257 $variable = 'pathauto_' . $module . '_bulkupdate'; 258 if (variable_get($variable, FALSE)) { 259 variable_set($variable, FALSE); 260 $function = $module . '_pathauto_bulkupdate'; 261 call_user_func($function); 262 } 263 $form[$module][$variable] = array( 264 '#type' => 'checkbox', 265 '#title' => $settings->bulkname, 266 '#default_value' => FALSE, 267 '#description' => $settings->bulkdescr, 268 ); 269 } 270 271 // If the module supports feeds, offer to generate aliases for them 272 if ($supportsfeeds) { 273 $variable = 'pathauto_' . $module . '_applytofeeds'; 274 $current = variable_get($variable, $supportsfeeds); 275 // This checks for the old style from 2.0 and earlier. TODO: At some point we can drop that. 276 if (is_numeric($current)) { 277 $current = $supportsfeeds; 278 } 279 280 $form[$module][$variable] = array( 281 '#type' => 'textfield', 282 '#title' => t('Internal feed alias text (leave blank to disable)'), 283 '#size' => 65, 284 '#maxlength' => 1280, 285 '#default_value' => $current, 286 '#description' => t('The text to use for aliases for RSS feeds. Examples are "0/feed" (used throughout Drupal core) and "feed" (used by some contributed Drupal modules, like Views).'), 287 ); 288 } 289 } 290 291 if (isset($do_index_bulkupdate) && $do_index_bulkupdate) { 292 drupal_set_message(format_plural($indexcount, 293 'Bulk generation of index aliases completed, one alias generated.', 294 'Bulk generation of index aliases completed, @count aliases generated.')); 295 } 296 297 return system_settings_form($form); 298 } 299 300 /** 301 * Element validation callback for URL alias patterns. 302 * 303 * This function performs the following validations: 304 * - Checks if the pattern has at least one token. 305 * - Checks if any tokens with raw companions are being used and recommends 306 * use of the raw tokens. 307 */ 308 function _pathauto_validate_pattern_element(&$element, &$form_state) { 309 // Get the current value of the element (since this can be used during both 310 // form display and validation). 311 $value = isset($element['#value']) ? $element['#value'] : $element['#default_value']; 312 313 // Empty patterns need no further validation. 314 if (!drupal_strlen($value)) { 315 return $element; 316 } 317 318 // Check to see if the required token functions are available. 319 if (!function_exists('token_scan') || !function_exists('token_element_validate_token_context')) { 320 drupal_set_message(t('Please make sure you are using the latest version of the Token module.'), 'warning', FALSE); 321 return $element; 322 } 323 324 // Check for at least one token. 325 $tokens = token_scan($value); 326 if (empty($tokens)) { 327 form_error($element, t('The %name should contain at least one token to ensure unique URL aliases are created.', array('%name' => $element['#title']))); 328 } 329 else { 330 token_element_validate_token_context($element, $form_state); 331 } 332 333 // Find any non-raw tokens that do have a raw companion token and warn. 334 module_load_include('inc', 'pathauto'); 335 $not_raw_tokens = array(); 336 $raw_tokens = _pathauto_get_raw_tokens(); 337 foreach ($tokens as $token) { 338 if (substr($token, -4) === '-raw') { 339 // Skip raw tokens. 340 continue; 341 } 342 elseif (in_array($token . '-raw', $raw_tokens)) { 343 drupal_set_message(t('You are using the token [%token] which has a raw companion token [%raw_token]. For Pathauto patterns you should use the -raw version of tokens unless you really know what you are doing. See the <a href="@pathauto-help">Pathauto help</a> for more details.', array('%token' => $token, '%raw_token' => $token . '-raw', '@pathauto-help' => url('admin/help/pathauto'))), 'error', FALSE); 344 } 345 } 346 347 return $element; 348 } 349 350 /** 351 * Validate a form element that should have an numeric value. 352 */ 353 function _pathauto_validate_numeric_element($element, &$form_state) { 354 $value = $element['#value']; 355 356 if (!is_numeric($value)) { 357 form_error($element, t('The field %name is not a valid number.', array('%name' => $element['#title']))); 358 } 359 elseif (isset($element['#max_value']) && $value > $element['#max_value']) { 360 form_error($element, t('The field %name cannot be greater than @max.', array('%name' => $element['#title'], '@max' => $element['#max_value']))); 361 } 362 elseif (isset($element['#min_value']) && $value < $element['#min_value']) { 363 form_error($element, t('The field %name cannot be less than @min.', array('%name' => $element['#title'], '@min' => $element['#min_value']))); 364 } 365 } 366 367 /** 368 * Validate pathauto_admin_settings form submissions. 369 */ 370 function pathauto_admin_settings_validate($form, &$form_state) { 371 module_load_include('inc', 'pathauto'); 372 373 // Perform a basic check for HTML characters in the strings to remove field. 374 if (strip_tags($form_state['values']['pathauto_ignore_words']) != $form_state['values']['pathauto_ignore_words']) { 375 form_set_error('pathauto_ignore_words', t('The <em>Strings to remove</em> field must not contain HTML. Make sure to disable any WYSIWYG editors for this field.')); 376 } 377 378 // Validate that the separator is not set to be removed per http://drupal.org/node/184119 379 // This isn't really all that bad so warn, but still allow them to save the value. 380 $separator = $form_state['values']['pathauto_separator']; 381 $punctuation = pathauto_punctuation_chars(); 382 foreach ($punctuation as $name => $details) { 383 if ($details['value'] == $separator) { 384 $action = $form_state['values']['pathauto_punctuation_' . $name]; 385 if ($action == 0) { 386 drupal_set_message(t('You have configured the @name to be the separator and to be removed when encountered in strings. This can cause problems with your patterns and especially with the catpath and termpath patterns. You should probably set the action for @name to be "replace by separator"', array('@name' => $details['name'])), 'error'); 387 } 388 } 389 } 390 } 391 392 /** 393 * Menu callback; select certain alias types to delete. 394 */ 395 function pathauto_admin_delete() { 396 /* TODO: 397 1) all - DONE 398 2) all node aliases - DONE 399 4) all user aliases - DONE 400 5) all taxonomy aliases - DONE 401 6) by node type 402 7) by taxonomy vocabulary 403 8) no longer existing aliases (see http://drupal.org/node/128366 ) 404 9) where src like 'pattern' - DON'T DO 405 10) where dst like 'pattern' - DON'T DO 406 */ 407 408 $form['delete'] = array( 409 '#type' => 'fieldset', 410 '#title' => t('Choose aliases to delete'), 411 '#collapsible' => FALSE, 412 '#collapsed' => FALSE, 413 ); 414 415 // First we do the "all" case 416 $total_count = db_result(db_query('SELECT count(1) FROM {url_alias}')); 417 $form['delete']['all_aliases'] = array( 418 '#type' => 'checkbox', 419 '#title' => t('All aliases'), 420 '#default_value' => FALSE, 421 '#description' => t('Delete all aliases. Number of aliases which will be deleted: %count.', array('%count' => $total_count)), 422 ); 423 424 // Next, iterate over an array of objects/alias types which can be deleted and provide checkboxes 425 $objects = module_invoke_all('path_alias_types'); 426 foreach ($objects as $internal_name => $label) { 427 $count = db_result(db_query("SELECT count(1) FROM {url_alias} WHERE src LIKE '%s%%'", $internal_name)); 428 $form['delete'][$internal_name] = array( 429 '#type' => 'checkbox', 430 '#title' => $label, // This label is sent through t() in the hard coded function where it is defined 431 '#default_value' => FALSE, 432 '#description' => t('Delete aliases for all @label. Number of aliases which will be deleted: %count.', array('@label' => $label, '%count' => $count)), 433 ); 434 } 435 436 // Warn them and give a button that shows we mean business 437 $form['warning'] = array('#value' => '<p>' . t('<strong>Note:</strong> there is no confirmation. Be sure of your action before clicking the "Delete aliases now!" button.<br />You may want to make a backup of the database and/or the url_alias table prior to using this feature.') . '</p>'); 438 $form['buttons']['submit'] = array( 439 '#type' => 'submit', 440 '#value' => t('Delete aliases now!'), 441 ); 442 443 return $form; 444 } 445 446 /** 447 * Process pathauto_admin_delete form submissions. 448 */ 449 function pathauto_admin_delete_submit($form, &$form_state) { 450 foreach ($form_state['values'] as $key => $value) { 451 if ($value) { 452 if ($key === 'all_aliases') { 453 db_query('DELETE FROM {url_alias}'); 454 drupal_set_message(t('All of your path aliases have been deleted.')); 455 } 456 $objects = module_invoke_all('path_alias_types'); 457 if (array_key_exists($key, $objects)) { 458 db_query("DELETE FROM {url_alias} WHERE src LIKE '%s%%'", $key); 459 drupal_set_message(t('All of your %type path aliases have been deleted.', array('%type' => $objects[$key]))); 460 } 461 } 462 } 463 $form_state['redirect'] = 'admin/build/path/delete_bulk'; 464 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |