Commit 5d9a8e34 authored by Dries's avatar Dries

- Made the cloud module a lot more configurable: both the update interval
  and the number of bytes required for an update, can be changed now.
parent 9e4e2dd5
......@@ -18,12 +18,7 @@ function cloud_help($type = "administrator") {
}
function cloud_cron() {
if (time() % 25 == 0) {
$result = db_query("SELECT * FROM site");
}
else {
$result = db_query("SELECT * FROM site WHERE timestamp > ". (time() - 604800));
}
$result = db_query("SELECT * FROM site WHERE timestamp = 0 OR timestamp + refresh < ". time());
while ($site = db_fetch_array($result)) {
cloud_update($site);
......@@ -69,7 +64,7 @@ function cloud_update($site) {
$data .= fgets($fp, 128);
}
if (abs($site["size"] - strlen($data)) > 50) {
if (abs($site["size"] - strlen($data)) > $site["threshold"]) {
db_query("UPDATE site SET size = '". strlen($data) ."', timestamp = '". time() ."' WHERE link = '". check_input($site["link"]) ."'");
}
......@@ -82,10 +77,14 @@ function cloud_update($site) {
function cloud_form($edit = array()) {
$period = array(900 => format_interval(900), 1800 => format_interval(1800), 3600 => format_interval(3600), 7200 => format_interval(7200), 10800 => format_interval(10800), 21600 => format_interval(21600), 32400 => format_interval(32400), 43200 => format_interval(43200), 64800 => format_interval(64800), 86400 => format_interval(86400), 172800 => format_interval(172800), 259200 => format_interval(259200), 604800 => format_interval(604800), 1209600 => format_interval(1209600), 2419200 => format_interval(2419200));
$threshold = array (0 => "0 bytes", 10 => "10 bytes", 20 => "20 bytes", 40 => "40 bytes", 60 => "60 bytes", 80 => "80 bytes", 160 => "160 bytes", 320 => "320 bytes", 640 => "640 bytes");
$form .= form_textfield("Site name", "name", $edit["name"], 50, 128, "The name of the website you want to monitor for updates.");
$form .= form_textfield("Site URL", "link", $edit["link"], 50, 255, "The URL of the website you want to monitor for updates.");
$form .= form_textfield("URL to monitor", "feed", $edit["feed"], 50, 255, "The URL of the page you want to monitor for updates. Likely to be same as the site's URL but useful to monitor framed pages and more accurate when pointed to a XML/RSS/RDF feed.");
$form .= form_select("Update interval", "refresh", ($edit["refresh"] ? $edit["refresh"] : 3600), $period, "The refresh interval indicating how often you want to check this site for updates. Requires crontab.");
$form .= form_select("Change threshold", "threshold", ($edit["threshold"] ? $edit["threshold"] : 40), $threshold, "The number of bytes the site must have been modified before concidered changed.");
$form .= form_submit("Submit");
......@@ -103,13 +102,13 @@ function cloud_get_site($sid) {
function cloud_save($edit) {
if ($edit["sid"] && $edit["name"]) {
db_query("UPDATE site SET name = '". check_input($edit["name"]) ."', link = '". check_input($edit["link"]) ."', feed = '". check_input($edit["feed"]) ."' WHERE sid = '". check_input($edit["sid"]) ."'");
db_query("UPDATE site SET name = '". check_input($edit["name"]) ."', link = '". check_input($edit["link"]) ."', feed = '". check_input($edit["feed"]) ."', refresh = '". check_input($edit["refresh"]) ."', threshold = '". check_input($edit["threshold"]) ."' WHERE sid = '". check_input($edit["sid"]) ."'");
}
else if ($edit["sid"]) {
db_query("DELETE FROM site WHERE sid = '". check_input($edit["sid"]) ."'");
}
else {
db_query("INSERT INTO site (name, link, feed) VALUES ('". check_input($edit["name"]) ."', '". check_input($edit["link"]) ."', '". check_input($edit["feed"]) ."')");
db_query("INSERT INTO site (name, link, feed, refresh, threshold) VALUES ('". check_input($edit["name"]) ."', '". check_input($edit["link"]) ."', '". check_input($edit["feed"]) ."', '". check_input($edit["refresh"]) ."', '". check_input($edit["threshold"]) ."')");
}
}
......
......@@ -47,7 +47,8 @@
"2002-01-27" => "update_20",
"2002-01-30" => "update_21",
"2002-02-19" => "update_22",
"2002-03-05" => "update_23"
"2002-03-05" => "update_23",
"2002-04-08" => "update_24"
);
// Update functions
......@@ -337,6 +338,13 @@ function update_23() {
update_sql("CREATE TABLE search_index (word varchar(50) default NULL, lno int(10) unsigned default NULL, type varchar(16) default NULL, count int(10) unsigned default NULL, KEY lno (lno), KEY word (word));");
}
function update_24() {
update_sql("ALTER TABLE site ADD refresh int(11) NOT NULL;");
update_sql("ALTER TABLE site ADD threshold int(11) NOT NULL;");
update_sql("UPDATE site SET refresh = '7200';");
update_sql("UPDATE site SET threshold = '50';");
}
/*
** System functions
*/
......
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