maxlength=256;
$snoop->read_timeout=10;
$oldLevel=error_reporting(E_ALL^(E_WARNING|E_NOTICE));
$result=$snoop->fetch($url);
error_reporting($oldLevel);
if ($result)
return TRUE;
$error=$snoop->error;
return FALSE;
}
//------------------------------------------------------------------------------
function utopia38_validate($time,$freq,$url)
{
// make input work - if really bad, return false, else finished entry
$now=time();
if (!preg_match('@^(2[0-3]|[01][0-9]|[0-9]).(\d\d)$@',trim($time),$matches))
return FALSE;
$timeValue=intval($matches[1])*3600+intval($matches[2])*60;
// time can be 0m or 0h format
if (!preg_match('@^(\d+)\s*([mhMH]?)$@',$freq,$matches))
return FALSE;
$freqValue=$matches[1]*60;
// if 'm' and 'h' not included, assume 'h'
if ( 'm'!=$matches[2] && 'M'!=$matches[2] )
$freqValue *= 60;
// never allow calling frequency of less than 5 minutes
$freqValue=max(300,$freqValue);
// get gmt time of call start and clamp to 24 hour day
$offset=get_settings('gmt_offset')*3600;
$timeValue=($timeValue-$offset+86400)%86400;
// now find next gmt time that we 'fire'
$nextCall=utopia38_next($timeValue,$freqValue,$now);
$rec=array('t'=>$timeValue,'f'=>$freqValue,'u'=>$url,'c'=>$nextCall);
return $rec;
}
//------------------------------------------------------------------------------
function utopia38_next($start,$freq,$now)
{
// figure out next firing time (sec) and return it
$midnight=$now-($now%86400);
$startTime=$midnight+$start;
if ($startTime>$now)
$startTime -= 86400;
// get crossover time
$remainder=($now-$startTime)%$freq;
$nextTick=$now+($freq-$remainder);
// avoid pointing back to 'now'
if ($startTime-$now<30)
$startTime += $freq;
return $nextTick;
}
//------------------------------------------------------------------------------
function utopia38_menu()
{
if (!current_user_can('manage_options'))
{
echo '
This section is only available to the administrator.
';
exit();
}
$data=get_option('utopia38_data');
$list=(isset($data['l'])?$data['l']:array());
$total=count($list);
$quoted=get_magic_quotes_gpc();
$time="";
$freq="";
$url="";
$msg="";
$update=FALSE;
// get input (if any)
if (isset($_POST['add']))
{
$time=trim(isset($_POST["time"])?$_POST["time"]:"");
$freq=trim(isset($_POST["freq"])?$_POST["freq"]:"");
$url=trim(isset($_POST["url"])?$_POST["url"]:"");
if ($quoted)
{
$url=stripslashes($url);
}
$rec=utopia38_validate($time,$freq,$url);
if (is_array($rec))
{
$list[]=$rec;
$msg="Entry added";
$update=TRUE;
}
else
{
$msg="Invalid inputs";
}
}
else
{
// check if one of our keys
for ($i=0;$i<$total;++$i)
{
if (isset($_POST["del$i"]))
{
// delete entry & pack array
array_splice($list,$i,1);
$msg="Entry deleted";
$update=TRUE;
break;
}
else if (isset($_POST["edit$i"]))
{
// update entry
$time=trim(isset($_POST["time$i"])?$_POST["time$i"]:"");
$freq=trim(isset($_POST["freq$i"])?$_POST["freq$i"]:"");
$url=trim(isset($_POST["url$i"])?$_POST["url$i"]:"");
if ($quoted)
{
$url=stripslashes($url);
}
$rec=utopia38_validate($time,$freq,$url);
if (is_array($rec))
{
$list[$i]=$rec;
$msg="Entry updated";
$update=TRUE;
}
else
{
$msg="Invalid inputs - couldn't update";
}
break;
}
else if (isset($_POST["test$i"]))
{
// try and access entry
$url=$list[$i]['u'];
if (utopia38_check($url,$msg))
$msg="Read AOK: $url";
break;
}
}
}
// save if needed
if ($update)
{
$data['l']=$list;
update_option('utopia38_data',$data);
$total=count($list);
}
// now output results
$homeURL=get_bloginfo('home');
$color='bgcolor="#E5F3FF"';
if (!empty($msg))
$msg=''.htmlentities($msg,ENT_QUOTES,'UTF-8').'
';
echo <<U-Cron (Utopia Cron) Easy Timed Jobs
URL Loading/Checks
$msg
How to Use
This is a simple plugin to approximately time tasks. As visitors load your blog
pages, this
plugin checks if any pages need loading and does so. By loading these web pages,
you can do useful tasks like checking your email. What you do is:
- Enter the URL of the web page to check.
This is the web page to 'load', or trigger. For example, if you wanted to run
your e-mail post checker (as set in Options/Writing/Post via e-mail), you could
try this entry:
{$homeURL}/wp-mail.php
- Enter a starting time for the check.
For example you might want to check at 2:35 pm, which is entered 14:35
(Military time, where the hour goes from 0 to 24). Note for repeated checks just
pick a start time (for example if you want 10 minutes after the hour, just pick
00:10 or 01:10, etc).
- Enter a repeat time for the check.
This is how often you want to check - for instance every 10 minutes, 15 minutes,
or even 24 hours to do it just once a day. Make sure you add m or h
after the number to set hours or minutes (for example 15m or 12h -
if you leave it off, hours are assumed).
- Save, then test.
Save the entry, then use the Test and View buttons to verify.
Test will load the page just as U-Cron would, and displays the result
(AOK or an error message). The View link opens the URL in a
seperate page, so you can confirm that the page you're loading is the right one.
Notes
Easy cron plugin for WordPress (utopia38/U-Cron) v1.00 © David Pankhurst/
ActiveBlogging.com. Licensed Under
Artistic License 2.0
HTML_CODE;
}
//------------------------------------------------------------------------------
if (!is_plugin_page())
{
// simple addon - add page to manager panel - no upper panels, no multipage, etc...
function utopia38_menuAdd()
{
add_submenu_page('edit.php','U-Cron','U-Cron',9,'u38_menu','utopia38_menu');
}
add_action('admin_menu','utopia38_menuAdd');
}
//------------------------------------------------------------------------------
add_action('wp_footer','utopia38_cron');
//------------------------------------------------------------------------------
?>