Guenni007

toggles

Jul 29th, 2021 (edited)
1,132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 35.33 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Accordion and toggles
  4.  * edited on base of enfold 4.8.6
  5.  * Creates toggles or accordions
  6.  */
  7. if( ! defined( 'ABSPATH' ) ) {  exit;  }    // Exit if accessed directly
  8.  
  9.  
  10. if( ! class_exists( 'avia_sc_toggle' ) )
  11. {
  12.     class avia_sc_toggle extends aviaShortcodeTemplate
  13.     {
  14.         /**
  15.          *
  16.          * @var int
  17.          */
  18.         static protected $toggle_id = 1;
  19.  
  20.         /**
  21.          *
  22.          * @var int
  23.          */
  24.         static protected $counter = 1;
  25.  
  26.         /**
  27.          *
  28.          * @var int
  29.          */
  30.         static protected $initial = 0;
  31.  
  32.         /**
  33.          *
  34.          * @var array
  35.          */
  36.         static protected $tags = array();
  37.  
  38.         /**
  39.          *
  40.          * @var array
  41.          */
  42.         static protected $parent_atts = array();
  43.  
  44.         /**
  45.          *
  46.          * @since 4.5.5
  47.          * @var array
  48.          */
  49.         protected $screen_options;
  50.  
  51.  
  52.         /**
  53.          *
  54.          * @since 4.5.5
  55.          * @param AviaBuilder $builder
  56.          */
  57.         public function __construct( $builder )
  58.         {
  59.             $this->screen_options = array();
  60.  
  61.             parent::__construct( $builder );
  62.         }
  63.  
  64.         /**
  65.          * @since 4.5.5
  66.          */
  67.         public function __destruct()
  68.         {
  69.             parent::__destruct();
  70.  
  71.             unset( $this->screen_options );
  72.         }
  73.  
  74.         /**
  75.          * Create the config array for the shortcode button
  76.          */
  77.         function shortcode_insert_button()
  78.         {
  79.             $this->config['version']        = '1.0';
  80.             $this->config['self_closing']   = 'no';
  81.             $this->config['base_element']   = 'yes';
  82.  
  83.             $this->config['name']           = __( 'Accordion', 'avia_framework' );
  84.             $this->config['tab']            = __( 'Content Elements', 'avia_framework' );
  85.             $this->config['icon']           = AviaBuilder::$path['imagesURL'] . 'sc-accordion.png';
  86.             $this->config['order']          = 70;
  87.             $this->config['target']         = 'avia-target-insert';
  88.             $this->config['shortcode']      = 'av_toggle_container';
  89.             $this->config['shortcode_nested'] = array( 'av_toggle' );
  90.             $this->config['tooltip']        = __( 'Creates toggles or accordions (can be used for FAQ)', 'avia_framework' );
  91.             $this->config['disabling_allowed'] = true;
  92.             $this->config['id_name']        = 'id';
  93.             $this->config['id_show']        = 'yes';
  94.             $this->config['alb_desc_id']    = 'alb_description';
  95.             $this->config['name_item']      = __( 'Accordion Item', 'avia_framework' );
  96.             $this->config['tooltip_item']   = __( 'An Accordion Item (toggle, accordions, FAQ)', 'avia_framework' );
  97.         }
  98.  
  99.         function admin_assets()
  100.         {
  101.             $ver = AviaBuilder::VERSION;
  102.  
  103.             wp_register_script('avia_tab_toggle_js', AviaBuilder::$path['assetsURL'] . 'js/avia-tab-toggle.js', array( 'avia_modal_js' ), $ver, true );
  104.             Avia_Builder()->add_registered_admin_script( 'avia_tab_toggle_js' );
  105.         }
  106.  
  107.         function extra_assets()
  108.         {
  109.             //load css
  110.             wp_enqueue_style( 'avia-module-toggles', AviaBuilder::$path['pluginUrlRoot'] . 'avia-shortcodes/toggles/toggles.css', array( 'avia-layout' ), false );
  111.  
  112.                 //load js
  113.             wp_enqueue_script( 'avia-module-toggles', AviaBuilder::$path['pluginUrlRoot'] . 'avia-shortcodes/toggles/toggles.js', array( 'avia-shortcodes' ), false, true );
  114.         }
  115.  
  116.  
  117.         /**
  118.          * Popup Elements
  119.          *
  120.          * If this function is defined in a child class the element automatically gets an edit button, that, when pressed
  121.          * opens a modal window that allows to edit the element properties
  122.          *
  123.          * @return void
  124.          */
  125.         function popup_elements()
  126.         {
  127.             $this->elements = array(
  128.  
  129.                 array(
  130.                         'type'  => 'tab_container',
  131.                         'nodescription' => true
  132.                     ),
  133.  
  134.                 array(
  135.                         'type'  => 'tab',
  136.                         'name'  => __( 'Content', 'avia_framework' ),
  137.                         'nodescription' => true
  138.                     ),
  139.  
  140.                     array(
  141.                             'type'          => 'template',
  142.                             'template_id'   => 'toggle_container',
  143.                             'templates_include' => array(
  144.                                                     $this->popup_key( 'content_togles' ),
  145.                                                     $this->popup_key( 'content_behaviour' )
  146.                                                 ),
  147.                             'nodescription' => true
  148.                         ),
  149.  
  150.                 array(
  151.                         'type'  => 'tab_close',
  152.                         'nodescription' => true
  153.                     ),
  154.  
  155.                 array(
  156.                         'type'  => 'tab',
  157.                         'name'  => __( 'Styling', 'avia_framework' ),
  158.                         'nodescription' => true
  159.                     ),
  160.  
  161.                     array(
  162.                             'type'          => 'template',
  163.                             'template_id'   => 'toggle_container',
  164.                             'templates_include' => array(
  165.                                                     $this->popup_key( 'styling_toggles' ),
  166.                                                     $this->popup_key( 'styling_colors' )
  167.                                                 ),
  168.                             'nodescription' => true
  169.                         ),
  170.  
  171.                 array(
  172.                         'type'  => 'tab_close',
  173.                         'nodescription' => true
  174.                     ),
  175.  
  176.                 array(
  177.                         'type'  => 'tab',
  178.                         'name'  => __( 'Advanced', 'avia_framework' ),
  179.                         'nodescription' => true
  180.                     ),
  181.  
  182.                     array(
  183.                             'type'  => 'toggle_container',
  184.                             'nodescription' => true
  185.                         ),
  186.  
  187.                         array(
  188.                                 'type'          => 'template',
  189.                                 'template_id'   => 'screen_options_toggle',
  190.                                 'lockable'      => true
  191.                             ),
  192.  
  193.                         array(
  194.                                 'type'          => 'template',
  195.                                 'template_id'   => 'developer_options_toggle',
  196.                                 'args'          => array( 'sc' => $this )
  197.                             ),
  198.  
  199.                     array(
  200.                             'type'  => 'toggle_container_close',
  201.                             'nodescription' => true
  202.                         ),
  203.  
  204.                 array(
  205.                         'type'  => 'tab_close',
  206.                         'nodescription' => true
  207.                     ),
  208.  
  209.                 array(
  210.                         'type'          => 'template',
  211.                         'template_id'   => 'element_template_selection_tab',
  212.                         'args'          => array( 'sc' => $this )
  213.                     ),
  214.  
  215.                 array(
  216.                         'type'  => 'tab_container_close',
  217.                         'nodescription' => true
  218.                     )
  219.  
  220.  
  221.                 );
  222.  
  223.         }
  224.  
  225.         /**
  226.          * Create and register templates for easier maintainance
  227.          *
  228.          * @since 4.6.4
  229.          */
  230.         protected function register_dynamic_templates()
  231.         {
  232.  
  233.             $this->register_modal_group_templates();
  234.  
  235.             /**
  236.              * Content Tab
  237.              * ===========
  238.              */
  239.  
  240.             $c = array(
  241.                         array(
  242.                             'name'          => __( 'Add/Edit Toggles', 'avia_framework' ),
  243.                             'desc'          => __( 'Here you can add, remove and edit the toggles you want to display.', 'avia_framework' ),
  244.                             'type'          => 'modal_group',
  245.                             'id'            => 'content',
  246.                             'modal_title'   => __( 'Edit Form Element', 'avia_framework' ),
  247.                             'editable_item' => true,
  248.                             'lockable'      => true,
  249.                             'tmpl_set_default'  => false,
  250.                             'std'           => array(
  251.                                                     array( 'title' => __( 'Toggle 1', 'avia_framework' ), 'tags' => '' ),
  252.                                                     array( 'title' => __( 'Toggle 2', 'avia_framework' ), 'tags' => '' ),
  253.                                                 ),
  254.                             'subelements'   => $this->create_modal()
  255.                         ),
  256.  
  257.                         array(
  258.                             'name'  => __( 'Use as FAQ Page (SEO improvement)', 'avia_framework' ),
  259.                             'desc'  => __( 'Select if content is used as FAQ and add schema.org markup to support Google Search. You must enable theme option &quot;Automated Schema.org HTML Markup&quot; (SEO tab). For valid structured HTML only one FAQ section allowed per page - you can activate &quot;Sorting&quot; and group questions if needed.', 'avia_framework' ),
  260.                             'id'    => 'faq_markup',
  261.                             'type'  => 'select',
  262.                             'std'   => '',
  263.                             'lockable'  => true,
  264.                             'tmpl_set_default'  => false,
  265.                             'subtype'   => array(
  266.                                                 __( 'No markup needed', 'avia_framework' )  => '',
  267.                                                 __( 'Add FAQ markup', 'avia_framework' )    => 'faq_markup'
  268.                                             )
  269.                         )
  270.  
  271.                 );
  272.  
  273.             $template = array(
  274.                             array(
  275.                                 'type'          => 'template',
  276.                                 'template_id'   => 'toggle',
  277.                                 'title'         => __( 'Toggles', 'avia_framework' ),
  278.                                 'content'       => $c
  279.                             ),
  280.                     );
  281.  
  282.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'content_togles' ), $template );
  283.  
  284.  
  285.             $c = array(
  286.                         array(
  287.                             'name'  => __( 'Initial Open', 'avia_framework' ),
  288.                             'desc'  => __( 'Enter the Number of the Accordion Item that should be open initially. Set to Zero if all should be close on page load', 'avia_framework' ),
  289.                             'id'    => 'initial',
  290.                             'type'  => 'input',
  291.                             'std'   => '0',
  292.                             'lockable'  => true,
  293.                         ),
  294.  
  295.                         array(
  296.                             'name'  => __( 'Behavior', 'avia_framework' ),
  297.                             'desc'  => __( 'Should only one toggle be active at a time and the others be hidden or can multiple toggles be open at the same time?', 'avia_framework' ),
  298.                             'id'    => 'mode',
  299.                             'type'  => 'select',
  300.                             'std'   => 'accordion',
  301.                             'lockable'  => true,
  302.                             'subtype'   => array(
  303.                                                 __( 'Only one toggle open at a time (Accordion Mode)', 'avia_framework' )   => 'accordion',
  304.                                                 __( 'Multiple toggles open allowed (Toggle Mode)', 'avia_framework' )       => 'toggle'
  305.                                             )
  306.                         ),
  307.  
  308.                         array(
  309.                             'name'  => __( 'Sorting', 'avia_framework' ),
  310.                             'desc'  => __( 'Display the toggle sorting menu? (You also need to add a number of tags to each toggle to make sorting possible)', 'avia_framework' ),
  311.                             'id'    => 'sort',
  312.                             'type'  => 'select',
  313.                             'std'   => '',
  314.                             'lockable'  => true,
  315.                             'subtype'   => array(
  316.                                                 __( 'No Sorting', 'avia_framework' )        => '',
  317.                                                 __( 'Sorting Active', 'avia_framework' )    => 'true'
  318.                                             )
  319.                         )
  320.  
  321.                 );
  322.  
  323.             $template = array(
  324.                             array(
  325.                                 'type'          => 'template',
  326.                                 'template_id'   => 'toggle',
  327.                                 'title'         => __( 'Behaviour', 'avia_framework' ),
  328.                                 'content'       => $c
  329.                             ),
  330.                     );
  331.  
  332.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'content_behaviour' ), $template );
  333.  
  334.             /**
  335.              * Styling Tab
  336.              * ===========
  337.              */
  338.  
  339.             $c = array(
  340.                         array(
  341.                             'name'  => __( 'Styling', 'avia_framework' ),
  342.                             'desc'  => __( 'Select the styling of the toggles', 'avia_framework' ),
  343.                             'id'    => 'styling',
  344.                             'type'  => 'select',
  345.                             'std'   => '',
  346.                             'lockable'  => true,
  347.                             'subtype'   => array(
  348.                                                 __( 'Default', 'avia_framework' )   => '',
  349.                                                 __( 'Minimal', 'avia_framework' )   => 'av-minimal-toggle',
  350.                                                 __( 'Elegant', 'avia_framework' )   => 'av-elegant-toggle'
  351.                                             )
  352.                         ),
  353.  
  354.  
  355.                 );
  356.  
  357.             $template = array(
  358.                             array(
  359.                                 'type'          => 'template',
  360.                                 'template_id'   => 'toggle',
  361.                                 'title'         => __( 'Toggles Styling', 'avia_framework' ),
  362.                                 'content'       => $c
  363.                             ),
  364.                     );
  365.  
  366.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_toggles' ), $template );
  367.  
  368.             $c = array(
  369.                         array(
  370.                             'name'  => __( 'Colors', 'avia_framework' ),
  371.                             'desc'  => __( 'Either use the themes default colors or apply some custom ones', 'avia_framework' ),
  372.                             'id'    => 'colors',
  373.                             'type'  => 'select',
  374.                             'std'   => '',
  375.                             'lockable'  => true,
  376.                             'subtype'   => array(
  377.                                                 __( 'Default', 'avia_framework' )               => '',
  378.                                                 __( 'Define Custom Colors', 'avia_framework' )  => 'custom'
  379.                                             ),
  380.                         ),
  381.  
  382.                         array(
  383.                             'name'  => __( 'Custom Font Color', 'avia_framework' ),
  384.                             'desc'  => __( 'Select a custom font color. Leave empty to use the default', 'avia_framework' ),
  385.                             'id'    => 'font_color',
  386.                             'type'  => 'colorpicker',
  387.                             'std'   => '',
  388.                             'rgba'  => true,
  389.                             'lockable'  => true,
  390.                             'required'  => array( 'colors', 'equals', 'custom' ),
  391.                             'container_class'   => 'av_third av_third_first'
  392.                         ),
  393.  
  394.                         array(
  395.                             'name'  => __( 'Custom Background Color', 'avia_framework' ),
  396.                             'desc'  => __( 'Select a custom background color. Leave empty to use the default', 'avia_framework' ),
  397.                             'id'    => 'background_color',
  398.                             'type'  => 'colorpicker',
  399.                             'std'   => '',
  400.                             'rgba'  => true,
  401.                             'lockable'  => true,
  402.                             'required'  => array( 'colors', 'equals', 'custom' ),
  403.                             'container_class'   => 'av_third',
  404.                         ),
  405.  
  406.                         array(
  407.                             'name'  => __( 'Custom Border Color', 'avia_framework' ),
  408.                             'desc'  => __( 'Select a custom border color. Leave empty to use the default', 'avia_framework' ),
  409.                             'id'    => 'border_color',
  410.                             'type'  => 'colorpicker',
  411.                             'std'   => '',
  412.                             'rgba'  => true,
  413.                             'lockable'  => true,
  414.                             'required'  => array( 'colors', 'equals', 'custom' ),
  415.                             'container_class'   => 'av_third',
  416.                         ),
  417.  
  418.                         array(
  419.                             'name'  => __( 'Current Toggle Appearance', 'avia_framework' ),
  420.                             'desc'  => __( 'Highlight title bar of open toggles', 'avia_framework' ),
  421.                             'id'    => 'colors_current',
  422.                             'type'  => 'select',
  423.                             'std'   => '',
  424.                             'lockable'  => true,
  425.                             'subtype'   => array(
  426.                                                 __( 'Default', 'avia_framework' )               => '',
  427.                                                 __( 'Define Custom Colors', 'avia_framework' )  => 'custom'
  428.                                             ),
  429.                         ),
  430.  
  431.                         array(
  432.                             'name'  => __( 'Custom Font Color Current Toggle', 'avia_framework' ),
  433.                             'desc'  => __( 'Select a custom font color for the current active toggle. Leave empty to use the default', 'avia_framework' ),
  434.                             'id'    => 'font_color_current',
  435.                             'type'  => 'colorpicker',
  436.                             'std'   => '',
  437.                             'rgba'  => true,
  438.                             'lockable'  => true,
  439.                             'required'  => array( 'colors_current', 'equals', 'custom' )
  440.                         ),
  441.  
  442.                         array(
  443.                             'name'  => __( 'Background Current Toggle', 'avia_framework' ),
  444.                             'desc'  => __( 'Select the type of background for the current active toggle title bar.', 'avia_framework' ),
  445.                             'id'    => 'background_current',
  446.                             'type'  => 'select',
  447.                             'std'   => '',
  448.                             'lockable'  => true,
  449.                             'required'  => array( 'colors_current', 'equals', 'custom' ),
  450.                             'subtype'   => array(
  451.                                                 __( 'Default', 'avia_framework' )               => '',
  452.                                                 __( 'Background Color', 'avia_framework' )      => 'bg_color',
  453.                                                 __( 'Background Gradient', 'avia_framework' )   => 'bg_gradient',
  454.                                             )
  455.                         ),
  456.  
  457.                         array(
  458.                             'name'  => __( 'Title Bar Custom Background Color', 'avia_framework' ),
  459.                             'desc'  => __( 'Select a custom background color. Leave empty for default color', 'avia_framework' ),
  460.                             'id'    => 'background_color_current',
  461.                             'type'  => 'colorpicker',
  462.                             'std'   => '',
  463.                             'rgba'  => true,
  464.                             'lockable'  => true,
  465.                             'required'  => array( 'background_current', 'equals', 'bg_color' ),
  466.                         ),
  467.  
  468.                         array(
  469.                             'type'          => 'template',
  470.                             'template_id'   => 'gradient_colors',
  471.                             'id'            => array( 'background_gradient_current_direction', 'background_gradient_current_color1', 'background_gradient_current_color2', 'background_gradient_current_color3' ),
  472.                             'lockable'      => true,
  473.                             'required'      => array( 'background_current', 'equals', 'bg_gradient' ),
  474.                             'container_class'   => array( '', 'av_third av_third_first', 'av_third', 'av_third' )
  475.                         ),
  476.  
  477.                         array(
  478.                             'name'  => __( 'Hover Toggle Appearance', 'avia_framework' ),
  479.                             'desc'  => __( 'Appearance of toggles on mouse hover', 'avia_framework' ),
  480.                             'id'    => 'hover_colors',
  481.                             'type'  => 'select',
  482.                             'std'   => '',
  483.                             'lockable'  => true,
  484.                             'subtype'   => array(
  485.                                                 __( 'Default', 'avia_framework' )               => '',
  486.                                                 __( 'Define Custom Colors', 'avia_framework' )  => 'custom'
  487.                                             ),
  488.                         ),
  489.  
  490.                         array(
  491.                             'name'  => __( 'Custom Hover Background Color', 'avia_framework' ),
  492.                             'desc'  => __( 'Select a custom hover background color. Leave empty to use the default', 'avia_framework' ),
  493.                             'id'    => 'hover_background_color',
  494.                             'type'  => 'colorpicker',
  495.                             'std'   => '',
  496.                             'rgba'  => true,
  497.                             'lockable'  => true,
  498.                             'container_class' => 'av_third av_half_first',
  499.                             'required'  => array( 'hover_colors', 'equals', 'custom')
  500.                         ),
  501.  
  502.                         array(
  503.                             'name'  => __( 'Custom Hover Font Color', 'avia_framework' ),
  504.                             'desc'  => __( 'Select a custom hover font color. Leave empty to use the default', 'avia_framework' ),
  505.                             'id'    => 'hover_font_color',
  506.                             'type'  => 'colorpicker',
  507.                             'std'   => '',
  508.                             'rgba'  => true,
  509.                             'lockable'  => true,
  510.                             'container_class' => 'av_third',
  511.                             'required'  => array( 'hover_colors', 'equals', 'custom' )
  512.                         )
  513.  
  514.                 );
  515.  
  516.             $template = array(
  517.                             array(
  518.                                 'type'          => 'template',
  519.                                 'template_id'   => 'toggle',
  520.                                 'title'         => __( 'Colors', 'avia_framework' ),
  521.                                 'content'       => $c
  522.                             ),
  523.                     );
  524.  
  525.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_colors' ), $template );
  526.  
  527.         }
  528.  
  529.         /**
  530.          * Creates the modal popup for a single entry
  531.          *
  532.          * @since 4.6.4
  533.          * @return array
  534.          */
  535.         protected function create_modal()
  536.         {
  537.             $elements = array(
  538.  
  539.                 array(
  540.                         'type'  => 'tab_container',
  541.                         'nodescription' => true
  542.                     ),
  543.  
  544.                 array(
  545.                         'type'  => 'tab',
  546.                         'name'  => __( 'Content', 'avia_framework' ),
  547.                         'nodescription' => true
  548.                     ),
  549.  
  550.                     array(
  551.                             'type'          => 'template',
  552.                             'template_id'   => $this->popup_key( 'modal_content_toggle' )
  553.                         ),
  554.  
  555.                 array(
  556.                         'type'  => 'tab_close',
  557.                         'nodescription' => true
  558.                     ),
  559.  
  560.                 array(
  561.                         'type'  => 'tab',
  562.                         'name'  => __( 'Advanced', 'avia_framework' ),
  563.                         'nodescription' => true
  564.                     ),
  565.  
  566.                     array(
  567.                             'type'          => 'template',
  568.                             'template_id'   => 'toggle_container',
  569.                             'templates_include' => array(
  570.                                                     $this->popup_key( 'modal_advanced_developer' )
  571.                                                 ),
  572.                             'nodescription' => true
  573.                         ),
  574.  
  575.                 array(
  576.                         'type'  => 'tab_close',
  577.                         'nodescription' => true
  578.                     ),
  579.  
  580.                 array(
  581.                         'type'          => 'template',
  582.                         'template_id'   => 'element_template_selection_tab',
  583.                         'args'          => array(
  584.                                                 'sc'            => $this,
  585.                                                 'modal_group'   => true
  586.                                             )
  587.                     ),
  588.  
  589.                 array(
  590.                         'type'  => 'tab_container_close',
  591.                         'nodescription' => true
  592.                     )
  593.  
  594.  
  595.                 );
  596.  
  597.             return $elements;
  598.         }
  599.  
  600.         /**
  601.          * Register all templates for the modal group popup
  602.          *
  603.          * @since 4.6.4
  604.          */
  605.         protected function register_modal_group_templates()
  606.         {
  607.             /**
  608.              * Content Tab
  609.              * ===========
  610.              */
  611.  
  612.             $c = array(
  613.                         array(
  614.                             'name'  => __( 'Toggle Title', 'avia_framework' ),
  615.                             'desc'  => __( 'Enter the toggle title here (Better keep it short)', 'avia_framework' ),
  616.                             'id'    => 'title',
  617.                             'type'  => 'input',
  618.                             'std'   => 'Toggle Title',
  619.                             'lockable'  => true,
  620.                         ),
  621.  
  622.                         array(
  623.                             'name'  => __( 'Toggle Content', 'avia_framework' ),
  624.                             'desc'  => __( 'Enter some content here', 'avia_framework' ),
  625.                             'id'    => 'content',
  626.                             'type'  => 'tiny_mce',
  627.                             'std'   => __( 'Toggle Content goes here', 'avia_framework' ),
  628.                             'lockable'  => true,
  629.                         ),
  630.  
  631.                         array(
  632.                             'name'  => __( 'Toggle Sorting Tags', 'avia_framework' ),
  633.                             'desc'  => __( 'Enter any number of comma separated tags here. If sorting is active the user can filter the visible toggles with the help of these tags', 'avia_framework' ),
  634.                             'id'    => 'tags',
  635.                             'type'  => 'input',
  636.                             'std'   => '',
  637.                             'lockable'  => true,
  638.                         ),
  639.  
  640.                 );
  641.  
  642.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'modal_content_toggle' ), $c );
  643.  
  644.             $setting_id = Avia_Builder()->get_developer_settings( 'custom_id' );
  645.             $class = in_array( $setting_id, array( 'deactivate', 'hide' ) ) ? 'avia-hidden' : '';
  646.  
  647.             $c = array(
  648.                         array(
  649.                             'name'  => __( 'For Developers: Custom Tab ID','avia_framework' ),
  650.                             'desc'  => __( 'Insert a custom ID for the element here. Make sure to only use allowed characters (latin characters, underscores, dashes and numbers, no special characters can be used)','avia_framework' ),
  651.                             'id'    => 'custom_id',
  652.                             'type'  => 'input',
  653.                             'std'   => '',
  654.                             'container_class'   => $class,
  655.                         )
  656.                 );
  657.  
  658.             $template = array(
  659.                             array(
  660.                                 'type'          => 'template',
  661.                                 'template_id'   => 'toggle',
  662.                                 'title'         => __( 'Developer Settings', 'avia_framework' ),
  663.                                 'content'       => $c
  664.                             ),
  665.                     );
  666.  
  667.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'modal_advanced_developer' ), $template );
  668.  
  669.         }
  670.  
  671.  
  672.         /**
  673.          * 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
  674.          * Works in the same way as Editor Element
  675.          * @param array $params this array holds the default values for $content and $args.
  676.          * @return $params the return array usually holds an innerHtml key that holds item specific markup.
  677.          */
  678.         function editor_sub_element( $params )
  679.         {
  680.             $default = array();
  681.             $locked = array();
  682.             $attr = $params['args'];
  683.             Avia_Element_Templates()->set_locked_attributes( $attr, $this, $this->config['shortcode_nested'][0], $default, $locked );
  684.  
  685.             $template = $this->update_option_lockable( 'title', $locked );
  686.  
  687.             $params['innerHtml']  = '';
  688.             $params['innerHtml'] .= "<div class='avia_title_container' {$template} data-update_element_template='yes'>{$attr['title']}</div>";
  689.  
  690.             return $params;
  691.         }
  692.  
  693.         /**
  694.          * Create custom stylings
  695.          *
  696.          * @since 4.8.4
  697.          * @param array $args
  698.          * @return array
  699.          */
  700.         protected function get_element_styles( array $args )
  701.         {
  702.             $result = parent::get_element_styles( $args );
  703.  
  704.             extract( $result );
  705.  
  706.             $default = array(
  707.                         'initial'           => '0',
  708.                         'mode'              => 'accordion',
  709.                         'sort'              => '',
  710.                         'faq_markup'        => '',
  711.                         'styling'           => '',
  712.                         'colors'            => '',
  713.                         'border_color'      => '',
  714.                         'font_color'        => '',
  715.                         'background_color'  => '',
  716.                         'colors_current'    => '',
  717.                         'font_color_current'        => '',
  718.                         'background_current'        => '',
  719.                         'background_color_current'  => '',
  720.                         'background_gradient_current_color1'    => '',
  721.                         'background_gradient_current_color2'    => '',
  722.                         'background_gradient_current_color3'    => '',
  723.                         'background_gradient_current_direction' => '',
  724.                         'hover_colors'              => '',
  725.                         'hover_background_color'    => '',
  726.                         'hover_font_color'          => ''
  727.                 );
  728.  
  729.             $default = $this->sync_sc_defaults_array( $default, 'no_modal_item', 'no_content' );
  730.  
  731.  
  732.             $locked = array();
  733.             Avia_Element_Templates()->set_locked_attributes( $atts, $this, $shortcodename, $default, $locked, $content );
  734.             Avia_Element_Templates()->add_template_class( $meta, $atts, $default );
  735.  
  736.             $this->screen_options = AviaHelper::av_mobile_sizes( $atts );   //return $av_font_classes, $av_title_font_classes and $av_display_classes
  737.  
  738.             $atts = shortcode_atts( $default, $atts, $this->config['shortcode'] );
  739.  
  740.  
  741.             if( ! is_numeric( $atts['initial'] ) || $atts['initial'] < 0 )
  742.             {
  743.                 $atts['initial'] = 0;
  744.             }
  745.             else
  746.             {
  747.                 $atts['initial'] = (int) $atts['initial'];
  748.                 $nr_toggles = substr_count( $content, '[av_toggle ' );
  749.  
  750.                 if( $atts['initial'] > $nr_toggles )
  751.                 {
  752.                     $atts['initial'] = $nr_toggles;
  753.                 }
  754.             }
  755.  
  756.             $element_styling->create_callback_styles( $atts );
  757.  
  758.             $classes = array(
  759.                         'togglecontainer',
  760.                         $element_id,
  761.                         $atts['styling']
  762.                     );
  763.  
  764.             $element_styling->add_classes( 'container', $classes );
  765.  
  766.             $element_styling->add_classes_from_array( 'container', $meta, 'el_class' );
  767.  
  768.             if( $atts['mode'] == 'accordion' )
  769.             {
  770.                 $element_styling->add_classes( 'container', 'toggle_close_all' );
  771.             }
  772.            
  773.             $cols = array(
  774.                         'color'             => $atts['font_color'],
  775.                         'background-color'  => $atts['background_color'],
  776.                         'border-color'      => $atts['border_color']
  777.                     );
  778.  
  779.             if( 'custom' == $atts['colors'] )
  780.             {
  781.                 /**
  782.                  * Styling: when font color is set, then icon gets font color, else border color
  783.                  */
  784.                 $element_styling->add_styles( 'toggle', $cols );
  785.                 $element_styling->add_styles( 'toggle-content', $cols );
  786.                    
  787.                 if( ! empty( $atts['font_color'] ) )
  788.                 {
  789.                     $element_styling->add_styles( 'toggle-icon', array(
  790.                                                             'color'         => $atts['font_color'],
  791.                                                             'border-color'  => $atts['font_color']
  792.                                                         ) );
  793.  
  794.                     $element_styling->add_classes( 'item_titleClass', 'hasCustomColor' );
  795.                    
  796.                 }
  797.                 else
  798.                 {
  799.                     $element_styling->add_styles( 'toggle-icon', array(
  800.                                                             'color'         => $atts['border_color'],
  801.                                                             'border-color'  => $atts['border_color']
  802.                                                         ) );
  803.                    
  804.                     $element_styling->add_classes( 'item_inherit', 'av-inherit-font-color' );
  805.                 }
  806.  
  807.                 if( ! empty( $atts['border_color'] ) )
  808.                 {
  809.                     $element_styling->add_classes( 'item_inherit', 'av-inherit-border-color' );
  810.                 }
  811.             }
  812.  
  813.             if( 'custom' == $atts['colors_current'] )
  814.             {
  815.                 if( ! empty( $atts['font_color_current'] ) )
  816.                 {
  817.                     $element_styling->add_styles( 'toggle-current', array(
  818.                                                                     'color'         => $atts['font_color_current'],
  819.                                                                     'border-color'  => $atts['font_color_current']
  820.                                                                 ) );
  821.                 }
  822.  
  823.                 if( 'bg_color' == $atts['background_current'] )
  824.                 {
  825.                     $element_styling->add_styles( 'toggle-current', array( 'background-color' => $atts['background_color_current'] ) );
  826.                 }
  827.                 else if( 'bg_gradient' == $atts['background_current'] )
  828.                 {
  829.                     $element_styling->add_callback_styles( 'toggle-current', array( 'background_gradient_current_direction' ) );
  830.                 }
  831.             }
  832.  
  833.             //  override dynamic stylesheet setting
  834.             $element_styling->add_styles( 'toggle-hover', $cols );
  835.            
  836.             if( 'custom' == $atts['hover_colors'] )
  837.             {
  838.                 $element_styling->add_styles( 'toggle-hover-not', array(
  839.                                                                     'color'             => $atts['hover_font_color'],
  840.                                                                     'background-color'  => $atts['hover_background_color']
  841.                                                                 ) );
  842.             }
  843.  
  844.             $selectors = array(
  845.                         'container'         => ".togglecontainer.{$element_id}",
  846.                         'toggle'            => ".togglecontainer.{$element_id} h2.toggler",
  847.                         'toggle-current'    => ".togglecontainer.{$element_id} h2.toggler.activeTitle",
  848.                         'toggle-hover'      => ".togglecontainer.{$element_id} h2.toggler:hover",
  849.                         'toggle-hover-not'  => ".togglecontainer.{$element_id} h2.toggler:not(.activeTitle):hover",
  850.                         'toggle-icon'       => "#top .togglecontainer.{$element_id} h2.toggler .toggle_icon",
  851.                         'toggle-content'    => ".togglecontainer.{$element_id} .toggle_wrap .toggle_content",
  852.                     );
  853.  
  854.             $element_styling->add_selectors( $selectors );
  855.  
  856.             $result['default'] = $default;
  857.             $result['atts'] = $atts;
  858.             $result['content'] = $content;
  859.             $result['element_styling'] = $element_styling;
  860.  
  861.             avia_sc_toggle::$parent_atts = $atts;
  862.             avia_sc_toggle::$initial = $atts['initial'];
  863.             avia_sc_toggle::$tags = array();
  864.  
  865.             $this->el_styling = $element_styling;
  866.  
  867.             return $result;
  868.         }
  869.  
  870.         /**
  871.          * Create custom stylings for items
  872.          *
  873.          * @since 4.8.4
  874.          * @param array $args
  875.          * @return array
  876.          */
  877.         protected function get_element_styles_item( array $args )
  878.         {
  879.             $result = parent::get_element_styles_item( $args );
  880.  
  881.             /**
  882.              * Fixes a problem when 3-rd party plugins call nested shortcodes without executing main shortcode  (like YOAST in wpseo-filter-shortcodes)
  883.              */
  884.             if( empty( $this->screen_options ) )
  885.             {
  886.                 return $result;
  887.             }
  888.  
  889.             extract( $result );
  890.  
  891.             $default = array(
  892.                         'title'         => '',
  893.                         'tags'          => '',
  894.                         'custom_id'     => '',
  895.                         'custom_markup' => ''
  896.                 );
  897.  
  898.             $default = $this->sync_sc_defaults_array( $default, 'modal_item', 'no_content' );
  899.  
  900.  
  901.             $locked = array();
  902.             Avia_Element_Templates()->set_locked_attributes( $atts, $this, $shortcodename, $default, $locked, $content );
  903.  
  904.             $atts = shortcode_atts( $default, $atts, $this->config['shortcode_nested'][0] );
  905.  
  906.             extract( $this->screen_options ); //return $av_font_classes, $av_title_font_classes and $av_display_classes
  907.  
  908.  
  909.             $classes = array(
  910.                         'av_toggle_section',
  911.                         $element_id
  912.                     );
  913.  
  914.             $element_styling->add_classes( 'container', $classes );
  915.  
  916.  
  917.  
  918.             $selectors = array(
  919.                         'container' => ".togglecontainer .av_toggle_section.{$element_id}",
  920.                         'toggler'   => ".togglecontainer .av_toggle_section.{$element_id} .toggler"
  921.                     );
  922.  
  923.             $element_styling->add_selectors( $selectors );
  924.  
  925.             $result['default'] = $default;
  926.             $result['atts'] = $atts;
  927.             $result['content'] = $content;
  928.             $result['element_styling'] = $element_styling;
  929.  
  930.             return $result;
  931.         }
  932.  
  933.         /**
  934.          * Frontend Shortcode Handler
  935.          *
  936.          * @param array $atts array of attributes
  937.          * @param string $content text within enclosing form of shortcode element
  938.          * @param string $shortcodename the shortcode found, when == callback name
  939.          * @return string $output returns the modified html string
  940.          */
  941.         function shortcode_handler( $atts, $content = '', $shortcodename = '', $meta = '' )
  942.         {
  943.             $result = $this->get_element_styles( compact( array( 'atts', 'content', 'shortcodename', 'meta' ) ) );
  944.  
  945.             extract( $result );
  946.             extract( $this->screen_options ); //return $av_font_classes, $av_title_font_classes and $av_display_classes
  947.             extract( $atts );
  948.  
  949.             $this->subitem_inline_styles = '';
  950.  
  951.  
  952.             $markup_faq = '';
  953.             if( ! empty( $atts['faq_markup'] ) )
  954.             {
  955.                 $markup_faq = avia_markup_helper( array( 'context' => 'faq_section', 'echo' => false ) );
  956.             }
  957.  
  958.             avia_sc_toggle::$counter = 1;
  959.  
  960.             $content = ShortcodeHelper::avia_remove_autop( $content, true );
  961.  
  962.             $style_tag = $element_styling->get_style_tag( $element_id );
  963.             $item_tag = $element_styling->style_tag_html( $this->subitem_inline_styles, 'sub-' . $element_id );
  964.             $container_class = $element_styling->get_class_string( 'container' );
  965.  
  966.             $output  = '';
  967.             $output .= $style_tag;
  968.             $output .= $item_tag;
  969.             $output .= "<div {$meta['custom_el_id']} class='{$container_class} {$av_display_classes}' {$markup_faq}>";
  970.             $output .=      ! empty( $sort ) ? $this->sort_list( $atts ) : '';
  971.             $output .=      $content;
  972.             $output .= '</div>';
  973.  
  974.             return $output;
  975.         }
  976.  
  977.  
  978.         /**
  979.          * Shortcode handler
  980.          *
  981.          * @param array $atts
  982.          * @param string $content
  983.          * @param string $shortcodename
  984.          * @return string
  985.          */
  986.         public function av_toggle( $atts, $content = '', $shortcodename = '' )
  987.         {
  988.             /**
  989.              * Fixes a problem when 3-rd party plugins call nested shortcodes without executing main shortcode  (like YOAST in wpseo-filter-shortcodes)
  990.              */
  991.             if( empty( $this->screen_options ) )
  992.             {
  993.                 return '';
  994.             }
  995.  
  996.             $result = $this->get_element_styles_item( compact( array( 'atts', 'content', 'shortcodename' ) ) );
  997.  
  998.             extract( $result );
  999.  
  1000.             extract( $this->screen_options ); //return $av_font_classes, $av_title_font_classes and $av_display_classes
  1001.  
  1002.             $toggle_atts = $atts;
  1003.  
  1004.  
  1005.             /**
  1006.              * We keep class settings in shortcode handler for better readability
  1007.              */
  1008.  
  1009.             $toggle_init_open_style = '';
  1010.  
  1011.             if( is_numeric( avia_sc_toggle::$initial ) && avia_sc_toggle::$counter == avia_sc_toggle::$initial )
  1012.             {
  1013.                 $element_styling->add_classes( 'titleClass', 'activeTitle' );
  1014.                 $element_styling->add_classes( 'contentClass', 'active_tc' );
  1015.  
  1016.                 //  must be set inline to avoid jumping to wrong tab in frontend
  1017.                 $toggle_init_open_style = "style='display:block;'";
  1018.             }
  1019.  
  1020.             if( empty( $toggle_atts['title'] ) )
  1021.             {
  1022.                 $toggle_atts['title'] = avia_sc_toggle::$counter;
  1023.             }
  1024.  
  1025.             $setting_id = Avia_Builder()->get_developer_settings( 'custom_id' );
  1026.             if( empty( $toggle_atts['custom_id'] ) || in_array( $setting_id, array( 'deactivate' ) ) )
  1027.             {
  1028.                 $toggle_atts['custom_id'] = 'toggle-id-' . avia_sc_toggle::$toggle_id++;
  1029.             }
  1030.             else
  1031.             {
  1032.                 $toggle_atts['custom_id'] = AviaHelper::save_string( $toggle_atts['custom_id'], '-' );
  1033.             }
  1034.  
  1035.  
  1036.             if( '' == avia_sc_toggle::$parent_atts['faq_markup'] )
  1037.             {
  1038.                 $markup_tab = avia_markup_helper( array( 'context' => 'entry', 'echo' => false, 'custom_markup' => $toggle_atts['custom_markup'] ) );
  1039.                 $markup_title = avia_markup_helper( array( 'context' => 'entry_title', 'echo' => false, 'custom_markup' => $toggle_atts['custom_markup'] ) );
  1040.                 $markup_answer = '';
  1041.                 $markup_text = avia_markup_helper( array( 'context' => 'entry_content', 'echo' => false, 'custom_markup' => $toggle_atts['custom_markup'] ) );
  1042.             }
  1043.             else
  1044.             {
  1045.                 $markup_tab = avia_markup_helper( array( 'context' => 'faq_question_container', 'echo' => false, 'custom_markup' => $toggle_atts['custom_markup'] ) );
  1046.                 $markup_title = avia_markup_helper( array( 'context' => 'faq_question_title', 'echo' => false, 'custom_markup' => $toggle_atts['custom_markup'] ) );
  1047.                 $markup_answer = avia_markup_helper( array( 'context' => 'faq_question_answer', 'echo' => false, 'custom_markup' => $toggle_atts['custom_markup'] ) );
  1048.                 $markup_text = avia_markup_helper( array( 'context' => 'entry_content', 'echo' => false, 'custom_markup' => $toggle_atts['custom_markup'] ) );
  1049.             }
  1050.  
  1051.  
  1052.  
  1053.             $this->subitem_inline_styles .= $element_styling->get_style_tag( $element_id, 'rules_only' );
  1054.  
  1055.             $item_titleClass = $this->el_styling->get_class_string( 'item_titleClass' );
  1056.             $item_contentClass = $this->el_styling->get_class_string( 'item_contentClass' );
  1057.             $item_inherit = $this->el_styling->get_class_string( 'item_inherit' );
  1058.  
  1059.             $section_class = $element_styling->get_class_string( 'container' );
  1060.             $titleClass = $element_styling->get_class_string( 'titleClass' );
  1061.             $contentClass = $element_styling->get_class_string( 'contentClass' );
  1062.  
  1063.             $output  = '';
  1064.             $output .= "<section class='{$section_class}' {$markup_tab}>";
  1065.             $output .=      '<div role="tablist" class="single_toggle" ' . $this->create_tag_string( $toggle_atts['tags'], $toggle_atts ) . '  >';
  1066.             $output .=          "<h2 data-fake-id='#{$toggle_atts['custom_id']}' class='toggler {$item_titleClass} {$titleClass} {$item_inherit}' {$markup_title} role='tab' tabindex='0' aria-controls='{$toggle_atts['custom_id']}'>";
  1067.             $output .=              $toggle_atts['title'];
  1068.             $output .=              '<span class="toggle_icon">';
  1069.             $output .=                  '<span class="vert_icon"></span>';
  1070.             $output .=                  '<span class="hor_icon"></span>';
  1071.             $output .=              '</span>';
  1072.             $output .=          '</h2>';
  1073.             $output .=          "<div id='{$toggle_atts['custom_id']}' class='toggle_wrap {$item_contentClass} {$contentClass}' {$toggle_init_open_style} {$markup_answer}>";
  1074.             $output .=              "<div class='toggle_content invers-color {$item_inherit}' {$markup_text}>";
  1075.             $output .=                  ShortcodeHelper::avia_apply_autop( ShortcodeHelper::avia_remove_autop( $content ) );
  1076.             $output .=              '</div>';
  1077.             $output .=          '</div>';
  1078.             $output .=      '</div>';
  1079.             $output .= '</section>';
  1080.  
  1081.             avia_sc_toggle::$counter ++;
  1082.  
  1083.             return $output;
  1084.         }
  1085.  
  1086.         /**
  1087.          * Returns the data string for the tags
  1088.          *
  1089.          * @param string $tags
  1090.          * @param array $toggle_atts
  1091.          * @return string
  1092.          */
  1093.         protected function create_tag_string( $tags, $toggle_atts )
  1094.         {
  1095.             $first_item_text = apply_filters( 'avf_toggle_sort_first_label', __( 'All', 'avia_framework' ), $toggle_atts );
  1096.  
  1097.             $tag_string = '{' . $first_item_text . '} ';
  1098.             if( trim( $tags ) != '' )
  1099.             {
  1100.                 $tags = explode( ',', $tags );
  1101.  
  1102.                 foreach( $tags as $tag )
  1103.                 {
  1104.                     $tag = esc_html( trim( $tag ) );
  1105.                     if( ! empty( $tag ) )
  1106.                     {
  1107.                         $tag_string .= '{' . $tag . '} ';
  1108.                         avia_sc_toggle::$tags[ $tag ] = true;
  1109.                     }
  1110.                 }
  1111.             }
  1112.  
  1113.             $tag_string = 'data-tags="' . $tag_string . '"';
  1114.  
  1115.             return $tag_string;
  1116.         }
  1117.  
  1118.         /**
  1119.          * Returns the HTML for the sort tags
  1120.          *
  1121.          * @param array $toggle_atts
  1122.          * @return string
  1123.          */
  1124.         protected function sort_list( $toggle_atts )
  1125.         {
  1126.             $output = '';
  1127.             $first = 'activeFilter';
  1128.  
  1129.             if( ! empty( avia_sc_toggle::$tags ) )
  1130.             {
  1131.                 ksort( avia_sc_toggle::$tags );
  1132.  
  1133.                 $first_item_text = apply_filters( 'avf_toggle_sort_first_label', __( 'All', 'avia_framework' ), $toggle_atts );
  1134.                 $start = array( $first_item_text => true );
  1135.                 avia_sc_toggle::$tags = $start + avia_sc_toggle::$tags;
  1136.  
  1137.                 $sep = apply_filters( 'avf_toggle_sort_seperator', '/', $toggle_atts );
  1138.  
  1139.                 foreach( avia_sc_toggle::$tags as $key => $value )
  1140.                 {
  1141.                     $output .= '<a href="#" data-tag="{' . $key . '}" class="' . $first . '">' . $key . '</a>';
  1142.                     $output .= "<span class='tag-seperator'>{$sep}</span>";
  1143.                     $first = '';
  1144.                 }
  1145.             }
  1146.  
  1147.             if( ! empty( $output ) )
  1148.             {
  1149.                 $output = "<div class='taglist'>{$output}</div>";
  1150.             }
  1151.  
  1152.             return $output;
  1153.         }
  1154.  
  1155.     }
  1156. }
  1157.  
Add Comment
Please, Sign In to add comment