Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > General > Member Archives
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Details »»

Version: , by (Guest)
Developer Last Online: Jan 1970 Show Printable Version Email this Page

Version: Unknown Rating:
Released: 10-20-2000 Last Update: Never Installs: 0
 
No support by the author.

I was experimenting with reading template from disk instead of the database. Following is my instructions on how to do this if you want to try it on your forum and see if it helps or makes it worse. Let me know if you try it, it does work as it is running on my forum at the moment but I can't say if it helped as my forum is small.

first
Make a directory called templates under your forums directory. If you don't have access to write files from php you will need to do this also:

chmod 777 templates

Next place this code in a file, temp.php and run it from your browser. It will take your templates and place them in files in the templates directory. Make sure to run it from your forums directory

Quote:
<?
$tempdir = "templates/";

require ("global.php");

$query = $DB_site->query("SELECT title, template FROM template");
while ($q = $DB_site->fetch_array($query))
{
$template = $tempdir . $q[title] . ".inc.php";
$fp = fopen($template, "w");
if ($fp)
{
fwrite($fp, $q[template]);
echo "Created $q[title].inc.php<br>";
}
else
{
echo "Error opening $q[title].inc.php<br>";
}
}
NEXT

Edit global.php

Look for ###################### Start gettemplate #######################

Remove everything between that line and this line
###################### Start verifyid #######################

In between those two lines place in :

Quote:
function gettemplate($templatename,$escape=1) {
// gets a template from the db or from the local cache
global $templatecache,$DB_site;

if (!$templatecache[$templatename])
{
$template = "templates/" . $templatename . ".inc.php";
$x = error_reporting();
error_reporting (0);
$file = fopen($template, "r");
$rf = fread($file, filesize ($template));
if(!$rf)
{
$template = "Error Opening Template $templatename.inc.php";
}
else
{
$template = $rf;
fclose($file);
}
error_reporting ($x);
if ($escape==1) {
$template=str_replace("\"","\\\"",$template);
}
$templatecache["$templatename"]=$template;
}
else
{
$template = $templatecache[$templatename];
}
return $template;
}
NEXT
Look for
Quote:
// ###################### Start templates #######################
//prepare default templates **********************
$temps=$DB_site->query("SELECT template,title FROM template WHERE title='cssinclude' OR title='header' OR title='footer' OR title='fivelinks' OR title='jumpforumbit' OR title='forumjump'");
while ($temp=$DB_site->fetch_array($temps)) {
$templatecache["$temp[title]"]=$temp[template];
}
Remove it or comment it all out.

Let me know!

Show Your Support

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

Comments
  #2  
Old 10-20-2000, 03:22 PM
Guest
 
Posts: n/a
Default

Hello Rangersan,

Thanks.

A couple of questions:

1. Right now I'm using Stallions DOSR.php template hack that writes all the templates to the .php scripts on execution. Is this hack faster? Better? why?

2. If I use your hack and update my templates through the web browser admin terminal, do I have to run the temp.php script again to copy the templates to the template directory?

Thanks again.
Reply With Quote
  #3  
Old 10-20-2000, 05:00 PM
Guest
 
Posts: n/a
Default

1. I have not seen that hack so I have no comment.

2. Yes you would have to run temp.php or just edit the templates files in the template directory.

3. I don't know if this will help or hurt performance so back up global.php before you try it out.
Reply With Quote
  #4  
Old 10-20-2000, 05:03 PM
Guest
 
Posts: n/a
Default

sorry...Stallion calls it his "Template Opt 1.0"
Reply With Quote
  #5  
Old 10-20-2000, 09:00 PM
Guest
 
Posts: n/a
Default

it's faster to have them in the actual php file rather than including them from disk.
Reply With Quote
  #6  
Old 10-20-2000, 10:42 PM
Guest
 
Posts: n/a
Default

Doron yes it would be but you can't have templates if they are to be stored in the php files themselves, kind of throws the whole template idea out the window.

Jim your referring to the template cache hack? I incorporated cacheing into this one also. Again I didn't say it would help, it would just be interesting to see if it is faster or slower on a big forum.

The question is: Is it quicker to read the template from disk or to retrieve the template via SQL. Does this change when 100 people are grabbing the template from disc vs 100 people grabbing the template from MySql.
Reply With Quote
  #7  
Old 10-21-2000, 07:07 PM
Guest
 
Posts: n/a
Default

the topti hack does just that - it manually adds the new templates into the php files.
Reply With Quote
  #8  
Old 10-21-2000, 08:57 PM
Guest
 
Posts: n/a
Default

Excuse me Doron but I assume you are talking about this hack :
http://www.vbulletin.org/hacks/hacks...=gethack&id=27


For any page that includes global.php this hack loads all the templates and places them in an array that is called using the gettemplate function.

Your usage of the verbage "it's faster to have them in the actual php" implies that the templates are not ever read from anything as they are stored in the actual PHP vBulletin files which, obviously, is not the case.

If you don't understand my hack functions EXACTLY like stallions hack except instead of loading all the templates for every new page, which is what is done whenever global.php is called. It only loads the templates needed for that page from disk and caches any template that is needed more than once (i.e. forumbit, postbit, etc).

The question I was looking at is: is it quicker to A. load all templates into a cache via mysql as topti does or is it quicker to include only the templates from disk that are needed for each page and cache them if they are used more than once.

It was only meant as a case study but Doron you have hopelessly confused everybody as to what it does vs. what topti actually does.

[Edited by rangersfan on 10-21-2000 at 06:02 PM]
Reply With Quote
  #9  
Old 10-22-2000, 04:13 AM
Guest
 
Posts: n/a
Default

Actually

That hack is tOpti 2.0.

VirtueTech has tOpti 1.0, which actually stores the templates (HTML code and all) directly inside the .php files. When you update your templates (from the web admin, as normal) you just need to run a file, and all the SQL calls are once again replaced with the HTML.

It has yet to be released, since he encountered a small bug regarding JavaScript code being escaped, but I will get around to it. As far as which hack is faster, I doubt it can get any faster than the way 1.0 handles it, but there's plenty of room to make it "cleaner".

So, Doron was right in talking about tOpti 1.0, and you were right talking about tOpti 2.0.
Reply With Quote
  #10  
Old 10-22-2000, 04:58 AM
Guest
 
Posts: n/a
Default

Well yes putting the templates into the actual php file would be the quickest way to do it and it all makes sense now.

It doesn't really matter to me because if you only have a maximum of 12 users online ever then these issues are unimportant to one
Reply With Quote
Reply


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 01:03 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05580 seconds
  • Memory Usage 2,268KB
  • Queries Executed 23 (?)
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
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (9)postbit
  • (10)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
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete