askew0

Untitled

Jul 20th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.45 KB | None | 0 0
  1. <pre>
  2. <?php
  3.     include 'JSmin.php';
  4.     include 'CSSmin.php';
  5.  
  6.     $sTemplatePath = $_SERVER['DOCUMENT_ROOT'] . '/bitrix/templates/template_name/';
  7.  
  8.     function minify(array $arr) {
  9.         foreach ($arr as $orig => $minVersion) {
  10.             $pathInfo = pathinfo($orig);
  11.  
  12.             if (file_exists($minVersion)) {
  13.                 $pathInfoMin = pathinfo($minVersion);
  14.             }
  15.  
  16.             if (filemtime($orig) > filemtime($minVersion)) {
  17.                 switch ($pathInfo['extension']) {
  18.                     case 'css':
  19.                         $filters = array (
  20.                             "ImportImports"                 => false,
  21.                             "RemoveComments"                => true,
  22.                             "RemoveEmptyRulesets"           => false,
  23.                             "RemoveEmptyAtBlocks"           => false,
  24.                             "ConvertLevel3AtKeyframes"      => false,
  25.                             "ConvertLevel3Properties"       => false,
  26.                             "Variables"                     => true,
  27.                             "RemoveLastDelarationSemiColon" => false,
  28.                         );
  29.                         $plugins = array (
  30.                             "Variables"                     => true,
  31.                             "ConvertFontWeight"             => false,
  32.                             "ConvertHslColors"              => false,
  33.                             "ConvertRgbColors"              => false,
  34.                             "ConvertNamedColors"            => false,
  35.                             "CompressColorValues"           => true,
  36.                             "CompressUnitValues"            => true,
  37.                             "CompressExpressionValues"      => false
  38.                         );
  39.  
  40.                         $minCode = CssMin::minify(file_get_contents($orig), array(), $plugins);
  41.                         break;
  42.                     case 'js':
  43.                         $minCode = JsMin::minify(file_get_contents($orig));
  44.                         break;
  45.                 }
  46.                 file_put_contents($minVersion, $minCode, LOCK_EX);
  47.                 if (file_exists($minVersion)) {
  48.                     $pathInfoMin = pathinfo($minVersion);
  49.                 }
  50.                 echo $pathInfoMin['basename']. " Сгенерирован" . "\n";
  51.             } else {
  52.                 echo sprintf('%s Актуальная версия %s', $pathInfoMin['basename'], $pathInfo['basename']) . "\n";
  53.             }
  54.         }
  55.     }
  56.  
  57.     $js = array(
  58.         $sTemplatePath . "js/sidebarmenu.js" => $sTemplatePath .  "js/sidebarmenu.min.js",
  59.         $_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',
  60.         $sTemplatePath . "js/utils.js" => $sTemplatePath .  "js/utils.min.js",
  61.         $sTemplatePath . "js/classifieds.js" => $sTemplatePath .  "js/classifieds.min.js",
  62.     );
  63.  
  64.     $css = array(
  65.         $sTemplatePath . "css/bootstrap.css" => $sTemplatePath .  "css/bootstrap.min.css",
  66.         $sTemplatePath . "css/classifieds.css" => $sTemplatePath .  "css/classifieds.min.css",
  67.         $sTemplatePath . "css/forum.css" => $sTemplatePath .  "css/forum.min.css",
  68.     );
  69.  
  70.     minify($js);
  71.     minify($css);
  72. ?>
  73. </pre>
Advertisement
Add Comment
Please, Sign In to add comment