Not Solved PHP in Templates and Template Conditionals
Not Solved
This is a relatively small plugin, but seems that a number of people wanted such a thing, so... here it is.

This plugin will allow you to use:
  • PHP in templates, using <?php ... ?> tags
  • Shortcut template conditionals, using <if ... then>...<elseif ... then>...<else>...</if>
  • Some shortcut string functions (see below), eg <func htmlspecialchars>...</func>
  • Call another template, using <template ...>, eg <template header>

Here's an example of some of the functions that this can be used for - for example, you may use this code in your postbit:


<if $post['fid5'] then>
Your game tag is <func htmlspecialchars_uni>{$post['fid5']}</func>
<elseif $post['fid6'] and $mybb->user['cancp'] then>
This user's lucky number is <func intval>{$post['fid6']}</func>
<else />Some other profile field: {$post['fid7']}</if>

<?php echo "Hi from PHP"; ?>

More info & Download
(it's easier to keep one location up to date Toungue)
Not Solved
Huh... this is very useful.

// We can insert javascript code in templates... so, why not some php code ?
Thank you so much. Smile

//Later: I think this should be included in the 1.4 version.
From January 08, 2013:
MyBB Romania - MyBB Community Forums from Romania
Not Solved
amazing Release Big Grin

Thanks Zinga
Not Solved
So this works without any hooks?
Not Solved
labrocca Wrote:So this works without any hooks?
Explicitly, no.

Gaining control of objects is a way to implicitly get "hooks".
Not Solved
I suck at objects..I just spent the day working on them though and learned a few things. I hope to be gain better OOP knowledge this upcoming year. It's the future of php of course.

Thanks for response Zinga.
Not Solved
thx zinga, you're beating one of the biggest weaknesses in mybb with this...
[Image: 350x19.jpg][Image: tstargermany.png]
Not Solved
Great Plugin! I have found it every useful.
Not Solved
eval does run slower, primarily due to the fact that it can't precompile/cache the PHP code, but since all of this is eval'd anyway, it's not too much of a difference. eval does cause some overhead when you put an extra layer on it though. Also, ob_* functions are used, which isn't the most efficient either.

This plugin is mainly for convenience purposes. As stated, if someone does manage to gain access to the AdminCP (or modify the templates table), they've got the ability to execute arbitrary code. Plus it's recommended to stick PHP in the .php files rather than templates (for speed and security).
Not Solved
How to put specific chunk of code....say "Test:Test" using gid & conditionals!?

Can I actually use GID in templates?

Forum Jump:

Users browsing this thread: 1 Guest(s)