summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2008-12-18 03:58:24 +0000
committerDries Buytaert <dries@buytaert.net>2008-12-18 03:58:24 +0000
commit22570fd6f583cde7393d20abfa0da53bd771a4bf (patch)
treedd5555513b544b7effb124302408e3bae5c2aec1 /modules
parent8d7eeb0df6c7e7870106f62f07c94a0d3aa95d9d (diff)
downloadbrdo-22570fd6f583cde7393d20abfa0da53bd771a4bf.tar.gz
brdo-22570fd6f583cde7393d20abfa0da53bd771a4bf.tar.bz2
- Patch #345866 by alexanderplas: remove from hook_block() -- addendum patch.
Diffstat (limited to 'modules')
-rw-r--r--modules/aggregator/aggregator.module135
-rw-r--r--modules/statistics/statistics.module95
2 files changed, 124 insertions, 106 deletions
diff --git a/modules/aggregator/aggregator.module b/modules/aggregator/aggregator.module
index d76e1fee4..d2826a587 100644
--- a/modules/aggregator/aggregator.module
+++ b/modules/aggregator/aggregator.module
@@ -294,76 +294,87 @@ function aggregator_cron() {
}
/**
- * Implementation of hook_block().
+ * Implementation of hook_block_list().
+ */
+function aggregator_block_list() {
+ $block = array();
+ $result = db_query('SELECT cid, title FROM {aggregator_category} ORDER BY title');
+ foreach ($result as $category) {
+ $block['category-' . $category->cid]['info'] = t('!title category latest items', array('!title' => $category->title));
+ }
+ $result = db_query('SELECT fid, title FROM {aggregator_feed} WHERE block <> 0 ORDER BY fid');
+ foreach ($result as $feed) {
+ $block['feed-' . $feed->fid]['info'] = t('!title feed latest items', array('!title' => $feed->title));
+ }
+ return $block;
+}
+
+/**
+ * Implementation of hook_block_configure().
+ */
+function aggregator_block_configure($delta = '') {
+ list($type, $id) = explode('-', $delta);
+ if ($type == 'category') {
+ $value = db_query('SELECT block FROM {aggregator_category} WHERE cid = :cid', array(':cid' => $id))->fetchField();
+ $form['block'] = array(
+ '#type' => 'select',
+ '#title' => t('Number of news items in block'),
+ '#default_value' => $value,
+ '#options' => drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20))
+ );
+ return $form;
+ }
+}
+
+/**
+ * Implementation of hook_block_save().
+ */
+function aggregator_block_save($delta = '', $edit = array()) {
+ list($type, $id) = explode('-', $delta);
+ if ($type == 'category') {
+ db_merge('aggregator_category')
+ ->key(array('cid' => $id))
+ ->fields(array('block' => $edit['block']))
+ ->execute();
+ }
+}
+
+/**
+ * Implementation of hook_block_view().
*
* Generates blocks for the latest news items in each category and feed.
*/
-function aggregator_block($op = 'list', $delta = '', $edit = array()) {
+function aggregator_block_view($delta = '') {
if (user_access('access news feeds')) {
- if ($op == 'list') {
- $result = db_query('SELECT cid, title FROM {aggregator_category} ORDER BY title');
- foreach ($result as $category) {
- $block['category-' . $category->cid]['info'] = t('!title category latest items', array('!title' => $category->title));
- }
- $result = db_query('SELECT fid, title FROM {aggregator_feed} WHERE block <> 0 ORDER BY fid');
- foreach ($result as $feed) {
- $block['feed-' . $feed->fid]['info'] = t('!title feed latest items', array('!title' => $feed->title));
- }
- }
- elseif ($op == 'configure') {
- list($type, $id) = explode('-', $delta);
- if ($type == 'category') {
- $value = db_query('SELECT block FROM {aggregator_category} WHERE cid = :cid', array(':cid' => $id))->fetchField();
- $form['block'] = array(
- '#type' => 'select',
- '#title' => t('Number of news items in block'),
- '#default_value' => $value,
- '#options' => drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20))
- );
- return $form;
- }
+ $block = array();
+ list($type, $id) = explode('-', $delta);
+ switch ($type) {
+ case 'feed':
+ if ($feed = db_query('SELECT fid, title, block FROM {aggregator_feed} WHERE block <> 0 AND fid = :fid', array(':fid' => $id))->fetchObject()) {
+ $block['subject'] = check_plain($feed->title);
+ $result = db_query_range("SELECT * FROM {aggregator_item} WHERE fid = :fid ORDER BY timestamp DESC, iid DESC", array(':fid' => $id), 0, $feed->block);
+ $read_more = theme('more_link', url('aggregator/sources/' . $feed->fid), t("View this feed's recent news."));
+ }
+ break;
+
+ case 'category':
+ if ($category = db_query('SELECT cid, title, block FROM {aggregator_category} WHERE cid = :cid', array(':cid' => $id))->fetchObject()) {
+ $block['subject'] = check_plain($category->title);
+ $result = db_query_range('SELECT i.* FROM {aggregator_category_item} ci LEFT JOIN {aggregator_item} i ON ci.iid = i.iid WHERE ci.cid = :cid ORDER BY i.timestamp DESC, i.iid DESC', array(':cid' => $category->cid), 0, $category->block);
+ $read_more = theme('more_link', url('aggregator/categories/' . $category->cid), t("View this category's recent news."));
+ }
+ break;
}
- elseif ($op == 'save') {
- list($type, $id) = explode('-', $delta);
- if ($type == 'category') {
- db_merge('aggregator_category')
- ->key(array('cid' => $id))
- ->fields(array('block' => $edit['block']))
- ->execute();
- }
+ $items = array();
+ foreach ($result as $item) {
+ $items[] = theme('aggregator_block_item', $item);
}
- elseif ($op == 'view') {
- list($type, $id) = explode('-', $delta);
- switch ($type) {
- case 'feed':
- if ($feed = db_query('SELECT fid, title, block FROM {aggregator_feed} WHERE block <> 0 AND fid = :fid', array(':fid' => $id))->fetchObject()) {
- $block['subject'] = check_plain($feed->title);
- $result = db_query_range("SELECT * FROM {aggregator_item} WHERE fid = :fid ORDER BY timestamp DESC, iid DESC", array(':fid' => $id), 0, $feed->block);
- $read_more = theme('more_link', url('aggregator/sources/' . $feed->fid), t("View this feed's recent news."));
- }
- break;
-
- case 'category':
- if ($category = db_query('SELECT cid, title, block FROM {aggregator_category} WHERE cid = :cid', array(':cid' => $id))->fetchObject()) {
- $block['subject'] = check_plain($category->title);
- $result = db_query_range('SELECT i.* FROM {aggregator_category_item} ci LEFT JOIN {aggregator_item} i ON ci.iid = i.iid WHERE ci.cid = :cid ORDER BY i.timestamp DESC, i.iid DESC', array(':cid' => $category->cid), 0, $category->block);
- $read_more = theme('more_link', url('aggregator/categories/' . $category->cid), t("View this category's recent news."));
- }
- break;
- }
- $items = array();
- foreach ($result as $item) {
- $items[] = theme('aggregator_block_item', $item);
- }
- // Only display the block if there are items to show.
- if (count($items) > 0) {
- $block['content'] = theme('item_list', $items) . $read_more;
- }
- }
- if (isset($block)) {
- return $block;
+ // Only display the block if there are items to show.
+ if (count($items) > 0) {
+ $block['content'] = theme('item_list', $items) . $read_more;
}
+ return $block;
}
}
diff --git a/modules/statistics/statistics.module b/modules/statistics/statistics.module
index 98dab7531..d90c257d2 100644
--- a/modules/statistics/statistics.module
+++ b/modules/statistics/statistics.module
@@ -252,58 +252,65 @@ function statistics_get($nid) {
}
/**
- * Implementation of hook_block().
+ * Implementation of hook_block_list().
*/
-function statistics_block($op = 'list', $delta = '', $edit = array()) {
- switch ($op) {
- case 'list':
- if (variable_get('statistics_count_content_views', 0)) {
- $blocks['popular']['info'] = t('Popular content');
- // Too dynamic to cache.
- $blocks['popular']['cache'] = BLOCK_NO_CACHE;
- return $blocks;
- }
- break;
+function statistics_block_list() {
+ if (variable_get('statistics_count_content_views', 0)) {
+ $blocks['popular']['info'] = t('Popular content');
+ // Too dynamic to cache.
+ $blocks['popular']['cache'] = BLOCK_NO_CACHE;
+ return $blocks;
+ }
+}
- case 'configure':
- // Popular content block settings
- $numbers = array('0' => t('Disabled')) + drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 40));
- $form['statistics_block_top_day_num'] = array('#type' => 'select', '#title' => t("Number of day's top views to display"), '#default_value' => variable_get('statistics_block_top_day_num', 0), '#options' => $numbers, '#description' => t('How many content items to display in "day" list.'));
- $form['statistics_block_top_all_num'] = array('#type' => 'select', '#title' => t('Number of all time views to display'), '#default_value' => variable_get('statistics_block_top_all_num', 0), '#options' => $numbers, '#description' => t('How many content items to display in "all time" list.'));
- $form['statistics_block_top_last_num'] = array('#type' => 'select', '#title' => t('Number of most recent views to display'), '#default_value' => variable_get('statistics_block_top_last_num', 0), '#options' => $numbers, '#description' => t('How many content items to display in "recently viewed" list.'));
- return $form;
+/**
+ * Implementation of hook_block_configure().
+ */
+function statistics_block_configure($delta = '') {
+ // Popular content block settings
+ $numbers = array('0' => t('Disabled')) + drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 40));
+ $form['statistics_block_top_day_num'] = array('#type' => 'select', '#title' => t("Number of day's top views to display"), '#default_value' => variable_get('statistics_block_top_day_num', 0), '#options' => $numbers, '#description' => t('How many content items to display in "day" list.'));
+ $form['statistics_block_top_all_num'] = array('#type' => 'select', '#title' => t('Number of all time views to display'), '#default_value' => variable_get('statistics_block_top_all_num', 0), '#options' => $numbers, '#description' => t('How many content items to display in "all time" list.'));
+ $form['statistics_block_top_last_num'] = array('#type' => 'select', '#title' => t('Number of most recent views to display'), '#default_value' => variable_get('statistics_block_top_last_num', 0), '#options' => $numbers, '#description' => t('How many content items to display in "recently viewed" list.'));
+ return $form;
+}
- case 'save':
- variable_set('statistics_block_top_day_num', $edit['statistics_block_top_day_num']);
- variable_set('statistics_block_top_all_num', $edit['statistics_block_top_all_num']);
- variable_set('statistics_block_top_last_num', $edit['statistics_block_top_last_num']);
- break;
+/**
+ * Implementation of hook_block_save().
+ */
+function statistics_block_save($delta = '', $edit = array()) {
+ variable_set('statistics_block_top_day_num', $edit['statistics_block_top_day_num']);
+ variable_set('statistics_block_top_all_num', $edit['statistics_block_top_all_num']);
+ variable_set('statistics_block_top_last_num', $edit['statistics_block_top_last_num']);
+}
- case 'view':
- if (user_access('access content')) {
- $content = array();
+/**
+ * Implementation of hook_block_view().
+ */
+function statistics_block_view($delta = '') {
+ if (user_access('access content')) {
+ $content = array();
- $daytop = variable_get('statistics_block_top_day_num', 0);
- if ($daytop && ($result = statistics_title_list('daycount', $daytop)) && ($node_title_list = node_title_list($result, t("Today's:")))) {
- $content[] = $node_title_list;
- }
+ $daytop = variable_get('statistics_block_top_day_num', 0);
+ if ($daytop && ($result = statistics_title_list('daycount', $daytop)) && ($node_title_list = node_title_list($result, t("Today's:")))) {
+ $content[] = $node_title_list;
+ }
- $alltimetop = variable_get('statistics_block_top_all_num', 0);
- if ($alltimetop && ($result = statistics_title_list('totalcount', $alltimetop)) && ($node_title_list = node_title_list($result, t('All time:')))) {
- $content[] = $node_title_list;
- }
+ $alltimetop = variable_get('statistics_block_top_all_num', 0);
+ if ($alltimetop && ($result = statistics_title_list('totalcount', $alltimetop)) && ($node_title_list = node_title_list($result, t('All time:')))) {
+ $content[] = $node_title_list;
+ }
- $lasttop = variable_get('statistics_block_top_last_num', 0);
- if ($lasttop && ($result = statistics_title_list('timestamp', $lasttop)) && ($node_title_list = node_title_list($result, t('Last viewed:')))) {
- $content[] = $node_title_list;
- }
+ $lasttop = variable_get('statistics_block_top_last_num', 0);
+ if ($lasttop && ($result = statistics_title_list('timestamp', $lasttop)) && ($node_title_list = node_title_list($result, t('Last viewed:')))) {
+ $content[] = $node_title_list;
+ }
- if (count($content)) {
- $block['content'] = implode('<br />', $content);
- $block['subject'] = t('Popular content');
- return $block;
- }
- }
+ if (count($content)) {
+ $block['content'] = implode('<br />', $content);
+ $block['subject'] = t('Popular content');
+ return $block;
+ }
}
}