PageRenderTime 37ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/js_composer/include/classes/shortcodes/vc-column.php

https://gitlab.com/oxidigitaluser/liguelista
PHP | 231 lines | 153 code | 17 blank | 61 comment | 64 complexity | d18f86ed832fc8b48f622aed35008cfb MD5 | raw file
  1. <?php
  2. /**
  3. * WPBakery Visual Composer shortcodes
  4. *
  5. * @package WPBakeryVisualComposer
  6. *
  7. */
  8. class WPBakeryShortCode_VC_Column extends WPBakeryShortCode {
  9. /**
  10. * @var array
  11. */
  12. protected $predefined_atts = array(
  13. 'font_color' => '',
  14. 'el_class' => '',
  15. 'el_position' => '',
  16. 'width' => '1/1'
  17. );
  18. /**
  19. * @param $controls
  20. * @param string $extended_css
  21. *
  22. * @return string
  23. */
  24. public function getColumnControls( $controls, $extended_css = '' ) {
  25. $output = '<div class="vc_controls vc_control-column vc_controls-visible controls' . ( !empty( $extended_css ) ? " {$extended_css}" : '' ) . '">';
  26. $controls_end = '</div>';
  27. if ( $extended_css == 'bottom-controls' ) {
  28. $control_title = __( 'Append to this column', 'js_composer' );
  29. } else {
  30. $control_title = __( 'Prepend to this column', 'js_composer' );
  31. }
  32. $controls_add = ' <a class="vc_control column_add vc_column-add" data-vc-control="add" href="#" title="' . $control_title . '"><i class="vc_icon"></i></a>';
  33. $controls_edit = ' <a class="vc_control column_edit vc_column-edit" data-vc-control="edit" href="#" title="' . __( 'Edit this column', 'js_composer' ) . '"><i class="vc_icon"></i></a>';
  34. $controls_delete = ' <a class="vc_control column_delete vc_column-delete" data-vc-control="delete" href="#" title="' . __( 'Delete this column', 'js_composer' ) . '"><i class="vc_icon"></i></a>';
  35. if ( is_array( $controls ) && !empty( $controls ) ) {
  36. foreach ( $controls as $control ) {
  37. $method_name = vc_camel_case( 'output-editor-control-' . $control );
  38. if ( method_exists( $this, $method_name ) ) {
  39. $output .= $this->$method_name();
  40. } else {
  41. $control_var = 'controls_' . $control;
  42. $output .= $$control_var;
  43. }
  44. }
  45. return $output . $controls_end;
  46. } elseif ( is_string( $controls ) && 'full' === $controls ) {
  47. return $output . $controls_add . $controls_edit . $controls_delete . $controls_end;
  48. } elseif ( is_string( $controls ) ) {
  49. $control_var = 'controls_' . $controls;
  50. if ( isset( $$control_var ) ) {
  51. return $output . $$control_var . $controls_end;
  52. }
  53. }
  54. return $output . $controls_add . $controls_edit . $controls_delete . $controls_end;
  55. }
  56. /**
  57. * @param $param
  58. * @param $value
  59. * @param array $settings
  60. * @param array $atts
  61. *
  62. * @return string
  63. */
  64. public function singleParamHtmlHolder( $param, $value ) {
  65. $output = '';
  66. // Compatibility fixes.
  67. $old_names = array(
  68. 'yellow_message',
  69. 'blue_message',
  70. 'green_message',
  71. 'button_green',
  72. 'button_grey',
  73. 'button_yellow',
  74. 'button_blue',
  75. 'button_red',
  76. 'button_orange'
  77. );
  78. $new_names = array(
  79. 'alert-block',
  80. 'alert-info',
  81. 'alert-success',
  82. 'btn-success',
  83. 'btn',
  84. 'btn-info',
  85. 'btn-primary',
  86. 'btn-danger',
  87. 'btn-warning'
  88. );
  89. $value = str_ireplace( $old_names, $new_names, $value );
  90. //$value = __($value, "js_composer");
  91. //
  92. $param_name = isset( $param['param_name'] ) ? $param['param_name'] : '';
  93. $type = isset( $param['type'] ) ? $param['type'] : '';
  94. $class = isset( $param['class'] ) ? $param['class'] : '';
  95. if ( isset( $param['holder'] ) == true && $param['holder'] != 'hidden' ) {
  96. $output .= '<' . $param['holder'] . ' class="wpb_vc_param_value ' . $param_name . ' ' . $type . ' ' . $class . '" name="' . $param_name . '">' . $value . '</' . $param['holder'] . '>';
  97. }
  98. return $output;
  99. }
  100. /**
  101. * @param $atts
  102. * @param null $content
  103. *
  104. * @return string
  105. */
  106. public function contentAdmin( $atts, $content = null ) {
  107. $width = $el_class = '';
  108. extract( shortcode_atts( $this->predefined_atts, $atts ) );
  109. $output = '';
  110. $column_controls = $this->getColumnControls( $this->settings( 'controls' ) );
  111. $column_controls_bottom = $this->getColumnControls( 'add', 'bottom-controls' );
  112. if ( $width == 'column_14' || $width == '1/4' ) {
  113. $width = array( 'vc_col-sm-3' );
  114. } else if ( $width == 'column_14-14-14-14' ) {
  115. $width = array( 'vc_col-sm-3', 'vc_col-sm-3', 'vc_col-sm-3', 'vc_col-sm-3' );
  116. } else if ( $width == 'column_13' || $width == '1/3' ) {
  117. $width = array( 'vc_col-sm-4' );
  118. } else if ( $width == 'column_13-23' ) {
  119. $width = array( 'vc_col-sm-4', 'vc_col-sm-8' );
  120. } else if ( $width == 'column_13-13-13' ) {
  121. $width = array( 'vc_col-sm-4', 'vc_col-sm-4', 'vc_col-sm-4' );
  122. } else if ( $width == 'column_12' || $width == '1/2' ) {
  123. $width = array( 'vc_col-sm-6' );
  124. } else if ( $width == 'column_12-12' ) {
  125. $width = array( 'vc_col-sm-6', 'vc_col-sm-6' );
  126. } else if ( $width == 'column_23' || $width == '2/3' ) {
  127. $width = array( 'vc_col-sm-8' );
  128. } else if ( $width == 'column_34' || $width == '3/4' ) {
  129. $width = array( 'vc_col-sm-9' );
  130. } else if ( $width == 'column_16' || $width == '1/6' ) {
  131. $width = array( 'vc_col-sm-2' );
  132. } else if ( $width == 'column_56' || $width == '5/6' ) {
  133. $width = array( 'vc_col-sm-10' );
  134. } else {
  135. $width = array( '' );
  136. }
  137. for ( $i = 0; $i < count( $width ); $i ++ ) {
  138. $output .= '<div ' . $this->mainHtmlBlockParams( $width, $i ) . '>';
  139. $output .= str_replace( "%column_size%", wpb_translateColumnWidthToFractional( $width[$i] ), $column_controls );
  140. $output .= '<div class="wpb_element_wrapper">';
  141. $output .= '<div ' . $this->containerHtmlBlockParams( $width, $i ) . '>';
  142. $output .= do_shortcode( shortcode_unautop( $content ) );
  143. $output .= '</div>';
  144. if ( isset( $this->settings['params'] ) ) {
  145. $inner = '';
  146. foreach ( $this->settings['params'] as $param ) {
  147. $param_value = isset( $$param['param_name'] ) ? $$param['param_name'] : '';
  148. if ( is_array( $param_value ) ) {
  149. // Get first element from the array
  150. reset( $param_value );
  151. $first_key = key( $param_value );
  152. $param_value = $param_value[$first_key];
  153. }
  154. $inner .= $this->singleParamHtmlHolder( $param, $param_value );
  155. }
  156. $output .= $inner;
  157. }
  158. $output .= '</div>';
  159. $output .= str_replace( "%column_size%", wpb_translateColumnWidthToFractional( $width[$i] ), $column_controls_bottom );
  160. $output .= '</div>';
  161. }
  162. return $output;
  163. }
  164. /**
  165. * @return string
  166. */
  167. public function customAdminBlockParams() {
  168. return '';
  169. }
  170. /**
  171. * @param $width
  172. * @param $i
  173. *
  174. * @return string
  175. */
  176. public function mainHtmlBlockParams( $width, $i ) {
  177. return 'data-element_type="' . $this->settings["base"] . '" data-vc-column-width="' . wpb_vc_get_column_width_indent( $width[$i] ) . '" class="wpb_' . $this->settings['base'] . ' wpb_sortable ' . $this->templateWidth() . ' wpb_content_holder"' . $this->customAdminBlockParams();
  178. }
  179. /**
  180. * @param $width
  181. * @param $i
  182. *
  183. * @return string
  184. */
  185. public function containerHtmlBlockParams( $width, $i ) {
  186. return 'class="wpb_column_container vc_container_for_children"';
  187. }
  188. /**
  189. * @param string $content
  190. *
  191. * @return string
  192. */
  193. public function template( $content = '' ) {
  194. return $this->contentAdmin( $this->atts );
  195. }
  196. /**
  197. * @return string
  198. */
  199. protected function templateWidth() {
  200. return '<%= window.vc_convert_column_size(params.width) %>';
  201. }
  202. /**
  203. * @param string $font_color
  204. *
  205. * @return string
  206. */
  207. public function buildStyle( $font_color = '' ) {
  208. $style = '';
  209. if ( !empty( $font_color ) ) {
  210. $style .= vc_get_css_color( 'color', $font_color );
  211. }
  212. return empty( $style ) ? $style : ' style="' . esc_attr($style) . '"';
  213. }
  214. }