Formatting and eol fixes.

git-svn-id: http://svn.automattic.com/wordpress/trunk@3697 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
matt 2006-04-06 05:25:50 +00:00
parent 8aa385cf3f
commit ecb3101f4e

View File

@ -1,93 +1,94 @@
<?php <?php
function wp_schedule_single_event($timestamp, $hook) {
$args = array_slice(func_get_args(), 2); function wp_schedule_single_event( $timestamp, $hook ) {
$crons = get_option('cron'); $args = array_slice( func_get_args(), 2 );
$crons[$timestamp][$hook] = array('schedule' => false, 'args' => $args); $crons = get_option( 'cron' );
ksort($crons); $crons[$timestamp][$hook] = array( 'schedule' => false, 'args' => $args );
update_option('cron', $crons); ksort( $crons );
update_option( 'cron', $crons );
} }
function wp_schedule_event($timestamp, $recurrence, $hook) {
$args = array_slice(func_get_args(), 3); function wp_schedule_event( $timestamp, $recurrence, $hook ) {
$crons = get_option('cron'); $args = array_slice( func_get_args(), 3 );
$crons = get_option( 'cron' );
$schedules = wp_get_schedules(); $schedules = wp_get_schedules();
if(!isset($schedules[$recurrence])) if ( !isset( $schedules[$recurrence] ) )
return false; return false;
$crons[$timestamp][$hook] = array('schedule' => $recurrence, 'args' => $args, 'interval' => $schedules[$recurrence]['interval']); $crons[$timestamp][$hook] = array( 'schedule' => $recurrence, 'args' => $args, 'interval' => $schedules[$recurrence]['interval'] );
ksort($crons); ksort( $crons );
update_option('cron', $crons); update_option( 'cron', $crons );
} }
function wp_reschedule_event( $timestamp, $recurrence, $hook ) {
function wp_reschedule_event($timestamp, $recurrence, $hook) { $args = array_slice( func_get_args(), 3 );
$args = array_slice(func_get_args(), 3); $crons = get_option( 'cron' );
$crons = get_option('cron');
$schedules = wp_get_schedules(); $schedules = wp_get_schedules();
$interval = 0; $interval = 0;
// First we try to get it from the schedule // First we try to get it from the schedule
if( 0 == $interval ) if ( 0 == $interval )
$interval = $schedules[$recurrence]['interval']; $interval = $schedules[$recurrence]['interval'];
// Now we try to get it from the saved interval in case the schedule disappears // Now we try to get it from the saved interval in case the schedule disappears
if( 0 == $interval ) if ( 0 == $interval )
$interval = $crons[$timestamp][$hook]['interval']; $interval = $crons[$timestamp][$hook]['interval'];
// Now we assume something is wrong and fail to schedule // Now we assume something is wrong and fail to schedule
if( 0 == $interval ) if ( 0 == $interval )
return false; return false;
while($timestamp < time() + 1) { while ( $timestamp < time() + 1 )
$timestamp += $interval; $timestamp += $interval;
}
wp_schedule_event($timestamp, $recurrence, $hook); wp_schedule_event( $timestamp, $recurrence, $hook );
} }
function wp_unschedule_event($timestamp, $hook) { function wp_unschedule_event( $timestamp, $hook ) {
$crons = get_option('cron'); $crons = get_option( 'cron' );
unset($crons[$timestamp][$hook]); unset( $crons[$timestamp][$hook] );
if ( empty($crons[$timestamp]) ) if ( empty($crons[$timestamp]) )
unset($crons[$timestamp]); unset( $crons[$timestamp] );
update_option('cron', $crons); update_option( 'cron', $crons );
} }
function wp_clear_scheduled_hook($hook) { function wp_clear_scheduled_hook( $hook ) {
while($timestamp = wp_next_scheduled($hook)) while ( $timestamp = wp_next_scheduled( $hook ) )
wp_unschedule_event($timestamp, $hook); wp_unschedule_event( $timestamp, $hook );
} }
function wp_next_scheduled($hook) { function wp_next_scheduled( $hook ) {
$crons = get_option('cron'); $crons = get_option( 'cron' );
if ( empty($crons) ) if ( empty($crons) )
return false; return false;
foreach($crons as $timestamp => $cron) { foreach ( $crons as $timestamp => $cron )
//if($timestamp <= time()) continue; if ( isset( $cron[$hook] ) )
if(isset($cron[$hook])) return $timestamp; return $timestamp;
}
return false; return false;
} }
function spawn_cron() { function spawn_cron() {
if (array_shift(array_keys(get_option('cron'))) > time()) return; if ( array_shift( array_keys( get_option( 'cron' ) ) ) > time() )
return;
$cron_url = get_settings('siteurl') . '/wp-cron.php';
$parts = parse_url($cron_url); $cron_url = get_settings( 'siteurl' ) . '/wp-cron.php';
$parts = parse_url( $cron_url );
$argyle = @ fsockopen($parts['host'], $_SERVER['SERVER_PORT'], $errno, $errstr, 0.01);
$argyle = @ fsockopen( $parts['host'], $_SERVER['SERVER_PORT'], $errno, $errstr, 0.01 );
if ( $argyle ) if ( $argyle )
fputs($argyle, fputs( $argyle,
"GET {$parts['path']}?check=" . md5(DB_PASS . '187425') . " HTTP/1.0\r\n" "GET {$parts['path']}?check=" . md5(DB_PASS . '187425') . " HTTP/1.0\r\n"
. "Host: {$_SERVER['HTTP_HOST']}\r\n\r\n" . "Host: {$_SERVER['HTTP_HOST']}\r\n\r\n"
); );
} }
function wp_cron() { function wp_cron() {
$crons = get_option('cron'); $crons = get_option( 'cron' );
if (!is_array($crons) || array_shift(array_keys($crons)) > time()) if ( !is_array($crons) || array_shift( array_keys( $crons ) ) > time() )
return; return;
$schedules = wp_get_schedules(); $schedules = wp_get_schedules();
foreach ($crons as $timestamp => $cronhooks) { foreach ( $crons as $timestamp => $cronhooks ) {
if ($timestamp > time()) break; if ( $timestamp > time() ) break;
foreach($cronhooks as $hook => $args) { foreach ( $cronhooks as $hook => $args ) {
if(isset($schedules[$hook]['callback']) && !call_user_func($schedules[$hook]['callback'])) if ( isset($schedules[$hook]['callback']) && !call_user_func( $schedules[$hook]['callback'] ) )
continue; continue;
spawn_cron(); spawn_cron();
break 2; break 2;
@ -97,9 +98,10 @@ function wp_cron() {
function wp_get_schedules() { function wp_get_schedules() {
$schedules = array( $schedules = array(
'hourly' => array('interval' => 3600, 'display' => __('Once Hourly')), 'hourly' => array( 'interval' => 3600, 'display' => __('Once Hourly') ),
'daily' => array('interval' => 86400, 'display' => __('Once Daily')), 'daily' => array( 'interval' => 86400, 'display' => __('Once Daily') ),
); );
return array_merge(apply_filters('cron_schedules', array()), $schedules); return array_merge( apply_filters( 'cron_schedules', array() ), $schedules );
} }
?>
?>