vc-row.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. die( '-1' );
  4. }
  5. /**
  6. * WPBakery WPBakery Page Builder row
  7. *
  8. * @package WPBakeryPageBuilder
  9. *
  10. */
  11. class WPBakeryShortCode_Vc_Row extends WPBakeryShortCode {
  12. protected $predefined_atts = array(
  13. 'el_class' => '',
  14. );
  15. public $nonDraggableClass = 'vc-non-draggable-row';
  16. /**
  17. * @param $settings
  18. */
  19. public function __construct( $settings ) {
  20. parent::__construct( $settings );
  21. $this->shortcodeScripts();
  22. }
  23. protected function shortcodeScripts() {
  24. wp_register_script( 'vc_jquery_skrollr_js', vc_asset_url( 'lib/bower/skrollr/dist/skrollr.min.js' ), array( 'jquery' ), WPB_VC_VERSION, true );
  25. wp_register_script( 'vc_youtube_iframe_api_js', 'https://www.youtube.com/iframe_api', array(), WPB_VC_VERSION, true );
  26. }
  27. /**
  28. * @param $atts
  29. * @param null $content
  30. * @return mixed|string
  31. */
  32. protected function content( $atts, $content = null ) {
  33. $prefix = '';
  34. return $prefix . $this->loadTemplate( $atts, $content );
  35. }
  36. /**
  37. * This returs block controls
  38. */
  39. public function getLayoutsControl() {
  40. global $vc_row_layouts;
  41. $controls_layout = '<span class="vc_row_layouts vc_control">';
  42. foreach ( $vc_row_layouts as $layout ) {
  43. $controls_layout .= '<a class="vc_control-set-column set_columns" data-cells="' . $layout['cells'] . '" data-cells-mask="' . $layout['mask'] . '" title="' . $layout['title'] . '"><i class="vc-composer-icon vc-c-icon-' . $layout['icon_class'] . '"></i></a> ';
  44. }
  45. $controls_layout .= '<br/><a class="vc_control-set-column set_columns custom_columns" data-cells="custom" data-cells-mask="custom" title="' . esc_attr__( 'Custom layout', 'js_composer' ) . '">' . esc_html__( 'Custom', 'js_composer' ) . '</a> ';
  46. $controls_layout .= '</span>';
  47. return $controls_layout;
  48. }
  49. /**
  50. * @param $controls
  51. * @param string $extended_css
  52. * @return string
  53. * @throws \Exception
  54. */
  55. public function getColumnControls( $controls, $extended_css = '' ) {
  56. $output = '<div class="vc_controls vc_controls-row controls_row vc_clearfix">';
  57. $controls_end = '</div>';
  58. // Create columns
  59. $controls_layout = $this->getLayoutsControl();
  60. $controls_move = ' <a class="vc_control column_move vc_column-move" href="#" title="' . esc_attr__( 'Drag row to reorder', 'js_composer' ) . '" data-vc-control="move"><i class="vc-composer-icon vc-c-icon-dragndrop"></i></a>';
  61. $moveAccess = vc_user_access()->part( 'dragndrop' )->checkStateAny( true, null )->get();
  62. if ( ! $moveAccess ) {
  63. $controls_move = '';
  64. }
  65. $controls_add = ' <a class="vc_control column_add vc_column-add" href="#" title="' . esc_attr__( 'Add column', 'js_composer' ) . '" data-vc-control="add"><i class="vc-composer-icon vc-c-icon-add"></i></a>';
  66. $controls_delete = '<a class="vc_control column_delete vc_column-delete" href="#" title="' . esc_attr__( 'Delete this row', 'js_composer' ) . '" data-vc-control="delete"><i class="vc-composer-icon vc-c-icon-delete_empty"></i></a>';
  67. $controls_edit = ' <a class="vc_control column_edit vc_column-edit" href="#" title="' . esc_attr__( 'Edit this row', 'js_composer' ) . '" data-vc-control="edit"><i class="vc-composer-icon vc-c-icon-mode_edit"></i></a>';
  68. $controls_clone = ' <a class="vc_control column_clone vc_column-clone" href="#" title="' . esc_attr__( 'Clone this row', 'js_composer' ) . '" data-vc-control="clone"><i class="vc-composer-icon vc-c-icon-content_copy"></i></a>';
  69. $controls_toggle = ' <a class="vc_control column_toggle vc_column-toggle" href="#" title="' . esc_attr__( 'Toggle row', 'js_composer' ) . '" data-vc-control="toggle"><i class="vc-composer-icon vc-c-icon-arrow_drop_down"></i></a>';
  70. $editAccess = vc_user_access_check_shortcode_edit( $this->shortcode );
  71. $allAccess = vc_user_access_check_shortcode_all( $this->shortcode );
  72. if ( is_array( $controls ) && ! empty( $controls ) ) {
  73. foreach ( $controls as $control ) {
  74. $control_var = 'controls_' . $control;
  75. if ( ( $editAccess && 'edit' === $control ) || $allAccess ) {
  76. if ( isset( ${$control_var} ) ) {
  77. $output .= ${$control_var};
  78. }
  79. }
  80. }
  81. $output .= $controls_end;
  82. } elseif ( is_string( $controls ) ) {
  83. $control_var = 'controls_' . $controls;
  84. if ( ( $editAccess && 'edit' === $controls ) || $allAccess ) {
  85. if ( isset( ${$control_var} ) ) {
  86. $output .= ${$control_var} . $controls_end;
  87. }
  88. }
  89. } else {
  90. $row_edit_clone_delete = '<span class="vc_row_edit_clone_delete">';
  91. if ( $allAccess ) {
  92. $row_edit_clone_delete .= $controls_delete . $controls_clone . $controls_edit;
  93. } elseif ( $editAccess ) {
  94. $row_edit_clone_delete .= $controls_edit;
  95. }
  96. $row_edit_clone_delete .= $controls_toggle;
  97. $row_edit_clone_delete .= '</span>';
  98. if ( $allAccess ) {
  99. $output .= '<div>' . $controls_move . $controls_layout . $controls_add . '</div>' . $row_edit_clone_delete . $controls_end;
  100. } elseif ( $editAccess ) {
  101. $output .= $row_edit_clone_delete . $controls_end;
  102. } else {
  103. $output .= $row_edit_clone_delete . $controls_end;
  104. }
  105. }
  106. return $output;
  107. }
  108. /**
  109. * @param $atts
  110. * @param null $content
  111. * @return string
  112. * @throws \Exception
  113. */
  114. public function contentAdmin( $atts, $content = null ) {
  115. $atts = shortcode_atts( $this->predefined_atts, $atts );
  116. $output = '';
  117. $column_controls = $this->getColumnControls( $this->settings( 'controls' ) );
  118. $output .= '<div data-element_type="' . $this->settings['base'] . '" class="' . $this->cssAdminClass() . '">';
  119. $output .= str_replace( '%column_size%', 1, $column_controls );
  120. $output .= '<div class="wpb_element_wrapper">';
  121. $output .= '<div class="vc_row vc_row-fluid wpb_row_container vc_container_for_children">';
  122. if ( '' === $content && ! empty( $this->settings['default_content_in_template'] ) ) {
  123. $output .= do_shortcode( shortcode_unautop( $this->settings['default_content_in_template'] ) );
  124. } else {
  125. $output .= do_shortcode( shortcode_unautop( $content ) );
  126. }
  127. $output .= '</div>';
  128. if ( isset( $this->settings['params'] ) ) {
  129. $inner = '';
  130. foreach ( $this->settings['params'] as $param ) {
  131. if ( ! isset( $param['param_name'] ) ) {
  132. continue;
  133. }
  134. $param_value = isset( $atts[ $param['param_name'] ] ) ? $atts[ $param['param_name'] ] : '';
  135. if ( is_array( $param_value ) ) {
  136. // Get first element from the array
  137. reset( $param_value );
  138. $first_key = key( $param_value );
  139. $param_value = $param_value[ $first_key ];
  140. }
  141. $inner .= $this->singleParamHtmlHolder( $param, $param_value );
  142. }
  143. $output .= $inner;
  144. }
  145. $output .= '</div>';
  146. $output .= '</div>';
  147. return $output;
  148. }
  149. /**
  150. * @return string
  151. * @throws \Exception
  152. */
  153. public function cssAdminClass() {
  154. $sortable = ( vc_user_access_check_shortcode_all( $this->shortcode ) ? ' wpb_sortable' : ' ' . $this->nonDraggableClass );
  155. return 'wpb_' . $this->settings['base'] . $sortable . '' . ( ! empty( $this->settings['class'] ) ? ' ' . $this->settings['class'] : '' );
  156. }
  157. /**
  158. * @return string
  159. * @deprecated 4.5 - due to it is not used anywhere? 4.5
  160. * @typo Bock - Block
  161. */
  162. public function customAdminBockParams() {
  163. // this function is depreacted
  164. return '';
  165. }
  166. /**
  167. * @param string $bg_image
  168. * @param string $bg_color
  169. * @param string $bg_image_repeat
  170. * @param string $font_color
  171. * @param string $padding
  172. * @param string $margin_bottom
  173. *
  174. * @return string
  175. * @deprecated 4.5
  176. *
  177. */
  178. public function buildStyle( $bg_image = '', $bg_color = '', $bg_image_repeat = '', $font_color = '', $padding = '', $margin_bottom = '' ) {
  179. // this function is deprecated
  180. $has_image = false;
  181. $style = '';
  182. $image_url = wp_get_attachment_url( $bg_image );
  183. if ( $image_url ) {
  184. $has_image = true;
  185. $style .= 'background-image: url(' . $image_url . ');';
  186. }
  187. if ( ! empty( $bg_color ) ) {
  188. $style .= vc_get_css_color( 'background-color', $bg_color );
  189. }
  190. if ( ! empty( $bg_image_repeat ) && $has_image ) {
  191. if ( 'cover' === $bg_image_repeat ) {
  192. $style .= 'background-repeat:no-repeat;background-size: cover;';
  193. } elseif ( 'contain' === $bg_image_repeat ) {
  194. $style .= 'background-repeat:no-repeat;background-size: contain;';
  195. } elseif ( 'no-repeat' === $bg_image_repeat ) {
  196. $style .= 'background-repeat: no-repeat;';
  197. }
  198. }
  199. if ( ! empty( $font_color ) ) {
  200. $style .= vc_get_css_color( 'color', $font_color );
  201. }
  202. if ( '' !== $padding ) {
  203. $style .= 'padding: ' . ( preg_match( '/(px|em|\%|pt|cm)$/', $padding ) ? $padding : $padding . 'px' ) . ';';
  204. }
  205. if ( '' !== $margin_bottom ) {
  206. $style .= 'margin-bottom: ' . ( preg_match( '/(px|em|\%|pt|cm)$/', $margin_bottom ) ? $margin_bottom : $margin_bottom . 'px' ) . ';';
  207. }
  208. return empty( $style ) ? '' : ' style="' . esc_attr( $style ) . '"';
  209. }
  210. }