2222
2323use Exception ;
2424use phpMyFAQ \Entity \NewsMessage ;
25+ use phpMyFAQ \Link \Util \TitleSlugifier ;
2526use phpMyFAQ \News \NewsRepository ;
2627use phpMyFAQ \News \NewsRepositoryInterface ;
2728use 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 }
0 commit comments