Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > vBulletin 2.x > vBulletin 2.x Full Releases

Reply
 
Thread Tools
Embed PHP in Templates Details »»
Embed PHP in Templates
Version: 1.00, by filburt1 filburt1 is offline
Developer Last Online: May 2007 Show Printable Version Email this Page

Version: 2.3.x Rating:
Released: 05-10-2003 Last Update: Never Installs: 16
 
No support by the author.

This hack lets you embed PHP code in templates. Simply add your code between a <? (not a <?php) and ?> tag and it will be eval'ed. All variables will be referenced in the global scope.

If you're using my Usergroup Tags in Templates hack then you're going to have an extraordinarily difficult time installing this hack. However the clever hacker can tell what has changed in this version.

You can somewhat use this to do conditionals in templates. Theoretically, this will work:

Code:
template...
<? $myvar = ($condition ? $truevalue : $falsevalue); ?>$myvar
...more template...
Just make sure that the variable to the left of the = and the variable right after the ?> match. Note that the entire <? and ?> tag itself will be stripped from the final template.

This hack also enhances the comments delimiting templates (if that option is turned on) to include the character count and PHP block count of the specified template.

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #12  
Old 05-11-2003, 03:39 PM
Dean C's Avatar
Dean C Dean C is offline
 
Join Date: Jan 2002
Location: England
Posts: 9,071
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

N9ne - its called a ternary operator i believe

I'm very interested to see how this develops as IMO i think we'll see a lot of PHP errors popping up now on vBulletin.org due to poor PHP coding in the templates

- miSt
Reply With Quote
  #13  
Old 05-11-2003, 04:45 PM
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Location: Maryland, US
Posts: 6,144
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Today at 05:29 AM N9ne said this in Post #6
Very nice filby! Is this efficient?
Theoretically it is only limited by the speed of the preg functions.
Reply With Quote
  #14  
Old 05-11-2003, 04:54 PM
mx3's Avatar
mx3 mx3 is offline
 
Join Date: Nov 2002
Location: prescott valley, az
Posts: 278
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

awesome! will install! i've been wanting this for awhile now!
Reply With Quote
  #15  
Old 05-11-2003, 07:45 PM
all-the-vb's Avatar
all-the-vb all-the-vb is offline
 
Join Date: Apr 2003
Location: Norwich,Uk
Posts: 174
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

nice work


All-the-vb click install
Reply With Quote
  #16  
Old 05-11-2003, 09:04 PM
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Location: Maryland, US
Posts: 6,144
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Pseudo-code of what it does:

1. Find every occurance of <? and ?> (and what's inbetween them)
2. For each occurance, make every variable within in the global scope, and then eval what's in the occurance
3. Remove the original occurances from the template.
Reply With Quote
  #17  
Old 05-11-2003, 09:29 PM
grog6's Avatar
grog6 grog6 is offline
 
Join Date: Apr 2002
Location: France
Posts: 328
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

And so, no need to modify PHP files to create new hack (even if I'll continue to modify the php files for my new hack, but this can be usefull for some modifications )

[high]* grog6 cliks install too
[/high]
Thx for it Filburt
Reply With Quote
  #18  
Old 05-12-2003, 08:40 AM
Chris M's Avatar
Chris M Chris M is offline
 
Join Date: Dec 2001
Location: Northampton, England
Posts: 6,186
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Very nice filby

Satna
Reply With Quote
  #19  
Old 05-12-2003, 09:09 AM
mossyuk mossyuk is offline
 
Join Date: Jul 2002
Posts: 35
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Very nice, thanks! :bunny: :banana:
Reply With Quote
  #20  
Old 05-13-2003, 09:45 AM
Slynderdale Slynderdale is offline
 
Join Date: Mar 2002
Location: New York State
Posts: 576
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

nice hack, I fixed it slightly though to suit my needs:
PHP Code:
        if (substr_count($template,'?'.'>')>=or substr_count($template,'php?'.'>')>=or substr_count($template,'</php>')>=1) {
            while (
preg_match("/(\<\?php|\<\?|\<php\>)(\r\n)*(.*)(\r\n)*(php\?"."\>|\?"."\>|\<\/php\>)/siU"$template$matches)) {
                if (
$parse_phpcode) {
                    
preg_match_all("/\\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/"$matches[3], $varnames);
                    
$varnames implode(", "$varnames[0]);
                    if (!empty(
$varnames)) {
                        @eval(
"global $varnames;");
                    }
                    
$eval_result = @eval(stripslashes($matches[3]));
                } else 
$eval_result "";
                
$template str_replace($matches[0], $eval_result$template);
            }
        } 
You can now use:
<? ?>
<?php php?>
<php></php>

and any combinations of them, such as:
<?php ?>

and so on.

Also now if you use return(stuff here); in the php script, it returns the data straight to the template itself. Like:
<?
$stuff = "stuff";
return $stuff;
?>

would return the $stuff varible right into the template for you.
Reply With Quote
  #21  
Old 05-13-2003, 11:20 AM
kaotic's Avatar
kaotic kaotic is offline
 
Join Date: Mar 2003
Posts: 259
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Odd... the following code doesn't seem to work:

Code:
<?
$default = "home";
if($page == ""){$page = $default;}elseif(isset($page)){$page = $page;}
?>
<?
include ("$page.html");
?>
What have I done wrong?
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:05 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05558 seconds
  • Memory Usage 2,315KB
  • Queries Executed 27 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (2)bbcode_code
  • (1)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (3)pagenav_pagelink
  • (11)post_thanks_box
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete