• Welcome to WebsiteBaker Community Forum. Please log in or sign up.
Welcome, Guest
News
Support WebsiteBaker
Your donations will help to:
PayPal
  • Pay for our dedicated server
  • Pay for domain registration
  • and much more!
You can donate by clicking on the button below.

how to auto rewrite links inside custom php file

Started by crnogorac081, July 19, 2024, 03:04:19 PM  ( Read 11,778 times )

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:

$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 ?
    Web developer

    dbs

    You could check for short.php ?

    if (!is_readable(WB_URL.'/short.php')) {  
     
    $sOut = str_replace("//", "/", $this->oReg->PagesDir.$sLink.$this->oReg->PageExtension);
    } else {
     
    $sOut = ...
    }

      crnogorac081

      Here is solution how to apply ShortUrl or any other filter in Ajax file.

      // 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
        Web developer

        \n\n