vc-cta.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. die( '-1' );
  4. }
  5. /**
  6. * WPBakery WPBakery Page Builder shortcodes
  7. *
  8. * @package WPBakeryPageBuilder
  9. * @since 4.5
  10. */
  11. /**
  12. * @since 4.5
  13. * Class WPBakeryShortCode_Vc_Cta
  14. */
  15. class WPBakeryShortCode_Vc_Cta extends WPBakeryShortCode {
  16. protected $template_vars = array();
  17. /**
  18. * @param $atts
  19. * @param $content
  20. * @throws \Exception
  21. */
  22. public function buildTemplate( $atts, $content ) {
  23. $output = array();
  24. $inline_css = array();
  25. $main_wrapper_classes = array( 'vc_cta3' );
  26. $container_classes = array();
  27. if ( ! empty( $atts['el_class'] ) ) {
  28. $main_wrapper_classes[] = $atts['el_class'];
  29. }
  30. if ( ! empty( $atts['style'] ) ) {
  31. $main_wrapper_classes[] = 'vc_cta3-style-' . $atts['style'];
  32. }
  33. if ( ! empty( $atts['shape'] ) ) {
  34. $main_wrapper_classes[] = 'vc_cta3-shape-' . $atts['shape'];
  35. }
  36. if ( ! empty( $atts['txt_align'] ) ) {
  37. $main_wrapper_classes[] = 'vc_cta3-align-' . $atts['txt_align'];
  38. }
  39. if ( ! empty( $atts['color'] ) && ! ( isset( $atts['style'] ) && 'custom' === $atts['style'] ) ) {
  40. $main_wrapper_classes[] = 'vc_cta3-color-' . $atts['color'];
  41. }
  42. if ( isset( $atts['style'] ) && 'custom' === $atts['style'] ) {
  43. if ( ! empty( $atts['custom_background'] ) ) {
  44. $inline_css[] = vc_get_css_color( 'background-color', $atts['custom_background'] );
  45. }
  46. }
  47. if ( ! empty( $atts['i_on_border'] ) ) {
  48. $main_wrapper_classes[] = 'vc_cta3-icons-on-border';
  49. }
  50. if ( ! empty( $atts['i_size'] ) ) {
  51. $main_wrapper_classes[] = 'vc_cta3-icon-size-' . $atts['i_size'];
  52. }
  53. if ( ! empty( $atts['i_background_style'] ) ) {
  54. $main_wrapper_classes[] = 'vc_cta3-icons-in-box';
  55. }
  56. if ( ! empty( $atts['el_width'] ) ) {
  57. $container_classes[] = 'vc_cta3-size-' . $atts['el_width'];
  58. }
  59. if ( ! empty( $atts['add_icon'] ) ) {
  60. $output[ 'icons-' . $atts['add_icon'] ] = $this->getVcIcon( $atts );
  61. $main_wrapper_classes[] = 'vc_cta3-icons-' . $atts['add_icon'];
  62. }
  63. if ( ! empty( $atts['add_button'] ) ) {
  64. $output[ 'actions-' . $atts['add_button'] ] = $this->getButton( $atts );
  65. $main_wrapper_classes[] = 'vc_cta3-actions-' . $atts['add_button'];
  66. }
  67. if ( ! empty( $atts['css_animation'] ) ) {
  68. $main_wrapper_classes[] = $this->getCSSAnimation( $atts['css_animation'] );
  69. }
  70. if ( ! empty( $atts['css'] ) ) {
  71. $main_wrapper_classes[] = vc_shortcode_custom_css_class( $atts['css'] );
  72. }
  73. $output['content'] = wpb_js_remove_wpautop( $content, true );
  74. $output['heading1'] = $this->getHeading( 'h2', $atts );
  75. $output['heading2'] = $this->getHeading( 'h4', $atts );
  76. $output['css-class'] = $main_wrapper_classes;
  77. $output['container-class'] = $container_classes;
  78. $output['inline-css'] = $inline_css;
  79. $this->template_vars = $output;
  80. }
  81. /**
  82. * @param $tag
  83. * @param $atts
  84. * @return string
  85. * @throws \Exception
  86. */
  87. public function getHeading( $tag, $atts ) {
  88. if ( isset( $atts[ $tag ] ) && '' !== trim( $atts[ $tag ] ) ) {
  89. if ( isset( $atts[ 'use_custom_fonts_' . $tag ] ) && 'true' === $atts[ 'use_custom_fonts_' . $tag ] ) {
  90. $custom_heading = visual_composer()->getShortCode( 'vc_custom_heading' );
  91. $data = vc_map_integrate_parse_atts( $this->shortcode, 'vc_custom_heading', $atts, $tag . '_' );
  92. $data['font_container'] = implode( '|', array_filter( array(
  93. 'tag:' . $tag,
  94. $data['font_container'],
  95. ) ) );
  96. $data['text'] = $atts[ $tag ]; // provide text to shortcode
  97. return $custom_heading->render( array_filter( $data ) );
  98. } else {
  99. $inline_css = array();
  100. $inline_css_string = '';
  101. if ( isset( $atts['style'] ) && 'custom' === $atts['style'] ) {
  102. if ( ! empty( $atts['custom_text'] ) ) {
  103. $inline_css[] = vc_get_css_color( 'color', $atts['custom_text'] );
  104. }
  105. }
  106. if ( ! empty( $inline_css ) ) {
  107. $inline_css_string = ' style="' . implode( '', $inline_css ) . '"';
  108. }
  109. return '<' . $tag . $inline_css_string . '>' . $atts[ $tag ] . '</' . $tag . '>';
  110. }
  111. }
  112. return '';
  113. }
  114. /**
  115. * @param $atts
  116. * @return string
  117. * @throws \Exception
  118. */
  119. public function getButton( $atts ) {
  120. $data = vc_map_integrate_parse_atts( $this->shortcode, 'vc_btn', $atts, 'btn_' );
  121. if ( $data ) {
  122. $btn = visual_composer()->getShortCode( 'vc_btn' );
  123. if ( is_object( $btn ) ) {
  124. return '<div class="vc_cta3-actions">' . $btn->render( array_filter( $data ) ) . '</div>';
  125. }
  126. }
  127. return '';
  128. }
  129. /**
  130. * @param $atts
  131. * @return string
  132. * @throws \Exception
  133. */
  134. public function getVcIcon( $atts ) {
  135. if ( empty( $atts['i_type'] ) ) {
  136. $atts['i_type'] = 'fontawesome';
  137. }
  138. $data = vc_map_integrate_parse_atts( $this->shortcode, 'vc_icon', $atts, 'i_' );
  139. if ( $data ) {
  140. $icon = visual_composer()->getShortCode( 'vc_icon' );
  141. if ( is_object( $icon ) ) {
  142. return '<div class="vc_cta3-icons">' . $icon->render( array_filter( $data ) ) . '</div>';
  143. }
  144. }
  145. return '';
  146. }
  147. /**
  148. * @param $string
  149. * @return mixed|string
  150. */
  151. public function getTemplateVariable( $string ) {
  152. if ( is_array( $this->template_vars ) && isset( $this->template_vars[ $string ] ) ) {
  153. return $this->template_vars[ $string ];
  154. }
  155. return '';
  156. }
  157. }