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