fixes #2092 redesigned handling of return to gallery after photo edit

* instead of using the provided cat_id in the URL parameters, registers the "context" of the last 10 photos viewed. Be it an album, a search, a tag...
* maybe not the cleanest way to do it (because we do not rebuild the url string) but simple and straightforward
This commit is contained in:
plegall
2025-11-03 21:45:27 +01:00
parent 8fb8f9f8f1
commit a04c93cf76
4 changed files with 78 additions and 71 deletions

View File

@@ -19,7 +19,6 @@ include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
check_status(ACCESS_ADMINISTRATOR); check_status(ACCESS_ADMINISTRATOR);
check_input_parameter('image_id', $_GET, false, PATTERN_ID); check_input_parameter('image_id', $_GET, false, PATTERN_ID);
check_input_parameter('cat_id', $_GET, false, PATTERN_ID);
// retrieving direct information about picture. This may have been already // retrieving direct information about picture. This may have been already
// done on admin/photo.php but this page can also be accessed without // done on admin/photo.php but this page can also be accessed without
@@ -54,37 +53,11 @@ if (isset($_GET['delete']))
// 2. else use the first reachable linked category // 2. else use the first reachable linked category
// 3. redirect to gallery root // 3. redirect to gallery root
if (isset($_GET['cat_id']) and !empty($_GET['cat_id'])) if ($custom_context = get_edit_context($_GET['image_id']))
{ {
redirect( // considering we have a context available, we fake one to build the url
make_index_url( // and we replace it with the context found in the session for this image_id
array( redirect(str_replace('list/1,2', $custom_context, make_index_url(array('list'=>array(1,2)))));
'category' => get_cat_info($_GET['cat_id'])
)
)
);
}
$query = '
SELECT category_id
FROM '.IMAGE_CATEGORY_TABLE.'
WHERE image_id = '.$_GET['image_id'].'
;';
$authorizeds = array_diff(
array_from_query($query, 'category_id'),
explode(',', calculate_permissions($user['id'], $user['status']))
);
foreach ($authorizeds as $category_id)
{
redirect(
make_index_url(
array(
'category' => get_cat_info($category_id)
)
)
);
} }
redirect(make_index_url()); redirect(make_index_url());
@@ -230,7 +203,6 @@ $template->set_filenames(
); );
$admin_url_start = $admin_photo_base_url.'-properties'; $admin_url_start = $admin_photo_base_url.'-properties';
$admin_url_start.= isset($_GET['cat_id']) ? '&cat_id='.$_GET['cat_id'] : '';
$src_image = new SrcImage($row); $src_image = new SrcImage($row);
@@ -396,42 +368,34 @@ $template->assign('related_categories_ids', $related_categories_ids);
// jump to link // jump to link
// //
// 1. find all linked categories that are reachable for the current user. // 1. if an edit_context is available, we use it (without checking permissions)
// 2. if a category is available in the URL, use it if reachable // 2. else if user level is higher than image level, randomly find an authorized category
// 3. if URL category not available or reachable, use the first reachable // 3. else no jumpto link
// linked category
// 4. if no category reachable, no jumpto link
// 5. if level is too high for current user, no jumpto link
$query = ' if ($custom_context = get_edit_context($_GET['image_id']))
{
$template->assign('U_JUMPTO', make_picture_url(array('image_id' => $_GET['image_id'])).'/'.$custom_context);
}
elseif ($user['level'] >= $page['image']['level'])
{
$query = '
SELECT category_id SELECT category_id
FROM '.IMAGE_CATEGORY_TABLE.' FROM '.IMAGE_CATEGORY_TABLE.'
WHERE image_id = '.$_GET['image_id'].' WHERE image_id = '.$_GET['image_id'].'
;'; ;';
$authorizeds = array_diff( $authorizeds = array_diff(
array_from_query($query, 'category_id'), array_from_query($query, 'category_id'),
explode( explode(
',', ',',
calculate_permissions($user['id'], $user['status']) calculate_permissions($user['id'], $user['status'])
)
);
if (isset($_GET['cat_id'])
and in_array($_GET['cat_id'], $authorizeds))
{
$url_img = make_picture_url(
array(
'image_id' => $_GET['image_id'],
'image_file' => $image_file,
'category' => $cache['cat_names'][ $_GET['cat_id'] ],
) )
); );
}
else if (count($authorizeds) > 0)
{
foreach ($authorizeds as $category)
{ {
$category = $authorizeds[array_rand($authorizeds)];
$url_img = make_picture_url( $url_img = make_picture_url(
array( array(
'image_id' => $_GET['image_id'], 'image_id' => $_GET['image_id'],
@@ -439,13 +403,9 @@ else
'category' => $cache['cat_names'][ $category ], 'category' => $cache['cat_names'][ $category ],
) )
); );
break;
}
}
if (isset($url_img) and $user['level'] >= $page['image']['level']) $template->assign('U_JUMPTO', $url_img);
{ }
$template->assign( 'U_JUMPTO', $url_img );
} }
// associate to albums // associate to albums

View File

@@ -2743,4 +2743,52 @@ function verify_user_code($secret, $code)
require_once(PHPWG_ROOT_PATH . 'include/totp.class.php'); require_once(PHPWG_ROOT_PATH . 'include/totp.class.php');
return PwgTOTP::verifyCode($code, $secret, min($conf['password_reset_code_duration'], 900), 1); return PwgTOTP::verifyCode($code, $secret, min($conf['password_reset_code_duration'], 900), 1);
} }
/**
* Register in the user session, the "context" of the last 10 viewed images.
*
* @since 16
*/
function save_edit_context()
{
global $page;
if (!is_admin() or !isset($page['section_url']) or !isset($page['image_id']))
{
return;
}
$_SESSION['edit_context'] ??= [];
// the $page['section_url'] is set in the include/section_init script. It
// contains the URL describing the "context" of the photo. Examples:
//
// * /198/list/2,69,198
// * /198/category/18801-yes_man
// * /198/tags/27-city_nantes/28-city_rennes
// * /198/search/psk-20251103-lqCHHAFSZY/posted-monthly-list-2025-3
//
// same photo #198 in different context. We need it to propose the best
// return page on the photo edit page in the administration.
// let's add the item on top of previous registered values and keep only the last 10 values
$_SESSION['edit_context'] = array_slice(array($page['image_id'] => $page['section_url']) + $_SESSION['edit_context'], 0, 10, true);
}
/**
* Returns the "context" of the requested image.
*
* @since 16
* @param int $image_id
* @return string|bool
*/
function get_edit_context($image_id)
{
if (!isset($_SESSION['edit_context'][$image_id]))
{
return false;
}
return preg_replace('/^\/'.$image_id.'\//', '', $_SESSION['edit_context'][$image_id]);
}
?> ?>

View File

@@ -59,6 +59,8 @@ if ( strncmp($page['root_path'], './', 2) == 0 )
$page['root_path'] = substr($page['root_path'], 2); $page['root_path'] = substr($page['root_path'], 2);
} }
$page['section_url'] = $rewritten;
// deleting first "/" if displayed // deleting first "/" if displayed
$tokens = explode('/', ltrim($rewritten, '/') ); $tokens = explode('/', ltrim($rewritten, '/') );
// $tokens = array( // $tokens = array(

View File

@@ -11,6 +11,8 @@ include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
include(PHPWG_ROOT_PATH.'include/section_init.inc.php'); include(PHPWG_ROOT_PATH.'include/section_init.inc.php');
include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php'); include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
save_edit_context();
// Check Access and exit when user status is not ok // Check Access and exit when user status is not ok
check_status(ACCESS_GUEST); check_status(ACCESS_GUEST);
@@ -781,12 +783,7 @@ if (is_admin())
if ($conf['picture_edit_icon']) if ($conf['picture_edit_icon'])
{ {
$url_admin = $template->assign('U_PHOTO_ADMIN', get_root_url().'admin.php?page=photo-'.$page['image_id']);
get_root_url().'admin.php?page=photo-'.$page['image_id']
.(isset($page['category']) ? '&cat_id='.$page['category']['id'] : '')
;
$template->assign('U_PHOTO_ADMIN', $url_admin);
} }
if ($conf['picture_caddie_icon']) if ($conf['picture_caddie_icon'])