Redirecting the old links
To make catch the URLs and redirect them to the new content, a module can be made. How simple this is depends on the old url structure, in this case it's only links starting modules/ and uploads/. Although some of the links under modules were complicated to say the least - so lots of code chopped from the example.
/**
* Implementation of hook_menu.
*/
function nabuur_xoops_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'uploads',
'callback' => 'nabuur_xoops_file',
'access' => true,
'type' => MENU_CALLBACK,
);
$items[] = array(
'path' => 'modules',
'callback' => 'nabuur_xoops_page',
'access' => true,
'type' => MENU_CALLBACK,
);
}
return $items;
}
/**
* Redirects uploads/ links by checking against stored filepath.
*/
function nabuur_xoops_file() {
global $base_url;
$xf_path = $_GET['q'];
if(preg_match('@[^ a-zA-Z0-9_\-\.\(\)/]@', $xf_path)) {
// character not in known filenames
drupal_not_found();
}
else {
if ($df_path = db_result(db_query("SELECT {filepath} FROM {xoops_files} x LEFT JOIN files f ON x.fid = f.fid WHERE file = '%s'", $xf_path))) {
// log
nabuur_xoops_goto($base_url .'/'. $df_path); // @todo
}
elseif ($df_path = file_create_path($xf_filepath)) {
nabuur_xoops_goto($base_url .'/'. $df_path);
}
else {
return drupal_not_found();
}
}
}
/**
* Redirects modules/ to new node/nid.
*/
function nabuur_xoops_page() {
if (isset($_GET['topic_id'])) {
// task (including links direct to posts in tasks)
if ($nid = db_result(db_query("SELECT nid FROM {xoops_content} WHERE xtable = 'xoops_bb_topics' AND xid = %d", $_GET['topic_id']))) {
nabuur_xoops_goto('node/'. $nid);
}
}
[......]
}
function nabuur_xoops_goto($path) {
drupal_goto($path, NULL, NULL, 301);
}
* Implementation of hook_menu.
*/
function nabuur_xoops_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'uploads',
'callback' => 'nabuur_xoops_file',
'access' => true,
'type' => MENU_CALLBACK,
);
$items[] = array(
'path' => 'modules',
'callback' => 'nabuur_xoops_page',
'access' => true,
'type' => MENU_CALLBACK,
);
}
return $items;
}
/**
* Redirects uploads/ links by checking against stored filepath.
*/
function nabuur_xoops_file() {
global $base_url;
$xf_path = $_GET['q'];
if(preg_match('@[^ a-zA-Z0-9_\-\.\(\)/]@', $xf_path)) {
// character not in known filenames
drupal_not_found();
}
else {
if ($df_path = db_result(db_query("SELECT {filepath} FROM {xoops_files} x LEFT JOIN files f ON x.fid = f.fid WHERE file = '%s'", $xf_path))) {
// log
nabuur_xoops_goto($base_url .'/'. $df_path); // @todo
}
elseif ($df_path = file_create_path($xf_filepath)) {
nabuur_xoops_goto($base_url .'/'. $df_path);
}
else {
return drupal_not_found();
}
}
}
/**
* Redirects modules/ to new node/nid.
*/
function nabuur_xoops_page() {
if (isset($_GET['topic_id'])) {
// task (including links direct to posts in tasks)
if ($nid = db_result(db_query("SELECT nid FROM {xoops_content} WHERE xtable = 'xoops_bb_topics' AND xid = %d", $_GET['topic_id']))) {
nabuur_xoops_goto('node/'. $nid);
}
}
[......]
}
function nabuur_xoops_goto($path) {
drupal_goto($path, NULL, NULL, 301);
}
