vc-gitem.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. die( '-1' );
  4. }
  5. /**
  6. * Class WPBakeryShortCode_Vc_Gitem
  7. */
  8. class WPBakeryShortCode_Vc_Gitem extends WPBakeryShortCodesContainer {
  9. /**
  10. * @param $atts
  11. * @param null $content
  12. * @return string
  13. * @throws \Exception
  14. */
  15. public function contentAdmin( $atts, $content = null ) {
  16. /**
  17. * @var string @el_class - comes
  18. */
  19. extract( shortcode_atts( $this->predefined_atts, $atts ) );
  20. $output = '';
  21. $column_controls = $this->getControls( $this->settings( 'controls' ) );
  22. $output .= '<div ' . $this->mainHtmlBlockParams( '12', '' ) . '>';
  23. $output .= $column_controls;
  24. $output .= '<div ' . $this->containerHtmlBlockParams( '12', '' ) . '>';
  25. $output .= $this->itemGrid();
  26. $output .= do_shortcode( shortcode_unautop( $content ) );
  27. $output .= '</div>';
  28. if ( isset( $this->settings['params'] ) ) {
  29. $inner = '';
  30. foreach ( $this->settings['params'] as $param ) {
  31. $param_value = isset( ${$param['param_name']} ) ? ${$param['param_name']} : '';
  32. if ( is_array( $param_value ) ) {
  33. // Get first element from the array
  34. reset( $param_value );
  35. $first_key = key( $param_value );
  36. $param_value = $param_value[ $first_key ];
  37. }
  38. $inner .= $this->singleParamHtmlHolder( $param, $param_value );
  39. }
  40. $output .= $inner;
  41. }
  42. $output .= '</div>';
  43. $output .= '</div>';
  44. return $output;
  45. }
  46. /**
  47. * @param $width
  48. * @param $i
  49. * @return string
  50. * @throws \Exception
  51. */
  52. public function mainHtmlBlockParams( $width, $i ) {
  53. $sortable = ( vc_user_access_check_shortcode_all( $this->shortcode ) ? 'wpb_sortable' : $this->nonDraggableClass );
  54. return 'data-element_type="' . $this->settings['base'] . '" class="' . $this->settings['base'] . '-shortcode ' . $sortable . ' wpb_content_holder vc_shortcodes_container"' . $this->customAdminBlockParams();
  55. }
  56. /**
  57. * @return string
  58. */
  59. public function itemGrid() {
  60. $output = '<div class="vc_row"><div class="vc_col-xs-4 vc_col-xs-offset-4"><div class="vc_gitem-add-c-col" data-vc-gitem="add-c" data-vc-position="top"></div></div></div><div class="vc_row"><div class="vc_col-xs-4 vc_gitem-add-c-left"><div class="vc_gitem-add-c-col" data-vc-gitem="add-c" data-vc-position="left"></div></div><div class="vc_col-xs-4 vc_gitem-ab-zone" data-vc-gitem="add-ab"></div><div class="vc_col-xs-4 vc_gitem-add-c-right"><div class="vc_gitem-add-c-col" data-vc-gitem="add-c" data-vc-position="right"></div></div></div><div class="vc_row"><div class="vc_col-xs-4 vc_col-xs-offset-4 vc_gitem-add-c-bottom"><div class="vc_gitem-add-c-col" data-vc-gitem="add-c" data-vc-position="bottom"></div></div></div>';
  61. return $output;
  62. }
  63. /**
  64. * @param $width
  65. * @param $i
  66. * @return string
  67. */
  68. public function containerHtmlBlockParams( $width, $i ) {
  69. return 'class="vc_gitem-content"';
  70. }
  71. /**
  72. * Get rendered controls
  73. *
  74. * @param array $controls
  75. *
  76. * @return string
  77. * @throws \Exception
  78. */
  79. public function getControls( $controls ) {
  80. if ( ! is_array( $controls ) || empty( $controls ) ) {
  81. return '';
  82. }
  83. $buttons = array();
  84. $editAccess = vc_user_access_check_shortcode_edit( $this->shortcode );
  85. $allAccess = vc_user_access_check_shortcode_all( $this->shortcode );
  86. foreach ( $controls as $control ) {
  87. switch ( $control ) {
  88. case 'add':
  89. if ( $allAccess ) {
  90. $buttons[] = '<a class="vc_control-btn vc_control-btn-add" href="#" title="' . esc_attr__( 'Add to this grid item', 'js_composer' ) . '" data-vc-control="add"><i class="vc_icon"></i></a>';
  91. }
  92. break;
  93. case 'edit':
  94. if ( $editAccess ) {
  95. $buttons[] = '<a class="vc_control-btn vc_control-btn-edit" href="#" title="' . esc_attr__( 'Edit this grid item', 'js_composer' ) . '" data-vc-control="edit"><i class="vc_icon"></i></a>';
  96. }
  97. break;
  98. case 'delete':
  99. if ( $allAccess ) {
  100. $buttons[] = '<a class="vc_control-btn vc_control-btn-delete" href="#" title="' . esc_attr__( 'Delete this grid item ', 'js_composer' ) . '" data-vc-control="delete"><i class="vc_icon"></i></a>';
  101. }
  102. break;
  103. }
  104. }
  105. $html = '<div class="vc_controls vc_controls-dark vc_controls-visible">' . implode( ' ', $buttons ) . '</div>';
  106. return $html;
  107. }
  108. }