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

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

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


Revision 1.4 - (show annotations) (download) (as text)
Mon Dec 29 05:56:41 2008 UTC (10 months, 3 weeks ago) by eric3
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +12 -6 lines
File MIME type: text/x-php
HEAD update
1 <?php
2 // $Id: template.php,v 1.1.4.2.2.4 2008/12/28 02:44:37 eric3 Exp $
3
4 /**
5 * @file
6 * NoProb-specific function definitions.
7 */
8
9 /**
10 * Return a multidimensional array of links for a navigation menu.
11 *
12 * @param $menu_name
13 * The name of the menu.
14 * @param $level
15 * Optional, the depth of the menu to be returned.
16 * @return
17 * An array of links of the specified menu and level.
18 */
19 function noprob_navigation_links($menu_name, $level = 0) {
20 // Don't even bother querying the menu table if no menu is specified.
21 if (empty($menu_name)) {
22 return array();
23 }
24
25 // Get the menu hierarchy for the current page.
26 $tree_page = menu_tree_page_data($menu_name);
27 // Also get the full menu hierarchy.
28 $tree_all = menu_tree_all_data($menu_name);
29
30 // Go down the active trail until the right level is reached.
31 while ($level-- > 0 && $tree_page) {
32 // Loop through the current level's items until we find one that is in trail.
33 while ($item = array_shift($tree_page)) {
34 if ($item['link']['in_active_trail']) {
35 // If the item is in the active trail, we continue in the subtree.
36 $tree_page = empty($item['below']) ? array() : $item['below'];
37 break;
38 }
39 }
40 }
41
42 return noprob_navigation_links_level($tree_page, $tree_all);
43 }
44
45
46 /**
47 * Helper function for noprob_navigation_links to recursively create an array of links.
48 * (Both trees are required in order to include every menu item and active trail info.)
49 */
50 function noprob_navigation_links_level($tree_page, $tree_all) {
51 $links = array();
52 foreach ($tree_all as $key => $item) {
53 $item_page = $tree_page[$key];
54 $item_all = $tree_all[$key];
55 if (!$item_all['link']['hidden']) {
56 $class = '';
57 $l = $item_all['link']['localized_options'];
58 $l['href'] = $item_all['link']['href'];
59 $l['title'] = $item_all['link']['title'];
60 if ($item_page['link']['in_active_trail']) {
61 $class = ' active-trail';
62 }
63 if ($item_all['below']) {
64 $l['children'] = noprob_navigation_links_level($item_page['below'], $item_all['below']);
65 }
66 // Keyed with the unique mlid to generate classes in theme_links().
67 $links['menu-'. $item_all['link']['mlid'] . $class] = $l;
68 }
69 }
70 return $links;
71 }
72
73
74 /**
75 * Helper function to retrieve the primary links using noprob_navigation_links().
76 */
77 function noprob_primary_links() {
78 return noprob_navigation_links(variable_get('menu_primary_links_source', 'primary-links'));
79 }
80
81
82 /**
83 * Return a themed set of links. (Extended to support multidimensional arrays of links.)
84 *
85 * @param $links
86 * A keyed array of links to be themed.
87 * @param $attributes
88 * A keyed array of attributes
89 * @return
90 * A string containing an unordered list of links.
91 */
92 function noprob_links($links, $attributes = array('class' => 'links')) {
93 $output = '';
94
95 if (count($links) > 0) {
96 $output = '<ul'. drupal_attributes($attributes) .'>';
97
98 $num_links = count($links);
99 $i = 1;
100
101 foreach ($links as $key => $link) {
102 $class = $key;
103
104 // Add first, last and active classes to the list of links to help out themers.
105 if ($i == 1) {
106 $class .= ' first';
107 }
108 if ($i == $num_links) {
109 $class .= ' last';
110 }
111 if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))) {
112 $class .= ' active';
113 }
114 // Added: if the link has child items, add a haschildren class
115 if (isset($link['children'])) {
116 $class .= ' haschildren';
117 }
118 $output .= '<li'. drupal_attributes(array('class' => $class)) .'>';
119
120 if (isset($link['href'])) {
121 // Pass in $link as $options, they share the same keys.
122 $output .= l($link['title'], $link['href'], $link);
123 }
124 elseif (!empty($link['title'])) {
125 // Some links are actually not links, but we wrap these in <span> for adding title and class attributes
126 if (empty($link['html'])) {
127 $link['title'] = check_plain($link['title']);
128 }
129 $span_attributes = '';
130 if (isset($link['attributes'])) {
131 $span_attributes = drupal_attributes($link['attributes']);
132 }
133 $output .= '<span'. $span_attributes .'>'. $link['title'] .'</span>';
134 }
135
136 // Added: if the link has child items, print them out recursively
137 if (isset($link['children'])) {
138 $output .= "\n" . theme('links', $link['children'], array('class' => 'sublinks'));
139 }
140
141 $i++;
142 $output .= "</li>\n";
143 }
144
145 $output .= '</ul>';
146 }
147
148 return $output;
149 }

  ViewVC Help
Powered by ViewVC 1.1.2