Guenni007

toggles

Dec 13th, 2020
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 31.58 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Accordion and toggles
  4.  * Guenni007 :  toggle titles are h3 instead of p tags
  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 $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.  
  82.             $this->config['name']           = __( 'Accordion', 'avia_framework' );
  83.             $this->config['tab']            = __( 'Content Elements', 'avia_framework' );
  84.             $this->config['icon']           = AviaBuilder::$path['imagesURL'] . 'sc-accordion.png';
  85.             $this->config['order']          = 70;
  86.             $this->config['target']         = 'avia-target-insert';
  87.             $this->config['shortcode']      = 'av_toggle_container';
  88.             $this->config['shortcode_nested'] = array( 'av_toggle' );
  89.             $this->config['tooltip']        = __( 'Creates toggles or accordions (can be used for FAQ)', 'avia_framework' );
  90.             $this->config['disabling_allowed'] = true;
  91.             $this->config['id_name']        = 'id';
  92.             $this->config['id_show']        = 'yes';
  93.             $this->config['alb_desc_id']    = 'alb_description';
  94.         }
  95.  
  96.         function admin_assets()
  97.         {
  98.             $ver = AviaBuilder::VERSION;
  99.            
  100.             wp_register_script('avia_tab_toggle_js', AviaBuilder::$path['assetsURL'] . 'js/avia-tab-toggle.js', array( 'avia_modal_js' ), $ver, true );
  101.             Avia_Builder()->add_registered_admin_script( 'avia_tab_toggle_js' );
  102.         }
  103.            
  104.         function extra_assets()
  105.         {
  106.             //load css
  107.             wp_enqueue_style( 'avia-module-toggles', AviaBuilder::$path['pluginUrlRoot'] . 'avia-shortcodes/toggles/toggles.css', array( 'avia-layout' ), false );
  108.  
  109.                 //load js
  110.             wp_enqueue_script( 'avia-module-toggles', AviaBuilder::$path['pluginUrlRoot'] . 'avia-shortcodes/toggles/toggles.js', array( 'avia-shortcodes' ), false, true );
  111.  
  112.         }
  113.        
  114.  
  115.         /**
  116.          * Popup Elements
  117.          *
  118.          * If this function is defined in a child class the element automatically gets an edit button, that, when pressed
  119.          * opens a modal window that allows to edit the element properties
  120.          *
  121.          * @return void
  122.          */
  123.         function popup_elements()
  124.         {
  125.             $this->elements = array(
  126.                
  127.                 array(
  128.                         'type'  => 'tab_container',
  129.                         'nodescription' => true
  130.                     ),
  131.                        
  132.                 array(
  133.                         'type'  => 'tab',
  134.                         'name'  => __( 'Content', 'avia_framework' ),
  135.                         'nodescription' => true
  136.                     ),
  137.                
  138.                     array(
  139.                             'type'          => 'template',
  140.                             'template_id'   => 'toggle_container',
  141.                             'templates_include' => array(
  142.                                                     $this->popup_key( 'content_togles' ),
  143.                                                     $this->popup_key( 'content_behaviour' )
  144.                                                 ),
  145.                             'nodescription' => true
  146.                         ),
  147.                
  148.                 array(
  149.                         'type'  => 'tab_close',
  150.                         'nodescription' => true
  151.                     ),
  152.  
  153.                 array(
  154.                         'type'  => 'tab',
  155.                         'name'  => __( 'Styling', 'avia_framework' ),
  156.                         'nodescription' => true
  157.                     ),
  158.                
  159.                     array(
  160.                             'type'          => 'template',
  161.                             'template_id'   => 'toggle_container',
  162.                             'templates_include' => array(
  163.                                                     $this->popup_key( 'styling_toggles' ),
  164.                                                     $this->popup_key( 'styling_colors' )
  165.                                                 ),
  166.                             'nodescription' => true
  167.                         ),
  168.                
  169.                 array(
  170.                         'type'  => 'tab_close',
  171.                         'nodescription' => true
  172.                     ),
  173.                
  174.                 array(
  175.                         'type'  => 'tab',
  176.                         'name'  => __( 'Advanced', 'avia_framework' ),
  177.                         'nodescription' => true
  178.                     ),
  179.                
  180.                     array(
  181.                             'type'  => 'toggle_container',
  182.                             'nodescription' => true
  183.                         ),
  184.                
  185.                         array( 
  186.                                 'type'          => 'template',
  187.                                 'template_id'   => 'screen_options_toggle'
  188.                             ),
  189.                
  190.                         array( 
  191.                                 'type'          => 'template',
  192.                                 'template_id'   => 'developer_options_toggle',
  193.                                 'args'          => array( 'sc' => $this )
  194.                             ),
  195.                
  196.                     array(
  197.                             'type'  => 'toggle_container_close',
  198.                             'nodescription' => true
  199.                         ),
  200.                
  201.                 array(
  202.                         'type'  => 'tab_close',
  203.                         'nodescription' => true
  204.                     ),
  205.  
  206.                 array(
  207.                         'type'  => 'tab_container_close',
  208.                         'nodescription' => true
  209.                     )
  210.  
  211.                
  212.                 );
  213.            
  214.         }
  215.        
  216.         /**
  217.          * Create and register templates for easier maintainance
  218.          *
  219.          * @since 4.6.4
  220.          */
  221.         protected function register_dynamic_templates()
  222.         {
  223.            
  224.             $this->register_modal_group_templates();
  225.            
  226.             /**
  227.              * Content Tab
  228.              * ===========
  229.              */
  230.            
  231.             $c = array(
  232.                         array(
  233.                             'name'  => __( 'Add/Edit Toggles', 'avia_framework' ),
  234.                             'desc'  => __( 'Here you can add, remove and edit the toggles you want to display.', 'avia_framework' ),
  235.                             'type'  => 'modal_group',
  236.                             'id'    => 'content',
  237.                             'modal_title'   => __('Edit Form Element', 'avia_framework' ),
  238.                             'std'   => array(
  239.                                             array( 'title' => __( 'Toggle 1', 'avia_framework' ), 'tags' => '' ),
  240.                                             array( 'title' => __( 'Toggle 2', 'avia_framework' ), 'tags' => '' ),
  241.                                         ),
  242.                             'subelements'   => $this->create_modal()
  243.                         ),
  244.                
  245.                         array(
  246.                             'name'  => __( 'Use as FAQ Page (SEO improvement)', 'avia_framework' ),
  247.                             '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' ),
  248.                             'id'    => 'faq_markup',
  249.                             'type'  => 'select',
  250.                             'std'   => '',
  251.                             'subtype'   => array(
  252.                                                 __( 'No markup needed', 'avia_framework' )  => '',
  253.                                                 __( 'Add FAQ markup', 'avia_framework' )    => 'faq_markup'
  254.                                             )
  255.                         )
  256.                
  257.                 );
  258.            
  259.             $template = array(
  260.                             array( 
  261.                                 'type'          => 'template',
  262.                                 'template_id'   => 'toggle',
  263.                                 'title'         => __( 'Toggles', 'avia_framework' ),
  264.                                 'content'       => $c
  265.                             ),
  266.                     );
  267.            
  268.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'content_togles' ), $template );
  269.            
  270.            
  271.             $c = array(
  272.                         array(
  273.                             'name'  => __( 'Initial Open', 'avia_framework' ),
  274.                             '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' ),
  275.                             'id'    => 'initial',
  276.                             'std'   => '0',
  277.                             'type'  => 'input'
  278.                         ),
  279.  
  280.                         array(
  281.                             'name'  => __( 'Behavior', 'avia_framework' ),
  282.                             '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' ),
  283.                             'id'    => 'mode',
  284.                             'type'  => 'select',
  285.                             'std'   => 'accordion',
  286.                             'subtype'   => array(
  287.                                                 __( 'Only one toggle open at a time (Accordion Mode)', 'avia_framework' )   => 'accordion',
  288.                                                 __( 'Multiple toggles open allowed (Toggle Mode)', 'avia_framework' )       => 'toggle'
  289.                                             )
  290.                         ),
  291.  
  292.                         array(
  293.                             'name'  => __( 'Sorting', 'avia_framework' ),
  294.                             'desc'  => __( 'Display the toggle sorting menu? (You also need to add a number of tags to each toggle to make sorting possible)', 'avia_framework' ),
  295.                             'id'    => 'sort',
  296.                             'type'  => 'select',
  297.                             'std'   => '',
  298.                             'subtype'   => array(
  299.                                                 __( 'No Sorting', 'avia_framework' )        => '',
  300.                                                 __( 'Sorting Active', 'avia_framework' )    => 'true'
  301.                                             )
  302.                         )
  303.                
  304.                 );
  305.            
  306.             $template = array(
  307.                             array( 
  308.                                 'type'          => 'template',
  309.                                 'template_id'   => 'toggle',
  310.                                 'title'         => __( 'Behaviour', 'avia_framework' ),
  311.                                 'content'       => $c
  312.                             ),
  313.                     );
  314.            
  315.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'content_behaviour' ), $template );
  316.            
  317.             /**
  318.              * Styling Tab
  319.              * ===========
  320.              */
  321.            
  322.             $c = array(
  323.                         array(
  324.                             'name'  => __( 'Styling', 'avia_framework' ),
  325.                             'desc'  => __( 'Select the styling of the toggles', 'avia_framework' ),
  326.                             'id'    => 'styling',
  327.                             'type'  => 'select',
  328.                             'std'   => '',
  329.                             'subtype'   => array(
  330.                                                 __( 'Default', 'avia_framework' )   => '',
  331.                                                 __( 'Minimal', 'avia_framework' )   => 'av-minimal-toggle',
  332.                                                 __( 'Elegant', 'avia_framework' )   => 'av-elegant-toggle'
  333.                                             )
  334.                         ),
  335.                
  336.                    
  337.                 );
  338.            
  339.             $template = array(
  340.                             array( 
  341.                                 'type'          => 'template',
  342.                                 'template_id'   => 'toggle',
  343.                                 'title'         => __( 'Toggles Styling', 'avia_framework' ),
  344.                                 'content'       => $c
  345.                             ),
  346.                     );
  347.            
  348.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_toggles' ), $template );
  349.            
  350.             $c = array(
  351.                         array(
  352.                             'name'  => __( 'Colors', 'avia_framework' ),
  353.                             'desc'  => __( 'Either use the themes default colors or apply some custom ones', 'avia_framework' ),
  354.                             'id'    => 'colors',
  355.                             'type'  => 'select',
  356.                             'std'   => '',
  357.                             'subtype'   => array(
  358.                                                 __( 'Default', 'avia_framework' )               => '',
  359.                                                 __( 'Define Custom Colors', 'avia_framework' )  => 'custom'
  360.                                             ),
  361.                         ),
  362.            
  363.                         array( 
  364.                             'name'  => __( 'Custom Font Color', 'avia_framework' ),
  365.                             'desc'  => __( 'Select a custom font color. Leave empty to use the default', 'avia_framework' ),
  366.                             'id'    => 'font_color',
  367.                             'type'  => 'colorpicker',
  368.                             'std'   => '',
  369.                             'rgba'  => true,
  370.                             'required'  => array( 'colors', 'equals', 'custom' ),
  371.                             'container_class'   => 'av_third av_third_first'
  372.                         ), 
  373.                    
  374.                         array( 
  375.                             'name'  => __( 'Custom Background Color', 'avia_framework' ),
  376.                             'desc'  => __( 'Select a custom background color. Leave empty to use the default', 'avia_framework' ),
  377.                             'id'    => 'background_color',
  378.                             'type'  => 'colorpicker',
  379.                             'std'   => '',
  380.                             'rgba'  => true,
  381.                             'required'  => array( 'colors', 'equals', 'custom' ),
  382.                             'container_class'   => 'av_third', 
  383.                         ),
  384.  
  385.                         array(
  386.                             'name'  => __( 'Custom Border Color', 'avia_framework' ),
  387.                             'desc'  => __( 'Select a custom border color. Leave empty to use the default', 'avia_framework' ),
  388.                             'id'    => 'border_color',
  389.                             'type'  => 'colorpicker',
  390.                             'std'   => '',
  391.                             'rgba'  => true,
  392.                             'required'  => array( 'colors', 'equals', 'custom' ),
  393.                             'container_class'   => 'av_third',
  394.                         ),
  395.                        
  396.                         array(
  397.                             'name'  => __( 'Current Toggle Appearance', 'avia_framework' ),
  398.                             'desc'  => __( 'Highlight title bar of open toggles', 'avia_framework' ),
  399.                             'id'    => 'colors_current',
  400.                             'type'  => 'select',
  401.                             'std'   => '',
  402.                             'subtype'   => array(
  403.                                                 __( 'Default', 'avia_framework' )               => '',
  404.                                                 __( 'Define Custom Colors', 'avia_framework' )  => 'custom'
  405.                                             ),
  406.                         ),
  407.  
  408.                         array(
  409.                             'name'  => __( 'Custom Font Color Current Toggle', 'avia_framework' ),
  410.                             'desc'  => __( 'Select a custom font color for the current active toggle. Leave empty to use the default', 'avia_framework' ),
  411.                             'id'    => 'font_color_current',
  412.                             'type'  => 'colorpicker',
  413.                             'std'   => '',
  414.                             'rgba'  => true,
  415.                             'required'  => array( 'colors_current', 'equals', 'custom' )
  416.                         ),
  417.  
  418.                         array(
  419.                             'name'  => __( 'Background Current Toggle', 'avia_framework' ),
  420.                             'desc'  => __( 'Select the type of background for the current active toggle title bar.', 'avia_framework' ),
  421.                             'id'    => 'background_current',
  422.                             'type'  => 'select',
  423.                             'std'   => '',
  424.                             'required'  => array( 'colors_current', 'equals', 'custom' ),
  425.                             'subtype'   => array(
  426.                                                 __( 'Default', 'avia_framework' )               => '',
  427.                                                 __( 'Background Color', 'avia_framework' )      => 'bg_color',
  428.                                                 __( 'Background Gradient', 'avia_framework' )   => 'bg_gradient',
  429.                                             )
  430.                         ),
  431.                
  432.                         array(
  433.                             'name'  => __( 'Title Bar Custom Background Color', 'avia_framework' ),
  434.                             'desc'  => __( 'Select a custom background color. Leave empty for default color', 'avia_framework' ),
  435.                             'id'    => 'background_color_current',
  436.                             'type'  => 'colorpicker',
  437.                             'rgba'  => true,
  438.                             'std'   => '',
  439.                             'required'  => array( 'background_current', 'equals', 'bg_color' ),
  440.                         ),
  441.  
  442.                         array(
  443.                             'name'  => __( 'Background Gradient Color 1', 'avia_framework' ),
  444.                             'desc'  => __( 'Select the first color for the gradient.', 'avia_framework' ),
  445.                             'id'    => 'background_gradient_current_color1',
  446.                             'type'  => 'colorpicker',
  447.                             'rgba'  => true,
  448.                             'std'   => '',
  449.                             'container_class' => 'av_third av_third_first',
  450.                             'required'  => array( 'background_current', 'equals', 'bg_gradient' ),
  451.                         ),
  452.                
  453.                         array(
  454.                             'name'  => __( 'Background Gradient Color 2', 'avia_framework' ),
  455.                             'desc'  => __( 'Select the second color for the gradient.', 'avia_framework' ),
  456.                             'id'    => 'background_gradient_current_color2',
  457.                             'type'  => 'colorpicker',
  458.                             'rgba'  => true,
  459.                             'std'   => '',
  460.                             'container_class' => 'av_third',
  461.                             'required'  => array( 'background_current', 'equals', 'bg_gradient' )
  462.                         ),
  463.  
  464.                         array(
  465.                             'name'  => __( 'Background Gradient Direction', 'avia_framework' ),
  466.                             'desc'  => __( 'Define the gradient direction', 'avia_framework' ),
  467.                             'id'    => 'background_gradient_current_direction',
  468.                             'type'  => 'select',
  469.                             'std'   => 'vertical',
  470.                             'container_class' => 'av_third',
  471.                             'required'  => array( 'background_current', 'equals', 'bg_gradient' ),
  472.                             'subtype'   => array(
  473.                                                 __( 'Vertical', 'avia_framework' )      => 'vertical',
  474.                                                 __( 'Horizontal', 'avia_framework' )    => 'horizontal',
  475.                                                 __( 'Radial', 'avia_framework' )        => 'radial',
  476.                                                 __( 'Diagonal Top Left to Bottom Right', 'avia_framework' ) => 'diagonal_tb',
  477.                                                 __( 'Diagonal Bottom Left to Top Right', 'avia_framework' ) => 'diagonal_bt',
  478.                                             )
  479.                         ),
  480.                
  481.                         array(
  482.                             'name'  => __( 'Hover Toggle Appearance', 'avia_framework' ),
  483.                             'desc'  => __( 'Appearance of toggles on mouse hover', 'avia_framework' ),
  484.                             'id'    => 'hover_colors',
  485.                             'type'  => 'select',
  486.                             'std'   => '',
  487.                             'subtype'   => array(
  488.                                                 __( 'Default', 'avia_framework' )               => '',
  489.                                                 __( 'Define Custom Colors', 'avia_framework' )  => 'custom'
  490.                                             ),
  491.                         ),
  492.  
  493.                         array(
  494.                             'name'  => __( 'Custom Hover Background Color', 'avia_framework' ),
  495.                             'desc'  => __( 'Select a custom hover background color. Leave empty to use the default', 'avia_framework' ),
  496.                             'id'    => 'hover_background_color',
  497.                             'type'  => 'colorpicker',
  498.                             'std'   => '',
  499.                             'rgba'  => true,
  500.                             'container_class' => 'av_third av_half_first',
  501.                             'required'  => array( 'hover_colors', 'equals', 'custom')
  502.                         ),
  503.  
  504.                         array(
  505.                             'name'  => __( 'Custom Hover Font Color', 'avia_framework' ),
  506.                             'desc'  => __( 'Select a custom hover font color. Leave empty to use the default', 'avia_framework' ),
  507.                             'id'    => 'hover_font_color',
  508.                             'type'  => 'colorpicker',
  509.                             'std'   => '',
  510.                             'rgba'  => true,
  511.                             'container_class' => 'av_third',
  512.                             'required'  => array( 'hover_colors', 'equals', 'custom' )
  513.                         ),
  514.                
  515.                 );
  516.            
  517.             $template = array(
  518.                             array( 
  519.                                 'type'          => 'template',
  520.                                 'template_id'   => 'toggle',
  521.                                 'title'         => __( 'Colors', 'avia_framework' ),
  522.                                 'content'       => $c
  523.                             ),
  524.                     );
  525.            
  526.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_colors' ), $template );
  527.            
  528.         }
  529.        
  530.         /**
  531.          * Creates the modal popup for a single entry
  532.          *
  533.          * @since 4.6.4
  534.          * @return array
  535.          */
  536.         protected function create_modal()
  537.         {
  538.             $elements = array(
  539.                
  540.                 array(
  541.                         'type'  => 'tab_container',
  542.                         'nodescription' => true
  543.                     ),
  544.                        
  545.                 array(
  546.                         'type'  => 'tab',
  547.                         'name'  => __( 'Content', 'avia_framework' ),
  548.                         'nodescription' => true
  549.                     ),
  550.                
  551.                     array( 
  552.                             'type'          => 'template',
  553.                             'template_id'   => $this->popup_key( 'modal_content_toggle' )
  554.                         ),
  555.                
  556.                 array(
  557.                         'type'  => 'tab_close',
  558.                         'nodescription' => true
  559.                     ),
  560.                
  561.                 array(
  562.                         'type'  => 'tab',
  563.                         'name'  => __( 'Advanced', 'avia_framework' ),
  564.                         'nodescription' => true
  565.                     ),
  566.                
  567.                     array(
  568.                             'type'          => 'template',
  569.                             'template_id'   => 'toggle_container',
  570.                             'templates_include' => array(
  571.                                                     $this->popup_key( 'modal_advanced_developer' )
  572.                                                 ),
  573.                             'nodescription' => true
  574.                         ),
  575.                
  576.                 array(
  577.                         'type'  => 'tab_close',
  578.                         'nodescription' => true
  579.                     ),
  580.                
  581.                 array(
  582.                         'type'  => 'tab_container_close',
  583.                         'nodescription' => true
  584.                     )
  585.                
  586.                
  587.                 );
  588.            
  589.             return $elements;
  590.         }
  591.        
  592.         /**
  593.          * Register all templates for the modal group popup
  594.          *
  595.          * @since 4.6.4
  596.          */
  597.         protected function register_modal_group_templates()
  598.         {
  599.             /**
  600.              * Content Tab
  601.              * ===========
  602.              */
  603.            
  604.             $c = array(
  605.                         array(
  606.                             'name'  => __( 'Toggle Title', 'avia_framework' ),
  607.                             'desc'  => __( 'Enter the toggle title here (Better keep it short)', 'avia_framework' ),
  608.                             'id'    => 'title',
  609.                             'std'   => 'Toggle Title',
  610.                             'type'  => 'input'
  611.                         ),
  612.  
  613.                         array(
  614.                             'name'  => __( 'Toggle Content', 'avia_framework' ),
  615.                             'desc'  => __( 'Enter some content here', 'avia_framework' ),
  616.                             'id'    => 'content',
  617.                             'type'  => 'tiny_mce',
  618.                             'std'   => __( 'Toggle Content goes here', 'avia_framework' ),
  619.                         ),
  620.  
  621.                         array(
  622.                             'name'  => __( 'Toggle Sorting Tags', 'avia_framework' ),
  623.                             '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' ),
  624.                             'id'    => 'tags',
  625.                             'std'   => '',
  626.                             'type'  => 'input'
  627.                         ),
  628.                        
  629.                 );
  630.            
  631.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'modal_content_toggle' ), $c );
  632.            
  633.             $setting_id = Avia_Builder()->get_developer_settings( 'custom_id' );
  634.             $class = in_array( $setting_id, array( 'deactivate', 'hide' ) ) ? 'avia-hidden' : '';
  635.  
  636.             $c = array(
  637.                         array(
  638.                             'name'  => __( 'For Developers: Custom Tab ID','avia_framework' ),
  639.                             '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' ),
  640.                             'id'    => 'custom_id',
  641.                             'type'  => 'input',
  642.                             'std'   => '',
  643.                             'container_class'   => $class,
  644.                         )
  645.                 );
  646.            
  647.             $template = array(
  648.                             array( 
  649.                                 'type'          => 'template',
  650.                                 'template_id'   => 'toggle',
  651.                                 'title'         => __( 'Developer Settings', 'avia_framework' ),
  652.                                 'content'       => $c
  653.                             ),
  654.                     );
  655.            
  656.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'modal_advanced_developer' ), $template );
  657.            
  658.         }
  659.        
  660.  
  661.         /**
  662.          * 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
  663.          * Works in the same way as Editor Element
  664.          * @param array $params this array holds the default values for $content and $args.
  665.          * @return $params the return array usually holds an innerHtml key that holds item specific markup.
  666.          */
  667.         function editor_sub_element( $params )
  668.         {
  669.             $template = $this->update_template( 'title', '{{title}}' );
  670.  
  671.             $params['innerHtml']  = '';
  672.             $params['innerHtml'] .= "<div class='avia_title_container' {$template}>{$params['args']['title']}</div>";
  673.  
  674.             return $params;
  675.         }
  676.  
  677.         /**
  678.          * Frontend Shortcode Handler
  679.          *
  680.          * @param array $atts array of attributes
  681.          * @param string $content text within enclosing form of shortcode element
  682.          * @param string $shortcodename the shortcode found, when == callback name
  683.          * @return string $output returns the modified html string
  684.          */
  685.         function shortcode_handler( $atts, $content = '', $shortcodename = '', $meta = '' )
  686.         {
  687.             $this->screen_options = AviaHelper::av_mobile_sizes( $atts );
  688.            
  689.             extract( $this->screen_options ); //return $av_font_classes, $av_title_font_classes and $av_display_classes
  690.  
  691.             $atts = shortcode_atts( array(
  692.                             'initial'           => '0',
  693.                             'mode'              => 'accordion',
  694.                             'sort'              => '',
  695.                             'faq_markup'        => '',
  696.                             'styling'           => '',
  697.                             'colors'            => '',
  698.                             'border_color'      => '',
  699.                             'font_color'        => '',
  700.                             'background_color'  => '',
  701.                             'colors_current'    => '',
  702.                             'font_color_current'        => '',
  703.                             'background_current'        => '',
  704.                             'background_color_current'  => '',
  705.                             'background_gradient_current_color1'    => '',
  706.                             'background_gradient_current_color2'    => '',
  707.                             'background_gradient_current_direction' => '',
  708.                             'hover_colors'              => '',
  709.                             'hover_background_color'    => '',
  710.                             'hover_font_color'          => ''
  711.  
  712.                         ), $atts, $this->config['shortcode'] );
  713.            
  714.            
  715.             extract( $atts );
  716.            
  717.            
  718.             if( ! is_numeric( $initial ) || $initial < 0 )
  719.             {
  720.                 $initial = 0;
  721.             }
  722.             else
  723.             {
  724.                 $initial = (int) $initial;
  725.                 $nr_toggles = substr_count( $content, '[av_toggle ' );
  726.                
  727.                 if( $initial > $nr_toggles )
  728.                 {
  729.                     $initial = $nr_toggles;
  730.                 }
  731.             }
  732.            
  733.  
  734.             $output = '';
  735.             $addClass = '';
  736.             if( $mode == 'accordion' )
  737.             {
  738.                 $addClass = 'toggle_close_all ';
  739.             }
  740.  
  741.             // custom title bar styling
  742.             $current_colors = '';
  743.  
  744.             if( $atts['colors_current'] == 'custom' )
  745.             {
  746.  
  747.                 if( $atts['font_color_current'] !== '' )
  748.                 {
  749.                     $current_colors .= AviaHelper::style_string( $atts, 'font_color_current', 'color' );
  750.                     $current_colors .= AviaHelper::style_string( $atts, 'font_color_current', 'border-color' );
  751.                     $addClass .= ' hasCurrentStyle';
  752.                 }
  753.  
  754.                 if( $atts['background_current'] == 'bg_color' )
  755.                 {
  756.                     $current_colors .= AviaHelper::style_string( $atts, 'background_color_current','background-color' );
  757.                 }
  758.                 else if( $atts['background_current'] == 'bg_gradient' )
  759.                 {
  760.                     $gradient_settings = array(
  761.                                                 $atts['background_gradient_current_direction'],
  762.                                                 $atts['background_gradient_current_color1'],
  763.                                                 $atts['background_gradient_current_color2']
  764.                                             );
  765.                    
  766.                     $atts['gradient_string'] = AviaHelper::css_background_string( array(), $gradient_settings );
  767.                     $atts['gradient_fallback'] = $atts['background_gradient_current_color1'];
  768.                     $current_colors .= AviaHelper::style_string( $atts, 'gradient_fallback', 'background-color' );
  769.                     $current_colors .= AviaHelper::style_string( $atts, 'gradient_string', 'background' );
  770.                 }
  771.  
  772.             }
  773.  
  774.             $current_colors_attr = '';
  775.             if( $current_colors )
  776.             {
  777.                 $current_colors_attr = "data-currentstyle='{$current_colors}'";
  778.             }
  779.  
  780.             $markup = '';
  781.             if( ! empty( $atts['faq_markup'] ) )
  782.             {
  783.                 $markup = avia_markup_helper( array( 'context' => 'faq_section', 'echo' => false ) );
  784.             }
  785.  
  786.             $output  = '<div ' . $markup . ' ' . $meta['custom_el_id'] . ' class="togglecontainer ' . $av_display_classes . ' ' . $styling . ' ' . $addClass . $meta['el_class'] . '" ' . $current_colors_attr . '>';
  787.  
  788.             avia_sc_toggle::$counter = 1;
  789.             avia_sc_toggle::$initial = $initial;
  790.             avia_sc_toggle::$tags = array();
  791.             avia_sc_toggle::$atts = $atts;
  792.  
  793.             $content  = ShortcodeHelper::avia_remove_autop( $content, true );
  794.             $sortlist = ! empty( $sort ) ? $this->sort_list( $atts ) : '';
  795.  
  796.             $output .= $sortlist . $content . '</div>';
  797.  
  798.             return $output;
  799.         }
  800.  
  801.  
  802.         /**
  803.          * Shortcode handler
  804.          *
  805.          * @param array $atts
  806.          * @param string $content
  807.          * @param string $shortcodename
  808.          * @return string
  809.          */
  810.         public function av_toggle( $atts, $content = '', $shortcodename = '' )
  811.         {
  812.             /**
  813.              * Fixes a problem when 3-rd party plugins call nested shortcodes without executing main shortcode  (like YOAST in wpseo-filter-shortcodes)
  814.              */
  815.             if( empty( $this->screen_options ) )
  816.             {
  817.                 return '';
  818.             }
  819.    
  820.             $toggle_atts = shortcode_atts( array(
  821.                                     'title'         => '',
  822.                                     'tags'          => '',
  823.                                     'custom_id'     => '',
  824.                                     'custom_markup' => ''
  825.                
  826.                             ), $atts, 'av_toggle' );
  827.            
  828.             $output = $titleClass = $contentClass = '';
  829.             $toggle_init_open_style = '';
  830.            
  831.             if( is_numeric( avia_sc_toggle::$initial ) && avia_sc_toggle::$counter == avia_sc_toggle::$initial )
  832.             {
  833.                 $titleClass = 'activeTitle';
  834.                 $contentClass = 'active_tc';
  835.                 $toggle_init_open_style = "style='display:block;'";
  836.             }
  837.  
  838.             if( empty( $toggle_atts['title'] ) )
  839.             {
  840.                 $toggle_atts['title'] = avia_sc_toggle::$counter;
  841.             }
  842.  
  843.             $setting_id = Avia_Builder()->get_developer_settings( 'custom_id' );
  844.             if( empty( $toggle_atts['custom_id'] ) || in_array( $setting_id, array( 'deactivate' ) ) )
  845.             {
  846.                 $toggle_atts['custom_id'] = 'toggle-id-' . avia_sc_toggle::$toggle_id++;
  847.             }
  848.             else
  849.             {
  850.                 $toggle_atts['custom_id'] = AviaHelper::save_string( $toggle_atts['custom_id'], '-' );
  851.             }
  852.            
  853.             //custom colors
  854.             $colors = $inherit = $icon_color = '';
  855.             if( ! empty( avia_sc_toggle::$atts['colors'] ) && avia_sc_toggle::$atts['colors'] == 'custom' )
  856.             {
  857.                 if( ! empty( avia_sc_toggle::$atts['background_color'] ) )
  858.                 {
  859.                     $colors = 'background-color: ' . avia_sc_toggle::$atts['background_color'] . '; ';
  860.                 }
  861.                
  862.                 if( ! empty(avia_sc_toggle::$atts['font_color'] ) )
  863.                 {
  864.                     $colors .= 'color: ' . avia_sc_toggle::$atts['font_color'] . '; ';
  865.                     $icon_color = "style='border-color:" . avia_sc_toggle::$atts['font_color'] . ";'";
  866.                     $inherit .= ' av-inherit-font-color ';
  867.                     $titleClass .= ' hasCustomColor';
  868.                 }
  869.                
  870.                 if( ! empty( avia_sc_toggle::$atts['border_color'] ) )
  871.                 {
  872.                     $colors .= 'border-color: ' . avia_sc_toggle::$atts['border_color'] . '; ';
  873.                     $inherit .= ' av-inherit-border-color ';
  874.                 }
  875.             }
  876.  
  877.             if( ! empty( $colors ) )
  878.             {
  879.                 $colors = "style='{$colors}'";
  880.             }
  881.  
  882.             // hover styling
  883.             $hover_styling = '';
  884.             if( ! empty( avia_sc_toggle::$atts['hover_colors'] ) && avia_sc_toggle::$atts['hover_colors'] == 'custom' )
  885.             {
  886.                 if( ! empty( avia_sc_toggle::$atts['hover_background_color'] ) )
  887.                 {
  888.                     $hover_styling .= 'background-color: ' . avia_sc_toggle::$atts['hover_background_color'] . '; ';
  889.                 }
  890.  
  891.                 if( ! empty( avia_sc_toggle::$atts['hover_font_color'] ) )
  892.                 {
  893.                     $hover_styling .= 'color: ' . avia_sc_toggle::$atts['hover_font_color'] . '; ';
  894.                 }
  895.             }
  896.  
  897.             $hover_styling_markup = ! empty( $hover_styling ) ? "data-hoverstyle='{$hover_styling}'" : '';
  898.  
  899.             $markup_answer = '';
  900.  
  901.             if( '' == avia_sc_toggle::$atts['faq_markup'] )
  902.             {
  903.                 $markup_tab = avia_markup_helper( array( 'context' => 'entry', 'echo' => false, 'custom_markup' => $toggle_atts['custom_markup'] ) );
  904.                 $markup_title = avia_markup_helper( array( 'context' => 'entry_title', 'echo' => false, 'custom_markup' => $toggle_atts['custom_markup'] ) );
  905.                 $markup_text = avia_markup_helper( array( 'context' => 'entry_content', 'echo' => false, 'custom_markup' => $toggle_atts['custom_markup'] ) );
  906.             }
  907.             else
  908.             {
  909.                 $markup_tab = avia_markup_helper( array( 'context' => 'faq_question_container', 'echo' => false, 'custom_markup' => $toggle_atts['custom_markup'] ) );
  910.                 $markup_title = avia_markup_helper( array( 'context' => 'faq_question_title', 'echo' => false, 'custom_markup' => $toggle_atts['custom_markup'] ) );
  911.                 $markup_answer = avia_markup_helper( array( 'context' => 'faq_question_answer', 'echo' => false, 'custom_markup' => $toggle_atts['custom_markup'] ) );
  912.                 $markup_text = avia_markup_helper( array( 'context' => 'entry_content', 'echo' => false, 'custom_markup' => $toggle_atts['custom_markup'] ) );
  913.             }
  914.            
  915.             $output .= '<section class="av_toggle_section" ' . $markup_tab . ' >';
  916.             $output .= '    <div role="tablist" class="single_toggle" ' . $this->create_tag_string( $toggle_atts['tags'], $toggle_atts ) . '  >';
  917.             $output .= '        <h3 data-fake-id="#' . $toggle_atts['custom_id'] . '" class="toggler ' . $titleClass . $inherit . '" ' . $markup_title . ' ' . $colors . ' ' . $hover_styling_markup . ' role="tab" tabindex="0" aria-controls="' . $toggle_atts['custom_id'] . '">' . $toggle_atts['title'] . '<span class="toggle_icon" ' . $icon_color . '>';
  918.             $output .= '        <span class="vert_icon"></span><span class="hor_icon"></span></span></h3>';
  919.             $output .= '        <div id="' . $toggle_atts['custom_id'] . '" class="toggle_wrap ' . $contentClass . '"  ' . $toggle_init_open_style . ' ' . $markup_answer . '>';
  920.             $output .= '            <div class="toggle_content invers-color ' . $inherit . '" ' . $markup_text . ' ' . $colors . ' >';
  921.             $output .=                  ShortcodeHelper::avia_apply_autop( ShortcodeHelper::avia_remove_autop( $content ) );
  922.             $output .= '            </div>';
  923.             $output .= '        </div>';
  924.             $output .= '    </div>';
  925.             $output .= '</section>';
  926.  
  927.             avia_sc_toggle::$counter ++;
  928.  
  929.             return $output;
  930.         }
  931.  
  932.         function create_tag_string( $tags, $toggle_atts )
  933.         {
  934.             $first_item_text = apply_filters( 'avf_toggle_sort_first_label', __( 'All', 'avia_framework' ), $toggle_atts );
  935.  
  936.             $tag_string = '{' . $first_item_text . '} ';
  937.             if( trim( $tags ) != '' )
  938.             {
  939.                 $tags = explode( ',', $tags );
  940.  
  941.                 foreach( $tags as $tag )
  942.                 {
  943.                     $tag = esc_html( trim( $tag ) );
  944.                     if( ! empty( $tag ) )
  945.                     {
  946.                         $tag_string .= '{' . $tag . '} ';
  947.                         avia_sc_toggle::$tags[ $tag ] = true;
  948.                     }
  949.                 }
  950.             }
  951.  
  952.             $tag_string = 'data-tags="' . $tag_string . '"';
  953.             return $tag_string;
  954.         }
  955.  
  956.  
  957.  
  958.         function sort_list( $toggle_atts )
  959.         {
  960.             $output = '';
  961.             $first = 'activeFilter';
  962.            
  963.             if( ! empty( avia_sc_toggle::$tags ) )
  964.             {
  965.                 ksort( avia_sc_toggle::$tags );
  966.                 $first_item_text = apply_filters( 'avf_toggle_sort_first_label', __( 'All', 'avia_framework' ), $toggle_atts );
  967.                 $start = array( $first_item_text => true );
  968.                 avia_sc_toggle::$tags = $start + avia_sc_toggle::$tags;
  969.                
  970.                 $sep = apply_filters( 'avf_toggle_sort_seperator', '/', $toggle_atts );
  971.                
  972.                 foreach( avia_sc_toggle::$tags as $key => $value )
  973.                 {
  974.                     $output .= '<a href="#" data-tag="{' . $key . '}" class="' . $first . '">' . $key . '</a>';
  975.                     $output .= "<span class='tag-seperator'>{$sep}</span>";
  976.                     $first = '';
  977.                 }
  978.             }
  979.  
  980.             if( ! empty( $output ) )
  981.             {
  982.                 $output = "<div class='taglist'>{$output}</div>";
  983.             }
  984.            
  985.             return $output;
  986.         }
  987.  
  988.     }
  989. }
  990.  
Add Comment
Please, Sign In to add comment