WebsiteBaker Logo
  • *
  • Templates
  • Help
  • Add-ons
  • Download
  • Home
*
Welcome, Guest. Please login or register.

Login with username, password and session length
 

News


WebsiteBaker 2.13.6 is now available!


Will it continue with WB? It goes on! | Geht es mit WB weiter? Es geht weiter!
https://forum.websitebaker.org/index.php/topic,32340.msg226702.html#msg226702


The forum email address board@websitebaker.org is working again
https://forum.websitebaker.org/index.php/topic,32358.0.html


R.I.P Dietmar (luisehahne) and thank you for all your valuable work for WB
https://forum.websitebaker.org/index.php/topic,32355.0.html


* Support WebsiteBaker


  • Home
  • Help
  • Search
  • Login
  • Register

  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.13.x) »
  • General Help & Support »
  • how to auto rewrite links inside custom php file
  • Print
Pages: [1]   Go Down

Author Topic: how to auto rewrite links inside custom php file  (Read 6140 times)

Offline crnogorac081

  • Posts: 2161
  • Gender: Male
how to auto rewrite links inside custom php file
« 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 ?
« Last Edit: July 19, 2024, 03:12:30 PM by crnogorac081 »
Logged
Web developer

Offline dbs

  • Betatester
  • **
  • Posts: 8914
  • Gender: Male
  • tioz4ever
    • WebsiteBaker - jQuery-Plugins - Module - Droplets - Tests
Re: how to auto rewrite links inside custom php file
« Reply #1 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 = ...
}
Logged
https://onkel-franky.de

Offline crnogorac081

  • Posts: 2161
  • Gender: Male
Re: apply ShortUrl (or any filter) in Ajax file
« Reply #2 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
Logged
Web developer

  • Print
Pages: [1]   Go Up
  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.13.x) »
  • General Help & Support »
  • how to auto rewrite links inside custom php file
 

  • SMF 2.0.19 | SMF © 2017, Simple Machines
  • XHTML
  • RSS
  • WAP2