Current time: 02-04-2012, 02:29 AM Hello There, Guest! (LoginRegister)


Post Reply 
 
Thread Rating:
  • 14 Votes - 3.64 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PHP in Templates and Template Conditionals
05-27-2008, 11:34 AM (This post was last modified: 04-28-2010 10:01 AM by Yumi.)
Post: #1
PHP in Templates and Template Conditionals
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:

Code:
{$post['user_details']}

<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)
Visit this user's website Find all posts by this user
Quote this message in a reply
05-27-2008, 11:38 AM (This post was last modified: 05-27-2008 11:46 AM by mybbromania.)
Post: #2
RE: PHP in Templates and Template Conditionals
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.

"First they ignore you. Then they laugh at you. Then they fight you. Then you win." - Mahatma Gandhi
Find all posts by this user
Quote this message in a reply
05-27-2008, 01:45 PM
Post: #3
RE: PHP in Templates and Template Conditionals
amazing Release Big Grin

Thanks Zinga

[]s, Claudio

Tutorial: Jquery (by google API) with mybb (Prototype)
Distinction between Paid/Free Plugins Threads
Visit this user's website Find all posts by this user
Quote this message in a reply
05-27-2008, 03:22 PM
Post: #4
RE: PHP in Templates and Template Conditionals
This user has been denied support. This user has been denied support.
So this works without any hooks?

New MyBB plugin is "IPLH (IP Log History) v1.0".
[Image: 468x60_SF.gif]
Vote for MyBB to add a Security section.
Visit this user's website Find all posts by this user
Quote this message in a reply
05-28-2008, 01:42 AM
Post: #5
RE: PHP in Templates and Template Conditionals
labrocca Wrote:So this works without any hooks?
Explicitly, no.

Gaining control of objects is a way to implicitly get "hooks".
Visit this user's website Find all posts by this user
Quote this message in a reply
05-28-2008, 02:00 AM
Post: #6
RE: PHP in Templates and Template Conditionals
This user has been denied support. This user has been denied support.
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.

New MyBB plugin is "IPLH (IP Log History) v1.0".
[Image: 468x60_SF.gif]
Vote for MyBB to add a Security section.
Visit this user's website Find all posts by this user
Quote this message in a reply
05-31-2008, 07:14 PM
Post: #7
RE: PHP in Templates and Template Conditionals
thx zinga, you're beating one of the biggest weaknesses in mybb with this...

[Image: 350x19.jpg][Image: tstargermany.png]
Find all posts by this user
Quote this message in a reply
08-15-2008, 12:44 AM
Post: #8
RE: PHP in Templates and Template Conditionals
Great Plugin! I have found it every useful.

www.maroonlife.com
[Image: logo4.jpg]
Find all posts by this user
Quote this message in a reply
08-17-2008, 12:47 PM
Post: #9
RE: PHP in Templates and Template Conditionals
Just a word about this...
This is a great plugin that halp a lot (I've even implemented something similar in one of my boards), but I don't think this will ever should be part of the normal releases.

MyBB separate PHP coding from templates & themes designing in a great way, so you can enable someone (probably your designer) to edit the templates with no worry that he can hurt your board in an unrecoverable way (because he just can't).
Unalike if you'll use a plugin such as this, anyone can edit your templates, probably will be able to edit any other file in your site with some code injections, so you have to be more careful with who you trust and you don't.

Moreover, to implement such thing you'll probably have to run some regexes on each template, and this will get your board a bit slower (or much slower depending on the implementation, but I'm trust ZB).

BTW, ZB (zinga burga),
Why the PHP run slower? does the eval function run slower than normal code?
(assuming you've used the eval function)

Creativity is a drug I cannot live without.
[Image: igG319dTu71gT.png]
Visit this user's website Find all posts by this user
Quote this message in a reply
08-17-2008, 10:56 PM
Post: #10
RE: PHP in Templates and Template Conditionals
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).
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)

Contact Us | MyBB | Return to Top | Return to Content | Lite (Archive) Mode | RSS Syndication