4 * The core functions for the Nitobe theme.
7 require_once
drupal_get_path('theme', 'nitobe') .
'/nitobe.utils.inc';
11 * Returns the path to the main Nitobe theme directory.
16 function nitobe_theme_path() {
19 if (!isset($theme_path)) {
22 if ($theme == "nitobe") {
23 $theme_path = path_to_theme();
25 $theme_path = drupal_get_path("theme", "nitobe");
34 * Overrides theme_pager() and alters the default quantity of pager items.
37 * Labels for the controls in the pager.
39 * The number of query results to display per page.
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).
50 * The HTML that generates the query pager.
52 function nitobe_pager($tags = array(), $limit = 10, $element = 0,
53 $parameters = array(), $quantity = 0) {
55 $quantity = theme_get_setting("nitobe_pager_page_count");
56 $quantity = empty($quantity) ?
5 : $quantity;
59 return theme_pager($tags, $limit, $element, $parameters, $quantity);
64 * Decorates theme_username() to strip the " (not verified)" string from the
67 * @param object $account
68 * An instance of a user object.
71 * The altered HTML output from theme_username().
73 function __nitobe_username($account) {
74 $output = theme_username($account);
76 if ((boolean
)theme_get_setting("nitobe_remove_not_verified")) {
77 $to_strip = " (" .
t("not verified") .
")";
78 $output = str_replace($to_strip, "", $output);
86 * Preprocesses the user picture.
88 * If no default user picture is provided, and pictures are enabled, use the
89 * theme's default user picture.
91 * @param array &$variables
92 * The template arguments.
94 function nitobe_preprocess_user_picture(&$variables) {
95 $account = $variables["account"];
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));
103 $variables["user_picture"] =
104 theme("image", array("path" => $picture, "alt" => $alt, "title" => $alt));
106 // -- Link the picture if allowed.
107 if (!empty($account->uid
) && user_access("access user profiles")) {
109 "attributes" => array(
110 "title" => t("View user profile."),
115 $variables["user_picture"] =
116 l($variables["user_picture"], "user/{$account->uid}", $attributes);
123 * Determines whether to show the date stamp for the given node.
125 * @param string $type
126 * The machine readable name of the type to check.
129 * TRUE if the node is of a type that should show the date stamp, FALSE if
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;
137 return (array_key_exists($type, $valid_types) && ($valid_types[$type] === $type));
142 * Produces the title effect.
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".
147 * @param string $title
148 * The text to render.
153 function nitobe_title_effect($title = "") {
154 $words = explode(" ", $title);
157 if (is_array($words)) {
159 foreach ($words as
$word) {
161 $result .
= "<span class=\"alt-color\">{$word}</span>";
175 * Adds the JavaScript and CSS required for the masthead image.
177 * @param array &$vars
178 * The page template variables.
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);
188 "group" => CSS_THEME
,
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();
200 drupal_add_js($js, $js_opts);
203 drupal_add_css($css, $css_opts);
208 * Preprocess the nodes.
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
217 * - nitobe_node_timestamp: The timestamp for this type, if one should be
218 * rendered for this type.
220 function nitobe_preprocess_node(&$variables) {
221 $content = $variables["content"];
222 $node = $variables["node"];
224 $variables["nitobe_perma_title"] =
225 t("Permanent Link to !title", array("!title" => $variables['title']));
227 if ($variables["display_submitted"]) {
228 $variables["nitobe_node_author"] =
229 t("Posted by !author", array("!author" => $variables["name"]));
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);
238 $variables["nitobe_show_meta"] = !empty($content["field_tags"]) ||
239 !empty($content["links"]);
244 * Provides page variables for the maintenance page.
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().
250 * @see nitobe_preprocess_page
252 function nitobe_preprocess_maintenance_page(&$variables) {
253 nitobe_preprocess_page($variables);
254 nitobe_process_page($variables);
259 * Preprocesses the regions.
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.
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.
270 * @see region.tpl.php
272 function nitobe_preprocess_region(&$variables) {
273 $region = $variables["region"];
274 $elements = $variables["elements"];
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
;
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"]);
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;
298 * Builds the title_group region.
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.
313 * @note This is only invoked by nitobe_preprocess_page() in order to pass
314 * necessary layout information to the region.
316 * @param array &$variables
317 * The page template variables passed from nitobe_preprocess_page().
319 * @see nitobe_preprocess_region()
320 * @see region--title-group.tpl.php
323 function _nitobe_build_title_group(&$variables) {
324 $page = $variables["page"];
325 $nitobe_vars = array();
327 $class = empty($page["header"]) ?
"grid-16" : "grid-10";
328 $variables["page"]["title_group"]["#nitobe_classes"] = array($class);
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"]));
335 $nitobe_vars["nitobe_title"] = check_plain($variables["site_name"]);
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);
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;
351 * Builds the menu bar.
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.
363 * @note This is only invoked by nitobe_preprocess_page() in order to pass
364 * necessary layout information to the region.
366 * @param array &$variables
367 * The page template variables passed from nitobe_preprocess_page().
369 * @see nitobe_preprocess_region()
370 * @see region--menu-bar.tpl.php
373 function _nitobe_build_menu_bar(&$variables) {
374 $nitobe_vars = array();
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"),
384 "text" => t("Secondary menu"),
386 "class" => array("element-invisible"),
391 if (!empty($variables["main_menu"])) {
392 $classes = array("primary-nav", "inline", "links", "main-menu", "grid-16");
394 if (!empty($nitobe_vars["nitobe_secondary_menu"])) {
395 $classes[] = "has-secondary";
398 $nitobe_vars["nitobe_main_menu"] = theme("links", array(
399 "links" => $variables["main_menu"],
400 "attributes" => array(
401 "id" => "primary-nav",
405 "text" => t("Main menu"),
407 "class" => array("element-invisible"),
412 // -- Copy necessary values from the page variables.
413 $keys = array("main_menu", "secondary_menu");
414 _nitobe_copy_if_exists($variables, $nitobe_vars, $keys);
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;
425 * Builds the masthead region.
427 * @note This is only invoked by nitobe_preprocess_page() in order to pass
428 * necessary layout information to the region.
430 * @param array &$variables
431 * The page template variables passed from nitobe_preprocess_page().
433 * @see nitobe_preprocess_region()
434 * @see region--masthead.tpl.php
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"];
442 if ($force_header || empty($variables["page"]["masthead"])) {
443 _nitobe_add_masthead_image($variables);
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");
458 * Builds the footer columns.
460 * Specifically, the function adds the necessary grid class to the footer
461 * columns and ensures that their containing divs render even when empty.
463 * @note This is only invoked by nitobe_preprocess_page() in order to pass
464 * necessary layout information to the region.
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
472 * @see region.tpl.php
475 function _nitobe_build_footer_columns(&$variables) {
476 $columns = array("footer_firstcolumn", "footer_secondcolumn",
477 "footer_thirdcolumn", "footer_fourthcolumn");
478 $page = $variables["page"];
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"]);
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");
495 $variables["page"][$column]["#nitobe_classes"] = array("grid-4");
501 * Preprocesses pages.
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
508 * - nitobe_tabs_primary: The array of primary tabs for this page.
509 * - nitobe_tabs_secondary: The array of secondary tabs for this page.
511 function nitobe_preprocess_page(&$variables) {
512 if(isset($variables["tabs"]['#primary'])){
513 $variables["nitobe_tabs_primary"] = $variables["tabs"]['#primary'];
515 $variables["nitobe_tabs_secondary"] = $variables["tabs"]['#secondary'];
517 // -- Determine which layout to use.
518 nitobe_set_layout($variables);
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);
529 * Does final page processing before rendering.
531 * Specifically, this implementation pre-renders the page title header and
532 * provides the node timestamp, if applicable.
534 * @param array &$variables
535 * The template variables. After invoking this function, these keys will be
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.
542 * @see nitobe_show_datestamp()
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"];
550 if (isset($variables["tabs"]["#primary"])) {
551 $classes_array[] = "with-tabs";
554 $classes = implode(" ", $classes_array);
555 $variables["nitobe_page_title"] = "<h1 class=\"{$classes}\">{$title}</h1>";
558 // -- The formatted date for this node, if the date should be rendered.
559 $node = isset($variables["node"]) ?
$variables["node"] : NULL
;
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);
570 * Preprocess the wrapping HTML.
572 * @param array &$variables
573 * The template variables.
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
));
580 // -- Force framework and reset CSS before everything else.
581 $stylesheet = $is_rtl ?
"framework/960-rtl.css" : "framework/960.css";
583 "group" => CSS_SYSTEM
- 1,
587 drupal_add_css($styles .
"framework/reset.css", $framework);
588 drupal_add_css($styles .
$stylesheet, $framework);
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
,
598 drupal_add_css($styles .
$stylesheet, $ie_condition);
600 $variables["classes_array"][] = "nitobe";
605 * Overrides template_preprocess_comment().
607 * @param array &$variables
608 * The template variables. After invoking this function, these keys will be
610 * - links: The comment links.
611 * - nitobe_attribution: The formatted author link and date for the comment's
614 function nitobe_preprocess_comment(&$variables) {
615 $comment = $variables["comment"];
616 $author = isset($variables["author"]) ?
$variables["author"] : NULL
;
618 if ($author == NULL
) {
619 $vars = array("account" => $variables["user"]);
620 $author = theme("username", $vars);
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");
627 empty($date_format) ?
"" : format_date($comment->created
, "custom", $date_format);
629 empty($time_format) ?
"" : format_date($comment->created
, "custom", $time_format);
632 '@date' => $comment_date,
633 '@time' => $comment_time,
634 '!author' => $author,
637 if ($comment_date && $comment_time) {
638 $variables['nitobe_attribution'] =
639 t("Posted by !author on @date at @time.", $params);
641 else if ($comment_date) {
642 $variables['nitobe_attribution'] =
643 t("Posted by !author on @date.", $params);
645 else if ($comment_time) {
646 $variables['nitobe_attribution'] =
647 t("Posted by !author at @time.", $params);
650 $variables['nitobe_attribution'] =
651 t("Posted by !author.", $params);
654 // -- Adds the zebra state so we can visually differentiate every other
656 $variables["classes_array"][] = $variables["zebra"];
661 * Renders the local tasks.
663 * The default implementation renders them as tabs. Overridden to split the
667 * The rendered local tasks.
669 function nitobe_menu_local_tasks() {
670 return menu_primary_local_tasks();
675 * Generates IE CSS links for LTR and RTL languages.
678 * The IE style elements.
680 function nitobe_get_ie_styles() {
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>';
695 * Determines the layout.
697 * The layout is determined the nitobe_content_placement setting and number of
698 * sidebars that have content.
700 * @param array &$variables
701 * The template variables. After invoking this function, these keys will be
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'.
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;
716 // -- Determine the classes for the content and sidebars.
717 $has_first = (($layout == "first") || ($layout == "both"));
718 $has_second = (($layout == "second") || ($layout == "both"));
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");
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);
730 // -- Add the push/pull classes.
731 $push_pull = _nitobe_get_push_pull();
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];
743 * Generates the JavaScript for rotating the header image.
746 * The JavaScript for rotating the header.
748 function _nitobe_random_header_js() {
751 $files = _nitobe_get_header_list();
754 foreach ($files as
$file => $data) {
755 $names[] = $base_url .
'/' .
$file;
758 $names_js = drupal_json_encode($names);
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
)] + ")");
771 * Generates the CSS to place inline to choose the header background image.
773 * @param string $filename
774 * The header image filename, relative to the theme.
777 * The CSS to add to the header.
779 function _nitobe_fixed_header_css($filename) {
782 $url = $base_url .
"/" .
$filename;
783 $output = ".region-masthead{background-image:url(%s);}";
785 return sprintf($output, $url);