67 lines
1.8 KiB
PHP
67 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace BRSystems\Core\Library\cMinify;
|
|
|
|
use MatthiasMullie\Minify;
|
|
|
|
/**
|
|
* cMinify class
|
|
*
|
|
* @category CMS
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @since Version 2.0
|
|
*
|
|
*/
|
|
class cMinify
|
|
{
|
|
/**
|
|
* Class constructor
|
|
*/
|
|
public function __construct() { }
|
|
|
|
/**
|
|
* Function to minify JS/CSS passed file
|
|
*
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @category CMS
|
|
* @param string $sFilePath - file path
|
|
* @param int $fileType - file path
|
|
* @param bool $bPreserveFileTitle - Preserve file title
|
|
* @return mixed new file name & path
|
|
*/
|
|
const FILE_TYPE_JS = 1;
|
|
const FILE_TYPE_CSS = 2;
|
|
public function minifyCssOrJsFileV2($sFilePath, $fileType = self::FILE_TYPE_JS, $bPreserveFileTitle = false, $sFolder = '', $bDeleteFile = false){
|
|
|
|
if(file_exists($sFilePath) && filesize($sFilePath)){
|
|
set_time_limit(20);
|
|
|
|
$filename = ($bPreserveFileTitle ? basename($sFilePath) : sha1_file($sFilePath) . ($fileType == self::FILE_TYPE_CSS ? '.css' : '.js'));
|
|
$sNewFilePath = __CACHE__ . ( $sFolder ? "{$sFolder}/" : '' ) . $filename;
|
|
|
|
if($bDeleteFile)
|
|
unlink($sNewFilePath);
|
|
|
|
if(!file_exists($sNewFilePath)){
|
|
switch($fileType){
|
|
case self::FILE_TYPE_CSS:
|
|
|
|
$oCssMinMod = new Minify\CSS($sFilePath);
|
|
$oCssMinMod->minify($sNewFilePath);
|
|
|
|
break;
|
|
|
|
case self::FILE_TYPE_JS:
|
|
|
|
$oCssMinMod = new Minify\JS($sFilePath);
|
|
$oCssMinMod->minify($sNewFilePath);
|
|
break;
|
|
}
|
|
}
|
|
|
|
return $filename;
|
|
}
|
|
return false;
|
|
}
|
|
}
|