--- me.module Thu Jan 15 10:14:12 1970 +++ me.module Thu Jan 15 10:14:12 1970 @@ -74,6 +74,15 @@ } /** + * Implementaiton of moduleName_preprocess_hook() for theme_menu_local_task. + */ +function me_preprocess_page(&$vars) { + foreach($vars['primary_links'] as $key => $value) { + _me_check_path($vars['primary_links'][$key]); + } +} + +/** * Helper function to check if a path can be rewritten or not. * * By this stage, the path is already rewritten, so we need to @@ -88,8 +97,15 @@ if (me_variable_get('me_rewrite_link') && !_me_handle_path($link['href'])) { $path_parts = explode('/', $link['href'], MENU_MAX_PARTS); + if (!isset($link['path']) && !isset($link['router_path'])) { + $link_item = menu_get_item($link['href']); + } + else { + $link_item = $link; + } + // The wildcarded path will either be in $link['path'], or $link['router_path']. - $wild_parts = explode('/', (isset($link['path']) ? $link['path'] : $link['router_path']), MENU_MAX_PARTS); + $wild_parts = explode('/', (isset($link_item['path']) ? $link_item['path'] : $link_item['router_path']), MENU_MAX_PARTS); // Go over each of the path parts and if one is equal to the me alias, make sure it is a wildcard, // and if so, switch it back out. @@ -232,6 +248,57 @@ } /** + * A special menu callback function for page manger pages that either redirects to + * a page with the uid in the path, or calls page_manager_page_execute + * + * @return page_manager_page_execute(args) + */ +function me_page_manager_page_execute() { + // If we want the uid shown in the address bar, we need to do a redirect. + if (me_variable_get('me_redirect') || _me_user_disabled() || !_me_handle_path($_GET['q'])) { + $redirect = FALSE; + // Get the menu path arguments. + $menu_parts = explode('/', $_GET['q'], MENU_MAX_PARTS); + + // Loop over each part. If it's a %me wildcard, then + // check the corresponding menu part for the me alias, + // if so, replace it out with the user id so we can redirect correctly. + // If no changes are required, then call the required function. + foreach ($menu_parts as $key => $value) { + if (_me_is_alias($value)) { + $redirect = TRUE; + $menu_parts[$key] = $GLOBALS['user']->uid; + } + } + + if ($redirect) { + $path = implode('/', $menu_parts); + // Save on an extra redirect by also checking the anonymous redirect here. + $redirect_path = me_variable_get('me_redirect_anonymous'); + if ($GLOBALS['user']->uid == 0 && !empty($redirect_path)) { + $path = $redirect_path; + } + drupal_goto($path); + } + } + + // Before going any further, set the current menu router item to include + // paths with %user, which allows modules to use menu_get_object() instead + // of arg() in blocks and the like. + $router_item = menu_get_item(); + foreach ($router_item['load_functions'] as $index => $function) { + // If the function is a me handled function, then swap the handler out with user. + if (0 === strpos($function, 'me')) { + $router_item['load_functions'][$index] = 'user_load'; + } + } + menu_set_item($_GET['q'], $router_item); + + $args = func_get_args(); + return call_user_func_array(page_manager_page_execute, $args); +} + +/** * Helper function to check if a user can have, and has me disabled. * * @return boolean @@ -334,6 +401,11 @@ unset($callbacks[$path]); $processed[] = $path; } + + // Alter the page callback for page manager pages + if ($data['page callback'] == 'page_manager_page_execute') { + $callbacks[$path]['page callback'] = 'me_page_manager_page_execute'; + } } } @@ -388,6 +460,19 @@ } /** + * Special menu _load() function for the user:uid argument. + * + * This is just the normal page manager argument. It only exists so that + * the to_arg can exist. + */ +function me_pm_uid_arg_load($value, $subtask, $argument) { + page_manager_get_task('page'); + $value = _me_check_arg($value); + + return _pm_arg_load($value, $subtask, $argument); +} + +/** * Menu to_arg function for %me. */ function me_to_arg($arg, $map, $index) { @@ -415,6 +500,19 @@ } /** + * Menu to_arg function for %me. + */ +function me_pm_uid_arg_to_arg($arg) { + $uid = user_uid_optional_to_arg($arg); + if (me_variable_get('me_rewrite_link') && !_me_user_disabled()) { + return $uid == $GLOBALS['user']->uid ? _me_get_me_alias() : $uid; + } + else { + return $uid; + } +} + +/** * A Helper function to check for the 'me' alias. * * @param $arg @@ -721,4 +819,4 @@ if ($module == 'ctools' && $plugin == 'arguments') { return 'plugins'; } -} +} \ No newline at end of file --- me_uid.inc Thu Jan 15 10:14:12 1970 +++ me_uid.inc Thu Jan 15 10:14:12 1970 @@ -23,6 +23,9 @@ '#type' => 'textfield', '#description' => t('Enter the user ID of a user for this argument or the %me alias.', array('%me' => _me_get_me_alias(TRUE))), ), + 'default' => array('to_arg' => TRUE), + 'path placeholder' => '%me_pm_uid_arg', // This is in pagemanager. + 'path placeholder to_arg' => TRUE, ); return $args; }