diff options
author | Dries Buytaert <dries@buytaert.net> | 2004-05-11 20:10:14 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2004-05-11 20:10:14 +0000 |
commit | c314ff54a6ef7a7e5115a12dcdd5e7f23b108542 (patch) | |
tree | 622db781726c3dcdabc56a7ee3e0ea2d1e454ec0 | |
parent | 4fad80e53822ca8d9a62098cfc7f23db1c4ea3e0 (diff) | |
download | brdo-c314ff54a6ef7a7e5115a12dcdd5e7f23b108542.tar.gz brdo-c314ff54a6ef7a7e5115a12dcdd5e7f23b108542.tar.bz2 |
- Code improvements by JonBob. Thanks again.
-rw-r--r-- | modules/admin.module | 7 | ||||
-rw-r--r-- | modules/aggregator.module | 365 | ||||
-rw-r--r-- | modules/aggregator/aggregator.module | 365 | ||||
-rw-r--r-- | modules/archive.module | 137 | ||||
-rw-r--r-- | modules/archive/archive.module | 137 | ||||
-rw-r--r-- | modules/block.module | 314 | ||||
-rw-r--r-- | modules/block/block.module | 314 |
7 files changed, 931 insertions, 708 deletions
diff --git a/modules/admin.module b/modules/admin.module index 6d1069947..8c9c97e01 100644 --- a/modules/admin.module +++ b/modules/admin.module @@ -1,6 +1,9 @@ <?php // $Id$ +/** + * Implementation of hook_help(). + */ function admin_help($section) { switch ($section) { case "admin/system/modules#description": @@ -21,6 +24,10 @@ function admin_link($type) { } } +/** + * Menu callback. Provides an overview to serve as the main page of the + * administration section. + */ function admin_admin() { print theme("page", watchdog_overview("actions")); } diff --git a/modules/aggregator.module b/modules/aggregator.module index 2ffd7664b..6b08be814 100644 --- a/modules/aggregator.module +++ b/modules/aggregator.module @@ -1,6 +1,9 @@ <?php /* $Id$ */ +/** + * Implementation of hook_help(). + */ function aggregator_help($section) { switch ($section) { case 'admin/help#aggregator': @@ -64,11 +67,18 @@ function aggregator_help($section) { } } +/** + * Menu callback. Displays the aggregator-specific information from admin/help. + */ function aggregator_help_page() { print theme('page', aggregator_help('admin/help#aggregator')); } +/** + * Implementation of hook_settings(). + */ function aggregator_settings() { + $output = ''; $number = drupal_map_assoc(array(5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100)); $items = array(0 => t('none'), 3 => t('3 items'), 5 => t('5 items'), 10 => t('10 items'), 15 => t('15 items'), 20 => t('20 items'), 25 => t('25 items')); @@ -79,6 +89,9 @@ function aggregator_settings() { return $output; } +/** + * Implementation of hook_perm(). + */ function aggregator_perm() { return array('administer news feeds', 'access news feeds'); } @@ -94,9 +107,11 @@ function aggregator_link($type) { if ($type == 'system') { $access = user_access('administer news feeds'); menu('admin/syndication', t('syndication'), $access ? 'aggregator_help_page' : MENU_DENIED, 5); - menu('admin/syndication/news', t('RSS/RDF'), $access ? 'aggregator_admin' : MENU_DENIED); - menu('admin/syndication/news/add/feed', t('new feed'), $access ? 'aggregator_admin' : MENU_DENIED, 2); - menu('admin/syndication/news/add/category', t('new category'), $access ? 'aggregator_admin' : MENU_DENIED, 3); + menu('admin/syndication/news', t('RSS/RDF'), $access ? 'aggregator_admin_overview' : MENU_DENIED); + menu('admin/syndication/news/add/feed', t('new feed'), $access ? 'aggregator_admin_edit_feed' : MENU_DENIED, 2); + menu('admin/syndication/news/add/category', t('new category'), $access ? 'aggregator_admin_edit_category' : MENU_DENIED, 3); + menu('admin/syndication/news/remove', t('remove items'), $access ? 'aggregator_admin_remove_feed' : MENU_DENIED, 0, MENU_HIDE, MENU_LOCKED); + menu('admin/syndication/news/update', t('update items'), $access ? 'aggregator_admin_refresh_feed' : MENU_DENIED, 0, MENU_HIDE, MENU_LOCKED); menu('admin/syndication/news/help', t('help'), $access ? 'aggregator_help_page' : MENU_DENIED, 9); $access = user_access('access news feeds'); @@ -106,6 +121,8 @@ function aggregator_link($type) { // To reduce the number of SQL queries, we don't query the database when // not on an aggregator page. + // If caching of the menu is implemented, this check should be removed + // so that DHTML menu presentation can be used correctly. if (arg(0) == 'aggregator') { // Sources: $result = db_query('SELECT title, fid FROM {aggregator_feed} ORDER BY title'); @@ -124,13 +141,23 @@ function aggregator_link($type) { } } +/** + * Implementation of hook_cron(). + * + * Checks news feeds for updates once their refresh interval has elapsed. + */ function aggregator_cron() { - $result = db_query("SELECT * FROM {aggregator_feed} WHERE checked + refresh < %d", time()); + $result = db_query('SELECT * FROM {aggregator_feed} WHERE checked + refresh < %d', time()); while ($feed = db_fetch_array($result)) { aggregator_refresh($feed); } } +/** + * Implementation of hook_block(). + * + * Generates blocks for the latest news items in each category and feed. + */ function aggregator_block($op, $delta) { if (user_access('access news feeds')) { if ($op == 'list') { @@ -161,9 +188,9 @@ function aggregator_block($op, $delta) { } $items = array(); while ($item = db_fetch_object($result)) { - $items[] = theme("aggregator_block_item", $item); + $items[] = theme('aggregator_block_item', $item); } - $block['content'] = theme("item_list", $items) . $block['content']; + $block['content'] = theme('item_list', $items) . $block['content']; } return $block; } @@ -182,16 +209,18 @@ function aggregator_remove($feed) { drupal_set_message(t('removed news items from \'%site\'.', array('%site' => $feed['title']))); } -// Call-back function used by XML parser: +/** + * Call-back function used by the XML parser. + */ function aggregator_element_start($parser, $name, $attributes) { global $item, $element, $tag; switch ($name) { - case "IMAGE": - case "TEXTINPUT": + case 'IMAGE': + case 'TEXTINPUT': $element = $name; break; - case "ITEM": + case 'ITEM': $element = $name; $item += 1; } @@ -199,40 +228,45 @@ function aggregator_element_start($parser, $name, $attributes) { $tag = $name; } -// Call-back function used by XML parser: +/** + * Call-back function used by the XML parser. + */ function aggregator_element_end($parser, $name) { global $element; switch ($name) { - case "IMAGE": - case "TEXTINPUT": - case "ITEM": - $element = ""; + case 'IMAGE': + case 'TEXTINPUT': + case 'ITEM': + $element = ''; } } -// Call-back function used by XML parser: +/** + * Call-back function used by the XML parser. + */ function aggregator_element_data($parser, $data) { global $channel, $element, $items, $item, $image, $tag; switch ($element) { - case "ITEM": + case 'ITEM': $items[$item][$tag] .= $data; break; - case "IMAGE": + case 'IMAGE': $image[$tag] .= $data; break; - case "TEXTINPUT": - /* - ** The sub-element is not supported but we have recognize - ** it or its content will end up in the items-array. - */ + case 'TEXTINPUT': + // The sub-element is not supported. However, we must recognize + // it or its contents will end up in the item array. break; default: $channel[$tag] .= $data; } } +/** + * Checks a news feed for new items. + */ function aggregator_refresh($feed) { global $channel, $image; @@ -242,7 +276,7 @@ function aggregator_refresh($feed) { $headers['If-None-Match'] = $feed['etag']; } if ($feed['modified']) { - $headers['If-Modified-Since'] = gmdate("D, d M Y H:i:s", $feed['modified']) ." GMT"; + $headers['If-Modified-Since'] = gmdate('D, d M Y H:i:s', $feed['modified']) .' GMT'; } // Request feed. @@ -251,18 +285,18 @@ function aggregator_refresh($feed) { // Process HTTP reponse code. switch ($result->code) { case 304: - db_query("UPDATE {aggregator_feed} SET checked = %d WHERE fid = %d", time(), $feed['fid']); - drupal_set_message(t("no new syndicated content from '%site'.", array('%site' => $feed['title']))); + db_query('UPDATE {aggregator_feed} SET checked = %d WHERE fid = %d', time(), $feed['fid']); + drupal_set_message(t('no new syndicated content from "%site".', array('%site' => $feed['title']))); break; case 301: $feed['url'] = $result->redirect_url; - watchdog('special', "aggregator: updated URL for feed '$feed[title]' to $feed[url]"); + watchdog('special', "aggregator: updated URL for feed \"$feed[title]\" to $feed[url]"); case 200: case 302: case 307: // Filter the input data: if (!valid_input_data($result->data)) { - drupal_set_message(t("failed to parse RSS feed '%site': suspicious input data.", array("%site" => $feed["title"])), 'error'); + drupal_set_message(t('failed to parse RSS feed "%site": suspicious input data.', array('%site' => $feed['title'])), 'error'); } else if (aggregator_parse_feed($result->data, $feed)) { @@ -279,7 +313,7 @@ function aggregator_refresh($feed) { } if ($image['LINK'] && $image['URL'] && $image['TITLE']) { - $image = "<a href=\"". $image['LINK'] ."\"><img src=\"". $image['URL'] ."\" alt=\"". $image['TITLE'] ."\" /></a>"; + $image = '<a href="'. $image['LINK'] .'"><img src="'. $image['URL'] .'" alt="'. $image['TITLE'] .'" /></a>'; } else { $image = NULL; @@ -297,13 +331,13 @@ function aggregator_refresh($feed) { cache_clear_all(); - $message = t("syndicated content from '%site'.", array("%site" => $feed["title"])); + $message = t('syndicated content from "%site".', array('%site' => $feed['title'])); watchdog('regular', "aggregator: $message"); drupal_set_message($message); } break; default: - $message = t("failed to parse RSS feed '%site': %error.", array('%site' => $feed['title'], '%error' => $result->code .' '. $result->error)); + $message = t('failed to parse RSS feed "%site": %error.', array('%site' => $feed['title'], '%error' => $result->code .' '. $result->error)); watchdog('error', "aggregator: $message"); drupal_set_message($message); } @@ -313,18 +347,18 @@ function aggregator_parse_feed(&$data, $feed) { global $items, $image, $channel; // Unset the global variables before we use them: - unset($GLOBALS["element"], $GLOBALS["item"], $GLOBALS["tag"]); + unset($GLOBALS['element'], $GLOBALS['item'], $GLOBALS['tag']); $items = array(); $image = array(); $channel = array(); // parse the data: $xml_parser = drupal_xml_parser_create($data); - xml_set_element_handler($xml_parser, "aggregator_element_start", "aggregator_element_end"); - xml_set_character_data_handler($xml_parser, "aggregator_element_data"); + xml_set_element_handler($xml_parser, 'aggregator_element_start', 'aggregator_element_end'); + xml_set_character_data_handler($xml_parser, 'aggregator_element_data'); if (!xml_parse($xml_parser, $data, 1)) { - $message = t("failed to parse RSS feed '%site': %error at line %line.", array("%site" => $feed["title"], "%error" => xml_error_string(xml_get_error_code($xml_parser)), "%line" => xml_get_current_line_number($xml_parser))); + $message = t('failed to parse RSS feed "%site": %error at line %line.', array('%site' => $feed['title'], '%error' => xml_error_string(xml_get_error_code($xml_parser)), '%line' => xml_get_current_line_number($xml_parser))); watchdog('error', "aggregator: $message"); drupal_set_message($message, 'error'); return 0; @@ -333,7 +367,7 @@ function aggregator_parse_feed(&$data, $feed) { // initialize the translation table: $tt = array_flip(get_html_translation_table(HTML_SPECIALCHARS)); - $tt["'"] = "'"; + $tt['''] = "'"; /* ** We reverse the array such that we store the first item last, @@ -357,25 +391,25 @@ function aggregator_parse_feed(&$data, $feed) { ** boundary but not splitting potential entities. */ - if ($item["TITLE"]) { - $title = $item["TITLE"]; + if ($item['TITLE']) { + $title = $item['TITLE']; } else { - $title = preg_replace('/^(.*)[^\w;&].*?$/', "\\1", truncate_utf8($item["DESCRIPTION"], 40)); + $title = preg_replace('/^(.*)[^\w;&].*?$/', "\\1", truncate_utf8($item['DESCRIPTION'], 40)); } /* ** Resolve the items link. */ - if ($item["LINK"]) { - $link = $item["LINK"]; + if ($item['LINK']) { + $link = $item['LINK']; } - elseif ($item["GUID"] && (strncmp($item["GUID"], "http://", 7) == 0)) { - $link = $item["GUID"]; + elseif ($item['GUID'] && (strncmp($item['GUID'], 'http://', 7) == 0)) { + $link = $item['GUID']; } else { - $link = $feed["link"]; + $link = $feed['link']; } /* @@ -398,7 +432,7 @@ function aggregator_parse_feed(&$data, $feed) { ** be parsed directly using PHP's strtotime(). It is not the only ** valid format so this might fail nonetheless ... */ - list($year, $month, $day, $hour, $minute, $second) = sscanf($date, "%4d-%2d-%2dT%2d:%2d:%2d"); + list($year, $month, $day, $hour, $minute, $second) = sscanf($date, '%4d-%2d-%2dT%2d:%2d:%2d'); $timestamp = strtotime("$year-$month-$day $hour:$minute:$second"); } @@ -412,14 +446,14 @@ function aggregator_parse_feed(&$data, $feed) { ** pass along it's ID such that we can update it if needed. */ - if ($link && $link != $feed["link"] && $link != $feed["url"]) { - $entry = db_fetch_object(db_query("SELECT iid FROM {aggregator_item} WHERE fid = %d AND link = '%s'", $feed["fid"], $link)); + if ($link && $link != $feed['link'] && $link != $feed['url']) { + $entry = db_fetch_object(db_query("SELECT iid FROM {aggregator_item} WHERE fid = %d AND link = '%s'", $feed['fid'], $link)); } else { - $entry = db_fetch_object(db_query("SELECT iid FROM {aggregator_item} WHERE fid = %d AND title = '%s'", $feed["fid"], $title)); + $entry = db_fetch_object(db_query("SELECT iid FROM {aggregator_item} WHERE fid = %d AND title = '%s'", $feed['fid'], $title)); } - aggregator_save_item(array('iid' => $entry->iid, 'fid' => $feed["fid"], 'timestamp' => $timestamp, 'title' => $title, 'link' => $link, 'author' => $item["AUTHOR"], 'description' => $item["DESCRIPTION"])); + aggregator_save_item(array('iid' => $entry->iid, 'fid' => $feed['fid'], 'timestamp' => $timestamp, 'title' => $title, 'link' => $link, 'author' => $item['AUTHOR'], 'description' => $item['DESCRIPTION'])); } /* @@ -428,14 +462,14 @@ function aggregator_parse_feed(&$data, $feed) { unset($items); - $result = db_query("SELECT iid FROM {aggregator_item} WHERE fid = %d ORDER BY timestamp", $feed["fid"]); + $result = db_query('SELECT iid FROM {aggregator_item} WHERE fid = %d ORDER BY timestamp', $feed['fid']); while ($item = db_fetch_object($result)) { $items[] = "iid = '$item->iid'"; } if (sizeof($items) > 50) { - db_query("DELETE FROM {aggregator_item} WHERE ". implode(" OR ", array_slice($items, 0, - 50))); + db_query('DELETE FROM {aggregator_item} WHERE '. implode(' OR ', array_slice($items, 0, - 50))); db_query('DELETE FROM {aggregator_category_item} WHERE '. implode(' OR ', array_slice($items, 0, -50))); } @@ -443,16 +477,16 @@ function aggregator_parse_feed(&$data, $feed) { } function aggregator_save_item($edit) { - if ($edit["iid"] && $edit["title"]) { - db_query("UPDATE {aggregator_item} SET title = '%s', link = '%s', author = '%s', description = '%s' WHERE iid = %d", $edit["title"], $edit["link"], $edit["author"], $edit["description"], $edit["iid"]); + if ($edit['iid'] && $edit['title']) { + db_query("UPDATE {aggregator_item} SET title = '%s', link = '%s', author = '%s', description = '%s' WHERE iid = %d", $edit['title'], $edit['link'], $edit['author'], $edit['description'], $edit['iid']); } - else if ($edit["iid"]) { - db_query("DELETE FROM {aggregator_item} WHERE iid = %d", $edit["iid"]); - db_query("DELETE FROM {aggregator_category_item} WHERE iid = %d", $edit["iid"]); + else if ($edit['iid']) { + db_query('DELETE FROM {aggregator_item} WHERE iid = %d', $edit['iid']); + db_query('DELETE FROM {aggregator_category_item} WHERE iid = %d', $edit['iid']); } - else if ($edit["title"] && $edit["link"]) { - $next_id = db_next_id("{aggregator_item}_iid"); - db_query("INSERT INTO {aggregator_item} (iid, fid, title, link, author, description, timestamp) VALUES (%d, %d, '%s', '%s', '%s', '%s', %d)", $next_id, $edit["fid"], $edit["title"], $edit["link"], $edit["author"], $edit["description"], $edit["timestamp"]); + else if ($edit['title'] && $edit['link']) { + $next_id = db_next_id('{aggregator_item}_iid'); + db_query("INSERT INTO {aggregator_item} (iid, fid, title, link, author, description, timestamp) VALUES (%d, %d, '%s', '%s', '%s', '%s', %d)", $next_id, $edit['fid'], $edit['title'], $edit['link'], $edit['author'], $edit['description'], $edit['timestamp']); // file the items in the categories indicated by the feed $categories = db_query('SELECT cid FROM {aggregator_category_feed} WHERE fid = %d', $edit['fid']); while ($category = db_fetch_object($categories)) { @@ -492,18 +526,18 @@ function aggregator_save_category($edit) { } function aggregator_form_feed($edit = array()) { - $period = drupal_map_assoc(array(900, 1800, 3600, 7200, 10800, 21600, 32400, 43200, 64800, 86400, 172800, 259200, 604800, 1209600, 2419200), "format_interval"); + $period = drupal_map_assoc(array(900, 1800, 3600, 7200, 10800, 21600, 32400, 43200, 64800, 86400, 172800, 259200, 604800, 1209600, 2419200), 'format_interval'); $block_items = array(0 => t('no block'), 3 => t('3 items'), 5 => t('5 items'), 10 => t('10 items'), 15 => t('15 items'), 20 => t('20 items'), 25 => t('25 items')); - if ($edit["refresh"] == "") { - $edit["refresh"] = 3600; + if ($edit['refresh'] == '') { + $edit['refresh'] = 3600; } - $form .= form_textfield(t("Title"), "title", $edit["title"], 50, 64, t("The name of the feed; typically the name of the web site you syndicate content from.")); - $form .= form_textfield(t("URL"), "url", $edit["url"], 50, 128, t("The fully-qualified URL of the feed.")); - $form .= form_select(t("Update interval"), "refresh", $edit["refresh"], $period, t("The refresh interval indicating how often you want to update this feed. Requires crontab.")); + $form .= form_textfield(t('Title'), 'title', $edit['title'], 50, 64, t('The name of the feed; typically the name of the web site you syndicate content from.')); + $form .= form_textfield(t('URL'), 'url', $edit['url'], 50, 128, t('The fully-qualified URL of the feed.')); + $form .= form_select(t('Update interval'), 'refresh', $edit['refresh'], $period, t('The refresh interval indicating how often you want to update this feed. Requires crontab.')); $form .= form_select(t('Latest items block'), 'block', $edit['block'], $block_items, t('If enabled, a block containing the latest items from this feed will be availiable for placement on the <a href="%url">block configuration</a> page.', array('%url' => url('admin/system/block')))); - $categories = db_query("SELECT c.cid, c.title, f.fid FROM {aggregator_category} c LEFT JOIN {aggregator_category_feed} f ON c.cid = f.cid AND f.fid = %d ORDER BY title", $edit['fid']); + $categories = db_query('SELECT c.cid, c.title, f.fid FROM {aggregator_category} c LEFT JOIN {aggregator_category_feed} f ON c.cid = f.cid AND f.fid = %d ORDER BY title', $edit['fid']); while ($category = db_fetch_object($categories)) { $checkboxes .= form_checkbox($category->title, "category][$category->cid", 1, $category->fid ? 1 : 0); } @@ -511,11 +545,11 @@ function aggregator_form_feed($edit = array()) { $form .= form_group(t('Automatically file items'), $checkboxes, t('New items in this feed will be automatically filed in the the checked categories as they are recieved.')); } - $form .= form_submit(t("Submit")); + $form .= form_submit(t('Submit')); - if ($edit["fid"]) { - $form .= form_submit(t("Delete")); - $form .= form_hidden("fid", $edit["fid"]); + if ($edit['fid']) { + $form .= form_submit(t('Delete')); + $form .= form_hidden('fid', $edit['fid']); } return form($form); @@ -556,101 +590,144 @@ function aggregator_save_feed($edit) { } function aggregator_get_feed($fid) { - return db_fetch_array(db_query("SELECT * FROM {aggregator_feed} WHERE fid = %d", $fid)); + return db_fetch_array(db_query('SELECT * FROM {aggregator_feed} WHERE fid = %d', $fid)); } function aggregator_get_category($cid) { - return db_fetch_array(db_query("SELECT * FROM {aggregator_category} WHERE cid = %d", $cid)); + return db_fetch_array(db_query('SELECT * FROM {aggregator_category} WHERE cid = %d', $cid)); } function aggregator_view() { - $result = db_query("SELECT f.*, COUNT(i.iid) AS items FROM {aggregator_feed} f LEFT JOIN {aggregator_item} i ON f.fid = i.fid GROUP BY f.fid, f.title, f.url, f.refresh, f.checked, f.link, f.description, f.etag, f.modified, f.image ORDER BY f.title"); + $result = db_query('SELECT f.*, COUNT(i.iid) AS items FROM {aggregator_feed} f LEFT JOIN {aggregator_item} i ON f.fid = i.fid GROUP BY f.fid, f.title, f.url, f.refresh, f.checked, f.link, f.description, f.etag, f.modified, f.image ORDER BY f.title'); - $output .= "<h3>". t("Feed overview") ."</h3>"; + $output .= '<h3>'. t('Feed overview') .'</h3>'; - $header = array(t("title"), t("items"), t("last update"), t("next update"), array("data" => t("operations"), "colspan" => 3)); + $header = array(t('title'), t('items'), t('last update'), t('next update'), array('data' => t('operations'), 'colspan' => 3)); $rows = array(); while ($feed = db_fetch_object($result)) { - $rows[] = array(l($feed->title, "aggregator/sources/$feed->fid"), format_plural($feed->items, "1 item", "%count items"), ($feed->checked ? t("%time ago", array("%time" => format_interval(time() - $feed->checked))) : t("never")), ($feed->checked ? t("%time left", array("%time" => format_interval($feed->checked + $feed->refresh - time()))) : t("never")), l(t("edit feed"), "admin/syndication/news/edit/feed/$feed->fid"), l(t("remove items"), "admin/syndication/news/remove/$feed->fid"), l(t("update items"), "admin/syndication/news/update/$feed->fid")); + $rows[] = array(l($feed->title, "aggregator/sources/$feed->fid"), format_plural($feed->items, '1 item', '%count items'), ($feed->checked ? t('%time ago', array('%time' => format_interval(time() - $feed->checked))) : t('never')), ($feed->checked ? t('%time left', array('%time' => format_interval($feed->checked + $feed->refresh - time()))) : t('never')), l(t('edit feed'), "admin/syndication/news/edit/feed/$feed->fid"), l(t('remove items'), "admin/syndication/news/remove/$feed->fid"), l(t('update items'), "admin/syndication/news/update/$feed->fid")); } - $output .= theme("table", $header, $rows); + $output .= theme('table', $header, $rows); - $result = db_query("SELECT * FROM {aggregator_category} ORDER BY title"); + $result = db_query('SELECT * FROM {aggregator_category} ORDER BY title'); - $output .= "<h3>". t("Category overview") ."</h3>"; + $output .= '<h3>'. t('Category overview') .'</h3>'; - $header = array(t("title"), t("operations")); + $header = array(t('title'), t('operations')); $rows = array(); while ($category = db_fetch_object($result)) { - $rows[] = array(l($category->title, "aggregator/categories/$category->cid"), l(t("edit category"), "admin/syndication/news/edit/category/$category->cid")); + $rows[] = array(l($category->title, "aggregator/categories/$category->cid"), l(t('edit category'), "admin/syndication/news/edit/category/$category->cid")); } - $output .= theme("table", $header, $rows); + $output .= theme('table', $header, $rows); return $output; } -function aggregator_admin() { - $edit = $_POST["edit"]; - - switch ($_POST["op"] ? $_POST["op"] : arg(3)) { - case "add": - if (arg(4) == "category") { - $output = aggregator_form_category(); - } - else { - $output = aggregator_form_feed(); - } - break; - case "edit": - if (arg(4) == "category") { - $output = aggregator_form_category(aggregator_get_category(arg(5))); +/** + * Menu callback. Displays the category edit form, or saves changes and + * displays the overview page. + */ +function aggregator_admin_edit_category($category = 0) { + $edit = $_POST['edit']; + $op = $_POST['op']; + + switch ($op) { + case t('Delete'): + $edit['title'] = 0; + // Fall through: + case t('Submit'): + aggregator_save_category($edit); + $output = aggregator_view(); + default: + if ($category) { + $output = aggregator_form_category(aggregator_get_category($category)); } else { - $output = aggregator_form_feed(aggregator_get_feed(arg(5))); + $output = aggregator_form_category(); } - break; - case "remove": - aggregator_remove(aggregator_get_feed(arg(4))); - $output .= aggregator_view(); - break; - case "update": - aggregator_refresh(aggregator_get_feed(arg(4))); - $output .= aggregator_view(); - break; - case t("Delete"): - $edit["title"] = 0; - // fall through: - case t("Submit"): - if (arg(4) == "category") { - aggregator_save_category($edit); + } + print theme('page', $output); +} + +/** + * Menu callback. Displays the feed edit form, or saves changes and + * displays the overview page. + */ +function aggregator_admin_edit_feed($feed = 0) { + $edit = $_POST['edit']; + $op = $_POST['op']; + + switch ($op) { + case t('Delete'): + $edit['title'] = 0; + // Fall through: + case t('Submit'): + aggregator_save_feed($edit); + $output = aggregator_view(); + default: + if ($feed) { + $output = aggregator_form_feed(aggregator_get_feed($feed)); } else { - aggregator_save_feed($edit); + $output = aggregator_form_feed(); } - // fall through: - default: - $output .= aggregator_view(); } - print theme("page", $output); + print theme('page', $output); +} + +/** + * Menu callback. Removes all items from a feed, then displays the overview page. + */ +function aggregator_admin_remove_feed($feed) { + aggregator_remove(aggregator_get_feed($feed)); + print theme('page', aggregator_view()); +} + +/** + * Menu callback. Refreshes a feed, then displays the overview page. + */ +function aggregator_admin_refresh_feed($feed) { + aggregator_refresh(aggregator_get_feed($feed)); + print theme('page', aggregator_view()); +} + +/** + * Menu callback. Displays the aggregator administration page. + */ +function aggregator_admin_overview() { + print theme('page', aggregator_view()); } +/** + * Menu callback. Displays the most recent items gathered from any feed. + */ function aggregator_page_last() { - _aggregator_page_list(db_query_range("SELECT i.*, f.title AS ftitle, f.link AS flink FROM {aggregator_item} i INNER JOIN {aggregator_feed} f ON i.fid = f.fid ORDER BY i.timestamp DESC, i.iid DESC", 0, variable_get("aggregator_page_limit", 75)), arg(1)); + _aggregator_page_list(db_query_range('SELECT i.*, f.title AS ftitle, f.link AS flink FROM {aggregator_item} i INNER JOIN {aggregator_feed} f ON i.fid = f.fid ORDER BY i.timestamp DESC, i.iid DESC', 0, variable_get('aggregator_page_limit', 75)), arg(1)); } +/** + * Menu callback. Displays all the items captured from a particular feed. + */ function aggregator_page_source() { - $feed = db_fetch_object(db_query("SELECT * FROM {aggregator_feed} WHERE fid = %d", arg(2))); + $feed = db_fetch_object(db_query('SELECT * FROM {aggregator_feed} WHERE fid = %d', arg(2))); $info = theme('aggregator_feed', $feed); - _aggregator_page_list(db_query_range("SELECT * FROM {aggregator_item} WHERE fid = %d ORDER BY timestamp DESC, iid DESC", $feed->fid, 0, variable_get("aggregator_page_limit", 75)), arg(1), "<div class=\"feed\">$info</div>"); + _aggregator_page_list(db_query_range('SELECT * FROM {aggregator_item} WHERE fid = %d ORDER BY timestamp DESC, iid DESC', $feed->fid, 0, variable_get('aggregator_page_limit', 75)), arg(1), "<div class=\"feed\">$info</div>"); } +/** + * Menu callback. Displays all the items aggregated in a particular category. + */ function aggregator_page_category() { - $category = db_fetch_object(db_query("SELECT cid, title FROM {aggregator_category} WHERE cid = %d", arg(2))); + $category = db_fetch_object(db_query('SELECT cid, title FROM {aggregator_category} WHERE cid = %d', arg(2))); _aggregator_page_list(db_query_range('SELECT i.*, f.title AS ftitle, f.link AS flink FROM {aggregator_category_item} c LEFT JOIN {aggregator_item} i ON c.iid = i.iid LEFT JOIN {aggregator_feed} f ON i.fid = f.fid WHERE cid = %d ORDER BY timestamp DESC, iid DESC', $category->cid, 0, variable_get('aggregator_page_limit', 75)), arg(1)); } +/** + * Prints an aggregator page listing a number of feed items. Various + * menu callbacks use this function to print their feeds. + */ function _aggregator_page_list($result, $op, $header = '') { if (user_access('administer news feeds') && $op == 'categorize') { if ($edit = $_POST['edit']) { @@ -716,6 +793,9 @@ function _aggregator_page_list($result, $op, $header = '') { print theme('page', $output); } +/** + * Menu callback. Displays all the feeds used by the aggregator. + */ function aggregator_page_sources() { $result = db_query('SELECT f.fid, f.title, f.description, f.image, MAX(i.timestamp) AS last FROM {aggregator_feed} f LEFT JOIN {aggregator_item} i ON f.fid = i.fid GROUP BY fid'); $output = '<div id="aggregator">'; @@ -738,14 +818,17 @@ function aggregator_page_sources() { print theme('page', $output); } +/** + * Menu callback. Generates an OPML representation of all feeds. + */ function aggregator_page_opml() { - $result = db_query("SELECT * FROM {aggregator_feed} ORDER BY title"); + $result = db_query('SELECT * FROM {aggregator_feed} ORDER BY title'); $output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; $output .= "<opml version=\"1.1\">\n"; $output .= "<head>\n"; - $output .= "<title>". drupal_specialchars(variable_get('site_name', 'Drupal')) ."</title>\n"; - $output .= "<dateModified>". gmdate('r') ."</dateModified>\n"; + $output .= '<title>'. drupal_specialchars(variable_get('site_name', 'Drupal')) ."</title>\n"; + $output .= '<dateModified>'. gmdate('r') ."</dateModified>\n"; $output .= "</head>\n"; $output .= "<body>\n"; @@ -756,10 +839,13 @@ function aggregator_page_opml() { $output .= "</body>\n"; $output .= "</opml>\n"; - drupal_set_header("Content-Type: text/xml; charset=utf-8"); + drupal_set_header('Content-Type: text/xml; charset=utf-8'); print $output; } +/** + * Menu callback. Displays all the categories used by the aggregator. + */ function aggregator_page_categories() { $result = db_query('SELECT c.cid, c.title, c.description FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid LEFT JOIN {aggregator_item} i ON ci.iid = i.iid GROUP BY cid'); $output = "<div id=\"aggregator\">\n"; @@ -770,13 +856,13 @@ function aggregator_page_categories() { $list = array(); $items = db_query_range('SELECT i.title, i.timestamp, i.link, f.title as feed_title, f.link as feed_link FROM {aggregator_category_item} ci LEFT JOIN {aggregator_item} i ON i.iid = ci.iid LEFT JOIN {aggregator_feed} f ON i.fid = f.fid WHERE ci.cid = %d ORDER BY i.timestamp DESC', $category->cid, 0, variable_get('aggregator_summary_items', 3)); while ($item = db_fetch_object($items)) { - $list[] = "<a href=\"". check_url($item->link) ."\">$item->title</a> <span class=\"age\">". t('%age ago', array('%age' => format_interval(time() - $item->timestamp))) ."</span>, <span class=\"source\"><a href=\"$item->feed_link\">$item->feed_title</a></span>\n"; + $list[] = '<a href="'. check_url($item->link) ."\">$item->title</a> <span class=\"age\">". t('%age ago', array('%age' => format_interval(time() - $item->timestamp))) ."</span>, <span class=\"source\"><a href=\"$item->feed_link\">$item->feed_title</a></span>\n"; } $output .= theme('item_list', $list); } $output .= '<div class="more-link">'. l(t('more'), 'aggregator/categories/'. $category->cid) .'</div>'; } - $output .= "</div>"; + $output .= '</div>'; print theme('page', $output); } @@ -788,18 +874,18 @@ function aggregator_page_categories() { function theme_aggregator_feed($feed) { - $output = ""; + $output = ''; if ($feed->image) { $output .= $feed->image; } $output .= $feed->description; - $output .= "<h3>". t("URL") ."</h3>\n"; + $output .= '<h3>'. t('URL') ."</h3>\n"; $output .= theme('xml_icon', $feed->url); $output .= "<a href=\"$feed->link\">$feed->link</a>\n"; - $output .= "<h3>". t('Last update') ."</h3>\n"; - $updated = t("%time ago", array("%time" => format_interval(time() - $feed->checked))); + $output .= '<h3>'. t('Last update') ."</h3>\n"; + $updated = t('%time ago', array('%time' => format_interval(time() - $feed->checked))); if (user_access('administer news feeds')) { $output .= l($updated, 'admin/syndication/news'); @@ -814,8 +900,8 @@ function theme_aggregator_feed($feed) { function theme_aggregator_block_item($item, $feed = 0) { global $user; - if ($user->uid && module_exist("blog") && user_access("maintain personal blog")) { - $output .= "<div class=\"icon\">". l("<img src=\"". theme("image", "blog.gif") ."\" alt=\"". t("blog it") ."\" title=\"". t("blog it") ."\" />", "node/add/blog", array("title" => t("Comment on this news item in your personal blog."), "class" => "blog-it"), "iid=$item->iid") ."</div>"; + if ($user->uid && module_exist('blog') && user_access('maintain personal blog')) { + $output .= '<div class="icon">'. l('<img src="'. theme('image', 'blog.gif') .'" alt="'. t('blog it') .'" title="'. t('blog it') .'" />', 'node/add/blog', array('title' => t('Comment on this news item in your personal blog.'), 'class' => 'blog-it'), "iid=$item->iid") .'</div>'; } // external link @@ -825,24 +911,23 @@ function theme_aggregator_block_item($item, $feed = 0) { } function theme_aggregator_page_item($item) { - static $last; - $date = date("Ymd", $item->timestamp); + $date = date('Ymd', $item->timestamp); if ($date != $last) { $last = $date; - $output .= "<h3>". date("F j, Y", $item->timestamp) ."</h3>\n"; + $output .= '<h3>'. date('F j, Y', $item->timestamp) ."</h3>\n"; } $output .= "<div class=\"news-item\">\n"; - $output .= " <div class=\"date\">". date("H:i", $item->timestamp) ."</div>\n"; + $output .= ' <div class="date">'. date('H:i', $item->timestamp) ."</div>\n"; $output .= " <div class=\"body\">\n"; $output .= " <div class=\"title\"><a href=\"$item->link\">$item->title</a></div>\n"; if ($item->description) { $output .= " <div class=\"description\">$item->description</div>\n"; } if ($item->ftitle && $item->fid) { - $output .= " <div class=\"source\">". t('Source') .": ". l($item->ftitle, "aggregator/sources/$item->fid") ."</div>\n"; + $output .= ' <div class="source">'. t('Source') .': '. l($item->ftitle, "aggregator/sources/$item->fid") ."</div>\n"; } $result = db_query('SELECT c.title, c.cid FROM {aggregator_category_item} ci LEFT JOIN {aggregator_category} c ON ci.cid = c.cid WHERE ci.iid = %d ORDER BY c.title', $item->iid); @@ -851,7 +936,7 @@ function theme_aggregator_page_item($item) { $categories[] = l($category->title, 'aggregator/categories/'. $category->cid); } if ($categories) { - $output .= " <div class=\"categories\">". t('Categories') .": ". implode(', ', $categories) ."</div>\n"; + $output .= ' <div class="categories">'. t('Categories') .': '. implode(', ', $categories) ."</div>\n"; } $output .= " </div>\n"; diff --git a/modules/aggregator/aggregator.module b/modules/aggregator/aggregator.module index 2ffd7664b..6b08be814 100644 --- a/modules/aggregator/aggregator.module +++ b/modules/aggregator/aggregator.module @@ -1,6 +1,9 @@ <?php /* $Id$ */ +/** + * Implementation of hook_help(). + */ function aggregator_help($section) { switch ($section) { case 'admin/help#aggregator': @@ -64,11 +67,18 @@ function aggregator_help($section) { } } +/** + * Menu callback. Displays the aggregator-specific information from admin/help. + */ function aggregator_help_page() { print theme('page', aggregator_help('admin/help#aggregator')); } +/** + * Implementation of hook_settings(). + */ function aggregator_settings() { + $output = ''; $number = drupal_map_assoc(array(5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100)); $items = array(0 => t('none'), 3 => t('3 items'), 5 => t('5 items'), 10 => t('10 items'), 15 => t('15 items'), 20 => t('20 items'), 25 => t('25 items')); @@ -79,6 +89,9 @@ function aggregator_settings() { return $output; } +/** + * Implementation of hook_perm(). + */ function aggregator_perm() { return array('administer news feeds', 'access news feeds'); } @@ -94,9 +107,11 @@ function aggregator_link($type) { if ($type == 'system') { $access = user_access('administer news feeds'); menu('admin/syndication', t('syndication'), $access ? 'aggregator_help_page' : MENU_DENIED, 5); - menu('admin/syndication/news', t('RSS/RDF'), $access ? 'aggregator_admin' : MENU_DENIED); - menu('admin/syndication/news/add/feed', t('new feed'), $access ? 'aggregator_admin' : MENU_DENIED, 2); - menu('admin/syndication/news/add/category', t('new category'), $access ? 'aggregator_admin' : MENU_DENIED, 3); + menu('admin/syndication/news', t('RSS/RDF'), $access ? 'aggregator_admin_overview' : MENU_DENIED); + menu('admin/syndication/news/add/feed', t('new feed'), $access ? 'aggregator_admin_edit_feed' : MENU_DENIED, 2); + menu('admin/syndication/news/add/category', t('new category'), $access ? 'aggregator_admin_edit_category' : MENU_DENIED, 3); + menu('admin/syndication/news/remove', t('remove items'), $access ? 'aggregator_admin_remove_feed' : MENU_DENIED, 0, MENU_HIDE, MENU_LOCKED); + menu('admin/syndication/news/update', t('update items'), $access ? 'aggregator_admin_refresh_feed' : MENU_DENIED, 0, MENU_HIDE, MENU_LOCKED); menu('admin/syndication/news/help', t('help'), $access ? 'aggregator_help_page' : MENU_DENIED, 9); $access = user_access('access news feeds'); @@ -106,6 +121,8 @@ function aggregator_link($type) { // To reduce the number of SQL queries, we don't query the database when // not on an aggregator page. + // If caching of the menu is implemented, this check should be removed + // so that DHTML menu presentation can be used correctly. if (arg(0) == 'aggregator') { // Sources: $result = db_query('SELECT title, fid FROM {aggregator_feed} ORDER BY title'); @@ -124,13 +141,23 @@ function aggregator_link($type) { } } +/** + * Implementation of hook_cron(). + * + * Checks news feeds for updates once their refresh interval has elapsed. + */ function aggregator_cron() { - $result = db_query("SELECT * FROM {aggregator_feed} WHERE checked + refresh < %d", time()); + $result = db_query('SELECT * FROM {aggregator_feed} WHERE checked + refresh < %d', time()); while ($feed = db_fetch_array($result)) { aggregator_refresh($feed); } } +/** + * Implementation of hook_block(). + * + * Generates blocks for the latest news items in each category and feed. + */ function aggregator_block($op, $delta) { if (user_access('access news feeds')) { if ($op == 'list') { @@ -161,9 +188,9 @@ function aggregator_block($op, $delta) { } $items = array(); while ($item = db_fetch_object($result)) { - $items[] = theme("aggregator_block_item", $item); + $items[] = theme('aggregator_block_item', $item); } - $block['content'] = theme("item_list", $items) . $block['content']; + $block['content'] = theme('item_list', $items) . $block['content']; } return $block; } @@ -182,16 +209,18 @@ function aggregator_remove($feed) { drupal_set_message(t('removed news items from \'%site\'.', array('%site' => $feed['title']))); } -// Call-back function used by XML parser: +/** + * Call-back function used by the XML parser. + */ function aggregator_element_start($parser, $name, $attributes) { global $item, $element, $tag; switch ($name) { - case "IMAGE": - case "TEXTINPUT": + case 'IMAGE': + case 'TEXTINPUT': $element = $name; break; - case "ITEM": + case 'ITEM': $element = $name; $item += 1; } @@ -199,40 +228,45 @@ function aggregator_element_start($parser, $name, $attributes) { $tag = $name; } -// Call-back function used by XML parser: +/** + * Call-back function used by the XML parser. + */ function aggregator_element_end($parser, $name) { global $element; switch ($name) { - case "IMAGE": - case "TEXTINPUT": - case "ITEM": - $element = ""; + case 'IMAGE': + case 'TEXTINPUT': + case 'ITEM': + $element = ''; } } -// Call-back function used by XML parser: +/** + * Call-back function used by the XML parser. + */ function aggregator_element_data($parser, $data) { global $channel, $element, $items, $item, $image, $tag; switch ($element) { - case "ITEM": + case 'ITEM': $items[$item][$tag] .= $data; break; - case "IMAGE": + case 'IMAGE': $image[$tag] .= $data; break; - case "TEXTINPUT": - /* - ** The sub-element is not supported but we have recognize - ** it or its content will end up in the items-array. - */ + case 'TEXTINPUT': + // The sub-element is not supported. However, we must recognize + // it or its contents will end up in the item array. break; default: $channel[$tag] .= $data; } } +/** + * Checks a news feed for new items. + */ function aggregator_refresh($feed) { global $channel, $image; @@ -242,7 +276,7 @@ function aggregator_refresh($feed) { $headers['If-None-Match'] = $feed['etag']; } if ($feed['modified']) { - $headers['If-Modified-Since'] = gmdate("D, d M Y H:i:s", $feed['modified']) ." GMT"; + $headers['If-Modified-Since'] = gmdate('D, d M Y H:i:s', $feed['modified']) .' GMT'; } // Request feed. @@ -251,18 +285,18 @@ function aggregator_refresh($feed) { // Process HTTP reponse code. switch ($result->code) { case 304: - db_query("UPDATE {aggregator_feed} SET checked = %d WHERE fid = %d", time(), $feed['fid']); - drupal_set_message(t("no new syndicated content from '%site'.", array('%site' => $feed['title']))); + db_query('UPDATE {aggregator_feed} SET checked = %d WHERE fid = %d', time(), $feed['fid']); + drupal_set_message(t('no new syndicated content from "%site".', array('%site' => $feed['title']))); break; case 301: $feed['url'] = $result->redirect_url; - watchdog('special', "aggregator: updated URL for feed '$feed[title]' to $feed[url]"); + watchdog('special', "aggregator: updated URL for feed \"$feed[title]\" to $feed[url]"); case 200: case 302: case 307: // Filter the input data: if (!valid_input_data($result->data)) { - drupal_set_message(t("failed to parse RSS feed '%site': suspicious input data.", array("%site" => $feed["title"])), 'error'); + drupal_set_message(t('failed to parse RSS feed "%site": suspicious input data.', array('%site' => $feed['title'])), 'error'); } else if (aggregator_parse_feed($result->data, $feed)) { @@ -279,7 +313,7 @@ function aggregator_refresh($feed) { } if ($image['LINK'] && $image['URL'] && $image['TITLE']) { - $image = "<a href=\"". $image['LINK'] ."\"><img src=\"". $image['URL'] ."\" alt=\"". $image['TITLE'] ."\" /></a>"; + $image = '<a href="'. $image['LINK'] .'"><img src="'. $image['URL'] .'" alt="'. $image['TITLE'] .'" /></a>'; } else { $image = NULL; @@ -297,13 +331,13 @@ function aggregator_refresh($feed) { cache_clear_all(); - $message = t("syndicated content from '%site'.", array("%site" => $feed["title"])); + $message = t('syndicated content from "%site".', array('%site' => $feed['title'])); watchdog('regular', "aggregator: $message"); drupal_set_message($message); } break; default: - $message = t("failed to parse RSS feed '%site': %error.", array('%site' => $feed['title'], '%error' => $result->code .' '. $result->error)); + $message = t('failed to parse RSS feed "%site": %error.', array('%site' => $feed['title'], '%error' => $result->code .' '. $result->error)); watchdog('error', "aggregator: $message"); drupal_set_message($message); } @@ -313,18 +347,18 @@ function aggregator_parse_feed(&$data, $feed) { global $items, $image, $channel; // Unset the global variables before we use them: - unset($GLOBALS["element"], $GLOBALS["item"], $GLOBALS["tag"]); + unset($GLOBALS['element'], $GLOBALS['item'], $GLOBALS['tag']); $items = array(); $image = array(); $channel = array(); // parse the data: $xml_parser = drupal_xml_parser_create($data); - xml_set_element_handler($xml_parser, "aggregator_element_start", "aggregator_element_end"); - xml_set_character_data_handler($xml_parser, "aggregator_element_data"); + xml_set_element_handler($xml_parser, 'aggregator_element_start', 'aggregator_element_end'); + xml_set_character_data_handler($xml_parser, 'aggregator_element_data'); if (!xml_parse($xml_parser, $data, 1)) { - $message = t("failed to parse RSS feed '%site': %error at line %line.", array("%site" => $feed["title"], "%error" => xml_error_string(xml_get_error_code($xml_parser)), "%line" => xml_get_current_line_number($xml_parser))); + $message = t('failed to parse RSS feed "%site": %error at line %line.', array('%site' => $feed['title'], '%error' => xml_error_string(xml_get_error_code($xml_parser)), '%line' => xml_get_current_line_number($xml_parser))); watchdog('error', "aggregator: $message"); drupal_set_message($message, 'error'); return 0; @@ -333,7 +367,7 @@ function aggregator_parse_feed(&$data, $feed) { // initialize the translation table: $tt = array_flip(get_html_translation_table(HTML_SPECIALCHARS)); - $tt["'"] = "'"; + $tt['''] = "'"; /* ** We reverse the array such that we store the first item last, @@ -357,25 +391,25 @@ function aggregator_parse_feed(&$data, $feed) { ** boundary but not splitting potential entities. */ - if ($item["TITLE"]) { - $title = $item["TITLE"]; + if ($item['TITLE']) { + $title = $item['TITLE']; } else { - $title = preg_replace('/^(.*)[^\w;&].*?$/', "\\1", truncate_utf8($item["DESCRIPTION"], 40)); + $title = preg_replace('/^(.*)[^\w;&].*?$/', "\\1", truncate_utf8($item['DESCRIPTION'], 40)); } /* ** Resolve the items link. */ - if ($item["LINK"]) { - $link = $item["LINK"]; + if ($item['LINK']) { + $link = $item['LINK']; } - elseif ($item["GUID"] && (strncmp($item["GUID"], "http://", 7) == 0)) { - $link = $item["GUID"]; + elseif ($item['GUID'] && (strncmp($item['GUID'], 'http://', 7) == 0)) { + $link = $item['GUID']; } else { - $link = $feed["link"]; + $link = $feed['link']; } /* @@ -398,7 +432,7 @@ function aggregator_parse_feed(&$data, $feed) { ** be parsed directly using PHP's strtotime(). It is not the only ** valid format so this might fail nonetheless ... */ - list($year, $month, $day, $hour, $minute, $second) = sscanf($date, "%4d-%2d-%2dT%2d:%2d:%2d"); + list($year, $month, $day, $hour, $minute, $second) = sscanf($date, '%4d-%2d-%2dT%2d:%2d:%2d'); $timestamp = strtotime("$year-$month-$day $hour:$minute:$second"); } @@ -412,14 +446,14 @@ function aggregator_parse_feed(&$data, $feed) { ** pass along it's ID such that we can update it if needed. */ - if ($link && $link != $feed["link"] && $link != $feed["url"]) { - $entry = db_fetch_object(db_query("SELECT iid FROM {aggregator_item} WHERE fid = %d AND link = '%s'", $feed["fid"], $link)); + if ($link && $link != $feed['link'] && $link != $feed['url']) { + $entry = db_fetch_object(db_query("SELECT iid FROM {aggregator_item} WHERE fid = %d AND link = '%s'", $feed['fid'], $link)); } else { - $entry = db_fetch_object(db_query("SELECT iid FROM {aggregator_item} WHERE fid = %d AND title = '%s'", $feed["fid"], $title)); + $entry = db_fetch_object(db_query("SELECT iid FROM {aggregator_item} WHERE fid = %d AND title = '%s'", $feed['fid'], $title)); } - aggregator_save_item(array('iid' => $entry->iid, 'fid' => $feed["fid"], 'timestamp' => $timestamp, 'title' => $title, 'link' => $link, 'author' => $item["AUTHOR"], 'description' => $item["DESCRIPTION"])); + aggregator_save_item(array('iid' => $entry->iid, 'fid' => $feed['fid'], 'timestamp' => $timestamp, 'title' => $title, 'link' => $link, 'author' => $item['AUTHOR'], 'description' => $item['DESCRIPTION'])); } /* @@ -428,14 +462,14 @@ function aggregator_parse_feed(&$data, $feed) { unset($items); - $result = db_query("SELECT iid FROM {aggregator_item} WHERE fid = %d ORDER BY timestamp", $feed["fid"]); + $result = db_query('SELECT iid FROM {aggregator_item} WHERE fid = %d ORDER BY timestamp', $feed['fid']); while ($item = db_fetch_object($result)) { $items[] = "iid = '$item->iid'"; } if (sizeof($items) > 50) { - db_query("DELETE FROM {aggregator_item} WHERE ". implode(" OR ", array_slice($items, 0, - 50))); + db_query('DELETE FROM {aggregator_item} WHERE '. implode(' OR ', array_slice($items, 0, - 50))); db_query('DELETE FROM {aggregator_category_item} WHERE '. implode(' OR ', array_slice($items, 0, -50))); } @@ -443,16 +477,16 @@ function aggregator_parse_feed(&$data, $feed) { } function aggregator_save_item($edit) { - if ($edit["iid"] && $edit["title"]) { - db_query("UPDATE {aggregator_item} SET title = '%s', link = '%s', author = '%s', description = '%s' WHERE iid = %d", $edit["title"], $edit["link"], $edit["author"], $edit["description"], $edit["iid"]); + if ($edit['iid'] && $edit['title']) { + db_query("UPDATE {aggregator_item} SET title = '%s', link = '%s', author = '%s', description = '%s' WHERE iid = %d", $edit['title'], $edit['link'], $edit['author'], $edit['description'], $edit['iid']); } - else if ($edit["iid"]) { - db_query("DELETE FROM {aggregator_item} WHERE iid = %d", $edit["iid"]); - db_query("DELETE FROM {aggregator_category_item} WHERE iid = %d", $edit["iid"]); + else if ($edit['iid']) { + db_query('DELETE FROM {aggregator_item} WHERE iid = %d', $edit['iid']); + db_query('DELETE FROM {aggregator_category_item} WHERE iid = %d', $edit['iid']); } - else if ($edit["title"] && $edit["link"]) { - $next_id = db_next_id("{aggregator_item}_iid"); - db_query("INSERT INTO {aggregator_item} (iid, fid, title, link, author, description, timestamp) VALUES (%d, %d, '%s', '%s', '%s', '%s', %d)", $next_id, $edit["fid"], $edit["title"], $edit["link"], $edit["author"], $edit["description"], $edit["timestamp"]); + else if ($edit['title'] && $edit['link']) { + $next_id = db_next_id('{aggregator_item}_iid'); + db_query("INSERT INTO {aggregator_item} (iid, fid, title, link, author, description, timestamp) VALUES (%d, %d, '%s', '%s', '%s', '%s', %d)", $next_id, $edit['fid'], $edit['title'], $edit['link'], $edit['author'], $edit['description'], $edit['timestamp']); // file the items in the categories indicated by the feed $categories = db_query('SELECT cid FROM {aggregator_category_feed} WHERE fid = %d', $edit['fid']); while ($category = db_fetch_object($categories)) { @@ -492,18 +526,18 @@ function aggregator_save_category($edit) { } function aggregator_form_feed($edit = array()) { - $period = drupal_map_assoc(array(900, 1800, 3600, 7200, 10800, 21600, 32400, 43200, 64800, 86400, 172800, 259200, 604800, 1209600, 2419200), "format_interval"); + $period = drupal_map_assoc(array(900, 1800, 3600, 7200, 10800, 21600, 32400, 43200, 64800, 86400, 172800, 259200, 604800, 1209600, 2419200), 'format_interval'); $block_items = array(0 => t('no block'), 3 => t('3 items'), 5 => t('5 items'), 10 => t('10 items'), 15 => t('15 items'), 20 => t('20 items'), 25 => t('25 items')); - if ($edit["refresh"] == "") { - $edit["refresh"] = 3600; + if ($edit['refresh'] == '') { + $edit['refresh'] = 3600; } - $form .= form_textfield(t("Title"), "title", $edit["title"], 50, 64, t("The name of the feed; typically the name of the web site you syndicate content from.")); - $form .= form_textfield(t("URL"), "url", $edit["url"], 50, 128, t("The fully-qualified URL of the feed.")); - $form .= form_select(t("Update interval"), "refresh", $edit["refresh"], $period, t("The refresh interval indicating how often you want to update this feed. Requires crontab.")); + $form .= form_textfield(t('Title'), 'title', $edit['title'], 50, 64, t('The name of the feed; typically the name of the web site you syndicate content from.')); + $form .= form_textfield(t('URL'), 'url', $edit['url'], 50, 128, t('The fully-qualified URL of the feed.')); + $form .= form_select(t('Update interval'), 'refresh', $edit['refresh'], $period, t('The refresh interval indicating how often you want to update this feed. Requires crontab.')); $form .= form_select(t('Latest items block'), 'block', $edit['block'], $block_items, t('If enabled, a block containing the latest items from this feed will be availiable for placement on the <a href="%url">block configuration</a> page.', array('%url' => url('admin/system/block')))); - $categories = db_query("SELECT c.cid, c.title, f.fid FROM {aggregator_category} c LEFT JOIN {aggregator_category_feed} f ON c.cid = f.cid AND f.fid = %d ORDER BY title", $edit['fid']); + $categories = db_query('SELECT c.cid, c.title, f.fid FROM {aggregator_category} c LEFT JOIN {aggregator_category_feed} f ON c.cid = f.cid AND f.fid = %d ORDER BY title', $edit['fid']); while ($category = db_fetch_object($categories)) { $checkboxes .= form_checkbox($category->title, "category][$category->cid", 1, $category->fid ? 1 : 0); } @@ -511,11 +545,11 @@ function aggregator_form_feed($edit = array()) { $form .= form_group(t('Automatically file items'), $checkboxes, t('New items in this feed will be automatically filed in the the checked categories as they are recieved.')); } - $form .= form_submit(t("Submit")); + $form .= form_submit(t('Submit')); - if ($edit["fid"]) { - $form .= form_submit(t("Delete")); - $form .= form_hidden("fid", $edit["fid"]); + if ($edit['fid']) { + $form .= form_submit(t('Delete')); + $form .= form_hidden('fid', $edit['fid']); } return form($form); @@ -556,101 +590,144 @@ function aggregator_save_feed($edit) { } function aggregator_get_feed($fid) { - return db_fetch_array(db_query("SELECT * FROM {aggregator_feed} WHERE fid = %d", $fid)); + return db_fetch_array(db_query('SELECT * FROM {aggregator_feed} WHERE fid = %d', $fid)); } function aggregator_get_category($cid) { - return db_fetch_array(db_query("SELECT * FROM {aggregator_category} WHERE cid = %d", $cid)); + return db_fetch_array(db_query('SELECT * FROM {aggregator_category} WHERE cid = %d', $cid)); } function aggregator_view() { - $result = db_query("SELECT f.*, COUNT(i.iid) AS items FROM {aggregator_feed} f LEFT JOIN {aggregator_item} i ON f.fid = i.fid GROUP BY f.fid, f.title, f.url, f.refresh, f.checked, f.link, f.description, f.etag, f.modified, f.image ORDER BY f.title"); + $result = db_query('SELECT f.*, COUNT(i.iid) AS items FROM {aggregator_feed} f LEFT JOIN {aggregator_item} i ON f.fid = i.fid GROUP BY f.fid, f.title, f.url, f.refresh, f.checked, f.link, f.description, f.etag, f.modified, f.image ORDER BY f.title'); - $output .= "<h3>". t("Feed overview") ."</h3>"; + $output .= '<h3>'. t('Feed overview') .'</h3>'; - $header = array(t("title"), t("items"), t("last update"), t("next update"), array("data" => t("operations"), "colspan" => 3)); + $header = array(t('title'), t('items'), t('last update'), t('next update'), array('data' => t('operations'), 'colspan' => 3)); $rows = array(); while ($feed = db_fetch_object($result)) { - $rows[] = array(l($feed->title, "aggregator/sources/$feed->fid"), format_plural($feed->items, "1 item", "%count items"), ($feed->checked ? t("%time ago", array("%time" => format_interval(time() - $feed->checked))) : t("never")), ($feed->checked ? t("%time left", array("%time" => format_interval($feed->checked + $feed->refresh - time()))) : t("never")), l(t("edit feed"), "admin/syndication/news/edit/feed/$feed->fid"), l(t("remove items"), "admin/syndication/news/remove/$feed->fid"), l(t("update items"), "admin/syndication/news/update/$feed->fid")); + $rows[] = array(l($feed->title, "aggregator/sources/$feed->fid"), format_plural($feed->items, '1 item', '%count items'), ($feed->checked ? t('%time ago', array('%time' => format_interval(time() - $feed->checked))) : t('never')), ($feed->checked ? t('%time left', array('%time' => format_interval($feed->checked + $feed->refresh - time()))) : t('never')), l(t('edit feed'), "admin/syndication/news/edit/feed/$feed->fid"), l(t('remove items'), "admin/syndication/news/remove/$feed->fid"), l(t('update items'), "admin/syndication/news/update/$feed->fid")); } - $output .= theme("table", $header, $rows); + $output .= theme('table', $header, $rows); - $result = db_query("SELECT * FROM {aggregator_category} ORDER BY title"); + $result = db_query('SELECT * FROM {aggregator_category} ORDER BY title'); - $output .= "<h3>". t("Category overview") ."</h3>"; + $output .= '<h3>'. t('Category overview') .'</h3>'; - $header = array(t("title"), t("operations")); + $header = array(t('title'), t('operations')); $rows = array(); while ($category = db_fetch_object($result)) { - $rows[] = array(l($category->title, "aggregator/categories/$category->cid"), l(t("edit category"), "admin/syndication/news/edit/category/$category->cid")); + $rows[] = array(l($category->title, "aggregator/categories/$category->cid"), l(t('edit category'), "admin/syndication/news/edit/category/$category->cid")); } - $output .= theme("table", $header, $rows); + $output .= theme('table', $header, $rows); return $output; } -function aggregator_admin() { - $edit = $_POST["edit"]; - - switch ($_POST["op"] ? $_POST["op"] : arg(3)) { - case "add": - if (arg(4) == "category") { - $output = aggregator_form_category(); - } - else { - $output = aggregator_form_feed(); - } - break; - case "edit": - if (arg(4) == "category") { - $output = aggregator_form_category(aggregator_get_category(arg(5))); +/** + * Menu callback. Displays the category edit form, or saves changes and + * displays the overview page. + */ +function aggregator_admin_edit_category($category = 0) { + $edit = $_POST['edit']; + $op = $_POST['op']; + + switch ($op) { + case t('Delete'): + $edit['title'] = 0; + // Fall through: + case t('Submit'): + aggregator_save_category($edit); + $output = aggregator_view(); + default: + if ($category) { + $output = aggregator_form_category(aggregator_get_category($category)); } else { - $output = aggregator_form_feed(aggregator_get_feed(arg(5))); + $output = aggregator_form_category(); } - break; - case "remove": - aggregator_remove(aggregator_get_feed(arg(4))); - $output .= aggregator_view(); - break; - case "update": - aggregator_refresh(aggregator_get_feed(arg(4))); - $output .= aggregator_view(); - break; - case t("Delete"): - $edit["title"] = 0; - // fall through: - case t("Submit"): - if (arg(4) == "category") { - aggregator_save_category($edit); + } + print theme('page', $output); +} + +/** + * Menu callback. Displays the feed edit form, or saves changes and + * displays the overview page. + */ +function aggregator_admin_edit_feed($feed = 0) { + $edit = $_POST['edit']; + $op = $_POST['op']; + + switch ($op) { + case t('Delete'): + $edit['title'] = 0; + // Fall through: + case t('Submit'): + aggregator_save_feed($edit); + $output = aggregator_view(); + default: + if ($feed) { + $output = aggregator_form_feed(aggregator_get_feed($feed)); } else { - aggregator_save_feed($edit); + $output = aggregator_form_feed(); } - // fall through: - default: - $output .= aggregator_view(); } - print theme("page", $output); + print theme('page', $output); +} + +/** + * Menu callback. Removes all items from a feed, then displays the overview page. + */ +function aggregator_admin_remove_feed($feed) { + aggregator_remove(aggregator_get_feed($feed)); + print theme('page', aggregator_view()); +} + +/** + * Menu callback. Refreshes a feed, then displays the overview page. + */ +function aggregator_admin_refresh_feed($feed) { + aggregator_refresh(aggregator_get_feed($feed)); + print theme('page', aggregator_view()); +} + +/** + * Menu callback. Displays the aggregator administration page. + */ +function aggregator_admin_overview() { + print theme('page', aggregator_view()); } +/** + * Menu callback. Displays the most recent items gathered from any feed. + */ function aggregator_page_last() { - _aggregator_page_list(db_query_range("SELECT i.*, f.title AS ftitle, f.link AS flink FROM {aggregator_item} i INNER JOIN {aggregator_feed} f ON i.fid = f.fid ORDER BY i.timestamp DESC, i.iid DESC", 0, variable_get("aggregator_page_limit", 75)), arg(1)); + _aggregator_page_list(db_query_range('SELECT i.*, f.title AS ftitle, f.link AS flink FROM {aggregator_item} i INNER JOIN {aggregator_feed} f ON i.fid = f.fid ORDER BY i.timestamp DESC, i.iid DESC', 0, variable_get('aggregator_page_limit', 75)), arg(1)); } +/** + * Menu callback. Displays all the items captured from a particular feed. + */ function aggregator_page_source() { - $feed = db_fetch_object(db_query("SELECT * FROM {aggregator_feed} WHERE fid = %d", arg(2))); + $feed = db_fetch_object(db_query('SELECT * FROM {aggregator_feed} WHERE fid = %d', arg(2))); $info = theme('aggregator_feed', $feed); - _aggregator_page_list(db_query_range("SELECT * FROM {aggregator_item} WHERE fid = %d ORDER BY timestamp DESC, iid DESC", $feed->fid, 0, variable_get("aggregator_page_limit", 75)), arg(1), "<div class=\"feed\">$info</div>"); + _aggregator_page_list(db_query_range('SELECT * FROM {aggregator_item} WHERE fid = %d ORDER BY timestamp DESC, iid DESC', $feed->fid, 0, variable_get('aggregator_page_limit', 75)), arg(1), "<div class=\"feed\">$info</div>"); } +/** + * Menu callback. Displays all the items aggregated in a particular category. + */ function aggregator_page_category() { - $category = db_fetch_object(db_query("SELECT cid, title FROM {aggregator_category} WHERE cid = %d", arg(2))); + $category = db_fetch_object(db_query('SELECT cid, title FROM {aggregator_category} WHERE cid = %d', arg(2))); _aggregator_page_list(db_query_range('SELECT i.*, f.title AS ftitle, f.link AS flink FROM {aggregator_category_item} c LEFT JOIN {aggregator_item} i ON c.iid = i.iid LEFT JOIN {aggregator_feed} f ON i.fid = f.fid WHERE cid = %d ORDER BY timestamp DESC, iid DESC', $category->cid, 0, variable_get('aggregator_page_limit', 75)), arg(1)); } +/** + * Prints an aggregator page listing a number of feed items. Various + * menu callbacks use this function to print their feeds. + */ function _aggregator_page_list($result, $op, $header = '') { if (user_access('administer news feeds') && $op == 'categorize') { if ($edit = $_POST['edit']) { @@ -716,6 +793,9 @@ function _aggregator_page_list($result, $op, $header = '') { print theme('page', $output); } +/** + * Menu callback. Displays all the feeds used by the aggregator. + */ function aggregator_page_sources() { $result = db_query('SELECT f.fid, f.title, f.description, f.image, MAX(i.timestamp) AS last FROM {aggregator_feed} f LEFT JOIN {aggregator_item} i ON f.fid = i.fid GROUP BY fid'); $output = '<div id="aggregator">'; @@ -738,14 +818,17 @@ function aggregator_page_sources() { print theme('page', $output); } +/** + * Menu callback. Generates an OPML representation of all feeds. + */ function aggregator_page_opml() { - $result = db_query("SELECT * FROM {aggregator_feed} ORDER BY title"); + $result = db_query('SELECT * FROM {aggregator_feed} ORDER BY title'); $output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; $output .= "<opml version=\"1.1\">\n"; $output .= "<head>\n"; - $output .= "<title>". drupal_specialchars(variable_get('site_name', 'Drupal')) ."</title>\n"; - $output .= "<dateModified>". gmdate('r') ."</dateModified>\n"; + $output .= '<title>'. drupal_specialchars(variable_get('site_name', 'Drupal')) ."</title>\n"; + $output .= '<dateModified>'. gmdate('r') ."</dateModified>\n"; $output .= "</head>\n"; $output .= "<body>\n"; @@ -756,10 +839,13 @@ function aggregator_page_opml() { $output .= "</body>\n"; $output .= "</opml>\n"; - drupal_set_header("Content-Type: text/xml; charset=utf-8"); + drupal_set_header('Content-Type: text/xml; charset=utf-8'); print $output; } +/** + * Menu callback. Displays all the categories used by the aggregator. + */ function aggregator_page_categories() { $result = db_query('SELECT c.cid, c.title, c.description FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid LEFT JOIN {aggregator_item} i ON ci.iid = i.iid GROUP BY cid'); $output = "<div id=\"aggregator\">\n"; @@ -770,13 +856,13 @@ function aggregator_page_categories() { $list = array(); $items = db_query_range('SELECT i.title, i.timestamp, i.link, f.title as feed_title, f.link as feed_link FROM {aggregator_category_item} ci LEFT JOIN {aggregator_item} i ON i.iid = ci.iid LEFT JOIN {aggregator_feed} f ON i.fid = f.fid WHERE ci.cid = %d ORDER BY i.timestamp DESC', $category->cid, 0, variable_get('aggregator_summary_items', 3)); while ($item = db_fetch_object($items)) { - $list[] = "<a href=\"". check_url($item->link) ."\">$item->title</a> <span class=\"age\">". t('%age ago', array('%age' => format_interval(time() - $item->timestamp))) ."</span>, <span class=\"source\"><a href=\"$item->feed_link\">$item->feed_title</a></span>\n"; + $list[] = '<a href="'. check_url($item->link) ."\">$item->title</a> <span class=\"age\">". t('%age ago', array('%age' => format_interval(time() - $item->timestamp))) ."</span>, <span class=\"source\"><a href=\"$item->feed_link\">$item->feed_title</a></span>\n"; } $output .= theme('item_list', $list); } $output .= '<div class="more-link">'. l(t('more'), 'aggregator/categories/'. $category->cid) .'</div>'; } - $output .= "</div>"; + $output .= '</div>'; print theme('page', $output); } @@ -788,18 +874,18 @@ function aggregator_page_categories() { function theme_aggregator_feed($feed) { - $output = ""; + $output = ''; if ($feed->image) { $output .= $feed->image; } $output .= $feed->description; - $output .= "<h3>". t("URL") ."</h3>\n"; + $output .= '<h3>'. t('URL') ."</h3>\n"; $output .= theme('xml_icon', $feed->url); $output .= "<a href=\"$feed->link\">$feed->link</a>\n"; - $output .= "<h3>". t('Last update') ."</h3>\n"; - $updated = t("%time ago", array("%time" => format_interval(time() - $feed->checked))); + $output .= '<h3>'. t('Last update') ."</h3>\n"; + $updated = t('%time ago', array('%time' => format_interval(time() - $feed->checked))); if (user_access('administer news feeds')) { $output .= l($updated, 'admin/syndication/news'); @@ -814,8 +900,8 @@ function theme_aggregator_feed($feed) { function theme_aggregator_block_item($item, $feed = 0) { global $user; - if ($user->uid && module_exist("blog") && user_access("maintain personal blog")) { - $output .= "<div class=\"icon\">". l("<img src=\"". theme("image", "blog.gif") ."\" alt=\"". t("blog it") ."\" title=\"". t("blog it") ."\" />", "node/add/blog", array("title" => t("Comment on this news item in your personal blog."), "class" => "blog-it"), "iid=$item->iid") ."</div>"; + if ($user->uid && module_exist('blog') && user_access('maintain personal blog')) { + $output .= '<div class="icon">'. l('<img src="'. theme('image', 'blog.gif') .'" alt="'. t('blog it') .'" title="'. t('blog it') .'" />', 'node/add/blog', array('title' => t('Comment on this news item in your personal blog.'), 'class' => 'blog-it'), "iid=$item->iid") .'</div>'; } // external link @@ -825,24 +911,23 @@ function theme_aggregator_block_item($item, $feed = 0) { } function theme_aggregator_page_item($item) { - static $last; - $date = date("Ymd", $item->timestamp); + $date = date('Ymd', $item->timestamp); if ($date != $last) { $last = $date; - $output .= "<h3>". date("F j, Y", $item->timestamp) ."</h3>\n"; + $output .= '<h3>'. date('F j, Y', $item->timestamp) ."</h3>\n"; } $output .= "<div class=\"news-item\">\n"; - $output .= " <div class=\"date\">". date("H:i", $item->timestamp) ."</div>\n"; + $output .= ' <div class="date">'. date('H:i', $item->timestamp) ."</div>\n"; $output .= " <div class=\"body\">\n"; $output .= " <div class=\"title\"><a href=\"$item->link\">$item->title</a></div>\n"; if ($item->description) { $output .= " <div class=\"description\">$item->description</div>\n"; } if ($item->ftitle && $item->fid) { - $output .= " <div class=\"source\">". t('Source') .": ". l($item->ftitle, "aggregator/sources/$item->fid") ."</div>\n"; + $output .= ' <div class="source">'. t('Source') .': '. l($item->ftitle, "aggregator/sources/$item->fid") ."</div>\n"; } $result = db_query('SELECT c.title, c.cid FROM {aggregator_category_item} ci LEFT JOIN {aggregator_category} c ON ci.cid = c.cid WHERE ci.iid = %d ORDER BY c.title', $item->iid); @@ -851,7 +936,7 @@ function theme_aggregator_page_item($item) { $categories[] = l($category->title, 'aggregator/categories/'. $category->cid); } if ($categories) { - $output .= " <div class=\"categories\">". t('Categories') .": ". implode(', ', $categories) ."</div>\n"; + $output .= ' <div class="categories">'. t('Categories') .': '. implode(', ', $categories) ."</div>\n"; } $output .= " </div>\n"; diff --git a/modules/archive.module b/modules/archive.module index 4040188ce..cf0e99157 100644 --- a/modules/archive.module +++ b/modules/archive.module @@ -1,39 +1,39 @@ <?php // $Id$ +/** + * Implementation of hook_help(). + */ function archive_help($section) { - $output = ""; - switch ($section) { case 'admin/system/modules#description': - $output = t("Displays a calendar to navigate old content."); - break; + return t('Displays a calendar to navigate old content.'); case 'admin/system/modules/archive': - $output = t("Choose the starting \"day of the week\" for the displayed calendar block."); - break; + return t('Choose the starting "day of the week" for the displayed calendar block.'); } - - return $output; } +/** + * Generates a monthly claendar, for display in the archive block. + */ function archive_calendar($original = 0) { global $user; - $edit = $_POST["edit"]; + $edit = $_POST['edit']; // Extract today's date: $offset = time() + $user->timezone; - $start_of_today = mktime(0, 0, 0, date("n", $offset), date("d", $offset), date("Y", $offset)) + $user->timezone; - $end_of_today = mktime(23, 59, 59, date("n", $offset), date("d", $offset), date("Y", $offset)) + $user->timezone; + $start_of_today = mktime(0, 0, 0, date('n', $offset), date('d', $offset), date('Y', $offset)) + $user->timezone; + $end_of_today = mktime(23, 59, 59, date('n', $offset), date('d', $offset), date('Y', $offset)) + $user->timezone; // Extract the requested date: - if ($edit["year"] && $edit["month"] && $edit["day"]) { - $year = $edit["year"]; - $month = $edit["month"]; - $day = $edit["day"]; + if ($edit['year'] && $edit['month'] && $edit['day']) { + $year = $edit['year']; + $month = $edit['month']; + $day = $edit['day']; $requested = mktime(0, 0, 0, $month, $day, $year) + $user->timezone; } - else if (arg(0) == "archive" && arg(3)) { + else if (arg(0) == 'archive' && arg(3)) { $year = arg(1); $month = arg(2); $day = arg(3); @@ -41,9 +41,9 @@ function archive_calendar($original = 0) { $requested = mktime(0, 0, 0, $month, $day, $year) + $user->timezone; } else { - $year = date("Y", time()); - $month = date("n", time()); - $day = date("d", time()); + $year = date('Y', time()); + $month = date('n', time()); + $day = date('d', time()); $requested = $end_of_today + $user->timezone; } @@ -51,10 +51,10 @@ function archive_calendar($original = 0) { $start_of_month = mktime(0, 0, 0, $month, 1, $year); // Extract first day of the month: - $first = date("w", $start_of_month); + $first = date('w', $start_of_month); // Extract last day of the month: - $last = date("t", $start_of_month); + $last = date('t', $start_of_month); $end_of_month = mktime(23, 59, 59, $month, $last, $year); @@ -66,27 +66,27 @@ function archive_calendar($original = 0) { // Calculate previous and next months dates and check for shorter months (28/30 days) $prevmonth = mktime(23, 59, 59, $month - 1, 1, $year); - $prev = mktime(23, 59, 59, $month - 1, min(date("t", $prevmonth), $day), $year); + $prev = mktime(23, 59, 59, $month - 1, min(date('t', $prevmonth), $day), $year); $nextmonth = mktime(23, 59, 59, $month + 1, 1, $year); - $next = mktime(23, 59, 59, $month + 1, min(date("t", $nextmonth), $day), $year); + $next = mktime(23, 59, 59, $month + 1, min(date('t', $nextmonth), $day), $year); $result = db_query("SELECT created FROM {node} WHERE status = 1 AND created > $start_of_month AND created < $end_of_month"); $days_with_posts = array(); while ($day_with_post = db_fetch_object($result)) { - $days_with_posts[] = date("j", $day_with_post->created + $user->timezone); + $days_with_posts[] = date('j', $day_with_post->created + $user->timezone); } $days_with_posts = array_unique($days_with_posts); // Generate calendar header: $output .= "\n<!-- calendar -->\n"; - $output .= "<div class=\"calendar\">"; - $output .= "<table summary=\"". t('A calendar to browse the archives') .".\">\n"; - $output .= " <caption>". l("«", "archive/". date("Y/m/d", $prev), array('title' => t("Previous month"))) ." ". format_date($requested, "custom", "F") . date(" Y", $requested) ." ". ($nextmonth <= time() ? l("»", "archive/". date("Y/m/d", $next), array('title' => t("Next month"))) : " ") ."</caption>\n"; + $output .= '<div class="calendar">'; + $output .= '<table summary="'. t('A calendar to browse the archives') .".\">\n"; + $output .= ' <caption>'. l('«', 'archive/'. date('Y/m/d', $prev), array('title' => t('Previous month'))) .' '. format_date($requested, 'custom', 'F') . date(' Y', $requested) .' '. ($nextmonth <= time() ? l('»', 'archive/'. date('Y/m/d', $next), array('title' => t('Next month'))) : ' ') ."</caption>\n"; // First day of week (0 => Sunday, 1 => Monday, ...) - $weekstart = variable_get("default_firstday", 0); + $weekstart = variable_get('default_firstday', 0); // Last day of week ($weekstart - 1 == -1) ? $lastday = 6 : $lastday = $weekstart - 1; @@ -101,7 +101,7 @@ function archive_calendar($original = 0) { } foreach ($days as $name => $fullname) { - $output .= " <th abbr=\"". $fullname ."\">". $name . "</th>\n"; + $output .= ' <th abbr="'. $fullname .'">'. $name . "</th>\n"; } $output .= "</tr>\n"; @@ -126,11 +126,11 @@ function archive_calendar($original = 0) { $date = mktime(0, 0, 0, $month, $nday, $year) + $user->timezone; if (in_array($nday, $days_with_posts)) { $daytext = l($nday, "archive/$year/$month/$nday"); - $dayclass = "day-link"; + $dayclass = 'day-link'; } else { $daytext = $nday; - $dayclass = "day-normal"; + $dayclass = 'day-normal'; } if ($date == $requested) { $output .= " <td class=\"day-selected\">$daytext</td>\n"; @@ -169,17 +169,22 @@ function archive_calendar($original = 0) { return $output; } -function archive_block($op = "list", $delta = 0) { - global $date; - if ($op == "list") { - $blocks[0]["info"] = t("Calendar to browse archives"); +/** + * Implementation of hook_block(). + * + * Generates a calendar for the current month, with links to the archives + * for each day. + */ +function archive_block($op = 'list', $delta = 0) { + if ($op == 'list') { + $blocks[0]['info'] = t('Calendar to browse archives'); return $blocks; } - else if (user_access("access content")) { + else if (user_access('access content')) { switch ($delta) { case 0: - $block["subject"] = t("Browse archives"); - $block["content"] = archive_calendar(); + $block['subject'] = t('Browse archives'); + $block['content'] = archive_calendar(); return $block; } } @@ -202,57 +207,51 @@ function archive_link($type) { return $links; } -function archive_page() { - global $date, $month, $year, $meta, $user; +/** + * Menu callback. Lists all nodes posted on a given date. + */ +function archive_page($year = 0, $month = 0, $day = 0) { + global $user; - $op = $_POST["op"]; - $edit = $_POST["edit"]; + $output = ''; + $op = $_POST['op']; + $edit = $_POST['edit']; - if ($op == t("Show")) { - $year = $edit["year"]; - $month = $edit["month"]; - $day = $edit["day"]; - } - else { - $year = arg(1); - $month = arg(2); - $day = arg(3); + if ($op == t('Show')) { + $year = $edit['year']; + $month = $edit['month']; + $day = $edit['day']; } $date = mktime(0, 0, 0, $month, $day, $year) - $user->timezone; $date_end = mktime(0, 0, 0, $month, $day + 1, $year) - $user->timezone; - /* - ** Prepare the values of the form fields: - */ - + // Prepare the values of the form fields. $years = drupal_map_assoc(range(2000, 2005)); - $months = array(1 => t("January"), 2 => t("February"), 3 => t("March"), 4 => t("April"), 5 => t("May"), 6 => t("June"), 7 => t("July"), 8 => t("August"), 9 => t("September"), 10 => t("October"), 11 => t("November"), 12 => t("December")); + $months = array(1 => t('January'), 2 => t('February'), 3 => t('March'), 4 => t('April'), 5 => t('May'), 6 => t('June'), 7 => t('July'), 8 => t('August'), 9 => t('September'), 10 => t('October'), 11 => t('November'), 12 => t('December')); $days = drupal_map_assoc(range(0, 31)); - $start = "<div class=\"container-inline\">"; - $start .= form_select("", "year", ($year ? $year : date("Y")), $years). form_select("", "month", ($month ? $month : date("m")), $months) . form_select("", "day", ($day ? $day : date("d")), $days) . form_submit(t("Show")); - $start .= "</div>"; + $start = '<div class="container-inline">'; + $start .= form_select('', 'year', ($year ? $year : date('Y')), $years). form_select('', 'month', ($month ? $month : date('m')), $months) . form_select('', 'day', ($day ? $day : date('d')), $days) . form_submit(t('Show')); + $start .= '</div>'; $output .= form($start); - /* - ** Fetch nodes for the selected date, or current date if none - ** selected. - */ - if ($year && $month && $day) { - $result = db_query_range("SELECT nid FROM {node} WHERE status = '1' AND created > %d AND created < %d ORDER BY created", $date, $date_end, 0, 20); + // Fetch nodes for the selected date, if one was specified. + $result = db_query_range('SELECT nid FROM {node} WHERE status = 1 AND created > %d AND created < %d ORDER BY created', $date, $date_end, 0, 20); while ($nid = db_fetch_object($result)) { - $output .= node_view(node_load(array("nid" => $nid->nid)), 1); + $output .= node_view(node_load(array('nid' => $nid->nid)), 1); } } - print theme("page", $output); + print theme('page', $output); } +/** + * Implementation of hook_settings(). + */ function archive_settings() { - - $output .= form_select(t("First day of week"), "default_firstday", variable_get("default_firstday", 0), array(0 => t("Sunday"), 1 => t("Monday"), 2 => t("Tuesday"), 3 => t("Wednesday"), 4 => t("Thursday"), 5 => t("Friday"), 6 => t("Saturday")), t("The first day of the week. By changing this value you choose how the calendar block is rendered.")); + $output = form_select(t('First day of week'), 'default_firstday', variable_get('default_firstday', 0), array(0 => t('Sunday'), 1 => t('Monday'), 2 => t('Tuesday'), 3 => t('Wednesday'), 4 => t('Thursday'), 5 => t('Friday'), 6 => t('Saturday')), t('The first day of the week. By changing this value you choose how the calendar block is rendered.')); return $output; } diff --git a/modules/archive/archive.module b/modules/archive/archive.module index 4040188ce..cf0e99157 100644 --- a/modules/archive/archive.module +++ b/modules/archive/archive.module @@ -1,39 +1,39 @@ <?php // $Id$ +/** + * Implementation of hook_help(). + */ function archive_help($section) { - $output = ""; - switch ($section) { case 'admin/system/modules#description': - $output = t("Displays a calendar to navigate old content."); - break; + return t('Displays a calendar to navigate old content.'); case 'admin/system/modules/archive': - $output = t("Choose the starting \"day of the week\" for the displayed calendar block."); - break; + return t('Choose the starting "day of the week" for the displayed calendar block.'); } - - return $output; } +/** + * Generates a monthly claendar, for display in the archive block. + */ function archive_calendar($original = 0) { global $user; - $edit = $_POST["edit"]; + $edit = $_POST['edit']; // Extract today's date: $offset = time() + $user->timezone; - $start_of_today = mktime(0, 0, 0, date("n", $offset), date("d", $offset), date("Y", $offset)) + $user->timezone; - $end_of_today = mktime(23, 59, 59, date("n", $offset), date("d", $offset), date("Y", $offset)) + $user->timezone; + $start_of_today = mktime(0, 0, 0, date('n', $offset), date('d', $offset), date('Y', $offset)) + $user->timezone; + $end_of_today = mktime(23, 59, 59, date('n', $offset), date('d', $offset), date('Y', $offset)) + $user->timezone; // Extract the requested date: - if ($edit["year"] && $edit["month"] && $edit["day"]) { - $year = $edit["year"]; - $month = $edit["month"]; - $day = $edit["day"]; + if ($edit['year'] && $edit['month'] && $edit['day']) { + $year = $edit['year']; + $month = $edit['month']; + $day = $edit['day']; $requested = mktime(0, 0, 0, $month, $day, $year) + $user->timezone; } - else if (arg(0) == "archive" && arg(3)) { + else if (arg(0) == 'archive' && arg(3)) { $year = arg(1); $month = arg(2); $day = arg(3); @@ -41,9 +41,9 @@ function archive_calendar($original = 0) { $requested = mktime(0, 0, 0, $month, $day, $year) + $user->timezone; } else { - $year = date("Y", time()); - $month = date("n", time()); - $day = date("d", time()); + $year = date('Y', time()); + $month = date('n', time()); + $day = date('d', time()); $requested = $end_of_today + $user->timezone; } @@ -51,10 +51,10 @@ function archive_calendar($original = 0) { $start_of_month = mktime(0, 0, 0, $month, 1, $year); // Extract first day of the month: - $first = date("w", $start_of_month); + $first = date('w', $start_of_month); // Extract last day of the month: - $last = date("t", $start_of_month); + $last = date('t', $start_of_month); $end_of_month = mktime(23, 59, 59, $month, $last, $year); @@ -66,27 +66,27 @@ function archive_calendar($original = 0) { // Calculate previous and next months dates and check for shorter months (28/30 days) $prevmonth = mktime(23, 59, 59, $month - 1, 1, $year); - $prev = mktime(23, 59, 59, $month - 1, min(date("t", $prevmonth), $day), $year); + $prev = mktime(23, 59, 59, $month - 1, min(date('t', $prevmonth), $day), $year); $nextmonth = mktime(23, 59, 59, $month + 1, 1, $year); - $next = mktime(23, 59, 59, $month + 1, min(date("t", $nextmonth), $day), $year); + $next = mktime(23, 59, 59, $month + 1, min(date('t', $nextmonth), $day), $year); $result = db_query("SELECT created FROM {node} WHERE status = 1 AND created > $start_of_month AND created < $end_of_month"); $days_with_posts = array(); while ($day_with_post = db_fetch_object($result)) { - $days_with_posts[] = date("j", $day_with_post->created + $user->timezone); + $days_with_posts[] = date('j', $day_with_post->created + $user->timezone); } $days_with_posts = array_unique($days_with_posts); // Generate calendar header: $output .= "\n<!-- calendar -->\n"; - $output .= "<div class=\"calendar\">"; - $output .= "<table summary=\"". t('A calendar to browse the archives') .".\">\n"; - $output .= " <caption>". l("«", "archive/". date("Y/m/d", $prev), array('title' => t("Previous month"))) ." ". format_date($requested, "custom", "F") . date(" Y", $requested) ." ". ($nextmonth <= time() ? l("»", "archive/". date("Y/m/d", $next), array('title' => t("Next month"))) : " ") ."</caption>\n"; + $output .= '<div class="calendar">'; + $output .= '<table summary="'. t('A calendar to browse the archives') .".\">\n"; + $output .= ' <caption>'. l('«', 'archive/'. date('Y/m/d', $prev), array('title' => t('Previous month'))) .' '. format_date($requested, 'custom', 'F') . date(' Y', $requested) .' '. ($nextmonth <= time() ? l('»', 'archive/'. date('Y/m/d', $next), array('title' => t('Next month'))) : ' ') ."</caption>\n"; // First day of week (0 => Sunday, 1 => Monday, ...) - $weekstart = variable_get("default_firstday", 0); + $weekstart = variable_get('default_firstday', 0); // Last day of week ($weekstart - 1 == -1) ? $lastday = 6 : $lastday = $weekstart - 1; @@ -101,7 +101,7 @@ function archive_calendar($original = 0) { } foreach ($days as $name => $fullname) { - $output .= " <th abbr=\"". $fullname ."\">". $name . "</th>\n"; + $output .= ' <th abbr="'. $fullname .'">'. $name . "</th>\n"; } $output .= "</tr>\n"; @@ -126,11 +126,11 @@ function archive_calendar($original = 0) { $date = mktime(0, 0, 0, $month, $nday, $year) + $user->timezone; if (in_array($nday, $days_with_posts)) { $daytext = l($nday, "archive/$year/$month/$nday"); - $dayclass = "day-link"; + $dayclass = 'day-link'; } else { $daytext = $nday; - $dayclass = "day-normal"; + $dayclass = 'day-normal'; } if ($date == $requested) { $output .= " <td class=\"day-selected\">$daytext</td>\n"; @@ -169,17 +169,22 @@ function archive_calendar($original = 0) { return $output; } -function archive_block($op = "list", $delta = 0) { - global $date; - if ($op == "list") { - $blocks[0]["info"] = t("Calendar to browse archives"); +/** + * Implementation of hook_block(). + * + * Generates a calendar for the current month, with links to the archives + * for each day. + */ +function archive_block($op = 'list', $delta = 0) { + if ($op == 'list') { + $blocks[0]['info'] = t('Calendar to browse archives'); return $blocks; } - else if (user_access("access content")) { + else if (user_access('access content')) { switch ($delta) { case 0: - $block["subject"] = t("Browse archives"); - $block["content"] = archive_calendar(); + $block['subject'] = t('Browse archives'); + $block['content'] = archive_calendar(); return $block; } } @@ -202,57 +207,51 @@ function archive_link($type) { return $links; } -function archive_page() { - global $date, $month, $year, $meta, $user; +/** + * Menu callback. Lists all nodes posted on a given date. + */ +function archive_page($year = 0, $month = 0, $day = 0) { + global $user; - $op = $_POST["op"]; - $edit = $_POST["edit"]; + $output = ''; + $op = $_POST['op']; + $edit = $_POST['edit']; - if ($op == t("Show")) { - $year = $edit["year"]; - $month = $edit["month"]; - $day = $edit["day"]; - } - else { - $year = arg(1); - $month = arg(2); - $day = arg(3); + if ($op == t('Show')) { + $year = $edit['year']; + $month = $edit['month']; + $day = $edit['day']; } $date = mktime(0, 0, 0, $month, $day, $year) - $user->timezone; $date_end = mktime(0, 0, 0, $month, $day + 1, $year) - $user->timezone; - /* - ** Prepare the values of the form fields: - */ - + // Prepare the values of the form fields. $years = drupal_map_assoc(range(2000, 2005)); - $months = array(1 => t("January"), 2 => t("February"), 3 => t("March"), 4 => t("April"), 5 => t("May"), 6 => t("June"), 7 => t("July"), 8 => t("August"), 9 => t("September"), 10 => t("October"), 11 => t("November"), 12 => t("December")); + $months = array(1 => t('January'), 2 => t('February'), 3 => t('March'), 4 => t('April'), 5 => t('May'), 6 => t('June'), 7 => t('July'), 8 => t('August'), 9 => t('September'), 10 => t('October'), 11 => t('November'), 12 => t('December')); $days = drupal_map_assoc(range(0, 31)); - $start = "<div class=\"container-inline\">"; - $start .= form_select("", "year", ($year ? $year : date("Y")), $years). form_select("", "month", ($month ? $month : date("m")), $months) . form_select("", "day", ($day ? $day : date("d")), $days) . form_submit(t("Show")); - $start .= "</div>"; + $start = '<div class="container-inline">'; + $start .= form_select('', 'year', ($year ? $year : date('Y')), $years). form_select('', 'month', ($month ? $month : date('m')), $months) . form_select('', 'day', ($day ? $day : date('d')), $days) . form_submit(t('Show')); + $start .= '</div>'; $output .= form($start); - /* - ** Fetch nodes for the selected date, or current date if none - ** selected. - */ - if ($year && $month && $day) { - $result = db_query_range("SELECT nid FROM {node} WHERE status = '1' AND created > %d AND created < %d ORDER BY created", $date, $date_end, 0, 20); + // Fetch nodes for the selected date, if one was specified. + $result = db_query_range('SELECT nid FROM {node} WHERE status = 1 AND created > %d AND created < %d ORDER BY created', $date, $date_end, 0, 20); while ($nid = db_fetch_object($result)) { - $output .= node_view(node_load(array("nid" => $nid->nid)), 1); + $output .= node_view(node_load(array('nid' => $nid->nid)), 1); } } - print theme("page", $output); + print theme('page', $output); } +/** + * Implementation of hook_settings(). + */ function archive_settings() { - - $output .= form_select(t("First day of week"), "default_firstday", variable_get("default_firstday", 0), array(0 => t("Sunday"), 1 => t("Monday"), 2 => t("Tuesday"), 3 => t("Wednesday"), 4 => t("Thursday"), 5 => t("Friday"), 6 => t("Saturday")), t("The first day of the week. By changing this value you choose how the calendar block is rendered.")); + $output = form_select(t('First day of week'), 'default_firstday', variable_get('default_firstday', 0), array(0 => t('Sunday'), 1 => t('Monday'), 2 => t('Tuesday'), 3 => t('Wednesday'), 4 => t('Thursday'), 5 => t('Friday'), 6 => t('Saturday')), t('The first day of the week. By changing this value you choose how the calendar block is rendered.')); return $output; } diff --git a/modules/block.module b/modules/block.module index a2f79c0e7..047e3bf64 100644 --- a/modules/block.module +++ b/modules/block.module @@ -1,12 +1,13 @@ <?php // $Id$ -function block_help($section = "admin/help#block") { - $output = ""; - +/** + * Implementation of hook_help(). + */ +function block_help($section) { switch ($section) { case 'admin/help#block': - $output = t(" + return t(" <p>Blocks are the boxes visible in the sidebar(s) of your web site. These are usually generated automatically by modules (e.g. recent forum topics), but you can also create your own blocks using either static HTML or dynamic PHP content.</p> <p>The sidebar each block appears in depends on both which theme you're using (some are left-only, some right, some both), and on the settings in block management.</p><p>Whether a block is visible in the first place depends on four things:</p><ul><li>It must have its \"enabled\" box checked in block management.</li><li>If it has its \"custom\" box checked in block management, the user must have chosen to display it in their user preferences.</li><li>If the \"path\" field in block management is set, the visitor must be on a page that matches the path specification (more on this later).</li><li>If the block has its throttle box checked, the user will only see the block if the site throttle level is low.</li></ul> <p>The block management screen also lets you specify the vertical sort-order of the blocks within a sidebar. You do this by assigning a <strong>weight</strong> to each block. Lighter blocks (smaller weight) \"float up\" towards the top of the sidebar. Heavier ones \"sink down\" towards the bottom of it. Once you've positioned things just so, you can preview what the layout will look like in different types of themes by clicking the preview placement link in the menu to the left.</p> @@ -34,31 +35,30 @@ function block_help($section = "admin/help#block") { return t(\"Welcome visitor, ... welcome message goes here ...\"); } </pre></blockquote> -<p>For more in-depth examples, we recommend that you check the existing boxes and use them as a starting point.</p>", array("%pcre" => "http://php.net/pcre/")); - break; +<p>For more in-depth examples, we recommend that you check the existing boxes and use them as a starting point.</p>", array('%pcre' => 'http://php.net/pcre/')); case 'admin/system/modules#description': - $output = t("Controls the boxes that are displayed around the main content."); - break; + return t('Controls the boxes that are displayed around the main content.'); case 'admin/system/block': - $output = t("Blocks are the boxes in the left- and right- side bars of the web site, depending on the choosen theme. They are created by <strong>active</strong> Drupal modules. The 'enabled' checkbox sets the default status of the block. Only enabled blocks are shown. When the 'custom' checkbox is checked, your users can show or hide the block using their account settings. In that case, the 'enabled' checkbox signifies the block's default status. You can assign the block's placement by giving it a region and a weight. The region specifies which side of the page the block is on, and the weight sorts blocks within a region. Lighter (smaller weight value) blocks \"float up\" towards the top of the page. The path setting lets you define which pages you want a block to be shown on. You can also create your own blocks, where you specify the content of the block rather than its being generated by a module (you can even use PHP in these). You can create one of these by clicking the <a href=\"%createblock\">new block</a> link in the menu to the left. Edit and delete links will become active below for these admin-defined blocks. Blocks can automatically be temporarily disabled to reduce server load when your site becomes extremely busy by checking throttle. The auto-throttle functionality must be enabled on the <a href=\"%throttle\">throttle configuration page</a> after having enabled the throttle module.", array("%createblock" => url("admin/system/block/add"), "%throttle" => url("admin/system/modules/throttle"))); - break; + return t("Blocks are the boxes in the left- and right- side bars of the web site, depending on the chosen theme. They are created by <strong>active</strong> Drupal modules. The \"enabled\" checkbox sets the default status of the block. Only enabled blocks are shown. When the \"custom\" checkbox is checked, your users can show or hide the block using their account settings. In that case, the 'enabled' checkbox signifies the block's default status. You can assign the block's placement by giving it a region and a weight. The region specifies which side of the page the block is on, and the weight sorts blocks within a region. Lighter (smaller weight value) blocks \"float up\" towards the top of the page. The path setting lets you define which pages you want a block to be shown on. You can also create your own blocks, where you specify the content of the block rather than its being generated by a module (you can even use PHP in these). You can create one of these by clicking the <a href=\"%createblock\">new block</a> link in the menu to the left. Edit and delete links will become active below for these admin-defined blocks. Blocks can automatically be temporarily disabled to reduce server load when your site becomes extremely busy by checking throttle. The auto-throttle functionality must be enabled on the <a href=\"%throttle\">throttle configuration page</a> after having enabled the throttle module.", array('%createblock' => url('admin/system/block/add'), '%throttle' => url('admin/system/modules/throttle'))); case 'admin/system/block/add': - $output = t("Here you can create a new block. Once you have created this block you must make it active, and give it a place on the page using <a href=\"%overview\">blocks</a>. The title is used when displaying the block. The description is used in the \"block\" column on the <a href=\"%overview\">blocks</a> page. If you are going to place PHP code in the block, and you have <strong>create php content</strong> permission (see the <a href=\"%permission\">permissions</a> page) you <strong>must</strong> change the type to PHP to make your code active.", array("%overview" => url("admin/system/block"), "%permission" => url("admin/user/permission"))); - break; + return t("Here you can create a new block. Once you have created this block you must make it active and give it a place on the page using <a href=\"%overview\">blocks</a>. The title is used when displaying the block. The description is used in the \"block\" column on the <a href=\"%overview\">blocks</a> page. If you are going to place PHP code in the block, and you have the <strong>create php content</strong> permission (see the <a href=\"%permission\">permissions</a> page), you <strong>must</strong> change the type to PHP to make your code active.", array('%overview' => url('admin/system/block'), '%permission' => url('admin/user/permission'))); case 'admin/system/block/preview': - $output = t("This page show you the placement of your blocks in different themes types. The numbers are the weight of each block, which is used to sort them within the sidebars."); - break; + return t('This page shows you the placement of your blocks in different theme types. The numbers are the weights of each block, which are used to sort them within the sidebars.'); } - - return $output; } +/** + * Menu callback. Presents the block-specific information from admin/help. + */ function block_help_page() { - print theme("page", block_help()); + print theme('page', block_help('admin/help#block')); } +/** + * Implementation of hook_perm(). + */ function block_perm() { - return array("administer blocks"); + return array('administer blocks'); } /** @@ -67,24 +67,31 @@ function block_perm() { function block_link($type) { if ($type == 'system') { menu('admin/system/block', t('blocks'), user_access('administer blocks') ? 'block_admin' : MENU_DENIED, 3); - menu('admin/system/block/add', t('new block'), user_access('administer blocks') ? 'block_admin' : MENU_DENIED, 2); - menu('admin/system/block/preview', t('preview placement'), user_access('administer blocks') ? 'block_admin' : MENU_DENIED, 3); + menu('admin/system/block/add', t('new block'), user_access('administer blocks') ? 'block_box_edit' : MENU_DENIED, 2); + menu('admin/system/block/edit', t('edit block'), user_access('administer blocks') ? 'block_box_edit' : MENU_DENIED, 0, MENU_HIDE, MENU_LOCKED); + menu('admin/system/block/delete', t('delete block'), user_access('administer blocks') ? 'block_box_delete' : MENU_DENIED, 0, MENU_HIDE, MENU_LOCKED); + menu('admin/system/block/preview', t('preview placement'), user_access('administer blocks') ? 'block_admin_preview' : MENU_DENIED, 3); menu('admin/system/block/help', t('help'), user_access('administer blocks') ? 'block_help_page' : MENU_DENIED, 9); } } -function block_block($op = "list", $delta = 0) { - if ($op == "list") { - $result = db_query("SELECT bid, title, info FROM {boxes} ORDER BY title"); +/** + * Implementation of hook_block(). + * + * Generates the administrator-defined blocks for display. + */ +function block_block($op = 'list', $delta = 0) { + if ($op == 'list') { + $result = db_query('SELECT bid, title, info FROM {boxes} ORDER BY title'); while ($block = db_fetch_object($result)) { - $blocks[$block->bid]["info"] = $block->info; + $blocks[$block->bid]['info'] = $block->info; } return $blocks; } else { - $block = db_fetch_object(db_query("SELECT * FROM {boxes} WHERE bid = %d", $delta)); - $data["subject"] = $block->title; - $data["content"] = ($block->type == 1) ? eval($block->body) : $block->body; + $block = db_fetch_object(db_query('SELECT * FROM {boxes} WHERE bid = %d', $delta)); + $data['subject'] = $block->title; + $data['content'] = ($block->type == 1) ? eval($block->body) : $block->body; return $data; } } @@ -93,52 +100,53 @@ function block_admin_save($edit) { foreach ($edit as $module => $blocks) { foreach ($blocks as $delta => $block) { db_query("UPDATE {blocks} SET region = %d, status = %d, custom = %d, path = '%s', weight = %d, throttle = %d WHERE module = '%s' AND delta = '%s'", - $block["region"], $block["status"], $block["custom"], $block["path"], $block["weight"], $block["throttle"], $module, $delta); + $block['region'], $block['status'], $block['custom'], $block['path'], $block['weight'], $block['throttle'], $module, $delta); } } - return t("the block settings have been updated."); + return t('the block settings have been updated.'); } /** - * update blocks db table with blocks currently exported by modules + * Update the 'blocks' DB table with the blocks currently exported by modules. * * @param $order_by php <a * href="http://www.php.net/manual/en/function.array-multisort.php">array_multisort()</a> * style sort ordering, eg. "weight", SORT_ASC, SORT_STRING. * - * @return blocks currently exported by modules, sorted by $order_by + * @return + * Blocks currently exported by modules, sorted by $order_by. */ -function _block_rehash($order_by = array("weight")) { - $result = db_query("SELECT * FROM {blocks} "); +function _block_rehash($order_by = array('weight')) { + $result = db_query('SELECT * FROM {blocks} '); while ($old_block = db_fetch_object($result)) { $old_blocks[$old_block->module][$old_block->delta] = $old_block; } - db_query("DELETE FROM {blocks} "); + db_query('DELETE FROM {blocks} '); foreach (module_list() as $module) { - $module_blocks = module_invoke($module, "block", "list"); + $module_blocks = module_invoke($module, 'block', 'list'); if ($module_blocks) { foreach ($module_blocks as $delta => $block) { - $block["module"] = $module; - $block["delta"] = $delta; + $block['module'] = $module; + $block['delta'] = $delta; if ($old_blocks[$module][$delta]) { - $block["status"] = $old_blocks[$module][$delta]->status; - $block["weight"] = $old_blocks[$module][$delta]->weight; - $block["region"] = $old_blocks[$module][$delta]->region; - $block["path"] = $old_blocks[$module][$delta]->path; - $block["custom"] = $old_blocks[$module][$delta]->custom; - $block["throttle"] = $old_blocks[$module][$delta]->throttle; + $block['status'] = $old_blocks[$module][$delta]->status; + $block['weight'] = $old_blocks[$module][$delta]->weight; + $block['region'] = $old_blocks[$module][$delta]->region; + $block['path'] = $old_blocks[$module][$delta]->path; + $block['custom'] = $old_blocks[$module][$delta]->custom; + $block['throttle'] = $old_blocks[$module][$delta]->throttle; } else { - $block["status"] = $block["weight"] = $block["region"] = $block["custom"] = 0; - $block["path"] = ""; + $block['status'] = $block['weight'] = $block['region'] = $block['custom'] = 0; + $block['path'] = ''; } // reinsert blocks into table db_query("INSERT INTO {blocks} (module, delta, status, weight, region, path, custom, throttle) VALUES ('%s', '%s', %d, %d, %d, '%s', %d, %d)", - $block["module"], $block["delta"], $block["status"], $block["weight"], $block["region"], $block["path"], $block["custom"], $block["throttle"]); + $block['module'], $block['delta'], $block['status'], $block['weight'], $block['region'], $block['path'], $block['custom'], $block['throttle']); $blocks[] = $block; @@ -154,177 +162,193 @@ function _block_rehash($order_by = array("weight")) { return $blocks; } +/** + * Prepare the main block administration form. + */ function block_admin_display() { $blocks = _block_rehash(); - $header = array(t("block"), t("enabled"), t("custom"), t("throttle"), t("weight"), t("region"), t("path"), array("data" => t("operations"), "colspan" => 2)); + $header = array(t('block'), t('enabled'), t('custom'), t('throttle'), t('weight'), t('region'), t('path'), array('data' => t('operations'), 'colspan' => 2)); foreach ($blocks as $block) { - if ($block["module"] == "block") { - $edit = l(t("edit"), "admin/system/block/edit/". $block["delta"]); - $delete = l(t("delete"), "admin/system/block/delete/". $block["delta"]); + if ($block['module'] == 'block') { + $edit = l(t('edit'), 'admin/system/block/edit/'. $block['delta']); + $delete = l(t('delete'), 'admin/system/block/delete/'. $block['delta']); } else { - $edit = ""; - $delete = ""; + $edit = ''; + $delete = ''; } - $rows[] = array($block["info"], array("data" => form_checkbox(NULL, $block["module"] ."][". $block["delta"] ."][status", 1, $block["status"]), "align" => "center"), array("data" => form_checkbox(NULL, $block["module"] ."][". $block["delta"] ."][custom", 1, $block["custom"]), "align" => "center"), array("data" => form_checkbox(NULL, $block["module"] ."][". $block["delta"] ."][throttle", 1, $block["throttle"], NULL, module_exist('throttle') ? NULL : array("disabled" => "disabled")), "align" => "center"), form_weight(NULL, $block["module"] ."][". $block["delta"] ."][weight", $block["weight"]), form_radios(NULL, $block["module"] ."][". $block["delta"] ."][region", $block["region"], array(t("left"), t("right"))), form_textfield(NULL, $block["module"] ."][". $block["delta"] ."][path", $block["path"], 10, 255), + $rows[] = array($block['info'], array('data' => form_checkbox(NULL, $block['module'] .']['. $block['delta'] .'][status', 1, $block['status']), 'align' => 'center'), array('data' => form_checkbox(NULL, $block['module'] .']['. $block['delta'] .'][custom', 1, $block['custom']), 'align' => 'center'), array('data' => form_checkbox(NULL, $block['module'] .']['. $block['delta'] .'][throttle', 1, $block['throttle'], NULL, module_exist('throttle') ? NULL : array('disabled' => 'disabled')), 'align' => 'center'), form_weight(NULL, $block['module'] .']['. $block['delta'] .'][weight', $block['weight']), form_radios(NULL, $block['module'] .']['. $block['delta'] .'][region', $block['region'], array(t('left'), t('right'))), form_textfield(NULL, $block['module'] .']['. $block['delta'] .'][path', $block['path'], 10, 255), $edit, $delete); } - $output = theme("table", $header, $rows); - $output .= form_submit(t("Save blocks")); + $output = theme('table', $header, $rows); + $output .= form_submit(t('Save blocks')); - return form($output); + return form($output, 'post', url('admin/system/block')); } +/** + * Menu callback. Displays the block layout as it will appear when themed. + */ function block_admin_preview() { - - $result = db_query("SELECT * FROM {blocks} WHERE status > 0 AND region = 0 ORDER BY weight"); + $result = db_query('SELECT * FROM {blocks} WHERE status > 0 AND region = 0 ORDER BY weight'); $lblocks .= "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\">\n"; while ($block = db_fetch_object($result)) { - $block_data = module_invoke($block->module, "block", "list"); - $name = $block_data[$block->delta]["info"]; - $lblocks .= " <tr><td>". ($block->status == 2 ? "<strong>$name</strong>" : $name) ."</td><td>$block->weight</td></tr>\n"; + $block_data = module_invoke($block->module, 'block', 'list'); + $name = $block_data[$block->delta]['info']; + $lblocks .= ' <tr><td>'. ($block->status == 2 ? "<strong>$name</strong>" : $name) ."</td><td>$block->weight</td></tr>\n"; } $lblocks .= "</table>\n"; - $result = db_query("SELECT * FROM {blocks} WHERE status > 0 AND region = 1 ORDER BY weight"); + $result = db_query('SELECT * FROM {blocks} WHERE status > 0 AND region = 1 ORDER BY weight'); $rblocks .= "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\">\n"; while ($block = db_fetch_object($result)) { - $block_data = module_invoke($block->module, "block", "list"); - $name = $block_data[$block->delta]["info"]; - $rblocks .= " <tr><td>". ($block->status == 2 ? "<strong>$name</strong>" : $name) ."</td><td>$block->weight</td></tr>\n"; + $block_data = module_invoke($block->module, 'block', 'list'); + $name = $block_data[$block->delta]['info']; + $rblocks .= ' <tr><td>'. ($block->status == 2 ? "<strong>$name</strong>" : $name) ."</td><td>$block->weight</td></tr>\n"; } $rblocks .= "</table>\n"; - $output .= "<h3>". t("Themes with both left and right sidebars") .":</h3>\n"; + $output .= '<h3>'. t('Themes with both left and right sidebars') .":</h3>\n"; $output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">\n"; - $output .= " <tr><td colspan=\"3\" style=\"text-align: center;\">". t("header") ."</td></tr>\n"; - $output .= " <tr><td>\n". ($lblocks ? $lblocks : " ") ."</td><td style=\"width: 300px;\"> </td><td>\n". ($rblocks ? $rblocks : " ") ."</td></tr>\n"; - $output .= " <tr><td colspan=\"3\" style=\"text-align: center;\">". t("footer") ."</td></tr>\n"; + $output .= ' <tr><td colspan="3" style="text-align: center;">'. t('header') ."</td></tr>\n"; + $output .= " <tr><td>\n". ($lblocks ? $lblocks : ' ') ."</td><td style=\"width: 300px;\"> </td><td>\n". ($rblocks ? $rblocks : ' ') ."</td></tr>\n"; + $output .= ' <tr><td colspan="3" style="text-align: center;">'. t('footer') ."</td></tr>\n"; $output .= "</table>\n"; - $result = db_query("SELECT * FROM {blocks} WHERE status > 0 ORDER BY weight"); + $result = db_query('SELECT * FROM {blocks} WHERE status > 0 ORDER BY weight'); $blocks .= "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\">\n"; while ($block = db_fetch_object($result)) { - $block_data = module_invoke($block->module, "block", "list"); - $name = $block_data[$block->delta]["info"]; - $blocks .= " <tr><td>". ($block->status == 2 ? "<strong>$name</strong>" : $name) ."</td><td>$block->weight</td></tr>\n"; + $block_data = module_invoke($block->module, 'block', 'list'); + $name = $block_data[$block->delta]['info']; + $blocks .= ' <tr><td>'. ($block->status == 2 ? "<strong>$name</strong>" : $name) ."</td><td>$block->weight</td></tr>\n"; } $blocks .= "</table>\n"; - $output .= "<h3>". t("Themes with right-sidebar only") .":</h3>\n"; + $output .= '<h3>'. t('Themes with right sidebar only') .":</h3>\n"; $output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">\n"; - $output .= " <tr><td colspan=\"2\" style=\"text-align: center;\">". t("header") ."</td></tr>\n"; - $output .= " <tr><td style=\"width: 400px;\"> </td><td>\n". ($blocks ? $blocks : " ") ."</td></tr>\n"; - $output .= " <tr><td colspan=\"2\" style=\"text-align: center;\">". t("footer") ."</td></tr>\n"; + $output .= ' <tr><td colspan="2" style="text-align: center;">'. t('header') ."</td></tr>\n"; + $output .= " <tr><td style=\"width: 400px;\"> </td><td>\n". ($blocks ? $blocks : ' ') ."</td></tr>\n"; + $output .= ' <tr><td colspan="2" style="text-align: center;">'. t('footer') ."</td></tr>\n"; $output .= "</table>\n"; - $output .= "<h3>". t("Themes with left-sidebar only") .":</h3>\n"; + $output .= '<h3>'. t('Themes with left sidebar only') .":</h3>\n"; $output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">\n"; - $output .= " <tr><td colspan=\"2\" style=\"text-align: center;\">". t("header") ."</td></tr>\n"; - $output .= " <tr><td>\n". ($blocks ? $blocks : " ") ."</td><td style=\"width: 400px;\"> </td></tr>\n"; - $output .= " <tr><td colspan=\"2\" style=\"text-align: center;\">". t("footer") ."</td></tr>\n"; + $output .= ' <tr><td colspan="2" style="text-align: center;">'. t('header') ."</td></tr>\n"; + $output .= " <tr><td>\n". ($blocks ? $blocks : ' ') ."</td><td style=\"width: 400px;\"> </td></tr>\n"; + $output .= ' <tr><td colspan="2" style="text-align: center;">'. t('footer') ."</td></tr>\n"; $output .= "</table>\n"; - return $output; + print theme('page', $output); } function block_box_get($bid) { - return db_fetch_array(db_query("SELECT * FROM {boxes} WHERE bid = %d", $bid)); + return db_fetch_array(db_query('SELECT * FROM {boxes} WHERE bid = %d', $bid)); +} + +/** + * Menu callback. Displays the block editing form, or saves changes and + * displays the block overview. + */ +function block_box_edit($bid = 0) { + $edit = $_POST['edit']; + $op = $_POST['op']; + + if ($op == t('Save block')) { + drupal_set_message(block_box_save($edit)); + cache_clear_all(); + $output = block_admin_display(); + } + else { + if ($bid) { + $output = block_box_form(block_box_get($bid)); + } + else { + $output = block_box_form(); + } + } + + print theme('page', $output); } function block_box_form($edit = array()) { - $type = array(0 => "HTML", 1 => "PHP"); + $type = array(0 => 'HTML', 1 => 'PHP'); - $form = form_textfield(t("Title"), "title", $edit["title"], 50, 64); - $form .= form_textfield(t("Description"), "info", $edit["info"], 50, 64); - $form .= form_textarea(t("Body"), "body", $edit["body"], 70, 10); - if (user_access("create php content")) { - $form .= form_select(t("Type"), "type", $edit["type"], $type); + $form = form_textfield(t('Title'), 'title', $edit['title'], 50, 64); + $form .= form_textfield(t('Description'), 'info', $edit['info'], 50, 64); + $form .= form_textarea(t('Body'), 'body', $edit['body'], 70, 10); + if (user_access('create php content')) { + $form .= form_select(t('Type'), 'type', $edit['type'], $type); } - if ($edit["bid"]) { - $form .= form_hidden("bid", $edit["bid"]); + if ($edit['bid']) { + $form .= form_hidden('bid', $edit['bid']); } - $form .= form_submit(t("Save block")); + $form .= form_submit(t('Save block')); return form($form); } function block_box_save($edit) { - if (!user_access("create php content")) { - $edit["type"] = 0; + if (!user_access('create php content')) { + $edit['type'] = 0; } - if ($edit["bid"]) { - db_query("UPDATE {boxes} SET title = '%s', body = '%s', info = '%s', type = %d WHERE bid = %d", $edit["title"], $edit["body"], $edit["info"], $edit["type"], $edit["bid"]); - return t("the block has been updated."); + if ($edit['bid']) { + db_query("UPDATE {boxes} SET title = '%s', body = '%s', info = '%s', type = %d WHERE bid = %d", $edit['title'], $edit['body'], $edit['info'], $edit['type'], $edit['bid']); + return t('the block has been updated.'); } else { - db_query("INSERT INTO {boxes} (title, body, info, type) VALUES ('%s', '%s', '%s', %d)", $edit["title"], $edit["body"], $edit["info"], $edit["type"]); - return t("the new block has been added."); + db_query("INSERT INTO {boxes} (title, body, info, type) VALUES ('%s', '%s', '%s', %d)", $edit['title'], $edit['body'], $edit['info'], $edit['type']); + return t('the new block has been added.'); } } -function block_box_delete($bid) { +/** + * Menu callback. Deletes a custom box, then displays the overview page. + */ +function block_box_delete($bid = 0) { if ($bid) { - db_query("DELETE FROM {boxes} WHERE bid = %d", $bid); - return t("the block has been deleted."); + db_query('DELETE FROM {boxes} WHERE bid = %d', $bid); + drupal_set_message(t('the block has been deleted.')); + cache_clear_all(); } + print theme('page', block_admin_display()); } +/** + * Menu callback. Displays the block overview page. + */ function block_admin() { - $op = $_POST["op"]; - $edit = $_POST["edit"]; + $edit = $_POST['edit']; + $op = $_POST['op']; - if (empty($op)) { - $op = arg(3); + if ($op == t('Save blocks')) { + drupal_set_message(block_admin_save($edit)); + cache_clear_all(); } - - switch ($op) { - case "preview": - $output = block_admin_preview(); - break; - case "add": - $output = block_box_form(); - break; - case "edit": - $output = block_box_form(block_box_get(arg(4))); - break; - case "delete": - drupal_set_message(block_box_delete(arg(4))); - cache_clear_all(); - $output .= block_admin_display(); - break; - case t("Save block"): - drupal_set_message(block_box_save($edit)); - cache_clear_all(); - $output .= block_admin_display(); - break; - case t("Save blocks"): - drupal_set_message(block_admin_save($edit)); - cache_clear_all(); - // fall through - default: - $output .= block_admin_display(); - } - - print theme("page", $output); + print theme('page', block_admin_display()); } +/** + * Implementation of hook_user(). + * + * Allow users to decide which custom blocks to display when they visit + * the site. + */ function block_user($type, $edit, &$user) { switch ($type) { - case "edit": - $result = db_query("SELECT * FROM {blocks} WHERE custom = %d ORDER BY module, delta", 1); + case 'edit': + $result = db_query('SELECT * FROM {blocks} WHERE custom = %d ORDER BY module, delta', 1); while ($block = db_fetch_object($result)) { - $data = module_invoke($block->module, "block", "list"); - if ($data[$block->delta]["info"]) { + $data = module_invoke($block->module, 'block', 'list'); + if ($data[$block->delta]['info']) { $form .= form_checkbox($data[$block->delta]['info'], "block][$block->module][$block->delta", 1, isset($user->block[$block->module][$block->delta]) ? $user->block[$block->module][$block->delta] : $block->status); } } @@ -334,9 +358,9 @@ function block_user($type, $edit, &$user) { } break; - case "validate": - if (!$edit["block"]) { - $edit["block"] = array(); + case 'validate': + if (!$edit['block']) { + $edit['block'] = array(); } return $edit; } @@ -361,7 +385,7 @@ function block_list($region) { if (!isset($blocks[$region])) { $blocks[$region] = array(); - $result = db_query("SELECT * FROM {blocks} WHERE (status = '1' OR custom = '1') ". ($region != "all" ? "AND region = %d " : "") ."ORDER BY weight, module", $region == "left" ? 0 : 1); + $result = db_query('SELECT * FROM {blocks} WHERE (status = 1 OR custom = 1) '. ($region != 'all' ? 'AND region = %d ' : '') .'ORDER BY weight, module', $region == 'left' ? 0 : 1); while ($result && ($block = db_fetch_array($result))) { // When the user's account setting is empty, we use the block's regular 'status' (which is the default) @@ -374,7 +398,7 @@ function block_list($region) { ** Check the current throttle status and see if block should be displayed ** based on server load. */ - if (!($block['throttle'] && (module_invoke("throttle", "status") > 4))) { + if (!($block['throttle'] && (module_invoke('throttle', 'status') > 4))) { $block = array_merge($block, module_invoke($block['module'], 'block', 'view', $block['delta'])); } if (isset($block['content']) && $block['content']) { diff --git a/modules/block/block.module b/modules/block/block.module index a2f79c0e7..047e3bf64 100644 --- a/modules/block/block.module +++ b/modules/block/block.module @@ -1,12 +1,13 @@ <?php // $Id$ -function block_help($section = "admin/help#block") { - $output = ""; - +/** + * Implementation of hook_help(). + */ +function block_help($section) { switch ($section) { case 'admin/help#block': - $output = t(" + return t(" <p>Blocks are the boxes visible in the sidebar(s) of your web site. These are usually generated automatically by modules (e.g. recent forum topics), but you can also create your own blocks using either static HTML or dynamic PHP content.</p> <p>The sidebar each block appears in depends on both which theme you're using (some are left-only, some right, some both), and on the settings in block management.</p><p>Whether a block is visible in the first place depends on four things:</p><ul><li>It must have its \"enabled\" box checked in block management.</li><li>If it has its \"custom\" box checked in block management, the user must have chosen to display it in their user preferences.</li><li>If the \"path\" field in block management is set, the visitor must be on a page that matches the path specification (more on this later).</li><li>If the block has its throttle box checked, the user will only see the block if the site throttle level is low.</li></ul> <p>The block management screen also lets you specify the vertical sort-order of the blocks within a sidebar. You do this by assigning a <strong>weight</strong> to each block. Lighter blocks (smaller weight) \"float up\" towards the top of the sidebar. Heavier ones \"sink down\" towards the bottom of it. Once you've positioned things just so, you can preview what the layout will look like in different types of themes by clicking the preview placement link in the menu to the left.</p> @@ -34,31 +35,30 @@ function block_help($section = "admin/help#block") { return t(\"Welcome visitor, ... welcome message goes here ...\"); } </pre></blockquote> -<p>For more in-depth examples, we recommend that you check the existing boxes and use them as a starting point.</p>", array("%pcre" => "http://php.net/pcre/")); - break; +<p>For more in-depth examples, we recommend that you check the existing boxes and use them as a starting point.</p>", array('%pcre' => 'http://php.net/pcre/')); case 'admin/system/modules#description': - $output = t("Controls the boxes that are displayed around the main content."); - break; + return t('Controls the boxes that are displayed around the main content.'); case 'admin/system/block': - $output = t("Blocks are the boxes in the left- and right- side bars of the web site, depending on the choosen theme. They are created by <strong>active</strong> Drupal modules. The 'enabled' checkbox sets the default status of the block. Only enabled blocks are shown. When the 'custom' checkbox is checked, your users can show or hide the block using their account settings. In that case, the 'enabled' checkbox signifies the block's default status. You can assign the block's placement by giving it a region and a weight. The region specifies which side of the page the block is on, and the weight sorts blocks within a region. Lighter (smaller weight value) blocks \"float up\" towards the top of the page. The path setting lets you define which pages you want a block to be shown on. You can also create your own blocks, where you specify the content of the block rather than its being generated by a module (you can even use PHP in these). You can create one of these by clicking the <a href=\"%createblock\">new block</a> link in the menu to the left. Edit and delete links will become active below for these admin-defined blocks. Blocks can automatically be temporarily disabled to reduce server load when your site becomes extremely busy by checking throttle. The auto-throttle functionality must be enabled on the <a href=\"%throttle\">throttle configuration page</a> after having enabled the throttle module.", array("%createblock" => url("admin/system/block/add"), "%throttle" => url("admin/system/modules/throttle"))); - break; + return t("Blocks are the boxes in the left- and right- side bars of the web site, depending on the chosen theme. They are created by <strong>active</strong> Drupal modules. The \"enabled\" checkbox sets the default status of the block. Only enabled blocks are shown. When the \"custom\" checkbox is checked, your users can show or hide the block using their account settings. In that case, the 'enabled' checkbox signifies the block's default status. You can assign the block's placement by giving it a region and a weight. The region specifies which side of the page the block is on, and the weight sorts blocks within a region. Lighter (smaller weight value) blocks \"float up\" towards the top of the page. The path setting lets you define which pages you want a block to be shown on. You can also create your own blocks, where you specify the content of the block rather than its being generated by a module (you can even use PHP in these). You can create one of these by clicking the <a href=\"%createblock\">new block</a> link in the menu to the left. Edit and delete links will become active below for these admin-defined blocks. Blocks can automatically be temporarily disabled to reduce server load when your site becomes extremely busy by checking throttle. The auto-throttle functionality must be enabled on the <a href=\"%throttle\">throttle configuration page</a> after having enabled the throttle module.", array('%createblock' => url('admin/system/block/add'), '%throttle' => url('admin/system/modules/throttle'))); case 'admin/system/block/add': - $output = t("Here you can create a new block. Once you have created this block you must make it active, and give it a place on the page using <a href=\"%overview\">blocks</a>. The title is used when displaying the block. The description is used in the \"block\" column on the <a href=\"%overview\">blocks</a> page. If you are going to place PHP code in the block, and you have <strong>create php content</strong> permission (see the <a href=\"%permission\">permissions</a> page) you <strong>must</strong> change the type to PHP to make your code active.", array("%overview" => url("admin/system/block"), "%permission" => url("admin/user/permission"))); - break; + return t("Here you can create a new block. Once you have created this block you must make it active and give it a place on the page using <a href=\"%overview\">blocks</a>. The title is used when displaying the block. The description is used in the \"block\" column on the <a href=\"%overview\">blocks</a> page. If you are going to place PHP code in the block, and you have the <strong>create php content</strong> permission (see the <a href=\"%permission\">permissions</a> page), you <strong>must</strong> change the type to PHP to make your code active.", array('%overview' => url('admin/system/block'), '%permission' => url('admin/user/permission'))); case 'admin/system/block/preview': - $output = t("This page show you the placement of your blocks in different themes types. The numbers are the weight of each block, which is used to sort them within the sidebars."); - break; + return t('This page shows you the placement of your blocks in different theme types. The numbers are the weights of each block, which are used to sort them within the sidebars.'); } - - return $output; } +/** + * Menu callback. Presents the block-specific information from admin/help. + */ function block_help_page() { - print theme("page", block_help()); + print theme('page', block_help('admin/help#block')); } +/** + * Implementation of hook_perm(). + */ function block_perm() { - return array("administer blocks"); + return array('administer blocks'); } /** @@ -67,24 +67,31 @@ function block_perm() { function block_link($type) { if ($type == 'system') { menu('admin/system/block', t('blocks'), user_access('administer blocks') ? 'block_admin' : MENU_DENIED, 3); - menu('admin/system/block/add', t('new block'), user_access('administer blocks') ? 'block_admin' : MENU_DENIED, 2); - menu('admin/system/block/preview', t('preview placement'), user_access('administer blocks') ? 'block_admin' : MENU_DENIED, 3); + menu('admin/system/block/add', t('new block'), user_access('administer blocks') ? 'block_box_edit' : MENU_DENIED, 2); + menu('admin/system/block/edit', t('edit block'), user_access('administer blocks') ? 'block_box_edit' : MENU_DENIED, 0, MENU_HIDE, MENU_LOCKED); + menu('admin/system/block/delete', t('delete block'), user_access('administer blocks') ? 'block_box_delete' : MENU_DENIED, 0, MENU_HIDE, MENU_LOCKED); + menu('admin/system/block/preview', t('preview placement'), user_access('administer blocks') ? 'block_admin_preview' : MENU_DENIED, 3); menu('admin/system/block/help', t('help'), user_access('administer blocks') ? 'block_help_page' : MENU_DENIED, 9); } } -function block_block($op = "list", $delta = 0) { - if ($op == "list") { - $result = db_query("SELECT bid, title, info FROM {boxes} ORDER BY title"); +/** + * Implementation of hook_block(). + * + * Generates the administrator-defined blocks for display. + */ +function block_block($op = 'list', $delta = 0) { + if ($op == 'list') { + $result = db_query('SELECT bid, title, info FROM {boxes} ORDER BY title'); while ($block = db_fetch_object($result)) { - $blocks[$block->bid]["info"] = $block->info; + $blocks[$block->bid]['info'] = $block->info; } return $blocks; } else { - $block = db_fetch_object(db_query("SELECT * FROM {boxes} WHERE bid = %d", $delta)); - $data["subject"] = $block->title; - $data["content"] = ($block->type == 1) ? eval($block->body) : $block->body; + $block = db_fetch_object(db_query('SELECT * FROM {boxes} WHERE bid = %d', $delta)); + $data['subject'] = $block->title; + $data['content'] = ($block->type == 1) ? eval($block->body) : $block->body; return $data; } } @@ -93,52 +100,53 @@ function block_admin_save($edit) { foreach ($edit as $module => $blocks) { foreach ($blocks as $delta => $block) { db_query("UPDATE {blocks} SET region = %d, status = %d, custom = %d, path = '%s', weight = %d, throttle = %d WHERE module = '%s' AND delta = '%s'", - $block["region"], $block["status"], $block["custom"], $block["path"], $block["weight"], $block["throttle"], $module, $delta); + $block['region'], $block['status'], $block['custom'], $block['path'], $block['weight'], $block['throttle'], $module, $delta); } } - return t("the block settings have been updated."); + return t('the block settings have been updated.'); } /** - * update blocks db table with blocks currently exported by modules + * Update the 'blocks' DB table with the blocks currently exported by modules. * * @param $order_by php <a * href="http://www.php.net/manual/en/function.array-multisort.php">array_multisort()</a> * style sort ordering, eg. "weight", SORT_ASC, SORT_STRING. * - * @return blocks currently exported by modules, sorted by $order_by + * @return + * Blocks currently exported by modules, sorted by $order_by. */ -function _block_rehash($order_by = array("weight")) { - $result = db_query("SELECT * FROM {blocks} "); +function _block_rehash($order_by = array('weight')) { + $result = db_query('SELECT * FROM {blocks} '); while ($old_block = db_fetch_object($result)) { $old_blocks[$old_block->module][$old_block->delta] = $old_block; } - db_query("DELETE FROM {blocks} "); + db_query('DELETE FROM {blocks} '); foreach (module_list() as $module) { - $module_blocks = module_invoke($module, "block", "list"); + $module_blocks = module_invoke($module, 'block', 'list'); if ($module_blocks) { foreach ($module_blocks as $delta => $block) { - $block["module"] = $module; - $block["delta"] = $delta; + $block['module'] = $module; + $block['delta'] = $delta; if ($old_blocks[$module][$delta]) { - $block["status"] = $old_blocks[$module][$delta]->status; - $block["weight"] = $old_blocks[$module][$delta]->weight; - $block["region"] = $old_blocks[$module][$delta]->region; - $block["path"] = $old_blocks[$module][$delta]->path; - $block["custom"] = $old_blocks[$module][$delta]->custom; - $block["throttle"] = $old_blocks[$module][$delta]->throttle; + $block['status'] = $old_blocks[$module][$delta]->status; + $block['weight'] = $old_blocks[$module][$delta]->weight; + $block['region'] = $old_blocks[$module][$delta]->region; + $block['path'] = $old_blocks[$module][$delta]->path; + $block['custom'] = $old_blocks[$module][$delta]->custom; + $block['throttle'] = $old_blocks[$module][$delta]->throttle; } else { - $block["status"] = $block["weight"] = $block["region"] = $block["custom"] = 0; - $block["path"] = ""; + $block['status'] = $block['weight'] = $block['region'] = $block['custom'] = 0; + $block['path'] = ''; } // reinsert blocks into table db_query("INSERT INTO {blocks} (module, delta, status, weight, region, path, custom, throttle) VALUES ('%s', '%s', %d, %d, %d, '%s', %d, %d)", - $block["module"], $block["delta"], $block["status"], $block["weight"], $block["region"], $block["path"], $block["custom"], $block["throttle"]); + $block['module'], $block['delta'], $block['status'], $block['weight'], $block['region'], $block['path'], $block['custom'], $block['throttle']); $blocks[] = $block; @@ -154,177 +162,193 @@ function _block_rehash($order_by = array("weight")) { return $blocks; } +/** + * Prepare the main block administration form. + */ function block_admin_display() { $blocks = _block_rehash(); - $header = array(t("block"), t("enabled"), t("custom"), t("throttle"), t("weight"), t("region"), t("path"), array("data" => t("operations"), "colspan" => 2)); + $header = array(t('block'), t('enabled'), t('custom'), t('throttle'), t('weight'), t('region'), t('path'), array('data' => t('operations'), 'colspan' => 2)); foreach ($blocks as $block) { - if ($block["module"] == "block") { - $edit = l(t("edit"), "admin/system/block/edit/". $block["delta"]); - $delete = l(t("delete"), "admin/system/block/delete/". $block["delta"]); + if ($block['module'] == 'block') { + $edit = l(t('edit'), 'admin/system/block/edit/'. $block['delta']); + $delete = l(t('delete'), 'admin/system/block/delete/'. $block['delta']); } else { - $edit = ""; - $delete = ""; + $edit = ''; + $delete = ''; } - $rows[] = array($block["info"], array("data" => form_checkbox(NULL, $block["module"] ."][". $block["delta"] ."][status", 1, $block["status"]), "align" => "center"), array("data" => form_checkbox(NULL, $block["module"] ."][". $block["delta"] ."][custom", 1, $block["custom"]), "align" => "center"), array("data" => form_checkbox(NULL, $block["module"] ."][". $block["delta"] ."][throttle", 1, $block["throttle"], NULL, module_exist('throttle') ? NULL : array("disabled" => "disabled")), "align" => "center"), form_weight(NULL, $block["module"] ."][". $block["delta"] ."][weight", $block["weight"]), form_radios(NULL, $block["module"] ."][". $block["delta"] ."][region", $block["region"], array(t("left"), t("right"))), form_textfield(NULL, $block["module"] ."][". $block["delta"] ."][path", $block["path"], 10, 255), + $rows[] = array($block['info'], array('data' => form_checkbox(NULL, $block['module'] .']['. $block['delta'] .'][status', 1, $block['status']), 'align' => 'center'), array('data' => form_checkbox(NULL, $block['module'] .']['. $block['delta'] .'][custom', 1, $block['custom']), 'align' => 'center'), array('data' => form_checkbox(NULL, $block['module'] .']['. $block['delta'] .'][throttle', 1, $block['throttle'], NULL, module_exist('throttle') ? NULL : array('disabled' => 'disabled')), 'align' => 'center'), form_weight(NULL, $block['module'] .']['. $block['delta'] .'][weight', $block['weight']), form_radios(NULL, $block['module'] .']['. $block['delta'] .'][region', $block['region'], array(t('left'), t('right'))), form_textfield(NULL, $block['module'] .']['. $block['delta'] .'][path', $block['path'], 10, 255), $edit, $delete); } - $output = theme("table", $header, $rows); - $output .= form_submit(t("Save blocks")); + $output = theme('table', $header, $rows); + $output .= form_submit(t('Save blocks')); - return form($output); + return form($output, 'post', url('admin/system/block')); } +/** + * Menu callback. Displays the block layout as it will appear when themed. + */ function block_admin_preview() { - - $result = db_query("SELECT * FROM {blocks} WHERE status > 0 AND region = 0 ORDER BY weight"); + $result = db_query('SELECT * FROM {blocks} WHERE status > 0 AND region = 0 ORDER BY weight'); $lblocks .= "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\">\n"; while ($block = db_fetch_object($result)) { - $block_data = module_invoke($block->module, "block", "list"); - $name = $block_data[$block->delta]["info"]; - $lblocks .= " <tr><td>". ($block->status == 2 ? "<strong>$name</strong>" : $name) ."</td><td>$block->weight</td></tr>\n"; + $block_data = module_invoke($block->module, 'block', 'list'); + $name = $block_data[$block->delta]['info']; + $lblocks .= ' <tr><td>'. ($block->status == 2 ? "<strong>$name</strong>" : $name) ."</td><td>$block->weight</td></tr>\n"; } $lblocks .= "</table>\n"; - $result = db_query("SELECT * FROM {blocks} WHERE status > 0 AND region = 1 ORDER BY weight"); + $result = db_query('SELECT * FROM {blocks} WHERE status > 0 AND region = 1 ORDER BY weight'); $rblocks .= "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\">\n"; while ($block = db_fetch_object($result)) { - $block_data = module_invoke($block->module, "block", "list"); - $name = $block_data[$block->delta]["info"]; - $rblocks .= " <tr><td>". ($block->status == 2 ? "<strong>$name</strong>" : $name) ."</td><td>$block->weight</td></tr>\n"; + $block_data = module_invoke($block->module, 'block', 'list'); + $name = $block_data[$block->delta]['info']; + $rblocks .= ' <tr><td>'. ($block->status == 2 ? "<strong>$name</strong>" : $name) ."</td><td>$block->weight</td></tr>\n"; } $rblocks .= "</table>\n"; - $output .= "<h3>". t("Themes with both left and right sidebars") .":</h3>\n"; + $output .= '<h3>'. t('Themes with both left and right sidebars') .":</h3>\n"; $output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">\n"; - $output .= " <tr><td colspan=\"3\" style=\"text-align: center;\">". t("header") ."</td></tr>\n"; - $output .= " <tr><td>\n". ($lblocks ? $lblocks : " ") ."</td><td style=\"width: 300px;\"> </td><td>\n". ($rblocks ? $rblocks : " ") ."</td></tr>\n"; - $output .= " <tr><td colspan=\"3\" style=\"text-align: center;\">". t("footer") ."</td></tr>\n"; + $output .= ' <tr><td colspan="3" style="text-align: center;">'. t('header') ."</td></tr>\n"; + $output .= " <tr><td>\n". ($lblocks ? $lblocks : ' ') ."</td><td style=\"width: 300px;\"> </td><td>\n". ($rblocks ? $rblocks : ' ') ."</td></tr>\n"; + $output .= ' <tr><td colspan="3" style="text-align: center;">'. t('footer') ."</td></tr>\n"; $output .= "</table>\n"; - $result = db_query("SELECT * FROM {blocks} WHERE status > 0 ORDER BY weight"); + $result = db_query('SELECT * FROM {blocks} WHERE status > 0 ORDER BY weight'); $blocks .= "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\">\n"; while ($block = db_fetch_object($result)) { - $block_data = module_invoke($block->module, "block", "list"); - $name = $block_data[$block->delta]["info"]; - $blocks .= " <tr><td>". ($block->status == 2 ? "<strong>$name</strong>" : $name) ."</td><td>$block->weight</td></tr>\n"; + $block_data = module_invoke($block->module, 'block', 'list'); + $name = $block_data[$block->delta]['info']; + $blocks .= ' <tr><td>'. ($block->status == 2 ? "<strong>$name</strong>" : $name) ."</td><td>$block->weight</td></tr>\n"; } $blocks .= "</table>\n"; - $output .= "<h3>". t("Themes with right-sidebar only") .":</h3>\n"; + $output .= '<h3>'. t('Themes with right sidebar only') .":</h3>\n"; $output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">\n"; - $output .= " <tr><td colspan=\"2\" style=\"text-align: center;\">". t("header") ."</td></tr>\n"; - $output .= " <tr><td style=\"width: 400px;\"> </td><td>\n". ($blocks ? $blocks : " ") ."</td></tr>\n"; - $output .= " <tr><td colspan=\"2\" style=\"text-align: center;\">". t("footer") ."</td></tr>\n"; + $output .= ' <tr><td colspan="2" style="text-align: center;">'. t('header') ."</td></tr>\n"; + $output .= " <tr><td style=\"width: 400px;\"> </td><td>\n". ($blocks ? $blocks : ' ') ."</td></tr>\n"; + $output .= ' <tr><td colspan="2" style="text-align: center;">'. t('footer') ."</td></tr>\n"; $output .= "</table>\n"; - $output .= "<h3>". t("Themes with left-sidebar only") .":</h3>\n"; + $output .= '<h3>'. t('Themes with left sidebar only') .":</h3>\n"; $output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">\n"; - $output .= " <tr><td colspan=\"2\" style=\"text-align: center;\">". t("header") ."</td></tr>\n"; - $output .= " <tr><td>\n". ($blocks ? $blocks : " ") ."</td><td style=\"width: 400px;\"> </td></tr>\n"; - $output .= " <tr><td colspan=\"2\" style=\"text-align: center;\">". t("footer") ."</td></tr>\n"; + $output .= ' <tr><td colspan="2" style="text-align: center;">'. t('header') ."</td></tr>\n"; + $output .= " <tr><td>\n". ($blocks ? $blocks : ' ') ."</td><td style=\"width: 400px;\"> </td></tr>\n"; + $output .= ' <tr><td colspan="2" style="text-align: center;">'. t('footer') ."</td></tr>\n"; $output .= "</table>\n"; - return $output; + print theme('page', $output); } function block_box_get($bid) { - return db_fetch_array(db_query("SELECT * FROM {boxes} WHERE bid = %d", $bid)); + return db_fetch_array(db_query('SELECT * FROM {boxes} WHERE bid = %d', $bid)); +} + +/** + * Menu callback. Displays the block editing form, or saves changes and + * displays the block overview. + */ +function block_box_edit($bid = 0) { + $edit = $_POST['edit']; + $op = $_POST['op']; + + if ($op == t('Save block')) { + drupal_set_message(block_box_save($edit)); + cache_clear_all(); + $output = block_admin_display(); + } + else { + if ($bid) { + $output = block_box_form(block_box_get($bid)); + } + else { + $output = block_box_form(); + } + } + + print theme('page', $output); } function block_box_form($edit = array()) { - $type = array(0 => "HTML", 1 => "PHP"); + $type = array(0 => 'HTML', 1 => 'PHP'); - $form = form_textfield(t("Title"), "title", $edit["title"], 50, 64); - $form .= form_textfield(t("Description"), "info", $edit["info"], 50, 64); - $form .= form_textarea(t("Body"), "body", $edit["body"], 70, 10); - if (user_access("create php content")) { - $form .= form_select(t("Type"), "type", $edit["type"], $type); + $form = form_textfield(t('Title'), 'title', $edit['title'], 50, 64); + $form .= form_textfield(t('Description'), 'info', $edit['info'], 50, 64); + $form .= form_textarea(t('Body'), 'body', $edit['body'], 70, 10); + if (user_access('create php content')) { + $form .= form_select(t('Type'), 'type', $edit['type'], $type); } - if ($edit["bid"]) { - $form .= form_hidden("bid", $edit["bid"]); + if ($edit['bid']) { + $form .= form_hidden('bid', $edit['bid']); } - $form .= form_submit(t("Save block")); + $form .= form_submit(t('Save block')); return form($form); } function block_box_save($edit) { - if (!user_access("create php content")) { - $edit["type"] = 0; + if (!user_access('create php content')) { + $edit['type'] = 0; } - if ($edit["bid"]) { - db_query("UPDATE {boxes} SET title = '%s', body = '%s', info = '%s', type = %d WHERE bid = %d", $edit["title"], $edit["body"], $edit["info"], $edit["type"], $edit["bid"]); - return t("the block has been updated."); + if ($edit['bid']) { + db_query("UPDATE {boxes} SET title = '%s', body = '%s', info = '%s', type = %d WHERE bid = %d", $edit['title'], $edit['body'], $edit['info'], $edit['type'], $edit['bid']); + return t('the block has been updated.'); } else { - db_query("INSERT INTO {boxes} (title, body, info, type) VALUES ('%s', '%s', '%s', %d)", $edit["title"], $edit["body"], $edit["info"], $edit["type"]); - return t("the new block has been added."); + db_query("INSERT INTO {boxes} (title, body, info, type) VALUES ('%s', '%s', '%s', %d)", $edit['title'], $edit['body'], $edit['info'], $edit['type']); + return t('the new block has been added.'); } } -function block_box_delete($bid) { +/** + * Menu callback. Deletes a custom box, then displays the overview page. + */ +function block_box_delete($bid = 0) { if ($bid) { - db_query("DELETE FROM {boxes} WHERE bid = %d", $bid); - return t("the block has been deleted."); + db_query('DELETE FROM {boxes} WHERE bid = %d', $bid); + drupal_set_message(t('the block has been deleted.')); + cache_clear_all(); } + print theme('page', block_admin_display()); } +/** + * Menu callback. Displays the block overview page. + */ function block_admin() { - $op = $_POST["op"]; - $edit = $_POST["edit"]; + $edit = $_POST['edit']; + $op = $_POST['op']; - if (empty($op)) { - $op = arg(3); + if ($op == t('Save blocks')) { + drupal_set_message(block_admin_save($edit)); + cache_clear_all(); } - - switch ($op) { - case "preview": - $output = block_admin_preview(); - break; - case "add": - $output = block_box_form(); - break; - case "edit": - $output = block_box_form(block_box_get(arg(4))); - break; - case "delete": - drupal_set_message(block_box_delete(arg(4))); - cache_clear_all(); - $output .= block_admin_display(); - break; - case t("Save block"): - drupal_set_message(block_box_save($edit)); - cache_clear_all(); - $output .= block_admin_display(); - break; - case t("Save blocks"): - drupal_set_message(block_admin_save($edit)); - cache_clear_all(); - // fall through - default: - $output .= block_admin_display(); - } - - print theme("page", $output); + print theme('page', block_admin_display()); } +/** + * Implementation of hook_user(). + * + * Allow users to decide which custom blocks to display when they visit + * the site. + */ function block_user($type, $edit, &$user) { switch ($type) { - case "edit": - $result = db_query("SELECT * FROM {blocks} WHERE custom = %d ORDER BY module, delta", 1); + case 'edit': + $result = db_query('SELECT * FROM {blocks} WHERE custom = %d ORDER BY module, delta', 1); while ($block = db_fetch_object($result)) { - $data = module_invoke($block->module, "block", "list"); - if ($data[$block->delta]["info"]) { + $data = module_invoke($block->module, 'block', 'list'); + if ($data[$block->delta]['info']) { $form .= form_checkbox($data[$block->delta]['info'], "block][$block->module][$block->delta", 1, isset($user->block[$block->module][$block->delta]) ? $user->block[$block->module][$block->delta] : $block->status); } } @@ -334,9 +358,9 @@ function block_user($type, $edit, &$user) { } break; - case "validate": - if (!$edit["block"]) { - $edit["block"] = array(); + case 'validate': + if (!$edit['block']) { + $edit['block'] = array(); } return $edit; } @@ -361,7 +385,7 @@ function block_list($region) { if (!isset($blocks[$region])) { $blocks[$region] = array(); - $result = db_query("SELECT * FROM {blocks} WHERE (status = '1' OR custom = '1') ". ($region != "all" ? "AND region = %d " : "") ."ORDER BY weight, module", $region == "left" ? 0 : 1); + $result = db_query('SELECT * FROM {blocks} WHERE (status = 1 OR custom = 1) '. ($region != 'all' ? 'AND region = %d ' : '') .'ORDER BY weight, module', $region == 'left' ? 0 : 1); while ($result && ($block = db_fetch_array($result))) { // When the user's account setting is empty, we use the block's regular 'status' (which is the default) @@ -374,7 +398,7 @@ function block_list($region) { ** Check the current throttle status and see if block should be displayed ** based on server load. */ - if (!($block['throttle'] && (module_invoke("throttle", "status") > 4))) { + if (!($block['throttle'] && (module_invoke('throttle', 'status') > 4))) { $block = array_merge($block, module_invoke($block['module'], 'block', 'view', $block['delta'])); } if (isset($block['content']) && $block['content']) { |