| 1 |
<?php
|
| 2 |
// $Id: views_rotator.module,v 1.3 2008/08/24 00:06:44 mfer Exp $
|
| 3 |
/**
|
| 4 |
* @file
|
| 5 |
* Provide a rotating item display style for Views.
|
| 6 |
*
|
| 7 |
* This is a placeholder file so drupal will enable the module. All logic is contained in
|
| 8 |
* other files located with the module.
|
| 9 |
*/
|
| 10 |
|
| 11 |
/**
|
| 12 |
* Implementation of hook_views_api().
|
| 13 |
*/
|
| 14 |
function views_rotator_views_api() {
|
| 15 |
return array('api' => 2);
|
| 16 |
}
|
| 17 |
|
| 18 |
/**
|
| 19 |
* Template function for views_rotator
|
| 20 |
*
|
| 21 |
* @param array $vars
|
| 22 |
* Array of template variables.
|
| 23 |
*/
|
| 24 |
function template_preprocess_views_view_rotator(&$vars) {
|
| 25 |
drupal_add_css(drupal_get_path('module', 'views_rotator') .'/views-rotator.css');
|
| 26 |
|
| 27 |
$view = $vars['view'];
|
| 28 |
$options = $view->style_plugin->options;
|
| 29 |
|
| 30 |
$vars['views_rotator_id'] = 'views-rotator-'. $view->name .'-'. $view->current_display;
|
| 31 |
|
| 32 |
drupal_add_js(drupal_get_path('module', 'views_rotator') .'/views-rotator.js');
|
| 33 |
|
| 34 |
$view_settings['fx'] = 'fade';
|
| 35 |
$view_settings['timeout'] = check_plain($options['timeout']) * 1000;
|
| 36 |
$view_settings['speed'] = check_plain($options['speed']) * 1000;
|
| 37 |
$view_settings['pause'] = check_plain($options['pause']);
|
| 38 |
$view_settings['cleartype'] = 1;
|
| 39 |
|
| 40 |
if (!empty($options['back_next_buttons'])) {
|
| 41 |
$view_settings['next'] = '#'. $vars['views_rotator_id'] .'-views-rotator-next';
|
| 42 |
$view_settings['prev'] = '#'. $vars['views_rotator_id'] .'-views-rotator-prev';
|
| 43 |
}
|
| 44 |
|
| 45 |
if (empty($options['height'])) {
|
| 46 |
$view_settings['height'] = 'auto';
|
| 47 |
$view_settings['auto_height'] = 1;
|
| 48 |
}
|
| 49 |
|
| 50 |
drupal_add_js(array('views_rotator' => array($vars['views_rotator_id'] => $view_settings)), 'setting');
|
| 51 |
}
|
| 52 |
|
| 53 |
/**
|
| 54 |
* Only returns true the first time it's called for an id
|
| 55 |
*
|
| 56 |
* @param $id
|
| 57 |
* A uniqe view id.
|
| 58 |
*
|
| 59 |
* @return bool
|
| 60 |
* TRUE for the first time called for a given $id
|
| 61 |
* FALSE for each time after that
|
| 62 |
*/
|
| 63 |
function theme_views_rotator_display_item($id) {
|
| 64 |
static $display = array();
|
| 65 |
|
| 66 |
if (!isset($display[$id])) $display[$id] = FALSE;
|
| 67 |
|
| 68 |
$output = $display[$id];
|
| 69 |
|
| 70 |
if ($display[$id] == FALSE) $display[$id] = TRUE;
|
| 71 |
|
| 72 |
return $output;
|
| 73 |
}
|