content_type_summary.module in Util 7
Simple Content Type Summary.
File
contribs/content_type_summary/content_type_summary.moduleView source
<?php
/**
* @file
* Simple Content Type Summary.
*/
/**
* Implements hook_menu().
*/
function content_type_summary_menu() {
$items = array();
$items['admin/content/summary'] = array(
'title' => 'Content Type Summary',
'description' => 'Basic information about content types on this site.',
'page callback' => 'content_type_summary_report',
'access arguments' => array(
'access administration pages',
),
);
return $items;
}
/**
* Menu callback.
*/
function content_type_summary_report() {
$output = '';
$types = node_type_get_types();
// dpm($types, 'node_type_get_types');
$auto_entitylabel_present = module_exists('auto_entitylabel');
// I don't know what this is, but I see a lot of it.
$modules = array(
'initialize' => 'Initialize',
);
foreach (module_list() as $module => $desc) {
$modules[$module] = filter_xss(ucwords(str_replace('_', ' ', $module)));
}
$table = array(
'header' => array(
t('Readable Type'),
t('Machine Type'),
t('Module'),
array(
'data' => t('Published'),
'align' => 'center',
),
t('Promoted'),
t('Revisions'),
t('Has Title'),
t('Has Help'),
t('Number Published'),
t('Number Unpublished'),
t('Fields'),
),
'rows' => array(),
'attributes' => array(
'id' => 'content-type-summary',
'style' => 'width:auto;',
),
'empty' => t('Strangely, I cannot find any content types.'),
);
$implememnts_hook = module_implements('content_type_summary');
$context = array(
'op' => 'header',
);
foreach ($implememnts_hook as $module) {
$function = $module . '_content_type_summary';
$function($context, $table['header']);
}
$published_query = "SELECT COUNT(*) FROM {node} WHERE status = 1 AND type = :type";
$unpublished_query = "SELECT COUNT(*) FROM {node} WHERE status <> 1 AND type = :type";
$context = array(
'op' => 'row',
);
$dest = drupal_get_destination();
foreach ($types as $type => $info) {
$options = variable_get('node_options_' . $type, NULL);
$args = array(
':type' => $type,
);
$has_title = empty($info->has_title) ? "χ" : "✔";
if ($auto_entitylabel_present) {
// Does this type have an automatic label?
$auto = auto_entitylabel_get_setting('node_' . $type);
// If it is set to non-auto, just let current value stand.
// Otherwise, differentiate between auto and "if empty".
if ($auto) {
$has_title = $auto == 1 ? "α" : "∅";
}
}
$row = array(
l($info->name, 'admin/structure/types/manage/' . $type, array(
'query' => $dest,
)),
filter_xss($type),
$modules[$info->module],
array(
'data' => in_array('status', $options) ? "✔" : "χ",
'align' => 'center',
),
array(
'data' => in_array('promote', $options) ? "✔" : "χ",
'align' => 'center',
),
array(
'data' => in_array('revision', $options) ? "✔" : "χ",
'align' => 'center',
),
array(
'data' => $has_title,
'align' => 'center',
),
array(
'data' => empty($info->help) ? "χ" : "✔",
'align' => 'center',
),
array(
'data' => number_format(db_query($published_query, $args)
->fetchField(), 0),
'align' => 'right',
),
array(
'data' => number_format(db_query($unpublished_query, $args)
->fetchField(), 0),
'align' => 'right',
),
array(
'data' => number_format(count(field_info_instances('node', $type)), 0),
'align' => 'right',
),
);
foreach ($implememnts_hook as $module) {
$function = $module . '_content_type_summary';
$function($context, $row, $info);
}
$table['rows'][] = $row;
}
$output .= theme('table', $table);
if ($auto_entitylabel_present) {
$output .= '<p>' . "Title: α ⇒ automatic; ∅ ⇒ automatic if empty." . '</p>';
}
return $output;
}
/**
* Implements hook_content_type_summary() on behalf of Comment module.
*/
function comment_content_type_summary($context, &$row, $type = NULL) {
if (!module_exists('comment')) {
return;
}
switch ($context['op']) {
// Modify the header row.
case 'header':
$row[] = t('Comment');
break;
// Modify the data row.
case 'row':
$comment_settings = array(
'0' => t('Hidden'),
'1' => t('Closed'),
'2' => t('Open'),
);
// Is comment enabled on this content type?
$x = variable_get('comment_' . $type->type, NULL);
$count = db_query("SELECT COUNT(*) FROM node n " . "LEFT JOIN comment c ON c.nid = n.nid " . "WHERE n.type = :type AND c.status = 1 ", array(
':type' => $type->type,
))
->fetchField();
if (is_null($x)) {
$row[] = array(
'data' => t('Disabled?'),
'align' => 'center',
);
}
else {
$row[] = array(
'data' => $comment_settings[$x] . ' (' . $count . ')',
'align' => 'center',
);
}
break;
}
}
/**
* Implements hook_content_type_summary() on behalf of Linkchecker module.
*/
function linkchecker_content_type_summary($context, &$row, $type = NULL) {
if (!module_exists('linkchecker')) {
return;
}
switch ($context['op']) {
// Modify the header row.
case 'header':
$row[] = t('Link Checker');
break;
// Modify the data row.
case 'row':
$scan_this_type = variable_get('linkchecker_scan_node_' . $type->type, FALSE);
$row[] = array(
'data' => $scan_this_type ? "✔" : "χ",
'align' => 'center',
);
break;
}
}
/**
* Implements hook_content_type_summary() on behalf of Workflow module.
*/
function workflow_content_type_summary($context, &$row, $type = NULL) {
if (!module_exists('workflow')) {
return;
}
switch ($context['op']) {
// Modify the header row.
case 'header':
$row[] = t('Workflow');
break;
// Modify the data row.
case 'row':
$type_in_workflow = workflow_get_workflow_type_map_by_type($type->type);
$row[] = array(
'data' => $type_in_workflow !== FALSE ? "✔" : "χ",
'align' => 'center',
);
break;
}
}
Functions
Name![]() |
Description |
---|---|
comment_content_type_summary | Implements hook_content_type_summary() on behalf of Comment module. |
content_type_summary_menu | Implements hook_menu(). |
content_type_summary_report | Menu callback. |
linkchecker_content_type_summary | Implements hook_content_type_summary() on behalf of Linkchecker module. |
workflow_content_type_summary | Implements hook_content_type_summary() on behalf of Workflow module. |