WC_Predictive_Search_Uploader

The WooCommerce Predictive Search LITE WC Predictive Search Uploader class.

Defined (1)

The class is defined in the following location(s).

/admin/includes/uploader/class-uploader.php  
  1. class WC_Predictive_Search_Uploader extends WC_Predictive_Search_Admin_UI 
  2.  
  3. /** 
  4. * @var string 
  5. */ 
  6. private $admin_uploader_url; 
  7.  
  8. /**-----------------------------------------------------------------------------------*/ 
  9. /** Admin Uploader Constructor */ 
  10. /**-----------------------------------------------------------------------------------*/ 
  11. public function __construct() { 
  12. if ( is_admin() ) { 
  13.  
  14. // include scripts to Admin UI Interface 
  15. add_action( $this->plugin_name . '_init_scripts', array( $this, 'uploader_js' ) ); 
  16.  
  17. // include styles to Admin UI Interface 
  18. add_action( $this->plugin_name . '_init_styles', array( $this, 'uploader_style' ) ); 
  19.  
  20.  
  21. /**-----------------------------------------------------------------------------------*/ 
  22. /** admin_uploader_url */ 
  23. /**-----------------------------------------------------------------------------------*/ 
  24. public function admin_uploader_url() { 
  25. if ( $this->admin_uploader_url ) return $this->admin_uploader_url; 
  26. return $this->admin_uploader_url = untrailingslashit( plugins_url( '/', __FILE__ ) ); 
  27.  
  28. /**-----------------------------------------------------------------------------------*/ 
  29. /** Include Uploader Script */ 
  30. /**-----------------------------------------------------------------------------------*/ 
  31. public function uploader_js () { 
  32. wp_enqueue_script( 'a3-uploader-script', $this->admin_uploader_url() . '/uploader-script.js', array( 'jquery', 'thickbox' ) ); 
  33. if ( function_exists( 'wp_enqueue_media' ) ) { 
  34. wp_enqueue_media(); 
  35. } else { 
  36. wp_enqueue_script('media-upload'); 
  37.  
  38. /**-----------------------------------------------------------------------------------*/ 
  39. /** Include Uploader Style */ 
  40. /**-----------------------------------------------------------------------------------*/ 
  41. public function uploader_style () { 
  42. wp_enqueue_style( 'thickbox' ); 
  43. wp_enqueue_style( 'a3-uploader-style', $this->admin_uploader_url() . '/uploader.css' ); 
  44. if ( is_rtl() ) { 
  45. wp_enqueue_style( 'a3-uploader-style-rtl', $this->admin_uploader_url() . '/uploader.rtl.css' ); 
  46.  
  47. /**-----------------------------------------------------------------------------------*/ 
  48. /** Get Upload Input Field */ 
  49. /**-----------------------------------------------------------------------------------*/ 
  50. public function upload_input ( $name_attribute, $id_attribute = '', $value = '', $attachment_id = 0, $default_value = '', $field_name = '', $class = '', $css = '', $description = '', $strip_methods = true ) { 
  51. $output = ''; 
  52.  
  53. if ( trim( $value ) == '' ) $value = trim( $default_value ); 
  54.  
  55. if ( strstr( $name_attribute, ']' ) ) { 
  56. $attachment_id_name_attribute = substr_replace( $name_attribute, '_attachment_id', -1, 0 ); 
  57. } else { 
  58. $attachment_id_name_attribute = $name_attribute.'_attachment_id'; 
  59.  
  60. if ( $strip_methods === false ) { 
  61. $strip_methods = 0; 
  62. } else { 
  63. $strip_methods = 1; 
  64.  
  65. $output .= '<input type="hidden" name="'.$attachment_id_name_attribute.'" id="'.$id_attribute.'_attachment_id" value="'.$attachment_id.'" class=" a3_upload_attachment_id" />'; 
  66. $output .= '<input data-strip-methods="'.$strip_methods.'" type="text" name="'.$name_attribute.'" id="'.$id_attribute.'" value="'.esc_attr( $value ).'" class="'.$id_attribute. ' ' .$class.' a3_upload" style="'.$css.'" rel="'.$field_name.'" /> '; 
  67. $output .= '<input id="upload_'.$id_attribute.'" class="a3rev-ui-upload-button a3_upload_button button" type="button" value="'.__( 'Upload', 'woops' ).'" /> '.$description; 
  68.  
  69. $output .= '<div style="clear:both;"></div><div class="a3_screenshot" id="'.$id_attribute.'_image" style="'.( ( $value == '' ) ? 'display:none;' : 'display:block;' ).'">'; 
  70.  
  71. if ( $value != '' ) { 
  72. $remove = '<a href="javascript:(void);" class="a3_uploader_remove a3-plugin-ui-delete-icon"> </a>'; 
  73.  
  74. $image = preg_match( '/(^.*\.jpg|jpeg|png|gif|ico*)/i', $value ); 
  75.  
  76. if ( $image ) { 
  77. $output .= '<img class="a3_uploader_image" src="' . esc_url( $value ) . '" alt="" />'.$remove.''; 
  78. } else { 
  79. $parts = explode( "/", $value ); 
  80.  
  81. for( $i = 0; $i < sizeof( $parts ); ++$i ) { 
  82. $title = $parts[$i]; 
  83.  
  84. $output .= ''; 
  85.  
  86. $title = __( 'View File', 'woops' ); 
  87.  
  88. $output .= '<div class="a3_no_image"><span class="a3_file_link"><a href="'.esc_url( $value ).'" target="_blank" rel="a3_external">'.$title.'</a></span>'.$remove.'</div>'; 
  89.  
  90.  
  91. $output .= '</div>'; 
  92.  
  93. return $output;