Guest User

Untitled

a guest
Jun 11th, 2025
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 11.30 KB | None | 0 0
  1. <?php
  2. if( ! defined( 'ABSPATH' ) ) {  exit;  }    // Exit if accessed directly
  3.  
  4.  
  5. if( ! class_exists( 'avia_responsive_mega_menu', false ) )
  6. {
  7.     /**
  8.      * The avia walker is the frontend walker and necessary to display the menu, this is a advanced version of the wordpress menu walker
  9.      * @package WordPress
  10.      * @since 1.0.0
  11.      * @uses Walker
  12.      */
  13.     class avia_responsive_mega_menu extends Walker
  14.     {
  15.         /**
  16.          * @see Walker::$tree_type
  17.          * @var string
  18.          */
  19.         var $tree_type = array( 'post_type', 'taxonomy', 'custom' );
  20.  
  21.         /**
  22.          * @see Walker::$db_fields
  23.          * @todo Decouple this.
  24.          * @var array
  25.          */
  26.         var $db_fields = array( 'parent' => 'menu_item_parent', 'id' => 'db_id' );
  27.  
  28.         /**
  29.          * @var int $columns
  30.          */
  31.         var $columns = 0;
  32.  
  33.         /**
  34.          * @var int $max_columns maximum number of columns within one mega menu
  35.          */
  36.         var $max_columns = 0;
  37.  
  38.         /**
  39.          * @var int $rows holds the number of rows within the mega menu
  40.          */
  41.         var $rows = 1;
  42.  
  43.         /**
  44.          * @var array $rowsCounter holds the number of columns for each row within a multidimensional array
  45.          */
  46.         var $rowsCounter = array();
  47.  
  48.         /**
  49.          * @var string $mega_active hold information whetever we are currently rendering a mega menu or not
  50.          */
  51.         var $mega_active = 0;
  52.  
  53.         /**
  54.          * @var array $grid_array holds the grid classes that get applied to the mega menu depending on the number of columns
  55.          */
  56.         var $grid_array = array();
  57.  
  58.         /**
  59.          * @var stores if we already have an active first level main menu item.
  60.          */
  61.         var $active_item = false;
  62.  
  63.         /**
  64.          * @var stores if we got a top or a sidebar main menu.
  65.          */
  66.         var $top_menu = true;
  67.  
  68.         /**
  69.          * @var stores if we got a text menu or a single burger icon
  70.          */
  71.         var $icon_menu = true;
  72.  
  73.         /**
  74.          * @var stores if we got a top or a sidebar main menu.
  75.          */
  76.         var $blog_id = false;
  77.  
  78.         /**
  79.          * @var stores the number of first level menu items
  80.          */
  81.         var $first_level_count = 0;
  82.  
  83.         /**
  84.          * @var stores if mega menu is active
  85.          */
  86.         var $mega_allowed = true;
  87.  
  88.         /**
  89.         *
  90.         * Constructor that sets the grid variables
  91.         *
  92.         */
  93.         function __construct( $options = array() )
  94.         {
  95.             $this->grid_array = array(
  96.                                 1 => "three units",
  97.                                 2 => "six units",
  98.                                 3 => "nine units",
  99.                                 4 => "twelve units",
  100.                                 5 => "twelve units",
  101.                                 6 => "twelve units",
  102.                                 7 => "twelve units"
  103.                             );
  104.  
  105.             $this->top_menu = avia_get_option( 'header_position', 'header_top' ) == 'header_top' ? true : false;
  106.  
  107.             /**
  108.              * Allows to alter default settings Enfold-> Main Menu -> General -> Menu Items for Desktop
  109.              * @since 4.4.2
  110.              */
  111.             $this->icon_menu = apply_filters( 'avf_burger_menu_active', avia_is_burger_menu(), $this );
  112.  
  113.             if( avia_get_option( 'frontpage' ) && avia_get_option( 'blogpage' ) )
  114.             {
  115.                 $this->blog_id = avia_get_option( 'blogpage' );
  116.             }
  117.  
  118.             if( isset( $options['megamenu'] ) && $options['megamenu'] == "disabled" )
  119.             {
  120.                 $this->mega_allowed = false;
  121.             }
  122.  
  123.             if( $this->icon_menu )
  124.             {
  125.                 //$this->mega_active = false;
  126.                 //$this->mega_allowed = false;
  127.             }
  128.         }
  129.  
  130.         /**
  131.          * @see Walker::start_lvl()
  132.          *
  133.          * @param string $output Passed by reference. Used to append additional content.
  134.          * @param int $depth Depth of page. Used for padding.
  135.          */
  136.         function start_lvl( &$output, $depth = 0, $args = array() )
  137.         {
  138.             $indent = str_repeat( "\t", $depth );
  139.             if( $depth === 0 )
  140.             {
  141.                 $output .= "\n{replace_one}\n";
  142.             }
  143.  
  144.             $output .= "\n$indent<ul class=\"sub-menu\">\n";
  145.         }
  146.  
  147.         /**
  148.          * @see Walker::end_lvl()
  149.          *
  150.          * @param string $output Passed by reference. Used to append additional content.
  151.          * @param int $depth Depth of page. Used for padding.
  152.          */
  153.         function end_lvl( &$output, $depth = 0, $args = array() )
  154.         {
  155.             $indent = str_repeat( "\t", $depth );
  156.             $output .= "{$indent}</ul>\n";
  157.  
  158.             if( $depth === 0 )
  159.             {
  160.                 if( $this->mega_active && $this->mega_allowed )
  161.                 {
  162.                     $output .= "\n</div>\n";
  163.                     $output = str_replace( "{replace_one}", "<div class='avia_mega_div avia_mega" . $this->max_columns . " " . $this->grid_array[ $this->max_columns ] . "'>", $output );
  164.                     $output = str_replace( "{last_item}", "avia_mega_menu_columns_last", $output );
  165.  
  166.                     foreach( $this->rowsCounter as $row => $columns )
  167.                     {
  168.                         $output = str_replace( "{current_row_" . $row . "}", "avia_mega_menu_columns_" . $columns . " " . $this->grid_array[1], $output );
  169.                     }
  170.  
  171.                     $this->columns = 0;
  172.                     $this->max_columns = 0;
  173.                     $this->rowsCounter = array();
  174.                 }
  175.                 else
  176.                 {
  177.                     $output = str_replace( "{replace_one}", '', $output );
  178.                 }
  179.             }
  180.         }
  181.  
  182.         /**
  183.          * @see Walker::start_el()
  184.          *
  185.          * @param string $output Passed by reference. Used to append additional content.
  186.          * @param object $item Menu item data object.
  187.          * @param int $depth Depth of menu item. Used for padding.
  188.          * @param int $current_page Menu item ID.
  189.          * @param object $args
  190.          */
  191.         function start_el( &$output, $item, $depth = 0, $args = array(), $current_object_id = 0 )
  192.         {
  193.             global $wp_query;
  194.  
  195.             //set maxcolumns
  196.             if( ! isset( $args->max_columns ) )
  197.             {
  198.                 $args->max_columns = 7;
  199.             }
  200.  
  201.             /**
  202.              * @used_by         ..\includes\config-enfold\functions-enfold.php    avia_menu_item_filter()    10
  203.              * @since ?????
  204.              * @param object $item
  205.              * @return object
  206.              */
  207.             $item = apply_filters( 'avf_menu_items', $item );
  208.  
  209.             $item_output = $li_text_block_class = $column_class = '';
  210.  
  211.             if( $depth === 0 )
  212.             {
  213.                 $this->first_level_count ++;
  214.                 $this->mega_active  = get_post_meta( $item->ID, '_menu-item-avia-megamenu', true );
  215.                 $style              = get_post_meta( $item->ID, '_menu-item-avia-style', true );
  216.             }
  217.  
  218.             if( ! empty( $item->url ) && strpos( $item->url, "[domain]" ) !== false )
  219.             {
  220.                 $replace = str_replace( "http://", '', get_home_url() );
  221.                 $replace = str_replace( "https://", '', $replace );
  222.                 $item->url = str_replace( "[domain]", $replace, $item->url );
  223.             }
  224.  
  225.             if( $depth === 1 && $this->mega_active && $this->mega_allowed )
  226.             {
  227.                 $this->columns ++;
  228.  
  229.                 //check if we have more than $args['max_columns'] columns or if the user wants to start a new row
  230.                 if( $this->columns > $args->max_columns || ( get_post_meta( $item->ID, '_menu-item-avia-division', true ) && $this->columns != 1 ) )
  231.                 {
  232.                     $this->columns = 1;
  233.                     $this->rows ++;
  234.  
  235.                     $output .= "\n</ul><ul class=\"sub-menu avia_mega_hr\">\n";
  236.                     $output = str_replace( "{last_item}", "avia_mega_menu_columns_last", $output );
  237.                 }
  238.                 else
  239.                 {
  240.                     $output = str_replace( "{last_item}", '', $output );
  241.                 }
  242.  
  243.                 $this->rowsCounter[ $this->rows ] = $this->columns;
  244.  
  245.                 if( $this->max_columns < $this->columns )
  246.                 {
  247.                     $this->max_columns = $this->columns;
  248.                 }
  249.  
  250.                 $title = apply_filters( 'the_title', $item->title, $item->ID );
  251.  
  252.                 if( $title != "&#8211;" && trim( $title ) != "-" && $title != '"-"' ) //fallback for people who copy the description o_O
  253.                 {
  254.                     $heading_title = do_shortcode( $title );
  255.  
  256.                     if( ! empty( $item->url ) && $item->url != "#" && $item->url != 'http://' )
  257.                     {
  258.                         $heading_title = "<a href='{$item->url}'>{$title}</a>";
  259.                     }
  260.  
  261.                     $item_output .= "<span class='mega_menu_title heading-color av-special-font'>{$heading_title}</span>";
  262.                 }
  263.  
  264.                 $column_class  = ' {current_row_' . $this->rows.  '} {last_item}';
  265.  
  266.                 if( $this->columns == 1 )
  267.                 {
  268.                     $column_class .= " avia_mega_menu_columns_first";
  269.                 }
  270.             }
  271.             else if( $depth >= 2 && $this->mega_active && $this->mega_allowed && get_post_meta( $item->ID, '_menu-item-avia-textarea', true ) )
  272.             {
  273.                 $li_text_block_class = 'avia_mega_text_block ';
  274.  
  275.                 $item_output.= do_shortcode( $item->post_content );
  276.             }
  277.             else
  278.             {
  279.                 $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) . '"' : '';
  280.                 $attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) . '"' : '';
  281.                 $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) . '"' : '';
  282.                 $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) . '"' : '';
  283.  
  284.                 if( 'inactive' != avia_get_option('markup') )
  285.                 {
  286.                     $attributes .= ' itemprop="url"';
  287.                 }
  288.  
  289.                 // @since 4.8.6.5    accessibility rules
  290.                 $attributes .= ' tabindex="0"';
  291.  
  292.  
  293.                 $item_output .= $args->before;
  294.                 $item_output .= '<a'. $attributes . '><span class="avia-bullet"></span>';
  295.                 $item_output .= $args->link_before . '<span class="avia-menu-text">'. do_shortcode( apply_filters( 'the_title', $item->title, $item->ID ) ) . "</span>" . $args->link_after;
  296.  
  297.                 if($depth === 0)
  298.                 {
  299.                     if(!empty($item->description))
  300.                     {
  301.                         $item_output .= '<span class="avia-menu-subtext">' . do_shortcode( $item->description ) . "</span>";
  302.                     }
  303.  
  304.                     $item_output .= '<span class="avia-menu-fx"><span class="avia-arrow-wrap"><span class="avia-arrow"></span></span></span>';
  305.                 }
  306.  
  307.                 $item_output .= '</a>';
  308.                 $item_output .= $args->after;
  309.             }
  310.  
  311.             $class_names = $value = '';
  312.             $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
  313.             $classes = empty( $item->classes ) ? array() : (array) $item->classes;
  314.  
  315.             if( isset( $style ) )
  316.             {
  317.                 $classes[] = $style;
  318.             }
  319.  
  320.             if( $depth === 0 && $key = array_search( 'current-menu-item', $classes ) )
  321.             {
  322.                 if( $this->active_item )
  323.                 {
  324.                      unset( $classes[ $key ] );
  325.                 }
  326.                 else
  327.                 {
  328.                     $this->active_item = true;
  329.                 }
  330.             }
  331.  
  332.             $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
  333.  
  334.             if( $depth === 0 && $this->mega_active && $this->mega_allowed )
  335.             {
  336.                 $class_names .= " menu-item-mega-parent ";
  337.             }
  338.  
  339.             if( $depth === 0 )
  340.             {
  341.                 $class_names .= " menu-item-top-level menu-item-top-level-{$this->first_level_count}";
  342.             }
  343.  
  344.             //highlight correct blog page
  345.             if( $depth === 0 && $this->blog_id && $this->blog_id == $item->object_id && is_singular( 'post' ) )
  346.             {
  347.                 $class_names .= " current-menu-item";
  348.             }
  349.  
  350.             $class_names = ' class="' . $li_text_block_class . esc_attr( $class_names ) . $column_class . '"';
  351.  
  352.             $output .= $indent . '<li role="menuitem" id="menu-item-'. $item->ID . '"' . $value . $class_names . '>';
  353.  
  354.             $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
  355.         }
  356.  
  357.         /**
  358.          * @see Walker::end_el()
  359.          *
  360.          * @param string $output Passed by reference. Used to append additional content.
  361.          * @param object $item Page data object. Not used.
  362.          * @param int $depth Depth of page. Not Used.
  363.          */
  364.         function end_el( &$output, $item, $depth = 0, $args = array() )
  365.         {
  366.             $output .= "</li>\n";
  367.         }
  368.     }
  369. }
  370.  
  371. if( ! function_exists( 'avia_responsive_fallback_menu' ) )
  372. {
  373.     /**
  374.      * Create a navigation out of pages if the user didnt create a menu in the backend
  375.      *
  376.      */
  377.     function avia_responsive_fallback_menu()
  378.     {
  379.         $current = '';
  380.         $exclude = avia_get_option( 'frontpage' );
  381.  
  382.         if( is_front_page() )
  383.         {
  384.             $current = "class='current-menu-item'";
  385.         }
  386.  
  387.         if( $exclude )
  388.         {
  389.             $exclude ="&exclude={$exclude}";
  390.         }
  391.  
  392.         echo "<div class='fallback_menu'>";
  393.         echo    "<ul class='avia_mega menu'>";
  394.         echo        "<li {$current}><a href='" . get_bloginfo( 'url' ) . "'>Home</a></li>";
  395.                     wp_list_pages( 'title_li=&sort_column=menu_order' . $exclude );
  396.         echo    "</ul>";
  397.         echo "</div>";
  398.     }
  399. }
  400.  
Advertisement
Add Comment
Please, Sign In to add comment