<?php
/**
* Fetch information about themes.
*/
function xray_stats_enabled_themes() {
$themes = list_themes();
$num_themes = count($themes);
// Initialize variables for the data we will collect.
$num_hidden = 0; // Number of hidden themes.
$num_enabled = 0;
$summaries = array();
// Iterate through each theme, gathering data that we care about.
foreach ($themes as $themename => $theme) {
// Do not gather statistics for hidden themes, but keep a count of them.
if (isset($theme->info['hidden']) && $theme->info['hidden']) {
$num_hidden++;
}
else { // This is a visible theme.
if ($theme->status) {
$num_enabled++;
// This is an enabled theme, provide more stats.
$summaries[$theme->info['name']] = array(
'regions' => count($theme->info['regions']),
'overlay_regions' => count($theme->info['overlay_regions']),
'regions_hidden' => count($theme->info['regions_hidden']),
'features' => count($theme->info['features']),
'kindsofstylesheets' => count($theme->info['stylesheets']),
'allstylesheets' => isset($theme->info['stylesheets']['all']) ? count($theme->info['stylesheets']['all']) : 0,
);
}
}
}
return compact('num_themes', 'num_hidden', 'num_enabled', 'summaries');
}
/**
* Summary data for Appearance section (admin/appearance).
*/
function xray_appearance_summary() {
$data = array();
$data['themes'] = xray_stats_enabled_themes();
return $data;
}
/**
* Returns HTML text summary of Appearance section (admin/appearance) data.
*
* @param $attributes
* (optional) An associative array of HTML tag attributes, suitable for
* flattening by drupal_attributes().
* @param $variables
* An associative array containing:
* - data: result of xray_appearance_summary().
*
* @ingroup themeable
*/
function theme_xray_appearance_summary($variables) {
$themes = $variables['data']['themes'];
// Collapse attributes for paragraph tag to a string.
$attr = drupal_attributes($variables['attributes']);
$output = '';
$output .= "<p $attr>";
$output .= t('This site');
$output .= ' ';
$output .= format_plural(
$themes['num_themes'] - $themes['num_hidden'],
'has only one theme available',
'has @count themes available'
);
$output .= ' ';
$output .= format_plural(
$themes['num_hidden'],
'plus one hidden theme.',
'plus @count hidden themes.'
);
$output .= ' ';
$output .= t('Of the non-hidden themes,');
$output .= ' ';
$output .= format_plural(
$themes['num_enabled'],
'one is enabled. The enabled theme',
'@count are enabled. In the enabled themes,'
);
$output .= ' ';
$summaries = array();
foreach ($themes['summaries'] as $name => $info) {
$summary = '';
$summary .= $name . ' ';
$summary .= format_plural(
$info['regions'],
'has one region',
'has @count regions'
);
if ($info['overlay_regions'] || $info['regions_hidden']) {
$summary .= ' ' . t('(including') . ' ';
$summary .= format_plural(
$info['overlay_regions'],
'one overlay region',
'@count overlay regions'
);
$summary .= ' ' . t('and') . ' ';
$summary .= format_plural(
$info['regions_hidden'],
'one hidden region',
'@count hidden regions'
);
$summary .= ')';
}
$summaries[] = $summary;
}
$output .= xray_oxford_comma_list($summaries);
$output .= '.';
$output .= '</p>';
return $output;
}
?>