Best approach: Rewrite all IMG-Urls after HTML is build

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
margau
Registered User
Posts: 3
Joined: Fri Aug 03, 2018 6:54 am

Best approach: Rewrite all IMG-Urls after HTML is build

Post by margau » Fri Aug 03, 2018 7:30 am

Hello,
I'm currently working on a plugin doing the following:
Catch all img-Tags, look at the URL and possibly rewrite them.
The Problem is: I can't do this with s9etextformatter, because the Rewritten URL changes every few days for security reasons.

So my idea is to get the HTML-Code inside the core.page_footer_after-Event, and rewrite it then.

How is this possible, unfortunately, I didn't find the right object to access and modify all HTML yet?

Is there a better place for rewriting Image-URL's in Posts and Message, regarding to caching?

Thank you and best regards
margau

User avatar
david63
Jr. Extension Validator
Posts: 15076
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: Best approach: Rewrite all IMG-Urls after HTML is build

Post by david63 » Fri Aug 03, 2018 8:00 am

margau wrote:
Fri Aug 03, 2018 7:30 am
The Problem is: I can't do this with s9etextformatter, because the Rewritten URL changes every few days for security reasons.
But won't it still change no matter which event you use?

Where is this "new" URL coming from?
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

User avatar
Ger
Recognised Extension Developer
Posts: 1792
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

Re: Best approach: Rewrite all IMG-Urls after HTML is build

Post by Ger » Fri Aug 03, 2018 10:14 am

Can't you simply use either of core.text_formatter_s9e_render_before or core.text_formatter_s9e_render_after? That's handled when a post is displayed.
My extensions:
Simple CMS, Feed post bot, Avatar Resize, Modbreak, Magic OGP, Live topic update, Modern Quote, Quoted Where (GDPR) and Autoresponder.
Newest: FAQ manager for 3.2

Like my work? Buy me a coffee to keep it coming. :ugeek:
-Available for custom work-

margau
Registered User
Posts: 3
Joined: Fri Aug 03, 2018 6:54 am

Re: Best approach: Rewrite all IMG-Urls after HTML is build

Post by margau » Fri Aug 03, 2018 3:58 pm

david63 wrote:
Fri Aug 03, 2018 8:00 am
margau wrote:
Fri Aug 03, 2018 7:30 am
The Problem is: I can't do this with s9etextformatter, because the Rewritten URL changes every few days for security reasons.
But won't it still change no matter which event you use?

Where is this "new" URL coming from?
Hello, yes it won't.
The problem is: core.text_formatter_s9e_configure_after is only run before the rendered BBCode is written into the Database - so I can't replace it there, because I have no "static" replacement. Have already tried that.

The "new" URL is a timestamp combined with the Original URL, we need it to have a "timeout" for our imageproxy.
The board has over 15 years in history, so changing all old posts in the database would be a not-so-great solution.
Ger wrote:
Fri Aug 03, 2018 10:14 am
Can't you simply use either of core.text_formatter_s9e_render_before or core.text_formatter_s9e_render_after? That's handled when a post is displayed.
Am I right that I cannot run attribute-filters on the renderer? Tried that too.

Best regards
margau

User avatar
Ger
Recognised Extension Developer
Posts: 1792
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

Re: Best approach: Rewrite all IMG-Urls after HTML is build

Post by Ger » Fri Aug 03, 2018 8:07 pm

If it's just about adding a timestamp to an URL, can't you do it with a few lines of Javascript?
My extensions:
Simple CMS, Feed post bot, Avatar Resize, Modbreak, Magic OGP, Live topic update, Modern Quote, Quoted Where (GDPR) and Autoresponder.
Newest: FAQ manager for 3.2

Like my work? Buy me a coffee to keep it coming. :ugeek:
-Available for custom work-

EVO_VV
Registered User
Posts: 51
Joined: Tue Feb 13, 2018 3:11 pm

Re: Best approach: Rewrite all IMG-Urls after HTML is build

Post by EVO_VV » Sat Aug 04, 2018 4:49 pm

It would be helpful to know a little more about exactly what you want to achieve.

Assuming that due to the frequent change just reading the database via SQL and performing the rewrites in there is not a viable solution, then altering the HTML 'on the fly' would be your option.

As Ger has mentioned you can do this by using the core.text_formatter_s9e_render_after Event as this gives you access to the HTML for that post.
Once you have successfully edited that HTML then that is what will be displayed to the Client.
Not sure if that also is valid for Messages but I would suspect so.

If the Domain Name for all the Image URLs is the same or if All image URLs need editing the HTML will be simpler to edit than if they are not.

Is the 'TimeStamp' an integral part of the URL Or is it just for display ?
How does the 'TimeStamp' relate to the Post Time or the Current Time ?

An Example of the 'Before Edit' and 'After Edit' URL would give us a much better idea of what you want to achieve.

NOTE:
Edited to correct the mentioned Event as per JoshyPHP's following post
Last edited by EVO_VV on Mon Aug 06, 2018 4:46 am, edited 1 time in total.

User avatar
JoshyPHP
Code Contributor
Posts: 972
Joined: Mon Jul 11, 2011 12:28 am

Re: Best approach: Rewrite all IMG-Urls after HTML is build

Post by JoshyPHP » Sun Aug 05, 2018 11:31 pm

margau wrote:
Fri Aug 03, 2018 3:58 pm
Am I right that I cannot run attribute-filters on the renderer? Tried that too.
No, attribute filters are applied at parsing time. The renderer is a lightweight process that simply builds HTML based on what's already there.

The event you'll want to use is core.text_formatter_s9e_render_after.
I wrote the thing that does BBCodes in 3.2.

Post Reply

Return to “Extension Writers Discussion”

Who is online

Users browsing this forum: caiocald, malaxpina, mrgoldy, wojtek64 and 5 guests