Ticket #2969: 2969.diff
| File 2969.diff, 6.9 KB (added by , 19 years ago) |
|---|
-
wp-admin/admin-ajax.php
13 13 function get_out_now() { exit; } 14 14 add_action( 'shutdown', 'get_out_now', -1 ); 15 15 16 function wp_clean_ajax_input( $i ) {17 global $wpdb;18 $i = is_array($i) ? array_map('wp_clean_ajax_input', $i) : $wpdb->escape( rawurldecode(stripslashes($i)) );19 return $i;20 }21 22 16 function wp_ajax_echo_meta( $pid, $mid, $key, $value ) { 23 17 $value = wp_specialchars($value, true); 24 18 $key_js = addslashes(wp_specialchars($key, 'double')); … … 35 29 return $r; 36 30 } 37 31 38 $_POST = wp_clean_ajax_input( $_POST );39 32 $id = (int) $_POST['id']; 40 33 switch ( $_POST['action'] ) : 41 34 case 'delete-comment' : … … 228 221 die($r); 229 222 break; 230 223 default : 224 do_action( 'wp_ajax_' . $_POST['action'] ); 231 225 die('0'); 232 226 break; 233 227 endswitch; -
wp-admin/list-manipulation-js.php
1 1 <?php 2 2 require_once('admin.php'); 3 3 header('Content-type: text/javascript; charset=' . get_settings('blog_charset'), true); 4 $handler = get_settings( 'siteurl' ) . '/wp-admin/admin-ajax.php'; 4 5 ?> 5 6 addLoadEvent(function(){theList=new listMan();}); 6 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;} … … 27 28 } WPAjax.prototype=new sack; 28 29 WPAjax.prototype.init=function(f,r){ 29 30 this.encVar('cookie', document.cookie); 30 this.requestFile=f ;this.getResponseElement(r);this.method='POST';31 this.requestFile=f?f:'<?php echo $handler; ?>';this.getResponseElement(r);this.method='POST'; 31 32 this.onLoading=function(){this.myResponseElement.innerHTML="<?php _e('Sending Data...'); ?>";}; 32 33 this.onLoaded=function(){this.myResponseElement.innerHTML="<?php _e('Data Sent...'); ?>";}; 33 34 this.onInteractive=function(){this.myResponseElement.innerHTML="<?php _e('Processing Data...'); ?>";}; 34 35 } 35 36 36 37 function listMan(theListId){ 37 this.theList=null; 38 this.ajaxRespEl=null; 38 this.theList=null;this.theListId=theListId; 39 this.ajaxRespEl=null;this.ajaxHandler='<?php echo $handler; ?>'; 39 40 this.inputData='';this.clearInputs=new Array();this.showLink=1; 40 41 this.topAdder=0;this.alt='alternate';this.recolorPos;this.reg_color='#FFFFFF';this.alt_color='#F1F1F1'; 41 42 this.addComplete=null;this.delComplete=null;this.dimComplete=null; … … 44 45 45 46 this.ajaxAdder=function(what,where,update){//for TR, server must wrap TR in TABLE TBODY. this.makeEl cleans it 46 47 if(self.aTrap)return;self.aTrap=1;setTimeout('aTrap=0',300); 47 this.ajaxAdd=new WPAjax( 'admin-ajax.php',this.ajaxRespEl?this.ajaxRespEl:'ajax-response');48 this.ajaxAdd=new WPAjax(this.ajaxHandler,this.ajaxRespEl?this.ajaxRespEl:'ajax-response'); 48 49 if(this.ajaxAdd.failed)return true; 49 50 this.grabInputs(where); 50 51 var tempObj=this; … … 53 54 var newItems=this.responseXML.getElementsByTagName(what); 54 55 if(tempObj.topAdder)tempObj.recolorPos=0; 55 56 if(newItems){for (c=0;c<newItems.length;c++){ 56 var id= parseInt(getNodeValue(newItems[c],'id'),10);57 var id=getNodeValue(newItems[c],'id'); 57 58 var exists=document.getElementById(what+'-'+id); 58 59 if(exists)tempObj.replaceListItem(exists.id,getNodeValue(newItems[c],'newitem'),newItems.length,update); 59 60 else tempObj.addListItem(getNodeValue(newItems[c],'newitem'),newItems.length); … … 71 72 this.ajaxUpdater=function(what,where){return this.ajaxAdder(what,where,true);} 72 73 this.ajaxDelete=function(what,id){ 73 74 if(self.aTrap)return;self.aTrap=1;setTimeout('aTrap=0',300); 74 this.ajaxDel=new WPAjax( 'admin-ajax.php',this.ajaxRespEl?this.ajaxRespEl:'ajax-response');75 this.ajaxDel=new WPAjax(this.ajaxHandler,this.ajaxRespEl?this.ajaxRespEl:'ajax-response'); 75 76 if(this.ajaxDel.failed)return true; 76 77 var tempObj=this; 77 78 this.ajaxDel.onCompletion=function(){if(this.parseAjaxResponse()){tempObj.removeListItem(what.replace('-as-spam','')+'-'+id);this.myResponseElement.innerHTML='';if(tempObj.delComplete&&typeof tempObj.delComplete=='function')tempObj.delComplete(what,id);tempObj.recolorList(tempObj.recolorPos,1000)}}; … … 80 81 } 81 82 this.ajaxDimmer=function(what,id,dimClass){ 82 83 if(self.aTrap)return;self.aTrap=1;setTimeout('aTrap=0',300); 83 this.ajaxDim=new WPAjax( 'admin-ajax.php',this.ajaxRespEl?this.ajaxRespEl:'ajax-response');84 this.ajaxDim=new WPAjax(this.ajaxHandler,this.ajaxRespEl?this.ajaxRespEl:'ajax-response'); 84 85 if(this.ajaxDim.failed)return true; 85 86 var tempObj=this; 86 87 this.ajaxDim.onCompletion=function(){if(this.parseAjaxResponse()){tempObj.dimItem(what+'-'+id,dimClass);this.myResponseElement.innerHTML='';if(tempObj.dimComplete&&typeof tempObj.dimComplete=='function')tempObj.dimComplete(what,id,dimClass);}}; … … 137 138 this.getListItems=function(){ 138 139 if(this.theList)return; 139 140 listItems=new Array(); 140 if(th eListId){this.theList=document.getElementById(theListId);if(!this.theList)return false;}141 else{this.theList=document.getElementById('the-list');if(this.theList)th eListId='the-list';}141 if(this.theListId){this.theList=document.getElementById(this.theListId);if(!this.theList)return false;} 142 else{this.theList=document.getElementById('the-list');if(this.theList)this.theListId='the-list';} 142 143 if(this.theList){ 143 144 var items=this.theList.getElementsByTagName('tr');listType='table'; 144 145 if(!items[0]){items=this.theList.getElementsByTagName('li');listType='list';} … … 155 156 } 156 157 this.getListItems(); 157 158 } 158 //No submit unless eval(code) returns true. 159 function killSubmit(code,e){if(!e){if(window.event)e=window.event;else return;}var t=e.target?e.target:e.srcElement;if(('text'==t.type&&e.keyCode==13)||('submit'==t.type&&'click'==e.type)){if(!eval(code)){e.returnValue=false;e.cancelBubble=true;return false;}}} 160 //Pretty func from ALA http://www.alistapart.com/articles/gettingstartedwithajax 161 function getNodeValue(tree,el){return tree.getElementsByTagName(el)[0].firstChild.nodeValue;} 159 //No submit unless code returns true. 160 function killSubmit ( code, e ) { 161 e = e ? e : window.event; 162 if ( !e ) return; 163 var t = e.target ? e.target : e.srcElement; 164 if ( ( 'text' == t.type && e.keyCode == 13 ) || ( 'submit' == t.type && 'click' == e.type ) ) { 165 if ( ( 'string' == typeof code && !eval(code) ) || 'function' == typeof code && !code() ) { 166 if ( !eval(code) ) { e.returnValue = false; e.cancelBubble = true; return false; } 167 } 168 } 169 } 170 //Pretty func adapted from ALA http://www.alistapart.com/articles/gettingstartedwithajax 171 function getNodeValue(tree,el){try { var r = tree.getElementsByTagName(el)[0].firstChild.nodeValue; } catch(err) { var r = null; } return r; } 162 172 //Generic but lame JS closure 163 173 function encloseFunc(f){var a=arguments[1];return function(){return f(a);}}