Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.47 KB | None | 0 0
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3.     die( '-1' );
  4. }
  5.  
  6. class WPBakeryShortCode_VC_Single_image extends WPBakeryShortCode {
  7.  
  8.     function __construct( $settings ) {
  9.         parent::__construct( $settings );
  10.  
  11.         $this->jsScripts();
  12.     }
  13.  
  14.     public function jsScripts() {
  15.         wp_register_script( 'zoom', vc_asset_url( 'lib/bower/zoom/jquery.zoom.min.js' ), array(), WPB_VC_VERSION );
  16.  
  17.         wp_register_script( 'vc_image_zoom', vc_asset_url( 'lib/vc_image_zoom/vc_image_zoom.min.js' ), array(
  18.             'jquery',
  19.             'zoom',
  20.         ), WPB_VC_VERSION, true );
  21.     }
  22.  
  23.     public function singleParamHtmlHolder( $param, $value ) {
  24.         $output = '';
  25.         // Compatibility fixes
  26.         $old_names = array(
  27.             'yellow_message',
  28.             'blue_message',
  29.             'green_message',
  30.             'button_green',
  31.             'button_grey',
  32.             'button_yellow',
  33.             'button_blue',
  34.             'button_red',
  35.             'button_orange',
  36.         );
  37.         $new_names = array(
  38.             'alert-block',
  39.             'alert-info',
  40.             'alert-success',
  41.             'btn-success',
  42.             'btn',
  43.             'btn-info',
  44.             'btn-primary',
  45.             'btn-danger',
  46.             'btn-warning',
  47.         );
  48.         $value = str_ireplace( $old_names, $new_names, $value );
  49.  
  50.         $param_name = isset( $param['param_name'] ) ? $param['param_name'] : '';
  51.         $type = isset( $param['type'] ) ? $param['type'] : '';
  52.         $class = isset( $param['class'] ) ? $param['class'] : '';
  53.  
  54.         if ( 'attach_image' === $param['type'] && 'image' === $param_name ) {
  55.             $output .= '<input type="hidden" class="wpb_vc_param_value ' . $param_name . ' ' . $type . ' ' . $class . '" name="' . $param_name . '" value="' . $value . '" />';
  56.             $element_icon = $this->settings( 'icon' );
  57.             $img = wpb_getImageBySize( array(
  58.                 'attach_id' => (int) preg_replace( '/[^\d]/', '', $value ),
  59.                 'thumb_size' => 'thumbnail',
  60.             ) );
  61.             $this->setSettings( 'logo', ( $img ? $img['thumbnail'] : '<img width="150" height="150" src="' . vc_asset_url( 'vc/blank.gif' ) . '" class="attachment-thumbnail vc_general vc_element-icon"  data-name="' . $param_name . '" alt="" title="" style="display: none;" />' ) . '<span class="no_image_image vc_element-icon' . ( ! empty( $element_icon ) ? ' ' . $element_icon : '' ) . ( $img && ! empty( $img['p_img_large'][0] ) ? ' image-exists' : '' ) . '" /><a href="#" class="column_edit_trigger' . ( $img && ! empty( $img['p_img_large'][0] ) ? ' image-exists' : '' ) . '">' . __( 'Add image', 'js_composer' ) . '</a>' );
  62.             $output .= $this->outputTitleTrue( $this->settings['name'] );
  63.         } elseif ( ! empty( $param['holder'] ) ) {
  64.             if ( 'input' === $param['holder'] ) {
  65.                 $output .= '<' . $param['holder'] . ' readonly="true" class="wpb_vc_param_value ' . $param_name . ' ' . $type . ' ' . $class . '" name="' . $param_name . '" value="' . $value . '">';
  66.             } elseif ( in_array( $param['holder'], array( 'img', 'iframe' ) ) ) {
  67.                 $output .= '<' . $param['holder'] . ' class="wpb_vc_param_value ' . $param_name . ' ' . $type . ' ' . $class . '" name="' . $param_name . '" src="' . $value . '">';
  68.             } elseif ( 'hidden' !== $param['holder'] ) {
  69.                 $output .= '<' . $param['holder'] . ' class="wpb_vc_param_value ' . $param_name . ' ' . $type . ' ' . $class . '" name="' . $param_name . '">' . $value . '</' . $param['holder'] . '>';
  70.             }
  71.         }
  72.  
  73.         if ( ! empty( $param['admin_label'] ) && true === $param['admin_label'] ) {
  74.             $output .= '<span class="vc_admin_label admin_label_' . $param['param_name'] . ( empty( $value ) ? ' hidden-label' : '' ) . '"><label>' . $param['heading'] . '</label>: ' . $value . '</span>';
  75.         }
  76.  
  77.         return $output;
  78.     }
  79.  
  80.     public function getImageSquareSize( $img_id, $img_size ) {
  81.         if ( preg_match_all( '/(\d+)x(\d+)/', $img_size, $sizes ) ) {
  82.             $exact_size = array(
  83.                 'width' => isset( $sizes[1][0] ) ? $sizes[1][0] : '0',
  84.                 'height' => isset( $sizes[2][0] ) ? $sizes[2][0] : '0',
  85.             );
  86.         } else {
  87.             $image_downsize = image_downsize( $img_id, $img_size );
  88.             $exact_size = array(
  89.                 'width' => $image_downsize[1],
  90.                 'height' => $image_downsize[2],
  91.             );
  92.         }
  93.         $exact_size_int_w = (int) $exact_size['width'];
  94.         $exact_size_int_h = (int) $exact_size['height'];
  95.         if ( isset( $exact_size['width'] ) && $exact_size_int_w !== $exact_size_int_h ) {
  96.             $img_size = $exact_size_int_w > $exact_size_int_h
  97.                 ? $exact_size['height'] . 'x' . $exact_size['height']
  98.                 : $exact_size['width'] . 'x' . $exact_size['width'];
  99.         }
  100.  
  101.         return $img_size;
  102.     }
  103.  
  104.     protected function outputTitle( $title ) {
  105.         return '';
  106.     }
  107.  
  108.     protected function outputTitleTrue( $title ) {
  109.         return '<h4 class="wpb_element_title">' . $title . ' ' . $this->settings( 'logo' ) . '</h4>';
  110.     }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement