|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Flex Slider specific markup, javascript, css and settings. |
|
5
|
|
|
*/ |
|
6
|
|
|
class MetaFlexSlider extends MetaSlider |
|
|
|
|
|
|
7
|
|
|
{ |
|
8
|
|
|
protected $js_function = 'flexslider'; |
|
9
|
|
|
protected $js_path = 'sliders/flexslider/jquery.flexslider-min.js'; |
|
10
|
|
|
protected $css_path = 'sliders/flexslider/flexslider.css'; |
|
11
|
|
|
protected $carousel_item_margin = 5; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Constructor |
|
15
|
|
|
* |
|
16
|
|
|
* @param integer $id slideshow ID |
|
17
|
|
|
* @param $shortcode_settings |
|
18
|
|
|
*/ |
|
19
|
|
|
public function __construct($id, $shortcode_settings) |
|
20
|
|
|
{ |
|
21
|
|
|
parent::__construct($id, $shortcode_settings); |
|
22
|
|
|
|
|
23
|
|
|
add_filter('metaslider_flex_slider_parameters', array($this, 'enable_carousel_mode'), 10, 2); |
|
24
|
|
|
add_filter('metaslider_flex_slider_parameters', array($this, 'enable_easing'), 10, 2); |
|
25
|
|
|
add_filter('metaslider_css', array($this, 'get_carousel_css'), 11, 3); |
|
26
|
|
|
add_filter('metaslider_css_classes', array($this, 'remove_bottom_margin'), 11, 3); |
|
27
|
|
|
|
|
28
|
|
|
$this->carousel_item_margin = apply_filters('metaslider_carousel_margin', $this->carousel_item_margin, $id); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Adjust the slider parameters so they're comparible with the carousel mode |
|
33
|
|
|
* |
|
34
|
|
|
* @param array $options |
|
35
|
|
|
* @param integer $slider_id |
|
36
|
|
|
* @return array $options |
|
37
|
|
|
*/ |
|
38
|
|
|
public function enable_carousel_mode($options, $slider_id) |
|
|
|
|
|
|
39
|
|
|
{ |
|
40
|
|
|
if (isset($options['carouselMode'])) { |
|
41
|
|
|
if ($options['carouselMode'] === 'true') { |
|
42
|
|
|
$options['itemWidth'] = $this->get_setting('width'); |
|
43
|
|
|
$options['animation'] = "'slide'"; |
|
44
|
|
|
$options['direction'] = "'horizontal'"; |
|
45
|
|
|
$options['minItems'] = 1; |
|
46
|
|
|
$options['itemMargin'] = $this->carousel_item_margin; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
unset($options['carouselMode']); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
// we don't want this filter hanging around if there's more than one slideshow on the page |
|
53
|
|
|
remove_filter('metaslider_flex_slider_parameters', array($this, 'enable_carousel_mode'), 10, 2); |
|
54
|
|
|
|
|
55
|
|
|
return $options; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Ensure CSS transitions are disabled when easing is enabled. |
|
60
|
|
|
* |
|
61
|
|
|
* @param array $options |
|
62
|
|
|
* @param integer $slider_id |
|
63
|
|
|
* @return array $options |
|
64
|
|
|
*/ |
|
65
|
|
|
public function enable_easing($options, $slider_id) |
|
|
|
|
|
|
66
|
|
|
{ |
|
67
|
|
|
if (isset($options['easing'])) { |
|
68
|
|
|
$options['useCSS'] = 'false'; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
// we don't want this filter hanging around if there's more than one slideshow on the page |
|
72
|
|
|
remove_filter('metaslider_flex_slider_parameters', array($this, 'enable_easing'), 10, 2); |
|
73
|
|
|
|
|
74
|
|
|
return $options; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Add a 'nav-hidden' class to slideshows where the navigation is hidden. |
|
79
|
|
|
* |
|
80
|
|
|
* @param $class |
|
81
|
|
|
* @param $id |
|
82
|
|
|
* @param array $settings |
|
83
|
|
|
* @return string $css |
|
84
|
|
|
* @internal param string $css |
|
85
|
|
|
* @internal param int $slider_id |
|
86
|
|
|
*/ |
|
87
|
|
|
public function remove_bottom_margin($class, $id, $settings) |
|
88
|
|
|
{ |
|
89
|
|
|
if (isset($settings['navigation']) && $settings['navigation'] === 'false') { |
|
90
|
|
|
return $class .= ' nav-hidden'; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
// we don't want this filter hanging around if there's more than one slideshow on the page |
|
94
|
|
|
remove_filter('metaslider_css_classes', array($this, 'remove_bottom_margin'), 11, 3); |
|
95
|
|
|
|
|
96
|
|
|
return $class; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Return css to ensure our slides are rendered correctly in the carousel |
|
101
|
|
|
* |
|
102
|
|
|
* @param string $css |
|
103
|
|
|
* @param array $settings |
|
104
|
|
|
* @param integer $slider_id |
|
105
|
|
|
* @return string $css |
|
106
|
|
|
*/ |
|
107
|
|
|
public function get_carousel_css($css, $settings, $slider_id) |
|
108
|
|
|
{ |
|
109
|
|
|
if (isset($settings['carouselMode']) && $settings['carouselMode'] === 'true') { |
|
110
|
|
|
$css .= "\n #metaslider_{$slider_id}.flexslider li {margin-right: {$this->carousel_item_margin}px;}"; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
// we don't want this filter hanging around if there's more than one slideshow on the page |
|
114
|
|
|
remove_filter('metaslider_css', array($this, 'get_carousel_css'), 11, 3); |
|
115
|
|
|
|
|
116
|
|
|
return $css; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Enable the parameters that are accepted by the slider |
|
121
|
|
|
* |
|
122
|
|
|
* @param string $param |
|
123
|
|
|
* @return array|boolean enabled parameters (false if parameter doesn't exist) |
|
|
|
|
|
|
124
|
|
|
*/ |
|
125
|
|
View Code Duplication |
protected function get_param($param) |
|
|
|
|
|
|
126
|
|
|
{ |
|
127
|
|
|
$params = array( |
|
128
|
|
|
'effect' => 'animation', |
|
129
|
|
|
'direction' => 'direction', |
|
130
|
|
|
'prevText' => 'prevText', |
|
131
|
|
|
'nextText' => 'nextText', |
|
132
|
|
|
'delay' => 'slideshowSpeed', |
|
133
|
|
|
'animationSpeed' => 'animationSpeed', |
|
134
|
|
|
'hoverPause' => 'pauseOnHover', |
|
135
|
|
|
'reverse' => 'reverse', |
|
136
|
|
|
'navigation' => 'controlNav', |
|
137
|
|
|
'links' => 'directionNav', |
|
138
|
|
|
'carouselMode' => 'carouselMode', |
|
139
|
|
|
'easing' => 'easing', |
|
140
|
|
|
'autoPlay' => 'slideshow' |
|
141
|
|
|
); |
|
142
|
|
|
|
|
143
|
|
|
if (isset($params[$param])) { |
|
144
|
|
|
return $params[$param]; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
return false; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* Include slider assets |
|
152
|
|
|
*/ |
|
153
|
|
|
public function enqueue_scripts() |
|
154
|
|
|
{ |
|
155
|
|
|
parent::enqueue_scripts(); |
|
156
|
|
|
|
|
157
|
|
|
if ($this->get_setting('printJs') === 'true') { |
|
158
|
|
|
wp_enqueue_script('metaslider-easing', METASLIDER_ASSETS_URL . 'easing/jQuery.easing.min.js', array('jquery'), METASLIDER_VERSION); |
|
159
|
|
|
} |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* Build the HTML for a slider. |
|
164
|
|
|
* |
|
165
|
|
|
* @return string slider markup. |
|
166
|
|
|
*/ |
|
167
|
|
|
protected function get_html() |
|
168
|
|
|
{ |
|
169
|
|
|
$class = $this->get_setting('noConflict') === 'true' ? '' : ' class="flexslider"'; |
|
170
|
|
|
|
|
171
|
|
|
$return_value = '<div id="' . $this->get_identifier() . '"' . $class . '>'; |
|
172
|
|
|
$return_value .= "\n <ul class=\"slides\">"; |
|
173
|
|
|
|
|
174
|
|
|
foreach ($this->slides as $slide) { |
|
175
|
|
|
// backwards compatibility with older versions of Meta Slider Pro (< v2.0) |
|
176
|
|
|
// MS Pro < 2.0 does not include the <li> |
|
177
|
|
|
// MS Pro 2.0+ returns the <li> |
|
178
|
|
|
if (strpos($slide, '<li') === 0) { |
|
179
|
|
|
$return_value .= "\n " . $slide; |
|
180
|
|
|
} else { |
|
181
|
|
|
$return_value .= "\n <li style=\"display: none;\">" . $slide . '</li>'; |
|
182
|
|
|
} |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
$return_value .= "\n </ul>"; |
|
186
|
|
|
$return_value .= "\n </div>"; |
|
187
|
|
|
|
|
188
|
|
|
return apply_filters('metaslider_flex_slider_get_html', $return_value, $this->id, $this->settings); |
|
189
|
|
|
} |
|
190
|
|
|
} |
|
191
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.