Commit 3832c4f6 authored by profix898's avatar profix898

- bugfix: link_path <> router_path relation broken (#220158)

- bugfix: can't add Gallery links to Drupal menu items (#223860)
parent 84497ad4
......@@ -225,11 +225,62 @@ function gallery_menu() {
'page arguments' => array(5),
'type' => MENU_CALLBACK
);
if (_gallery_init(TRUE)) {
// Derive $skiparg parameter from current rewrite rules
// (only required if url rewrite is enabled)
$skiparg = 0;
$url_generator =& $GLOBALS['gallery']->getUrlGenerator();
if (isset($url_generator->_shortUrls)) {
list ($ret, $rules) = GalleryCoreApi::getPluginParameter('module', 'rewrite', 'activeRules');
if (!$ret) {
$rules = unserialize($rules);
$key = array_search('%path%', explode('/', $rules['rewrite'][0]['pattern']));
$skiparg = ($key === FALSE) ? 0 : $key;
}
}
variable_set('gallery_skiparg', $skiparg);
// Build the router items for gallery paths
for ($i=1; $i<=MENU_MAX_PARTS; $i++) {
$path = variable_get('gallery_base', 'gallery') .'/'. implode('/', array_fill(0, $i, '%gallery'));
$items[$path] = array(
'access callback' => ($i < $skiparg) ? FALSE : 'gallery_item_access',
'access arguments' => array($i),
'load arguments' => array('%map', '%index'),
'type' => MENU_CALLBACK
);
}
}
}
return $items;
}
/**
* Function gallery_load().
* (_load callback for the menu handler)
*/
function gallery_load($arg, $map, $index) {
if (!_gallery_init(TRUE)) {
return FALSE;
}
// Skip args that are static in the G2 rewrite rules
$skiparg = variable_get('gallery_skiparg', 0);
if ($index < $skiparg) {
return $arg;
}
// Check whether the $arg item/path exists and return the G2 item id (if available)
$url_generator =& $GLOBALS['gallery']->getUrlGenerator();
$path = isset($url_generator->_shortUrls) ? implode('/', array_slice($map, $skiparg)) : $arg;
if (($id = gallery_check_path2id($path)) !== FALSE) {
return ($index+1 < count($map)) ? $arg : $id;
}
return FALSE;
}
/**
* Function gallery_admin_access().
*/
......
......@@ -297,6 +297,33 @@ function gallery_get_image_frames() {
return $list;
}
/**
* Function gallery_check_path2id().
*/
function gallery_check_path2id($path) {
if (!_gallery_init(TRUE)) {
return FALSE;
}
// Cache the request items here to save G2 API calls
// (the menu system invokes _load repeatedly with the same arguments)
static $items = NULL;
if (!isset($items[$path])) {
$url_generator =& $GLOBALS['gallery']->getUrlGenerator();
if (isset($url_generator->_shortUrls)) {
// Fetch item id for this path (to check existence) and return id
list($ret, $id) = GalleryCoreApi::fetchItemIdByPath($path);
$items[$path] = $ret ? FALSE : $id;
}
else if (is_numeric($path) && ($id = intval($path))) {
// Fetch item by id (to check existence) and return id
list($ret, $entity) = GalleryCoreApi::loadEntitiesById($id);
$items[$path] = $ret ? FALSE : $id;
}
}
return $items[$path];
}
/**
* Function gallery_generate_url().
*/
......@@ -387,7 +414,7 @@ function gallery_item_details($id, $verbose = FALSE) {
* Function gallery_item_access().
*/
function gallery_item_access($id, $permission = 'core.view', $user = NULL) {
if (!_gallery_init(TRUE)) {
if (!_gallery_init(TRUE) || !is_numeric($id)) {
return FALSE;
}
// Check access permissions
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment