[ Index ] |
|
Code source de Drupal 5.3 |
1 <?php 2 // $Id: legacy.module,v 1.15 2006/11/21 20:14:18 dries Exp $ 3 4 /** 5 * @file 6 * Provides legacy handlers for upgrades from older Drupal installations. 7 */ 8 9 /** 10 * Implementation of hook_help(). 11 */ 12 function legacy_help($section) { 13 switch ($section) { 14 case 'admin/help#legacy': 15 $output = '<p>'. t('The legacy module provides legacy handlers for upgrades from older installations. These handlers help automatically redirect references to pages from old installations and prevent <em>page not found</em> errors for your site.') .'</p>'; 16 $output .= '<p>'. t('The legacy module handles legacy style taxonomy page, taxonomy feed, and blog feed paths. It also handles URL upgrades from Drupal 4.1. It rewrites old-style URLs to new-style URLs (clean URLs). ') .'</p>'; 17 $output .= t('<p>Example Mappings:</p> 18 <ul> 19 <li><em>taxonomy/page/or/52,97</em> to <em>taxonomy/term/52+97</em>.</li> 20 <li><em>taxonomy/feed/or/52,97</em> to <em>taxonomy/term/52+97/0/feed</em>.</li> 21 <li><em>blog/feed/52</em> to <em>blog/52/feed</em>.</li> 22 <li><em>node/view/52</em> to <em>node/52</em>.</li> 23 <li><em>book/view/52</em> to <em>node/52</em>.</li> 24 <li><em>user/view/52</em> to <em>user/52</em>.</li> 25 </ul> 26 '); 27 $output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="@legacy">Legacy page</a>.', array('@legacy' => 'http://drupal.org/handbook/modules/legacy/')) .'</p>'; 28 return $output; 29 } 30 } 31 32 /** 33 * Implementation of hook_menu(). 34 * 35 * Registers menu paths used in earlier Drupal versions. 36 */ 37 function legacy_menu($may_cache) { 38 $items = array(); 39 40 if ($may_cache) { 41 // Map "taxonomy/page/or/52,97" to "taxonomy/term/52+97". 42 $items[] = array('path' => 'taxonomy/page', 'title' => t('Taxonomy'), 43 'callback' => 'legacy_taxonomy_page', 44 'access' => TRUE, 'type' => MENU_CALLBACK); 45 46 // Map "taxonomy/feed/or/52,97" to "taxonomy/term/52+97/0/feed". 47 $items[] = array('path' => 'taxonomy/feed', 'title' => t('Taxonomy'), 48 'callback' => 'legacy_taxonomy_feed', 49 'access' => TRUE, 'type' => MENU_CALLBACK); 50 51 // Map "blog/feed/52" to "blog/52/feed". 52 $items[] = array('path' => 'blog/feed', 'title' => t('Blog'), 53 'callback' => 'legacy_blog_feed', 54 'access' => TRUE, 'type' => MENU_CALLBACK); 55 } 56 else { 57 // Map "node/view/52" to "node/52". 58 $items[] = array('path' => 'node/view', 'title' => t('View'), 59 'callback' => 'drupal_goto', 60 'callback arguments' => array('node/'. arg(2), NULL, NULL), 61 'access' => TRUE, 'type' => MENU_CALLBACK); 62 63 // Map "book/view/52" to "node/52". 64 $items[] = array('path' => 'book/view', 'title' => t('View'), 65 'callback' => 'drupal_goto', 66 'callback arguments' => array('node/'. arg(2), NULL, NULL), 67 'access' => TRUE, 'type' => MENU_CALLBACK); 68 69 // Map "user/view/52" to "user/52". 70 $items[] = array('path' => 'user/view', 'title' => t('View'), 71 'callback' => 'drupal_goto', 72 'callback arguments' => array('user/'. arg(2), NULL, NULL), 73 'access' => TRUE, 'type' => MENU_CALLBACK); 74 } 75 76 return $items; 77 } 78 79 /** 80 * Menu callback; redirects users to new taxonomy page paths. 81 */ 82 function legacy_taxonomy_page($operation = 'or', $str_tids = '') { 83 if ($operation == 'or') { 84 $str_tids = str_replace(',', '+', $str_tids); 85 } 86 drupal_goto('taxonomy/term/'. $str_tids); 87 } 88 89 /** 90 * Menu callback; redirects users to new taxonomy feed paths. 91 */ 92 function legacy_taxonomy_feed($operation = 'or', $str_tids = '') { 93 if ($operation == 'or') { 94 $str_tids = str_replace(',', '+', $str_tids); 95 } 96 drupal_goto('taxonomy/term/'. $str_tids .'/0/feed'); 97 } 98 99 /** 100 * Menu callback; redirects users to new blog feed paths. 101 */ 102 function legacy_blog_feed($str_uid = '') { 103 // if URL is of form blog/feed/52 redirect 104 // if URL is of form blog/feed we have to call blog_feed_last(). 105 if (is_numeric($str_uid)) { 106 drupal_goto('blog/'. $str_uid .'/feed'); 107 } 108 else { 109 module_invoke('blog', 'feed_last'); 110 } 111 } 112 113 /** 114 * Implementation of hook_filter(). Handles URL upgrades from Drupal 4.1. 115 */ 116 function legacy_filter($op, $delta = 0, $format = -1, $text = '') { 117 switch ($op) { 118 case 'list': 119 return array(t('Legacy filter')); 120 121 case 'description': 122 return t('Replaces URLs from Drupal 4.1 (and lower) with updated equivalents.'); 123 124 case 'process': 125 return _legacy_filter_old_urls($text); 126 127 case 'settings': 128 return; 129 130 default: 131 return $text; 132 } 133 } 134 135 /** 136 * Rewrite legacy URLs. 137 * 138 * This is a *temporary* filter to rewrite old-style URLs to new-style 139 * URLs (clean URLs). Currently, URLs are being rewritten dynamically 140 * (ie. "on output"), however when these rewrite rules have been tested 141 * enough, we will use them to permanently rewrite the links in node 142 * and comment bodies. 143 */ 144 function _legacy_filter_old_urls($text) { 145 if (!variable_get('rewrite_old_urls', 0)) { 146 return $text; 147 } 148 149 global $base_url; 150 151 $end = substr($base_url, 12); 152 153 if (variable_get('clean_url', '0') == '0') { 154 // Relative URLs: 155 156 // rewrite 'node.php?id=<number>[&cid=<number>]' style URLs: 157 $text = eregi_replace("\"(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "\"?q=\\1/view/\\2/\\4", $text); 158 159 // rewrite 'module.php?mod=<name>{&<op>=<value>}' style URLs: 160 $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"?q=\\2/\\4/\\6" , $text); 161 $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"?q=\\2/\\4", $text); 162 $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "\"?q=\\2", $text); 163 164 // Absolute URLs: 165 166 // rewrite 'node.php?id=<number>[&cid=<number>]' style URLs: 167 $text = eregi_replace("$end/(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "$end/?q=\\1/view/\\2/\\4", $text); 168 169 // rewrite 'module.php?mod=<name>{&<op>=<value>}' style URLs: 170 $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/?q=\\2/\\4/\\6" , $text); 171 $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/?q=\\2/\\4", $text); 172 $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "\"$end/?q=\\2", $text); 173 } 174 else { 175 // Relative URLs: 176 177 // Rewrite 'node.php?id=<number>[&cid=<number>]' style URLs: 178 $text = eregi_replace("\"(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "\"\\1/view/\\2/\\4", $text); 179 180 // Rewrite 'module.php?mod=<name>{&<op>=<value>}' style URLs: 181 $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"\\2/\\4/\\6", $text); 182 $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"\\2/\\4", $text); 183 $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "\"\\2", $text); 184 185 // Absolute URLs: 186 187 // Rewrite 'node.php?id=<number>[&cid=<number>]' style URLs: 188 $text = eregi_replace("$end/(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "$end/\\1/view/\\2/\\4", $text); 189 190 // Rewrite 'module.php?mod=<name>{&<op>=<value>}' style URLs: 191 $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/\\2/\\4/\\6", $text); 192 $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/\\2/\\4", $text); 193 $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/\\2", $text); 194 } 195 196 return $text; 197 } 198 199
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Nov 30 16:20:15 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |