Hello my friend,
I'm experimenting with esi:include (https://www.xxxx.com/products/features/edge-side-includes) to serve dynamic information in cached pages.
For example, cache the whole page except the username.
So I'm using Litespeed ESI Includes like this:
This calls a file that has a function that returns this:
$link = '/index.php?option=com_contact&Itemid=562&id=' . $contact_id . '&lang=en&view=contact';
echo '' . $name . '';
Now as you can see it calls for a link in the non-sef format of course.
Normally, sh404sef would convert this to SEF.
However, esi:includes are added to the page AFTER the pages is rendered, so sh404sef never gets to the code. So the url remains non sef. This is expected and I understand it.
But my question is this: Is there any way I can trigger in my function the code from sh404sef to convert the link from nonsef to the sh404sef version?
So in my function I have:
$link = '/index.php?option=com_contact&Itemid=562&id=' . $contact_id . '&lang=en&view=contact';
Is there anything I can do to do something like:
$sef_link = callSomeMagicsh404sefFunction($link) ?
So I can then output the $sef_link?
Let me know!
Thanks
Best,
Andy
Last post
4 hours 8 min ago
Posts last week
141
Average response time last week
4 hours 42 min
All time posts
67772
All time tickets
10472
All time avg. posts per day
21
Helpdesk is open from Monday through Friday CET
Please create an (free) account to post any question in the support area.
Please check the development versions area. Look at the changelog, maybe your specific problem has been resolved already!
All tickets are private and they cannot be viewed by anyone. We have made public only a few tickets that we found helpful, after removing private information from them.
#7145 – SEF URLS with esi:include?
Posted in ‘sh404SEF’
This is a public ticket. Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.
TheSDHotel
wb_weeblr
Hi Andy,
First comment:
Now even without that, conversion cannot be done of course because you're loading directly that PHP file which means Joomla itself never gets loaded at all and so sh404SEF would not be initialized (unless your file loads Joomla and initialize it).
If I were to do that, I think I'd try to read directly the SEF URL from sh404SEF database. You'd need to build the full non-sef url: index.php?option=xxxxx and then try to find it in the #__sh404sef_urls database table. You need to pay attention to:
- have the URL disk cache disabled
- have correct parameters ordering: must be "index.php?option=com_contact&" and then all parameters in alphabetical order of the key, ie view=contact comes after id=12
- might have a problem with the Itemid, you need to know the Itemid if any. In other words, you must be searching exactly what's in the SEF URL manager
Not exactly trivial but possible. Another way would be to run your esi inclide file through Joomla. Instead of calling /esi_includes/getLinkedUsername.php, you could call
/index.php?__action=esi&other_parameters_here
Then you write a Joomla system plugin that has an onAfterRoute() event handler. This causes Joomla (and sh404SEF to be fully loaded). And at this point, if you detect that __action=esi has been passed as a parameter to the request, you can do your computing and use Joomla JRoute:_() function normally.
As a side note, on this site, I do about the same without esi. The page is fully cached but the user state (the top right corner menu) is fetched with ajax. Not exactly trivial either.
Best regards
Yannick Gaultier
weeblr.com
@weeblr
First comment:
Normally, sh404sef would convert this to SEF.Neither Joomla nor sh404SEF would convert this link to a SEF URL under any circumstances because it starts with /index.php... instead of index.php?...
But my question is this: Is there any way I can trigger in my function the code from sh404sef to convert the link from nonsef to the sh404sef version?
Now even without that, conversion cannot be done of course because you're loading directly that PHP file which means Joomla itself never gets loaded at all and so sh404SEF would not be initialized (unless your file loads Joomla and initialize it).
However, esi:includes are added to the page AFTER the pages is rendered, so sh404sef never gets to the code.Might be confused but I don't think that's how it works. You add the esi:includes tag to the page at some point, which doesn't really matter. But the include itself, ie loading the /esi_includes/getLinkedUsername.php file is executed at any time, when a user loads a page and most importantly, again, it does not execute Joomla. So neither Joomla nor sh404SEF are ran at all. Again, unless you actually load Joomla entirely.
If I were to do that, I think I'd try to read directly the SEF URL from sh404SEF database. You'd need to build the full non-sef url: index.php?option=xxxxx and then try to find it in the #__sh404sef_urls database table. You need to pay attention to:
- have the URL disk cache disabled
- have correct parameters ordering: must be "index.php?option=com_contact&" and then all parameters in alphabetical order of the key, ie view=contact comes after id=12
- might have a problem with the Itemid, you need to know the Itemid if any. In other words, you must be searching exactly what's in the SEF URL manager
Not exactly trivial but possible. Another way would be to run your esi inclide file through Joomla. Instead of calling /esi_includes/getLinkedUsername.php, you could call
/index.php?__action=esi&other_parameters_here
Then you write a Joomla system plugin that has an onAfterRoute() event handler. This causes Joomla (and sh404SEF to be fully loaded). And at this point, if you detect that __action=esi has been passed as a parameter to the request, you can do your computing and use Joomla JRoute:_() function normally.
As a side note, on this site, I do about the same without esi. The page is fully cached but the user state (the top right corner menu) is fetched with ajax. Not exactly trivial either.
Best regards
Yannick Gaultier
weeblr.com
@weeblr
TheSDHotel
Hey man,
In my code I actually do call Joomla.
See my pastebin, this is the code that I made: https://pastebin.com/7AXi2MiS
I'm getting the user so of course I indeed need to call Joomla for it.
I had to add a leading slash / before index.php because without the leading slash the path wasn't relative to the root when it was output.
So does that mean that, since I'm loading Joomla, sh404sef should actually still pick it up? Then for some reason, it looks like it's not picking it up.
"If I were to do that, I think I'd try to read directly the SEF URL from sh404SEF database."
That's actually really smart though! I can definitely do this.
If there aren't any other ideas you have based on the new information I provided, then I will defintely use the solution of reading the URL from the database :)
PS: Please increase the font-size of this input form here, it's too damn small! Haha :)
In my code I actually do call Joomla.
See my pastebin, this is the code that I made: https://pastebin.com/7AXi2MiS
I'm getting the user so of course I indeed need to call Joomla for it.
I had to add a leading slash / before index.php because without the leading slash the path wasn't relative to the root when it was output.
So does that mean that, since I'm loading Joomla, sh404sef should actually still pick it up? Then for some reason, it looks like it's not picking it up.
"If I were to do that, I think I'd try to read directly the SEF URL from sh404SEF database."
That's actually really smart though! I can definitely do this.
If there aren't any other ideas you have based on the new information I provided, then I will defintely use the solution of reading the URL from the database :)
PS: Please increase the font-size of this input form here, it's too damn small! Haha :)
TheSDHotel
To reply to your alternative idea, unfortunately writing a plugin is out of my PHP knowledge for now (haven't gotten to that skill level yet) :D
wb_weeblr
HI
Look at Joomla's index.php file, you'll see:
execute() does a whole lot of things, including loading all plugins, doing all the routing and many more things - including starting sh404SEF - that are required for routing to work (ie being able to transform a non-sef url into a SEF. I'm not sure if the Joomla app can be ran inside a simple external file like this to be honest.
Best regards
Yannick Gaultier
weeblr.com
@weeblr
In my code I actually do call Joomla.You don't "call it", you only load it so that you can access its classes and functions.
Look at Joomla's index.php file, you'll see:
// Instantiate the application. $app = JFactory::getApplication('site'); // Execute the application. $app->execute();
execute() does a whole lot of things, including loading all plugins, doing all the routing and many more things - including starting sh404SEF - that are required for routing to work (ie being able to transform a non-sef url into a SEF. I'm not sure if the Joomla app can be ran inside a simple external file like this to be honest.
I had to add a leading slash / before index.php because without the leading slash the path wasn't relative to the root when it was output.That's one of the role of the routing process to make the URL relative to the site root (not always simple as sites can be in subfolders for instance).
So does that mean that, since I'm loading Joomla, sh404sef should actually still pick it up? Then for some reason, it looks like it's not picking it up.See above, Joomla is not ran and so no extension is loaded.
To reply to your alternative idea, unfortunately writing a plugin is out of my PHP knowledge for now (haven't gotten to that skill level yet) :DIt's way simpler to create a plugin. That's pretty easy, starting from an existing system plugin one and copying and adjusting it.
I would try that first and then try the custom plugin way if that fails for some reason.
If there aren't any other ideas you have based on the new information I provided, then I will defintely use the solution of reading the URL from the database :)
PS: Please increase the font-size of this input form here, it's too damn small! Haha :)Made a not of it. I'm a bit sick of fighting against Akeeba Ticket System visual aspect and CSS, I have hundreds of lines of CSS added to the site just for it.
Best regards
Yannick Gaultier
weeblr.com
@weeblr
TheSDHotel
I'm not sure if the Joomla app can be ran inside a simple external file like this to be honest.
Indeed, it looks like it can't.
It's way simpler to create a plugin. That's pretty easy, starting from an existing system plugin one and copying and adjusting it.
It's not much about doing a plugin, it's more like what code to write inside that plugin, I literally know 0 about getting data.
The database query approach works nicely, for this specific purpose.
However i am finding myself now realizing that I need the esi include for a couple of more things as well (such as an "Edit My Profile" button etc..) and that's a bit more complicated to get from an external file (it's not just a db query).
So your idea of actually doing:" run your esi include file through Joomla. Instead of calling /esi_includes/getLinkedUsername.php, you could call /index.php?__action=esi&other_parameters_here"
would probably be a way better approach, however as I said I have no clue I would go about it. Since you say it's something simple, is there a chance I could ask you if you could do it for me? Of course as a paid thing.. In the case of yes, I would be happy to put it together together with you in a skype call or something like that so we could test it out live to see if it works. Again, would pay you for it. Of course if this is something simple. If this something that would require hours and hours and hours, then I don't know if you want to do that. If you can give me more details it would be great. And also how much the cost would be if you would be willing to do it.
Thank you a lot very much in advance.
Best,
Andy
Made a not of it. I'm a bit sick of fighting against Akeeba Ticket System visual aspect and CSS, I have hundreds of lines of CSS added to the site just for it.
Hahaha :)
TheSDHotel
Hello my friend,
At the end, I think the solution of querying data from the database works fine for me.
It's been a few days of it being live and it works fine, I was able to achieve what I wanted this way.
So I think it's all good and we can close this ticket :)
Thanks!!
At the end, I think the solution of querying data from the database works fine for me.
It's been a few days of it being live and it works fine, I was able to achieve what I wanted this way.
So I think it's all good and we can close this ticket :)
Thanks!!
wb_weeblr
Hi
Closing this ticket now, feel free to open a new one as needed. If you do so, please mention this ticket number in the new one.
Best regards
Yannick Gaultier
weeblr.com
@weeblr
It's not much about doing a plugin, it's more like what code to write inside that plugin, I literally know 0 about getting data.The code would be the same as yours. The pluing is only a means to get your code loaded inside Joomla at the right moment: after all of Joomla has been loaded and initialized but before the rest of the Joomla normal processing of the page has started.
At the end, I think the solution of querying data from the database works fine for me.When it works, it works!
It's been a few days of it being live and it works fine, I was able to achieve what I wanted this way.
Closing this ticket now, feel free to open a new one as needed. If you do so, please mention this ticket number in the new one.
Best regards
Yannick Gaultier
weeblr.com
@weeblr
This ticket is closed, therefore read-only. You can no longer reply to it. If you need to provide more information, please open a new ticket and mention this ticket's number.