Dear forum visitors, if the support forum is not available, please try again a few minutes later. Thanks!
QuoteHowever, 4SEF is not going to be able to ADD the category. This would require knowing how JDownloads stores categories and being able to identify the category an item belongs to (plus read that category title from the database).
I'd suggest talking to the JDownloads developer here: if you provide them this code, they should be able to modify it to provide the category where it's missing.
Also, they should be able to add the category in the non-sef URL, which may solve the issue from the start.
<?php
/**
* 4SEF hooks file
*
* You can use 2 variables to access 4SEO content:
*
* $factory: access variables
* $hooks: add handlers
*/
use Weeblr\Wblib\Forsef\Wb;
// no direct access
defined('WBLIB_EXEC') || die;
/**
* Filter the built URL pair (sef + nonSef) object just before it's stored to the database. Pagination and suffix has been attached
* but dynamic variables are not present as they are not stored to DB. This currently includes:
*
* - /feed/rss and /feed/atom suffixes
* - print suffix
*
* @version 1.0.1
* @date 2023-11-08 16:43:24
*
* @api forsef
* @package 4SEF\filter\build
* @var forsef_before_store_url
* @since 1.0.0
*
* @param Data\Urlpair $urlPair
* @param Uri\Uri $uriToBuild
* @param Uri\Uri $platformUri
*
* @return Data\Urlpair $urlPair
*
*/
function wblTranformSefUrlPath($originalPath, $catid, $id)
{
// separate into segments at each / sign
$urlSegments = explode(
'/',
$originalPath
);
// drop the leading segment, the menu item: download
array_shift($urlSegments);
// put back together the remaining segment
$modifiedPath = implode('/', $urlSegments);
// remove the category id from the beginning of the string
$modifiedPath = Wb\lTrim(
$modifiedPath,
$catid . '-'
);
// remove the download id from the beginning of the string
if ($id)
{
$modifiedPath = str_replace(
'/' . $id . '-',
'/',
$modifiedPath
);
}
return $modifiedPath;
}
$hooks->add(
'forsef_before_store_url',
function ($urlPair, $uriToBuild, $platformUri) {
$option = $uriToBuild->getVar('option');
$view = $uriToBuild->getVar('view');
$id = (int)$uriToBuild->getVar('id');
$catid = (int)$uriToBuild->getVar('catid');
if ('com_jdownloads' !== $option)
{
return $urlPair;
}
if (!in_array(
$view,
[
'download',
'category'
]
)
)
{
return $urlPair;
}
// the SEF as built by 4SEF: download/category/download-name
$modifiedSef = wblTranformSefUrlPath($urlPair->get('sef'), $catid, $id);
$modifiedPath = wblTranformSefUrlPath($urlPair->get('base_path'), $catid, $id);
// set the modified SEF into the URL pair
$urlPair->set(
'sef',
$modifiedSef
);
$urlPair->set(
'base_path',
$modifiedPath
);
return $urlPair;
}
);