Make WordPress Core

Changeset 8368


Ignore:
Timestamp:
07/18/2008 03:16:53 AM (16 years ago)
Author:
ryan
Message:

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

Location:
trunk/wp-admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/plugin.php

    r8367 r8368  
    113113function get_plugin_data( $plugin_file ) {
    114114    $plugin_data = plugin_get_contents( $plugin_file );
    115     preg_match( '|Plugin Name:(.*)$|mi', $plugin_data, $plugin_name );
    116     preg_match( '|Plugin URI:(.*)$|mi', $plugin_data, $plugin_uri );
     115    preg_match( '|Plugin Name:(.*)$|mi', $plugin_data, $name );
     116    preg_match( '|Plugin URI:(.*)$|mi', $plugin_data, $uri );
     117    preg_match( '|Version:(.*)|i', $plugin_data, $version );
    117118    preg_match( '|Description:(.*)$|mi', $plugin_data, $description );
    118119    preg_match( '|Author:(.*)$|mi', $plugin_data, $author_name );
    119120    preg_match( '|Author URI:(.*)$|mi', $plugin_data, $author_uri );
    120 
    121     if ( preg_match( "|Version:(.*)|i", $plugin_data, $version ))
    122         $version = trim( $version[1] );
    123     else
    124         $version = '';
    125 
    126     if( preg_match( '|Text Domain:(.*)$|mi', $plugin_data, $text_domain ) ) {
    127         if( preg_match( '|Domain Path:(.*)$|mi', $plugin_data, $domain_path ) )
    128             $domain_path = trim( $domain_path[1] );
    129 
    130         $text_domain = trim( $text_domain[1] );
    131 
    132         if( !empty( $text_domain ) ) {
    133             if( !empty( $domain_path ) )
    134                 load_plugin_textdomain($text_domain, dirname($plugin_file). $domain_path);
    135             else
    136                 load_plugin_textdomain($text_domain, dirname($plugin_file));
    137         }
    138 
    139         $description[1] = translate(trim($description[1]), $text_domain);
    140         $plugin_name[1] = translate(trim($plugin_name[1]), $text_domain);
    141         $plugin_uri[1] = translate(trim($plugin_uri[1]), $text_domain);
    142         $author_name[1] = translate(trim($author_name[1]), $text_domain);
    143         $author_uri[1] = translate(trim($author_uri[1]), $text_domain);
    144     }
    145 
    146     $description = wptexturize( trim( $description[1] ));
    147 
    148     $name = $plugin_name[1];
    149     $name = trim( $name );
    150     $plugin = $name;
    151     if ('' != trim($plugin_uri[1]) && '' != $name ) {
    152         $plugin = '<a href="' . trim( $plugin_uri[1] ) . '" title="'.__( 'Visit plugin homepage' ).'">'.$plugin.'</a>';
    153     }
    154 
    155     if ('' == $author_uri[1] ) {
    156         $author = trim( $author_name[1] );
    157     } else {
    158         $author = '<a href="' . trim( $author_uri[1] ) . '" title="'.__( 'Visit author homepage' ).'">' . trim( $author_name[1] ) . '</a>';
    159     }
    160 
    161     return array('Name' => $name, 'Title' => $plugin, 'Description' => $description, 'Author' => $author, 'Version' => $version);
     121    preg_match( '|Text Domain:(.*)$|mi', $plugin_data, $text_domain );
     122    preg_match( '|Domain Path:(.*)$|mi', $plugin_data, $domain_path );
     123
     124    foreach ( array( 'name', 'uri', 'version', 'description', 'author_name', 'author_uri', 'text_domain', 'domain_path' ) as $field ) {
     125        if ( !empty( ${$field} ) )
     126            ${$field} = trim(${$field}[1]);
     127        else
     128            ${$field} = '';
     129    }
     130
     131    return array(
     132                'Name' => $name, 'PluginURI' => $uri, 'Description' => $description,
     133                'Author' => $author_name, 'AuthorURI' => $author_uri, 'Version' => $version,
     134                'TextDomain' => $text_domain, 'DomainPath' => $domain_path
     135                );
    162136}
    163137
  • trunk/wp-admin/plugins.php

    r8218 r8368  
    217217foreach( (array)$all_plugins as $plugin_file => $plugin_data) {
    218218
     219    //Translate fields
     220    if( !empty($plugin_data['TextDomain']) ) {
     221        if( !empty( $plugin_data['DomainPath'] ) )
     222            load_plugin_textdomain($plugin_data['TextDomain'], dirname($plugin_file). $plugin_data['DomainPath']);
     223        else
     224            load_plugin_textdomain($plugin_data['TextDomain'], dirname($plugin_file));
     225
     226        foreach ( array('Name', 'PluginURI', 'Description', 'Author', 'AuthorURI', 'Version') as $field )
     227            $plugin_data[ $field ] = translate($plugin_data[ $field ], $plugin_data['TextDomain']);
     228    }
     229
     230    //Apply Markup
     231    $plugin_data['Title'] = $plugin_data['Name'];
     232    if ( !empty($plugin_data['PluginURI']) && !empty($plugin_data['Name']) )
     233        $plugin_data['Title'] = '<a href="' . $plugin_data['PluginURI'] . '" title="'.__( 'Visit plugin homepage' ).'">' . $plugin_data['Name'] . '</a>';
     234   
     235    if ( ! empty($plugin_data['AuthorURI']) )
     236        $plugin_data['Author'] = '<a href="' . $plugin_data['AuthorURI'] . '" title="'.__( 'Visit author homepage' ).'">' . $plugin_data['Author'] . '</a>';
     237   
     238    $plugin_data['Description'] = wptexturize( $plugin_data['Description'] );
     239
    219240    // Sanitize all displayed data
    220241    $plugin_data['Title']       = wp_kses($plugin_data['Title'], $plugins_allowedtags);
     
    264285        if( 'active' == $context )
    265286            $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>';
    266         else //Available or Recently deactivated
     287        else //Inactive or Recently deactivated
    267288            $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>';
    268289
Note: See TracChangeset for help on using the changeset viewer.