Go to the documentation of this file.00001 <?php
00012 class views_plugin_argument_validate_php extends views_plugin_argument_validate {
00013 function option_definition() {
00014 $options = parent::option_definition();
00015 $options['code'] = array('default' => '');
00016
00017 return $options;
00018 }
00019
00020 function options_form(&$form, &$form_state) {
00021 parent::options_form($form, $form_state);
00022 $form['code'] = array(
00023 '#type' => 'textarea',
00024 '#title' => t('PHP validate code'),
00025 '#default_value' => $this->options['code'],
00026 '#description' => t('Enter PHP code that returns TRUE or FALSE. No return is the same as FALSE, so be SURE to return something if you do not want to declare the argument invalid. Do not use <?php ?>. The argument to validate will be "$argument" and the view will be "$view". You may change the argument by setting "$handler->argument". You may change the title used for substitutions for this argument by setting "$handler->validated_title".'),
00027 );
00028
00029 $this->check_access($form, 'code');
00030 }
00031
00036 function access() {
00037 return user_access('use PHP for settings');
00038 }
00039
00040 function convert_options(&$options) {
00041 if (!isset($options['code']) && isset($this->argument->options['validate_argument_php'])) {
00042 $options['code'] = $this->argument->options['validate_argument_php'];
00043 }
00044 }
00045
00046 function validate_argument($argument) {
00047
00048 $view = &$this->view;
00049 $handler = &$this->argument;
00050
00051 ob_start();
00052 $result = eval($this->options['code']);
00053 ob_end_clean();
00054 return $result;
00055 }
00056 }