vc-gallery.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. die( '-1' );
  4. }
  5. /**
  6. * Class WPBakeryShortCode_Vc_gallery
  7. */
  8. class WPBakeryShortCode_Vc_Gallery extends WPBakeryShortCode {
  9. /**
  10. * WPBakeryShortCode_Vc_gallery constructor.
  11. * @param $settings
  12. */
  13. public function __construct( $settings ) {
  14. parent::__construct( $settings );
  15. $this->shortcodeScripts();
  16. }
  17. public function shortcodeScripts() {
  18. wp_register_script( 'vc_grid-js-imagesloaded', vc_asset_url( 'lib/bower/imagesloaded/imagesloaded.pkgd.min.js' ), array( 'jquery' ), WPB_VC_VERSION, true );
  19. }
  20. /**
  21. * @param $param
  22. * @param $value
  23. * @return string
  24. */
  25. public function singleParamHtmlHolder( $param, $value ) {
  26. $output = '';
  27. // Compatibility fixes
  28. $old_names = array(
  29. 'yellow_message',
  30. 'blue_message',
  31. 'green_message',
  32. 'button_green',
  33. 'button_grey',
  34. 'button_yellow',
  35. 'button_blue',
  36. 'button_red',
  37. 'button_orange',
  38. );
  39. $new_names = array(
  40. 'alert-block',
  41. 'alert-info',
  42. 'alert-success',
  43. 'btn-success',
  44. 'btn',
  45. 'btn-info',
  46. 'btn-primary',
  47. 'btn-danger',
  48. 'btn-warning',
  49. );
  50. $value = str_ireplace( $old_names, $new_names, $value );
  51. $param_name = isset( $param['param_name'] ) ? $param['param_name'] : '';
  52. $type = isset( $param['type'] ) ? $param['type'] : '';
  53. $class = isset( $param['class'] ) ? $param['class'] : '';
  54. if ( isset( $param['holder'] ) && 'hidden' !== $param['holder'] ) {
  55. $output .= '<' . $param['holder'] . ' class="wpb_vc_param_value ' . $param_name . ' ' . $type . ' ' . $class . '" name="' . $param_name . '">' . $value . '</' . $param['holder'] . '>';
  56. }
  57. if ( 'images' === $param_name ) {
  58. $images_ids = empty( $value ) ? array() : explode( ',', trim( $value ) );
  59. $output .= '<ul class="attachment-thumbnails' . ( empty( $images_ids ) ? ' image-exists' : '' ) . '" data-name="' . $param_name . '">';
  60. foreach ( $images_ids as $image ) {
  61. $img = wpb_getImageBySize( array(
  62. 'attach_id' => (int) $image,
  63. 'thumb_size' => 'thumbnail',
  64. ) );
  65. $output .= ( $img ? '<li>' . $img['thumbnail'] . '</li>' : '<li><img width="150" height="150" test="' . $image . '" src="' . esc_url( vc_asset_url( 'vc/blank.gif' ) ) . '" class="attachment-thumbnail" alt="" title="" /></li>' );
  66. }
  67. $output .= '</ul>';
  68. $output .= '<a href="#" class="column_edit_trigger' . ( ! empty( $images_ids ) ? ' image-exists' : '' ) . '">' . esc_html__( 'Add images', 'js_composer' ) . '</a>';
  69. }
  70. return $output;
  71. }
  72. }