diff --git a/admin/picture_modify.php b/admin/picture_modify.php index 4485ff921..6468ecaf8 100644 --- a/admin/picture_modify.php +++ b/admin/picture_modify.php @@ -19,7 +19,6 @@ include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); check_status(ACCESS_ADMINISTRATOR); 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 // 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 // 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( - make_index_url( - array( - '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) - ) - ) - ); + // considering we have a context available, we fake one to build the url + // and we replace it with the context found in the session for this image_id + redirect(str_replace('list/1,2', $custom_context, make_index_url(array('list'=>array(1,2))))); } redirect(make_index_url()); @@ -230,7 +203,6 @@ $template->set_filenames( ); $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); @@ -396,42 +368,34 @@ $template->assign('related_categories_ids', $related_categories_ids); // jump to link // -// 1. find all linked categories that are reachable for the current user. -// 2. if a category is available in the URL, use it if reachable -// 3. if URL category not available or reachable, use the first reachable -// linked category -// 4. if no category reachable, no jumpto link -// 5. if level is too high for current user, no jumpto link +// 1. if an edit_context is available, we use it (without checking permissions) +// 2. else if user level is higher than image level, randomly find an authorized category +// 3. else 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 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']) - ) - ); - -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'] ], + $authorizeds = array_diff( + array_from_query($query, 'category_id'), + explode( + ',', + calculate_permissions($user['id'], $user['status']) ) ); -} -else -{ - foreach ($authorizeds as $category) + + if (count($authorizeds) > 0) { + $category = $authorizeds[array_rand($authorizeds)]; + $url_img = make_picture_url( array( 'image_id' => $_GET['image_id'], @@ -439,13 +403,9 @@ else '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 diff --git a/include/functions_user.inc.php b/include/functions_user.inc.php index 82ffcf52e..394c095ba 100644 --- a/include/functions_user.inc.php +++ b/include/functions_user.inc.php @@ -2743,4 +2743,52 @@ function verify_user_code($secret, $code) require_once(PHPWG_ROOT_PATH . 'include/totp.class.php'); 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]); +} ?> diff --git a/include/section_init.inc.php b/include/section_init.inc.php index 2f751864e..82b0b1bfa 100644 --- a/include/section_init.inc.php +++ b/include/section_init.inc.php @@ -59,6 +59,8 @@ if ( strncmp($page['root_path'], './', 2) == 0 ) $page['root_path'] = substr($page['root_path'], 2); } +$page['section_url'] = $rewritten; + // deleting first "/" if displayed $tokens = explode('/', ltrim($rewritten, '/') ); // $tokens = array( diff --git a/picture.php b/picture.php index 115c72048..067ee6d48 100644 --- a/picture.php +++ b/picture.php @@ -11,6 +11,8 @@ include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); include(PHPWG_ROOT_PATH.'include/section_init.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_status(ACCESS_GUEST); @@ -781,12 +783,7 @@ if (is_admin()) if ($conf['picture_edit_icon']) { - $url_admin = - 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); + $template->assign('U_PHOTO_ADMIN', get_root_url().'admin.php?page=photo-'.$page['image_id']); } if ($conf['picture_caddie_icon'])