Dynamic text replacement plugin

Creating and modifying plugins.
Post Reply
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Dynamic text replacement plugin

Post by garvinhicking »

Hi!

Spartacus, anyone? :-)

Great plugin!

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
carl_galloway
Regular
Posts: 1331
Joined: Sun Dec 04, 2005 5:43 pm
Location: Andalucia, Spain
Contact:

Post by carl_galloway »

My only question, is this the same plugin that mattsches and Rob were collaborating on, or will there be two plugins?

But I definitely think these should be in Spartacus, this functionality is very much in demand from users, most of them don't know it can be done, but once the average user sees it working there will be a rush to download it. Might be an idea to announce this work on the s9y blog as well.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Dynamic text replacement plugin

Post by garvinhicking »

Hi!

Maybe some few suggestions/comments:

1. Am I right that [DTR]My'stuff[/DTR] the ' character could make problems in the evaluated regular expressions?

2. Maybe it would be nice to make the plugin be able to read the TTF files bundled with the spamblock plugin? So you would not need to bundled the Vera*.ttf files with the plugin as well - because that makes the plugin a whopping 500kb download. :)

3. The output of the <IMG> tag is not XHTML compliant: If possible make it <img /> and use "&" instead of "&" seperators, and use lowercase attributes with no extra space before and after the '=' chars?

4. You use a hard-coded "plugins/..." path to access the 'dtr.php' file. In some environments (like mine) the spartacus plugins get put into an "additional_plugins" folder, so this would not load the right PHP file. The best way would be to make the HTTP path to dtr.php configurable, so that I could fix that on my installation. The default could then be the string you are currently using?

5. The 'dtr.php' uses a relative path to "../../templates_c" which might make problems (see 4.). Mabe it would be nice to make dtr.php not a standalone PHP file, but instead use the 'external_plugin' s9y event hook. The benefit of that would be that you do not need to care about 4.), and that you'D have all $serendipity[] variables to build the path to templates_c. :)

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Dynamic text replacement plugin

Post by garvinhicking »

Hi Rob!

1. Am I right that [DTR]My'stuff[/DTR] the ' character could make problems in the evaluated regular expressions?
Unfortunately, yes. I don't know enough about regexps and string handling to fix that :( Suggestions are welcome.
[/quote]

Phew. I don't know either, I'm completely unfamiliar with the regex "e" modifier. Maybe instead of using that modifier, a preg_replace_callback() function would be better to apply that sort of escaping?
2. Maybe it would be nice to make the plugin be able to read the TTF files bundled with the spamblock plugin? So you would not need to bundled the Vera*.ttf files with the plugin as well - because that makes the plugin a whopping 500kb download. :)
Ideally, we could have a standard font folder (maybe as a subfolder of the uploads?) that ALL such plugins, (captha, this one, and the one Carl referred to) can use. It would also be nice for the application to provide a variable to that real path.....
Alernately, the plugin could be modified to let the user enter their own path....
Yeah, for the long run this would be more ideal. But maybe for the time being we could rely on the spamblock plugin? *g*
4. You use a hard-coded "plugins/..." path to access the 'dtr.php' file. In some environments (like mine) the spartacus plugins get put into an "additional_plugins" folder, so this would not load the right PHP file. The best way would be to make the HTTP path to dtr.php configurable, so that I could fix that on my installation. The default could then be the string you are currently using?
Is there a function to return the plugin path? I had to use the app root and then append /plugin/serendipity_event_dtrmarkup/ but as you point out, that won't always work...
[/quote]

If you use the "external_plugin" hook, you can make up your own name. You could use this code in building the link:

Code: Select all

$link = $serendipity['baseURL'] . ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . 'plugin/mycustomname';
Then you just make the external_plugin event hook check if $eventData == 'mycustomname' and there you go with the output.

Hope that makes some sense somehow? If not, have a look at the spamblock plugin, how it emits the <img> tag for a captcha image...
1) Is there a way to get the piped content to show up at the end in the backend configuration? Right now it is in the middle for some reason...
Uh, ah...I'm afraid I don't understand the question. Which piped contents do you mean?
2) Is there a way (if 5 is done) to make the image generation scrip only work if called from the blog itself? I wanted to prevent a direct external call (like image leaching)
That is pretty hard to do, like preventing all image leaching. There are only two ways that really work:

1. Utilize sessions, so that the script can only be called if a session variable is present, which the plugin itself sets when emitting the appropriate <img> tag. However, then people without cookies won't see images replaced.

2. Check the HTTP referer in the generation script. But then people who do not submit their HTTP referer will see no images.

So, either way, I don't see a method that would really work. You could prevent people from using their own strings by encoding a variable with the content of the string, and using an encrpytion routine that common people can't decifer; by passing a configurable password into the plugin that uses this passphrase to bitshift the string variables, or whatever. But this might be hackable as well, and not worth all the hassle?!
3) is there a need to manage the size of templates_c? This could chew up lots of space, and it might be good to purge the cached files occasionally....
Good question. Since cached images only represent replacements that usually are always contained and always recreated (even through googlebotr or whatever) I don'T believing purging the cache will do much good.

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

Ah! The order of config items should be decided by the order of when it is placed in the "configuration" propbag array!

As another way of showing it, you could use the "Example" method (or whatever its called) of a plugin. Maybe you can have a look at the emoticate plugin, I believe it uses this method to show a list of available emoticons?!
Also... What are the serendipity variables to build guaranteed paths to templates_c and to the plugins directory?
That would simply be $serendipity['serendipityPath'] + "templates_c" or + "plugins". Both directories are not allowed to be called differently. Instead of prefixing serendipityPath you can also prefix $serendipity['baseURL'].

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
mattsches
Regular
Posts: 440
Joined: Sat Nov 05, 2005 9:35 pm
Location: Wiesbaden, Germany
Contact:

Post by mattsches »

Hi, sorry for chiming in so late :wink:

First of all, RobA, your plugin works great and does a lot more than mine with respect to image replacement possibilites. I focused on titles/headings only since this is the recommended way for sIFR (too many Flash movies on one page aren't good), and it's quite difficult to generate Flash on-the-fly for other elements, too.

So, since I basically copied RobA's code for GD, what are we gonna do with these plugins? I suggest we either keep them separate and I remove the GD code from my plugin again (with the advantage that the user doesn't have to edit his templates when using sIFR 8) ); or RobA and I can try to merge my sIFR code into his plugin, e.g. if you write [SIFR ...] instead of [DTR ...] the second method is used. OTOH, with my plugin the user won't have to use any extra markup, but gets all his headlines delivered in Flash.

I'm pretty tired right now, so I have to think about it a little bit more tomorrow. What do others think?

- Mattsches
d_cee
Regular
Posts: 603
Joined: Wed Jan 18, 2006 6:32 pm
Location: UK
Contact:

Post by d_cee »

Hi Rob

Another great plugin :-)
I uploaded it to try it out but I couldn't get past the config screen - which unfortunately didn't look like your screenshot. I've posted a screenshot here.

cheers

Dave
Post Reply