| 1 |
<?php |
<?php |
| 2 |
// $Id: me.module,v 1.5.2.7.2.5 2009/03/31 06:52:18 cdale Exp $ |
// $Id: me.module,v 1.5.2.7.2.6 2009/04/03 10:13:28 cdale Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 393 |
function me_to_arg($arg, $map, $index) { |
function me_to_arg($arg, $map, $index) { |
| 394 |
$uid = user_uid_optional_to_arg($arg, $map, $index); |
$uid = user_uid_optional_to_arg($arg, $map, $index); |
| 395 |
if (me_variable_get('me_rewrite_link') && !_me_user_disabled()) { |
if (me_variable_get('me_rewrite_link') && !_me_user_disabled()) { |
| 396 |
return $uid == $GLOBALS['user']->uid ? me_variable_get('me_alias') : $uid; |
return $uid == $GLOBALS['user']->uid ? _me_get_me_alias() : $uid; |
| 397 |
} |
} |
| 398 |
else { |
else { |
| 399 |
return $uid; |
return $uid; |
| 450 |
} |
} |
| 451 |
|
|
| 452 |
/** |
/** |
| 453 |
|
* Helper function to return the me alias. |
| 454 |
|
* |
| 455 |
|
* @param $print_name |
| 456 |
|
* Shows a friendly print name of the alias instead |
| 457 |
|
* of the actual alias itself. This argument is only |
| 458 |
|
* checked if the token module is installed. |
| 459 |
|
* |
| 460 |
|
* @return string |
| 461 |
|
* The me alias, token replaced if appropriate. |
| 462 |
|
*/ |
| 463 |
|
function _me_get_me_alias($print = FALSE) { |
| 464 |
|
$alias = me_variable_get('me_alias'); |
| 465 |
|
|
| 466 |
|
// Replace with any global tokens that might have been used in the alias. |
| 467 |
|
if (module_exists('token')) { |
| 468 |
|
$replaced_alias = token_replace($alias, 'global'); |
| 469 |
|
|
| 470 |
|
// They will not match if a replacement happened. |
| 471 |
|
if ($print && $replaced_alias != $alias) { |
| 472 |
|
$alias = ucwords(str_replace(array('-', '[', ']'), array(' ', ''), $alias)); |
| 473 |
|
} |
| 474 |
|
else { |
| 475 |
|
$alias = $replaced_alias; |
| 476 |
|
} |
| 477 |
|
} |
| 478 |
|
|
| 479 |
|
return $alias; |
| 480 |
|
} |
| 481 |
|
|
| 482 |
|
/** |
| 483 |
* A helper function to check if a string is equal to the 'me' alias. |
* A helper function to check if a string is equal to the 'me' alias. |
| 484 |
* |
* |
| 485 |
* @param $arg |
* @param $arg |
| 490 |
*/ |
*/ |
| 491 |
function _me_is_alias($arg) { |
function _me_is_alias($arg) { |
| 492 |
$compare_function = me_variable_get('me_case_insensitive') ? 'strcasecmp' : 'strcmp'; |
$compare_function = me_variable_get('me_case_insensitive') ? 'strcasecmp' : 'strcmp'; |
| 493 |
return $compare_function($arg, me_variable_get('me_alias')) === 0; |
return $compare_function($arg, _me_get_me_alias()) === 0; |
| 494 |
} |
} |
| 495 |
|
|
| 496 |
/** |
/** |
| 545 |
'#default_value' => me_variable_get('me_alias'), |
'#default_value' => me_variable_get('me_alias'), |
| 546 |
'#required' => TRUE, |
'#required' => TRUE, |
| 547 |
); |
); |
| 548 |
|
if (module_exists('token')) { |
| 549 |
|
$form['me_token_help'] = array( |
| 550 |
|
'#title' => t('Replacement patterns for me alias'), |
| 551 |
|
'#type' => 'fieldset', |
| 552 |
|
'#collapsible' => TRUE, |
| 553 |
|
'#collapsed' => TRUE, |
| 554 |
|
'help' => array( |
| 555 |
|
'#type' => 'markup', |
| 556 |
|
'#value' => theme('token_help', 'global'), |
| 557 |
|
), |
| 558 |
|
); |
| 559 |
|
} |
| 560 |
|
|
| 561 |
$form['me_case_insensitive'] = array( |
$form['me_case_insensitive'] = array( |
| 562 |
'#type' => 'checkbox', |
'#type' => 'checkbox', |
| 643 |
* Validation callback for me_admin_settings_form. |
* Validation callback for me_admin_settings_form. |
| 644 |
*/ |
*/ |
| 645 |
function me_admin_settings_form_validate($form, &$form_state) { |
function me_admin_settings_form_validate($form, &$form_state) { |
| 646 |
if (preg_match('/[^a-zA-Z]/', $form_state['values']['me_alias'])) { |
// If the token module is installed, we need to also allow a list of tokens |
| 647 |
form_set_error('me_alias', t('The alias can only contain characters from a-z and A-Z.')); |
// that are allowed to match against. We include all global tokens here, even though |
| 648 |
|
// some of them don't really make sense, but that is up to the end user. |
| 649 |
|
$token_list = array(); |
| 650 |
|
if (module_exists('token')) { |
| 651 |
|
$token_list = array_map(create_function('$n', 'return "[$n]";'), array_keys(array_pop(token_get_list('global')))); |
| 652 |
|
} |
| 653 |
|
if (preg_match('/[^a-zA-Z]/', $form_state['values']['me_alias']) && !in_array($form_state['values']['me_alias'], $token_list)) { |
| 654 |
|
if (!empty($token_list)) { |
| 655 |
|
$message = t('The alias can only contain characters from a-z and A-Z, or one of the tokens specified in the "Replacement patterns for me alias" section.'); |
| 656 |
|
} |
| 657 |
|
else { |
| 658 |
|
$message = t('The alias can only contain characters from a-z and A-Z.'); |
| 659 |
|
} |
| 660 |
|
form_set_error('me_alias', $message); |
| 661 |
} |
} |
| 662 |
} |
} |
| 663 |
|
|
| 671 |
return array( |
return array( |
| 672 |
array( |
array( |
| 673 |
'name' => 'me', |
'name' => 'me', |
| 674 |
'title' => t("'@me' alias", array('@me' => me_variable_get('me_alias'))), |
'title' => t("'@me' alias", array('@me' => _me_get_me_alias(TRUE))), |
| 675 |
'weight' => 2, |
'weight' => 2, |
| 676 |
), |
), |
| 677 |
); |
); |
| 688 |
|
|
| 689 |
$form['me_disable'] = array( |
$form['me_disable'] = array( |
| 690 |
'#type' => 'checkbox', |
'#type' => 'checkbox', |
| 691 |
'#title' => t("Disable '%me' alias for this account", array('%me' => me_variable_get('me_alias'))), |
'#title' => t("Disable '%me' alias for this account", array('%me' => _me_get_me_alias(TRUE))), |
| 692 |
'#description' => t('This option stops your user id from being replaced with %me. %me will still work when entered into the address bar, but you will be redirected to a page with your uid in its place.', array('%me' => me_variable_get('me_alias'))), |
'#description' => t('This option stops your user id from being replaced with %me. %me will still work when entered into the address bar, but you will be redirected to a page with your uid in its place.', array('%me' => _me_get_me_alias(TRUE))), |
| 693 |
'#default_value' => !empty($account->me_disable), |
'#default_value' => !empty($account->me_disable), |
| 694 |
); |
); |
| 695 |
|
|
| 704 |
$account->content['me'] = array( |
$account->content['me'] = array( |
| 705 |
'#type' => 'markup', |
'#type' => 'markup', |
| 706 |
'#value' => t("'%me' aliases are $enabled for this account. Account user id is '@uid'.", |
'#value' => t("'%me' aliases are $enabled for this account. Account user id is '@uid'.", |
| 707 |
array('%me' => me_variable_get('me_alias'), '@uid' => $account->uid)), |
array('%me' => _me_get_me_alias(TRUE), '@uid' => $account->uid)), |
| 708 |
'#weight' => 10, |
'#weight' => 10, |
| 709 |
); |
); |
| 710 |
} |
} |