/[drupal]/contributions/modules/outline_dmenu/outline_dmenu.module
ViewVC logotype

Contents of /contributions/modules/outline_dmenu/outline_dmenu.module

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


Revision 1.3 - (show annotations) (download) (as text)
Wed Mar 5 09:55:11 2008 UTC (20 months, 3 weeks ago) by rapsli
Branch: MAIN
CVS Tags: DRUPAL-5--0-1-beta2, HEAD
Changes since 1.2: +1 -1 lines
File MIME type: text/x-php
added // $Id$
1 <?php
2 // $Id$
3 /**
4 * implementation of hook_block
5 *
6 * @param string $op
7 * @param int $delta
8 * @param array $edit
9 * @return string html
10 */
11 function outline_dmenu_block($op = 'list', $delta=0, $edit=array()){
12 switch ($op) {
13 case 'list':
14 $blocks[0]['info'] = t('Outline Dmenu');
15 return $blocks;
16 break;
17
18 case 'view':
19 if(is_numeric(arg(1)) && $delta==0 && arg(0) == 'node' && module_exists('outline')){
20 $this_node = node_load(arg(1));
21 if (!empty($this_node->volume_id)) {
22 $path = outline_location($this_node);
23 $path[] = $this_node;
24 $expand = array();
25 foreach ($path as $key => $node) {
26 $expand[] = $node->nid;
27 }
28 drupal_add_css(drupal_get_path('module','outline_dmenu').'/outline_dmenu.css');
29 drupal_add_js(drupal_get_path('module','outline_dmenu').'/outline_dmenu.js');
30
31 drupal_add_js("var curr_nid='".$this_node->nid."'",'inline');
32
33
34 $block['content'] = _outline_dmenu_get_block($this_node->volume_id,$path[0]->nid, variable_get('navigation_depth',7), $expand);
35
36 if($block['content'] != ''){
37 $block['subject'] = check_plain($path[0]->title);
38 }
39 }
40 }
41
42 return $block;
43 break;
44
45 default:
46 break;
47 }
48 }
49
50
51
52
53
54
55
56
57 /**
58 * Helper function returns the block content
59 *
60 * @param int $nid
61 * @return string html
62 */
63 function _outline_dmenu_get_block($vol_id,$parent,$depth,$unfold){
64 $children = outline_tree($vol_id);
65 return theme('outline_dmenu',$parent, $depth, $children, $unfold);
66 }
67
68 /**
69 * ajax handler for expanding the menu
70 *
71 * @param int $nid
72 */
73 function outline_dmenu_update($nid){
74 $this_node = node_load($nid);
75 $path = outline_location($this_node);
76 $expand = array();
77 foreach ($path as $key => $node) {
78 $expand[] = $node->nid;
79 }
80 print theme('outline_dmenu_children',outline_dmenu_get_child_of_outline_node($nid,1));
81 }
82
83 /**
84 * theme function that is being called when a ajax call is being made
85 *
86 * @param array $ar_items
87 * @return html
88 */
89 function theme_outline_dmenu_children($ar_items){
90 if(!is_array($ar_items)){
91 return '';
92 }
93 $output = '<ul>';
94 foreach ($ar_items as $item) {
95 if($item['has_children'] == 'true'){
96 $output .= '<li class="collapsed" id="dmenu_'.$item['nid'].'" title="'.$item['nid'].'">
97 <span class="collapsed" title="'.$item['nid'].'" >&nbsp;</span><a href="/node/'.$item['nid'].'">'.$item['title'].'</a></li>';
98 }else{
99 $output .= '<li class="leaf" id="dmenu_'.$item['nid'].'" title="'.$item['nid'].'"><a href="/node/'.$item['nid'].'">'.$item['title'].'</a></li>';
100 }
101 }
102 return $output.'</ul>';
103 }
104
105
106 /**
107 * Theme the outline dmenu.
108 *
109 * @param int $nid
110 * @param int $depth
111 * @param unknown_type $children
112 * @param unknown_type $unfold
113 * @return html
114 */
115 function theme_outline_dmenu($nid, $depth, $children, $unfold = NULL){
116 $output = '';
117 if ($depth > 0) {
118 if (isset($children[$nid])) {
119 $output .= '<ul class="menu outline_dmenu">';
120 foreach ($children[$nid] as $node) {
121 if (isset($children[$node->nid])) {
122 // if (empty($unfold)){
123 if ($unfold == NULL){
124 if ($depth == 1) {
125 $output .= '<li class="expanded" title="'.$node->nid.'" id="dmenu_'.$node->nid.'">
126 <span class="expanded" title="'.$node->nid.'">&nbsp;</span>'. l($node->title, 'node/'. $node->nid);
127 }
128 else {
129 $output .= '<li class="collapsed" title="'.$node->nid.'" id="dmenu_'.$node->nid.'">
130 <span class="collapsed" title="'.$node->nid.'">&nbsp;</span>' . l($node->title, 'node/'. $node->nid);
131 $output .= theme_outline_dmenu($node->nid, $depth - 1, $children, $unfold);
132 }
133 }
134 else {
135 if ($depth == 1 || !in_array($node->nid, $unfold)) {
136 $output .= '<li class="collapsed" title="'.$node->nid.'" id="dmenu_'.$node->nid.'">
137 <span class="collapsed" title="'.$node->nid.'">&nbsp;</span><div class="dmenu_link">'. l($node->title, 'node/'. $node->nid).'</div>';
138 }
139 else {
140 $output .= '<li class="expanded" title="'.$node->nid.'" id="dmenu_'.$node->nid.'">
141 <span class="expanded" title="'.$node->nid.'">&nbsp;</span>' . l($node->title, 'node/'. $node->nid);
142 $output .= theme_outline_dmenu($node->nid, $depth - 1, $children, $unfold);
143 }
144 }
145 }
146 else {
147 $output .= '<li class="leaf" title="'.$node->nid.'" id="dmenu_'.$node->nid.'">'. l($node->title, 'node/'. $node->nid);
148 }
149 $output .= '</li>';
150 }
151 $output .= '</ul>';
152 }
153 }
154
155 return $output;
156 }
157
158 /**
159 * Implementation of hook_menu
160 *
161 * @param boolean $may_cache
162 */
163 function outline_dmenu_menu($may_cache){
164 $items[] = array(
165 'path' => 'outline_dmenu/update/'.arg(2),
166 'type' => MENU_CALLBACK,
167 'callback' => 'outline_dmenu_update',
168 'callback arguments' => arg(2),
169 'access' => user_access('view kapitel node')
170 );
171 $items[] = array(
172 'path' => 'outline_dmenu/get_static_menu',
173 'type' => MENU_CALLBACK,
174 'callback' => 'outline_dmenu_static_menu',
175 'callback arguments' => arg(2),
176 'access' => user_access('view kapitel node'),
177 );
178 return $items;
179 }
180
181 /**
182 * This functions retrieves some information about a node:
183 * It's Child nodes
184 * the child's node's title
185 * the child's node's original text
186 * the cilds's nid
187 *
188 * It's recursive meaning: if $anz_children = 1 there will be only one loop. For $anz_children>1 there
189 * will be $anz_children iterations
190 *
191 * @param int $nid
192 * @param int $anz_children
193 * @return array
194 */
195 function outline_dmenu_get_child_of_outline_node($nid,$anz_children=1){
196 if($anz_children>0){
197 $sql = "SELECT o.nid,n.title FROM {outline_nodes} AS o, {node} AS n
198 WHERE o.parent=%d
199 AND n.nid = o.nid
200 GROUP BY n.nid";
201 $result = db_query($sql,$nid);
202
203 $anz_children--;
204 $ar_result = array();
205 while ($row = db_fetch_object($result)) {
206 $ar_temp = array(
207 "title" => $row->title,
208 "nid" => $row->nid,
209 );
210
211 $sql = "SELECT COUNT(n.nid) FROM {outline_nodes} AS o, {node} AS n
212 WHERE o.parent=%d
213 AND n.nid = o.nid
214 ";
215 $result_2 = db_query($sql,$ar_temp['nid']);
216 $row_2 = db_fetch_array($result_2);
217 if($row_2['COUNT(n.nid)'] > 0){
218 $ar_temp['has_children'] = 'true';
219 }
220
221 $ar_temp['child'] = outline_dmenu_get_child_of_outline_node($row->nid,$anz_children);
222 // debug('child Stufe: '.$anz_children.' Titel: '.$row->title,$ar_temp['child']);
223 $ar_result[] = $ar_temp;
224 // debug('child Stufe: '.$anz_children.' Titel: '.$row->title,$ar_result);
225 }
226 }
227 return $ar_result;
228 }
229
230 /**
231 incase javascript is not enabled this is going to build the static menu
232 */
233 function outline_dmenu_static_menu($nid){
234 $this_node = node_load($nid);
235 if (!empty($this_node->volume_id)) {
236 $path = outline_location($this_node);
237 $path[] = $this_node;
238 $expand = array();
239 foreach ($path as $key => $node) {
240 $expand[] = $node->nid;
241 }
242
243 print outline_page_menu_tree($this_node->volume_id,$path[0]->nid, variable_get('navigation_depth',7), $expand);
244 }
245 else{
246 print t('Error with the navigation');
247 }
248 }

  ViewVC Help
Powered by ViewVC 1.1.2