Issue #1016038 by arrrgh: Avoid "Undefined Index" error.
[project/nitobe.git] / template.php
1 <?php
2 /**
3 * @file
4 * The core functions for the Nitobe theme.
5 */
6
7 require_once drupal_get_path('theme', 'nitobe') . '/nitobe.utils.inc';
8
9
10 /**
11 * Returns the path to the main Nitobe theme directory.
12 *
13 * @return string
14 * The path to Nitobe.
15 */
16 function nitobe_theme_path() {
17 static $theme_path;
18
19 if (!isset($theme_path)) {
20 global $theme;
21
22 if ($theme == "nitobe") {
23 $theme_path = path_to_theme();
24 } else {
25 $theme_path = drupal_get_path("theme", "nitobe");
26 }
27 }
28
29 return $theme_path;
30 }
31
32
33 /**
34 * Overrides theme_pager() and alters the default quantity of pager items.
35 *
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).
48 *
49 * @return string
50 * The HTML that generates the query pager.
51 */
52 function nitobe_pager($tags = array(), $limit = 10, $element = 0,
53 $parameters = array(), $quantity = 0) {
54 if ($quantity == 0) {
55 $quantity = theme_get_setting("nitobe_pager_page_count");
56 $quantity = empty($quantity) ? 5 : $quantity;
57 }
58
59 return theme_pager($tags, $limit, $element, $parameters, $quantity);
60 }
61
62
63 /**
64 * Decorates theme_username() to strip the " (not verified)" string from the
65 * commenter's name.
66 *
67 * @param object $account
68 * An instance of a user object.
69 *
70 * @return string
71 * The altered HTML output from theme_username().
72 */
73 function __nitobe_username($account) {
74 $output = theme_username($account);
75
76 if ((boolean)theme_get_setting("nitobe_remove_not_verified")) {
77 $to_strip = " (" . t("not verified") . ")";
78 $output = str_replace($to_strip, "", $output);
79 }
80
81 return $output;
82 }
83
84
85 /**
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.
90 *
91 * @param array &$variables
92 * The template arguments.
93 */
94 function nitobe_preprocess_user_picture(&$variables) {
95 $account = $variables["account"];
96
97 if (empty($variables["user_picture"]) && (variable_get("user_pictures", 0) != 0)) {
98 $picture = nitobe_theme_path() . "/images/user-icon.jpg";
99 $name = $account->name ? $account->name :
100 variable_get("anonymous", t("Anonymous"));
101 $alt = t("@user's picture", array('@user' => $name));
102
103 $variables["user_picture"] =
104 theme("image", array("path" => $picture, "alt" => $alt, "title" => $alt));
105
106 // -- Link the picture if allowed.
107 if (!empty($account->uid) && user_access("access user profiles")) {
108 $attributes = array(
109 "attributes" => array(
110 "title" => t("View user profile."),
111 ),
112 "html" => TRUE
113 );
114
115 $variables["user_picture"] =
116 l($variables["user_picture"], "user/{$account->uid}", $attributes);
117 }
118 }
119 }
120
121
122 /**
123 * Determines whether to show the date stamp for the given node.
124 *
125 * @param string $type
126 * The machine readable name of the type to check.
127 *
128 * @return boolean
129 * TRUE if the node is of a type that should show the date stamp, FALSE if
130 * not.
131 */
132 function nitobe_show_datestamp($type) {
133 $default = drupal_map_assoc(array("blog", "forum", "poll", "article"));
134 $valid_types = theme_get_setting("nitobe_show_datestamp");
135 $valid_types = (!empty($valid_types)) ? $valid_types : $default;
136
137 return (array_key_exists($type, $valid_types) && ($valid_types[$type] === $type));
138 }
139
140
141 /**
142 * Produces the title effect.
143 *
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 *
147 * @param string $title
148 * The text to render.
149 *
150 * @return string
151 * The rendered HTML.
152 */
153 function nitobe_title_effect($title = "") {
154 $words = explode(" ", $title);
155 $result = "";
156
157 if (is_array($words)) {
158 $alt = FALSE;
159 foreach ($words as $word) {
160 if ($alt) {
161 $result .= "<span class=\"alt-color\">{$word}</span>";
162 } else {
163 $result .= $word;
164 }
165
166 $alt = !$alt;
167 }
168 }
169
170 return $result;
171 }
172
173
174 /**
175 * Adds the JavaScript and CSS required for the masthead image.
176 *
177 * @param array &$vars
178 * The page template variables.
179 */
180 function _nitobe_add_masthead_image(&$vars) {
181 // -- Determine the header image if it is set, or add the JavaScript for
182 // -- random header images.
183 $header_img = theme_get_setting("nitobe_header_image");
184 $header_img = empty($header_img) ? "<random>" : $header_img;
185 $css = _nitobe_fixed_header_css($header_img);
186 $css_opts = array(
187 "type" => "inline",
188 "group" => CSS_THEME,
189 );
190
191 if ($header_img == "<random>") {
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(
196 "type" => "inline",
197 "group" => JS_THEME,
198 );
199
200 drupal_add_js($js, $js_opts);
201 }
202
203 drupal_add_css($css, $css_opts);
204 }
205
206
207 /**
208 * Preprocess the nodes.
209 *
210 * @param array &$variables
211 * The template variables. After invoking this function, these keys will be
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.
219 */
220 function nitobe_preprocess_node(&$variables) {
221 $content = $variables["content"];
222 $node = $variables["node"];
223
224 $variables["nitobe_perma_title"] =
225 t("Permanent Link to !title", array("!title" => $variables['title']));
226
227 if ($variables["display_submitted"]) {
228 $variables["nitobe_node_author"] =
229 t("Posted by !author", array("!author" => $variables["name"]));
230 }
231
232 if ($variables["display_submitted"] && isset($node->created)) {
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);
236 }
237
238 $variables["nitobe_show_meta"] = !empty($content["field_tags"]) ||
239 !empty($content["links"]);
240 }
241
242
243 /**
244 * Provides page variables for the maintenance page.
245 *
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().
249 *
250 * @see nitobe_preprocess_page
251 */
252 function nitobe_preprocess_maintenance_page(&$variables) {
253 nitobe_preprocess_page($variables);
254 nitobe_process_page($variables);
255 }
256
257
258 /**
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.
264 *
265 * @param array &$variables
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
271 */
272 function nitobe_preprocess_region(&$variables) {
273 $region = $variables["region"];
274 $elements = $variables["elements"];
275
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
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
296
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
321 * @see page.tpl.php
322 */
323 function _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"]);
336 }
337
338 // -- Copy necessary values from the page variables.
339 $keys = array("front_page", "logo", "site_name", "site_slogan", "title");
340 _nitobe_copy_if_exists($variables, $nitobe_vars, $keys);
341
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;
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
371 * @see page.tpl.php
372 */
373 function _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",
381 "class" => array("secondary-nav", "inline", "links", "secondary-menu", "grid-16"),
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"])) {
392 $classes = array("primary-nav", "inline", "links", "main-menu", "grid-16");
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 ));
410 }
411
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
416 $variables["page"]["menu_bar"]["#nitobe_classes"] = array("grid-16", "nav-links");
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
435 * @see page.tpl.php
436 */
437 function _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);
444 }
445
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)) {
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 */
475 function _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");
496 }
497 }
498
499
500 /**
501 * Preprocesses pages.
502 *
503 * @param array &$variables
504 * The template variables. After invoking this function, these keys will be
505 * added to $variables:
506 * - nitobe_footers_empty: TRUE if all of the footer column regions are
507 * empty.
508 * - nitobe_tabs_primary: The array of primary tabs for this page.
509 * - nitobe_tabs_secondary: The array of secondary tabs for this page.
510 */
511 function nitobe_preprocess_page(&$variables) {
512 if(isset($variables["tabs"]['#primary'])){
513 $variables["nitobe_tabs_primary"] = $variables["tabs"]['#primary'];
514 }
515 $variables["nitobe_tabs_secondary"] = $variables["tabs"]['#secondary'];
516
517 // -- Determine which layout to use.
518 nitobe_set_layout($variables);
519
520 // -- Build the special regions.
521 _nitobe_build_title_group($variables);
522 _nitobe_build_menu_bar($variables);
523 _nitobe_build_masthead($variables);
524 _nitobe_build_footer_columns($variables);
525 }
526
527
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 */
544 function nitobe_process_page(&$variables) {
545 // -- Pre-render the page title with the appropriate CSS classes.
546 if (isset($variables["title"])) {
547 $classes_array = array("page-title");
548 $title = $variables["title"];
549
550 if (isset($variables["tabs"]["#primary"])) {
551 $classes_array[] = "with-tabs";
552 }
553
554 $classes = implode(" ", $classes_array);
555 $variables["nitobe_page_title"] = "<h1 class=\"{$classes}\">{$title}</h1>";
556 }
557
558 // -- The formatted date for this node, if the date should be rendered.
559 $node = isset($variables["node"]) ? $variables["node"] : NULL;
560
561 if (!empty($node) && isset($node->created) && nitobe_show_datestamp($node->type)) {
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);
565 }
566 }
567
568
569 /**
570 * Preprocess the wrapping HTML.
571 *
572 * @param array &$variables
573 * The template variables.
574 */
575 function nitobe_preprocess_html(&$variables) {
576 $language = $variables["language"];
577 $styles = nitobe_theme_path() . "/styles/";
578 $is_rtl = (defined("LANGUAGE_RTL") && ($language->dir == LANGUAGE_RTL));
579
580 // -- Force framework and reset CSS before everything else.
581 $stylesheet = $is_rtl ? "framework/960-rtl.css" : "framework/960.css";
582 $framework = array(
583 "group" => CSS_SYSTEM - 1,
584 "weight" => -10,
585 );
586
587 drupal_add_css($styles . "framework/reset.css", $framework);
588 drupal_add_css($styles . $stylesheet, $framework);
589
590 // -- IE CSS fixes.
591 $stylesheet = $is_rtl ? "fix-ie-rtl.css" : "fix-ie.css";
592 $ie_condition = array(
593 "group" => CSS_THEME,
594 "browsers" => array("IE" => "lt IE 8", "!IE" => FALSE),
595 "preprocess" => FALSE,
596 );
597
598 drupal_add_css($styles . $stylesheet, $ie_condition);
599
600 $variables["classes_array"][] = "nitobe";
601 }
602
603
604 /**
605 * Overrides template_preprocess_comment().
606 *
607 * @param array &$variables
608 * The template variables. After invoking this function, these keys will be
609 * added to $vars:
610 * - links: The comment links.
611 * - nitobe_attribution: The formatted author link and date for the comment's
612 * meta data area.
613 */
614 function nitobe_preprocess_comment(&$variables) {
615 $comment = $variables["comment"];
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
623 // -- The author and timestamp
624 $date_format = theme_get_setting("nitobe_comment_date_format");
625 $time_format = theme_get_setting("nitobe_comment_time_format");
626 $comment_date =
627 empty($date_format) ? "" : format_date($comment->created, "custom", $date_format);
628 $comment_time =
629 empty($time_format) ? "" : format_date($comment->created, "custom", $time_format);
630
631 $params = array(
632 '@date' => $comment_date,
633 '@time' => $comment_time,
634 '!author' => $author,
635 );
636
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 }
653
654 // -- Adds the zebra state so we can visually differentiate every other
655 // -- comment.
656 $variables["classes_array"][] = $variables["zebra"];
657 }
658
659
660 /**
661 * Renders the local tasks.
662 *
663 * The default implementation renders them as tabs. Overridden to split the
664 * secondary tasks.
665 *
666 * @return string
667 * The rendered local tasks.
668 */
669 function nitobe_menu_local_tasks() {
670 return menu_primary_local_tasks();
671 }
672
673
674 /**
675 * Generates IE CSS links for LTR and RTL languages.
676 *
677 * @return string
678 * The IE style elements.
679 */
680 function nitobe_get_ie_styles() {
681 global $language;
682
683 $iecss = '<link type="text/css" rel="stylesheet" media="screen" href="' .
684 base_path() . path_to_theme() . '/styles/fix-ie.css" />';
685 if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL) {
686 $iecss .= '<style type="text/css" media="screen">@import "' .
687 base_path() . path_to_theme() . '/styles/fix-ie-rtl.css";</style>';
688 }
689
690 return $iecss;
691 }
692
693
694 /**
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 */
709 function 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;
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
733 foreach (array("sidebar_first", "sidebar_second") as $region) {
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 /**
743 * Generates the JavaScript for rotating the header image.
744 *
745 * @return string
746 * The JavaScript for rotating the header.
747 */
748 function _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);
759 $js = <<<EOJS
760 jQuery(document).ready(function() {
761 var names = {$names_js};
762 jQuery(".region-masthead").css("background-image", "url(" + names[Math.floor(Math.random() * names.length)] + ")");
763 });
764 EOJS;
765
766 return $js;
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 */
779 function _nitobe_fixed_header_css($filename) {
780 global $base_url;
781
782 $url = $base_url . "/" . $filename;
783 $output = ".region-masthead{background-image:url(%s);}";
784
785 return sprintf($output, $url);
786 }
787