/
var
/
www
/
barefootlaw.org
/
wp-content
/
themes
/
barefoot
/
inc
/
walker
/
Upload File
HOME
<?php /** * Nav Menu API: Covercase_Menu_Walker class * * @package Aisconverse * @subpackage Covercase * @since Covercase 1.0 */ if ( ! class_exists( 'Covercase_Menu_Walker' ) ) { /** * Core class used to implement an HTML list of nav menu items. * * Class Covercase_Menu_Walker */ class Covercase_Menu_Walker extends Walker_Nav_Menu { /** * Init columns with Mega Menu items * * @var array */ public static $mega_menu_cols = array( '', '', '', '' ); /** * Contain all images & params in mega menu * * @var int */ public static $mega_image = array(); public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) { if ( ! $element ) { return; } $id_field = $this->db_fields['id']; $id = $element->$id_field; // get current status for megamenu $megaMenuStatus = $megaMenuImage = $megaMenuImageSize = $megaMenuImageOffset = false; if ( $depth === 0 ) { $megaMenuStatus = get_post_meta( $id, 'menu-item-basement_mega_enabled', true ); $megaMenuImage = get_post_meta( $id, 'menu-item-basement_mega_image', true ); $megaMenuImageSize = (int) get_post_meta( $id, 'menu-item-basement_mega_image_size', true ); $megaMenuImageOffset = (int) get_post_meta( $id, 'menu-item-basement_mega_image_offset', true ); } // Add class for item with Mega menu ONLY FOR depth = 0 if ( 'yes' === $megaMenuStatus && $depth === 0 && isset( $children_elements[ $id ] ) ) { $element->classes[] = apply_filters( 'basement_root_class_megamenu', 'menu-item-is-megamenu' ); // Reset Mega Cols If new Mega Menu is init self::$mega_menu_cols = array( '', '', '', '' ); self::$mega_image = array(); if ( $megaMenuImage ) { // Fill image params self::$mega_image['size'] = $megaMenuImageSize; self::$mega_image['src'] = $megaMenuImage; self::$mega_image['offset'] = $megaMenuImageOffset; // Fill columns with images - SPECIAL KEY - `image` $filled_images = array_fill( $megaMenuImageOffset, $megaMenuImageSize, 'image' ); self::$mega_menu_cols = $filled_images+self::$mega_menu_cols; // Sort all items ksort(self::$mega_menu_cols); } } //display this element $this->has_children = ! empty( $children_elements[ $id ] ); if ( isset( $args[0] ) && is_array( $args[0] ) ) { $args[0]['has_children'] = $this->has_children; // Back-compat. } $cb_args = array_merge( array( &$output, $element, $depth ), $args ); call_user_func_array( array( $this, 'start_el' ), $cb_args ); // descend only when the depth is right and there are childrens for this element if ( ( $max_depth == 0 || $max_depth > $depth + 1 ) && isset( $children_elements[ $id ] ) ) { // check if mega menu Enabled if ( 'yes' !== $megaMenuStatus ) { // Here output default drop down menu foreach ( $children_elements[ $id ] as $child ) { if ( ! isset( $newlevel ) ) { $newlevel = true; //start the child delimiter $cb_args = array_merge( array( &$output, $depth ), $args ); call_user_func_array( array( $this, 'start_lvl' ), $cb_args ); } $this->display_element( $child, $children_elements, $max_depth, $depth + 1, $args, $output ); } unset( $children_elements[ $id ] ); } else { // Here output mega menu $basement_header = array(); if ( function_exists( 'Basement_header' ) ) { $basement_header = Basement_header(); } $padding_bottom = isset( $basement_header['header_padding_bottom'] ) && is_numeric( $basement_header['header_padding_bottom'] ) ? (int) $basement_header['header_padding_bottom'] : '21'; $inline_style = 'padding-top:' . ( $padding_bottom ) . 'px;'; $inline_style .= 'top: calc(100% - ' . ($padding_bottom + 5) . 'px);'; foreach ( $children_elements[ $id ] as $child ) { $cb_args = array_merge( array( &$output, $depth ), $args ); $id_child = $child->ID; $megaMenuItemTitle = get_post_meta( $id_child, 'menu-item-basement_mega_title', true ); $megaMenuItemCol = get_post_meta( $id_child, 'menu-item-basement_mega_column', true ); $col_index = $megaMenuItemCol - 1; // If current item is TITLE $child->mega_item_title = 'yes' === $megaMenuItemTitle ? true : false; // Set image status for item if ( $megaMenuImage ) { $child->mega_item_img = $megaMenuImage; $child->mega_item_offset = $megaMenuImageOffset; $child->mega_item_size = $megaMenuImageSize; } // Check if index -1 (if all columns has image) if ( $col_index >= 0 ) { $current_col_value = isset( self::$mega_menu_cols[ $col_index ] ) ? self::$mega_menu_cols[ $col_index ] : ''; if ( 'image' !== $current_col_value ) { //self::$mega_menu_cols[ $col_index ][] = array_merge( array( 'element' => $child, 'args' => $cb_args ) ); // $id_child . ' ' . $child->post_title; } else { foreach ( self::$mega_menu_cols as $col_position => $radnom_item ) { if ( is_array( $radnom_item ) ) { self::$mega_menu_cols[ $col_position ][] = array_merge( array( 'element' => $child, 'args' => $cb_args ) ); } } } } } // Again sort items (just in case :)) ksort( self::$mega_menu_cols ); $cols_html = ''; if ( ! empty( self::$mega_menu_cols ) ) { $col_img_status = false; foreach ( self::$mega_menu_cols as $col_inx => $col_item ) { // If COL item is not Image if ( 'image' !== $col_item ) { $col_html_items = ''; // Output default element LINK if ( is_array( $col_item ) && !empty($col_item) ) { foreach( $col_item as $item ) { // Link Attributes $atts = array(); $atts['title'] = ! empty( $item['element']->attr_title ) ? $item['element']->attr_title : ''; $atts['target'] = ! empty( $item['element']->target ) ? $item['element']->target : ''; $atts['rel'] = ! empty( $item['element']->xfn ) ? $item['element']->xfn : ''; $atts['href'] = ! empty( $item['element']->url ) ? $item['element']->url : ''; $attributes = ''; foreach ( $atts as $attr => $value ) { if ( ! empty( $value ) ) { $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); $attributes .= ' ' . $attr . '="' . $value . '"'; } } // Get item title $title = apply_filters( 'the_title', $item['element']->title, $item['element']->ID ); // Check if current item is title if(empty($item['element']->mega_item_title) ) { // Make default mega menu item $col_html_items .= '<li class="menu-item-megamenu"><a ' . $attributes . ' >' . $title . '</a></li>'; } else { $col_html_items .= '<li class="menu-item-megamenu menu-item-megamenu--title">' . $title . '</li>'; } }; } // Build default Mega Menu column if(!empty($col_html_items)) { $col_html_items = '<ul class="menu-list-megamenu">'.$col_html_items.'</ul>'; } $cols_html .= '<div class="col-sm-3 menu-col-megamenu">' . $col_html_items . '</div>'; } elseif ('image' === $col_item) { // If image is set - ignore this condition if($col_img_status) continue; // Images set status $col_img_status = true; $mega_image_size = isset(self::$mega_image['size']) ? self::$mega_image['size'] : 0; $mega_image_url = isset(self::$mega_image['src']) ? self::$mega_image['src'] : ''; // Set col size $col_img_size = 3 * $mega_image_size; $cols_html .= '<div class="col-sm-'.esc_attr($col_img_size).' menu-col-megamenu menu-col-megamenu--has-img"><div style="background-image: url('.esc_url($mega_image_url).')"></div></div>'; } } }; $output .= apply_filters( 'basement_html_megamenu', '<div class="wpnav-dropdown sf-mega" style="' . $inline_style . '"><div class="js-container-megamenu-trigger container"><i class="menu-shadow"></i><div class="row menu-row-megamenu">'.$cols_html.'</div></div></div>' ); } } if ( isset( $newlevel ) && $newlevel ) { //end the child delimiter $cb_args = array_merge( array( &$output, $depth ), $args ); call_user_func_array( array( $this, 'end_lvl' ), $cb_args ); } //end this element $cb_args = array_merge( array( &$output, $element, $depth ), $args ); call_user_func_array( array( $this, 'end_el' ), $cb_args ); } public function start_lvl( &$output, $depth = 0, $args = array() ) { $basement_header = array(); if ( function_exists( 'Basement_header' ) ) { $basement_header = Basement_header(); } $padding_bottom = isset( $basement_header['header_padding_bottom'] ) && is_numeric( $basement_header['header_padding_bottom'] ) ? (int) $basement_header['header_padding_bottom'] - 5 : 22; if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) { $t = ''; $n = ''; } else { $t = "\t"; $n = "\n"; } $indent = str_repeat( $t, $depth ); // Default class. $classes = array( 'sub-menu' ); $class_names = join( ' ', apply_filters( 'nav_menu_submenu_css_class', $classes, $args, $depth ) ); $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; $output .= "{$n}{$indent}<div data-depth=\"{$depth}\" class=\"wpnav-dropdown sf-mega \" style=\"padding-top: {$padding_bottom}px;\"><i class=\"menu-shadow menu-shadow--default\" style=\"top:{$padding_bottom}px\"></i><ul$class_names>{$n}"; } public function end_lvl( &$output, $depth = 0, $args = array() ) { if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) { $t = ''; $n = ''; } else { $t = "\t"; $n = "\n"; } $indent = str_repeat( $t, $depth ); $output .= "$indent</ul></div>{$n}"; } public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) { $t = ''; $n = ''; } else { $t = "\t"; $n = "\n"; } $indent = ( $depth ) ? str_repeat( $t, $depth ) : ''; $classes = empty( $item->classes ) ? array() : (array) $item->classes; $classes[] = 'menu-item-' . $item->ID; if ( $depth === 0 && ( in_array( 'current-menu-ancestor', $classes ) ) ) { $classes[] = 'active'; } if ( $depth === 0 && ( in_array( 'current-menu-item', $classes, true ) || in_array( 'current_page_item', $classes, true ) ) ) { $classes = array_diff( $classes, array( 'current-menu-item', 'current_page_item', 'active' ) ); $classes[] = 'active'; } /** * Filters the arguments for a single nav menu item. * * @since 4.4.0 * * @param stdClass $args An object of wp_nav_menu() arguments. * @param WP_Post $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. */ $args = apply_filters( 'nav_menu_item_args', $args, $item, $depth ); /** * Filters the CSS class(es) applied to a menu item's list item element. * * @since 3.0.0 * @since 4.1.0 The `$depth` parameter was added. * * @param array $classes The CSS classes that are applied to the menu item's `<li>` element. * @param WP_Post $item The current menu item. * @param stdClass $args An object of wp_nav_menu() arguments. * @param int $depth Depth of menu item. Used for padding. */ $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ) ); $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; /** * Filters the ID applied to a menu item's list item element. * * @since 3.0.1 * @since 4.1.0 The `$depth` parameter was added. * * @param string $menu_id The ID that is applied to the menu item's `<li>` element. * @param WP_Post $item The current menu item. * @param stdClass $args An object of wp_nav_menu() arguments. * @param int $depth Depth of menu item. Used for padding. */ $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args, $depth ); $id = $id ? ' id="' . esc_attr( $id ) . '"' : ''; $output .= $indent . '<li' . $id . $class_names .'>'; $atts = array(); $atts['title'] = ! empty( $item->attr_title ) ? $item->attr_title : ''; $atts['target'] = ! empty( $item->target ) ? $item->target : ''; $atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : ''; $atts['href'] = ! empty( $item->url ) ? $item->url : ''; /** * Filters the HTML attributes applied to a menu item's anchor element. * * @since 3.6.0 * @since 4.1.0 The `$depth` parameter was added. * * @param array $atts { * The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored. * * @type string $title Title attribute. * @type string $target Target attribute. * @type string $rel The rel attribute. * @type string $href The href attribute. * } * @param WP_Post $item The current menu item. * @param stdClass $args An object of wp_nav_menu() arguments. * @param int $depth Depth of menu item. Used for padding. */ $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth ); $attributes = ''; foreach ( $atts as $attr => $value ) { if ( ! empty( $value ) ) { $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); $attributes .= ' ' . $attr . '="' . $value . '"'; } } /** This filter is documented in wp-includes/post-template.php */ $title = apply_filters( 'the_title', $item->title, $item->ID ); /** * Filters a menu item's title. * * @since 4.4.0 * * @param string $title The menu item's title. * @param WP_Post $item The current menu item. * @param stdClass $args An object of wp_nav_menu() arguments. * @param int $depth Depth of menu item. Used for padding. */ $title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth ); $item_output = $args->before; $item_output .= '<a'. $attributes .'>'; $item_output .= $args->link_before . $title . $args->link_after; $item_output .= '</a>'; $item_output .= $args->after; /** * Filters a menu item's starting output. * * The menu item's starting output only includes `$args->before`, the opening `<a>`, * the menu item's title, the closing `</a>`, and `$args->after`. Currently, there is * no filter for modifying the opening and closing `<li>` for a menu item. * * @since 3.0.0 * * @param string $item_output The menu item's starting HTML output. * @param WP_Post $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param stdClass $args An object of wp_nav_menu() arguments. */ $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); } } }