[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/views_slideshow/contrib/views_slideshow_singleframe/ -> views_slideshow_singleframe.theme.inc (source)

   1  <?php
   2  
   3  /**
   4   * @file
   5   * Theme & preprocess functions for the Views Slideshow: SingleFrame module.
   6   */
   7  
   8  /**
   9   * Implements template_preprocess_hook_THEMENAME().
  10   */
  11  function template_preprocess_views_slideshow_singleframe(&$vars) {
  12    $options = $vars['options'];
  13    $rows = $vars['rows'];
  14    $view = $vars['view'];
  15    $vss_id = $view->name . '-' . $view->current_display;
  16    $settings = $options['views_slideshow_singleframe'];
  17    
  18    // Cast the strings into int or bool as necessary.
  19    $new_settings = array();
  20    foreach ($settings as $key => $value) {
  21      if (is_string($value)) {
  22        $value = trim($value);
  23  
  24        if (is_numeric($value)) {
  25          $value = (int)$value;
  26        }
  27        elseif (strtolower($value) == 'true') {
  28          $value = TRUE;
  29        }
  30        elseif (strtolower($value) == 'false') {
  31          $value = FALSE;
  32        }
  33      }
  34      
  35      $new_settings[$key] = $value;
  36    }
  37  
  38    $settings = array_merge(
  39      array(
  40        'num_divs' => sizeof($vars['rows']),
  41        'id_prefix' => '#views_slideshow_singleframe_main_',
  42        'div_prefix' => '#views_slideshow_singleframe_div_',
  43        'vss_id' => $vss_id,
  44      ),
  45      $new_settings
  46    );
  47  
  48    // We need to go through the current js setting values to make sure the one we
  49    // want to add is not already there. If it is already there then append -[num]
  50    // to the id to make it unique.
  51    $slideshow_count = 1;
  52    $current_settings = drupal_add_js();
  53    foreach ($current_settings['setting'] AS $current_setting) {
  54      if (isset($current_setting['viewsSlideshowSingleFrame'])) {
  55        $current_keys = array_keys($current_setting['viewsSlideshowSingleFrame']);
  56        if (stristr($current_keys[0], '#views_slideshow_singleframe_main_' . $vss_id)) {
  57          $slideshow_count++;
  58        }
  59      }
  60    }
  61  
  62    if ($slideshow_count > 1) {
  63      $vss_id .= '-' . $slideshow_count;
  64      $settings['vss_id'] = $vss_id;  
  65    }
  66  
  67    drupal_add_js(array('viewsSlideshowSingleFrame' => array('#views_slideshow_singleframe_main_' . $vss_id => $settings)), 'setting');
  68  
  69    $hidden_elements = theme('views_slideshow_singleframe_no_display_section', $view, $rows, $vss_id, $options['mode']);
  70    $vars['slideshow'] = theme('views_slideshow_main_section', $vss_id, $hidden_elements, 'views_slideshow_singleframe');
  71  
  72    $singleframe = $vars['options']['views_slideshow_singleframe'];
  73  
  74    // Only show controls when there is more than one result.
  75    $vars['controls_top'] = '';
  76    $vars['controls_bottom'] = '';
  77    if ($settings['num_divs'] > 1) {
  78      if ($singleframe['controls'] == 1) {
  79        $vars['controls_top'] = theme('views_slideshow_singleframe_controls', $vss_id, $view, $options);
  80      }
  81      elseif ($singleframe['controls'] == 2) {
  82        $vars['controls_bottom'] = theme('views_slideshow_singleframe_controls', $vss_id, $view, $options);
  83      }
  84    }
  85  
  86    $vars['pager_top'] = '';
  87    $vars['pager_bottom'] = '';
  88    if ($singleframe['pager'] == 1) {
  89      $vars['pager_top'] = theme('views_slideshow_singleframe_pager', $vss_id, $view, $options);
  90    }
  91    elseif ($singleframe['pager'] == 2) {
  92      $vars['pager_bottom'] = theme('views_slideshow_singleframe_pager', $vss_id, $view, $options);
  93    }
  94    
  95    $vars['image_count_top'] = '';
  96    $vars['image_count_bottom'] = '';
  97    if ($singleframe['image_count'] == 1) {
  98      $vars['image_count_top'] = theme('views_slideshow_singleframe_image_count', $vss_id, $view, $options);
  99    }
 100    elseif ($singleframe['image_count'] == 2) {
 101      $vars['image_count_bottom'] = theme('views_slideshow_singleframe_image_count', $vss_id, $view, $options);
 102    }
 103  }
 104  
 105  /**
 106   * Add the HTML for the hidden slideshow elements.
 107   *
 108   * @ingroup themeable
 109   */
 110  function theme_views_slideshow_singleframe_no_display_section($view, $rows, $vss_id, $mode) {
 111    // Retrive the number of itmes per frame
 112    if (isset($view->display_handler->display->display_options['style_options']['views_slideshow_singleframe']['items_per_slide']) && $view->display_handler->display->display_options['style_options']['views_slideshow_singleframe']['items_per_slide'] > 0) {
 113      $items_per_slide = $view->display_handler->display->display_options['style_options']['views_slideshow_singleframe']['items_per_slide'];
 114    }
 115    elseif (isset($view->display['default']->display_options['style_options']['views_slideshow_singleframe']['items_per_slide']) && $view->display['default']->display_options['style_options']['views_slideshow_singleframe']['items_per_slide'] > 0) {
 116      $items_per_slide = $view->display['default']->display_options['style_options']['views_slideshow_singleframe']['items_per_slide'];
 117    }
 118    else {
 119      $items_per_slide = 1;
 120    }
 121    
 122    // Add the slideshow elements.
 123    $attributes['id'] = "views_slideshow_singleframe_teaser_section_" . $vss_id;
 124    $attributes['class'] = 'views_slideshow_singleframe_teaser_section';
 125    $attributes = drupal_attributes($attributes);
 126  
 127    $output = "<div$attributes>";
 128    
 129    $items = array();
 130    $slideshow_count = 0;
 131    foreach ($rows as $count => $item) {
 132      $items[] = $item;
 133      if (count($items) == $items_per_slide || $count == (count($rows)-1)) {
 134        $output .= theme('views_slideshow_singleframe_no_display_teaser', $items, $vss_id, $slideshow_count);
 135        $items = array();
 136        $slideshow_count++;
 137      }
 138    }
 139    $output .= "</div>\n";
 140  
 141    return $output;
 142  }
 143  
 144  /**
 145   * Views Slideshow slideshow elements.
 146   *
 147   * @ingroup themeable
 148   */
 149  function theme_views_slideshow_singleframe_no_display_teaser($items, $vss_id, $count) {
 150    $current = $count + 1;
 151    $classes = array(
 152      'views_slideshow_singleframe_slide',
 153      "views_slideshow_slide views-row-$current",
 154    );
 155    if ($count) {
 156      $classes[] = 'views_slideshow_singleframe_hidden';
 157    }
 158    $classes[] = ($count % 2) ? 'views-row-even' : 'views-row-odd';
 159  
 160    $attributes['class'] = implode(' ', $classes);
 161    $attributes['id'] = "views_slideshow_singleframe_div_" . $vss_id . "_" . $count;
 162    $attributes = drupal_attributes($attributes);
 163  
 164    $output = "<div$attributes>";
 165    foreach ($items as $item_count => $item) {
 166      $item_class = 'views-row views-row-' . $item_count;
 167      if (!$item_count) {
 168        $item_class .= ' views-row-first';
 169      }
 170      if ($item_count % 2) {
 171        $item_class .= ' views-row-even';
 172      }
 173      else {
 174        $item_class .= ' views-row-odd';
 175      }
 176      $output .= '<div class="' . $item_class . '">' . "\n";
 177      $output .= $item . "\n";
 178      $output .= '</div>' . "\n";
 179    }
 180  
 181    $output .= "</div>\n";
 182    return $output;
 183  }
 184  
 185  /**
 186   * The slideshow controls.
 187   *
 188   * @ingroup themeable
 189   */
 190  function theme_views_slideshow_singleframe_controls($vss_id, $view, $options) {
 191    $classes = array(
 192      'views_slideshow_singleframe_controls',
 193      'views_slideshow_controls',
 194    );
 195  
 196    $attributes['class'] = implode(' ', $classes);
 197    $attributes['id'] = "views_slideshow_singleframe_controls_" . $vss_id;
 198    $attributes = drupal_attributes($attributes);
 199  
 200    $output = "<div$attributes>";
 201    $output .= theme('views_slideshow_singleframe_control_previous', $vss_id, $view, $options);
 202    if ($options['views_slideshow_singleframe']['timeout']) {
 203      $output .= theme('views_slideshow_singleframe_control_pause', $vss_id, $view, $options);
 204    }
 205    $output .= theme('views_slideshow_singleframe_control_next', $vss_id, $view, $options);
 206    $output .= "</div>\n";
 207    return $output;
 208  }
 209  
 210  /**
 211   * Views Slideshow: "previous" control.
 212   *
 213   * @ingroup themeable
 214   */
 215  function theme_views_slideshow_singleframe_control_previous($vss_id, $view, $options) {
 216    return l(t('Previous'), '#', array(
 217      'attributes' => array(
 218        'class' => 'views_slideshow_singleframe_previous views_slideshow_previous',
 219        'id' => "views_slideshow_singleframe_prev_" . $vss_id,
 220      ),
 221      'fragment' => ' ',
 222      'external' => TRUE,
 223    ));
 224  }
 225  
 226  /**
 227   * Views Slideshow: "pause" control.
 228   *
 229   * @ingroup themeable
 230   */
 231  function theme_views_slideshow_singleframe_control_pause($vss_id, $view, $options) {
 232    return l(t('Pause'), '', array(
 233      'attributes' => array(
 234        'class' => 'views_slideshow_singleframe_pause views_slideshow_pause',
 235        'id' => "views_slideshow_singleframe_playpause_" . $vss_id,
 236      ),
 237      'fragment' => ' ',
 238      'external' => TRUE,
 239    ));
 240  }
 241  
 242  /**
 243   * Views Slideshow: "next" control.
 244   *
 245   * @ingroup themeable
 246   */
 247  function theme_views_slideshow_singleframe_control_next($vss_id, $view, $options) {
 248    return l(t('Next'), '#', array(
 249      'attributes' => array(
 250        'class' => 'views_slideshow_singleframe_next views_slideshow_next',
 251        'id' => "views_slideshow_singleframe_next_" . $vss_id,
 252      ),
 253      'fragment' => ' ',
 254      'external' => TRUE,
 255    ));
 256  }
 257  
 258  /**
 259   * Views Slideshow: pager.
 260   *
 261   * @ingroup themeable
 262   */
 263  function theme_views_slideshow_singleframe_pager($vss_id, $view, $options) {
 264    $pager_type = $options['views_slideshow_singleframe']['pager_type'];
 265  
 266    $attributes['class'] = "views_slideshow_singleframe_pager views_slideshow_pager$pager_type";
 267    $attributes['id'] = "views_slideshow_singleframe_pager_" . $vss_id;
 268    $attributes = drupal_attributes($attributes);
 269  
 270    return "<div$attributes></div>";
 271  }
 272  
 273  /**
 274   * Views Slideshow: image counter.
 275   *
 276   * @ingroup themeable
 277   */
 278  function theme_views_slideshow_singleframe_image_count($vss_id, $view, $options) {
 279    $attributes['class'] = 'views_slideshow_singleframe_image_count views_slideshow_image_count';
 280    $attributes['id'] = "views_slideshow_singleframe_image_count_" . $vss_id;
 281    $attributes = drupal_attributes($attributes);
 282  
 283    $counter = '<span class="num">1</span> ' . t('of') . ' <span class="total">1</span>';
 284  
 285    return "<div$attributes>$counter</div>";
 286  }


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7