4 * Here we override the default HTML output of drupal.
5 * refer to http://drupal.org/node/550722
8 // Auto-rebuild the theme registry during theme development.
9 if (theme_get_setting('clear_registry')) {
10 // Rebuild .info data.
11 system_rebuild_theme_data();
12 // Rebuild theme registry.
13 drupal_theme_rebuild();
16 // Add Zen Tabs styles
17 if (theme_get_setting('basic_tabs')) {
18 drupal_add_css( drupal_get_path('theme', 'basic') .
'/css/tabs.css');
21 function basic_preprocess_html(&$vars) {
22 if (theme_get_setting('basic_ie_enabled')) {
23 $basic_ie_enabled_versions = theme_get_setting('basic_ie_enabled_versions');
24 if (in_array('ie8', $basic_ie_enabled_versions, TRUE
)) {
25 drupal_add_css(path_to_theme() .
'/css/ie8.css', array('group' => CSS_THEME
, 'browsers' => array('IE' => 'IE 8', '!IE' => FALSE
), 'preprocess' => FALSE
));
26 drupal_add_js(path_to_theme() .
'/js/selectivizr.js');
28 if (in_array('ie9', $basic_ie_enabled_versions, TRUE
)) {
29 drupal_add_css(path_to_theme() .
'/css/ie9.css', array('group' => CSS_THEME
, 'browsers' => array('IE' => 'IE 9', '!IE' => FALSE
), 'preprocess' => FALSE
));
34 function basic_preprocess_page(&$vars, $hook) {
35 if (isset($vars['node_title'])) {
36 $vars['title'] = $vars['node_title'];
38 // Adding a class to #page in wireframe mode
39 if (theme_get_setting('wireframe_mode')) {
40 $vars['classes_array'][] = 'wireframe-mode';
42 // Adding classes wether #navigation is here or not
43 if (!empty($vars['main_menu']) or
!empty($vars['sub_menu'])) {
44 $vars['classes_array'][] = 'with-navigation';
46 if (!empty($vars['secondary_menu'])) {
47 $vars['classes_array'][] = 'with-subnav';
50 // Add first/last classes to node listings about to be rendered.
51 if (isset($vars['page']['content']['system_main']['nodes'])) {
52 // All nids about to be loaded (without the #sorted attribute).
53 $nids = element_children($vars['page']['content']['system_main']['nodes']);
54 // Only add first/last classes if there is more than 1 node being rendered.
55 if (count($nids) > 1) {
56 $first_nid = reset($nids);
57 $last_nid = end($nids);
58 $first_node = $vars['page']['content']['system_main']['nodes'][$first_nid]['#node'];
59 $first_node->classes_array
= array('first');
60 $last_node = $vars['page']['content']['system_main']['nodes'][$last_nid]['#node'];
61 $last_node->classes_array
= array('last');
66 function basic_preprocess_node(&$vars) {
67 // Add a striping class.
68 $vars['classes_array'][] = 'node-' .
$vars['zebra'];
70 // Add $unpublished variable.
71 $vars['unpublished'] = (!$vars['status']) ? TRUE
: FALSE
;
73 // Merge first/last class (from basic_preprocess_page) into classes array of current node object.
74 $node = $vars['node'];
75 if (!empty($node->classes_array
)) {
76 $vars['classes_array'] = array_merge($vars['classes_array'], $node->classes_array
);
80 function basic_preprocess_block(&$vars, $hook) {
81 // Add a striping class.
82 $vars['classes_array'][] = 'block-' .
$vars['block_zebra'];
84 // Add first/last block classes
86 // If block id (count) is 1, it's first in region.
87 if ($vars['block_id'] == '1') {
88 $first_last = "first";
89 $vars['classes_array'][] = $first_last;
91 // Count amount of blocks about to be rendered in that region.
92 $block_count = count(block_list($vars['elements']['#block']->region
));
93 if ($vars['block_id'] == $block_count) {
95 $vars['classes_array'][] = $first_last;
100 * Return a themed breadcrumb trail.
103 * An array containing the breadcrumb links.
105 * A string containing the breadcrumb output.
107 function basic_breadcrumb($variables) {
108 $breadcrumb = $variables['breadcrumb'];
109 // Determine if we are to display the breadcrumb.
110 $show_breadcrumb = theme_get_setting('basic_breadcrumb');
111 if ($show_breadcrumb == 'yes' || $show_breadcrumb == 'admin' && arg(0) == 'admin') {
113 // Optionally get rid of the homepage link.
114 $show_breadcrumb_home = theme_get_setting('basic_breadcrumb_home');
115 if (!$show_breadcrumb_home) {
116 array_shift($breadcrumb);
119 // Return the breadcrumb with separators.
120 if (!empty($breadcrumb)) {
121 $breadcrumb_separator = theme_get_setting('basic_breadcrumb_separator');
122 $trailing_separator = $title = '';
123 if (theme_get_setting('basic_breadcrumb_title')) {
124 $item = menu_get_item();
125 if (!empty($item['tab_parent'])) {
126 // If we are on a non-default tab, use the tab's title.
127 $title = check_plain($item['title']);
130 $title = drupal_get_title();
133 $trailing_separator = $breadcrumb_separator;
136 elseif (theme_get_setting('basic_breadcrumb_trailing')) {
137 $trailing_separator = $breadcrumb_separator;
140 // Provide a navigational heading to give context for breadcrumb links to
141 // screen-reader users. Make the heading invisible with .element-invisible.
142 $heading = '<h2 class="element-invisible">' .
t('You are here') .
'</h2>';
144 return $heading .
'<div class="breadcrumb">' .
implode($breadcrumb_separator, $breadcrumb) .
$trailing_separator .
$title .
'</div>';
147 // Otherwise, return an empty string.
152 * Converts a string to a suitable html ID attribute.
154 * http://www.w3.org/TR/html4/struct/global.html#h-7.5.2 specifies what makes a
155 * valid ID attribute in HTML. This function:
157 * - Ensure an ID starts with an alpha character by optionally adding an 'n'.
158 * - Replaces any character except A-Z, numbers, and underscores with dashes.
159 * - Converts entire string to lowercase.
164 * The converted string
166 function basic_id_safe($string) {
167 // Replace with dashes anything that isn't A-Z, numbers, dashes, or underscores.
168 $string = strtolower(preg_replace('/[^a-zA-Z0-9_-]+/', '-', $string));
169 // If the first character is not a-z, add 'n' in front.
170 if (!ctype_lower($string{0})) { // Don't use ctype_alpha since its locale aware.
171 $string = 'id'.
$string;
177 * Generate the HTML output for a menu link and submenu.
180 * An associative array containing:
181 * - element: Structured array data for a menu link.
184 * A themed HTML string.
189 function basic_menu_link(array $variables) {
190 $element = $variables['element'];
193 if ($element['#below']) {
194 $sub_menu = drupal_render($element['#below']);
196 $output = l($element['#title'], $element['#href'], $element['#localized_options']);
197 // Adding a class depending on the TITLE of the link (not constant)
198 $element['#attributes']['class'][] = basic_id_safe($element['#title']);
199 // Adding a class depending on the ID of the link (constant)
200 $element['#attributes']['class'][] = 'mid-' .
$element['#original_link']['mlid'];
201 return '<li' .
drupal_attributes($element['#attributes']) .
'>' .
$output .
$sub_menu .
"</li>\n";
205 * Override or insert variables into theme_menu_local_task().
207 function basic_preprocess_menu_local_task(&$variables) {
208 $link =& $variables['element']['#link'];
210 // If the link does not contain HTML already, check_plain() it now.
211 // After we set 'html'=TRUE the link will not be sanitized by l().
212 if (empty($link['localized_options']['html'])) {
213 $link['title'] = check_plain($link['title']);
215 $link['localized_options']['html'] = TRUE
;
216 $link['title'] = '<span class="tab">' .
$link['title'] .
'</span>';
220 * Duplicate of theme_menu_local_tasks() but adds clearfix to tabs.
222 function basic_menu_local_tasks(&$variables) {
225 if (!empty($variables['primary'])) {
226 $variables['primary']['#prefix'] = '<h2 class="element-invisible">' .
t('Primary tabs') .
'</h2>';
227 $variables['primary']['#prefix'] .
= '<ul class="tabs primary clearfix">';
228 $variables['primary']['#suffix'] = '</ul>';
229 $output .
= drupal_render($variables['primary']);
231 if (!empty($variables['secondary'])) {
232 $variables['secondary']['#prefix'] = '<h2 class="element-invisible">' .
t('Secondary tabs') .
'</h2>';
233 $variables['secondary']['#prefix'] .
= '<ul class="tabs secondary clearfix">';
234 $variables['secondary']['#suffix'] = '</ul>';
235 $output .
= drupal_render($variables['secondary']);