| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @file 5 * Hook implementations for node module integration. 6 * 7 * @ingroup pathauto 8 */ 9 10 /** 11 * Implements hook_pathauto(). 12 */ 13 function node_pathauto($op) { 14 switch ($op) { 15 case 'settings': 16 $settings = array(); 17 $settings['module'] = 'node'; 18 $settings['token_type'] = 'node'; 19 $settings['groupheader'] = t('Node paths'); 20 $settings['patterndescr'] = t('Default path pattern (applies to all node types with blank patterns below)'); 21 $settings['patterndefault'] = 'content/[title-raw]'; 22 $settings['bulkname'] = t('Bulk generate aliases for nodes that are not aliased'); 23 $settings['bulkdescr'] = t('Generate aliases for all existing nodes which do not already have aliases.'); 24 25 $patterns = token_get_list('node'); 26 foreach ($patterns as $type => $pattern_set) { 27 if ($type != 'global') { 28 foreach ($pattern_set as $pattern => $description) { 29 $settings['placeholders']['['. $pattern .']'] = $description; 30 } 31 } 32 } 33 $settings['supportsfeeds'] = 'feed'; 34 35 if (module_exists('locale')) { 36 $languages = array('' => t('Language neutral')) + locale_language_list('name'); 37 } 38 else { 39 $languages = array(); 40 } 41 foreach (node_get_types('names') as $node_type => $node_name) { 42 if (variable_get('language_content_type_'. $node_type, 0) && count($languages)) { 43 $settings['patternitems'][$node_type] = t('Default path pattern for @node_type (applies to all @node_type node types with blank patterns below)', array('@node_type' => $node_name)); 44 foreach ($languages as $lang_code => $lang_name) { 45 if (!empty($lang_code)) { 46 $settings['patternitems'][$node_type .'_'. $lang_code] = t('Pattern for all @node_type paths in @language', array('@node_type' => $node_name, '@language' => $lang_name)); 47 } 48 else { 49 $settings['patternitems'][$node_type .'_'. $lang_code] = t('Pattern for all language neutral @node_type paths', array('@node_type' => $node_name)); 50 } 51 } 52 } 53 else { 54 $settings['patternitems'][$node_type] = t('Pattern for all @node_type paths', array('@node_type' => $node_name)); 55 } 56 } 57 return (object) $settings; 58 default: 59 break; 60 } 61 } 62 63 /** 64 * Generate aliases for all nodes without aliases. 65 */ 66 function node_pathauto_bulkupdate() { 67 // From all node types, only attempt to update those with patterns 68 $pattern_types = array(); 69 70 // If there's a default pattern we assume all types might be updated. 71 if (trim(variable_get('pathauto_node_pattern', ''))) { 72 $pattern_types = array_keys(node_get_types('names')); 73 } 74 else { 75 // Check first for a node specific pattern... 76 $languages = array(); 77 if (module_exists('locale')) { 78 $languages = array('' => t('Language neutral')) + locale_language_list('name'); 79 } 80 foreach (array_keys(node_get_types('names')) as $type) { 81 if (trim(variable_get('pathauto_node_'. $type .'_pattern', ''))) { 82 $pattern_types[$type] = $type; 83 continue; 84 } 85 // ...then for a node-language pattern. 86 if (variable_get('language_content_type_'. $type, 0) && $languages) { 87 foreach ($languages as $lang_code => $lang_name) { 88 if (trim(variable_get('pathauto_node_'. $type .'_'. $lang_code .'_pattern', ''))) { 89 $pattern_types[$type] = $type; 90 continue 2; 91 } 92 } 93 } 94 } 95 } 96 97 $count = 0; 98 if (count($pattern_types)) { 99 $concat = _pathauto_sql_concat("'node/'", 'n.nid'); 100 $sql = "SELECT n.nid FROM {node} n LEFT JOIN {url_alias} ua ON $concat = ua.src WHERE ua.src IS NULL AND n.type IN (". db_placeholders($pattern_types, 'varchar') .')'; 101 $query = db_query_range($sql, $pattern_types, 0, variable_get('pathauto_max_bulk_update', 50)); 102 103 $placeholders = array(); 104 while ($nid = db_result($query)) { 105 $node = node_load($nid, NULL, TRUE); 106 $placeholders = pathauto_get_placeholders('node', $node); 107 $source = "node/$node->nid"; 108 if (pathauto_create_alias('node', 'bulkupdate', $placeholders, $source, $node->nid, $node->type, $node->language)) { 109 $count++; 110 } 111 } 112 } 113 114 drupal_set_message(format_plural($count, 115 'Bulk generation of nodes completed, one alias generated.', 116 'Bulk generation of nodes completed, @count aliases generated.')); 117 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |