221 lines
9.0 KiB
Plaintext
221 lines
9.0 KiB
Plaintext
<?php
|
|
// $Id$
|
|
|
|
function cloud_help($type = "administrator") {
|
|
if ($type == "user") {
|
|
$output .= "<p>". t("The cloud monitor tracks or crawls other interesting websites and displays their latest modification dates. It acts as a link watcher such that you can keep an eye on the other sites in our cloud.") ."</p>";
|
|
}
|
|
else {
|
|
$output .= "The cloud monitor tracks or crawls other interesting websites and displays their last modification dates. Visitors to the host site learn about relevant sites and can easily see if there is new content. Here is how it works:";
|
|
$output .= "<ul>";
|
|
$output .= " <li>The site administrator enters names and URLs of the relevant pages on the cloud monitor administration page.</li>";
|
|
$output .= " <li>Drupal's cron function, triggers the cloud module to check all the registered websites for recent changes or updates. (A page is updated when there is a 50-character difference since the last time it checked.)</li>";
|
|
$output .= " <li>The module exports both a page and a block that display the registered sites ordered by their last modification date.</li>";
|
|
$output .= "</ul>";
|
|
}
|
|
|
|
return $output;
|
|
}
|
|
|
|
function cloud_system($field){
|
|
$system["description"] = t("Tracks other sites and displays last date changed.");
|
|
return $system[$field];
|
|
}
|
|
|
|
function cloud_cron() {
|
|
$result = db_query("SELECT * FROM site WHERE timestamp = 0 OR timestamp + refresh < ". time());
|
|
|
|
while ($site = db_fetch_array($result)) {
|
|
cloud_update($site);
|
|
}
|
|
}
|
|
|
|
function cloud_perm() {
|
|
return array("access site cloud", "administer site cloud");
|
|
}
|
|
|
|
function cloud_link($type) {
|
|
if ($type == "page" && user_access("access site cloud")) {
|
|
$links[] = lm(t("site cloud"), array("mod" => "cloud"), "", array("title" => t("Monitor other sites in the cloud.")));
|
|
}
|
|
|
|
if ($type == "admin" && user_access("administer site cloud")) {
|
|
$cloud = "The cloud monitor tracks or crawls other interesting websites and displays their last modification dates. Visitors to the host site learn about relevant sites and can easily see if there is new content.";
|
|
|
|
menu_add("blogrolling", "admin.php?mod=cloud", "Maintain the sites in your blogroll.", $cloud, NULL, 3);
|
|
menu_add("add new site", "admin.php?mod=cloud&op=add", "Add a new sites to your blogroll.", NULL, "blogrolling", 3);
|
|
menu_add("help", "admin.php?mod=cloud&op=help", "More information about the site cloud.", NULL, "blogrolling", 9);
|
|
}
|
|
|
|
return $links ? $links : array();
|
|
}
|
|
|
|
function cloud_update($site) {
|
|
|
|
/*
|
|
** Check whether the site is properly configured:
|
|
*/
|
|
|
|
if (!ereg("^http://|https://|ftp://", $site["link"])) {
|
|
watchdog("warning", "cloud: invalid or missing URL for '". $site["name"] ."'");
|
|
}
|
|
|
|
if (!ereg("^http://|https://|ftp://", $site["feed"])) {
|
|
watchdog("warning", "cloud: invalid or missing URL to monitor for '". $site["name"] ."'");
|
|
}
|
|
|
|
/*
|
|
** Grab the page and update the database if required:
|
|
*/
|
|
|
|
if ($fp = @fopen($site["feed"], "r")) {
|
|
while (!feof($fp)) {
|
|
$data .= fgets($fp, 128);
|
|
}
|
|
|
|
if (abs($site["size"] - strlen($data)) >= $site["threshold"]) {
|
|
db_query("UPDATE site SET size = '". strlen($data) ."', timestamp = '". time() ."' WHERE link = '%s'", $site["link"]);
|
|
}
|
|
|
|
fclose($fp);
|
|
}
|
|
else {
|
|
watchdog("warning", "cloud: failed to syndicate from '". $site["name"] ."'". ($errstr ? ": $errstr" : ""));
|
|
}
|
|
}
|
|
|
|
|
|
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(1 => "1 byte", 10 => "10 bytes", 20 => "20 bytes", 40 => "40 bytes", 60 => "60 bytes", 80 => "80 bytes", 100 => "100 bytes", 120 => "120 bytes", 140 => "140 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 considered changed.");
|
|
|
|
$form .= form_submit("Submit");
|
|
|
|
if ($edit["sid"]) {
|
|
$form .= form_submit("Delete");
|
|
$form .= form_hidden("sid", $edit["sid"]);
|
|
}
|
|
|
|
return form($form);
|
|
}
|
|
|
|
function cloud_get_site($sid) {
|
|
return db_fetch_array(db_query("SELECT * FROM site WHERE sid = '%s'", $sid));
|
|
}
|
|
|
|
function cloud_save($edit) {
|
|
if ($edit["sid"] && $edit["name"]) {
|
|
db_query("UPDATE site SET name = '%s', link = '%s', feed = '%s', refresh = '%s', threshold = '%s' WHERE sid = '%s'", $edit["name"], $edit["link"], $edit["feed"], $edit["refresh"], $edit["threshold"], $edit["sid"]);
|
|
}
|
|
else if ($edit["sid"]) {
|
|
db_query("DELETE FROM site WHERE sid = '%s'", $edit["sid"]);
|
|
}
|
|
else {
|
|
db_query("INSERT INTO site (name, link, feed, refresh, threshold) VALUES ('%s', '%s', '%s', '%s', '%s')", $edit["name"], $edit["link"], $edit["feed"], $edit["refresh"], $edit["threshold"]);
|
|
}
|
|
}
|
|
|
|
function cloud_display() {
|
|
$result = db_query("SELECT * FROM site ORDER BY name");
|
|
|
|
$output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">\n";
|
|
$output .= " <tr><th>site</th><th>last update</th><th colspan=\"2\">operations</th></tr>\n";
|
|
while ($site = db_fetch_object($result)) {
|
|
$output .= " <tr><td><a href=\"". check_output($site->link) ."\">". check_output($site->name) ."</a></td><td>". ($site->timestamp ? format_interval(time() - $site->timestamp) ." ago" : "never") ."</td><td>". la(t("edit site"), array("mod" => "cloud", "op" => "edit", "id" => $site->sid)) ."</td><td>". la(t("update site"), array("mod" => "cloud", "op" => "update", "id" => $site->sid)) ."</td></tr>\n";
|
|
}
|
|
$output .= "</table>\n";
|
|
|
|
return $output;
|
|
}
|
|
|
|
function cloud_list($limit = 10) {
|
|
$result = db_query("SELECT * FROM site WHERE timestamp > ". (time() - 604800) ." ORDER BY timestamp DESC LIMIT $limit");
|
|
|
|
$hour = -1;
|
|
$list = -1;
|
|
|
|
while ($site = db_fetch_object($result)) {
|
|
if ($hour != floor((time() - $site->timestamp) / 3600)) {
|
|
$hour = floor((time() - $site->timestamp) / 3600);
|
|
if ($hour < 12) {
|
|
if ($hour == 0) {
|
|
$output .= "<br />". t("Updated < 1 hours ago:");
|
|
}
|
|
else {
|
|
$output .= "<br />". t("Updated %a ago:", array("%a" => format_plural($hour, "hour", "hours")));
|
|
}
|
|
}
|
|
else if ($list) {
|
|
$output .= "<br />". t("Updated more than %a ago:", array("%a" => format_plural($hour, "hour", "hours")));
|
|
$list = 0;
|
|
}
|
|
}
|
|
$output .= "<div style=\"padding-left: 10px;\"><a href=\"$site->link\">$site->name</a></div>";
|
|
}
|
|
return $output;
|
|
}
|
|
|
|
function cloud_page() {
|
|
global $theme;
|
|
|
|
if (user_access("access site cloud")) {
|
|
$theme->header();
|
|
$theme->box(t("Site cloud"), cloud_help("user") . cloud_list(100));
|
|
$theme->footer();
|
|
}
|
|
}
|
|
|
|
function cloud_block($op = "list", $delta = 0) {
|
|
if ($op == "list") {
|
|
$blocks[0]["info"] = t("Site cloud");
|
|
return $blocks;
|
|
}
|
|
else {
|
|
$block["subject"] = t("Site cloud");
|
|
$block["content"] = cloud_list(20) ."<br /><div align=\"right\">". lm(t("more"), array("mod" => "cloud"), "", array("title" => t("Monitor other sites in the cloud."))) ."</div>";
|
|
return $block;
|
|
}
|
|
}
|
|
|
|
function cloud_admin() {
|
|
global $op, $id, $edit;
|
|
|
|
if (user_access("administer site cloud")) {
|
|
print "<small>". la(t("add new site"), array("mod" => "cloud", "op" => "add")) ." | ". la(t("overview"), array("mod" => "cloud")) ." | ". la(t("help"), array("mod" => "cloud", "op" => "help")) ."</small><hr />\n";
|
|
|
|
switch ($op) {
|
|
case "add":
|
|
print cloud_form();
|
|
break;
|
|
case "edit":
|
|
print cloud_form(cloud_get_site($id));
|
|
break;
|
|
case "update":
|
|
print status(cloud_update(cloud_get_site($id)));
|
|
print cloud_display();
|
|
break;
|
|
case "help":
|
|
print cloud_help();
|
|
break;
|
|
case "Delete":
|
|
$edit["name"] = 0;
|
|
// fall through:
|
|
case "Submit":
|
|
print status(cloud_save($edit));
|
|
// fall through:
|
|
default:
|
|
print cloud_display();
|
|
}
|
|
}
|
|
else {
|
|
print message_access();
|
|
}
|
|
}
|
|
|
|
?> |