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

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

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


Revision 1.5 - (show annotations) (download) (as text)
Wed Jun 25 12:04:34 2008 UTC (17 months ago) by chrisada
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1
Changes since 1.4: +104 -19 lines
File MIME type: text/x-php
Initial commit for Drupal 6
1 <?php
2
3 // Don't display empty help from node_help().
4 if ($vars['help'] == "<div class=\"help\"><p></p>\n</div>") {
5 $vars['help'] = '';
6 }
7
8 // Classes for body element. Allows advanced theming based on context
9 // (home page, node of certain type, etc.)
10 $body_classes = array($vars['body_classes']);
11 if (!$vars['is_front']) {
12 // Add unique classes for each page and website section
13 $path = drupal_get_path_alias($_GET['q']);
14 list($section, ) = explode('/', $path, 2);
15 $body_classes[] = k2_id_safe('page-' . $path);
16 $body_classes[] = k2_id_safe('section-' . $section);
17 if (arg(0) == 'node') {
18 if (arg(1) == 'add') {
19 if ($section == 'node') {
20 array_pop($body_classes); // Remove 'section-node'
21 }
22 $body_classes[] = 'section-node-add'; // Add 'section-node-add'
23 }
24 elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) {
25 if ($section == 'node') {
26 array_pop($body_classes); // Remove 'section-node'
27 }
28 $body_classes[] = 'section-node-' . arg(2); // Add 'section-node-edit' or 'section-node-delete'
29 }
30 }
31 }
32 $vars['body_classes'] = implode(' ', $body_classes); // Concatenate with spaces
33
34 /**
35 * Converts a string to a suitable html ID attribute.
36 *
37 * http://www.w3.org/TR/html4/struct/global.html#h-7.5.2 specifies what makes a
38 * valid ID attribute in HTML. This function:
39 *
40 * - Ensure an ID starts with an alpha character by optionally adding an 'n'.
41 * - Replaces any character except A-Z, numbers, and underscores with dashes.
42 * - Converts entire string to lowercase.
43 *
44 * @param $string
45 * The string
46 * @return
47 * The converted string
48 */
49 function k2_id_safe($string) {
50 // Replace with dashes anything that isn't A-Z, numbers, dashes, or underscores.
51 $string = strtolower(preg_replace('/[^a-zA-Z0-9_-]+/', '-', $string));
52 // If the first character is not a-z, add 'n' in front.
53 if (!ctype_lower($string{0})) { // Don't use ctype_alpha since its locale aware.
54 $string = 'id' . $string;
55 }
56 return $string;
57 }
58
59 /**
60 * Allow themable wrapping of all comments.
61 */
62 function k2_comment_wrapper($content, $type = null) {
63 static $node_type;
64 if (isset($type)) $node_type = $type;
65
66 if (!$content || $node_type == 'forum') {
67 return '<span id="comments">'. $content . '</span>';
68 }
69 else {
70 return '<h4><span id="comments"></span>'. t('Comments') .'</h4><ol id="commentlist">'. $content .'</ol>';
71 }
72 }
73
74 /**
75 * Override or insert PHPTemplate variables into the comment templates.
76 *
77 * @param $vars
78 * A sequential array of variables to pass to the theme template.
79 * @param $hook
80 * The name of the theme function being called ("comment" in this case.)
81 */
82 function k2_preprocess_comment(&$vars, $hook) {
83 global $user;
84
85 // We load the node object that the current comment is attached to
86 $node = node_load($vars['comment']->nid);
87 // If the author of this comment is equal to the author of the node, we
88 // set a variable so we can theme this comment uniquely.
89 $vars['author_comment'] = $vars['comment']->uid == $node->uid ? TRUE : FALSE;
90
91 $comment_classes = array();
92
93 // Odd/even handling
94 static $comment_odd = TRUE;
95 $comment_classes[] = $comment_odd ? 'odd' : 'even';
96 $comment_odd = !$comment_odd;
97
98 if ($vars['comment']->status == COMMENT_NOT_PUBLISHED) {
99 $comment_classes[] = 'comment-unpublished';
100 $vars['unpublished'] = TRUE;
101 }
102 else {
103 $vars['unpublished'] = FALSE;
104 }
105 if ($vars['author_comment']) {
106 // Comment is by the node author
107 $comment_classes[] = 'bypostauthor';
108 }
109 if ($vars['comment']->uid == 0) {
110 // Comment is by an anonymous user
111 $comment_classes[] = 'comment-by-anon';
112 }
113 if ($user->uid && $vars['comment']->uid == $user->uid) {
114 // Comment was posted by current user
115 $comment_classes[] = 'comment-mine';
116 }
117 $vars['comment_classes'] = implode(' ', $comment_classes);
118
119 // If comment subjects are disabled, don't display 'em
120 if (variable_get('comment_subject_field', 1) == 0) {
121 $vars['title'] = '';
122 }
123 }
124
125 /**
126 * Override or insert PHPTemplate variables into the templates.
127 */
128 function _phptemplate_variables($hook, $vars) {
129 if ($hook == 'page') {
130
131 if ($secondary = menu_secondary_local_tasks()) {
132 $output = '<span class="clear"></span>';
133 $output .= "<ul class=\"tabs secondary\">\n". $secondary ."</ul>\n";
134 $vars['tabs2'] = $output;
135 }
136
137 // Hook into color.module
138 if (module_exists('color')) {
139 _color_page_alter($vars);
140 }
141 return $vars;
142 }
143 return array();
144 }
145
146 /**
147 * Returns the rendered local tasks. The default implementation renders
148 * them as tabs.
149 *
150 * @ingroup themeable
151 */
152 function phptemplate_menu_local_tasks() {
153 $output = '';
154
155 if ($primary = menu_primary_local_tasks()) {
156 $output .= "<ul class=\"tabs primary\">\n". $primary ."</ul>\n";
157 }
158
159 return $output;
160 }

  ViewVC Help
Powered by ViewVC 1.1.2