PluginProbe
QuadMenu – Mega Menu / 1.9.0
QuadMenu – Mega Menu v1.9.0
3.3.7 3.3.6 trunk 1.8.4 1.8.5 1.8.7 1.8.8 1.8.9 1.9.0 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 All 87 releases
quadmenu / includes / frontend / walker / QuadMenuItem.class.php

QuadMenuItem.class.php in QuadMenu – Mega Menu 1.9.0, at includes/frontend/walker/QuadMenuItem.class.php

475 lines 14.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH')) {
3 die('-1');
4 }
5
6 abstract class QuadMenuItem {
7
8 protected $type = 'unknown';
9 protected $ID = 0;
10 protected $source_id = 0;
11 protected $output;
12 protected $item;
13 protected $depth;
14 protected $args;
15 protected $id;
16 protected $walker;
17 protected $dropdown_classes = array();
18 protected $dropdown_ul_classes = array();
19 protected $item_classes = array(0 => '');
20 protected $item_atts = array();
21 protected $dropdown_style = array();
22 protected $has_children = false;
23 protected $thumbnail = '';
24 protected $description = '';
25 private $prefix = '#quadmenu-';
26
27 function __construct(&$output, &$item, $depth = 0, &$args = array(), $id = 0, &$walker, $has_children = false, $children_elements = false) {
28
29 $this->output = &$output;
30 $this->item = &$item;
31 $this->depth = $depth;
32 $this->args = &$args;
33 $this->id = $id;
34 $this->walker = &$walker;
35 $this->source_id = $this->item->db_id;
36 $this->has_children = $has_children;
37 $this->children_elements = $children_elements;
38
39 // Properties
40 // ---------------------------------------------------------------------
41
42 $this->item->columns = array_filter((array) $this->item->columns);
43 $this->item->animation = new stdClass();
44
45 // Arguments
46 // ---------------------------------------------------------------------
47 $this->args->has_title = (bool) $this->item->title;
48 $this->args->has_icon = (bool) $this->item->icon;
49 $this->args->has_link = (bool) $this->item->url;
50 $this->args->has_caret = $this->args->has_dropdown = $this->has_children;
51 $this->args->has_submenu = (0 < $this->depth && $this->args->has_dropdown);
52 $this->args->has_subtitle = (bool) $this->item->subtitle;
53 $this->args->has_badge = (bool) $this->item->badge;
54 $this->args->has_background = (bool) $this->item->background;
55 $this->args->has_description = (bool) $this->item->description;
56 $this->args->has_thumbnail = false;
57 $this->args->has_columns = array_filter((array) $this->item->columns);
58
59 $this->init();
60
61 $this->remove_item_url();
62
63 $this->add_item_dropdown_classes();
64
65 $this->add_item_dropdown_ul_classes();
66
67 $this->add_item_animations();
68 }
69
70 function add_item_animations() {
71
72 $this->item->animation->title = '';
73 $this->item->animation->subtitle = '';
74 $this->item->animation->icon = '';
75 $this->item->animation->badge = '';
76
77 if ($this->depth > 0) {
78 if (!empty($this->args->dropdown_animation_badge)) {
79 $this->item->animation->text = join(' ', array_map('sanitize_html_class', (array) $this->args->dropdown_animation_text));
80 }
81 if (!empty($this->args->dropdown_animation_subtitle)) {
82 $this->item->animation->subtitle = join(' ', array_map('sanitize_html_class', (array) $this->args->dropdown_animation_subtitle));
83 }
84 if (!empty($this->args->dropdown_animation_badge)) {
85 $this->item->animation->badge = join(' ', array_map('sanitize_html_class', (array) $this->args->dropdown_animation_badge));
86 }
87 if (!empty($this->args->dropdown_animation_icon)) {
88 $this->item->animation->icon = join(' ', array_map('sanitize_html_class', (array) $this->args->dropdown_animation_icon));
89 }
90 } else {
91 if (!empty($this->args->navbar_animation_badge)) {
92 $this->item->animation->text = join(' ', array_map('sanitize_html_class', (array) $this->args->navbar_animation_text));
93 }
94 if (!empty($this->args->navbar_animation_subtitle)) {
95 $this->item->animation->subtitle = join(' ', array_map('sanitize_html_class', (array) $this->args->navbar_animation_subtitle));
96 }
97 if (!empty($this->args->navbar_animation_badge)) {
98 $this->item->animation->badge = join(' ', array_map('sanitize_html_class', (array) $this->args->navbar_animation_badge));
99 }
100 if (!empty($this->args->navbar_animation_icon)) {
101 $this->item->animation->icon = join(' ', array_map('sanitize_html_class', (array) $this->args->navbar_animation_icon));
102 }
103 }
104 }
105
106 function start_el() {
107 $this->output.= apply_filters('quadmenu_nav_menu_start_el', $this->get_start_el(), $this->item, $this->depth, $this->args);
108 }
109
110 function end_el() {
111 $this->output.= apply_filters('quadmenu_nav_menu_end_el', $this->get_end_el(), $this->item, $this->depth, $this->args);
112 }
113
114 function start_lvl() {
115 $this->output.= $this->get_dropdown_wrap_start();
116 }
117
118 function end_lvl() {
119 $this->output.= $this->get_dropdown_wrap_end();
120 }
121
122 abstract function get_start_el();
123
124 function get_end_el() {
125 $item_output = '</li>';
126 return $item_output;
127 }
128
129 function init() {
130
131 }
132
133 function add_item_classes() {
134
135 $this->item_classes[] = 'menu-item-' . $this->item->ID;
136
137 if (is_array($this->item->classes)) {
138 $this->item_classes = array_merge($this->item_classes, $this->item->classes);
139 }
140 }
141
142 function add_item_classes_current() {
143
144 if ($this->args->layout_current) {
145 //$parent = (bool) array_search('current-menu-parent', $this->item->classes);
146 //$current = (bool) array_search('current-menu-item', $this->item->classes);
147 //if ($parent || $current) {
148 // $this->item_classes[] = 'open';
149 //}
150 if (count(array_intersect(array('current-menu-ancestor'), $this->item->classes))) {
151 $this->item_classes[] = 'open';
152 }
153 }
154 }
155
156 function add_item_classes_prefix() {
157
158 $this->item_classes = array_diff($this->item_classes, array('menu-item-type-custom', 'menu-item-type-post_type', 'menu-item-type-post_type_archive'));
159
160 foreach ($this->item_classes as $i => $class) {
161
162 if (!in_array(sanitize_key($class), array('open', 'active'))) {
163
164 if (substr($class, 0, 9) == 'menu-item') {
165 $this->item_classes[$i] = str_replace('menu-item', 'quadmenu-item', $class);
166 }
167
168 //if ($class == 'current-menu-ancestor') {
169 // $this->item_classes[$i] = 'quadmenu-current-menu-ancestor';
170 //}
171 //if ($class == 'current-menu-parent') {
172 // $this->item_classes[$i] = 'quadmenu-current-menu-parent';
173 //}
174 //if ($class == 'current-menu-item') {
175 // $this->item_classes[$i] = 'quadmenu-current-menu-item';
176 //}
177 }
178 }
179 }
180
181 function add_item_classes_quadmenu() {
182
183 $this->item_classes[] = 'quadmenu-item-type-' . $this->type;
184
185 $this->item_classes[] = 'quadmenu-item-level-' . $this->depth;
186
187 $this->item_classes[] = $this->args->has_dropdown ? 'quadmenu-dropdown' : '';
188
189 $this->item_classes[] = $this->args->has_submenu ? 'quadmenu-dropdown-submenu' : '';
190
191 $this->item_classes[] = $this->args->has_subtitle ? 'quadmenu-has-subtitle' : '';
192
193 $this->item_classes[] = $this->args->has_badge ? 'quadmenu-has-badge' : '';
194
195 $this->item_classes[] = $this->args->has_caret ? 'quadmenu-has-caret' : '';
196
197 $this->item_classes[] = $this->args->has_description ? 'quadmenu-has-description' : '';
198
199 $this->item_classes[] = $this->args->has_thumbnail ? 'quadmenu-has-image-' . $this->item->thumb : '';
200
201 $this->item_classes[] = $this->args->has_title ? 'quadmenu-has-title' : '';
202
203 $this->item_classes[] = $this->args->has_icon ? 'quadmenu-has-icon' : '';
204
205 $this->item_classes[] = $this->args->has_link || $this->args->has_dropdown ? 'quadmenu-has-link' : '';
206
207 $this->item_classes[] = $this->args->has_background ? 'quadmenu-has-background' : '';
208
209 if (!empty($this->item->float)) {
210 $this->item_classes[] = 'quadmenu-float-' . $this->item->float;
211 }
212
213 if (!empty($this->item->dropdown)) {
214 $this->item_classes[] = 'quadmenu-dropdown-' . $this->item->dropdown;
215 }
216
217 if (!empty($this->item->hidden)) {
218 $this->item_classes[] = join(' ', array_map('sanitize_html_class', (array) $this->item->hidden));
219 }
220
221 //if (!empty($this->args->navbar_animation_link)) {
222 // $this->item_classes[] = join(' ', array_map('sanitize_html_class', (array) $this->args->navbar_animation_link));
223 //}
224 }
225
226 function add_item_classes_maxheight() {
227
228 if ($this->args->layout_dropdown_maxheight) {
229 $this->item_classes[] = 'dropdown-maxheight';
230 }
231 }
232
233 function get_item_id() {
234
235 return ' id="menu-item-' . esc_attr($this->item->ID) . '"';
236 }
237
238 function get_item_classes() {
239 $class_names = join(' ', apply_filters('quadmenu_nav_menu_css_class', array_filter($this->item_classes), $this->item, $this->args));
240 $class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : '';
241 return $class_names;
242 }
243
244 function add_link_atts() {
245
246 $this->item_atts['title'] = !empty($this->item->attr_title) ? $this->item->attr_title : '';
247
248 $this->item_atts['target'] = !empty($this->item->target) ? '_blank' : '';
249
250 $this->item_atts['rel'] = !empty($this->item->xfn) ? $this->item->xfn : '';
251
252 $this->item_atts['href'] = !empty($this->item->url) ? $this->item->url : 'javascript:void(0)';
253
254 $this->item_atts = apply_filters('quadmenu_nav_menu_link_atts', $this->item_atts, $this->item, $this->args);
255 }
256
257 function add_link_atts_toggle() {
258
259 if ($this->has_children) {
260 $this->item_atts['class'] = 'quadmenu-dropdown-toggle ' . $this->args->layout_trigger;
261 }
262 }
263
264 function add_dropdown_background() {
265
266 if (!$this->args->has_background)
267 return;
268
269 $_src = wp_get_attachment_image_src($this->item->background['thumbnail-id'], 'full');
270
271 if (empty($_src[0]))
272 return;
273
274 ob_start();
275 ?>
276 <div class="quadmenu-dropdown-background" style="
277 background-image: url('<?php echo esc_url($_src[0]); ?>');
278 background-position: <?php echo esc_attr($this->item->background['position']); ?>;
279 background-repeat: <?php echo esc_attr($this->item->background['repeat']); ?>;
280 background-size: <?php echo esc_attr($this->item->background['size']); ?>;
281 background-origin: <?php echo esc_attr($this->item->background['origin']); ?>;
282 opacity: <?php echo esc_attr($this->item->background['opacity'] / 100); ?>">
283 </div>
284 <?php
285 return ob_get_clean();
286 }
287
288 function get_link_attr() {
289
290 $atts = '';
291
292 foreach ($this->item_atts as $attr => $value) {
293
294 if (empty($value))
295 continue;
296
297 if ($attr == 'href') {
298 $value = esc_url($value);
299 } elseif ($attr == 'title') {
300 $value = esc_html($value);
301 } else {
302 $value = esc_attr($value);
303 }
304
305 $atts .= ' ' . esc_attr($attr) . '="' . $value . '"';
306 }
307
308 return $atts;
309 }
310
311 function get_link() {
312
313 ob_start();
314 ?>
315 <?php echo $this->args->before; ?>
316 <a <?php echo $this->get_link_attr(); ?>>
317 <span class="quadmenu-item-content">
318 <?php echo $this->args->link_before; ?>
319 <?php echo $this->get_thumbnail(); ?>
320 <?php echo $this->get_caret(); ?>
321 <?php echo $this->get_icon(); ?>
322 <?php echo $this->get_title(); ?>
323 <?php echo $this->get_badge(); ?>
324 <?php echo $this->get_subtitle(); ?>
325 <?php echo $this->get_description(); ?>
326 <?php echo $this->args->link_after; ?>
327 </span>
328 </a>
329 <?php echo $this->args->after; ?>
330 <?php
331 return ob_get_clean();
332 }
333
334 function get_caret() {
335 if ($this->args->has_caret) {
336 ob_start();
337 ?>
338 <span class="quadmenu-caret<?php //echo join(' ', array_map('sanitize_html_class', (array) $this->args->navbar_animation_caret)); ?>"></span>
339 <?php
340 return ob_get_clean();
341 }
342 }
343
344 function get_icon() {
345
346 if ($this->args->has_icon && $this->item->icon) {
347 ob_start();
348 ?>
349 <span class="quadmenu-icon <?php echo esc_attr($this->item->icon); ?> <?php echo esc_attr($this->item->animation->icon); ?>"></span>
350 <?php
351 return ob_get_clean();
352 }
353 }
354
355 function get_title() {
356 if ($this->args->has_title) {
357 ob_start();
358 ?>
359 <span class="quadmenu-text <?php echo esc_attr($this->item->animation->text); ?>"><?php echo $this->item->title; ?></span>
360 <?php
361 return ob_get_clean();
362 }
363 }
364
365 function get_subtitle() {
366
367 if (!empty($this->args->has_subtitle)) {
368 ob_start();
369 ?>
370 <span class="quadmenu-subtitle <?php echo esc_attr($this->item->animation->subtitle); ?>"><?php echo esc_attr($this->item->subtitle); ?></span>
371 <?php
372 return ob_get_clean();
373 }
374 }
375
376 function get_badge() {
377
378 if (!empty($this->args->has_badge)) {
379 ob_start();
380 ?>
381 <span class="quadmenu-badge <?php echo esc_attr($this->item->animation->badge); ?>"><span class="quadmenu-badge-bubble"><?php echo esc_attr($this->item->badge); ?></span></span>
382 <?php
383 return ob_get_clean();
384 }
385 }
386
387 function get_thumbnail() {
388 if (!empty($this->args->has_thumbnail)) {
389 return get_the_post_thumbnail($this->item->object_id, $this->item->thumb);
390 }
391 }
392
393 function get_description() {
394 if (!empty($this->args->has_description)) {
395 ob_start();
396 ?>
397 <span class="quadmenu-description"><?php echo esc_html($this->item->description); ?></span>
398 <?php
399 return ob_get_clean();
400 }
401 }
402
403 function add_item_dropdown_classes() {
404
405 $this->dropdown_classes = array_merge($this->dropdown_classes, array_map('sanitize_html_class', (array) $this->args->layout_animation));
406
407 $this->dropdown_classes[] = 'quadmenu-dropdown-menu';
408 }
409
410 function add_item_dropdown_ul_classes() {
411
412 }
413
414 function get_dropdown_ul_style() {
415 if (!empty($this->dropdown_style)) {
416 return ' style="' . join(';', $this->dropdown_style) . '"';
417 }
418 }
419
420 function get_dropdown_ul_classes() {
421
422 if (!empty($this->dropdown_ul_classes)) {
423
424 $class_names = join(' ', $this->dropdown_ul_classes);
425 $class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : '';
426 return $class_names;
427 }
428 }
429
430 function get_dropdown_ul_data() {
431
432 }
433
434 function get_dropdown_wrap_start() {
435 ob_start();
436 ?>
437 <div id="dropdown-<?php echo esc_attr($this->item->ID); ?>" class="<?php echo join(' ', array_map('sanitize_html_class', $this->dropdown_classes)); ?>">
438 <?php echo $this->add_dropdown_background(); ?>
439 <ul<?php echo $this->get_dropdown_ul_style(); ?><?php echo $this->get_dropdown_ul_classes(); ?><?php echo $this->get_dropdown_ul_data(); ?>>
440 <?php
441 return ob_get_clean();
442 }
443
444 function get_dropdown_wrap_end() {
445 ob_start();
446 ?>
447 </ul>
448 </div>
449 <?php
450 return ob_get_clean();
451 }
452
453 function remove_item_url() {
454
455 if (empty($this->item->url))
456 return;
457
458 if (strpos($this->item->url, $this->prefix) !== false) {
459 $this->item->url = '';
460 }
461 }
462
463 function clean_item_content($content) {
464
465 $content = preg_replace('/\[[\/]?[^\]]*\]/', '', $content);
466
467 $content = html_entity_decode($content);
468
469 $content = wp_strip_all_tags($content, true);
470
471 return $content;
472 }
473
474 }
475