skipv1_0_0File

The Facebook Fanpage Import skip v1 0 File class.

Defined (1)

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

/includes/skip/elements/forms/file.php  
  1. class File extends Form_Element{ 
  2.  
  3. var $delete; 
  4. var $wp_browse; 
  5.  
  6. /** 
  7. * Constructor 
  8. * @since 1.0 
  9. * @param string $name Name of File Field. 
  10. * @param array/string $args List of Arguments. 
  11. */ 
  12. function __construct( $name, $label = FALSE, $args = array() ) { 
  13.  
  14. $defaults = array( 
  15. 'delete' => FALSE,  
  16. 'save' => TRUE 
  17. ); 
  18.  
  19. $args = wp_parse_args( $args, $defaults ); 
  20. $this->delete = $args[ 'delete' ]; 
  21.  
  22. $args[ 'close_tag' ] = FALSE; // No Close tag for Input type Text 
  23. $args[ 'label' ] = $label; 
  24.  
  25. parent::__construct( 'input', $name, $args ); 
  26.  
  27. $this->del_param( 'value' ); // Not needed here 
  28. $this->add_param( 'type', 'file' ); // This is a text field! 
  29.  
  30.  
  31. /** 
  32. * Rendering Editor field 
  33. * @package Skip 
  34. * @since 1.0 
  35. * @return string $html Returns The HTML Code. 
  36. */  
  37. public function render() { 
  38. global $skip_javascripts; 
  39.  
  40. $file_url = $this->value[ 'url' ]; 
  41. $file_path = $this->value[ 'file' ]; 
  42.  
  43. $skip_javascripts[] = '  
  44. $( "#skip_filepreview_' . $this->params[ 'id' ] . '" ).attr( "src", $( "#skip_filename_' . $this->params[ 'id' ] . ' a" ).attr( "href" ) ); 
  45. '; 
  46.  
  47. $html_before = '<div class="skip_file ui-state-default ui-corner-all">'; 
  48. $html_before.= '<div class="skip_filepreview">'; 
  49. $html_before.= '<img id="skip_filepreview_' . $this->params[ 'id' ] . '" class="skip_filepreview_image" />'; 
  50. if( isset( $this->value[ 'url' ] ) )  
  51. $html_before.= '<div class="skip_filename" id="skip_filename_' . $this->params[ 'id' ] . '"><a href="' . $file_url . '" target="_blank">' . basename( $file_path ) . '</a></div>'; 
  52.  
  53. $html_before.= '</div>'; 
  54. $html_before.= '<div class="skip_fileuploader">'; 
  55.  
  56. $html_after = '</div></div>'; 
  57.  
  58. $this->before( $html_before ); 
  59. $this->after( $html_after ); 
  60.  
  61. $this->add_param( 'class', 'skip_file_fileinput' ); 
  62.  
  63. return parent::render(); 
  64.  
  65. /** 
  66. * Saving Editor field 
  67. * @package Skip 
  68. * @since 1.0 
  69. */  
  70. public function save() { 
  71.  
  72. if( array_key_exists( 'CONTENT_LENGTH', $_SERVER ) ) 
  73. if( $_SERVER['CONTENT_LENGTH'] > max_upload() ) 
  74. $this->error_msgs[] = $this->errors[ 2 ]; 
  75.  
  76. if( array_key_exists( $this->form_name . '_value', $_FILES ) ): 
  77.  
  78. if( file_exists( $_FILES[ $this->form_name . '_value' ][ 'tmp_name' ][ $this->name ] ) ): 
  79.  
  80. $file[ 'name' ] = $_FILES[ $this->form_name . '_value' ][ 'name' ][ $this->name ]; 
  81. $file[ 'type' ] = $_FILES[ $this->form_name . '_value' ][ 'type' ][ $this->name ]; 
  82. $file[ 'tmp_name' ] = $_FILES[ $this->form_name . '_value' ][ 'tmp_name' ][ $this->name ]; 
  83. $file[ 'error' ] = $_FILES[ $this->form_name . '_value' ][ 'error' ][ $this->name ]; 
  84. $file[ 'size' ] = $_FILES[ $this->form_name . '_value' ][ 'size' ][ $this->name ]; 
  85.  
  86. $file_before = $this->value(); 
  87.  
  88. if( file_exists( $file_before[ 'file' ] ) ) 
  89. unlink( $file_before[ 'file' ] ); 
  90.  
  91. $override = array( 
  92. 'test_form' => FALSE,  
  93. 'action' => 'update' 
  94. ); 
  95.  
  96. $wp_file = wp_handle_upload( $file, $override ); 
  97.  
  98. @unlink( $file[ 'tmp_name' ] ); 
  99.  
  100. update_option( $this->option_name, $wp_file ); 
  101. endif; 
  102.  
  103. endif;