Move plugin data translation and display markup to plugins page. Props DD32. see #3089

git-svn-id: http://svn.automattic.com/wordpress/trunk@8368 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-07-18 03:16:53 +00:00
parent bd434383f7
commit 8f29cb96e7
2 changed files with 37 additions and 42 deletions

View File

@ -112,53 +112,27 @@ function plugin_has_required_fields($plugin_contents) {
*/
function get_plugin_data( $plugin_file ) {
$plugin_data = plugin_get_contents( $plugin_file );
preg_match( '|Plugin Name:(.*)$|mi', $plugin_data, $plugin_name );
preg_match( '|Plugin URI:(.*)$|mi', $plugin_data, $plugin_uri );
preg_match( '|Plugin Name:(.*)$|mi', $plugin_data, $name );
preg_match( '|Plugin URI:(.*)$|mi', $plugin_data, $uri );
preg_match( '|Version:(.*)|i', $plugin_data, $version );
preg_match( '|Description:(.*)$|mi', $plugin_data, $description );
preg_match( '|Author:(.*)$|mi', $plugin_data, $author_name );
preg_match( '|Author URI:(.*)$|mi', $plugin_data, $author_uri );
preg_match( '|Text Domain:(.*)$|mi', $plugin_data, $text_domain );
preg_match( '|Domain Path:(.*)$|mi', $plugin_data, $domain_path );
if ( preg_match( "|Version:(.*)|i", $plugin_data, $version ))
$version = trim( $version[1] );
else
$version = '';
if( preg_match( '|Text Domain:(.*)$|mi', $plugin_data, $text_domain ) ) {
if( preg_match( '|Domain Path:(.*)$|mi', $plugin_data, $domain_path ) )
$domain_path = trim( $domain_path[1] );
$text_domain = trim( $text_domain[1] );
if( !empty( $text_domain ) ) {
if( !empty( $domain_path ) )
load_plugin_textdomain($text_domain, dirname($plugin_file). $domain_path);
else
load_plugin_textdomain($text_domain, dirname($plugin_file));
}
$description[1] = translate(trim($description[1]), $text_domain);
$plugin_name[1] = translate(trim($plugin_name[1]), $text_domain);
$plugin_uri[1] = translate(trim($plugin_uri[1]), $text_domain);
$author_name[1] = translate(trim($author_name[1]), $text_domain);
$author_uri[1] = translate(trim($author_uri[1]), $text_domain);
foreach ( array( 'name', 'uri', 'version', 'description', 'author_name', 'author_uri', 'text_domain', 'domain_path' ) as $field ) {
if ( !empty( ${$field} ) )
${$field} = trim(${$field}[1]);
else
${$field} = '';
}
$description = wptexturize( trim( $description[1] ));
$name = $plugin_name[1];
$name = trim( $name );
$plugin = $name;
if ('' != trim($plugin_uri[1]) && '' != $name ) {
$plugin = '<a href="' . trim( $plugin_uri[1] ) . '" title="'.__( 'Visit plugin homepage' ).'">'.$plugin.'</a>';
}
if ('' == $author_uri[1] ) {
$author = trim( $author_name[1] );
} else {
$author = '<a href="' . trim( $author_uri[1] ) . '" title="'.__( 'Visit author homepage' ).'">' . trim( $author_name[1] ) . '</a>';
}
return array('Name' => $name, 'Title' => $plugin, 'Description' => $description, 'Author' => $author, 'Version' => $version);
return array(
'Name' => $name, 'PluginURI' => $uri, 'Description' => $description,
'Author' => $author_name, 'AuthorURI' => $author_uri, 'Version' => $version,
'TextDomain' => $text_domain, 'DomainPath' => $domain_path
);
}
function get_plugins($plugin_folder = '') {

View File

@ -216,6 +216,27 @@ $plugins_allowedtags = array('a' => array('href' => array(),'title' => array()),
foreach( (array)$all_plugins as $plugin_file => $plugin_data) {
//Translate fields
if( !empty($plugin_data['TextDomain']) ) {
if( !empty( $plugin_data['DomainPath'] ) )
load_plugin_textdomain($plugin_data['TextDomain'], dirname($plugin_file). $plugin_data['DomainPath']);
else
load_plugin_textdomain($plugin_data['TextDomain'], dirname($plugin_file));
foreach ( array('Name', 'PluginURI', 'Description', 'Author', 'AuthorURI', 'Version') as $field )
$plugin_data[ $field ] = translate($plugin_data[ $field ], $plugin_data['TextDomain']);
}
//Apply Markup
$plugin_data['Title'] = $plugin_data['Name'];
if ( !empty($plugin_data['PluginURI']) && !empty($plugin_data['Name']) )
$plugin_data['Title'] = '<a href="' . $plugin_data['PluginURI'] . '" title="'.__( 'Visit plugin homepage' ).'">' . $plugin_data['Name'] . '</a>';
if ( ! empty($plugin_data['AuthorURI']) )
$plugin_data['Author'] = '<a href="' . $plugin_data['AuthorURI'] . '" title="'.__( 'Visit author homepage' ).'">' . $plugin_data['Author'] . '</a>';
$plugin_data['Description'] = wptexturize( $plugin_data['Description'] );
// Sanitize all displayed data
$plugin_data['Title'] = wp_kses($plugin_data['Title'], $plugins_allowedtags);
$plugin_data['Version'] = wp_kses($plugin_data['Version'], $plugins_allowedtags);
@ -263,7 +284,7 @@ function print_plugins_table($plugins, $context = '') {
if( 'active' == $context )
$action_links[] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&amp;plugin=' . $plugin_file, 'deactivate-plugin_' . $plugin_file) . '" title="' . __('Deactivate this plugin') . '" class="delete">' . __('Deactivate') . '</a>';
else //Available or Recently deactivated
else //Inactive or Recently deactivated
$action_links[] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin') . '" class="edit">' . __('Activate') . '</a>';
if ( current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) )