Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/bdthemes-element-pack/modules/navbar/module.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
namespace ElementPack\Modules\Navbar;
3
+
4
+
use ElementPack\Base\Element_Pack_Module_Base;
5
+
use Walker_Nav_Menu;
6
+
7
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
8
+
9
+
class Module extends Element_Pack_Module_Base {
10
+
11
+
public function get_name() {
12
+
return 'navbar';
13
+
}
14
+
15
+
public function get_widgets() {
16
+
17
+
$widgets = [
18
+
'Navbar',
19
+
];
20
+
21
+
return $widgets;
22
+
}
23
+
}
24
+
25
+
26
+
class ep_menu_walker extends Walker_Nav_Menu {
27
+
var $has_child = false;
28
+
public function start_lvl(&$output, $depth = 0, $args = array()) {
29
+
$output .= '<div class="bdt-navbar-dropdown bdt-drop"><ul class="bdt-nav bdt-navbar-dropdown-nav">';
30
+
}
31
+
32
+
public function end_lvl(&$output, $depth = 0, $args = array()) {
33
+
$output .= '</ul></div>';
34
+
}
35
+
36
+
public function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) {
37
+
$data = array();
38
+
$class = '';
39
+
$classes = empty($item->classes) ? array() : (array) $item->classes;
40
+
if($classes) {
41
+
$class = trim(preg_replace('/menu-item(.+)/', '', implode(' ', $classes)));
42
+
}
43
+
//new class
44
+
$classes = array();
45
+
$data['style'] = '';
46
+
47
+
if($args->walker->has_children){
48
+
$classes[] =' bdt-parent';
49
+
}
50
+
51
+
if($item->current || $item->current_item_parent || $item->current_item_ancestor) {
52
+
$classes[] = ' bdt-active';
53
+
}
54
+
if($item->dropdown_child && $depth > 0) {
55
+
$classes[] = ' sub-dropdown';
56
+
}
57
+
// set id
58
+
$data['data-id'] = $item->ID;
59
+
60
+
// is current item ?
61
+
if (in_array('current-menu-item', $classes) || in_array('current_page_item', $classes)) {
62
+
$data['data-menu-active'] = 2;
63
+
64
+
// home/frontpage item
65
+
} elseif (preg_replace('/#(.+)$/', '', $item->url) == 'index.php' && (is_home() || is_front_page())) {
66
+
$data['data-menu-active'] = 2;
67
+
}
68
+
if($item->full_width){
69
+
$data['full_width'] = $item->full_width;
70
+
} elseif($item->style_position) {
71
+
if ($item->style_position == 'bottom-left') {
72
+
$data_uk_dropdown = (is_rtl()) ? 'bottom-right' : 'bottom-left';
73
+
} elseif ($item->style_position == 'bottom-right') {
74
+
$data_uk_dropdown = (is_rtl()) ? 'bottom-left' : 'bottom-right';
75
+
} else {
76
+
$data_uk_dropdown = $item->style_position;
77
+
}
78
+
$data['dropdown_style'] = ($data_uk_dropdown);
79
+
}
80
+
$attributes = '';
81
+
foreach ($data as $name => $value) {
82
+
$attributes .= sprintf(' %s="%s"', $name, $value);
83
+
}
84
+
85
+
// create item output
86
+
$id = apply_filters('nav_menu_item_id', '', $item, $args);
87
+
88
+
if($classes) {
89
+
$class .= implode(' ', $classes);
90
+
}
91
+
if($class) {
92
+
$class = ' class="'.$class.'"';
93
+
} else {
94
+
$class = '';
95
+
}
96
+
97
+
$output .= '<li'.$attributes . $class.'>';
98
+
99
+
// set link attributes
100
+
$attributes = '';
101
+
foreach (array('attr_title' => 'title', 'target' => 'target', 'xfn' => 'rel', 'url' => 'href') as $var => $attr) {
102
+
if (!empty($item->$var)) {
103
+
$attributes .= sprintf(' %s="%s"', $attr, $item->$var);
104
+
}
105
+
}
106
+
107
+
// escape link title
108
+
//$item->title = $item->title; //htmlspecialchars($item->title, ENT_COMPAT, "UTF-8");
109
+
$classes = trim(preg_replace('/menu-item(.+)/', '', implode(' ', $classes)));
110
+
111
+
// is separator ?
112
+
if ($item->url == '#') {
113
+
$isline = preg_match("/^\s*\-+\s*$/", $item->title);
114
+
115
+
$type = "header";
116
+
if ($isline) {
117
+
$type = 'separator-line';
118
+
} elseif ($item->hasChildren) {
119
+
$type = 'separator-text';
120
+
}
121
+
122
+
$format = '%s<a href="#" %s>%s</a>%s';
123
+
$classes .= ' seperator';
124
+
$attributes = ' class="'.$classes.'" data-type="'.$type.'"';
125
+
} else {
126
+
$format = '%s<a%s>%s</a>%s';
127
+
}
128
+
129
+
// create link output
130
+
$item_output = sprintf($format, $args->before, $attributes, $args->link_before.apply_filters('the_title', $item->title, $item->ID).$args->link_after, $args->after);
131
+
132
+
$output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args);
133
+
}
134
+
135
+
public function end_el(&$output, $item, $depth = 0, $args = array(), $id = 0) {
136
+
$output .= '</li>';
137
+
}
138
+
139
+
function display_element ($element, &$children_elements, $max_depth, $depth, $args, &$output) {
140
+
// attach to element so that it's available in start_el()
141
+
$element->hasChildren = isset($children_elements[$element->ID]) && !empty($children_elements[$element->ID]);
142
+
143
+
return parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output);
144
+
}
145
+
}