WebsiteBaker Community Forum

WebsiteBaker Support (2.12.x) => Modules => Topic started by: dbs on September 26, 2019, 11:19:14 AM

Title: Minify CSS & JS
Post by: dbs on September 26, 2019, 11:19:14 AM
Those using Ruud's experimental module Minify (https://forum.WebsiteBaker.org/index.php/topic,30487.0.html) you should consider changing the code in include.php for newer WB versions.

In newer WB versions you can use frontendUser.css and frontendUser.js in all modules (to keep your own changes update safe), but this is not yet included in the Minify module. A small change should fix this. It now looks first for frontendUser.js|css and if not available then for frontend.js|css. Nothing else was changed.

modules/minify/include.php line 146 (whole function _get_frontend), replace with this:
Code: [Select]
<?php // <-- this line is not needed, only for colored code here

function _get_frontend($type'css') {
    global 
$database,$css,$js;
    
$path _clean_filename(WB_PATH);
    
$query "SELECT DISTINCT `directory` FROM ".TABLE_PREFIX."addons where function='snippet'";
    
$res $database->query($query);
    if(
$res && $res->numRows() > 0) {
        while (
$row $res->fetchRow()) {
            
$fpath $path.'/modules/'.$row['directory'];
            if(
$type=='css' && file_exists($fpath.'/frontendUser.css')) {
                
$css[] = $fpath.'/frontendUser.css';
            } else if (
$type=='css' && file_exists($fpath.'/frontend.css')) {
                
$css[] = $fpath.'/frontend.css';
            }
           
            if(
$type=='js' && file_exists($fpath.'/frontendUser.js')) {
                
$js[] = $fpath.'/frontendUser.js';
            } else if (
$type=='js' && file_exists($fpath.'/frontend.js')) {
                
$js[] = $fpath.'/frontend.js';
            }
        }
    }   
    
$query "SELECT DISTINCT `directory` FROM ".TABLE_PREFIX."addons a JOIN
             "
.TABLE_PREFIX."sections s ON s.module = a.directory";
    
$res $database->query($query);
    if(
$res && $res->numRows() > 0) {
        while (
$row $res->fetchRow()) {
            
$fpath $path.'/modules/'.$row['directory'];
            if(
$type=='css' && file_exists($fpath.'/frontendUser.css')) {
                
$css[] = $fpath.'/frontendUser.css';
            } else if (
$type=='css' && file_exists($fpath.'/frontend.css')) {
                
$css[] = $fpath.'/frontend.css';
            }
           
            if(
$type=='js' && file_exists($fpath.'/frontendUser.js')) {
                
$js[] = $fpath.'/frontendUser.js';
            } else if (
$type=='js' && file_exists($fpath.'/frontend.js')) {
                
$js[] = $fpath.'/frontend.js';
            }
        }
    }
    
$done 1;
}