Mercurial > hg > rr-repo
comparison sites/all/modules/views_slideshow/views_slideshow.module @ 2:b74b41bb73f0
-- Google analytics module
author | danieleb <danielebarchiesi@me.com> |
---|---|
date | Thu, 22 Aug 2013 17:22:54 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1:67ce89da90df | 2:b74b41bb73f0 |
---|---|
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 ), | |
17 'views_slideshow_pager_widget_render' => array( | |
18 'variables' => array('vss_id' => NULL, 'view' => NULL, 'settings' => array(), 'location' => NULL, 'rows' => array()), | |
19 'file' => 'theme/views_slideshow.theme.inc', | |
20 ), | |
21 'views_slideshow_pager_fields' => array( | |
22 'variables' => array('vss_id' => NULL, 'view' => NULL, 'settings' => array(), 'location' => NULL, 'attributes' => array()), | |
23 'template' => 'theme/views-slideshow-pager-fields', | |
24 ), | |
25 'views_slideshow_pager_field_field' => array( | |
26 'variables' => array('view' => NULL, 'field' => NULL, 'count' => NULL), | |
27 'template' => 'theme/views-slideshow-pager-field-field', | |
28 'file' => 'theme/views_slideshow.theme.inc', | |
29 ), | |
30 'views_slideshow_pager_field_item' => array( | |
31 'variables' => array('vss_id' => NULL, 'item' => NULL, 'count' => NULL, 'location' => NULL), | |
32 'template' => 'theme/views-slideshow-pager-field-item', | |
33 ), | |
34 'views_slideshow_controls_widget_render' => array( | |
35 'variables' => array('vss_id' => NULL, 'view' => NULL, 'settings' => array(), 'location' => NULL, 'rows' => array()), | |
36 'file' => 'theme/views_slideshow.theme.inc', | |
37 ), | |
38 'views_slideshow_controls_text' => array( | |
39 'variables' => array('vss_id' => NULL, 'view' => NULL, 'settings' => array(), 'location' => NULL, 'rows' => array()), | |
40 'template' => 'theme/views-slideshow-controls-text', | |
41 ), | |
42 'views_slideshow_controls_text_previous' => array( | |
43 'variables' => array('vss_id' => NULL, 'view' => NULL, 'settings' => array()), | |
44 'template' => 'theme/views-slideshow-controls-text-previous', | |
45 ), | |
46 'views_slideshow_controls_text_pause' => array( | |
47 'variables' => array('vss_id' => NULL, 'view' => NULL, 'settings' => array()), | |
48 'template' => 'theme/views-slideshow-controls-text-pause', | |
49 ), | |
50 'views_slideshow_controls_text_next' => array( | |
51 'variables' => array('vss_id' => NULL, 'view' => NULL, 'settings' => array()), | |
52 'template' => 'theme/views-slideshow-controls-text-next', | |
53 ), | |
54 'views_slideshow_slide_counter_widget_render' => array( | |
55 'variables' => array('vss_id' => NULL, 'view' => NULL, 'settings' => array(), 'location' => NULL, 'rows' => array()), | |
56 'file' => 'theme/views_slideshow.theme.inc', | |
57 ), | |
58 'views_slideshow_slide_counter' => array( | |
59 'variables' => array('vss_id' => NULL, 'view' => NULL, 'settings' => array(), 'location' => NULL, 'rows' => array()), | |
60 'template' => 'theme/views-slideshow-slide-counter', | |
61 ), | |
62 ); | |
63 } | |
64 | |
65 /** | |
66 * Implements hook_views_api(). | |
67 */ | |
68 function views_slideshow_views_api() { | |
69 return array( | |
70 'api' => '3', | |
71 ); | |
72 } | |
73 | |
74 /** | |
75 * Implements hook_help(). | |
76 */ | |
77 function views_slideshow_help($path, $arg) { | |
78 switch ($path) { | |
79 case 'admin/help#views_slideshow': | |
80 return '<p>Check the Views Slideshow project page documentation for tutorials and videos on how to use this module.</p>'; | |
81 } | |
82 } | |
83 | |
84 /** | |
85 * Implements hook_init(). | |
86 */ | |
87 function views_slideshow_init() { | |
88 // Load javascript on the page in init to help fool caching. | |
89 drupal_add_js(drupal_get_path('module', 'views_slideshow') . '/js/views_slideshow.js'); | |
90 | |
91 $vs_path = drupal_get_path('module', 'views_slideshow'); | |
92 drupal_add_css($vs_path . '/views_slideshow.css'); | |
93 } | |
94 | |
95 /** | |
96 * Implementation of hook_views_slideshow_skin_info(). | |
97 */ | |
98 function views_slideshow_views_slideshow_skin_info() { | |
99 return array( | |
100 'default' => array( | |
101 'name' => t('Default'), | |
102 ), | |
103 ); | |
104 } | |
105 | |
106 /** | |
107 * Implements hook_views_slideshow_widget_info(). | |
108 */ | |
109 function views_slideshow_views_slideshow_widget_info() { | |
110 return array( | |
111 'views_slideshow_pager' => array( | |
112 'name' => t('Pager'), | |
113 'accepts' => array( | |
114 'transitionBegin' => array('required' => TRUE), | |
115 'goToSlide', | |
116 'previousSlide', | |
117 'nextSlide', | |
118 ), | |
119 'calls' => array( | |
120 'goToSlide', | |
121 'pause', | |
122 'play', | |
123 ), | |
124 ), | |
125 'views_slideshow_controls' => array( | |
126 'name' => t('Controls'), | |
127 'accepts' => array( | |
128 'pause' => array('required' => TRUE), | |
129 'play' => array('required' => TRUE), | |
130 ), | |
131 'calls' => array( | |
132 'nextSlide', | |
133 'pause', | |
134 'play', | |
135 'previousSlide', | |
136 ), | |
137 ), | |
138 'views_slideshow_slide_counter' => array( | |
139 'name' => t('Slide Counter'), | |
140 'accepts' => array( | |
141 'transitionBegin' => array('required' => TRUE), | |
142 'goToSlide', | |
143 'previousSlide', | |
144 'nextSlide', | |
145 ), | |
146 'calls' => array(), | |
147 ), | |
148 ); | |
149 } | |
150 | |
151 /** | |
152 * Implements [widget]_views_slideshow_widget_form_options(). | |
153 */ | |
154 function views_slideshow_pager_views_slideshow_widget_form_options(&$form, &$form_state, &$view, $defaults, $dependency) { | |
155 // Get all the pager info from other modules. | |
156 // hook_views_slideshow_pager_info($view, $option_values, $dependency_prefix) | |
157 $pagers = module_invoke_all('views_slideshow_widget_pager_info', $view); | |
158 | |
159 if (!empty($pagers)) { | |
160 $pager_options = array(); | |
161 foreach($pagers as $pager_id => $pager_info) { | |
162 $pager_options[$pager_id] = $pager_info['name']; | |
163 } | |
164 asort($pager_options); | |
165 | |
166 // Need to wrap this so it indents correctly. | |
167 $form['views_slideshow_pager_wrapper'] = array( | |
168 '#markup' => '<div class="vs-dependent">', | |
169 ); | |
170 | |
171 // Add field to see if they would like to hide pager if there is only one | |
172 // slide. | |
173 $form['hide_on_single_slide'] = array( | |
174 '#type' => 'checkbox', | |
175 '#title' => t('Hide pager if there is only one slide'), | |
176 '#default_value' => $defaults['hide_on_single_slide'], | |
177 '#description' => t('Should the pager be hidden if there is only one slide.'), | |
178 '#states' => array( | |
179 'visible' => array( | |
180 ':input[name="' . $dependency . '[enable]"]' => array('checked' => TRUE), | |
181 ), | |
182 ), | |
183 ); | |
184 | |
185 // Create the widget type field. | |
186 $form['type'] = array( | |
187 '#type' => 'select', | |
188 '#title' => t('Pager Type'), | |
189 '#description' => t('Style of the pager'), | |
190 '#default_value' => $defaults['type'], | |
191 '#options' => $pager_options, | |
192 '#states' => array( | |
193 'visible' => array( | |
194 ':input[name="' . $dependency . '[enable]"]' => array('checked' => TRUE), | |
195 ), | |
196 ), | |
197 ); | |
198 | |
199 // Add any additional form elements | |
200 // Build our arguments to pass to | |
201 // [pager-type]_views_slideshow_widget_pager_form_options | |
202 $arguments = array( | |
203 &$form, | |
204 &$form_state, | |
205 &$view, | |
206 $defaults, | |
207 $dependency, | |
208 ); | |
209 | |
210 foreach ($pagers as $pager_key => $pager_info) { | |
211 $function = $pager_key . '_views_slideshow_widget_pager_form_options'; | |
212 if (function_exists($function)) { | |
213 call_user_func_array($function, $arguments); | |
214 } | |
215 } | |
216 | |
217 $form['views_slideshow_pager_wrapper_close'] = array( | |
218 '#markup' => '</div>', | |
219 ); | |
220 } | |
221 else { | |
222 $form['enable_pager'] = array( | |
223 '#markup' => 'There are no pagers available.', | |
224 ); | |
225 } | |
226 } | |
227 | |
228 /** | |
229 * Implementation of hook_views_slideshow_widget_pager_info | |
230 */ | |
231 function views_slideshow_views_slideshow_widget_pager_info($view) { | |
232 $settings = array(); | |
233 // Settings for fields pager. | |
234 // First verfiy that the view is using fields. | |
235 if ($view->row_plugin->uses_fields()) { | |
236 $settings = array( | |
237 'views_slideshow_pager_fields' => array( | |
238 'name' => t('Fields'), | |
239 ), | |
240 ); | |
241 } | |
242 | |
243 return $settings; | |
244 } | |
245 | |
246 /** | |
247 * Implementation [widget-type]_views_slideshow_pager_form_options | |
248 */ | |
249 function views_slideshow_pager_fields_views_slideshow_widget_pager_form_options(&$form, &$form_state, &$view, $defaults, $dependency) { | |
250 // Settings for fields pager. | |
251 $options = array(); | |
252 // Get each field and it's name. | |
253 foreach ($view->display->handler->get_handlers('field') as $field => $handler) { | |
254 $options[$field] = $handler->ui_name(); | |
255 } | |
256 // Need to wrap this so it indents correctly. | |
257 $form['views_slideshow_pager_fields_wrapper'] = array( | |
258 '#markup' => '<div class="vs-dependent">', | |
259 ); | |
260 // Add ability to choose which fields to show in the pager. | |
261 $form['views_slideshow_pager_fields_fields'] = array( | |
262 '#type' => 'checkboxes', | |
263 '#title' => t('Pager fields'), | |
264 '#options' => $options, | |
265 '#default_value' => $defaults['views_slideshow_pager_fields_fields'], | |
266 '#description' => t("Choose the fields that will appear in the pager."), | |
267 '#process' => array( | |
268 'form_process_checkboxes', | |
269 ), | |
270 '#states' => array( | |
271 'visible' => array( | |
272 ':input[name="' . $dependency . '[enable]"]' => array('checked' => TRUE), | |
273 ':input[name="' . $dependency . '[type]"]' => array('value' => 'views_slideshow_pager_fields'), | |
274 ), | |
275 ), | |
276 ); | |
277 | |
278 // Add field to see if they would like to activate slide and pause on pager | |
279 // hover | |
280 $form['views_slideshow_pager_fields_hover'] = array( | |
281 '#type' => 'checkbox', | |
282 '#title' => t('Activate Slide and Pause on Pager Hover'), | |
283 '#default_value' => $defaults['views_slideshow_pager_fields_hover'], | |
284 '#description' => t('Should the slide be activated and paused when hovering over a pager item.'), | |
285 '#states' => array( | |
286 'visible' => array( | |
287 ':input[name="' . $dependency . '[enable]"]' => array('checked' => TRUE), | |
288 ':input[name="' . $dependency . '[type]"]' => array('value' => 'views_slideshow_pager_fields'), | |
289 ), | |
290 ), | |
291 ); | |
292 | |
293 $form['views_slideshow_pager_fields_wrapper_close'] = array( | |
294 '#markup' => '</div>', | |
295 ); | |
296 } | |
297 | |
298 /** | |
299 * Implements [widget]_views_slideshow_widget_form_options(). | |
300 */ | |
301 function views_slideshow_controls_views_slideshow_widget_form_options(&$form, &$form_state, &$view, $defaults, $dependency) { | |
302 // Get all the control info from other modules. | |
303 // hook_views_slideshow_controls_settings($view, $option_values, $dependency_prefix) | |
304 $controls = module_invoke_all('views_slideshow_widget_controls_info', $view); | |
305 | |
306 if (!empty($controls)) { | |
307 $control_type_options = array(); | |
308 foreach($controls as $control_id => $control_info) { | |
309 $control_type_options[$control_id] = $control_info['name']; | |
310 } | |
311 asort($control_type_options); | |
312 | |
313 // Need to wrap this so it indents correctly. | |
314 $form['views_slideshow_controls_wrapper'] = array( | |
315 '#markup' => '<div class="vs-dependent">', | |
316 ); | |
317 | |
318 // Add field to see if they would like to hide controls if there is only one | |
319 // slide | |
320 $form['hide_on_single_slide'] = array( | |
321 '#type' => 'checkbox', | |
322 '#title' => t('Hide controls if there is only one slide'), | |
323 '#default_value' => $defaults['hide_on_single_slide'], | |
324 '#description' => t('Should the controls be hidden if there is only one slide.'), | |
325 '#states' => array( | |
326 'visible' => array( | |
327 ':input[name="' . $dependency . '[enable]"]' => array('checked' => TRUE), | |
328 ), | |
329 ), | |
330 ); | |
331 | |
332 // Create the widget type field. | |
333 $form['type'] = array( | |
334 '#type' => 'select', | |
335 '#title' => t('Controls Type'), | |
336 '#description' => t('Style of the controls'), | |
337 '#default_value' => $defaults['type'], | |
338 '#options' => $control_type_options, | |
339 '#states' => array( | |
340 'visible' => array( | |
341 ':input[name="' . $dependency . '[enable]"]' => array('checked' => TRUE), | |
342 ), | |
343 ), | |
344 ); | |
345 | |
346 // Add any additional form elements | |
347 // Build our arguments to pass to | |
348 // [pager-type]_views_slideshow_widget_pager_form_options | |
349 $arguments = array( | |
350 &$form, | |
351 &$form_state, | |
352 &$view, | |
353 $defaults, | |
354 $dependency, | |
355 ); | |
356 | |
357 foreach ($controls as $control_key => $control_info) { | |
358 $function = $control_key . '_views_slideshow_widget_controls_form_options'; | |
359 if (function_exists($function)) { | |
360 call_user_func_array($function, $arguments); | |
361 } | |
362 } | |
363 | |
364 $form['controls_wrapper_close'] = array( | |
365 '#markup' => '</div>', | |
366 ); | |
367 } | |
368 else { | |
369 $form['enable_controls'] = array( | |
370 '#markup' => 'There are no controls available.', | |
371 ); | |
372 } | |
373 } | |
374 | |
375 /** | |
376 * Implementation of hook_views_slideshow_controls_info | |
377 */ | |
378 function views_slideshow_views_slideshow_widget_controls_info($view) { | |
379 return array( | |
380 'views_slideshow_controls_text' => array( | |
381 'name' => t('Text'), | |
382 ) | |
383 ); | |
384 } | |
385 | |
386 /** | |
387 * Implements hook_views_slideshow_option_definition. | |
388 */ | |
389 function views_slideshow_views_slideshow_option_definition() { | |
390 | |
391 // Default slideshow type and skins | |
392 $options['slideshow_type'] = array('default' => ''); | |
393 $options['slideshow_skin'] = array('default' => ''); | |
394 $options['skin_info'] = array( | |
395 'default' => array( | |
396 'class' => 'default', | |
397 'name' => t('Untitled skin'), | |
398 'module' => 'views_slideshow', | |
399 'path' => '', | |
400 'stylesheets' => array(), | |
401 ), | |
402 ); | |
403 | |
404 // Set default widgets and weight values. | |
405 $widgets = module_invoke_all('views_slideshow_widget_info'); | |
406 if ($widgets) { | |
407 $locations = array('top', 'bottom'); | |
408 foreach ($locations as $location) { | |
409 foreach ($widgets as $widget_id => $widget_name) { | |
410 $options['widgets']['contains'][$location]['contains'][$widget_id]['contains']['enable'] = array('default' => 0); | |
411 $options['widgets']['contains'][$location]['contains'][$widget_id]['contains']['weight'] = array('default' => 1); | |
412 } | |
413 } | |
414 } | |
415 | |
416 // Defaults for the pager widget. | |
417 foreach ($locations as $location) { | |
418 $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['hide_on_single_slide'] = array('default' => 0); | |
419 $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['type'] = array('default' => 0); | |
420 $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['views_slideshow_pager_numbered_hover'] = array('default' => 0); | |
421 $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['views_slideshow_pager_numbered_click_to_page'] = array('default' => 0); | |
422 $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['views_slideshow_pager_thumbnails_hover'] = array('default' => 0); | |
423 $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['views_slideshow_pager_thumbnails_click_to_page'] = array('default' => 0); | |
424 $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['views_slideshow_pager_fields_fields'] = array('default' => array()); | |
425 $options['widgets']['contains'][$location]['contains']['views_slideshow_pager']['contains']['views_slideshow_pager_fields_hover'] = array('default' => 0); | |
426 | |
427 $options['widgets']['contains'][$location]['contains']['views_slideshow_controls']['contains']['hide_on_single_slide'] = array('default' => 0); | |
428 $options['widgets']['contains'][$location]['contains']['views_slideshow_controls']['contains']['type'] = array('default' => 0); | |
429 } | |
430 | |
431 return $options; | |
432 } | |
433 | |
434 /** | |
435 * Need to have preprocess functions here because drupal doesn't cache them | |
436 * correctly in the theme.inc file. | |
437 * | |
438 * If you would like to override the preprocess functions make sure to look at | |
439 * the associated function in theme.inc. | |
440 */ | |
441 | |
442 // Trying to make sure the theme.inc get's loaded. | |
443 include_once('theme/views_slideshow.theme.inc'); | |
444 | |
445 function template_preprocess_views_slideshow(&$vars) { | |
446 _views_slideshow_preprocess_views_slideshow($vars); | |
447 } | |
448 | |
449 function template_preprocess_views_slideshow_pager_fields(&$vars) { | |
450 _views_slideshow_preprocess_views_slideshow_pager_fields($vars); | |
451 } | |
452 | |
453 function template_preprocess_views_slideshow_pager_field_item(&$vars) { | |
454 _views_slideshow_preprocess_views_slideshow_pager_field_item($vars); | |
455 } | |
456 | |
457 function template_preprocess_views_slideshow_controls_text(&$vars) { | |
458 _views_slideshow_preprocess_views_slideshow_controls_text($vars); | |
459 } | |
460 | |
461 function template_preprocess_views_slideshow_controls_text_previous(&$vars) { | |
462 _views_slideshow_preprocess_views_slideshow_controls_text_previous($vars); | |
463 } | |
464 | |
465 function template_preprocess_views_slideshow_controls_text_pause(&$vars) { | |
466 _views_slideshow_preprocess_views_slideshow_controls_text_pause($vars); | |
467 } | |
468 | |
469 function template_preprocess_views_slideshow_controls_text_next(&$vars) { | |
470 _views_slideshow_preprocess_views_slideshow_controls_text_next($vars); | |
471 } | |
472 | |
473 function template_preprocess_views_slideshow_slide_counter(&$vars) { | |
474 _views_slideshow_preprocess_views_slideshow_slide_counter($vars); | |
475 } |