Commit 22570fd6 authored by Dries's avatar Dries

- Patch #345866 by alexanderplas: remove from hook_block() -- addendum patch.

parent 8d7eeb0d
......@@ -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;
}
}
......
......@@ -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;
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment