Advertisement
Guest User

tab_section.php

a guest
Jul 6th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.54 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" => "tab",
  294. "name" => __("Screen Options",'avia_framework' ),
  295. 'nodescription' => true
  296. ),
  297.  
  298.  
  299. array(
  300. "name" => __("Element Visibility",'avia_framework' ),
  301. "desc" => __("Set the visibility for this element, based on the device screensize.", 'avia_framework' ),
  302. "type" => "heading",
  303. "description_class" => "av-builder-note av-neutral",
  304. ),
  305.  
  306. array(
  307. "desc" => __("Hide on large screens (wider than 990px - eg: Desktop)", 'avia_framework'),
  308. "id" => "av-desktop-hide",
  309. "std" => "",
  310. "container_class" => 'av-multi-checkbox',
  311. "type" => "checkbox"),
  312.  
  313. array(
  314.  
  315. "desc" => __("Hide on medium sized screens (between 768px and 989px - eg: Tablet Landscape)", 'avia_framework'),
  316. "id" => "av-medium-hide",
  317. "std" => "",
  318. "container_class" => 'av-multi-checkbox',
  319. "type" => "checkbox"),
  320.  
  321. array(
  322.  
  323. "desc" => __("Hide on small screens (between 480px and 767px - eg: Tablet Portrait)", 'avia_framework'),
  324. "id" => "av-small-hide",
  325. "std" => "",
  326. "container_class" => 'av-multi-checkbox',
  327. "type" => "checkbox"),
  328.  
  329. array(
  330.  
  331. "desc" => __("Hide on very small screens (smaller than 479px - eg: Smartphone Portrait)", 'avia_framework'),
  332. "id" => "av-mini-hide",
  333. "std" => "",
  334. "container_class" => 'av-multi-checkbox',
  335. "type" => "checkbox"),
  336.  
  337.  
  338. array(
  339. "type" => "close_div",
  340. 'nodescription' => true
  341. ),
  342.  
  343.  
  344.  
  345.  
  346. array(
  347. "type" => "close_div",
  348. 'nodescription' => true
  349. ),
  350.  
  351.  
  352.  
  353. array(
  354. "type" => "close_div",
  355. 'nodescription' => true
  356. ),
  357.  
  358. );
  359. }
  360.  
  361. /**
  362. * Frontend Shortcode Handler
  363. *
  364. * @param array $atts array of attributes
  365. * @param string $content text within enclosing form of shortcode element
  366. * @param string $shortcodename the shortcode found, when == callback name
  367. * @return string $output returns the modified html string
  368. */
  369. function shortcode_handler($atts, $content = "", $shortcodename = "", $meta = "")
  370. {
  371. extract(AviaHelper::av_mobile_sizes($atts)); //return $av_font_classes, $av_title_font_classes and $av_display_classes
  372.  
  373. avia_sc_tab_section::$tab = 0;
  374. avia_sc_tab_section::$tab_titles = array();
  375. avia_sc_tab_section::$tab_icons = array();
  376. avia_sc_tab_section::$tab_images = array();
  377. avia_sc_tab_section::$tab_atts = array();
  378. avia_sc_tab_section::$count++;
  379.  
  380. $atts = shortcode_atts(array(
  381. 'initial' => 1,
  382. 'id' => '',
  383. 'padding' => 'default',
  384. 'tab_padding' => 'default',
  385. 'transition' => 'av-tab-no-transition' ,
  386. 'bg_color' => '' ,
  387. 'color' => '' ,
  388. 'tab_pos' => 'av-tab-above-content',
  389. 'content_height' => ''
  390.  
  391.  
  392.  
  393. ), $atts, $this->config['shortcode']);
  394.  
  395. extract($atts);
  396. $output = "";
  397.  
  398.  
  399. $params['class'] = "av-tab-section-container entry-content-wrapper main_color {$transition} {$content_height} {$av_display_classes} {$tab_pos} ".$meta['el_class'];
  400. $params['open_structure'] = false;
  401. $params['id'] = !empty($id) ? AviaHelper::save_string($id,'-') : "av-tab-section-".avia_sc_tab_section::$count;
  402. $params['custom_markup'] = $meta['custom_markup'];
  403.  
  404.  
  405. //we dont need a closing structure if the element is the first one or if a previous fullwidth element was displayed before
  406. if(isset($meta['index']) && $meta['index'] == 0) $params['close'] = false;
  407. if(!empty($meta['siblings']['prev']['tag']) && in_array($meta['siblings']['prev']['tag'], AviaBuilder::$full_el_no_section )) $params['close'] = false;
  408.  
  409. if(isset($meta['index']) && $meta['index'] != 0) $params['class'] .= " submenu-not-first";
  410.  
  411. avia_sc_tab_sub_section::$attr = $atts;
  412. $final_content = ShortcodeHelper::avia_remove_autop($content,true) ;
  413.  
  414. $width = avia_sc_tab_section::$tab * 100;
  415. $tabs = "";
  416. $tab_style = "";
  417. $custom_tab_color = "";
  418. $arrow = "<span class='av-tab-arrow-container'><span></span></span>";
  419.  
  420. if($atts['initial'] > avia_sc_tab_section::$tab) $atts['initial'] = avia_sc_tab_section::$tab;
  421.  
  422. for($i = 1; $i <= avia_sc_tab_section::$tab; $i ++)
  423. {
  424. $icon = !empty(avia_sc_tab_section::$tab_icons[$i]) ? avia_sc_tab_section::$tab_icons[$i] : "";
  425. $image = !empty(avia_sc_tab_section::$tab_images[$i]) ? avia_sc_tab_section::$tab_images[$i] : "";
  426.  
  427. $extraClass = "";
  428. $extraClass .= !empty($icon) ? "av-tab-with-icon " : "av-tab-no-icon ";
  429. $extraClass .= !empty($image) ? "av-tab-with-image noHover " : "av-tab-no-image ";
  430. $extraClass .= avia_sc_tab_section::$tab_atts[ $i ]['tab_image_style'];
  431.  
  432. $active_tab = $i == $atts['initial'] ? "av-active-tab-title" : "";
  433.  
  434. $tab_title = !empty(avia_sc_tab_section::$tab_titles[$i]) ? avia_sc_tab_section::$tab_titles[$i] : "";
  435. if($tab_title == "" && empty($image) && empty($icon)){
  436. $tab_title = __('Tab','avia_framework' ). " ". $i;
  437. }
  438.  
  439. if($tab_title == "")
  440. {
  441. $extraClass .= " av-tab-without-text ";
  442. }
  443.  
  444. $tab_link = AviaHelper::save_string($tab_title,'-');
  445. $tabs .= "<a href='#{$tab_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>";
  446. }
  447.  
  448.  
  449.  
  450. if(!empty($atts['bg_color']))
  451. {
  452. $tab_style .= AviaHelper::style_string($atts, 'bg_color', 'background-color');
  453. }
  454.  
  455. if(!empty($atts['color']))
  456. {
  457. $tab_style .= AviaHelper::style_string($atts, 'color', 'color');
  458. $custom_tab_color = "av-custom-tab-color";
  459. }
  460.  
  461. if(!empty($tab_style)) $tab_style = "style='".$tab_style."'";
  462. $tabs_final = "<div class='av-tab-section-tab-title-container avia-tab-title-padding-{$tab_padding} {$custom_tab_color}' {$tab_style}>{$tabs}</div>";
  463.  
  464. $output .= avia_new_section($params);
  465. $output .= "<div class='av-tab-section-outer-container'>";
  466. if($tab_pos == 'av-tab-above-content') $output .= $tabs_final;
  467.  
  468. $output .= "<div class='av-tab-section-inner-container avia-section-{$padding}' style='width:{$width}vw; left:".(($atts['initial'] -1)* -100)."%;'>";
  469.  
  470. $output .= "<span class='av_prev_tab_section av_tab_navigation'></span><span class='av_next_tab_section av_tab_navigation'></span>";
  471. $output .= $final_content;
  472. $output .= "</div>";
  473.  
  474. if($tab_pos == 'av-tab-below-content') $output .= $tabs_final;
  475.  
  476. $output .= "</div>";
  477. $output .= avia_section_after_element_content( $meta , 'after_submenu', false);
  478.  
  479. // added to fix http://www.kriesi.at/support/topic/footer-disseapearing/#post-427764
  480. avia_sc_section::$close_overlay = "";
  481.  
  482.  
  483. return $output;
  484. }
  485. }
  486. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement