Commit 8d103a08 authored by Dries's avatar Dries

- Committed Marco's block rewrite:

   + Blocks are not longer called if not rendered: major performance
     improvement.
   + Fixed some bugs (preview option was broken, path option was broken).
   + Removed "ascii"-type blocks.
   + Added permission to for "PHP blocks"
   + ...

  NOTES:

   + You'll want to run "update.php":

       ALTER TABLE blocks DROP remove;
       ALTER TABLE blocks DROP name;

   + You'll want to update your custom modules as well as the modules in
     the contrib repository.  Block function should now read:

       function *_block($op = "list", $delta = 0) {
         if ($op == "list") {
           return array of block infos
         }
         else {
           return subject and content of $delta block
         }
       }
parent 2ec14f35
......@@ -619,6 +619,14 @@ function form_submit($value) {
return "<input type=\"submit\" name=\"op\" value=\"". check_form($value) ."\" />\n";
}
function form_weight($title = NULL, $name = "weight", $value = 0, $delta = 10, $description = 0, $extra = 0) {
for ($n = (-1*$delta); $n <= $delta; $n++) {
$weights[$n] = $n;
}
return form_select($title, $name, $value, $weights, $description, $extra);
}
/**
* Build an URL; use this functions when you must write an URL
* for example in a form or a redirect.
......
......@@ -69,25 +69,4 @@ function module_hook($name, $hook) {
return function_exists($name ."_". $hook);
}
// rehash module-exported blocks:
function module_rehash_blocks($name) {
db_query("UPDATE blocks SET remove = '1' WHERE module = '$name'");
if ($blocks = module_invoke($name, "block")) {
foreach ($blocks as $delta => $block) {
foreach ($block as $item => $data) {
$block[$item] = addslashes($data);
}
if (!db_fetch_object(db_query("SELECT * FROM blocks WHERE module = '$name' AND name = '$block[info]'"))) {
db_query("INSERT INTO blocks (name, module, delta) VALUES ('$block[info]', '$name', '$delta')");
}
else {
db_query("UPDATE blocks SET delta = '$delta', remove = '0' WHERE module = '$name' AND name = '$block[info]'");
}
}
}
db_query("DELETE FROM blocks WHERE module = '$name' AND remove = '1'");
}
?>
\ No newline at end of file
......@@ -123,15 +123,15 @@ function theme_init() {
}
function theme_blocks($region, &$theme) {
global $id, $PHP_SELF, $user;
global $user, $PHP_SELF;
$result = db_query("SELECT * FROM blocks WHERE (status = '1' OR custom = '1') ". ($region != "all" ? "AND region = '%s' " : "") ."ORDER BY weight, name", $region == "left" ? 0 : 1);
$result = db_query("SELECT * FROM blocks WHERE (status = '1' OR custom = '1') ". ($region != "all" ? "AND region = '%s' " : "") ."ORDER BY weight, module", $region == "left" ? 0 : 1);
while ($result && ($block = db_fetch_object($result))) {
if (($block->status && (!$user->uid || !$block->custom)) || ($block->custom && $user->block[$block->name])) {
$blocks = module_invoke($block->module, "block");
if ($blocks[$block->delta]["content"]) {
$theme->box($blocks[$block->delta]["subject"], $blocks[$block->delta]["content"], $region);
if ((($block->status && (!$user->uid || !$block->custom)) || ($block->custom && $user->block[$block->module][$block->delta])) && (!$block->path || preg_match("|$block->path|", $PHP_SELF))) {
$block_data = module_invoke($block->module, "block", "view", $block->delta);
if ($block_data["content"]) {
$theme->box($block_data["subject"], $block_data["content"], $region);
}
}
}
......
......@@ -93,20 +93,44 @@ function import_feed_block($feed) {
return $output;
}
function import_block() {
return array_merge(import_get_bundles(), import_get_feeds());
function import_block($op, $delta) {
if ($op == "list") {
$result = db_query("SELECT * FROM bundle ORDER BY title");
while ($bundle = db_fetch_object($result)) {
$block[$bundle->bid]["info"] = "$bundle->title bundle";
}
$result = db_query("SELECT * FROM feed ORDER BY fid");
while ($feed = db_fetch_object($result)) {
$block[$feed->fid]["info"] = "$feed->title feed";
}
return $block;
}
else {
$feed = db_fetch_object(db_query("SELECT * FROM feed WHERE fid = '%d'", $delta));
if ($feed) {
$block["subject"] = $feed->title;
$block["content"] = import_feed_block($feed) ."<p><div align=\"right\">". lm(t("more"), array("mod" => "import", "op" => "feed", "id" => $feed->fid), "", array("title" => t("View this feed's recent news."))) ."</div></p>";
}
else {
// it was a bundle. this is NOT elegant
$bundle = db_fetch_object(db_query("SELECT * FROM bundle WHERE bid = '%d'", $delta));
$block["subject"] = $bundle->title;
$block["content"] = import_bundle_block($bundle->attributes) ."<p><div align=\"right\">". lm(t("more"), array("mod" => "import", "op" => "bundle", "id" => $bundle->bid), "", array("title" => t("View this bundle's recent news."))) ."</div></p>";
}
return $block;
}
}
function import_get_bundles($attributes = 0) {
$result = db_query("SELECT * FROM bundle ORDER BY title");
$i = 0;
while ($bundle = db_fetch_object($result)) {
$block[$i]["subject"] = $bundle->title;
$block[$i]["content"] = import_bundle_block($bundle->attributes) ."<p><div align=\"right\">". lm(t("more"), array("mod" => "import", "op" => "bundle", "id" => $bundle->bid), "", array("title" => t("View this bundle's recent news."))) ."</div></p>";
$block[$i]["info"] = "$bundle->title bundle";
$i++;
$block[$bundle->bid]["subject"] = $bundle->title;
$block[$bundle->bid]["content"] = import_bundle_block($bundle->attributes) ."<p><div align=\"right\">". lm(t("more"), array("mod" => "import", "op" => "bundle", "id" => $bundle->bid), "", array("title" => t("View this bundle's recent news."))) ."</div></p>";
$block[$bundle->bid]["info"] = "$bundle->title bundle";
}
return $block;
......@@ -115,13 +139,10 @@ function import_get_bundles($attributes = 0) {
function import_get_feeds($attributes = 0) {
$result = db_query("SELECT * FROM feed ORDER BY fid");
$i = 0;
while ($feed = db_fetch_object($result)) {
$block[$i]["subject"] = $feed->title;
$block[$i]["content"] = import_feed_block($feed) ."<p><div align=\"right\">". lm(t("more"), array("mod" => "import", "op" => "feed", "id" => $feed->fid), "", array("title" => t("View this feed's recent news."))) ."</div></p>";
$block[$i]["info"] = "$feed->title feed";
$i++;
$block[$feed->fid]["subject"] = $feed->title;
$block[$feed->fid]["content"] = import_feed_block($feed) ."<p><div align=\"right\">". lm(t("more"), array("mod" => "import", "op" => "feed", "id" => $feed->fid), "", array("title" => t("View this feed's recent news."))) ."</div></p>";
$block[$feed->fid]["info"] = "$feed->title feed";
}
return $block;
......@@ -289,10 +310,10 @@ function import_save_bundle($edit) {
db_query("DELETE FROM bundle WHERE bid = '%s'", $edit["bid"]);
}
else if ($edit["title"]) {
db_query("INSERT INTO bundle (title, attributes) VALUES ('%s', '%s')", $edit["title"], $edit["attributes"]);
// a single unique id for bundles and feeds, to use in blocks
$next_id = db_next_id("import");
db_query("INSERT INTO bundle (bid, title, attributes) VALUES ('%d', '%s', '%s')", $next_id, $edit["title"], $edit["attributes"]);
}
module_rehash_blocks("import");
}
function import_form_feed($edit = array()) {
......@@ -328,7 +349,9 @@ function import_save_feed($edit) {
db_query("DELETE FROM item WHERE fid = '%s'", $edit["fid"]);
}
else if ($edit["title"]) {
db_query("INSERT INTO feed (title, url, attributes, refresh) VALUES ('%s', '%s', '%s', '%s')", $edit["title"], $edit["url"], $edit["attributes"], $edit["refresh"]);
// a single unique id for bundles and feeds, to use in blocks
$next_id = db_next_id("import");
db_query("INSERT INTO feed (fid, title, url, attributes, refresh) VALUES ('%d', '%s', '%s', '%s', '%s')", $next_id, $edit["title"], $edit["url"], $edit["attributes"], $edit["refresh"]);
}
}
......@@ -694,26 +717,24 @@ function import_page_feeds() {
function import_page_blocks($blocks) {
global $theme;
$count = count($blocks);
$items = ceil($count / 3);
$c1 = min($items, $count);
$c2 = min(2 * $items, $count);
$c3 = $count;
$i = 0;
$theme->header();
$theme->box(t("News feeds"), import_page_info());
print "<table cellpadding=\"0\" cellspacing=\"5\" border=\"0\" width=\"100%\">\n";
print " <tr>\n";
print " <td width=\"33%\" valign=\"top\">\n";
for ($i; $i < $c1; $i++) $theme->box($blocks[$i]["subject"], $blocks[$i]["content"]);
print " </td>\n";
print " <td width=\"33%\" valign=\"top\">\n";
for ($i; $i < $c2; $i++) $theme->box($blocks[$i]["subject"], $blocks[$i]["content"]);
print " </td>\n";
print " <td width=\"33%\" valign=\"top\">\n";
for ($i; $i < $c3; $i++) $theme->box($blocks[$i]["subject"], $blocks[$i]["content"]);
print " </td>\n";
for ($t = 0; $t < 3; $t++) {
$i = 1;
print " <td width=\"33%\" valign=\"top\">\n";
while ($block = each($blocks)) {
$theme->box($block["value"]["subject"], $block["value"]["content"]);
if ($i == ceil(count($blocks) / 3)) {
break;
}
$i++;
}
print " </td>\n";
}
print " </tr>\n";
print "</table>\n";
$theme->footer();
......@@ -748,4 +769,4 @@ function import_page() {
}
}
?>
?>
\ No newline at end of file
......@@ -93,20 +93,44 @@ function import_feed_block($feed) {
return $output;
}
function import_block() {
return array_merge(import_get_bundles(), import_get_feeds());
function import_block($op, $delta) {
if ($op == "list") {
$result = db_query("SELECT * FROM bundle ORDER BY title");
while ($bundle = db_fetch_object($result)) {
$block[$bundle->bid]["info"] = "$bundle->title bundle";
}
$result = db_query("SELECT * FROM feed ORDER BY fid");
while ($feed = db_fetch_object($result)) {
$block[$feed->fid]["info"] = "$feed->title feed";
}
return $block;
}
else {
$feed = db_fetch_object(db_query("SELECT * FROM feed WHERE fid = '%d'", $delta));
if ($feed) {
$block["subject"] = $feed->title;
$block["content"] = import_feed_block($feed) ."<p><div align=\"right\">". lm(t("more"), array("mod" => "import", "op" => "feed", "id" => $feed->fid), "", array("title" => t("View this feed's recent news."))) ."</div></p>";
}
else {
// it was a bundle. this is NOT elegant
$bundle = db_fetch_object(db_query("SELECT * FROM bundle WHERE bid = '%d'", $delta));
$block["subject"] = $bundle->title;
$block["content"] = import_bundle_block($bundle->attributes) ."<p><div align=\"right\">". lm(t("more"), array("mod" => "import", "op" => "bundle", "id" => $bundle->bid), "", array("title" => t("View this bundle's recent news."))) ."</div></p>";
}
return $block;
}
}
function import_get_bundles($attributes = 0) {
$result = db_query("SELECT * FROM bundle ORDER BY title");
$i = 0;
while ($bundle = db_fetch_object($result)) {
$block[$i]["subject"] = $bundle->title;
$block[$i]["content"] = import_bundle_block($bundle->attributes) ."<p><div align=\"right\">". lm(t("more"), array("mod" => "import", "op" => "bundle", "id" => $bundle->bid), "", array("title" => t("View this bundle's recent news."))) ."</div></p>";
$block[$i]["info"] = "$bundle->title bundle";
$i++;
$block[$bundle->bid]["subject"] = $bundle->title;
$block[$bundle->bid]["content"] = import_bundle_block($bundle->attributes) ."<p><div align=\"right\">". lm(t("more"), array("mod" => "import", "op" => "bundle", "id" => $bundle->bid), "", array("title" => t("View this bundle's recent news."))) ."</div></p>";
$block[$bundle->bid]["info"] = "$bundle->title bundle";
}
return $block;
......@@ -115,13 +139,10 @@ function import_get_bundles($attributes = 0) {
function import_get_feeds($attributes = 0) {
$result = db_query("SELECT * FROM feed ORDER BY fid");
$i = 0;
while ($feed = db_fetch_object($result)) {
$block[$i]["subject"] = $feed->title;
$block[$i]["content"] = import_feed_block($feed) ."<p><div align=\"right\">". lm(t("more"), array("mod" => "import", "op" => "feed", "id" => $feed->fid), "", array("title" => t("View this feed's recent news."))) ."</div></p>";
$block[$i]["info"] = "$feed->title feed";
$i++;
$block[$feed->fid]["subject"] = $feed->title;
$block[$feed->fid]["content"] = import_feed_block($feed) ."<p><div align=\"right\">". lm(t("more"), array("mod" => "import", "op" => "feed", "id" => $feed->fid), "", array("title" => t("View this feed's recent news."))) ."</div></p>";
$block[$feed->fid]["info"] = "$feed->title feed";
}
return $block;
......@@ -289,10 +310,10 @@ function import_save_bundle($edit) {
db_query("DELETE FROM bundle WHERE bid = '%s'", $edit["bid"]);
}
else if ($edit["title"]) {
db_query("INSERT INTO bundle (title, attributes) VALUES ('%s', '%s')", $edit["title"], $edit["attributes"]);
// a single unique id for bundles and feeds, to use in blocks
$next_id = db_next_id("import");
db_query("INSERT INTO bundle (bid, title, attributes) VALUES ('%d', '%s', '%s')", $next_id, $edit["title"], $edit["attributes"]);
}
module_rehash_blocks("import");
}
function import_form_feed($edit = array()) {
......@@ -328,7 +349,9 @@ function import_save_feed($edit) {
db_query("DELETE FROM item WHERE fid = '%s'", $edit["fid"]);
}
else if ($edit["title"]) {
db_query("INSERT INTO feed (title, url, attributes, refresh) VALUES ('%s', '%s', '%s', '%s')", $edit["title"], $edit["url"], $edit["attributes"], $edit["refresh"]);
// a single unique id for bundles and feeds, to use in blocks
$next_id = db_next_id("import");
db_query("INSERT INTO feed (fid, title, url, attributes, refresh) VALUES ('%d', '%s', '%s', '%s', '%s')", $next_id, $edit["title"], $edit["url"], $edit["attributes"], $edit["refresh"]);
}
}
......@@ -694,26 +717,24 @@ function import_page_feeds() {
function import_page_blocks($blocks) {
global $theme;
$count = count($blocks);
$items = ceil($count / 3);
$c1 = min($items, $count);
$c2 = min(2 * $items, $count);
$c3 = $count;
$i = 0;
$theme->header();
$theme->box(t("News feeds"), import_page_info());
print "<table cellpadding=\"0\" cellspacing=\"5\" border=\"0\" width=\"100%\">\n";
print " <tr>\n";
print " <td width=\"33%\" valign=\"top\">\n";
for ($i; $i < $c1; $i++) $theme->box($blocks[$i]["subject"], $blocks[$i]["content"]);
print " </td>\n";
print " <td width=\"33%\" valign=\"top\">\n";
for ($i; $i < $c2; $i++) $theme->box($blocks[$i]["subject"], $blocks[$i]["content"]);
print " </td>\n";
print " <td width=\"33%\" valign=\"top\">\n";
for ($i; $i < $c3; $i++) $theme->box($blocks[$i]["subject"], $blocks[$i]["content"]);
print " </td>\n";
for ($t = 0; $t < 3; $t++) {
$i = 1;
print " <td width=\"33%\" valign=\"top\">\n";
while ($block = each($blocks)) {
$theme->box($block["value"]["subject"], $block["value"]["content"]);
if ($i == ceil(count($blocks) / 3)) {
break;
}
$i++;
}
print " </td>\n";
}
print " </tr>\n";
print "</table>\n";
$theme->footer();
......@@ -748,4 +769,4 @@ function import_page() {
}
}
?>
?>
\ No newline at end of file
......@@ -102,14 +102,20 @@ function archive_display($original = 0) {
return $output;
}
function archive_block() {
function archive_block($op = "list", $delta = 0) {
global $date;
$block[0]["subject"] = "Browse archives";
$block[0]["content"] = archive_display($date);
$block[0]["info"] = "Calendar to browse archives";
return $block;
if ($op == "list") {
$blocks[0]["info"] = t("Calendar to browse archives");
return $blocks;
}
else {
switch ($delta) {
case 0:
$block["subject"] = t("Browse archives");
$block["content"] = archive_display($date);
return $block;
}
}
}
function archive_link($type) {
......@@ -169,10 +175,11 @@ function archive_page() {
}
}
else {
$theme->box(t("Access denied"), message_access());
#$theme->box(t("Access denied"), message_access());
message_access();
}
$theme->footer();
}
?>
?>
\ No newline at end of file
......@@ -102,14 +102,20 @@ function archive_display($original = 0) {
return $output;
}
function archive_block() {
function archive_block($op = "list", $delta = 0) {
global $date;
$block[0]["subject"] = "Browse archives";
$block[0]["content"] = archive_display($date);
$block[0]["info"] = "Calendar to browse archives";
return $block;
if ($op == "list") {
$blocks[0]["info"] = t("Calendar to browse archives");
return $blocks;
}
else {
switch ($delta) {
case 0:
$block["subject"] = t("Browse archives");
$block["content"] = archive_display($date);
return $block;
}
}
}
function archive_link($type) {
......@@ -169,10 +175,11 @@ function archive_page() {
}
}
else {
$theme->box(t("Access denied"), message_access());
#$theme->box(t("Access denied"), message_access());
message_access();
}
$theme->footer();
}
?>
?>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
......@@ -332,25 +332,24 @@ function blog_link($type, $node = 0, $main) {
return $links ? $links : array();
}
function blog_block() {
function blog_block($op = "list", $delta = 0) {
global $user;
$result = db_query("SELECT u.uid, u.name, n.created, n.title, n.nid FROM node n LEFT JOIN users u ON n.uid = u.uid WHERE n.type = 'blog' ORDER BY n.nid DESC LIMIT 10");
if (user_access("access content")) {
while ($node = db_fetch_object($result)) {
$output .= l(check_output($node->title), array("id" => $node->nid)) ."<br />\n";
if ($op == "list") {
$blocks[0]["info"] = t("User blogs");
return $blocks;
}
else {
if (user_access("access content")) {
$result = db_query("SELECT u.uid, u.name, n.created, n.title, n.nid FROM node n LEFT JOIN users u ON n.uid = u.uid WHERE n.type = 'blog' ORDER BY n.nid DESC LIMIT 10");
while ($node = db_fetch_object($result)) {
$output .= l(check_output($node->title), array("id" => $node->nid)) ."<br />\n";
}
$output .= "<br /><div align=\"right\">". lm(t("more"), array("mod" => "blog"), "", array("title" => t("Read the latest blog entries."))) ."</div>";
$block["content"] = $output;
$block["subject"] = t("User blogs");
}
$output .= "<br /><div align=\"right\">".lm(t("more"), array("mod" => "blog"), "", array("title" => t("Read the latest blog entries."))) ."</div>";
$block[0]["content"] = $output;
return $block;
}
$block[0]["subject"] = t("User blogs");
$block[0]["info"] = t("User blogs");
$block[0]["link"] = drupal_url(array("mod" => "blog"), "module");
return $block;
}
?>
?>
\ No newline at end of file
......@@ -332,25 +332,24 @@ function blog_link($type, $node = 0, $main) {
return $links ? $links : array();
}
function blog_block() {
function blog_block($op = "list", $delta = 0) {
global $user;
$result = db_query("SELECT u.uid, u.name, n.created, n.title, n.nid FROM node n LEFT JOIN users u ON n.uid = u.uid WHERE n.type = 'blog' ORDER BY n.nid DESC LIMIT 10");
if (user_access("access content")) {
while ($node = db_fetch_object($result)) {
$output .= l(check_output($node->title), array("id" => $node->nid)) ."<br />\n";
if ($op == "list") {
$blocks[0]["info"] = t("User blogs");
return $blocks;
}
else {
if (user_access("access content")) {
$result = db_query("SELECT u.uid, u.name, n.created, n.title, n.nid FROM node n LEFT JOIN users u ON n.uid = u.uid WHERE n.type = 'blog' ORDER BY n.nid DESC LIMIT 10");
while ($node = db_fetch_object($result)) {
$output .= l(check_output($node->title), array("id" => $node->nid)) ."<br />\n";
}
$output .= "<br /><div align=\"right\">". lm(t("more"), array("mod" => "blog"), "", array("title" => t("Read the latest blog entries."))) ."</div>";
$block["content"] = $output;
$block["subject"] = t("User blogs");
}
$output .= "<br /><div align=\"right\">".lm(t("more"), array("mod" => "blog"), "", array("title" => t("Read the latest blog entries."))) ."</div>";
$block[0]["content"] = $output;
return $block;
}
$block[0]["subject"] = t("User blogs");
$block[0]["info"] = t("User blogs");
$block[0]["link"] = drupal_url(array("mod" => "blog"), "module");
return $block;
}
?>
?>
\ No newline at end of file
......@@ -167,11 +167,16 @@ function cloud_page() {
}
}
function cloud_block() {
$block[0]["subject"] = t("Site cloud");
$block[0]["content"] = cloud_list(20) ."<br /><div align=\"right\">". lm(t("more"), array("mod" => "cloud"), "", array("title" => t("Monitor other sites in the cloud."))) ."</div>";
$block[0]["info"] = t("Site cloud");
return $block;
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() {
......@@ -209,4 +214,4 @@ function cloud_admin() {
}
}
?>
?>
\ No newline at end of file
......@@ -93,20 +93,44 @@ function import_feed_block($feed) {
return $output;
}
function import_block() {
return array_merge(import_get_bundles(), import_get_feeds());
function import_block($op, $delta) {
if ($op == "list") {
$result = db_query("SELECT * FROM bundle ORDER BY title");
while ($bundle = db_fetch_object($result)) {
$block[$bundle->bid]["info"] = "$bundle->title bundle";
}
$result = db_query("SELECT * FROM feed ORDER BY fid");
while ($feed = db_fetch_object($result)) {
$block[$feed->fid]["info"] = "$feed->title feed";
}
return $block;
}
else {
$feed = db_fetch_object(db_query("SELECT * FROM feed WHERE fid = '%d'", $delta));
if ($feed) {
$block["subject"] = $feed->title;
$block["content"] = import_feed_block($feed) ."<p><div align=\"right\">". lm(t("more"), array("mod" => "import", "op" => "feed", "id" => $feed->fid), "", array("title" => t("View this feed's recent news."))) ."</div></p>";
}
else {
// it was a bundle. this is NOT elegant
$bundle = db_fetch_object(db_query("SELECT * FROM bundle WHERE bid = '%d'", $delta));
$block["subject"] = $bundle->title;
$block["content"] = import_bundle_block($bundle->attributes) ."<p><div align=\"right\">". lm(t("more"), array("mod" => "import", "op" => "bundle", "id" => $bundle->bid), "", array("title" => t("View this bundle's recent news."))) ."</div></p>";
}
return $block;
}
}
function import_get_bundles($attributes = 0) {
$result = db_query("SELECT * FROM bundle ORDER BY title");
$i = 0;
while ($bundle = db_fetch_object($result)) {
$block[$i]["subject"] = $bundle->title;
$block[$i]["content"] = import_bundle_block($bundle->attributes) ."<p><div align=\"right\">". lm(t("more"), array("mod" => "import", "op" => "bundle", "id" => $bundle->bid), "", array("title" => t("View this bundle's recent news."))) ."</div></p>";
$block[$i]["info"] = "$bundle->title bundle";
$i++;
$block[$bundle->bid]["subject"] = $bundle->title;
$block[$bundle->bid]["content"] = import_bundle_block($bundle->attributes) ."<p><div align=\"right\">". lm(t("more"), array("mod" => "import", "op" => "bundle", "id" => $bundle->bid), "", array("title" => t("View this bundle's recent news."))) ."</div></p>";
$block[$bundle->bid]["info"] = "$bundle->title bundle";
}
return $block;
......@@ -115,13 +139,10 @@ function import_get_bundles($attributes = 0) {
function import_get_feeds($attributes = 0) {
$result = db_query("SELECT * FROM feed ORDER BY fid");
$i = 0;
while ($feed = db_fetch_object($result)) {
$block[$i]["subject"] = $feed->title;
$block[$i]["content"] = import_feed_block($feed) ."<p><div align=\"right\">". lm(t("more"), array("mod" => "import", "op" => "feed", "id" => $feed->fid), "", array("title" => t("View this feed's recent news."))) ."</div></p>";
$block[$i]["info"] = "$feed->title feed";
$i++;
$block[$feed->fid]["subject"] = $feed->title;
$block[$feed->fid]["content"] = import_feed_block($feed) ."<p><div align=\"right\">". lm(t("more"), array("mod" => "import", "op" => "feed", "id" => $feed->fid), "", array("title" => t("View this feed's recent news."))) ."</div></p>";
$block[$feed->fid]["info"] = "$feed->title feed";
}
return $block;
......@@ -289,10 +310,10 @@ function import_save_bundle($edit) {
db_query("DELETE FROM bundle WHERE bid = '%s'", $edit["bid"]);
}
else if ($edit["title"]) {
db_query("INSERT INTO bundle (title, attributes) VALUES ('%s', '%s')", $edit["title"], $edit["attributes"]);
// a single unique id for bundles and feeds, to use in blocks
$next_id = db_next_id("import");
db_query("INSERT INTO bundle (bid, title, attributes) VALUES ('%d', '%s', '%s')", $next_id, $edit["title"], $edit["attributes"]);
}
module_rehash_blocks("import");
}
function import_form_feed($edit = array()) {
......@@ -328,7 +349,9 @@ function import_save_feed($edit) {
db_query("DELETE FROM item WHERE fid = '%s'", $edit["fid"]);
}
else if ($edit["title"]) {
db_query("INSERT INTO feed (title, url, attributes, refresh) VALUES ('%s', '%s', '%s', '%s')", $edit["title"], $edit["url"], $edit["attributes"], $edit["refresh"]);
// a single unique id for bundles and feeds, to use in blocks
$next_id = db_next_id("import");
db_query("INSERT INTO feed (fid, title, url, attributes, refresh) VALUES ('%d', '%s', '%s', '%s', '%s')", $next_id, $edit["title"], $edit["url"], $edit["attributes"], $edit["refresh"]);
}
}
......@@ -694,26 +717,24 @@ function import_page_feeds() {
function import_page_blocks($blocks) {
global $theme;
$count = count($blocks);
$items = ceil($count / 3);
$c1 = min($items, $count);
$c2 = min(2 * $items, $count);
$c3 = $count;
$i = 0;
$theme->header();
$theme->box(t("News feeds"), import_page_info());
print "<table cellpadding=\"0\" cellspacing=\"5\" border=\"0\" width=\"100%\">\n";
print " <tr>\n";
print " <td width=\"33%\" valign=\"top\">\n";
for ($i; $i < $c1; $i++) $theme->box($blocks[$i]["subject"], $blocks[$i]["content"]);
print " </td>\n";
print " <td width=\"33%\" valign=\"top\">\n";
for ($i; $i < $c2; $i++) $theme->box($blocks[$i]["subject"], $blocks[$i]["content"]);
print " </td>\n";
print " <td width=\"33%\" valign=\"top\">\n";
for ($i; $i < $c3; $i++) $theme->box($blocks[$i]["subject"], $blocks[$i]["content"]);
print " </td>\n";
for ($t = 0; $t < 3; $t++) {
$i = 1;
print " <td width=\"33%\" valign=\"top\">\n";
while ($block = each($blocks)) {
$theme->box($block["value"]["subject"], $block["value"]["content"]);
if ($i == ceil(count($blocks) / 3)) {
break;
}
$i++;
}
print " </td>\n";
}
print " </tr>\n";
print "</table>\n";
$theme->footer();
......@@ -748,4 +769,4 @@ function import_page() {
}
}
?>
?>
\ No newline at end of file
......@@ -670,14 +670,18 @@ function node_admin() {
}
}
function node_block() {