You are here

class me_plugin_argument_validate_me_alias in me aliases 7

Same name and namespace in other branches
  1. 8 includes/views/handlers/me_plugin_argument_validate_me_alias.inc \me_plugin_argument_validate_me_alias
  2. 6.2 includes/me_plugin_argument_validate_me_alias.inc \me_plugin_argument_validate_me_alias

Validate whether an argument is an acceptable me alias, and user name/uid.

Hierarchy

Expanded class hierarchy of me_plugin_argument_validate_me_alias

1 string reference to 'me_plugin_argument_validate_me_alias'
me_views_plugins in includes/views/me.views.inc
Implementation of hook_views_plugins

File

includes/views/handlers/me_plugin_argument_validate_me_alias.inc, line 14
Argument validator to help validate the me alias. If the argument is 'me', other validators will most likely be useless at this point, so we provde the same functionality as the user validator.

View source
class me_plugin_argument_validate_me_alias extends views_plugin_argument_validate_user {
  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);
    $form['roles']['#dependency'] = array(
      'edit-options-validate-options-me-restrict-roles' => array(
        1,
      ),
    );
    $form['me_redirect'] = array(
      '#type' => 'checkbox',
      '#title' => t("Redirect to the users uid when '%me' is entered as an argument.", array(
        '%me' => _me_get_me_alias(TRUE),
      )),
      '#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'.", array(
        '%me' => _me_get_me_alias(TRUE),
      )),
      '#default_value' => !empty($this->argument->options['me_redirect']),
    );
  }

  /**
   * Provides a form of options for our validator.
   */
  function options_validate(&$form, &$form_state) {

    // We are unable to rely on options having already been set, so let's make
    // sure defaults are here:
    parent::options_validate($form, $form_state);
    if (!isset($this->argument->options['me_redirect'])) {
      $this->argument->options['me_redirect'] = FALSE;
      $this->argument->options['me_validate_user_argument_type'] = 'uid';
      $this->argument->options['me_validate_user_roles'] = array();
    }
  }

  /**
   * Performs the actual validation.
   */
  function validate_argument($argument) {

    // Only modify the argument when the wildcard does not equal the 'me' alias.
    if (!isset($this->argument->options['wildcard']) || !_me_is_alias($this->argument->options['wildcard'])) {
      $uid_args = array();
      $seperator = ' ';
      if (empty($this->argument->options['break_phrase'])) {
        $uid_args[] = $argument;
      }
      else {

        // Modified from views_break_phrase() to include characters that a 'me' alias
        // may include.
        if (preg_match('/^([0-9a-zA-Z]+[+ ])+[0-9a-zA-Z]+$/', $argument)) {

          // The '+' character in a query string may be parsed as ' '.
          $uid_args = preg_split('/[+ ]/', $argument);
        }
        else {
          if (preg_match('/^([0-9a-zA-Z]+,)*[0-9a-zA-Z]+$/', $argument)) {
            $seperator = ',';
            $uid_args = explode(',', $argument);
          }
        }
      }

      // Check if we need to do a redirect, and make sure the option is disabled if we don't.
      // But be sure not to redirect in a live preview.
      if (empty($this->view->live_preview) && !empty($this->options['me_redirect'])) {
        $redirect_args = array_filter($uid_args, create_function('$n', 'return _me_is_alias($n);'));
        if (!empty($redirect_args)) {

          // Trigger a redirect.
          me_views_pre_execute(NULL, TRUE);
        }
      }

      // The alias could potentially show up more than once. Loop over each argument
      // and check to be sure.
      foreach ($uid_args as $key => $uid_arg) {
        $uid_args[$key] = _me_check_arg($uid_arg, $this->options['type'] == 'name', FALSE);

        //Make sure we only allow access to the current user
        if (is_numeric($uid_args[$key])) {
          if ($uid_args[$key] != $GLOBALS['user']->uid) {
            $this->view->build_info['denied'] = TRUE;
            return FALSE;
          }
        }
        else {
          if ($uid_args[$key] != $GLOBALS['user']->name) {
            $this->view->build_info['denied'] = TRUE;
            return FALSE;
          }
        }
      }
      $argument = implode($seperator, $uid_args);
    }

    // We always need to return the parent::set_argument() call.
    $this->argument->options['validate_user_argument_type'] = $this->options['type'];
    $this->argument->options['validate_user_restrict_roles'] = $this->options['restrict_roles'];
    $this->argument->options['validate_user_roles'] = $this->options['roles'];
    return parent::validate_argument($argument);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
me_plugin_argument_validate_me_alias::options_form function Provide the default form for setting options. Overrides views_plugin_argument_validate_user::options_form
me_plugin_argument_validate_me_alias::options_validate function Provides a form of options for our validator. Overrides views_plugin_argument_validate::options_validate
me_plugin_argument_validate_me_alias::validate_argument function Performs the actual validation. Overrides views_plugin_argument_validate_user::validate_argument
views_object::$definition public property Handler's definition.
views_object::$options public property Except for displays, options for the object will be held here. 1
views_object::altered_option_definition function Collect this handler's option definition and alter them, ready for use.
views_object::construct public function Views handlers use a special construct function. 4
views_object::destroy public function Destructor. 2
views_object::export_option public function 1
views_object::export_options public function
views_object::export_option_always public function Always exports the option, regardless of the default value.
views_object::options Deprecated public function Set default options on this object. 1
views_object::set_default_options public function Set default options.
views_object::set_definition public function Let the handler know what its full definition is.
views_object::unpack_options public function Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away.
views_object::unpack_translatable public function Unpack a single option definition.
views_object::unpack_translatables public function Unpacks each handler to store translatable texts.
views_object::_set_option_defaults public function
views_plugin::$display public property The current used views display.
views_plugin::$plugin_name public property The plugin name of this plugin, for example table or full.
views_plugin::$plugin_type public property The plugin type of this plugin, for example style or query.
views_plugin::$view public property The top object of a view. Overrides views_object::$view 1
views_plugin::additional_theme_functions public function Provide a list of additional theme functions for the theme info page.
views_plugin::plugin_title public function Return the human readable name of the display.
views_plugin::query public function Add anything to the query that we might need to. 7
views_plugin::summary_title public function Returns the summary of the settings in the display. 8
views_plugin::theme_functions public function Provide a full list of possible theme templates used by this style.
views_plugin::validate public function Validate that the plugin is correct and can be saved. 3
views_plugin_argument_validate::access public function Determine if the administrator has the privileges to use this plugin. 1
views_plugin_argument_validate::check_access public function If we don't have access to the form but are showing it anyway, ensure that the form is safe and cannot be changed from user input.
views_plugin_argument_validate::init public function Initialize this plugin with the view and the argument it is linked to. 1
views_plugin_argument_validate_user::convert_options public function Convert options from the older style. Overrides views_plugin_argument_validate::convert_options
views_plugin_argument_validate_user::options_submit public function Provide the default form form for submitting options Overrides views_plugin_argument_validate::options_submit
views_plugin_argument_validate_user::option_definition public function Retrieve the options when this is a new access control plugin. Overrides views_plugin_argument_validate::option_definition
views_plugin_argument_validate_user::process_summary_arguments public function Process the summary arguments for displaying. Overrides views_plugin_argument_validate::process_summary_arguments