Welcome! » Log In » Create A New Profile

display URL source

Posted by notromda 
Re: display URL source
October 25, 2008 01:52AM

Ok, I see that I can access the config object by overloading the prepare() method (calling parent of course), and I have a config object ready... but how do I do this, eval() the config string?, or is it already instantiated?

Arg, I hit another snag... I cannot use the Autoformat namespace, as it's trying to snatch up all of those to load as injectors... and then I hit a class not found error. Maybe I'll make a AutoformatConfig namespace?

Re: display URL source
October 25, 2008 02:08AM

Ok, so there's a bunch of things to address:

First question, Is there a routine somewhere that can read a small string and tokenize it?

If you're talking about HTML, you want HTMLPurifier_Lexer::create($config). It's a pretty heavyweight class, though, so avoid using it if possible.

I was thinking of making a helper class to go with this injector, which will have its methods called to populate the new link. The default class could do the output as we have it, and then a configuration item could be used to override with a subclass.

So, one important consideration is the fact flexibility often goes against simplicity. If users where going to be making three plus different types of URL source display, making a helper class might be justified; however, that is simply not the case: most of the time, they won't use this class at all, and the rest of the time, they'll have a very specific format they want to use, and will end up coding a derivative class anyway. As such, I don't think the interface/supertype is necessary.

Is this the Strategy pattern?

Yep.

public function LinkAttributes($linktext);

HTML Purifier naming convention is for methods to start lower-case.

If not, then the subclass has to create the tokens directly. Anyway, see where I'm going with this?

I understand, and this is a deliberate consideration for performance considerations. Check out the graph here; the blue constitutes time spent parsing, and while the graph is not completely representative, it should give you an idea for this sort of thing.

It may be useful to make an easy API for creating tokens, however.

I'm not sure how to instantiate the default strategy, unless that can be done in a configuration item. I suppose that's the way it needs to be instantiated so it can be set from the unit tests.

Constructor or the setup() function works.

Ok, I see that I can access the config object by overloading the prepare() method (calling parent of course), and I have a config object ready... but how do I do this, eval() the config string?, or is it already instantiated?

If the directive type is "mixed", you can put a literal object in the configuration, and then pull it out using get() normally.

Arg, I hit another snag... I cannot use the Autoformat namespace, as it's trying to snatch up all of those to load as injectors... and then I hit a class not found error. Maybe I'll make a AutoformatConfig namespace?

You want AutoFormatParam namespace.

Re: display URL source
October 25, 2008 12:19PM
I was thinking of making a helper class to go with this injector, which will have its methods called to populate the new link. The default class could do the output as we have it, and then a configuration item could be used to override with a subclass.

So, one important consideration is the fact flexibility often goes against simplicity. If users where going to be making three plus different types of URL source display, making a helper class might be justified; however, that is simply not the case: most of the time, they won't use this class at all, and the rest of the time, they'll have a very specific format they want to use, and will end up coding a derivative class anyway. As such, I don't think the interface/supertype is necessary.

Without the interface, then I guess no more work is needed... Any different output would just need a slightly rewritten Injector class which could be in my own code and included in the config call... the existing copy serves as the example I guess. :)

Re: display URL source
October 25, 2008 03:07PM

I'm very happy with the way this turned out. I have a patch waiting for my own project, but I'd like to wait until you have a released version before we apply it. Do you have any estimate when it might be ready for a release?

(BTW, you can see a picture of the end result on that ticket too)

Re: display URL source
October 25, 2008 08:16PM
Without the interface, then I guess no more work is needed... Any different output would just need a slightly rewritten Injector class which could be in my own code and included in the config call... the existing copy serves as the example I guess. :)

Sounds good. Saves you work from having to code another iteration, too. :-) If someone else requests a feature modification, we can always extend things.

I'm very happy with the way this turned out. I have a patch waiting for my own project, but I'd like to wait until you have a released version before we apply it. Do you have any estimate when it might be ready for a release?

HTML Purifier hasn't had a release for several months, and is long overdue for one. So hopefully, soon. :-)

Re: display URL source
November 13, 2008 11:55AM

Excellent - I see the new release, and I've added my own extension to my project. Here's a nice picture of it in action: https://www.maiamailguard.com/maia/attachment/ticket/513/Picture%209.png

It sure is nice to have that extra info presented nicely! :) Thanks again for your help!

Author:
Your Email:

Subject:

HTML input is enabled. Make sure you escape all HTML and angled brackets with < and >.

Auto-paragraphing is enabled. Double newlines will be converted to paragraphs; for single newlines, use the pre tag.

Allowed tags: a, abbr, acronym, b, blockquote, caption, cite, code, dd, del, dfn, div, dl, dt, em, i, ins, kbd, li, ol, p, pre, s, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, var.

For inputting literal code such as HTML and PHP for display, use CDATA tags to auto-escape your angled brackets, and pre to preserve newlines:

<pre><![CDATA[
Place code here
]]></pre>

Power users, you can hide this notice with:

.htmlpurifier-help {display:none;}

Message: