Projet

Général

Profil

Paste
Télécharger (16,6 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views_slideshow / theme / views_slideshow.theme.inc @ 7547bb19

1
<?php
2

    
3
/**
4
 * @file
5
 * The theme system, which controls the output of views slideshow.
6
 *
7
 * This just adds a wrapper div to the slideshow.
8
 */
9

    
10
/**
11
 * Implements hook_preprocess_views_slideshow().
12
 */
13
function template_preprocess_views_slideshow(&$vars) {
14
  $options = $vars['options'];
15
  $vars['skin'] = 'default';
16
  $vars['slideshow'] = '';
17
  $main_frame_module = $options['slideshow_type'];
18

    
19
  if (empty($main_frame_module)) {
20
    // Get all slideshow types.
21
    $slideshows = module_invoke_all('views_slideshow_slideshow_info');
22

    
23
    if ($slideshows) {
24
      foreach ($slideshows as $slideshow_id => $slideshow_info) {
25
        $main_frame_module = $slideshow_id;
26
        break;
27
      }
28
    }
29
  }
30

    
31
  // Make sure the main slideshow settings are defined before building the
32
  // slideshow.
33
  if (empty($main_frame_module)) {
34
    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');
35
  }
36
  elseif (empty($options[$main_frame_module])) {
37
    drupal_set_message(t('The options for !module does not exists.', array('!module' => $main_frame_module)), 'error');
38
  }
39
  elseif (!empty($vars['rows'])) {
40
    $settings = $options[$main_frame_module];
41
    $view = $vars['view'];
42
    $rows = $vars['rows'];
43
    $num_divs = count($rows);
44
    $vss_id = $view->name . '-' . $view->current_display;
45

    
46
    // Give each slideshow a unique id if there are more than one on the page.
47
    static $instances = array();
48
    if (isset($instances[$vss_id])) {
49
      $instances[$vss_id]++;
50
      $vss_id .= "_" . $instances[$vss_id];
51
    }
52
    else {
53
      $instances[$vss_id] = 1;
54
    }
55

    
56
    // Building our default methods.
57
    $methods = array(
58
      'goToSlide' => array(),
59
      'nextSlide' => array(),
60
      'pause' => array(),
61
      'play' => array(),
62
      'previousSlide' => array(),
63
      'transitionBegin' => array(),
64
      'transitionEnd' => array(),
65
    );
66

    
67
    // Pull all widget info and slideshow info and merge them together.
68
    $widgets = module_invoke_all('views_slideshow_widget_info');
69
    $slideshows = module_invoke_all('views_slideshow_slideshow_info');
70
    $addons = array_merge($widgets, $slideshows);
71

    
72
    // Loop through all the addons and call their methods if needed.
73
    foreach ($addons as $addon_id => $addon_info) {
74
      foreach ($addon_info['accepts'] as $imp_key => $imp_value) {
75
        if (is_array($imp_value)) {
76
          $methods[$imp_key][] = views_slideshow_format_addons_name($addon_id);
77
        }
78
        else {
79
          $methods[$imp_value][] = views_slideshow_format_addons_name($addon_id);
80
        }
81
      }
82
    }
83

    
84
    $js_settings = array(
85
      'viewsSlideshow' => array(
86
        $vss_id => array(
87
          'methods' => $methods,
88
          'paused' => 0,
89
        ),
90
      ),
91
    );
92
    drupal_add_library('views_slideshow', 'views_slideshow');
93
    drupal_add_js($js_settings, 'setting');
94

    
95
    // Process Skins.
96
    $skin_info = array();
97
    if (isset($options['skin_info'])) {
98
      $skin_info = $options['skin_info'];
99
    }
100

    
101
    // Make sure $skin_info has all the values.
102
    $skin_info += array(
103
      'class' => 'default',
104
      'name' => t('Untitled skin'),
105
      'module' => 'views_slideshow',
106
      'path' => '',
107
      'stylesheets' => array(),
108
    );
109

    
110
    $vars['skin'] = $skin_info['class'];
111

    
112
    // Enqueue any stylesheets set for the skin on this view are added.
113
    $skin_path = drupal_get_path('module', $skin_info['module']);
114
    if ($skin_info['path']) {
115
      $skin_path .= '/' . $skin_info['path'];
116
    }
117

    
118
    // Add stylesheet.
119
    if (!empty($skin_info['stylesheets'])) {
120
      foreach ($skin_info['stylesheets'] as $stylesheet) {
121
        drupal_add_css($skin_path . '/' . $stylesheet);
122
      }
123
    }
124

    
125
    // Process Widgets.
126
    // Build weights.
127
    for ($i = 1; $i <= count($widgets); $i++) {
128
      $weight['top'][$i] = array();
129
      $weight['bottom'][$i] = array();
130
    }
131

    
132
    foreach ($widgets as $widget_id => $widget_name) {
133
      // Put our widgets in the right location.
134
      if ($options['widgets']['top'][$widget_id]['enable']) {
135
        $widget_weight = ($options['widgets']['top'][$widget_id]['weight'] > count($widgets)) ? count($widgets) : $options['widgets']['top'][$widget_id]['weight'];
136
        $weight['top'][$widget_weight][] = $widget_id;
137
      }
138

    
139
      if ($options['widgets']['bottom'][$widget_id]['enable']) {
140
        $widget_weight = ($options['widgets']['bottom'][$widget_id]['weight'] > count($widgets)) ? count($widgets) : $options['widgets']['bottom'][$widget_id]['weight'];
141
        $weight['bottom'][$widget_weight][] = $widget_id;
142
      }
143
    }
144

    
145
    // Build our widgets.
146
    foreach ($weight as $location => $order) {
147
      $vars[$location . '_widget_rendered'] = '';
148
      foreach ($order as $order_num => $widgets) {
149
        if (is_array($widgets)) {
150
          foreach ($widgets as $widget_id) {
151
            $vars[$widget_id . '_' . $location] = theme(views_theme_functions($widget_id . '_widget_render', $view, $view->display[$view->current_display]), array(
152
              'vss_id' => $vss_id,
153
              'view' => $view,
154
              'settings' => $options['widgets'][$location][$widget_id],
155
              'location' => $location,
156
              'rows' => $rows,
157
            ));
158
            $vars[$location . '_widget_rendered'] .= $vars[$widget_id . '_' . $location];
159
          }
160
        }
161
      }
162
    }
163

    
164
    // Process Slideshow.
165
    $slides = theme(views_theme_functions($main_frame_module . '_main_frame', $view, $view->display[$view->current_display]), array(
166
      'vss_id' => $vss_id,
167
      'view' => $view,
168
      'settings' => $settings,
169
      'rows' => $rows,
170
      'options' => $options,
171
    ));
172
    $vars['slideshow'] = theme(views_theme_functions('views_slideshow_main_section', $view, $view->display[$view->current_display]), array(
173
      'vss_id' => $vss_id,
174
      'slides' => $slides,
175
      'plugin' => $main_frame_module,
176
    ));
177
  }
178
}
179

    
180
/**
181
 * The current element of the slideshow.
182
 *
183
 * @ingroup themeable
184
 */
185
function theme_views_slideshow_main_section($vars) {
186
  return '<div id="' . $vars['plugin'] . '_main_' . $vars['vss_id'] . '" class="' . $vars['plugin'] . '_main views_slideshow_main">' . $vars['slides'] . '</div>';
187
}
188

    
189
/**
190
 * Views Slideshow: pager.
191
 *
192
 * @ingroup themeable
193
 */
194
function theme_views_slideshow_pager_widget_render($vars) {
195
  if (isset($vars['settings']['hide_on_single_slide']) && $vars['settings']['hide_on_single_slide'] === 1 && count($vars['rows']) < 2) {
196
    return '';
197
  }
198

    
199
  // Add JavaScript settings for the pager type.
200
  $js_vars = array(
201
    'viewsSlideshowPager' => array(
202
      $vars['vss_id'] => array(
203
        $vars['location'] => array(
204
          'type' => views_slideshow_format_addons_name($vars['settings']['type']),
205
          'master_pager' => views_slideshow_format_addons_name($vars['settings']['master_pager']),
206
        ),
207
      ),
208
    ),
209
  );
210

    
211
  drupal_add_library('views_slideshow', 'views_slideshow');
212
  drupal_add_js($js_vars, 'setting');
213

    
214
  // Create some attributes.
215
  $attributes['class'] = 'widget_pager widget_pager_' . $vars['location'];
216
  $attributes['id'] = 'widget_pager_' . $vars['location'] . '_' . $vars['vss_id'];
217
  return theme(views_theme_functions($vars['settings']['type'], $vars['view'], $vars['view']->display[$vars['view']->current_display]), array(
218
    'vss_id' => $vars['vss_id'],
219
    'view' => $vars['view'],
220
    'settings' => $vars['settings']
221
    , 'location' => $vars['location'],
222
    'attributes' => $attributes,
223
  ));
224
}
225

    
226
/**
227
 * Theme pager fields.
228
 */
229
function template_preprocess_views_slideshow_pager_fields(&$vars) {
230
  // Build our JavaScript settings.
231
  $js_vars = array(
232
    'viewsSlideshowPagerFields' => array(
233
      $vars['vss_id'] => array(
234
        $vars['location'] => array(
235
          'activatePauseOnHover' => $vars['settings']['views_slideshow_pager_fields_hover'],
236
        ),
237
      ),
238
    ),
239
  );
240

    
241
  // Add the settings to the page.
242
  drupal_add_library('views_slideshow', 'views_slideshow');
243
  drupal_add_js($js_vars, 'setting');
244

    
245
  // Add hover intent library.
246
  if ($vars['settings']['views_slideshow_pager_fields_hover']) {
247
    if (module_exists('libraries')) {
248
      // Load jQuery hoverIntent.
249
      $hoverIntent_path = libraries_get_path('jquery.hoverIntent');
250
      if (!empty($hoverIntent_path) && file_exists($hoverIntent_path . '/jquery.hoverIntent.js')) {
251
        drupal_add_js($hoverIntent_path . '/jquery.hoverIntent.js');
252
      }
253
    }
254
  }
255

    
256
  $vars['classes_array'][] = $vars['attributes']['class'];
257
  $vars['widget_id'] = $vars['attributes']['id'];
258
  // Add our class to the wrapper.
259
  $vars['classes_array'][] = 'views_slideshow_pager_field';
260

    
261
  // Render all the fields unless there is only 1 slide and the user specified
262
  // to hide them when there is only one slide.
263
  $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;
264
  $vars['rendered_field_items'] = '';
265
  if (empty($vars['settings']['hide_on_single_slide']) || count($vars['view']->result) > $items_per_slide) {
266
    foreach ($vars['view']->result as $count => $node) {
267
      $rendered_fields = '';
268
      foreach ($vars['settings']['views_slideshow_pager_fields_fields'] as $field => $use) {
269
        if ($use !== 0 && is_object($vars['view']->field[$field])) {
270
          $rendered_fields .= theme(views_theme_functions('views_slideshow_pager_field_field', $vars['view'], $vars['view']->display[$vars['view']->current_display]), array(
271
            'view' => $vars['view'],
272
            'field' => $field,
273
            'count' => $count,
274
          ));
275
        }
276
      }
277
      $vars['rendered_field_items'] .= theme(views_theme_functions('views_slideshow_pager_field_item', $vars['view'], $vars['view']->display[$vars['view']->current_display]), array(
278
        'vss_id' => $vars['vss_id'],
279
        'item' => $rendered_fields,
280
        'count' => $count,
281
        'location' => $vars['location'],
282
        'length' => count($vars['view']->result),
283
      ));
284
    }
285
  }
286
}
287

    
288
/**
289
 * Views Slideshow: pager item.
290
 *
291
 * @ingroup themeable
292
 */
293
function template_preprocess_views_slideshow_pager_field_item(&$vars) {
294
  $vars['classes_array'][] = 'views_slideshow_pager_field_item';
295
  $vars['classes_array'][] = ($vars['count'] % 2) ? 'views-row-even' : 'views-row-odd';
296
  if ($vars['count'] == 0) {
297
    $vars['classes_array'][] = 'views-row-first';
298
  }
299
  elseif ($vars['count'] == $vars['length'] - 1) {
300
    $vars['classes_array'][] = 'views-row-last';
301
  }
302
}
303

    
304
/**
305
 * Views Slideshow: pager field item field.
306
 *
307
 * @ingroup themeable
308
 */
309
function template_preprocess_views_slideshow_pager_field_field(&$vars) {
310
  $view = $vars['view'];
311
  $vars['field_item'] = $view->field[$vars['field']];
312
  $vars['field_rendered'] = $view->style_plugin->rendered_fields[$vars['count']][$vars['field']];
313
  $vars['css_id'] = drupal_clean_css_identifier($vars['field_item']->field);
314
  if (!strstr($vars['field_rendered'], '<a')) {
315
    $vars['field_rendered'] = "<a href='#slideshow-${vars['count']}'>${vars['field_rendered']}</a>";
316
  }
317
}
318

    
319
/**
320
 * Views Slideshow: Controls.
321
 *
322
 * @inggroup themeable
323
 */
324
function theme_views_slideshow_controls_widget_render($vars) {
325
  // Add JavaScript settings for the controls type.
326
  $js_vars = array(
327
    'viewsSlideshowControls' => array(
328
      $vars['vss_id'] => array(
329
        $vars['location'] => array(
330
          'type' => views_slideshow_format_addons_name($vars['settings']['type']),
331
        ),
332
      ),
333
    ),
334
  );
335

    
336
  drupal_add_library('views_slideshow', 'views_slideshow');
337
  drupal_add_js($js_vars, 'setting');
338

    
339
  $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;
340
  $output = '';
341
  if (empty($vars['settings']['hide_on_single_slide']) || count($vars['rows']) > $items_per_slide) {
342
    $output = theme(views_theme_functions($vars['settings']['type'], $vars['view'], $vars['view']->display[$vars['view']->current_display]), array(
343
      'vss_id' => $vars['vss_id'],
344
      'view' => $vars['view'],
345
      'settings' => $vars['settings'],
346
      'location' => $vars['location'],
347
      'rows' => $vars['rows'],
348
    ));
349
  }
350

    
351
  return $output;
352
}
353

    
354
/**
355
 * The slideshow controls.
356
 *
357
 * @ingroup themeable
358
 */
359
function template_preprocess_views_slideshow_controls_text(&$vars) {
360
  $module_path = drupal_get_path('module', 'views_slideshow');
361
  drupal_add_css($module_path . '/views_slideshow_controls_text.css', array('type' => 'file'));
362

    
363
  $vars['classes_array'][] = 'views_slideshow_controls_text';
364

    
365
  $vars['rendered_control_previous'] = theme(views_theme_functions('views_slideshow_controls_text_previous', $vars['view'], $vars['view']->display[$vars['view']->current_display]), array(
366
    'vss_id' => $vars['vss_id'],
367
    'view' => $vars['view'],
368
    'settings' => $vars['settings'],
369
  ));
370

    
371
  $vars['rendered_control_pause'] = theme(views_theme_functions('views_slideshow_controls_text_pause', $vars['view'], $vars['view']->display[$vars['view']->current_display]), array(
372
    'vss_id' => $vars['vss_id'],
373
    'view' => $vars['view'],
374
    'settings' => $vars['settings'],
375
  ));
376

    
377
  $vars['rendered_control_next'] = theme(views_theme_functions('views_slideshow_controls_text_next', $vars['view'], $vars['view']->display[$vars['view']->current_display]), array(
378
    'vss_id' => $vars['vss_id'],
379
    'view' => $vars['view'],
380
    'settings' => $vars['settings'],
381
  ));
382
}
383

    
384
/**
385
 * Views Slideshow: "previous" control.
386
 *
387
 * @ingroup themeable
388
 */
389
function template_preprocess_views_slideshow_controls_text_previous(&$vars) {
390
  $vars['classes_array'][] = 'views_slideshow_controls_text_previous';
391
}
392

    
393
/**
394
 * Views Slideshow: "pause" control.
395
 *
396
 * @ingroup themeable
397
 */
398
function template_preprocess_views_slideshow_controls_text_pause(&$vars) {
399
  $vars['classes_array'][] = 'views_slideshow_controls_text_pause  views-slideshow-controls-text-status-play';
400
  $vars['start_text'] = t('Pause');
401
}
402

    
403
/**
404
 * Views Slideshow: "next" control.
405
 *
406
 * @ingroup themeable
407
 */
408
function template_preprocess_views_slideshow_controls_text_next(&$vars) {
409
  $vars['classes_array'][] = 'views_slideshow_controls_text_next';
410
}
411

    
412
/**
413
 * Views Slideshow: Slide Counter.
414
 *
415
 * @inggroup themeable
416
 */
417
function theme_views_slideshow_slide_counter_widget_render($vars) {
418
  return theme(views_theme_functions('views_slideshow_slide_counter', $vars['view'], $vars['view']->display[$vars['view']->current_display]), array(
419
    'vss_id' => $vars['vss_id'],
420
    'view' => $vars['view'],
421
    'settings' => $vars['settings'],
422
    'location' => $vars['location'],
423
    'rows' => $vars['rows'],
424
  ));
425
}
426

    
427
/**
428
 * Views Slideshow: slide counter.
429
 */
430
function template_preprocess_views_slideshow_slide_counter(&$vars) {
431
  $vars['classes_array'][] = 'views_slideshow_slide_counter';
432
  $vars['slide_count'] = count($vars['rows']);
433
}
434

    
435
/**
436
 * Backwards compatability wrapper.
437
 *
438
 * @see template_preprocess_views_slideshow().
439
 */
440
function _views_slideshow_preprocess_views_slideshow(&$vars) {
441
 template_preprocess_views_slideshow($vars);
442
}
443

    
444
/**
445
 * Backwards compatability wrapper.
446
 *
447
 * @see template_preprocess_views_slideshow_pager_fields().
448
 */
449
function _views_slideshow_preprocess_views_slideshow_pager_fields(&$vars) {
450
  template_preprocess_views_slideshow_pager_fields($vars);
451
}
452

    
453
/**
454
 * Backwards compatability wrapper.
455
 *
456
 * @see template_preprocess_views_slideshow_pager_field_item().
457
 */
458
function _views_slideshow_preprocess_views_slideshow_pager_field_item(&$vars) {
459
  template_preprocess_views_slideshow_pager_field_item($vars);
460
}
461

    
462
/**
463
 * Backwards compatability wrapper.
464
 *
465
 * @see template_preprocess_views_slideshow_controls_text().
466
 */
467
function _views_slideshow_preprocess_views_slideshow_controls_text(&$vars) {
468
  template_preprocess_views_slideshow_controls_text($vars);
469
}
470

    
471
/**
472
 * Backwards compatability wrapper.
473
 *
474
 * @see template_preprocess_views_slideshow_controls_text_previous().
475
 */
476
function _views_slideshow_preprocess_views_slideshow_controls_text_previous(&$vars) {
477
  template_preprocess_views_slideshow_controls_text_previous($vars);
478
}
479

    
480
/**
481
 * Backwards compatability wrapper.
482
 *
483
 * @see template_preprocess_views_slideshow_controls_text_pause().
484
 */
485
function _views_slideshow_preprocess_views_slideshow_controls_text_pause(&$vars) {
486
  template_preprocess_views_slideshow_controls_text_pause($vars);
487
}
488

    
489
/**
490
 * Backwards compatability wrapper.
491
 *
492
 * @see template_preprocess_views_slideshow_controls_text_next().
493
 */
494
function _views_slideshow_preprocess_views_slideshow_controls_text_next(&$vars) {
495
  template_preprocess_views_slideshow_controls_text_next($vars);
496
}
497

    
498
/**
499
 * Backwards compatability wrapper.
500
 *
501
 * @see template_preprocess_views_slideshow_slide_counter().
502
 */
503
function _views_slideshow_preprocess_views_slideshow_slide_counter(&$vars) {
504
  template_preprocess_views_slideshow_slide_counter($vars);
505
}