Make WordPress Core

Ticket #3099: 3099c.diff

File 3099c.diff, 26.3 KB (added by mdawaffe, 18 years ago)
  • wp-includes/js/wp-ajax-js.php

     
     1<?php @require_once('../../wp-config.php'); cache_javascript_headers(); ?>
     2var WPAjax = Class.create();
     3Object.extend(WPAjax.prototype, Ajax.Request.prototype);
     4Object.extend(WPAjax.prototype, {
     5        WPComplete: false, // onComplete function
     6        WPError: false, // onWPError function
     7        initialize: function(url, responseEl) {
     8                var tempObj = this;
     9                this.transport = Ajax.getTransport();
     10                if ( !this.transport )
     11                        return false;
     12                this.setOptions( {
     13                        parameters: 'cookie=' + encodeURIComponent(document.cookie),
     14                        onComplete: function(transport) { // transport = XMLHttpRequest object
     15                                if ( tempObj.parseAjaxResponse() ) {
     16                                        if ( 'function' == typeof tempObj.WPComplete )
     17                                                tempObj.WPComplete(transport);
     18                                } else if ( 'function' == typeof tempObj.WPError ) // if response corresponds to an error (bad data, say, not 404)
     19                                        tempObj.WPError(transport);
     20                        }
     21                });
     22                this.url = url;
     23                this.getResponseElement(responseEl);
     24        },
     25        addArg: function(key, value) {
     26                var a = $H(this.options.parameters.parseQuery());
     27                a[encodeURIComponent(key)] = encodeURIComponent(value);
     28                this.options.parameters = a.map(function(pair) {
     29                        return pair.join('=');
     30                }).join('&');
     31        },
     32        getResponseElement: function(r) {
     33                var p = $(r + '-p');
     34                if ( !p ) {
     35                        new Insertion.Bottom(r, "<span id='" + r + "-p'></span>");
     36                        var p = $(r + '-p');
     37                }
     38                this.myResponseElement = p;
     39        },
     40        parseAjaxResponse: function() { // 1 = good, 0 = strange (bad data?), -1 = you lack permission
     41                if ( this.transport.responseXML && typeof this.transport.responseXML == 'object' ) {
     42                        var err = this.transport.responseXML.getElementsByTagName('wp_error');
     43                        if ( err[0] ) {
     44                                var msg = $A(err).inject( '', function(a, b) { return a + '<p>' + b.firstChild.nodeValue + '</p>'; } );
     45                                this.myResponseElement.update('<div class="error">' + msg + '</div>');
     46                                return false;
     47                        }
     48                        return true;
     49                }
     50                var r = this.transport.responseText;
     51                if ( isNaN(r) ) {
     52                        this.myResponseElement.update('<div class="error"><p>' + r + '</p></div>');
     53                        return false;
     54                }
     55                var r = parseInt(r,10);
     56                if ( -1 == r ) {
     57                        this.myResponseElement.update("<div class='error'><p><?php _e("You don't have permission to do that."); ?></p></div>");
     58                        return false;
     59                } else if ( 0 == r ) {
     60                        this.myResponseElement.update("<div class='error'><p><?php _e("Something strange happened.  Try refreshing the page."); ?></p></div>");
     61                        return false;
     62                }
     63                return true;
     64        },
     65        addOnComplete: function(f) {
     66                if ( 'function' == typeof f ) { var of = this.WPComplete; this.WPComplete = function(t) { if ( of ) of(t); f(t); } }
     67        },
     68        addOnWPError: function(f) {
     69                if ( 'function' == typeof f ) { var of = this.WPError; this.WPError = function(t) { if ( of ) of(t); f(t); } }
     70        },
     71        notInitialized: function() {
     72                return this.transport ? false : true;
     73        }
     74});
     75
     76Ajax.activeSendCount = 0;
     77Ajax.Responders.register( {
     78        onCreate: function() {
     79                Ajax.activeSendCount++;
     80                if ( 1 != Ajax.activeSendCount )
     81                        return;
     82                wpBeforeUnload = window.onbeforeunload;
     83                window.onbeforeunload = function() {
     84                        return "<?php _e("Slow down, I'm still sending your data!"); ?>";
     85                }
     86        },
     87        onLoading: function() { // Can switch to onLoaded if we lose data
     88                Ajax.activeSendCount--;
     89                if ( 0 != Ajax.activeSendCount )
     90                        return;
     91                window.onbeforeunload = wpBeforeUnload;
     92        }
     93});
  • wp-includes/js/list-manipulation-js.php

     
     1<?php
     2@require_once('../../wp-config.php');
     3cache_javascript_headers();
     4$handler =  get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php';
     5?>
     6addLoadEvent(function(){theList=new listMan();});
     7function deleteSomething(what,id,message,obj){if(!obj)obj=theList;if(!message)message="<?php printf(__('Are you sure you want to delete this %s?'),"'+what+'"); ?>";if(confirm(message))return obj.ajaxDelete(what,id);else return false;}
     8function dimSomething(what,id,dimClass,obj){if(!obj)obj=theList;return obj.ajaxDimmer(what,id,dimClass);}
     9
     10var listMan = Class.create();
     11Object.extend(listMan.prototype, {
     12        reg_color: '#FFFFFF',
     13        alt_color: '#F1F1F1',
     14        ajaxRespEl: 'ajax-response',
     15        ajaxHandler: '<?php echo $handler; ?>',
     16        inputData: '',
     17        clearInputs: [],
     18        showLink: true,
     19        topAdder: false,
     20        alt: 'alternate',
     21        addComplete: null,
     22        delComplete: null,
     23        dimComplete: null,
     24        dataStore: null,
     25        formStore: null,
     26
     27        initialize: function(theListId) {
     28                this.theList = $(theListId ? theListId : 'the-list');
     29                if ( !this.theList )
     30                        return false;
     31                this.theList.cleanWhitespace();
     32        },
     33
     34        // sends add-what and fields contained in where
     35        // recieves html with top element having an id like what-#
     36        ajaxAdder: function( what, where, update ) { // Do NOT wrap TR in TABLE TBODY
     37                var ajaxAdd = new WPAjax( this.ajaxHandler, this.ajaxRespEl );
     38                if ( ajaxAdd.notInitialized() )
     39                        return true;
     40                ajaxAdd.options.parameters += '&action=' + ( update ? 'update-' : 'add-' ) + what + '&' + this.grabInputs( where, ajaxAdd ) + this.inputData;
     41                var tempObj=this;
     42                ajaxAdd.addOnComplete( function(transport) {
     43                        var newItems = $A(transport.responseXML.getElementsByTagName(what));
     44                        if ( newItems ) {
     45                                newItems.each( function(i) {
     46                                        var id = i.getAttribute('id');
     47                                        var exists = $(what+'-'+id);
     48                                        if ( exists )
     49                                                tempObj.replaceListItem( exists, getNodeValue(i,'response_data'), update );
     50                                        else
     51                                                tempObj.addListItem( getNodeValue(i, 'response_data') );
     52                                        if ( tempObj.showLink )
     53                                                tempObj.showLink = id;
     54                                });
     55                        }
     56                        ajaxAdd.myResponseElement.update(tempObj.showLink ? ( "<div id='jumplink' class='updated fade'><p><a href='#" + what + '-' + tempObj.showLink + "'><?php _e('Jump to new item'); ?></a></p></div>" ) : '');
     57                        if ( tempObj.addComplete && typeof tempObj.addComplete == 'function' )
     58                                tempObj.addComplete( what, where, update, transport );
     59                        tempObj.recolorList();
     60                        ajaxAdd.restoreInputs = null;
     61                });
     62                ajaxAdd.addOnWPError( function(transport) { tempObj.restoreForm(ajaxAdd.restoreInputs); });
     63                ajaxAdd.request(ajaxAdd.url);
     64                this.clear();
     65                return false;
     66        },
     67
     68        // sends update-what and fields contained in where
     69        // recieves html with top element having an id like what-#
     70        ajaxUpdater: function( what, where ) { return this.ajaxAdder( what, where, true ); },
     71
     72        // sends delete-what and id#
     73        ajaxDelete: function( what, id ) {
     74                var ajaxDel = new WPAjax( this.ajaxHandler, this.ajaxRespEl );
     75                if( ajaxDel.notInitialized() )
     76                        return true;
     77                var tempObj = this;
     78                var action = 'delete-' + what + '&id=' + id;
     79                var idName = what.replace('-as-spam','') + '-' + id;
     80                ajaxDel.addOnComplete( function(transport) {
     81                        ajaxDel.myResponseElement.update('');
     82                        tempObj.destore(action);
     83                        if( tempObj.delComplete && typeof tempObj.delComplete == 'function' )
     84                                tempObj.delComplete( what, id, transport );
     85                });
     86                ajaxDel.addOnWPError( function(transport) { tempObj.restore(action, true); });
     87                ajaxDel.options.parameters += '&action=' + action + this.inputData;
     88                ajaxDel.request(ajaxDel.url);
     89                this.store(action, idName);
     90                tempObj.removeListItem( idName );
     91                return false;
     92        },
     93
     94        // Toggles class nomes
     95        // sends dim-what and id#
     96        ajaxDimmer: function( what, id, dimClass ) {
     97                ajaxDim = new WPAjax( this.ajaxHandler, this.ajaxRespEl );
     98                if ( ajaxDim.notInitialized() )
     99                        return true;
     100                var tempObj = this;
     101                var action = 'dim-' + what + '&id=' + id;
     102                var idName = what + '-' + id;
     103                ajaxDim.addOnComplete( function(transport) {
     104                        ajaxDim.myResponseElement.update('');
     105                        tempObj.destore(action);
     106                        if ( tempObj.dimComplete && typeof tempObj.dimComplete == 'function' )
     107                                tempObj.dimComplete( what, id, dimClass, transport );
     108                });
     109                ajaxDim.addOnWPError( function(transport) { tempObj.restore(action, true); });
     110                ajaxDim.options.parameters += '&action=' + action + this.inputData;
     111                ajaxDim.request(ajaxDim.url);
     112                this.store(action, idName);
     113                this.dimItem( idName, dimClass );
     114                return false;
     115        },
     116
     117        addListItem: function( h ) {
     118                new Insertion[this.topAdder ? 'Top' : 'Bottom'](this.theList,h);
     119                this.theList.cleanWhitespace();
     120                var id = this.topAdder ? this.theList.firstChild.id : this.theList.lastChild.id;
     121                if ( this.alt )
     122                        if ( this.theList.childNodes.length % 2 )
     123                                $(id).addClassName(this.alt);
     124                Fat.fade_element(id);
     125        },
     126
     127        // only hides the element sa it can be put back again if necessary
     128        removeListItem: function( id, noFade ) {
     129                id = $(id);
     130                if ( !noFade ) {
     131                        Fat.fade_element(id.id,null,700,'#FF3333');
     132                        var tempObj = this;
     133                        var func = function() { id.hide(); tempObj.recolorList(); }
     134                        setTimeout(func, 705);
     135                } else {
     136                        id.hide();
     137                        this.recolorList();
     138                }
     139        },
     140
     141        replaceListItem: function( id, h, update ) {
     142                id = $(id);
     143                if ( !update ) {
     144                        id.remove();
     145                        this.addListItem( h );
     146                        return;
     147                }
     148                id.replace(h);
     149                Fat.fade_element(id.id);
     150        },
     151
     152        // toggles class
     153        dimItem: function( id, dimClass, noFade ) {
     154                id = $(id);
     155                if ( id.hasClassName(dimClass) ) {
     156                        if ( !noFade )
     157                                Fat.fade_element(id.id,null,700,null);
     158                        id.removeClassName(dimClass);
     159                } else {
     160                        if ( !noFade )
     161                                Fat.fade_element(id.id,null,700,'#FF3333');
     162                        id.addClassName(dimClass);
     163                }
     164        },
     165
     166        // store an element in case we need it later
     167        store: function(action, id) {
     168                if ( !this.dataStore )
     169                        this.dataStore = $H();
     170                this.dataStore[action] = $(id).cloneNode(true);
     171        },
     172
     173        // delete from store
     174        destore: function(action) { delete(this.dataStore[action]); },
     175
     176        // restore element from store into existing (possibly hidden) element of same id
     177        restore: function(action, error) {
     178                var id = this.dataStore[action].id;
     179                this.theList.replaceChild(this.dataStore[action], $(id));
     180                delete(this.dataStore[action]);
     181                if ( error ) {
     182                        func = function() { $(id).setStyle( { 'background-color': '#FF3333' } ); }
     183                        func(); setTimeout(func, 705); // Hit it twice in case it's still fading.
     184                }
     185        },
     186
     187        // Like Form.serialize, but excludes action and sets up clearInputs
     188        grabInputs: function( where, ajaxObj ) {
     189                if ( ajaxObj )
     190                        ajaxObj.restoreInputs = [];
     191                var elements = Form.getElements($(where));
     192                var queryComponents = new Array();
     193                for (var i = 0; i < elements.length; i++) {
     194                        if ( 'action' == elements[i].name )
     195                                continue;
     196                        if ( 'hidden' != elements[i].type && 'submit' != elements[i].type && 'button' != elements[i].type ) {
     197                                this.clearInputs.push(elements[i]);
     198                                if ( ajaxObj )
     199                                        ajaxObj.restoreInputs.push([elements[i], elements[i].value]);
     200                        }
     201                        var queryComponent = Form.Element.serialize(elements[i]);
     202                        if (queryComponent) {
     203                                queryComponents.push(queryComponent);
     204                        }
     205                }
     206                return queryComponents.join('&');
     207        },
     208
     209        // form.reset() can only do whole forms.  This can do subsections.
     210        clear: function() {
     211                this.clearInputs.each( function(i) {
     212                        i = $(i);
     213                        if ( 'textarea' == i.tagName.toLowerCase() )
     214                                i.value = '';
     215                        else
     216                                switch ( i.type.toLowerCase() ) {
     217                                        case 'password': case 'text':
     218                                                i.value = '';
     219                                                break;
     220                                        case 'checkbox': case 'radio':
     221                                                i.checked = false;
     222                                                break;
     223                                        case 'select': case 'select-one':
     224                                                i.selectedIndex = null;
     225                                                break;
     226                                        case 'select-multiple':
     227                                                for (var o = 0; o < i.length; o++) i.options[o].selected = false;
     228                                                break;
     229                                }
     230                });
     231                this.clearInputs = [];
     232        },
     233
     234        restoreForm: function(elements) {
     235                elements.each( function(i) {
     236                        i[0].value = i[1];
     237                });
     238        },
     239
     240        recolorList: function() {
     241                if ( !this.alt )
     242                        return;
     243                var alt = this.alt;
     244                var listItems = $A(this.theList.childNodes).findAll( function(i) { return i.visible() } );
     245                listItems.each( function(i,n) {
     246                        if ( n % 2 )
     247                                i.removeClassName(alt);
     248                        else
     249                                i.addClassName(alt);
     250                });
     251        }
     252});
     253
     254//No submit unless code returns true.
     255function killSubmit ( code, e ) {
     256        e = e ? e : window.event;
     257        if ( !e ) return;
     258        var t = e.target ? e.target : e.srcElement;
     259        if ( ( 'text' == t.type && e.keyCode == 13 ) || ( 'submit' == t.type && 'click' == e.type ) ) {
     260                if ( ( 'string' == typeof code && !eval(code) ) || ( 'function' == typeof code && !code() ) ) {
     261                        e.returnValue = false; e.cancelBubble = true; return false;
     262                }
     263        }
     264}
     265//Pretty func adapted from ALA http://www.alistapart.com/articles/gettingstartedwithajax
     266function getNodeValue(tree,el){try { var r = tree.getElementsByTagName(el)[0].firstChild.nodeValue; } catch(err) { var r = null; } return r; }
     267//Generic but lame JS closure
     268function encloseFunc(f){var a=arguments[1];return function(){return f(a);}}
  • wp-includes/classes.php

     
    709709        }
    710710}
    711711
     712class WP_Ajax_Response {
     713        var $responses = array();
     714
     715        function WP_Ajax_Response( $args = '' ) {
     716                if ( !empty($args) )
     717                        $this->add($args);
     718        }
     719
     720        // a WP_Error object can be passed in 'id' or 'data'
     721        function add( $args = '' ) {
     722                if ( is_array($args) )
     723                        $r = &$args;
     724                else
     725                        parse_str($args, $r);
     726
     727                $defaults = array('what' => 'object', 'action' => false, 'id' => '0', 'old_id' => false,
     728                                'data' => '', 'supplemental' => array());
     729
     730                $r = array_merge($defaults, $r);
     731                extract($r);
     732
     733                if ( is_wp_error($id) ) {
     734                        $data = $id;
     735                        $id = 0;
     736                }
     737
     738                $response = '';
     739                if ( is_wp_error($data) )
     740                        foreach ( $data->get_error_codes() as $code )
     741                                $response .= "<wp_error code='$code'><![CDATA[" . $data->get_error_message($code) . "]]></wp_error>";
     742                else
     743                        $response = "<response_data><![CDATA[$data]]></response_data>";
     744
     745                $s = '';
     746                if ( (array) $supplemental )
     747                        foreach ( $supplemental as $k => $v )
     748                                $s .= "<$k><![CDATA[$v]]></$k>";
     749
     750                if ( false === $action )
     751                        $action = $_POST['action'];
     752
     753                $x = '';
     754                $x .= "<response action='$action_$id'>"; // The action attribute in the xml output is formatted like a nonce action
     755                $x .=   "<$what id='$id'" . ( false !== $old_id ? "old_id='$old_id'>" : '>' );
     756                $x .=           $response;
     757                $x .=           $s;
     758                $x .=   "</$what>";
     759                $x .= "</response>";
     760
     761                $this->responses[] = $x;
     762                return $x;
     763        }
     764
     765        function send() {
     766                header('Content-type: text/xml');
     767                echo "<?xml version='1.0' standalone='yes'?><wp_ajax>";
     768                foreach ( $this->responses as $response )
     769                        echo $response;
     770                echo '</wp_ajax>';
     771                die();
     772        }
     773}
     774
    712775?>
  • wp-includes/script-loader.php

     
    1919                $this->add( 'wp_tiny_mce', '/wp-includes/js/tinymce/tiny_mce_config.php', array('tiny_mce'), '04162006' );
    2020                $this->add( 'prototype', '/wp-includes/js/prototype.js', false, '1.5.0');
    2121                $this->add( 'autosave', '/wp-includes/js/autosave.js.php', array('prototype', 'sack'), '4107');
     22                $this->add( 'wp-ajax', '/wp-includes/js/wp-ajax-js.php', array('prototype'), rand());
     23                $this->add( 'listman', '/wp-includes/js/list-manipulation-js.php', array('wp-ajax', 'fat'), rand());
    2224                if ( is_admin() ) {
    2325                        $this->add( 'dbx-admin-key', '/wp-admin/dbx-admin-key-js.php', array('dbx'), '3651' );
    24                         $this->add( 'listman', '/wp-admin/list-manipulation-js.php', array('sack', 'fat'), '4042' ); // Make changeset # the correct one
     26                        $this->add( 'listman-old', '/wp-admin/list-manipulation-js.php', array('sack', 'fat'), '4042' ); // Make changeset # the correct one
    2527                        $this->add( 'ajaxcat', '/wp-admin/cat-js.php', array('listman'), '3684' );
    2628                        $this->add( 'admin-categories', '/wp-admin/categories.js', array('listman'), '3684' );
    2729                        $this->add( 'admin-custom-fields', '/wp-admin/custom-fields.js', array('listman'), '3733' );
  • wp-admin/users.php

     
    490490
    491491<?php if ( is_wp_error( $add_user_errors ) ) : ?>
    492492        <div class="error">
    493                 <ul>
    494493                <?php
    495494                        foreach ( $add_user_errors->get_error_messages() as $message )
    496                                 echo "$message<br />";
     495                                echo "<p>$message<p>";
    497496                ?>
    498                 </ul>
    499497        </div>
    500498<?php endif; ?>
    501499<div id="ajax-response"></div>
  • wp-admin/custom-fields.js

     
    1 function customFieldsOnComplete() {
    2         var pidEl = document.getElementById('post_ID');
     1function customFieldsOnComplete( what, where, update, transport ) {
     2        var pidEl = $('post_ID');
    33        pidEl.name = 'post_ID';
    4         pidEl.value = getNodeValue(theList.ajaxAdd.responseXML, 'postid');
    5         var aEl = document.getElementById('hiddenaction')
     4        pidEl.value = getNodeValue(transport.responseXML, 'postid');
     5        var aEl = $('hiddenaction')
    66        if ( aEl.value == 'post' ) aEl.value = 'postajaxpost';
    77}
    88addLoadEvent(customFieldsAddIn);
     
    2121                }
    2222        }
    2323
    24         document.getElementById('metakeyinput').onkeypress = function(e) {return killSubmit('theList.inputData+="&id="+document.getElementById("post_ID").value;theList.ajaxAdder("meta", "newmeta");', e); };
    25         document.getElementById('updatemetasub').onclick = function(e) {return killSubmit('theList.inputData+="&id="+document.getElementById("post_ID").value;theList.ajaxAdder("meta", "newmeta");', e); };
     24        $('metakeyinput').onkeypress = function(e) {return killSubmit('theList.inputData+="&id="+$("post_ID").value;theList.ajaxAdder("meta", "newmeta");', e); };
     25        $('updatemetasub').onclick = function(e) {return killSubmit('theList.inputData+="&id="+$("post_ID").value;theList.ajaxAdder("meta", "newmeta");', e); };
    2626}
  • wp-admin/admin-ajax.php

     
    55
    66define('DOING_AJAX', true);
    77
    8 
    98check_ajax_referer();
    109if ( !is_user_logged_in() )
    1110        die('-1');
     
    1312function get_out_now() { exit; }
    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' />";
    2321        $r .= "</td><td><textarea name='meta[$mid][value]' tabindex='6' rows='2' cols='30'>$value</textarea></td><td align='center'>";
    2422        $r .= "<input name='updatemeta' type='button' class='updatemeta' tabindex='6' value='Update' onclick='return theList.ajaxUpdater(&#039;meta&#039;,&#039;meta-$mid&#039;);' /><br />";
    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}
    3128
     
    113110        if ( !current_user_can( 'manage_categories' ) )
    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);
    119116                if ( !$category_nicename = sanitize_title($cat_name) )
     
    121118                if ( !$cat_id = category_exists( $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>";
     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                ) );
    128126        }
    129         $r .= '</ajaxresponse>';
    130         header('Content-type: text/xml');
    131         die($r);
     127        $x->send();
    132128        break;
    133129case 'add-cat' : // From Manage->Categories
    134130        if ( !current_user_can( 'manage_categories' ) )
     
    147143        }
    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' :
    158155        if ( !current_user_can( 'edit_post', $id ) )
     
    171168        $value = $meta->meta_value;
    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' :
    181180        $mid = (int) array_pop(array_keys($_POST['meta']));
     
    185184                die('0');
    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 );
     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();
    193197        }
    194         $r .= '</ajaxresponse>';
    195         header('Content-type: text/xml');
    196         die($r);
     198        die('0');
    197199        break;
    198200case 'add-user' :
    199201        if ( !current_user_can('edit_users') )
    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');
     208                        echo "<p>$message<p>";
     209                exit;
    209210        }
    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);
     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' :
    217219        $_POST['post_content'] = $_POST['content'];
  • wp-admin/categories.js

     
    11addLoadEvent(function() {
    22        if (!theList.theList) return false;
    33        document.forms.addcat.submit.onclick = function(e) {return killSubmit('theList.ajaxAdder("cat", "addcat");', e); };
    4         theList.addComplete = function(what, where, update) {
    5                 var name = getNodeValue(theList.ajaxAdd.responseXML, 'name');
    6                 var id = getNodeValue(theList.ajaxAdd.responseXML, 'id');
     4        theList.addComplete = function(what, where, update, transport) {
     5                var name = getNodeValue(transport.responseXML, 'name');
     6                var id = transport.responseXML.getElementsByTagName(what)[0].getAttribute('id');
    77                var options = document.forms['addcat'].category_parent.options;
    88                options[options.length] = new Option(name, id);
    99        };
  • wp-admin/cat-js.php

     
    55addLoadEvent(function(){catList=new listMan('categorychecklist');catList.ajaxRespEl='jaxcat';catList.topAdder=1;catList.alt=0;catList.showLink=0;});
    66addLoadEvent(newCatAddIn);
    77function newCatAddIn() {
    8         if ( !document.getElementById('jaxcat') ) return false;
    9         var ajaxcat = document.createElement('span');
    10         ajaxcat.id = 'ajaxcat';
    11 
    12         newcat = document.createElement('input');
    13         newcat.type = 'text';
    14         newcat.name = 'newcat';
    15         newcat.id = 'newcat';
    16         newcat.size = '16';
    17         newcat.setAttribute('autocomplete', 'off');
    18         newcat.onkeypress = function(e) { return killSubmit("catList.ajaxAdder('category','categorydiv');", e); };
    19 
    20         var newcatSub = document.createElement('input');
    21         newcatSub.type = 'button';
    22         newcatSub.name = 'Button';
    23         newcatSub.id = 'catadd';
    24         newcatSub.value = '<?php _e('Add'); ?>';
    25         newcatSub.onclick = function() { catList.ajaxAdder('category', 'categorydiv'); };
    26 
    27         ajaxcat.appendChild(newcat);
    28         ajaxcat.appendChild(newcatSub);
    29         document.getElementById('jaxcat').appendChild(ajaxcat);
    30 
    31         howto = document.createElement('span');
    32         howto.innerHTML = "<?php _e('Separate multiple categories with commas.'); ?>";
    33         howto.id = 'howto';
    34         ajaxcat.appendChild(howto);
     8        var jaxcat = $('jaxcat');
     9        if ( !jaxcat )
     10                return false;
     11        jaxcat.update('<span id="ajaxcat"><input type="text" name="newcat" id="newcat" size="16" autocomplete="off"/><input type="button" name="Button" id="catadd" value="<?php _e('Add'); ?>"/><span id="howto"><?php _e('Separate multiple categories with commas.'); ?></span></span>');
     12        $('newcat').onkeypress = function(e) { return killSubmit("catList.ajaxAdder('category','jaxcat');", e); };
     13        $('catadd').onclick = function() { catList.ajaxAdder('category', 'jaxcat'); };
    3514}