vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   serve template from filesystem instead of DB (https://vborg.vbsupport.ru/showthread.php?t=314471)

fxdigi-cash 09-22-2014 09:59 PM

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? :confused:

Thanks

Update: I made a mistake posting in vb3 section where this actually supposed to be on vb4

tpearl5 09-23-2014 12:58 AM

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 >>>'

nerbert 09-23-2014 01:30 AM

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()

fxdigi-cash 09-23-2014 05:00 AM

Quote:

Originally Posted by nerbert (Post 2516215)
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 (Post 2516213)
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?

kh99 09-23-2014 10:58 AM

Quote:

Originally Posted by nerbert (Post 2516215)
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.

fxdigi-cash 09-23-2014 02:05 PM

Quote:

Originally Posted by kh99 (Post 2516258)
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?? :(

tpearl5 09-23-2014 02:19 PM

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 (Post 2516258)
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.

Max Taxable 09-23-2014 05:09 PM

Quote:

Originally Posted by tpearl5 (Post 2516269)
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!

nerbert 09-23-2014 09:11 PM

Quote:

Originally Posted by kh99 (Post 2516258)
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

kh99 09-23-2014 10:25 PM

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.


All times are GMT. The time now is 06:41 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.01184 seconds
  • Memory Usage 1,813KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (2)bbcode_php_printable
  • (7)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete