Projet

Général

Profil

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

root / drupal7 / sites / all / modules / views_slideshow / views_slideshow.module @ 87dbc3bf

1
<?php
2

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

    
8
/**
9
 * Implement 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('vss_id' => NULL, 'view' => NULL, 'settings' => array(), 'location' => NULL, 'rows' => array()),
20
      'file' => 'theme/views_slideshow.theme.inc',
21
      'pattern' => 'views_slideshow_pager_widget_render__',
22
    ),
23
    'views_slideshow_pager_fields' => array(
24
      'variables' => array('vss_id' => NULL, 'view' => NULL, 'settings' => array(), 'location' => NULL, 'attributes' => array()),
25
      'template' => 'theme/views-slideshow-pager-fields',
26
      'pattern' => 'views_slideshow_pager_fields__',
27
    ),
28
    'views_slideshow_pager_field_field' => array(
29
      'variables' => array('view' => NULL, 'field' => NULL, 'count' => NULL),
30
      'template' => 'theme/views-slideshow-pager-field-field',
31
      'file' => 'theme/views_slideshow.theme.inc',
32
      'pattern' => 'views_slideshow_pager_field_field__',
33
    ),
34
    'views_slideshow_pager_field_item' => array(
35
      'variables' => array('vss_id' => NULL, 'item' => NULL, 'count' => NULL, 'location' => NULL, 'length' => NULL),
36
      'template' => 'theme/views-slideshow-pager-field-item',
37
      'pattern' => 'views_slideshow_pager_field_item__',
38
    ),
39
    'views_slideshow_controls_widget_render' => array(
40
      'variables' => array('vss_id' => NULL, 'view' => NULL, 'settings' => array(), 'location' => NULL, 'rows' => array()),
41
      'file' => 'theme/views_slideshow.theme.inc',
42
      'pattern' => 'views_slideshow_controls_widget_render__',
43
    ),
44
    'views_slideshow_controls_text' => array(
45
      'variables' => array('vss_id' => NULL, 'view' => NULL, 'settings' => array(), 'location' => NULL, 'rows' => array()),
46
      'template' => 'theme/views-slideshow-controls-text',
47
      'pattern' => 'views_slideshow_controls_text__',
48
    ),
49
    'views_slideshow_controls_text_previous' => array(
50
      'variables' => array('vss_id' => NULL, 'view' => NULL, 'settings' => array()),
51
      'template' => 'theme/views-slideshow-controls-text-previous',
52
      'pattern' => 'views_slideshow_controls_text_previous__',
53
    ),
54
    'views_slideshow_controls_text_pause' => array(
55
      'variables' => array('vss_id' => NULL, 'view' => NULL, 'settings' => array()),
56
      'template' => 'theme/views-slideshow-controls-text-pause',
57
      'pattern' => 'views_slideshow_controls_text_pause__',
58
    ),
59
    'views_slideshow_controls_text_next' => array(
60
      'variables' => array('vss_id' => NULL, 'view' => NULL, 'settings' => array()),
61
      'template' => 'theme/views-slideshow-controls-text-next',
62
      'pattern' => 'views_slideshow_controls_text_next__',
63
    ),
64
    'views_slideshow_slide_counter_widget_render' => array(
65
      'variables' => array('vss_id' => NULL, 'view' => NULL, 'settings' => array(), 'location' => NULL, 'rows' => array()),
66
      'file' => 'theme/views_slideshow.theme.inc',
67
      'pattern' => 'views_slideshow_counter_widget_render__',
68
    ),
69
    'views_slideshow_slide_counter' => array(
70
      'variables' => array('vss_id' => NULL, 'view' => NULL, 'settings' => array(), 'location' => NULL, 'rows' => array()),
71
      'template' => 'theme/views-slideshow-slide-counter',
72
      'pattern' => 'views_slideshow_slide_counter__',
73
    ),
74
  );
75
}
76

    
77
/**
78
 * Implements hook_views_api().
79
 */
80
function views_slideshow_views_api() {
81
  return array(
82
    'api' => '3',
83
  );
84
}
85

    
86
/**
87
 * Implements hook_help().
88
 */
89
function views_slideshow_help($path, $arg) {
90
  switch ($path) {
91
    case 'admin/help#views_slideshow':
92
      return '<p>Check the Views Slideshow project page documentation for tutorials and videos on how to use this module.</p>';
93
  }
94
}
95

    
96
/**
97
 * Implements hook_library().
98
 */
99
function views_slideshow_library() {
100
  $libraries = array();
101

    
102
  $libraries['views_slideshow'] = array(
103
    'title' => 'Views slideshow',
104
    'version' => '1.0',
105
    'js' => array(
106
      drupal_get_path('module', 'views_slideshow') . '/js/views_slideshow.js' => array(),
107
    ),
108
    'css' => array(
109
      drupal_get_path('module', 'views_slideshow') . '/views_slideshow.css' => array(
110
        'type' => 'file',
111
        'media' => 'screen',
112
      ),
113
    ),
114
  );
115

    
116
  return $libraries;
117
}
118

    
119
/**
120
 * Implementation of hook_views_slideshow_skin_info().
121
 */
122
function views_slideshow_views_slideshow_skin_info() {
123
  return array(
124
    'default' => array(
125
      'name' => t('Default'),
126
    ),
127
  );
128
}
129

    
130
/**
131
 * Implements hook_views_slideshow_widget_info().
132
 */
133
function views_slideshow_views_slideshow_widget_info() {
134
  return array(
135
    'views_slideshow_pager' => array(
136
      'name' => t('Pager'),
137
      'accepts' => array(
138
        'transitionBegin' => array('required' => TRUE),
139
        'goToSlide',
140
        'previousSlide',
141
        'nextSlide',
142
      ),
143
      'calls' => array(
144
        'goToSlide',
145
        'pause',
146
        'play',
147
      ),
148
    ),
149
    'views_slideshow_controls' => array(
150
      'name' => t('Controls'),
151
      'accepts' => array(
152
        'pause' => array('required' => TRUE),
153
        'play' => array('required' => TRUE),
154
      ),
155
      'calls' => array(
156
        'nextSlide',
157
        'pause',
158
        'play',
159
        'previousSlide',
160
      ),
161
    ),
162
    'views_slideshow_slide_counter' => array(
163
      'name' => t('Slide Counter'),
164
      'accepts' => array(
165
        'transitionBegin' => array('required' => TRUE),
166
        'goToSlide',
167
        'previousSlide',
168
        'nextSlide',
169
      ),
170
      'calls' => array(),
171
    ),
172
  );
173
}
174

    
175
/**
176
 * Implements [widget]_views_slideshow_widget_form_options().
177
 */
178
function views_slideshow_pager_views_slideshow_widget_form_options(&$form, &$form_state, &$view, $defaults, $dependency) {
179
  // Get all the pager info from other modules.
180
  // hook_views_slideshow_pager_info($view, $option_values, $dependency_prefix)
181
  $pagers = module_invoke_all('views_slideshow_widget_pager_info', $view);
182

    
183
  if (!empty($pagers)) {
184
    $pager_options = array();
185
    foreach($pagers as $pager_id => $pager_info) {
186
      $pager_options[$pager_id] = $pager_info['name'];
187
    }
188
    asort($pager_options);
189

    
190
    // Need to wrap this so it indents correctly.
191
    $form['views_slideshow_pager_wrapper'] = array(
192
      '#markup' => '<div class="vs-dependent">',
193
    );
194

    
195
    // Add field to see if they would like to hide pager if there is only one
196
    // slide.
197
    $form['hide_on_single_slide'] = array(
198
      '#type' => 'checkbox',
199
      '#title' => t('Hide pager if there is only one slide'),
200
      '#default_value' => $defaults['hide_on_single_slide'],
201
      '#description' => t('Should the pager be hidden if there is only one slide.'),
202
      '#states' => array(
203
        'visible' => array(
204
          ':input[name="' . $dependency . '[enable]"]' => array('checked' => TRUE),
205
        ),
206
      ),
207
    );
208

    
209
    // Create the widget type field.
210
    $form['type'] = array(
211
      '#type' => 'select',
212
      '#title' => t('Pager Type'),
213
      '#description' => t('Style of the pager'),
214
      '#default_value' => $defaults['type'],
215
      '#options' => $pager_options,
216
      '#states' => array(
217
        'visible' => array(
218
          ':input[name="' . $dependency . '[enable]"]' => array('checked' => TRUE),
219
        ),
220
      ),
221
    );
222

    
223
    // Add any additional form elements
224
    // Build our arguments to pass to
225
    // [pager-type]_views_slideshow_widget_pager_form_options
226
    $arguments = array(
227
      &$form,
228
      &$form_state,
229
      &$view,
230
      $defaults,
231
      $dependency,
232
    );
233

    
234
    foreach ($pagers as $pager_key => $pager_info) {
235
      $function = $pager_key . '_views_slideshow_widget_pager_form_options';
236
      if (function_exists($function)) {
237
        call_user_func_array($function, $arguments);
238
      }
239
    }
240

    
241
    $form['views_slideshow_pager_wrapper_close'] = array(
242
      '#markup' => '</div>',
243
    );
244
  }
245
  else {
246
    $form['enable_pager'] = array(
247
      '#markup' => 'There are no pagers available.',
248
    );
249
  }
250
}
251

    
252
/**
253
 * preg_replace_callback callback().
254
 * @see views_slideshow_format_addons_name().
255
 */
256
function _views_slideshow_get_preg_strtoupper_callback($matches) {
257
  if (isset($matches[1])) {
258
    return strtoupper($matches[1]);
259
  }
260
}
261

    
262
/**
263
 * php5.x preg_replace_callback() method.
264
 */
265
function views_slideshow_format_addons_name($subject) {
266
  return preg_replace_callback('/_(.?)/', '_views_slideshow_get_preg_strtoupper_callback', $subject);
267
}
268

    
269
/**
270
 * Implementation of hook_views_slideshow_widget_pager_info
271
 */
272
function views_slideshow_views_slideshow_widget_pager_info($view) {
273
  $settings = array();
274
  // Settings for fields pager.
275
  // First verfiy that the view is using fields.
276
  if ($view->row_plugin->uses_fields()) {
277
    $settings = array(
278
      'views_slideshow_pager_fields' => array(
279
        'name' => t('Fields'),
280
      ),
281
    );
282
  }
283

    
284
  return $settings;
285
}
286

    
287
/**
288
 * Implementation [widget-type]_views_slideshow_pager_form_options
289
 */
290
function views_slideshow_pager_fields_views_slideshow_widget_pager_form_options(&$form, &$form_state, &$view, $defaults, $dependency) {
291
  // Settings for fields pager.
292
  $options = array();
293
  // Get each field and it's name.
294
  foreach ($view->display->handler->get_handlers('field') as $field => $handler) {
295
    $options[$field] = $handler->ui_name();
296
  }
297
  // Need to wrap this so it indents correctly.
298
  $form['views_slideshow_pager_fields_wrapper'] = array(
299
    '#markup' => '<div class="vs-dependent">',
300
  );
301
  // Add ability to choose which fields to show in the pager.
302
  $form['views_slideshow_pager_fields_fields'] = array(
303
    '#type' => 'checkboxes',
304
    '#title' => t('Pager fields'),
305
    '#options' => $options,
306
    '#default_value' => $defaults['views_slideshow_pager_fields_fields'],
307
    '#description' => t("Choose the fields that will appear in the pager."),
308
    '#process' => array(
309
      'form_process_checkboxes',
310
    ),
311
    '#states' => array(
312
      'visible' => array(
313
        ':input[name="' . $dependency . '[enable]"]' => array('checked' => TRUE),
314
        ':input[name="' . $dependency . '[type]"]' => array('value' => 'views_slideshow_pager_fields'),
315
      ),
316
    ),
317
  );
318

    
319
  // Add field to see if they would like to activate slide and pause on pager
320
  // hover
321
  $form['views_slideshow_pager_fields_hover'] = array(
322
    '#type' => 'checkbox',
323
    '#title' => t('Activate Slide and Pause on Pager Hover'),
324
    '#default_value' => $defaults['views_slideshow_pager_fields_hover'],
325
    '#description' => t('Should the slide be activated and paused when hovering over a pager item.'),
326
    '#states' => array(
327
      'visible' => array(
328
        ':input[name="' . $dependency . '[enable]"]' => array('checked' => TRUE),
329
        ':input[name="' . $dependency . '[type]"]' => array('value' => 'views_slideshow_pager_fields'),
330
      ),
331
    ),
332
  );
333

    
334
  $form['views_slideshow_pager_fields_wrapper_close'] = array(
335
    '#markup' => '</div>',
336
  );
337
}
338

    
339
/**
340
 * Implements [widget]_views_slideshow_widget_form_options().
341
 */
342
function views_slideshow_controls_views_slideshow_widget_form_options(&$form, &$form_state, &$view, $defaults, $dependency) {
343
  // Get all the control info from other modules.
344
  // hook_views_slideshow_controls_settings($view, $option_values, $dependency_prefix)
345
  $controls = module_invoke_all('views_slideshow_widget_controls_info', $view);
346

    
347
  if (!empty($controls)) {
348
    $control_type_options = array();
349
    foreach($controls as $control_id => $control_info) {
350
      $control_type_options[$control_id] = $control_info['name'];
351
    }
352
    asort($control_type_options);
353

    
354
    // Need to wrap this so it indents correctly.
355
    $form['views_slideshow_controls_wrapper'] = array(
356
      '#markup' => '<div class="vs-dependent">',
357
    );
358

    
359
    // Add field to see if they would like to hide controls if there is only one
360
    // slide
361
    $form['hide_on_single_slide'] = array(
362
      '#type' => 'checkbox',
363
      '#title' => t('Hide controls if there is only one slide'),
364
      '#default_value' => $defaults['hide_on_single_slide'],
365
      '#description' => t('Should the controls be hidden if there is only one slide.'),
366
      '#states' => array(
367
        'visible' => array(
368
          ':input[name="' . $dependency . '[enable]"]' => array('checked' => TRUE),
369
        ),
370
      ),
371
    );
372

    
373
    // Create the widget type field.
374
    $form['type'] = array(
375
      '#type' => 'select',
376
      '#title' => t('Controls Type'),
377
      '#description' => t('Style of the controls'),
378
      '#default_value' => $defaults['type'],
379
      '#options' => $control_type_options,
380
      '#states' => array(
381
        'visible' => array(
382
          ':input[name="' . $dependency . '[enable]"]' => array('checked' => TRUE),
383
        ),
384
      ),
385
    );
386

    
387
    // Add any additional form elements
388
    // Build our arguments to pass to
389
    // [pager-type]_views_slideshow_widget_pager_form_options
390
    $arguments = array(
391
      &$form,
392
      &$form_state,
393
      &$view,
394
      $defaults,
395
      $dependency,
396
    );
397

    
398
    foreach ($controls as $control_key => $control_info) {
399
      $function = $control_key . '_views_slideshow_widget_controls_form_options';
400
      if (function_exists($function)) {
401
        call_user_func_array($function, $arguments);
402
      }
403
    }
404

    
405
    $form['controls_wrapper_close'] = array(
406
      '#markup' => '</div>',
407
    );
408
  }
409
  else {
410
    $form['enable_controls'] = array(
411
      '#markup' => 'There are no controls available.',
412
    );
413
  }
414
}
415

    
416
/**
417
 * Implementation of hook_views_slideshow_controls_info
418
 */
419
function views_slideshow_views_slideshow_widget_controls_info($view) {
420
  return array(
421
    'views_slideshow_controls_text' => array(
422
      'name' => t('Text'),
423
    )
424
  );
425
}
426

    
427
/**
428
 * Implements hook_views_slideshow_option_definition.
429
 */
430
function views_slideshow_views_slideshow_option_definition() {
431

    
432
  // Default slideshow type and skins
433
  $options['slideshow_type'] = array('default' => '');
434
  $options['slideshow_skin'] = array('default' => '');
435
  $options['skin_info'] = array(
436
    'default' => array(
437
      'class' => 'default',
438
      'name' => t('Untitled skin'),
439
      'module' => 'views_slideshow',
440
      'path' => '',
441
      'stylesheets' => array(),
442
    ),
443
  );
444

    
445
  // Set default widgets and weight values.
446
  $widgets = module_invoke_all('views_slideshow_widget_info');
447
  if ($widgets) {
448
    $locations = array('top', 'bottom');
449
    foreach ($locations as $location) {
450
      foreach ($widgets as $widget_id => $widget_name) {
451
        $options['widgets']['contains'][$location]['contains'][$widget_id]['contains']['enable'] = array('default' => 0);
452
        $options['widgets']['contains'][$location]['contains'][$widget_id]['contains']['weight'] = array('default' => 1);
453
      }
454
    }
455
  }
456

    
457
  // Defaults for the pager widget.
458
  foreach ($locations as $location) {
459
    $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['hide_on_single_slide'] = array('default' => 0);
460
    $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['type'] = array('default' => 0);
461
    $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['views_slideshow_pager_numbered_hover'] = array('default' => 0);
462
    $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['views_slideshow_pager_numbered_click_to_page'] = array('default' => 0);
463
    $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['views_slideshow_pager_thumbnails_hover'] = array('default' => 0);
464
    $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['views_slideshow_pager_thumbnails_click_to_page'] = array('default' => 0);
465
    $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['views_slideshow_pager_fields_fields'] = array('default' => array());
466
    $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['views_slideshow_pager_fields_hover'] = array('default' => 0);
467

    
468
    $options['widgets']['contains'][$location]['contains']['views_slideshow_controls']['contains']['hide_on_single_slide'] = array('default' => 0);
469
    $options['widgets']['contains'][$location]['contains']['views_slideshow_controls']['contains']['type'] = array('default' => 0);
470
  }
471

    
472
  return $options;
473
}
474

    
475
/**
476
 * Need to have preprocess functions here because drupal doesn't cache them
477
 * correctly in the theme.inc file.
478
 *
479
 * If you would like to override the preprocess functions make sure to look at
480
 * the associated function in theme.inc.
481
 */
482

    
483
// Trying to make sure the theme.inc get's loaded.
484
include_once('theme/views_slideshow.theme.inc');
485

    
486
function template_preprocess_views_slideshow(&$vars) {
487
  _views_slideshow_preprocess_views_slideshow($vars);
488
}
489

    
490
function template_preprocess_views_slideshow_pager_fields(&$vars) {
491
  _views_slideshow_preprocess_views_slideshow_pager_fields($vars);
492
}
493

    
494
function template_preprocess_views_slideshow_pager_field_item(&$vars) {
495
  _views_slideshow_preprocess_views_slideshow_pager_field_item($vars);
496
}
497

    
498
function template_preprocess_views_slideshow_controls_text(&$vars) {
499
  _views_slideshow_preprocess_views_slideshow_controls_text($vars);
500
}
501

    
502
function template_preprocess_views_slideshow_controls_text_previous(&$vars) {
503
  _views_slideshow_preprocess_views_slideshow_controls_text_previous($vars);
504
}
505

    
506
function template_preprocess_views_slideshow_controls_text_pause(&$vars) {
507
  _views_slideshow_preprocess_views_slideshow_controls_text_pause($vars);
508
}
509

    
510
function template_preprocess_views_slideshow_controls_text_next(&$vars) {
511
  _views_slideshow_preprocess_views_slideshow_controls_text_next($vars);
512
}
513

    
514
function template_preprocess_views_slideshow_slide_counter(&$vars) {
515
  _views_slideshow_preprocess_views_slideshow_slide_counter($vars);
516
}