Skip to content

Commit 5a4e685

Browse files
committed
fix: corrected URL schemes
1 parent c5746e9 commit 5a4e685

File tree

6 files changed

+45
-50
lines changed

6 files changed

+45
-50
lines changed

phpmyfaq/src/phpMyFAQ/Administration/RatingData.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
use phpMyFAQ\Configuration;
2323
use phpMyFAQ\Database;
24-
use phpMyFAQ\Link;
24+
use phpMyFAQ\Link\Util\TitleSlugifier;
2525
use phpMyFAQ\Strings;
2626

2727
readonly class RatingData
@@ -116,22 +116,20 @@ private function mapRowToRating(object $row): array
116116
{
117117
$question = Strings::htmlspecialchars(trim((string) $row->question));
118118
$url = sprintf(
119-
'%sindex.php?action=faq&cat=%d&id=%d&artlang=%s',
119+
'%scontent/%d/%d/%s/%s.html',
120120
$this->configuration->getDefaultUrl(),
121121
$row->category_id,
122122
$row->id,
123123
$row->lang,
124+
TitleSlugifier::slug($question),
124125
);
125126

126-
$link = new Link($url, $this->configuration);
127-
$link->setTitle($question);
128-
129127
return [
130128
'id' => $row->id,
131129
'lang' => $row->lang,
132130
'category_id' => $row->category_id,
133131
'question' => $question,
134-
'url' => $link->toString(),
132+
'url' => $url,
135133
'number' => $row->num,
136134
'user' => $row->usr,
137135
];

phpmyfaq/src/phpMyFAQ/Export/Pdf/Wrapper.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
use Exception;
2525
use phpMyFAQ\Configuration;
2626
use phpMyFAQ\Date;
27-
use phpMyFAQ\Link;
27+
use phpMyFAQ\Link\Util\TitleSlugifier;
2828
use phpMyFAQ\Strings;
2929
use phpMyFAQ\Translation;
3030
use TCPDF;
@@ -421,30 +421,26 @@ public function Footer(): void
421421
if (!$this->enableBookmarks) {
422422
$this->SetY(-15);
423423
$this->SetFont($this->currentFont, style: '', size: 8);
424-
$baseUrl = 'index.php';
424+
$baseUrl = $this->config->getDefaultUrl() . 'content';
425425
if ($this->faq !== []) {
426-
$baseUrl .= '?action=faq&';
427-
$baseUrl .= 'cat=0';
428426
if (array_key_exists($this->category, $this->categories)) {
429-
$baseUrl .= 'cat=' . $this->categories[$this->category]['id'];
427+
$baseUrl .= '/' . $this->categories[$this->category]['id'];
430428
}
431429

432-
$baseUrl .= '&id=' . $this->faq['id'];
433-
$baseUrl .= '&artlang=' . $this->faq['lang'];
430+
$baseUrl .= '/' . $this->faq['id'];
431+
$baseUrl .= '/' . $this->faq['lang'];
432+
$baseUrl .= '/' . TitleSlugifier::slug($this->question) . '.html';
434433
}
435434

436-
$url = $this->config->getDefaultUrl() . $baseUrl;
437-
$link = new Link($url, $this->config);
438-
$link->setTitle($this->question);
439435
$this->Cell(
440436
w: 0,
441437
h: 10,
442-
txt: 'URL: ' . $link->toString(),
438+
txt: 'URL: ' . $baseUrl,
443439
border: 0,
444440
ln: 1,
445441
align: 'C',
446442
fill: false,
447-
link: $link->toString(),
443+
link: $baseUrl,
448444
);
449445
}
450446

phpmyfaq/src/phpMyFAQ/News.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
use Exception;
2424
use phpMyFAQ\Entity\NewsMessage;
25+
use phpMyFAQ\Link\Util\TitleSlugifier;
2526
use phpMyFAQ\News\NewsRepository;
2627
use phpMyFAQ\News\NewsRepositoryInterface;
2728
use stdClass;
@@ -64,11 +65,13 @@ public function getAll(bool $showArchive = false, bool $active = true): array
6465

6566
foreach ($this->newsRepository->getLatest($language, $active, $limit) as $row) {
6667
$entry = new stdClass();
67-
$link = '%sindex.php?action=news&newsid=%d&newslang=%s';
68-
$url = sprintf($link, $this->configuration->getDefaultUrl(), $row->id, $row->lang);
69-
$link = new Link($url, $this->configuration);
70-
$link->setTitle($row->header);
71-
$entry->url = $link->toString();
68+
$entry->url = sprintf(
69+
'%snews/%d/%s/%s.html',
70+
$this->configuration->getDefaultUrl(),
71+
$row->id,
72+
$row->lang,
73+
TitleSlugifier::slug($row->header),
74+
);
7275
$entry->header = $row->header;
7376
$entry->content = strip_tags((string) $row->artikel);
7477
$entry->date = $date->format($row->datum);
@@ -104,11 +107,13 @@ public function getLatestData(bool $showArchive = false, bool $active = true, bo
104107
}
105108

106109
foreach ($this->newsRepository->getLatest($language, $active, $limit) as $row) {
107-
// original conditional logic preserved implicitly by limit handling
108-
$link = '%sindex.php?action=news&newsid=%d&newslang=%s';
109-
$url = sprintf($link, $this->configuration->getDefaultUrl(), $row->id, $row->lang);
110-
$oLink = new Link($url, $this->configuration);
111-
$oLink->setTitle($row->header);
110+
$url = sprintf(
111+
'%snews/%d/%s/%s.html',
112+
$this->configuration->getDefaultUrl(),
113+
$row->id,
114+
$row->lang,
115+
TitleSlugifier::slug($row->header),
116+
);
112117
$item = [
113118
'id' => (int) $row->id,
114119
'lang' => $row->lang,
@@ -122,7 +127,7 @@ public function getLatestData(bool $showArchive = false, bool $active = true, bo
122127
'link' => $row->link,
123128
'linkTitle' => $row->linktitel,
124129
'target' => $row->target,
125-
'url' => $oLink->toString(),
130+
'url' => $url,
126131
];
127132
$news[] = $item;
128133
}

phpmyfaq/src/phpMyFAQ/Sitemap.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use League\CommonMark\CommonMarkConverter;
2424
use League\CommonMark\Exception\CommonMarkException;
2525
use phpMyFAQ\Database\Sqlite3;
26+
use phpMyFAQ\Link\Util\TitleSlugifier;
2627
use stdClass;
2728

2829
/**
@@ -130,14 +131,12 @@ public function getAllFirstLetters(): array
130131
$letter->letter = Strings::strtoupper($row->letters);
131132

132133
if (Strings::preg_match("/^\w+/iu", $letter->letter) !== 0) {
133-
$url = sprintf(
134-
'%sindex.php?action=sitemap&letter=%s&lang=%s',
134+
$letter->url = sprintf(
135+
'%ssitemap/%s/%s.html',
135136
$this->configuration->getDefaultUrl(),
136137
$letter->letter,
137138
$this->configuration->getLanguage()->getLanguage(),
138139
);
139-
$link = new Link($url, $this->configuration);
140-
$letter->url = $link->toString();
141140
}
142141

143142
$letters[] = $letter;
@@ -222,18 +221,15 @@ public function getFaqsFromLetter(string $letter = 'A'): array
222221
if ($oldId !== $row->id) {
223222
$faq = new stdClass();
224223
$faq->question = $row->thema;
225-
$url = sprintf(
226-
'%sindex.php?action=faq&cat=%d&id=%d&artlang=%s',
224+
$faq->url = sprintf(
225+
'%scontent/%d/%d/%s/%s.html',
227226
$this->configuration->getDefaultUrl(),
228227
$row->category_id,
229228
$row->id,
230229
$row->lang,
230+
TitleSlugifier::slug($row->thema),
231231
);
232232

233-
$link = new Link($url, $this->configuration);
234-
$link->setTitle($row->thema);
235-
$faq->url = $link->toString();
236-
237233
if ($this->configuration->get(item: 'main.enableMarkdownEditor')) {
238234
$answer = strip_tags($commonMarkConverter->convert($row->snap)->getContent());
239235
} else {

tests/phpMyFAQ/Administration/RatingDataTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function testGetAllReturnsSingleRating(): void
6868
$this->assertEquals('Test Question', $result[0]['question']);
6969
$this->assertEquals(4.5, $result[0]['number']);
7070
$this->assertEquals(10, $result[0]['user']);
71-
$this->assertStringContainsString('index.php?action=faq&cat=2&id=1&artlang=en', $result[0]['url']);
71+
$this->assertStringContainsString('http://example.com/content/2/1/en/test-question.html', $result[0]['url']);
7272
}
7373

7474
public function testGetAllReturnsMultipleRatings(): void
@@ -176,7 +176,7 @@ public function testGetAllGeneratesCorrectUrl(): void
176176
$result = $this->ratingData->getAll();
177177

178178
$this->assertCount(1, $result);
179-
$expectedUrl = 'https://faq.example.com/index.php?action=faq&cat=15&id=42&artlang=de';
179+
$expectedUrl = 'https://faq.example.com/content/15/42/de/german-question.html';
180180
$this->assertStringContainsString($expectedUrl, $result[0]['url']);
181181
}
182182

@@ -185,7 +185,7 @@ public function testGetAllVerifiesQueryStructure(): void
185185
// Mock configuration default URL
186186
$this->mockConfiguration->method('getDefaultUrl')->willReturn('http://example.com/');
187187

188-
// Verify that query method is called with a SQL string containing expected elements
188+
// Verify that a query method is called with a SQL string containing expected elements
189189
$this->mockDb
190190
->expects($this->once())
191191
->method('query')
@@ -217,8 +217,8 @@ public function testGetAllHandlesNumericTypes(): void
217217
$mockResult->lang = 'en';
218218
$mockResult->category_id = 8;
219219
$mockResult->question = 'Numeric Test Question';
220-
$mockResult->num = 2.75; // float rating
221-
$mockResult->usr = 12; // integer user count
220+
$mockResult->num = 2.75;
221+
$mockResult->usr = 12;
222222

223223
$this->mockDb->method('query')->willReturn(true);
224224
$this->mockDb->method('fetchObject')->willReturn($mockResult, false);

tests/phpMyFAQ/PaginationTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ public function testRender(): void
1313
$pagination = new Pagination([
1414
'total' => 30,
1515
'perPage' => 10,
16-
'baseUrl' => 'http://example.com?action=foo',
16+
'baseUrl' => 'http://example.com/foo',
1717
]);
1818

1919
$expectedOutput =
2020
'<ul class="pagination justify-content-center">'
2121
. '<li class="page-item active">'
22-
. '<a class="page-link" href="http://example.com?action=foo&page=1">1</a>'
22+
. '<a class="page-link" href="http://example.com/foo?page=1">1</a>'
2323
. '</li>&nbsp;&nbsp;<li class="page-item">'
24-
. '<a class="page-link" href="http://example.com?action=foo&page=2">2</a>'
24+
. '<a class="page-link" href="http://example.com/foo?page=2">2</a>'
2525
. '</li>&nbsp;&nbsp;<li class="page-item">'
26-
. '<a class="page-link" href="http://example.com?action=foo&page=3">3</a>'
26+
. '<a class="page-link" href="http://example.com/foo?page=3">3</a>'
2727
. '</li>&nbsp;&nbsp;<li class="page-item">'
28-
. '<a class="page-link" href="http://example.com?action=foo&page=2">&rarr;</a>'
28+
. '<a class="page-link" href="http://example.com/foo?page=2">&rarr;</a>'
2929
. '</li>&nbsp;&nbsp;<li class="page-item">'
30-
. '<a class="page-link" href="http://example.com?action=foo&page=3">&#8677;</a>'
30+
. '<a class="page-link" href="http://example.com/foo?page=3">&#8677;</a>'
3131
. '</li></ul>';
3232

3333
$this->assertEquals($expectedOutput, $pagination->render());

0 commit comments

Comments
 (0)