View source
<?php
function total_control_overview_ctools_content_types() {
return array(
'single' => TRUE,
'icon' => 'icon_node_form.png',
'no title override' => TRUE,
'title' => t('Site Overview'),
'description' => t('An overview of both content and users in one pane'),
'category' => t('Total Control'),
'js' => array(
'misc/autocomplete.js',
'misc/textarea.js',
'misc/collapse.js',
),
'defaults' => array(
'type' => NULL,
'comments' => NULL,
'spam' => 1,
'user' => NULL,
'roles' => NULL,
),
);
}
function total_control_overview_content_type_admin_title($subtype, $conf, $context) {
return t('Site Overview');
}
function total_control_overview_content_type_admin_info($subtype, $conf, $context) {
$block = new stdClass();
$block->title = t('An overview of both content and users in one pane');
return $block;
}
function total_control_overview_content_type_render($subtype, $conf, $panel_args, &$context) {
$block = new stdClass();
$block->module = t('total_control');
$types = node_get_types('types');
$overview_cnt = array();
$overview_usr = array();
foreach ($types as $type => $object) {
if ($conf['types'] == NULL || $conf['types'][$type]) {
$type_query = db_query("SELECT count(*) FROM {node} WHERE type = '%s' and status = 1", $type);
$total[$type] = format_plural(db_result($type_query), '1 ' . $object->name . ' item', '@count ' . $object->name . ' items');
$comment_setting = variable_get('comment_' . $type, 'comment');
if ($comment_setting != 0 || $conf['comments'][$type]) {
$comment_query = db_query("SELECT count(DISTINCT cid) FROM {comments} c INNER JOIN {node} n ON c.nid = n.nid WHERE n.type = '%s' and c.status = 1 AND n.status = 1", $type);
$total[$type . '_comments'] = format_plural(db_result($comment_query), '1 comment', '@count comments');
if ($conf['spam'] == 1) {
$spam_query = db_query("SELECT count(DISTINCT c.cid) FROM {comments} c INNER JOIN {node} n ON c.nid = n.nid WHERE n.type = '%s' and c.status = 0 AND n.status = 1", $type);
$total[$type . '_comments_spam'] = format_plural(db_result($spam_query), '1 spam', '@count spam');
}
}
$line = $total[$type];
$line .= $total[$type . '_comments'] ? ' with ' . $total[$type . '_comments'] : '';
$line .= $total[$type . '_comments_spam'] ? ' (' . $total[$type . '_comments_spam'] . ')' : '';
$overview_cnt[] = $line;
}
}
if (!$conf['user'] || $conf['user'] == 1) {
$user_query = db_query("SELECT count(*) FROM {users}");
$total['users_all'] = format_plural(db_result($user_query), '1 total user', '@count total users');
$user_active_query = db_query("SELECT count(*) FROM {users} WHERE status = 1 AND login != 0");
$total['users_active'] = format_plural(db_result($user_active_query), '1 active user', '@count active users');
$user_block_query = db_query("SELECT count(*) FROM {users} WHERE status = 0");
$total['users_block'] = format_plural(db_result($user_block_query), '1 blocked user', '@count blocked users');
$overview_usr[] = $total['users_all'];
$overview_usr[] = $total['users_active'];
$overview_usr[] = $total['users_block'];
}
$roles = user_roles(TRUE);
$total['users_roles'] = '';
foreach ($roles as $rid => $role) {
if ((!$conf['roles'] || $conf['roles'][$rid]) && $rid != 2) {
$user_role_query = db_query("SELECT count(*) FROM {users} u INNER JOIN {users_roles} r on u.uid = r.uid WHERE r.rid = %d", $rid);
$total['users_role_' . $rid] .= format_plural(db_result($user_role_query), '1 user', '@count users');
$total['users_role_' . $rid] .= ' in role: ' . $role;
$overview_usr[] = $total['users_role_' . $rid];
}
}
$pane = total_control_overview_ctools_content_types();
$content = '<div class="total-control-site-overview">';
$content .= ' <h2 class="title">' . $pane['title'] . '</h2>';
$content .= ' <div class="content">';
$content .= ' <strong>' . t('Content') . '</strong>';
$content .= theme('item_list', $overview_cnt);
$content .= ' <strong>' . t('Users') . '</strong>';
$content .= theme('item_list', $overview_usr);
$content .= ' </div>';
$content .= '</div>';
$block->content = $content;
return $block;
}
function total_control_overview_content_type_edit_form(&$form, &$form_state) {
$conf = $form_state['conf'];
$types = node_get_types('types');
$type_options = array();
$type_defaults = array();
$comment_defaults = array();
foreach ($types as $type => $object) {
$type_options[$type] = $object->name;
$type_defaults[] = $type;
if ($type == 'blog' || $type == 'forum topic') {
$comment_defaults[] = $type;
}
}
$form['types'] = array(
'#type' => 'checkboxes',
'#title' => t('Include Stats on Content Types'),
'#options' => $type_options,
'#default_value' => $form_state['op'] == 'add' ? $type_defaults : $conf['types'],
);
$form['comments'] = array(
'#type' => 'checkboxes',
'#title' => t('Include Comment Stats for Content Types'),
'#options' => $type_options,
'#default_value' => $form_state['op'] == 'add' ? $comment_defaults : $conf['comments'],
);
$spam_options = array(
0 => t('no'),
1 => t('Include Spam Comment count'),
);
$form['spam'] = array(
'#type' => 'checkbox',
'#title' => t('Include Spam Comment count'),
'#options' => $spam_options,
'#default_value' => $form_state['op'] == 'add' ? TRUE : $conf['spam'],
);
$user_options = array(
0 => t('no'),
1 => t('Show User Stats'),
);
$form['user'] = array(
'#type' => 'checkbox',
'#title' => t('Include User Counts'),
'#options' => $user_options,
'#default_value' => $form_state['op'] == 'add' ? TRUE : $conf['user'],
);
$roles = user_roles(TRUE);
$roles_options = array();
$roles_defaults = array();
foreach ($roles as $rid => $role) {
if ($rid != 2) {
$roles_options[$rid] = $role;
$roles_defaults[] = $rid;
}
}
if (!empty($roles_options)) {
$form['roles'] = array(
'#type' => 'checkboxes',
'#title' => t('Include User counts in Roles'),
'#options' => $roles_options,
'#default_value' => $form_state['op'] == 'add' ? $roles_defaults : $conf['roles'],
);
}
return $form;
}
function total_control_overview_content_type_edit_form_submit(&$form, &$form_state) {
foreach (array_keys($form_state['plugin']['defaults']) as $key) {
$form_state['conf'][$key] = $form_state['values'][$key];
}
}