vc-section.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. die( '-1' );
  4. }
  5. /**
  6. * WPBakery WPBakery Page Builder section
  7. *
  8. * @package WPBakeryPageBuilder
  9. *
  10. */
  11. class WPBakeryShortCode_Vc_Section extends WPBakeryShortCodesContainer {
  12. /**
  13. * @param $width
  14. * @param $i
  15. * @return string
  16. */
  17. public function containerHtmlBlockParams( $width, $i ) {
  18. return 'class="vc_section_container vc_container_for_children"';
  19. }
  20. /**
  21. * @param $settings
  22. */
  23. public function __construct( $settings ) {
  24. parent::__construct( $settings );
  25. $this->shortcodeScripts();
  26. }
  27. protected function shortcodeScripts() {
  28. wp_register_script( 'vc_jquery_skrollr_js', vc_asset_url( 'lib/bower/skrollr/dist/skrollr.min.js' ), array( 'jquery' ), WPB_VC_VERSION, true );
  29. wp_register_script( 'vc_youtube_iframe_api_js', 'https://www.youtube.com/iframe_api', array(), WPB_VC_VERSION, true );
  30. }
  31. /**
  32. * @return string
  33. * @throws \Exception
  34. */
  35. public function cssAdminClass() {
  36. $sortable = ( vc_user_access_check_shortcode_all( $this->shortcode ) ? ' wpb_sortable' : ' ' . $this->nonDraggableClass );
  37. return 'wpb_' . $this->settings['base'] . $sortable . '' . ( ! empty( $this->settings['class'] ) ? ' ' . $this->settings['class'] : '' );
  38. }
  39. /**
  40. * @param string $controls
  41. * @param string $extended_css
  42. * @return string
  43. * @throws \Exception
  44. */
  45. public function getColumnControls( $controls = 'full', $extended_css = '' ) {
  46. $controls_start = '<div class="vc_controls vc_controls-visible controls_column' . ( ! empty( $extended_css ) ? " {$extended_css}" : '' ) . '">';
  47. $output = '<div class="vc_controls vc_controls-row controls_row vc_clearfix">';
  48. $controls_end = '</div>';
  49. // Create columns
  50. $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>';
  51. $moveAccess = vc_user_access()->part( 'dragndrop' )->checkStateAny( true, null )->get();
  52. if ( ! $moveAccess ) {
  53. $controls_move = '';
  54. }
  55. $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>';
  56. $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>';
  57. $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>';
  58. $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>';
  59. $editAccess = vc_user_access_check_shortcode_edit( $this->shortcode );
  60. $allAccess = vc_user_access_check_shortcode_all( $this->shortcode );
  61. $row_edit_clone_delete = '<span class="vc_row_edit_clone_delete">';
  62. if ( 'add' === $controls ) {
  63. return $controls_start . $controls_add . $controls_end;
  64. }
  65. if ( $allAccess ) {
  66. $row_edit_clone_delete .= $controls_delete . $controls_clone . $controls_edit;
  67. } elseif ( $editAccess ) {
  68. $row_edit_clone_delete .= $controls_edit;
  69. }
  70. $row_edit_clone_delete .= '</span>';
  71. if ( $allAccess ) {
  72. $output .= '<div>' . $controls_move . $controls_add . '</div>' . $row_edit_clone_delete . $controls_end;
  73. } elseif ( $editAccess ) {
  74. $output .= $row_edit_clone_delete . $controls_end;
  75. } else {
  76. $output .= $row_edit_clone_delete . $controls_end;
  77. }
  78. return $output;
  79. }
  80. /**
  81. * @param $atts
  82. * @param null $content
  83. * @return string
  84. * @throws \Exception
  85. */
  86. public function contentAdmin( $atts, $content = null ) {
  87. $width = '';
  88. $atts = shortcode_atts( $this->predefined_atts, $atts );
  89. $output = '';
  90. $column_controls = $this->getColumnControls();
  91. $output .= '<div data-element_type="' . $this->settings['base'] . '" class="' . $this->cssAdminClass() . '">';
  92. $output .= str_replace( '%column_size%', 1, $column_controls );
  93. $output .= '<div class="wpb_element_wrapper">';
  94. if ( isset( $this->settings['custom_markup'] ) && '' !== $this->settings['custom_markup'] ) {
  95. $markup = $this->settings['custom_markup'];
  96. $output .= $this->customMarkup( $markup );
  97. } else {
  98. $output .= '<div ' . $this->containerHtmlBlockParams( $width, 1 ) . '>';
  99. $output .= do_shortcode( shortcode_unautop( $content ) );
  100. $output .= '</div>';
  101. }
  102. if ( isset( $this->settings['params'] ) ) {
  103. $inner = '';
  104. foreach ( $this->settings['params'] as $param ) {
  105. if ( ! isset( $param['param_name'] ) ) {
  106. continue;
  107. }
  108. $param_value = isset( $atts[ $param['param_name'] ] ) ? $atts[ $param['param_name'] ] : '';
  109. if ( is_array( $param_value ) ) {
  110. // Get first element from the array
  111. reset( $param_value );
  112. $first_key = key( $param_value );
  113. $param_value = $param_value[ $first_key ];
  114. }
  115. $inner .= $this->singleParamHtmlHolder( $param, $param_value );
  116. }
  117. $output .= $inner;
  118. }
  119. $output .= '</div>';
  120. if ( $this->backened_editor_prepend_controls ) {
  121. $output .= $this->getColumnControls( 'add', 'vc_section-bottom-controls bottom-controls' );
  122. }
  123. $output .= '</div>';
  124. return $output;
  125. }
  126. }