PDA

View Full Version : Miscellaneous Hacks - Let PHP Live! (Allow PHP code in templates)


King Internet
16 Aug 2006, 08:32
I got frustrated that the vBulletin template system limited me in this way so... I wrote a hack around it.

Just use <? <?php <?= as you would normally in the templates.

I'd like to see PHP based templates in the future, vBulletin! <if> is useless if I can just type <? if ?> !

Things to Remember

You cannot break up PHP blocks.

<? if (0): ?>
Hello!!!
<? endif ?>

will not work, and you'll get a nice error message about how it didn't. If it's really a concern for anyone, I can try to get it working. In my opinion, that's not a big deal. I think PHP support sans breaking up blocks in 10 lines of hack code is pretty nice, myself.

That's a limitation of eval anyway ;)

Variables aren't always the same in PHP mode!

While you can use $vboptions[bbtitle] in your main code and get it working, vBulletin is doing behind the scenes voodoo on stuff.

To access $vboptions[x]: $GLOBALS['vbulletin']->options['x']

leestrong7
16 Aug 2006, 08:44
Interesting, Ill wait untill someones got this working though

Phalynx
16 Aug 2006, 09:14
Thanks for sharing.

King Internet
16 Aug 2006, 10:36
Interesting, Ill wait untill someones got this working though

Not much to get working... you import the XML file, the end. Nothing to configure. Code only runs when templates are compiled.

D.Ilyin
16 Aug 2006, 12:46
hm.... intresting..... installed....

epic1
16 Aug 2006, 16:11
Damn, could have used this when I was struggling to get some PHP scripts to work with 3.6 in the beginning, lol.

I'll still take this for a spin for when I next need to do some PHP stuff. Thanks!

Kirk Y
16 Aug 2006, 20:07
I think, as probably do the vB Coding Team, that the ability to use PHP in Templates is a Security Risk. What if you've got an Administrator on your board who gets bored and decides to execute some harmful code?

Zachariah
16 Aug 2006, 21:07
What if you've got an Administrator on your board who gets bored and decides to execute some harmful code?

I do not put people in power who I can not trust.
Do you ? If you do, make sure you back up.

Ntfu2
16 Aug 2006, 22:53
awesome, i only tested with a simple echo statement but it worked like a charm :yesway:

Kirk Y
16 Aug 2006, 23:03
I do not put people in power who I can not trust.
Do you ? If you do, make sure you back up.

I trust all my Administrators. But just because you trust someone doesn't mean that they wouldn't for some reason get upset and retaliate.

Paul M
16 Aug 2006, 23:17
I'm sure there was a very good reason php was not allowed in templates, and it's never necessary if stuff is written properly. Still, nice of you to share. :)

King Internet
16 Aug 2006, 23:39
I'm pretty sure it's annoying when software intentionally tries to limit the administrator. If you have a huge problem, remove Styles Permissions in the administrator permissions for the administrator you cannot trust. All of my admins also have FTP access and have been in my community for 5 years, I would trust them with babysitting my children. If you cannot trust your administrators, then who can you trust? They have access to all of your board. They could delete all of that board. I guess it is a security risk to have administrators at all. :/

However, it is not good to assume that all situations can be solved by saying "well, if it was written RIGHT then this wouldn't be necessary." This is a nice shortcut for anyone who actually wants to turn vBulletin into something else besides a stock vBulletin with a different logo and color scheme.

Here is my situation and the reason I wrote this particular hack: I wanted to integrate the header and footer which vBulletin uses with the rest of my site's template system. I do this by calling top() and bottom() when I need the header and when I need the footer respectively. Since each template has different values that I will need to pass to top() for the navigation selection, title, necessary <head> elements, etc I will need to replace the HTML code that starts every template with a call to top(). Saying that I could just put this in $header is ridiculous- vBulletin itself does not do that. What am I supposed to do? Make a plugin for every single _start of a document? That's also ridiculous, and also hard to maintain.

I know separating code and display is the hot new thing to do, but that doesn't mean you should have to go out of your way to do it. Personally, I like being able to include template files and use PHP formatting logic to echo stuff directly into templates without being assed to make a plugin in some far away part of the CP. vBulletin template support is poor; it needs this. :D

Thanks to everyone who installed!

utw-Mephisto
17 Aug 2006, 11:41
FINALLY - thanks :)

I need it for certain gameserver stuff which was a pain before. I mean yes, you can call php files using a nice neet plugin and such, but this makes it sooo easier - thanks

/me clicks install

wolfyman
18 Aug 2006, 21:36
can I get a "this hack for dummies" post? How exactly does this work?

I want to put this php code in my header:
<?php
{
include("http://www.mysite.com/in.php");
}

?>

The reason - mysite.com and forums.mysite.com are on two different servers.


*EDIT*

Is it as easy as using this:

<?php { include("http://www.mysite.com/in.php");} ?>


????

BETIServices
18 Aug 2006, 21:49
I installed and works perfect.. <!- / thank you - >

Adrian Schneider
19 Aug 2006, 01:11
$top = top();
$bottom = bottom();
Much easier IMO. Or, do it properly, and actually USE the templates.

I'd like to see PHP based templates in the future, vBulletin! <if> is useless if I can just type <? if ?> !<? if ?> is useless if I can just type <if>. Plus, it's pretty much still XHTML, so you can use it in editors easily. As far as maintenance goes, I would say this is a step in the wrong direction.

What do you mean about having to use multiple _start plugins? You should only have to use global_start. One plugin. You can even have it include a PHP script you can edit/upload to change the code. This way, it is all in one central location, and it keeps your templates as templates, rather than code soup.

I would like to see how your templates are holding up in a years time.

Anyway, if it works for you - great, I'm sure others will appreciate it as well. I just think you should give the template system another try the way it is supposed to be used, and you will probably see why we feel this way.

wtrk
19 Aug 2006, 01:21
I think, as probably do the vB Coding Team, that the ability to use PHP in Templates is a Security Risk. What if you've got an Administrator on your board who gets bored and decides to execute some harmful code?

just dont tell anybody. whos going to know if you dont tell them? you could even change the name of the plugin so they dont know.

Kirk Y
19 Aug 2006, 01:37
I assume that was some poor attempt at sarcasm -- but you should probably know that most of "them" read and post here often. ;)

King Internet
21 Aug 2006, 01:02
$top = top();
$bottom = bottom();
Much easier IMO. Or, do it properly, and actually USE the templates.

Well no, you are assuming thats how it works and assumptions are never nice. top() and bottom() take parameters depending on what page they are called from, and I don't want to use the template system. That means I have to keep two seperate copies of the current template of my site and I surely don't like redundancy. Please read my previous (and very long) post.

<? if ?> is useless if I can just type <if>. Plus, it's pretty much still XHTML, so you can use it in editors easily. As far as maintenance goes, I would say this is a step in the wrong direction.

<else /> is dumb, and I'd rather not be limited in what comparison functions I can use.

What do you mean about having to use multiple _start plugins? You should only have to use global_start. One plugin. You can even have it include a PHP script you can edit/upload to change the code. This way, it is all in one central location, and it keeps your templates as templates, rather than code soup.

Well no, you are assuming thats how it works and assumptions are never nice. top() and bottom() take parameters depending on what page they are called from, and I don't want to use the template system. That means I have to keep two seperate copies of the current template of my site and I surely don't like redundancy. Please read my previous (and very long) post.

I would like to see how your templates are holding up in a years time.

Much better than your way, as I am not having to maintain two sets of templates. Please read my previous (and very long) post, get off your high horse and get out of my topic.

I don't really want to bruise egos here, so I will reserve the majority of what I have to say. All I will say is that you can't even do something simple like zebra-striping tables with vBulletin's templating functionality, and it is embarrassing. Please don't talk to me like I am new and stop hijacking my thread with your nonsense. Thanks.

And once again, thanks to everyone who installed!

BETIServices
21 Aug 2006, 04:20
Thank you for the mod.... and keep them coming :D

Zas
21 Aug 2006, 05:22
Thanks a lot, it works perfectly. I needed this so I could display random banners.

zephy
13 Sep 2006, 15:23
Thanks for your Mod, like Zas I wanted something to display random banners :)

Kirk Y
13 Sep 2006, 19:50
Which can easily be done by using 1 Plugin...

papa_face
15 Sep 2006, 17:57
Can someone confirm that this mod doesnt work for 3.6.1?
I dont seem to be able to add pages now with php, although my previously added ones work fine.
Fatal error: Call to undefined function: showprevious() in /home/devnerds/public_html/includes/adminfunctions_template.php(3593) : eval()'d code(27) : eval()'d code on line 1
Is the error I get.

Regards

papa_face
15 Sep 2006, 18:48
My mistake, i was using php blocks

Been Told
31 Dec 2006, 15:06
Thanks, just what I needed! :)

cageybee
08 Jan 2007, 04:49
Hi, I have a question -- what is a user wants to paste a php code into the post -- will it work?

Basically, what I wonder is can I paste it into a post and have a script executed? What would have to be enabled for that script to be executed?

Doctor Who
08 Jan 2007, 18:54
Does this still work? I can't seem to include a file...

GameWizard
15 Jan 2007, 04:33
Found an alternative:
http://www.vbulletin.com/forum/showthread.php?t=173937

marinig
07 Sep 2007, 22:33
Hi, I have a question -- what is a user wants to paste a php code into the post -- will it work?

Basically, what I wonder is can I paste it into a post and have a script executed? What would have to be enabled for that script to be executed?

I think this is very important question. Can someone give an answer about this?
Thanks

Millenium IT
08 Sep 2007, 19:45
I would not advise you to use php in your templates. The vBulletin plugin/hook alocation system is not only much easier on a global scale, but also much more reliable and secure. Mixing php in your templates could cause difficulties or problems in your forum script as you go along.

Cole2026
08 Sep 2007, 23:15
I would be curious to know how much time this would add to a page's processing time.

CrazyCanuck
22 Dec 2007, 14:43
thanks for this addon

odonel
22 Dec 2007, 15:23
I understand where VB is coming from in regard to some threats pose to forums with php codes but a lot of us users want to add custom code to our forums and VB is aware of that.
This is one thing VB lacks, integration with an external page. Why not give us easier ways to do these sort of things VB ?? tips/guides templates anything.........

thanx for this addon i will play with it to see if i can use it

DonHouston
12 Jun 2008, 19:11
thanks alot, exactly what i was looking for!

Freddy.k
28 Aug 2008, 18:25
Merci cool

Hitterman
30 Sep 2008, 11:25
Its really awesomeeeeeee.e
Great work. really nice.
Hurray!!!!!!!!!!!
"Installed" & "Nominated" because it works with 3.7.x also.

GNeRaL
18 Jun 2009, 14:42
Great work, thanks!

To access $vboptions[x]: $GLOBALS['vbulletin']->options['x']

I've one question, I want to use postid with PHP. How to use?

And can you explain ?

Thanks for your answer.

angeljs
14 Sep 2009, 17:31
This is so cool, and works great, thanks

Spinball
24 Jan 2010, 12:07
Just a note to say that a Russian hacker used this plugin to point Google to a Canadian Pharmacy store when it visited our home page.

sapgaurav
28 Jun 2011, 10:55
i just install and tried to add php code but now working. do i need to do someting else to run php code?

can you give me example php to to test