mp-wp_genesis 1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * File contains all the administration image manipulation functions.
mp-wp_genesis 4 *
mp-wp_genesis 5 * @package WordPress
mp-wp_genesis 6 * @subpackage Administration
mp-wp_genesis 7 */
mp-wp_genesis 8
mp-wp_genesis 9 /** The descriptions for theme files. */
mp-wp_genesis 10 $wp_file_descriptions = array (
mp-wp_genesis 11 'index.php' => __( 'Main Index Template' ),
mp-wp_genesis 12 'style.css' => __( 'Stylesheet' ),
mp-wp_genesis 13 'rtl.css' => __( 'RTL Stylesheet' ),
mp-wp_genesis 14 'comments.php' => __( 'Comments' ),
mp-wp_genesis 15 'comments-popup.php' => __( 'Popup Comments' ),
mp-wp_genesis 16 'footer.php' => __( 'Footer' ),
mp-wp_genesis 17 'header.php' => __( 'Header' ),
mp-wp_genesis 18 'sidebar.php' => __( 'Sidebar' ),
mp-wp_genesis 19 'archive.php' => __( 'Archives' ),
mp-wp_genesis 20 'category.php' => __( 'Category Template' ),
mp-wp_genesis 21 'page.php' => __( 'Page Template' ),
mp-wp_genesis 22 'search.php' => __( 'Search Results' ),
mp-wp_genesis 23 'searchform.php' => __( 'Search Form' ),
mp-wp_genesis 24 'single.php' => __( 'Single Post' ),
mp-wp_genesis 25 '404.php' => __( '404 Template' ),
mp-wp_genesis 26 'link.php' => __( 'Links Template' ),
mp-wp_genesis 27 'functions.php' => __( 'Theme Functions' ),
mp-wp_genesis 28 'attachment.php' => __( 'Attachment Template' ),
mp-wp_genesis 29 'image.php' => __('Image Attachment Template'),
mp-wp_genesis 30 'video.php' => __('Video Attachment Template'),
mp-wp_genesis 31 'audio.php' => __('Audio Attachment Template'),
mp-wp_genesis 32 'application.php' => __('Application Attachment Template'),
mp-wp_genesis 33 'my-hacks.php' => __( 'my-hacks.php (legacy hacks support)' ),
mp-wp_genesis 34 '.htaccess' => __( '.htaccess (for rewrite rules )' ),
mp-wp_genesis 35 // Deprecated files
mp-wp_genesis 36 'wp-layout.css' => __( 'Stylesheet' ), 'wp-comments.php' => __( 'Comments Template' ), 'wp-comments-popup.php' => __( 'Popup Comments Template' ));
mp-wp_genesis 37
mp-wp_genesis 38 /**
mp-wp_genesis 39 * {@internal Missing Short Description}}
mp-wp_genesis 40 *
mp-wp_genesis 41 * @since unknown
mp-wp_genesis 42 *
mp-wp_genesis 43 * @return unknown
mp-wp_genesis 44 */
mp-wp_genesis 45 function get_home_path() {
mp-wp_genesis 46 $home = get_option( 'home' );
mp-wp_genesis 47 if ( $home != '' && $home != get_option( 'siteurl' ) ) {
mp-wp_genesis 48 $home_path = parse_url( $home );
mp-wp_genesis 49 $home_path = $home_path['path'];
mp-wp_genesis 50 $root = str_replace( $_SERVER["PHP_SELF"], '', $_SERVER["SCRIPT_FILENAME"] );
mp-wp_genesis 51 $home_path = trailingslashit( $root.$home_path );
mp-wp_genesis 52 } else {
mp-wp_genesis 53 $home_path = ABSPATH;
mp-wp_genesis 54 }
mp-wp_genesis 55
mp-wp_genesis 56 return $home_path;
mp-wp_genesis 57 }
mp-wp_genesis 58
mp-wp_genesis 59 /**
mp-wp_genesis 60 * {@internal Missing Short Description}}
mp-wp_genesis 61 *
mp-wp_genesis 62 * @since unknown
mp-wp_genesis 63 *
mp-wp_genesis 64 * @return unknown
mp-wp_genesis 65 */
mp-wp_genesis 66 function get_temp_dir() {
mp-wp_genesis 67 if ( defined('WP_TEMP_DIR') )
mp-wp_genesis 68 return trailingslashit(WP_TEMP_DIR);
mp-wp_genesis 69
mp-wp_genesis 70 $temp = WP_CONTENT_DIR . '/';
mp-wp_genesis 71 if ( is_dir($temp) && is_writable($temp) )
mp-wp_genesis 72 return $temp;
mp-wp_genesis 73
mp-wp_genesis 74 if ( function_exists('sys_get_temp_dir') )
mp-wp_genesis 75 return trailingslashit(sys_get_temp_dir());
mp-wp_genesis 76
mp-wp_genesis 77 return '/tmp/';
mp-wp_genesis 78 }
mp-wp_genesis 79
mp-wp_genesis 80 /**
mp-wp_genesis 81 * {@internal Missing Short Description}}
mp-wp_genesis 82 *
mp-wp_genesis 83 * @since unknown
mp-wp_genesis 84 *
mp-wp_genesis 85 * @param unknown_type $filename
mp-wp_genesis 86 * @param unknown_type $dir
mp-wp_genesis 87 * @return unknown
mp-wp_genesis 88 */
mp-wp_genesis 89 function wp_tempnam($filename = '', $dir = ''){
mp-wp_genesis 90 if ( empty($dir) )
mp-wp_genesis 91 $dir = get_temp_dir();
mp-wp_genesis 92 $filename = basename($filename);
mp-wp_genesis 93 if ( empty($filename) )
mp-wp_genesis 94 $filename = time();
mp-wp_genesis 95
mp-wp_genesis 96 $filename = $dir . wp_unique_filename($dir, $filename);
mp-wp_genesis 97 touch($filename);
mp-wp_genesis 98 return $filename;
mp-wp_genesis 99 }
mp-wp_genesis 100
mp-wp_genesis 101 /**
mp-wp_genesis 102 * {@internal Missing Short Description}}
mp-wp_genesis 103 *
mp-wp_genesis 104 * @since unknown
mp-wp_genesis 105 *
mp-wp_genesis 106 * @param array $file Reference to a single element of $_FILES. Call the function once for each uploaded file.
mp-wp_genesis 107 * @param array $overrides Optional. An associative array of names=>values to override default variables with extract( $overrides, EXTR_OVERWRITE ).
mp-wp_genesis 108 * @return array On success, returns an associative array of file attributes. On failure, returns $overrides['upload_error_handler'](&$file, $message ) or array( 'error'=>$message ).
mp-wp_genesis 109 */
mp-wp_genesis 110 function wp_handle_upload( &$file, $overrides = false, $time = null ) {
mp-wp_genesis 111 // The default error handler.
mp-wp_genesis 112 if (! function_exists( 'wp_handle_upload_error' ) ) {
mp-wp_genesis 113 function wp_handle_upload_error( &$file, $message ) {
mp-wp_genesis 114 return array( 'error'=>$message );
mp-wp_genesis 115 }
mp-wp_genesis 116 }
mp-wp_genesis 117
mp-wp_genesis 118 // You may define your own function and pass the name in $overrides['upload_error_handler']
mp-wp_genesis 119 $upload_error_handler = 'wp_handle_upload_error';
mp-wp_genesis 120
mp-wp_genesis 121 // You may define your own function and pass the name in $overrides['unique_filename_callback']
mp-wp_genesis 122 $unique_filename_callback = null;
mp-wp_genesis 123
mp-wp_genesis 124 // $_POST['action'] must be set and its value must equal $overrides['action'] or this:
mp-wp_genesis 125 $action = 'wp_handle_upload';
mp-wp_genesis 126
mp-wp_genesis 127 // Courtesy of php.net, the strings that describe the error indicated in $_FILES[{form field}]['error'].
mp-wp_genesis 128 $upload_error_strings = array( false,
mp-wp_genesis 129 __( "The uploaded file exceeds the <code>upload_max_filesize</code> directive in <code>php.ini</code>." ),
mp-wp_genesis 130 __( "The uploaded file exceeds the <em>MAX_FILE_SIZE</em> directive that was specified in the HTML form." ),
mp-wp_genesis 131 __( "The uploaded file was only partially uploaded." ),
mp-wp_genesis 132 __( "No file was uploaded." ),
mp-wp_genesis 133 '',
mp-wp_genesis 134 __( "Missing a temporary folder." ),
mp-wp_genesis 135 __( "Failed to write file to disk." ));
mp-wp_genesis 136
mp-wp_genesis 137 // All tests are on by default. Most can be turned off by $override[{test_name}] = false;
mp-wp_genesis 138 $test_form = true;
mp-wp_genesis 139 $test_size = true;
mp-wp_genesis 140
mp-wp_genesis 141 // If you override this, you must provide $ext and $type!!!!
mp-wp_genesis 142 $test_type = true;
mp-wp_genesis 143 $mimes = false;
mp-wp_genesis 144
mp-wp_genesis 145 // Install user overrides. Did we mention that this voids your warranty?
mp-wp_genesis 146 if ( is_array( $overrides ) )
mp-wp_genesis 147 extract( $overrides, EXTR_OVERWRITE );
mp-wp_genesis 148
mp-wp_genesis 149 // A correct form post will pass this test.
mp-wp_genesis 150 if ( $test_form && (!isset( $_POST['action'] ) || ($_POST['action'] != $action ) ) )
mp-wp_genesis 151 return $upload_error_handler( $file, __( 'Invalid form submission.' ));
mp-wp_genesis 152
mp-wp_genesis 153 // A successful upload will pass this test. It makes no sense to override this one.
mp-wp_genesis 154 if ( $file['error'] > 0 )
mp-wp_genesis 155 return $upload_error_handler( $file, $upload_error_strings[$file['error']] );
mp-wp_genesis 156
mp-wp_genesis 157 // A non-empty file will pass this test.
mp-wp_genesis 158 if ( $test_size && !($file['size'] > 0 ) )
mp-wp_genesis 159 return $upload_error_handler( $file, __( 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini.' ));
mp-wp_genesis 160
mp-wp_genesis 161 // A properly uploaded file will pass this test. There should be no reason to override this one.
mp-wp_genesis 162 if (! @ is_uploaded_file( $file['tmp_name'] ) )
mp-wp_genesis 163 return $upload_error_handler( $file, __( 'Specified file failed upload test.' ));
mp-wp_genesis 164
mp-wp_genesis 165 // A correct MIME type will pass this test. Override $mimes or use the upload_mimes filter.
mp-wp_genesis 166 if ( $test_type ) {
mp-wp_genesis 167 $wp_filetype = wp_check_filetype( $file['name'], $mimes );
mp-wp_genesis 168
mp-wp_genesis 169 extract( $wp_filetype );
mp-wp_genesis 170
mp-wp_genesis 171 if ( ( !$type || !$ext ) && !current_user_can( 'unfiltered_upload' ) )
mp-wp_genesis 172 return $upload_error_handler( $file, __( 'File type does not meet security guidelines. Try another.' ));
mp-wp_genesis 173
mp-wp_genesis 174 if ( !$ext )
mp-wp_genesis 175 $ext = ltrim(strrchr($file['name'], '.'), '.');
mp-wp_genesis 176
mp-wp_genesis 177 if ( !$type )
mp-wp_genesis 178 $type = $file['type'];
mp-wp_genesis 179 }
mp-wp_genesis 180
mp-wp_genesis 181 // A writable uploads dir will pass this test. Again, there's no point overriding this one.
mp-wp_genesis 182 if ( ! ( ( $uploads = wp_upload_dir($time) ) && false === $uploads['error'] ) )
mp-wp_genesis 183 return $upload_error_handler( $file, $uploads['error'] );
mp-wp_genesis 184
mp-wp_genesis 185 $filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback );
mp-wp_genesis 186
mp-wp_genesis 187 // Move the file to the uploads dir
mp-wp_genesis 188 $new_file = $uploads['path'] . "/$filename";
mp-wp_genesis 189 if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) ) {
mp-wp_genesis 190 return $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] ) );
mp-wp_genesis 191 }
mp-wp_genesis 192
mp-wp_genesis 193 // Set correct file permissions
mp-wp_genesis 194 $stat = stat( dirname( $new_file ));
mp-wp_genesis 195 $perms = $stat['mode'] & 0000666;
mp-wp_genesis 196 @ chmod( $new_file, $perms );
mp-wp_genesis 197
mp-wp_genesis 198 // Compute the URL
mp-wp_genesis 199 $url = $uploads['url'] . "/$filename";
mp-wp_genesis 200
mp-wp_genesis 201 $return = apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => $type ) );
mp-wp_genesis 202
mp-wp_genesis 203 return $return;
mp-wp_genesis 204 }
mp-wp_genesis 205
mp-wp_genesis 206 ?>