Projet

Général

Profil

Paste
Télécharger (18,5 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views_slideshow / theme / views_slideshow.theme.inc @ 18596a08

1
<?php
2

    
3
/**
4
 * @file
5
 * The theme system, which controls the output of views slideshow.
6
 */
7

    
8
 /**
9
 * @defgroup vss_templates Templates
10
 * @{
11
 * Slideshow and component templates.
12
 *
13
 * @see vss_theme
14
 * @}
15
 */
16

    
17
 /**
18
 * @defgroup vss_theme Theme Functions
19
 * @{
20
 * Theme processing and display generation.
21
 *
22
 * Most of the logic behind the generation of the slideshow is here.
23
 *
24
 * @see vss_templates
25
 */
26

    
27
/**
28
 * Implements hook_preprocess_views_slideshow().
29
 */
30
function template_preprocess_views_slideshow(&$vars) {
31
  $options = $vars['options'];
32
  $vars['skin'] = 'default';
33
  $vars['slideshow'] = '';
34
  $main_frame_module = $options['slideshow_type'];
35

    
36
  if (empty($main_frame_module)) {
37
    // Get all slideshow types.
38
    $slideshows = module_invoke_all('views_slideshow_slideshow_info');
39

    
40
    if ($slideshows) {
41
      foreach ($slideshows as $slideshow_id => $slideshow_info) {
42
        $main_frame_module = $slideshow_id;
43
        break;
44
      }
45
    }
46
  }
47

    
48
  // Make sure the main slideshow settings are defined before building the
49
  // slideshow.
50
  if (empty($main_frame_module)) {
51
    drupal_set_message(t('No main frame module is enabled for views slideshow. This is often because another module which Views Slideshow needs is not enabled. For example, 3.x needs a module like "Views Slideshow: Cycle" enabled.'), 'error');
52
  }
53
  elseif (empty($options[$main_frame_module])) {
54
    drupal_set_message(t('The options for !module does not exists.', array('!module' => $main_frame_module)), 'error');
55
  }
56
  elseif (!empty($vars['rows'])) {
57
    $settings = $options[$main_frame_module];
58
    $view = $vars['view'];
59
    $rows = $vars['rows'];
60
    $vss_id = $view->name . '-' . $view->current_display;
61

    
62
    // Give each slideshow a unique id if there are more than one on the page.
63
    static $instances = array();
64
    if (isset($instances[$vss_id])) {
65
      $instances[$vss_id]++;
66
      $vss_id .= "_" . $instances[$vss_id];
67
    }
68
    else {
69
      $instances[$vss_id] = 1;
70
      $vss_id .= '_1';
71
    }
72

    
73
    // Building our default methods.
74
    $methods = array(
75
      'goToSlide' => array(),
76
      'nextSlide' => array(),
77
      'pause' => array(),
78
      'play' => array(),
79
      'previousSlide' => array(),
80
      'transitionBegin' => array(),
81
      'transitionEnd' => array(),
82
    );
83

    
84
    // Pull all widget info and slideshow info and merge them together.
85
    $widgets = module_invoke_all('views_slideshow_widget_info');
86
    $slideshows = module_invoke_all('views_slideshow_slideshow_info');
87
    $addons = array_merge($widgets, $slideshows);
88

    
89
    // Loop through all the addons and call their methods if needed.
90
    foreach ($addons as $addon_id => $addon_info) {
91
      foreach ($addon_info['accepts'] as $imp_key => $imp_value) {
92
        if (is_array($imp_value)) {
93
          $methods[$imp_key][] = views_slideshow_format_addons_name($addon_id);
94
        }
95
        else {
96
          $methods[$imp_value][] = views_slideshow_format_addons_name($addon_id);
97
        }
98
      }
99
    }
100

    
101
    $js_settings = array(
102
      'viewsSlideshow' => array(
103
        $vss_id => array(
104
          'methods' => $methods,
105
          'paused' => 0,
106
        ),
107
      ),
108
    );
109
    drupal_add_library('views_slideshow', 'views_slideshow');
110
    drupal_add_js($js_settings, 'setting');
111

    
112
    // Process Skins.
113
    $skin_info = array();
114
    if (isset($options['skin_info'])) {
115
      $skin_info = $options['skin_info'];
116
    }
117

    
118
    // Make sure $skin_info has all the values.
119
    $skin_info += array(
120
      'class' => 'default',
121
      'name' => t('Untitled skin'),
122
      'module' => 'views_slideshow',
123
      'path' => '',
124
      'stylesheets' => array(),
125
    );
126

    
127
    $vars['skin'] = $skin_info['class'];
128

    
129
    // Enqueue any stylesheets set for the skin on this view are added.
130
    $skin_path = drupal_get_path('module', $skin_info['module']);
131
    if ($skin_info['path']) {
132
      $skin_path .= '/' . $skin_info['path'];
133
    }
134

    
135
    // Add stylesheet.
136
    if (!empty($skin_info['stylesheets'])) {
137
      foreach ($skin_info['stylesheets'] as $stylesheet) {
138
        drupal_add_css($skin_path . '/' . $stylesheet);
139
      }
140
    }
141

    
142
    // Process Widgets.
143
    // Build weights.
144
    for ($i = 1; $i <= count($widgets); $i++) {
145
      $weight['top'][$i] = array();
146
      $weight['bottom'][$i] = array();
147
    }
148

    
149
    foreach ($widgets as $widget_id => $widget_name) {
150
      // Put our widgets in the right location.
151
      if ($options['widgets']['top'][$widget_id]['enable']) {
152
        $widget_weight = ($options['widgets']['top'][$widget_id]['weight'] > count($widgets)) ? count($widgets) : $options['widgets']['top'][$widget_id]['weight'];
153
        $weight['top'][$widget_weight][] = $widget_id;
154
      }
155

    
156
      if ($options['widgets']['bottom'][$widget_id]['enable']) {
157
        $widget_weight = ($options['widgets']['bottom'][$widget_id]['weight'] > count($widgets)) ? count($widgets) : $options['widgets']['bottom'][$widget_id]['weight'];
158
        $weight['bottom'][$widget_weight][] = $widget_id;
159
      }
160
    }
161

    
162
    // Build our widgets.
163
    foreach ($weight as $location => $order) {
164
      $vars[$location . '_widget_rendered'] = '';
165
      foreach ($order as $order_num => $widgets) {
166
        if (is_array($widgets)) {
167
          foreach ($widgets as $widget_id) {
168
            $vars[$widget_id . '_' . $location] = theme(views_theme_functions($widget_id . '_widget_render', $view, $view->display[$view->current_display]), array(
169
              'vss_id' => $vss_id,
170
              'view' => $view,
171
              'settings' => $options['widgets'][$location][$widget_id],
172
              'location' => $location,
173
              'rows' => $rows,
174
            ));
175
            $vars[$location . '_widget_rendered'] .= $vars[$widget_id . '_' . $location];
176
          }
177
        }
178
      }
179
    }
180

    
181
    // Process Slideshow.
182
    $slides = theme(views_theme_functions($main_frame_module . '_main_frame', $view, $view->display[$view->current_display]), array(
183
      'vss_id' => $vss_id,
184
      'view' => $view,
185
      'settings' => $settings,
186
      'rows' => $rows,
187
      'options' => $options,
188
    ));
189
    $vars['slideshow'] = theme(views_theme_functions('views_slideshow_main_section', $view, $view->display[$view->current_display]), array(
190
      'vss_id' => $vss_id,
191
      'slides' => $slides,
192
      'plugin' => $main_frame_module,
193
    ));
194
  }
195
}
196

    
197
/**
198
 * The current element of the slideshow.
199
 *
200
 * @param array $vars
201
 *   Theme variables.
202
 *
203
 * @return string
204
 *   The html string for the slideshow element.
205
 */
206
function theme_views_slideshow_main_section($vars) {
207
  return '<div id="' . $vars['plugin'] . '_main_' . $vars['vss_id'] . '" class="' . $vars['plugin'] . '_main views_slideshow_main">' . $vars['slides'] . '</div>';
208
}
209

    
210
/**
211
 * Views Slideshow: pager.
212
 *
213
 * @param array $vars
214
 *   Theme variables.
215
 *
216
 * @return string
217
 *   The html string for the pager widget or an empty string if disabled.
218
 */
219
function theme_views_slideshow_pager_widget_render($vars) {
220
  if (isset($vars['settings']['hide_on_single_slide']) && $vars['settings']['hide_on_single_slide'] === 1 && count($vars['rows']) < 2) {
221
    return '';
222
  }
223

    
224
  // Add JavaScript settings for the pager type.
225
  $js_vars = array(
226
    'viewsSlideshowPager' => array(
227
      $vars['vss_id'] => array(
228
        $vars['location'] => array(
229
          'type' => views_slideshow_format_addons_name($vars['settings']['type']),
230
          'master_pager' => views_slideshow_format_addons_name($vars['settings']['master_pager']),
231
        ),
232
      ),
233
    ),
234
  );
235

    
236
  drupal_add_library('views_slideshow', 'views_slideshow');
237
  drupal_add_js($js_vars, 'setting');
238

    
239
  // Create some attributes.
240
  $attributes['class'] = 'widget_pager widget_pager_' . $vars['location'];
241
  $attributes['id'] = 'widget_pager_' . $vars['location'] . '_' . $vars['vss_id'];
242
  return theme(views_theme_functions($vars['settings']['type'], $vars['view'], $vars['view']->display[$vars['view']->current_display]), array(
243
    'vss_id' => $vars['vss_id'],
244
    'view' => $vars['view'],
245
    'settings' => $vars['settings']
246
    , 'location' => $vars['location'],
247
    'attributes' => $attributes,
248
  ));
249
}
250

    
251
/**
252
 * Theme pager fields.
253
 *
254
 * @param array $vars
255
 *   Theme variables.
256
 */
257
function template_preprocess_views_slideshow_pager_fields(&$vars) {
258
  // Build our JavaScript settings.
259
  $js_vars = array(
260
    'viewsSlideshowPagerFields' => array(
261
      $vars['vss_id'] => array(
262
        $vars['location'] => array(
263
          'activatePauseOnHover' => $vars['settings']['views_slideshow_pager_fields_hover'],
264
        ),
265
      ),
266
    ),
267
  );
268

    
269
  // Add the settings to the page.
270
  drupal_add_library('views_slideshow', 'views_slideshow');
271
  drupal_add_js($js_vars, 'setting');
272

    
273
  // Add hover intent library.
274
  if ($vars['settings']['views_slideshow_pager_fields_hover']) {
275
    if (module_exists('libraries')) {
276
      // Load jQuery hoverIntent.
277
      $hoverIntent_path = libraries_get_path('jquery.hoverIntent');
278
      if (!empty($hoverIntent_path) && file_exists($hoverIntent_path . '/jquery.hoverIntent.js')) {
279
        drupal_add_js($hoverIntent_path . '/jquery.hoverIntent.js');
280
      }
281
    }
282
  }
283

    
284
  $vars['classes_array'][] = $vars['attributes']['class'];
285
  $vars['widget_id'] = $vars['attributes']['id'];
286
  // Add our class to the wrapper.
287
  $vars['classes_array'][] = 'views_slideshow_pager_field';
288

    
289
  // Render all the fields unless there is only 1 slide and the user specified
290
  // to hide them when there is only one slide.
291
  $items_per_slide = (isset($vars['view']->style_options['views_slideshow_cycle']['items_per_slide'])) ? $vars['view']->style_options['views_slideshow_cycle']['items_per_slide'] : null;
292
  $vars['rendered_field_items'] = '';
293
  if (empty($vars['settings']['hide_on_single_slide']) || count($vars['view']->result) > $items_per_slide) {
294
    foreach ($vars['view']->result as $count => $node) {
295
      $rendered_fields = '';
296
      foreach ($vars['settings']['views_slideshow_pager_fields_fields'] as $field => $use) {
297
        if ($use !== 0 && is_object($vars['view']->field[$field])) {
298
          $rendered_fields .= theme(views_theme_functions('views_slideshow_pager_field_field', $vars['view'], $vars['view']->display[$vars['view']->current_display]), array(
299
            'view' => $vars['view'],
300
            'field' => $field,
301
            'count' => $count,
302
          ));
303
        }
304
      }
305
      $vars['rendered_field_items'] .= theme(views_theme_functions('views_slideshow_pager_field_item', $vars['view'], $vars['view']->display[$vars['view']->current_display]), array(
306
        'vss_id' => $vars['vss_id'],
307
        'item' => $rendered_fields,
308
        'count' => $count,
309
        'location' => $vars['location'],
310
        'length' => count($vars['view']->result),
311
      ));
312
    }
313
  }
314
}
315

    
316
/**
317
 * Views Slideshow: pager item.
318
 *
319
 * @param array $vars
320
 *   Theme variables.
321
 */
322
function template_preprocess_views_slideshow_pager_field_item(&$vars) {
323
  $vars['classes_array'][] = 'views_slideshow_pager_field_item';
324
  $vars['classes_array'][] = ($vars['count'] % 2) ? 'views-row-even' : 'views-row-odd';
325
  if ($vars['count'] == 0) {
326
    $vars['classes_array'][] = 'views-row-first';
327
  }
328
  elseif ($vars['count'] == $vars['length'] - 1) {
329
    $vars['classes_array'][] = 'views-row-last';
330
  }
331
}
332

    
333
/**
334
 * Views Slideshow: pager field item field.
335
 *
336
 * @param array $vars
337
 *   Theme variables.
338
 */
339
function template_preprocess_views_slideshow_pager_field_field(&$vars) {
340
  $view = $vars['view'];
341
  $vars['field_item'] = $view->field[$vars['field']];
342
  $vars['field_rendered'] = $view->style_plugin->rendered_fields[$vars['count']][$vars['field']];
343
  $vars['css_id'] = drupal_clean_css_identifier($vars['field_item']->field);
344
  if (!strstr($vars['field_rendered'], '<a')) {
345
    $vars['field_rendered'] = "<a href='#slideshow-${vars['count']}'>${vars['field_rendered']}</a>";
346
  }
347
}
348

    
349
/**
350
 * Views Slideshow: Controls.
351
 *
352
 * @param array $vars
353
 *   Theme variables.
354
 *
355
 * @return string
356
 *   The html string for the control widget.
357
 */
358
function theme_views_slideshow_controls_widget_render($vars) {
359
  // Add JavaScript settings for the controls type.
360
  $js_vars = array(
361
    'viewsSlideshowControls' => array(
362
      $vars['vss_id'] => array(
363
        $vars['location'] => array(
364
          'type' => views_slideshow_format_addons_name($vars['settings']['type']),
365
        ),
366
      ),
367
    ),
368
  );
369

    
370
  drupal_add_library('views_slideshow', 'views_slideshow');
371
  drupal_add_js($js_vars, 'setting');
372

    
373
  $items_per_slide = (isset($vars['view']->style_options['views_slideshow_cycle']['items_per_slide'])) ? $vars['view']->style_options['views_slideshow_cycle']['items_per_slide'] : null;
374
  $output = '';
375
  if (empty($vars['settings']['hide_on_single_slide']) || count($vars['rows']) > $items_per_slide) {
376
    $output = theme(views_theme_functions($vars['settings']['type'], $vars['view'], $vars['view']->display[$vars['view']->current_display]), array(
377
      'vss_id' => $vars['vss_id'],
378
      'view' => $vars['view'],
379
      'settings' => $vars['settings'],
380
      'location' => $vars['location'],
381
      'rows' => $vars['rows'],
382
    ));
383
  }
384

    
385
  return $output;
386
}
387

    
388
/**
389
 * The slideshow controls.
390
 *
391
 * @param array $vars
392
 *   Theme variables.
393
 */
394
function template_preprocess_views_slideshow_controls_text(&$vars) {
395
  $module_path = drupal_get_path('module', 'views_slideshow');
396
  drupal_add_css($module_path . '/views_slideshow_controls_text.css', array('type' => 'file'));
397

    
398
  $vars['classes_array'][] = 'views_slideshow_controls_text';
399

    
400
  $vars['rendered_control_previous'] = theme(views_theme_functions('views_slideshow_controls_text_previous', $vars['view'], $vars['view']->display[$vars['view']->current_display]), array(
401
    'vss_id' => $vars['vss_id'],
402
    'view' => $vars['view'],
403
    'settings' => $vars['settings'],
404
  ));
405

    
406
  $vars['rendered_control_pause'] = theme(views_theme_functions('views_slideshow_controls_text_pause', $vars['view'], $vars['view']->display[$vars['view']->current_display]), array(
407
    'vss_id' => $vars['vss_id'],
408
    'view' => $vars['view'],
409
    'settings' => $vars['settings'],
410
  ));
411

    
412
  $vars['rendered_control_next'] = theme(views_theme_functions('views_slideshow_controls_text_next', $vars['view'], $vars['view']->display[$vars['view']->current_display]), array(
413
    'vss_id' => $vars['vss_id'],
414
    'view' => $vars['view'],
415
    'settings' => $vars['settings'],
416
  ));
417
}
418

    
419
/**
420
 * Views Slideshow: "previous" control.
421
 *
422
 * @param array $vars
423
 *   Theme variables.
424
 */
425
function template_preprocess_views_slideshow_controls_text_previous(&$vars) {
426
  $vars['classes_array'][] = 'views_slideshow_controls_text_previous';
427
}
428

    
429
/**
430
 * Views Slideshow: "pause" control.
431
 *
432
 * @param array $vars
433
 *   Theme variables.
434
 */
435
function template_preprocess_views_slideshow_controls_text_pause(&$vars) {
436
  $vars['classes_array'][] = 'views_slideshow_controls_text_pause  views-slideshow-controls-text-status-play';
437
  $vars['start_text'] = t('Pause');
438
}
439

    
440
/**
441
 * Views Slideshow: "next" control.
442
 *
443
 * @param array $vars
444
 *   Theme variables.
445
 */
446
function template_preprocess_views_slideshow_controls_text_next(&$vars) {
447
  $vars['classes_array'][] = 'views_slideshow_controls_text_next';
448
}
449

    
450
/**
451
 * Views Slideshow: Slide Counter.
452
 *
453
 * @param array $vars
454
 *   Theme variables.
455
 *
456
 * @return string
457
 *   The html string for the counter widget.
458
 */
459
function theme_views_slideshow_slide_counter_widget_render($vars) {
460
  return theme(views_theme_functions('views_slideshow_slide_counter', $vars['view'], $vars['view']->display[$vars['view']->current_display]), array(
461
    'vss_id' => $vars['vss_id'],
462
    'view' => $vars['view'],
463
    'settings' => $vars['settings'],
464
    'location' => $vars['location'],
465
    'rows' => $vars['rows'],
466
  ));
467
}
468

    
469
/**
470
 * Views Slideshow: slide counter.
471
 *
472
 * @param array $vars
473
 *   Theme variables.
474
 */
475
function template_preprocess_views_slideshow_slide_counter(&$vars) {
476
  $vars['classes_array'][] = 'views_slideshow_slide_counter';
477
  $vars['slide_count'] = count($vars['rows']);
478
}
479

    
480
/**
481
 * Backwards compatibility wrapper.
482
 *
483
 * @param array $vars
484
 *   Theme variables.
485
 *
486
 * @deprecated Removed in 3.5 when the hook_theme() implementation was fixed.
487
 *
488
 * @see template_preprocess_views_slideshow().
489
 */
490
function _views_slideshow_preprocess_views_slideshow(&$vars) {
491
 template_preprocess_views_slideshow($vars);
492
}
493

    
494
/**
495
 * Backwards compatibility wrapper.
496
 *
497
 * @param array $vars
498
 *   Theme variables.
499
 *
500
 * @deprecated Removed in 3.5 when the hook_theme() implementation was fixed.
501
 *
502
 * @see template_preprocess_views_slideshow_pager_fields().
503
 */
504
function _views_slideshow_preprocess_views_slideshow_pager_fields(&$vars) {
505
  template_preprocess_views_slideshow_pager_fields($vars);
506
}
507

    
508
/**
509
 * Backwards compatibility wrapper.
510
 *
511
 * @param array $vars
512
 *   Theme variables.
513
 *
514
 * @param array $vars
515
 *   Theme variables.
516
 *
517
 * @deprecated Removed in 3.5 when the hook_theme() implementation was fixed.
518
 *
519
 * @see template_preprocess_views_slideshow_pager_field_item().
520
 */
521
function _views_slideshow_preprocess_views_slideshow_pager_field_item(&$vars) {
522
  template_preprocess_views_slideshow_pager_field_item($vars);
523
}
524

    
525
/**
526
 * Backwards compatibility wrapper.
527
 *
528
 * @param array $vars
529
 *   Theme variables.
530
 *
531
 * @deprecated Removed in 3.5 when the hook_theme() implementation was fixed.
532
 *
533
 * @see template_preprocess_views_slideshow_controls_text().
534
 */
535
function _views_slideshow_preprocess_views_slideshow_controls_text(&$vars) {
536
  template_preprocess_views_slideshow_controls_text($vars);
537
}
538

    
539
/**
540
 * Backwards compatibility wrapper.
541
 *
542
 * @param array $vars
543
 *   Theme variables.
544
 *
545
 * @see template_preprocess_views_slideshow_controls_text_previous().
546
 */
547
function _views_slideshow_preprocess_views_slideshow_controls_text_previous(&$vars) {
548
  template_preprocess_views_slideshow_controls_text_previous($vars);
549
}
550

    
551
/**
552
 * Backwards compatibility wrapper.
553
 *
554
 * @param array $vars
555
 *   Theme variables.
556
 *
557
 * @deprecated Removed in 3.5 when the hook_theme() implementation was fixed.
558
 *
559
 * @see template_preprocess_views_slideshow_controls_text_pause().
560
 */
561
function _views_slideshow_preprocess_views_slideshow_controls_text_pause(&$vars) {
562
  template_preprocess_views_slideshow_controls_text_pause($vars);
563
}
564

    
565
/**
566
 * Backwards compatibility wrapper.
567
 *
568
 * @param array $vars
569
 *   Theme variables.
570
 *
571
 * @deprecated Removed in 3.5 when the hook_theme() implementation was fixed.
572
 *
573
 * @see template_preprocess_views_slideshow_controls_text_next().
574
 */
575
function _views_slideshow_preprocess_views_slideshow_controls_text_next(&$vars) {
576
  template_preprocess_views_slideshow_controls_text_next($vars);
577
}
578

    
579
/**
580
 * Backwards compatibility wrapper.
581
 *
582
 * @param array $vars
583
 *   Theme variables.
584
 *
585
 * @deprecated Removed in 3.5 when the hook_theme() implementation was fixed.
586
 *
587
 * @see template_preprocess_views_slideshow_slide_counter().
588
 */
589
function _views_slideshow_preprocess_views_slideshow_slide_counter(&$vars) {
590
  template_preprocess_views_slideshow_slide_counter($vars);
591
}
592

    
593
/**
594
 * @} End of "defgroup vss_theme".
595
 */