Make WordPress Core


Ignore:
Timestamp:
09/13/2006 09:39:53 PM (18 years ago)
Author:
ryan
Message:

AJAX responsiveness improvements from mdawaffe. fixes #3099

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-ajax.php

    r4163 r4187  
    66define('DOING_AJAX', true);
    77
    8 
    98check_ajax_referer();
    109if ( !is_user_logged_in() )
     
    1413add_action( 'shutdown', 'get_out_now', -1 );
    1514
    16 function wp_ajax_echo_meta( $pid, $mid, $key, $value ) {
     15function wp_ajax_meta_row( $pid, $mid, $key, $value ) {
    1716    $value = wp_specialchars($value, true);
    1817    $key_js = addslashes(wp_specialchars($key, 'double'));
    1918    $key = wp_specialchars($key, true);
    20     $r  = "<meta><id>$mid</id><postid>$pid</postid><newitem><![CDATA[<table><tbody>";
    2119    $r .= "<tr id='meta-$mid'><td valign='top'>";
    2220    $r .= "<input name='meta[$mid][key]' tabindex='6' onkeypress='return killSubmit(\"theList.ajaxUpdater(&#039;meta&#039;,&#039;meta-$mid&#039;);\",event);' type='text' size='20' value='$key' />";
     
    2523    $r .= "<input name='deletemeta[$mid]' type='submit' onclick=\"return deleteSomething( 'meta', $mid, '";
    2624    $r .= sprintf(__("You are about to delete the &quot;%s&quot; custom field on this post.\\n&quot;OK&quot; to delete, &quot;Cancel&quot; to stop."), $key_js);
    27     $r .= "' );\" class='deletemeta' tabindex='6' value='Delete' />";
    28     $r .= "</td></tr></tbody></table>]]></newitem></meta>";
     25    $r .= "' );\" class='deletemeta' tabindex='6' value='Delete' /></td></tr>";
    2926    return $r;
    3027}
     
    114111        die('-1');
    115112    $names = explode(',', $_POST['newcat']);
    116     $r = "<?xml version='1.0' standalone='yes'?><ajaxresponse>";
     113    $x = new WP_Ajax_Response();
    117114    foreach ( $names as $cat_name ) {
    118115        $cat_name = trim($cat_name);
     
    122119            $cat_id = wp_create_category( $cat_name );
    123120        $cat_name = wp_specialchars(stripslashes($cat_name));
    124         $r .= "<category><id>$cat_id</id><newitem><![CDATA[";
    125         $r .= "<li id='category-$cat_id'><label for='in-category-$cat_id' class='selectit'>";
    126         $r .= "<input value='$cat_id' type='checkbox' checked='checked' name='post_category[]' id='in-category-$cat_id'/> $cat_name</label></li>";
    127         $r .= "]]></newitem></category>";
    128     }
    129     $r .= '</ajaxresponse>';
    130     header('Content-type: text/xml');
    131     die($r);
     121        $x->add( array(
     122            'what' => 'category',
     123            'id' => $cat_id,
     124            'data' => "<li id='category-$cat_id'><label for='in-category-$cat_id' class='selectit'><input value='$cat_id' type='checkbox' checked='checked' name='post_category[]' id='in-category-$cat_id'/> $cat_name</label></li>"
     125        ) );
     126    }
     127    $x->send();
    132128    break;
    133129case 'add-cat' : // From Manage->Categories
     
    148144    $cat_full_name = wp_specialchars( $cat_full_name, 1 );
    149145
    150     $r  = "<?xml version='1.0' standalone='yes'?><ajaxresponse>";
    151     $r .= "<cat><id>$cat->cat_ID</id><name>$cat_full_name</name><newitem><![CDATA[<table><tbody>";
    152     $r .= _cat_row( $cat, $level, $cat_full_name );
    153     $r .= "</tbody></table>]]></newitem></cat></ajaxresponse>";
    154     header('Content-type: text/xml');
    155     die($r);
     146    $x = new WP_Ajax_Response( array(
     147        'what' => 'cat',
     148        'id' => $cat->cat_ID,
     149        'data' => _cat_row( $cat, $level, $cat_full_name ),
     150        'supplemental' => array('name' => $cat_full_name)
     151    ) );
     152    $x->send();
    156153    break;
    157154case 'add-meta' :
     
    172169    $pid = (int) $meta->post_id;
    173170
    174     $r = "<?xml version='1.0' standalone='yes'?><ajaxresponse>";
    175     $r .= wp_ajax_echo_meta( $pid, $mid, $key, $value );
    176     $r .= '</ajaxresponse>';
    177     header('Content-type: text/xml');
    178     die($r);
     171    $x = new WP_Ajax_Response( array(
     172        'what' => 'meta',
     173        'id' => $mid,
     174        'data' => wp_ajax_meta_row( $pid, $mid, $key, $value ),
     175        'supplemental' => array('postid' => $pid)
     176    ) );
     177    $x->send();
    179178    break;
    180179case 'update-meta' :
     
    186185    if ( !current_user_can( 'edit_post', $meta->post_id ) )
    187186        die('-1');
    188     $r = "<?xml version='1.0' standalone='yes'?><ajaxresponse>";
    189187    if ( $u = update_meta( $mid, $key, $value ) ) {
    190188        $key = stripslashes($key);
    191189        $value = stripslashes($value);
    192         $r .= wp_ajax_echo_meta( $meta->post_id, $mid, $key, $value );
    193     }
    194     $r .= '</ajaxresponse>';
    195     header('Content-type: text/xml');
    196     die($r);
     190        $x = new WP_Ajax_Response( array(
     191            'what' => 'meta',
     192            'id' => $mid,
     193            'data' => wp_ajax_meta_row( $meta->post_id, $mid, $key, $value ),
     194            'supplemental' => array('postid' => $meta->post_id)
     195        ) );
     196        $x->send();
     197    }
     198    die('0');
    197199    break;
    198200case 'add-user' :
     
    200202        die('-1');
    201203    require_once(ABSPATH . WPINC . '/registration.php');
    202     $user_id = add_user();
    203     if ( is_wp_error( $user_id ) ) {
     204    if ( !$user_id = add_user() )
     205        die('0');
     206    elseif ( is_wp_error( $user_id ) ) {
    204207        foreach( $user_id->get_error_messages() as $message )
    205             echo "$message<br />";
    206     exit;
    207     } elseif ( !$user_id ) {
    208         die('0');
    209     }
    210     $r  = "<?xml version='1.0' standalone='yes'?><ajaxresponse><user><id>$user_id</id><newitem><![CDATA[<table><tbody>";
    211     $r .= user_row( $user_id );
    212     $r .= "</tbody></table>]]></newitem></user></ajaxresponse>";
    213     header('Content-type: text/xml');
    214     die($r);
     208            echo "<p>$message<p>";
     209        exit;
     210    }
     211    $x = new WP_Ajax_Response( array(
     212        'what' => 'user',
     213        'id' => $user_id,
     214        'data' => user_row( $user_id )
     215    ) );
     216    $x->send();
    215217    break;
    216218case 'autosave' :
Note: See TracChangeset for help on using the changeset viewer.