From 8043cb998f3325731bfab8d82251fa49639aec1d Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sat, 20 Apr 2002 11:52:50 +0000 Subject: - Applied Marco's big patch, including contributions from Moshe: + Changed the db_query() API. + Wrapped all links in l(), lm(), la(), ..., drupal_url() functions. + XHTML-ified some HTML. + Wrapped a lot of text in the administrative pages in a t() function. + Replaced all $REQUEST_URI/$PATH_INFOs by request_uri(). + Small bugfixes (eg. bug in book_export_html() and clean-ups (eg. RSS code). + Fixed some bugs in the taxonomy module (eg. tree making bug), added new functionality (eg. new APIs for use by other modules), included Moshe's taxonomy extensions, and some documentation udpates. + ... --- modules/aggregator.module | 102 +++++++++++++++++++++++++--------------------- 1 file changed, 55 insertions(+), 47 deletions(-) (limited to 'modules/aggregator.module') diff --git a/modules/aggregator.module b/modules/aggregator.module index 013cd7100..d3b79bf7c 100644 --- a/modules/aggregator.module +++ b/modules/aggregator.module @@ -25,11 +25,11 @@ function import_perm() { function import_link($type) { if ($type == "admin" && user_access("administer news feeds")) { - $links[] = "news feeds"; + $links[] = la(t("news feeds"), array("mod" => "import")); } if ($type == "page" && user_access("access news feeds")) { - $links[] = "". t("news feeds") .""; + $links[] = lm(t("news feeds"), array("mod" => "import"), t("Read the latest news from syndicated websites.")); } return $links ? $links : array(); @@ -53,9 +53,10 @@ function import_format_item($item, $feed = 0) { global $theme, $user; if ($user->uid && user_access("post blogs")) { - $output .= "iid\" title=\"". t("Comment on this news item in your personal blog.") ."\">image("blog.gif") ."\" border=\"0\" width=\"12\" height=\"16\" alt=\"". t("Blog this item") ."\" /> "; + $output .= lm("image("blog.gif") ."\" border=\"0\" width=\"12\" height=\"16\" alt=\"". t("Blog this item") ."\" />", array("mod" => "node", "op" => "add", "type" => "blog", "iid" => $item->iid), t("Comment on this news item in your personal blog.")); } + // external link $output .= "link) ."\" target=\"new\">". check_output($item->title) .""; return $output ."
"; @@ -78,7 +79,7 @@ function import_bundle_block($attributes) { } function import_feed_block($feed) { - $result = db_query("SELECT * FROM item WHERE fid = '$feed->fid' ORDER BY iid DESC LIMIT ". variable_get("import_block_limit", 15)); + $result = db_query("SELECT * FROM item WHERE fid = '%s' ORDER BY iid DESC LIMIT ". variable_get("import_block_limit", 15), $feed->fid); while ($item = db_fetch_object($result)) { $output .= import_format_item($item); @@ -97,7 +98,7 @@ function import_get_bundles($attributes = 0) { $i = 0; while ($bundle = db_fetch_object($result)) { $block[$i]["subject"] = $bundle->title; - $block[$i]["content"] = import_bundle_block($bundle->attributes) ."

bid\" title=\"". t("View this bundle's recent news.") ."\">". t("more") ."

"; + $block[$i]["content"] = import_bundle_block($bundle->attributes) ."

".lm(t("more"), array("mod" => "import", "op" => "bundle", "id" => $bundle->bid), t("View this bundle's recent news."))."

"; $block[$i]["info"] = "$bundle->title bundle"; $i++; @@ -112,7 +113,7 @@ function import_get_feeds($attributes = 0) { $i = 0; while ($feed = db_fetch_object($result)) { $block[$i]["subject"] = $feed->title; - $block[$i]["content"] = import_feed_block($feed) ."

fid\" title=\"". t("View this feed's recent news.") ."\">". t("more") ."

"; + $block[$i]["content"] = import_feed_block($feed) ."

".lm(t("more"), array("mod" => "import", "op" => "feed", "id" => $feed->fid), t("View this feed's recent news."))."

"; $block[$i]["info"] = "$feed->title feed"; $i++; @@ -122,7 +123,7 @@ function import_get_feeds($attributes = 0) { } function import_remove($feed) { - db_query("DELETE FROM item WHERE fid = '". $feed["fid"] ."'"); + db_query("DELETE FROM item WHERE fid = '%s'", $feed["fid"]); return "feed '". $feed["title"] ."' reset."; } @@ -175,7 +176,7 @@ function import_refresh($feed) { $link = strip_tags($link[1]); $description = filter(strtr($description[1], $tt)); - db_query("UPDATE feed SET timestamp = '". time() ."', link = '". check_input($link) ."', description = '". check_input($description) ."' WHERE fid = '". $feed["fid"] ."'"); + db_query("UPDATE feed SET timestamp = '%s', link = '%s', description = '%s' WHERE fid = '%s'",time(), $link, $description, $feed["fid"]); /* ** Extract and process individual items: @@ -214,10 +215,10 @@ function import_refresh($feed) { */ if ($link && $link != $feed["link"] && $link != $feed["url"]) { - $entry = db_fetch_object(db_query("SELECT iid FROM item WHERE fid = '". check_query($feed["fid"]) ."' AND link = '". check_query($link) ."'")); + $entry = db_fetch_object(db_query("SELECT iid FROM item WHERE fid = '%s' AND link = '%s'", $feed["fid"], $link)); } else { - $entry = db_fetch_object(db_query("SELECT iid FROM item WHERE fid = '". check_query($feed["fid"]) ."' AND title = '". check_query($title) ."'")); + $entry = db_fetch_object(db_query("SELECT iid FROM item WHERE fid = '%s' AND title = '%s'", $feed["fid"], $title)); } import_save_item(array(iid => $entry->iid, fid => $feed["fid"], title => $title, link => $link, author => $author, description => $description, attributes => $feed["attributes"])); @@ -230,7 +231,7 @@ function import_refresh($feed) { unset($items); - $result = db_query("SELECT iid FROM item WHERE fid = '". $feed["fid"] ."' ORDER BY timestamp"); + $result = db_query("SELECT iid FROM item WHERE fid = '%s' ORDER BY timestamp", $feed["fid"]); while ($item = db_fetch_object($result)) { $items[] = "iid = '$item->iid'"; @@ -250,13 +251,13 @@ function import_refresh($feed) { function import_save_item($edit) { if ($edit["iid"] && $edit["title"]) { - db_query("UPDATE item SET title = '". check_input($edit["title"]) ."', link = '". check_input($edit["link"]) ."', author = '". check_input($edit["author"]) ."', description = '". check_input($edit["description"]) ."', attributes = '". check_input($edit["attributes"]) ."' WHERE iid = '". check_input($edit["iid"]) ."'"); + db_query("UPDATE item SET title = '%s', link = '%s', author = '%s', description = '%s', attributes = '%s' WHERE iid = '%s'", $edit["title"], $edit["link"], $edit["author"], $edit["description"], $edit["attributes"], $edit["iid"]); } else if ($edit["iid"]) { - db_query("DELETE FROM item WHERE iid = '". check_input($edit["iid"]) ."'"); + db_query("DELETE FROM item WHERE iid = '%s'", $edit["iid"]); } else if ($edit["title"] && $edit["link"]) { - db_query("INSERT INTO item (fid, title, link, author, description, attributes, timestamp) VALUES ('". check_input($edit["fid"]) ."', '". check_input($edit["title"]) ."', '". check_input($edit["link"]) ."', '". check_input($edit["author"]) ."', '". check_input($edit["description"]) ."', '". check_input($edit["attributes"]) ."', '". time() ."')"); + db_query("INSERT INTO item (fid, title, link, author, description, attributes, timestamp) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s')", $edit["fid"], $edit["title"], $edit["link"], $edit["author"], $edit["description"], $edit["attributes"], time()); } } @@ -277,13 +278,13 @@ function import_form_bundle($edit = array()) { function import_save_bundle($edit) { if ($edit["bid"] && $edit["title"]) { - db_query("UPDATE bundle SET title = '". check_input($edit["title"]) ."', attributes = '". check_input($edit["attributes"]) ."' WHERE bid = '". check_input($edit["bid"]) ."'"); + db_query("UPDATE bundle SET title = '%s', attributes = '%s' WHERE bid = '%s'", $edit["title"], $edit["attributes"], $edit["bid"]); } else if ($edit["bid"]) { - db_query("DELETE FROM bundle WHERE bid = '". check_input($edit["bid"]) ."'"); + db_query("DELETE FROM bundle WHERE bid = '%s'", $edit["bid"]); } else if ($edit["title"]) { - db_query("INSERT INTO bundle (title, attributes) VALUES ('". check_input($edit["title"]) ."', '". check_input($edit["attributes"]) ."')"); + db_query("INSERT INTO bundle (title, attributes) VALUES ('%s', '%s')", $edit["title"], $edit["attributes"]); } module_rehash_blocks("import"); @@ -314,31 +315,31 @@ function import_form_feed($edit = array()) { function import_save_feed($edit) { if ($edit["fid"] && $edit["title"]) { - db_query("UPDATE feed SET title = '". check_input($edit["title"]) ."', url = '". check_input($edit["url"]) ."', attributes = '". check_input($edit["attributes"]) ."', refresh = '". check_input($edit["refresh"]) ."' WHERE fid = '". check_input($edit["fid"]) ."'"); - db_query("DELETE FROM item WHERE fid = '". check_input($edit["fid"]) ."'"); + db_query("UPDATE feed SET title = '%s', url = '%s', attributes = '%s', refresh = '%s' WHERE fid = '%s'", $edit["title"], $edit["url"], $edit["attributes"], $edit["refresh"], $edit["fid"]); + db_query("DELETE FROM item WHERE fid = '%s'", $edit["fid"]); } else if ($edit["fid"]) { - db_query("DELETE FROM feed WHERE fid = '". check_input($edit["fid"]) ."'"); - db_query("DELETE FROM item WHERE fid = '". check_input($edit["fid"]) ."'"); + db_query("DELETE FROM feed WHERE fid = '%s'", $edit["fid"]); + db_query("DELETE FROM item WHERE fid = '%s'", $edit["fid"]); } else if ($edit["title"]) { - db_query("INSERT INTO feed (title, url, attributes, refresh) VALUES ('". check_input($edit["title"]) ."', '". check_input($edit["url"]) ."', '". check_input($edit["attributes"]) ."', '". check_input($edit["refresh"]) ."')"); + db_query("INSERT INTO feed (title, url, attributes, refresh) VALUES ('%s', '%s', '%s', '%s')", $edit["title"], $edit["url"], $edit["attributes"], $edit["refresh"]); } } function import_save_attributes($edit) { foreach ($edit as $iid => $value) { - db_query("UPDATE item SET attributes = '". check_input($value) ."' WHERE iid = '". check_input($iid) ."'"); + db_query("UPDATE item SET attributes = '%s' WHERE iid = '%s'", $value, $iid); } return "attributes has been saved"; } function import_get_feed($fid) { - return db_fetch_array(db_query("SELECT * FROM feed WHERE fid = '". check_input($fid) ."'")); + return db_fetch_array(db_query("SELECT * FROM feed WHERE fid = '%s'", $fid)); } function import_get_bundle($bid) { - return db_fetch_array(db_query("SELECT * FROM bundle WHERE bid = '". check_input($bid) ."'")); + return db_fetch_array(db_query("SELECT * FROM bundle WHERE bid = '%s'", $bid)); } function import_view() { @@ -348,7 +349,7 @@ function import_view() { $output .= "\n"; $output .= " \n"; while ($feed = db_fetch_object($result)) { - $output .= " \n"; + $output .= " \n"; } $output .= "
titleattributesitemslast 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
". 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") ."".la(t("edit feed"), array("mod" => "import", "type" => "feed", "op" => "edit", "id" => $feed->fid))."" .la(t("remove items"), array("mod" => "import", "type" => "feed", "op" => "remove", "id" => $feed->fid)). "". la(t("update items"), array("mod" => "import", "type" => "feed", "op" => "update", "id" => $feed->fid)). "
\n"; @@ -358,7 +359,7 @@ function import_view() { $output .= "\n"; $output .= " \n"; while ($bundle = db_fetch_object($result)) { - $output .= " \n"; + $output .= " \n"; } $output .= "
titleattributesoperations
". check_output($bundle->title) ."". check_output($bundle->attributes) ."bid\">edit bundle
". check_output($bundle->title) ."". check_output($bundle->attributes) ."".la(t("edit bundle"), array("mod" => "import", "type" => "bundle", "op" => "edit", "id" => $bundle->bid))."
\n"; @@ -402,7 +403,7 @@ function import_fd_collect($edit) { $title = strip_tags(strtr($title[1], $tt)); // print "title = $title, link = $link
"; - if ($link && $link && !db_fetch_array(db_query("SELECT * FROM feed WHERE url = '". check_input($link) ."'"))) { + if ($link && $link && !db_fetch_array(db_query("SELECT * FROM feed WHERE url = '%s'", $link))) { $output .= " ". strtr($title, $tt) ."
"; } } @@ -431,7 +432,7 @@ function import_tag() { $output .= "\n"; $output .= " \n"; while ($item = db_fetch_object($result)) { - $output .= " \n"; + $output .= " \n"; } $output .= "
timefeeditem
". format_date($item->timestamp, "custom", "m/d/y") ."
". format_date($item->timestamp, "custom", "H:i") ."
fid\">". check_output($item->feed) ."link) ."\">". check_output($item->title) ."". ($item->description ? "
". check_output($item->description, 1) ."" : "") ."
iid]\" value=\"". check_form($item->attributes) ."\" size=\"50\" />
". format_date($item->timestamp, "custom", "m/d/y") ."
". format_date($item->timestamp, "custom", "H:i") ."
".la(check_output($item->feed), array("mod" => "import", "type" => "feed", "op" => "edit", "id" => $item->fid))."link) ."\">". check_output($item->title) ."". ($item->description ? "
". check_output($item->description, 1) ."" : "") ."
iid]\" value=\"". check_form($item->attributes) ."\" size=\"50\" />
\n"; $output .= "\n"; @@ -444,7 +445,14 @@ function import_admin() { if (user_access("administer news feeds")) { - print "add new feed | add new bundle | import feeds | tag items | overview | help
"; + $links[] = la(t("add new feed"), array("mod" => "import", "type" => "feed", "op" => "add")); + $links[] = la(t("add new bundle"), array("mod" => "import", "type" => "bundle", "op" => "add")); + $links[] = la(t("import feeds"), array("mod" => "import", "op" => "fd")); + $links[] = la(t("tag items"), array("mod" => "import", "op" => "tag")); + $links[] = la(t("overview"), array("mod" => "import", "op" => "view")); + $links[] = la(t("help"), array("mod" => "import", "op" => "help")); + + print "".implode(" | ", $links)."
"; switch ($op) { case "help": @@ -514,10 +522,10 @@ function import_admin() { function import_page_info() { global $theme; - $links[] = "". t("latest news") .""; - $links[] = "". t("news by source") .""; - $links[] = "". t("news by topic") .""; - $links[] = "". t("news sources") .""; + $links[] = lm(t("latest news"), array("mod" => "import"), t("Read the latest news from syndicated websites.")); + $links[] = lm(t("news by source"), array("mod" => "import", "op" => "feeds"), t("View the latest headlines sorted by source.")); + $links[] = lm(t("news by topic"), array("mod" => "import", "op" => "bundles"), t("View the latest headlines sorted by topic.")); + $links[] = lm(t("news sources"), array("mod" => "import", "op" => "sources"), t("View a list of all the websites we syndicate from.")); return "
". $theme->links($links) ."
"; } @@ -529,11 +537,11 @@ function import_page_last() { $output .= ""; while ($item = db_fetch_object($result)) { - $links[] = "iid\" title=\"". t("Comment on this news item in your personal blog.") ."\">". t("blog it") .""; - $links[] = "fid\" title=\"". t("Read more syndicated news from this feed.") ."\">". t("feed") .""; + $links[] = lm(t("blog it"), array("mod" => "node", "op" => "add", "type" => "blog", "iid" => $item->iid), t("Comment on this news item in your personal blog.")); + $links[] = lm(t("feed"), array("mod" => "import", "op" => "feed", "id" => $item->fid), t("Read more syndicated news from this feed.")); if ($item->link) { - $output .= "\n"; + $output .= "\n"; } if ($item->description) { @@ -553,17 +561,17 @@ function import_page_last() { function import_page_feed($fid) { global $theme; - $feed = db_fetch_object(db_query("SELECT * FROM feed WHERE fid = '". check_input($fid) ."'")); + $feed = db_fetch_object(db_query("SELECT * FROM feed WHERE fid = '%s'", $fid)); $header .= "

". t("Website") .":

". format_url($feed->link) ."

"; $header .= "

". t("Description") .":

". check_output($feed->description, 1) ."

"; $header .= "

". t("Last update") .":

". format_interval(time() - $feed->timestamp) ." ". t("ago") ."url\">image("xml.gif") ."\" width=\"36\" height=\"14\" align=\"right\" border=\"0\" />

\n"; - $result = db_query("SELECT * FROM item WHERE fid = '". check_input($fid) ."' ORDER BY iid DESC LIMIT ". variable_get("import_page_limit", 75)); + $result = db_query("SELECT * FROM item WHERE fid = '%s' ORDER BY iid DESC LIMIT ". variable_get("import_page_limit", 75), $fid); $output .= "
". format_url($item->link, $item->title) ." · fid\" title=\"". t("View more information about this feed.") ."\">$item->ftitle". $theme->links($links) ."
". format_url($item->link, $item->title) ." · ".lm($item->ftitle, array("mod" => "import", "op" => "feed", "id" => $item->fid), t("View more information about this feed."))."". $theme->links($links) ."
"; while ($item = db_fetch_object($result)) { - $links[] = "iid\" title=\"". t("Comment on this news item in your personal blog.") ."\">". t("blog it") .""; + $links[] = lm(t("blog it"), array("mod" => "node", "op" => "add", "type" => "blog", "iid" => $item->iid), t("Comment on this news item in your personal blog.")); $links[] = "link\">". t("visit") .""; if ($item->link) { @@ -586,9 +594,9 @@ function import_page_feed($fid) { function import_page_bundle($bid) { global $theme; - $bundle = db_fetch_object(db_query("SELECT * FROM bundle WHERE bid = '". check_input($bid) ."'")); + $bundle = db_fetch_object(db_query("SELECT * FROM bundle WHERE bid = '%s'", $bid)); - $header .= "

". t("Website") .":

". format_url("module.php?mod=import&op=bundle&id=$bundle->bid") ."

"; + $header .= "

". t("Website") .":

". format_url(drupal_url(array("mod" => "import", "op" => "bundle", "id" => $bundle->bid), "module")) ."

"; $header .= "

". t("Description") .":

". t("A composite news feed about") ." ". check_output($bundle->attributes) .".

"; $keys = explode(",", $bundle->attributes); @@ -597,12 +605,12 @@ function import_page_bundle($bid) { $output .= "
"; while ($item = db_fetch_object($result)) { - $links[] = "iid\" title=\"". t("Comment on this news item in your personal blog.") ."\">". t("blog it") .""; - $links[] = "fid\" title=\"". t("Read more syndicated news from this feed.") ."\">". t("feed") .""; + $links[] = lm(t("blog it"), array("mod" => "node", "op" => "add", "type" => "blog", "iid" => $item->iid), t("Comment on this news item in your personal blog.")); + $links[] = lm(t("feed"), array("mod" => "import", "op" => "feed", "id" => $item->fid), t("Read more syndicated news from this feed.")); $links[] = "link\">". t("visit") .""; if ($item->link) { - $output .= "\n"; + $output .= "\n"; } if ($item->description) { @@ -626,11 +634,11 @@ function import_page_sources() { $result = db_query("SELECT * FROM feed ORDER BY title"); while ($feed = db_fetch_object($result)) { - $output .= format_url("module.php?mod=import&op=feed&id=$feed->fid", $feed->title); + $output .= format_url(drupal_url(array("mod" => "import", "op" => "feed", "id" => $feed->fid), "module"), $feed->title); $output .= "
". check_output($feed->description, 1) ."

"; } - $output .= "image("xml.gif") ."\" width=\"36\" height=\"14\" align=\"right\" border=\"0\" />
\n"; + $output .= lm("image("xml.gif") ."\" width=\"36\" height=\"14\" align=\"right\" border=\"0\" />", array("mod" => "import", "op" => "fd"), t("View the list of syndicated websites in XML format."))."
\n"; $theme->header(); $theme->box(t("News feeds"), import_page_info()); -- cgit v1.2.3
". format_url($item->link, $item->title) ." · fid\" title=\"". t("View more information about this feed.") ."\">$item->ftitle". $theme->links($links) ."
". format_url($item->link, $item->title) ." · ".lm($item->ftitle, array("mod" => "import", "op" => "feed", "id" => $item->fid), t("View more information about this feed."))."". $theme->links($links) ."