/[drupal]/contributions/menu_sitemap.module
ViewVC logotype

Contents of /contributions/menu_sitemap.module

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


Revision 1.1 - (show annotations) (download) (as text)
Fri Sep 18 05:41:39 2009 UTC (2 months, 1 week ago) by tronathan
Branch: MAIN
File MIME type: text/x-php
Menu Sitemap Initial commit
1 <?php
2 // $Id:
3
4 include_once('/var/www/modules/menu/menu.admin.inc');
5
6 /**
7 * Menu for this module
8 * @return array An array with this module's settings.
9 */
10 function menu_sitemap_menu() {
11 $items = array();
12
13 //Link to the menu_sitemap_module admin page:
14 $items['admin/settings/menu_sitemap'] = array(
15 'title' => 'Menu Sitemap',
16 'description' => 'Set default menu to use for Menu Sitemap',
17 'page callback' => 'menu_sitemap_admin',
18 'access arguments' => array('administer menu_sitemap'),
19 'type' => MENU_NORMAL_ITEM,
20 );
21
22 //Link to the menu_sitemap_module site map
23 $items['site-map'] = array(
24 'title' => 'Site Map',
25 'description' => 'View Site Map',
26 'page callback' => 'menu_sitemap_viewsitemap',
27 'access arguments' => array(''),
28 'type' => MENU_NORMAL_ITEM,
29 );
30
31 return $items;
32 }
33
34 function menu_sitemap_admin() {
35 return drupal_get_form('menu_sitemap_admin_form');
36 }
37
38 /**
39 * The callback function (form constructor) that creates the HTML form for test_module_message().
40 * @return form an array of form data.
41 */
42 function menu_sitemap_admin_form() {
43
44 // $options - based on
45
46 // $options = array('1' => t('Enabled'), '0' => t('Disabled'));
47 $options = menu_get_menus($all = TRUE);
48
49 $form['menu_sitemap_menuname'] = array(
50 '#type' => 'select',
51 '#title' => t('Menu for Sitemap'),
52 '#default_value' => variable_get('menu_sitemap_menuname', 'primary-links'),
53 '#options' => $options,
54 '#description' => t("Choose the menu that displays the links that you'd like to show in the site map at <a href='/site-map'>/site-map</a>."),
55 );
56
57 //Submit button:
58 $form['submit'] = array(
59 '#type' => 'submit',
60 '#value' => t('Save Configuration'),
61 );
62
63 return $form;
64 }
65
66 /**
67 * Form validation for this module's settings
68 * @param form an array that contains this module's settings
69 * @param form_state an array that contains this module's settings
70 */
71 function test_module_message_form_validate($form, &$form_state) {
72 // No validation.
73 }
74
75 /**
76 * Form submission for user data.
77 * @param form an array that contains user data
78 * @param form_state an array that contains user data
79 */
80 function menu_sitemap_admin_form_submit($form, &$form_state) {
81 drupal_set_message('Menu Sitemap configuration saved.');
82 $menuname = $form_state['values']['menu_sitemap_menuname'];
83 variable_set('menu_sitemap_menuname', $menuname);
84 $form_state['redirect'] = 'admin/settings/menu_sitemap';
85 }
86
87
88
89 /**********************************************************************************/
90 /**********************************************************************************/
91 /**********************************************************************************/
92 /**********************************************************************************/
93 /**********************************************************************************/
94
95
96 function menu_sitemap_viewsitemap() {
97 $menuname = variable_get('menu_sitemap_menuname', 'primary-links');
98 $form = array();
99 $f = menu_sitemap_overview_form(&$form, array('menu_name' => $menuname));
100 return(menu_sitemap_theme_menu_overview_form($f));
101 }
102
103 function menu_sitemap_overview_form(&$form_state, $menu) {
104 global $menu_admin;
105 $sql = "
106 SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.type, m.description, ml.*
107 FROM {menu_links} ml LEFT JOIN {menu_router} m ON m.path = ml.router_path
108 WHERE ml.menu_name = '%s'
109 ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC, p7 ASC, p8 ASC, p9 ASC";
110 $result = db_query($sql, $menu['menu_name']);
111 $tree = menu_tree_data($result);
112 $node_links = array();
113 menu_tree_collect_node_links($tree, $node_links);
114 // We indicate that a menu administrator is running the menu access check.
115 $menu_admin = TRUE;
116 menu_tree_check_access($tree, $node_links);
117 $menu_admin = FALSE;
118
119 $form = _menu_overview_tree_form($tree);
120 $form['#menu'] = $menu;
121 if (element_children($form)) {
122 $form['submit'] = array(
123 '#type' => 'submit',
124 '#value' => t('Save configuration'),
125 );
126 }
127 else {
128 $form['empty_menu'] = array('#value' => t('There are no menu items yet.'));
129 }
130 return $form;
131 }
132
133 function menu_sitemap_theme_menu_overview_form($form) {
134 // Some of the code below is commented out, it was included in the material that this was
135 // adapted from, and I didn't remove them because i dont know what they do - if we may need them later.
136
137 drupal_add_tabledrag('menu-overview', 'match', 'parent', 'menu-plid', 'menu-plid', 'menu-mlid', TRUE, MENU_MAX_DEPTH - 1);
138 drupal_add_tabledrag('menu-overview', 'order', 'sibling', 'menu-weight');
139
140 $header = array(
141 t('Menu item'),
142 // array('data' => t('Enabled'), 'class' => 'checkbox'),
143 // array('data' => t('Expanded'), 'class' => 'checkbox'),
144 t('Weight'),
145 array('data' => t('Operations'), 'colspan' => '3'),
146 );
147
148 $rows = array();
149 $menurows = array();
150 foreach (element_children($form) as $mlid) {
151 if (isset($form[$mlid]['hidden'])) {
152 $element = &$form[$mlid];
153 // Build a list of operations.
154 $operations = array();
155 foreach (element_children($element['operations']) as $op) {
156
157 // Remove "nolink" links - support for http://drupal.org/project/special_menu_items
158 $element['title']['#value'] = str_replace('/nolink', '#', $element['title']['#value']);
159
160 // $operations[] = drupal_render($element['operations'][$op]);
161
162 // Remove "separator" links - support for http://drupal.org/project/special_menu_items
163 if ('<a href="/separator" title="">separator</a>' == $element['title']['#value'])
164 $element['title']['#value'] = '';
165 }
166 while (count($operations) < 2) {
167 $operations[] = '';
168 }
169
170 // Add special classes to be used for tabledrag.js.
171 $element['plid']['#attributes']['class'] = 'menu-plid';
172 $element['mlid']['#attributes']['class'] = 'menu-mlid';
173 $element['weight']['#attributes']['class'] = 'menu-weight';
174
175 // Change the parent field to a hidden. This allows any value but hides the field.
176 $element['plid']['#type'] = 'hidden';
177
178 $menurow = array();
179 if ($element['#item']['hidden'] != 1)
180 $menurow[] = theme('indentation', $element['#item']['depth'] - 1) . $element['title']['#value']; // drupal_render($element['title']);
181 $menurows[] = $menurow;
182 $row = array();
183 $row[] = theme('indentation', $element['#item']['depth'] - 1) . drupal_render($element['title']);
184 // $row[] = array('data' => drupal_render($element['hidden']), 'class' => 'checkbox');
185 // $row[] = array('data' => drupal_render($element['expanded']), 'class' => 'checkbox');
186 $row[] = drupal_render($element['weight']) . drupal_render($element['plid']) . drupal_render($element['mlid']);
187 $row = array_merge($row, $operations);
188
189 $row = array_merge(array('data' => $row), $element['#attributes']);
190 $row['class'] = !empty($row['class']) ? $row['class'] .' draggable' : 'draggable';
191
192
193 // if ('<a href="/separator" title="">separator</a>' == $element['title']['#value'])
194 // $rows[] = $row;
195 }
196 }
197
198 return theme('table', t('Menu item'), $menurows, array('id' => 'menu-overview'));;
199
200 $output = '';
201 if ($rows) {
202 $output .= theme('table', $header, $rows, array('id' => 'menu-overview'));
203 }
204 // krumo($output);
205 $output .= drupal_render($form);
206 return $output;
207 }

  ViewVC Help
Powered by ViewVC 1.1.2