From a641b9eb08650272b3bf8f9e9db92ffd3e529d1f Mon Sep 17 00:00:00 2001 From: plegall Date: Thu, 17 Dec 2020 16:31:51 +0100 Subject: [PATCH] fixes #1266 improve url parsing after bugs introduced for #626 * /categories/123-album/start-10 now works * /categories/permalink1/permalink2/start-20 now works (each permalink can contain several "/") --- include/functions_url.inc.php | 39 ++++++++++++++++++++++++++++++----- include/section_init.inc.php | 2 +- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/include/functions_url.inc.php b/include/functions_url.inc.php index 0a27d03d3..676651b51 100644 --- a/include/functions_url.inc.php +++ b/include/functions_url.inc.php @@ -353,10 +353,19 @@ function make_section_in_url($params) { foreach ($params['combined_categories'] as $category) { - $section_string.= '/'.$category['id']; - if ( $conf['category_url_style']=='id-name' ) + $section_string.= '/'; + + if ( empty($category['permalink']) ) { - $section_string.= '-'.str2url($category['name']); + $section_string.= $category['id']; + if ( $conf['category_url_style']=='id-name' ) + { + $section_string.= '-'.str2url($category['name']); + } + } + else + { + $section_string.= $category['permalink']; } } } @@ -434,9 +443,21 @@ function parse_section_url( $tokens, &$next_token) $next_token++; $i = $next_token; + $loop_counter = 0; while (isset($tokens[$next_token])) { + if ($loop_counter++ > count($tokens)+10){die('infinite loop?');} + + if ( + strpos($tokens[$next_token], 'created-')===0 + or strpos($tokens[$next_token], 'posted-')===0 + or strpos($tokens[$next_token], 'start-')===0 + ) + { + break; + } + if (preg_match('/^(\d+)(?:-(.+))?$/', $tokens[$next_token], $matches)) { if ( isset($matches[2]) ) @@ -482,8 +503,16 @@ function parse_section_url( $tokens, &$next_token) if ( isset($cat_id) ) { $next_token += $perma_index+1; - $page['category'] = $cat_id; - $page['hit_by']['cat_permalink'] = $maybe_permalinks[$perma_index]; + + if (!isset($page['category'])) + { + $page['category'] = $cat_id; + $page['hit_by']['cat_permalink'] = $maybe_permalinks[$perma_index]; + } + else + { + $page['combined_categories'][] = $cat_id; + } } else { diff --git a/include/section_init.inc.php b/include/section_init.inc.php index db4c30460..60f439268 100644 --- a/include/section_init.inc.php +++ b/include/section_init.inc.php @@ -614,7 +614,7 @@ if ( $filter['enabled'] ) } // see if we need a redirect because of a permalink -if ( 'categories'==$page['section'] and isset($page['category']) ) +if ( 'categories'==$page['section'] and isset($page['category']) and !isset($page['combined_categories'])) { $need_redirect=false; if ( empty($page['category']['permalink']) )