vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3.6 Add-ons (https://vborg.vbsupport.ru/forumdisplay.php?f=194)
-   -   Miscellaneous Hacks - Let PHP Live! (Allow PHP code in templates) (https://vborg.vbsupport.ru/showthread.php?t=124094)

King Internet 08-15-2006 10:00 PM

Let PHP Live! (Allow PHP code in templates)
 
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 08-16-2006 07:44 AM

Interesting, Ill wait untill someones got this working though

Phalynx 08-16-2006 08:14 AM

Thanks for sharing.

King Internet 08-16-2006 09:36 AM

Quote:

Originally Posted by leestrong7
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 08-16-2006 11:46 AM

hm.... intresting..... installed....

epic1 08-16-2006 03:11 PM

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 08-16-2006 07:07 PM

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 08-16-2006 08:07 PM

Quote:

Originally Posted by acidburn0520
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 08-16-2006 09:53 PM

awesome, i only tested with a simple echo statement but it worked like a charm :yesway:

Kirk Y 08-16-2006 10:03 PM

Quote:

Originally Posted by Zachariah
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 08-16-2006 10:17 PM

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 08-16-2006 10:39 PM

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 08-17-2006 10:41 AM

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

[high]* utw-Mephisto clicks install[/high]

wolfyman 08-18-2006 08:36 PM

can I get a "this hack for dummies" post? How exactly does this work?

I want to put this php code in my header:
Code:

<?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:

Code:

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

BETIServices 08-18-2006 08:49 PM

I installed and works perfect.. <!- / thank you - >

Adrian Schneider 08-19-2006 12:11 AM

PHP Code:

$top top();
$bottom bottom(); 

Much easier IMO. Or, do it properly, and actually USE the templates.

Quote:

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 08-19-2006 12:21 AM

Quote:

Originally Posted by acidburn0520
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 08-19-2006 12:37 AM

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 08-21-2006 12:02 AM

Quote:

Originally Posted by SirAdrian
PHP Code:

$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.

Quote:

<? 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.

Quote:

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.

Quote:

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 08-21-2006 03:20 AM

Thank you for the mod.... and keep them coming :D

Zas 08-21-2006 04:22 AM

Thanks a lot, it works perfectly. I needed this so I could display random banners.

zephy 09-13-2006 02:23 PM

Thanks for your Mod, like Zas I wanted something to display random banners :)

Kirk Y 09-13-2006 06:50 PM

Which can easily be done by using 1 Plugin...

papa_face 09-15-2006 04:57 PM

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.
Quote:

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 09-15-2006 05:48 PM

My mistake, i was using php blocks

Been Told 12-31-2006 02:06 PM

Thanks, just what I needed! :)

cageybee 01-08-2007 03:49 AM

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 01-08-2007 05:54 PM

Does this still work? I can't seem to include a file...

GameWizard 01-15-2007 03:33 AM

Found an alternative:
http://www.vbulletin.com/forum/showthread.php?t=173937

marinig 09-07-2007 09:33 PM

Quote:

Originally Posted by cageybee (Post 1153289)
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 09-08-2007 06:45 PM

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 09-08-2007 10:15 PM

I would be curious to know how much time this would add to a page's processing time.

CrazyCanuck 12-22-2007 01:43 PM

thanks for this addon

odonel 12-22-2007 02:23 PM

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 06-12-2008 06:11 PM

thanks alot, exactly what i was looking for!

Freddy.k 08-28-2008 05:25 PM

Merci cool

Hitterman 09-30-2008 10:25 AM

Its really awesomeeeeeee.e
Great work. really nice.
Hurray!!!!!!!!!!!
"Installed" & "Nominated" because it works with 3.7.x also.

GNeRaL 06-18-2009 01:42 PM

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 09-14-2009 04:31 PM

This is so cool, and works great, thanks

Spinball 01-24-2010 11:07 AM

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.


All times are GMT. The time now is 03:12 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01392 seconds
  • Memory Usage 1,827KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (2)bbcode_php_printable
  • (11)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (40)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete