'object',
'path' => $path,
);
$items['maintenance_page'] = array(
'template' => 'page',
'path' => $path,
);
return $items;
}
/**
* Implementation of preprocess_block().
*/
function hi5_preprocess_block(&$vars) {
$vars['attr'] = array();
$vars['attr']['id'] = "block-{$vars['block']->module}-{$vars['block']->delta}";
$vars['attr']['class'] = "block block-{$vars['block']->module}";
$vars['element'] = 'aside';
$vars['hook'] = 'block';
$vars['hide'] = empty($vars['block']->content);
$vars['title'] = !empty($vars['block']->subject) ? $vars['block']->subject : '';
$vars['content'] = $vars['block']->content;
}
/**
* Implementation of preprocess_box().
*/
function hi5_preprocess_box(&$vars) {
$vars['attr'] = array();
$vars['attr']['class'] = "box";
$vars['element'] = 'div';
$vars['hook'] = 'box';
}
/**
* Implementation of preprocess_comment().
*/
function hi5_preprocess_comment(&$vars) {
$vars['attr'] = array();
$vars['attr']['id'] = "comment-{$vars['comment']->cid}";
$vars['attr']['class'] = "comment {$vars['status']}";
$vars['element'] = 'article';
$vars['hook'] = 'comment';
}
/**
* Implementation of preprocess_node().
*/
function hi5_preprocess_node(&$vars) {
$vars['attr'] = array();
$vars['attr']['id'] = "node-{$vars['node']->nid}";
$vars['attr']['class'] = "node node-{$vars['node']->type}";
$vars['attr']['class'] .= $vars['node']->sticky ? ' sticky' : '';
$vars['element'] = 'article';
$vars['hook'] = 'node';
}
/**
* Implementation of preprocess_page().
*/
function hi5_preprocess_page(&$vars) {
global $theme_key;
$vars['attr'] = array();
$vars['attr']['class'] = $vars['body_classes'];
$vars['attr']['class'] .= ' '. $theme_key;
// Remove duplicate content-type header -- see http://drupal.org/node/451304
$vars['headers'] = preg_replace('/]*>\n/', '', $vars['head']);
// Add links to externel assets
$vars['assets'] = _hi5_assets($theme_key);
// Get minimal styles
$vars['styles'] = _hi5_styles($theme_key);
}
/**
* Implementation of preprocess_maintenance_page().
*/
function hi5_preprocess_maintenance_page(&$vars) {
hi5_preprocess_page($vars);
$vars['primary_links'] =
$vars['secondary_links'] =
$vars['tabs'] = NULL;
}
/**
* Generate links to external assets (CSS and JS).
*/
function _hi5_assets($theme_key) {
$themes = list_themes();
$theme = $themes[$theme_key];
static $assets = NULL;
if (empty($assets)) {
// Add external scripts
$scripts = $theme->info['external scripts'];
if (is_array($scripts)) {
foreach ($scripts as $url) {
$assets .= "\n";
}
}
// Add external stylesheets
$styles = $theme->info['external stylesheets'];
if (is_array($styles)) {
foreach ($styles as $url) {
$assets .= '' ."\n";
}
}
}
return $assets;
}
/**
* Remove most stylesheets.
*/
function _hi5_styles($theme_key) {
$themes = list_themes();
$theme = $themes[$theme_key];
static $styles = NULL;
if (empty($styles)) {
$css = drupal_add_css();
// Add path to current theme (plus base theme[s]) to whitelist.
$whitelist = _hi5_theme_paths($theme_key);
// Add paths for specified modules to whitelist.
$exceptions = (is_array($theme->info['css whitelist'])) ? $theme->info['css whitelist'] : array();
foreach ($exceptions as $exception) {
if (module_exists($exception)) {
$whitelist[] = drupal_get_path('module', $exception) .'/*';
}
}
// Implode whitelist array to use with drupal_match_path()
$whitelist = implode("\n", $whitelist);
// Actually remove css files not found in whitelist.
foreach ($css as $scope => $types) {
foreach ($types as $type => $paths) {
foreach (array_keys($paths) as $path) {
if (!drupal_match_path($path, $whitelist)) {
unset($css[$scope][$type][$path]);
}
}
}
}
// Trigger CSS aggregation, generate HTML
$styles = drupal_get_css($css);
}
return $styles;
}
/**
* (Recursively) get current theme and base theme paths.
*/
function _hi5_theme_paths($theme_key) {
$themes = list_themes();
$theme = $themes[$theme_key];
$paths = array(drupal_get_path('theme', $theme_key) .'/*');
if (isset($theme->info['base theme'])) {
$paths = array_merge($paths, _hi5_theme_paths($theme->info['base theme']));
}
return $paths;
}