Commit 030f6937 authored by profix898's avatar profix898

- update D6 version (Oct-15, 2007)

parent dccc293a
......@@ -3,7 +3,7 @@
function g2ic_open(field) {
// Set some properties
var form = $('#'+field).parents('form').attr('id');
var url = Drupal.settings.gallery2.g2image_uri+'g2image.php?g2ic_form='+form+'&g2ic_field='+field+'&g2ic_tinymce=0';
var url = Drupal.settings.gallery.g2image_uri+'g2image.php?g2ic_form='+form+'&g2ic_field='+field+'&g2ic_tinymce=0';
var name = 'g2image';
var w = 600;
var h = 600;
......
......@@ -37,8 +37,20 @@ function gallery_theme() {
'gallery_severity_status_message' => array(
'arguments' => array('severity' => NULL, 'status' => NULL, 'full_msg' => FALSE, 'invert' => FALSE),
),
'gallery_g2image_textarea_link' => array(
'arguments' => array('element' => NULL, 'link' => NULL),
),
'gallery_report' => array(
'arguments' => array('report' => FALSE),
),
'gallery_block_image_block' => array(
'arguments' => array('content' => NULL, 'class' => NULL),
),
'gallery_block_grid_block' => array(
'arguments' => array('images' => NULL, 'num_cols' => NULL, 'class' => NULL),
),
'gallery_search_item' => array(
'arguments' => array('item' => NULL),
)
);
}
......@@ -52,7 +64,7 @@ function gallery_init() {
drupal_add_css(drupal_get_path('module', 'gallery') .'/gallery.css');
drupal_add_css(drupal_get_path('module', 'gallery') .'/gallery_filter.css');
// Switch theme for gallery pages
if (arg(0) == 'gallery' && (($theme = variable_get('gallery_page_theme', NULL)) != 'default')) {
if (arg(0) == variable_get('gallery_base', 'gallery') && (($theme = variable_get('gallery_page_theme', NULL)) != 'default')) {
$custom_theme = $theme;
init_theme();
}
......@@ -65,7 +77,7 @@ function gallery_menu() {
$items = array();
$gallery_valid = variable_get('gallery_valid', 0);
if ($gallery_valid) {
$items['gallery'] = array(
$items[variable_get('gallery_base', 'gallery')] = array(
'title' => 'Gallery',
'description' => 'Visit your embedded Gallery2.',
'access callback' => 'user_access',
......@@ -373,7 +385,7 @@ function gallery_block($op = 'list', $delta = 0, $edit = array()) {
* (main gallery display page)
*/
function gallery_page() {
if (!_gallery_init(FALSE)) {
if (!_gallery_init()) {
return '';
}
// Turn off sidebar
......@@ -423,7 +435,7 @@ function gallery_page() {
}
}
// Store the sidebar info in a global variable for use in the gallery navigation block
$GLOBALS['_gallery_sidebar_'] = $result['sidebarBlocksHtml'];
$GLOBALS['gallery_sidebar'] = $result['sidebarBlocksHtml'];
return $result['bodyHtml'];
}
......
......@@ -188,12 +188,10 @@ function gallery_get_image_frames() {
* Function gallery_generate_url().
*/
function gallery_generate_url($params, $html = TRUE, $full = TRUE) {
if (!isset($GLOBALS['gallery'])) {
if (!_gallery_init()) {
return '';
}
if (!_gallery_init()) {
return '';
}
// Get URL generator and generate the url
$url_generator =& $GLOBALS['gallery']->getUrlGenerator();
if (!$url_generator) {
gallery_error(t('Error: UrlGenerator not available'));
......@@ -215,7 +213,7 @@ function gallery_generate_url($params, $html = TRUE, $full = TRUE) {
* Function gallery_album_tree().
*/
function gallery_album_tree($root = NULL, $depth = NULL, $uid = NULL) {
if (!_gallery_init()) {
if (!_gallery_init(TRUE)) {
return array();
}
// If this is called for the Drupal guest user, pass in G2
......@@ -242,6 +240,9 @@ function gallery_album_tree($root = NULL, $depth = NULL, $uid = NULL) {
*/
function gallery_item_details($id, $verbose = FALSE) {
$details = array();
if (!_gallery_init(TRUE)) {
return $details;
}
// Load entity
list($ret, $entity) = GalleryCoreApi::loadEntitiesById($id);
if ($ret) {
......@@ -250,32 +251,50 @@ function gallery_item_details($id, $verbose = FALSE) {
return $details;
}
// Extract details
$details['g2id'] = $id;
$details['g2type'] = $entity->entityType;
$details['g2owner'] = $entity->ownerId;
$details['g2parent'] = $entity->parentId;
// Drupal node properties (no g2 prefix)
$details['title'] = _gallery_htmlcharsdecode($entity->title);
$details['created'] = $entity->creationTimestamp;
$details['changed'] = $entity->modificationTimestamp;
if ($verbose) {
$details['g2description'] = _gallery_htmlcharsdecode($entity->description);
$details['g2summary'] = _gallery_htmlcharsdecode($entity->summary);
$details['g2keywords'] = $entity->keywords;
$details['g2theme'] = $entity->theme;
$details['g2theme'] = isset($entity->theme) ? $entity->theme : NULL;
}
return $details;
}
/**
* Function gallery_item_access().
*/
function gallery_item_access($id, $permission = 'core.view', $user = NULL) {
if (!_gallery_init(TRUE)) {
return FALSE;
}
// Check access permissions
list($ret, $access) = GalleryCoreApi::hasItemPermission($id, $permission, $user);
if ($ret) {
gallery_error(t('Error calling hasItemPermission()'), $ret);
return FALSE;
}
return $access;
}
/**
* Function gallery_db_query().
*/
function gallery_db_query($query, $data = NULL) {
if (!isset($GLOBALS['gallery'])) {
if (!_gallery_init()) {
return FALSE;
}
if (!_gallery_init(TRUE)) {
return FALSE;
}
// Perform query
list ($ret, $search) = $GLOBALS['gallery']->search($query, $data);
if ($ret) {
return FALSE;
......@@ -292,11 +311,10 @@ function gallery_db_query($query, $data = NULL) {
* Function gallery_flush_entity_cache().
*/
function gallery_flush_entity_cache() {
if (!isset($GLOBALS['gallery'])) {
if (!_gallery_init()) {
return FALSE;
}
if (!_gallery_init()) {
return FALSE;
}
// Flush entity cache
$platform =& $GLOBALS['gallery']->getPlatform();
$cache_basedir = $GLOBALS['gallery']->getConfig('data.gallery.cache');
$cache_dir = $cache_basedir .'entity';
......@@ -333,21 +351,27 @@ function gallery_set_css($css) {
if (count($css)) {
$css = preg_replace('/<link(.*?)href="([^"]*)"(.*?)\/>/i', '${2}', $css);
$css = preg_replace(array('#^'. $base_url .'#', '#^'. base_path() .'#', '#^/#'), '', $css);
foreach ($css as $include) {
if (!in_array(($md5 = md5($include)), $css_memory)) {
$css_memory[] = $md5;
if (substr($include, 0, 6) == '<style') {
// drupal_add_css() does not support inline styles
drupal_set_html_head($include);
}
elseif (substr($include, 0, 4) == 'http' || variable_get('gallery_outside', 0)) {
if (variable_get('gallery_outside', 0)) {
// drupal_add_css() does not support external paths
drupal_set_html_head('<link type="text/css" rel="stylesheet" media="all" href="'. $include .'" />'."\n");
drupal_set_html_head('<link type="text/css" rel="stylesheet" media="all" href="'. $include .'" />');
}
else {
// Gallery's css must always be added first to allow overriding from the module(s)
drupal_add_css($include, 'module', 'all', FALSE);
$include = preg_replace(array('#^'. $base_url .'#', '#^'. base_path() .'#', '#^/#'), '', $include);
if (substr($include, 0, 6) == '<style') {
// drupal_add_css() does not support inline styles
drupal_set_html_head($include);
}
elseif (substr($include, 0, 4) == 'http') {
// drupal_add_css() does not support external paths
drupal_set_html_head('<link type="text/css" rel="stylesheet" media="all" href="'. $include .'" />');
}
else {
// Gallery's css must always be added first to allow overriding from the module(s)
drupal_add_css($include, 'module', 'all', FALSE);
}
}
}
}
......@@ -370,22 +394,54 @@ function gallery_set_javascript($javascript) {
drupal_add_js(implode("\n", $inline), 'inline');
// Javascript files
$files = preg_replace('/<script(.*?)src="([^"]*)"([^>]*)>(.*?)<\/script>/i', '${2}', $files);
$files = preg_replace(array('#^'. $base_url .'#', '#^'. base_path() .'#', '#^/#'), '', $files);
foreach ($files as $include) {
if (!in_array(($md5 = md5($include)), $js_memory)) {
$js_memory[] = $md5;
if (substr($include, 0, 4) == 'http' || variable_get('gallery_outside', 0)) {
if (variable_get('gallery_outside', 0)) {
// drupal_add_js() does not support external paths
drupal_set_html_head('<script type="text/javascript" src="'. $include .'"></script>'."\n");
drupal_set_html_head('<script type="text/javascript" src="'. $include .'"></script>');
}
else {
drupal_add_js($include);
$include = preg_replace(array('#^'. $base_url .'#', '#^'. base_path() .'#', '#^/#'), '', $include);
if (substr($include, 0, 4) == 'http') {
// drupal_add_js() does not support external paths
drupal_set_html_head('<script type="text/javascript" src="'. $include .'"></script>');
}
else {
drupal_add_js($include);
}
}
}
}
}
}
/**
* Function gallery_get_block().
*
* This function allows developers to fetch an image or grid block with certain
* parameters from Gallery2.
*
* @param $params
* An array of parameters to be passed to getImageBlock().
* (http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryEmbed.html#methodgetImageBlock)
* If 'itemId' is set to 'user' (or 'user:uid') items are be taken from the
* current (or specified) user's useralbum.
* @param $num_cols
* If given a grid block with $num_cols columns is generated.
* Otherwise (default) a 'normal' image block is returned.
* @param $class
* Optional class to apply to the block (if customized css styles are required).
*/
function gallery_get_block($params, $num_cols = NULL, $class = NULL) {
if (!_gallery_init()) {
return array('content' => '');
}
// Include gallery_block.inc and call the private implementation
require_once(drupal_get_path('module', 'gallery') .'/gallery_block.inc');
return _gallery_block_get_block($params, $num_cols, $class);
}
/**
* Function _gallery_split_imageblock().
* (split an image block result into individual images)
......@@ -515,8 +571,7 @@ function gallery_plugin_status($plugin_names) {
static $all_plugins_status = array();
$plugins_status = array();
if (!_gallery_init(FALSE)) {
gallery_error(t('Unable to initialize Gallery2.'), $ret);
if (!_gallery_init()) {
foreach ($plugin_names as $plugin) {
$plugins_status[$plugin] = GALLERY_PLUGIN_STATUS_UNKNOWN;
}
......@@ -598,10 +653,10 @@ function gallery_get_status() {
* Function gallery_version().
*/
function gallery_version() {
if (!_gallery_init(FALSE)) {
if (!_gallery_init()) {
return array();
}
// Get API version
list($core_major, $core_minor) = GalleryCoreApi::getApiVersion();
list($embed_major, $embed_minor) = GalleryEmbed::getApiVersion();
$version = array(
......
......@@ -17,21 +17,32 @@ function _gallery_block($op = 'list', $delta = 0, $edit = array()) {
$type_map = $param_map = array();
_gallery_block_options($type_map, $param_map);
list($type, $delta) = (stristr($delta, '-') !== FALSE) ? explode('-', $delta) : array('', 0);
if ($delta == 'navigation') {
$type = $delta;
}
else {
list($type, $delta) = (stristr($delta, '-') !== FALSE) ? explode('-', $delta) : array('', 0);
}
switch ($op) {
case 'list':
// Navigation Block
$blocks['navigation']['info'] = t('Gallery Navigation');
$blocks['navigation']['cache'] = variable_get('gallery_block_navigation_cache', BLOCK_CACHE_PER_USER);
// Image Block
$imageblock_num = variable_get('gallery_block_image_num', 1);
for ($i=0; $i<$imageblock_num; $i++) {
$id = variable_get('gallery_block_image_'. $i .'_blockid', '');
$blocks['image-'. $i]['info'] = t('Gallery Image Block @id',
array('@id' => ($imageblock_num > 1) ? ('['. ($id ? $id : $i+1) .']') : ''));
$blocks['image-'. $i]['cache'] = variable_get('gallery_block_image_'. $i .'_cache', BLOCK_CACHE_PER_USER);
}
// Image Grid Block
$gridblock_num = variable_get('gallery_block_grid_num', 1);
for ($i=0; $i<$gridblock_num; $i++) {
$id = variable_get('gallery_block_grid_'. $i .'_blockid', '');
$blocks['grid-'. $i]['info'] = t('Gallery Grid Block @id',
array('@id' => ($gridblock_num > 1) ? ('['. ($id ? $id : $i+1) .']') : ''));
$blocks['grid-'. $i]['cache'] = variable_get('gallery_block_grid_'. $i .'_cache', BLOCK_CACHE_PER_USER);
}
return $blocks;
case 'view':
......@@ -40,10 +51,9 @@ function _gallery_block($op = 'list', $delta = 0, $edit = array()) {
}
switch ($type) {
case 'navigation': // Navigation Block
global $_gallery_sidebar_;
if ((arg(0) == 'gallery') && !empty($_gallery_sidebar_)) {
if ((arg(0) == variable_get('gallery_base', 'gallery')) && !empty($GLOBALS['gallery_sidebar'])) {
$block['subject'] = t('Gallery Navigation');
$block['content'] = '<div id="gsSidebar" class="gcBorder1">'. implode('', $_gallery_sidebar_) .'</div>';
$block['content'] = '<div id="gsSidebar" class="gcBorder1">'. implode('', $GLOBALS['gallery_sidebar']) .'</div>';
}
break;
case 'image': // Image Block
......@@ -58,6 +68,8 @@ function _gallery_block($op = 'list', $delta = 0, $edit = array()) {
case 'configure':
require_once(drupal_get_path('module', 'gallery') .'/gallery_settings.inc');
switch ($type) {
case 'navigation': // Navigation Block
return _gallery_settings_block_navigation();
case 'image': // Image Block
return _gallery_settings_block_image($delta);
case 'grid': // Image Grid Block
......@@ -101,16 +113,9 @@ function _gallery_block_options(&$type_map, &$param_map) {
* Function _gallery_block_image_block().
*/
function _gallery_block_image_block($delta, $type_map) {
$param_blocks_array = variable_get('gallery_block_image_'. $delta .'_block_block', array('randomImage'));
$param_blocks_array = array_filter(variable_get('gallery_block_image_'. $delta .'_block_block', array('randomImage')));
$params['blocks'] = is_array($param_blocks_array) ? implode('|', $param_blocks_array) : '';
$param_itemid = variable_get('gallery_block_image_'. $delta .'_item_id', '');
if (trim($param_itemid) == '%user') {
require_once(drupal_get_path('module', 'gallery') .'/gallery_user.inc');
$param_itemid = gallery_user_useralbum(NULL, FALSE);
}
if (!empty($param_itemid)) {
$params['itemId'] = $param_itemid;
}
$params['itemId'] = variable_get('gallery_block_image_'. $delta .'_item_id', '');
$param_show_array = variable_get('gallery_block_image_'. $delta .'_block_show', array());
$params['show'] = is_array($param_show_array) ? implode('|', $param_show_array) : '';
if (variable_get('gallery_block_image_'. $delta .'_size_method', GALLERY_IMAGEBLOCK_SIZE_METHOD_DEFAULT) == 'maxsize') {
......@@ -123,37 +128,13 @@ function _gallery_block_image_block($delta, $type_map) {
$params['itemFrame'] = variable_get('gallery_block_image_'. $delta .'_item_frame', 'none');
$params['linkTarget'] = variable_get('gallery_block_image_'. $delta .'_link_target', '');
$params['link'] = variable_get('gallery_block_image_'. $delta .'_link', '');
$block = array();
list($ret, $content, $head) = GalleryEmbed::getImageBlock($params);
if ($ret) {
gallery_error(t('Unable to get Gallery image block'), $ret);
return array();
}
if ($content) {
if (count($param_blocks_array) > 1) {
$block['subject'] = t('Gallery');
}
else {
$block['subject'] = $type_map[$params['blocks']];
}
$block['content'] = theme('gallery_block_image_block', $content);
}
if ($head) {
gallery_set_head($head);
}
$block = _gallery_block_get_block($params);
$block['subject'] = (count($param_blocks_array) > 1) ? t('Gallery') : $type_map[$params['blocks']];
return $block;
}
/**
* Theme function : theme_gallery_block_image_block().
*/
function theme_gallery_block_image_block($content) {
return '<div class="g2image_centered">'. $content .'</div>';
}
/**
* Function _gallery_block_grid_block().
*/
......@@ -164,14 +145,7 @@ function _gallery_block_grid_block($delta, $type_map) {
$param_blocks_array = array_fill(0, $num_images, variable_get('gallery_block_grid_'. $delta .'_block_block', 'randomImage'));
$params['blocks'] = is_array($param_blocks_array) ? implode('|', $param_blocks_array) : '';
$param_itemid = variable_get('gallery_block_grid_'. $delta .'_item_id', '');
if (trim($param_itemid) == '%user') {
require_once(drupal_get_path('module', 'gallery') .'/gallery_user.inc');
$param_itemid = gallery_user_useralbum(NULL, FALSE);
}
if (!empty($param_itemid)) {
$params['itemId'] = $param_itemid;
}
$params['itemId'] = variable_get('gallery_block_grid_'. $delta .'_item_id', '');
$param_show_array = variable_get('gallery_block_grid_'. $delta .'_block_show', array());
$params['show'] = is_array($param_show_array) ? implode('|', $param_show_array) : '';
if (variable_get('gallery_block_grid_'. $delta .'_size_method', GALLERY_GRID_SIZE_METHOD_DEFAULT) == 'maxsize') {
......@@ -185,29 +159,62 @@ function _gallery_block_grid_block($delta, $type_map) {
$params['linkTarget'] = variable_get('gallery_block_grid_'. $delta .'_link_target', '');
$params['link'] = variable_get('gallery_block_grid_'. $delta .'_link', '');
$block = array();
return _gallery_block_get_block($params, $num_cols);
}
/**
* Function _gallery_block_get_block().
*/
function _gallery_block_get_block($params, $num_cols = NULL, $class = NULL) {
// Handle useralbum feature
if (preg_match('/user(:([\d]+))?/i', $params['itemId'], $param_uid)) {
require_once(drupal_get_path('module', 'gallery') .'/gallery_user.inc');
$params['itemId'] = gallery_user_useralbum(isset($param_uid[2]) ? $param_uid[2] : NULL, FALSE);
}
if (empty($params['itemId']) || $params['itemId'] === FALSE) {
unset($params['itemId']);
}
// Get the image(s) from G2
list($ret, $content, $head) = GalleryEmbed::getImageBlock($params);
if ($ret) {
gallery_error(t('Unable to get Gallery image block'), $ret);
return array();
}
// Format the block content
$block = array();
if ($content) {
$block['subject'] = t('Gallery');
$images = _gallery_split_imageblock($content);
$images = array_chunk($images, $num_cols);
$block['content'] = theme('gallery_block_grid_block', $images);
}
if ($head) {
gallery_set_head($head);
$block['subject'] = t('Gallery');
if (isset($num_cols)) {
$class = isset($class) ? $class : 'gallery-grid-block';
$block['content'] = theme('gallery_block_grid_block', $content, $num_cols, $class);
}
else {
$class = isset($class) ? $class : 'g2image_centered';
$block['content'] = theme('gallery_block_image_block', $content, $class);
}
// Add css/js to the page
if ($head) {
gallery_set_head($head);
}
}
return $block;
}
/**
* Theme function : theme_gallery_block_image_block().
*/
function theme_gallery_block_image_block($content, $class = 'g2image_centered') {
return '<div class="'. $class .'">'. $content .'</div>';
}
/**
* Theme function : theme_gallery_block_grid_block().
*/
function theme_gallery_block_grid_block($images) {
function theme_gallery_block_grid_block($content, $num_cols, $class = 'gallery-grid-block') {
$images = _gallery_split_imageblock($content);
$images = array_chunk($images, $num_cols);
$rows = array();
foreach ($images as $image_row) {
$row = array();
......@@ -216,10 +223,10 @@ function theme_gallery_block_grid_block($images) {
}
$rows[] = $row;
}
$html = '<div class="gallery-grid-block"><div class="image-grid">';
$html = '<div class="'. $class .'"><div class="image-grid">';
$html .= theme('table', array(), $rows);
$html .= '</div></div>';
return $html;
}
......@@ -39,8 +39,12 @@ function gallery_filter_process($text) {
foreach ($matches as $match) {
// First argument is numeric => valid G2 filter tag
if (is_numeric($match[1])) {
$params = array();
$params = array('type' => 'specificItem');
$params['itemId'] = intval($match[1]);
if (preg_match('/user(:([\d]+))?/i', $params['itemId'], $param_uid)) {
require_once(drupal_get_path('module', 'gallery') .'/gallery_user.inc');
$params['itemId'] = gallery_user_useralbum(isset($param_uid[2]) ? $param_uid[2] : NULL, FALSE);
}
$args = array_filter(preg_split('/[\s,]+/', $match[2]));
// Loop over all (optional) arguments
foreach ($args as $arg) {
......@@ -57,13 +61,16 @@ function gallery_filter_process($text) {
// entered value must take precedence over the default)
if (isset($params['maxsize'])) {
unset($default['exactsize']);
}
if (isset($params['exactsize'])) {
}
else if (isset($params['exactsize'])) {
unset($default['maxsize']);
}
// Merge params with default values
$params = array_merge($default, $params);
// Transform 'type' into a valid parameter
if ($params['n'] > 1 && $params['type'] == 'specificItem') {
$params['type'] = $default['type'];
}
if (is_array($params['type'])) {
// Ensure 'type' contains 'n' elements (auto-append if necessary)
$count = count($params['type']);
......@@ -80,19 +87,27 @@ function gallery_filter_process($text) {
}
// Convert into G2-compatible arguments
$params['blocks'] = implode('|', $params['type']);
if (isset($params['maxsize']) && !empty($params['maxsize'])) {
if (isset($params['maxsize']) && !empty($params['maxsize'])) {
$params['maxSize'] = $params['maxsize'];
unset($params['exactSize']);
}
if (isset($params['exactsize']) && !empty($params['exactsize'])) {
else if (isset($params['exactsize']) && !empty($params['exactsize'])) {
$params['exactSize'] = $params['exactsize'];
unset($params['maxSize']);
}
$params['albumFrame'] = $params['album_frame'];
$params['itemFrame'] = $params['item_frame'];
$params['show'] = implode('|', $params['show']);
$params['linkTarget'] = $params['target'];
$params['link'] = $params['link'];
// Unset redundant parameters
unset(
$params['n'],
$params['type'],
$params['exactsize'],
$params['maxsize'],
$params['frame'],
$params['album_frame'],
$params['item_frame'],
$params['target']
);
// Fetch the images and format output
list($ret, $content, $head) = GalleryEmbed::getImageBlock($params);
if ($ret) {
......@@ -100,6 +115,8 @@ function gallery_filter_process($text) {
continue;
}
if ($content) {
// Allow modules to alter the filter output
drupal_alter('gallery_filter', $content);
// Replace G2 filter tag with image block html
$params['class'] = 'giImageBlock'. ($params['class'] ? ' '. $params['class'] : '');
$content = '<div class ="'. $params['class'] .'">'. $content .'</div>';
......
......@@ -16,8 +16,8 @@ function gallery_g2image_add_js() {
$path = drupal_get_path('module', 'gallery');
$g2image_uri = base_path() . $path .'/g2image/';
drupal_add_js(array('gallery2' => array('g2image_uri' => $g2image_uri)), 'setting');
drupal_add_js($path .'/g2image.js');
drupal_add_js(array('gallery' => array('g2image_uri' => $g2image_uri)), 'setting');
drupal_add_js($path .'/gallery.js');
$sent = TRUE;
}
......
This diff is collapsed.
......@@ -20,10 +20,6 @@ function gallery_menu_theme() {
* Implementation of hook_init().
*/
function gallery_menu_init() {
// Initialize G2
if (!_gallery_init(FALSE)) {
return;
}
// 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
......@@ -55,57 +51,61 @@ function gallery_menu_menu() {
return $items;
}
/**
* 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);
}
/**
* Implementation of hook_gallery_page_alter().
*/
function gallery_menu_gallery_page_alter(&$result) {
if (isset($result['themeData']['pageUrl']['itemId'])) {
$id = $result['themeData']['pageUrl']['itemId'];
$item = gallery_item_details($id);
if ($item['g2type'] != 'GalleryAlbumItem') {
$id = $item['g2parent'];
// Remove trailing slash from the G2 path
if (!empty($_GET['g2_path'])) {
$_GET['g2_path'] = rtrim($_GET['g2_path'], '/');
}
// Generate the path to set the active menu item
if (isset($result['themeData']['item'])) {
$gallery_base = variable_get('gallery_base', 'gallery');
$id = $result['themeData']['item']['id'];
if ($result['themeData']['item']['entityType'] != 'GalleryAlbumItem') {
$id = $result['themeData']['item']['parentId'];
}
list($ret, $parents) = GalleryCoreApi::fetchParentSequence($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_base .'/'. (count($parents) ? implode('/', $parents) .'/' : '') . $id;
}
}
list($ret, $root) = GalleryCoreApi::getDefaultAlbumId();
if ($ret) {
gallery_error(t('Error fetching item parents'), $ret);
gallery_error(t('Error calling getDefaultAlbumId()'), $ret);
}
else {
array_shift($parents);
$path = 'gallery/'. (count($parents) ? implode('/', $parents) .'/' : '') . $id;
menu_set_active_item($path);
menu_set_active_item(($id == $root) ? $gallery_base : $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() {
$items = array();
// Load any user from the G2 admin group
list($ret, $g2_admin_gid) = GalleryCoreApi::getPluginParameter('module', 'core', 'id.adminGroup');
if ($ret) {
gallery_error(t('Error getting \'adminGroup\' id'), $ret);
return $items;
}
list($ret, $user) = GalleryCoreApi::fetchUsersForGroup($g2_admin_gid, 1);
if ($ret) {
gallery_error(t('Error fetching users for \'adminGroup\' id'), $ret);
return $items;
}
$user = array_keys($user);
// Fetch the album tree and generate the menu items
$depth = variable_get('gallery_menu_depth', 0);
$tree = gallery_album_tree(NULL, $depth ? $depth : NULL, $user[0]);
$depth = variable_get('gallery_menu_depth', 5);
$tree = gallery_album_tree(NULL, $depth ? $depth : NULL);
_gallery_menu_traverse($tree, $items);
return $items;
......@@ -117,34 +117,42 @@ function gallery_menu_build_menu() {
function _gallery_menu_traverse(&$tree, &$items) {
static $parents = array();
foreach (array_keys($tree) as $id) {
$album = gallery_item_details($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)) {
$path = gallery_generate_url(array('itemId' => $id), FALSE, FALSE);
$item['path'] = substr($path, strlen(base_path()));
if (isset($url_generator->_shortUrls) && variable_get('gallery_menu_rewrite', 0)) {
$path = _gallery_menu_album_path($id);
}
else {
$item['path'] = 'gallery/'. (count($parents) ? implode('/', $parents) .'/' : '') . $id;
$path = variable_get('gallery_base', 'gallery') .'/'. (count($parents) ? implode('/', $parents) .'/' : '') . $id;
$item['page callback'] = 'gallery_menu_album';
$item['page arguments'] = array((string)$id);
}
$album = gallery_item_details($id);
$item['title'] = $album['title'];
$item['access callback'] = 'gallery_item_access';