You are here

class views_autorefresh_handler_area_autorefresh in Views Auto-Refresh 7

Same name and namespace in other branches
  1. 7.2 views/views_autorefresh_handler_area_autorefresh.inc \views_autorefresh_handler_area_autorefresh

Base class for area handlers.

Hierarchy

Expanded class hierarchy of views_autorefresh_handler_area_autorefresh

1 string reference to 'views_autorefresh_handler_area_autorefresh'
views_autorefresh_views_data_alter in views/views_autorefresh.views.inc
Implementation of hook_views_data_alter().

File

views/views_autorefresh_handler_area_autorefresh.inc, line 8

View source
class views_autorefresh_handler_area_autorefresh extends views_handler_area {

  /**
   * Overrides views_handler_area::init().
   *
   * Reset override done in views_handler_area::init(). This area must be
   * rendered even if view has no results.
   */
  function init(&$view, &$options) {
    parent::init($view, $options);
  }
  function option_definition() {
    $options = parent::option_definition();
    $options['interval'] = array(
      'default' => '',
    );
    $options['nodejs'] = array(
      'default' => FALSE,
      'bool' => TRUE,
    );
    $options['incremental'] = array(
      'default' => FALSE,
      'bool' => TRUE,
    );
    $options['display'] = array(
      'default' => '',
    );
    $options['incremental_advanced'] = array(
      'contains' => array(
        'sourceSelector' => array(
          'default' => '.view-content',
        ),
        'targetSelector' => array(
          'default' => '.view-content',
        ),
        'emptySelector' => array(
          'default' => '.view-empty',
        ),
        'afterSelector' => array(
          'default' => '.view-header',
        ),
        'targetStructure' => array(
          'default' => '<div class="view-content"></div>',
        ),
        'firstClass' => array(
          'default' => 'views-row-first',
        ),
        'lastClass' => array(
          'default' => 'views-row-last',
        ),
        'oddClass' => array(
          'default' => 'views-row-odd',
        ),
        'evenClass' => array(
          'default' => 'views-row-even',
        ),
        'rowClassPrefix' => array(
          'default' => 'views-row-',
        ),
      ),
    );
    $options['ping'] = array(
      'default' => FALSE,
      'bool' => TRUE,
    );
    $options['ping_base_path'] = array(
      'default' => '',
    );
    $options['ping_arguments'] = array(
      'default' => '',
    );
    $options['trigger_onload'] = array(
      'default' => FALSE,
      'bool' => TRUE,
    );
    return $options;
  }
  function options_form(&$form, &$form_state) {
    if (module_exists('nodejs')) {
      $form['nodejs'] = array(
        '#type' => 'checkbox',
        '#title' => t('Use Node.js to refresh the view instead of interval pings'),
        '#default_value' => $this->options['nodejs'],
      );
    }
    else {
      $form['nodejs'] = array(
        '#type' => 'value',
        '#value' => FALSE,
      );
    }
    $form['interval'] = array(
      '#type' => 'textfield',
      '#title' => t('Interval to check for new items'),
      '#default_value' => $this->options['interval'],
      '#field_suffix' => 'milliseconds',
      '#required' => TRUE,
      '#dependency' => array(
        'edit-options-nodejs' => array(
          0,
        ),
      ),
    );
    $form['incremental'] = array(
      '#type' => 'checkbox',
      '#title' => t('Use a secondary view display to incrementally insert new items only'),
      '#default_value' => $this->options['incremental'],
    );
    $options = array();
    if ($this->view->display) {
      foreach ($this->view->display as $display) {
        if ($display->display_plugin == 'page') {

          // @TODO: check secondary display arguments.
          $options[$display->id] = $display->display_title;
        }
      }
    }
    $incremental_advanced = $this->options['incremental_advanced'];
    $form['display'] = array(
      '#type' => 'select',
      '#title' => t('Secondary display'),
      '#default_value' => $this->options['display'],
      '#description' => t('Only displays of type page are eligible. Additionally the display must have a timestamp argument of the <em>(with operator)</em> variant. For example <em>Node: Post date (with operator)</em>.'),
      '#options' => $options,
      '#dependency' => array(
        'edit-options-incremental' => array(
          1,
        ),
      ),
    );
    $form['incremental_advanced'] = array(
      '#type' => 'fieldset',
      '#title' => t('Advanced'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#dependency' => array(
        'edit-options-incremental' => array(
          1,
        ),
      ),
      '#description' => t('Advanced settings for incremental display. Unless your view is using an overridden template, the defaults below should be fine.'),
    );
    $form['incremental_advanced']['sourceSelector'] = array(
      '#type' => 'textfield',
      '#title' => t('Source selector'),
      '#default_value' => $incremental_advanced['sourceSelector'],
      '#description' => t('A jQuery selector expression representing the main view container of your secondary display.'),
    );
    $form['incremental_advanced']['targetSelector'] = array(
      '#type' => 'textfield',
      '#title' => t('Target selector'),
      '#default_value' => $incremental_advanced['targetSelector'],
      '#description' => t('A jQuery selector expression representing the main view container of your primary display.'),
    );
    $form['incremental_advanced']['emptySelector'] = array(
      '#type' => 'textfield',
      '#title' => t('Empty selector'),
      '#default_value' => $incremental_advanced['emptySelector'],
      '#description' => t('A jQuery selector expression representing the main view container in case of empty results.'),
    );
    $form['incremental_advanced']['afterSelector'] = array(
      '#type' => 'textfield',
      '#title' => t('Header selector'),
      '#default_value' => $incremental_advanced['afterSelector'],
      '#description' => t('A jQuery selector expression representing the view header, in case the header is displayed with empty results.'),
    );
    $form['incremental_advanced']['targetStructure'] = array(
      '#type' => 'textfield',
      '#title' => t('Target structure'),
      '#default_value' => $incremental_advanced['targetStructure'],
      '#description' => t('An HTML fragment describing the view skeleton in case of empty results.'),
    );
    $form['incremental_advanced']['firstClass'] = array(
      '#type' => 'textfield',
      '#title' => t('First row class'),
      '#default_value' => $incremental_advanced['firstClass'],
      '#description' => t('A class to be added to the first result row.'),
    );
    $form['incremental_advanced']['lastClass'] = array(
      '#type' => 'textfield',
      '#title' => t('Last row class'),
      '#default_value' => $incremental_advanced['lastClass'],
      '#description' => t('A class to be added to the last result row.'),
    );
    $form['incremental_advanced']['oddClass'] = array(
      '#type' => 'textfield',
      '#title' => t('Odd rows class'),
      '#default_value' => $incremental_advanced['oddClass'],
      '#description' => t('A class to be added to each odd result row.'),
    );
    $form['incremental_advanced']['evenClass'] = array(
      '#type' => 'textfield',
      '#title' => t('Even rows class'),
      '#default_value' => $incremental_advanced['evenClass'],
      '#description' => t('A class to be added to each even result row.'),
    );
    $form['incremental_advanced']['rowClassPrefix'] = array(
      '#type' => 'textfield',
      '#title' => t('Row class prefix'),
      '#default_value' => $incremental_advanced['rowClassPrefix'],
      '#description' => t('The prefix of a class to be added to each result row. The row number will be appended to this prefix.'),
    );
    $form['ping'] = array(
      '#type' => 'checkbox',
      '#title' => t('Use a ping url'),
      '#default_value' => $this->options['ping'],
      '#description' => t('Use a custom script for faster check of new items. See <code>views_autorefresh_ping.default.php</code> in <code>views_autorefresh</code> folder for reference.'),
    );
    $form['ping_base_path'] = array(
      '#type' => 'textfield',
      '#title' => t('Path to the ping script'),
      '#default_value' => $this->options['ping_base_path'],
      '#description' => t('This path is relative to the Drupal root.'),
      '#dependency' => array(
        'edit-options-ping' => array(
          1,
        ),
      ),
    );
    $form['ping_arguments'] = array(
      '#type' => 'textarea',
      '#title' => t('Ping arguments'),
      '#default_value' => $this->options['ping_arguments'],
      '#description' => t('A PHP script that generates arguments that will be sent on the ping URL as query parameters. Do not surround with <code>&lt;?php&gt;</code> tag.'),
      '#dependency' => array(
        'edit-options-ping' => array(
          1,
        ),
      ),
    );
    $form['trigger_onload'] = array(
      '#type' => 'checkbox',
      '#title' => t('Trigger Refresh on Load'),
      '#default_value' => $this->options['trigger_onload'],
    );
  }
  function options_validate(&$form, &$form_state) {
    if (!is_numeric($form_state['values']['options']['interval'])) {
      form_set_error('interval', t('Invalid interval.'));
    }
    if ($form_state['values']['options']['ping']) {
      $ping_base_path = DRUPAL_ROOT . '/' . $form_state['values']['options']['ping_base_path'];
      if (!file_exists($ping_base_path)) {
        form_set_error('ping_base_path', t('Ping script not found at %path.', array(
          '%path' => $ping_base_path,
        )));
      }
      $args = $this
        ->eval_ping_arguments($form_state['values']['options']['ping_arguments']);
      if (!is_array($args)) {
        form_set_error('ping_arguments', t('Error in ping arguments script: %error', array(
          '%error' => $args,
        )));
      }
    }
  }
  function options_submit(&$form, &$form_state) {
    $this->view->display_handler
      ->set_option('use_ajax', TRUE);
  }
  function render($empty = FALSE) {
    $args = array();
    $args['view'] = $this->view;
    $args['nodejs'] = !empty($this->options['nodejs']);
    $args['interval'] = $this->options['interval'];
    if ($this->options['ping']) {
      $args['ping'] = array(
        'ping_base_path' => $this->options['ping_base_path'],
        'ping_args' => $this
          ->eval_ping_arguments($this->options['ping_arguments']),
      );
    }
    $args['trigger_onload'] = $this->options['trigger_onload'];
    if ($this->options['incremental']) {
      $display = $this->view->display[$this->options['display']];
      $incremental_advanced = $this->options['incremental_advanced'];
      $args['incremental'] = array(
        'view_base_path' => $display->display_options['path'],
        'view_display_id' => $display->id,
        'view_name' => $this->view->name,
        'sourceSelector' => $incremental_advanced['sourceSelector'],
        'targetSelector' => $incremental_advanced['targetSelector'],
        'emptySelector' => $incremental_advanced['emptySelector'],
        'afterSelector' => $incremental_advanced['afterSelector'],
        'targetStructure' => $incremental_advanced['targetStructure'],
        'firstClass' => $incremental_advanced['firstClass'],
        'lastClass' => $incremental_advanced['lastClass'],
        'oddClass' => $incremental_advanced['oddClass'],
        'evenClass' => $incremental_advanced['evenClass'],
        'rowClassPrefix' => $incremental_advanced['rowClassPrefix'],
      );
    }
    return theme('views_autorefresh', $args);
  }
  function eval_ping_arguments($script) {
    $args = array();
    if (empty($script)) {
      return $args;
    }

    // @TODO determine if necessary
    // Make view visible to script.
    $view = $this->view;

    // Avoid Drupal's error handler: http://www.php.net/manual/en/function.restore-error-handler.php#93261
    set_error_handler(create_function('$errno,$errstr', 'return false;'));
    $return = eval($script);
    if ($return === FALSE) {
      $error = error_get_last();
      $args = $error['message'];
    }
    else {
      if (is_array($return)) {
        $args = $return;
      }
      else {
        $args = t('expecting an array of arguments, got a !type instead.', array(
          '!type' => gettype($return),
        ));
      }
    }
    restore_error_handler();
    return $args;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
views_autorefresh_handler_area_autorefresh::eval_ping_arguments function
views_autorefresh_handler_area_autorefresh::init function Overrides views_handler_area::init(). Overrides views_handler_area::init
views_autorefresh_handler_area_autorefresh::options_form function Default options form that provides the label widget that all fields should have. Overrides views_handler_area::options_form
views_autorefresh_handler_area_autorefresh::options_submit function Perform any necessary changes to the form values prior to storage. There is no need for this function to actually store the data. Overrides views_handler::options_submit
views_autorefresh_handler_area_autorefresh::options_validate function Validate the options form. Overrides views_handler::options_validate
views_autorefresh_handler_area_autorefresh::option_definition function Information about options for all kinds of purposes will be held here. Overrides views_handler_area::option_definition
views_autorefresh_handler_area_autorefresh::render function Render the area. Overrides views_handler_area::render
views_handler::$handler_type public property The type of the handler, for example filter/footer/field.
views_handler::$query public property Where the $query object will reside:. 1
views_handler::$real_field public property The actual field in the database table, maybe different on other kind of query plugins/special handlers.
views_handler::$relationship public property The relationship used for this field.
views_handler::$table_alias public property The alias of the table of this handler which is used in the query.
views_handler::$view public property The top object of a view. Overrides views_object::$view
views_handler::accept_exposed_input public function Take input from exposed handlers and assign to this handler, if necessary. 1
views_handler::access public function Check whether current user has access to this handler. 10
views_handler::broken public function Determine if the handler is considered 'broken'. 6
views_handler::can_expose public function Determine if a handler can be exposed. 2
views_handler::case_transform public function Transform a string by a certain method.
views_handler::ensure_my_table public function Ensure the main table for this handler is in the query. This is used a lot. 8
views_handler::exposed_form public function Render our chunk of the exposed handler form when selecting. 1
views_handler::exposed_info public function Get information about the exposed form for the form renderer. 1
views_handler::exposed_submit public function Submit the exposed handler form.
views_handler::exposed_validate public function Validate the exposed handler form. 4
views_handler::expose_form public function Form for exposed handler options. 2
views_handler::expose_options public function Set new exposed option defaults when exposed setting is flipped on. 2
views_handler::expose_submit public function Perform any necessary changes to the form exposes prior to storage. There is no need for this function to actually store the data.
views_handler::expose_validate public function Validate the options form. 1
views_handler::extra_options public function Provide defaults for the handler.
views_handler::extra_options_form public function Provide a form for setting options. 1
views_handler::extra_options_submit public function Perform any necessary changes to the form values prior to storage. There is no need for this function to actually store the data.
views_handler::extra_options_validate public function Validate the options form.
views_handler::get_field public function Shortcut to get a handler's raw field value.
views_handler::get_join public function Get the join object that should be used for this handler.
views_handler::groupby_form public function Provide a form for aggregation settings. 1
views_handler::groupby_form_submit public function Perform any necessary changes to the form values prior to storage. There is no need for this function to actually store the data. 1
views_handler::has_extra_options public function If a handler has 'extra options' it will get a little settings widget and another form called extra_options. 1
views_handler::is_a_group public function Returns TRUE if the exposed filter works like a grouped filter. 1
views_handler::is_exposed public function Determine if this item is 'exposed', meaning it provides form elements to let users modify the view.
views_handler::multiple_exposed_input public function Define if the exposed input has to be submitted multiple times. This is TRUE when exposed filters grouped are using checkboxes as widgets. 1
views_handler::needs_style_plugin public function Determine if the argument needs a style plugin. 1
views_handler::placeholder public function Provides a unique placeholders for handlers.
views_handler::post_execute public function Run after the view is executed, before the result is cached. 1
views_handler::pre_query public function Run before the view is built. 1
views_handler::sanitize_value public function Sanitize the value for output.
views_handler::set_relationship public function Called just prior to query(), this lets a handler set up any relationship it needs.
views_handler::show_expose_button public function Shortcut to display the expose/hide button. 2
views_handler::show_expose_form public function Shortcut to display the exposed options form.
views_handler::store_exposed_input public function If set to remember exposed input in the session, store it there. 1
views_handler::ui_name public function Return a string representing this handler's name in the UI. 9
views_handler::validate public function Validates the handler against the complete View. 1
views_handler_area::admin_summary public function Provide extra data to the administration form. Overrides views_handler::admin_summary
views_handler_area::label public function
views_handler_area::query public function Don't run a query. 1
views_handler_area::use_group_by public function Area handlers shouldn't have groupby. Overrides views_handler::use_group_by
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