Ticket #3099: 3099b.diff
File 3099b.diff, 25.3 KB (added by , 18 years ago) |
---|
-
wp-includes/js/wp-ajax-js.php
1 <?php @require_once('../../wp-config.php'); cache_javascript_headers(); ?> 2 var WPAjax = Class.create(); 3 Object.extend(WPAjax.prototype, Ajax.Request.prototype); 4 Object.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 }); -
wp-includes/js/list-manipulation-js.php
1 <?php 2 @require_once('../../wp-config.php'); 3 cache_javascript_headers(); 4 $handler = get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php'; 5 ?> 6 addLoadEvent(function(){theList=new listMan();}); 7 function 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;} 8 function dimSomething(what,id,dimClass,obj){if(!obj)obj=theList;return obj.ajaxDimmer(what,id,dimClass);} 9 10 var listMan = Class.create(); 11 Object.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 26 initialize: function(theListId) { 27 this.theList = $(theListId ? theListId : 'the-list'); 28 if ( !this.theList ) 29 return false; 30 this.theList.cleanWhitespace(); 31 }, 32 33 // sends add-what and fields contained in where 34 // recieves html with top element having an id like what-# 35 ajaxAdder: function( what, where, update ) { // Do NOT wrap TR in TABLE TBODY 36 var ajaxAdd = new WPAjax( this.ajaxHandler, this.ajaxRespEl ); 37 if ( ajaxAdd.notInitialized() ) 38 return true; 39 ajaxAdd.options.parameters += '&action=' + ( update ? 'update-' : 'add-' ) + what + '&' + this.grabInputs(where) + this.inputData; 40 var tempObj=this; 41 ajaxAdd.addOnComplete( function(transport) { 42 var newItems = $A(transport.responseXML.getElementsByTagName(what)); 43 if ( newItems ) { 44 newItems.each( function(i) { 45 var id = i.getAttribute('id'); 46 var exists = $(what+'-'+id); 47 if ( exists ) 48 tempObj.replaceListItem( exists, getNodeValue(i,'response_data'), update ); 49 else 50 tempObj.addListItem( getNodeValue(i, 'response_data') ); 51 if ( tempObj.showLink ) 52 tempObj.showLink = id; 53 }); 54 } 55 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>" ) : ''); 56 tempObj.clear(); 57 if ( tempObj.addComplete && typeof tempObj.addComplete == 'function' ) 58 tempObj.addComplete( what, where, update, transport ); 59 tempObj.recolorList(); 60 }); 61 ajaxAdd.request(ajaxAdd.url); 62 return false; 63 }, 64 65 // sends update-what and fields contained in where 66 // recieves html with top element having an id like what-# 67 ajaxUpdater: function( what, where ) { return this.ajaxAdder( what, where, true ); }, 68 69 // sends delete-what and id# 70 ajaxDelete: function( what, id ) { 71 var ajaxDel = new WPAjax( this.ajaxHandler, this.ajaxRespEl ); 72 if( ajaxDel.notInitialized() ) 73 return true; 74 var tempObj = this; 75 var action = 'delete-' + what + '&id=' + id; 76 var idName = what.replace('-as-spam','') + '-' + id; 77 ajaxDel.addOnComplete( function(transport) { 78 ajaxDel.myResponseElement.update(''); 79 tempObj.destore(action); 80 if( tempObj.delComplete && typeof tempObj.delComplete == 'function' ) 81 tempObj.delComplete( what, id, transport ); 82 }); 83 ajaxDel.addOnWPError( function(transport) { tempObj.restore(action, true); }); 84 ajaxDel.options.parameters += '&action=' + action + this.inputData; 85 ajaxDel.request(ajaxDel.url); 86 this.store(action, idName); 87 tempObj.removeListItem( idName ); 88 return false; 89 }, 90 91 // Toggles class nomes 92 // sends dim-what and id# 93 ajaxDimmer: function( what, id, dimClass ) { 94 ajaxDim = new WPAjax( this.ajaxHandler, this.ajaxRespEl ); 95 if ( ajaxDim.notInitialized() ) 96 return true; 97 var tempObj = this; 98 var action = 'dim-' + what + '&id=' + id; 99 var idName = what + '-' + id; 100 ajaxDim.addOnComplete( function(transport) { 101 ajaxDim.myResponseElement.update(''); 102 tempObj.destore(action); 103 if ( tempObj.dimComplete && typeof tempObj.dimComplete == 'function' ) 104 tempObj.dimComplete( what, id, dimClass, transport ); 105 }); 106 ajaxDim.addOnWPError( function(transport) { tempObj.restore(action, true); }); 107 ajaxDim.options.parameters += '&action=' + action + this.inputData; 108 ajaxDim.request(ajaxDim.url); 109 this.store(action, idName); 110 this.dimItem( idName, dimClass ); 111 return false; 112 }, 113 114 addListItem: function( h ) { 115 new Insertion[this.topAdder ? 'Top' : 'Bottom'](this.theList,h); 116 this.theList.cleanWhitespace(); 117 var id = this.topAdder ? this.theList.firstChild.id : this.theList.lastChild.id; 118 if ( this.alt ) 119 if ( this.theList.childNodes.length % 2 ) 120 $(id).addClassName(this.alt); 121 Fat.fade_element(id); 122 }, 123 124 // only hides the element sa it can be put back again if necessary 125 removeListItem: function( id, noFade ) { 126 id = $(id); 127 if ( !noFade ) { 128 Fat.fade_element(id.id,null,700,'#FF3333'); 129 var tempObj = this; 130 var func = function() { id.hide(); tempObj.recolorList(); } 131 setTimeout(func, 705); 132 } else { 133 id.hide(); 134 this.recolorList(); 135 } 136 }, 137 138 replaceListItem: function( id, h, update ) { 139 id = $(id); 140 if ( !update ) { 141 id.remove(); 142 this.addListItem( h ); 143 return; 144 } 145 id.replace(h); 146 Fat.fade_element(id.id); 147 }, 148 149 // toggles class 150 dimItem: function( id, dimClass, noFade ) { 151 id = $(id); 152 if ( id.hasClassName(dimClass) ) { 153 if ( !noFade ) 154 Fat.fade_element(id.id,null,700,null); 155 id.removeClassName(dimClass); 156 } else { 157 if ( !noFade ) 158 Fat.fade_element(id.id,null,700,'#FF3333'); 159 id.addClassName(dimClass); 160 } 161 }, 162 163 // store an element in case we need it later 164 store: function(action, id) { 165 if ( !this.dataStore ) 166 this.dataStore = $H(); 167 this.dataStore[action] = $(id).cloneNode(true); 168 }, 169 170 // delete from store 171 destore: function(action) { delete(this.dataStore[action]); }, 172 173 // restore element from store into existing (possibly hidden) element of same id 174 restore: function(action, error) { 175 var id = this.dataStore[action].id; 176 this.theList.replaceChild(this.dataStore[action], $(id)); 177 delete(this.dataStore[action]); 178 if ( error ) { 179 func = function() { $(id).setStyle( { 'background-color': '#FF3333' } ); } 180 func(); setTimeout(func, 705); // Hit it twice in case it's still fading. 181 } 182 }, 183 184 // Like Form.serialize, but excludes action and sets up clearInputs 185 grabInputs: function( where ) { 186 var elements = Form.getElements($(where)); 187 var queryComponents = new Array(); 188 for (var i = 0; i < elements.length; i++) { 189 if ( 'action' == elements[i].name ) 190 continue; 191 if ( 'hidden' != elements[i].type && 'submit' != elements[i].type && 'button' != elements[i].type ) 192 this.clearInputs.push(elements[i]); 193 var queryComponent = Form.Element.serialize(elements[i]); 194 if (queryComponent) 195 queryComponents.push(queryComponent); 196 } 197 return queryComponents.join('&'); 198 }, 199 200 // form.reset() can only do whole forms. This can do subsections. 201 clear: function() { 202 this.clearInputs.each( function(i) { 203 if ( 'textarea' == i.tagName.toLowerCase() ) 204 i.value = ''; 205 else 206 switch ( i.type.toLowerCase() ) { 207 case 'password': case 'text': 208 i.value = ''; 209 break; 210 case 'checkbox': case 'radio': 211 i.checked = false; 212 break; 213 case 'select': case 'select-one': 214 i.selectedIndex = null; 215 break; 216 case 'select-multiple': 217 for (var o = 0; o < i.length; o++) i.options[o].selected = false; 218 break; 219 } 220 }); 221 this.clearInputs = []; 222 }, 223 224 recolorList: function() { 225 if ( !this.alt ) 226 return; 227 var alt = this.alt; 228 var listItems = $A(this.theList.childNodes).findAll( function(i) { return i.visible() } ); 229 listItems.each( function(i,n) { 230 if ( n % 2 ) 231 i.removeClassName(alt); 232 else 233 i.addClassName(alt); 234 }); 235 } 236 }); 237 238 //No submit unless code returns true. 239 function killSubmit ( code, e ) { 240 e = e ? e : window.event; 241 if ( !e ) return; 242 var t = e.target ? e.target : e.srcElement; 243 if ( ( 'text' == t.type && e.keyCode == 13 ) || ( 'submit' == t.type && 'click' == e.type ) ) { 244 if ( ( 'string' == typeof code && !eval(code) ) || ( 'function' == typeof code && !code() ) ) { 245 e.returnValue = false; e.cancelBubble = true; return false; 246 } 247 } 248 } 249 //Pretty func adapted from ALA http://www.alistapart.com/articles/gettingstartedwithajax 250 function getNodeValue(tree,el){try { var r = tree.getElementsByTagName(el)[0].firstChild.nodeValue; } catch(err) { var r = null; } return r; } 251 //Generic but lame JS closure 252 function encloseFunc(f){var a=arguments[1];return function(){return f(a);}} -
wp-includes/classes.php
709 709 } 710 710 } 711 711 712 class 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 712 775 ?> -
wp-includes/script-loader.php
19 19 $this->add( 'wp_tiny_mce', '/wp-includes/js/tinymce/tiny_mce_config.php', array('tiny_mce'), '04162006' ); 20 20 $this->add( 'prototype', '/wp-includes/js/prototype.js', false, '1.5.0'); 21 21 $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()); 22 24 if ( is_admin() ) { 23 25 $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 one26 $this->add( 'listman-old', '/wp-admin/list-manipulation-js.php', array('sack', 'fat'), '4042' ); // Make changeset # the correct one 25 27 $this->add( 'ajaxcat', '/wp-admin/cat-js.php', array('listman'), '3684' ); 26 28 $this->add( 'admin-categories', '/wp-admin/categories.js', array('listman'), '3684' ); 27 29 $this->add( 'admin-custom-fields', '/wp-admin/custom-fields.js', array('listman'), '3733' ); -
wp-admin/users.php
490 490 491 491 <?php if ( is_wp_error( $add_user_errors ) ) : ?> 492 492 <div class="error"> 493 <ul>494 493 <?php 495 494 foreach ( $add_user_errors->get_error_messages() as $message ) 496 echo " $message<br />";495 echo "<p>$message<p>"; 497 496 ?> 498 </ul>499 497 </div> 500 498 <?php endif; ?> 501 499 <div id="ajax-response"></div> -
wp-admin/custom-fields.js
1 function customFieldsOnComplete( ) {2 var pidEl = document.getElementById('post_ID');1 function customFieldsOnComplete( what, where, update, transport ) { 2 var pidEl = $('post_ID'); 3 3 pidEl.name = 'post_ID'; 4 pidEl.value = getNodeValue(t heList.ajaxAdd.responseXML, 'postid');5 var aEl = document.getElementById('hiddenaction')4 pidEl.value = getNodeValue(transport.responseXML, 'postid'); 5 var aEl = $('hiddenaction') 6 6 if ( aEl.value == 'post' ) aEl.value = 'postajaxpost'; 7 7 } 8 8 addLoadEvent(customFieldsAddIn); … … 21 21 } 22 22 } 23 23 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); }; 26 26 } -
wp-admin/admin-ajax.php
5 5 6 6 define('DOING_AJAX', true); 7 7 8 9 8 check_ajax_referer(); 10 9 if ( !is_user_logged_in() ) 11 10 die('-1'); … … 13 12 function get_out_now() { exit; } 14 13 add_action( 'shutdown', 'get_out_now', -1 ); 15 14 16 function wp_ajax_ echo_meta( $pid, $mid, $key, $value ) {15 function wp_ajax_meta_row( $pid, $mid, $key, $value ) { 17 16 $value = wp_specialchars($value, true); 18 17 $key_js = addslashes(wp_specialchars($key, 'double')); 19 18 $key = wp_specialchars($key, true); 20 $r = "<meta><id>$mid</id><postid>$pid</postid><newitem><![CDATA[<table><tbody>";21 19 $r .= "<tr id='meta-$mid'><td valign='top'>"; 22 20 $r .= "<input name='meta[$mid][key]' tabindex='6' onkeypress='return killSubmit(\"theList.ajaxUpdater('meta','meta-$mid');\",event);' type='text' size='20' value='$key' />"; 23 21 $r .= "</td><td><textarea name='meta[$mid][value]' tabindex='6' rows='2' cols='30'>$value</textarea></td><td align='center'>"; 24 22 $r .= "<input name='updatemeta' type='button' class='updatemeta' tabindex='6' value='Update' onclick='return theList.ajaxUpdater('meta','meta-$mid');' /><br />"; 25 23 $r .= "<input name='deletemeta[$mid]' type='submit' onclick=\"return deleteSomething( 'meta', $mid, '"; 26 24 $r .= sprintf(__("You are about to delete the "%s" custom field on this post.\\n"OK" to delete, "Cancel" 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>"; 29 26 return $r; 30 27 } 31 28 … … 113 110 if ( !current_user_can( 'manage_categories' ) ) 114 111 die('-1'); 115 112 $names = explode(',', $_POST['newcat']); 116 $ r = "<?xml version='1.0' standalone='yes'?><ajaxresponse>";113 $x = new WP_Ajax_Response(); 117 114 foreach ( $names as $cat_name ) { 118 115 $cat_name = trim($cat_name); 119 116 if ( !$category_nicename = sanitize_title($cat_name) ) … … 121 118 if ( !$cat_id = category_exists( $cat_name ) ) 122 119 $cat_id = wp_create_category( $cat_name ); 123 120 $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 ) ); 128 126 } 129 $r .= '</ajaxresponse>'; 130 header('Content-type: text/xml'); 131 die($r); 127 $x->send(); 132 128 break; 133 129 case 'add-cat' : // From Manage->Categories 134 130 if ( !current_user_can( 'manage_categories' ) ) … … 147 143 } 148 144 $cat_full_name = wp_specialchars( $cat_full_name, 1 ); 149 145 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(); 156 153 break; 157 154 case 'add-meta' : 158 155 if ( !current_user_can( 'edit_post', $id ) ) … … 171 168 $value = $meta->meta_value; 172 169 $pid = (int) $meta->post_id; 173 170 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(); 179 178 break; 180 179 case 'update-meta' : 181 180 $mid = (int) array_pop(array_keys($_POST['meta'])); … … 185 184 die('0'); 186 185 if ( !current_user_can( 'edit_post', $meta->post_id ) ) 187 186 die('-1'); 188 $r = "<?xml version='1.0' standalone='yes'?><ajaxresponse>";189 187 if ( $u = update_meta( $mid, $key, $value ) ) { 190 188 $key = stripslashes($key); 191 189 $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(); 193 197 } 194 $r .= '</ajaxresponse>'; 195 header('Content-type: text/xml'); 196 die($r); 198 die('0'); 197 199 break; 198 200 case 'add-user' : 199 201 if ( !current_user_can('edit_users') ) 200 202 die('-1'); 201 203 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 ) ) { 204 207 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; 209 210 } 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(); 215 217 break; 216 218 case 'autosave' : 217 219 $_POST['post_content'] = $_POST['content']; -
wp-admin/categories.js
1 1 addLoadEvent(function() { 2 2 if (!theList.theList) return false; 3 3 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(t heList.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'); 7 7 var options = document.forms['addcat'].category_parent.options; 8 8 options[options.length] = new Option(name, id); 9 9 }; -
wp-admin/cat-js.php
5 5 addLoadEvent(function(){catList=new listMan('categorychecklist');catList.ajaxRespEl='jaxcat';catList.topAdder=1;catList.alt=0;catList.showLink=0;}); 6 6 addLoadEvent(newCatAddIn); 7 7 function 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 = '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="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'); }; 35 14 }