| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @file 5 * Theme & preprocess functions for the Views Slideshow: ThumbnailHover module. 6 */ 7 8 /** 9 * Implements template_preprocess_hook_THEMENAME(). 10 */ 11 function template_preprocess_views_slideshow_thumbnailhover(&$vars) { 12 $options = $vars['options']; 13 $view = $vars['view']; 14 $rows = $vars['rows']; 15 $vss_id = $view->name . '-' . $view->current_display; 16 $settings = $options['views_slideshow_thumbnailhover']; 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 'teasers_last' => (isset($options['thumbnailhover']['teasers_last']) && $options['thumbnailhover']['teasers_last']) ? TRUE : FALSE, 42 'id_prefix' => '#views_slideshow_thumbnailhover_main_', 43 'div_prefix' => '#views_slideshow_thumbnailhover_div_', 44 'vss_id' => $vss_id, 45 'view_id' => $vss_id, 46 ), 47 $new_settings 48 ); 49 50 // We need to go through the current js setting values to make sure the one we 51 // want to add is not already there. If it is already there then append -[num] 52 // to the id to make it unique. 53 $slideshow_count = 1; 54 $current_settings = drupal_add_js(); 55 foreach ($current_settings['setting'] AS $current_setting) { 56 if (isset($current_setting['viewsSlideshowThumbnailHover'])) { 57 $current_keys = array_keys($current_setting['viewsSlideshowThumbnailHover']); 58 if (stristr($current_keys[0], '#views_slideshow_thumbnailhover_main_' . $vss_id)) { 59 $slideshow_count++; 60 } 61 } 62 } 63 64 if ($slideshow_count > 1) { 65 $vss_id .= '-' . $slideshow_count; 66 $settings['vss_id'] = $vss_id; 67 } 68 69 drupal_add_js(array('viewsSlideshowThumbnailHover' => array( 70 "#views_slideshow_thumbnailhover_main_" . $vss_id => $settings)), 'setting'); 71 72 // Add the hoverIntent plugin. 73 if ($settings['pager_event'] == 'hoverIntent') { 74 if (module_exists('jq')) { 75 $loaded_plugins = jq_plugins(); 76 if (!empty($loaded_plugins['hoverIntent'])) { 77 jq_add('hoverIntent'); 78 } 79 } 80 if (module_exists('hoverintent')) { 81 hoverintent_add(); 82 } 83 } 84 85 $teaser = ($options['views_slideshow_thumbnailhover']['hover_breakout'] == 'teaser') ? TRUE : FALSE; 86 $hidden_elements = theme('views_slideshow_thumbnailhover_no_display_section', $view, $rows, $vss_id, $options, $teaser); 87 $vars['slideshow'] = theme('views_slideshow_main_section', $vss_id, $hidden_elements, 'views_slideshow_thumbnailhover'); 88 89 $thumbnailhover = $vars['options']['views_slideshow_thumbnailhover']; 90 91 // Only show controls when there is more than one result. 92 $vars['controls_top'] = ''; 93 $vars['controls_bottom'] = ''; 94 if ($settings['num_divs'] > 1) { 95 if ($thumbnailhover['controls'] == 1) { 96 $vars['controls_top'] = theme('views_slideshow_thumbnailhover_controls', $vss_id, $view, $options); 97 } 98 elseif ($thumbnailhover['controls'] == 2) { 99 $vars['controls_bottom'] = theme('views_slideshow_thumbnailhover_controls', $vss_id, $view, $options); 100 } 101 } 102 103 $vars['breakout_top'] = ''; 104 $vars['breakout_bottom'] = ''; 105 if (!$thumbnailhover['teasers_last']) { 106 $vars['breakout_top'] = theme('views_slideshow_thumbnailhover_breakout_teasers', $view, $rows, $vss_id, $options); 107 } 108 else { 109 $vars['breakout_bottom'] = theme('views_slideshow_thumbnailhover_breakout_teasers', $view, $rows, $vss_id, $options); 110 } 111 112 $vars['image_count_top'] = ''; 113 $vars['image_count_bottom'] = ''; 114 if ($thumbnailhover['image_count'] == 1) { 115 $vars['image_count_top'] = theme('views_slideshow_thumbnailhover_image_count', $vss_id, $view, $options); 116 } 117 elseif ($thumbnailhover['image_count'] == 2) { 118 $vars['image_count_bottom'] = theme('views_slideshow_thumbnailhover_image_count', $vss_id, $view, $options); 119 } 120 } 121 122 /** 123 * Add the the HTML for the hidden slideshow elements. 124 * 125 * @ingroup themeable 126 */ 127 function theme_views_slideshow_thumbnailhover_no_display_section($view, $rows, $vss_id, $options, $teaser = TRUE) { 128 // Add the slideshow elements. 129 $attributes['id'] = "views_slideshow_thumbnailhover_teaser_section_" . $vss_id; 130 $attributes['class'] = 'views_slideshow_thumbnailhover_teaser_section views_slideshow_teaser_section'; 131 $attributes = drupal_attributes($attributes); 132 133 $output = "<div$attributes>"; 134 foreach ($view->result as $count => $node) { 135 if ($view->display_handler->uses_fields()) { 136 $rendered = ''; 137 foreach ($options['views_slideshow_thumbnailhover']['main_fields'] as $field => $use) { 138 if ($use !== 0 && is_object($view->field[$field]) && !$view->field[$field]->options['exclude']) { 139 $rendered .= '<div class="views-field-'. views_css_safe($view->field[$field]->field) .'">'; 140 if ($view->field[$field]->label()) { 141 $rendered .= '<label class="view-label-'. views_css_safe($view->field[$field]->field) . '">'; 142 $rendered .= $view->field[$field]->label() . ':'; 143 $rendered .= '</label>'; 144 } 145 $rendered .= '<div class="views-content-'. views_css_safe($view->field[$field]->field) .'">'; 146 $rendered .= $view->style_plugin->rendered_fields[$count][$field]; 147 $rendered .= '</div>'; 148 $rendered .= '</div>'; 149 } 150 } 151 } 152 else { 153 $rendered = node_view(node_load($node->nid), $teaser, FALSE, FALSE); 154 } 155 $output .= theme('views_slideshow_thumbnailhover_no_display_teaser', $rendered, $vss_id, $count); 156 } 157 $output .= "</div>"; 158 return $output; 159 } 160 161 /** 162 * Views Slideshow: active element. 163 * 164 * @ingroup themeable 165 */ 166 function theme_views_slideshow_thumbnailhover_no_display_teaser($item, $vss_id, $count) { 167 $current = $count + 1; 168 169 $classes = array( 170 'views_slideshow_thumbnailhover_slide', 171 "views_slideshow_slide views-row-$current", 172 ); 173 174 if ($count) { 175 $classes[] = 'views_slideshow_thumbnailhover_hidden'; 176 } 177 $classes[] = ($count % 2) ? 'views-row-even' : 'views-row-odd'; 178 179 $attributes['id'] = "views_slideshow_thumbnailhover_div_" . $vss_id . "_" . $count; 180 $attributes['class'] = implode(' ', $classes); 181 $attributes = drupal_attributes($attributes); 182 183 return "<div$attributes>$item</div>"; 184 } 185 186 /** 187 * Views Slideshow: pager in the form of node teasers. 188 * 189 * @ingroup themeable 190 */ 191 function theme_views_slideshow_thumbnailhover_breakout_teasers($view, $items, $vss_id, $options) { 192 $attributes['id'] = "views_slideshow_thumbnailhover_breakout_teasers_" . $vss_id; 193 $attributes['class'] = 'views_slideshow_thumbnailhover_breakout_teasers clear-block'; 194 $attributes = drupal_attributes($attributes); 195 196 $output = "<div$attributes>"; 197 if ('title' == $options['views_slideshow_thumbnailhover']['hover_breakout']) { 198 foreach ($view->result as $count => $node) { 199 $node = node_load($node->nid); // TODO, this loads too much, but on node row we dont access the fields separately. 200 $output .= theme('views_slideshow_thumbnailhover_breakout_teaser', $node->title, $vss_id, $count); 201 } 202 } 203 elseif ($view->display_handler->uses_fields()) { 204 foreach ($view->result as $count => $node) { 205 $rendered_fields = ''; 206 foreach ($options['views_slideshow_thumbnailhover']['breakout_fields'] as $field => $use) { 207 if ($use !== 0 && is_object($view->field[$field]) && !$view->field[$field]->options['exclude']) { 208 $rendered_fields .= '<div class="views-field-'. views_css_safe($view->field[$field]->field) .'">'; 209 if ($view->field[$field]->label()) { 210 $rendered_fields .= '<label class="view-label-'. views_css_safe($view->field[$field]->field) . '">'; 211 $rendered_fields .= $view->field[$field]->label() . ':'; 212 $rendered_fields .= '</label>'; 213 } 214 $rendered_fields .= '<div class="views-content-'. views_css_safe($view->field[$field]->field) .'">'; 215 $rendered_fields .= $view->style_plugin->rendered_fields[$count][$field]; 216 $rendered_fields .= '</div>'; 217 $rendered_fields .= '</div>'; 218 } 219 } 220 $output .= theme('views_slideshow_thumbnailhover_breakout_teaser', $rendered_fields, $vss_id, $count); 221 } 222 } 223 else { 224 foreach ($items as $count => $item) { 225 $output .= theme('views_slideshow_thumbnailhover_breakout_teaser', $item, $vss_id, $count); 226 } 227 } 228 $output .= "</div>\n"; 229 230 return $output; 231 } 232 233 /** 234 * Views Slideshow: breakout teaser. 235 * 236 * @ingroup themeable 237 */ 238 function theme_views_slideshow_thumbnailhover_breakout_teaser($item, $vss_id, $count) { 239 $current = $count + 1; 240 $classes = array( 241 'views_slideshow_thumbnailhover_div_breakout_teaser', 242 ); 243 if (!$count) { 244 $classes[] = 'views_slideshow_thumbnailhover_active_teaser'; 245 } 246 $classes[] = ($count % 2) ? 'views-row-even' : 'views-row-odd'; 247 248 $attributes['class'] = implode(' ', $classes); 249 $attributes['id'] = "views_slideshow_thumbnailhover_div_breakout_teaser_" . $vss_id . "_" . $count; 250 $attributes = drupal_attributes($attributes); 251 252 return "<div$attributes>$item</div>\n"; 253 } 254 255 /** 256 * Views Slideshow: slideshow controls. 257 * 258 * @ingroup themeable 259 */ 260 function theme_views_slideshow_thumbnailhover_controls($vss_id, $view, $options) { 261 $classes = array( 262 'views_slideshow_thumbnailhover_controls', 263 'views_slideshow_controls', 264 ); 265 266 $attributes['class'] = implode(' ', $classes); 267 268 $attributes['id'] = "views_slideshow_thumbnailhover_controls_" . $vss_id; 269 $attributes = drupal_attributes($attributes); 270 271 $output = "<div$attributes>"; 272 $output .= theme('views_slideshow_thumbnailhover_control_previous', $vss_id, $view, $options); 273 if ($options['views_slideshow_thumbnailhover']['timeout']) { 274 $output .= theme('views_slideshow_thumbnailhover_control_pause', $vss_id, $view, $options); 275 } 276 $output .= theme('views_slideshow_thumbnailhover_control_next', $vss_id, $view, $options); 277 $output .= "</div>\n"; 278 return $output; 279 } 280 281 /** 282 * Views Slideshow: "previous" control. 283 * 284 * @ingroup themeable 285 */ 286 function theme_views_slideshow_thumbnailhover_control_previous($vss_id, $view, $options) { 287 return l(t('Previous'), '', array( 288 'attributes' => array( 289 'class' => 'views_slideshow_thumbnailhover_previous views_slideshow_previous', 290 'id' => "views_slideshow_thumbnailhover_prev_" . $vss_id, 291 ), 292 'fragment' => ' ', 293 'external' => TRUE, 294 )); 295 } 296 297 /** 298 * Views Slideshow: "pause" control. 299 * 300 * @ingroup themeable 301 */ 302 function theme_views_slideshow_thumbnailhover_control_pause($vss_id, $view, $options) { 303 return l(t('Pause'), '', array( 304 'attributes' => array( 305 'class' => 'views_slideshow_thumbnailhover_pause views_slideshow_pause', 306 'id' => "views_slideshow_thumbnailhover_playpause_" . $vss_id, 307 ), 308 'fragment' => ' ', 309 'external' => TRUE, 310 )); 311 } 312 313 /** 314 * Views Slideshow: "next" control. 315 * 316 * @ingroup themeable 317 */ 318 function theme_views_slideshow_thumbnailhover_control_next($vss_id, $view, $options) { 319 return l(t('Next'), '', array( 320 'attributes' => array( 321 'class' => 'views_slideshow_thumbnailhover_next views_slideshow_next', 322 'id' => "views_slideshow_thumbnailhover_next_" . $vss_id, 323 ), 324 'fragment' => ' ', 325 'external' => TRUE, 326 )); 327 } 328 329 /** 330 * Views Slideshow: image counter. 331 * 332 * @ingroup themeable 333 */ 334 function theme_views_slideshow_thumbnailhover_image_count($vss_id, $view, $options) { 335 $attributes['class'] = 'views_slideshow_thumbnailhover_image_count views_slideshow_image_count'; 336 $attributes['id'] = "views_slideshow_thumbnailhover_image_count_" . $vss_id; 337 $attributes = drupal_attributes($attributes); 338 339 $counter = '<span class="num">1</span> ' . t('of') .' <span class="total">1</span>'; 340 341 return "<div$attributes>$counter</div>"; 342 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |