1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Theme & preprocess functions for the Views Slideshow: cycle module.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Views Slideshow: Theme the main frame wrapper.
|
10
|
*
|
11
|
* @param array $vars
|
12
|
* Theme variables.
|
13
|
*
|
14
|
* @ingroup vss_theme
|
15
|
*/
|
16
|
function template_preprocess_views_slideshow_cycle_main_frame(&$vars) {
|
17
|
$settings = $vars['settings'];
|
18
|
$rows = $vars['rows'];
|
19
|
$view = $vars['view'];
|
20
|
$vss_id = $vars['vss_id'];
|
21
|
|
22
|
// Cast the strings into int or bool as necessary.
|
23
|
$new_settings = array();
|
24
|
foreach ($settings as $key => $value) {
|
25
|
if (is_string($value)) {
|
26
|
$value = str_replace("\n", ' ', $value);
|
27
|
|
28
|
$value = trim($value);
|
29
|
|
30
|
if (is_numeric($value)) {
|
31
|
$value = (int) $value;
|
32
|
}
|
33
|
elseif (strtolower($value) == 'true') {
|
34
|
$value = TRUE;
|
35
|
}
|
36
|
elseif (strtolower($value) == 'false') {
|
37
|
$value = FALSE;
|
38
|
}
|
39
|
}
|
40
|
|
41
|
$new_settings[$key] = $value;
|
42
|
}
|
43
|
|
44
|
$settings = array_merge(
|
45
|
array(
|
46
|
'num_divs' => count($rows),
|
47
|
'id_prefix' => '#views_slideshow_cycle_main_',
|
48
|
'div_prefix' => '#views_slideshow_cycle_div_',
|
49
|
'vss_id' => $vss_id,
|
50
|
),
|
51
|
$new_settings
|
52
|
);
|
53
|
|
54
|
// We need to go through the current js setting values to make sure the one we
|
55
|
// want to add is not already there. If it is already there then append -[num]
|
56
|
// to the id to make it unique.
|
57
|
$slideshow_count = 1;
|
58
|
$current_settings = drupal_add_js();
|
59
|
foreach ($current_settings['settings']['data'] as $current_setting) {
|
60
|
if (isset($current_setting['viewsSlideshowCycle'])) {
|
61
|
$current_keys = array_keys($current_setting['viewsSlideshowCycle']);
|
62
|
if (stristr($current_keys[0], '#views_slideshow_cycle_main_' . $vss_id)) {
|
63
|
$slideshow_count++;
|
64
|
}
|
65
|
}
|
66
|
}
|
67
|
|
68
|
if ($slideshow_count > 1) {
|
69
|
$vss_id .= '-' . $slideshow_count;
|
70
|
$settings['vss_id'] = $vss_id;
|
71
|
}
|
72
|
|
73
|
$module_path = drupal_get_path('module', 'views_slideshow_cycle');
|
74
|
|
75
|
// Don't load JavaScript unless libraries module is present.
|
76
|
if (module_exists('libraries')) {
|
77
|
// Load jQuery Cycle.
|
78
|
if ($cycle_path = _views_slideshow_cycle_library_path()) {
|
79
|
drupal_add_js($cycle_path);
|
80
|
}
|
81
|
|
82
|
// Load Json2.
|
83
|
$json_path = libraries_get_path('json2');
|
84
|
if (!empty($json_path) && file_exists($json_path . '/json2.js')) {
|
85
|
drupal_add_js($json_path . '/json2.js');
|
86
|
}
|
87
|
|
88
|
// Add hover intent library.
|
89
|
if ($settings['pause']) {
|
90
|
$hoverIntent_path = libraries_get_path('jquery.hoverIntent');
|
91
|
if (!empty($hoverIntent_path) && file_exists($hoverIntent_path . '/jquery.hoverIntent.js')) {
|
92
|
drupal_add_js($hoverIntent_path . '/jquery.hoverIntent.js');
|
93
|
}
|
94
|
}
|
95
|
|
96
|
// Add jquery easing library.
|
97
|
if (strstr($settings['advanced_options'], '"eas')) {
|
98
|
$easing_path = libraries_get_path('jquery.easing');
|
99
|
if (!empty($easing_path) && file_exists($easing_path . '/jquery.easing.1.3.js')) {
|
100
|
drupal_add_js($easing_path . '/jquery.easing.1.3.js');
|
101
|
}
|
102
|
}
|
103
|
|
104
|
// Load our cycle js.
|
105
|
drupal_add_js($module_path . '/js/views_slideshow_cycle.js');
|
106
|
|
107
|
// Load the pause library.
|
108
|
if (!empty($settings['pause_in_middle']) && $pause_path = _views_slideshow_cycle_pause_library_path()) {
|
109
|
drupal_add_js($pause_path);
|
110
|
}
|
111
|
}
|
112
|
|
113
|
// Load our cycle css.
|
114
|
drupal_add_css($module_path . '/views_slideshow_cycle.css', 'file');
|
115
|
|
116
|
drupal_add_js(array('viewsSlideshowCycle' => array('#views_slideshow_cycle_main_' . $vss_id => $settings)), 'setting');
|
117
|
|
118
|
// Add the slideshow elements.
|
119
|
$vars['classes_array'][] = 'views_slideshow_cycle_teaser_section';
|
120
|
|
121
|
$styles = array();
|
122
|
if (isset($view->display_handler->display->display_options['style_options']['views_slideshow_cycle'])) {
|
123
|
$styles = $view->display_handler->display->display_options['style_options']['views_slideshow_cycle'];
|
124
|
}
|
125
|
|
126
|
$styles_default = array();
|
127
|
if (isset($view->display['default']->display_options['style_options']['views_slideshow_cycle'])) {
|
128
|
$styles_default = $view->display['default']->display_options['style_options']['views_slideshow_cycle'];
|
129
|
}
|
130
|
|
131
|
// Retrieve the number of items per frame.
|
132
|
if (isset($styles['items_per_slide']) && $styles['items_per_slide'] > 0) {
|
133
|
$items_per_slide = $styles['items_per_slide'];
|
134
|
}
|
135
|
elseif (isset($styles_default['items_per_slide']) && $styles_default['items_per_slide'] > 0) {
|
136
|
$items_per_slide = $styles_default['items_per_slide'];
|
137
|
}
|
138
|
else {
|
139
|
$items_per_slide = 1;
|
140
|
}
|
141
|
|
142
|
$vars['items_per_slide'] = $items_per_slide;
|
143
|
|
144
|
$widgets = $vars['options']['widgets'];
|
145
|
if (isset($widgets['top']['views_slideshow_pager']['enable']) && $widgets['top']['views_slideshow_pager']['enable']) {
|
146
|
$aria = "aria-labelledby='views_slideshow_pager_field_item_top_${vss_id}_";
|
147
|
}
|
148
|
elseif (isset($widgets['bottom']['views_slideshow_pager']['enable']) && $widgets['bottom']['views_slideshow_pager']['enable']) {
|
149
|
$aria = "aria-labelledby='views_slideshow_pager_field_item_bottom_${vss_id}_";
|
150
|
}
|
151
|
else {
|
152
|
$aria = "";
|
153
|
}
|
154
|
|
155
|
|
156
|
$items = array();
|
157
|
$slideshow_count = 0;
|
158
|
$rendered_rows = '';
|
159
|
$last_slide = ceil(count($rows) / $items_per_slide);
|
160
|
foreach ($rows as $count => $item) {
|
161
|
$items[] = $item;
|
162
|
if (count($items) == $items_per_slide || $count == (count($rows) - 1)) {
|
163
|
$slide = array(
|
164
|
'vss_id' => $vss_id,
|
165
|
'items' => $items,
|
166
|
'count' => $slideshow_count,
|
167
|
'view' => $vars['view'],
|
168
|
'last_slide' => $last_slide,
|
169
|
);
|
170
|
if ($aria) {
|
171
|
$slide['aria'] = $aria . $slideshow_count . "'";
|
172
|
}
|
173
|
else {
|
174
|
$slide['aria'] = '';
|
175
|
}
|
176
|
$rendered_rows .= theme(views_theme_functions('views_slideshow_cycle_main_frame_row', $vars['view'], $vars['view']->display[$vars['view']->current_display]), $slide);
|
177
|
$items = array();
|
178
|
$slideshow_count++;
|
179
|
}
|
180
|
}
|
181
|
|
182
|
$vars['rendered_rows'] = $rendered_rows;
|
183
|
}
|
184
|
|
185
|
/**
|
186
|
* Views Slideshow slideshow rows.
|
187
|
*
|
188
|
* @param array $vars
|
189
|
* Theme variables.
|
190
|
*
|
191
|
* @ingroup vss_theme
|
192
|
*/
|
193
|
function template_preprocess_views_slideshow_cycle_main_frame_row(&$vars) {
|
194
|
$current = $vars['count'] + 1;
|
195
|
$vars['classes_array'][] = 'views_slideshow_cycle_slide';
|
196
|
$vars['classes_array'][] = 'views_slideshow_slide views-row-' . $current;
|
197
|
|
198
|
if ($vars['count']) {
|
199
|
$vars['classes_array'][] = 'views_slideshow_cycle_hidden';
|
200
|
if ($current == $vars['last_slide']) {
|
201
|
$vars['classes_array'][] = 'views-row-last';
|
202
|
}
|
203
|
}
|
204
|
else {
|
205
|
$vars['classes_array'][] = 'views-row-first';
|
206
|
}
|
207
|
$vars['classes_array'][] = ($vars['count'] % 2) ? 'views-row-even' : 'views-row-odd';
|
208
|
|
209
|
$vars['rendered_items'] = '';
|
210
|
foreach ($vars['items'] as $item_count => $item) {
|
211
|
$vars['rendered_items'] .= theme(views_theme_functions('views_slideshow_cycle_main_frame_row_item', $vars['view'], $vars['view']->display[$vars['view']->current_display]), array(
|
212
|
'item' => $item,
|
213
|
'item_count' => $item_count,
|
214
|
'count' => $vars['count'],
|
215
|
'view' => $vars['view'],
|
216
|
'length' => count($vars['items']),
|
217
|
));
|
218
|
}
|
219
|
}
|
220
|
|
221
|
/**
|
222
|
* Implements hook_preprocess_views_slideshow_cycle_main_frame_row_item().
|
223
|
*
|
224
|
* @param array $vars
|
225
|
* Theme variables.
|
226
|
*
|
227
|
* @ingroup vss_theme
|
228
|
*/
|
229
|
function template_preprocess_views_slideshow_cycle_main_frame_row_item(&$vars) {
|
230
|
$vars['classes_array'][] = 'views-row views-row-' . $vars['item_count'];
|
231
|
$vars['classes_array'][] = ($vars['item_count'] % 2) ? 'views-row-even' : 'views-row-odd';
|
232
|
if ($vars['count'] == 0) {
|
233
|
$vars['classes_array'][] = 'views-row-first';
|
234
|
}
|
235
|
elseif ($vars['count'] == $vars['length'] - 1) {
|
236
|
$vars['classes_array'][] = 'views-row-last';
|
237
|
}
|
238
|
|
239
|
// Support custom row classes.
|
240
|
if ($row_class = $vars['view']->style_plugin->get_row_class($vars['count'])) {
|
241
|
$vars['classes_array'][] = $row_class;
|
242
|
}
|
243
|
}
|
244
|
|
245
|
/**
|
246
|
* Implements hook_preprocess_views_slideshow_pager_fields().
|
247
|
*
|
248
|
* @param array $vars
|
249
|
* Theme variables.
|
250
|
*
|
251
|
* @ingroup vss_theme
|
252
|
*/
|
253
|
function views_slideshow_cycle_preprocess_views_slideshow_pager_fields(&$vars) {
|
254
|
$slide_count = count($vars['view']->result);
|
255
|
$items_per_slide = $vars['view']->style_options['views_slideshow_cycle']['items_per_slide'];
|
256
|
|
257
|
if ($vars['view']->style_options['slideshow_type'] == 'views_slideshow_cycle') {
|
258
|
$slide_count = $slide_count / $items_per_slide;
|
259
|
$slide_count = ceil($slide_count);
|
260
|
}
|
261
|
|
262
|
$vars['rendered_field_items'] = '';
|
263
|
if (empty($vars['settings']['hide_on_single_slide']) || $slide_count > 1) {
|
264
|
foreach ($vars['view']->result as $count => $node) {
|
265
|
if ($count < $slide_count) {
|
266
|
$rendered_fields = '';
|
267
|
foreach ($vars['settings']['views_slideshow_pager_fields_fields'] as $field => $use) {
|
268
|
if ($use !== 0 && is_object($vars['view']->field[$field])) {
|
269
|
$rendered_fields .= theme(views_theme_functions('views_slideshow_pager_field_field', $vars['view'], $vars['view']->display[$vars['view']->current_display]), array(
|
270
|
'view' => $vars['view'],
|
271
|
'field' => $field,
|
272
|
'count' => $count,
|
273
|
));
|
274
|
}
|
275
|
}
|
276
|
$vars['rendered_field_items'] .= theme(views_theme_functions('views_slideshow_pager_field_item', $vars['view'], $vars['view']->display[$vars['view']->current_display]), array(
|
277
|
'vss_id' => $vars['vss_id'],
|
278
|
'item' => $rendered_fields,
|
279
|
'count' => $count,
|
280
|
'location' => $vars['location'],
|
281
|
'view' => $vars['view'],
|
282
|
));
|
283
|
}
|
284
|
}
|
285
|
}
|
286
|
}
|
287
|
|
288
|
/**
|
289
|
* Implements hook_preprocess_views_slideshow_slide_counter().
|
290
|
*
|
291
|
* @param array $vars
|
292
|
* Theme variables.
|
293
|
*
|
294
|
* @ingroup vss_theme
|
295
|
*/
|
296
|
function views_slideshow_cycle_preprocess_views_slideshow_slide_counter(&$vars) {
|
297
|
if ($vars['view']->style_options['slideshow_type'] == 'views_slideshow_cycle') {
|
298
|
$vars['slide_count'] = $vars['slide_count'] / $vars['view']->style_options['views_slideshow_cycle']['items_per_slide'];
|
299
|
$vars['slide_count'] = ceil($vars['slide_count']);
|
300
|
}
|
301
|
}
|
302
|
|
303
|
/**
|
304
|
* Backwards comparability wrapper.
|
305
|
*
|
306
|
* @param array $vars
|
307
|
* Theme variables.
|
308
|
*
|
309
|
* @deprecated Removed in 3.5 when the hook_theme() implementation was fixed.
|
310
|
*
|
311
|
* @see template_preprocess_views_slideshow_cycle_main_frame().
|
312
|
*
|
313
|
* @ingroup vss_theme
|
314
|
*/
|
315
|
function _views_slideshow_cycle_preprocess_views_slideshow_cycle_main_frame(&$vars) {
|
316
|
template_preprocess_views_slideshow_cycle_main_frame($vars);
|
317
|
}
|
318
|
|
319
|
/**
|
320
|
* Backwards compatibility wrapper.
|
321
|
*
|
322
|
* @param array $vars
|
323
|
* Theme variables.
|
324
|
*
|
325
|
* @deprecated Removed in 3.5 when the hook_theme() implementation was fixed.
|
326
|
*
|
327
|
* @see template_preprocess_views_slideshow_cycle_main_frame_row().
|
328
|
*
|
329
|
* @ingroup vss_theme
|
330
|
*/
|
331
|
function _views_slideshow_cycle_preprocess_views_slideshow_cycle_main_frame_row(&$vars) {
|
332
|
template_preprocess_views_slideshow_cycle_main_frame_row($vars);
|
333
|
}
|
334
|
|
335
|
/**
|
336
|
* Backwards compatibility wrapper.
|
337
|
*
|
338
|
* @param array $vars
|
339
|
* Theme variables.
|
340
|
*
|
341
|
* @deprecated Removed in 3.5 when the hook_theme() implementation was fixed.
|
342
|
*
|
343
|
* @see template_preprocess_views_slideshow_cycle_main_frame_row_item().
|
344
|
*
|
345
|
* @ingroup vss_theme
|
346
|
*/
|
347
|
function _views_slideshow_cycle_preprocess_views_slideshow_cycle_main_frame_row_item(&$vars) {
|
348
|
template_preprocess_views_slideshow_cycle_main_frame_row_item($vars);
|
349
|
}
|