getk2 / k2

K2 - the powerful content extension for Joomla
https://getk2.org
GNU General Public License v3.0
136 stars 95 forks source link

Use the category ID in the URL - is not honoured and breaks routing #547

Open shoulders opened 2 years ago

shoulders commented 2 years ago

Joomla: 3.10.4 K2: 2.10.3

How I found this.

After I upgraded to K2 v2.10.3 when i searched for the article Configure OpenWRT on a BT Home Hub 5 / Plusnet One Router as a Secure WiFi Client it found the article with the link. (p.s. just search for Secure WiFi Client)

https://quantumwarp.com/kb/articles/37-kb/2-hardware/dsl-broadband/950-configure-openwrt-on-a-bt-home-hub-5-plusnet-one-router-as-a-secure-wifi-client

But when I click on the link I am redirected to that page but I am showing the content from the article Bios Limitations which has an article ID of 2.

If you look in the first link you can see that the hardware category also has an ID of 2. So I presumed that there was a (int) typecasting going on.

Router

My attention has now turned to the router.php as I have check those articles are correctly present and were working in the previous version of K2.

In settings the option Use the category ID in the URL was enabled image but if you referer back to the first URL the parent category is shown without an ID on the slug.

in the component router this line is responsible for stripping the item ID form the slug https://github.com/getk2/k2/blob/2f47c2a44418d934cfa2ff5de78ccc134114a1b6/components/com_k2/router.php#L133

if this is replaced with the following code it seems to fix routing

$slug = $segments[0];

Further notes

The router slugs between the modes of Use the category ID in the URL are not the same if you ignore the category ID aspect

Cat ID On: https://localhost/platforms/joomla3/kb/articles/25-dsl-broadband/configure-openwrt-on-a-bt-home-hub-5-plusnet-one-router-as-a-secure-wifi-client
CatID Off: https://localhost/platforms/joomla3/kb/articles/kb/hardware/dsl-broadband/configure-openwrt-on-a-bt-home-hub-5-plusnet-one-router-as-a-secure-wifi-client

Will be a new router in K2 for Joomla 4, if not I might need to rework this one?