e06b150c7fb11586ba4a596c64a10c48cacc56a9
9 * Implementation of hook_menu().
11 function gallery_menu_menu($may_cache) {
13 if (variable_get('gallery_valid', 0)) {
16 'path' => 'admin/settings/gallery/menu',
18 'callback' => 'drupal_get_form',
19 'callback arguments' => '_gallery_menu_settings',
20 'access' => user_access('administer gallery settings'),
21 'type' => MENU_LOCAL_TASK
,
26 $items = gallery_menu_build_menu();
34 * Implementation of hook_enable().
36 function gallery_menu_enable() {
37 variable_set('gallery_page_callback', 'gallery_menu_page');
41 * Implementation of hook_disable().
43 function gallery_menu_disable() {
44 variable_del('gallery_page_callback');
48 * Function gallery_menu_page().
50 function gallery_menu_page() {
51 $result = gallery_page(TRUE
);
52 if (isset($result['themeData']['pageUrl']['itemId'])) {
53 $id = $result['themeData']['pageUrl']['itemId'];
54 $item = gallery_item_details($id);
55 if ($item['type'] != 'GalleryAlbumItem') {
56 $id = $item['parent'];
58 list($ret, $parents) = GalleryCoreApi
::fetchParentSequence($id);
60 gallery_error(t('Error fetching item parents'), $ret);
63 array_shift($parents);
64 $path = 'gallery/'.
(count($parents) ?
implode('/', $parents) .
'/' : '') .
$id;
65 menu_set_active_item($path);
69 return $result['bodyHtml'];
73 * Function gallery_menu_album().
75 function gallery_menu_album($id) {
76 // Redirect to true album url (from the virtual menu path)
77 $url = gallery_generate_url(array('itemId' => $id), FALSE
);
82 * Function gallery_menu_build_menu().
84 function gallery_menu_build_menu() {
87 if (!_gallery_init(TRUE
)) {
91 $depth = variable_get('gallery_menu_depth', 0);
92 $tree = _gallery_menu_album_tree(NULL
, $depth ?
$depth : NULL
);
93 $cid = 'gallery_menu:'.
$user->uid .
':'.
md5(serialize($tree));
94 if ($cache = cache_get($cid)) {
95 $items = unserialize($cache->data
);
98 _gallery_menu_traverse($tree, $items);
99 cache_set($cid, 'cache', serialize($items), CACHE_TEMPORARY
);
102 GalleryEmbed
::done();
107 * Function _gallery_menu_album_tree().
109 function _gallery_menu_album_tree($root = NULL
, $depth = NULL
, $user = NULL
) {
110 list($ret, $tree) = GalleryCoreApi
::fetchAlbumTree($root, $depth, $user);
112 gallery_error(t('Error fetching album tree'), $ret);
120 * Function _gallery_menu_traverse().
122 function _gallery_menu_traverse(&$tree, &$items) {
123 static
$parents = array();
124 foreach (array_keys($tree) as
$id) {
125 $album = gallery_item_details($id);
126 if (variable_get('gallery_menu_show_'.
$id, 1)) {
127 $path = 'gallery/'.
(count($parents) ?
implode('/', $parents) .
'/' : '') .
$id;
130 'title' => htmlspecialchars_decode($album['title']),
131 'callback' => 'gallery_menu_album',
132 'callback arguments' => array($id),
133 'access' => user_access('access gallery'),
134 'type' => MENU_DYNAMIC_ITEM
136 if (count($tree[$id])) {
137 array_push($parents, $id);
138 _gallery_menu_traverse($tree[$id], $items);
142 $tree[$id] += $album;
147 * Function _gallery_menu_settings().
149 function _gallery_menu_settings() {
150 $form['menu'] = array(
151 '#type' => 'fieldset',
152 '#title' => t('Gallery menu settings'),
153 '#collapsible' => FALSE
,
154 '#collapsed' => FALSE
,
156 $form['menu']['gallery_menu_depth'] = array(
157 '#type' => 'textfield',
158 '#title' => t('Depth of Gallery albums'),
159 '#default_value' => variable_get('gallery_menu_depth', 0),
160 '#description' => 'Depth of album hierarchy to include (\'0\' for infinite).'
163 // Item visibility settings
164 $form['menu']['items'] = array(
165 '#type' => 'fieldset',
166 '#title' => t('Menu Items'),
167 '#collapsible' => TRUE
,
170 $form['menu']['items'][] = _gallery_menu_settings_table();
172 $form['#submit']['_gallery_menu_settings_submit'] = array();
173 $form['#submit']['system_settings_form_submit'] = array();
174 return system_settings_form($form);
178 * Function _gallery_menu_settings_submit().
180 function _gallery_menu_settings_submit($form_id, $form_values) {
181 cache_clear_all('gallery_menu:', 'cache', TRUE
);
185 * Function _gallery_menu_settings_table().
187 function _gallery_menu_settings_table() {
188 if (!_gallery_init(TRUE
)) {
192 $depth = variable_get('gallery_menu_depth', 0);
193 $tree = _gallery_menu_album_tree(NULL
, $depth ?
$depth : NULL
);
195 $form = _gallery_menu_settings_traverse($tree);
196 $form['#theme'] = 'gallery_menu_settings_table';
198 GalleryEmbed
::done();
203 * Function _gallery_menu_album_traverse().
205 function _gallery_menu_settings_traverse(&$tree) {
206 static
$parents = array();
207 foreach (array_keys($tree) as
$id) {
208 $album = gallery_item_details($id);
209 $enabled = variable_get('gallery_menu_show_'.
$id, 1);
210 $form[$id]['title'] = array('#value' => implode('', $parents) .
' '.
$album['title']);
211 $form[$id]['checkbox']['gallery_menu_show_'.
$id] = array(
212 '#type' => 'checkbox',
214 '#default_value' => $enabled
216 if (count($tree[$id]) && $enabled) {
217 array_push($parents, '-');
218 $form[$id]['children'] = _gallery_menu_settings_traverse($tree[$id]);
221 $tree[$id] += $album;
228 * Theme function : theme_gallery_menu_settings_table().
230 function theme_gallery_menu_settings_table($form, $rows = array()) {
232 foreach (element_children($form) as
$key) {
233 if (isset($form[$key]['title'])) {
235 $row[] = drupal_render($form[$key]['title']);
236 $row[] = drupal_render($form[$key]['checkbox']);
239 if (isset($form[$key]['children'])) {
241 $rows = theme_gallery_menu_settings_table($form[$key]['children'], $rows);
246 return ($depth < 0) ?
theme('table', array(t('Album'), t('Show')), $rows) : $rows;