WebsiteBaker Community Forum

WebsiteBaker Support (2.13.x) => General Help & Support => Topic started by: crnogorac081 on July 19, 2024, 03:04:19 PM

Title: how to auto rewrite links inside custom php file
Post by: crnogorac081 on July 19, 2024, 03:04:19 PM
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: [Select]
$sLink = '/something/something-else'; // from database

$sOut = str_replace("//", "/", $this->oReg->PagesDir.$sLink.$this->oReg->PageExtension);
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 ?
Title: Re: how to auto rewrite links inside custom php file
Post by: dbs on July 19, 2024, 03:28:09 PM
You could check for short.php ?

Code: [Select]
if (!is_readable(WB_URL.'/short.php')) { 
   $sOut = str_replace("//", "/", $this->oReg->PagesDir.$sLink.$this->oReg->PageExtension);
} else {
   $sOut = ...
}
Title: Re: apply ShortUrl (or any filter) in Ajax file
Post by: crnogorac081 on July 22, 2024, 12:49:25 PM
Here is solution how to apply ShortUrl or any other filter in Ajax file.

Code: [Select]
// 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);

I hope it will help somebody