Ticket #8964: wptrac_8964_patch4.diff
File wptrac_8964_patch4.diff, 8.8 KB (added by , 15 years ago) |
---|
-
wp-includes/theme.php
162 162 * @return array Theme data. 163 163 */ 164 164 function get_theme_data( $theme_file ) { 165 $default_headers = array( 166 'Name' => 'Theme Name', 167 'URI' => 'Plugin URI', 168 'Description' => 'Description', 169 'Author' => 'Author', 170 'AuthorURI' => 'Author URI', 171 'Version' => 'Version', 172 'Template' => 'Template', 173 'Status' => 'Status', 174 'Tags' => 'Tags' 175 ); 176 165 177 $themes_allowed_tags = array( 166 178 'a' => array( 167 179 'href' => array(),'title' => array() … … 177 189 'strong' => array() 178 190 ); 179 191 180 $theme_data = implode( '', file( $theme_file ) ); 181 $theme_data = str_replace ( '\r', '\n', $theme_data ); 182 if ( preg_match( '|Theme Name:(.*)$|mi', $theme_data, $theme_name ) ) 183 $name = $theme = wp_kses( _cleanup_header_comment($theme_name[1]), $themes_allowed_tags ); 184 else 185 $name = $theme = ''; 192 $theme_data = get_file_data( $theme_file, $default_headers, 'theme' ); 186 193 187 if ( preg_match( '|Theme URI:(.*)$|mi', $theme_data, $theme_uri ) ) 188 $theme_uri = esc_url( _cleanup_header_comment($theme_uri[1]) ); 189 else 190 $theme_uri = ''; 194 $theme_data['Name'] = $title = wp_kses( $theme_data['Name'], $themes_allowed_tags ); 191 195 192 if ( preg_match( '|Description:(.*)$|mi', $theme_data, $description ) ) 193 $description = wptexturize( wp_kses( _cleanup_header_comment($description[1]), $themes_allowed_tags ) ); 194 else 195 $description = ''; 196 $theme_data['URI'] = esc_url( $theme_data['URI'] ); 196 197 197 if ( preg_match( '|Author URI:(.*)$|mi', $theme_data, $author_uri ) ) 198 $author_uri = esc_url( _cleanup_header_comment($author_uri[1]) ); 199 else 200 $author_uri = ''; 198 $theme_data['Description'] = wptexturize( wp_kses( $theme_data['Description'], $themes_allowed_tags ) ); 201 199 202 if ( preg_match( '|Template:(.*)$|mi', $theme_data, $template ) ) 203 $template = wp_kses( _cleanup_header_comment($template[1]), $themes_allowed_tags ); 204 else 205 $template = ''; 200 $theme_data['AuthorURI'] = esc_url( $theme_data['AuthorURI'] ); 206 201 207 if ( preg_match( '|Version:(.*)|i', $theme_data, $version ) ) 208 $version = wp_kses( _cleanup_header_comment($version[1]), $themes_allowed_tags ); 209 else 210 $version = ''; 202 $theme_data['Template'] = wp_kses( $theme_data['Template'], $themes_allowed_tags ); 211 203 212 if ( preg_match('|Status:(.*)|i', $theme_data, $status) ) 213 $status = wp_kses( _cleanup_header_comment($status[1]), $themes_allowed_tags ); 204 $theme_data['Version'] = wp_kses( $theme_data['Version'], $themes_allowed_tags ); 205 206 if ( $theme_data['Status'] == '' ) 207 $theme_data['Status'] = 'publish'; 214 208 else 215 $ status = 'publish';209 $theme_data['Status'] = wp_kses( $theme_data['Status'], $themes_allowed_tags ); 216 210 217 if ( preg_match('|Tags:(.*)|i', $theme_data, $tags))218 $t ags = array_map( 'trim', explode( ',', wp_kses( _cleanup_header_comment($tags[1]), array() ) ));211 if ( $theme_data['Tags'] == '' ) 212 $theme_data['Tags'] = array(); 219 213 else 220 $t ags = array();214 $theme_data['Tags'] = array_map( 'trim', explode( ',', wp_kses( $theme_data['Tags'], array() ) ) ); 221 215 222 if ( preg_match( '|Author:(.*)$|mi', $theme_data, $author_name ) ) { 223 if ( empty( $author_uri ) ) { 224 $author = wp_kses( _cleanup_header_comment($author_name[1]), $themes_allowed_tags ); 216 if ( $theme_data['Author'] == '' ) { 217 $theme_data['Author'] = __('Anonymous'); 218 } else { 219 if ( empty( $theme_data['AuthorURI'] ) ) { 220 $theme_data['Author'] = wp_kses( $theme_data['Author'], $themes_allowed_tags ); 225 221 } else { 226 $author = sprintf( '<a href="%1$s" title="%2$s">%3$s</a>', $ author_uri, __( 'Visit author homepage' ), wp_kses( _cleanup_header_comment($author_name[1]), $themes_allowed_tags ) );222 $author = sprintf( '<a href="%1$s" title="%2$s">%3$s</a>', $theme_data['AuthorURI'], __( 'Visit author homepage' ), wp_kses( $theme_data['Author'], $themes_allowed_tags ) ); 227 223 } 228 } else {229 $author = __('Anonymous');230 224 } 225 unset( $theme_data['AuthorURI'] ); 231 226 232 return array( 'Name' => $name, 'Title' => $theme, 'URI' => $theme_uri, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template, 'Status' => $status, 'Tags' => $tags );227 return $theme_data; 233 228 } 234 229 235 230 /** -
wp-includes/functions.php
3395 3395 3396 3396 update_option('wp_trash_meta', $trash_meta); 3397 3397 } 3398 3399 /** 3400 * Parse the file contents to retrieve its metadata. 3401 * 3402 * Searches for metadata for a file, such as a plugin or theme. Each piece of 3403 * metadata must be on its own line. For a field spanning multple lines, it 3404 * must not have any newlines or only parts of it will be displayed. 3405 * 3406 * Some users have issues with opening large files and manipulating the contents 3407 * for want is usually the first 1kiB or 2kiB. This function stops pulling in 3408 * the file contents when it has all of the required data. 3409 * 3410 * The first 8kiB of the file will be pulled in and if the file data is not 3411 * within that first 8kiB, then the author should correct their plugin file 3412 * and move the data headers to the top. 3413 * 3414 * The file is assumed to have permissions to allow for scripts to read 3415 * the file. This is not checked however and the file is only opened for 3416 * reading. 3417 * 3418 * @since 2.9.0 3419 * 3420 * @param string $file Path to the file 3421 * @param bool $markup If the returned data should have HTML markup applied 3422 * @param bool $translate If the returned data should be translated 3423 * @return An array of headers 3424 */ 3425 function get_file_data( $file, $default_headers, $context = '' ) { 3426 // We don't need to write to the file, so just open for reading. 3427 $fp = fopen( $file, 'r' ); 3428 3429 // Pull only the first 8kiB of the file in. 3430 $file_data = fread( $fp, 8192 ); 3431 3432 // PHP will close file handle, but we are good citizens. 3433 fclose( $fp ); 3434 3435 if( $context != '' ) { 3436 $extra_headers = apply_filters( "extra_$context".'_headers', array() ); 3437 3438 $extra_headers = array_flip( $extra_headers ); 3439 foreach( $extra_headers as $key=>$value ) { 3440 $extra_headers[$key] = $key; 3441 } 3442 $all_headers = array_merge($extra_headers, $default_headers); 3443 } else { 3444 $all_headers = $default_headers; 3445 } 3446 3447 3448 foreach ( $all_headers as $field => $regex ) { 3449 preg_match( '/' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, ${$field}); 3450 if ( !empty( ${$field} ) ) 3451 ${$field} = _cleanup_header_comment( ${$field}[1] ); 3452 else 3453 ${$field} = ''; 3454 } 3455 3456 $file_data = compact( array_keys( $all_headers ) ); 3457 3458 return $file_data; 3459 } 3398 3460 ?> 3461 No newline at end of file -
wp-admin/includes/plugin.php
66 66 * @return array See above for description. 67 67 */ 68 68 function get_plugin_data( $plugin_file, $markup = true, $translate = true ) { 69 // We don't need to write to the file, so just open for reading.70 $fp = fopen($plugin_file, 'r');71 69 72 // Pull only the first 8kiB of the file in. 73 $plugin_data = fread( $fp, 8192 ); 70 $default_headers = array( 71 'Name' => 'Plugin Name', 72 'PluginURI' => 'Plugin URI', 73 'Version' => 'Version', 74 'Description' => 'Description', 75 'Author' => 'Author', 76 'AuthorURI' => 'Author URI', 77 'TextDomain' => 'Text Domain', 78 'DomainPath' => 'Domain Path' 79 ); 74 80 75 // PHP will close file handle, but we are good citizens. 76 fclose($fp); 81 $plugin_data = get_file_data( $plugin_file, $default_headers, 'plugin' ); 77 82 78 preg_match( '|Plugin Name:(.*)$|mi', $plugin_data, $name );79 preg_match( '|Plugin URI:(.*)$|mi', $plugin_data, $uri );80 preg_match( '|Version:(.*)|i', $plugin_data, $version );81 preg_match( '|Description:(.*)$|mi', $plugin_data, $description );82 preg_match( '|Author:(.*)$|mi', $plugin_data, $author_name );83 preg_match( '|Author URI:(.*)$|mi', $plugin_data, $author_uri );84 preg_match( '|Text Domain:(.*)$|mi', $plugin_data, $text_domain );85 preg_match( '|Domain Path:(.*)$|mi', $plugin_data, $domain_path );86 87 foreach ( array( 'name', 'uri', 'version', 'description', 'author_name', 'author_uri', 'text_domain', 'domain_path' ) as $field ) {88 if ( !empty( ${$field} ) )89 ${$field} = _cleanup_header_comment(${$field}[1]);90 else91 ${$field} = '';92 }93 94 $plugin_data = array(95 'Name' => $name, 'Title' => $name, 'PluginURI' => $uri, 'Description' => $description,96 'Author' => $author_name, 'AuthorURI' => $author_uri, 'Version' => $version,97 'TextDomain' => $text_domain, 'DomainPath' => $domain_path98 );99 83 if ( $markup || $translate ) 100 $plugin_data = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, $markup, $translate);84 $plugin_data = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, $markup, $translate ); 101 85 102 86 return $plugin_data; 103 87 }