Skip to content

Commit 16e8237

Browse files
committed
refactor: migrated tag routes (#3834)
1 parent 1a88e30 commit 16e8237

File tree

6 files changed

+39
-39
lines changed

6 files changed

+39
-39
lines changed

.docker/frankenphp/Caddyfile

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,6 @@
3333
rewrite /sitemap.gz /index.php
3434
rewrite /sitemap.xml.gz /index.php
3535

36-
# Tags pages with page count
37-
@tags_page path_regexp tags_page ^/tags/([0-9]+)/([0-9]+)/(.+)\.html?$
38-
rewrite @tags_page /index.php?action=search&tagging_id={re.tags_page.1}&seite={re.tags_page.2}
39-
40-
# Tags pages
41-
@tags path_regexp tags ^/tags/([0-9]+)/([^/]+)\.html?$
42-
rewrite @tags /index.php?action=search&tagging_id={re.tags.1}
43-
4436
# Setup and update pages
4537
@setup path /setup*
4638
rewrite @setup /setup/index.php
@@ -107,14 +99,6 @@
10799
rewrite /sitemap.gz /index.php
108100
rewrite /sitemap.xml.gz /index.php
109101

110-
# Tags pages with page count
111-
@tags_page path_regexp tags_page ^/tags/([0-9]+)/([0-9]+)/(.+)\.html?$
112-
rewrite @tags_page /index.php?action=search&tagging_id={re.tags_page.1}&seite={re.tags_page.2}
113-
114-
# Tags pages
115-
@tags path_regexp tags ^/tags/([0-9]+)/([^/]+)\.html?$
116-
rewrite @tags /index.php?action=search&tagging_id={re.tags.1}
117-
118102
@setup path /setup*
119103
rewrite @setup /setup/index.php
120104

.docker/nginx/default.conf

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,6 @@ server {
8282
rewrite ^/sitemap\.gz$ /index.php last;
8383
rewrite ^/sitemap\.xml\.gz$ /index.php last;
8484

85-
# PMF tags page with page count
86-
rewrite ^/tags/([0-9]+)/([0-9]+)/(.+)\.htm(l?)$ /index.php?action=search&tagging_id=$1&seite=$2 last;
87-
88-
# PMF tags page
89-
rewrite ^/tags/([0-9]+)/([^\/]+)\.htm(l?)$ /index.php?action=search&tagging_id=$1 last;
90-
9185
# Administration API
9286
rewrite ^/admin/api/(.*)$ /admin/api/index.php last;
9387

@@ -222,12 +216,6 @@ server {
222216
rewrite ^/sitemap\.gz$ /index.php last;
223217
rewrite ^/sitemap\.xml\.gz$ /index.php last;
224218

225-
# PMF tags page with page count
226-
rewrite ^/tags/([0-9]+)/([0-9]+)/(.+)\.htm(l?)$ /index.php?action=search&tagging_id=$1&seite=$2 last;
227-
228-
# PMF tags page
229-
rewrite ^/tags/([0-9]+)/([^\/]+)\.htm(l?)$ /index.php?action=search&tagging_id=$1 last;
230-
231219
# Administration API
232220
rewrite ^/admin/api/(.*)$ /admin/api/index.php last;
233221

nginx.conf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,6 @@ server {
9393
rewrite ^/sitemap\.gz$ /index.php last;
9494
rewrite ^/sitemap\.xml\.gz$ /index.php last;
9595

96-
# PMF tags page with page count
97-
rewrite ^/tags/([0-9]+)/([0-9]+)/(.+)\.htm(l?)$ /index.php?action=search&tagging_id=$1&seite=$2 last;
98-
99-
# PMF tags page
100-
rewrite ^/tags/([0-9]+)/([^\/]+)\.htm(l?)$ /index.php?action=search&tagging_id=$1 last;
101-
10296
# Administration API
10397
rewrite ^/admin/api/(.*)$ /admin/api/index.php last;
10498

phpmyfaq/.htaccess

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,6 @@ Header set Access-Control-Allow-Headers "Content-Type, Authorization"
108108
RewriteRule ^sitemap.xml$ index.php [L,QSA]
109109
RewriteRule ^sitemap.gz$ index.php [L,QSA]
110110
RewriteRule ^sitemap.xml.gz$ index.php [L,QSA]
111-
# phpMyFAQ tags page with page count
112-
RewriteRule ^tags/([0-9]+)/([0-9]+)/(.+)\.htm(l?)$ index.php?action=search&tagging_id=$1&seite=$2 [L,QSA]
113-
# phpMyFAQ tags page
114-
RewriteRule ^tags/([0-9]+)/([^/]+)\.htm(l?)$ index.php?action=search&tagging_id=$1 [L,QSA]
115111
# Administration API
116112
RewriteRule ^admin/api/(.*) admin/api/index.php [L,QSA]
117113
# Administration pages

phpmyfaq/src/phpMyFAQ/Controller/Frontend/SearchController.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
namespace phpMyFAQ\Controller\Frontend;
2121

2222
use Exception;
23+
use League\CommonMark\Exception\CommonMarkException;
2324
use phpMyFAQ\Filter;
2425
use phpMyFAQ\Language\Plurals;
2526
use phpMyFAQ\Search\SearchService;
@@ -36,10 +37,37 @@
3637
final class SearchController extends AbstractFrontController
3738
{
3839
/**
39-
* Displays search results for fulltext or tag-based search.
40+
* Redirects tag URLs with pagination to search
41+
*
42+
* @throws Exception
43+
*/
44+
#[Route(path: '/tags/{tagId}/{page}/{slug}.html', name: 'public.tags.paginated', methods: ['GET'])]
45+
public function tagsPaginated(Request $request): Response
46+
{
47+
$tagId = Filter::filterVar($request->attributes->get('tagId'), FILTER_VALIDATE_INT, 0);
48+
$page = Filter::filterVar($request->attributes->get('page'), FILTER_VALIDATE_INT, 1);
49+
50+
return new RedirectResponse(sprintf('/search.html?tagging_id=%d&seite=%d', $tagId, $page));
51+
}
52+
53+
/**
54+
* Redirects tag URLs to search
4055
*
4156
* @throws Exception
4257
*/
58+
#[Route(path: '/tags/{tagId}/{slug}.html', name: 'public.tags', methods: ['GET'])]
59+
public function tags(Request $request): Response
60+
{
61+
$tagId = Filter::filterVar($request->attributes->get('tagId'), FILTER_VALIDATE_INT, 0);
62+
63+
return new RedirectResponse(sprintf('/search.html?tagging_id=%d', $tagId));
64+
}
65+
66+
/**
67+
* Displays search results for fulltext or tag-based search.
68+
*
69+
* @throws Exception|CommonMarkException
70+
*/
4371
#[Route(path: '/search.html', name: 'public.search', methods: ['GET'])]
4472
public function index(Request $request): Response
4573
{

phpmyfaq/src/public-routes.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,16 @@
159159
'controller' => [SearchController::class, 'index'],
160160
'methods' => 'GET',
161161
],
162+
'public.tags.paginated' => [
163+
'path' => '/tags/{tagId}/{page}/{slug}.html',
164+
'controller' => [SearchController::class, 'tagsPaginated'],
165+
'methods' => 'GET',
166+
],
167+
'public.tags' => [
168+
'path' => '/tags/{tagId}/{slug}.html',
169+
'controller' => [SearchController::class, 'tags'],
170+
'methods' => 'GET',
171+
],
162172
'public.user.register' => [
163173
'path' => '/user/register',
164174
'controller' => [UserController::class, 'register'],

0 commit comments

Comments
 (0)