- Patch 7897: don't show blocks if they have no content

4.7.x
Dries Buytaert 2005-07-02 11:58:16 +00:00
parent d9d21371df
commit aa75f0a18c
4 changed files with 36 additions and 30 deletions

View File

@ -277,11 +277,14 @@ function blog_block($op = 'list', $delta = 0) {
} }
else if ($op == 'view') { else if ($op == 'view') {
if (user_access('access content')) { if (user_access('access content')) {
$block['content'] = node_title_list(db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), 0, 10)); $result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), 0, 10);
$block['content'] .= '<div class="more-link">'. l(t('more'), 'blog', array('title' => t('Read the latest blog entries.'))) .'</div>'; if (db_num_rows($result)) {
$block['subject'] = t('Recent blog posts'); $block['content'] = node_title_list($result);
$block['content'] .= '<div class="more-link">'. l(t('more'), 'blog', array('title' => t('Read the latest blog entries.'))) .'</div>';
$block['subject'] = t('Recent blog posts');
return $block;
}
} }
return $block;
} }
} }

View File

@ -277,11 +277,14 @@ function blog_block($op = 'list', $delta = 0) {
} }
else if ($op == 'view') { else if ($op == 'view') {
if (user_access('access content')) { if (user_access('access content')) {
$block['content'] = node_title_list(db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), 0, 10)); $result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), 0, 10);
$block['content'] .= '<div class="more-link">'. l(t('more'), 'blog', array('title' => t('Read the latest blog entries.'))) .'</div>'; if (db_num_rows($result)) {
$block['subject'] = t('Recent blog posts'); $block['content'] = node_title_list($result);
$block['content'] .= '<div class="more-link">'. l(t('more'), 'blog', array('title' => t('Read the latest blog entries.'))) .'</div>';
$block['subject'] = t('Recent blog posts');
return $block;
}
} }
return $block;
} }
} }

View File

@ -447,25 +447,25 @@ function statistics_block($op = 'list', $delta = 0, $edit = array()) {
$content = array(); $content = array();
$daytop = variable_get('statistics_block_top_day_num', 0); $daytop = variable_get('statistics_block_top_day_num', 0);
if ($daytop) { if ($daytop && ($result = statistics_title_list('daycount', $daytop)) && db_num_rows($result)) {
$content[] = node_title_list(statistics_title_list('daycount', $daytop), t("Today's:")); $content[] = node_title_list($result, t("Today's:"));
} }
$alltimetop = variable_get('statistics_block_top_all_num', 0); $alltimetop = variable_get('statistics_block_top_all_num', 0);
if ($alltimetop) { if ($alltimetop && ($result = statistics_title_list('totalcount', $alltimetop)) && db_num_rows($result)) {
$content[] = node_title_list(statistics_title_list('totalcount', $alltimetop), t('All time:')); $content[] = node_title_list($result, t('All time:'));
} }
$lasttop = variable_get('statistics_block_top_last_num', 0); $lasttop = variable_get('statistics_block_top_last_num', 0);
if ($lasttop) { if ($lasttop && ($result = statistics_title_list('timestamp', $lasttop)) && db_num_rows($result)) {
$content[] = node_title_list(statistics_title_list('timestamp', $lasttop), t('Last viewed:')); $content[] = node_title_list($result, t('Last viewed:'));
} }
$output = implode($content, '<br />');
$block['subject'] = t('Popular content'); if (count($content)) {
$block['content'] = $output; $block['content'] = implode($content, '<br />');
$block['subject'] = t('Popular content');
return $block; return $block;
}
} }
} }
} }

View File

@ -447,25 +447,25 @@ function statistics_block($op = 'list', $delta = 0, $edit = array()) {
$content = array(); $content = array();
$daytop = variable_get('statistics_block_top_day_num', 0); $daytop = variable_get('statistics_block_top_day_num', 0);
if ($daytop) { if ($daytop && ($result = statistics_title_list('daycount', $daytop)) && db_num_rows($result)) {
$content[] = node_title_list(statistics_title_list('daycount', $daytop), t("Today's:")); $content[] = node_title_list($result, t("Today's:"));
} }
$alltimetop = variable_get('statistics_block_top_all_num', 0); $alltimetop = variable_get('statistics_block_top_all_num', 0);
if ($alltimetop) { if ($alltimetop && ($result = statistics_title_list('totalcount', $alltimetop)) && db_num_rows($result)) {
$content[] = node_title_list(statistics_title_list('totalcount', $alltimetop), t('All time:')); $content[] = node_title_list($result, t('All time:'));
} }
$lasttop = variable_get('statistics_block_top_last_num', 0); $lasttop = variable_get('statistics_block_top_last_num', 0);
if ($lasttop) { if ($lasttop && ($result = statistics_title_list('timestamp', $lasttop)) && db_num_rows($result)) {
$content[] = node_title_list(statistics_title_list('timestamp', $lasttop), t('Last viewed:')); $content[] = node_title_list($result, t('Last viewed:'));
} }
$output = implode($content, '<br />');
$block['subject'] = t('Popular content'); if (count($content)) {
$block['content'] = $output; $block['content'] = implode($content, '<br />');
$block['subject'] = t('Popular content');
return $block; return $block;
}
} }
} }
} }