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
  #32  
Old 05-21-2003, 06:01 PM
gmarik's Avatar
gmarik gmarik is offline
 
Join Date: May 2002
Location: Mocsow
Posts: 1,288
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
function gettemplate($templatename$escapecontents true,
    
$gethtmlcomments true$parsephp true)
{
    
// gets a template from the db or from the local cache
    
global $templatecache$DB_site$templatesetid$addtemplatename;
    
    
$templatesetid intval($templatesetid);
    if (isset(
$templatecache[$templatename]))
    {
        
$toreturn $templatecache[$templatename];
    }
    else
    {
        
$template $DB_site->query_first("SELECT template FROM template
            WHERE title = \"" 
addslashes($templatename) . "\"
            AND (templatesetid = -1 OR templatesetid = 
$templatesetid)
            ORDER BY templatesetid DESC LIMIT 1"
);
        
$toreturn $template['template'];
        
$templatecache[$templatename] = $toreturn;
    }
    
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 (
$parsephp) {
                    
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);
            }
        }

    if (
$parsephp// is this needed still?
    
{
        
// regex is mangled to avoid breaking stupid ides
        
$count preg_match_all("/<\?(.*)\?" ">/siU"$toreturn$matches);
        foreach (
$matches[1] as $match)
        {
            
// put vars in the global scope
            
preg_match_all("/\\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/",
            
$match$varnames);
            
$varnames implode(", "$varnames[0]);
            if (!empty(
$varnames)) eval("global $varnames;");         
            eval(
$match);
        }
        
        
str_replace($matches[0], ""$toreturn);
    }       

    if (
$escapecontents)
    {
        
$toreturn addslashes($toreturn);
        
$toreturn str_replace("\'""'"$toreturn);
    }
    
    if (
$gethtmlcomments and $addtemplatename)
    {
        
$charcount strlen($templatecache[$templatename]) .
            
" chars originally";
        
$phpcount = ($parsephp ", $count embedded PHP tags" "");
        
        return 
"<!-- begin template \"$templatename\" ($charcount$phpcount) " .
            
"-->\n$toreturn\n<!-- END TEMPLATE: $templatename -->";
    }
    return 
$toreturn
Reply With Quote
  #33  
Old 05-21-2003, 07:34 PM
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Location: Maryland, US
Posts: 6,144
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The template, not the PHP in gettemplate...
Reply With Quote
  #34  
Old 05-21-2003, 07:34 PM
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Location: Maryland, US
Posts: 6,144
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You're also not using my original hack, so I support it even less...
Reply With Quote
  #35  
Old 05-21-2003, 11:18 PM
bryanzera bryanzera is offline
 
Join Date: May 2003
Posts: 2
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm not getting this to work either. Such is my code:

Quote:
<a href='http://www.pollstar.com/member/index.cgi?Premium=1&From=http://forums.pollstar.com<? return getenv('REQUEST_URI') ?>'>Log in to Pollstar Premium now!</a>
what I get is this in my link field:

Quote:
http://www.pollstar.com/member/index.cgi?Premium=1&From=http://forums.pollstar.com<? return getenv(
Is the getenv out of this hack's scope?
Reply With Quote
  #36  
Old 05-21-2003, 11:20 PM
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Location: Maryland, US
Posts: 6,144
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This hack doesn't work this way. All it does is blindly execute the code in the tags and a return statement will confuse the hell out of it.

Instead use:
Code:
...<? $something = getenv("REQUEST_URI"); ?>$something...
Reply With Quote
  #37  
Old 05-21-2003, 11:39 PM
bryanzera bryanzera is offline
 
Join Date: May 2003
Posts: 2
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Still doesn't seem to work right. this code:

Quote:
<a href='http://www.pollstar.com/member/index.cgi?Premium=1&From=http://forums.pollstar.com <? $something = getenv("REQUEST_URI"); ?>$something'>Log in to Pollstar Premium now!</a>
gives this url:

Quote:
http://www.pollstar.com/member/index.cgi?Premium=1&From=http://forums.pollstar.com <? = getenv("REQUEST_URI"); ?>
Reply With Quote
  #38  
Old 05-21-2003, 11:40 PM
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Location: Maryland, US
Posts: 6,144
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Make sure you're using my original hack and not the one you quoted.
Reply With Quote
  #39  
Old 05-22-2003, 04:01 AM
gmarik's Avatar
gmarik gmarik is offline
 
Join Date: May 2002
Location: Mocsow
Posts: 1,288
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Filburt. Doent know why,
but your origianl hack does not works in ant way.
Our ou should write a manual, how to use it.

I need to write freely php code in every template, can I do it?
Reply With Quote
  #40  
Old 05-30-2003, 03:36 PM
GameZilla GameZilla is offline
 
Join Date: Oct 2001
Posts: 56
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

anyawy so that i can include files
cause when do it just displays on top no matter where i put the code
Reply With Quote
  #41  
Old 05-30-2003, 06:53 PM
gmarik's Avatar
gmarik gmarik is offline
 
Join Date: May 2002
Location: Mocsow
Posts: 1,288
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

GameZilla,
All you need is all I need.
I don't care how - it must work as an ordinary php file!!
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:16 AM.


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.04439 seconds
  • Memory Usage 2,335KB
  • Queries Executed 25 (?)
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
  • (4)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
  • (4)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_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