Ticket #23216: 23216.patch
File 23216.patch, 8.0 KB (added by , 12 years ago) |
---|
-
wp-admin/admin-ajax.php
56 56 'save-widget', 'set-post-thumbnail', 'date_format', 'time_format', 'wp-fullscreen-save-post', 57 57 'wp-remove-post-lock', 'dismiss-wp-pointer', 'upload-attachment', 'get-attachment', 58 58 'query-attachments', 'save-attachment', 'save-attachment-compat', 'send-link-to-editor', 59 'send-attachment-to-editor', 'save-attachment-order', 59 'send-attachment-to-editor', 'save-attachment-order', 'heartbeat', 60 60 ); 61 61 62 62 // Register core Ajax calls. -
wp-admin/includes/ajax-actions.php
2071 2071 2072 2072 wp_send_json_success( $html ); 2073 2073 } 2074 2075 function wp_ajax_heartbeat() { 2076 check_ajax_referer( 'heartbeat-nonce', '_nonce' ); 2077 $response = array(); 2078 2079 if ( ! empty($_POST['data']) ) { 2080 $data = (array) $_POST['data']; 2081 // todo: how much to sanitize and preset and what to leave to be accessed from $data or $_POST..? 2082 $user = wp_get_current_user(); 2083 $data['user_id'] = $user->exists() ? $user->ID : 0; 2084 2085 // todo: separate filters: 'heartbeat_[action]' so we call different callbacks only when there is data for them, 2086 // or all callbacks listen to one filter and run when there is something for them in $data? 2087 $response = apply_filters( 'heartbeat_received', $response, $data ); 2088 } 2089 2090 $response = apply_filters( 'heartbeat_send', $response ); 2091 2092 // Allow the transport to be replaced with long-polling easily 2093 do_action( 'heartbeat_tick', $response ); 2094 2095 // always send the current time acording to the server 2096 $response['time'] = time(); 2097 2098 wp_send_json($response); 2099 } -
wp-admin/load-scripts.php
103 103 function json_encode() {} 104 104 endif; 105 105 106 /** 107 * @ignore 108 */ 109 function wp_create_nonce() {} 110 106 111 function get_file($path) { 107 112 108 113 if ( function_exists('realpath') ) -
wp-admin/load-styles.php
81 81 */ 82 82 function wp_guess_url() {} 83 83 84 /** 85 * @ignore 86 */ 87 function wp_create_nonce() {} 88 84 89 function get_file($path) { 85 90 86 91 if ( function_exists('realpath') ) -
wp-includes/js/autosave.js
341 341 } 342 342 343 343 autosaveOldMessage = jQuery('#autosave').html(); 344 345 // for testing only 346 wp.heartbeat.send('autosave', post_data); 347 348 349 /* 344 350 jQuery.ajax({ 345 351 data: post_data, 346 352 beforeSend: doAutoSave ? autosave_loading : null, … … 348 354 url: ajaxurl, 349 355 success: successCallback 350 356 }); 357 */ 351 358 } -
wp-includes/js/heartbeat.js
1 /** 2 * Heartbeat API 3 */ 4 5 // Ensure the global `wp` object exists. 6 window.wp = window.wp || {}; 7 8 (function($){ 9 var Heartbeat = function() { 10 var self = this, 11 running, 12 timeout, 13 nonce, 14 tick = 0, 15 queue = {}, 16 interval, 17 lastconnect = 0; 18 19 this.url = typeof ajaxurl != 'undefined' ? ajaxurl : 'wp-admin/admin-ajax.php'; 20 this.autostart = true; 21 22 if ( typeof( window.heartbeatSettings != 'undefined' ) ) { 23 settings = $.extend( {}, window.heartbeatSettings ); 24 delete window.heartbeatSettings; 25 26 nonce = settings.nonce || ''; 27 delete settings.nonce; 28 29 interval = settings.interval || 15000; // default interval 30 delete settings.interval; 31 32 $.extend( this, settings ); 33 } 34 35 function time(s) { 36 if ( s ) 37 return parseInt( (new Date()).getTime() / 1000 ); 38 39 return (new Date()).getTime(); 40 } 41 42 function throttle(seconds) { 43 if ( seconds ) { 44 // Limit 45 if ( 5 > seconds || seconds > 60 ) 46 return false; 47 48 interval = seconds * 1000; 49 } else if ( seconds === 0 ) { 50 // Allow long polling to be turned on 51 interval = 0; 52 } 53 return interval / 1000; 54 } 55 56 function errorstate() { 57 var since; 58 59 if ( lastconnect ) { 60 since = time() - lastconnect; 61 62 if ( since > 180000 ) { 63 self.connectionLost = true; 64 $(document).trigger( 'heartbeat-connection-lost', { seconds: parseInt(since / 1000) } ); 65 } else if ( self.connectionLost ) { 66 self.connectionLost = false; 67 $(document).trigger( 'heartbeat-connection-restored' ); 68 } 69 } 70 } 71 72 function connect() { 73 var data = {}; 74 tick = time(); 75 76 data.data = $.extend( {}, queue ); 77 queue = {}; 78 79 data.interval = interval / 1000; 80 data._nonce = nonce; 81 data.action = 'heartbeat'; 82 83 self.xhr = $.post( self.url, data, function(r){ 84 lastconnect = time(); 85 self.tick(r); 86 }, 'json' ).always( function(){ 87 next(); 88 }).fail( function(r){ 89 errorstate(); 90 self.error(r); 91 }); 92 }; 93 94 function next() { 95 var delta = time() - tick; 96 97 if ( !running ) 98 return; 99 100 if ( delta < interval ) { 101 timeout = window.setTimeout( 102 function(){ 103 if ( running ) 104 connect(); 105 }, 106 interval - delta 107 ); 108 } else { 109 window.clearTimeout(timeout); // this has already expired? 110 connect(); 111 } 112 }; 113 114 this.interval = function(seconds) { 115 return throttle(seconds); 116 }; 117 118 this.start = function() { 119 // start only once 120 if ( running ) 121 return false; 122 123 running = true; 124 connect(); 125 126 return true; 127 }; 128 129 this.stop = function() { 130 if ( !running ) 131 return false; 132 133 if ( self.xhr ) 134 self.xhr.abort(); 135 136 running = false; 137 return true; 138 } 139 140 this.send = function(action, data) { 141 if ( action ) 142 queue[action] = data; 143 } 144 145 if ( this.autostart ) 146 $(document).ready( function(){ self.start(); }); 147 } 148 149 $.extend( Heartbeat.prototype, { 150 tick: function(r) { 151 $(document).trigger( 'heartbeat-tick', r ); 152 }, 153 error: function(r) { 154 $(document).trigger( 'heartbeat-error', r ); 155 } 156 }); 157 158 wp.heartbeat = new Heartbeat(); 159 160 }(jQuery)); -
wp-includes/js/heartbeat.js
-
wp-includes/script-loader.php
Property changes on: wp-includes/js/heartbeat.js ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property
107 107 ) ); 108 108 109 109 $scripts->add( 'autosave', "/wp-includes/js/autosave$suffix.js", array('schedule', 'wp-ajax-response'), false, 1 ); 110 111 $scripts->add( 'heartbeat', "/wp-includes/js/heartbeat$suffix.js", array(), false, 1 ); 112 did_action( 'init' ) && $scripts->localize( 'heartbeat', 'heartbeatSettings', 113 apply_filters( 'heartbeatSettings', array( 'nonce' => wp_create_nonce( 'heartbeat-nonce' ) ) ) 114 ); 110 115 111 116 $scripts->add( 'wp-lists', "/wp-includes/js/wp-lists$suffix.js", array( 'wp-ajax-response', 'jquery-color' ), false, 1 ); 112 117 … … 371 376 372 377 $scripts->add( 'postbox', "/wp-admin/js/postbox$suffix.js", array('jquery-ui-sortable'), false, 1 ); 373 378 374 $scripts->add( 'post', "/wp-admin/js/post$suffix.js", array('suggest', 'wp-lists', 'postbox' ), false, 1 );379 $scripts->add( 'post', "/wp-admin/js/post$suffix.js", array('suggest', 'wp-lists', 'postbox', 'heartbeat'), false, 1 ); 375 380 did_action( 'init' ) && $scripts->localize( 'post', 'postL10n', array( 376 381 'ok' => __('OK'), 377 382 'cancel' => __('Cancel'),