Projet

Général

Profil

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

root / drupal7 / sites / all / modules / views_slideshow / theme / views_slideshow.theme.inc @ 99781f3b

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
        ),
206
      ),
207
    ),
208
  );
209

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

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

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

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

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

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

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

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

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

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

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

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

    
350
  return $output;
351
}
352

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

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

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

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

    
376
  $vars['rendered_control_next'] = theme(views_theme_functions('views_slideshow_controls_text_next', $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
  ));
381
}
382

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

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

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

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

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

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

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

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

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

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

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

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

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