Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 09-22-2014, 09:59 PM
fxdigi-cash fxdigi-cash is offline
 
Join Date: Jul 2012
Posts: 674
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default serve template from filesystem instead of DB

Hi,

I'm trying to serve the template from filesystem instead of DB so I followed this short tut here: http://www.vbulletin.com/forum/forum...to-file-system

there is another tut has been around for a while, but it doesn't work anymore since vb has made a lot of updates and changes: http://www.go4expert.com/articles/ex...-files-t25345/

what I did is the following:

1- created a folder in the root named template_dump with CHmod 0777
2- turned on your debug mode $config['Misc']['debug'] = true;
3- created the files visiting this url on my forum: http://FORUM_NAME.com/admincp/template.php?do=createfiles&dostyleid=your_active_ style

4- moved the folder template_dump to under includes ( includes/vb_templates )
5- in includes/class_core.php --> replaced protected static function fetch_template($template_name) with can protected static function file_get_contents (DIR. '/includes/vb_templates/'.$template_name.'htm')

after all that my forum doesn't work... sounds like there is something wrong...

any idea what's going on?

Thanks

Update: I made a mistake posting in vb3 section where this actually supposed to be on vb4
Reply With Quote
  #2  
Old 09-23-2014, 12:58 AM
tpearl5's Avatar
tpearl5 tpearl5 is offline
 
Join Date: Nov 2001
Location: PA
Posts: 1,014
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Did you do your active style and -1 for the master style? Otherwise you will only get templates that are different from the master style.

Not to mention you can't just replace the function with "file_get_contents" - now you have a function named "file_get_contents".

I would play around with the fetch_template_start hook and try putting in the code from the second page:
PHP Code:
    if ($template == '<<< FILE >>>')
    {
        
$template addslashes(implode(''file("./templates/$template_name.htm")));
        
$vbulletin->templatecache["$template_name"] = $template;
    } 
(note that $templatename is now $template_name)

Then create the child style '<<< FILE >>>'
Reply With Quote
2 благодарности(ей) от:
fxdigi-cash, ozzy47
  #3  
Old 09-23-2014, 01:30 AM
nerbert nerbert is offline
 
Join Date: May 2008
Posts: 784
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I would restore your file includes/class_core.php back to original and create this plugin for fetch_template_start:

Code:
 
		if (!$fetched)
		{
			if (isset($vbulletin->templatecache["$template_name"]))
			{
				$template = $vbulletin->templatecache["$template_name"];
			}
			else
			{
				self::$template_queries[$template_name] = true;
				$fetch_tid = intval($templateassoc["$template_name"]);
				if (!$fetch_tid)
				{
					$gettemp = array('template' => '');
				}
				else
				{
					$gettemp = $vbulletin->db->query_first_slave("
						SELECT template
						FROM " . TABLE_PREFIX . "template
						WHERE templateid = $fetch_tid
					");
				}
				$template = $gettemp['template'];
				$vbulletin->templatecache["$template_name"] = $template;
			}
		}

		if (!isset(self::$template_usage[$template_name]))
		{
			self::$template_usage[$template_name] = 1;
		}
		else
		{
			self::$template_usage[$template_name]++;
		}

		/////////($hook = vBulletinHook::fetch_hook('fetch_template_complete')) ? eval($hook) : false;

		return $template;
That code is a straight copy/paste out of the file itself with the fetch_template_complete hook commented out (Idon't think you can have a hook in a plugin). Now the plugin code finishes the function (method, for you purists) and everything should run.

Now try playing around with commenting out the database query and replacing it with file_get_contents(). You should actually open, lock, read and unlock the file instead of just reading it with f_g_c()
Reply With Quote
3 благодарности(ей) от:
fxdigi-cash, Max Taxable, ozzy47
  #4  
Old 09-23-2014, 05:00 AM
fxdigi-cash fxdigi-cash is offline
 
Join Date: Jul 2012
Posts: 674
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by nerbert View Post
I would restore your file includes/class_core.php back to original and create this plugin for fetch_template_start:

Code:
 
        if (!$fetched)
        {
            if (isset($vbulletin->templatecache["$template_name"]))
            {
                $template = $vbulletin->templatecache["$template_name"];
            }
            else
            {
                self::$template_queries[$template_name] = true;
                $fetch_tid = intval($templateassoc["$template_name"]);
                if (!$fetch_tid)
                {
                    $gettemp = array('template' => '');
                }
                else
                {
                    $gettemp = $vbulletin->db->query_first_slave("
                        SELECT template
                        FROM " . TABLE_PREFIX . "template
                        WHERE templateid = $fetch_tid
                    ");
                }
                $template = $gettemp['template'];
                $vbulletin->templatecache["$template_name"] = $template;
            }
        }

        if (!isset(self::$template_usage[$template_name]))
        {
            self::$template_usage[$template_name] = 1;
        }
        else
        {
            self::$template_usage[$template_name]++;
        }

        /////////($hook = vBulletinHook::fetch_hook('fetch_template_complete')) ? eval($hook) : false;

        return $template;
That code is a straight copy/paste out of the file itself with the fetch_template_complete hook commented out (Idon't think you can have a hook in a plugin). Now the plugin code finishes the function (method, for you purists) and everything should run.

Now try playing around with commenting out the database query and replacing it with file_get_contents(). You should actually open, lock, read and unlock the file instead of just reading it with f_g_c()
Thanks for the solution...

I'm somehow new to this so not sure what database query I should be replacing with file_get_contents()

can you give an example?

--------------- Added [DATE]1411452481[/DATE] at [TIME]1411452481[/TIME] ---------------

Quote:
Originally Posted by tpearl5 View Post
Did you do your active style and -1 for the master style? Otherwise you will only get templates that are different from the master style.

Not to mention you can't just replace the function with "file_get_contents" - now you have a function named "file_get_contents".

I would play around with the fetch_template_start hook and try putting in the code from the second page:
PHP Code:
    if ($template == '<<< FILE >>>')
    {
        
$template addslashes(implode(''file("./templates/$template_name.htm")));
        
$vbulletin->templatecache["$template_name"] = $template;
    } 
(note that $templatename is now $template_name)

Then create the child style '<<< FILE >>>'

Thanks mate for the quick solution.

I have done the steps as you instructed me. now only thing is how do I know it is working or not?? how do I test it?
Reply With Quote
  #5  
Old 09-23-2014, 10:58 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by nerbert View Post
That code is a straight copy/paste out of the file itself with the fetch_template_complete hook commented out (Idon't think you can have a hook in a plugin). Now the plugin code finishes the function (method, for you purists) and everything should run.
I don't think that quite works as expected because calling return in a plugin doesn't return from the function that calls it, it provides a return value from the 'eval' call (which is ignored). But as you can see in the code above, there's a "fetched" variable, and if the plugin sets that to true then the database query (or cache lookup) won't be done. So I think you'd want your plugin to include only the code from inside the "if", then set $fetched to true.

Edit: I think tpearl's code would work because the code in fetch_template() gets it from the cache if it's set.
Reply With Quote
Благодарность от:
fxdigi-cash
  #6  
Old 09-23-2014, 02:05 PM
fxdigi-cash fxdigi-cash is offline
 
Join Date: Jul 2012
Posts: 674
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
I don't think that quite works as expected because calling return in a plugin doesn't return from the function that calls it, it provides a return value from the 'eval' call (which is ignored). But as you can see in the code above, there's a "fetched" variable, and if the plugin sets that to true then the database query (or cache lookup) won't be done. So I think you'd want your plugin to include only the code from inside the "if", then set $fetched to true.

Edit: I think tpearl's code would work because the code in fetch_template() gets it from the cache if it's set.
Thanks mate for the confirmation. I used tpearl's code now as I want to test how it performs. I believe setting the debug mode will tell me whether things work or not...

not sure of another way on how to test it though.

any idea??
Reply With Quote
  #7  
Old 09-23-2014, 02:19 PM
tpearl5's Avatar
tpearl5 tpearl5 is offline
 
Join Date: Nov 2001
Location: PA
Posts: 1,014
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

yep, setting debug mode should tell you where the templates are being read from in the bottom dropdown...

--------------- Added [DATE]1411485646[/DATE] at [TIME]1411485646[/TIME] ---------------

Quote:
Originally Posted by kh99 View Post
I don't think that quite works as expected because calling return in a plugin doesn't return from the function that calls it, it provides a return value from the 'eval' call (which is ignored). But as you can see in the code above, there's a "fetched" variable, and if the plugin sets that to true then the database query (or cache lookup) won't be done. So I think you'd want your plugin to include only the code from inside the "if", then set $fetched to true.

Edit: I think tpearl's code would work because the code in fetch_template() gets it from the cache if it's set.
I was about to say the same thing.


fyi, vb optimise has a feature to do all of this and/or read templates from the cache of your choice.
Reply With Quote
  #8  
Old 09-23-2014, 05:09 PM
Max Taxable's Avatar
Max Taxable Max Taxable is offline
 
Join Date: Feb 2011
Posts: 3,134
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by tpearl5 View Post
fyi, vb optimise has a feature to do all of this and/or read templates from the cache of your choice.
That's exactly what I use, and do.... And had forgotten about it!
Reply With Quote
  #9  
Old 09-23-2014, 09:11 PM
nerbert nerbert is offline
 
Join Date: May 2008
Posts: 784
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
I don't think that quite works as expected because calling return in a plugin doesn't return from the function that calls it, it provides a return value from the 'eval' call (which is ignored). But as you can see in the code above, there's a "fetched" variable, and if the plugin sets that to true then the database query (or cache lookup) won't be done. So I think you'd want your plugin to include only the code from inside the "if", then set $fetched to true.

Edit: I think tpearl's code would work because the code in fetch_template() gets it from the cache if it's set.
Well, you got me curous so I tested it

Code:
if (!$fetched)
		{
			if (isset($vbulletin->templatecache["$template_name"]))
			{
				$template = $vbulletin->templatecache["$template_name"];
			}
			else
			{
				self::$template_queries[$template_name] = true;
				$fetch_tid = intval($templateassoc["$template_name"]);
				if (!$fetch_tid)
				{
					$gettemp = array('template' => '');
				}
				else
				{
					$gettemp = $vbulletin->db->query_first_slave("
						SELECT template
						FROM " . TABLE_PREFIX . "template
						WHERE templateid = $fetch_tid
					");
				}
				$template = $gettemp['template'];
				$vbulletin->templatecache["$template_name"] = $template;
			}
		}

		if (!isset(self::$template_usage[$template_name]))
		{
			self::$template_usage[$template_name] = 1;
		}
		else
		{
			self::$template_usage[$template_name]++;
		}

		($hook = vBulletinHook::fetch_hook('fetch_template_complete')) ? eval($hook) : false;
		echo 'before return<br>';
		return $template;
		echo 'after return';
And in hook fetch_template_complete I just put in

echo 'test hook<br>';

and got many echos of
test hook
before return
test hook
test hook
before return
test hook
test hook
Reply With Quote
  #10  
Old 09-23-2014, 10:25 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well yeah, "return" ends the plugin execution, but what I was saying is that it doesn't end the execution of fetch_template(), so if your plugin code doesn't set $fetched to true or set $vbulletin->templatecache["$template_name"], then fetch_template will go on and do it's work. And even if the plugin does one of those things, I don't think you'd want to increment the usage count since that will happen in any case.

Edit: I think I misunderstood the above post - what I was saying is if you were to for instance create a plugin that just contained a return, that wouldn't stop the rest of fetch_template from running. It's not exactly the same as insertng the code at the point the hook is eval'd. Also if the hook is called inside a loop you can't break or continue that loop from the plugin.

Maybe you knew all that and you assumed the code would be changed to remove that stuff, but I thought it could be clarified. Or maybe I'm missing something.
Reply With Quote
Reply

Thread Tools
Display Modes

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 09:55 PM.


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.05388 seconds
  • Memory Usage 2,294KB
  • Queries Executed 13 (?)
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
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_code
  • (2)bbcode_php
  • (7)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (6)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (3)post_thanks_postbit
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (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_postinfo_query
  • fetch_postinfo
  • 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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete