comparison sites/all/modules/flexslider_views_slideshow/theme/flexslider_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 * Theme and preprocess functions for Flexslider Views
6 *
7 * @author Mathew Winstone (minorOffense) <mwinstone@coldfrontlabs.ca>
8 */
9
10 /**
11 * FlexSlider Views theme for the main wrapper element
12 *
13 * @ingroup themeable
14 */
15 function _flexslider_views_slideshow_preprocess_flexslider_views_slideshow_main_frame(&$vars) {
16 // @todo see if we can get this to call theme('flexslider') instead.
17 // return
18 // Load the settings, row information, view data and views slideshow ID into
19 // more conveniently named variables.
20 $settings = $vars['settings'];
21 $rows = $vars['rows'];
22 $view = $vars['view'];
23 $vss_id = $vars['vss_id'];
24
25 // Load the option set data
26 $optionset = $settings['optionset'];
27 $settings = flexslider_optionset_load($settings['optionset']);
28 $settings = $settings->options;
29
30
31 // Cast the strings into int or bool as necessary
32 $new_settings = array();
33 foreach ($settings as $key => $value) {
34 if (is_string($value)) {
35
36 $value = str_ireplace("\n", ' ', $value);
37 $value = trim($value);
38
39 // Check for numbers and/or boolean values
40 if (is_numeric($value)) {
41 $value = (int)$value;
42 }
43 elseif (drupal_strtolower($value) == 'true') {
44 $value = TRUE;
45 }
46 elseif (drupal_strtolower($value) == 'false') {
47 $value = FALSE;
48 }
49 }
50
51 $new_settings[$key] = $value;
52 }
53
54 // Merge the existing settings with the generated ones
55 $settings = array_merge(
56 array(
57 'num_divs' => sizeof($rows),
58 'id_prefix' => '#flexslider_views_slideshow_main_',
59 //'div_prefix' => '#'
60 // @todo figure out what the div prefix is used for
61 'vss_id' => $vss_id,
62 ),
63 $new_settings
64 );
65
66 // We need to go through the current js setting values to make sure the one we
67 // want to add is not already there. If it is already there then append -[num]
68 // to the id to make it unique.
69 $slideshow_count = 1;
70 $current_settings = drupal_add_js();
71 foreach ($current_settings['settings']['data'] AS $current_setting) {
72 if (isset($current_setting['flexslider_views_slideshow'])) {
73 $current_keys = array_keys($current_setting['flexslider_views_slideshow']);
74 if (stristr($current_keys[0], '#flexslider_views_slideshow_main_' . $vss_id)) {
75 $slideshow_count++;
76 }
77 }
78 }
79
80 // Append the new unique IDs if required
81 if ($slideshow_count > 1) {
82 $vss_id .= '-' . $slideshow_count;
83 $settings['vss_id'] = $vss_id;
84 }
85
86 // Load the FlexSlider library for use.
87 libraries_load('flexslider');
88
89 // Create the settings container
90 // Due to a limitation inside of views_slideshow, the ID for the settings container
91 // must end with _main
92 //
93 // see lines 162 through 169 in views_slideshow.theme.inc
94 drupal_add_js(array('flexslider_views_slideshow' => array('#flexslider_views_slideshow_main_' . $vss_id => $settings)), 'setting');
95
96 // Load the initilization javascript
97 drupal_add_js(drupal_get_path('module', 'flexslider_views_slideshow') . '/js/flexslider_views_slideshow.js');
98
99 // Required container class for FlexSlider
100 $vars['classes_array'][] = 'slides';
101
102 // Render the rows
103 $rendered_rows = '';
104 $slideshow_count = 0;
105 foreach ($rows as $count => $row) {
106 $items[] = $row;
107 // @todo see if we can group multiple items per slide
108 $rendered_rows .= theme('flexslider_views_slideshow_main_frame_row', array('vss_id' => $vss_id, 'items' => $items, 'count' => $count, 'view' => $view));
109
110 // Clear the items array
111 $items = array();
112 // Count the number of slides created
113 $slideshow_count++;
114 }
115
116 // Save the rendered rows
117 $vars['rendered_rows'] = $rendered_rows;
118 }
119
120 /**
121 * FlexSlider Views Slideshow theme for the row element
122 *
123 * @ingroup themeable
124 */
125 function _flexslider_views_slideshow_preprocess_flexslider_views_slideshow_main_frame_row(&$vars) {
126 $current = $vars['count'] + 1;
127 $vars['classes_array'][] = 'flexslider_views_slideshow_slide views-row-' . $current;
128
129 // @todo figure out why this if statement is here
130 if ($vars['count']) {
131 $vars['classes_array'][] = 'views_slideshow_cycle_hidden';
132 }
133 // @todo add option to toggle views rows counters on/off
134 $vars['classes_array'][] = ($vars['count'] % 2) ? 'views-row-even' : 'views-row-odd';
135
136 $vars['rendered_items'] = '';
137 foreach ($vars['items'] as $item_count => $item) {
138 $vars['rendered_items'] .= theme('flexslider_views_slideshow_main_frame_row_item', array('item' => $item, 'item_count' => $item_count, 'view' => $vars['view']));
139 }
140 }
141
142 /**
143 * FlexSlider Views Slideshow theme for an item within a row
144 *
145 * @ingroup themeable
146 */
147 function _flexslider_views_slideshow_preprocess_flexslider_views_slideshow_main_frame_row_item(&$vars) {
148 $vars['classes_array'][] = 'views-row views-row-' . $vars['item_count'];
149 if (!$vars['item_count']) {
150 $vars['classes_array'][] = 'views-row-first';
151 }
152 if ($vars['item_count'] % 2) {
153 $vars['classes_array'][] = 'views-row-even';
154 }
155 else {
156 $vars['classes_array'][] = 'views-row-odd';
157 }
158
159 /**
160 * Support custom row classes.
161 */
162 if ($row_class = $vars['view']->style_plugin->get_row_class($vars['item_count'])) {
163 $vars['classes_array'][] = $row_class;
164 }
165 }