function modr8_block in modr8 6
Same name and namespace in other branches
- 5 modr8.module \modr8_block()
Implementation of hook_block().
File
- ./
modr8.module, line 250 - Easy dedicated content moderation
Code
function modr8_block($op = 'list', $delta = 0) {
if ($op == 'list') {
$blocks[0]['info'] = t("Modr8 moderator's block");
$blocks['modr8-moderators']['info'] = t("Modr8 moderators credit list");
$blocks['modr8-moderators']['cache'] = BLOCK_CACHE_GLOBAL;
return $blocks;
}
elseif ($op == 'view') {
if ($delta == 'modr8-moderators') {
$block = array();
$cutoff = strtotime('now -6 months');
$result = db_query_range("SELECT COUNT(ml.modid) AS number, u.* FROM {modr8_log} ml INNER JOIN {users} u on u.uid = ml.uid WHERE ml.action != 'Response' AND ml.timestamp > %d AND u.status = 1 GROUP BY u.uid ORDER BY number DESC", $cutoff, 0, variable_get('modr8_top_moderators_limit', 10));
$header = array(
t('User'),
t('Number of actions'),
);
$rows = array();
while ($account = db_fetch_object($result)) {
$rows[] = array(
theme('username', $account),
$account->number,
);
}
if ($rows) {
$block['content'] = t('Last 6 months:') . '<br />' . theme('table', $header, $rows);
$block['subject'] = t('Top moderators');
}
return $block;
}
elseif (user_access('moderate content')) {
$block['subject'] = t('Moderation queue');
$is_published = '';
if (!user_access('administer nodes')) {
// Users who don't have the 'administer nodes' permission can only see published nodes.
$is_published = 'n.status = 1 AND ';
}
$count = db_result(db_query(db_rewrite_sql('SELECT COUNT(*) FROM {node} n WHERE ' . $is_published . ' n.moderate = 1')));
$content = '<p>' . l(t('@items in moderation', array(
'@items' => format_plural($count, '1 post', '@count posts'),
)), 'admin/content/modr8') . '</p>';
if ($count) {
$sql = db_rewrite_sql('SELECT n.nid, n.title FROM {node} n WHERE ' . $is_published . ' n.moderate = 1 ORDER BY n.changed DESC');
$result = db_query_range($sql, 0, 6);
$content .= node_title_list($result, t('Recent additions:'));
}
$block['content'] = $content;
return $block;
}
}
}