cronAction = e_QUERY;
// The 'available' flag only gives the option to configure the cron if the underlying feature is enabled
$this->coreCrons['_system'] = array(
0 => array('name' => 'Test Email', 'function' => 'sendEmail', 'description' => 'Send a test email to '.$pref['siteadminemail'].'
Recommended to test the scheduling system.'),
1 => array('name' => 'Mail Queue', 'function' => 'procEmailQueue', 'description' => 'Process mail queue'),
2 => array('name' => 'Mail Bounce Check', 'function' => 'procEmailBounce', 'description' => 'Check for bounced emails', 'available' => vartrue($pref['mail_bounce_auto'])),
// 1 => array('name'=>'User Purge', 'function' => 'userPurge', 'description'=>'Purge Unactivated Users'),
// 2 => array('name'=>'User UnActivated', 'function' => 'userUnactivated', 'description'=>'Resend activation email to unactivated users.'),
// 3 => array('name'=>'News Sticky', 'function' => 'newsPurge', 'description'=>'Remove Sticky News Items')
);
if (!vartrue($pref['e_cron_pwd']))
{
$pwd = $this->setCronPwd();
}
if (isset($_POST['submit']))
{
$this->cronSave();
}
$this->lastRefresh();
$this->cronLoad();
if (isset($_POST['save_prefs']))
{
$this->cronSavePrefs();
}
if (isset($_POST['execute']))
{
$class_func = key($_POST['execute']);
$this->cronExecute($class_func);
}
// Set Core Cron Options.
// These core functions need to be put into e_BASE/cron.php ie. news_purge()
if ($this->cronAction == "" || $this->cronAction == "main")
{
$this->cronRenderPage();
}
if ($this->cronAction == "pref")
{
$this->cronRenderPrefs();
}
}
function lastRefresh()
{
$pref = e107::getPref();
e107::getCache()->CachePageMD5 = '_';
$lastload = e107::getCache()->retrieve('cronLastLoad', FALSE, TRUE, TRUE);
$mes = e107::getMessage();
$ago = (time() - $lastload);
$active = ($ago < 901) ? TRUE : FALSE;
$status = ($active) ? LAN_ENABLED : LAN_DISABLED; // "Enabled" : "Offline";
$mins = floor($ago / 60);
$secs = $ago % 60;
$lastRun = ($mins) ? $mins." minutes and ".$secs." seconds ago." : $secs." seconds ago.";
$lastRefresh = ($ago < 10000) ? $lastRun : 'Never';
$mes->add("Status: ".$status."", E_MESSAGE_INFO);
// print_a($pref['e_cron_pref']);
if ($pref['e_cron_pref']) // grab cron
{
foreach ($pref['e_cron_pref'] as $func => $cron)
{
if ($cron['active'] == 1)
{
$list[$func] = $cron;
}
}
}
$mes->add("Active Crons: ".count($list)."", E_MESSAGE_INFO);
$mes->add("Last cron refresh: ".$lastRefresh, E_MESSAGE_INFO);
//FIXME: for Windows, the is_executable() function only checks the file
// extensions of exe, com, bat and cmd.
if (!is_executable(e_BASE."cron.php"))
{
$mes->add("Please CHMOD /cron.php to 755", E_MESSAGE_WARNING);
}
elseif (!$active)
{
$setpwd_message = "Use the following Cron Command: ".$_SERVER['DOCUMENT_ROOT'].e_HTTP."cron.php ".$pref['e_cron_pwd']."
Using your server control panel (eg. cPanel,Plesk etc.) please create a crontab to run this command on your server every minute.";
$mes->add($setpwd_message, E_MESSAGE_INFO);
}
}
function cronName($classname, $method)
{
$tp = e107::getParser();
foreach ($this->e_cron as $class => $val)
{
if ($class == $classname)
{
foreach ($val as $func)
{
if ($func['function'] == $method)
{
return $tp->toHtml($func['name']);
}
}
}
}
}
function cronExecute($class_func)
{
//TODO LANs
list($class_name, $method_name) = explode("__", $class_func);
$mes = e107::getMessage();
$taskName = $class_name;
if ($class_name == '_system')
{
require_once(e_HANDLER.'cron_class.php');
}
else
{
require_once(e_PLUGIN.$class_name.'/e_cron.php');
}
$class_name .= '_cron';
$status = $this->cronExecuteMethod($class_name, $method_name) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
$mes->add("Running ".$this->cronName($taskName, $method_name)."", $status);
}
function cronSavePref()
{
// Store the USERID with the password.
// This way only the one password is needed, and the user login can be looked up in e_base/cron.php
}
function cronSave()
{
global $pref;
$mes = e107::getMessage();
$activeCount = 0;
foreach ($_POST['cron'] as $key => $val)
{
if (!$val['active'])
{
$val['active'] = 0;
}
else
{
$activeCount++;
}
$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']."
";
list($class, $func) = explode("__", $key);
$val['function'] = $func;
$val['class'] = $class;
$val['path'] = $class;
$cron[$key] = $val;
}
$pref['e_cron_pref'] = $cron;
if (!vartrue($pref['e_cron_pwd']) || varset($_POST['generate_pwd']))
{
$pwd = $this->setCronPwd();
$setpwd_message = "Use the following Cron Command:
".$_SERVER['DOCUMENT_ROOT'].e_HTTP."cron.php ".$pwd."
This cron command is unique and will not be displayed again. Please copy and paste it into your webserver cron area to be run every minute (or 15 minutes) of every day.";
$mes->add($setpwd_message, E_MESSAGE_WARNING);
}
// print_a($pref['e_cron_pref']);
if (save_prefs())
{
$mes->add(LAN_SETSAVED, E_MESSAGE_SUCCESS);
$mes->add($activeCount." Cron(s) Active", E_MESSAGE_SUCCESS);
}
else
{
$mes->add("There was a problem saving your settings.", E_MESSAGE_ERROR);
}
}
function setCronPwd()
{
//global $pref;
$userMethods = e107::getUserSession();
$newpwd = $userMethods->generateRandomString('*^*#.**^*');
$newpwd = sha1($newpwd.time());
//$pref['e_cron_pwd'] = $newpwd;
e107::getConfig()->set('e_cron_pwd', $newpwd)->save(false);
return true;
}
// --------------------------------------------------------------------------
function cronRenderPrefs()
{
//global $frm,$ns;
$frm = e107::getForm();
$text = "