Back to vBulletin 3.0 Add-Ons

Compress Forum Templates (Speed up your Forums & Save Bandwidth)
Mod Version: 2.8, by Trigunflame

This modification is in the archives.
vB Version: 3.0.7 Rating: (2 votes - 5.00 average) Installs: 95
Released: 14 Apr 2005 Last Update: Never Downloads: 8
Not Supported  

Compress Forum Templates & Phrases
Speed up your Forums & Save Bandwidth


Description:

Hi, this is a pretty simple hack that involves compressing the 'compiled' version of your templates, this way it only compresses the part thats to be shown on the forum and not the actual template data you edit.

Background:

Got the idea from Zero Tolerance in buro9's thread:
Page Output Compression - Whitespace stripper.

The above hack compresses the page at parse time, while it provides some speed enhancement, on large pages you can actually "negate" the point of using the hack in the first place, because of the overhead in compression.

Thus, the creation of this hack is to provide similiar functionality, but done in the adminCP; and without the overhead of constant compression.

Info:

No Queries. Only query is used when compressing your templates, the rest of the time its just pulling the templates straight out of the database like normal.

Updates:

Version 2.8 - Added Strip Whitespace from Start of JS Line by buro9
Version 2.7 - Option to strip HTML Comments from Compressed Output
Version 2.6 - Removed Phrase Compression altogether, Too Iffy
Version 2.5 - Removed the ASCII \n removal, emails should work now.
Version 2.4 - Had to add editor_jsoptions_size to the Bad Templates array, it also was causing a font selection error.
Version 2.3 - Added Phrase compression support, should help further increase page compression.
Version 2.2 - Slightly Recoded Template compression for faster results.
Version 2.1 - Added php_include templates to bad templates, will not compress these.
Version 2.0 - Recoded Script, added support for certain templates to not compress
Version 1.9 - Re-Added support for InLine Styles.
Version 1.8 - Removed support for InLine Styles, all Style data is left with Linebreaks.
Version 1.7 - Removed support for InLine Javascript, all JavaScript is left with Linebreaks.
Version 1.6 - Fixed Tab problem, tabs are replaced with a single space
Version 1.5 - Removed a part of the SQL.
Version 1.4 - TOTALLY Remade, Works perfect now; Ultimate Compression
Version 1.3 - Adjusted Again
Version 1.2 - Adjusted Stripping regex
Version 1.1 - Added Uncompress Support
Version 1.0 - Release

Install:

Step 1. [ Open admincp/template.php ]
Step 2. [ Go to about line: 1278, or just look for $_REQUEST['do'] == 'edit' ]
Step 3. [ Above Step 2, add the below code ]

PHP Code:
// #############################################################################
// Rebuild Templates Compressed
if ($_REQUEST['do'] == 'compressall')
{
    
/**
     * Compress Templates Mod
     *
     * Thanks for Idea From Zero Tolerance.
     * Thanks for Help & Support From buro9
     *
     * @author Trigunflame
     * @version 2.8
     * @copyright Dusty Burns, 2005-2006
     */

    // Strip Comments?
    // Use true or false
    
$stripComments true;

    
// Search & Replace
    
$search  = array('/\s+/''/\t+/'); 
    
$replace ' '
    
$jsearch  = array('/^\s+/''/\t+/');
    
$jreplace = array(''' ');
    
    
// Strip Comments
    
if ($stripComments) { $search[] = '/<!--.*?-->/'; }
    
    
// List of Templates to NOT Compress
    
$badTemplates = array(
        
'editor_jsoptions_font',
        
'editor_jsoptions_size',
        
'phpinclude_start',
        
'phpinclude_end'
    
);
            
    
// Get Modified Templates
    
$templates $DB_site->query(
        
"SELECT templateid, title, template_un " 
        
"FROM " TABLE_PREFIX "template " .
        
"WHERE template_un <> '' "
    
);
    
    
// Selectively Compress
    
while ($template $DB_site->fetch_array($templates))
    {
        
// Compile Template
        
$compiledTemplate compile_template($template['template_un']);
        
        
// Bad Template
        
if (in_array(strtolower($template['title']), $badTemplates))
        {
            
// Ignoring Template
            
echo "Bad Template [" $template['templateid'] . "] " $template['title'] . "<br />\n";
            
            
$compressedTemplate $compiledTemplate;
        }
        
        
// Reverting Template
        
else if ($_REQUEST['revert'])
        {
            
// Uncompressing
            
echo "Uncompressing [" $template['templateid'] . "] " $template['title'] . "<br />\n";
            
            
$compressedTemplate $compiledTemplate;
        }
        
        
// Good Template
        
else
        {
            
// Compressing
            
echo "Compressing [" $template['templateid'] . "] " $template['title'] . "<br />\n";
            
            
// Get All Lines
            
$compiledTemplate preg_split('(\r\n|\r|\n)'$compiledTemplate);
            
            
// Javascript Status
            
$js false;

            
// Compressed Output
            
$compressedTemplate '';
            
            
// Loop Lines
            
foreach ($compiledTemplate AS $line)
            {
                
// LowerCase Line
                
$lowerLine strtolower($line);
                
                
// Look For Start of JavaScript
                
if (strpos($lowerLine'<script') !== false) { $js true; }
                
                
// Check For Null
                
if (trim($line) == '') continue;
    
                
// Check JS Status
                
if (!$js && !$st)
                {
                    
// Full WhiteSpace Strip
                    
$line preg_replace($search$replace$line);
                }
                else
                {
                    
// Straight Output
                    
$line preg_replace($jsearch$jreplace$line) . "\r\n";
                }

                
// Look For End of JavaScript
                
if (strpos($lowerLine'</script>') !== false) { $js false; }
                
                
// Check For Null
                
if (trim($line) == '') continue;
                
                
// Append Line
                
$compressedTemplate .= $line;
            }
        }
        
        
// Update Template
        
$DB_site->query(
            
"UPDATE " TABLE_PREFIX "template " 
            
"SET template = '" addslashes($compressedTemplate) . "' " 
            
"WHERE templateid = '" $template['templateid'] . "'"
        
);
    }
    
    
// Redirect
    
print_cp_redirect('index.php?do=home'1);
    
    
/**
     * End Compress Templates Mod
     */

Step 4. [ close admincp/template.php and open admincp/index.php ]
Step 5. [ look for ]

PHP Code:
construct_nav_option($vbphrase['find_updated_templates'], 'template.php?do=findupdates''<br />'); 
Step 6. [ below this, add the code ]

PHP Code:
construct_nav_option("Compress Templates"'template.php?do=compressall''<br />');
construct_nav_option("Uncompress Templates"'template.php?do=compressall&revert=1''<br />'); 
How-To Run

1. Install
2. In the admincp left navigation, select "Compress Templates".
3. Repeat Step 2 after each modification of your Templates whenever you decide to change something.
4. If you want to uncompress all Templates, select "Uncompress Templates"
5. IF Any Templates Come Out Weird, add the template Name to the Bad Templates Array and Re-Run the Compress Templates.

Download

No files for download.

Supporters / CoAuthors

  • buro9

Screenshots

 

Similar Mods

Compress Forum Templates vBulletin 3.5 Add-ons
Save bandwidth with CSS. vBulletin 2.x Template Modifications

vblts.ru supports vBulletin®, 2022-2024