WordPress.org

Make WordPress Core

Changeset 5913


Ignore:
Timestamp:
08/22/2007 10:48:48 AM (13 years ago)
Author:
matt
Message:

First pass plugin update notification, see #4795

Location:
trunk/wp-admin
Files:
3 edited

Legend:

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

    r5904 r5913  
    3838add_action( 'admin_notices', 'update_nag', 3 );
    3939
     40function wp_update_plugins() {
     41    global $wp_version;
     42    $plugins = get_plugins();
     43    $active  = get_option( 'active_plugins' );
     44    $current = get_option( 'update_plugins' );
     45
     46    $new_option = '';
     47    $new_option->last_checked = time();
     48
     49    $plugin_changed = false;
     50    foreach ( $plugins as $file => $p ) {
     51        $new_option->checked[ $file ] = $p['Version'];
     52
     53        if ( !isset( $current->checked[ $file ] ) ) {
     54            $plugin_changed = true;
     55            continue;
     56        }
     57
     58        if ( $current->checked[ $file ] != $p['Version'] )
     59            $plugin_changed = true;
     60    }
     61
     62    if (
     63        isset( $current->last_checked ) &&
     64        43200 > ( time() - $current->last_checked ) &&
     65        !$plugin_changed
     66    )
     67        return false;
     68
     69    $to_send->plugins = $plugins;
     70    $to_send->active = $active;
     71    $send = serialize( $to_send );
     72
     73    $request = 'plugins=' . urlencode( $send );
     74    $http_request  = "POST /plugins/update-check/1.0/ HTTP/1.0\r\n";
     75    $http_request .= "Host: api.wordpress.org\r\n";
     76    $http_request .= "Content-Type: application/x-www-form-urlencoded; charset=" . get_option('blog_charset') . "\r\n";
     77    $http_request .= "Content-Length: " . strlen($request) . "\r\n";
     78    $http_request .= 'User-Agent: WordPress/' . $wp_version . '; ' . get_bloginfo('url') . "\r\n";
     79    $http_request .= "\r\n";
     80    $http_request .= $request;
     81
     82    $response = '';
     83    if( false != ( $fs = @fsockopen( 'api.wordpress.org', 80, $errno, $errstr, 3) ) ) {
     84        fwrite($fs, $http_request);
     85
     86        while ( !feof($fs) )
     87            $response .= fgets($fs, 1160); // One TCP-IP packet
     88        fclose($fs);
     89        $response = explode("\r\n\r\n", $response, 2);
     90    }
     91
     92    $response = unserialize( $response[1] );
     93
     94    if ( $response )
     95        $new_option->response = $response;
     96
     97    update_option( 'update_plugins', $new_option );
     98}
     99add_action( 'load-plugins.php', 'wp_update_plugins' );
     100
     101function wp_plugin_update_row( $file ) {
     102    global $plugin_data;
     103    $current = get_option( 'update_plugins' );
     104    if ( !isset( $current->response[ $file ] ) )
     105        return false;
     106
     107    $r = $current->response[ $file ];
     108
     109    echo "<tr><td colspan='5' class='plugin-update'>";
     110    printf( __('There is a new version of %s available. <a href="%s">Download version %s here</a>.'), $plugin_data['Name'], $r->url, $r->new_version );
     111    echo "</td></tr>";
     112}
     113add_action( 'after_plugin_row', 'wp_plugin_update_row' );
     114
    40115?>
  • trunk/wp-admin/plugins.php

    r5753 r5913  
    164164        echo"
    165165    </tr>";
     166    do_action( 'after_plugin_row', $plugin_file );
    166167    }
    167168?>
  • trunk/wp-admin/wp-admin.css

    r5904 r5913  
    13311331}
    13321332
    1333 #update-nag {
     1333#update-nag, .plugin-update {
    13341334    border-bottom: 1px solid #ccc;
    13351335    background: #fffeeb;
    1336     text-align: center;
    13371336    line-height: 29px;
    13381337    font-size: 12px;
    13391338    color: #555;
    1340 }
    1341 #update-nag a {
     1339    text-align: center;
     1340}
     1341
     1342#update-nag a, .plugin-update a {
    13421343    font-size: 1.1em;
    13431344}
    1344 #update-nag a:link {
     1345#update-nag a:link, .plugin-update a:link {
    13451346    color: #036;
    13461347}
     1348
     1349.plugin-update {
     1350    text-align: left;
     1351}
Note: See TracChangeset for help on using the changeset viewer.