2009-10-24 05:13:44 +00:00
|
|
|
<?php
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Module to help test hook_url_inbound_alter() and hook_url_outbound_alter().
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2009-12-04 16:49:48 +00:00
|
|
|
* Implements hook_url_inbound_alter().
|
2009-10-24 05:13:44 +00:00
|
|
|
*/
|
|
|
|
function url_alter_test_url_inbound_alter(&$path, $original_path, $path_language) {
|
|
|
|
// Rewrite user/username to user/uid.
|
|
|
|
if (preg_match('!^user/([^/]+)(/.*)?!', $path, $matches)) {
|
|
|
|
if ($account = user_load_by_name($matches[1])) {
|
|
|
|
$matches += array(2 => '');
|
|
|
|
$path = 'user/' . $account->uid . $matches[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rewrite community/ to forum/.
|
|
|
|
if ($path == 'community' || strpos($path, 'community/') === 0) {
|
|
|
|
$path = 'forum' . substr($path, 9);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-12-04 16:49:48 +00:00
|
|
|
* Implements hook_url_outbound_alter().
|
2009-10-24 05:13:44 +00:00
|
|
|
*/
|
|
|
|
function url_alter_test_url_outbound_alter(&$path, &$options, $original_path) {
|
|
|
|
// Rewrite user/uid to user/username.
|
|
|
|
if (preg_match('!^user/([0-9]+)(/.*)?!', $path, $matches)) {
|
|
|
|
if ($account = user_load($matches[1])) {
|
|
|
|
$matches += array(2 => '');
|
|
|
|
$path = 'user/' . $account->name . $matches[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rewrite forum/ to community/.
|
|
|
|
if ($path == 'forum' || strpos($path, 'forum/') === 0) {
|
|
|
|
$path = 'community' . substr($path, 5);
|
|
|
|
}
|
|
|
|
}
|