[wp-hackers] Easytags template system
false.hopes at gmail.com
Wed May 10 14:59:44 GMT 2006
Regardless on whether or not I think this should be done, how much of
a templating language PHP is and is not, and how silly I think it is
arguing over this, especially on the recommendation of it being a
plugin, here's how it could (and probably should) be done, whether in
a plugin or in the core [begin flames upon me here].
First thing is file concatenation. If we're going to do this as a
system like this, we should let them select front page view, single
page view, etc. and make it all one file, instead of trying to split
out headers, because inevitably people will want to do something
different with it, and if anything, we shouldn't be approving the use
of <ifsinglepage><someothertag></ifsinglepage>, so let's keep them all
in one file. For when editing existing themes, we should concatenate
all the associated files for each view.
Second thing is parsing. Lucky for us, the PHP guys have made this
easy for us, and given us access to Zend's lexical scanner and
tokenizer from PHP userspace. The downside is for us linux users, its
disabled by default as of 4.3, this is something whoever does this
will have to work around (I declare thee the dumbest person ever if
you run off to try to write a lexical PHP scanner in PHP). On the
bright side, its built in for all windows versions to date. 
So, the suggested method here is using token_get_all() and taking
advantage of the lexical scanner. While looping over, you output any
inline HTML, you replace any specific PHP blocks that you want with
HTML. Easy as pie, really.
The hard part is going from whatever desired format(s) you want back
to PHP. This pretty much could be left to the imagination of the
person writing this, as a proper parser for this probably has to be
created from scratch, have fun with preg_match. For someone
sufficiently skilled, I doubt this is a problem, for half the people
spouting off on this discussion today, well, I'll be nice.
On a related note, Matt, have you thought about looking into Savant's
(http://phpsavant.com) scripts and classes for cleaning PHP for
templates? From what I understand, its designed and does a decent job
at what it does, and would probably be something very useful to WP.com
if its as good as I've heard it is.
More information about the wp-hackers