WebsiteBaker Support (2.13.x) > General Help & Support
how to auto rewrite links inside custom php file
(1/1)
crnogorac081:
Hello,
What I am trying to do is to create live ajax search , and I want to create links for items.
So far the links are created inside my custom class:
--- Code: ---$sLink = '/something/something-else'; // from database
$sOut = str_replace("//", "/", $this->oReg->PagesDir.$sLink.$this->oReg->PageExtension);
--- End code ---
This is later used inside ajax.php file, and content is sent to site.
What my problem is , that if ShortUrl is enabled , I would like to automaticly rewrite links (that removes /pages/ and .php ).
Is there a code inside wb for this ? And how can I detect if ShorUrl is enabled or not (I could not find in oReg, oRequest, oApp) ?
So far I see two solutions.
1. Where links are created in my custom class, to use method page_link() from wb abstract class, but since wb class is abstract, I cannot use it inside my custom class (is there a way to use method page_link() ?)
2. or in ajax.php I have output that I want to display inside string ($sOutput), where I could apply filter on my content, that I saw in output_filter\Filters\ShortUrl Filter class file. Is there an example how to apply filter to custom string or to use inside custom class method ?
dbs:
You could check for short.php ?
--- Code: ---if (!is_readable(WB_URL.'/short.php')) {
$sOut = str_replace("//", "/", $this->oReg->PagesDir.$sLink.$this->oReg->PageExtension);
} else {
$sOut = ...
}
--- End code ---
crnogorac081:
Here is solution how to apply ShortUrl or any other filter in Ajax file.
--- Code: ---// at the top of page
use addon\output_filter\Filters\ShortUrl\{Filter};
....
// My content that goes to page
$sMyContent = '.....';
// Filter Short
$aFilterSettings = [];
$sSql = "SELECT `value` FROM ".TABLE_PREFIX."mod_output_filter WHERE `name` = 'ShortUrl' ";
$aFilterSettings['ShortUrl'] = ($oDb->get_one($sSql) ?? 0);
$cFilter = new Filter($oReg, $aFilterSettings);
// Apply filter
$sMyContent = $cFilter->execute($sMyContent);
--- End code ---
I hope it will help somebody
Navigation
[0] Message Index
Go to full version