<?php
function legacy_help($section) {
switch ($section) {
case 'admin/help#legacy':
$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>';
$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>';
$output .= t('<p>Example Mappings:</p>
<ul>
<li><em>taxonomy/page/or/52,97</em> to <em>taxonomy/term/52+97</em>.</li>
<li><em>taxonomy/feed/or/52,97</em> to <em>taxonomy/term/52+97/0/feed</em>.</li>
<li><em>blog/feed/52</em> to <em>blog/52/feed</em>.</li>
<li><em>node/view/52</em> to <em>node/52</em>.</li>
<li><em>book/view/52</em> to <em>node/52</em>.</li>
<li><em>user/view/52</em> to <em>user/52</em>.</li>
</ul>
');
$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>';
return $output;
}
}
function legacy_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array('path' => 'taxonomy/page', 'title' => t('Taxonomy'),
'callback' => 'legacy_taxonomy_page',
'access' => TRUE, 'type' => MENU_CALLBACK);
$items[] = array('path' => 'taxonomy/feed', 'title' => t('Taxonomy'),
'callback' => 'legacy_taxonomy_feed',
'access' => TRUE, 'type' => MENU_CALLBACK);
$items[] = array('path' => 'blog/feed', 'title' => t('Blog'),
'callback' => 'legacy_blog_feed',
'access' => TRUE, 'type' => MENU_CALLBACK);
}
else {
$items[] = array('path' => 'node/view', 'title' => t('View'),
'callback' => 'drupal_goto',
'callback arguments' => array('node/'. arg(2), NULL, NULL, 301),
'access' => TRUE, 'type' => MENU_CALLBACK);
$items[] = array('path' => 'book/view', 'title' => t('View'),
'callback' => 'drupal_goto',
'callback arguments' => array('node/'. arg(2), NULL, NULL, 301),
'access' => TRUE, 'type' => MENU_CALLBACK);
$items[] = array('path' => 'user/view', 'title' => t('View'),
'callback' => 'drupal_goto',
'callback arguments' => array('user/'. arg(2), NULL, NULL, 301),
'access' => TRUE, 'type' => MENU_CALLBACK);
}
return $items;
}
function legacy_taxonomy_page($operation = 'or', $str_tids = '') {
if ($operation == 'or') {
$str_tids = str_replace(',', '+', $str_tids);
}
drupal_goto('taxonomy/term/'. $str_tids);
}
function legacy_taxonomy_feed($operation = 'or', $str_tids = '') {
if ($operation == 'or') {
$str_tids = str_replace(',', '+', $str_tids);
}
drupal_goto('taxonomy/term/'. $str_tids .'/0/feed');
}
function legacy_blog_feed($str_uid = '') {
if (is_numeric($str_uid)) {
drupal_goto('blog/'. $str_uid .'/feed');
}
else {
module_invoke('blog', 'feed_last');
}
}
function legacy_filter($op, $delta = 0, $format = -1, $text = '') {
switch ($op) {
case 'list':
return array(t('Legacy filter'));
case 'description':
return t('Replaces URLs from Drupal 4.1 (and lower) with updated equivalents.');
case 'process':
return _legacy_filter_old_urls($text);
case 'settings':
return;
default:
return $text;
}
}
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') {
$text = eregi_replace("\"(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "\"?q=\\1/view/\\2/\\4", $text);
$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);
$text = eregi_replace("$end/(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "$end/?q=\\1/view/\\2/\\4", $text);
$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 {
$text = eregi_replace("\"(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "\"\\1/view/\\2/\\4", $text);
$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);
$text = eregi_replace("$end/(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "$end/\\1/view/\\2/\\4", $text);
$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;
}