Advertisement
Guenni007

menu

Mar 3rd, 2022
754
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 24.18 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Fullwidth Sub Menu
  4.  *
  5.  * Shortcode that allows to display a fullwidth Sub Menu
  6.  */
  7. if( ! defined( 'ABSPATH' ) ) {  exit;  }    // Exit if accessed directly
  8.  
  9.  
  10. if( ! class_exists( 'avia_sc_submenu' ) )
  11. {
  12.     class avia_sc_submenu extends aviaShortcodeTemplate
  13.     {
  14.         /**
  15.          *
  16.          * @var int
  17.          */
  18.         static protected $count = 0;
  19.  
  20.         /**
  21.          *
  22.          * @var int
  23.          */
  24.         static protected $custom_items = 0;
  25.  
  26.         /**
  27.          *
  28.          * @since 4.8.8
  29.          * @var boolean
  30.          */
  31.         protected $in_sc_exec;
  32.  
  33.         /**
  34.          *
  35.          * @since 4.8.7
  36.          * @param AviaBuilder $builder
  37.          */
  38.         public function __construct( $builder )
  39.         {
  40.             $this->in_sc_exec = false;
  41.  
  42.             parent::__construct( $builder );
  43.         }
  44.  
  45.         /**
  46.          * @since 4.8.7
  47.          */
  48.         public function __destruct()
  49.         {
  50.             parent::__destruct();
  51.         }
  52.  
  53.         /**
  54.          * Create the config array for the shortcode button
  55.          */
  56.         function shortcode_insert_button()
  57.         {
  58.             $this->config['version']        = '1.0';
  59.             $this->config['is_fullwidth']   = 'yes';
  60.             $this->config['self_closing']   = 'no';
  61.  
  62.             $this->config['name']           = __( 'Fullwidth Sub Menu', 'avia_framework' );
  63.             $this->config['tab']            = __( 'Content Elements', 'avia_framework' );
  64.             $this->config['icon']           = AviaBuilder::$path['imagesURL'] . 'sc-submenu.png';
  65.             $this->config['order']          = 30;
  66.             $this->config['target']         = 'avia-target-insert';
  67.             $this->config['shortcode']      = 'av_submenu';
  68.             $this->config['shortcode_nested'] = array( 'av_submenu_item' );
  69.             $this->config['tooltip']        = __( 'Display a sub menu', 'avia_framework' );
  70.             $this->config['tinyMCE']        = array( 'disable' => 'true' );
  71.             $this->config['drag-level']     = 1;
  72.             $this->config['preview']        = false;
  73.             $this->config['disabling_allowed'] = true;
  74.  
  75.             $this->config['id_name']        = 'id';
  76.             $this->config['id_show']        = 'yes';
  77.             $this->config['alb_desc_id']    = 'alb_description';
  78.         }
  79.  
  80.         function extra_assets(){
  81.         // load css - now from child-theme folder shortcodes -
  82.         // necessary because some css rules set to !important can't be overwritten by quick css
  83.         wp_enqueue_style( 'avia-module-menu', get_stylesheet_directory_uri().'/shortcodes/menu.css', array( 'avia-layout' ), false );
  84.  
  85.         // load js - necessary because the if clause on hamburger visible had to be changed
  86.         // everything else here on menu.php is untouched
  87.         wp_enqueue_script( 'avia-module-menu', get_stylesheet_directory_uri().'/shortcodes/menu.js', array( 'avia-shortcodes' ), false, true );
  88.         }
  89.  
  90.         /**
  91.          * Popup Elements
  92.          *
  93.          * If this function is defined in a child class the element automatically gets an edit button, that, when pressed
  94.          * opens a modal window that allows to edit the element properties
  95.          *
  96.          * @return void
  97.          */
  98.         function popup_elements()
  99.         {
  100.  
  101.             $this->elements = array(
  102.  
  103.                 array(
  104.                         'type'  => 'tab_container',
  105.                         'nodescription' => true
  106.                     ),
  107.  
  108.                 array(
  109.                         'type'  => 'tab',
  110.                         'name'  => __( 'Content', 'avia_framework' ),
  111.                         'nodescription' => true
  112.                     ),
  113.  
  114.                     array(
  115.                             'type'          => 'template',
  116.                             'template_id'   => $this->popup_key( 'content_menus' ),
  117.                             'nodescription' => true
  118.                         ),
  119.  
  120.                 array(
  121.                         'type'  => 'tab_close',
  122.                         'nodescription' => true
  123.                     ),
  124.  
  125.                 array(
  126.                         'type'  => 'tab',
  127.                         'name'  => __( 'Styling', 'avia_framework' ),
  128.                         'nodescription' => true
  129.                     ),
  130.  
  131.                     array(
  132.                             'type'          => 'template',
  133.                             'template_id'   => $this->popup_key( 'styling_colors' ),
  134.                             'nodescription' => true
  135.                         ),
  136.  
  137.                 array(
  138.                         'type'  => 'tab_close',
  139.                         'nodescription' => true
  140.                     ),
  141.  
  142.                 array(
  143.                         'type'  => 'tab',
  144.                         'name'  => __( 'Advanced', 'avia_framework' ),
  145.                         'nodescription' => true
  146.                     ),
  147.  
  148.                     array(
  149.                             'type'  => 'toggle_container',
  150.                             'nodescription' => true
  151.                         ),
  152.  
  153.                         array(
  154.                                     'type'          => 'template',
  155.                                     'template_id'   => $this->popup_key( 'advanced_responsive' ),
  156.                                     'nodescription' => true
  157.                                 ),
  158.  
  159.                         array(
  160.                                 'type'          => 'template',
  161.                                 'template_id'   => 'developer_options_toggle',
  162.                                 'args'          => array( 'sc' => $this )
  163.                             ),
  164.  
  165.                     array(
  166.                             'type'  => 'toggle_container_close',
  167.                             'nodescription' => true
  168.                         ),
  169.  
  170.                 array(
  171.                         'type'  => 'tab_close',
  172.                         'nodescription' => true
  173.                     ),
  174.  
  175.                 array(
  176.                         'type'  => 'tab_container_close',
  177.                         'nodescription' => true
  178.                     )
  179.  
  180.                 );
  181.  
  182.         }
  183.  
  184.         /**
  185.          * Create and register templates for easier maintainance
  186.          *
  187.          * @since 4.6.4
  188.          */
  189.         protected function register_dynamic_templates()
  190.         {
  191.             global $avia_config;
  192.  
  193.             $this->register_modal_group_templates();
  194.  
  195.             /**
  196.              * Content Tab
  197.              * ===========
  198.              */
  199.  
  200.             $menus = array();
  201.             if( ! empty( $_POST ) && ! empty( $_POST['action'] ) && $_POST['action'] == 'avia_ajax_av_submenu' )
  202.             {
  203.                 $menus = AviaHelper::list_menus();
  204.             }
  205.  
  206.             $c = array(
  207.                         array(
  208.                             'name'  => __( 'Which kind of menu do you want to display','avia_framework' ),
  209.                             'desc'  => __( 'Either use an existing menu, built in Appearance -> Menus or create a simple custom menu here', 'avia_framework' ),
  210.                             'id'    => 'which_menu',
  211.                             'type'  => 'select',
  212.                             'std'   => 'center',
  213.                             'subtype'   => array(
  214.                                                 __( 'Use existing menu', 'avia_framework' )         => '',
  215.                                                 __( 'Build simple custom menu', 'avia_framework' )  => 'custom',
  216.                                             )
  217.                         ),
  218.  
  219.  
  220.                         array(
  221.                             'name'  => __( 'Select menu to display', 'avia_framework' ),
  222.                             'desc'  => __( 'You can create new menus in ', 'avia_framework' ) . "<a target='_blank' href='" . admin_url( 'nav-menus.php?action=edit&menu=0' ) . "'>" . __( 'Appearance -> Menus', 'avia_framework' ) . '</a><br/>' . __( 'Please note that Mega Menus are not supported for this element ', 'avia_framework' ),
  223.                             'id'    => 'menu',
  224.                             'type'  => 'select',
  225.                             'std'   => '',
  226.                             'required'  => array( 'which_menu', 'not', 'custom' ),
  227.                             'subtype'   =>  $menus
  228.                         ),
  229.  
  230.                         array(
  231.                             'name'          => __( 'Add/Edit submenu item text', 'avia_framework' ),
  232.                             'desc'          => __( 'Here you can add, remove and edit the submenu item text', 'avia_framework' ),
  233.                             'type'          => 'modal_group',
  234.                             'id'            => 'content',
  235.                             'required'      => array( 'which_menu', 'equals', 'custom' ),
  236.                             'modal_title'   => __( 'Edit Text Element', 'avia_framework' ),
  237.                             'std'           => array(
  238.                                                     array( 'title' => __( 'Menu Item 1', 'avia_framework' ) ),
  239.                                                     array( 'title' => __( 'Menu Item 2', 'avia_framework' ) ),
  240.                                                 ),
  241.                             'subelements'   => $this->create_modal()
  242.                         ),
  243.  
  244.                         array(
  245.                             'name'  => __( 'Menu Position', 'avia_framework' ),
  246.                             'desc'  => __( 'Aligns the menu either to the left, the right or centers it', 'avia_framework' ),
  247.                             'id'    => 'position',
  248.                             'type'  => 'select',
  249.                             'std'   => 'center',
  250.                             'subtype'   => array(
  251.                                                 __( 'Left', 'avia_framework' )      => 'left',
  252.                                                 __( 'Center', 'avia_framework' )    => 'center',
  253.                                                 __( 'Right', 'avia_framework' )     => 'right',
  254.                                             )
  255.                         ),
  256.  
  257.                         array(
  258.                             'name'  => __( 'Sticky Submenu', 'avia_framework' ),
  259.                             'desc'  => __( 'If checked the menu will stick at the top of the page once it touches it. This option is ignored when burger menu icon is shown.', 'avia_framework' ),
  260.                             'id'    => 'sticky',
  261.                             'std'   => 'true',
  262.                             'type'  => 'checkbox'
  263.                         ),
  264.  
  265.                 );
  266.  
  267.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'content_menus' ), $c );
  268.  
  269.  
  270.             /**
  271.              * Styling Tab
  272.              * ===========
  273.              */
  274.  
  275.             $desc  = __('The menu will use the color scheme you select. Color schemes are defined on your styling page', 'avia_framework' );
  276.             $desc .= '<br/><a target="_blank" href="' . admin_url( 'admin.php?page=avia#goto_styling' ) . '">';
  277.             $desc .= __( '(Show Styling Page)', 'avia_framework' ) . '</a>';
  278.  
  279.  
  280.             $c = array(
  281.                         array(
  282.                             'name'  => __( 'Menu Colors', 'avia_framework' ),
  283.                             'id'    => 'color',
  284.                             'desc'  => $desc,
  285.                             'type'  => 'select',
  286.                             'std'   => 'main_color',
  287.                             'subtype' =>  array_flip( $avia_config['color_sets'] )
  288.                         ),
  289.  
  290.                 );
  291.  
  292.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_colors' ), $c );
  293.  
  294.             /**
  295.              * Advanced Tab
  296.              * ============
  297.              */
  298.  
  299.             $c = array(
  300.                         array(
  301.                             'name'  => __( 'Mobile Menu Display','avia_framework' ),
  302.                             'desc'  => __( 'How do you want to display the menu on mobile devices','avia_framework' ),
  303.                             'id'    => 'mobile',
  304.                             'type'  => 'select',
  305.                             'std'   => 'disabled',
  306.                             'subtype'   => array(
  307.                                                 __( 'Display full menu (works best if you only got a few menu items)', 'avia_framework' )               => 'disabled',
  308.                                                 __( 'Display a button to open menu (works best for menus with a lot of menu items)', 'avia_framework' ) => 'active',
  309.                                             )
  310.                         ),
  311.  
  312.                         array(
  313.                             'name'      => __( 'Screenwidth for burger menu button', 'avia_framework' ),
  314.                             'desc'      => __( 'Select the maximum screenwidth to use a burger menu button instead of full menu. Above that the full menu is displayed', 'avia_framework' ),
  315.                             'id'        => 'mobile_switch',
  316.                             'type'      => 'select',
  317.                             'std'       => 'av-switch-768',
  318.                             'required'  => array( 'mobile', 'equals', 'active' ),
  319.                             'subtype'   => array(
  320.                                                 __( 'Switch at 990px (tablet landscape)','avia_framework' )     => 'av-switch-990',
  321.                                                 __( 'Switch at 768px (tablet portrait)','avia_framework' )      => 'av-switch-768',
  322.                                                 __( 'Switch at 480px (smartphone portrait)','avia_framework' )  => 'av-switch-480',
  323.                                             )
  324.                         ),
  325.  
  326.                         array(
  327.                             'name'  => __( 'Hide Mobile Menu Submenu Items', 'avia_framework'),
  328.                             'desc'  => __( 'By default all menu items of the mobile menu are visible. If you activate this option they will be hidden and a user needs to click on the parent menu item to display the submenus', 'avia_framework'),
  329.                             'id'    => 'mobile_submenu',
  330.                             'required'  => array( 'mobile', 'equals', 'active' ),
  331.                             'type'  => 'checkbox',
  332.                             'std'   => ''
  333.                         ),
  334.  
  335.  
  336.                 );
  337.  
  338.             $template = array(
  339.                             array(
  340.                                 'type'          => 'template',
  341.                                 'template_id'   => 'toggle',
  342.                                 'title'         => __( 'Responsive', 'avia_framework' ),
  343.                                 'content'       => $c
  344.                             ),
  345.                     );
  346.  
  347.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'advanced_responsive' ), $template );
  348.  
  349.         }
  350.  
  351.         /**
  352.          * Creates the modal popup for a single entry
  353.          *
  354.          * @since 4.6.4
  355.          * @return array
  356.          */
  357.         protected function create_modal()
  358.         {
  359.             $elements = array(
  360.  
  361.                 array(
  362.                         'type'  => 'tab_container',
  363.                         'nodescription' => true
  364.                     ),
  365.  
  366.                 array(
  367.                         'type'  => 'tab',
  368.                         'name'  => __( 'Content', 'avia_framework' ),
  369.                         'nodescription' => true
  370.                     ),
  371.  
  372.                     array(
  373.                             'type'          => 'template',
  374.                             'template_id'   => $this->popup_key( 'modal_content_menu' )
  375.                         ),
  376.  
  377.                 array(
  378.                         'type'  => 'tab_close',
  379.                         'nodescription' => true
  380.                     ),
  381.  
  382.                 array(
  383.                         'type'  => 'tab',
  384.                         'name'  => __( 'Styling', 'avia_framework' ),
  385.                         'nodescription' => true
  386.                     ),
  387.  
  388.                     array(
  389.                             'type'          => 'template',
  390.                             'template_id'   => $this->popup_key( 'modal_styling_style' )
  391.                         ),
  392.  
  393.                 array(
  394.                         'type'  => 'tab_close',
  395.                         'nodescription' => true
  396.                     ),
  397.  
  398.                 array(
  399.                         'type'  => 'tab',
  400.                         'name'  => __( 'Advanced', 'avia_framework' ),
  401.                         'nodescription' => true
  402.                     ),
  403.  
  404.                     array(
  405.                             'type'          => 'template',
  406.                             'template_id'   => $this->popup_key( 'modal_advanced_link' )
  407.                         ),
  408.  
  409.                 array(
  410.                         'type'  => 'tab_close',
  411.                         'nodescription' => true
  412.                     ),
  413.  
  414.                 array(
  415.                         'type'  => 'tab_container_close',
  416.                         'nodescription' => true
  417.                     )
  418.  
  419.                 );
  420.  
  421.             return $elements;
  422.         }
  423.  
  424.         /**
  425.          * Register all templates for the modal group popup
  426.          *
  427.          * @since 4.6.4
  428.          */
  429.         protected function register_modal_group_templates()
  430.         {
  431.             /**
  432.              * Content Tab
  433.              * ===========
  434.              */
  435.             $c = array(
  436.                         array(
  437.                             'name'  => __( 'Menu Text', 'avia_framework' ),
  438.                             'desc'  => __( 'Enter the menu text here', 'avia_framework' ) ,
  439.                             'id'    => 'title',
  440.                             'std'   => '',
  441.                             'type'  => 'input'
  442.                         ),
  443.  
  444.  
  445.                 );
  446.  
  447.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'modal_content_menu' ), $c );
  448.  
  449.  
  450.             /**
  451.              * Styling Tab
  452.              * ===========
  453.              */
  454.             $c = array(
  455.                         array(
  456.                             'name'  => __( 'Style', 'avia_framework' ),
  457.                             'desc'  => __( 'Select the styling of your menu item', 'avia_framework' ),
  458.                             'id'    => 'button_style',
  459.                             'type'  => 'select',
  460.                             'std'   => '',
  461.                             'subtype'   => array(
  462.                                                 __( 'Default Style', 'avia_framework' )             => '',
  463.                                                 __( 'Button Style (Colored)', 'avia_framework' )    => 'av-menu-button av-menu-button-colored',
  464.                                                 __( 'Button Style (Bordered)', 'avia_framework' )   => 'av-menu-button av-menu-button-bordered',
  465.                                             ),
  466.                         )
  467.  
  468.                 );
  469.  
  470.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'modal_styling_style' ), $c );
  471.  
  472.             /**
  473.              * Advanced Tab
  474.              * ===========
  475.              */
  476.  
  477.             $c = array(
  478.                         array(
  479.                             'type'          => 'template',
  480.                             'template_id'   => 'linkpicker_toggle',
  481.                             'name'          => __( 'Menu Link?', 'avia_framework' ),
  482.                             'desc'          => __( 'Apply a link to the menu text?', 'avia_framework' ),
  483.                             'subtypes'      => array( 'manually', 'single', 'taxonomy' ),
  484.                             'no_toggle'     => true
  485.                         ),
  486.                 );
  487.  
  488.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'modal_advanced_link' ), $c );
  489.  
  490.         }
  491.  
  492.  
  493.         /**
  494.          * Editor Sub Element - this function defines the visual appearance of an element that is displayed within a modal window and on click opens its own modal window
  495.          * Works in the same way as Editor Element
  496.          * @param array $params this array holds the default values for $content and $args.
  497.          * @return $params the return array usually holds an innerHtml key that holds item specific markup.
  498.          */
  499.         function editor_sub_element( $params )
  500.         {
  501.             $template = $this->update_template( 'title', '{{title}}' );
  502.  
  503.             $params['innerHtml']  = '';
  504.             $params['innerHtml'] .= "<div class='avia_title_container'>";
  505.             $params['innerHtml'] .= "<span {$template} >{$params['args']['title']}</span></div>";
  506.  
  507.             return $params;
  508.         }
  509.  
  510.  
  511.         /**
  512.          * Editor Element - this function defines the visual appearance of an element on the AviaBuilder Canvas
  513.          * Most common usage is to define some markup in the $params['innerHtml'] which is then inserted into the drag and drop container
  514.          * Less often used: $params['data'] to add data attributes, $params['class'] to modify the className
  515.          *
  516.          *
  517.          * @param array $params this array holds the default values for $content and $args.
  518.          * @return $params the return array usually holds an innerHtml key that holds item specific markup.
  519.          */
  520.         function editor_element( $params )
  521.         {
  522. //          $term_args = array(
  523. //                          'taxonomy'      => 'nav_menu',
  524. //                          'hide_empty'    => false
  525. //                      );
  526. //
  527. //          $menus = AviaHelper::get_terms( $term_args );
  528.  
  529.  
  530.             $params = parent::editor_element( $params );
  531.  
  532.             return $params;
  533.         }
  534.  
  535.  
  536.         /**
  537.          * Returns false by default.
  538.          * Override in a child class if you need to change this behaviour.
  539.          *
  540.          * @since 4.2.1
  541.          * @param string $shortcode
  542.          * @return boolean
  543.          */
  544.         public function is_nested_self_closing( $shortcode )
  545.         {
  546.             if( in_array( $shortcode, $this->config['shortcode_nested'] ) )
  547.             {
  548.                 return true;
  549.             }
  550.  
  551.             return false;
  552.         }
  553.  
  554.         /**
  555.          * Create custom stylings
  556.          *
  557.          * @since 4.8.7
  558.          * @param array $args
  559.          * @return array
  560.          */
  561.         protected function get_element_styles( array $args )
  562.         {
  563.             $result = parent::get_element_styles( $args );
  564.  
  565.             extract( $result );
  566.  
  567.             $default = array(
  568.                             'style'         => '',
  569.                             'menu'          => '',
  570.                             'position'      => 'center',
  571.                             'sticky'        => '',
  572.                             'color'         => 'main_color',
  573.                             'mobile'        => 'disabled',
  574.                             'mobile_switch' => 'av-switch-768',
  575.                             'mobile_submenu'=> '',
  576.                             'which_menu'    => ''
  577.  
  578.                     );
  579.  
  580.             $default = $this->sync_sc_defaults_array( $default, 'no_modal_item', 'no_content' );
  581.  
  582.             Avia_Element_Templates()->add_template_class( $meta, $atts, $default );
  583.  
  584.             $atts = shortcode_atts( $default, $atts, $this->config['shortcode'] );
  585.  
  586.             $this->in_sc_exec = true;
  587.  
  588.  
  589.             if( 'disabled' == $atts['mobile'] )
  590.             {
  591.                 $atts['mobile_switch'] = '';
  592.             }
  593.             else if( empty( $atts['mobile_switch'] ) )
  594.             {
  595.                 $atts['mobile_switch'] = 'av-switch-768';
  596.             }
  597.  
  598.  
  599.             $classes = array(
  600.                         'av-submenu-container',
  601.                         $element_id,
  602.                         $atts['color'],
  603.                         $atts['mobile_switch']
  604.                     );
  605.  
  606.             $element_styling->add_classes( 'section', $classes );
  607.             $element_styling->add_classes_from_array( 'section', $meta, 'el_class' );
  608.  
  609.             if( ! empty( $atts['sticky'] ) && $atts['sticky'] != 'disabled' )
  610.             {
  611.                 $element_styling->add_classes( 'section', 'av-sticky-submenu' );
  612.             }
  613.  
  614.             if( isset( $meta['index'] ) && $meta['index'] > 0 )
  615.             {
  616.                 $element_styling->add_classes( 'section', 'submenu-not-first' );
  617.             }
  618.  
  619.  
  620.             $classes = array(
  621.                         'container',
  622.                         "av-menu-mobile-{$atts['mobile']}",
  623.                         "av-submenu-pos-{$atts['position']}"
  624.                     );
  625.  
  626.             $element_styling->add_classes( 'container-menu', $classes );
  627.  
  628.             if( ! empty( $atts['mobile'] ) && 'active' == $atts['mobile'] && ! empty( $atts['mobile_submenu'] ) && $atts['mobile_submenu'] != 'disabled' )
  629.             {
  630.                 $element_styling->add_classes( 'container-menu', 'av-submenu-hidden' );
  631.             }
  632.  
  633.             $classes = array(
  634.                         'av-subnav-menu',
  635. //                      "av-submenu-pos-{$atts['position']}"
  636.                     );
  637.  
  638.             $element_styling->add_classes( 'container-submenu', $classes );
  639.  
  640.  
  641.             $selectors = array(
  642.                         'section'           => ".av-submenu-container.{$element_id}",
  643.                         'container-menu'    => ".av-submenu-container.{$element_id} .container",
  644.                         'container-submenu' => ".av-submenu-container.{$element_id} .av-subnav-menu",
  645.                     );
  646.  
  647.             $element_styling->add_selectors( $selectors );
  648.  
  649.  
  650.             $result['default'] = $default;
  651.             $result['atts'] = $atts;
  652.             $result['content'] = $content;
  653.             $result['element_styling'] = $element_styling;
  654.  
  655.             return $result;
  656.         }
  657.  
  658.         /**
  659.          * Create custom stylings for items
  660.          * (also called when creating header implicit)
  661.          *
  662.          * @since 4.8.7
  663.          * @param array $args
  664.          * @return array
  665.          */
  666.         protected function get_element_styles_item( array $args )
  667.         {
  668.             $result = parent::get_element_styles_item( $args );
  669.  
  670.             extract( $result );
  671.  
  672.             $default = array(
  673.                         'title'         => '',
  674.                         'link'          => '',
  675.                         'linktarget'    => '',
  676.                         'button_style'  => '',
  677.                     );
  678.  
  679.             $default = $this->sync_sc_defaults_array( $default, 'modal_item', 'no_content' );
  680.  
  681.             $atts = shortcode_atts( $default, $atts, $this->config['shortcode_nested'][0] );
  682.  
  683.             $classes = array(
  684.                         'menu-item',
  685.                         $element_id,
  686.                         'menu-item-top-level',
  687.                         $atts['button_style']
  688.                     );
  689.  
  690.             $element_styling->add_classes( 'container', $classes );
  691.  
  692.  
  693.  
  694.             $selectors = array(
  695.                         'container'         => ".menu-item.{$element_id}"
  696.                     );
  697.  
  698.             $element_styling->add_selectors( $selectors );
  699.  
  700.             $result['default'] = $default;
  701.             $result['atts'] = $atts;
  702.             $result['content'] = $content;
  703.             $result['element_styling'] = $element_styling;
  704.             $result['meta'] = $meta;
  705.  
  706.             return $result;
  707.         }
  708.  
  709.  
  710.         /**
  711.          * Frontend Shortcode Handler
  712.          *
  713.          * @param array $atts array of attributes
  714.          * @param string $content text within enclosing form of shortcode element
  715.          * @param string $shortcodename the shortcode found, when == callback name
  716.          * @return string $output returns the modified html string
  717.          */
  718.         function shortcode_handler( $atts, $content = '', $shortcodename = '', $meta = '' )
  719.         {
  720.             $result = $this->get_element_styles( compact( array( 'atts', 'content', 'shortcodename', 'meta' ) ) );
  721.  
  722.             extract( $result );
  723.  
  724.             extract( $atts );
  725.  
  726.  
  727.             avia_sc_submenu::$count ++;
  728.             avia_sc_submenu::$custom_items = 0;
  729.  
  730.             $params = array();
  731.  
  732.             $element = '';
  733.             $sticky_div = '';
  734.             $mobile_button = '';
  735.             $submenu_class = $element_styling->get_class_string( 'container-submenu' );
  736.  
  737.             if( $which_menu == 'custom' )
  738.             {
  739.                 $custom_menu = ShortcodeHelper::avia_remove_autop( $content, true );
  740.  
  741.                 if( ! empty( $custom_menu ) )
  742.                 {
  743.                     $element .= "<ul id='av-custom-submenu-" . avia_sc_submenu::$count . "' class='{$submenu_class}'>";
  744.                     $element .=     $custom_menu;
  745.                     $element .= '</ul>';
  746.                 }
  747.             }
  748.             else
  749.             {
  750.                 $element .= wp_nav_menu(
  751.                     array(
  752.                         'menu'          => wp_get_nav_menu_object( $menu ),
  753.                         'menu_class'    => $submenu_class,
  754.                         'fallback_cb'   => '',
  755.                         'container'     => false,
  756.                         'echo'          => false,
  757.                         'walker'        => new avia_responsive_mega_menu( array( 'megamenu' => 'disabled' ) )
  758.                     )
  759.                 );
  760.             }
  761.  
  762.             if( ! empty( $mobile ) && 'active' == $mobile )
  763.             {
  764.                 $mobile_button  = '<a href="#" class="mobile_menu_toggle" ' . av_icon_string( 'mobile_menu' ) . '>';
  765.                 $mobile_button .=       '<span class="av-current-placeholder">' . __( 'Menu', 'avia_framework' ) . '</span>';
  766.                 $mobile_button .= '</a>';
  767.             }
  768.  
  769.  
  770.             $params['open_structure'] = false;
  771.             $params['id'] = ! empty( $meta['custom_id_val'] ) ? $meta['custom_id_val'] : 'sub_menu' . avia_sc_submenu::$count;
  772.             $params['custom_markup'] = $meta['custom_markup'];
  773.             $params['style'] = "style='z-index:" . ( avia_sc_submenu::$count + 300 ) . "'";
  774.  
  775.             if( $sticky && $sticky != 'disabled' )
  776.             {
  777.                 $params['before_new'] = "<div class='clear'></div>";
  778.                 $sticky_div = "<div class='sticky_placeholder'></div>";
  779.             }
  780.  
  781.             //we dont need a closing structure if the element is the first one or if a previous fullwidth element was displayed before
  782.             if( isset( $meta['index'] ) && $meta['index'] == 0 )
  783.             {
  784.                 $params['close'] = false;
  785.             }
  786.  
  787.             if( ! empty( $meta['siblings']['prev']['tag'] ) && in_array( $meta['siblings']['prev']['tag'], AviaBuilder::$full_el_no_section  ) )
  788.             {
  789.                 $params['close'] = false;
  790.             }
  791.  
  792.             $params['class'] = $element_styling->get_class_string( 'section' );
  793.  
  794.             $style_tag = $element_styling->get_style_tag( $element_id );
  795.             $menu_class = $element_styling->get_class_string( 'container-menu' );
  796.  
  797.             $output  = '';
  798.             $output .= $style_tag;
  799.             $output .= avia_new_section( $params );
  800.             $output .=      "<div class='{$menu_class}'>{$mobile_button}{$element}</div>";
  801.             $output .= avia_section_after_element_content( $meta , 'after_submenu_' . avia_sc_submenu::$count, false, $sticky_div );
  802.  
  803.             $this->in_sc_exec = false;
  804.  
  805.             return $output;
  806.         }
  807.  
  808.         /**
  809.          * Shortcode handler
  810.          *
  811.          * @param array $atts
  812.          * @param string $content
  813.          * @param string $shortcodename
  814.          * @param array $meta
  815.          * @return string
  816.          */
  817.         public function av_submenu_item( $atts, $content = '', $shortcodename = '', $meta = '' )
  818.         {
  819.             /**
  820.              * Fixes a problem when 3-rd party plugins call nested shortcodes without executing main shortcode  (like YOAST in wpseo-filter-shortcodes)
  821.              */
  822.             if( ! $this->in_sc_exec )
  823.             {
  824.                 return '';
  825.             }
  826.  
  827.             $result = $this->get_element_styles_item( compact( array( 'atts', 'content', 'shortcodename' ) ) );
  828.  
  829.             extract( $result );
  830.  
  831.             extract( $atts );
  832.  
  833.             if( empty( $title) )
  834.             {
  835.                 return '';
  836.             }
  837.  
  838.             avia_sc_submenu::$custom_items++;
  839.  
  840.             $link = AviaHelper::get_url( $link );
  841.             $blank = AviaHelper::get_link_target( $linktarget );
  842.  
  843.             $element_styling->add_classes( 'container', 'menu-item-top-level-' . avia_sc_submenu::$custom_items );
  844.  
  845.  
  846.             $style_tag = $element_styling->get_style_tag( $element_id );
  847.             //          $this->subitem_inline_styles .= $element_styling->get_style_tag( $element_id, 'rules_only' );
  848.             $container_class = $element_styling->get_class_string( 'container' );
  849.  
  850.  
  851.             $output  = '';
  852.             $output .= $style_tag;
  853.             $output .= "<li class='{$container_class}'>";
  854.             $output .=      "<a href='{$link}' {$blank}><span class='avia-bullet'></span>";
  855.             $output .=          "<span class='avia-menu-text'>{$title}</span>";
  856.             //$output .=        "<span class='avia-menu-fx'><span class='avia-arrow-wrap'><span class='avia-arrow'></span></span></span>";
  857.             $output .=      '</a>';
  858.             $output .= '</li>';
  859.  
  860.             return $output;
  861.         }
  862.     }
  863.  
  864. }
  865.  
  866.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement