|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
// Oenu walker for top bar |
|
4
|
|
|
/** |
|
5
|
|
|
* @param $element |
|
6
|
|
|
* @param $children_elements |
|
7
|
|
|
* @param $max_depth |
|
8
|
|
|
* @param $depth |
|
9
|
|
|
* @param $args |
|
10
|
|
|
* @param $output |
|
11
|
|
|
*/ |
|
12
|
|
|
final class Top_Bar_Walker extends Walker_Nav_Menu |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @param $element |
|
16
|
|
|
* @param $children_elements |
|
17
|
|
|
* @param $max_depth |
|
18
|
|
|
* @param $depth |
|
19
|
|
|
* @param $args |
|
20
|
|
|
* @param $output |
|
21
|
|
|
*/ |
|
22
|
|
View Code Duplication |
public function display_element($element, &$children_elements, $max_depth, $depth = 0, $args, &$output) |
|
|
|
|
|
|
23
|
|
|
{ |
|
24
|
|
|
$element->has_children = !empty($children_elements[$element->ID]); |
|
25
|
|
|
$element->classes[] = ($element->current || $element->current_item_ancestor) ? 'active' : ''; |
|
26
|
|
|
$element->classes[] = ($element->has_children && 1 !== $max_depth) ? 'has-submenu' : ''; |
|
27
|
|
|
parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param $output |
|
32
|
|
|
* @param $object |
|
33
|
|
|
* @param $depth |
|
34
|
|
|
* @param array $args |
|
35
|
|
|
* @param $current_object_id |
|
36
|
|
|
*/ |
|
37
|
|
|
public function start_el(&$output, $object, $depth = 0, $args = [], $current_object_id = 0) |
|
38
|
|
|
{ |
|
39
|
|
|
$item_html = ''; |
|
40
|
|
|
parent::start_el($item_html, $object, $depth, $args); |
|
41
|
|
|
//$output .= ( 0 == $depth ) ? '<li class="divider"></li>' : ''; |
|
42
|
|
|
$classes = empty($object->classes) ? [] : (array) $object->classes; |
|
43
|
|
|
|
|
44
|
|
|
if (in_array('label', $classes)) { |
|
45
|
|
|
|
|
46
|
|
|
//$output .= '<li class="divider"></li>'; |
|
47
|
|
|
$item_html = preg_replace('/<a[^>]*>(.*)<\/a>/iU', '<label>$1</label>', $item_html); |
|
48
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
if (in_array('divider', $classes)) { |
|
52
|
|
|
|
|
53
|
|
|
$item_html = preg_replace('/<a[^>]*>( .* )<\/a>/iU', '', $item_html); |
|
54
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$output .= $item_html; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @param $output |
|
62
|
|
|
* @param $depth |
|
63
|
|
|
* @param array $args |
|
64
|
|
|
*/ |
|
65
|
|
|
public function start_lvl(&$output, $depth = 0, $args = []) |
|
66
|
|
|
{ |
|
67
|
|
|
$output .= "\n<ul class=\"submenu menu vertical\">\n"; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
// Offcanvas menu walker |
|
73
|
|
|
/** |
|
74
|
|
|
* @param $element |
|
75
|
|
|
* @param $children_elements |
|
76
|
|
|
* @param $max_depth |
|
77
|
|
|
* @param $depth |
|
78
|
|
|
* @param $args |
|
79
|
|
|
* @param $output |
|
80
|
|
|
*/ |
|
81
|
|
|
final class Offcanvas_Walker extends Walker_Nav_Menu |
|
82
|
|
|
{ |
|
83
|
|
|
/** |
|
84
|
|
|
* @param $element |
|
85
|
|
|
* @param $children_elements |
|
86
|
|
|
* @param $max_depth |
|
87
|
|
|
* @param $depth |
|
88
|
|
|
* @param $args |
|
89
|
|
|
* @param $output |
|
90
|
|
|
*/ |
|
91
|
|
View Code Duplication |
public function display_element($element, &$children_elements, $max_depth, $depth = 0, $args, &$output) |
|
|
|
|
|
|
92
|
|
|
{ |
|
93
|
|
|
$element->has_children = !empty($children_elements[$element->ID]); |
|
94
|
|
|
$element->classes[] = ($element->current || $element->current_item_ancestor) ? 'active' : ''; |
|
95
|
|
|
$element->classes[] = ($element->has_children && 1 !== $max_depth) ? 'has-submenu' : ''; |
|
96
|
|
|
parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @param $output |
|
101
|
|
|
* @param $object |
|
102
|
|
|
* @param $depth |
|
103
|
|
|
* @param array $args |
|
104
|
|
|
* @param $current_object_id |
|
105
|
|
|
*/ |
|
106
|
|
|
public function start_el(&$output, $object, $depth = 0, $args = [], $current_object_id = 0) |
|
107
|
|
|
{ |
|
108
|
|
|
$item_html = ''; |
|
109
|
|
|
parent::start_el($item_html, $object, $depth, $args); |
|
110
|
|
|
$classes = empty($object->classes) ? [] : (array) $object->classes; |
|
111
|
|
|
|
|
112
|
|
|
if (in_array('label', $classes)) { |
|
113
|
|
|
|
|
114
|
|
|
$item_html = preg_replace('/<a[^>]*>(.*)<\/a>/iU', '<label>$1</label>', $item_html); |
|
115
|
|
|
|
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
$output .= $item_html; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @param $output |
|
123
|
|
|
* @param $depth |
|
124
|
|
|
* @param array $args |
|
125
|
|
|
*/ |
|
126
|
|
|
public function start_lvl(&$output, $depth = 0, $args = []) |
|
127
|
|
|
{ |
|
128
|
|
|
$output .= "\n<ul class=\"left-submenu\">\n<li class=\"back\"><a href=\"#\">" . __('Back', 'podium') . "</a></li>\n"; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
} |
|
132
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.