Guest User

tab_sub_section.php

a guest
Jul 6th, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 17.97 KB | None | 0 0
  1. <?php
  2. /**
  3.  * COLUMNS
  4.  * Shortcode which creates columns for better content separation
  5.  */
  6.  
  7.  // Don't load directly
  8. if ( !defined('ABSPATH') ) { die('-1'); }
  9.  
  10.  
  11.  
  12. if ( !class_exists( 'avia_sc_tab_sub_section' ) )
  13. {
  14.     class avia_sc_tab_sub_section extends aviaShortcodeTemplate{
  15.  
  16.             static $extraClass = "";
  17.             static $attr = array();
  18.  
  19.             /**
  20.              * Create the config array for the shortcode button
  21.              */
  22.             function shortcode_insert_button()
  23.             {
  24.                 $this->config['invisible'] = true;
  25.                 $this->config['name']       = 'Single Tab';
  26.                 $this->config['icon']       = AviaBuilder::$path['imagesURL']."sc-full.png";
  27.                 $this->config['tab']        = __('Layout Elements', 'avia_framework' );
  28.                 $this->config['order']      = 100;
  29.                 $this->config['target']     = "avia-section-drop";
  30.                 $this->config['shortcode']  = 'av_tab_sub_section';
  31.                 $this->config['html_renderer']  = false;
  32.                 $this->config['tinyMCE']    = array('disable' => "true");
  33.                 $this->config['tooltip']    = __('Creates a single tab for the tab section element', 'avia_framework' );
  34.                 $this->config['drag-level'] = 2;
  35.                 $this->config['drop-level'] = 1;
  36.             }
  37.  
  38.  
  39.             /**
  40.              * Editor Element - this function defines the visual appearance of an element on the AviaBuilder Canvas
  41.              * Most common usage is to define some markup in the $params['innerHtml'] which is then inserted into the drag and drop container
  42.              * Less often used: $params['data'] to add data attributes, $params['class'] to modify the className
  43.              *
  44.              *
  45.              * @param array $params this array holds the default values for $content and $args.
  46.              * @return $params the return array usually holds an innerHtml key that holds item specific markup.
  47.              */
  48.  
  49.             function editor_element($params)
  50.             {
  51.                 avia_sc_tab_section::$tab += 1;
  52.                
  53.                 extract($params);
  54.                
  55.                 if(empty($data)) $data = array();
  56.                
  57.                 $name       = $this->config['shortcode'];
  58.                 $drag       = $this->config['drag-level'];
  59.                 $drop       = $this->config['drop-level'];
  60.  
  61.                
  62.                 $data['shortcodehandler']   = $this->config['shortcode'];
  63.                 $data['modal_title']        = __('Edit Tab','avia_framework' );
  64.                 $data['modal_ajax_hook']    = $this->config['shortcode'];
  65.                 $data['dragdrop-level']     = $this->config['drag-level'];
  66.                 $data['allowed-shortcodes'] = $this->config['shortcode'];
  67.                
  68.                 if(!empty($this->config['modal_on_load']))
  69.                 {
  70.                     $data['modal_on_load']  = $this->config['modal_on_load'];
  71.                 }
  72.    
  73.                 $dataString  = AviaHelper::create_data_string($data);
  74.                
  75.                 $el_bg = !empty($args['background_color']) ? " style='background:".$args['background_color'].";'" : "";
  76.                 $active_tab = avia_sc_tab_section::$tab == avia_sc_tab_section::$admin_active ? "av-admin-section-tab-content-active" : "";
  77.                 avia_sc_tab_section::$tab_titles[ avia_sc_tab_section::$tab ] = !empty($args['tab_title']) ? ": ".$args['tab_title'] : "";
  78.                
  79.  
  80.                 $output  = "<div  class='avia_layout_column avia_layout_tab {$active_tab} avia-no-visual-updates ".$name." av_drag' {$dataString} data-width='{$name}' data-av-tab-section-content='".avia_sc_tab_section::$tab."' >";
  81.                 $output .= "<div class='avia_sorthandle'>";
  82.  
  83.                 //$output .= "<span class='avia-element-title'>".$this->config['name']."<span class='avia-element-title-id'>".$title_id."</span></span>";
  84.                 $output .= "<a class='avia-delete avia-tab-delete av-special-delete'  href='#delete' title='".__('Delete Tab','avia_framework' )."'>x</a>";
  85.                 $output .= "<a class='avia-clone avia-tab-clone av-special-clone'  href='#clone' title='".__('Clone Tab','avia_framework' )."' >".__('Clone Cell','avia_framework' )."</a>";
  86.                
  87.                 if(!empty($this->config['popup_editor']))
  88.                 {
  89.                     $output .= "<a class='avia-edit-element'  href='#edit-element' title='".__('Edit Tab','avia_framework' )."'>edit</a>";
  90.                 }
  91.                
  92.                 $output .= "</div><div class='avia_inner_shortcode avia_connect_sort av_drop ' data-dragdrop-level='{$drop}'>";
  93.                 $output .= "<textarea data-name='text-shortcode' cols='20' rows='4'>".ShortcodeHelper::create_shortcode_by_array($name, $content, $args)."</textarea>";
  94.                 if($content)
  95.                 {
  96.                     $content = $this->builder->do_shortcode_backend($content);
  97.                 }
  98.                 $output .= $content;
  99.                 $output .= "</div>";
  100.                 $output .= "<div class='avia-layout-element-bg' ".$this->get_bg_string($args)."></div>";
  101.                 $output .= "</div>";
  102.  
  103.  
  104.                 return $output;
  105.             }
  106.            
  107.             function get_bg_string($args)
  108.             {
  109.                 $style = "";
  110.            
  111.                 if(!empty($args['attachment']))
  112.                 {
  113.                     $image = false;
  114.                     $src = wp_get_attachment_image_src($args['attachment'], $args['attachment_size']);
  115.                     if(!empty($src[0])) $image = $src[0];
  116.                    
  117.                    
  118.                     if($image)
  119.                     {
  120.                         $bg     = !empty($args['background_color']) ?       $args['background_color'] : "transparent"; $bg = "transparent";
  121.                         $pos    = !empty($args['background_position'])  ?   $args['background_position'] : "center center";
  122.                         $repeat = !empty($args['background_repeat']) ?      $args['background_repeat'] : "no-repeat";
  123.                         $extra  = "";
  124.                        
  125.                         if($repeat == "stretch")
  126.                         {
  127.                             $repeat = "no-repeat";
  128.                             $extra = "background-size: cover;";
  129.                         }
  130.                        
  131.                         if($repeat == "contain")
  132.                         {
  133.                             $repeat = "no-repeat";
  134.                             $extra = "background-size: contain;";
  135.                         }
  136.                        
  137.                        
  138.                        
  139.                         $style = "style='background: $bg url($image) $repeat $pos; $extra'";
  140.                     }
  141.                    
  142.                 }
  143.                
  144.                 return $style;
  145.             }
  146.            
  147.            
  148.            
  149.             /**
  150.              * Popup Elements
  151.              *
  152.              * If this function is defined in a child class the element automatically gets an edit button, that, when pressed
  153.              * opens a modal window that allows to edit the element properties
  154.              *
  155.              * @return void
  156.              */
  157.             function popup_elements()
  158.             {
  159.                 global  $avia_config;
  160.  
  161.                 $this->elements = array(
  162.                    
  163.  
  164.                     array(
  165.                             "type"  => "tab_container", 'nodescription' => true
  166.                         ),
  167.                    
  168.                      array(
  169.                         "type"  => "tab",
  170.                         "name"  => __("Settings" , 'avia_framework'),
  171.                         'nodescription' => true
  172.                     ),
  173.                
  174.                     array( 
  175.                             "name"  => __("Tab Title", 'avia_framework' ),
  176.                             "desc"  => __("Set a tab title", 'avia_framework' ),
  177.                             "id"    => "tab_title",
  178.                             "type"  => "input",
  179.                             "std"   => "",
  180.                         ),
  181.                    
  182.                     array( 
  183.                             "name"  => __("Vertical align", 'avia_framework' ),
  184.                             "desc"  => __("Choose the vertical alignment of your tab content. (only applies if tabs are set to fixed height)", 'avia_framework' ),
  185.                             "id"    => "vertical_align",
  186.                             "type"  => "select",
  187.                             "std"   => "middle",
  188.                             "subtype" => array(
  189.                                 __('Top',   'avia_framework' ) =>'top',
  190.                                 __('Middle',  'avia_framework' ) =>'middle',
  191.                                 __('Bottom',   'avia_framework' ) =>'bottom',
  192.                             )),
  193.                            
  194.                     array(
  195.                             "name"  => __("Tab Symbol", 'avia_framework' ),
  196.                             "desc"  => __("Should an icon or image be displayed at the top of the tab title?", 'avia_framework' ),
  197.                             "id"    => "icon_select",
  198.                             "type"  => "select",
  199.                             "std"   => "no",
  200.                             "subtype" => array(
  201.                                 __('No icon or image',  'avia_framework' ) =>'no',
  202.                                 __('Display icon',  'avia_framework' ) =>'icon_top',
  203.                                 __('Display image',  'avia_framework' ) =>'image_top')),
  204.  
  205.                         array(
  206.                             "name"  => __("Tab Icon",'avia_framework' ),
  207.                             "desc"  => __("Select an icon for your tab title below",'avia_framework' ),
  208.                             "id"    => "icon",
  209.                             "type"  => "iconfont",
  210.                             "std"   => "",
  211.                             "required" => array('icon_select','equals','icon_top')
  212.                         ),
  213.                        
  214.                         array(
  215.                                     "name"  => __("Tab Image",'avia_framework' ),
  216.                                     "desc"  => __("Either upload a new, or choose an existing image from your media library",'avia_framework' ),
  217.                                     "id"    => "tab_image",
  218.                                     "type"  => "image",
  219.                                     "fetch" => "id",
  220.                                     "secondary_img" => true,
  221.                                     "force_id_fetch"=> true,
  222.                                     "title" =>  __("Insert Image",'avia_framework' ),
  223.                                     "button" => __("Insert",'avia_framework' ),
  224.                                     "required" => array('icon_select','equals','image_top'),
  225.                                     "std"   => ""),
  226.                    
  227.                        
  228.                         array(
  229.                             "name"  => __("Tab Image Style", 'avia_framework' ),
  230.                             "id"    => "tab_image_style",
  231.                             "type"  => "select",
  232.                             "std"   => "",
  233.                             "required" => array('icon_select','equals','image_top'),
  234.                             "subtype" => array(
  235.                                 __('No special style',  'avia_framework' ) =>'',
  236.                                 __('Rounded Borders',  'avia_framework' ) =>'av-tab-image-rounded',
  237.                                 __('Circle',  'avia_framework' ) =>'av-tab-image-circle',
  238.                                )),
  239.                        
  240.                        
  241.                     array(
  242.                             "type"  => "close_div",
  243.                             'nodescription' => true
  244.                         ),
  245.                  
  246.                   array(
  247.                         "type"  => "tab",
  248.                         "name"  => __("Colors" , 'avia_framework'),
  249.                         'nodescription' => true
  250.                     ),
  251.                    
  252.                     array( 
  253.                             "name"  => __("Active Tab Font Color", 'avia_framework' ),
  254.                             "desc"  => __("Select a custom font color for the active tab here. Leave empty for default color", 'avia_framework' ),
  255.                             "id"    => "color",
  256.                             "type"  => "colorpicker",
  257.                             "std"   => "",
  258.                         ),
  259.                    
  260.                    
  261.                     array( 
  262.                             "name"  => __("Custom Background Color", 'avia_framework' ),
  263.                             "desc"  => __("Select a custom background color for this section here. Leave empty for default color", 'avia_framework' ),
  264.                             "id"    => "background_color",
  265.                             "type"  => "colorpicker",
  266.                             "std"   => "",
  267.                         ),
  268.                        
  269.                     array(
  270.                             "name"  => __("Custom Background Image",'avia_framework' ),
  271.                             "desc"  => __("Either upload a new, or choose an existing image from your media library. Leave empty if you don't want to use a background image ",'avia_framework' ),
  272.                             "id"    => "src",
  273.                             "type"  => "image",
  274.                             "title" => __("Insert Image",'avia_framework' ),
  275.                             "button" => __("Insert",'avia_framework' ),
  276.                             "std"   => ""),
  277.                    
  278.                     array(
  279.                         "name"  => __("Background Attachment",'avia_framework' ),
  280.                         "desc"  => __("Background can either scroll with the page or be fixed", 'avia_framework' ),
  281.                         "id"    => "background_attachment",
  282.                         "type"  => "select",
  283.                         "std"   => "scroll",
  284.                         "required" => array('src','not',''),
  285.                         "subtype" => array(
  286.                             __('Scroll','avia_framework' )=>'scroll',
  287.                             __('Fixed','avia_framework' ) =>'fixed',
  288.                             )
  289.                         ),
  290.                    
  291.                     array(
  292.                         "name"  => __("Background Image Position",'avia_framework' ),
  293.                         "id"    => "background_position",
  294.                         "type"  => "select",
  295.                         "std"   => "top left",
  296.                         "required" => array('src','not',''),
  297.                         "subtype" => array(   __('Top Left','avia_framework' )       =>'top left',
  298.                                               __('Top Center','avia_framework' )     =>'top center',
  299.                                               __('Top Right','avia_framework' )      =>'top right',
  300.                                               __('Bottom Left','avia_framework' )    =>'bottom left',
  301.                                               __('Bottom Center','avia_framework' )  =>'bottom center',
  302.                                               __('Bottom Right','avia_framework' )   =>'bottom right',
  303.                                               __('Center Left','avia_framework' )    =>'center left',
  304.                                               __('Center Center','avia_framework' )  =>'center center',
  305.                                               __('Center Right','avia_framework' )   =>'center right'
  306.                                               )
  307.                     ),
  308.  
  309.                    array(
  310.                         "name"  => __("Background Repeat",'avia_framework' ),
  311.                         "id"    => "background_repeat",
  312.                         "type"  => "select",
  313.                         "std"   => "no-repeat",
  314.                         "required" => array('src','not',''),
  315.                         "subtype" => array(   __('No Repeat','avia_framework' )          =>'no-repeat',
  316.                                               __('Repeat','avia_framework' )             =>'repeat',
  317.                                               __('Tile Horizontally','avia_framework' )  =>'repeat-x',
  318.                                               __('Tile Vertically','avia_framework' )    =>'repeat-y',
  319.                                               __('Stretch to fit (stretches image to cover the element)','avia_framework' )     =>'stretch',
  320.                                               __('Scale to fit (scales image so the whole image is always visible)','avia_framework' )     =>'contain'
  321.                                               )
  322.                   ),
  323.                  
  324.                  array(
  325.                             "type"  => "close_div",
  326.                             'nodescription' => true
  327.                         ),
  328.                  
  329.                
  330.                  
  331.                  array(
  332.                             "type"  => "close_div",
  333.                             'nodescription' => true
  334.                         ),
  335.                    
  336.                    
  337.                    
  338.                 );
  339.             }
  340.            
  341.            
  342.  
  343.             /**
  344.              * Frontend Shortcode Handler
  345.              *
  346.              * @param array $atts array of attributes
  347.              * @param string $content text within enclosing form of shortcode element
  348.              * @param string $shortcodename the shortcode found, when == callback name
  349.              * @return string $output returns the modified html string
  350.              */
  351.             function shortcode_handler($atts, $content = "", $shortcodename = "", $meta = "")
  352.             {
  353.                 global $avia_config;
  354.                
  355.                 $atts = shortcode_atts(array(
  356.                    
  357.                     'tab_title'             => '',
  358.                     'vertical_align'        => '',
  359.                     'color'                 => '',
  360.                     'background_color'      => '',
  361.                     'background_position'   => '',
  362.                     'background_repeat'     => '',
  363.                     'background_attachment' => '',
  364.                     'fetch_image'           => '',
  365.                     'attachment_size'       => '',
  366.                     'attachment'            => '',
  367.                     'icon'                  => '',
  368.                     'font'                  => '',
  369.                     'icon_select'           => 'no',
  370.                     'tab_image'             => '',
  371.                     'tab_image_style'       => '',
  372.                    
  373.                    
  374.                
  375.                 ), $atts, $this->config['shortcode']);
  376.                
  377.                 if(avia_sc_tab_sub_section::$attr['content_height'] == "av-tab-content-auto"){
  378.                     $atts['vertical_align'] = "top";
  379.                 }
  380.                
  381.                 avia_sc_tab_section::$tab += 1;
  382.                 avia_sc_tab_section::$tab_titles[ avia_sc_tab_section::$tab ] = !empty($atts['tab_title']) ? $atts['tab_title'] : "";
  383.                 avia_sc_tab_section::$tab_atts[ avia_sc_tab_section::$tab ] = $atts;
  384.                
  385.                
  386.                 $extraClass     = "";
  387.                 $outer_style    = "";
  388.                 $data           = "";
  389.                 $display_char   = av_icon($atts['icon'], $atts['font']);
  390.                 $icon           = "";
  391.                 $image          = "";
  392.                
  393.                 if($atts['icon_select'] == "icon_top")
  394.                 {
  395.                     avia_sc_tab_section::$tab_icons[ avia_sc_tab_section::$tab ] = "<span class='av-tab-section-icon' {$display_char}></span>";
  396.                 }
  397.                
  398.                 if($atts['icon_select'] == "image_top")
  399.                 {
  400.                     if(!empty($atts['tab_image']))
  401.                     {
  402.                         $src = wp_get_attachment_image_src($atts['tab_image'], 'square');
  403.                        
  404.                         if(!empty($src[0])){
  405.                             avia_sc_tab_section::$tab_images[ avia_sc_tab_section::$tab ] = "<img class='av-tab-section-image' src='".$src[0]."' alt='' title='' />";
  406.                         }
  407.                     }
  408.                 }
  409.                
  410.                 if(!empty($atts['attachment']))
  411.                 {
  412.                     $src = wp_get_attachment_image_src($atts['attachment'], $atts['attachment_size']);
  413.                     if(!empty($src[0])) $atts['fetch_image'] = $src[0];
  414.                 }
  415.                
  416.                 if(!empty($atts['color']))
  417.                 {
  418.                     $data .= "data-av-tab-color='".$atts['color']."' ";
  419.                 }
  420.                
  421.                 if(!empty($atts['background_color']))
  422.                 {
  423.                     $data .= "data-av-tab-bg-color='".$atts['background_color']."' ";
  424.                 }
  425.                
  426.                 if($atts['background_repeat'] == "stretch")
  427.                 {
  428.                     $extraClass .= " avia-full-stretch";
  429.                     $atts['background_repeat'] = "no-repeat";
  430.                 }
  431.                
  432.                 if($atts['background_repeat'] == "contain")
  433.                 {
  434.                     $extraClass .= " avia-full-contain";
  435.                     $atts['background_repeat'] = "no-repeat";
  436.                 }
  437.                
  438.                
  439.                
  440.                 if(!empty($atts['fetch_image']))
  441.                 {
  442.                     $outer_style .= AviaHelper::style_string($atts, 'fetch_image', 'background-image');
  443.                     $outer_style .= AviaHelper::style_string($atts, 'background_position', 'background-position');
  444.                     $outer_style .= AviaHelper::style_string($atts, 'background_repeat', 'background-repeat');
  445.                     $outer_style .= AviaHelper::style_string($atts, 'background_attachment', 'background-attachment');
  446.                 }
  447.                
  448.                 $outer_style .= AviaHelper::style_string($atts, 'vertical_align', 'vertical-align');
  449.                 $outer_style .= AviaHelper::style_string($atts, 'padding');
  450.                 $outer_style .= AviaHelper::style_string($atts, 'background_color', 'background-color');
  451.                
  452.                
  453.                 if(!empty($outer_style)) $outer_style = "style='".$outer_style."'";
  454.                                
  455.                 $avia_config['current_column'] = $shortcodename;
  456.                
  457.                 $tab_nr = isset(avia_sc_tab_sub_section::$attr['initial']) ? avia_sc_tab_sub_section::$attr['initial'] : 1;
  458.                 $active_tab = avia_sc_tab_section::$tab == $tab_nr ? "av-active-tab-content __av_init_open" : "";
  459.                
  460.                
  461.                 $tab_link = AviaHelper::save_string($atts['tab_title'],'-');
  462.                
  463.                 $output   = '<div data-av-tab-section-content="'.avia_sc_tab_section::$tab.'" class="av-layout-tab av-animation-delay-container '.$active_tab.' '.$meta['el_class'].' '.$extraClass.' '.avia_sc_tab_sub_section::$extraClass.'" '.$outer_style.' '.$data.' data-tab-section-id="'.$tab_link.'">';
  464.                 $output  .= "<div class='av-layout-tab-inner'>";
  465.                 $output  .= "<div class='container'>";
  466.                 //if the user uses the column shortcode without the layout builder make sure that paragraphs are applied to the text
  467.                 $content =  (empty($avia_config['conditionals']['is_builder_template'])) ? ShortcodeHelper::avia_apply_autop(ShortcodeHelper::avia_remove_autop($content)) : ShortcodeHelper::avia_remove_autop($content, true);
  468.                 $output .= $content.'</div>';
  469.                 $output .= '</div>';
  470.                 $output .= '</div>';
  471.  
  472.                 unset($avia_config['current_column']);
  473.                    
  474.                 return $output;
  475.             }
  476.            
  477.     }
  478. }
Add Comment
Please, Sign In to add comment