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