comparison sites/all/modules/views_slideshow/theme/views_slideshow.theme.inc @ 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 * The theme system, which controls the output of views slideshow.
6 *
7 * This just adds a wrapper div to the slideshow.
8 */
9
10 function _views_slideshow_preprocess_views_slideshow(&$vars) {
11 $options = $vars['options'];
12 $vars['skin'] = 'default';
13 $vars['slideshow'] = '';
14 $main_frame_module = $options['slideshow_type'];
15
16 if (empty($main_frame_module)) {
17 // Get all slideshow types.
18 $slideshows = module_invoke_all('views_slideshow_slideshow_info');
19
20 if ($slideshows) {
21 foreach ($slideshows as $slideshow_id => $slideshow_info) {
22 $main_frame_module = $slideshow_id;
23 break;
24 }
25 }
26 }
27
28 // Make sure the main slideshow settings are defined before building the
29 // slideshow.
30 if (empty($main_frame_module)) {
31 drupal_set_message(t('No main frame module is enabled for views slideshow.'), 'error');
32 }
33 elseif (empty($options[$main_frame_module])) {
34 drupal_set_message(t('The options for !module does not exists.', array('!module' => $main_frame_module)), 'error');
35 }
36 else {
37 $settings = $options[$main_frame_module];
38 $view = $vars['view'];
39 $rows = $vars['rows'];
40 $num_divs = count($rows);
41 $vss_id = $view->name . '-' . $view->current_display;
42
43 // Give each slideshow a unique id if there are more than one on the page.
44 static $instances = array();
45 if (isset($instances[$vss_id])) {
46 $instances[$vss_id]++;
47 $vss_id .= "_" . $instances[$vss_id];
48 }
49 else {
50 $instances[$vss_id] = 1;
51 }
52
53 // Building our default methods.
54 $methods = array(
55 'goToSlide' => array(),
56 'nextSlide' => array(),
57 'pause' => array(),
58 'play' => array(),
59 'previousSlide' => array(),
60 'transitionBegin' => array(),
61 'transitionEnd' => array(),
62 );
63
64 // Pull all widget info and slideshow info and merge them together.
65 $widgets = module_invoke_all('views_slideshow_widget_info');
66 $slideshows = module_invoke_all('views_slideshow_slideshow_info');
67 $addons = array_merge($widgets, $slideshows);
68
69 // Loop through all the addons and call their methods if needed.
70 foreach ($addons as $addon_id => $addon_info) {
71 foreach ($addon_info['accepts'] as $imp_key => $imp_value) {
72 if (is_array($imp_value)) {
73 $methods[$imp_key][] = preg_replace('/_(.?)/e',"strtoupper('$1')", $addon_id);
74 }
75 else {
76 $methods[$imp_value][] = preg_replace('/_(.?)/e',"strtoupper('$1')", $addon_id);
77 }
78 }
79 }
80
81 $js_settings = array(
82 'viewsSlideshow' => array(
83 $vss_id => array(
84 'methods' => $methods,
85 'paused' => 0,
86 )
87 )
88 );
89 drupal_add_js($js_settings, 'setting');
90
91 /**
92 * Process Skins
93 */
94 $skin_info = array();
95 if (isset($options['skin_info'])) {
96 $skin_info = $options['skin_info'];
97 }
98
99 // Make sure $skin_info has all the values.
100 $skin_info += array(
101 'class' => 'default',
102 'name' => t('Untitled skin'),
103 'module' => 'views_slideshow',
104 'path' => '',
105 'stylesheets' => array(),
106 );
107
108 $vars['skin'] = $skin_info['class'];
109
110 // Enqueue any stylesheets set for the skin on this view are added.
111 $skin_path = drupal_get_path('module', $skin_info['module']);
112 if ($skin_info['path']) {
113 $skin_path .= '/' . $skin_info['path'];
114 }
115
116 // Add stylesheet.
117 if (!empty($skin_info['stylesheets'])) {
118 foreach ($skin_info['stylesheets'] as $stylesheet) {
119 drupal_add_css($skin_path . '/' . $stylesheet);
120 }
121 }
122
123 /**
124 * Process Widgets
125 */
126
127 // Build weights
128 for ($i = 1; $i <= count($widgets); $i++) {
129 $weight['top'][$i] = '';
130 $weight['bottom'][$i] = '';
131 }
132
133 foreach ($widgets as $widget_id => $widget_name) {
134 // Put our widgets in the right location.
135 if ($options['widgets']['top'][$widget_id]['enable']) {
136 $widget_weight = ($options['widgets']['top'][$widget_id]['weight'] > count($widgets)) ? count($widgets) : $options['widgets']['top'][$widget_id]['weight'];
137 $weight['top'][$widget_weight][] = $widget_id;
138 }
139
140 if ($options['widgets']['bottom'][$widget_id]['enable']) {
141 $widget_weight = ($options['widgets']['bottom'][$widget_id]['weight'] > count($widgets)) ? count($widgets) : $options['widgets']['bottom'][$widget_id]['weight'];
142 $weight['bottom'][$widget_weight][] = $widget_id;
143 }
144 }
145
146 // Build our widgets
147 foreach ($weight as $location => $order) {
148 $vars[$location . '_widget_rendered'] = '';
149 foreach ($order as $order_num => $widgets) {
150 if (is_array($widgets)) {
151 foreach ($widgets as $widget_id) {
152 $vars[$widget_id . '_' . $location] = theme($widget_id . '_widget_render', array('vss_id' => $vss_id, 'view' => $view, 'settings' => $options['widgets'][$location][$widget_id], 'location' => $location, 'rows' => $rows));
153 $vars[$location . '_widget_rendered'] .= $vars[$widget_id . '_' . $location];
154 }
155 }
156 }
157 }
158
159 /**
160 * Process Slideshow
161 */
162 $slides = theme($main_frame_module . '_main_frame', array('vss_id' => $vss_id, 'view' => $view, 'settings' => $settings, 'rows' => $rows));
163 $vars['slideshow'] = theme('views_slideshow_main_section', array('vss_id' => $vss_id, 'slides' => $slides, 'plugin' => $main_frame_module));
164 }
165 }
166
167 /**
168 * The current element of the slideshow.
169 *
170 * @ingroup themeable
171 */
172 function theme_views_slideshow_main_section($vars) {
173 return '<div id="' . $vars['plugin'] . '_main_' . $vars['vss_id'] . '" class="' . $vars['plugin'] . '_main views_slideshow_main">' . $vars['slides'] . '</div>';
174 }
175
176 /**
177 * Views Slideshow: pager.
178 *
179 * @ingroup themeable
180 */
181 function theme_views_slideshow_pager_widget_render($vars) {
182 // Add javascript settings for the pager type.
183 $js_vars = array(
184 'viewsSlideshowPager' => array(
185 $vars['vss_id'] => array(
186 $vars['location'] => array(
187 'type' => preg_replace('/_(.?)/e',"strtoupper('$1')", $vars['settings']['type']),
188 ),
189 ),
190 ),
191 );
192
193 drupal_add_js($js_vars, 'setting');
194
195 // Create some attributes
196 $attributes['class'] = 'widget_pager widget_pager_' . $vars['location'];
197 $attributes['id'] = 'widget_pager_' . $vars['location'] . '_' . $vars['vss_id'];
198 return theme($vars['settings']['type'], array('vss_id' => $vars['vss_id'], 'view' => $vars['view'], 'settings' => $vars['settings'], 'location' => $vars['location'], 'attributes' => $attributes));
199 }
200
201 /**
202 * Theme pager fields
203 */
204 function _views_slideshow_preprocess_views_slideshow_pager_fields(&$vars) {
205 // Build our javascript settings.
206 $js_vars = array(
207 'viewsSlideshowPagerFields' => array(
208 $vars['vss_id'] => array(
209 $vars['location'] => array(
210 'activatePauseOnHover' => $vars['settings']['views_slideshow_pager_fields_hover'],
211 ),
212 ),
213 ),
214 );
215
216 // Add the settings to the page.
217 drupal_add_js($js_vars, 'setting');
218
219 // Add hover intent library
220 if ($vars['settings']['views_slideshow_pager_fields_hover']) {
221 if (module_exists('libraries')) {
222 // Load jQuery hoverIntent
223 $hoverIntent_path = libraries_get_path('jquery.hoverIntent');
224 if (!empty($hoverIntent_path) && file_exists($hoverIntent_path . '/jquery.hoverIntent.js')) {
225 drupal_add_js($hoverIntent_path . '/jquery.hoverIntent.js');
226 }
227 }
228 }
229
230 $vars['classes_array'][] = $vars['attributes']['class'];
231 $vars['widget_id'] = $vars['attributes']['id'];
232 // Add our class to the wrapper.
233 $vars['classes_array'][] = 'views_slideshow_pager_field';
234
235 // Render all the fields unless there is only 1 slide and the user specified
236 // to hide them when there is only one slide.
237 $vars['rendered_field_items'] = '';
238 if (empty($vars['settings']['hide_on_single_slide']) && count($vars['view']->result) > 1) {
239 foreach ($vars['view']->result as $count => $node) {
240 $rendered_fields = '';
241 foreach ($vars['settings']['views_slideshow_pager_fields_fields'] as $field => $use) {
242 if ($use !== 0 && is_object($vars['view']->field[$field])) {
243 $rendered_fields .= theme('views_slideshow_pager_field_field', array('view' => $vars['view'], 'field' => $field, 'count' => $count));
244 }
245 }
246 $vars['rendered_field_items'] .= theme('views_slideshow_pager_field_item', array('vss_id' => $vars['vss_id'], 'item' => $rendered_fields, 'count' => $count, 'location' => $vars['location']));
247 }
248 }
249 }
250
251 /**
252 * Views Slideshow: pager item.
253 *
254 * @ingroup themeable
255 */
256 function _views_slideshow_preprocess_views_slideshow_pager_field_item(&$vars) {
257 $vars['classes_array'][] = 'views_slideshow_pager_field_item';
258 if (!$vars['count']) {
259 $vars['classes_array'][] = 'views_slideshow_active_pager_field_item';
260 }
261 $vars['classes_array'][] = ($vars['count'] % 2) ? 'views-row-even' : 'views-row-odd';
262 }
263
264 /**
265 * Views Slideshow: Controls.
266 *
267 * @inggroup themeable
268 */
269 function theme_views_slideshow_controls_widget_render($vars) {
270 // Add javascript settings for the controls type.
271 $js_vars = array(
272 'viewsSlideshowControls' => array(
273 $vars['vss_id'] => array(
274 $vars['location'] => array(
275 'type' => preg_replace('/_(.?)/e',"strtoupper('$1')", $vars['settings']['type']),
276 ),
277 ),
278 ),
279 );
280
281 drupal_add_js($js_vars, 'setting');
282
283 $output = '';
284 if (empty($vars['settings']['hide_on_single_slide']) && count($vars['rows']) > 1) {
285 $output = theme($vars['settings']['type'], array('vss_id' => $vars['vss_id'], 'view' => $vars['view'], 'settings' => $vars['settings'], 'location' => $vars['location'], 'rows' => $vars['rows']));
286 }
287
288 return $output;
289 }
290
291 /**
292 * The slideshow controls.
293 *
294 * @ingroup themeable
295 */
296 function _views_slideshow_preprocess_views_slideshow_controls_text(&$vars) {
297 $module_path = drupal_get_path('module', 'views_slideshow');
298 drupal_add_css($module_path . '/views_slideshow_controls_text.css', array('type' => 'file'));
299
300 $vars['classes_array'][] = 'views_slideshow_controls_text';
301
302 $vars['rendered_control_previous'] = theme('views_slideshow_controls_text_previous', array('vss_id' => $vars['vss_id'], 'view' => $vars['view'], 'settings' => $vars['settings']));
303
304 $vars['rendered_control_pause'] = theme('views_slideshow_controls_text_pause', array('vss_id' => $vars['vss_id'], 'view' => $vars['view'], 'settings' => $vars['settings']));
305
306 $vars['rendered_control_next'] = theme('views_slideshow_controls_text_next', array('vss_id' => $vars['vss_id'], 'view' => $vars['view'], 'settings' => $vars['settings']));
307 }
308
309 /**
310 * Views Slideshow: "previous" control.
311 *
312 * @ingroup themeable
313 */
314 function _views_slideshow_preprocess_views_slideshow_controls_text_previous(&$vars) {
315 $vars['classes_array'][] = 'views_slideshow_controls_text_previous';
316 }
317
318 /**
319 * Views Slideshow: "pause" control.
320 *
321 * @ingroup themeable
322 */
323 function _views_slideshow_preprocess_views_slideshow_controls_text_pause(&$vars) {
324 $vars['classes_array'][] = 'views_slideshow_controls_text_pause';
325 $vars['start_text'] = t('Pause');
326 }
327
328 /**
329 * Views Slideshow: "next" control.
330 *
331 * @ingroup themeable
332 */
333 function _views_slideshow_preprocess_views_slideshow_controls_text_next(&$vars) {
334 $vars['classes_array'][] = 'views_slideshow_controls_text_next';
335 }
336
337 /**
338 * Views Slideshow: Slide Counter.
339 *
340 * @inggroup themeable
341 */
342 function theme_views_slideshow_slide_counter_widget_render($vars) {
343 return theme('views_slideshow_slide_counter', array('vss_id' => $vars['vss_id'], 'view' => $vars['view'], 'settings' => $vars['settings'], 'location' => $vars['location'], 'rows' => $vars['rows']));
344 }
345
346 /**
347 * Views Slideshow: slide counter.
348 */
349 function _views_slideshow_preprocess_views_slideshow_slide_counter(&$vars) {
350 $vars['classes_array'][] = 'views_slideshow_slide_counter';
351 }