From 038b9cc19b1d4198a2f0408e2f5077b8f490bae3 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Fri, 13 Jul 2001 19:51:42 +0000 Subject: - cloud.module: + Fixed "rotten date" (as remco like to calls it). + Added "URL to monitor" field. + Added some error checking. + Apply the updates in 2.00-to-x.xx.sql. --- modules/cloud.module | 49 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) (limited to 'modules') diff --git a/modules/cloud.module b/modules/cloud.module index 56971f20a..32378e18e 100644 --- a/modules/cloud.module +++ b/modules/cloud.module @@ -33,23 +33,39 @@ function cloud_link($type) { } function cloud_update($site) { - // open socket: - $url = parse_url($site[url]); - $fp = fsockopen($url[host], ($url[port] ? $url[port] : 80), $errno, $errstr, 15); + + /* + ** Check whether the site is properly configured: + */ + + if (!ereg("^http://|ftp://", $site[link])) { + watchdog("warning", "cloud: invalid or missing URL for '$site[name]'"); + } + + if (!ereg("^http://|ftp://", $site[feed])) { + watchdog("warning", "cloud: invalid or missing URL to monitor for '$site[name]'"); + } + + /* + ** Grab the page and update the database if required: + */ + + $link = parse_url($site[feed]); + $fp = fsockopen($link[host], ($link[port] ? $link[port] : 80), &$errno, &$errstr, 15); if ($fp) { // fetch data: - fputs($fp, "GET $url[path]?$url[query] HTTP/1.0\nUser-Agent: ". variable_get(site_name, "drupal") ."\nHost: $url[host]\nAccept: */*\n\n"); + fputs($fp, "GET $link[path]?$link[query] HTTP/1.0\nUser-Agent: ". variable_get(site_name, "drupal") ."\nHost: $link[host]\nAccept: */*\n\n"); while(!feof($fp)) $data .= fgets($fp, 128); if (strstr($data, "200 OK")) { if (abs($site[size] - strlen($data)) > 50) { - db_query("UPDATE site SET size = '". strlen($data) ."', timestamp = '". time() ."' WHERE url = '". check_input($site[url]) ."'"); + db_query("UPDATE site SET size = '". strlen($data) ."', timestamp = '". time() ."' WHERE link = '". check_input($site[link]) ."'"); } } } else { - watchdog("error", "cloud: failed to syndicate from '$site[title]'"); + watchdog("warning", "cloud: failed to syndicate from '$site[name]'". ($errstr ? ": $errstr" : "")); } } @@ -57,8 +73,9 @@ function cloud_update($site) { function cloud_form($edit = array()) { global $REQUEST_URI; - $form .= form_textfield("Title", "title", $edit["title"], 50, 64); - $form .= form_textfield("URL", "url", $edit["url"], 50, 64); + $form .= form_textfield("Site name", "name", $edit["name"], 50, 64, "The name of the website you want to monitor for updates."); + $form .= form_textfield("Site URL", "link", $edit["link"], 50, 64, "The URL of the website you want to monitor for updates."); + $form .= form_textfield("URL to monitor", "feed", $edit["feed"], 50, 64, "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_submit("Submit"); @@ -75,24 +92,24 @@ function cloud_get_site($sid) { } function cloud_save($edit) { - if ($edit["sid"] && $edit["title"]) { - db_query("UPDATE site SET title = '". check_input($edit["title"]) ."', url = '". check_input($edit["url"]) ."' WHERE sid = '". check_input($edit["sid"]) ."'"); + 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"]) ."'"); } else if ($edit["sid"]) { db_query("DELETE FROM site WHERE sid = '". check_input($edit["sid"]) ."'"); } else { - db_query("INSERT INTO site (title, url) VALUES ('". check_input($edit["title"]) ."', '". check_input($edit["url"]) ."')"); + db_query("INSERT INTO site (name, link, feed) VALUES ('". check_input($edit["name"]) ."', '". check_input($edit["link"]) ."', '". check_input($edit["feed"]) ."')"); } } function cloud_display() { - $result = db_query("SELECT * FROM site ORDER BY title"); + $result = db_query("SELECT * FROM site ORDER BY name"); $output .= "\n"; $output .= " \n"; while ($site = db_fetch_object($result)) { - $output .= " \n"; + $output .= " \n"; } $output .= "
sitelast updateoperations
url) ."\">". check_output($site->title) ."". ($site->timestamp ? format_interval(time() - $site->timestamp) ." ago" : "never") ."sid\">edit sitesid\">update site
link) ."\">". check_output($site->name) ."". ($site->timestamp ? format_interval(time() - $site->timestamp) ." ago" : "never") ."sid\">edit sitesid\">update site
\n"; @@ -100,7 +117,7 @@ function cloud_display() { } function cloud_list($limit = 10) { - $result = db_query("SELECT * FROM site ORDER BY timestamp DESC LIMIT $limit"); + $result = db_query("SELECT * FROM site WHERE timestamp > ". (time() - 604800) ." ORDER BY timestamp DESC LIMIT $limit"); $hour = -1; while ($site = db_fetch_object($result)) { @@ -108,7 +125,7 @@ function cloud_list($limit = 10) { $hour = floor((time() - $site->timestamp) / 3600); $output .= "

Updated ". format_plural($hour, "hour", "hours") ." ago:"; } - $output .= "
  ". format_url($site->url, $site->title); + $output .= "
  ". format_url($site->link, $site->name); } return $output; } @@ -151,7 +168,7 @@ function cloud_admin() { cloud_help(); break; case "Delete": - $edit[title] = 0; + $edit[name] = 0; // fall through: case "Submit": print status(cloud_save($edit)); -- cgit v1.2.3