PHP Classes

File: minifier-function.inc.php

Recommend this page to a friend!
  Classes of Bennett Stone   MagicMin   minifier-function.inc.php   Download  
File: minifier-function.inc.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: MagicMin
Merge and minify and JavaScript and CSS files
Author: By
Last change:
Date: 10 years ago
Size: 1,845 bytes
 

Contents

Class file image Download
<?php
/**
 * minifier-function.inc.php
 * Provides aux support to simplify magic min usage
 * See https://github.com/bennettstone/magic-min for more configuration options
 *
 * @version 1.0
 * @date 07-Oct-2014
 * @package MagicMin
 **/


/**
 * Function to simplify replacements of absolute vs. relative paths when using magicmin
 *
 * @access public
 * @param string $output_filename
 * @param array $files
 * @param string $output_directory (just the 'css', 'js' etc... bit)
 * @param string $type (js, css)
 * @return string
 */
function magic_min_merge( $output_filename, $files = array(), $output_directory = 'css' )
{
    if( empty(
$files ) )
    {
        return
'';
    }
   
    require_once(
dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'class.magic-min.php' );
   
   
$output_type = strtolower( pathinfo( basename( $output_filename ), PATHINFO_EXTENSION ) );
   
   
$minified = new Minifier(
        array(
           
'closure' => true,
           
'echo' => false,
           
'timer' => false,
           
'hashed_filenames' => true,
           
'remove_comments' => true
       
)
    );

    switch(
$output_type )
    {
        case
'css':
            return
'<link rel="stylesheet" href="'.
               
$minified->merge(
                   
$output_directory.'/'.$output_filename,
                   
$output_directory,
                   
$files,
                   
$output_type
               
) .'" />' . PHP_EOL;
           
        break;
        case
'js':
       
        default:
            return
'<script src="'.
               
$minified->merge(
                   
$output_directory.'/'.$output_filename,
                   
$output_directory,
                   
$files,
                   
$output_type
               
) .'"></script>' . PHP_EOL;
           
        break;
    }
}