1
|
<?php
|
2
|
/**
|
3
|
* @file
|
4
|
* Theming functions for the flexslider module.
|
5
|
*
|
6
|
* Preprocessor functions fill variables for templates and helper
|
7
|
* functions to make theming easier.
|
8
|
*/
|
9
|
|
10
|
/**
|
11
|
* Default theme implementation for flexslider_list
|
12
|
*/
|
13
|
function theme_flexslider_list(&$variables) {
|
14
|
// Reference configuration variables
|
15
|
$optionset = &$variables['settings']['optionset'];
|
16
|
$items = &$variables['items'];
|
17
|
$attributes = &$variables['settings']['attributes'];
|
18
|
$type = &$variables['settings']['type'];
|
19
|
$output = '';
|
20
|
|
21
|
// Build the list
|
22
|
if (!empty($items)) {
|
23
|
$output .= "<$type" . drupal_attributes($attributes) . '>';
|
24
|
foreach ($items as $item) {
|
25
|
|
26
|
$caption = '';
|
27
|
if (!empty($item['caption'])) {
|
28
|
$caption = $item['caption'];
|
29
|
}
|
30
|
|
31
|
$output .= theme('flexslider_list_item', array(
|
32
|
'item' => $item['slide'],
|
33
|
'settings' => array(
|
34
|
'optionset' => $optionset,
|
35
|
),
|
36
|
'caption' => $caption,
|
37
|
));
|
38
|
}
|
39
|
$output .= "</$type>";
|
40
|
}
|
41
|
|
42
|
return $output;
|
43
|
}
|
44
|
|
45
|
/**
|
46
|
* Default theme implementation for flexslider_list_item
|
47
|
*/
|
48
|
function theme_flexslider_list_item(&$variables) {
|
49
|
return '<li' . drupal_attributes($variables['settings']['attributes']) . '>' . $variables['item'] . $variables['caption'] . "</li>\n";
|
50
|
}
|
51
|
|
52
|
/**
|
53
|
* Prepares variables for flexslider templates.
|
54
|
*
|
55
|
* @see flexslider.tpl.php.
|
56
|
*/
|
57
|
function template_process_flexslider(&$variables) {
|
58
|
|
59
|
// Reference configuration variables
|
60
|
$optionset = &$variables['settings']['optionset'];
|
61
|
$settings = &$variables['settings'];
|
62
|
$items = &$variables['items'];
|
63
|
|
64
|
// Set the default container type
|
65
|
if (empty($settings['type'])) {
|
66
|
$settings['type'] = 'ul';
|
67
|
}
|
68
|
|
69
|
// Load the selected optionset
|
70
|
if (!empty($optionset)) {
|
71
|
$optionset = flexslider_optionset_load($optionset);
|
72
|
}
|
73
|
|
74
|
// Check if an optionset was loaded
|
75
|
if (empty($optionset)) {
|
76
|
// Fall back to 'default' option set
|
77
|
$optionset = flexslider_optionset_load('default');
|
78
|
watchdog('flexslider', 'Fallback to default optionset.', array(), WATCHDOG_WARNING);
|
79
|
}
|
80
|
|
81
|
// Configure attributes for containing elements
|
82
|
$attributes = array();
|
83
|
// Merge with defined attributes
|
84
|
if (isset($settings['attributes']) and is_array($settings['attributes'])) {
|
85
|
$attributes += $settings['attributes'];
|
86
|
}
|
87
|
|
88
|
// Set the ID for each flexslider instance if none is provided
|
89
|
if (empty($attributes['id'])) {
|
90
|
$flexslider_id = &drupal_static('flexslider_id', 0);
|
91
|
$attributes['id'] = 'flexslider-' . ++$flexslider_id;
|
92
|
}
|
93
|
|
94
|
// Add the namespace to any classes
|
95
|
// @todo figure out what this is supposed to do
|
96
|
if (!empty($attributes['class']) && !empty($optionset->options['namespace'])) {
|
97
|
foreach ($attributes['class'] as $key => $value) {
|
98
|
$attributes['class'][$key] = $optionset->options['namespace'] . $value;
|
99
|
}
|
100
|
}
|
101
|
|
102
|
// Add the flexslider class to be namespaced
|
103
|
$attributes['class'][] = 'flexslider';
|
104
|
|
105
|
// Add the optionset name as a class to the container.
|
106
|
$attributes['class'][] = 'optionset-' . drupal_html_class($optionset->name);
|
107
|
|
108
|
// Add the image style name as a class to the container.
|
109
|
if (!empty($settings['image_style'])) {
|
110
|
$attributes['class'][] = 'imagestyle-' . drupal_html_class($settings['image_style']);
|
111
|
}
|
112
|
|
113
|
// Add the attributes to the settings array.
|
114
|
$settings['attributes'] = $attributes;
|
115
|
|
116
|
// Finally, add the configuration to the page
|
117
|
flexslider_add($variables['settings']['attributes']['id'], $variables['settings']['optionset']);
|
118
|
}
|
119
|
|
120
|
/**
|
121
|
* Prepares variables for flexslider list templates.
|
122
|
*
|
123
|
* @see flexslider-list.tpl.php.
|
124
|
*/
|
125
|
function template_process_flexslider_list(&$variables) {
|
126
|
// Reset the list of attributes
|
127
|
$variables['settings']['attributes'] = array(
|
128
|
// @todo find a way to detect the outter container class if possible
|
129
|
'class' => array('slides'),
|
130
|
);
|
131
|
|
132
|
}
|
133
|
|
134
|
/**
|
135
|
* Prepares variables for flexslider list item templates.
|
136
|
*
|
137
|
* @see flexslider-list-item.tpl.php.
|
138
|
*/
|
139
|
function template_process_flexslider_list_item(&$variables) {
|
140
|
// Reset the list of attributes
|
141
|
$variables['settings']['attributes'] = array();
|
142
|
|
143
|
// Reference configuration variables
|
144
|
$item = &$variables['item'];
|
145
|
$settings = &$variables['settings'];
|
146
|
$caption = &$variables['caption'];
|
147
|
$attributes = &$variables['settings']['attributes'];
|
148
|
|
149
|
// Generated thumbnail support
|
150
|
if (isset($settings['optionset']->options['controlNav']) and $settings['optionset']->options['controlNav'] === "thumbnails") {
|
151
|
// If the thumbnails are enabled in the option set, scan for the first img
|
152
|
// tag and extract the src attribute to set as the thumbnail data
|
153
|
$src = array();
|
154
|
preg_match("/<img.+?src=[\"'](.+?)[\"'].+?>/", $item, $src);
|
155
|
|
156
|
if (!empty($src[1])) {
|
157
|
$attributes['data-thumb'] = $src[1];
|
158
|
}
|
159
|
|
160
|
// Let's also get the alt attribute to apply to thumbnails.
|
161
|
// This only works in library version 2.6+.
|
162
|
$alt = array();
|
163
|
preg_match("/<img.+?alt=[\"'](.*?)[\"'].+?>/", $item, $alt);
|
164
|
|
165
|
if (!empty($alt)) {
|
166
|
$attributes['data-thumb-alt'] = $alt[1];
|
167
|
}
|
168
|
}
|
169
|
|
170
|
if (isset($settings['optionset']->options['thumbCaptions']) and $settings['optionset']->options['thumbCaptions'] and !empty($caption)) {
|
171
|
$attributes['data-thumbcaption'] = $caption;
|
172
|
// Prevent captions from appearing in the slider as well
|
173
|
if (isset($settings['optionset']->options['thumbCaptionsBoth']) and FALSE === $settings['optionset']->options['thumbCaptionsBoth']) {
|
174
|
$caption = '';
|
175
|
}
|
176
|
}
|
177
|
|
178
|
if (!empty($caption)) {
|
179
|
$caption = '<div class="flex-caption">' . $caption . '</div>';
|
180
|
}
|
181
|
}
|