Issue #1016038 by arrrgh: Avoid "Undefined Index" error.
[project/nitobe.git] / template.php
CommitLineData
aa43a991 1<?php
aa43a991 2/**
c53fc478
SL
3 * @file
4 * The core functions for the Nitobe theme.
aa43a991
SL
5 */
6
73d4b474 7require_once drupal_get_path('theme', 'nitobe') . '/nitobe.utils.inc';
cc7ea041 8
77afe95f
SL
9
10/**
c53fc478
SL
11 * Returns the path to the main Nitobe theme directory.
12 *
13 * @return string
14 * The path to Nitobe.
77afe95f 15 */
c53fc478 16function nitobe_theme_path() {
77afe95f 17 static $theme_path;
c675ea8a 18
77afe95f
SL
19 if (!isset($theme_path)) {
20 global $theme;
cc7ea041 21
57d25656 22 if ($theme == "nitobe") {
77afe95f 23 $theme_path = path_to_theme();
c53fc478 24 } else {
57d25656 25 $theme_path = drupal_get_path("theme", "nitobe");
77afe95f
SL
26 }
27 }
c53fc478 28
77afe95f
SL
29 return $theme_path;
30}
31
aa43a991
SL
32
33/**
c53fc478 34 * Overrides theme_pager() and alters the default quantity of pager items.
aa43a991 35 *
c53fc478
SL
36 * @param array $tags
37 * Labels for the controls in the pager.
38 * @param int $limit
39 * The number of query results to display per page.
40 * @param int $element
41 * An optional ID to distinguish between multiple pagers on one page.
42 * @param array $parameters
43 * An mapping of query string parameters to append to the pager links.
44 * @param int $quantity
45 * The number of page items to show in the pager. If this value is zero (0),
46 * the item count specified by the theme setting nitobe_pager_page_count will
47 * be used (5 if not set).
09639ced 48 *
c53fc478
SL
49 * @return string
50 * The HTML that generates the query pager.
aa43a991 51 */
c53fc478
SL
52function nitobe_pager($tags = array(), $limit = 10, $element = 0,
53 $parameters = array(), $quantity = 0) {
54 if ($quantity == 0) {
aaf80833 55 $quantity = theme_get_setting("nitobe_pager_page_count");
c53fc478 56 $quantity = empty($quantity) ? 5 : $quantity;
aa43a991 57 }
c53fc478
SL
58
59 return theme_pager($tags, $limit, $element, $parameters, $quantity);
aa43a991
SL
60}
61
62
63/**
c53fc478
SL
64 * Decorates theme_username() to strip the " (not verified)" string from the
65 * commenter's name.
aa43a991 66 *
c53fc478
SL
67 * @param object $account
68 * An instance of a user object.
09639ced 69 *
c53fc478
SL
70 * @return string
71 * The altered HTML output from theme_username().
aa43a991 72 */
aaf80833 73function __nitobe_username($account) {
c53fc478 74 $output = theme_username($account);
d719a8b6 75
57d25656
SL
76 if ((boolean)theme_get_setting("nitobe_remove_not_verified")) {
77 $to_strip = " (" . t("not verified") . ")";
78 $output = str_replace($to_strip, "", $output);
aa43a991 79 }
09639ced 80
aa43a991
SL
81 return $output;
82}
83
84
85/**
c53fc478
SL
86 * Preprocesses the user picture.
87 *
88 * If no default user picture is provided, and pictures are enabled, use the
89 * theme's default user picture.
77afe95f 90 *
4220d927 91 * @param array &$variables
c53fc478 92 * The template arguments.
77afe95f 93 */
4220d927
SL
94function nitobe_preprocess_user_picture(&$variables) {
95 $account = $variables["account"];
57d25656 96
4220d927 97 if (empty($variables["user_picture"]) && (variable_get("user_pictures", 0) != 0)) {
57d25656
SL
98 $picture = nitobe_theme_path() . "/images/user-icon.jpg";
99 $name = $account->name ? $account->name :
100 variable_get("anonymous", t("Anonymous"));
c53fc478
SL
101 $alt = t("@user's picture", array('@user' => $name));
102
4220d927
SL
103 $variables["user_picture"] =
104 theme("image", array("path" => $picture, "alt" => $alt, "title" => $alt));
c53fc478
SL
105
106 // -- Link the picture if allowed.
57d25656 107 if (!empty($account->uid) && user_access("access user profiles")) {
c53fc478 108 $attributes = array(
57d25656
SL
109 "attributes" => array(
110 "title" => t("View user profile."),
c53fc478 111 ),
57d25656 112 "html" => TRUE
c53fc478
SL
113 );
114
4220d927
SL
115 $variables["user_picture"] =
116 l($variables["user_picture"], "user/{$account->uid}", $attributes);
77afe95f
SL
117 }
118 }
119}
120
121
122/**
c53fc478 123 * Determines whether to show the date stamp for the given node.
aa43a991 124 *
c53fc478
SL
125 * @param string $type
126 * The machine readable name of the type to check.
09639ced 127 *
c53fc478
SL
128 * @return boolean
129 * TRUE if the node is of a type that should show the date stamp, FALSE if
130 * not.
aa43a991 131 */
d719a8b6 132function nitobe_show_datestamp($type) {
57d25656
SL
133 $default = drupal_map_assoc(array("blog", "forum", "poll", "article"));
134 $valid_types = theme_get_setting("nitobe_show_datestamp");
d719a8b6 135 $valid_types = (!empty($valid_types)) ? $valid_types : $default;
aa43a991 136
d719a8b6 137 return (array_key_exists($type, $valid_types) && ($valid_types[$type] === $type));
60a041ea
SL
138}
139
140
141/**
c53fc478
SL
142 * Produces the title effect.
143 *
aa43a991
SL
144 * Removes the spaces between words in the given string and returns an HTML
145 * string with every other word wrapped in a span with the class "alt-color".
146 *
c53fc478
SL
147 * @param string $title
148 * The text to render.
09639ced 149 *
c53fc478
SL
150 * @return string
151 * The rendered HTML.
aa43a991 152 */
57d25656
SL
153function nitobe_title_effect($title = "") {
154 $words = explode(" ", $title);
155 $result = "";
09639ced 156
aa43a991
SL
157 if (is_array($words)) {
158 $alt = FALSE;
159 foreach ($words as $word) {
160 if ($alt) {
57d25656 161 $result .= "<span class=\"alt-color\">{$word}</span>";
c53fc478 162 } else {
aa43a991
SL
163 $result .= $word;
164 }
09639ced 165
aa43a991
SL
166 $alt = !$alt;
167 }
168 }
09639ced 169
aa43a991
SL
170 return $result;
171}
172
173
174/**
c53fc478 175 * Adds the JavaScript and CSS required for the masthead image.
63f14243 176 *
c53fc478
SL
177 * @param array &$vars
178 * The page template variables.
63f14243 179 */
cc7ea041 180function _nitobe_add_masthead_image(&$vars) {
c53fc478
SL
181 // -- Determine the header image if it is set, or add the JavaScript for
182 // -- random header images.
57d25656
SL
183 $header_img = theme_get_setting("nitobe_header_image");
184 $header_img = empty($header_img) ? "<random>" : $header_img;
cc7ea041
SL
185 $css = _nitobe_fixed_header_css($header_img);
186 $css_opts = array(
57d25656
SL
187 "type" => "inline",
188 "group" => CSS_THEME,
cc7ea041 189 );
c53fc478 190
57d25656 191 if ($header_img == "<random>") {
cc7ea041
SL
192 $image = array_rand(_nitobe_get_header_list());
193 $css = _nitobe_fixed_header_css($image);
194 $js = _nitobe_random_header_js();
195 $js_opts = array(
57d25656
SL
196 "type" => "inline",
197 "group" => JS_THEME,
cc7ea041
SL
198 );
199
200 drupal_add_js($js, $js_opts);
63f14243 201 }
cc7ea041
SL
202
203 drupal_add_css($css, $css_opts);
c53fc478 204}
c675ea8a 205
c675ea8a 206
c53fc478 207/**
9e0b14ce 208 * Preprocess the nodes.
c53fc478 209 *
9e0b14ce 210 * @param array &$variables
c53fc478 211 * The template variables. After invoking this function, these keys will be
9e0b14ce
SL
212 * added to $variables:
213 * - nitobe_node_author: The node's "posted by" text and author link.
214 * - nitobe_perma_title: The localized permalink text for the node.
215 * - nitobe_show_meta: Indicates whether the meta data div should be
216 * rendered.
217 * - nitobe_node_timestamp: The timestamp for this type, if one should be
218 * rendered for this type.
c53fc478 219 */
9e0b14ce
SL
220function nitobe_preprocess_node(&$variables) {
221 $content = $variables["content"];
57d25656 222 $node = $variables["node"];
9e0b14ce 223
4220d927
SL
224 $variables["nitobe_perma_title"] =
225 t("Permanent Link to !title", array("!title" => $variables['title']));
9e0b14ce 226
4220d927
SL
227 if ($variables["display_submitted"]) {
228 $variables["nitobe_node_author"] =
229 t("Posted by !author", array("!author" => $variables["name"]));
63f14243 230 }
9e0b14ce 231
4220d927 232 if ($variables["display_submitted"] && isset($node->created)) {
80529006
SL
233 $date_format = theme_get_setting("nitobe_node_datestamp_format");
234 $variables['nitobe_node_timestamp'] =
235 empty($date_format) ? "" : format_date($node->created, "custom", $date_format);
9e0b14ce
SL
236 }
237
238 $variables["nitobe_show_meta"] = !empty($content["field_tags"]) ||
239 !empty($content["links"]);
63f14243
SL
240}
241
242
243/**
c53fc478 244 * Provides page variables for the maintenance page.
aa43a991 245 *
c53fc478
SL
246 * @param array &$vars
247 * The template variables. After invoking this function, this array will have
248 * the same added values provided by nitobe_preprocess_page().
aa43a991 249 *
c53fc478 250 * @see nitobe_preprocess_page
aa43a991 251 */
4220d927
SL
252function nitobe_preprocess_maintenance_page(&$variables) {
253 nitobe_preprocess_page($variables);
254 nitobe_process_page($variables);
aa43a991
SL
255}
256
257
aa43a991 258/**
73d4b474
SL
259 * Preprocesses the regions.
260 *
261 * The function checks for the presence of the keys "#nitobe_classes" and
262 * "#nitobe_vars" in $variables["elements"] and uses them to add classes and
263 * template variables, respectively.
bf2114bc
SL
264 *
265 * @param array &$variables
57d25656
SL
266 * The template variables. After invoking this function, &$variables will
267 * contain the key "nitobe_force_render" indicating that the region should
268 * render even if empty.
269 *
270 * @see region.tpl.php
bf2114bc
SL
271 */
272function nitobe_preprocess_region(&$variables) {
73d4b474
SL
273 $region = $variables["region"];
274 $elements = $variables["elements"];
275
57d25656
SL
276 // -- Indicate if the theme should render this region even if it is empty.
277 $variables["nitobe_force_render"] = isset($elements["#nitobe_force_render"]) ?
278 $elements["#nitobe_force_render"] : FALSE;
279
73d4b474
SL
280 // -- If any layout classes were added by nitobe_preprocess_page(), those
281 // -- are added here.
282 if (!empty($elements["#nitobe_classes"])) {
283 $variables["classes_array"] =
284 array_merge($elements["#nitobe_classes"], $variables["classes_array"]);
285 }
286
287 // -- If there are any Nitobe specific variables added by
288 // -- nitobe_preprocess_page(), add those to the region's template scope.
289 if (!empty($elements["#nitobe_vars"])) {
290 foreach ($elements["#nitobe_vars"] as $name => $value) {
291 $variables[$name] = $value;
292 }
293 }
294}
295
bf2114bc 296
73d4b474
SL
297/**
298 * Builds the title_group region.
299 *
300 * After this function is invoked, the array &$variables["page"]["title_group"]
301 * will be populated with the necessary data to render the region. This will
302 * result in the necessary classes being added to the region and will add
303 * the following variables to region--title-group.tpl.php:
304 * - $front_page The path of the site's front page.
305 * - $logo The URI for the site logo, if present.
306 * - $nitobe_title The site title with Nitobe's title effect applied.
307 * - $title The page title, if present
308 * - $title_prefix An array of title prefix data for this page.
309 * - $title_suffix An array of title suffix data for this page.
310 * - $site_name The site's name.
311 * - $site_slogan The site slogan, if present.
312 *
313 * @note This is only invoked by nitobe_preprocess_page() in order to pass
314 * necessary layout information to the region.
315 *
316 * @param array &$variables
317 * The page template variables passed from nitobe_preprocess_page().
318 *
319 * @see nitobe_preprocess_region()
320 * @see region--title-group.tpl.php
57d25656 321 * @see page.tpl.php
73d4b474
SL
322 */
323function _nitobe_build_title_group(&$variables) {
324 $page = $variables["page"];
325 $nitobe_vars = array();
326
327 $class = empty($page["header"]) ? "grid-16" : "grid-10";
328 $variables["page"]["title_group"]["#nitobe_classes"] = array($class);
329
330 // -- Handle the title effect
331 if (isset($variables["site_name"]) &&
332 ((boolean)theme_get_setting("nitobe_title_effect") == TRUE)) {
333 $nitobe_vars["nitobe_title"] = nitobe_title_effect(check_plain($variables["site_name"]));
334 } else {
335 $nitobe_vars["nitobe_title"] = check_plain($variables["site_name"]);
bf2114bc 336 }
aaf80833 337
73d4b474 338 // -- Copy necessary values from the page variables.
57d25656 339 $keys = array("front_page", "logo", "site_name", "site_slogan", "title");
73d4b474
SL
340 _nitobe_copy_if_exists($variables, $nitobe_vars, $keys);
341
4220d927
SL
342 $variables["page"]["title_group"]["#region"] = "title_group";
343 $variables["page"]["title_group"]["#sorted"] = TRUE;
344 $variables["page"]["title_group"]["#nitobe_force_render"] = TRUE;
345 $variables["page"]["title_group"]["#theme_wrappers"] = array("region");
346 $variables["page"]["title_group"]["#nitobe_vars"] = $nitobe_vars;
73d4b474
SL
347}
348
349
350/**
351 * Builds the menu bar.
352 *
353 * After this function is invoked, the array &$variables["page"]["menu_bar"]
354 * will be populated with the necessary data to render the region. This will
355 * result in the necessary classes being added to the region and will add
356 * the following variables to region--menu-bar.tpl.php if primary and
357 * secondary menus are available:
358 * - $main_menu The array of primary links.
359 * - $nitobe_main_menu The HTML for the rendered primary links.
360 * - $nitobe_secondary_menu The HTML for the rendered secondary links.
361 * - $secondary_menu The array of secondary links.
362 *
363 * @note This is only invoked by nitobe_preprocess_page() in order to pass
364 * necessary layout information to the region.
365 *
366 * @param array &$variables
367 * The page template variables passed from nitobe_preprocess_page().
368 *
369 * @see nitobe_preprocess_region()
370 * @see region--menu-bar.tpl.php
57d25656 371 * @see page.tpl.php
73d4b474
SL
372 */
373function _nitobe_build_menu_bar(&$variables) {
374 $nitobe_vars = array();
375
376 if (isset($variables["secondary_menu"])) {
377 $nitobe_vars["nitobe_secondary_menu"] = theme("links", array(
378 "links" => $variables["secondary_menu"],
379 "attributes" => array(
380 "id" => "secondary-nav",
d516f32e 381 "class" => array("secondary-nav", "inline", "links", "secondary-menu", "grid-16"),
73d4b474
SL
382 ),
383 "heading" => array(
384 "text" => t("Secondary menu"),
385 "level" => "h2",
386 "class" => array("element-invisible"),
387 )
388 ));
389 }
390
391 if (!empty($variables["main_menu"])) {
d516f32e 392 $classes = array("primary-nav", "inline", "links", "main-menu", "grid-16");
73d4b474
SL
393
394 if (!empty($nitobe_vars["nitobe_secondary_menu"])) {
395 $classes[] = "has-secondary";
396 }
397
398 $nitobe_vars["nitobe_main_menu"] = theme("links", array(
399 "links" => $variables["main_menu"],
400 "attributes" => array(
401 "id" => "primary-nav",
402 "class" => $classes,
403 ),
404 "heading" => array(
405 "text" => t("Main menu"),
406 "level" => "h2",
407 "class" => array("element-invisible"),
408 )
409 ));
bf2114bc
SL
410 }
411
73d4b474
SL
412 // -- Copy necessary values from the page variables.
413 $keys = array("main_menu", "secondary_menu");
414 _nitobe_copy_if_exists($variables, $nitobe_vars, $keys);
415
d516f32e 416 $variables["page"]["menu_bar"]["#nitobe_classes"] = array("grid-16", "nav-links");
73d4b474
SL
417 $variables["page"]["menu_bar"]["#sorted"] = TRUE;
418 $variables["page"]["menu_bar"]["#theme_wrappers"] = array("region");
419 $variables["page"]["menu_bar"]["#region"] = "menu_bar";
420 $variables["page"]["menu_bar"]["#nitobe_vars"] = $nitobe_vars;
421}
422
423
424/**
425 * Builds the masthead region.
426 *
427 * @note This is only invoked by nitobe_preprocess_page() in order to pass
428 * necessary layout information to the region.
429 *
430 * @param array &$variables
431 * The page template variables passed from nitobe_preprocess_page().
432 *
433 * @see nitobe_preprocess_region()
434 * @see region--masthead.tpl.php
57d25656 435 * @see page.tpl.php
73d4b474
SL
436 */
437function _nitobe_build_masthead(&$variables) {
438 // -- Determine if the masthead image should be displayed.
439 $force_header = theme_get_setting('nitobe_header_always_show');
440 $masthead = $variables["page"]["masthead"];
441
442 if ($force_header || empty($variables["page"]["masthead"])) {
443 _nitobe_add_masthead_image($variables);
bf2114bc
SL
444 }
445
73d4b474
SL
446 // -- The Masthead region needs to always render in order to show the image,
447 // -- so if it's empty, we need to populate it with something.
448 if (empty($masthead)) {
57d25656
SL
449 $variables["page"]["masthead"]["#region"] = "masthead";
450 $variables["page"]["masthead"]["#sorted"] = TRUE;
451 $variables["page"]["masthead"]["#nitobe_force_render"] = TRUE;
452 $variables["page"]["masthead"]["#theme_wrappers"] = array("region");
453 }
454}
455
456
457/**
458 * Builds the footer columns.
459 *
460 * Specifically, the function adds the necessary grid class to the footer
461 * columns and ensures that their containing divs render even when empty.
462 *
463 * @note This is only invoked by nitobe_preprocess_page() in order to pass
464 * necessary layout information to the region.
465 *
466 * @param array &$variables
467 * The page template variables passed from nitobe_preprocess_page(). After
468 * invoking this function, &$variables will have the key
469 * "nitobe_footers_empty" which indicates that all of the footer columns are
470 * empty if TRUE.
471 *
472 * @see region.tpl.php
473 * @see page.tpl.php
474 */
475function _nitobe_build_footer_columns(&$variables) {
476 $columns = array("footer_firstcolumn", "footer_secondcolumn",
477 "footer_thirdcolumn", "footer_fourthcolumn");
478 $page = $variables["page"];
479
480 // -- Are all of the footer column regions empty?
481 $variables["nitobe_footers_empty"] =
482 empty($page["footer_firstcolumn"]) && empty($page["footer_secondcolumn"]) &&
483 empty($page["footer_thirdcolumn"]) && empty($page["footer_fourthcolumn"]);
484
485 // -- Add the grid-4 class and force any empty columns to at least render
486 // -- their containing div in order to maintain the layout.
487 foreach ($columns as $column) {
488 if (empty($variables["page"][$column])) {
489 $variables["page"][$column]["#region"] = $column;
490 $variables["page"][$column]["#sorted"] = TRUE;
491 $variables["page"][$column]["#nitobe_force_render"] = TRUE;
492 $variables["page"][$column]["#theme_wrappers"] = array("region");
493 }
494
495 $variables["page"][$column]["#nitobe_classes"] = array("grid-4");
73d4b474 496 }
bf2114bc
SL
497}
498
499
500/**
c53fc478 501 * Preprocesses pages.
aa43a991 502 *
c4c2c073 503 * @param array &$variables
c53fc478 504 * The template variables. After invoking this function, these keys will be
c4c2c073 505 * added to $variables:
57d25656
SL
506 * - nitobe_footers_empty: TRUE if all of the footer column regions are
507 * empty.
c4c2c073
SL
508 * - nitobe_tabs_primary: The array of primary tabs for this page.
509 * - nitobe_tabs_secondary: The array of secondary tabs for this page.
aa43a991 510 */
c4c2c073 511function nitobe_preprocess_page(&$variables) {
b2fc2acc 512 if(isset($variables["tabs"]['#primary'])){
513 $variables["nitobe_tabs_primary"] = $variables["tabs"]['#primary'];
514 }
c4c2c073
SL
515 $variables["nitobe_tabs_secondary"] = $variables["tabs"]['#secondary'];
516
c53fc478 517 // -- Determine which layout to use.
c4c2c073 518 nitobe_set_layout($variables);
d719a8b6 519
73d4b474 520 // -- Build the special regions.
c4c2c073
SL
521 _nitobe_build_title_group($variables);
522 _nitobe_build_menu_bar($variables);
523 _nitobe_build_masthead($variables);
524 _nitobe_build_footer_columns($variables);
57d25656 525}
c675ea8a 526
c53fc478 527
57d25656
SL
528/**
529 * Does final page processing before rendering.
530 *
531 * Specifically, this implementation pre-renders the page title header and
532 * provides the node timestamp, if applicable.
533 *
534 * @param array &$variables
535 * The template variables. After invoking this function, these keys will be
536 * added:
537 * - nitobe_node_timestamp The node timestamp, if applicable.
538 * - nitobe_page_title: The pre-rendered page title element with the
539 * appropriate CSS classes assigned.
540 *
541 * @see page.tpl.php
542 * @see nitobe_show_datestamp()
543 */
544function nitobe_process_page(&$variables) {
c53fc478 545 // -- Pre-render the page title with the appropriate CSS classes.
57d25656 546 if (isset($variables["title"])) {
d516f32e
SL
547 $classes_array = array("page-title");
548 $title = $variables["title"];
549
b2fc2acc 550 if (isset($variables["tabs"]["#primary"])) {
d516f32e
SL
551 $classes_array[] = "with-tabs";
552 }
553
554 $classes = implode(" ", $classes_array);
555 $variables["nitobe_page_title"] = "<h1 class=\"{$classes}\">{$title}</h1>";
57d25656 556 }
c53fc478
SL
557
558 // -- The formatted date for this node, if the date should be rendered.
57d25656
SL
559 $node = isset($variables["node"]) ? $variables["node"] : NULL;
560
c53fc478 561 if (!empty($node) && isset($node->created) && nitobe_show_datestamp($node->type)) {
80529006
SL
562 $date_format = theme_get_setting("nitobe_node_datestamp_format");
563 $variables['nitobe_node_timestamp'] =
564 empty($date_format) ? "" : format_date($node->created, "custom", $date_format);
aa43a991 565 }
04538805 566}
aa43a991 567
cc7ea041
SL
568
569/**
570 * Preprocess the wrapping HTML.
571 *
572 * @param array &$variables
573 * The template variables.
574 */
575function nitobe_preprocess_html(&$variables) {
4220d927
SL
576 $language = $variables["language"];
577 $styles = nitobe_theme_path() . "/styles/";
578 $is_rtl = (defined("LANGUAGE_RTL") && ($language->dir == LANGUAGE_RTL));
cc7ea041 579
4220d927
SL
580 // -- Force framework and reset CSS before everything else.
581 $stylesheet = $is_rtl ? "framework/960-rtl.css" : "framework/960.css";
cc7ea041 582 $framework = array(
4220d927
SL
583 "group" => CSS_SYSTEM - 1,
584 "weight" => -10,
cc7ea041
SL
585 );
586
4220d927 587 drupal_add_css($styles . "framework/reset.css", $framework);
cc7ea041
SL
588 drupal_add_css($styles . $stylesheet, $framework);
589
590 // -- IE CSS fixes.
4220d927 591 $stylesheet = $is_rtl ? "fix-ie-rtl.css" : "fix-ie.css";
cc7ea041 592 $ie_condition = array(
4220d927
SL
593 "group" => CSS_THEME,
594 "browsers" => array("IE" => "lt IE 8", "!IE" => FALSE),
595 "preprocess" => FALSE,
cc7ea041
SL
596 );
597
598 drupal_add_css($styles . $stylesheet, $ie_condition);
599
4220d927 600 $variables["classes_array"][] = "nitobe";
cc7ea041
SL
601}
602
603
aa43a991 604/**
c53fc478 605 * Overrides template_preprocess_comment().
aa43a991 606 *
4220d927 607 * @param array &$variables
c53fc478
SL
608 * The template variables. After invoking this function, these keys will be
609 * added to $vars:
4220d927
SL
610 * - links: The comment links.
611 * - nitobe_attribution: The formatted author link and date for the comment's
c53fc478 612 * meta data area.
aa43a991 613 */
4220d927
SL
614function nitobe_preprocess_comment(&$variables) {
615 $comment = $variables["comment"];
aaf80833
SL
616 $author = isset($variables["author"]) ? $variables["author"] : NULL;
617
618 if ($author == NULL) {
619 $vars = array("account" => $variables["user"]);
620 $author = theme("username", $vars);
621 }
622
c53fc478 623 // -- The author and timestamp
80529006
SL
624 $date_format = theme_get_setting("nitobe_comment_date_format");
625 $time_format = theme_get_setting("nitobe_comment_time_format");
626 $comment_date =
c4c2c073 627 empty($date_format) ? "" : format_date($comment->created, "custom", $date_format);
80529006 628 $comment_time =
c4c2c073 629 empty($time_format) ? "" : format_date($comment->created, "custom", $time_format);
80529006 630
aa43a991 631 $params = array(
80529006
SL
632 '@date' => $comment_date,
633 '@time' => $comment_time,
aaf80833 634 '!author' => $author,
aa43a991 635 );
c675ea8a 636
80529006
SL
637 if ($comment_date && $comment_time) {
638 $variables['nitobe_attribution'] =
639 t("Posted by !author on @date at @time.", $params);
640 }
641 else if ($comment_date) {
642 $variables['nitobe_attribution'] =
643 t("Posted by !author on @date.", $params);
644 }
645 else if ($comment_time) {
646 $variables['nitobe_attribution'] =
647 t("Posted by !author at @time.", $params);
648 }
649 else {
650 $variables['nitobe_attribution'] =
651 t("Posted by !author.", $params);
652 }
c53fc478 653
4220d927
SL
654 // -- Adds the zebra state so we can visually differentiate every other
655 // -- comment.
656 $variables["classes_array"][] = $variables["zebra"];
d719a8b6
SL
657}
658
659
660/**
c53fc478
SL
661 * Renders the local tasks.
662 *
663 * The default implementation renders them as tabs. Overridden to split the
664 * secondary tasks.
aa43a991 665 *
c53fc478
SL
666 * @return string
667 * The rendered local tasks.
aa43a991 668 */
dc6a3727 669function nitobe_menu_local_tasks() {
aa43a991
SL
670 return menu_primary_local_tasks();
671}
672
60a041ea 673
aa43a991 674/**
c53fc478
SL
675 * Generates IE CSS links for LTR and RTL languages.
676 *
677 * @return string
678 * The IE style elements.
679 */
dc6a3727 680function nitobe_get_ie_styles() {
c53fc478
SL
681 global $language;
682
683 $iecss = '<link type="text/css" rel="stylesheet" media="screen" href="' .
4220d927 684 base_path() . path_to_theme() . '/styles/fix-ie.css" />';
c53fc478
SL
685 if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL) {
686 $iecss .= '<style type="text/css" media="screen">@import "' .
4220d927 687 base_path() . path_to_theme() . '/styles/fix-ie-rtl.css";</style>';
c53fc478 688 }
d719a8b6 689
c53fc478
SL
690 return $iecss;
691}
692
693
694/**
57d25656
SL
695 * Determines the layout.
696 *
697 * The layout is determined the nitobe_content_placement setting and number of
698 * sidebars that have content.
699 *
700 * @param array &$variables
701 * The template variables. After invoking this function, these keys will be
702 * added to $vars:
703 * - nitobe_content_width: The CSS class providing the full width of the
704 * content region without any push/pull classes.
705 * - nitobe_placement: The theme setting for how the sidebars should be
706 * rendered relative to the content region. Will be one of: 'left',
707 * 'center', or 'right'.
708 */
709function nitobe_set_layout(&$variables) {
710 // -- Add the layout variables.
711 $placement = theme_get_setting("nitobe_content_placement");
712 $placement = empty($placement) ? "center" : $placement;
713 $layout = $variables["layout"];
714 $variables["nitobe_placement"] = $placement;
715
716 // -- Determine the classes for the content and sidebars.
717 $has_first = (($layout == "first") || ($layout == "both"));
718 $has_second = (($layout == "second") || ($layout == "both"));
719
720 $content = nitobe_ns("grid-16", $has_first, 4, $has_second, 4);
721 $variables["nitobe_content_width"] = $content;
57d25656
SL
722 $variables["page"]["sidebar_first"]["#nitobe_classes"] = array("grid-4");
723 $variables["page"]["sidebar_second"]["#nitobe_classes"] = array("grid-4");
724
725 // -- The grid class for items in the main column.
726 $variables["nitobe_content_width"] =
727 nitobe_ns("grid-16", $has_first, 4, $has_second, 4);
728
729
730 // -- Add the push/pull classes.
731 $push_pull = _nitobe_get_push_pull();
732
80529006 733 foreach (array("sidebar_first", "sidebar_second") as $region) {
57d25656
SL
734 if (isset($push_pull[$placement][$layout][$region])) {
735 $variables["page"][$region]["#nitobe_classes"][] =
736 $push_pull[$placement][$layout][$region];
737 }
738 }
739}
740
741
742/**
cc7ea041
SL
743 * Generates the JavaScript for rotating the header image.
744 *
745 * @return string
746 * The JavaScript for rotating the header.
747 */
748function _nitobe_random_header_js() {
749 global $base_url;
750
751 $files = _nitobe_get_header_list();
752 $names = array();
753
754 foreach ($files as $file => $data) {
755 $names[] = $base_url . '/' . $file;
756 }
757
758 $names_js = drupal_json_encode($names);
57d25656
SL
759 $js = <<<EOJS
760jQuery(document).ready(function() {
761 var names = {$names_js};
762 jQuery(".region-masthead").css("background-image", "url(" + names[Math.floor(Math.random() * names.length)] + ")");
763});
764EOJS;
765
766 return $js;
cc7ea041
SL
767}
768
769
770/**
771 * Generates the CSS to place inline to choose the header background image.
772 *
773 * @param string $filename
774 * The header image filename, relative to the theme.
775 *
776 * @return string
777 * The CSS to add to the header.
778 */
779function _nitobe_fixed_header_css($filename) {
780 global $base_url;
781
57d25656
SL
782 $url = $base_url . "/" . $filename;
783 $output = ".region-masthead{background-image:url(%s);}";
cc7ea041
SL
784
785 return sprintf($output, $url);
786}
787