Commit 8d5b4e7b authored by Dries's avatar Dries
Browse files

- intermediate commit: see previous commit
parent 60e1a60d
<?
include "includes/theme.inc";
function cron_set($module, $scheduled, $message = "") {
if (empty($module) || empty($scheduled)) {
$message = "failed: information missing";
}
else if (db_fetch_object(db_query("SELECT * FROM cron WHERE module = '$module'"))) {
db_query("UPDATE cron SET scheduled = $scheduled WHERE module = '$module'");
}
else {
db_query("INSERT INTO cron (module, scheduled, timestamp) VALUES ('". check_input($module) ."', '". check_input($scheduled) ."', '42')");
}
}
function cron_get($module) {
return db_fetch_object(db_query("SELECT * FROM cron WHERE module = '$module'"), 0);
}
function cron_delete($module) {
$result = db_query("DELETE FROM cron WHERE module = '$module'");
}
function cron_run($cron) {
$time = time();
$result = db_query("SELECT * FROM cron WHERE $time - timestamp > scheduled");
while ($task = db_fetch_object($result)) {
include "modules/". $task->module .".module";
if ($function = $module["cron"]) {
watchdog("message", "cron: executed '". $task->module ."_cron()'");
$function();
}
}
db_query("UPDATE cron SET timestamp = $time WHERE $time - timestamp > scheduled");
}
?>
<?
function module_iterate($function) {
global $repository;
foreach ($repository as $name=>$module) {
$function($name, $module);
}
}
function module_execute($module, $hook, $argument = "") {
global $repository;
return ($repository[$module][$hook]) ? $repository[$module][$hook]($argument) : "";
}
function module_rehash_crons($name, $module) {
if ($module["cron"]) {
if (!db_fetch_object(db_query("SELECT * FROM crons WHERE module = '$name'"))) {
db_query("INSERT INTO crons (module, scheduled, timestamp) VALUES ('". check_input($name) ."', '172800', '0')");
}
}
else {
db_query("DELETE FROM crons WHERE module = '$name'");
}
}
function module_rehash_blocks($name, $module) {
db_query("DELETE FROM blocks WHERE module = '$name'");
if ($module["block"]) {
foreach ($blocks = $module["block"]() as $offset=>$block) {
db_query("INSERT INTO blocks (name, module, offset) VALUES ('". check_input($block["info"]) ."', '". check_input($name) ."', '". check_input($offset) ."')");
}
}
}
function module_rehash($name) {
global $repository;
if ($module = $repository[$name]) {
$result = db_query("SELECT * FROM modules WHERE name = '$name'");
if (!$object = db_fetch_object($result)) {
db_query("INSERT INTO modules (name) VALUES ('". check_input($name) ."')");
}
// rehash crons (if necessary):
module_rehash_crons($name, $module);
// rehash blocks (if necessary):
module_rehash_blocks($name, $module);
}
else {
// remove all reference to module:
db_query("DELETE FROM modules WHERE name = '$name'");
db_query("DELETE FROM blocks WHERE module = '$name'");
db_query("DELETE FROM crons WHERE module = '$name'");
}
}
// load modules into repository:
$handle = opendir("modules");
while ($file = readdir($handle)) {
if ($filename = substr($file, 0, strpos($file, ".module"))) {
include "modules/$filename.module";
$repository[$filename] = $module;
}
}
closedir($handle);
?>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment