1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 12:48:24 +01:00

Initial commit of e_cron task scheduling.

This commit is contained in:
CaMer0n 2008-06-17 05:39:46 +00:00
parent b691081942
commit 8ea8db9f56
13 changed files with 1061 additions and 15 deletions

92
cron.php Normal file
View File

@ -0,0 +1,92 @@
#!/usr/bin/php -q
<?php
/*
+ ----------------------------------------------------------------------------+
|| e107 website system
|
| ©Steve Dunstan 2001-2002
| http://e107.org
| jalist@e107.org
|
| Released under the terms and conditions of the
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/cron.php,v $
| $Revision: 1.1 $
| $Date: 2008-06-17 05:39:22 $
| $Author: e107coders $
+----------------------------------------------------------------------------+
*/
// Usage: [full path to this script]cron.php --u=admin --p=password // use your admin login.
$_E107['cli'] = TRUE;
require_once(realpath(dirname(__FILE__)."/class2.php"));
// from the plugin directory:
// realpath(dirname(__FILE__)."/../../")."/";
//echo "\n\nUSERNAME= ".USERNAME."\n";
//echo "\nUSEREMAIL= ".USEREMAIL."\n";
if($pref['e_cron_pref']) // grab cron
{
foreach($pref['e_cron_pref'] as $func=>$cron)
{
if($cron['active']==1)
{
$list[$func] = $cron;
}
}
}
require_once(e_HANDLER."cron_class.php");
$cron = new CronParser();
foreach($list as $func=>$val)
{
$cron->calcLastRan($val['tab']);
$due = $cron->getLastRanUnix();
if($due > (time()-45))
{
if(is_readable(e_PLUGIN.$val['path']."/e_cron.php"))
{
// echo date("r")." ".$func."\n";
require_once(e_PLUGIN.$val['path']."/e_cron.php");
if(call_user_func($func)===FALSE)
{
// echo "\nerror running the function ".$func.".\n"; log the error.
}
}
}
// echo "Cron Unix = ". $cron->getLastRanUnix();
// echo "<br />Now = ".time();
}
// echo "<br />Cron '$cron_str0' last due at: " . date('r', $cron->getLastRanUnix()) . "<p>";
// $cron->getLastRan() returns last due time in an array
// print_a($cron->getLastRan());
// echo "Debug:<br>" . nl2br($cron->getDebug());
/*
$cron_str1 = "3 12 * * *";
if ($cron->calcLastRan($cron_str1))
{
echo "<p>Cron '$cron_str1' last due at: " . date('r', $cron->getLastRanUnix()) . "<p>";
print_r($cron->getLastRan());
}
else
{
echo "Error parsing";
}
echo "Debug:<br>" . nl2br($cron->getDebug());
*/
exit;
?>

View File

@ -11,9 +11,9 @@
| GNU General Public License (http://gnu.org). | GNU General Public License (http://gnu.org).
| |
| $Source: /cvs_backup/e107_0.8/e107_admin/ad_links.php,v $ | $Source: /cvs_backup/e107_0.8/e107_admin/ad_links.php,v $
| $Revision: 1.3 $ | $Revision: 1.4 $
| $Date: 2007-12-15 15:06:40 $ | $Date: 2008-06-17 05:39:22 $
| $Author: e107steved $ | $Author: e107coders $
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
*/ */
@ -122,6 +122,9 @@ if (!defined('E_16_CACHE')) {
if (!defined('E_16_CREDITS')) { if (!defined('E_16_CREDITS')) {
define('E_16_CREDITS', "<img src='".e_IMAGE."packs/".$imode."/admin_images/credits_16.png' alt='' style='border:0px; vertical-align:bottom; width: 16px; height: 16px' />"); define('E_16_CREDITS', "<img src='".e_IMAGE."packs/".$imode."/admin_images/credits_16.png' alt='' style='border:0px; vertical-align:bottom; width: 16px; height: 16px' />");
} }
if (!defined('E_16_CRON')) {
define('E_16_CRON', "<img src='".e_IMAGE."packs/".$imode."/admin_images/cron_16.png' alt='' style='border:0px; vertical-align:bottom; width: 16px; height: 16px' />");
}
if (!defined('E_16_CUST')) { if (!defined('E_16_CUST')) {
define('E_16_CUST', "<img src='".e_IMAGE."packs/".$imode."/admin_images/custom_16.png' alt='' style='border:0px; vertical-align:bottom; width: 16px; height: 16px' />"); define('E_16_CUST', "<img src='".e_IMAGE."packs/".$imode."/admin_images/custom_16.png' alt='' style='border:0px; vertical-align:bottom; width: 16px; height: 16px' />");
} }
@ -245,6 +248,10 @@ if (!defined('E_32_CACHE')) {
if (!defined('E_32_CREDITS')) { if (!defined('E_32_CREDITS')) {
define('E_32_CREDITS', "<img src='".e_IMAGE."packs/".$imode."/admin_images/credits_32.png' alt='' style='border:0px; width: 32px; height: 32px' />"); define('E_32_CREDITS', "<img src='".e_IMAGE."packs/".$imode."/admin_images/credits_32.png' alt='' style='border:0px; width: 32px; height: 32px' />");
} }
if (!defined('E_32_CRON')) {
define('E_32_CRON', "<img src='".e_IMAGE."packs/".$imode."/admin_images/cron_32.png' alt='' style='border:0px; width: 32px; height: 32px' />");
}
if (!defined('E_32_CUST')) { if (!defined('E_32_CUST')) {
define('E_32_CUST', "<img src='".e_IMAGE."packs/".$imode."/admin_images/custom_32.png' alt='' style='border:0px; width: 32px; height: 32px' />"); define('E_32_CUST', "<img src='".e_IMAGE."packs/".$imode."/admin_images/custom_32.png' alt='' style='border:0px; width: 32px; height: 32px' />");
} }
@ -364,6 +371,7 @@ $e_icon_array = array(
'banner' => E_32_BANNER, 'banner' => E_32_BANNER,
'cache' => E_32_CACHE, 'cache' => E_32_CACHE,
'credits' => E_32_CREDITS, 'credits' => E_32_CREDITS,
'cron' => E_32_CRON,
'custom' => E_32_CUST, 'custom' => E_32_CUST,
'database' => E_32_DATAB, 'database' => E_32_DATAB,
'docs' => E_32_DOCS, 'docs' => E_32_DOCS,
@ -467,6 +475,7 @@ $array_functions = array(
27 => array(e_ADMIN."mailout.php", ADLAN_136, ADLAN_137, "W", 2, E_16_MAIL, E_32_MAIL), 27 => array(e_ADMIN."mailout.php", ADLAN_136, ADLAN_137, "W", 2, E_16_MAIL, E_32_MAIL),
28 => array(e_ADMIN."users_extended.php", ADLAN_78, ADLAN_79, "4", 2, E_16_USER_EXTENDED, E_32_USER_EXTENDED), 28 => array(e_ADMIN."users_extended.php", ADLAN_78, ADLAN_79, "4", 2, E_16_USER_EXTENDED, E_32_USER_EXTENDED),
29 => array(e_ADMIN."fileinspector.php", ADLAN_147, ADLAN_148, "Y", 4, E_16_INSPECT, E_32_INSPECT), 29 => array(e_ADMIN."fileinspector.php", ADLAN_147, ADLAN_148, "Y", 4, E_16_INSPECT, E_32_INSPECT),
30 => array(e_ADMIN."notify.php", ADLAN_149, ADLAN_150, "O", 4, E_16_NOTIFY, E_32_NOTIFY) 30 => array(e_ADMIN."notify.php", ADLAN_149, ADLAN_150, "O", 4, E_16_NOTIFY, E_32_NOTIFY),
31 => array(e_ADMIN."cron.php", ADLAN_157, ADLAN_158, "U", 4, E_16_CRON, E_32_CRON)
); );
?> ?>

View File

@ -11,9 +11,9 @@
| GNU General Public License (http://gnu.org). | GNU General Public License (http://gnu.org).
| |
| $Source: /cvs_backup/e107_0.8/e107_admin/administrator.php,v $ | $Source: /cvs_backup/e107_0.8/e107_admin/administrator.php,v $
| $Revision: 1.3 $ | $Revision: 1.4 $
| $Date: 2007-12-15 15:06:40 $ | $Date: 2008-06-17 05:39:22 $
| $Author: e107steved $ | $Author: e107coders $
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
*/ */
require_once('../class2.php'); require_once('../class2.php');
@ -191,7 +191,7 @@ function edit_administrator($row){
$text .= checkb("Y", $a_perms).ADMSLAN_67."<br />"; // file inspector $text .= checkb("Y", $a_perms).ADMSLAN_67."<br />"; // file inspector
$text .= checkb("O", $a_perms).ADMSLAN_68."<br />"; // notify $text .= checkb("O", $a_perms).ADMSLAN_68."<br />"; // notify
$text .= checkb("7", $a_perms).ADMSLAN_26."<br />"; // Oversee news categories $text .= checkb("7", $a_perms).ADMSLAN_26."<br />"; // Oversee news categories
$text .= checkb("8", $a_perms).ADMSLAN_27."<br />"; // Oversee link categories // $text .= checkb("8", $a_perms).ADMSLAN_27."<br />"; // Oversee link categories
$text .= checkb("C", $a_perms).ADMSLAN_64."<br />"; // Clear Cache - Previously moderate chatbox $text .= checkb("C", $a_perms).ADMSLAN_64."<br />"; // Clear Cache - Previously moderate chatbox
$text .= checkb("9", $a_perms).ADMSLAN_28."<br />"; // Take site down for maintenance $text .= checkb("9", $a_perms).ADMSLAN_28."<br />"; // Take site down for maintenance
$text .= checkb("W", $a_perms).ADMSLAN_65."<br /><br />"; // Configure mail settings and mailout $text .= checkb("W", $a_perms).ADMSLAN_65."<br /><br />"; // Configure mail settings and mailout

251
e107_admin/cron.php Normal file
View File

@ -0,0 +1,251 @@
<?php
/*
+ ----------------------------------------------------------------------------+
| e107 website system
|
| ©Steve Dunstan 2001-2002
| http://e107.org
| jalist@e107.org
|
| Released under the terms and conditions of the
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_admin/cron.php,v $
| $Revision: 1.1 $
| $Date: 2008-06-17 05:39:22 $
| $Author: e107coders $
+----------------------------------------------------------------------------+
*/
require_once('../class2.php');
if (!getperms('U'))
{
header('location:'.e_BASE.'index.php');
exit;
}
$e_sub_cat = 'cron';
require_once('auth.php');
if(isset($_POST['submit']))
{
foreach($_POST['cron'] as $key=>$val)
{
if(!$val['active'])
{
$val['active'] = 0;
}
$t['minute'] = implode(",",$_POST['tab'][$key]['minute']);
$t['hour'] = implode(",",$_POST['tab'][$key]['hour']);
$t['day'] = implode(",",$_POST['tab'][$key]['day']);
$t['month'] = implode(",",$_POST['tab'][$key]['month']);
$t['weekday'] = implode(",",$_POST['tab'][$key]['weekday']);
$val['tab'] = implode(" ",$t);
$tabs .= $val['tab']."<br />";
$cron[$key] = $val;
}
$pref['e_cron_pref'] = $cron;
save_prefs();
$ns -> tablerender(LAN_SAVED,"<div style='text-align:center'>".LAN_SETSAVED."</div>");
}
$cronpref = $pref['e_cron_pref'];
// ----------- Grab All e_cron parameters -----------------------------------
$count = 0;
foreach($pref['e_cron_list'] as $key=>$val)
{
$eplug_cron = array();
if(is_readable(e_PLUGIN.$key."/e_cron.php"))
{
require_once(e_PLUGIN.$key."/e_cron.php");
foreach($eplug_cron as $v)
{
$e_cron[$count]['name'] = $v['name'];
$e_cron[$count]['function'] = $v['function'];
$e_cron[$count]['description'] = $v['description'];
$e_cron[$count]['path'] = $key;
$count++;
}
}
}
// ---------------------- List All Functions -----------------------------
$text = "<div style='text-align:center'>
<form method='post' action='".e_SELF."' id='linkform'>
<table style='".ADMIN_WIDTH."' class='fborder'>
<tr>
<td class='fcaption'>".LAN_CRON_1."</td>
<td class='fcaption'>".LAN_CRON_2."</td>
<td class='fcaption'>".LAN_CRON_3."</td>
<td class='fcaption'>".LAN_CRON_4."</td>
<td class='fcaption'>".LAN_CRON_5."</td>
<td class='fcaption'>".LAN_CRON_6."</td>
<td class='fcaption'>".LAN_CRON_7."</td>
<td class='fcaption'>".LAN_CRON_8."</td>
</tr>";
foreach($e_cron as $cron)
{
$c = $cron['function'];
$sep = array();
list($sep['minute'],$sep['hour'],$sep['day'],$sep['month'],$sep['weekday']) = explode(" ",$cronpref[$c]['tab']);
foreach($sep as $key=>$value)
{
if($value=="")
{
$sep[$key] = "*";
}
}
$minute = explode(",",$sep['minute']);
$hour = explode(",",$sep['hour']);
$day = explode(",",$sep['day']);
$month = explode(",",$sep['month']);
$weekday = explode(",",$sep['weekday']);
$min_options = array(
"*" => LAN_CRON_11,
"0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58" => LAN_CRON_12,
"0,5,10,15,20,25,30,35,40,45,50,55" => LAN_CRON_13,
"0,10,20,30,40,50" => LAN_CRON_14,
"0,15,30,45" => LAN_CRON_15
);
$hour_options = array(
"*" => LAN_CRON_16,
"0,2,4,6,8,10,12,14,16,18,20,22" => LAN_CRON_17,
"0,3,6,9,12,15,18,21" => LAN_CRON_18,
"0,6,12,18" => LAN_CRON_19
);
$text .= "<tr>
<td class='forumheader3'>".$cron['name']."</td>
<td class='forumheader3'>".$cron['description']."</td>
<td class='forumheader3'>
<input type='hidden' name='cron[$c][path]' value='".$cron['path']."' />
<select class='tbox' style='height:70px' multiple='multiple' name='tab[$c][minute][]'>\n";
foreach($min_options as $key=>$val)
{
if($sep['minute'] == $key)
{
$sel = "selected='selected'";
$minute = "";
}
else
{
$sel = "";
}
$text .= "<option value='$key' $sel>".$val."</option>\n";
}
for ($i=0; $i<=59; $i++)
{
$sel = (in_array(strval($i),$minute)) ? "selected='selected'" : "";
$text .= "<option value='$i' $sel>".$i."</option>\n";
}
$text .= "</select>
</td>
<td class='forumheader3'>
<select class='tbox' style='height:70px' multiple='multiple' name='tab[$c][hour][]'>
\n";
foreach($hour_options as $key=>$val)
{
if($sep['hour'] == $key)
{
$sel = "selected='selected'";
$hour = "";
}
else
{
$sel = "";
}
$text .= "<option value='$key' $sel>".$val."</option>\n";
}
for ($i=0; $i<=23; $i++)
{
$sel = (in_array(strval($i),$hour)) ? "selected='selected'" : "";
$diz = mktime($i,00,00,1,1,2000);
$text .= "<option value='$i' $sel>".$i." - ".date("g A",$diz)."</option>\n";
}
$text .= "</select>
</td>
<td class='forumheader3'>
<select class='tbox' style='height:70px' multiple='multiple' name='tab[$c][day][]'>\n";
$sel_day = ($day[0] == "*") ? "selected='selected'" : "";
$text .= "<option value='*' {$sel_day}>".LAN_CRON_20."</option>\n"; // Every Day
for ($i=1; $i<=31; $i++)
{
$sel = (in_array($i,$day)) ? "selected='selected'" : "";
$text .= "<option value='$i' $sel>".$i."</option>\n";
}
$text .= "</select>
</td>
<td class='forumheader3'>
<select class='tbox' style='height:70px' multiple='multiple' name='tab[$c][month][]'>\n";
$sel_month = ($month[0] == "*") ? "selected='selected'" : "";
$text .= "<option value='*' $sel_month>".LAN_CRON_21."</option>\n"; // Every Month
for ($i=1; $i<=12; $i++)
{
$sel = (in_array($i,$month)) ? "selected='selected'" : "";
$diz = mktime(00,00,00,$i,1,2000);
$text .= "<option value='$i' $sel>".strftime("%B",$diz)."</option>\n";
}
$text .= "</select>
</td>
<td class='forumheader3'>
<select class='tbox' style='height:70px' multiple='multiple' name='tab[$c][weekday][]'>\n";
$sel_weekday = ($weekday[0] == "*") ? "selected='selected'" : "";
$text .= "<option value='*' $sel_weekday>".LAN_CRON_22."</option>\n"; // Every Week Day.
$days = array(LAN_SUN,LAN_MON,LAN_TUE,LAN_WED,LAN_THU,LAN_FRI,LAN_SAT);
for ($i=0; $i<=6; $i++)
{
$sel = (in_array(strval($i),$weekday)) ? "selected='selected'" : "";
$text .= "<option value='$i' $sel>".$days[$i]."</option>\n";
}
$text .= "</select>
</td>
<td class='forumheader3' style='text-align:center'>";
$checked = ($cronpref[$c]['active'] == 1) ? "checked='checked'" : "";
$text .= "<input type='checkbox' name='cron[$c][active]' value='1' $checked />
</td>
</tr>";
}
$text .= "
<tr style='vertical-align:top'>
<td colspan='8' style='text-align:center' class='forumheader'>";
$text .= "<input class='button' type='submit' name='submit' value='".LAN_SAVE."' />";
$text .= "</td>
</tr>
</table>
</form>
</div>";
$ns -> tablerender(PAGE_NAME, $text);
require_once(e_ADMIN."footer.php");
exit;
?>

View File

@ -0,0 +1,604 @@
<?php /* $Id: cron_class.php,v 1.1 2008-06-17 05:39:22 e107coders Exp $ */
/**####################################################################################################**\
Version: V1.01
Release Date: 12 Sep 2005
Licence: GPL
By: Nikol S
Please send bug reports to ns@eyo.com.au
\**####################################################################################################**/
/* This class is based on the concept in the CronParser class written by Mick Sear http://www.ecreate.co.uk
* The following functions are direct copies from or based on the original class:
* getLastRan(), getDebug(), debug(), expand_ranges()
*
* Who can use this class?
* This class is idea for people who can not use the traditional Unix cron through shell.
* One way of using is embedding the calling script in a web page which is often visited.
* The script will work out the last due time, by comparing with run log timestamp. The scrip
* will envoke any scripts needed to run, be it deleting older table records, or updating prices.
* It can parse the same cron string used by Unix.
*/
/* Usage example:
$cron_str0 = "0,12,30-51 3,21-23,10 1-25 9-12,1 0,3-7";
require_once("CronParser.php");
$cron = new CronParser();
$cron->calcLastRan($cron_str0);
// $cron->getLastRanUnix() returns an Unix timestamp
echo "Cron '$cron_str0' last due at: " . date('r', $cron->getLastRanUnix()) . "<p>";
// $cron->getLastRan() returns last due time in an array
print_r($cron->getLastRan());
echo "Debug:<br>" . nl2br($cron->getDebug());
$cron_str1 = "3 12 * * *";
if ($cron->calcLastRan($cron_str1))
{
echo "<p>Cron '$cron_str1' last due at: " . date('r', $cron->getLastRanUnix()) . "<p>";
print_r($cron->getLastRan());
}
else
{
echo "Error parsing";
}
echo "Debug:<br>" . nl2br($cron->getDebug());
*#######################################################################################################
*/
class CronParser
{
var $bits = Array(); //exploded String like 0 1 * * *
var $now = Array(); //Array of cron-style entries for time()
var $lastRan; //Timestamp of last ran time.
var $taken;
var $debug;
var $year;
var $month;
var $day;
var $hour;
var $minute;
var $minutes_arr = array(); //minutes array based on cron string
var $hours_arr = array(); //hours array based on cron string
var $months_arr = array(); //months array based on cron string
function getLastRan()
{
return explode(",", strftime("%M,%H,%d,%m,%w,%Y", $this->lastRan)); //Get the values for now in a format we can use
}
function getLastRanUnix()
{
return $this->lastRan;
}
function getDebug()
{
return $this->debug;
}
function debug($str)
{
if (is_array($str))
{
$this->debug .= "\nArray: ";
foreach($str as $k=>$v)
{
$this->debug .= "$k=>$v, ";
}
}
else
{
$this->debug .= "\n$str";
}
//echo nl2br($this->debug);
}
/**
* Assumes that value is not *, and creates an array of valid numbers that
* the string represents. Returns an array.
*/
function expand_ranges($str)
{
if (strstr($str, ","))
{
$arParts = explode(',', $str);
foreach ($arParts AS $part)
{
if (strstr($part, '-'))
{
$arRange = explode('-', $part);
for ($i = $arRange[0]; $i <= $arRange[1]; $i++)
{
$ret[] = $i;
}
}
else
{
$ret[] = $part;
}
}
}
elseif (strstr($str, '-'))
{
$arRange = explode('-', $str);
for ($i = $arRange[0]; $i <= $arRange[1]; $i++)
{
$ret[] = $i;
}
}
else
{
$ret[] = $str;
}
$ret = array_unique($ret);
sort($ret);
return $ret;
}
function daysinmonth($month, $year)
{
return date('t', mktime(0, 0, 0, $month, 1, $year));
}
/**
* Calculate the last due time before this moment
*/
function calcLastRan($string)
{
$tstart = microtime();
$this->debug = "";
$this->lastRan = 0;
$this->year = NULL;
$this->month = NULL;
$this->day = NULL;
$this->hour = NULL;
$this->minute = NULL;
$this->hours_arr = array();
$this->minutes_arr = array();
$this->months_arr = array();
$string = preg_replace('/[\s]{2,}/', ' ', $string);
if (preg_match('/[^-,* \\d]/', $string) !== 0)
{
$this->debug("Cron String contains invalid character");
return false;
}
$this->debug("<b>Working on cron schedule: $string</b>");
$this->bits = @explode(" ", $string);
if (count($this->bits) != 5)
{
$this->debug("Cron string is invalid. Too many or too little sections after explode");
return false;
}
//put the current time into an array
$t = strftime("%M,%H,%d,%m,%w,%Y", time());
$this->now = explode(",", $t);
$this->year = $this->now[5];
$arMonths = $this->_getMonthsArray();
do
{
$this->month = array_pop($arMonths);
}
while ($this->month > $this->now[3]);
if ($this->month === NULL)
{
$this->year = $this->year - 1;
$this->debug("Not due within this year. So checking the previous year " . $this->year);
$arMonths = $this->_getMonthsArray();
$this->_prevMonth($arMonths);
}
elseif ($this->month == $this->now[3]) //now Sep, month = array(7,9,12)
{
$this->debug("Cron is due this month, getting days array.");
$arDays = $this->_getDaysArray($this->month, $this->year);
do
{
$this->day = array_pop($arDays);
}
while ($this->day > $this->now[2]);
if ($this->day === NULL)
{
$this->debug("Smallest day is even greater than today");
$this->_prevMonth($arMonths);
}
elseif ($this->day == $this->now[2])
{
$this->debug("Due to run today");
$arHours = $this->_getHoursArray();
do
{
$this->hour = array_pop($arHours);
}
while ($this->hour > $this->now[1]);
if ($this->hour === NULL) // now =2, arHours = array(3,5,7)
{
$this->debug("Not due this hour and some earlier hours, so go for previous day");
$this->_prevDay($arDays, $arMonths);
}
elseif ($this->hour < $this->now[1]) //now =2, arHours = array(1,3,5)
{
$this->minute = $this->_getLastMinute();
}
else // now =2, arHours = array(1,2,5)
{
$this->debug("Due this hour");
$arMinutes = $this->_getMinutesArray();
do
{
$this->minute = array_pop($arMinutes);
}
while ($this->minute > $this->now[0]);
if ($this->minute === NULL)
{
$this->debug("Not due this minute, so go for previous hour.");
$this->_prevHour($arHours, $arDays, $arMonths);
}
else
{
$this->debug("Due this very minute or some earlier minutes before this moment within this hour.");
}
}
}
else
{
$this->debug("Cron was due on " . $this->day . " of this month");
$this->hour = $this->_getLastHour();
$this->minute = $this->_getLastMinute();
}
}
else //now Sep, arrMonths=array(7, 10)
{
$this->debug("Cron was due before this month. Previous month is: " . $this->year . '-' . $this->month);
$this->day = $this->_getLastDay($this->month, $this->year);
if ($this->day === NULL)
{
//No scheduled date within this month. So we will try the previous month in the month array
$this->_prevMonth($arMonths);
}
else
{
$this->hour = $this->_getLastHour();
$this->minute = $this->_getLastMinute();
}
}
$tend = microtime();
$this->taken = $tend - $tstart;
$this->debug("Parsing $string taken " . $this->taken . " seconds");
//if the last due is beyond 1970
if ($this->minute === NULL)
{
$this->debug("Error calculating last due time");
return false;
}
else
{
$this->debug("LAST DUE: " . $this->hour . ":" . $this->minute . " on " . $this->day . "/" . $this->month . "/" . $this->year);
$this->lastRan = mktime($this->hour, $this->minute, 0, $this->month, $this->day, $this->year);
return true;
}
}
//get the due time before current month
function _prevMonth($arMonths)
{
$this->month = array_pop($arMonths);
if ($this->month === NULL)
{
$this->year = $this->year -1;
if ($this->year <= 1970)
{
$this->debug("Can not calculate last due time. At least not before 1970..");
}
else
{
$this->debug("Have to go for previous year " . $this->year);
$arMonths = $this->_getMonthsArray();
$this->_prevMonth($arMonths);
}
}
else
{
$this->debug("Getting the last day for previous month: " . $this->year . '-' . $this->month);
$this->day = $this->_getLastDay($this->month, $this->year);
if ($this->day === NULL)
{
//no available date schedule in this month
$this->_prevMonth($arMonths);
}
else
{
$this->hour = $this->_getLastHour();
$this->minute = $this->_getLastMinute();
}
}
}
//get the due time before current day
function _prevDay($arDays, $arMonths)
{
$this->debug("Go for the previous day");
$this->day = array_pop($arDays);
if ($this->day === NULL)
{
$this->debug("Have to go for previous month");
$this->_prevMonth($arMonths);
}
else
{
$this->hour = $this->_getLastHour();
$this->minute = $this->_getLastMinute();
}
}
//get the due time before current hour
function _prevHour($arHours, $arDays, $arMonths)
{
$this->debug("Going for previous hour");
$this->hour = array_pop($arHours);
if ($this->hour === NULL)
{
$this->debug("Have to go for previous day");
$this->_prevDay($arDays, $arMonths);
}
else
{
$this->minute = $this->_getLastMinute();
}
}
//not used at the moment
function _getLastMonth()
{
$months = $this->_getMonthsArray();
$month = array_pop($months);
return $month;
}
function _getLastDay($month, $year)
{
//put the available days for that month into an array
$days = $this->_getDaysArray($month, $year);
$day = array_pop($days);
return $day;
}
function _getLastHour()
{
$hours = $this->_getHoursArray();
$hour = array_pop($hours);
return $hour;
}
function _getLastMinute()
{
$minutes = $this->_getMinutesArray();
$minute = array_pop($minutes);
return $minute;
}
//remove the out of range array elements. $arr should be sorted already and does not contain duplicates
function _sanitize ($arr, $low, $high)
{
$count = count($arr);
for ($i = 0; $i <= ($count - 1); $i++)
{
if ($arr[$i] < $low)
{
$this->debug("Remove out of range element. {$arr[$i]} is outside $low - $high");
unset($arr[$i]);
}
else
{
break;
}
}
for ($i = ($count - 1); $i >= 0; $i--)
{
if ($arr[$i] > $high)
{
$this->debug("Remove out of range element. {$arr[$i]} is outside $low - $high");
unset ($arr[$i]);
}
else
{
break;
}
}
//re-assign keys
sort($arr);
return $arr;
}
//given a month/year, list all the days within that month fell into the week days list.
function _getDaysArray($month, $year = 0)
{
if ($year == 0)
{
$year = $this->year;
}
$days = array();
//return everyday of the month if both bit[2] and bit[4] are '*'
if ($this->bits[2] == '*' AND $this->bits[4] == '*')
{
$days = $this->getDays($month, $year);
}
else
{
//create an array for the weekdays
if ($this->bits[4] == '*')
{
for ($i = 0; $i <= 6; $i++)
{
$arWeekdays[] = $i;
}
}
else
{
$arWeekdays = $this->expand_ranges($this->bits[4]);
$arWeekdays = $this->_sanitize($arWeekdays, 0, 7);
//map 7 to 0, both represents Sunday. Array is sorted already!
if (in_array(7, $arWeekdays))
{
if (in_array(0, $arWeekdays))
{
array_pop($arWeekdays);
}
else
{
$tmp[] = 0;
array_pop($arWeekdays);
$arWeekdays = array_merge($tmp, $arWeekdays);
}
}
}
$this->debug("Array for the weekdays");
$this->debug($arWeekdays);
if ($this->bits[2] == '*')
{
$daysmonth = $this->getDays($month, $year);
}
else
{
$daysmonth = $this->expand_ranges($this->bits[2]);
// so that we do not end up with 31 of Feb
$daysinmonth = $this->daysinmonth($month, $year);
$daysmonth = $this->_sanitize($daysmonth, 1, $daysinmonth);
}
//Now match these days with weekdays
foreach ($daysmonth AS $day)
{
$wkday = date('w', mktime(0, 0, 0, $month, $day, $year));
if (in_array($wkday, $arWeekdays))
{
$days[] = $day;
}
}
}
$this->debug("Days array matching weekdays for $year-$month");
$this->debug($days);
return $days;
}
//given a month/year, return an array containing all the days in that month
function getDays($month, $year)
{
$daysinmonth = $this->daysinmonth($month, $year);
$this->debug("Number of days in $year-$month : $daysinmonth");
$days = array();
for ($i = 1; $i <= $daysinmonth; $i++)
{
$days[] = $i;
}
return $days;
}
function _getHoursArray()
{
if (empty($this->hours_arr))
{
$hours = array();
if ($this->bits[1] == '*')
{
for ($i = 0; $i <= 23; $i++)
{
$hours[] = $i;
}
}
else
{
$hours = $this->expand_ranges($this->bits[1]);
$hours = $this->_sanitize($hours, 0, 23);
}
$this->debug("Hour array");
$this->debug($hours);
$this->hours_arr = $hours;
}
return $this->hours_arr;
}
function _getMinutesArray()
{
if (empty($this->minutes_arr))
{
$minutes = array();
if ($this->bits[0] == '*')
{
for ($i = 0; $i <= 60; $i++)
{
$minutes[] = $i;
}
}
else
{
$minutes = $this->expand_ranges($this->bits[0]);
$minutes = $this->_sanitize($minutes, 0, 59);
}
$this->debug("Minutes array");
$this->debug($minutes);
$this->minutes_arr = $minutes;
}
return $this->minutes_arr;
}
function _getMonthsArray()
{
if (empty($this->months_arr))
{
$months = array();
if ($this->bits[3] == '*')
{
for ($i = 1; $i <= 12; $i++)
{
$months[] = $i;
}
}
else
{
$months = $this->expand_ranges($this->bits[3]);
$months = $this->_sanitize($months, 1, 12);
}
$this->debug("Months array");
$this->debug($months);
$this->months_arr = $months;
}
return $this->months_arr;
}
}
?>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

@ -4,9 +4,9 @@
| e107 website system - Language File. | e107 website system - Language File.
| |
| $Source: /cvs_backup/e107_0.8/e107_languages/English/admin/lan_admin.php,v $ | $Source: /cvs_backup/e107_0.8/e107_languages/English/admin/lan_admin.php,v $
| $Revision: 1.6 $ | $Revision: 1.7 $
| $Date: 2007-12-15 15:06:40 $ | $Date: 2008-06-17 05:39:30 $
| $Author: e107steved $ | $Author: e107coders $
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
*/ */
define("ADLAN_0", "News"); define("ADLAN_0", "News");
@ -178,6 +178,9 @@ define('ADLAN_154', "Error contacting Sourceforge to check for new version");
define('ADLAN_155', 'System Logs'); define('ADLAN_155', 'System Logs');
define('ADLAN_156', 'Admin log, user audit, rolling log'); define('ADLAN_156', 'Admin log, user audit, rolling log');
define("ADLAN_157", "Schedule Tasks");
define("ADLAN_158", "Cron Jobs and Automated Tasks");
define('ADLAN_CL_1', 'Settings'); define('ADLAN_CL_1', 'Settings');
define('ADLAN_CL_2', 'Users'); define('ADLAN_CL_2', 'Users');
define('ADLAN_CL_3', 'Content'); define('ADLAN_CL_3', 'Content');

View File

@ -4,9 +4,9 @@
| e107 website system - Language File. | e107 website system - Language File.
| |
| $Source: /cvs_backup/e107_0.8/e107_languages/English/admin/lan_administrator.php,v $ | $Source: /cvs_backup/e107_0.8/e107_languages/English/admin/lan_administrator.php,v $
| $Revision: 1.2 $ | $Revision: 1.3 $
| $Date: 2007-12-15 15:06:40 $ | $Date: 2008-06-17 05:39:30 $
| $Author: e107steved $ | $Author: e107coders $
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
*/ */
define("ADMSLAN_0", "New user/admin entry created for"); define("ADMSLAN_0", "New user/admin entry created for");
@ -49,7 +49,7 @@ define("ADMSLAN_41", "Post articles");
define("ADMSLAN_42", "Post reviews"); define("ADMSLAN_42", "Post reviews");
define("ADMSLAN_43", "Post content pages"); define("ADMSLAN_43", "Post content pages");
define("ADMSLAN_44", "Post downloads"); define("ADMSLAN_44", "Post downloads");
define("ADMSLAN_45", "Post polls"); define("ADMSLAN_45", "Schedule Tasks");
define("ADMSLAN_46", "Welcome message"); define("ADMSLAN_46", "Welcome message");
define("ADMSLAN_47", "Moderate submitted news"); define("ADMSLAN_47", "Moderate submitted news");

View File

@ -0,0 +1,50 @@
<?php
/*
+ ----------------------------------------------------------------------------+
| e107 website system - Language File.
|
| $Source: /cvs_backup/e107_0.8/e107_languages/English/admin/lan_cron.php,v $
| $Revision: 1.1 $
| $Date: 2008-06-17 05:39:30 $
| $Author: e107coders $
+----------------------------------------------------------------------------+
*/
if (!defined("PAGE_NAME")) { define("PAGE_NAME", "Schedule Tasks"); }
define("LAN_CRON_1", "Name");
define("LAN_CRON_2", "Description");
define("LAN_CRON_3", "Minute(s)");
define("LAN_CRON_4", "Hour(s)");
define("LAN_CRON_5", "Day(s)");
define("LAN_CRON_6", "Month(s)");
define("LAN_CRON_7", "Weekday(s)");
define("LAN_CRON_8", "Active");
define("LAN_CRON_9", "Description");
define("LAN_CRON_10", "Description");
define("LAN_CRON_11", "Every Minute");
define("LAN_CRON_12", "Every Other Minute");
define("LAN_CRON_13", "Every 5 Minutes");
define("LAN_CRON_14", "Every 10 minutes");
define("LAN_CRON_15", "Every 30 minutes");
define("LAN_CRON_16", "Every Hour");
define("LAN_CRON_17", "Every Other Hour");
define("LAN_CRON_18", "Every 3 Hours");
define("LAN_CRON_19", "Every 6 Hours");
define("LAN_CRON_20", "Every Day");
define("LAN_CRON_21", "Every Month");
define("LAN_CRON_22", "Every Week Day");
define("LAN_SUN", "Sunday");
define("LAN_MON", "Monday");
define("LAN_TUE","Tuesday");
define("LAN_WED","Wednesday");
define("LAN_THU","Thursday");
define("LAN_FRI","Friday");
define("LAN_SAT","Saturday");
?>

View File

@ -0,0 +1,37 @@
<?php
if (!defined('e107_INIT')) { exit; }
// -------- e_cron setup -----------------------------------------------------
$cron['name'] = "Update Records";
$cron['function'] = "gsitemap_myfunction";
$cron['description'] = "Dummy example.";
$cron2['name'] = "Test Email";
$cron2['function'] = "gsitemap_myfunction2";
$cron2['description'] = "Sends a test email to ".$pref['siteadminemail'];
$eplug_cron[] = $cron;
$eplug_cron[] = $cron2;
// ------------------------- Functions -----------------------------------------
function gsitemap_myfunction() // include plugin-folder in the function name.
{
// Whatever code you wish.
}
function gsitemap_myfunction2()
{
require_once(e_HANDLER."mail.php");
$message = "Your Cron Job worked correctly. Sent at ".date("r").".";
sendemail($pref['siteadminemail'], "e107 - TEST Email Sent by cron.", $message, $pref['siteadmin'],$pref['siteadminemail'], $pref['siteadmin']);
}
?>