Advertisement
Guest User

Tab Section

a guest
Jun 8th, 2017
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 18.22 KB | None | 0 0
  1. <?php
  2.  
  3.  // Don't load directly
  4. if ( !defined('ABSPATH') ) { die('-1'); }
  5.  
  6.  
  7.  
  8. if ( !class_exists( 'avia_sc_tab_section' ) )
  9. {
  10.     class avia_sc_tab_section extends aviaShortcodeTemplate{
  11.  
  12.             static $count = 0;
  13.             static $tab = 0;
  14.             static $admin_active = 1;
  15.             static $tab_titles = array();
  16.             static $tab_icons = array();
  17.             static $tab_images = array();
  18.             static $tab_atts = array();
  19.            
  20.            
  21.            
  22.            
  23.             /**
  24.              * Create the config array for the shortcode button
  25.              */
  26.             function shortcode_insert_button()
  27.             {
  28.                 $this->config['name']       = __('Tab Section', 'avia_framework' );
  29.                 $this->config['icon']       = AviaBuilder::$path['imagesURL']."sc-tabsection.png";
  30.                 $this->config['tab']        = __('Layout Elements', 'avia_framework' );
  31.                 $this->config['order']      = 13;
  32.                 $this->config['shortcode']  = 'av_tab_section';
  33.                 $this->config['html_renderer']  = false;
  34.                 $this->config['tinyMCE']    = array('disable' => "true");
  35.                 $this->config['tooltip']    = __('Add a fullwidth section with tabs that can contain columns and other elements', 'avia_framework' );
  36.                 $this->config['drag-level'] = 1;
  37.                 $this->config['drop-level'] = 100;
  38.  
  39.             }
  40.            
  41.             function extra_assets()
  42.             {
  43.                 if(is_admin())
  44.                 {
  45.                     $ver = AviaBuilder::VERSION;
  46.                     wp_enqueue_script('avia_tab_section_js' , AviaBuilder::$path['assetsURL'].'js/avia-tab-section.js' , array('avia_builder_js','avia_modal_js'), $ver, TRUE );
  47.                 }
  48.             }
  49.  
  50.  
  51.             /**
  52.              * Editor Element - this function defines the visual appearance of an element on the AviaBuilder Canvas
  53.              * Most common usage is to define some markup in the $params['innerHtml'] which is then inserted into the drag and drop container
  54.              * Less often used: $params['data'] to add data attributes, $params['class'] to modify the className
  55.              *
  56.              *
  57.              * @param array $params this array holds the default values for $content and $args.
  58.              * @return $params the return array usually holds an innerHtml key that holds item specific markup.
  59.              */
  60.  
  61.             function editor_element($params)
  62.             {
  63.                
  64.                 extract($params);
  65.                
  66.                 avia_sc_tab_section::$tab = 0;
  67.                 avia_sc_tab_section::$tab_titles = array();
  68.                 avia_sc_tab_section::$admin_active = !empty($args['av_admin_tab_active']) ? $args['av_admin_tab_active'] : 1;
  69.                
  70.                
  71.                 $name = $this->config['shortcode'];
  72.                 $data['shortcodehandler']   = $this->config['shortcode'];
  73.                 $data['modal_title']        = $this->config['name'];
  74.                 $data['modal_ajax_hook']    = $this->config['shortcode'];
  75.                 $data['dragdrop-level']     = $this->config['drag-level'];
  76.                 $data['allowed-shortcodes'] = $this->config['shortcode'];
  77.                
  78.                 if(!empty($this->config['modal_on_load']))
  79.                 {
  80.                     $data['modal_on_load']  = $this->config['modal_on_load'];
  81.                 }
  82.  
  83.                 $dataString  = AviaHelper::create_data_string($data);
  84.                
  85.                
  86.                 if($content)
  87.                 {
  88.                     $final_content = $this->builder->do_shortcode_backend($content);
  89.                     $text_area = ShortcodeHelper::create_shortcode_by_array($name, $content, $args);
  90.                 }
  91.                 else
  92.                 {
  93.                     $tab = new avia_sc_tab_sub_section($this->builder);
  94.                     $params = array('content' => "", 'args' => array(), 'data'=>'');
  95.                     $final_content  = "";
  96.                     $final_content .= $tab->editor_element($params);
  97.                     $final_content .= $tab->editor_element($params);
  98.                     $final_content .= $tab->editor_element($params);
  99.                     $final_content .= $tab->editor_element($params);
  100.                     $text_area = ShortcodeHelper::create_shortcode_by_array($name, '[av_tab_sub_section][/av_tab_sub_section][av_tab_sub_section][/av_tab_sub_section][av_tab_sub_section][/av_tab_sub_section][av_tab_sub_section][/av_tab_sub_section]', $args);
  101.                
  102.                 }
  103.                
  104.                 $title_id = !empty($args['id']) ? ": ".ucfirst($args['id']) : "";
  105.                 $hidden_el_active = !empty($args['av_element_hidden_in_editor']) ? "av-layout-element-closed" : "";
  106.                
  107.                
  108.  
  109.                 $output  = "<div class='avia_tab_section {$hidden_el_active} avia_layout_section avia_pop_class avia-no-visual-updates ".$name." av_drag' ".$dataString.">";
  110.  
  111.                                 $output .= "    <div class='avia_sorthandle menu-item-handle'>";
  112.                 $output .= "        <span class='avia-element-title'>".$this->config['name']."<span class='avia-element-title-id'>".$title_id."</span></span>";
  113.                 $output .= "        <a class='avia-delete'  href='#delete' title='".__('Delete Tab Section','avia_framework' )."'>x</a>";
  114.                 $output .= "        <a class='avia-toggle-visibility'  href='#toggle' title='".__('Show/Hide Tab Section','avia_framework' )."'></a>";
  115.  
  116.                 if(!empty($this->config['popup_editor']))
  117.                 {
  118.                     $output .= "    <a class='avia-edit-element'  href='#edit-element' title='".__('Edit Tab Section','avia_framework' )."'>".__('edit','avia_framework' )."</a>";
  119.                 }
  120.                 $output .= "<a class='avia-save-element'  href='#save-element' title='".__('Save Element as Template','avia_framework' )."'>+</a>";
  121.                 $output .= "        <a class='avia-clone'  href='#clone' title='".__('Clone Tab Section','avia_framework' )."' >".__('Clone Tab Section','avia_framework' )."</a></div>";
  122.                
  123.                 $output .= "<div class='avia_inner_shortcode avia_connect_sort av_drop' data-dragdrop-level='".$this->config['drop-level']."'>";
  124.                
  125.                 $output  .="<div class='avia_tab_section_titles'>";
  126.                 //create tabs
  127.                
  128.                 for($i = 1; $i <= avia_sc_tab_section::$tab; $i ++)
  129.                 {
  130.                     $active_tab = $i == avia_sc_tab_section::$admin_active ? "av-admin-section-tab-active" : "";
  131.                     $tab_title = isset(avia_sc_tab_section::$tab_titles[$i]) ? avia_sc_tab_section::$tab_titles[$i] : "";
  132.                    
  133.                     $output  .= "<a href='#' data-av-tab-section-title='{$i}' class='av-admin-section-tab {$active_tab}'><span class='av-admin-section-tab-move-handle'></span><span class='av-tab-title-text-wrap-full'>".__('Tab','avia_framework' )." <span class='av-tab-nr'>{$i}</span><span class='av-tab-custom-title'>{$tab_title}</span></span></a>";
  134.                 }
  135.                
  136.                 //$output .= "<a class='avia-clone-tab avia-add'  href='#clone-tab' title='".__('Clone Last Tab','avia_framework' )."'>".__('Clone Last Tab','avia_framework' )."</a>";
  137.                 $output .= "<a class='avia-add-tab avia-add'  href='#add-tab' title='".__('Add Tab','avia_framework' )."'>".__('Add Tab','avia_framework' )."</a>";
  138.                 $output .="</div>";
  139.                
  140.                 $output .= "<textarea data-name='text-shortcode' cols='20' rows='4'>".$text_area."</textarea>";
  141.                 $output .= $final_content;
  142.                
  143.                 $output .= "</div>";
  144.                
  145.                 $output .= "<a class='avia-layout-element-hidden' href='#'>".__('Tab Section content hidden. Click here to show it','avia_framework')."</a>";
  146.                
  147.                 $output .= "</div>";
  148.  
  149.                 return $output;
  150.             }
  151.  
  152.             /**
  153.              * Popup Elements
  154.              *
  155.              * If this function is defined in a child class the element automatically gets an edit button, that, when pressed
  156.              * opens a modal window that allows to edit the element properties
  157.              *
  158.              * @return void
  159.              */
  160.             function popup_elements()
  161.             {
  162.                 global  $avia_config;
  163.  
  164.                 $this->elements = array(
  165.                    
  166.                     array(
  167.                             "type"  => "tab_container", 'nodescription' => true
  168.                         ),
  169.                        
  170.                     array(
  171.                             "type"  => "tab",
  172.                             "name"  => __("Content" , 'avia_framework'),
  173.                             'nodescription' => true
  174.                         ),
  175.                    
  176.                    
  177.                     array(
  178.                         "name"  => __("Content transition",'avia_framework' ),
  179.                         "id"    => "transition",
  180.                         "desc"  => __("Define the transition between tab content",'avia_framework' ),
  181.                         "type"  => "select",
  182.                         "std"   => "av-tab-no-transition",
  183.                         "subtype" => array(   __('None','avia_framework' )  =>'av-tab-no-transition',
  184.                                               __('Slide','avia_framework' ) =>'av-tab-slide-transition',
  185.                                           )),
  186.                                          
  187.                                          
  188.                    
  189.                     array(
  190.                         "name"  => __("Content Padding",'avia_framework' ),
  191.                         "id"    => "padding",
  192.                         "desc"  => __("Define the sections top and bottom padding",'avia_framework' ),
  193.                         "type"  => "select",
  194.                         "std"   => "default",
  195.                         "subtype" => array(   __('No Padding','avia_framework' )    =>'no-padding',
  196.                                               __('Small Padding','avia_framework' ) =>'small',
  197.                                               __('Default Padding','avia_framework' )   =>'default',
  198.                                               __('Large Padding','avia_framework' ) =>'large',
  199.                                               __('Huge Padding','avia_framework' )  =>'huge',
  200.                                           )),
  201.                    
  202.                    
  203.                    
  204.                     array(
  205.                         "name"  => __("Tab Position",'avia_framework' ),
  206.                         "id"    => "tab_pos",
  207.                         "desc"  => __("Define the position of the tab buttons",'avia_framework' ),
  208.                         "type"  => "select",
  209.                         "std"   => "av-tab-above-content",
  210.                         "subtype" => array(   __('Display Tabs above content','avia_framework' )    =>'av-tab-above-content',
  211.                                               __('Display Tabs below content','avia_framework' )    =>'av-tab-below-content',
  212.                                           )),
  213.                    
  214.                     array(
  215.                         "name"      =>  __( "Content height", 'avia_framework' ),
  216.                         "id"        =>  "content_height",
  217.                         "desc"      =>  __( "Define the behaviour for the size of the content tabs when switching between the tabs.", 'avia_framework' ),
  218.                         "type"      =>  "select",
  219.                         "std"       =>  "",
  220.                         "required"  =>  array( 'tab_pos', 'contains', 'av-tab-above-content' ),
  221.                         "subtype"   =>  array(      __( 'Same height for all tabs','avia_framework' )   =>  '',
  222.                                                     __( 'Auto adjust to content','avia_framework' )     =>  'av-tab-content-auto',
  223.                                             )),
  224.                                        
  225.                    
  226.                     array(
  227.                         "name"  => __("Tab Padding",'avia_framework' ),
  228.                         "id"    => "tab_padding",
  229.                         "desc"  => __("Define the tab titles top and bottom padding (only works if no icon is displayed at the top off the tab title)",'avia_framework' ),
  230.                         "type"  => "select",
  231.                         "std"   => "default",
  232.                         "subtype" => array(     __('No Padding','avia_framework' )  =>'none',
  233.                                                 __('Small Padding','avia_framework' )   =>'small',
  234.                                                 __('Default Padding','avia_framework' ) =>'default',
  235.                                                 __('Large Padding','avia_framework' )   =>'large',
  236.                                           )),
  237.                    
  238.                    
  239.                     array(
  240.                     "name"  => __("Initial Open", 'avia_framework' ),
  241.                     "desc"  => __("Enter the Number of the Tab that should be open initially.", 'avia_framework' ),
  242.                     "id"    => "initial",
  243.                     "std"   => "1",
  244.                     "type"  => "input"),
  245.                    
  246.                    
  247.                     array(  "name"  => __("For Developers: Section ID", 'avia_framework' ),
  248.                             "desc"  => __("Apply a custom ID Attribute to the section, so you can apply a unique style via CSS. This option is also helpful if you want to use anchor links to scroll to a sections when a link is clicked", 'avia_framework' )."<br/><br/>".
  249.                                        __("Use with caution and make sure to only use allowed characters. No special characters can be used.", 'avia_framework' ),
  250.                             "id"    => "id",
  251.                             "type"  => "input",
  252.                             "std" => ""),
  253.                            
  254.                     array(  "id"    => "av_element_hidden_in_editor",
  255.                             "type"  => "hidden",
  256.                             "std" => "0"),
  257.                            
  258.                      array( "id"    => "av_admin_tab_active",
  259.                             "type"  => "hidden",
  260.                             "std" => "1"),      
  261.                            
  262.                      array(
  263.                             "type"  => "close_div",
  264.                             'nodescription' => true
  265.                         ),
  266.                    
  267.                 array(
  268.                         "type"  => "tab",
  269.                         "name"  => __("Colors",'avia_framework' ),
  270.                         'nodescription' => true
  271.                     ),
  272.                
  273.                 array(
  274.                     "name"  => __("Tab Title Background Color", 'avia_framework' ),
  275.                     "desc"  => __("Here you can set the background color of the tab title bar. Enter no value if you want to use the standard color.", 'avia_framework' ),
  276.                     "id"    => "bg_color",
  277.                     "rgba"  => true,
  278.                     "type"  => "colorpicker"), 
  279.                    
  280.                 array(
  281.                     "name"  => __("Inactive Tab Font Color", 'avia_framework' ),
  282.                     "desc"  => __("Here you can set the text color of the tab. Enter no value if you want to use the standard font color.", 'avia_framework' ),
  283.                     "id"    => "color",
  284.                     "rgba"  => true,
  285.                     "type"  => "colorpicker"), 
  286.                    
  287.                 array(
  288.                         "type"  => "close_div",
  289.                         'nodescription' => true
  290.                     ),
  291.                    
  292.                 array(
  293.                         "type"  => "close_div",
  294.                         'nodescription' => true
  295.                     ),      
  296.                    
  297.                 );
  298.             }
  299.  
  300.             /**
  301.              * Frontend Shortcode Handler
  302.              *
  303.              * @param array $atts array of attributes
  304.              * @param string $content text within enclosing form of shortcode element
  305.              * @param string $shortcodename the shortcode found, when == callback name
  306.              * @return string $output returns the modified html string
  307.              */
  308.             function shortcode_handler($atts, $content = "", $shortcodename = "", $meta = "")
  309.             {
  310.            
  311.                 avia_sc_tab_section::$tab = 0;
  312.                 avia_sc_tab_section::$tab_titles = array();
  313.                 avia_sc_tab_section::$tab_icons = array();
  314.                 avia_sc_tab_section::$tab_images = array();
  315.                 avia_sc_tab_section::$tab_atts = array();
  316.                 avia_sc_tab_section::$count++;
  317.                
  318.                 $atts = shortcode_atts(array(
  319.                 'initial'           =>  1,
  320.                 'id'                =>  '',
  321.                 'padding'           =>  'default',
  322.                 'tab_padding'       =>  'default',
  323.                 'transition'        =>  'av-tab-no-transition' ,
  324.                 'bg_color'          =>  '' ,
  325.                 'color'             =>  '' ,
  326.                 'tab_pos'           =>  'av-tab-above-content',
  327.                 'content_height'    =>  ''
  328.                
  329.                
  330.                
  331.                 ), $atts, $this->config['shortcode']);
  332.                
  333.                 extract($atts);
  334.                 $output     = "";
  335.                
  336.                
  337.                 $params['class'] = "av-tab-section-container entry-content-wrapper main_color {$transition} {$content_height} {$tab_pos} ".$meta['el_class'];
  338.                 $params['open_structure'] = false;
  339.                 $params['id'] = !empty($id) ? AviaHelper::save_string($id,'-') : "av-tab-section-".avia_sc_tab_section::$count;
  340.                 $params['custom_markup'] = $meta['custom_markup'];
  341.                
  342.                
  343.                 //we dont need a closing structure if the element is the first one or if a previous fullwidth element was displayed before
  344.                 if(isset($meta['index']) && $meta['index'] == 0) $params['close'] = false;
  345.                 if(!empty($meta['siblings']['prev']['tag']) && in_array($meta['siblings']['prev']['tag'], AviaBuilder::$full_el_no_section )) $params['close'] = false;
  346.                
  347.                 if(isset($meta['index']) && $meta['index'] != 0) $params['class'] .= " submenu-not-first";
  348.                
  349.                 avia_sc_tab_sub_section::$attr = $atts;
  350.                 $final_content =  ShortcodeHelper::avia_remove_autop($content,true) ;
  351.                
  352.                 $width      = avia_sc_tab_section::$tab * 100;
  353.                 $tabs       = "";
  354.                 $tab_style  = "";
  355.                 $custom_tab_color = "";
  356.                 $arrow = "<span class='av-tab-arrow-container'><span></span></span>";
  357.                
  358.                 if($atts['initial'] > avia_sc_tab_section::$tab) $atts['initial'] = avia_sc_tab_section::$tab;
  359.                
  360.                 for($i = 1; $i <= avia_sc_tab_section::$tab; $i ++)
  361.                 {
  362.                     $icon   = !empty(avia_sc_tab_section::$tab_icons[$i]) ? avia_sc_tab_section::$tab_icons[$i] : "";
  363.                     $image  = !empty(avia_sc_tab_section::$tab_images[$i]) ? avia_sc_tab_section::$tab_images[$i] : "";
  364.                    
  365.                     $extraClass  = "";
  366.                     $extraClass .= !empty($icon)    ? "av-tab-with-icon " : "av-tab-no-icon ";
  367.                     $extraClass .= !empty($image)   ? "av-tab-with-image noHover " : "av-tab-no-image ";
  368.                     $extraClass .= avia_sc_tab_section::$tab_atts[ $i ]['tab_image_style'];
  369.                    
  370.                     $active_tab = $i == $atts['initial'] ? "av-active-tab-title" : "";                 
  371.                    
  372.                     $tab_title = !empty(avia_sc_tab_section::$tab_titles[$i]) ? avia_sc_tab_section::$tab_titles[$i] : "";
  373.                     if($tab_title == "" && empty($image) && empty($icon)){
  374.                         $tab_title = __('Tab','avia_framework' ). " ". $i;
  375.                     }
  376.                    
  377.                     $tab_title_link = clean($tab_title);
  378.                    
  379.                     if($tab_title == "")
  380.                     {
  381.                         $extraClass .= " av-tab-without-text ";
  382.                     }
  383.                     /*
  384.                     $tabs  .= "<a href='#{$tab_title_link}' data-av-tab-section-title='{$i}' class='av-section-tab-title {$active_tab} {$extraClass} '>{$icon}{$image}<span class='av-outer-tab-title'><span class='av-inner-tab-title'>{$tab_title}</span></span>{$arrow}</a>";*/
  385.                    
  386.                     $tab_title_href = avia_sc_tab_section::clean_title_anchor( $tab_title, $i );
  387.                    
  388.                     $tabs  .= "<a href='#{$tab_title_href}' data-av-tab-section-title='{$i}' class='av-section-tab-title {$active_tab} {$extraClass} '>{$icon}{$image}<span class='av-outer-tab-title'><span class='av-inner-tab-title'>{$tab_title}</span></span>{$arrow}</a>";
  389.                 }
  390.                
  391.                
  392.                
  393.                 if(!empty($atts['bg_color']))
  394.                 {
  395.                     $tab_style .= AviaHelper::style_string($atts, 'bg_color', 'background-color');
  396.                 }
  397.                
  398.                 if(!empty($atts['color']))
  399.                 {
  400.                     $tab_style .= AviaHelper::style_string($atts, 'color', 'color');
  401.                     $custom_tab_color = "av-custom-tab-color";
  402.                 }
  403.                
  404.                 if(!empty($tab_style)) $tab_style = "style='".$tab_style."'";
  405.                 $tabs_final =  "<div class='av-tab-section-tab-title-container avia-tab-title-padding-{$tab_padding} {$custom_tab_color}' {$tab_style}>{$tabs}</div>";
  406.                
  407.                 $output .=  avia_new_section($params);
  408.                 $output .=  "<div class='av-tab-section-outer-container'>";
  409.                 if($tab_pos == 'av-tab-above-content') $output .=  $tabs_final;
  410.                
  411.                 $output .=  "<div class='av-tab-section-inner-container avia-section-{$padding}' style='width:{$width}vw; left:".(($atts['initial'] -1)* -100)."%;'>";
  412.                
  413.                 $output .= "<span class='av_prev_tab_section av_tab_navigation'></span><span class='av_next_tab_section av_tab_navigation'></span>";
  414.                 $output .=  $final_content;
  415.                 $output .=  "</div>";
  416.                
  417.                 if($tab_pos == 'av-tab-below-content') $output .=  $tabs_final;
  418.                
  419.                 $output .=  "</div>";
  420.                 $output .= avia_section_after_element_content( $meta , 'after_submenu', false);
  421.                
  422.                 // added to fix http://www.kriesi.at/support/topic/footer-disseapearing/#post-427764
  423.                 avia_sc_section::$close_overlay = "";
  424.                
  425.                
  426.                 return $output;
  427.             }
  428.        
  429.         static public function &clean_title_anchor( $string, $unique_id )
  430.             {
  431.                     // Replace sequences of spaces with hyphen
  432.                 $str = preg_replace( '/  */', '-', $string );
  433.                
  434.                     // Remove all characters except A-Z, a-z, 0-9, hyphens
  435.                 $str = preg_replace('/[^A-Za-z0-9-]/', '', $str );
  436.                
  437.                 $str = $unique_id . '-' . $str;
  438.                 return $str;
  439.             }
  440.     }
  441. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement