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(&$vars) {
|
14
|
// Reference configuration variables
|
15
|
$optionset = &$vars['settings']['optionset'];
|
16
|
$items = &$vars['items'];
|
17
|
$attributes = &$vars['settings']['attributes'];
|
18
|
$type = &$vars['settings']['type'];
|
19
|
$output = '';
|
20
|
|
21
|
// Build the list
|
22
|
if (!empty($items)) {
|
23
|
$output .= "<$type" . drupal_attributes($attributes) . '>';
|
24
|
foreach ($items as $i => $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(&$vars) {
|
49
|
return '<li' . drupal_attributes($vars['settings']['attributes']) . '>' . $vars['item'] . $vars['caption'] . "</li>\n";
|
50
|
}
|
51
|
|
52
|
/**
|
53
|
* Template preprocess handler for 'flexslider' theme.
|
54
|
*/
|
55
|
function template_process_flexslider(&$vars) {
|
56
|
|
57
|
// Reference configuration variables
|
58
|
$optionset = &$vars['settings']['optionset'];
|
59
|
$settings = &$vars['settings'];
|
60
|
$items = &$vars['items'];
|
61
|
|
62
|
// Set the default container type
|
63
|
if (empty($settings['type'])) {
|
64
|
$settings['type'] = 'ul';
|
65
|
}
|
66
|
|
67
|
// Load the selected optionset
|
68
|
if (!empty($optionset)) {
|
69
|
$optionset = flexslider_optionset_load($optionset);
|
70
|
}
|
71
|
|
72
|
// Check if an optionset was loaded
|
73
|
if (empty($optionset)) {
|
74
|
// Fall back to 'default' option set
|
75
|
$optionset = flexslider_optionset_load('default');
|
76
|
watchdog('flexslider', 'Fallback to default optionset.', array(), WATCHDOG_WARNING);
|
77
|
}
|
78
|
|
79
|
// Configure attributes for containing elements
|
80
|
$attributes = array();
|
81
|
// Merge with defined attributes
|
82
|
if (isset($settings['attributes']) and is_array($settings['attributes'])) {
|
83
|
$attributes += $settings['attributes'];
|
84
|
}
|
85
|
|
86
|
// Set the ID for each flexslider instance if none is provided
|
87
|
if (empty($attributes['id'])) {
|
88
|
$flexslider_id = &drupal_static('flexslider_id', 0);
|
89
|
$attributes['id'] = 'flexslider-' . ++$flexslider_id;
|
90
|
}
|
91
|
|
92
|
// Add the namespace to any classes
|
93
|
// @todo figure out what this is supposed to do
|
94
|
if (!empty($attributes['class']) && !empty($optionset->options['namespace'])) {
|
95
|
foreach ($attributes['class'] as $key => $value) {
|
96
|
$attributes['class'][$key] = $optionset->options['namespace'] . $value;
|
97
|
}
|
98
|
}
|
99
|
|
100
|
// Add the flexslider class to be namespaced
|
101
|
$attributes['class'][] = 'flexslider';
|
102
|
|
103
|
// Add the attributes to the settings array.
|
104
|
$settings['attributes'] = $attributes;
|
105
|
|
106
|
// Finally, add the configuration to the page
|
107
|
flexslider_add($vars['settings']['attributes']['id'], $vars['settings']['optionset']);
|
108
|
}
|
109
|
|
110
|
/**
|
111
|
* Process function for flexslider_list_item
|
112
|
*/
|
113
|
function template_process_flexslider_list(&$vars) {
|
114
|
// Reset the list of attributes
|
115
|
$vars['settings']['attributes'] = array(
|
116
|
// @todo find a way to detect the outter container class if possible
|
117
|
'class' => array('slides'),
|
118
|
);
|
119
|
|
120
|
}
|
121
|
|
122
|
/**
|
123
|
* Process function for flexslider_list_item
|
124
|
*/
|
125
|
function template_process_flexslider_list_item(&$vars) {
|
126
|
// Reset the list of attributes
|
127
|
$vars['settings']['attributes'] = array();
|
128
|
|
129
|
// Reference configuration variables
|
130
|
$item = &$vars['item'];
|
131
|
$settings = &$vars['settings'];
|
132
|
$caption = &$vars['caption'];
|
133
|
$attributes = &$vars['settings']['attributes'];
|
134
|
|
135
|
// Generated thumbnail support
|
136
|
if (isset($settings['optionset']->options['controlNav']) and $settings['optionset']->options['controlNav'] === "thumbnails") {
|
137
|
// If the thumbnails are enabled in the option set, scan for the first img
|
138
|
// tag and extract the src attribute to set as the thumbnail data
|
139
|
$src = array();
|
140
|
preg_match("<img.+?src=[\"'](.+?)[\"'].+?>", $item, $src);
|
141
|
|
142
|
if (!empty($src[1])) {
|
143
|
$attributes['data-thumb'] = $src[1];
|
144
|
}
|
145
|
}
|
146
|
|
147
|
if (isset($settings['optionset']->options['thumbCaptions']) and $settings['optionset']->options['thumbCaptions'] and !empty($caption)) {
|
148
|
$attributes['data-thumbcaption'] = $caption;
|
149
|
// Prevent captions from appearing in the slider as well
|
150
|
if (isset($settings['optionset']->options['thumbCaptionsBoth']) and FALSE === $settings['optionset']->options['thumbCaptionsBoth']) {
|
151
|
$caption = '';
|
152
|
}
|
153
|
}
|
154
|
|
155
|
if (!empty($caption)) {
|
156
|
$caption = '<div class="flex-caption">' . $caption . '</div>';
|
157
|
}
|
158
|
}
|