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

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

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


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

  ViewVC Help
Powered by ViewVC 1.1.2