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

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

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


Revision 1.3 - (show annotations) (download) (as text)
Fri Feb 13 08:56:04 2009 UTC (9 months, 1 week ago) by jwolf
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--2
Changes since 1.2: +9 -9 lines
File MIME type: text/x-php
Updating HEAD
#369552 - clean implementation of rebuild_registry - by wmostrey
#369692 - collapse fieldsets - by wmostrey
1 <?php
2 // $Id: template.php,v 1.1.2.10 2009/02/13 08:22:38 jwolf Exp $
3
4 /**
5 * Initialize theme settings
6 */
7 if (is_null(theme_get_setting('user_notverified_display')) || theme_get_setting('rebuild_registry')) {
8
9 // Auto-rebuild the theme registry during theme development.
10 if(theme_get_setting('rebuild_registry')) {
11 drupal_set_message(t('The theme registry has been rebuilt. <a href="!link">Turn off</a> this feature on production websites.', array('!link' => url('admin/build/themes/settings/' . $GLOBALS['theme']))), 'warning');
12 }
13
14 global $theme_key;
15 // Get node types
16 $node_types = node_get_types('names');
17
18 /**
19 * The default values for the theme variables. Make sure $defaults exactly
20 * matches the $defaults in the theme-settings.php file.
21 */
22 $defaults = array(
23 'user_notverified_display' => 1,
24 'breadcrumb_display' => 0,
25 'search_snippet' => 1,
26 'search_info_type' => 1,
27 'search_info_user' => 1,
28 'search_info_date' => 1,
29 'search_info_comment' => 1,
30 'search_info_upload' => 1,
31 'mission_statement_pages' => 'home',
32 'front_page_title_display' => 'title_slogan',
33 'page_title_display_custom' => '',
34 'other_page_title_display' => 'ptitle_slogan',
35 'other_page_title_display_custom' => '',
36 'configurable_separator' => ' | ',
37 'meta_keywords' => '',
38 'meta_description' => '',
39 'taxonomy_display_default' => 'only',
40 'taxonomy_format_default' => 'vocab',
41 'taxonomy_enable_content_type' => 0,
42 'submitted_by_author_default' => 1,
43 'submitted_by_date_default' => 1,
44 'submitted_by_enable_content_type' => 0,
45 'readmore_default' => t('Read more'),
46 'readmore_title_default' => t('Read the rest of this posting.'),
47 'readmore_prefix_default' => '',
48 'readmore_suffix_default' => '',
49 'readmore_enable_content_type' => 0,
50 'comment_singular_default' => t('1 comment'),
51 'comment_plural_default' => t('@count comments'),
52 'comment_title_default' => t('Jump to the first comment of this posting.'),
53 'comment_prefix_default' => '',
54 'comment_suffix_default' => '',
55 'comment_new_singular_default' => t('1 new comment'),
56 'comment_new_plural_default' => t('@count new comments'),
57 'comment_new_title_default' => t('Jump to the first new comment of this posting.'),
58 'comment_new_prefix_default' => '',
59 'comment_new_suffix_default' => '',
60 'comment_add_default' => t('Add new comment'),
61 'comment_add_title_default' => t('Add a new comment to this page.'),
62 'comment_add_prefix_default' => '',
63 'comment_add_suffix_default' => '',
64 'comment_node_default' => t('Add new comment'),
65 'comment_node_title_default' => t('Share your thoughts and opinions related to this posting.'),
66 'comment_node_prefix_default' => '',
67 'comment_node_suffix_default' => '',
68 'comment_enable_content_type' => 0,
69 'rebuild_registry' => 0,
70 );
71
72 // Make the default content-type settings the same as the default theme settings,
73 // so we can tell if content-type-specific settings have been altered.
74 $defaults = array_merge($defaults, theme_get_settings());
75
76 // Set the default values for content-type-specific settings
77 foreach ($node_types as $type => $name) {
78 $defaults["taxonomy_display_{$type}"] = $defaults['taxonomy_display_default'];
79 $defaults["taxonomy_format_{$type}"] = $defaults['taxonomy_format_default'];
80 $defaults["submitted_by_author_{$type}"] = $defaults['submitted_by_author_default'];
81 $defaults["submitted_by_date_{$type}"] = $defaults['submitted_by_date_default'];
82 $defaults["readmore_{$type}"] = $defaults['readmore_default'];
83 $defaults["readmore_title_{$type}"] = $defaults['readmore_title_default'];
84 $defaults["readmore_prefix_{$type}"] = $defaults['readmore_prefix_default'];
85 $defaults["readmore_suffix_{$type}"] = $defaults['readmore_suffix_default'];
86 $defaults["comment_singular_{$type}"] = $defaults['comment_singular_default'];
87 $defaults["comment_plural_{$type}"] = $defaults['comment_plural_default'];
88 $defaults["comment_title_{$type}"] = $defaults['comment_title_default'];
89 $defaults["comment_prefix_{$type}"] = $defaults['comment_prefix_default'];
90 $defaults["comment_suffix_{$type}"] = $defaults['comment_suffix_default'];
91 $defaults["comment_new_singular_{$type}"] = $defaults['comment_new_singular_default'];
92 $defaults["comment_new_plural_{$type}"] = $defaults['comment_new_plural_default'];
93 $defaults["comment_new_title_{$type}"] = $defaults['comment_new_title_default'];
94 $defaults["comment_new_prefix_{$type}"] = $defaults['comment_new_prefix_default'];
95 $defaults["comment_new_suffix_{$type}"] = $defaults['comment_new_suffix_default'];
96 $defaults["comment_add_{$type}"] = $defaults['comment_add_default'];
97 $defaults["comment_add_title_{$type}"] = $defaults['comment_add_title_default'];
98 $defaults["comment_add_prefix_{$type}"] = $defaults['comment_add_prefix_default'];
99 $defaults["comment_add_suffix_{$type}"] = $defaults['comment_add_suffix_default'];
100 $defaults["comment_node_{$type}"] = $defaults['comment_node_default'];
101 $defaults["comment_node_title_{$type}"] = $defaults['comment_node_title_default'];
102 $defaults["comment_node_prefix_{$type}"] = $defaults['comment_node_prefix_default'];
103 $defaults["comment_node_suffix_{$type}"] = $defaults['comment_node_suffix_default'];
104 }
105
106 // Get default theme settings.
107 $settings = theme_get_settings($theme_key);
108
109 // If content type-specifc settings are not enabled, reset the values
110 if (!$settings['readmore_enable_content_type']) {
111 foreach ($node_types as $type => $name) {
112 $settings["readmore_{$type}"] = $settings['readmore_default'];
113 $settings["readmore_title_{$type}"] = $settings['readmore_title_default'];
114 $settings["readmore_prefix_{$type}"] = $settings['readmore_prefix_default'];
115 $settings["readmore_suffix_{$type}"] = $settings['readmore_suffix_default'];
116 }
117 }
118 if (!$settings['comment_enable_content_type']) {
119 foreach ($node_types as $type => $name) {
120 $defaults["comment_singular_{$type}"] = $defaults['comment_singular_default'];
121 $defaults["comment_plural_{$type}"] = $defaults['comment_plural_default'];
122 $defaults["comment_title_{$type}"] = $defaults['comment_title_default'];
123 $defaults["comment_prefix_{$type}"] = $defaults['comment_prefix_default'];
124 $defaults["comment_suffix_{$type}"] = $defaults['comment_suffix_default'];
125 $defaults["comment_new_singular_{$type}"] = $defaults['comment_new_singular_default'];
126 $defaults["comment_new_plural_{$type}"] = $defaults['comment_new_plural_default'];
127 $defaults["comment_new_title_{$type}"] = $defaults['comment_new_title_default'];
128 $defaults["comment_new_prefix_{$type}"] = $defaults['comment_new_prefix_default'];
129 $defaults["comment_new_suffix_{$type}"] = $defaults['comment_new_suffix_default'];
130 $defaults["comment_add_{$type}"] = $defaults['comment_add_default'];
131 $defaults["comment_add_title_{$type}"] = $defaults['comment_add_title_default'];
132 $defaults["comment_add_prefix_{$type}"] = $defaults['comment_add_prefix_default'];
133 $defaults["comment_add_suffix_{$type}"] = $defaults['comment_add_suffix_default'];
134 $defaults["comment_node_{$type}"] = $defaults['comment_node_default'];
135 $defaults["comment_node_title_{$type}"] = $defaults['comment_node_title_default'];
136 $defaults["comment_node_prefix_{$type}"] = $defaults['comment_node_prefix_default'];
137 $defaults["comment_node_suffix_{$type}"] = $defaults['comment_node_suffix_default'];
138 }
139 }
140
141 // Don't save the toggle_node_info_ variables
142 if (module_exists('node')) {
143 foreach (node_get_types() as $type => $name) {
144 unset($settings['toggle_node_info_'. $type]);
145 }
146 }
147 // Save default theme settings
148 variable_set(
149 str_replace('/', '_', 'theme_'. $theme_key .'_settings'),
150 array_merge($defaults, $settings)
151 );
152 // Force refresh of Drupal internals
153 theme_get_setting('', TRUE);
154 }
155
156
157 /**
158 * Modify theme variables
159 */
160 function phptemplate_preprocess(&$vars) {
161 global $user; // Get the current user
162 $vars['is_admin'] = in_array('admin', $user->roles); // Check for Admin, logged in
163 $vars['logged_in'] = ($user->uid > 0) ? TRUE : FALSE;
164 }
165
166
167 function phptemplate_preprocess_page(&$vars) {
168 // Remove sidebars if disabled
169 if (!$vars['show_blocks']) {
170 $vars['sidebar_first'] = '';
171 $vars['sidebar_last'] = '';
172 }
173 // Build array of helpful body classes
174 $body_classes = array();
175 $body_classes[] = ($vars['logged_in']) ? 'logged-in' : 'not-logged-in'; // Page user is logged in
176 $body_classes[] = ($vars['is_front']) ? 'front' : 'not-front'; // Page is front page
177 if (isset($vars['node'])) {
178 $body_classes[] = ($vars['node']) ? 'full-node' : ''; // Page is one full node
179 $body_classes[] = (($vars['node']->type == 'forum') || (arg(0) == 'forum')) ? 'forum' : ''; // Page is Forum page
180 $body_classes[] = ($vars['node']->type) ? 'node-type-'. $vars['node']->type : ''; // Page has node-type-x, e.g., node-type-page
181 }
182 else {
183 $body_classes[] = (arg(0) == 'forum') ? 'forum' : ''; // Page is Forum page
184 }
185 $body_classes[] = (module_exists('panels_page') && (panels_page_get_current())) ? 'panels' : ''; // Page is Panels page
186 $body_classes[] = 'layout-'. (($vars['sidebar_first']) ? 'first-main' : 'main') . (($vars['sidebar_last']) ? '-last' : ''); // Page sidebars are active
187 if ($vars['preface_first'] || $vars['preface_middle'] || $vars['preface_last']) { // Preface regions are active
188 $preface_regions = 'preface';
189 $preface_regions .= ($vars['preface_first']) ? '-first' : '';
190 $preface_regions .= ($vars['preface_middle']) ? '-middle' : '';
191 $preface_regions .= ($vars['preface_last']) ? '-last' : '';
192 $body_classes[] = $preface_regions;
193 }
194 if ($vars['postscript_first'] || $vars['postscript_middle'] || $vars['postscript_last']) { // Postscript regions are active
195 $postscript_regions = 'postscript';
196 $postscript_regions .= ($vars['postscript_first']) ? '-first' : '';
197 $postscript_regions .= ($vars['postscript_middle']) ? '-middle' : '';
198 $postscript_regions .= ($vars['postscript_last']) ? '-last' : '';
199 $body_classes[] = $postscript_regions;
200 }
201 $body_classes = array_filter($body_classes); // Remove empty elements
202 $vars['body_classes'] = implode(' ', $body_classes); // Create class list separated by spaces
203
204 // Add preface & postscript classes with number of active sub-regions
205 $region_list = array(
206 'prefaces' => array('preface_first', 'preface_middle', 'preface_last'),
207 'postscripts' => array('postscript_first', 'postscript_middle', 'postscript_last')
208 );
209 foreach ($region_list as $sub_region_key => $sub_region_list) {
210 $active_regions = array();
211 foreach ($sub_region_list as $region_item) {
212 if ($vars[$region_item]) {
213 $active_regions[] = $region_item;
214 }
215 }
216 $vars[$sub_region_key] = $sub_region_key .'-'. strval(count($active_regions));
217 }
218
219 // Generate menu tree from source of primary links
220 $vars['primary_links_tree'] = menu_tree(variable_get('menu_primary_links_source', 'primary-links'));
221
222 // TNT THEME SETTINGS SECTION
223 // Display mission statement on all pages
224 if (theme_get_setting('mission_statement_pages') == 'all') {
225 $vars['mission'] = theme_get_setting('mission', false);
226 }
227
228 // Hide breadcrumb on all pages
229 if (theme_get_setting('breadcrumb_display') == 0) {
230 $vars['breadcrumb'] = '';
231 }
232
233 // Set site title, slogan, mission, page title & separator
234 $title = t(variable_get('site_name', ''));
235 $slogan = t(variable_get('site_slogan', ''));
236 $mission = t(variable_get('site_mission', ''));
237 $page_title = t(drupal_get_title());
238 $title_separator = theme_get_setting('configurable_separator');
239 if (drupal_is_front_page()) { // Front page title settings
240 switch (theme_get_setting('front_page_title_display')) {
241 case 'title_slogan':
242 $vars['head_title'] = drupal_set_title($title . $title_separator . $slogan);
243 break;
244 case 'slogan_title':
245 $vars['head_title'] = drupal_set_title($slogan . $title_separator . $title);
246 break;
247 case 'title_mission':
248 $vars['head_title'] = drupal_set_title($title . $title_separator . $mission);
249 break;
250 case 'custom':
251 if (theme_get_setting('page_title_display_custom') !== '') {
252 $vars['head_title'] = drupal_set_title(t(theme_get_setting('page_title_display_custom')));
253 }
254 }
255 }
256 else { // Non-front page title settings
257 switch (theme_get_setting('other_page_title_display')) {
258 case 'ptitle_slogan':
259 $vars['head_title'] = drupal_set_title($page_title . $title_separator . $slogan);
260 break;
261 case 'ptitle_stitle':
262 $vars['head_title'] = drupal_set_title($page_title . $title_separator . $title);
263 break;
264 case 'ptitle_smission':
265 $vars['head_title'] = drupal_set_title($page_title . $title_separator . $mission);
266 break;
267 case 'ptitle_custom':
268 if (theme_get_setting('other_page_title_display_custom') !== '') {
269 $vars['head_title'] = drupal_set_title($page_title . $title_separator . t(theme_get_setting('other_page_title_display_custom')));
270 }
271 break;
272 case 'custom':
273 if (theme_get_setting('other_page_title_display_custom') !== '') {
274 $vars['head_title'] = drupal_set_title(t(theme_get_setting('other_page_title_display_custom')));
275 }
276 }
277 }
278 $vars['head_title'] = strip_tags($vars['head_title']); // Remove any potential html tags
279
280 if (!module_exists('nodewords')) {
281 if (theme_get_setting('meta_keywords') !== '') {
282 $keywords = '<meta name="keywords" content="'. theme_get_setting('meta_keywords') .'" />';
283 $vars['head'] .= $keywords ."\n";
284 }
285 if (theme_get_setting('meta_description') !== '') {
286 $keywords = '<meta name="description" content="'. theme_get_setting('meta_description') .'" />';
287 $vars['head'] .= $keywords ."\n";
288 }
289 }
290 $vars['closure'] .= '<div id="legal-notice">Theme provided by <a href="http://www.acquia.com">Acquia, Inc.</a> under GPL license from TopNotchThemes <a href="http://www.topnotchthemes.com">Drupal themes</a></div>';
291 }
292
293
294 function phptemplate_preprocess_block(&$vars) {
295 // Add regions with rounded blocks (e.g., sidebar_first, sidebar_last) to $rounded_regions array
296 $rounded_regions = array('sidebar_first','sidebar_last','postscript_first','postscript_middle','postscript_last');
297 $vars['rounded_block'] = (in_array($vars['block']->region, $rounded_regions)) ? TRUE : FALSE;
298 }
299
300
301 function phptemplate_preprocess_node(&$vars) {
302 // Build array of handy node classes
303 $node_classes = array();
304 $node_classes[] = $vars['zebra']; // Node is odd or even
305 $node_classes[] = (!$vars['node']->status) ? 'node-unpublished' : ''; // Node is unpublished
306 $node_classes[] = ($vars['sticky']) ? 'sticky' : ''; // Node is sticky
307 $node_classes[] = (isset($vars['node']->teaser)) ? 'teaser' : 'full-node'; // Node is teaser or full-node
308 $node_classes[] = 'node-type-'. $vars['node']->type; // Node is type-x, e.g., node-type-page
309 $node_classes = array_filter($node_classes); // Remove empty elements
310 $vars['node_classes'] = implode(' ', $node_classes); // Implode class list with spaces
311
312 // Add node_bottom region content
313 $vars['node_bottom'] = theme('blocks', 'node_bottom');
314
315 // Node Theme Settings
316
317 // Date & author
318 $date = t('Posted ') . format_date($vars['node']->created, 'medium'); // Format date as small, medium, or large
319 $author = theme('username', $vars['node']);
320 $author_only_separator = t('Posted by ');
321 $author_date_separator = t(' by ');
322 $submitted_by_content_type = (theme_get_setting('submitted_by_enable_content_type') == 1) ? $vars['node']->type : 'default';
323 $date_setting = (theme_get_setting('submitted_by_date_'. $submitted_by_content_type) == 1);
324 $author_setting = (theme_get_setting('submitted_by_author_'. $submitted_by_content_type) == 1);
325 $author_separator = ($date_setting) ? $author_date_separator : $author_only_separator;
326 $date_author = ($date_setting) ? $date : '';
327 $date_author .= ($author_setting) ? $author_separator . $author : '';
328 $vars['submitted'] = $date_author;
329
330 // Taxonomy
331 $taxonomy_content_type = (theme_get_setting('taxonomy_enable_content_type') == 1) ? $vars['node']->type : 'default';
332 $taxonomy_display = theme_get_setting('taxonomy_display_'. $taxonomy_content_type);
333 $taxonomy_format = theme_get_setting('taxonomy_format_'. $taxonomy_content_type);
334 if ((module_exists('taxonomy')) && ($taxonomy_display == 'all' || ($taxonomy_display == 'only' && $vars['page']))) {
335 $vocabularies = taxonomy_get_vocabularies($vars['node']->type);
336 $output = '';
337 $vocab_delimiter = '';
338 foreach ($vocabularies as $vocabulary) {
339 if (theme_get_setting('taxonomy_vocab_display_'. $taxonomy_content_type .'_'. $vocabulary->vid) == 1) {
340 $terms = taxonomy_node_get_terms_by_vocabulary($vars['node'], $vocabulary->vid);
341 if ($terms) {
342 $output .= ($taxonomy_format == 'vocab') ? '<li class="vocab vocab-'. $vocabulary->vid .'"><span class="vocab-name">'. $vocabulary->name .':</span> <ul class="vocab-list">' : '';
343 $links = array();
344 foreach ($terms as $term) {
345 $links[] = '<li class="vocab-term">'. l($term->name, taxonomy_term_path($term), array('attributes' => array('rel' => 'tag', 'title' => strip_tags($term->description)))) .'</li>';
346 }
347 if ($taxonomy_format == 'list') {
348 $output .= $vocab_delimiter; // Add comma between vocabularies
349 $vocab_delimiter = ', '; // Use a comma delimiter after first displayed vocabulary
350 }
351 $output .= implode(", ", $links);
352 $output .= ($taxonomy_format == 'vocab') ? '</ul></li>' : '';
353 }
354 }
355 }
356 if ($output != '') {
357 $output = '<ul class="taxonomy">'. $output .'</ul>';
358 }
359 $vars['terms'] = $output;
360 }
361 else {
362 $vars['terms'] = '';
363 }
364
365 // Node Links
366 if (isset($vars['node']->links['node_read_more'])) {
367 $node_content_type = (theme_get_setting('readmore_enable_content_type') == 1) ? $vars['node']->type : 'default';
368 $vars['node']->links['node_read_more'] = array(
369 'title' => _themesettings_link(
370 theme_get_setting('readmore_prefix_'. $node_content_type),
371 theme_get_setting('readmore_suffix_'. $node_content_type),
372 theme_get_setting('readmore_'. $node_content_type),
373 'node/'. $vars['node']->nid,
374 array(
375 'attributes' => array('title' => theme_get_setting('readmore_title_'. $node_content_type)),
376 'query' => NULL, 'fragment' => NULL, 'absolute' => FALSE, 'html' => TRUE
377 )
378 ),
379 'attributes' => array('class' => 'readmore-item'),
380 'html' => TRUE,
381 );
382 }
383 if (isset($vars['node']->links['comment_add'])) {
384 $node_content_type = (theme_get_setting('comment_enable_content_type') == 1) ? $vars['node']->type : 'default';
385 if ($vars['teaser']) {
386 $vars['node']->links['comment_add'] = array(
387 'title' => _themesettings_link(
388 theme_get_setting('comment_add_prefix_'. $node_content_type),
389 theme_get_setting('comment_add_suffix_'. $node_content_type),
390 theme_get_setting('comment_add_'. $node_content_type),
391 "comment/reply/".$vars['node']->nid,
392 array(
393 'attributes' => array('title' => theme_get_setting('comment_add_title_'. $node_content_type)),
394 'query' => NULL, 'fragment' => 'comment-form', 'absolute' => FALSE, 'html' => TRUE
395 )
396 ),
397 'attributes' => array('class' => 'comment-add-item'),
398 'html' => TRUE,
399 );
400 }
401 else {
402 $vars['node']->links['comment_add'] = array(
403 'title' => _themesettings_link(
404 theme_get_setting('comment_node_prefix_'. $node_content_type),
405 theme_get_setting('comment_node_suffix_'. $node_content_type),
406 theme_get_setting('comment_node_'. $node_content_type),
407 "comment/reply/".$vars['node']->nid,
408 array(
409 'attributes' => array('title' => theme_get_setting('comment_node_title_'. $node_content_type)),
410 'query' => NULL, 'fragment' => 'comment-form', 'absolute' => FALSE, 'html' => TRUE
411 )
412 ),
413 'attributes' => array('class' => 'comment-node-item'),
414 'html' => TRUE,
415 );
416 }
417 }
418 if (isset($vars['node']->links['comment_new_comments'])) {
419 $node_content_type = (theme_get_setting('comment_enable_content_type') == 1) ? $vars['node']->type : 'default';
420 $vars['node']->links['comment_new_comments'] = array(
421 'title' => _themesettings_link(
422 theme_get_setting('comment_new_prefix_'. $node_content_type),
423 theme_get_setting('comment_new_suffix_'. $node_content_type),
424 format_plural(
425 comment_num_new($vars['node']->nid),
426 theme_get_setting('comment_new_singular_'. $node_content_type),
427 theme_get_setting('comment_new_plural_'. $node_content_type)
428 ),
429 "node/".$vars['node']->nid,
430 array(
431 'attributes' => array('title' => theme_get_setting('comment_new_title_'. $node_content_type)),
432 'query' => NULL, 'fragment' => 'new', 'absolute' => FALSE, 'html' => TRUE
433 )
434 ),
435 'attributes' => array('class' => 'comment-new-item'),
436 'html' => TRUE,
437 );
438 }
439 if (isset($vars['node']->links['comment_comments'])) {
440 $node_content_type = (theme_get_setting('comment_enable_content_type') == 1) ? $vars['node']->type : 'default';
441 $vars['node']->links['comment_comments'] = array(
442 'title' => _themesettings_link(
443 theme_get_setting('comment_prefix_'. $node_content_type),
444 theme_get_setting('comment_suffix_'. $node_content_type),
445 format_plural(
446 comment_num_all($vars['node']->nid),
447 theme_get_setting('comment_singular_'. $node_content_type),
448 theme_get_setting('comment_plural_'. $node_content_type)
449 ),
450 "node/".$vars['node']->nid,
451 array(
452 'attributes' => array('title' => theme_get_setting('comment_title_'. $node_content_type)),
453 'query' => NULL, 'fragment' => 'comments', 'absolute' => FALSE, 'html' => TRUE
454 )
455 ),
456 'attributes' => array('class' => 'comment-item'),
457 'html' => TRUE,
458 );
459 }
460 $vars['links'] = theme('links', $vars['node']->links, array('class' => 'links inline'));
461 }
462
463
464 function phptemplate_preprocess_comment(&$vars) {
465 global $user;
466 // Build array of handy comment classes
467 $comment_classes = array();
468 static $comment_odd = TRUE; // Comment is odd or even
469 $comment_classes[] = $comment_odd ? 'odd' : 'even';
470 $comment_odd = !$comment_odd;
471 $comment_classes[] = ($vars['comment']->status == COMMENT_NOT_PUBLISHED) ? 'comment-unpublished' : ''; // Comment is unpublished
472 $comment_classes[] = ($vars['comment']->new) ? 'comment-new' : ''; // Comment is new
473 $comment_classes[] = ($vars['comment']->uid == 0) ? 'comment-by-anon' : ''; // Comment is by anonymous user
474 $comment_classes[] = ($user->uid && $vars['comment']->uid == $user->uid) ? 'comment-mine' : ''; // Comment is by current user
475 $node = node_load($vars['comment']->nid); // Comment is by node author
476 $vars['author_comment'] = ($vars['comment']->uid == $node->uid) ? TRUE : FALSE;
477 $comment_classes[] = ($vars['author_comment']) ? 'comment-by-author' : '';
478 $comment_classes = array_filter($comment_classes); // Remove empty elements
479 $vars['comment_classes'] = implode(' ', $comment_classes); // Create class list separated by spaces
480 // Date & author
481 $submitted_by = t('by ') .'<span class="comment-name">'. theme('username', $vars['comment']) .'</span>';
482 $submitted_by .= t(' - ') .'<span class="comment-date">'. format_date($vars['comment']->timestamp, 'small') .'</span>'; // Format date as small, medium, or large
483 $vars['submitted'] = $submitted_by;
484 }
485
486
487 /**
488 * Set defaults for comments display
489 * (Requires comment-wrapper.tpl.php file in theme directory)
490 */
491 function phptemplate_preprocess_comment_wrapper(&$vars) {
492 $vars['display_mode'] = COMMENT_MODE_FLAT_EXPANDED;
493 $vars['display_order'] = COMMENT_ORDER_OLDEST_FIRST;
494 $vars['comment_controls_state'] = COMMENT_CONTROLS_HIDDEN;
495 }
496
497
498 /**
499 * Adds a class for the style of view
500 * (e.g., node, teaser, list, table, etc.)
501 * (Requires views-view.tpl.php file in theme directory)
502 */
503 function phptemplate_preprocess_views_view(&$vars) {
504 $vars['css_name'] = $vars['css_name'] .' view-style-'. views_css_safe(strtolower($vars['view']->type));
505 }
506
507
508 /**
509 * Modify search results based on theme settings
510 */
511 function phptemplate_preprocess_search_result(&$variables) {
512 static $search_zebra = 'even';
513 $search_zebra = ($search_zebra == 'even') ? 'odd' : 'even';
514 $variables['search_zebra'] = $search_zebra;
515
516 $result = $variables['result'];
517 $variables['url'] = check_url($result['link']);
518 $variables['title'] = check_plain($result['title']);
519
520 // Check for existence. User search does not include snippets.
521 $variables['snippet'] = '';
522 if (isset($result['snippet']) && theme_get_setting('search_snippet')) {
523 $variables['snippet'] = $result['snippet'];
524 }
525
526 $info = array();
527 if (!empty($result['type']) && theme_get_setting('search_info_type')) {
528 $info['type'] = check_plain($result['type']);
529 }
530 if (!empty($result['user']) && theme_get_setting('search_info_user')) {
531 $info['user'] = $result['user'];
532 }
533 if (!empty($result['date']) && theme_get_setting('search_info_date')) {
534 $info['date'] = format_date($result['date'], 'small');
535 }
536 if (isset($result['extra']) && is_array($result['extra'])) {
537 // $info = array_merge($info, $result['extra']); Drupal bug? [extra] array not keyed with 'comment' & 'upload'
538 if (!empty($result['extra'][0]) && theme_get_setting('search_info_comment')) {
539 $info['comment'] = $result['extra'][0];
540 }
541 if (!empty($result['extra'][1]) && theme_get_setting('search_info_upload')) {
542 $info['upload'] = $result['extra'][1];
543 }
544 }
545
546 // Provide separated and grouped meta information.
547 $variables['info_split'] = $info;
548 $variables['info'] = implode(' - ', $info);
549
550 // Provide alternate search result template.
551 $variables['template_files'][] = 'search-result-'. $variables['type'];
552 }
553
554
555 /**
556 * Override username theming to display/hide 'not verified' text
557 */
558 function phptemplate_username($object) {
559 if ($object->uid && $object->name) {
560 // Shorten the name when it is too long or it will break many tables.
561 if (drupal_strlen($object->name) > 20) {
562 $name = drupal_substr($object->name, 0, 15) .'...';
563 }
564 else {
565 $name = $object->name;
566 }
567 if (user_access('access user profiles')) {
568 $output = l($name, 'user/'. $object->uid, array('attributes' => array('title' => t('View user profile.'))));
569 }
570 else {
571 $output = check_plain($name);
572 }
573 }
574 else if ($object->name) {
575 // Sometimes modules display content composed by people who are
576 // not registered members of the site (e.g. mailing list or news
577 // aggregator modules). This clause enables modules to display
578 // the true author of the content.
579 if (!empty($object->homepage)) {
580 $output = l($object->name, $object->homepage, array('attributes' => array('rel' => 'nofollow')));
581 }
582 else {
583 $output = check_plain($object->name);
584 }
585 // Display or hide 'not verified' text
586 if (theme_get_setting('user_notverified_display') == 1) {
587 $output .= ' ('. t('not verified') .')';
588 }
589 }
590 else {
591 $output = variable_get('anonymous', t('Anonymous'));
592 }
593 return $output;
594 }
595
596
597 /**
598 * Set default form file input size
599 */
600 function phptemplate_file($element) {
601 $element['#size'] = 40;
602 return theme_file($element);
603 }
604
605
606 /**
607 * Creates a link with prefix and suffix text
608 *
609 * @param $prefix
610 * The text to prefix the link.
611 * @param $suffix
612 * The text to suffix the link.
613 * @param $text
614 * The text to be enclosed with the anchor tag.
615 * @param $path
616 * The Drupal path being linked to, such as "admin/content/node". Can be an external
617 * or internal URL.
618 * - If you provide the full URL, it will be considered an
619 * external URL.
620 * - If you provide only the path (e.g. "admin/content/node"), it is considered an
621 * internal link. In this case, it must be a system URL as the url() function
622 * will generate the alias.
623 * @param $options
624 * An associative array that contains the following other arrays and values
625 * @param $attributes
626 * An associative array of HTML attributes to apply to the anchor tag.
627 * @param $query
628 * A query string to append to the link.
629 * @param $fragment
630 * A fragment identifier (named anchor) to append to the link.
631 * @param $absolute
632 * Whether to force the output to be an absolute link (beginning with http:).
633 * Useful for links that will be displayed outside the site, such as in an RSS
634 * feed.
635 * @param $html
636 * Whether the title is HTML or not (plain text)
637 * @return
638 * an HTML string containing a link to the given path.
639 */
640 function _themesettings_link($prefix, $suffix, $text, $path, $options) {
641 return $prefix . (($text) ? l($text, $path, $options) : '') . $suffix;
642 }

  ViewVC Help
Powered by ViewVC 1.1.2