Originally Posted by orban
(Post 1157214)
EXPERIMENTAL (for your dev board)
This will NEVER work with plugins who modify templates on run time so don't even try :)
Place the function in a file & create forums/cache folder
Code:
function cache_templates_one_file($templates, $templateidlist)
{
global $vbulletin, $templateassoc;
if (empty($templateassoc))
{
$templateassoc = unserialize($templateidlist);
}
if ($vbulletin->options['legacypostbit'] AND in_array('postbit', $templates))
{
$templateassoc['postbit'] = $templateassoc['postbit_legacy'];
}
foreach ($templates AS $template)
{
$templateids[] = intval($templateassoc["$template"]);
}
/* THE ACTUAL PLUGIN */
$templatefile = 'cache/'.md5(implode(',', $templateids)).'.php';
if (file_exists($templatefile))
{
include($templatefile);
}
else
{
$templatecache = '';
/* END ACTUAL PLUGIN */
// run query
$temps = $vbulletin->db->query_read("
SELECT templateid, title, template
FROM " . TABLE_PREFIX . "template
WHERE templateid IN (" . implode(',', $templateids) . ")");
// cache templates
while ($temp = $vbulletin->db->fetch_array($temps))
{
/* START ACTUAL PLUGIN */
preg_match_all('/\$[a-zA-Z][a-zA-Z\_0-9]+/', $temp['template'], $out);
$vars = array_unique($out[0]);
$templatecache .= '
/* '.$temp['title'].' */ $template_vars['.$temp['templateid'].'] = \''.implode(', ', $vars).'\'; function template_'.$temp['templateid'].'('.implode(', ', $vars).') { return "'.$temp['template'].'"; } ';
/* END ACTUAL PLUGIN */
}
$vbulletin->db->free_result($temps);
/* START ACTUAL PLUGIN */
$fp = fopen($templatefile, 'w+');
if ($fp && flock($fp, LOCK_EX))
{
fwrite($fp, '<?php '.$templatecache.' ?>');
flock($fp, LOCK_UN);
fclose($fp);
}
include($templatefile);
/* END ACTUAL PLUGIN */
}
foreach ($templates AS $template)
{
if (substr($template, 0, 17) == 'editor_jsoptions_' or substr($template, 0, 14) == 'editor_styles_')
{
$vbulletin->templatecache[$template] = call_user_func('template_'.intval($templateassoc["$template"]));
}
else $vbulletin->templatecache[$template] = '".template_'.intval($templateassoc["$template"]).'('.$template_vars[intval($templateassoc["$template"])].')."';
#$vbulletin->templatecache[$template] = '';
}
$vbulletin->bbcode_style = array(
'code' => &$templateassoc['bbcode_code_styleid'],
'html' => &$templateassoc['bbcode_html_styleid'],
'php' => &$templateassoc['bbcode_php_styleid'],
'quote' => &$templateassoc['bbcode_quote_styleid']
);
}
And call it in "cache_templates" hook (adjust the path for the file with the function in it)
Code:
include('includes/functions_hooks.php');
cache_templates_one_file($globaltemplates, $style['templatelist']);
$globaltemplates = array();
does not delete cache when modifying templates and no options in it, please
ONLY USE THIS IF YOU KNOW WHAT YOU ARE DOING and understand the code
It basically reads all templates and creates a function for every template with all the variables in it passed as arguments so you can avoid scope issues.
Please note this takes up A LOT of space in xcache/APC (about 40mb for the cache/ files alone) so make sure you have enough space allocated (I'm using 128mb atm and that works fine).
Again please don't install this if you don't know PHP well and know what you're doing. Just sharing this because I've been using it for a few days successfully and maybe somebody can use it. :) This mod doesn't modify the database or any vB files (like the version you can download).
|