Kroc / NoNonsenseForum

A free, open source, PHP-based simple discussion forum. It favours removing barriers to conversation rather than massaging egos. Download Here: https://github.com/Kroc/NoNonsenseForum/archive/master.zip
http://camendesign.com/nononsense_forum
Other
247 stars 34 forks source link

Add 3rd party template hooks for loops (such as posts in a thread) #155

Open Kroc opened 12 years ago

Kroc commented 12 years ago

Add a hook for 'theme.php' so that theme designers can add additional templating to each post in a thread, etc.

Zegnat commented 12 years ago

I was wondering if this should be moved to DOMTemplate?

Also wondering if a possible solution might be a jQuery like .html(function(){}). This would allow to change the element’s content depending on the current content. That way no extra hooks are needed for the forum software and future DOMTemplate projects benefit from it.

How would this work? Maybe something along these lines:

/* Append the string “ (external link)” to outgoing links.  *
 * We can find outgoing links through the external rel and  *
 *  then use a function to manipulate the original content. */

$template->setValue ('a@rel', function($orig) {
    return $orig . ' (external link)';
}, true);

I am using true at the end incase the A-element included any HTML tags (maybe an em?) and we’ll want to keep those as they are. This of course does not apply to NoNonsenseForum.

(This would up DOMTemplate’s PHP requirement to 5.3.0, which would be bad, are there alternative ideas?)

Kroc commented 12 years ago

Yeah, it's the 5.3.0 limit I'm concerned about; yes people should keep their servers up to date, but real life is not so practical, and NNF is certainly used by people on free / shared hosting where things are most likely to be out of date.

I would only want to push to PHP5.3 or above if there were some major wide-sweeping improvements that could be made to the whole of NNF rather than a small optimisation here and there. I may consider a rewrite of NNF / DOMTemplate once PHP 5.4/5 become commonplace, but that's probably a few years away yet. (I would really appreciate being able to $var = this_function_returns__an_array (param)[1];)

I definitely acknowledge that DOMTemplate needs a means to read data better (rather than being write-only) and it is this way currently because of the limitation in PHP that means that you cannot subclass DOMNodeList so that xpath queries return your custom class. When I first began writing DOMTemplate, I started by subclassing DOMDocument / DOMElement / DOMNode so that you could freely interact with the DOM all within the same context as templating, making reading the DOM for templating use so much easier.

Should that bug get fixed, I will consider going back to that method. I received an e-mail from a user who suggested a workaround that would give me what I wanted, but I need to go investigate that to see the viability.

For now, a intermediate compromise is needed, we can't use callbacks in PHP5.2, but I'm sure there's other things we can do to suit the most common and likely use-case.

Kroc commented 11 years ago

Been looking at the requirements for this. The first-posts that appear individually at the top of each post, and the post-copies that appear on the delete / append pages would need to be templated using a normal repeater (no issue) so it can be passed to the custom function in 'theme.php', however the main problem is that these special posts use different CSS IDs than the replies and the custom function wouldn't be able to know which is which without something ugly.

I need to think of a way to unify the first-posts / replies in a way that a custom function can receive a DOMTemplateRepeater and modify regardless of where it belongs on the page.