Index: includes/me_views_handler_argument_user_name.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/me/includes/Attic/me_views_handler_argument_user_name.inc,v retrieving revision 1.1.4.2 diff -u -r1.1.4.2 me_views_handler_argument_user_name.inc --- includes/me_views_handler_argument_user_name.inc 2 Mar 2009 21:31:18 -0000 1.1.4.2 +++ includes/me_views_handler_argument_user_name.inc 3 Apr 2009 10:05:35 -0000 @@ -30,6 +30,7 @@ $options = parent::option_definition(); $options['me_alias'] = array('default' => FALSE); + $options['me_redirect'] = array('default' => FALSE); return $options; } @@ -43,11 +44,19 @@ $form['me_alias'] = array( '#type' => 'checkbox', '#title' => t("Let users enter the 'me' alias instead of their user name."), - '#description' => t("If selected, users can enter the 'me' alias inplace of their user name. When this option is selected, " - ."the wildcard can not be the same as the 'me' alias and you will not be able to select a user whos name is the same " - ."as the 'me' alias."), + '#description' => t("If selected, users can enter the 'me' alias inplace of their user name. When this option is selected, the wildcard can not be the same as the 'me' alias and you will not be able to select a user whos name is the same as the 'me' alias."), '#default_value' => !empty($this->options['me_alias']), ); + + // Allow the view creator to decide if the 'me' alias will redirect to the name. + $form['me_redirect'] = array( + '#type' => 'checkbox', + '#title' => t("Redirect to the users name when 'me' is entered as an argument."), + '#description' => t("If selected, when a user enters 'me' for this argument, they will be redirected to the view with their user name inplace of 'me'."), + '#default_value' => !empty($this->options['me_redirect']), + '#process' => array('views_process_dependency'), + '#dependency' => array('edit-options-me-alias' => array(TRUE)), + ); } /** @@ -72,7 +81,10 @@ // Whilst we do validate this in the options form, this is here for views that // were created before the me module was installed. if (!_me_is_alias($this->options['wildcard']) && !empty($this->options['me_alias'])) { - return parent::set_argument(_me_views_set_argument($arg, $this->options['break_phrase'], TRUE)); + // Set a flag on the view so we know if we need to redirect or not. + $this->view->me_redirect = $this->options['me_redirect']; + + return parent::set_argument(_me_views_set_argument($arg, $this->view, $this->options['break_phrase'], TRUE)); } } } Index: includes/me.views.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/me/includes/me.views.inc,v retrieving revision 1.1.2.3.2.2 diff -u -r1.1.2.3.2.2 me.views.inc --- includes/me.views.inc 20 Mar 2009 10:47:05 -0000 1.1.2.3.2.2 +++ includes/me.views.inc 3 Apr 2009 10:05:34 -0000 @@ -8,7 +8,9 @@ */ /** - * Implementation of hook_views_data_alter(). + * Implementation of views' hook_views_data_alter(). + * + * See http://drupal.org/project/views for module and hook information. */ function me_views_data_alter(&$cache) { // Make our handler the one to use for handling user arguments. @@ -30,10 +32,37 @@ } /** + * Implementation of Views' hook_views_pre_execute(). + * + * See http://drupal.org/project/views for module and hook information. + */ +function me_views_pre_execute(&$view) { + // Check if we need to do a redirect. Be sure not to redirect in a live preview. + if (!empty($view->me_redirect) && empty($view->live_preview)) { + // We should always be able to redirect here regardless, as our handler has to + // have run for our option to be set, which means we need to redirect anyway. + + // Loop over the argument handlers to get the arguments we need. We also keep this + // consistent with any extra arguments that may have been passed in. + $arguments = $view->args; + foreach (array_values($view->argument) as $key => $argument) { + if (isset($argument->argument)) { + $arguments[$key] = $argument->argument; + } + } + + // Redirect to the path. + drupal_goto($view->get_url($arguments)); + } +} + +/** * Helper function to set the views user arguments we override. * * @param $arg * The arg(s) we are checking. + * @param &$view + * The view object. * @param $break_phase * Helps us determine if there are multiple arguments. * @param $username @@ -42,7 +71,7 @@ * @return string * The modified argument list. */ -function _me_views_set_argument($arg, $break_phase, $username = FALSE) { +function _me_views_set_argument($arg, &$view, $break_phase, $username = FALSE) { $uid_args = array(); $seperator = ' '; if (empty($break_phase)) { @@ -61,10 +90,18 @@ } } + // Check if we need to do a redirect, and make sure the option is disabled if we don't. + if ($view->me_redirect) { + $redirect_args = array_filter($uid_args, create_function('$n', 'return _me_is_alias($n);')); + if (empty($redirect_args)) { + $view->me_redirect = FALSE; + } + } + // The alias could potentially show up more than once. Loop over each argument // and check to be sure. - foreach ($uid_args as &$uid_arg) { - $uid_arg = _me_check_arg($uid_arg, $username, FALSE); + foreach ($uid_args as $key => $uid_arg) { + $uid_args[$key] = _me_check_arg($uid_arg, $username, FALSE); } return implode($seperator, $uid_args); Index: includes/me_views_handler_argument_user_uid.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/me/includes/me_views_handler_argument_user_uid.inc,v retrieving revision 1.1.2.3.2.1 diff -u -r1.1.2.3.2.1 me_views_handler_argument_user_uid.inc --- includes/me_views_handler_argument_user_uid.inc 2 Mar 2009 21:31:18 -0000 1.1.2.3.2.1 +++ includes/me_views_handler_argument_user_uid.inc 3 Apr 2009 10:05:35 -0000 @@ -30,6 +30,7 @@ $options = parent::option_definition(); $options['me_alias'] = array('default' => TRUE); + $options['me_redirect'] = array('default' => FALSE); return $options; } @@ -43,10 +44,19 @@ $form['me_alias'] = array( '#type' => 'checkbox', '#title' => t("Let users enter the 'me' alias instead of their user id."), - '#description' => t("If selected, users can enter the 'me' alias inplace of their user id. When this option is selected, " - ."the wildcard can not be the same as the 'me' alias."), + '#description' => t("If selected, users can enter the 'me' alias inplace of their user id. When this option is selected, the wildcard can not be the same as the 'me' alias."), '#default_value' => !empty($this->options['me_alias']), ); + + // Allow the view creator to decide if the 'me' alias will redirect to the uid. + $form['me_redirect'] = array( + '#type' => 'checkbox', + '#title' => t("Redirect to the users uid when 'me' is entered as an argument."), + '#description' => t("If selected, when a user enters 'me' for this argument, they will be redirected to the view with their user id inplace of 'me'."), + '#default_value' => !empty($this->options['me_redirect']), + '#process' => array('views_process_dependency'), + '#dependency' => array('edit-options-me-alias' => array(TRUE)), + ); } /** @@ -71,7 +81,10 @@ // Whilst we do validate this in the options form, this is here for views that // were created before the me module was installed. if (!_me_is_alias($this->options['wildcard']) && !empty($this->options['me_alias'])) { - return parent::set_argument(_me_views_set_argument($arg, $this->options['break_phrase'])); + // Set a flag on the view so we know if we need to redirect or not. + $this->view->me_redirect = $this->options['me_redirect']; + + return parent::set_argument(_me_views_set_argument($arg, $this->view, $this->options['break_phrase'])); } } } Index: me.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/me/me.module,v retrieving revision 1.5.2.7.2.5 diff -u -r1.5.2.7.2.5 me.module --- me.module 31 Mar 2009 06:52:18 -0000 1.5.2.7.2.5 +++ me.module 3 Apr 2009 10:05:34 -0000 @@ -464,7 +464,9 @@ } /** - * Implementation of hook_views_api(). + * Implementation of Views' hook_views_api(). + * + * See http://drupal.org/project/views for module and hook information. */ function me_views_api() { return array( @@ -563,14 +565,11 @@ ME_PATH_EXCLUDE => t('Use me alias on every path except the listed paths.'), ME_PATH_INCLUDE => t('Use me alias only on the listed paths.'), ); - $description = t("Enter one path per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the ' - .'blog page and %blog-wildcard for every personal blog. %front is the front page.", - array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '')); + $description = t("Enter one path per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '')); if ($access) { $options[ME_PATH_PHP] = t('Use me alias if the following PHP code returns TRUE (PHP-mode, experts only).'); - $description .= ' '. t('If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can ' - .'break your Drupal site.', array('%php' => '')); + $description .= ' '. t('If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.', array('%php' => '')); } $form['me_paths_settings']['me_path_rule'] = array( '#type' => 'radios', @@ -582,10 +581,7 @@ '#type' => 'textarea', '#title' => t('Paths'), '#default_value' => $paths, - '#description' => $description . t('

NOTE: This option simply ensures that the browser address bar for these paths have ' - .'the uid and not me. The me alias will still work for these paths. It will have no effect on specific uids in paths, ' - .'but if the path includes the me alias, then me will be affected for those paths. This will only affect paths ' - .'that me can already handle. It will not allow me to work for unknown paths.

'), + '#description' => $description . t('

NOTE: This option simply ensures that the browser address bar for these paths have the uid and not me. The me alias will still work for these paths. It will have no effect on specific uids in paths, but if the path includes the me alias, then me will be affected for those paths. This will only affect paths that me can already handle. It will not allow me to work for unknown paths.

'), ); } @@ -638,9 +634,7 @@ $form['me_disable'] = array( '#type' => 'checkbox', '#title' => t("Disable '%me' alias for this account", 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_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_variable_get('me_alias'))), '#default_value' => !empty($account->me_disable), );