Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <pre>
- <?php
- include 'JSmin.php';
- include 'CSSmin.php';
- $sTemplatePath = $_SERVER['DOCUMENT_ROOT'] . '/bitrix/templates/template_name/';
- function minify(array $arr) {
- foreach ($arr as $orig => $minVersion) {
- $pathInfo = pathinfo($orig);
- if (file_exists($minVersion)) {
- $pathInfoMin = pathinfo($minVersion);
- }
- if (filemtime($orig) > filemtime($minVersion)) {
- switch ($pathInfo['extension']) {
- case 'css':
- $filters = array (
- "ImportImports" => false,
- "RemoveComments" => true,
- "RemoveEmptyRulesets" => false,
- "RemoveEmptyAtBlocks" => false,
- "ConvertLevel3AtKeyframes" => false,
- "ConvertLevel3Properties" => false,
- "Variables" => true,
- "RemoveLastDelarationSemiColon" => false,
- );
- $plugins = array (
- "Variables" => true,
- "ConvertFontWeight" => false,
- "ConvertHslColors" => false,
- "ConvertRgbColors" => false,
- "ConvertNamedColors" => false,
- "CompressColorValues" => true,
- "CompressUnitValues" => true,
- "CompressExpressionValues" => false
- );
- $minCode = CssMin::minify(file_get_contents($orig), array(), $plugins);
- break;
- case 'js':
- $minCode = JsMin::minify(file_get_contents($orig));
- break;
- }
- file_put_contents($minVersion, $minCode, LOCK_EX);
- if (file_exists($minVersion)) {
- $pathInfoMin = pathinfo($minVersion);
- }
- echo $pathInfoMin['basename']. " Сгенерирован" . "\n";
- } else {
- echo sprintf('%s Актуальная версия %s', $pathInfoMin['basename'], $pathInfo['basename']) . "\n";
- }
- }
- }
- $js = array(
- $sTemplatePath . "js/sidebarmenu.js" => $sTemplatePath . "js/sidebarmenu.min.js",
- $_SERVER['DOCUMENT_ROOT'] . '/bitrix/cache/js/ru/slid_main/kernel_main/kernel_main.js' => $_SERVER['DOCUMENT_ROOT'] . '/bitrix/cache/js/ru/slid_main/kernel_main/kernel_main.min.js',
- $sTemplatePath . "js/utils.js" => $sTemplatePath . "js/utils.min.js",
- $sTemplatePath . "js/classifieds.js" => $sTemplatePath . "js/classifieds.min.js",
- );
- $css = array(
- $sTemplatePath . "css/bootstrap.css" => $sTemplatePath . "css/bootstrap.min.css",
- $sTemplatePath . "css/classifieds.css" => $sTemplatePath . "css/classifieds.min.css",
- $sTemplatePath . "css/forum.css" => $sTemplatePath . "css/forum.min.css",
- );
- minify($js);
- minify($css);
- ?>
- </pre>
Advertisement
Add Comment
Please, Sign In to add comment