'admin/settings/gallery/menu', 'title' => t('Menu'), 'callback' => 'drupal_get_form', 'callback arguments' => '_gallery_menu_settings', 'access' => user_access('administer gallery settings'), 'type' => MENU_LOCAL_TASK, 'weight' => 6 ); } else { // Rebuild the menu if the G2 album structure changed $timestamp = variable_get('gallery_menu_timestamp', 0); $query = 'SELECT COUNT([GalleryEntity::id]) FROM [GalleryEntity], [GalleryAlbumItem] WHERE [GalleryAlbumItem::id] = [GalleryEntity::id] AND [GalleryEntity::modificationTimeStamp] > ?'; if (($results = gallery_db_query($query, array($timestamp))) && $results[0]) { cache_clear_all('gallery:menu', 'cache', TRUE); variable_set('gallery_menu_timestamp', time()); } // Insert the menu items if (user_access('access gallery')) { $items = gallery_menu_build_menu(); } } } return $items; } /** * Function gallery_menu_page(). */ function gallery_menu_page($result) { // Generate the path to set the active menu item if (isset($result['themeData']['item'])) { switch ($result['themeData']['item']['entityType']) { case 'GalleryAlbumItem': $id = $result['themeData']['item']['id']; break; case 'GalleryDynamicAlbum': $id = $result['themeData']['pageUrl']['albumId']; break; default: $id = $result['themeData']['item']['parentId']; } if (!empty($id)) { $url_generator =& $GLOBALS['gallery']->getUrlGenerator(); if (isset($url_generator->_shortUrls) && variable_get('gallery_menu_rewrite', 0)) { $path = _gallery_menu_album_path($id); } else { list($ret, $parents) = GalleryCoreApi::fetchParentSequence($id); if ($ret) { gallery_error(t('Error fetching item parents'), $ret); } else { array_shift($parents); $path = 'gallery/'. (count($parents) ? implode('/', $parents) .'/' : '') . $id; } } } list($ret, $root) = GalleryCoreApi::getDefaultAlbumId(); if ($ret) { gallery_error(t('Error calling getDefaultAlbumId()'), $ret); } menu_set_active_item(($id == $root) ? 'gallery' : $path); } } /** * Function gallery_menu_album(). */ function gallery_menu_album($id) { // Redirect to true album url (from the virtual menu path) $url = gallery_generate_url(array('itemId' => $id), FALSE); drupal_goto($url); } /** * Function gallery_menu_build_menu(). */ function gallery_menu_build_menu() { global $user; $items = array(); $cid = 'gallery:menu:'. $user->uid; if ($cache = cache_get($cid)) { $items = unserialize($cache->data); } else { $depth = variable_get('gallery_menu_depth', 5); $tree = gallery_album_tree(NULL, $depth ? $depth : NULL); if (count($tree)) { _gallery_menu_traverse($tree, $items); // My Album link $items[] = array( 'path' => gallery_user_useralbum(), 'title' => t('My Album'), 'description' => t('Go to your Gallery2 useralbum.'), 'callback' => 'gallery_page', 'access' => user_access('access gallery') ); cache_set($cid, 'cache', serialize($items), CACHE_TEMPORARY); } } return $items; } /** * Function _gallery_menu_traverse(). */ function _gallery_menu_traverse(&$tree, &$items) { static $parents = array(); foreach (array_keys($tree) as $id) { if (variable_get('gallery_menu_show_'. $id, 1)) { $item = array(); // Check for URL Rewrite being available $url_generator =& $GLOBALS['gallery']->getUrlGenerator(); if (isset($url_generator->_shortUrls) && variable_get('gallery_menu_rewrite', 0)) { $item['path'] = _gallery_menu_album_path($id); } else { $item['path'] = 'gallery/'. (count($parents) ? implode('/', $parents) .'/' : '') . $id; $item['callback'] = 'gallery_menu_album'; $item['callback arguments'] = array($id); } $album = gallery_item_details($id); $item['title'] = $album['title']; $item['access'] = user_access('access gallery'); $item['type'] = MENU_DYNAMIC_ITEM; $items[] = $item; if (count($tree[$id])) { array_push($parents, $id); _gallery_menu_traverse($tree[$id], $items); array_pop($parents); } } } } /** * Function _gallery_menu_album_path(). */ function _gallery_menu_album_path($id) { $path = urldecode(gallery_generate_url(array('itemId' => $id), FALSE, FALSE)); // Strip off the base path ... $path = substr($path, strlen(base_path())); // ... and additional parameter (e.g. session id, etc.) if (($pos = strrpos($path, '/')) !== FALSE) { $path = substr($path, 0, $pos + 1); } // Remove the language-prefix if (module_exists('i18n')) { i18n_get_lang_prefix($path, TRUE); } return rtrim($path, '/'); } /** * Function _gallery_menu_settings(). */ function _gallery_menu_settings() { $form['menu'] = array( '#type' => 'fieldset', '#title' => t('Gallery menu settings'), '#collapsible' => FALSE, '#collapsed' => FALSE, ); $url_generator =& $GLOBALS['gallery']->getUrlGenerator(); $form['menu']['gallery_menu_rewrite'] = array( '#type' => 'checkbox', '#title' => t('Enable URL Rewrite mode'), '#default_value' => variable_get('gallery_menu_rewrite', 0), '#description' => t('By default gallery menu paths look like \'gallery/album_id/subalbum_id\'. However if URL Rewrite plugin is enabled in G2 you can force the module to use the same paths as generated by G2 internally (i.e. \'gallery/v/album/subalbum\').'), '#disabled' => !isset($url_generator->_shortUrls) ); $form['menu']['gallery_menu_depth'] = array( '#type' => 'textfield', '#title' => t('Depth of Gallery albums'), '#size' => 10, '#default_value' => variable_get('gallery_menu_depth', 5), '#description' => 'Depth of album hierarchy to include (\'0\' for infinite).' ); // Item visibility settings $form['menu']['items'] = array( '#type' => 'fieldset', '#title' => t('Menu Items'), '#collapsible' => TRUE, '#collapsed' => TRUE ); $form['menu']['items'][] = _gallery_menu_settings_table(); $form['#submit']['_gallery_menu_settings_submit'] = array(); $form['#submit']['system_settings_form_submit'] = array(); return system_settings_form($form); } /** * Function _gallery_menu_settings_submit(). */ function _gallery_menu_settings_submit($form_id, $form_values) { cache_clear_all('gallery:menu', 'cache', TRUE); } /** * Function _gallery_menu_settings_table(). */ function _gallery_menu_settings_table() { $depth = variable_get('gallery_menu_depth', 5); $tree = gallery_album_tree(NULL, $depth ? $depth : NULL); $form = _gallery_menu_settings_traverse($tree); $form['#theme'] = 'gallery_menu_settings_table'; GalleryEmbed::done(); return $form; } /** * Function _gallery_menu_album_traverse(). */ function _gallery_menu_settings_traverse(&$tree) { static $parents = array(); foreach (array_keys($tree) as $id) { $album = gallery_item_details($id); $enabled = variable_get('gallery_menu_show_'. $id, 1); $form[$id]['title'] = array('#value' => implode('', $parents) .' '. $album['title']); $form[$id]['checkbox']['gallery_menu_show_'. $id] = array( '#type' => 'checkbox', '#title' => '', '#default_value' => $enabled ); if (count($tree[$id]) && $enabled) { array_push($parents, '-'); $form[$id]['children'] = _gallery_menu_settings_traverse($tree[$id]); array_pop($parents); } } return $form; } /** * Theme function : theme_gallery_menu_settings_table(). */ function theme_gallery_menu_settings_table($form, $rows = array()) { static $depth = 0; foreach (element_children($form) as $key) { if (isset($form[$key]['title'])) { $row = array(); $row[] = drupal_render($form[$key]['title']); $row[] = drupal_render($form[$key]['checkbox']); $rows[] = $row; } if (isset($form[$key]['children'])) { $depth++; $rows = theme_gallery_menu_settings_table($form[$key]['children'], $rows); } } $depth--; return ($depth < 0) ? theme('table', array(t('Album'), t('Show')), $rows) : $rows; }