The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
How-To Cache Templates
This article assumes that you are building your own product with end-user options. INTRODUCTORY ON CACHING TEMPLATES: Whenever you create a product you should cache your templates by adding them to the $globaltemplates and $actiontemplates array. $globaltemplates are templates loaded by all actions. $actiontemplates are templates loaded when a specified action is called such as $do (e.g. ?do=edit). TEMPLATES NOT CACHED: Quote:
To remedy this some coders add the uncached templates to the $globaltemplates array. However, this is the wrong way to do it. As a coder, our obligation is to cache the least amount of templates to consume less memory. *NOTE: This usually happens when you are redirected back to the page via $_POST. THE FIX: To cache these templates, we add the following: PHP Code:
EXAMPLE: A blog product that I am working on will display an error message to the end-user upon an error. The error message will be on the same page (redirected back via $_POST) not a STANDARD_ERROR page. The interface is full of options that at the very least requires the end-user to enter a TITLE and DESCRIPTION. The interface is accessible by the action "do=options". To cache the required templates to build the interface I add the templates to the $actiontemplates array such as: PHP Code:
whenever the end-user forgets to enter a TITLE an error message is displayed. (The system requires the title.) When the error message is displayed none of the templates are cached. We are missing something... To remedy this we need to look at the $_POST "do" action of the form. A closer look at the html source tells me that the "do" action is HTML Code:
<input name="do" value="insertsettings" type="hidden">
PHP Code:
The final code should look like this: PHP Code:
|
#22
|
||||
|
||||
Quote:
|
#23
|
||||
|
||||
good day,
i using that method to cache template i implented a postbit marqee hack and for some reason that method won't work. Code:
$globaltemplates[] = 'Postbit_Marquee'; thanks in advance. |
#24
|
|||
|
|||
I just cant get my head around adding "cache" to a product, to cache the templates.
Will you do me a favour Princeton or anybody else who knows how to do this. Take a look at my product code and add the cache code for me. So I can just paste it back in my XML file. Code:
<?xml version="1.0" encoding="ISO-8859-1"?> <product productid="ed2k_links_hack" active="1"> <title>eD2K Links Hack</title> <description>This will let you add eD2K Links to your forum board.</description> <version>1.0.0</version> <url>http://www.ed2k.biz</url> <dependencies><dependency dependencytype="vbulletin" minversion="3.6.0" maxversion="" /> </dependencies> <codes></codes> <templates> <template name="ed2k" templatetype="template" date="1133098897" username="eD2K" version="3.6.0"><![CDATA[<script type="text/javascript"> <!-- function checkAll(str,checked) { var a = document.getElementsByName(str); var n = a.length; for (var i = 0; i < n; i++) { a[i].checked = checked; } em_size(str); } function download(str, i, first) { var a = document.getElementsByName(str); var n = a.length; for (var i = i; i < n; i++) { if(a[i].checked) { window.location=a[i].value; if (first) timeout = 6000; else timeout = 500; i++; window.setTimeout("download('"+str+"', "+i+", 0)", timeout); break; } } } function copy(str) { var a = document.getElementsByName(str); var n = a.length; var ed2kcopy = document.getElementById("ed2kcopy_"+str) ed2kcopy.innerHTML = "" for (var i = 0; i < n; i++) { if(a[i].checked) { ed2kcopy.innerHTML += a[i].value; ed2kcopy.innerHTML += "<br />"; } } var rng = document.body.createTextRange(); rng.moveToElementText(ed2kcopy) rng.scrollIntoView(); rng.select(); rng.execCommand("Copy"); rng.collapse(false); } function em_size(str) { var a = document.getElementsByName(str); var n = a.length; try { var input_checkall = document.getElementById("checkall_"+str); var size = 0; input_checkall.checked = true ; for (var i=0; i < n; i++) { if (a[i].checked) { var piecesArray = a[i].value.split( "|" ); size += piecesArray[3]*1; } else { input_checkall.checked = false; } } test = document.getElementById("size_"+str); test.innerHTML = gen_size(size, 3, 2); } catch (e) { } } function gen_size(val, li, sepa ) { sep = Math.pow(10, sepa); li = Math.pow(10, li); retval = val; unit = 'Bytes'; if (val >= li*1000000000) { val = Math.round( val / (1099511627776/sep) ) / sep; unit = 'TB'; } else if (val >= li*1000000) { val = Math.round( val / (1073741824/sep) ) / sep; unit = 'GB'; } else if (val >= li*1000) { val = Math.round( val / (1048576/sep) ) / sep; unit = 'MB'; } else if (val >= li) { val = Math.round( val / (1024/sep) ) / sep; unit = 'KB'; } return val + unit; } // --> </script> <br /><table class="tborder" cellpadding="5" cellspacing="1" border="0" width="100%" align="center"> <thead><tr><td class="tcat" colspan="2">eD2K Links</td></tr></thead><tbody> $ed2kbit <tr align="left" class="alt$key2"><td width="80%" align="left"><input type="checkbox" id="checkall_ed2k$rand" onclick="checkAll('ed2k$rand',this.checked)" checked="checked"/><label for="checkall_ed2k$rand">Select All</label> <input type="button" value="Download Selected" onclick="download('ed2k$rand',0,1)" /> <input type="button" value="Copy Selected" onclick="copy('ed2k$rand')" /><div id="ed2kcopy_ed2k$rand" style="position:absolute;height:0px;width:0px;overflow:hidden;"></div></td><td align="center" id="size_ed2k$rand">Total Size: $total</td></tr></tbody></table>]]></template> <template name="ed2kbit" templatetype="template" date="1133028805" username="eD2K" version="3.6.0"><![CDATA[<tr align="left" class="alt$key1"><td width="80%" align="left"><input type="checkbox" name="ed2k$rand" value="$ed2k" onclick="em_size('ed2k$rand');" checked="checked" /><a href="$ed2k">$ed2k_array[2]</a></td><td align="center">$totalper</td></tr>]]></template> </templates> <plugins> <plugin active="1"> <title>eD2K Links Hack</title> <hookname>bbcode_fetch_tags</hookname> <phpcode><![CDATA[if ($vbulletin->options['allowedbbcodes'] & ALLOW_BBCODE_URL) { // [ED2K] $tag_list['no_option']['ed2k'] = array( 'callback' => 'handle_ed2k_links', ); }]]></phpcode> </plugin> </plugins> <phrases> </phrases> <options> </options> </product> |
#25
|
|||
|
|||
Thanks for the explanation. It worked for me too.
|
#26
|
||||
|
||||
If you have a lot of templates which may not necessarily be used, you can save resources that would be used to cache unneeded templates by instead caching them dynamically based on whether or not they are needed. This does assume a bit of knowledge, but it's commented for clarity.
Let's say you have 10 templates, all of which can be enabled or disabled individually via a yesno option in your plugin. I'll just display 3 for the example. PHP Code:
I would suggest using the microstats plugin to easily check everything is caching as it should. |
#27
|
||||
|
||||
I need a little help.
PHP Code:
|
#28
|
||||
|
||||
THIS_SCRIPT changes from file to file ...
at the top of any file you will find THIS_SCRIPT defined ... this is the value that needs to be used on the conditional |
#29
|
||||
|
||||
I used another plugin to cache this template with this code.
Code:
$globaltemplates = array_merge($globaltemplates, array('quickreply_addon')); |
#30
|
|||
|
|||
When writing my plugin code, the following doesn't work in the cache_templates hook (queries still added for uncached templates):
PHP Code:
PHP Code:
PHP Code:
PHP Code:
|
#31
|
|||
|
|||
Quote:
|
Thread Tools | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|