diff --git a/modules/aggregator.module b/modules/aggregator.module index 30f350300cf..c8afe7c5abb 100644 --- a/modules/aggregator.module +++ b/modules/aggregator.module @@ -107,7 +107,7 @@ function import_update($feed) { db_query("UPDATE feed SET timestamp = '". time() ."' WHERE fid = '". $feed[fid] ."'"); } else { - watchdog("error", "failed to syndicate from '$feed[title]'"); + watchdog("error", "import: failed to syndicate from '$feed[title]'"); } } @@ -213,7 +213,7 @@ function import_view_feed() { $output .= "

Feed overview

"; $output .= "\n"; - $output .= " \n"; + $output .= " \n"; while ($feed = db_fetch_object($result)) { $output .= " \n"; } diff --git a/modules/aggregator/aggregator.module b/modules/aggregator/aggregator.module index 30f350300cf..c8afe7c5abb 100644 --- a/modules/aggregator/aggregator.module +++ b/modules/aggregator/aggregator.module @@ -107,7 +107,7 @@ function import_update($feed) { db_query("UPDATE feed SET timestamp = '". time() ."' WHERE fid = '". $feed[fid] ."'"); } else { - watchdog("error", "failed to syndicate from '$feed[title]'"); + watchdog("error", "import: failed to syndicate from '$feed[title]'"); } } @@ -213,7 +213,7 @@ function import_view_feed() { $output .= "

Feed overview

"; $output .= "
titleattributesitemslast updatenext updateoperations
siteattributesitemslast updatenext updateoperations
". check_output($feed->title) ."". check_output($feed->attributes) ."". format_plural($feed->items, "item", "items") ."". ($feed->timestamp ? format_interval(time() - $feed->timestamp) ." ago" : "never") ."". ($feed->timestamp ? format_interval($feed->timestamp + $feed->refresh - time()) ." left" : "never") ."fid\">edit feedfid\">remove itemsfid\">update items
\n"; - $output .= " \n"; + $output .= " \n"; while ($feed = db_fetch_object($result)) { $output .= " \n"; } diff --git a/modules/cloud.module b/modules/cloud.module new file mode 100644 index 00000000000..a384f0fde82 --- /dev/null +++ b/modules/cloud.module @@ -0,0 +1,163 @@ + ". (time() - 604800)); + } + + 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[] = "". t("site cloud") .""; + } + + if ($type == "admin" && user_access("administer site cloud")) { + $links[] = "". t("site cloud") .""; + } + + return $links ? $links : array(); +} + +function cloud_update($site) { + // open socket: + $url = parse_url($site[url]); + $fp = fsockopen($url[host], ($url[port] ? $url[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"); + 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]) ."'"); + } + } + } + else { + watchdog("error", "cloud: failed to syndicate from '$site[title]'"); + } +} + + +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_submit("Submit"); + + if ($edit["sid"]) { + $form .= form_submit("Delete"); + $form .= form_hidden("sid", $edit["sid"]); + } + + return form($REQUEST_URI, $form); +} + +function cloud_get_site($sid) { + return db_fetch_array(db_query("SELECT * FROM site WHERE sid = '". check_input($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"]) ."'"); + } + 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"]) ."')"); + } +} + +function cloud_display() { + $result = db_query("SELECT * FROM site ORDER BY timestamp DESC"); + + $output .= "
titleattributesitemslast updatenext updateoperations
siteattributesitemslast updatenext updateoperations
". check_output($feed->title) ."". check_output($feed->attributes) ."". format_plural($feed->items, "item", "items") ."". ($feed->timestamp ? format_interval(time() - $feed->timestamp) ." ago" : "never") ."". ($feed->timestamp ? format_interval($feed->timestamp + $feed->refresh - time()) ." left" : "never") ."fid\">edit feedfid\">remove itemsfid\">update items
\n"; + $output .= " \n"; + while ($site = db_fetch_object($result)) { + $output .= " \n"; + } + $output .= "
sitelast updateoperations
url) ."\">". check_output($site->title) ."". ($site->timestamp ? format_interval(time() - $site->timestamp) ." ago" : "never") ."sid\">edit site
\n"; + + return $output; +} + +function cloud_list() { + $result = db_query("SELECT * FROM site ORDER BY timestamp DESC LIMIT 100"); + + while ($site = db_fetch_object($result)) { + if ($date != date("g A", $site->timestamp)) { + $date = date("g A", $site->timestamp); + $output .= "

$date:"; + } + $output .= "
". format_url($site->url, $site->title); + } + return $output; +} + +function cloud_page() { + global $theme; + + if (user_access("access site cloud")) { + $theme->header(); + $theme->box(t("Updated sites"), cloud_list()); + $theme->footer(); + } +} + +function cloud_block() { + $block[0]["subject"] = t("Sites"); + $block[0]["content"] = cloud_list(); + $block[0]["info"] = t("Sites"); + return $block; +} + +function cloud_admin() { + global $op, $id, $edit; + + if (user_access("administer site cloud")) { + print "add new site | overview | help


\n"; + + switch ($op) { + case "add": + print cloud_form(); + break; + case "edit": + print cloud_form(cloud_get_site($id)); + break; + case "help": + cloud_help(); + break; + case "Delete": + $edit[title] = 0; + // fall through: + case "Submit": + print status(cloud_save($edit)); + // fall through: + default: + print cloud_display(); + } + } + else { + print message_access(); + } +} + +?> \ No newline at end of file diff --git a/modules/import.module b/modules/import.module index 30f350300cf..c8afe7c5abb 100644 --- a/modules/import.module +++ b/modules/import.module @@ -107,7 +107,7 @@ function import_update($feed) { db_query("UPDATE feed SET timestamp = '". time() ."' WHERE fid = '". $feed[fid] ."'"); } else { - watchdog("error", "failed to syndicate from '$feed[title]'"); + watchdog("error", "import: failed to syndicate from '$feed[title]'"); } } @@ -213,7 +213,7 @@ function import_view_feed() { $output .= "

Feed overview

"; $output .= "\n"; - $output .= " \n"; + $output .= " \n"; while ($feed = db_fetch_object($result)) { $output .= " \n"; } diff --git a/updates/2.00-to-x.xx.sql b/updates/2.00-to-x.xx.sql index 346ad8d0530..05aca61f5bf 100644 --- a/updates/2.00-to-x.xx.sql +++ b/updates/2.00-to-x.xx.sql @@ -299,3 +299,15 @@ CREATE TABLE cache ( timestamp int(11) NOT NULL, PRIMARY KEY (url) ); + +# 08/06/01 +CREATE TABLE site ( + sid int(10) unsigned DEFAULT '0' NOT NULL auto_increment, + title varchar(128) DEFAULT '' NOT NULL, + url varchar(255) DEFAULT '' NOT NULL, + size text NOT NULL, + timestamp int(11) NOT NULL, + UNIQUE (title), + UNIQUE (url), + PRIMARY KEY (sid) +);
titleattributesitemslast updatenext updateoperations
siteattributesitemslast updatenext updateoperations
". check_output($feed->title) ."". check_output($feed->attributes) ."". format_plural($feed->items, "item", "items") ."". ($feed->timestamp ? format_interval(time() - $feed->timestamp) ." ago" : "never") ."". ($feed->timestamp ? format_interval($feed->timestamp + $feed->refresh - time()) ." left" : "never") ."fid\">edit feedfid\">remove itemsfid\">update items