skipv1_0_0WP_File

The Facebook Fanpage Import skip v1 0 WP File class.

Defined (1)

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

/includes/skip/elements/forms/wp-file.php  
  1. class WP_File extends Textfield{ 
  2.  
  3. /** 
  4. * Constructor 
  5. * @since 1.0.0 
  6. * @param string $name Name of WP File Field. 
  7. * @param array/string $args List of Arguments. 
  8. */ 
  9. function __construct( $name, $label = FALSE, $args = array() ) { 
  10.  
  11. $defaults = array( 
  12. 'wp_browse' => __( 'Add Media' ) 
  13. ); 
  14.  
  15. $args = wp_parse_args( $args, $defaults ); 
  16. $this->wp_browse = $args[ 'wp_browse' ]; 
  17.  
  18. parent::__construct( $name, $label, $args ); 
  19.  
  20. /** 
  21. * Rendering WP File field 
  22. * @package Skip 
  23. * @since 1.0 
  24. * @return string $html Returns The HTML Code. 
  25. */  
  26. public function render() { 
  27. global $skip_javascripts; 
  28.  
  29. $skip_javascripts[] = '  
  30. $("#skip_filebutton_' . $this->params[ 'id' ] . '").click(function() { 
  31.  
  32. if ( typeof wp !== "undefined" && wp.media && wp.media.editor ) { 
  33. wp.media.editor.open( "#skip_filebutton_' . $this->params[ 'id' ] . '" ); 
  34.  
  35. wp.media.editor.send.attachment = function( props, attachment ) { 
  36. console.log( attachment ); 
  37.  
  38. if( attachment.url.match(/\.jpg$/i) || attachment.url.match(/\.gif$/i) || attachment.url.match(/\.png$/i) ) { 
  39. preview_file = attachment.url; 
  40. }else{ 
  41. preview_file = attachment.icon; 
  42.  
  43. $( "#skip_file_' . $this->params[ 'id' ] . '" ).val( attachment.url ); 
  44. $( "#skip_filepreview_' . $this->params[ 'id' ] . '" ).attr( "src", preview_file );  
  45. $( "#skip_filename_' . $this->params[ 'id' ] . ' a" ).text( preview_file.replace( /.*\//, "" ) ); 
  46. $( "#skip_filename_' . $this->params[ 'id' ] . ' a" ).attr( "href", preview_file );  
  47. $( "#skip_filepreview_src_' . $this->params[ 'id' ] . '" ).val( preview_file ); 
  48.  
  49. }); 
  50.  
  51. $( "#skip_filepreview_' . $this->params[ 'id' ] . '" ).attr( "src", $( "#skip_filepreview_src_' . $this->params[ 'id' ] . '" ).val() ); 
  52.  
  53. '; 
  54.  
  55.  
  56. $html = $this->before_element; 
  57. $html.= '<div class="skip_file ui-state-default ui-corner-all">'; 
  58. $html.= '<div class="skip_filepreview">'; 
  59. $html.= '<img id="skip_filepreview_' . $this->params[ 'id' ] . '" class="skip_filepreview_image" />'; 
  60. if( isset( $this->value ) )  
  61. $html.= '<div class="skip_filename" id="skip_filename_' . $this->params[ 'id' ] . '"><a href="' . $this->value . '" target="_blank">' . basename( $this->value ) . '</a></div>'; 
  62.  
  63. $html.= '</div>'; 
  64. $html.= '<div class="skip_fileuploader">'; 
  65. $html.= '<input id="skip_file_' . $this->params[ 'id' ] . '" class="skip_file_name" type="text" name="' . $this->params[ 'name' ] . '" value="' . $this->value . '" />'; 
  66. $html.= '<input id="skip_filebutton_' . $this->params[ 'id' ] . '" class="skip_file_button" type="button" value="' . $this->wp_browse . '" />'; 
  67. $html.= hidden( $this->name . '_icon_src', array( 'id' => 'skip_filepreview_src_' . $this->params[ 'id' ] ) ); 
  68. $html.= '</div>'; 
  69. $html.= '</div>'; 
  70. $html.= $this->after_element; 
  71.  
  72. return $html; 
  73.