Projet

Général

Profil

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

root / drupal7 / sites / all / modules / views_slideshow / views_slideshow.module @ 7547bb19

1
<?php
2

    
3
/**
4
 * @file
5
 * Provides Slideshow style options for Views.
6
 */
7

    
8
/**
9
 * Implements hook_theme().
10
 */
11
function views_slideshow_theme($existing, $type, $theme, $path) {
12
  return array(
13
    'views_slideshow_main_section' => array(
14
      'variables' => array('vss_id' => NULL, 'slides' => NULL, 'plugin' => NULL),
15
      'file' => 'theme/views_slideshow.theme.inc',
16
      'pattern' => 'views_slideshow_main_section__',
17
    ),
18
    'views_slideshow_pager_widget_render' => array(
19
      'variables' => array(
20
        'vss_id' => NULL,
21
        'view' => NULL,
22
        'settings' => array(),
23
        'location' => NULL,
24
        'rows' => array(),
25
      ),
26
      'file' => 'theme/views_slideshow.theme.inc',
27
      'pattern' => 'views_slideshow_pager_widget_render__',
28
    ),
29
    'views_slideshow_pager_fields' => array(
30
      'variables' => array(
31
        'vss_id' => NULL,
32
        'view' => NULL,
33
        'settings' => array(),
34
        'location' => NULL,
35
        'attributes' => array(),
36
      ),
37
      'template' => 'theme/views-slideshow-pager-fields',
38
      'file' => 'theme/views_slideshow.theme.inc',
39
      'pattern' => 'views_slideshow_pager_fields__',
40
    ),
41
    'views_slideshow_pager_field_field' => array(
42
      'variables' => array('view' => NULL, 'field' => NULL, 'count' => NULL),
43
      'template' => 'theme/views-slideshow-pager-field-field',
44
      'file' => 'theme/views_slideshow.theme.inc',
45
      'pattern' => 'views_slideshow_pager_field_field__',
46
    ),
47
    'views_slideshow_pager_field_item' => array(
48
      'variables' => array(
49
        'vss_id' => NULL,
50
        'item' => NULL,
51
        'count' => NULL,
52
        'location' => NULL,
53
        'length' => NULL,
54
      ),
55
      'template' => 'theme/views-slideshow-pager-field-item',
56
      'file' => 'theme/views_slideshow.theme.inc',
57
      'pattern' => 'views_slideshow_pager_field_item__',
58
    ),
59
    'views_slideshow_controls_widget_render' => array(
60
      'variables' => array(
61
        'vss_id' => NULL,
62
        'view' => NULL,
63
        'settings' => array(),
64
        'location' => NULL,
65
        'rows' => array(),
66
      ),
67
      'file' => 'theme/views_slideshow.theme.inc',
68
      'pattern' => 'views_slideshow_controls_widget_render__',
69
    ),
70
    'views_slideshow_controls_text' => array(
71
      'variables' => array(
72
        'vss_id' => NULL,
73
        'view' => NULL,
74
        'settings' => array(),
75
        'location' => NULL,
76
        'rows' => array(),
77
      ),
78
      'template' => 'theme/views-slideshow-controls-text',
79
      'file' => 'theme/views_slideshow.theme.inc',
80
      'pattern' => 'views_slideshow_controls_text__',
81
    ),
82
    'views_slideshow_controls_text_previous' => array(
83
      'variables' => array(
84
        'vss_id' => NULL,
85
        'view' => NULL,
86
        'settings' => array(),
87
      ),
88
      'template' => 'theme/views-slideshow-controls-text-previous',
89
      'file' => 'theme/views_slideshow.theme.inc',
90
      'pattern' => 'views_slideshow_controls_text_previous__',
91
    ),
92
    'views_slideshow_controls_text_pause' => array(
93
      'variables' => array(
94
        'vss_id' => NULL,
95
        'view' => NULL,
96
        'settings' => array(),
97
      ),
98
      'template' => 'theme/views-slideshow-controls-text-pause',
99
      'file' => 'theme/views_slideshow.theme.inc',
100
      'pattern' => 'views_slideshow_controls_text_pause__',
101
    ),
102
    'views_slideshow_controls_text_next' => array(
103
      'variables' => array(
104
        'vss_id' => NULL,
105
        'view' => NULL,
106
        'settings' => array(),
107
      ),
108
      'template' => 'theme/views-slideshow-controls-text-next',
109
      'file' => 'theme/views_slideshow.theme.inc',
110
      'pattern' => 'views_slideshow_controls_text_next__',
111
    ),
112
    'views_slideshow_slide_counter_widget_render' => array(
113
      'variables' => array(
114
        'vss_id' => NULL,
115
        'view' => NULL,
116
        'settings' => array(),
117
        'location' => NULL,
118
        'rows' => array(),
119
      ),
120
      'file' => 'theme/views_slideshow.theme.inc',
121
      'pattern' => 'views_slideshow_counter_widget_render__',
122
    ),
123
    'views_slideshow_slide_counter' => array(
124
      'variables' => array(
125
        'vss_id' => NULL,
126
        'view' => NULL,
127
        'settings' => array(),
128
        'location' => NULL,
129
        'rows' => array(),
130
      ),
131
      'template' => 'theme/views-slideshow-slide-counter',
132
      'file' => 'theme/views_slideshow.theme.inc',
133
      'pattern' => 'views_slideshow_slide_counter__',
134
    ),
135
  );
136
}
137

    
138
/**
139
 * Implements hook_views_api().
140
 */
141
function views_slideshow_views_api() {
142
  return array(
143
    'api' => '3',
144
  );
145
}
146

    
147
/**
148
 * Implements hook_help().
149
 */
150
function views_slideshow_help($path, $arg) {
151
  switch ($path) {
152
    case 'admin/help#views_slideshow':
153
      return '<p>Check the Views Slideshow project page documentation for tutorials and videos on how to use this module.</p>';
154
  }
155
}
156

    
157
/**
158
 * Implements hook_library().
159
 */
160
function views_slideshow_library() {
161
  $libraries = array();
162

    
163
  $libraries['views_slideshow'] = array(
164
    'title' => 'Views slideshow',
165
    'version' => '1.0',
166
    'js' => array(
167
      drupal_get_path('module', 'views_slideshow') . '/js/views_slideshow.js' => array(),
168
    ),
169
    'css' => array(
170
      drupal_get_path('module', 'views_slideshow') . '/views_slideshow.css' => array(),
171
    ),
172
  );
173

    
174
  return $libraries;
175
}
176

    
177
/**
178
 * Implements hook_views_slideshow_skin_info().
179
 */
180
function views_slideshow_views_slideshow_skin_info() {
181
  return array(
182
    'default' => array(
183
      'name' => t('Default'),
184
    ),
185
  );
186
}
187

    
188
/**
189
 * Implements hook_views_slideshow_widget_info().
190
 */
191
function views_slideshow_views_slideshow_widget_info() {
192
  return array(
193
    'views_slideshow_pager' => array(
194
      'name' => t('Pager'),
195
      'accepts' => array(
196
        'transitionBegin' => array('required' => TRUE),
197
        'goToSlide' => array(),
198
        'previousSlide' => array(),
199
        'nextSlide' => array(),
200
      ),
201
      'calls' => array(
202
        'goToSlide',
203
        'pause',
204
        'play',
205
      ),
206
    ),
207
    'views_slideshow_controls' => array(
208
      'name' => t('Controls'),
209
      'accepts' => array(
210
        'pause' => array('required' => TRUE),
211
        'play' => array('required' => TRUE),
212
      ),
213
      'calls' => array(
214
        'nextSlide',
215
        'pause',
216
        'play',
217
        'previousSlide',
218
      ),
219
    ),
220
    'views_slideshow_slide_counter' => array(
221
      'name' => t('Slide Counter'),
222
      'accepts' => array(
223
        'transitionBegin' => array('required' => TRUE),
224
        'goToSlide' => array(),
225
        'previousSlide' => array(),
226
        'nextSlide' => array(),
227
      ),
228
      'calls' => array(),
229
    ),
230
  );
231
}
232

    
233
/**
234
 * Implements [widget]_views_slideshow_widget_form_options().
235
 */
236
function views_slideshow_pager_views_slideshow_widget_form_options(&$form, &$form_state, &$view, $defaults, $dependency) {
237
  // Get all the pager info from other modules.
238
  $pagers = module_invoke_all('views_slideshow_widget_pager_info', $view);
239

    
240
  if (!empty($pagers)) {
241
    $pager_options = array();
242
    foreach ($pagers as $pager_id => $pager_info) {
243
      $pager_options[$pager_id] = $pager_info['name'];
244
    }
245
    asort($pager_options);
246

    
247
    // Need to wrap this so it indents correctly.
248
    $form['views_slideshow_pager_wrapper'] = array(
249
      '#markup' => '<div class="vs-dependent">',
250
    );
251

    
252
    // Option for master_pager to control all slideshows in this location.
253
    $form['master_pager'] = array(
254
      '#type' => 'checkbox',
255
      '#title' => t('Master Pager'),
256
      '#default_value' => $defaults['master_pager'],
257
      '#description' => t('Should this pager control all slideshows in this location.'),
258
      '#states' => array(
259
        'visible' => array(
260
          ':input[name="' . $dependency . '[enable]"]' => array('checked' => TRUE),
261
        ),
262
      ),
263
    );
264

    
265
    // Add field to see if they would like to hide pager if there is only one
266
    // slide.
267
    $form['hide_on_single_slide'] = array(
268
      '#type' => 'checkbox',
269
      '#title' => t('Hide pager if there is only one slide'),
270
      '#default_value' => $defaults['hide_on_single_slide'],
271
      '#description' => t('Should the pager be hidden if there is only one slide.'),
272
      '#states' => array(
273
        'visible' => array(
274
          ':input[name="' . $dependency . '[enable]"]' => array('checked' => TRUE),
275
        ),
276
      ),
277
    );
278

    
279
    // Create the widget type field.
280
    $form['type'] = array(
281
      '#type' => 'select',
282
      '#title' => t('Pager Type'),
283
      '#description' => t('Style of the pager'),
284
      '#default_value' => $defaults['type'],
285
      '#options' => $pager_options,
286
      '#states' => array(
287
        'visible' => array(
288
          ':input[name="' . $dependency . '[enable]"]' => array('checked' => TRUE),
289
        ),
290
      ),
291
    );
292

    
293
    // Add any additional form elements
294
    // Build our arguments to pass to
295
    // [pager-type]_views_slideshow_widget_pager_form_options.
296
    $arguments = array(
297
      &$form,
298
      &$form_state,
299
      &$view,
300
      $defaults,
301
      $dependency,
302
    );
303

    
304
    foreach ($pagers as $pager_key => $pager_info) {
305
      $function = $pager_key . '_views_slideshow_widget_pager_form_options';
306
      if (function_exists($function)) {
307
        call_user_func_array($function, $arguments);
308
      }
309
    }
310

    
311
    $form['views_slideshow_pager_wrapper_close'] = array(
312
      '#markup' => '</div>',
313
    );
314
  }
315
  else {
316
    $form['enable_pager'] = array(
317
      '#markup' => 'There are no pagers available.',
318
    );
319
  }
320
}
321

    
322
/**
323
 * Callback for preg_replace_callback.
324
 *
325
 * @see views_slideshow_format_addons_name()
326
 */
327
function _views_slideshow_get_preg_strtoupper_callback($matches) {
328
  if (isset($matches[1])) {
329
    return strtoupper($matches[1]);
330
  }
331
}
332

    
333
/**
334
 * PHP5.x preg_replace_callback() method.
335
 */
336
function views_slideshow_format_addons_name($subject) {
337
  return preg_replace_callback('/_(.?)/', '_views_slideshow_get_preg_strtoupper_callback', $subject);
338
}
339

    
340
/**
341
 * Implements hook_views_slideshow_widget_pager_info().
342
 */
343
function views_slideshow_views_slideshow_widget_pager_info($view) {
344
  $settings = array();
345
  // Settings for fields pager.
346
  // First verfiy that the view is using fields.
347
  if ($view->row_plugin->uses_fields()) {
348
    $settings = array(
349
      'views_slideshow_pager_fields' => array(
350
        'name' => t('Fields'),
351
      ),
352
    );
353
  }
354

    
355
  return $settings;
356
}
357

    
358
/**
359
 * Implements [widget-type]_views_slideshow_pager_form_options().
360
 */
361
function views_slideshow_pager_fields_views_slideshow_widget_pager_form_options(&$form, &$form_state, &$view, $defaults, $dependency) {
362
  // Settings for fields pager.
363
  $options = array();
364
  // Get each field and it's name.
365
  foreach ($view->display->handler->get_handlers('field') as $field => $handler) {
366
    $options[$field] = $handler->ui_name();
367
  }
368
  // Need to wrap this so it indents correctly.
369
  $form['views_slideshow_pager_fields_wrapper'] = array(
370
    '#markup' => '<div class="vs-dependent">',
371
  );
372
  // Add ability to choose which fields to show in the pager.
373
  $form['views_slideshow_pager_fields_fields'] = array(
374
    '#type' => 'checkboxes',
375
    '#title' => t('Pager fields'),
376
    '#options' => $options,
377
    '#default_value' => $defaults['views_slideshow_pager_fields_fields'],
378
    '#description' => t("Choose the fields that will appear in the pager."),
379
    '#process' => array(
380
      'form_process_checkboxes',
381
    ),
382
    '#states' => array(
383
      'visible' => array(
384
        ':input[name="' . $dependency . '[enable]"]' => array('checked' => TRUE),
385
        ':input[name="' . $dependency . '[type]"]' => array('value' => 'views_slideshow_pager_fields'),
386
      ),
387
    ),
388
  );
389

    
390
  // Add field to see if they would like to activate slide and pause on pager
391
  // hover.
392
  $form['views_slideshow_pager_fields_hover'] = array(
393
    '#type' => 'checkbox',
394
    '#title' => t('Activate Slide and Pause on Pager Hover'),
395
    '#default_value' => $defaults['views_slideshow_pager_fields_hover'],
396
    '#description' => t('Should the slide be activated and paused when hovering over a pager item.'),
397
    '#states' => array(
398
      'visible' => array(
399
        ':input[name="' . $dependency . '[enable]"]' => array('checked' => TRUE),
400
        ':input[name="' . $dependency . '[type]"]' => array('value' => 'views_slideshow_pager_fields'),
401
      ),
402
    ),
403
  );
404

    
405
  $form['views_slideshow_pager_fields_wrapper_close'] = array(
406
    '#markup' => '</div>',
407
  );
408
}
409

    
410
/**
411
 * Implements [widget]_views_slideshow_widget_form_options().
412
 */
413
function views_slideshow_controls_views_slideshow_widget_form_options(&$form, &$form_state, &$view, $defaults, $dependency) {
414
  // Get all the control info from other modules.
415
  $controls = module_invoke_all('views_slideshow_widget_controls_info', $view);
416

    
417
  if (!empty($controls)) {
418
    $control_type_options = array();
419
    foreach ($controls as $control_id => $control_info) {
420
      $control_type_options[$control_id] = $control_info['name'];
421
    }
422
    asort($control_type_options);
423

    
424
    // Need to wrap this so it indents correctly.
425
    $form['views_slideshow_controls_wrapper'] = array(
426
      '#markup' => '<div class="vs-dependent">',
427
    );
428

    
429
    // Add field to see if they would like to hide controls if there is only one
430
    // slide.
431
    $form['hide_on_single_slide'] = array(
432
      '#type' => 'checkbox',
433
      '#title' => t('Hide controls if there is only one slide'),
434
      '#default_value' => $defaults['hide_on_single_slide'],
435
      '#description' => t('Should the controls be hidden if there is only one slide.'),
436
      '#states' => array(
437
        'visible' => array(
438
          ':input[name="' . $dependency . '[enable]"]' => array('checked' => TRUE),
439
        ),
440
      ),
441
    );
442

    
443
    // Create the widget type field.
444
    $form['type'] = array(
445
      '#type' => 'select',
446
      '#title' => t('Controls Type'),
447
      '#description' => t('Style of the controls'),
448
      '#default_value' => $defaults['type'],
449
      '#options' => $control_type_options,
450
      '#states' => array(
451
        'visible' => array(
452
          ':input[name="' . $dependency . '[enable]"]' => array('checked' => TRUE),
453
        ),
454
      ),
455
    );
456

    
457
    // Add any additional form elements
458
    // Build our arguments to pass to
459
    // [pager-type]_views_slideshow_widget_pager_form_options.
460
    $arguments = array(
461
      &$form,
462
      &$form_state,
463
      &$view,
464
      $defaults,
465
      $dependency,
466
    );
467

    
468
    foreach ($controls as $control_key => $control_info) {
469
      $function = $control_key . '_views_slideshow_widget_controls_form_options';
470
      if (function_exists($function)) {
471
        call_user_func_array($function, $arguments);
472
      }
473
    }
474

    
475
    $form['controls_wrapper_close'] = array(
476
      '#markup' => '</div>',
477
    );
478
  }
479
  else {
480
    $form['enable_controls'] = array(
481
      '#markup' => 'There are no controls available.',
482
    );
483
  }
484
}
485

    
486
/**
487
 * Implements hook_views_slideshow_controls_info().
488
 */
489
function views_slideshow_views_slideshow_widget_controls_info($view) {
490
  return array(
491
    'views_slideshow_controls_text' => array(
492
      'name' => t('Text'),
493
    ),
494
  );
495
}
496

    
497
/**
498
 * Implements hook_views_slideshow_option_definition().
499
 */
500
function views_slideshow_views_slideshow_option_definition() {
501

    
502
  // Default slideshow type and skins.
503
  $options['slideshow_type'] = array('default' => '');
504
  $options['slideshow_skin'] = array('default' => '');
505
  $options['skin_info'] = array(
506
    'default' => array(
507
      'class' => 'default',
508
      'name' => t('Untitled skin'),
509
      'module' => 'views_slideshow',
510
      'path' => '',
511
      'stylesheets' => array(),
512
    ),
513
  );
514

    
515
  // Set default widgets and weight values.
516
  $widgets = module_invoke_all('views_slideshow_widget_info');
517
  if ($widgets) {
518
    $locations = array('top', 'bottom');
519
    foreach ($locations as $location) {
520
      foreach ($widgets as $widget_id => $widget_name) {
521
        $options['widgets']['contains'][$location]['contains'][$widget_id]['contains']['enable'] = array('default' => 0);
522
        $options['widgets']['contains'][$location]['contains'][$widget_id]['contains']['weight'] = array('default' => 1);
523
      }
524
    }
525
  }
526

    
527
  // Defaults for the pager widget.
528
  foreach ($locations as $location) {
529
    $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['master_pager'] = array('default' => 0);
530
    $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['hide_on_single_slide'] = array('default' => 0);
531
    $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['type'] = array('default' => 0);
532
    $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['views_slideshow_pager_numbered_hover'] = array('default' => 0);
533
    $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['views_slideshow_pager_numbered_click_to_page'] = array('default' => 0);
534
    $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['views_slideshow_pager_thumbnails_hover'] = array('default' => 0);
535
    $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['views_slideshow_pager_thumbnails_click_to_page'] = array('default' => 0);
536
    $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['views_slideshow_pager_fields_fields'] = array('default' => array());
537
    $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['views_slideshow_pager_fields_hover'] = array('default' => 0);
538

    
539
    $options['widgets']['contains'][$location]['contains']['views_slideshow_controls']['contains']['hide_on_single_slide'] = array('default' => 0);
540
    $options['widgets']['contains'][$location]['contains']['views_slideshow_controls']['contains']['type'] = array('default' => 0);
541
  }
542

    
543
  return $options;
544
}