Please report bugs on https://github.com/matthiasmullie/minify/issues
Author: Matthias Mullie (minify@mullie.eu)
Author: Tijs Verkoyen (minify@verkoyen.eu)
Inheritance: extends Minify
Exemplo n.º 1
0
 function setAssets($assets, $type, $outPutFolder, $outPutFileName)
 {
     $lastModifiedFile = $outPutFolder . '/' . basename($outPutFileName) . '-lm';
     $files = array_combine($assets, array_map("filemtime", $assets));
     arsort($files);
     $latestStoredFile = key($files);
     $latestStoredFileModified = filemtime($latestStoredFile);
     $lastCached = FALSE;
     if (!file_exists($lastModifiedFile)) {
         file_put_contents($lastModifiedFile, $latestStoredFileModified);
     } else {
         $lastCached = file_get_contents($lastModifiedFile);
     }
     if ($lastCached == FALSE || $latestStoredFileModified > $lastCached) {
         if ($type == 'js') {
             $minifier = new Minify\JS();
         } else {
             if ($type == 'css') {
                 $minifier = new Minify\CSS();
             }
         }
         foreach ($assets as $asset) {
             $minifier->add($asset);
         }
         $minifier->minify($outPutFolder . '/' . $outPutFileName);
         file_put_contents($lastModifiedFile, $latestStoredFileModified);
     }
     return $outPutFolder . '/' . $outPutFileName;
 }
Exemplo n.º 2
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ('development' != $input->getArgument('environment') && 'production' != $input->getArgument('environment')) {
         return $output->writeln($input->getArgument('environment') . ' environment not found');
     }
     $jsMinifier = new JS();
     $cssMinifier = new CSS();
     $output->writeln('Building environment: ' . $input->getArgument('environment'));
     $output->write('Generating JavaScript build file...');
     $jsFiles = FileSystem::listDirectoryRecursive(Application::webRoot() . '/js', '/^.+\\.js$/i');
     $buildFile = fopen(Application::webRoot() . '/min/build.js', 'w');
     foreach ($jsFiles as $filePath) {
         fwrite($buildFile, file_get_contents($filePath) . "\n\n");
     }
     fclose($buildFile);
     $output->writeln('done');
     $output->write('Shrinking JavaScript...');
     $jsMinifier->add(Application::webRoot() . '/min/build.js');
     $jsMinifier->minify(Application::webRoot() . '/min/build.min.js');
     $output->writeln('done');
     $output->write('Compiling less files...');
     $less = new \lessc();
     $less->compileFile(Application::webRoot() . '/media/importer.less', Application::webRoot() . '/min/build.css');
     $output->writeln('done');
     $output->write('Shrinking css files...');
     $cssMinifier->add(Application::webRoot() . '/min/build.css');
     $cssMinifier->minify(Application::webRoot() . '/min/build.min.css');
     $output->writeln('done');
     return null;
 }
Exemplo n.º 3
0
 /**
  * @param array $current_state
  *
  * @return array updated_state
  */
 public function process(array $current_state)
 {
     $minifier = new Minify\CSS();
     $updated_state = [];
     foreach ($current_state as $filename => $content) {
         $minifier->add($content);
     }
     $updated_state['all.min.css'] = $minifier->minify();
     return $updated_state;
 }
Exemplo n.º 4
0
 /**
  * Test minifier import configuration methods.
  *
  * @test
  */
 public function setConfig()
 {
     $this->minifier->setMaxImportSize(10);
     $this->minifier->setImportExtensions(array('gif' => 'data:image/gif'));
     $object = new ReflectionObject($this->minifier);
     $property = $object->getProperty('maxImportSize');
     $property->setAccessible(true);
     $this->assertEquals($property->getValue($this->minifier), 10);
     $property = $object->getProperty('importExtensions');
     $property->setAccessible(true);
     $this->assertEquals($property->getValue($this->minifier), array('gif' => 'data:image/gif'));
 }
Exemplo n.º 5
0
 private static function minifyCSS()
 {
     $sourcePathConfig = tr::config()->get("app.minify");
     $minifier = new Minify\CSS();
     if ($sourcePathConfig['css']) {
         foreach ($sourcePathConfig['css'] as $v) {
             $minifier->add($v);
         }
     }
     $minifier->minify(ROOT_PATH . "/public/asset/global.css");
     return true;
 }
Exemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function run(OutputInterface $output)
 {
     $destination = $this->getParameter('dest');
     /** @var SplFileInfo[] $files */
     $files = $this->getFiles($this->getParameter('src'));
     $minifier = new CSS();
     foreach ($files as $file) {
         $minifier->add($file);
     }
     if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) {
         $output->writeln("Writing to " . $destination);
     }
     (new Filesystem())->mkdir(dirname($destination));
     $minifier->minify($destination);
 }
Exemplo n.º 7
0
 /**
  * @inheritdoc
  */
 public function execute(Source $src)
 {
     $min = new CSS();
     foreach ($src->getDistFiles() as $key => $file) {
         if (preg_match('/css$/', $file->getName()) || preg_match('/css$/', $file->getDistpathname())) {
             if (!$this->options['join']) {
                 $min = new CSS();
             }
             $min->add($file->getContent());
             if (!$this->options['join']) {
                 $file->setContent($min->minify());
             } else {
                 $src->removeDistFile($key);
             }
         }
     }
     if ($this->options['join']) {
         $src->addDistFile(new DistFile($min->minify(), md5(uniqid(microtime())) . '.css'));
     }
 }
Exemplo n.º 8
0
 /**
  * @param SplFileInfo[] $sources
  * @param SplFileInfo[] $destinations
  * @return SplFileInfo[]
  */
 public function run(array $sources, array $destinations)
 {
     $cssMinifier = new CSS();
     $jsMinifier = new JS();
     $hasJs = false;
     $hasCss = false;
     // add source files to the minifier
     foreach ($sources as $source) {
         if ($source->getExtension() == 'js') {
             $this->addNotification('Add ' . $source . ' to js minification');
             $jsMinifier->add($source);
             $hasJs = true;
         }
         if ($source->getExtension() == 'css') {
             $this->addNotification('add ' . $source . ' to css minification');
             $cssMinifier->add($source);
             $hasCss = true;
         }
     }
     $cssMinified = $this->getCacheDir() . 'minified.css';
     $jsMinified = $this->getCacheDir() . 'minified.js';
     $updatedSources = [];
     // js minification if required
     if ($hasJs) {
         $this->addNotification($jsMinified . ' js minification');
         $jsMinifier->minify($jsMinified);
         $updatedSources[] = $jsMinified;
     }
     // css minification if required
     if ($hasCss) {
         $this->addNotification($cssMinified . ' css minification');
         $cssMinifier->minify($cssMinified);
         $updatedSources[] = $cssMinified;
     }
     return $updatedSources;
 }
Exemplo n.º 9
0
 /**
  * Compile CSS
  * @param string $filename LESS filename without extension
  * @param array $options Compile options
  * @return bool true on succes, false on failure
  */
 public function compile($filename, $options = array())
 {
     $config = $this->prepareConfig($options);
     $input_path = $config['less_path'] . DIRECTORY_SEPARATOR . $filename . '.less';
     $output_path = $config['public_path'] . DIRECTORY_SEPARATOR . $filename . '.css';
     $css_dir_depth = $this->getDirDepth(public_path(), $output_path);
     $parser = new \Less_Parser($config);
     $parser->parseFile($input_path, str_repeat('{relative_path_fix}/', $css_dir_depth));
     // Iterate through jobs
     foreach ($this->jobs as $i => $job) {
         call_user_func_array(array($parser, array_shift($job)), $job);
     }
     $written = $this->writeCss($output_path, $parser->getCss());
     // Remove old cache files if succesfully written
     if ($written === true) {
         $this->cleanCache();
     }
     // Minifying CSS
     if (env('LESS_MINIFY', false)) {
         $minifier = new Minify\CSS($output_path);
         $minifier->minify($output_path);
     }
     return $written;
 }
Exemplo n.º 10
0
 /**
  * Minify the HTML markup preserving pre, script, style and textarea tags
  *
  * @param string $strHtml The HTML markup
  *
  * @return string The minified HTML markup
  */
 public function minifyHtml($strHtml)
 {
     // The feature has been disabled
     if (!\Config::get('minifyMarkup') || \Config::get('debugMode')) {
         return $strHtml;
     }
     // Split the markup based on the tags that shall be preserved
     $arrChunks = preg_split('@(</?pre[^>]*>)|(</?script[^>]*>)|(</?style[^>]*>)|( ?</?textarea[^>]*>)@i', $strHtml, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
     $strHtml = '';
     $blnPreserveNext = false;
     $blnOptimizeNext = false;
     $strType = null;
     // Check for valid JavaScript types (see #7927)
     $isJavaScript = function ($strChunk) {
         $typeMatch = array();
         if (preg_match('/\\stype\\s*=\\s*(?:(?J)(["\'])\\s*(?<type>.*?)\\s*\\1|(?<type>[^\\s>]+))/i', $strChunk, $typeMatch) && !in_array(strtolower($typeMatch['type']), static::$validJavaScriptTypes)) {
             return false;
         }
         if (preg_match('/\\slanguage\\s*=\\s*(?:(?J)(["\'])\\s*(?<type>.*?)\\s*\\1|(?<type>[^\\s>]+))/i', $strChunk, $typeMatch) && !in_array('text/' . strtolower($typeMatch['type']), static::$validJavaScriptTypes)) {
             return false;
         }
         return true;
     };
     // Recombine the markup
     foreach ($arrChunks as $strChunk) {
         if (strncasecmp($strChunk, '<pre', 4) === 0 || strncasecmp(ltrim($strChunk), '<textarea', 9) === 0) {
             $blnPreserveNext = true;
         } elseif (strncasecmp($strChunk, '<script', 7) === 0) {
             if ($isJavaScript($strChunk)) {
                 $blnOptimizeNext = true;
                 $strType = 'js';
             } else {
                 $blnPreserveNext = true;
             }
         } elseif (strncasecmp($strChunk, '<style', 6) === 0) {
             $blnOptimizeNext = true;
             $strType = 'css';
         } elseif ($blnPreserveNext) {
             $blnPreserveNext = false;
         } elseif ($blnOptimizeNext) {
             $blnOptimizeNext = false;
             // Minify inline scripts
             if ($strType == 'js') {
                 $objMinify = new Minify\JS();
                 $objMinify->add($strChunk);
                 $strChunk = $objMinify->minify();
             } elseif ($strType == 'css') {
                 $objMinify = new Minify\CSS();
                 $objMinify->add($strChunk);
                 $strChunk = $objMinify->minify();
             }
         } else {
             // Remove line indentations and trailing spaces
             $strChunk = str_replace("\r", '', $strChunk);
             $strChunk = preg_replace(array('/^[\\t ]+/m', '/[\\t ]+$/m', '/\\n\\n+/'), array('', '', "\n"), $strChunk);
         }
         $strHtml .= $strChunk;
     }
     return trim($strHtml);
 }
Exemplo n.º 11
0
 /**
  * Minify a CSS-file
  *
  * @param string $file The file to be minified.
  * @return string
  */
 private function minifyCSS($file)
 {
     // create unique filename
     $fileName = md5($file) . '.css';
     $finalURL = BACKEND_CACHE_URL . '/MinifiedCss/' . $fileName;
     $finalPath = BACKEND_CACHE_PATH . '/MinifiedCss/' . $fileName;
     // check that file does not yet exist or has been updated already
     if (!is_file($finalPath) || filemtime(PATH_WWW . $file) > filemtime($finalPath)) {
         // minify the file
         $css = new Minify\CSS(PATH_WWW . $file);
         $css->minify($finalPath);
     }
     return $finalURL;
 }
Exemplo n.º 12
0
<?php

ini_set("max_execution_time", 190);
require_once 'config/_definitions.php';
//load main node config
require_once CORE_REPOSITORY_REAL_PATH . 'vendor/autoload.php';
use MatthiasMullie\Minify;
$minifier = new Minify\CSS();
$sourcePathArray = ['css/bootstrap.min.css', 'css/core.css', 'css/jquery-ui.css', 'js/jquery-timepicker/jquery-ui-timepicker-addon.css', 'css/jquery.timepicker.css', 'css/jquery.fancybox.css', 'css/bootstrap-switch.min.css', 'css/search/search.css', 'css/fullcalendar.css', 'js/notify/css/bootstrap-notify.css', 'css/custom-menu.css'];
foreach ($sourcePathArray as $cssPath) {
    $minifier->add(CORE_REPOSITORY_REAL_PATH . $cssPath);
}
// save minified file to disk
$minifier->minify(CORE_REPOSITORY_REAL_PATH . 'css/build/core.css');
$minifier = new Minify\JS();
$sourcePathArrayJS = ['js/jquery/jquery-1.11.0.min.js', 'js/support/support.js', 'js/jquery/jquery-ui-1.10.3.custom.js', 'js/jquery-timepicker/jquery-ui-timepicker-addon.js', 'js/jquery/jquery.timepicker.min.js', 'js/bootstrap.js', 'js/modals/Modal.class.js', 'js/search/core.class.js', 'js/search/clicker.js', 'js/core.js', "js/notify/js/soundmanager2-nodebug-jsmin.js", "js/notify/js/bootstrap-notify.js", "js/production/fancybox/source/jquery.fancybox.pack.js", "js/bootstrap-switch.min.js", "js/jquery.fancybox.js", "js/lib/moment.min.js", "js/fullcalendar.js", "js/ru.js", 'js/jquery/spinner.js', 'js/jquery/spin.jquery.plugin.js'];
foreach ($sourcePathArrayJS as $jsPath) {
    $minifier->add(CORE_REPOSITORY_REAL_PATH . $jsPath);
}
// save minified file to disk
$minifier->minify(CORE_REPOSITORY_REAL_PATH . 'js/build/core.js');
Exemplo n.º 13
0
 /**
  * Minify CSS
  *
  * @return string
  */
 protected function minifyCss()
 {
     $output = '';
     // Core variables and mixins
     $output .= '@import "variables.less";';
     $output .= '@import "mixins.less";';
     // Reset and dependencies
     $output .= $this->prepareCssForLess('normalize');
     $output .= $this->prepareCssForLess('print');
     $output .= $this->prepareCssForLess('glyphicons');
     // Core CSS
     $output .= $this->prepareCssForLess('scaffolding');
     $output .= $this->prepareCssForLess('type');
     $output .= $this->prepareCssForLess('code');
     $output .= $this->prepareCssForLess('grid');
     $output .= $this->prepareCssForLess('tables');
     $output .= $this->prepareCssForLess('forms');
     $output .= $this->prepareCssForLess('buttons');
     // Components
     $output .= $this->prepareCssForLess('component-animations');
     $output .= $this->prepareCssForLess('dropdowns');
     $output .= $this->prepareCssForLess('button-groups');
     $output .= $this->prepareCssForLess('input-groups');
     $output .= $this->prepareCssForLess('navs');
     $output .= $this->prepareCssForLess('navbar');
     $output .= $this->prepareCssForLess('breadcrumbs');
     $output .= $this->prepareCssForLess('pagination');
     $output .= $this->prepareCssForLess('pager');
     $output .= $this->prepareCssForLess('labels');
     $output .= $this->prepareCssForLess('badges');
     $output .= $this->prepareCssForLess('jumbotron');
     $output .= $this->prepareCssForLess('thumbnails');
     $output .= $this->prepareCssForLess('alerts');
     $output .= $this->prepareCssForLess('progress-bars');
     $output .= $this->prepareCssForLess('media');
     $output .= $this->prepareCssForLess('list-group');
     $output .= $this->prepareCssForLess('panels');
     $output .= $this->prepareCssForLess('responsive-embed');
     $output .= $this->prepareCssForLess('wells');
     $output .= $this->prepareCssForLess('close');
     // Components w/ JavaScript
     $output .= $this->prepareCssForLess('modals');
     $output .= $this->prepareCssForLess('tooltip');
     $output .= $this->prepareCssForLess('popovers');
     $output .= $this->prepareCssForLess('carousel');
     // Utility classes
     $output .= $this->prepareCssForLess('utilities');
     $output .= $this->prepareCssForLess('responsive-utilities');
     $less = new \Less_Parser();
     $less->SetImportDirs([base_path('vendor/twbs/bootstrap/less') => 'bootstrap']);
     $css = $less->parse($output, 'bootstrap.components.less')->getCss();
     $minifier = new Minify\CSS();
     $minifier->add($css);
     return $minifier->minify();
 }
Exemplo n.º 14
0
 public function _minify($code = NULL)
 {
     if (is_null($code)) {
         $code = $this->code;
     }
     //----------------------------------------------------------
     //init var
     //----------------------------------------------------------
     $chk = array("bool" => true, 'traceID' => "minJs");
     //----------------------------------------------------------
     if ($this->type == "js" || strpos($this->fileName, "js") !== false) {
         //krumo($this->type);
         //krumo($this->code);
         //print_r($code."                        |||||||||||||||||||||||             ");
         //$code = StringUtil::removeAllJSComments($code);
         $minifier = new Minify\JS();
         $minifier->add($code);
         $content = $minifier->minify();
     } else {
         if ($this->type == "css" || strpos($this->fileName, "css") !== false) {
             $minifier = new Minify\CSS();
             $minifier->add($code);
             $content = $minifier->minify();
         } else {
             if (strpos($this->fileName, "html") !== false) {
                 $content = $code;
             }
         }
     }
     //----------------------------------------------------------
     $chk['result'] = $content;
     //----------------------------------------------------------
     if (is_null($fileLocation)) {
         $chk['message'] = "code has been successfully minified!!!!!";
     }
     //----------------------------------------------------------
     //$chk = CreateFile_v0::go($this->fileName, $content, $this->fileLocation, true);
     //----------------------------------------------------------
     //Minifier_v0::createDependantFiles($content);
     //----------------------------------------------------------
     return $chk;
 }
Exemplo n.º 15
0
 /**
  *
  *
  * @return string
  */
 public function __toString()
 {
     $result = '';
     try {
         // LESS
         $parser = new Less_Parser();
         foreach ($this->container as $content) {
             list($t, $c) = $content;
             if ($t == static::TYPE_LESS_FILE) {
                 $parser->parseFile($c);
             } elseif ($t == static::TYPE_LESS) {
                 $parser->parse($c);
             }
         }
         $less = $parser->getCss();
         // If we want to minify
         if ($this->isMinify()) {
             $hash = '';
             $contents = [];
             // manage remote or local file
             foreach ($this->container as $content) {
                 list($t, $c) = $content;
                 if ($t == static::TYPE_STYLE_FILE) {
                     // scheme case
                     if (preg_match('#^//.+$#', $c)) {
                         $c = 'http:' . $c;
                         $contents[] = ['remote', $c];
                         $hash .= md5($c);
                         // url case
                     } elseif (preg_match('#^https?://.+$#', $c)) {
                         $contents[] = ['remote', $c];
                         $hash .= md5($c);
                         // local file
                     } else {
                         $c = public_path($c);
                         $hash .= md5_file($c);
                         $contents[] = ['local', $c];
                     }
                 } elseif ($t == static::TYPE_STYLE) {
                     $hash .= md5($c);
                     $contents[] = ['style', $c];
                 }
             }
             // Less
             if (!empty($less)) {
                 $hash .= md5($less);
                 $contents[] = ['style', $less];
             }
             // destination file
             $target = public_path($this->getTargetPath());
             if (substr($target, -1) != '/') {
                 $target .= '/';
             }
             $target .= md5($hash) . '.css';
             // add css to minifier
             if (!file_exists($target)) {
                 $minifier = new MiniCss();
                 // Remote file management
                 foreach ($contents as $content) {
                     list($t, $c) = $content;
                     // we get remote file content
                     if ($t == 'remote') {
                         $c = file_get_contents($c);
                     }
                     $minifier->add($c);
                 }
                 // minify
                 $minifier->minify($target);
             }
             // set $file
             $result .= html('link', ['href' => str_replace(public_path(), '', $target), 'rel' => 'stylesheet', 'type' => 'text/css']) . PHP_EOL;
         } else {
             foreach ($this->container as $content) {
                 list($t, $c) = $content;
                 // render file
                 if ($t == static::TYPE_STYLE_FILE) {
                     $result .= html('link', ['href' => $c, 'rel' => 'stylesheet', 'type' => 'text/css']) . PHP_EOL;
                     // render style
                 } elseif ($t == static::TYPE_STYLE) {
                     $result .= html('style', [], $c);
                 }
             }
             // Less
             if (!empty($less)) {
                 $result .= html('style', [], $less);
             }
         }
     } catch (\Exception $e) {
         $result = '<!--' . PHP_EOL . 'Error on css generation' . PHP_EOL;
         // stack trace if in debug mode
         if (debug()) {
             $result .= $e->getMessage() . ' : ' . PHP_EOL . $e->getTraceAsString() . PHP_EOL;
         }
         $result .= '-->';
     }
     return $result;
 }
Exemplo n.º 16
0
 /**
  * Minify a CSS-file
  *
  * @param string $file The file to be minified.
  * @return string
  */
 private function minifyCSS($file)
 {
     $fileName = md5($file) . '.css';
     $finalURL = FRONTEND_CACHE_URL . '/MinifiedCss/' . $fileName;
     $finalPath = FRONTEND_CACHE_PATH . '/MinifiedCss/' . $fileName;
     // check that file does not yet exist or has been updated already
     $fs = new Filesystem();
     if (!$fs->exists($finalPath) || filemtime(PATH_WWW . $file) > filemtime($finalPath)) {
         // create directory if it does not exist
         if (!$fs->exists(dirname($finalPath))) {
             $fs->mkdir(dirname($finalPath));
         }
         // minify the file
         $css = new Minify\CSS(PATH_WWW . $file);
         $css->minify($finalPath);
     }
     return $finalURL;
 }
Exemplo n.º 17
0
 private function ProcessSiteFolder($source, $dest, $folderPermissions, $filePermissions, $ignoreFiles = null, $ignoreMasks = null)
 {
     // Check for symlinks
     if (is_link($source)) {
         // No support for symlinks
         return true;
         //            return symlink(readlink($source), $dest);
     }
     // If it truly is a file
     if (is_file($source)) {
         // Check file is a Blueprint, ignore if it is and add it to the views, else copy it.
         $check = strpos(file_get_contents($source), TAG_START . TAG_BLUEPRINT);
         if ($check !== false) {
             $this->views[] = new View($this, $source);
             return true;
         }
         // Is this file a compress-ible file?
         if ($this->getGlobalCompression()) {
             // Copy / Return the already minimized versions of libraries
             if (strpos($source, ".min.") || strpos($source, "-min.")) {
                 Core::Output(INFO, "Not Compressing " . $source);
                 return copy($source, $dest);
             }
             switch (strtolower(pathinfo($dest, PATHINFO_EXTENSION))) {
                 case 'js':
                     $minifier = new Minify\JS($source);
                     Core::Output(INFO, "Compressing " . $source);
                     return file_put_contents($dest, $minifier->minify());
                 case 'css':
                     $minifier = new Minify\CSS($source);
                     Core::Output(INFO, "Compressing " . $source);
                     return file_put_contents($dest, $minifier->minify());
                 default:
                     return copy($source, $dest);
             }
         } else {
             return copy($source, $dest);
         }
     }
     // Make destination directory
     if (!is_dir($dest)) {
         mkdir($dest, $folderPermissions, true);
     }
     // Loop through the folder
     $dir = dir($source);
     while (false !== ($entry = $dir->read())) {
         // Skip pointers
         if ($entry == '.' || $entry == '..' || in_array($entry, $ignoreFiles) || \StringHelper::MaskCheck($entry, $ignoreMasks)) {
             continue;
         }
         // Deep copy directories
         $this->ProcessSiteFolder("{$source}/{$entry}", "{$dest}/{$entry}", $folderPermissions, $filePermissions, $ignoreFiles, $ignoreMasks);
     }
     // Clean up
     $dir->close();
     return true;
 }
Exemplo n.º 18
0
 public static function minifyCSS($css)
 {
     $minifier = new Minify\CSS();
     $minifier->add($css);
     return $minifier->minify();
 }
Exemplo n.º 19
0
$key = 'Infrajs::Collect::' . $isjs . $isgzip;
//Два кэша зазипованый и нет. Не все браузеры понимают зазипованую версию.
$code = Mem::get($key);
if (!$code) {
    if (!Load::isphp()) {
        header('Infrajs-Cache: false');
    }
    if ($isjs) {
        $code = Collect::js($name);
    } else {
        $code = Collect::css($name);
    }
    if ($isjs) {
        $min = new Minify\JS($code);
    } else {
        $min = new Minify\CSS($code);
    }
    if ($isgzip) {
        $code = $min->gzip();
    } else {
        $code = $min->minify();
    }
    Mem::set($key, $code);
}
if (!Load::isphp()) {
    if ($isgzip) {
        header('Content-Encoding: gzip');
        header('Vary: accept-encoding');
        header('Content-Length: ' . strlen($code));
    }
}
Exemplo n.º 20
0
 /**
  * Minifies CSS code you give it.
  * @param string $cssCode CSS code
  * @return string Minified CSS code
  */
 public function css($cssCode)
 {
     $this->_minifyCss->add($cssCode);
     return $this->_minifyCss->minify();
 }
Exemplo n.º 21
0
 /**
  * Minify CSS.
  *
  * @param $value
  *
  * @return string
  */
 public function minifyCss($value)
 {
     $minifier = new Minify\CSS($value);
     return $minifier->minify();
 }
Exemplo n.º 22
0
 public function performMinification($script)
 {
     $minifier = new CSS();
     $minifier->add($script);
     return $minifier->minify();
 }
Exemplo n.º 23
0
 public function __destruct()
 {
     // API
     if (substr($_SERVER['HTTP_ACCEPT'], 0, 6) == 'api://') {
         header('Content-Type: application/json');
         die((new Exec(substr($_SERVER['HTTP_ACCEPT'], 6), file_get_contents('php://input')))->json());
     }
     // API[FILE]
     if (substr($_SERVER['HTTP_ACCEPT'], 0, 12) == 'api[file]://') {
         $file = file_get_contents('php://input');
         $fileTmp = tempnam(sys_get_temp_dir(), microtime(1));
         file_put_contents($fileTmp, $file);
         File::add($fileTmp);
         die((new Exec(substr($_SERVER['HTTP_ACCEPT'], 12)))->json());
     }
     // VIEW
     if (substr($_SERVER['HTTP_ACCEPT'], 0, 7) == 'view://') {
         header('Content-Type: application/json');
         $path = substr($_SERVER['HTTP_ACCEPT'], 7);
         $html = explode('/', $path);
         foreach ($html as $key => $value) {
             $value = trim($value);
             if (empty($value)) {
                 unset($html[$key]);
             }
         }
         $output = [];
         ob_start();
         $view = new View();
         if (empty($html)) {
             $html = ['index'];
         }
         while ($name = array_shift($html)) {
             if (count($html) == 0) {
                 $view->{$name}();
             } else {
                 $view = $view->{$name};
             }
         }
         $html = ob_get_clean();
         $html = preg_replace('/\\>\\s+\\</Uui', '><', $html);
         $html = preg_replace('/\\s/Uui', ' ', $html);
         $html = preg_replace('/[ ]+/Uui', ' ', $html);
         $output['html'] = $html;
         $path = Path::$view . '' . $path;
         $css = $path . '/index.css';
         if (is_file($css)) {
             $output['css'] = file_get_contents($css);
         }
         $js = $path . '/index.js';
         if (is_file($js)) {
             $output['js'] = file_get_contents($js);
         }
         die(json_encode($output, JSON_UNESCAPED_UNICODE));
     }
     // Json
     $json = function ($path) {
         $json = $path . '/index.json';
         if (is_file($json)) {
             $json = file_get_contents($json);
             $json = json_decode($json, true);
         }
         return $json;
     };
     // Save get
     $save = Save::get();
     // Type Content
     switch (Path::$path) {
         case "js":
             $type = 'js';
             break;
         case "css":
             $type = 'css';
             break;
         default:
             $type = 'page';
     }
     // Js
     if ($type == 'js') {
         header("Content-Type: text/javascript");
         $config = $json(Path::$page . '/' . $_GET['path']);
         $content = '';
         // Config
         if (isset($config['js']) && is_array($config['js'])) {
             foreach ($config['js'] as $value) {
                 $file = Path::$js . '/' . $value . '.js';
                 if (is_file($file)) {
                     $content .= file_get_contents($file);
                 }
             }
         }
         // Slave
         $slave = Path::$page . '/' . $_GET['path'] . '/index.js';
         if (is_file($slave)) {
             $content .= file_get_contents($slave);
         }
         // Slave js
         if (isset($save['view'])) {
             foreach ($save['view'] as $path) {
                 $config = $json(Path::$view . '/' . $path);
                 if (isset($config['js']) && is_array($config['js'])) {
                     foreach ($config['js'] as $value) {
                         $file = Path::$js . '/' . $value . '.js';
                         if (is_file($file)) {
                             $content .= file_get_contents($file);
                         }
                     }
                 }
                 $file = Path::$view . $path . '/index.js';
                 if (!is_file($file)) {
                     continue;
                 }
                 $content .= file_get_contents($file);
             }
         }
         // Minify
         if (!empty($content)) {
             $minifier = new JS();
             $minifier->add($content);
             $content = $minifier->minify();
         }
         die($content);
     }
     // Css
     if ($type == 'css') {
         header("Content-Type: text/css");
         $config = $json(Path::$page . '/' . $_GET['path']);
         $content = '';
         // Config
         if (isset($config['css']) && is_array($config['css'])) {
             foreach ($config['css'] as $value) {
                 $file = Path::$css . '/' . $value . '.css';
                 if (is_file($file)) {
                     $content .= file_get_contents($file);
                 }
             }
         }
         // Slave
         $slave = Path::$page . '/' . $_GET['path'] . '/index.css';
         if (is_file($slave)) {
             $content .= file_get_contents($slave);
         }
         // Slave view
         if (isset($save['view'])) {
             foreach ($save['view'] as $path) {
                 $config = $json(Path::$view . '/' . $path);
                 if (isset($config['css']) && is_array($config['css'])) {
                     foreach ($config['css'] as $value) {
                         $file = Path::$css . '/' . $value . '.css';
                         if (is_file($file)) {
                             $content .= file_get_contents($file);
                         }
                     }
                 }
                 $file = Path::$view . $path . '/index.css';
                 if (!is_file($file)) {
                     continue;
                 }
                 $content .= file_get_contents($file);
             }
         }
         // Minify
         if (!empty($content)) {
             $minifier = new CSS();
             $minifier->add($content);
             $content = $minifier->minify();
         }
         die($content);
     }
     // Page
     $content = '';
     ob_start();
     new Page();
     $content = ob_get_clean();
     $save = Save::get();
     $save['view'] = Info::$view;
     Save::set($save);
     $title = Meta::$title;
     $title = implode(' &ndash; ', $title);
     $description = Meta::$description;
     $keywords = Meta::$keywords;
     $keywords = implode(', ', $keywords);
     $content = '<!DOCTYPE html>' . '<html>' . '<head>' . '<title>' . $title . '</title>' . '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . '<link rel="icon" type="image/x-icon" sizes="16x16" href="/favicon.ico">' . '<meta name ="Generator" Content="LiveSugare">' . '<meta name="description" Content="' . $description . '">' . '<meta name="keywords" Content="' . $keywords . '">' . '<meta name="robots" content="Index,follow">' . '<meta charset="utf-8">' . '<meta name="viewport" content="width=device-width, initial-scale=1">' . '<link rel="stylesheet" type="text/css" href="/css?path=' . Path::$path . '">' . '<script src="/js?path=' . Path::$path . '" type="text/javascript"></script>' . '</head>' . '<body>' . $content . '</body></html>';
     $content = preg_replace('/\\>\\s+\\</Uui', '><', $content);
     $content = preg_replace('/\\s/Uui', ' ', $content);
     $content = preg_replace('/[ ]+/Uui', ' ', $content);
     die($content);
 }
Exemplo n.º 24
0
 public function minifyCss($s)
 {
     $oMinifier = new Minify\CSS();
     $oMinifier->add($s);
     return $oMinifier->minify();
 }