View source
<?php
function me_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'admin/settings/me',
'title' => t('\'me\' Aliases'),
'description' => t('Define URL paths for Me aliasing.'),
'callback' => 'drupal_get_form',
'callback arguments' => array(
'me_settings',
),
'access' => user_access('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
);
}
return array_merge($items, _me_create_menu_items($may_cache));
}
function _me_create_menu_items($may_cache) {
$items = array();
$aliases = explode("\n", variable_get('me_aliases', 'user/me'));
foreach ($aliases as $alias) {
$alias = preg_split('/[\\?\\#]/', $alias);
$alias = trim(check_url($alias[0]), "/ \t\n\r\0");
$path = drupal_get_normal_path($_GET['q']);
if (preg_match('/(\\/m|^m)(e$|e\\/)/', $alias, $matches) > 0 && ($may_cache || 0 === strpos($path, $alias))) {
$items[] = array(
'path' => $may_cache ? $alias : $path,
'type' => MENU_CALLBACK,
'callback' => 'me_relay',
'access' => true,
);
if (!$may_cache) {
break;
}
}
}
return $items;
}
function me_settings() {
$form['me_aliases'] = array(
'#type' => 'textarea',
'#title' => t('Aliases to create'),
'#default_value' => variable_get('me_aliases', "user/me"),
'#cols' => 50,
'#rows' => 6,
'#description' => t('The per-user aliases to create. Each alias must contain the \'me\' fragment or it will be ignored. Enter one alias per line, and do not include trailing or leading slashes.'),
);
return system_settings_form($form);
}
function me_relay() {
global $user;
if ($user->uid != 0) {
$index = 0;
$destination = '';
$fragment = arg(0);
while ($fragment) {
$destination .= ($destination == '' ? '' : '/') . ($fragment == 'me' ? $user->uid : $fragment);
$index++;
$fragment = arg($index);
}
drupal_goto($destination);
}
else {
drupal_set_message(t('Please login to access this personalised page.'));
$destination = "destination=" . drupal_urlencode($_GET['q']);
drupal_goto('user/login', $destination);
}
}