vc-tta-section.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. die( '-1' );
  4. }
  5. VcShortcodeAutoloader::getInstance()->includeClass( 'WPBakeryShortCode_Vc_Tta_Accordion' );
  6. /**
  7. * Class WPBakeryShortCode_Vc_Tta_Section
  8. */
  9. class WPBakeryShortCode_Vc_Tta_Section extends WPBakeryShortCode_Vc_Tta_Accordion {
  10. protected $controls_css_settings = 'tc vc_control-container';
  11. protected $controls_list = array(
  12. 'add',
  13. 'edit',
  14. 'clone',
  15. 'delete',
  16. );
  17. protected $backened_editor_prepend_controls = false;
  18. /**
  19. * @var WPBakeryShortCode_Vc_Tta_Accordion
  20. */
  21. public static $tta_base_shortcode;
  22. public static $self_count = 0;
  23. public static $section_info = array();
  24. /**
  25. * @return mixed|string
  26. */
  27. public function getFileName() {
  28. if ( isset( self::$tta_base_shortcode ) && 'vc_tta_pageable' === self::$tta_base_shortcode->getShortcode() ) {
  29. return 'vc_tta_pageable_section';
  30. } else {
  31. return 'vc_tta_section';
  32. }
  33. }
  34. /**
  35. * @return string
  36. */
  37. public function containerContentClass() {
  38. return 'wpb_column_container vc_container_for_children vc_clearfix';
  39. }
  40. /**
  41. * @return string
  42. */
  43. public function getElementClasses() {
  44. $classes = array();
  45. $classes[] = 'vc_tta-panel';
  46. $isActive = ! vc_is_page_editable() && $this->getTemplateVariable( 'section-is-active' );
  47. if ( $isActive ) {
  48. $classes[] = $this->activeClass;
  49. }
  50. /**
  51. * @since 4.6.2
  52. */
  53. if ( isset( $this->atts['el_class'] ) ) {
  54. $classes[] = $this->atts['el_class'];
  55. }
  56. return implode( ' ', array_filter( $classes ) );
  57. }
  58. /**
  59. * @param $atts
  60. * @param $content
  61. *
  62. * @return string
  63. */
  64. public function getParamContent( $atts, $content ) {
  65. return wpb_js_remove_wpautop( $content );
  66. }
  67. /**
  68. * @param $atts
  69. * @param $content
  70. *
  71. * @return string|null
  72. */
  73. public function getParamTabId( $atts, $content ) {
  74. if ( isset( $atts['tab_id'] ) && strlen( $atts['tab_id'] ) > 0 ) {
  75. return $atts['tab_id'];
  76. }
  77. return null;
  78. }
  79. /**
  80. * @param $atts
  81. * @param $content
  82. *
  83. * @return string|null
  84. */
  85. public function getParamTitle( $atts, $content ) {
  86. if ( isset( $atts['title'] ) && strlen( $atts['title'] ) > 0 ) {
  87. return $atts['title'];
  88. }
  89. return null;
  90. }
  91. /**
  92. * @param $atts
  93. * @param $content
  94. *
  95. * @return string|null
  96. */
  97. public function getParamIcon( $atts, $content ) {
  98. if ( ! empty( $atts['add_icon'] ) && 'true' === $atts['add_icon'] ) {
  99. $iconClass = '';
  100. if ( isset( $atts[ 'i_icon_' . $atts['i_type'] ] ) ) {
  101. $iconClass = $atts[ 'i_icon_' . $atts['i_type'] ];
  102. }
  103. vc_icon_element_fonts_enqueue( $atts['i_type'] );
  104. return '<i class="vc_tta-icon ' . esc_attr( $iconClass ) . '"></i>';
  105. }
  106. return null;
  107. }
  108. /**
  109. * @param $atts
  110. * @param $content
  111. *
  112. * @return string|null
  113. */
  114. public function getParamIconLeft( $atts, $content ) {
  115. if ( 'left' === $atts['i_position'] ) {
  116. return $this->getParamIcon( $atts, $content );
  117. }
  118. return null;
  119. }
  120. /**
  121. * @param $atts
  122. * @param $content
  123. *
  124. * @return string|null
  125. */
  126. public function getParamIconRight( $atts, $content ) {
  127. if ( 'right' === $atts['i_position'] ) {
  128. return $this->getParamIcon( $atts, $content );
  129. }
  130. return null;
  131. }
  132. /**
  133. * Section param active
  134. * @param $atts
  135. * @param $content
  136. * @return bool|null
  137. */
  138. public function getParamSectionIsActive( $atts, $content ) {
  139. if ( is_object( self::$tta_base_shortcode ) ) {
  140. if ( isset( self::$tta_base_shortcode->atts['active_section'] ) && strlen( self::$tta_base_shortcode->atts['active_section'] ) > 0 ) {
  141. $active = (int) self::$tta_base_shortcode->atts['active_section'];
  142. if ( $active === self::$self_count ) {
  143. return true;
  144. }
  145. }
  146. }
  147. return null;
  148. }
  149. /**
  150. * @param $atts
  151. * @param $content
  152. * @return string|null
  153. */
  154. public function getParamControlIconPosition( $atts, $content ) {
  155. if ( is_object( self::$tta_base_shortcode ) ) {
  156. if ( isset( self::$tta_base_shortcode->atts['c_icon'] ) && strlen( self::$tta_base_shortcode->atts['c_icon'] ) > 0 && isset( self::$tta_base_shortcode->atts['c_position'] ) && strlen( self::$tta_base_shortcode->atts['c_position'] ) > 0 ) {
  157. $c_position = self::$tta_base_shortcode->atts['c_position'];
  158. return 'vc_tta-controls-icon-position-' . $c_position;
  159. }
  160. }
  161. return null;
  162. }
  163. /**
  164. * @param $atts
  165. * @param $content
  166. * @return string|null
  167. */
  168. public function getParamControlIcon( $atts, $content ) {
  169. if ( is_object( self::$tta_base_shortcode ) ) {
  170. if ( isset( self::$tta_base_shortcode->atts['c_icon'] ) && strlen( self::$tta_base_shortcode->atts['c_icon'] ) > 0 ) {
  171. $c_icon = self::$tta_base_shortcode->atts['c_icon'];
  172. return '<i class="vc_tta-controls-icon vc_tta-controls-icon-' . $c_icon . '"></i>';
  173. }
  174. }
  175. return null;
  176. }
  177. /**
  178. * @param $atts
  179. * @param $content
  180. * @return string
  181. */
  182. public function getParamHeading( $atts, $content ) {
  183. $isPageEditable = vc_is_page_editable();
  184. $h4attributes = array();
  185. $h4classes = array(
  186. 'vc_tta-panel-title',
  187. );
  188. if ( $isPageEditable ) {
  189. $h4attributes[] = 'data-vc-tta-controls-icon-position=""';
  190. } else {
  191. $controlIconPosition = $this->getTemplateVariable( 'control-icon-position' );
  192. if ( $controlIconPosition ) {
  193. $h4classes[] = $controlIconPosition;
  194. }
  195. }
  196. $h4attributes[] = 'class="' . implode( ' ', $h4classes ) . '"';
  197. $output = '<h4 ' . implode( ' ', $h4attributes ) . '>'; // close h4
  198. if ( $isPageEditable ) {
  199. $output .= '<a href="javascript:;" data-vc-target=""';
  200. $output .= ' data-vc-tta-controls-icon-wrapper';
  201. $output .= ' data-vc-use-cache="false"';
  202. } else {
  203. $output .= '<a href="#' . esc_attr( $this->getTemplateVariable( 'tab_id' ) ) . '"';
  204. }
  205. $output .= ' data-vc-accordion';
  206. $output .= ' data-vc-container=".vc_tta-container">';
  207. $output .= $this->getTemplateVariable( 'icon-left' );
  208. $output .= '<span class="vc_tta-title-text">' . $this->getTemplateVariable( 'title' ) . '</span>';
  209. $output .= $this->getTemplateVariable( 'icon-right' );
  210. if ( ! $isPageEditable ) {
  211. $output .= $this->getTemplateVariable( 'control-icon' );
  212. }
  213. $output .= '</a>';
  214. $output .= '</h4>'; // close h4 fix #2229
  215. return $output;
  216. }
  217. /**
  218. * Get basic heading
  219. *
  220. * These are used in Pageable element inside content and are hidden from view
  221. *
  222. * @param $atts
  223. * @param $content
  224. *
  225. * @return string
  226. */
  227. public function getParamBasicHeading( $atts, $content ) {
  228. $isPageEditable = vc_is_page_editable();
  229. if ( $isPageEditable ) {
  230. $attributes = array(
  231. 'href' => 'javascript:;',
  232. 'data-vc-container' => '.vc_tta-container',
  233. 'data-vc-accordion' => '',
  234. 'data-vc-target' => '',
  235. 'data-vc-tta-controls-icon-wrapper' => '',
  236. 'data-vc-use-cache' => 'false',
  237. );
  238. } else {
  239. $attributes = array(
  240. 'data-vc-container' => '.vc_tta-container',
  241. 'data-vc-accordion' => '',
  242. 'data-vc-target' => esc_attr( '#' . $this->getTemplateVariable( 'tab_id' ) ),
  243. );
  244. }
  245. $output = '
  246. <span class="vc_tta-panel-title">
  247. <a ' . vc_convert_atts_to_string( $attributes ) . '></a>
  248. </span>
  249. ';
  250. return $output;
  251. }
  252. /**
  253. * Check is allowed to add another element inside current element.
  254. *
  255. * @return bool
  256. * @since 4.8
  257. *
  258. */
  259. public function getAddAllowed() {
  260. return vc_user_access()->part( 'shortcodes' )->checkStateAny( true, 'custom', null )->get();
  261. }
  262. }