vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Community Lounge (https://vborg.vbsupport.ru/forumdisplay.php?f=13)
-   -   How Long is your PHP_INCLUDE START template? (https://vborg.vbsupport.ru/showthread.php?t=71088)

Xenon 10-28-2004 08:13 PM

there may be people who like hacking more than editing templates ;)

also if he made some scriptspecific things in phpinclude it doesn't look that well

Michael Morris 10-29-2004 12:36 AM

Heh heh,

Well, another reason it's so long is I LOVE whitespace and making the code both nice to look at as well as functioning. Many of the lines are simply { because I leave those to themselves.

I also have a LOT of commentary text so that if anyone comes in after me they can see what it does.

As an example, here's the first section...

PHP Code:

/*==============================================*\
|| ############################################ ||
|| # Startup Proceedures for Vbulletin Boards # ||
|| #         at Wizards of the Coast          # ||
|| # ---------------------------------------- # ||
|| #   Created for Wizards of the Coast by    # ||
|| #           Michael Lloyd Morris           # ||
|| #           email mlmorr0@uky.edu          # ||
|| # ---------------------------------------- # ||
|| #    This is a PHPINCLUDE_START template   # ||
|| ############################################ ||
\*==============================================*/

// ###############################################
// ##### HANDLE $_REQUESTs #######################
// ###############################################

// Launch Did You Know Pop Up
if (($_REQUEST['do'] == 'didyouknow') AND (THIS_SCRIPT == 'index'))
    {
        
$tip rand(1,15);
        
$tip 'didyouknow_' $tip;
        eval(
'$tipoftheday = "' fetch_template($tip) . '";');    
        eval(
'print_output("' fetch_template('DIDYOUKNOW') . '");');        
    }

// Move thread to Admin Forum preset
if (($_REQUEST['do'] == 'moveadmin') AND (THIS_SCRIPT == 'postings'))
    {
        
$_REQUEST['do'] = 'domovethread';
        
$_POST['do'] = 'domovethread';
        
$_POST['forumid'] = '399';
        
$_POST['method'] = 'move';
    } 

I've found that since PHP_INCLUDE start runs before any other templates or the remainder of the various vbulletin scripts it's the perfect time to intercept special $_REQUEST and $_POST variables and reassign them. The pop-up launcher is the cleanest example of this since it terminates the execution of the rest of the index script immediately when it makes the Print Output call. You can actually create whole new pages that way if you really want to. From a processing standpoint the pop-up makes sense in the PHPINCLUDE_START template since it doesn't need the $header, $footer or any other templates - just the custom DIDYOUKNOW templates.

The second item more cleanly allows the move thread presets. It's actually the 2nd version of a hack I've released and if you make a lot of thread moves it comes highly recommended.

The rest of the script does these things (just copying the commentary text...)

PHP Code:

// ###############################################
// ##### DEFINE FUNCTIONS USED IN TEMPLATE #######
// ###############################################

// ###############################################
// ##### MAIN PAGES INITIALIZATION  ##############
// ###############################################

// #### Prepare $banner array #########################

// #### Merge custom display information into $show ##########

// #### Set Defaults ################################

// ##### PARSE GLOBAL MENU TEMPLATE  #################

// ###############################################
// ##### START ANNOUNCMENTS  #####################
// ###############################################

// ###############################################
// ##### START USER SETTINGS  ####################
// ###############################################

    // #### Set Postbit ##########################
            
    // #### Set Left Column ######################

    // #### Set New Posts in Bold ################

    // #### Set Subscribed in Italics ############

    // #### Set Thread Previews ######################

    // #### Set Display Member Info at top ###########
            
    // #### Set Variable Display Width ###############

    // #### Set Forum Icon Display ###################
            
    // #### Set Tip Launcher ###################

    // #### FORUMHOME User Info ######################
        
// ###############################################
// ##### MISC ACTIONS B4 PARSING HEADERS  ########
// ###############################################

// Turn Left Columns off if we're on an editor interface

// ###############################################
// ##### START HEADERS  ##########################
// ###############################################

// ##### Forumhome ###############################

        // Parse the Forumhome greeting

        //Set the left column to false - this page has a left colum, but unlike 
        //other pages the forumhome template creates the column without the header template doing so.
        //This page is also unaffected by the status of $show['leftcolumn']

// ##### RPGA ####################################

        //Set the Banner

        //RPGA has multiple subforums with slightly different heights
        //and not all allow the navbar to slide under them.
        
        //Living Greyhawk

        //Living Force

        //RPGA Default

        //Set Items which apply to all three banners

// ##### Dungeons & Dragons #######################

        //Set the Banner

        //Set the Left Column if required

                //The D&D styleset has multiple left menus depending on the header
                //The code below changes the left menu depending on the header called.
                
                //Forgotten Realms

                //Eberron

                //D&D Miniatures

                //D&D Main

// ##### Magic: The Gathering #####################

                //This small program determines the date of the Monday that started this week.
                //We need it to determine the file name of the MtG header used in most MtG areas.
                //I think this is going to be good but it might screw up during a change of year.


                // The file name requires leading zeros, so let's add them as necessary.    
            
                // Done. Spit out the filename and evaluate the rest of the MtG header.

        // MtG: Online has a different header that doesn't change weekly.

        // Now let's attend to the prep shared by MtG and MtG Online
        //Parse the lower Magic Menu.

// ##### Duel Masters #############################

// ##### NeoPets ##################################

// ##### MLB Showdown ##############################

// ##### Star Wars TCG ##############################

// ##### Star Wars RPG ##############################

// ##### Star Wars Minis ##############################

// ##### d20 Modern #################################

// ##### d20 System #################################

// ##### GI Joe ##############################

// ##### Other banners ################################# 

And that's just the major commentary text. As I've said before, these boards are much like having 12 different boards tied at the hip - but somehow it works. I've very proud of my PHPINCLUDE_START template even if it's the one part of the boards the users never see.

Erwin 10-29-2004 01:49 AM

Looks intriguing. :) There are some load liabilities using phpinclude when you could be using global.php but if you're wanting to maintain Jelsoft official vB.com support, you do what you can. :)

Erwin 10-29-2004 01:51 AM

Quote:

Originally Posted by filburt1
57 in php_include_start, 80 in php_include_end. However, both of those have require() statements in which the required files are hundreds of lines long. I also haven't modified a single line of vB code.

Really? How do you integrate your points system without file modification?

Michael Morris 10-29-2004 02:00 AM

The Jelsoft support concern is definitely a valid one, but we have modified the code to allow forum banners. The changes are minor and can be undone in an hour or so if need be, but they are there.

I suppose I could require it in global.php, but I'm constantly upgrading the thing and as I said I don't have FTP access to the server, which I sorta would need to put it in an include file.

Logikos 10-29-2004 02:46 PM

I never touch my include template. Everything is file modded for me. ^^

Xenon 10-29-2004 04:01 PM

i think the combination is best

phpinclude can be a strong way to make some changes, but there are things which shouldn't be in that template ;)

AlexanderT 10-29-2004 06:25 PM

perhaps we should make a list of when phpinclude is especially useful and when definitely not ;) Thinking in more practical terms; it is obvious that mysql queries should be left out from phpinclude, but is it obvious to everyone why phpinclude could be still useful?

Brad 10-29-2004 06:30 PM

Phpinclude should not be used for calling templates imho, seeing how you have to hack the files to get the new template in the cache list anyway. Query's are fine in phpinclude, it just boils down to what the query dose as with hacking.

We really need to do some testing with phpinclude to see how much of an impact it has on resources over placing code directly into the files.

Brad 10-29-2004 06:40 PM

Ok I re-applied some stock vB code for de-buging to the phpinclude_start template, try this little hacket out and see how much time/memory your phpinclude_start template is eating up.

In /forumroot/global.php find:

PHP Code:

// #############################################################################
// parse PHP include
if (!is_demo_mode())
{
    @
ob_start();
    eval(
fetch_template('phpinclude_start', -10));
    
$phpinclude_output = @ob_get_contents();
    @
ob_end_clean();


Replace with:

PHP Code:

// #############################################################################
// parse PHP include
if (!is_demo_mode())
{
    if (
DB_QUERIES)
    {
        
// Time for phpinclude_start template
        
echo('Parsing phpinclude_start\n');
        
$pageendtime microtime();
        
$starttime explode(' '$pagestarttime);
        
$endtime explode(' '$pageendtime);
        
$beforetime $endtime[0] - $starttime[0] + $endtime[1] - $starttime[1];
        echo(
'Time before: $beforetime\n');
        if (
function_exists('memory_get_usage'))
        {
            echo(
'Memory Before Phpinclude_start: ' number_format((memory_get_usage() / 1024)) . 'KB' ' \n');
        }
    }

        @
ob_start();
        eval(
fetch_template('phpinclude_start', -10));
        
$phpinclude_output = @ob_get_contents();
        @
ob_end_clean();

    if (
DB_QUERIES)
    {
        
// end phpinclude_start parse timer
        
$pageendtime microtime();
        
$starttime explode(' '$pagestarttime);
        
$endtime explode(' '$pageendtime);
        
$aftertime $endtime[0] - $starttime[0] + $endtime[1] - $starttime[1];
        echo(
'Time after:  $aftertime\n');
        echo(
'Time taken: ' . ($aftertime $beforetime) . '\n');
        if (
function_exists('memory_get_usage'))
        {
            echo(
'Memory After Phpinclude_start: ' number_format((memory_get_usage() / 1024)) . 'KB' ' \n');
        }
        echo(
'\n<hr />\n\n');
    }


Go into debug mode and get the stats per normal method.


All times are GMT. The time now is 05:51 PM.

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.01261 seconds
  • Memory Usage 1,814KB
  • 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
  • (4)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (3)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