function _legacy_filter_old_urls in Drupal 5
Same name and namespace in other branches
- 4 modules/legacy.module \_legacy_filter_old_urls()
Rewrite legacy URLs.
This is a *temporary* filter to rewrite old-style URLs to new-style URLs (clean URLs). Currently, URLs are being rewritten dynamically (ie. "on output"), however when these rewrite rules have been tested enough, we will use them to permanently rewrite the links in node and comment bodies.
1 call to _legacy_filter_old_urls()
- legacy_filter in modules/
legacy/ legacy.module - Implementation of hook_filter(). Handles URL upgrades from Drupal 4.1.
File
- modules/
legacy/ legacy.module, line 143 - Provides legacy handlers for upgrades from older Drupal installations.
Code
function _legacy_filter_old_urls($text) {
if (!variable_get('rewrite_old_urls', 0)) {
return $text;
}
global $base_url;
$end = substr($base_url, 12);
if (variable_get('clean_url', '0') == '0') {
// Relative URLs:
// rewrite 'node.php?id=<number>[&cid=<number>]' style URLs:
$text = eregi_replace("\"(node)\\.php\\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "\"?q=\\1/view/\\2/\\4", $text);
// rewrite 'module.php?mod=<name>{&<op>=<value>}' style URLs:
$text = ereg_replace("\"module\\.php\\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"?q=\\2/\\4/\\6", $text);
$text = ereg_replace("\"module\\.php\\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"?q=\\2/\\4", $text);
$text = ereg_replace("\"module\\.php\\?(&?[[:alpha:]]+=([[:alnum:]]+))", "\"?q=\\2", $text);
// Absolute URLs:
// rewrite 'node.php?id=<number>[&cid=<number>]' style URLs:
$text = eregi_replace("{$end}/(node)\\.php\\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "{$end}/?q=\\1/view/\\2/\\4", $text);
// rewrite 'module.php?mod=<name>{&<op>=<value>}' style URLs:
$text = ereg_replace("{$end}/module\\.php\\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "{$end}/?q=\\2/\\4/\\6", $text);
$text = ereg_replace("{$end}/module\\.php\\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "{$end}/?q=\\2/\\4", $text);
$text = ereg_replace("{$end}/module\\.php\\?(&?[[:alpha:]]+=([[:alnum:]]+))", "\"{$end}/?q=\\2", $text);
}
else {
// Relative URLs:
// Rewrite 'node.php?id=<number>[&cid=<number>]' style URLs:
$text = eregi_replace("\"(node)\\.php\\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "\"\\1/view/\\2/\\4", $text);
// Rewrite 'module.php?mod=<name>{&<op>=<value>}' style URLs:
$text = ereg_replace("\"module\\.php\\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"\\2/\\4/\\6", $text);
$text = ereg_replace("\"module\\.php\\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"\\2/\\4", $text);
$text = ereg_replace("\"module\\.php\\?(&?[[:alpha:]]+=([[:alnum:]]+))", "\"\\2", $text);
// Absolute URLs:
// Rewrite 'node.php?id=<number>[&cid=<number>]' style URLs:
$text = eregi_replace("{$end}/(node)\\.php\\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "{$end}/\\1/view/\\2/\\4", $text);
// Rewrite 'module.php?mod=<name>{&<op>=<value>}' style URLs:
$text = ereg_replace("{$end}/module\\.php\\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "{$end}/\\2/\\4/\\6", $text);
$text = ereg_replace("{$end}/module\\.php\\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "{$end}/\\2/\\4", $text);
$text = ereg_replace("{$end}/module\\.php\\?(&?[[:alpha:]]+=([[:alnum:]]+))", "{$end}/\\2", $text);
}
return $text;
}