Projet

Général

Profil

Paste
Télécharger (17,2 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views_slideshow / theme / views_slideshow.theme.inc @ c73bc8d8

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
    $num_divs = count($rows);
61
    $vss_id = $view->name . '-' . $view->current_display;
62

    
63
    // Give each slideshow a unique id if there are more than one on the page.
64
    static $instances = array();
65
    if (isset($instances[$vss_id])) {
66
      $instances[$vss_id]++;
67
      $vss_id .= "_" . $instances[$vss_id];
68
    }
69
    else {
70
      $instances[$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
function theme_views_slideshow_main_section($vars) {
201
  return '<div id="' . $vars['plugin'] . '_main_' . $vars['vss_id'] . '" class="' . $vars['plugin'] . '_main views_slideshow_main">' . $vars['slides'] . '</div>';
202
}
203

    
204
/**
205
 * Views Slideshow: pager.
206
 */
207
function theme_views_slideshow_pager_widget_render($vars) {
208
  if (isset($vars['settings']['hide_on_single_slide']) && $vars['settings']['hide_on_single_slide'] === 1 && count($vars['rows']) < 2) {
209
    return '';
210
  }
211

    
212
  // Add JavaScript settings for the pager type.
213
  $js_vars = array(
214
    'viewsSlideshowPager' => array(
215
      $vars['vss_id'] => array(
216
        $vars['location'] => array(
217
          'type' => views_slideshow_format_addons_name($vars['settings']['type']),
218
          'master_pager' => views_slideshow_format_addons_name($vars['settings']['master_pager']),
219
        ),
220
      ),
221
    ),
222
  );
223

    
224
  drupal_add_library('views_slideshow', 'views_slideshow');
225
  drupal_add_js($js_vars, 'setting');
226

    
227
  // Create some attributes.
228
  $attributes['class'] = 'widget_pager widget_pager_' . $vars['location'];
229
  $attributes['id'] = 'widget_pager_' . $vars['location'] . '_' . $vars['vss_id'];
230
  return theme(views_theme_functions($vars['settings']['type'], $vars['view'], $vars['view']->display[$vars['view']->current_display]), array(
231
    'vss_id' => $vars['vss_id'],
232
    'view' => $vars['view'],
233
    'settings' => $vars['settings']
234
    , 'location' => $vars['location'],
235
    'attributes' => $attributes,
236
  ));
237
}
238

    
239
/**
240
 * Theme pager fields.
241
 */
242
function template_preprocess_views_slideshow_pager_fields(&$vars) {
243
  // Build our JavaScript settings.
244
  $js_vars = array(
245
    'viewsSlideshowPagerFields' => array(
246
      $vars['vss_id'] => array(
247
        $vars['location'] => array(
248
          'activatePauseOnHover' => $vars['settings']['views_slideshow_pager_fields_hover'],
249
        ),
250
      ),
251
    ),
252
  );
253

    
254
  // Add the settings to the page.
255
  drupal_add_library('views_slideshow', 'views_slideshow');
256
  drupal_add_js($js_vars, 'setting');
257

    
258
  // Add hover intent library.
259
  if ($vars['settings']['views_slideshow_pager_fields_hover']) {
260
    if (module_exists('libraries')) {
261
      // Load jQuery hoverIntent.
262
      $hoverIntent_path = libraries_get_path('jquery.hoverIntent');
263
      if (!empty($hoverIntent_path) && file_exists($hoverIntent_path . '/jquery.hoverIntent.js')) {
264
        drupal_add_js($hoverIntent_path . '/jquery.hoverIntent.js');
265
      }
266
    }
267
  }
268

    
269
  $vars['classes_array'][] = $vars['attributes']['class'];
270
  $vars['widget_id'] = $vars['attributes']['id'];
271
  // Add our class to the wrapper.
272
  $vars['classes_array'][] = 'views_slideshow_pager_field';
273

    
274
  // Render all the fields unless there is only 1 slide and the user specified
275
  // to hide them when there is only one slide.
276
  $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;
277
  $vars['rendered_field_items'] = '';
278
  if (empty($vars['settings']['hide_on_single_slide']) || count($vars['view']->result) > $items_per_slide) {
279
    foreach ($vars['view']->result as $count => $node) {
280
      $rendered_fields = '';
281
      foreach ($vars['settings']['views_slideshow_pager_fields_fields'] as $field => $use) {
282
        if ($use !== 0 && is_object($vars['view']->field[$field])) {
283
          $rendered_fields .= theme(views_theme_functions('views_slideshow_pager_field_field', $vars['view'], $vars['view']->display[$vars['view']->current_display]), array(
284
            'view' => $vars['view'],
285
            'field' => $field,
286
            'count' => $count,
287
          ));
288
        }
289
      }
290
      $vars['rendered_field_items'] .= theme(views_theme_functions('views_slideshow_pager_field_item', $vars['view'], $vars['view']->display[$vars['view']->current_display]), array(
291
        'vss_id' => $vars['vss_id'],
292
        'item' => $rendered_fields,
293
        'count' => $count,
294
        'location' => $vars['location'],
295
        'length' => count($vars['view']->result),
296
      ));
297
    }
298
  }
299
}
300

    
301
/**
302
 * Views Slideshow: pager item.
303
 */
304
function template_preprocess_views_slideshow_pager_field_item(&$vars) {
305
  $vars['classes_array'][] = 'views_slideshow_pager_field_item';
306
  $vars['classes_array'][] = ($vars['count'] % 2) ? 'views-row-even' : 'views-row-odd';
307
  if ($vars['count'] == 0) {
308
    $vars['classes_array'][] = 'views-row-first';
309
  }
310
  elseif ($vars['count'] == $vars['length'] - 1) {
311
    $vars['classes_array'][] = 'views-row-last';
312
  }
313
}
314

    
315
/**
316
 * Views Slideshow: pager field item field.
317
 */
318
function template_preprocess_views_slideshow_pager_field_field(&$vars) {
319
  $view = $vars['view'];
320
  $vars['field_item'] = $view->field[$vars['field']];
321
  $vars['field_rendered'] = $view->style_plugin->rendered_fields[$vars['count']][$vars['field']];
322
  $vars['css_id'] = drupal_clean_css_identifier($vars['field_item']->field);
323
  if (!strstr($vars['field_rendered'], '<a')) {
324
    $vars['field_rendered'] = "<a href='#slideshow-${vars['count']}'>${vars['field_rendered']}</a>";
325
  }
326
}
327

    
328
/**
329
 * Views Slideshow: Controls.
330
 */
331
function theme_views_slideshow_controls_widget_render($vars) {
332
  // Add JavaScript settings for the controls type.
333
  $js_vars = array(
334
    'viewsSlideshowControls' => array(
335
      $vars['vss_id'] => array(
336
        $vars['location'] => array(
337
          'type' => views_slideshow_format_addons_name($vars['settings']['type']),
338
        ),
339
      ),
340
    ),
341
  );
342

    
343
  drupal_add_library('views_slideshow', 'views_slideshow');
344
  drupal_add_js($js_vars, 'setting');
345

    
346
  $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;
347
  $output = '';
348
  if (empty($vars['settings']['hide_on_single_slide']) || count($vars['rows']) > $items_per_slide) {
349
    $output = theme(views_theme_functions($vars['settings']['type'], $vars['view'], $vars['view']->display[$vars['view']->current_display]), array(
350
      'vss_id' => $vars['vss_id'],
351
      'view' => $vars['view'],
352
      'settings' => $vars['settings'],
353
      'location' => $vars['location'],
354
      'rows' => $vars['rows'],
355
    ));
356
  }
357

    
358
  return $output;
359
}
360

    
361
/**
362
 * The slideshow controls.
363
 */
364
function template_preprocess_views_slideshow_controls_text(&$vars) {
365
  $module_path = drupal_get_path('module', 'views_slideshow');
366
  drupal_add_css($module_path . '/views_slideshow_controls_text.css', array('type' => 'file'));
367

    
368
  $vars['classes_array'][] = 'views_slideshow_controls_text';
369

    
370
  $vars['rendered_control_previous'] = theme(views_theme_functions('views_slideshow_controls_text_previous', $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_pause'] = theme(views_theme_functions('views_slideshow_controls_text_pause', $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
  $vars['rendered_control_next'] = theme(views_theme_functions('views_slideshow_controls_text_next', $vars['view'], $vars['view']->display[$vars['view']->current_display]), array(
383
    'vss_id' => $vars['vss_id'],
384
    'view' => $vars['view'],
385
    'settings' => $vars['settings'],
386
  ));
387
}
388

    
389
/**
390
 * Views Slideshow: "previous" control.
391
 */
392
function template_preprocess_views_slideshow_controls_text_previous(&$vars) {
393
  $vars['classes_array'][] = 'views_slideshow_controls_text_previous';
394
}
395

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

    
404
/**
405
 * Views Slideshow: "next" control.
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
function theme_views_slideshow_slide_counter_widget_render($vars) {
415
  return theme(views_theme_functions('views_slideshow_slide_counter', $vars['view'], $vars['view']->display[$vars['view']->current_display]), array(
416
    'vss_id' => $vars['vss_id'],
417
    'view' => $vars['view'],
418
    'settings' => $vars['settings'],
419
    'location' => $vars['location'],
420
    'rows' => $vars['rows'],
421
  ));
422
}
423

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

    
432
/**
433
 * Backwards compatability wrapper.
434
 *
435
 * @deprecated Removed in 3.5 when the hook_theme() implementation was fixed.
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
 * @deprecated Removed in 3.5 when the hook_theme() implementation was fixed.
447
 *
448
 * @see template_preprocess_views_slideshow_pager_fields().
449
 */
450
function _views_slideshow_preprocess_views_slideshow_pager_fields(&$vars) {
451
  template_preprocess_views_slideshow_pager_fields($vars);
452
}
453

    
454
/**
455
 * Backwards compatability wrapper.
456
 *
457
 * @deprecated Removed in 3.5 when the hook_theme() implementation was fixed.
458
 *
459
 * @see template_preprocess_views_slideshow_pager_field_item().
460
 */
461
function _views_slideshow_preprocess_views_slideshow_pager_field_item(&$vars) {
462
  template_preprocess_views_slideshow_pager_field_item($vars);
463
}
464

    
465
/**
466
 * Backwards compatability wrapper.
467
 *
468
 * @deprecated Removed in 3.5 when the hook_theme() implementation was fixed.
469
 *
470
 * @see template_preprocess_views_slideshow_controls_text().
471
 */
472
function _views_slideshow_preprocess_views_slideshow_controls_text(&$vars) {
473
  template_preprocess_views_slideshow_controls_text($vars);
474
}
475

    
476
/**
477
 * Backwards compatability wrapper.
478
 *
479
 * @see template_preprocess_views_slideshow_controls_text_previous().
480
 */
481
function _views_slideshow_preprocess_views_slideshow_controls_text_previous(&$vars) {
482
  template_preprocess_views_slideshow_controls_text_previous($vars);
483
}
484

    
485
/**
486
 * Backwards compatability wrapper.
487
 *
488
 * @deprecated Removed in 3.5 when the hook_theme() implementation was fixed.
489
 *
490
 * @see template_preprocess_views_slideshow_controls_text_pause().
491
 */
492
function _views_slideshow_preprocess_views_slideshow_controls_text_pause(&$vars) {
493
  template_preprocess_views_slideshow_controls_text_pause($vars);
494
}
495

    
496
/**
497
 * Backwards compatability wrapper.
498
 *
499
 * @deprecated Removed in 3.5 when the hook_theme() implementation was fixed.
500
 *
501
 * @see template_preprocess_views_slideshow_controls_text_next().
502
 */
503
function _views_slideshow_preprocess_views_slideshow_controls_text_next(&$vars) {
504
  template_preprocess_views_slideshow_controls_text_next($vars);
505
}
506

    
507
/**
508
 * Backwards compatability wrapper.
509
 *
510
 * @deprecated Removed in 3.5 when the hook_theme() implementation was fixed.
511
 *
512
 * @see template_preprocess_views_slideshow_slide_counter().
513
 */
514
function _views_slideshow_preprocess_views_slideshow_slide_counter(&$vars) {
515
  template_preprocess_views_slideshow_slide_counter($vars);
516
}
517

    
518
/**
519
 * @} End of "defgroup vss_theme".
520
 */