/[drupal]/contributions/themes/n_rebuild/template.php
ViewVC logotype

Contents of /contributions/themes/n_rebuild/template.php

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.53 - (show annotations) (download) (as text)
Mon Oct 5 18:51:39 2009 UTC (7 weeks, 5 days ago) by bz
Branch: MAIN
CVS Tags: DRUPAL-6--1-44, HEAD
Changes since 1.52: +14 -0 lines
File MIME type: text/x-php
*** empty log message ***
1 <?php
2
3 /**
4 * [EN] Force refresh of theme registry.
5 * DEVELOPMENT USE ONLY - COMMENT OUT FOR PRODUCTION
6 */
7 drupal_rebuild_theme_registry();
8
9
10 defined('NX_C_LINK_NAME') or define('NX_C_LINK_NAME', 'c_link');
11 defined('NX_C_ITEM_NAME') or define('NX_C_ITEM_NAME', 'c_item');
12
13
14 global $full_system_path;
15 $full_system_path = check_url(url('', array('absolute' => TRUE, 'language' => language_default())));
16 // -------------------------------------------------------------------------------
17 global $full_theme_path;
18 $full_theme_path = check_url(url(path_to_theme().'/', array('absolute' => TRUE, 'language' => language_default())));
19 $full_theme_path = str_replace('?q=', '', $full_theme_path); // [EN] if not clear_url mode
20 // -------------------------------------------------------------------------------
21 global $nx_theme_registration_pool;
22 $nx_theme_registration_pool = array();
23
24
25 require_once 'templates/search-block-form-functions.inc.php';
26 require_once 'templates/user-login-block-functions.tpl.php';
27
28
29 function n_rebuild_theme() {
30 global $nx_theme_registration_pool;
31 // ----------
32 $nx_theme_registration_pool['nx-fieldset-template'] = array(
33 'template' => 'nx-fieldset',
34 'arguments' => array(
35 'attributes' => '',
36 'title' => 'title',
37 'description' => 'description',
38 'children' => 'children',
39 'value' => 'value')
40 );
41 // ----------
42 return $nx_theme_registration_pool;
43 }
44
45
46 /**
47 * ------------------------
48 * [EN] Override or insert PHPTemplate variables into the templates
49 * ------------------------
50 */
51
52
53 function phptemplate_preprocess(&$vars) {
54 global $full_system_path;
55 global $full_theme_path;
56 $vars['full_system_path'] = $full_system_path;
57 $vars['full_theme_path'] = $full_theme_path;
58 }
59
60
61 $inline_code = "nx_ie_version = 0;\n";
62 $inline_code.= "nx_png_fix_mode = ". (theme_get_setting('nx_png_fix_mode') ? 'true' : 'false') .";\n";
63 $inline_code.= "nx_base_path = '". $full_system_path ."';\n";
64 $inline_code.= "nx_empty_gif_path = '". $full_theme_path ."images/empty.gif';";
65 drupal_add_js($inline_code, 'inline');
66
67
68 function phptemplate_preprocess_page(&$vars) {
69 global $full_system_path;
70 global $full_theme_path;
71 $tabs_pri = nx_prepare_tabs_c_items(menu_primary_local_tasks());
72 $tabs_sec = nx_prepare_tabs_c_items(menu_secondary_local_tasks());
73 $vars['tabs_pri'] = $tabs_pri ? '<div class="tabs tabs_pri"><div class="c_clear">&nbsp;</div><ul>' . $tabs_pri . '</ul><div class="c_clear">&nbsp;</div></div>' . "\n" : '';
74 $vars['tabs_sec'] = $tabs_sec ? '<div class="tabs tabs_sec"><div class="c_clear">&nbsp;</div><ul>' . $tabs_sec . '</ul><div class="c_clear">&nbsp;</div></div>' . "\n" : '';
75
76 $vars['site_title'] = $vars['site_name'] ? check_plain($vars['site_name']) : t('Home');
77 if ($vars['site_slogan']) {$vars['site_slogan'] = check_plain($vars['site_slogan']);}
78
79 $nx_body_classes = array();
80 $nx_body_classes[] = $vars['is_admin'] ? 'user-admin' : 'user-not_admin';
81 $nx_body_classes[] = $vars['logged_in'] ? 'logged_in-yes' : 'logged_in-no';
82 $nx_body_classes[] = $vars['is_front'] ? 'page-front' : 'page-not_front';
83 $nx_body_classes[] = 'layout-' . $vars['layout'];
84 $nx_body_classes[] = nx_get_destination2();
85 $nx_body_classes[] = 'universal_' . nx_get_destination2(TRUE);
86 $vars['nx_body_classes'] = implode(' ', $nx_body_classes);
87
88 // [EN] meta_keywords and meta_description
89 if (theme_get_setting('nx_meta_keywords')) {$vars['head'] .= '<meta name="keywords" content="'. theme_get_setting('nx_meta_keywords') .'" />'."\n";}
90 if (theme_get_setting('nx_meta_description')) {$vars['head'] .= '<meta name="description" content="'. theme_get_setting('nx_meta_description') .'" />'."\n";}
91 // [EN] IE styles and version
92 $vars['styles'] .= '<!--[if lt IE 7]><link type="text/css" rel="stylesheet" media="all" href="'. $full_theme_path . 'nx-style-ltIE7.css" /><![endif]-->' . "\n";
93 $vars['styles'] .= '<!--[if lt IE 8]><link type="text/css" rel="stylesheet" media="all" href="'. $full_theme_path . 'nx-style-ltIE8.css" /><![endif]-->' . "\n";
94 $vars['scripts'] .= '<!--[if IE 6]><script type="text/javascript"> nx_ie_version = 6; </script><![endif]-->' . "\n";
95 $vars['scripts'] .= '<!--[if IE 7]><script type="text/javascript"> nx_ie_version = 7; </script><![endif]-->' . "\n";
96 $vars['scripts'] .= '<!--[if IE 8]><script type="text/javascript"> nx_ie_version = 8; </script><![endif]-->' . "\n";
97 }
98
99
100 function nx_prepare_tabs_c_items($c_item_html){
101 $c_item = explode('<li ', $c_item_html);
102 for ($i = 1; $i < count($c_item); $i++){
103 if ($i == 1) {$c_item[$i] = str_replace(NX_C_ITEM_NAME, NX_C_ITEM_NAME . ' first', $c_item[$i]);}
104 if ($i == count($c_item)-1) {$c_item[$i] = str_replace(NX_C_ITEM_NAME, NX_C_ITEM_NAME . ' last', $c_item[$i]);}
105 }
106 return implode('<li ', $c_item);
107 }
108
109
110 function nx_get_destination2($with_mask = FALSE){
111 $destination = strip_tags((string)$_GET['q']);
112 $args = explode('/', $destination);
113 for ($i = 0; $i < count($args); $i++) {
114 $args[$i] = str_replace(array('-',' '), '_', $args[$i]);
115 if ($with_mask && is_numeric($args[$i])) {$args[$i] = 'n';}
116 }
117 return 'destination-'. implode('-', $args);
118 }
119
120
121 /**
122 * ------------------------
123 * [EN] Return a themed button
124 * ------------------------
125 */
126
127
128 function phptemplate_button($element) {
129 if (isset($element['#attributes']['class'])) {$element['#attributes']['class'] = 'form-'. $element['#button_type'] .' '. $element['#attributes']['class'];}
130 else {$element['#attributes']['class'] = 'form-'. $element['#button_type'];}
131 return '<span class="button-ex button-ex-id-'. $element['#id'] .'"><span class="bc-1 bc-x"><span class="bc-2 bc-x"><span class="bc-3 bc-x"><input type="submit" '. (empty($element['#name']) ? '' : 'name="'. $element['#name'] .'" ') .'id="'. $element['#id'] .'" value="'. check_plain($element['#value']) .'" '. drupal_attributes($element['#attributes']) .' /></span></span></span></span>' . "\n";
132 }
133
134
135 /**
136 * ------------------------
137 * [EN] Generate the HTML output for a single local task link
138 * ------------------------
139 */
140
141
142 function phptemplate_menu_local_task($link, $active = FALSE) {
143 return '<li class="'. NX_C_ITEM_NAME . ($active ? ' active' : '') .'">'.
144 '<span class="c1 cx"><span class="c2 cx"><span class="c3 cx">'. $link .'</span></span></span>'.
145 "</li>\n";
146 }
147
148
149 /**
150 * ------------------------
151 * [EN] Return a themed set of links
152 * ------------------------
153 */
154
155
156 function phptemplate_links($links, $attributes = array('class' => 'links'), $cover = array(
157 'outer_prefix' => '',
158 'inner_prefix' => '',
159 'inner_suffix' => '',
160 'outer_suffix' => '<span class="c_bounder">&nbsp;</span>')) {
161 global $language;
162 $output = '';
163 if (count($links) > 0) {
164 $output = '<ul'. drupal_attributes($attributes) .'>';
165 $num_links = count($links);
166 $i = 1;
167 foreach ($links as $key => $link) {
168 $class = $key;
169 // [EN] Add first, last and active classes to the list of links to help out themers.
170 if ($i == 1) {$class .= ' first';}
171 if ($i == $num_links) {$class .= ' last';}
172 if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page())) && (empty($link['language']) || $link['language']->language == $language->language)) {$class .= ' active';}
173 $output .= '<li'. drupal_attributes(array('class' => $class)) .'>';
174 if (isset($link['href'])) {
175 // [EN] Pass in $link as $options, they share the same keys.
176 // -------------------------------------------------------
177 $link['title'] = $cover['inner_prefix'] . ($link['html'] ? $link['title'] : check_plain($link['title'])) . $cover['inner_suffix'];
178 $link['html'] = TRUE;
179 $output .= $cover['outer_prefix'];
180 $output .= l($link['title'], $link['href'], $link);
181 $output .= $cover['outer_suffix'];
182 // -------------------------------------------------------
183 }
184 else if (!empty($link['title'])) {
185 // [EN] Some links are actually not links, but we wrap these in <span> for adding title and class attributes
186 if (empty($link['html'])) {$link['title'] = check_plain($link['title']);}
187 $span_attributes = '';
188 if (isset($link['attributes'])) {$span_attributes = drupal_attributes($link['attributes']);}
189 // -------------------------------------------------------
190 $output .= $cover['outer_prefix'].'<span'. $span_attributes .'>'.$cover['inner_prefix'].$link['title'].$cover['inner_suffix'].'</span>'.$cover['outer_suffix'];
191 // -------------------------------------------------------
192 }
193 $i++;
194 $output .= "</li>\n";
195 }
196 $output .= '</ul>';
197 }
198 return $output;
199 }
200
201
202 /**
203 * ------------------------
204 * [EN] Return a themed set of status and/or error messages. The messages are grouped by type
205 * ------------------------
206 */
207
208
209 function phptemplate_status_messages($display = NULL) {
210 $output = '';
211 foreach (drupal_get_messages($display) as $type => $messages) {
212 $output .= "<div class=\"messages message-$type\">\n";
213 if (count($messages) > 1) {
214 $output .= " <ul>\n";
215 foreach ($messages as $message) {
216 $output .= ' <li>'. $message ."</li>\n";
217 }
218 $output .= " </ul>\n";
219 } else {
220 $output .= $messages[0];
221 }
222 $output .= "</div>\n";
223 }
224 return $output;
225 }
226
227
228 /**
229 * ------------------------
230 * [EN] Return a themed help message
231 * ------------------------
232 */
233
234
235 function phptemplate_help() {
236 if ($help = menu_get_active_help()) {
237 if (strlen($help) > 10) {return '<div class="help">'. $help .'</div>';}
238 }
239 }
240
241
242 /**
243 * ------------------------
244 * [EN] Return a themed breadcrumb trail
245 * ------------------------
246 */
247
248
249 function phptemplate_breadcrumb($breadcrumb) {
250 if (!empty($breadcrumb)) {
251 $last_item = &$breadcrumb[count($breadcrumb)-1];
252 $last_item = str_replace('<a ', '<a class="last" ', $last_item);
253 return '<div class="breadcrumb">' . implode('<span class="gt">&gt;</span>', $breadcrumb) . '</div>';
254 }
255 }
256
257
258 /**
259 * ------------------------
260 * [EN] Format a group of form items
261 * ------------------------
262 */
263
264
265 function phptemplate_fieldset($element) {
266 if (!empty($element['#collapsible'])) {
267 if (!isset($element['#attributes']['class'])) {
268 $element['#attributes']['class'] = '';
269 }
270 $element['#attributes']['class'] .= ' collapsible';
271 if (!empty($element['#collapsed'])) {
272 $element['#attributes']['class'] .= ' collapsed';
273 }
274 }
275 return theme('nx-fieldset-template',
276 drupal_attributes($element['#attributes']),
277 ($element['#title'] ? $element['#title'] : ''),
278 (isset($element['#description']) && $element['#description'] ? $element['#description'] : ''),
279 (!empty($element['#children']) ? $element['#children'] : ''),
280 (isset($element['#value']) ? $element['#value'] : ''));
281 }
282
283
284 /**
285 * ------------------------
286 * [EN] Allow themable wrapping of all comments
287 * ------------------------
288 */
289
290
291 function phptemplate_comment_wrapper($content, $node) {
292 if (strlen($content) == 0) {return;}
293 if ($node->type == 'forum') {return '<div id="comments" class="c_all_comments">'. $content .'</div>';}
294 else {return '<div id="comments" class="c_all_comments"><h2 class="c_all_comments_title">'. t('Comments') .'</h2>'. $content .'</div>';}
295 }
296
297
298 /**
299 * ------------------------
300 * [EN] Return a set of blocks available for the current user
301 * ------------------------
302 */
303
304
305 function phptemplate_blocks($region) {
306 $output = '';
307 if ($list = block_list($region)) {
308 $blocks_num = count($list);
309 $i = 1;
310 foreach ($list as $key => $block) {
311 // [EN] where $key is "module_delta"
312 if ($blocks_num == 1) {
313 $block->nx_block_extra_class = 'single';
314 }
315 else {
316 if ($i == 1) {$block->nx_block_extra_class = 'first';}
317 if ($i == $blocks_num) {$block->nx_block_extra_class = 'last';}
318 }
319 $block->nx_block_num = $i++;
320 $output .= theme('block', $block);
321 }
322 }
323 // [EN] Add any content assigned to this region through drupal_set_content() calls.
324 $output .= drupal_get_content($region);
325 return $output;
326 }
327
328
329 /**
330 * ------------------------
331 * [EN] Return a themed table
332 * ------------------------
333 */
334
335
336 function nx_set_column_number2($cell, $num){
337 if (!is_array($cell)) {$cell = array('class' => '', 'data' => $cell);}
338 if (!isset($cell['class'])) {$cell['class'] = '';}
339 $cell['class'].= ' tc-'. $num;
340 return $cell;
341 }
342
343
344 function phptemplate_table($header, $rows, $attributes = array(), $caption = NULL) {
345
346 // [EN] Add classes to <TABLE>
347 $attributes['class'] = empty($attributes['class']) ? 'table' : ($attributes['class'] .' table');
348
349 // [EN] Add classes to HEAD <TD>/<TH>
350 if (count($header)) {
351 for ($i = 0; $i < count($header); $i++) {
352 $header[$i] = nx_set_column_number2($header[$i], $i+1);
353 }
354 }
355
356 // [EN] Add classes to BODY <TD>/<TH>
357 if (count($rows)) {
358 for ($j = 0; $j < count($rows); $j++) {
359 // [EN] Check if we're dealing with a simple or complex row
360 $tr_attributes = array();
361 if (isset($rows[$j]['data'])) {
362 foreach ($rows[$j] as $key => $value) {
363 if ($key == 'data') {$cells = $value;}
364 else {$tr_attributes[$key] = $value;}
365 }
366 } else {
367 $cells = $rows[$j];
368 }
369 if (count($cells)) {
370 for ($i = 0; $i < count($cells); $i++) {$cells[$i] = nx_set_column_number2($cells[$i], $i+1);}
371 $rows_out[] = array('data' => $cells) + $tr_attributes;
372 }
373 }
374 }
375
376 return '<div class="table_cover">'. theme_table($header, isset($rows_out) ? $rows_out : $rows , $attributes, $caption) .'</div>';
377 }
378
379
380 /**
381 * ------------------------
382 * [EN] Generate the HTML output for a menu
383 * theme_menu_tree - [EN] Generate the HTML output for a menu tree
384 * theme_menu_item - [EN] Generate the HTML output for a menu item and submenu
385 * theme_menu_item_link - [EN] Generate the HTML output for a single menu link
386 * ------------------------
387 */
388
389
390 global $NX_MENU_ITEMS_POOL;
391 global $NX_MENU_C_ITEM;
392 $NX_MENU_ITEMS_POOL = array();
393 $NX_MENU_C_ITEM = NULL;
394
395
396 function phptemplate_menu_tree($tree) {
397 $class = 'menu c_menu';
398 global $NX_MENU_C_ITEM;
399 if (isset($NX_MENU_C_ITEM['depth']) && $NX_MENU_C_ITEM['depth'] == 1){
400 $class.= ($NX_MENU_C_ITEM['menu_name'] ? ' menu-' . $NX_MENU_C_ITEM['menu_name'] : '');
401 }
402 return '<ul class="' . $class . '">'. $tree .'</ul>';
403 }
404
405
406 function phptemplate_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
407 $is_collapsed = ($menu ? 'expanded' : ($has_children ? 'collapsed' : 'leaf'));
408 $class = NX_C_ITEM_NAME . ' ' . $is_collapsed;
409 if (!empty($extra_class)) {$class .= ' '. $extra_class;} // [EN] .first and .last in extra_class
410 if ($in_active_trail) {$class .= ' active-trail';}
411 // -------------------------------------------------------------
412 global $NX_MENU_ITEMS_POOL;
413 $last_item = array_pop(&$NX_MENU_ITEMS_POOL);
414 $class .= ($last_item['depth'] ? ' depth_' . $last_item['depth'] : '');
415 $class .= ($last_item['depth'] ? ' ' . $is_collapsed . '-depth_' . $last_item['depth'] : '');
416 // -------------------------------------------------------------
417 return '<li class="'. $class .'">'. $link . $menu ."</li>\n";
418 }
419
420
421 function phptemplate_menu_item_link($link, $cover = array(
422 'outer_prefix' => '',
423 'inner_prefix' => '<span><span>',
424 'inner_suffix' => '</span></span>',
425 'outer_suffix' => '')) {
426 if (empty($link['localized_options'])) {$link['localized_options'] = array();}
427 // -------------------------------------------------------------
428 $options = $link['localized_options'];
429 $options['attributes']['class'] = NX_C_LINK_NAME . ' ' . ($link['depth'] ? 'depth_' . $link['depth'] : '');
430 // -----
431 $link['title'] = $cover['inner_prefix'] . ($options['html'] ? $link['title'] : check_plain($link['title'])) . $cover['inner_suffix'];
432 $options['html'] = TRUE;
433 // -----
434 global $NX_MENU_ITEMS_POOL, $NX_MENU_C_ITEM;
435 array_push($NX_MENU_ITEMS_POOL, $link);
436 $NX_MENU_C_ITEM = $link;
437 return $cover['outer_prefix'] . l($link['title'], $link['href'], $options) . $cover['outer_suffix'];
438 }
439

  ViewVC Help
Powered by ViewVC 1.1.2