/[drupal]/contributions/modules/gallery/gallery_menu/gallery_menu.module
ViewVC logotype

Contents of /contributions/modules/gallery/gallery_menu/gallery_menu.module

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


Revision 1.3 - (show annotations) (download) (as text)
Fri Nov 23 11:20:33 2007 UTC (2 years ago) by profix898
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1
Changes since 1.2: +91 -130 lines
File MIME type: text/x-php
- very early D6 version (Oct-01, 2007)
1 <?php
2 // $Id: gallery_menu.module,v 1.1.2.5 2007/09/10 18:04:17 profix898 Exp $
3
4 /**
5 * gallery_menu.module
6 */
7
8 /**
9 * Implementation of hook_theme().
10 */
11 function gallery_menu_theme() {
12 return array(
13 'gallery_menu_settings_table' => array(
14 'arguments' => array('form' => NULL, 'rows' => NULL),
15 )
16 );
17 }
18
19 /**
20 * Implementation of hook_init().
21 */
22 function gallery_menu_init() {
23 // Initialize G2
24 if (!_gallery_init(FALSE)) {
25 return;
26 }
27 // Rebuild the menu if the G2 album structure changed
28 $timestamp = variable_get('gallery_menu_timestamp', 0);
29 $query = 'SELECT COUNT([GalleryEntity::id]) FROM [GalleryEntity], [GalleryAlbumItem] WHERE
30 [GalleryAlbumItem::id] = [GalleryEntity::id] AND [GalleryEntity::modificationTimeStamp] > ?';
31 if (($results = gallery_db_query($query, array($timestamp))) && $results[0]) {
32 menu_rebuild();
33 variable_set('gallery_menu_timestamp', time());
34 }
35 }
36
37 /**
38 * Implementation of hook_menu().
39 */
40 function gallery_menu_menu() {
41 $items = array();
42 if (variable_get('gallery_valid', 0)) {
43 $items['admin/settings/gallery/menu'] = array(
44 'title' => 'Menu',
45 'access callback' => 'user_access',
46 'access arguments' => array('administer gallery settings'),
47 'page callback' => 'drupal_get_form',
48 'page arguments' => array('_gallery_menu_settings'),
49 'type' => MENU_LOCAL_TASK,
50 'weight' => 5
51 );
52 $items = array_merge($items, gallery_menu_build_menu());
53 }
54
55 return $items;
56 }
57
58 /**
59 * Function gallery_menu_album().
60 */
61 function gallery_menu_album($id) {
62 // Redirect to true album url (from the virtual menu path)
63 $url = gallery_generate_url(array('itemId' => $id), FALSE);
64 drupal_goto($url);
65 }
66
67 /**
68 * Implementation of hook_gallery_page_alter().
69 */
70 function gallery_menu_gallery_page_alter(&$result) {
71 if (isset($result['themeData']['pageUrl']['itemId'])) {
72 $id = $result['themeData']['pageUrl']['itemId'];
73 $item = gallery_item_details($id);
74 if ($item['g2type'] != 'GalleryAlbumItem') {
75 $id = $item['g2parent'];
76 }
77 list($ret, $parents) = GalleryCoreApi::fetchParentSequence($id);
78 if ($ret) {
79 gallery_error(t('Error fetching item parents'), $ret);
80 }
81 else {
82 array_shift($parents);
83 $path = 'gallery/'. (count($parents) ? implode('/', $parents) .'/' : '') . $id;
84 menu_set_active_item($path);
85 }
86 }
87 }
88
89 /**
90 * Function gallery_menu_build_menu().
91 */
92 function gallery_menu_build_menu() {
93 $items = array();
94 // Load any user from the G2 admin group
95 list($ret, $g2_admin_gid) = GalleryCoreApi::getPluginParameter('module', 'core', 'id.adminGroup');
96 if ($ret) {
97 gallery_error(t('Error getting \'adminGroup\' id'), $ret);
98 return $items;
99 }
100 list($ret, $user) = GalleryCoreApi::fetchUsersForGroup($g2_admin_gid, 1);
101 if ($ret) {
102 gallery_error(t('Error fetching users for \'adminGroup\' id'), $ret);
103 return $items;
104 }
105 $user = array_keys($user);
106 // Fetch the album tree and generate the menu items
107 $depth = variable_get('gallery_menu_depth', 0);
108 $tree = gallery_album_tree(NULL, $depth ? $depth : NULL, $user[0]);
109 _gallery_menu_traverse($tree, $items);
110
111 return $items;
112 }
113
114 /**
115 * Function _gallery_menu_traverse().
116 */
117 function _gallery_menu_traverse(&$tree, &$items) {
118 static $parents = array();
119 foreach (array_keys($tree) as $id) {
120 $album = gallery_item_details($id);
121 if (variable_get('gallery_menu_show_'. $id, 1)) {
122 $item = array();
123 // Check for URL Rewrite being available
124 $url_generator =& $GLOBALS['gallery']->getUrlGenerator();
125 if (isset($url_generator->_shortUrls)) {
126 $path = gallery_generate_url(array('itemId' => $id), FALSE, FALSE);
127 $item['path'] = substr($path, strlen(base_path()));
128 }
129 else {
130 $item['path'] = 'gallery/'. (count($parents) ? implode('/', $parents) .'/' : '') . $id;
131 $item['page callback'] = 'gallery_menu_album';
132 $item['page arguments'] = array((string)$id);
133 }
134 $item['title'] = $album['title'];
135 $item['access callback'] = 'gallery_item_access';
136 $item['access arguments'] = array((string)$id);
137 $items[] = $item;
138 if (count($tree[$id])) {
139 array_push($parents, $id);
140 _gallery_menu_traverse($tree[$id], $items);
141 array_pop($parents);
142 }
143 }
144 $tree[$id] += $album;
145 }
146 }
147
148 /**
149 * Function _gallery_menu_settings().
150 */
151 function _gallery_menu_settings() {
152 $form['menu'] = array(
153 '#type' => 'fieldset',
154 '#title' => t('Gallery menu settings'),
155 '#collapsible' => FALSE,
156 '#collapsed' => FALSE,
157 );
158 $form['menu']['gallery_menu_depth'] = array(
159 '#type' => 'textfield',
160 '#title' => t('Depth of Gallery albums'),
161 '#default_value' => variable_get('gallery_menu_depth', 0),
162 '#description' => 'Depth of album hierarchy to include (\'0\' for infinite).'
163 );
164
165 // Item visibility settings
166 $form['menu']['items'] = array(
167 '#type' => 'fieldset',
168 '#title' => t('Menu Items'),
169 '#collapsible' => TRUE,
170 '#collapsed' => TRUE
171 );
172 $form['menu']['items'][] = _gallery_menu_settings_table();
173
174 return system_settings_form($form);
175 }
176
177 /**
178 * Function _gallery_menu_settings_table().
179 */
180 function _gallery_menu_settings_table() {
181 if (!_gallery_init(TRUE)) {
182 return array();
183 }
184
185 $depth = variable_get('gallery_menu_depth', 0);
186 $tree = gallery_album_tree(NULL, $depth ? $depth : NULL);
187
188 $form = _gallery_menu_settings_traverse($tree);
189 $form['#theme'] = 'gallery_menu_settings_table';
190
191 GalleryEmbed::done();
192 return $form;
193 }
194
195 /**
196 * Function _gallery_menu_album_traverse().
197 */
198 function _gallery_menu_settings_traverse(&$tree) {
199 static $parents = array();
200 foreach (array_keys($tree) as $id) {
201 $album = gallery_item_details($id);
202 $enabled = variable_get('gallery_menu_show_'. $id, 1);
203 $form[$id]['title'] = array('#value' => implode('', $parents) .' '. $album['title']);
204 $form[$id]['checkbox']['gallery_menu_show_'. $id] = array(
205 '#type' => 'checkbox',
206 '#title' => '',
207 '#default_value' => $enabled
208 );
209 if (count($tree[$id]) && $enabled) {
210 array_push($parents, '-');
211 $form[$id]['children'] = _gallery_menu_settings_traverse($tree[$id]);
212 array_pop($parents);
213 }
214 $tree[$id] += $album;
215 }
216
217 return $form;
218 }
219
220 /**
221 * Theme function : theme_gallery_menu_settings_table().
222 */
223 function theme_gallery_menu_settings_table($form, $rows = array()) {
224 static $depth = 0;
225 foreach (element_children($form) as $key) {
226 if (isset($form[$key]['title'])) {
227 $row = array();
228 $row[] = drupal_render($form[$key]['title']);
229 $row[] = drupal_render($form[$key]['checkbox']);
230 $rows[] = $row;
231 }
232 if (isset($form[$key]['children'])) {
233 $depth++;
234 $rows = theme_gallery_menu_settings_table($form[$key]['children'], $rows);
235 }
236 }
237
238 $depth--;
239 return ($depth < 0) ? theme('table', array(t('Album'), t('Show')), $rows) : $rows;
240 }

  ViewVC Help
Powered by ViewVC 1.1.2