Version: 1.00, by filburt1
Developer Last Online: May 2007
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:
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.
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,'?'.'>')>=1 or substr_count($template,'php?'.'>')>=1 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);
}
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>