Changeset 753
- Timestamp:
- 09/14/06 15:04:44 (2 years ago)
- Files:
-
- trunk/wp-admin/admin-ajax.php (modified) (9 diffs)
- trunk/wp-admin/cat-js.php (modified) (1 diff)
- trunk/wp-admin/categories.js (modified) (1 diff)
- trunk/wp-admin/custom-fields.js (modified) (2 diffs)
- trunk/wp-admin/list-manipulation-js.php (deleted)
- trunk/wp-admin/users.php (modified) (1 diff)
- trunk/wp-cron.php (modified) (2 diffs)
- trunk/wp-includes/classes.php (modified) (1 diff)
- trunk/wp-includes/cron.php (modified) (6 diffs)
- trunk/wp-includes/js/list-manipulation-js.php (added)
- trunk/wp-includes/js/wp-ajax-js.php (added)
- trunk/wp-includes/post.php (modified) (1 diff)
- trunk/wp-includes/script-loader.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/wp-admin/admin-ajax.php
r722 r753 6 6 define('DOING_AJAX', true); 7 7 8 9 8 check_ajax_referer(); 10 9 if ( !is_user_logged_in() ) … … 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' />"; … … 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 } … … 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); … … 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>"; 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(); 132 128 break; 133 129 case 'add-cat' : // From Manage->Categories … … 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' : … … 159 156 die('-1'); 160 157 if ( $id < 0 ) { 161 if ( $pid = w rite_post() )162 $m eta = has_meta( $pid );158 if ( $pid = wp_insert_post() ) 159 $mid = add_meta( $pid ); 163 160 else 164 161 die('0'); 165 $key = $meta[0]['meta_key']; 166 $value = $meta[0]['meta_value']; 167 $mid = (int) $meta[0]['meta_id']; 168 } else { 169 if ( $mid = add_meta( $id ) ) 170 $meta = get_post_meta_by_id( $mid ); 171 else 172 die('0'); 173 $key = $meta->meta_key; 174 $value = $meta->meta_value; 175 $pid = (int) $meta->post_id; 176 } 177 $r = "<?xml version='1.0' standalone='yes'?><ajaxresponse>"; 178 $r .= wp_ajax_echo_meta( $pid, $mid, $key, $value ); 179 $r .= '</ajaxresponse>'; 180 header('Content-type: text/xml'); 181 die($r); 162 } else if ( !$mid = add_meta( $id ) ) { 163 die('0'); 164 } 165 166 $meta = get_post_meta_by_id( $mid ); 167 $key = $meta->meta_key; 168 $value = $meta->meta_value; 169 $pid = (int) $meta->post_id; 170 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(); 182 178 break; 183 179 case 'update-meta' : … … 189 185 if ( !current_user_can( 'edit_post', $meta->post_id ) ) 190 186 die('-1'); 191 $r = "<?xml version='1.0' standalone='yes'?><ajaxresponse>";192 187 if ( $u = update_meta( $mid, $key, $value ) ) { 193 188 $key = stripslashes($key); 194 189 $value = stripslashes($value); 195 $r .= wp_ajax_echo_meta( $meta->post_id, $mid, $key, $value ); 196 } 197 $r .= '</ajaxresponse>'; 198 header('Content-type: text/xml'); 199 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'); 200 199 break; 201 200 case 'add-user' : … … 203 202 die('-1'); 204 203 require_once(ABSPATH . WPINC . '/registration.php'); 205 $user_id = add_user(); 206 if ( is_wp_error( $user_id ) ) { 204 if ( !$user_id = add_user() ) 205 die('0'); 206 elseif ( is_wp_error( $user_id ) ) { 207 207 foreach( $user_id->get_error_messages() as $message ) 208 echo "$message<br />"; 209 exit; 210 } elseif ( !$user_id ) { 211 die('0'); 212 } 213 $r = "<?xml version='1.0' standalone='yes'?><ajaxresponse><user><id>$user_id</id><newitem><![CDATA[<table><tbody>"; 214 $r .= user_row( $user_id ); 215 $r .= "</tbody></table>]]></newitem></user></ajaxresponse>"; 216 header('Content-type: text/xml'); 217 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(); 218 217 break; 219 218 case 'autosave' : trunk/wp-admin/cat-js.php
r734 r753 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 = '<?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'); }; 35 14 } trunk/wp-admin/categories.js
r707 r753 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); trunk/wp-admin/custom-fields.js
r550 r753 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 } … … 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 } trunk/wp-admin/users.php
r748 r753 587 587 <?php if ( is_wp_error( $add_user_errors ) ) : ?> 588 588 <div class="error"> 589 <ul>590 589 <?php 591 590 foreach ( $add_user_errors->get_error_messages() as $message ) 592 echo "$message<br />"; 593 ?> 594 </ul> 591 echo "<p>$message<p>"; 592 ?> 595 593 </div> 596 594 <?php endif; ?> trunk/wp-cron.php
r721 r753 7 7 exit; 8 8 9 $crons = get_option('cron');9 $crons = _get_cron_array(); 10 10 $keys = array_keys($crons); 11 11 if (!is_array($crons) || $keys[0] > time()) … … 13 13 foreach ($crons as $timestamp => $cronhooks) { 14 14 if ($timestamp > time()) break; 15 foreach($cronhooks as $hook => $args) { 16 wp_unschedule_event($timestamp, $hook); 17 do_action($hook, $args['args']); 18 $schedule = $args['schedule']; 19 if($schedule != false) { 20 $args = array_merge( array($timestamp, $schedule, $hook), $args['args']); 21 call_user_func_array('wp_reschedule_event', $args); 15 foreach ($cronhooks as $hook => $keys) { 16 foreach ($keys as $key => $args) { 17 do_action_ref_array($hook, $args['args']); 18 $schedule = $args['schedule']; 19 if ($schedule != false) { 20 $new_args = array_merge( array($timestamp, $schedule, $hook), $args['args']); 21 call_user_func_array('wp_reschedule_event', $new_args); 22 } 23 wp_unschedule_event($timestamp, $hook, $args['args']); 22 24 } 23 25 } trunk/wp-includes/classes.php
r744 r753 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 ?> trunk/wp-includes/cron.php
r729 r753 3 3 function wp_schedule_single_event( $timestamp, $hook ) { 4 4 $args = array_slice( func_get_args(), 2 ); 5 $crons = get_option( 'cron' ); 6 $crons[$timestamp][$hook] = array( 'schedule' => false, 'args' => $args ); 5 $crons = _get_cron_array(); 6 $key = md5(serialize($args)); 7 $crons[$timestamp][$hook][$key] = array( 'schedule' => false, 'args' => $args ); 7 8 ksort( $crons ); 8 update_option( 'cron',$crons );9 _set_cron_array( $crons ); 9 10 } 10 11 11 12 function wp_schedule_event( $timestamp, $recurrence, $hook ) { 12 13 $args = array_slice( func_get_args(), 3 ); 13 $crons = get_option( 'cron');14 $crons = _get_cron_array(); 14 15 $schedules = wp_get_schedules(); 16 $key = md5(serialize($args)); 15 17 if ( !isset( $schedules[$recurrence] ) ) 16 18 return false; 17 $crons[$timestamp][$hook] = array( 'schedule' => $recurrence, 'args' => $args, 'interval' => $schedules[$recurrence]['interval'] );19 $crons[$timestamp][$hook][$key] = array( 'schedule' => $recurrence, 'args' => $args, 'interval' => $schedules[$recurrence]['interval'] ); 18 20 ksort( $crons ); 19 update_option( 'cron',$crons );21 _set_cron_array( $crons ); 20 22 } 21 23 22 24 function wp_reschedule_event( $timestamp, $recurrence, $hook ) { 23 25 $args = array_slice( func_get_args(), 3 ); 24 $crons = get_option( 'cron');26 $crons = _get_cron_array(); 25 27 $schedules = wp_get_schedules(); 28 $key = md5(serialize($args)); 26 29 $interval = 0; 27 30 … … 31 34 // Now we try to get it from the saved interval in case the schedule disappears 32 35 if ( 0 == $interval ) 33 $interval = $crons[$timestamp][$hook][ 'interval'];36 $interval = $crons[$timestamp][$hook][$key]['interval']; 34 37 // Now we assume something is wrong and fail to schedule 35 38 if ( 0 == $interval ) … … 39 42 $timestamp += $interval; 40 43 41 wp_schedule_event( $timestamp, $recurrence, $hook );44 wp_schedule_event( $timestamp, $recurrence, $hook, $args ); 42 45 } 43 46 44 function wp_unschedule_event( $timestamp, $hook ) { 45 $crons = get_option( 'cron' ); 46 unset( $crons[$timestamp][$hook] ); 47 function wp_unschedule_event( $timestamp, $hook, $args = array() ) { 48 $crons = _get_cron_array(); 49 $key = md5(serialize($args)); 50 unset( $crons[$timestamp][$hook][$key] ); 51 if ( empty($crons[$timestamp][$hook]) ) 52 unset( $crons[$timestamp][$hook] ); 47 53 if ( empty($crons[$timestamp]) ) 48 54 unset( $crons[$timestamp] ); 49 update_option( 'cron',$crons );55 _set_cron_array( $crons ); 50 56 } 51 57 … … 54 60 55 61 while ( $timestamp = wp_next_scheduled( $hook, $args ) ) 56 wp_unschedule_event( $timestamp, $hook );62 wp_unschedule_event( $timestamp, $hook, $args ); 57 63 } 58 64 59 function wp_next_scheduled( $hook, $args = '' ) { 60 $crons = get_option( 'cron' ); 65 function wp_next_scheduled( $hook, $args = array() ) { 66 $crons = _get_cron_array(); 67 $key = md5(serialize($args)); 61 68 if ( empty($crons) ) 62 69 return false; 63 foreach ( $crons as $timestamp => $cron ) 64 if ( isset( $cron[$hook] ) ) { 65 if ( empty($args) ) 66 return $timestamp; 67 if ( $args == $cron[$hook]['args'] ) 68 return $timestamp; 69 } 70 foreach ( $crons as $timestamp => $cron ) { 71 if ( isset( $cron[$hook][$key] ) ) 72 return $timestamp; 73 } 70 74 return false; 71 75 } 72 76 73 77 function spawn_cron() { 74 $crons = get_option( 'cron');78 $crons = _get_cron_array(); 75 79 76 80 if ( !is_array($crons) ) … … 93 97 94 98 function wp_cron() { 95 $crons = get_option( 'cron');99 $crons = _get_cron_array(); 96 100 97 101 if ( !is_array($crons) ) … … 122 126 } 123 127 128 // 129 // Private functions 130 // 131 132 function _get_cron_array() { 133 $cron = get_option('cron'); 134 if ( ! is_array($cron) ) 135 return false; 136 137 if ( !isset($cron['version']) ) 138 $cron = _upgrade_cron_array($cron); 139 140 unset($cron['version']); 141 142 return $cron; 143 } 144 145 function _set_cron_array($cron) { 146 $cron['version'] = 2; 147 update_option( 'cron', $cron ); 148 } 149 150 function _upgrade_cron_array($cron) { 151 if ( isset($cron['version']) && 2 == $cron['version']) 152 return $cron; 153 154 $new_cron = array(); 155 156 foreach ($cron as $timestamp => $hooks) { 157 foreach ( $hooks as $hook => $args ) { 158 $key = md5(serialize($args['args'])); 159 $new_cron[$timestamp][$hook][$key] = $args; 160 } 161 } 162 163 $new_cron['version'] = 2; 164 update_option( 'cron', $new_cron ); 165 return $new_cron; 166 } 167 124 168 ?> trunk/wp-includes/post.php
r736 r753 699 699 // Schedule publication. 700 700 if ( 'future' == $post_status ) 701 wp_schedule_single_event( mysql2date('U', $post_date), 'publish_future_post', $post_ID);701 wp_schedule_single_event(strtotime($post_date_gmt. ' GMT'), 'publish_future_post', $post_ID); 702 702 703 703 do_action('save_post', $post_ID); trunk/wp-includes/script-loader.php
r743 r753 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 $this->add( 'autosave', '/wp-includes/js/autosave.js.php', array('prototype', 'sack'), '4107'); 21 $this->add( 'autosave', '/wp-includes/js/autosave.js.php', array('prototype', 'sack'), '4183'); 22 $this->add( 'wp-ajax', '/wp-includes/js/wp-ajax-js.php', array('prototype'), '4187'); 23 $this->add( 'listman', '/wp-includes/js/list-manipulation-js.php', array('wp-ajax', 'fat'), '4187'); 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 one25 26 $this->add( 'ajaxcat', '/wp-admin/cat-js.php', array('listman'), '3684' ); 26 27 $this->add( 'admin-categories', '/wp-admin/categories.js', array('listman'), '3684' ); 27 28 $this->add( 'admin-custom-fields', '/wp-admin/custom-fields.js', array('listman'), '3733' ); 28 $this->add( 'admin-comments', '/wp-admin/edit-comments.js', array('listman'), '38 50' ); // Make changeset # the correct one29 $this->add( 'admin-comments', '/wp-admin/edit-comments.js', array('listman'), '3847' ); 29 30 $this->add( 'admin-users', '/wp-admin/users.js', array('listman'), '3684' ); 30 31 $this->add( 'xfn', '/wp-admin/xfn.js', false, '3517' );
