Newer
Older
<?php
/**
* Contains theme override functions and preprocess functions for the Zen theme.
* IMPORTANT WARNING: DO NOT MODIFY THIS FILE.
*
* The base Zen theme is designed to be easily extended by its sub-themes. You
* shouldn't modify this or any of the CSS or PHP files in the root zen/ folder.
* See the online documentation for more information:
* http://drupal.org/node/193318
Ted Serbinski
committed
*/
John Albin Wilkins
committed
// Auto-rebuild the theme registry during theme development.
if (theme_get_setting('zen_rebuild_registry')) {
// Rebuild .info data.
John Albin Wilkins
committed
system_rebuild_theme_data();
// Rebuild theme registry.
drupal_theme_rebuild();
John Albin Wilkins
committed
}
John Albin Wilkins
committed
/**
* Implements HOOK_theme().
John Albin Wilkins
committed
function zen_theme(&$existing, $type, $theme, $path) {
John Albin Wilkins
committed
include_once './' . drupal_get_path('theme', 'zen') . '/zen-internals/template.theme-registry.inc';
John Albin Wilkins
committed
return _zen_theme($existing, $type, $theme, $path);
}
/**
* Return a themed breadcrumb trail.
*
* @param $variables
* - title: An optional string to be used as a navigational heading to give
* context for breadcrumb links to screen-reader users.
* - title_attributes_array: Array of HTML attributes for the title. It is
* flattened into a string within the theme function.
* - breadcrumb: An array containing the breadcrumb links.
* @return
* A string containing the breadcrumb output.
*/
John Albin Wilkins
committed
function zen_breadcrumb($variables) {
$breadcrumb = $variables['breadcrumb'];
John Albin Wilkins
committed
// Determine if we are to display the breadcrumb.
$show_breadcrumb = theme_get_setting('zen_breadcrumb');
if ($show_breadcrumb == 'yes' || $show_breadcrumb == 'admin' && arg(0) == 'admin') {
John Albin Wilkins
committed
// Optionally get rid of the homepage link.
$show_breadcrumb_home = theme_get_setting('zen_breadcrumb_home');
if (!$show_breadcrumb_home) {
array_shift($breadcrumb);
}
John Albin Wilkins
committed
// Return the breadcrumb with separators.
$breadcrumb_separator = theme_get_setting('zen_breadcrumb_separator');
John Albin Wilkins
committed
$trailing_separator = $title = '';
if (theme_get_setting('zen_breadcrumb_title')) {
John Albin Wilkins
committed
$item = menu_get_item();
if (!empty($item['tab_parent'])) {
// If we are on a non-default tab, use the tab's title.
John Albin Wilkins
committed
$title = check_plain($item['title']);
}
else {
$title = drupal_get_title();
}
if ($title) {
John Albin Wilkins
committed
$trailing_separator = $breadcrumb_separator;
}
John Albin Wilkins
committed
}
elseif (theme_get_setting('zen_breadcrumb_trailing')) {
$trailing_separator = $breadcrumb_separator;
}
John Albin Wilkins
committed
// Provide a navigational heading to give context for breadcrumb links to
// screen-reader users.
if (empty($variables['title'])) {
$variables['title'] = t('You are here');
}
// Unless overridden by a preprocess function, make the heading invisible.
if (!isset($variables['title_attributes_array']['class'])) {
$variables['title_attributes_array']['class'][] = 'element-invisible';
}
$heading = '<h2' . drupal_attributes($variables['title_attributes_array']) . '>' . $variables['title'] . '</h2>';
John Albin Wilkins
committed
return '<div class="breadcrumb">' . $heading . implode($breadcrumb_separator, $breadcrumb) . $trailing_separator . $title . '</div>';
John Albin Wilkins
committed
// Otherwise, return an empty string.
John Albin Wilkins
committed
/**
John Albin Wilkins
committed
* Duplicate of theme_menu_local_tasks() but adds clearfix to tabs.
John Albin Wilkins
committed
*/
John Albin Wilkins
committed
function zen_menu_local_tasks(&$variables) {
$output = '';
John Albin Wilkins
committed
if ($primary = drupal_render($variables['primary'])) {
$output .= '<h2 class="element-invisible">' . t('Primary tabs') . '</h2>';
$output .= '<ul class="tabs primary clearfix">' . $primary . '</ul>';
John Albin Wilkins
committed
}
if ($secondary = drupal_render($variables['secondary'])) {
$output .= '<h2 class="element-invisible">' . t('Secondary tabs') . '</h2>';
$output .= '<ul class="tabs secondary clearfix">' . $secondary . '</ul>';
John Albin Wilkins
committed
}
return $output;
}
Ted Serbinski
committed
/**
* Override or insert variables into theme_menu_local_task().
*/
function zen_preprocess_menu_local_task(&$variables) {
$link =& $variables['element']['#link'];
// If the link does not contain HTML already, check_plain() it now.
// After we set 'html'=TRUE the link will not be sanitized by l().
if (empty($link['localized_options']['html'])) {
$link['title'] = check_plain($link['title']);
}
$link['localized_options']['html'] = TRUE;
$link['title'] = '<span class="tab">' . $link['title'] . '</span>';
}
John Albin Wilkins
committed
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/**
* Adds conditional CSS from the .info file.
*
* Copy of conditional_styles_preprocess_html().
*/
function zen_add_conditional_styles() {
// Make a list of base themes and the current theme.
$themes = $GLOBALS['base_theme_info'];
$themes[] = $GLOBALS['theme_info'];
foreach (array_keys($themes) as $key) {
$theme_path = dirname($themes[$key]->filename) . '/';
if (isset($themes[$key]->info['stylesheets-conditional'])) {
foreach (array_keys($themes[$key]->info['stylesheets-conditional']) as $condition) {
foreach (array_keys($themes[$key]->info['stylesheets-conditional'][$condition]) as $media) {
foreach ($themes[$key]->info['stylesheets-conditional'][$condition][$media] as $stylesheet) {
// Add each conditional stylesheet.
drupal_add_css(
$theme_path . $stylesheet,
array(
'group' => CSS_THEME,
'browsers' => array(
'IE' => $condition,
'!IE' => FALSE,
),
'every_page' => TRUE,
)
);
}
}
}
}
}
}
* Override or insert variables into the html template.
* An array of variables to pass to the theme template.
* The name of the template being rendered ("html" in this case.)
function zen_preprocess_html(&$vars, $hook) {
// If the user is silly and enables Zen as the theme, add some styles.
if ($GLOBALS['theme'] == 'zen') {
John Albin Wilkins
committed
include_once './' . drupal_get_path('theme', 'zen') . '/zen-internals/template.zen.inc';
_zen_preprocess_html($vars, $hook);
John Albin Wilkins
committed
elseif (!module_exists('conditional_styles')) {
zen_add_conditional_styles();
}
// Classes for body element. Allows advanced theming based on context
// (home page, node of certain type, etc.)
if (!$vars['is_front']) {
// Add unique class for each page.
$path = drupal_get_path_alias($_GET['q']);
// Add unique class for each website section.
if (arg(0) == 'node') {
if (arg(1) == 'add') {
}
elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) {
$section = 'node-' . arg(2);
John Albin Wilkins
committed
$vars['classes_array'][] = drupal_html_class('section-' . $section);
Ted Serbinski
committed
}
if (theme_get_setting('zen_wireframes')) {
$vars['classes_array'][] = 'with-wireframes'; // Optionally add the wireframes style.
// Store the menu item since it has some useful information.
$vars['menu_item'] = menu_get_item();
switch ($vars['menu_item']['page_callback']) {
case 'views_page':
// Is this a Views page?
$vars['classes_array'][] = 'page-views';
break;
case 'page_manager_page_execute':
case 'page_manager_node_view':
case 'page_manager_contact_site':
// Is this a Panels page?
$vars['classes_array'][] = 'page-panels';
break;
}
John Albin Wilkins
committed
/**
* Override or insert variables into the maintenance page template.
*
* @param $vars
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered ("maintenance_page" in this case.)
John Albin Wilkins
committed
*/
John Albin Wilkins
committed
function zen_preprocess_maintenance_page(&$vars, $hook) {
John Albin Wilkins
committed
// If Zen is the maintenance theme, add some styles.
if ($GLOBALS['theme'] == 'zen') {
John Albin Wilkins
committed
include_once './' . drupal_get_path('theme', 'zen') . '/zen-internals/template.zen.inc';
_zen_preprocess_html($vars, $hook);
John Albin Wilkins
committed
}
elseif (!module_exists('conditional_styles')) {
John Albin Wilkins
committed
zen_add_conditional_styles();
John Albin Wilkins
committed
}
}
* Override or insert variables into the node templates.
* An array of variables to pass to the theme template.
* The name of the template being rendered ("node" in this case.)
John Albin Wilkins
committed
function zen_preprocess_node(&$vars, $hook) {
John Albin Wilkins
committed
// Add $unpublished variable.
$vars['unpublished'] = (!$vars['status']) ? TRUE : FALSE;
John Albin Wilkins
committed
John Albin Wilkins
committed
// Add a class to show node is authored by current user.
John Albin Wilkins
committed
if ($vars['uid'] && $vars['uid'] == $GLOBALS['user']->uid) {
John Albin Wilkins
committed
$vars['classes_array'][] = 'node-by-viewer';
John Albin Wilkins
committed
$vars['title_attributes_array']['class'][] = 'node-title';
* Override or insert variables into the comment templates.
* An array of variables to pass to the theme template.
* The name of the template being rendered ("comment" in this case.)
John Albin Wilkins
committed
function zen_preprocess_comment(&$vars, $hook) {
// If comment subjects are disabled, don't display them.
if (variable_get('comment_subject_field_' . $vars['node']->type, 1) == 0) {
$vars['title'] = '';
}
// Zebra striping.
if ($vars['id'] == 1) {
$vars['classes_array'][] = 'first';
}
if ($vars['id'] == $vars['node']->comment_count) {
$vars['classes_array'][] = 'last';
}
$vars['classes_array'][] = $vars['zebra'];
$vars['title_attributes_array']['class'][] = 'comment-title';
Ted Serbinski
committed
}
Jeff Robbins
committed
/**
* Preprocess variables for region.tpl.php
*
* Prepare the values passed to the theme_region function to be passed into a
* pluggable template engine. Uses the region name to generate a template file
* suggestions. If none are found, the default region.tpl.php is used.
*
* @see region.tpl.php
*/
function zen_preprocess_region(&$vars, $hook) {
John Albin Wilkins
committed
// Sidebar regions get some extra classes and a common template suggestion.
if (strpos($vars['region'], 'sidebar_') === 0) {
$vars['classes_array'][] = 'column';
$vars['classes_array'][] = 'sidebar';
John Albin Wilkins
committed
$vars['theme_hook_suggestions'][] = 'region__sidebar';
// Allow a region-specific template to override Zen's region--sidebar.
$vars['theme_hook_suggestions'][] = 'region__' . $vars['region'];
* Override or insert variables into the block templates.
* An array of variables to pass to the theme template.
* The name of the template being rendered ("block" in this case.)
John Albin Wilkins
committed
function zen_preprocess_block(&$vars, $hook) {
// Classes describing the position of the block within the region.
if ($vars['block_id'] == 1) {
$vars['classes_array'][] = 'first';
}
// The last_in_region property is set in zen_page_alter().
if (isset($vars['block']->last_in_region)) {
$vars['classes_array'][] = 'last';
}
$vars['classes_array'][] = $vars['block_zebra'];
John Albin Wilkins
committed
$vars['title_attributes_array']['class'][] = 'block-title';
John Albin Wilkins
committed
}
/**
* Override or insert variables into the block templates.
*
* @param $vars
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered ("block" in this case.)
*/
function zen_process_block(&$vars, $hook) {
// Drupal 7 should use a $title variable instead of $block->subject.
$vars['title'] = $vars['block']->subject;
}
/**
* Implements hook_page_alter().
*
* Look for the last block in the region. This is impossible to determine from
* within a preprocess_block function.
*
* @param $page
* Nested array of renderable elements that make up the page.
*/
function zen_page_alter(&$page) {
// Look in each visible region for blocks.
foreach (system_region_list($GLOBALS['theme'], REGIONS_VISIBLE) as $region => $name) {
if (!empty($page[$region])) {
// Find the last block in the region.
$blocks = array_reverse(element_children($page[$region]));
while ($blocks && !isset($page[$region][$blocks[0]]['#block'])) {
array_shift($blocks);
}
if ($blocks) {
$page[$region][$blocks[0]]['#block']->last_in_region = TRUE;
}
}
}
}