class views_autorefresh_handler_area_autorefresh in Views Auto-Refresh 7
Same name and namespace in other branches
- 7.2 views/views_autorefresh_handler_area_autorefresh.inc \views_autorefresh_handler_area_autorefresh
Base class for area handlers.
Hierarchy
- class \views_object
- class \views_handler
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><?php></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
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
views_autorefresh_handler_area_autorefresh:: |
function | |||
views_autorefresh_handler_area_autorefresh:: |
function |
Overrides views_handler_area::init(). Overrides views_handler_area:: |
||
views_autorefresh_handler_area_autorefresh:: |
function |
Default options form that provides the label widget that all fields should
have. Overrides views_handler_area:: |
||
views_autorefresh_handler_area_autorefresh:: |
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:: |
||
views_autorefresh_handler_area_autorefresh:: |
function |
Validate the options form. Overrides views_handler:: |
||
views_autorefresh_handler_area_autorefresh:: |
function |
Information about options for all kinds of purposes will be held here. Overrides views_handler_area:: |
||
views_autorefresh_handler_area_autorefresh:: |
function |
Render the area. Overrides views_handler_area:: |
||
views_handler:: |
public | property | The type of the handler, for example filter/footer/field. | |
views_handler:: |
public | property | Where the $query object will reside:. | 1 |
views_handler:: |
public | property | The actual field in the database table, maybe different on other kind of query plugins/special handlers. | |
views_handler:: |
public | property | The relationship used for this field. | |
views_handler:: |
public | property | The alias of the table of this handler which is used in the query. | |
views_handler:: |
public | property |
The top object of a view. Overrides views_object:: |
|
views_handler:: |
public | function | Take input from exposed handlers and assign to this handler, if necessary. | 1 |
views_handler:: |
public | function | Check whether current user has access to this handler. | 10 |
views_handler:: |
public | function | Determine if the handler is considered 'broken'. | 6 |
views_handler:: |
public | function | Determine if a handler can be exposed. | 2 |
views_handler:: |
public | function | Transform a string by a certain method. | |
views_handler:: |
public | function | Ensure the main table for this handler is in the query. This is used a lot. | 8 |
views_handler:: |
public | function | Render our chunk of the exposed handler form when selecting. | 1 |
views_handler:: |
public | function | Get information about the exposed form for the form renderer. | 1 |
views_handler:: |
public | function | Submit the exposed handler form. | |
views_handler:: |
public | function | Validate the exposed handler form. | 4 |
views_handler:: |
public | function | Form for exposed handler options. | 2 |
views_handler:: |
public | function | Set new exposed option defaults when exposed setting is flipped on. | 2 |
views_handler:: |
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:: |
public | function | Validate the options form. | 1 |
views_handler:: |
public | function | Provide defaults for the handler. | |
views_handler:: |
public | function | Provide a form for setting options. | 1 |
views_handler:: |
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:: |
public | function | Validate the options form. | |
views_handler:: |
public | function | Shortcut to get a handler's raw field value. | |
views_handler:: |
public | function | Get the join object that should be used for this handler. | |
views_handler:: |
public | function | Provide a form for aggregation settings. | 1 |
views_handler:: |
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:: |
public | function | If a handler has 'extra options' it will get a little settings widget and another form called extra_options. | 1 |
views_handler:: |
public | function | Returns TRUE if the exposed filter works like a grouped filter. | 1 |
views_handler:: |
public | function | Determine if this item is 'exposed', meaning it provides form elements to let users modify the view. | |
views_handler:: |
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:: |
public | function | Determine if the argument needs a style plugin. | 1 |
views_handler:: |
public | function | Provides a unique placeholders for handlers. | |
views_handler:: |
public | function | Run after the view is executed, before the result is cached. | 1 |
views_handler:: |
public | function | Run before the view is built. | 1 |
views_handler:: |
public | function | Sanitize the value for output. | |
views_handler:: |
public | function | Called just prior to query(), this lets a handler set up any relationship it needs. | |
views_handler:: |
public | function | Shortcut to display the expose/hide button. | 2 |
views_handler:: |
public | function | Shortcut to display the exposed options form. | |
views_handler:: |
public | function | If set to remember exposed input in the session, store it there. | 1 |
views_handler:: |
public | function | Return a string representing this handler's name in the UI. | 9 |
views_handler:: |
public | function | Validates the handler against the complete View. | 1 |
views_handler_area:: |
public | function |
Provide extra data to the administration form. Overrides views_handler:: |
|
views_handler_area:: |
public | function | ||
views_handler_area:: |
public | function | Don't run a query. | 1 |
views_handler_area:: |
public | function |
Area handlers shouldn't have groupby. Overrides views_handler:: |
|
views_object:: |
public | property | Handler's definition. | |
views_object:: |
public | property | Except for displays, options for the object will be held here. | 1 |
views_object:: |
function | Collect this handler's option definition and alter them, ready for use. | ||
views_object:: |
public | function | Views handlers use a special construct function. | 4 |
views_object:: |
public | function | Destructor. | 2 |
views_object:: |
public | function | 1 | |
views_object:: |
public | function | ||
views_object:: |
public | function | Always exports the option, regardless of the default value. | |
views_object:: |
public | function | Set default options on this object. | 1 |
views_object:: |
public | function | Set default options. | |
views_object:: |
public | function | Let the handler know what its full definition is. | |
views_object:: |
public | function | Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away. | |
views_object:: |
public | function | Unpack a single option definition. | |
views_object:: |
public | function | Unpacks each handler to store translatable texts. | |
views_object:: |
public | function |