This is essentially a more restrictive version of my
PHP in Templates plugin. The restrictions aim to make this a "safe" plugin to use, that is, doesn't allow arbitrary PHP execution, but still gives the benefits of template conditionals.
You may notice that this still uses the "phptpl" name, and thus, is incompatible with the PHP in Templates plugin. Both plugins are very similar though. The differences between this and the other plugin are:
v1.0-1.3 of this plugin is based off v1.7 of PHP in Templates.
As of v1.8, PHP 5.3 or later is required.
This plugin can be used with the
Admin Security plugin.
"Safe expressions"
This plugin implements "
safe expression" checking; essentially, this does impose a bit of a performance hit, but, on the other hand, tries to ensure no "bad PHP" gets executed.
For more information on what I consider to be a "safe expression",
see my blog post here.
For the purposes of this plugin, all valid PHP expressions are allowed, as long as they don't infringe on any of the following conditions:
- no assignment/modification operators (=, +=, |=, ++ etc) allowed
- no statements such as include, exit, eval etc are allowed
- no special constants such as PHP_OS, PHP_LIBDIR etc are allowed
- backtick (`) operator not allowed
- heredoc type strings not allowed (takes too much effort to handle) - use double quoted strings instead
- double quoted strings may not contain the "{" character (takes too much effort to handle) - use string concatenation instead
- array and object typecasting not allowed
- no variable functions or method calls allowed
- single line comments (//, #) not allowed
- only some functions are allowed - see inc/plugins/phptpl_allowed_funcs.txt for a list of allowed functions