skipv1_0_0File
The WordPress Core skip v1 0 File class.
Defined (1)
The class is defined in the following location(s).
- /includes/skip/elements/forms/file.php
- class File extends Form_Element{
- var $delete;
- var $wp_browse;
- /**
- * Constructor
- * @since 1.0
- * @param string $name Name of File Field.
- * @param array/string $args List of Arguments.
- */
- function __construct( $name, $label = FALSE, $args = array() ) {
- $defaults = array(
- 'delete' => FALSE,
- 'save' => TRUE
- );
- $args = wp_parse_args( $args, $defaults );
- $this->delete = $args[ 'delete' ];
- $args[ 'close_tag' ] = FALSE; // No Close tag for Input type Text
- $args[ 'label' ] = $label;
- parent::__construct( 'input', $name, $args );
- $this->del_param( 'value' ); // Not needed here
- $this->add_param( 'type', 'file' ); // This is a text field!
- }
- /**
- * Rendering Editor field
- * @package Skip
- * @since 1.0
- * @return string $html Returns The HTML Code.
- */
- public function render() {
- global $skip_javascripts;
- $file_url = $this->value[ 'url' ];
- $file_path = $this->value[ 'file' ];
- $skip_javascripts[] = '
- $( "#skip_filepreview_' . $this->params[ 'id' ] . '" ).attr( "src", $( "#skip_filename_' . $this->params[ 'id' ] . ' a" ).attr( "href" ) );
- ';
- $html_before = '<div class="skip_file ui-state-default ui-corner-all">';
- $html_before.= '<div class="skip_filepreview">';
- $html_before.= '<img id="skip_filepreview_' . $this->params[ 'id' ] . '" class="skip_filepreview_image" />';
- if( isset( $this->value[ 'url' ] ) )
- $html_before.= '<div class="skip_filename" id="skip_filename_' . $this->params[ 'id' ] . '"><a href="' . $file_url . '" target="_blank">' . basename( $file_path ) . '</a></div>';
- $html_before.= '</div>';
- $html_before.= '<div class="skip_fileuploader">';
- $html_after = '</div></div>';
- $this->before( $html_before );
- $this->after( $html_after );
- $this->add_param( 'class', 'skip_file_fileinput' );
- return parent::render();
- }
- /**
- * Saving Editor field
- * @package Skip
- * @since 1.0
- */
- public function save() {
- if( array_key_exists( 'CONTENT_LENGTH', $_SERVER ) )
- if( $_SERVER['CONTENT_LENGTH'] > max_upload() )
- $this->error_msgs[] = $this->errors[ 2 ];
- if( array_key_exists( $this->form_name . '_value', $_FILES ) ):
- if( file_exists( $_FILES[ $this->form_name . '_value' ][ 'tmp_name' ][ $this->name ] ) ):
- $file[ 'name' ] = $_FILES[ $this->form_name . '_value' ][ 'name' ][ $this->name ];
- $file[ 'type' ] = $_FILES[ $this->form_name . '_value' ][ 'type' ][ $this->name ];
- $file[ 'tmp_name' ] = $_FILES[ $this->form_name . '_value' ][ 'tmp_name' ][ $this->name ];
- $file[ 'error' ] = $_FILES[ $this->form_name . '_value' ][ 'error' ][ $this->name ];
- $file[ 'size' ] = $_FILES[ $this->form_name . '_value' ][ 'size' ][ $this->name ];
- $file_before = $this->value();
- if( file_exists( $file_before[ 'file' ] ) )
- unlink( $file_before[ 'file' ] );
- $override = array(
- 'test_form' => FALSE,
- 'action' => 'update'
- );
- $wp_file = wp_handle_upload( $file, $override );
- @unlink( $file[ 'tmp_name' ] );
- update_option( $this->option_name, $wp_file );
- endif;
- endif;
- }
- }