Exemplo n.º 1
0
 /**
  * Minify Javascript.
  *
  * @param string $js Javascript to be minified
  * @return string
  */
 public static function minify($js, $pic = false)
 {
     $jsmin = new JSMin($js, $pic);
     $min = $jsmin->min();
     unset($jsmin);
     return $min;
 }
Exemplo n.º 2
0
 function minify($js)
 {
     $jsmin = new JSMin($js);
     $output = $jsmin->min();
     if ($output === false) {
         return $js;
     }
     return $output;
 }
Exemplo n.º 3
0
 private function get_js_html($cachefile)
 {
     if (Configure::read('debug') > 0) {
         $ret = "";
         foreach ($this->libs['js'] as $lib) {
             $ret .= $this->Javascript->link($lib);
         }
         return $ret;
     }
     if (file_exists($this->cachePath['js'] . '/' . $cachefile)) {
         return $this->Javascript->link($cachefile);
     }
     // Get the content
     $file_content = '';
     foreach ($this->libs['js'] as $lib) {
         $file_content .= "\n\n" . file_get_contents($this->basePath['js'] . '/' . $lib);
     }
     // If compression is enable, compress it !
     if ($this->__options['js']['enableCompression']) {
         App::import('Vendor', 'jsmin/jsmin');
         $file_content = trim(JSMin::minify($file_content));
     }
     // Get inline code if exist
     // Do it after jsmin to preserve variable's names
     if (!empty($this->inline_code['js'])) {
         foreach ($this->inline_code['js'] as $inlineJs) {
             $file_content .= "\n\n" . $inlineJs;
         }
     }
     if ($fp = fopen($this->cachePath['js'] . '/' . $cachefile, 'wb')) {
         fwrite($fp, $file_content);
         fclose($fp);
     }
     return $this->Javascript->link($cachefile);
 }
Exemplo n.º 4
0
 public static function pack($compression = 'none', $code = '')
 {
     if (!$code) {
         throw new PHPJS_Exception('No code to pack');
         return false;
     }
     switch ($compression) {
         case 'packed':
             require_once dirname(__FILE__) . '/Pack/class.JavaScriptPacker.php';
             $packer = new JavaScriptPacker($code, 'Normal', true, false);
             $code = $packer->pack();
             break;
         case 'minified':
             require_once dirname(__FILE__) . '/Pack/jsmin.php';
             $code = JSMin::minify($code);
             break;
         case 'none':
             break;
         default:
             throw new PHPJS_Exception('No such packer: "' . $compression . '"');
             return false;
             break;
     }
     return '// Compression: ' . $compression . "\n\n" . $code;
 }
Exemplo n.º 5
0
 function compile()
 {
     $output = $this->CI->output->get_output();
     // get <head> contents
     $matches = array();
     preg_match('#<head>(.*?)<\\/head>#si', $output, $matches);
     // head contents
     $head = $matches[1];
     // get JS includes via <script> references
     preg_match_all('#<script(.*?)src="(.*?)"(.*?)>(.*?)<\\/script>#si', $head, $matches);
     $js_includes = $matches[2];
     // delete non-local includes
     foreach ($js_includes as $key => $script) {
         if (strpos($script, '//') !== FALSE and strpos($script, $this->CI->config->item('base_url')) === FALSE) {
             // this script is external (has "//") and it's not just a domain reference to this site
             unset($js_includes[$key]);
         }
     }
     if (!empty($js_includes)) {
         $this->load->library('JSMin');
         // minify!
         $js_compiled = '';
         foreach ($js_includes as $script) {
             // get the file
             $js_compiled .= JSMin::minify($script);
         }
     }
     // TODO:
     // - load the files for minification
     //		- this includes using the base_href tag if one exists, otherwise loading paths relative to the domain or
     //		  using the full script URL if it's in that format
     // - replace old <script> references with one big reference
     // return the output
 }
Exemplo n.º 6
0
/**
 * Emoji表情解析
 * @return string
 * @param [string] [$str] [将字符串中的[E537] 这类的emoji标签【仅支持SB Unicode】转化为Unicode值 ]
 *        emoji标签 详情网址: http://punchdrunker.github.io/iOSEmoji/table_html/index.html
 */
function Amango_Asset($options, $type = 'js')
{
    $path = './Data/js_cache/' . md5($options) . '.js';
    if (!is_file($path)) {
        //静态资源地址
        $files = explode(',', $options);
        $content = '';
        foreach ($files as $val) {
            $content .= file_get_contents('.' . str_replace(__ROOT__, '', $val));
        }
        import('Common.ORG.JSMin');
        $JSMin = new JSMin();
        file_put_contents($path, $JSMin->minify($content));
    }
    echo '<script type="text/javascript" src="' . $path . '?' . time() . '"></script>';
}
Exemplo n.º 7
0
 public function minify($inPath, $outPath)
 {
     $extension = $this->getExtension($inPath);
     echo basename($inPath) . ' -> ' . basename($outPath) . '...';
     $inText = file_get_contents($inPath);
     if ($inText === false) {
         $this->error("Unable to open file {$inPath} for reading.");
         exit(1);
     }
     $outFile = fopen($outPath, 'w');
     if (!$outFile) {
         $this->error("Unable to open file {$outPath} for writing.");
         exit(1);
     }
     switch ($extension) {
         case 'js':
             $outText = JSMin::minify($inText);
             break;
         default:
             $this->error("No minifier defined for extension \"{$extension}\"");
     }
     fwrite($outFile, $outText);
     fclose($outFile);
     echo " ok\n";
 }
Exemplo n.º 8
0
 public function minify()
 {
     if ($this->contentType != 'text/css') {
         G::LoadThirdParty('jsmin', 'jsmin');
         $this->content = JSMin::minify($this->content);
     }
 }
Exemplo n.º 9
0
 /**
  * Минификация яваскриптов
  * 
  * @return void
  */
 public function jsAction()
 {
     $this->_response->setHeader('Content-Type', 'text/javascript', true);
     if (isset($this->_params['files'])) {
         $files = explode(',', $this->_params['files']);
         foreach ($files as $key => $file) {
             $file = $this->_jsdir . trim($file) . '.js';
             if (file_exists($file)) {
                 $files[$key] = $file;
             }
         }
         if (!empty($files)) {
             $cacheid = 'minify_js_' . md5(implode(',', $files));
             $this->_cache->setMasterFiles($files);
             if ($this->_cache->test($cacheid)) {
                 $this->_response->setBody($this->_cache->load($cacheid));
             } else {
                 require_once 'Phorm/Plugin/jsmin.php';
                 $str = '';
                 foreach ($files as $file) {
                     $str .= file_get_contents($file) . PHP_EOL;
                 }
                 $js = JSMin::minify($str);
                 $this->_cache->save($js, $cacheid);
                 $this->_response->setBody($js);
             }
         }
     }
 }
Exemplo n.º 10
0
 public static function minifyJs(array $jsFiles)
 {
     if (true) {
         foreach ($jsFiles as $path) {
             $pathInfo = pathinfo($path);
             if (strpos($path, 'js/xenforo/') !== false) {
                 // ignore xenforo files
                 continue;
             }
             $dirName = $pathInfo['dirname'];
             $realDirName = realpath($dirName);
             $fullDirName = realpath($realDirName . '/full');
             $baseName = $pathInfo['basename'];
             $minPath = $realDirName . '/' . $baseName;
             $fullPath = $fullDirName . '/' . $baseName;
             if (file_exists($fullPath) and (!file_exists($minPath) or filemtime($fullPath) > filemtime($minPath))) {
                 $fullContents = file_get_contents($fullPath);
                 if (strpos($fullContents, '/* no minify */') === false) {
                     require_once dirname(__FILE__) . '/../Lib/jsmin-php/jsmin.php';
                     $minified = JSMin::minify($fullContents);
                 } else {
                     // the file requested not to be minify... (debugging?)
                     $minified = $fullContents;
                 }
                 self::writeFile($minPath, $minified, false, false);
             }
         }
     }
 }
Exemplo n.º 11
0
function moodbile_performance_minify_js($js)
{
    global $CFG;
    require_once $CFG['basepath'] . 'misc/jsmin.php';
    $js = JSMin::minify($js);
    return $js;
}
Exemplo n.º 12
0
 /** 
  * minify js and return js link
  * if minify is disabled: return direct js links
  *
  * @return string with html tag
  * @param array $javascripts with js files
  */
 public function minifyjs($javascripts)
 {
     if (Zend_Registry::get('config')->cache->enable == 1 && Zend_Registry::get('config')->cache->minifyjs == 1) {
         // check file
         $target = Zend_Registry::get('config')->pub->path . 'javascript/' . Zend_Registry::get('config')->cache->minifiedjsfile;
         $targeturl = 'javascript/' . Zend_Registry::get('config')->cache->minifiedjsfile;
         if (file_exists($target)) {
             return "<script type=\"text/javascript\" src=\"" . $targeturl . "\"></script>\n";
         }
         // load and minify files
         $all = "";
         foreach ($javascripts as $js) {
             $jscontent = file_get_contents(Zend_Registry::get('config')->pub->path . $js);
             $jscontent = JSMin::minify($jscontent);
             $all = $all . "\n\n// " . $js . "\n" . $jscontent;
         }
         file_put_contents($target, $all);
         return "<script type=\"text/javascript\" src=\"" . $targeturl . "\"></script>\n";
     } else {
         $ret = "";
         foreach ($javascripts as $js) {
             $ret = $ret . "<script type=\"text/javascript\" src=\"" . $js . "\"></script>\n";
         }
         return $ret;
     }
 }
function addjstext($output, $minify = true)
{
    if ($minify == true && (MINIFY == true || MINIFY == 1)) {
        $output = JSMin::minify($output);
    }
    return $output;
}
Exemplo n.º 14
0
 public function beforeAction($action)
 {
     $base = Cshop::$rootpath;
     $jsfilename = $base . "/static/cache/final.js";
     if (!file_exists($jsfilename)) {
         $filename = $base . "/static/js/jquery.js";
         $js = file_get_contents($filename);
         $filename = $base . "/static/js/jquery-ui.js";
         $js .= file_get_contents($filename);
         $filename = $base . "/static/js/jquery.mousewheel.js";
         $js .= file_get_contents($filename);
         $filename = $base . "/static/js/perfect-scrollbar.js";
         $js .= file_get_contents($filename);
         $filename = $base . "/static/js/jquery.placeholder.js";
         $js .= file_get_contents($filename);
         $filename = $base . "/static/js/jquery.noty.packaged.min.js";
         $js .= file_get_contents($filename);
         $filename = $base . "/static/js/script.js";
         $js .= file_get_contents($filename);
         $js = JSMin::minify($js);
         file_put_contents($jsfilename, $js);
     }
     $cssfilename = $base . "/static/cache/final.css";
     if (!file_exists($cssfilename)) {
         $filename = $base . "/static/css/style.css";
         $css = file_get_contents($filename);
         $filename = $base . "/static/css/perfect-scrollbar.css";
         $css .= file_get_contents($filename);
         $minify = new CSSmin();
         $css = $minify->run($css, true);
         file_put_contents($cssfilename, $css);
     }
     return parent::beforeAction($action);
 }
Exemplo n.º 15
0
 /**
  * override method: get content of css files
  */
 function getJsContents($files, $isCompressed = true, $isYUI = false)
 {
     $contents = "/**ICE-ENGINE-JS**/";
     foreach ($files as $file) {
         $subpath = str_replace('/', DS, $file);
         $fullpath = JPATH_ROOT . DS . $subpath;
         //	$basepath = preg_replace( '/^\//', '', dirname($files2[$key]) );
         $contentFile = '';
         if (preg_match('/\\.php/', $file)) {
             $contentFile = @file_get_contents(JURI::base() . str_replace("&amp;", "&", $file));
         } else {
             if (file_exists($fullpath)) {
                 // get Content Of File;
                 $contentFile = @file_get_contents($fullpath);
             }
         }
         if ($contentFile) {
             $contents .= "/** '.{$subpath}.' **/\t";
             $contents .= $contentFile;
         }
     }
     if ($isCompressed) {
         if ($isYUI) {
             $app =& JFactory::getApplication();
             Minify_YUICompressor::$jarFile = dirname(__FILE__) . DS . 'Minify' . DS . 'yuicompressor-2.4.6.jar';
             Minify_YUICompressor::$tempDir = $app->getCfg("tmp_path");
             $contents = Minify_YUICompressor::minifyJs($contents, array('nomunge' => true, 'line-break' => 1000));
         } else {
             $contents = JSMin::minify($contents);
         }
     }
     return $contents;
 }
Exemplo n.º 16
0
 /**
  * Combine multiple text assets into a single file for better http performance this
  * method generates a new cache file with every symfony cc you can override the cache
  * by adding ?clearassetcache=1 to the page request.
  *
  * @param type      string css or js
  * @param namespace string the combined file namespace (eg. module+action names)
  * @param response  object the sfWebResponse instance
  * @return          string the url for the combiner service
  */
 public function combine($type, $namespace, sfWebResponse $response)
 {
     //configure the combiner
     $type = $type === 'css' ? 'css' : 'js';
     $fullname = $type === 'css' ? 'Stylesheets' : 'Javascripts';
     $response_getter = 'get' . $fullname;
     $namespace = StreemeUtil::slugify($namespace);
     //integrate into symfony's asset globals
     sfConfig::set(sprintf('symfony.asset.%s_included', strtolower($fullname)), true);
     //build the cache filename - this file will be regenerated on a symfony cc
     $path = sprintf('%s/combine/%s/', sfConfig::get('sf_cache_dir'), $type);
     $filename = sprintf('%s.%s', $namespace, $type);
     // you can force a cache clear by passing ?clearassetcache=1 to any template
     if (!is_readable($path . $filename) || @$_GET['clearassetcache'] == 1) {
         //build one file of all of the css or js files
         $file_content = '';
         //load vendor libraries for minifying assets
         require_once sfConfig::get('sf_lib_dir') . '/vendor/jsmin/jsmin.php';
         require_once sfConfig::get('sf_lib_dir') . '/vendor/cssmin/cssmin.php';
         foreach ($response->{$response_getter}() as $file => $options) {
             if ($type === 'css') {
                 $file_content .= CSSMin::minify(file_get_contents(sfConfig::get('sf_web_dir') . $file));
             } else {
                 $file_content .= JSMin::minify(file_get_contents(sfConfig::get('sf_web_dir') . $file));
             }
         }
         //this file resides in the cache and requires wide permissions for both cli and apache users
         @umask(00);
         @mkdir($path, 0777, true);
         file_put_contents($path . $filename, $file_content);
     }
     return sprintf('/service/combine/%s/%s', $type, str_replace('-', '_', $namespace));
 }
Exemplo n.º 17
0
 /**
  * Include Javascript files
  *
  * @param array $files
  * @return string HTML JavaScript file include
  */
 function js($files = array())
 {
     // Output links to normal uncompressed files if developing
     if (Configure::read('debug') > 0) {
         return $this->Javascript->link($files);
     }
     // Create new packed files if not up to date
     $jsBaseName = 'cache.js';
     $jsFilePath = "{$this->_jsDir}{$jsBaseName}";
     // Create the cache if it doesn't exist
     if (!file_exists($jsFilePath)) {
         $save = '';
         // Get content of all files
         foreach ($files as &$file) {
             $file = str_replace('/', DS, $file);
             // replace URL dash with file system dash
             $ext = substr(strrchr($file, '.'), 1);
             // Add .js file extension if using short file name
             if ($ext !== '.js') {
                 $file = "{$file}.js";
             }
             $path = "{$this->_jsDir}{$file}";
             // Add file content
             $save .= file_get_contents($path);
         }
         // Minify the JavaScript content
         $save = JSMin::minify($save);
         $file = fopen($jsFilePath, 'w');
         fwrite($file, $save);
         fclose($file);
     }
     return $this->Javascript->link($jsBaseName);
 }
Exemplo n.º 18
0
 public static function run($mode, $browser = 'cross')
 {
     self::$buildDir = dirname(__FILE__) . DIRECTORY_SEPARATOR;
     self::$browser = $browser;
     chdir(self::$buildDir . '..');
     $release = $mode == 'release' || file_exists(self::gitHead) && preg_match('!/master$!', file_get_contents(self::gitHead));
     $buildMode = $release ? 'Release' : 'Dev';
     echo "{$buildMode} mode\n";
     $buildTime = date('Y-m-d H:i:s');
     $buildNumber = (int) @file_get_contents(self::buildFile);
     if ($release) {
         // increase release build number for extensions
         /* Now we can't increate it automatically. Do this manually
         			$buildNumber++;
         			file_put_contents(self::buildFile, $buildNumber);
         			*/
         echo "Build number: {$buildNumber}\n";
     }
     $code = strtr(file_get_contents(self::core), array('// @corelibs@' => self::sourcesByList('corelibs.txt', 'core/'), '// @contentModules@' => self::sourcesByList('contentModules.txt', 'content/'), '// @modules@' => self::sourcesByList('modules.txt', 'modules/'), '@buildTime@' => $buildTime, '@buildMode@' => $buildMode, '@buildNumber@' => $buildNumber, '// @jQuery@' => file_get_contents('core/libs/jquery.js')));
     if ($release) {
         file_put_contents(self::revisor, json_encode(array('buildTime' => $buildTime)));
         echo "Compressing...\n";
         require_once self::$buildDir . 'jsmin.php';
         $parts = explode('==/UserScript==', $code);
         $parts[1] = JSMin::minify($parts[1]);
         $code = implode("==/UserScript==\n", $parts);
         $output = self::output;
     } else {
         $output = self::devOutput;
     }
     file_put_contents($output, $code);
     echo "done.\n";
     echo "Now install " . realpath($output) . " script into your browser.\n";
 }
Exemplo n.º 19
0
 public static function getCompressed()
 {
     ob_end_clean();
     header('Content-Encoding: none');
     if (!array_key_exists('file', $_GET)) {
         die;
     }
     $filename = PATH_ABS_ROOT . ltrim($_GET['file'], '/');
     $contents = file_get_contents($filename);
     $etag = sha1($filename . $contents);
     $ext = pathinfo($filename, PATHINFO_EXTENSION);
     switch ($ext) {
         case 'js':
             $type = 'text/javascript';
             $contents = JSMin::minify($contents);
             break;
         case 'css':
             $type = 'text/css';
             //$contents = CssMin::minify($contents);
             break;
         default:
             $type = 'text/html';
     }
     //		utopia::Cache_Check($etag,$type);
     utopia::Cache_Output($contents, $etag, $type);
     die($contents);
 }
Exemplo n.º 20
0
    protected function load($path)
    {
        if (isset($this->loaded[$path])) {
            return '';
        }
        if (!file_exists($path)) {
            die("ERROR: Couldn't load {$path} required from {$this->currentInput}\n");
        }
        echo "loading {$path} \n";
        $this->loaded[$path] = true;
        $this->currentInput = $path;
        $code = file_get_contents($path);
        $this->bytesIn += strlen($code);
        $this->fileCount++;
        if ($this->format & self::MINIFIED) {
            $code = trim(JSMin::minify($code));
        }
        // Naively probe the file for 'ig.module().requires().defines()' code;
        // the 'requries()' part will be handled by the regexp callback
        $this->definesModule = false;
        $code = preg_replace_callback('/ig\\s*
				\\.\\s*module\\s*\\((.*?)\\)\\s*
				(\\.\\s*requires\\s*\\((.*?)\\)\\s*)?
				\\.\\s*defines\\s*\\(
			/smx', array($this, 'loadCallback'), $code);
        // All files should define a module; maybe we just missed it? Print a
        // friendly reminder :)
        if (!$this->definesModule) {
            echo "WARNING: file {$path} seems to define no module!\n";
        }
        return $code;
    }
Exemplo n.º 21
0
 public function run($args)
 {
     if (!count($args)) {
         echo $this->getHelp();
         die;
     }
     $jsWebDir = rtrim(array_shift($args), DIRECTORY_SEPARATOR);
     $jsFileExt = array_shift($args) ?: 'js';
     $jsMinSuffix = array_shift($args) ?: 'min';
     $combine = array_shift($args) ?: false;
     echo "\n\n\n";
     echo "I will minify js-files (*.{$jsFileExt}) in '{$jsWebDir}' directory !\n\n";
     if (!is_dir($jsWebDir) || !is_writable($jsWebDir)) {
         die("\n!!!! Can't access {$jsWebDir} directory, check path and access rights! !!!!!\n");
     }
     $rawFiles = glob("{$jsWebDir}/*.{$jsFileExt}");
     $file = array();
     if (count($rawFiles)) {
         echo "I will add '{$jsMinSuffix}' suffix to minifyed files!\n\n";
         echo "Found " . count($rawFiles) . " files\n";
         $totalSize = 0;
         foreach ($rawFiles as $f) {
             $file[$f] = filesize($f);
             echo basename($f) . ' ===> ' . $file[$f] . " bytes\n";
             $totalSize += $file[$f];
         }
         echo "===== Without compress/minify: {$totalSize} bytes ======\n\n\n\n";
         echo "\n===== GoGoGoGo! Compress them all !!! ===== \n\n";
         $totalMinSize = 0;
         $combineFileName = $combineContent = '';
         foreach ($rawFiles as $rf) {
             $minFileContents = JSMin::minify(file_get_contents($rf));
             if ($combine) {
                 $combineContent .= $minFileContents;
             }
             $minFileName = rtrim(basename($rf), $jsFileExt) . $jsMinSuffix . '.' . $jsFileExt;
             $minFileSize = file_put_contents(dirname($rf) . DIRECTORY_SEPARATOR . $minFileName, $minFileContents);
             $totalMinSize += $minFileSize;
             echo $minFileName . ' ===> ' . $minFileSize . " bytes (" . round(($file[$rf] - $minFileSize) / 100, 2) . "%)\n";
         }
         echo "\n\n===== After compress/minify: {$totalMinSize} bytes ======\n\n";
         if ($combine) {
             $combineFileName = "{$combine}.{$jsMinSuffix}.{$jsFileExt}";
             $combineFileSize = file_put_contents($jsWebDir . DIRECTORY_SEPARATOR . $combineFileName, $combineContent);
             echo "===== Created combined file '{$jsWebDir}/{$combineFileName}', size: {$combineFileSize} bytes ====== \n\n";
         }
         $totalPercent = round(($totalSize - $totalMinSize) / 100);
         $diffSize = $totalSize - $totalMinSize;
         echo "===== Size of your scripts is reduced by " . $totalPercent . '% (' . $diffSize . " bytes) ======\n\n";
         echo "\nThanks for minify js-files, your users will be happy!!!\n";
         echo "\np.s. don't forget minify css-files too!!!\n";
         echo "\np.p.s. use NGINX for serve static files =) !!!\n";
         echo "\np.p.s. Follow me on twitter http://twitter.com/xomaa !!!\n";
         echo "\nПока!!!\n\n\n";
     } else {
         echo "\n !!! Files '*.{$jsFileExt}' in directory '{$jsWebDir}' not found !!! \n\n\n";
         exit;
     }
 }
Exemplo n.º 22
0
 function minify()
 {
     $this->setTemplate(get_template_path("empty"));
     if (!logged_user()->isAdministrator()) {
         die("You must be an administrator to run this tool.");
     }
     // include libraries
     include_once LIBRARY_PATH . '/jsmin/JSMin.class.php';
     include_once LIBRARY_PATH . '/cssmin/CSSMin.class.php';
     // process arguments
     $minify = isset($_GET['minify']);
     // process javascripts
     echo "Concatenating javascripts ... \n";
     $files = (include "application/layouts/javascripts.php");
     $jsmin = "";
     foreach ($files as $file) {
         $jsmin .= file_get_contents("public/assets/javascript/{$file}") . "\n";
     }
     echo "Done!<br>\n";
     if ($minify) {
         echo "Minifying javascript ... \n";
         $jsmin = JSMin::minify($jsmin);
         echo "Done!<br>\n";
     }
     echo "Writing to file 'ogmin.js' ... ";
     file_put_contents("public/assets/javascript/ogmin.js", $jsmin);
     echo "Done!<br>";
     echo "<br>";
     // process CSS
     function changeUrls($css, $base)
     {
         return preg_replace("/url\\s*\\(\\s*['\"]?([^\\)'\"]*)['\"]?\\s*\\)/i", "url(" . $base . "/\$1)", $css);
     }
     function parseCSS($filename, $filebase, $imgbase)
     {
         $css = file_get_contents($filebase . $filename);
         $imports = explode("@import", $css);
         $cssmin = changeUrls($imports[0], $imgbase);
         for ($i = 1; $i < count($imports); $i++) {
             $split = explode(";", $imports[$i], 2);
             $import = trim($split[0], " \t\n\r\v'\"");
             $cssmin .= parseCSS($import, $filebase, $imgbase . "/" . dirname($import));
             $cssmin .= changeUrls($split[1], $imgbase);
         }
         return $cssmin;
     }
     echo "Concatenating CSS ... ";
     $cssmin = parseCSS("website.css", "public/assets/themes/default/stylesheets/", ".");
     echo "Done!<br>";
     if ($minify) {
         echo "Minifying CSS ... ";
         $cssmin = CSSMin::minify($cssmin);
         echo "Done!<br>";
     }
     echo "Writing to file 'ogmin.css' ... ";
     file_put_contents("public/assets/themes/default/stylesheets/ogmin.css", $cssmin);
     echo "Done!<br>";
     die;
 }
Exemplo n.º 23
0
 /**
  * {@inheritdoc}
  */
 protected function execute($string)
 {
     try {
         return \JSMin::minify($string);
     } catch (\JSMinException $exception) {
         return $string;
     }
 }
Exemplo n.º 24
0
 public static function packJS($js_content)
 {
     if (strlen($js_content) > 0) {
         require_once _PS_TOOL_DIR_ . 'js_minify/jsmin.php';
         return JSMin::minify($js_content);
     }
     return false;
 }
Exemplo n.º 25
0
/**
 * Minify js
 * 
 * @param string $content
 * @return string
 */
function minifyJs($content)
{
    if (!empty($_GET['minoff'])) {
        return $content;
    }
    require_once 'JSMin.php';
    return JSMin::minify($content);
}
Exemplo n.º 26
0
function minify_javascript($command, $args)
{
    CLI::logging("BUILD-JS\n");
    //disabling the rakefile version, until we have updated the dev environment
    //CLI::logging("Checking if rake is installed...\n");
    //$rakeFile = PROCESSMAKER_PATH . "workflow/engine/bin/tasks/Rakefile";
    //system('rake -f ' . $rakeFile);

    require_once (PATH_THIRDPARTY . 'jsmin/jsmin.php');

    $libraries = json_decode( file_get_contents ( PATH_HOME . 'engine/bin/tasks/libraries.json' ));
    //print_r($libraries);

    foreach ($libraries as $k=>$library ) {
        $build = $library->build;
        if ($build) {
            $bufferMini = "";
            $sum1 = 0;
            $sum2 = 0;
            $libName = $library->name;
            $files   = $library->libraries;
            $js_path = $library->build_js_to;
            printf ("Processing %s library:\n", $libName );
            foreach ( $files as $file ) {
                printf ( "    %-20s ", $file->name );
                $fileNameMini = PATH_TRUNK . $file->mini;
                if ($file->minify) {
                    $minify = JSMin::minify( file_get_contents( $fileNameMini ) );
                } else {
                    $minify = file_get_contents( $fileNameMini );
                }
                $bufferMini .= $minify;
                $size1 = filesize($fileNameMini);
                $size2 = strlen($minify);
                $sum1 += $size1;
                $sum2 += $size2;
                printf ("%7d -> %7d %5.2f%%\n", $size1, $size2, 100 - $size2/$size1*100) ;
            }
            if (substr($library->build_js_to ,-1) != '/') {
                $library->build_js_to .= '/';
            }
            $outputMiniFile = PATH_TRUNK . $library->build_js_to . $libName . ".js";
            file_put_contents ( $outputMiniFile, $bufferMini );
            printf ("    -------------------- -------    ------- ------\n");
            printf ("    %-20s %7d -> %7d %6.2f%%\n", $libName.'.js', $sum1, $sum2, 100-$sum2/$sum1*100) ;
            print "    $outputMiniFile\n";

        }
    }

    //Safe upgrade for JavaScript files
    CLI::logging("\nSafe upgrade for files cached by the browser\n\n");

    G::browserCacheFilesSetUid();

    //Done
    CLI::logging("BUILD-JS DONE\n");
}
Exemplo n.º 27
0
 /**
  */
 public function apply($in, $params = [])
 {
     require_php_lib('jsmin');
     if (!class_exists('\\JSMin')) {
         throw new Exception('Assets: class \\JSMin not found');
         return $in;
     }
     return \JSMin::minify($in);
 }
Exemplo n.º 28
0
 public function getMinified($type)
 {
     $retval = '';
     $files = $this->assets[$type];
     foreach ($files as $file) {
         $retval .= ($type === self::css ? $this->normalizeUrls($file) : JSMin::minify(file_get_contents($file))) . "\n";
     }
     return $retval;
 }
Exemplo n.º 29
0
 public function doProcessFile($file, $replace = false)
 {
     $optimizedContent = JSMin::minify(file_get_contents($file));
     if ($replace) {
         return parent::replaceFile($file, $optimizedContent);
     } else {
         return $optimizedContent;
     }
 }
Exemplo n.º 30
0
/**
 * Filter function used by compress.php to minify contents of javascript files
 *
 * @param	string	$content
 * @return	$content
 */
function jsmin_compress_filter($content)
{
    class_exists('JSMin') or (require VIVVO_FS_INSTALL_ROOT . 'lib/minify/JSMin.php');
    try {
        $content = JSMin::minify($content);
    } catch (Exception $e) {
    }
    return $content;
}