Example #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;
 }
Example #2
0
 function minify($js)
 {
     $jsmin = new JSMin($js);
     $output = $jsmin->min();
     if ($output === false) {
         return $js;
     }
     return $output;
 }
Example #3
0
	public static function minify($js, $level=3) {
		$jsmin = new JSMin($js, $level);
		return $jsmin->min();
	}
Example #4
0
 public function minify($aFiles, $sVersion, $bIsJS = true, $bDoInit = false, $bReturn = false, $bReplaceUrl = true)
 {
     static $oFormat = null;
     if (!isset($oFormat)) {
         $oFormat = Phpfox::getLib('parse.format');
     }
     if (!is_array($aFiles)) {
         $aFiles = array($aFiles);
     }
     $sHash = md5(implode($aFiles) . $sVersion);
     $sNameMd5 = md5(implode($aFiles) . $sVersion) . ($bIsJS ? '.js' : '.css');
     $sFilePath = PHPFOX_DIR_FILE . 'static' . PHPFOX_DS . $sNameMd5;
     $sUrl = Phpfox::getParam('core.path') . 'file/static/' . $sNameMd5;
     $bExists = false;
     if (Phpfox::getParam('core.allow_cdn') && Phpfox::getParam('core.push_jscss_to_cdn')) {
         $sCacheId = Phpfox::getLib('cache')->set(array('jscss', $sHash));
         if (Phpfox::getLib('cache')->get($sCacheId)) {
             $bExists = true;
         }
     } else {
         $bExists = file_exists($sFilePath);
     }
     if ($bExists) {
         if (Phpfox::getParam('core.allow_cdn') && Phpfox::getParam('core.push_jscss_to_cdn')) {
             $sUrl = Phpfox::getLib('cdn')->getUrl($sUrl);
         }
     } else {
         $sMinified = '';
         if ($bIsJS) {
             foreach ($aFiles as $sFile) {
                 $sOriginal = file_get_contents(PHPFOX_DIR . $sFile);
                 $oJsMin = new JSMin($sOriginal);
                 $sCompressed = $oJsMin->min();
                 // $sCompressed = $oFormat->helpJS($sCompressed);
                 $sMinified .= "\n /* {$sFile} */" . $sCompressed;
             }
         } else {
             $sHomeThemePath = Phpfox::getParam('core.force_https_secure_pages') && Phpfox::getParam('core.force_secure_site') ? 'https://' : 'http://';
             $sHomeThemePath .= Phpfox::getParam('core.host') . Phpfox::getParam('core.folder') . 'theme';
             foreach ($aFiles as $sFile) {
                 $sOriginal = file_get_contents(PHPFOX_DIR . $sFile);
                 $sCompressed = str_replace(array("\r\n", "\r", "\n", "\t", '  ', '    ', '    '), ' ', $sOriginal);
                 $sPathTo = substr($sFile, 0, strrpos($sFile, '/'));
                 $sPathTo = substr($sPathTo, 0, strrpos($sPathTo, '/'));
                 if (Phpfox::getParam('core.allow_cdn') && Phpfox::getParam('core.push_jscss_to_cdn') && defined('PHPFOX_IS_HOSTED_SCRIPT')) {
                     $sCompressed = str_replace('url(\'..', 'url(\'' . Phpfox::getCdnPath() . '' . $sPathTo, $sCompressed, $iCount);
                     $sCompressed = str_replace('url("..', 'url("' . Phpfox::getCdnPath() . '' . $sPathTo, $sCompressed, $iCount);
                     $sCompressed = str_replace('url(..', 'url(' . Phpfox::getCdnPath() . '' . $sPathTo, $sCompressed, $iCount);
                 } else {
                     if ($bReplaceUrl == true) {
                         $sCompressed = str_replace('url(\'..', 'url(\'../../' . $sPathTo, $sCompressed, $iCount);
                         $sCompressed = str_replace('url("..', 'url("../../' . $sPathTo, $sCompressed, $iCount);
                         $sCompressed = str_replace('url(..', 'url(../../' . $sPathTo, $sCompressed, $iCount);
                         $sCompressed = str_replace('../../theme', '' . $sHomeThemePath, $sCompressed, $iCount);
                     }
                 }
                 if ($bReplaceUrl == true) {
                     $sCompressed = str_replace('css/', 'image/', $sCompressed);
                 }
                 $sMinified .= $sCompressed;
             }
         }
         if ($bReturn == true) {
             return $sMinified;
         }
         if ($bIsJS && $bDoInit) {
             $sMinified .= "\n" . '$Core.init();';
         }
         file_put_contents($sFilePath, $sMinified);
         // if cdn enabled put it in cdn as well here
         if (Phpfox::getParam('core.allow_cdn') && Phpfox::getParam('core.push_jscss_to_cdn')) {
             Phpfox::getLib('cache')->save($sCacheId, '1');
             Phpfox::getLib('cdn')->put($sFilePath);
             $sUrl = Phpfox::getLib('cdn')->getUrl($sUrl);
         }
     }
     return $sUrl . $sVersion;
 }
Example #5
0
 public static function Minificar_JS_CSS()
 {
     if (file_exists(dirname(__FILE__) . '/Config/ArchivosMinify.php')) {
         include "CSSMin.php";
         include "JSMin.php";
         $MinDebug = "\n";
         //$MinDebug = "";
         $ArrayMin = (require dirname(__FILE__) . '/Config/ArchivosMinify.php');
         $StringJS = "";
         foreach ($ArrayMin["js"] as $Archivo) {
             $JSMin = new JSMin(file_get_contents(dirname(__FILE__) . $Archivo));
             $StringJS .= $JSMin->min() . $MinDebug;
         }
         file_put_contents(dirname(__FILE__) . "/Cache/devildrey33.min.js", $StringJS);
         $StringCSS = "";
         $CSSMin = new CSSmin();
         foreach ($ArrayMin["css"] as $Archivo) {
             $StringCSS .= $CSSMin->run(file_get_contents(dirname(__FILE__) . $Archivo));
         }
         file_put_contents(dirname(__FILE__) . "/Cache/devildrey33.min.css", $StringCSS);
         return "Cache actualizada!";
     } else {
         error_log("<span style='color:red'>Error!</span> devildrey33::Minificar_JS_CSS -> el archivo '/Config/ArchivosMinify.php' no existe.");
         return "Error del servidor";
     }
 }
 /**
  * Minify Javascript
  *
  * @param string $js Javascript to be minified
  * @return string
  */
 public static function minify($js)
 {
     // look out for syntax like "++ +" and "- ++"
     $p = '\\+';
     $m = '\\-';
     if (preg_match("/([{$p}{$m}])(?:\\1 [{$p}{$m}]| (?:{$p}{$p}|{$m}{$m}))/", $js)) {
         // likely pre-minified and would be broken by JSMin
         return $js;
     }
     $jsmin = new JSMin($js);
     return $jsmin->min();
 }
Example #7
0
 public static function minify($js)
 {
     /* Protect all datas inside blocks like :
      *	//<<
      *	...
      *	//!>>
      * Used to protect copyrights texts or already minimified JS
      */
     $matches = array();
     //augment pcre.backtrack_limit
     ini_set('pcre.backtrack_limit', 500000);
     preg_match_all("#\\/{2}<{2}(.*)\\/{2}\\!>{2}#Us", $js, $matches);
     //reset pcre.backtrack_limit
     ini_set('pcre.backtrack_limit', 100000);
     if (isset($matches[1]) && $matches[1]) {
         $return = '';
         $js = explode('//<<', $js);
         if (trim($js[0]) != '') {
             $jsminStart = new JSMin($js[0]);
             $return .= $jsminStart->min();
         }
         unset($js[0]);
         $js = array_values($js);
         foreach ($matches[1] as $key => $match) {
             $code = explode('//!>>', $js[$key]);
             $jsmin = new JSMin($code[1]);
             try {
                 $return .= $match . "\n" . $jsmin->min();
             } catch (JSMinException $e) {
                 CMS_grandFather::raiseError($e->getMessage());
                 $return .= $match . "\n" . $code[1];
             }
         }
         return $return;
     } else {
         $jsmin = new JSMin($js);
         try {
             return $jsmin->min();
         } catch (JSMinException $e) {
             CMS_grandFather::raiseError($e->getMessage());
             return $js;
         }
     }
 }
 static function minify($L)
 {
     $J = new JSMin($L);
     return $J->min();
 }
Example #9
0
 private function minify_js($contents)
 {
     $jsmin = new JSMin($contents);
     $contents = $jsmin->min();
     return $contents;
 }
Example #10
0
 /**
  * Minify Javascript
  *
  * @uses __construct()
  * @uses min()
  * @param string $js Javascript to be minified
  * @return string
  */
 public static function minify($js, $nivel = 2, $cabecalho = "")
 {
     $jsmin = new JSMin($js, $nivel, $cabecalho);
     return $jsmin->min();
 }
Example #11
0
 public static function minify($js, $filename = '')
 {
     static $instance;
     // this is a singleton
     if (!$instance) {
         $instance = new JSMin();
     }
     return $instance->min($js, $filename);
 }
Example #12
0
 /**
  * Formal CSS, LESS and JS content.
  */
 public function format_content($content)
 {
     if ('style' == $this->compiler['type']) {
         if ('less' == $this->compiler['format']) {
             if (!class_exists('Beans_Lessc')) {
                 require_once BEANS_API_PATH . 'compiler/vendors/lessc.php';
             }
             $less = new Beans_Lessc();
             $content = $less->compile($content);
         }
         if (!_beans_is_compiler_dev_mode()) {
             $content = $this->strip_whitespace($content);
         }
     }
     if ('script' == $this->compiler['type'] && !_beans_is_compiler_dev_mode() && $this->compiler['minify_js']) {
         if (!class_exists('JSMin')) {
             require_once BEANS_API_PATH . 'compiler/vendors/js-minifier.php';
         }
         $js_min = new JSMin($content);
         $content = $js_min->min();
     }
     return $content;
 }
Example #13
0
/**
 * Minimise the given Javascript
 *
 * @param 	string		Javascript to minimise
 * @return 	string		Minimised Javascript
 */
function js_minify($js)
{
    if (strpos($js, 'no minify') !== false) {
        return $js;
    }
    require_code('jsmin');
    if (!class_exists('JSMin')) {
        return $js;
    }
    $jsmin = new JSMin($js);
    return $jsmin->min();
}
Example #14
0
 public function makeJs()
 {
     require_once __DIR__ . '/../../Lib/JSMin.php';
     require_once __DIR__ . '/../../Lib/CSSmin.php';
     $Cdn = new Cdn($this->O);
     $debug_level = $this->O->glob('debug');
     if ($debug_level > 2) {
         $line_cr = "\r\n";
     } else {
         $line_cr = null;
     }
     foreach ($this->js as $key => $files) {
         foreach ($files as $file) {
             echo '<script src="' . $this->rw_cache($file) . '" type="text/javascript" ></script>' . $line_cr;
         }
     }
     if ($debug_level >= 2 && $this->O->glob('cache')) {
         foreach ($this->cachedJs as $key => $files) {
             foreach ($files as $file) {
                 echo '<script src="' . $this->rw_cache($file) . '" type="text/javascript" ></script>' . $line_cr;
             }
         }
         $this->cachedJs = array();
     } else {
         foreach ($this->cachedJs as $key => $files) {
             $sorted_files_ref = $files;
             sort($sorted_files_ref);
             $key = 'js_' . md5(implode('', $sorted_files_ref)) . '_' . count($files) . '_' . $this->O->glob('version') . self::$cache . '.js';
             if (!($cache = $Cdn->exist($key))) {
                 foreach ($files as $file) {
                     try {
                         // lazy loading fix
                         $srcfile = json_encode($file);
                         $cache .= "document._currentScript = document.createElement('script');";
                         $cache .= "document._currentScript.src = {$srcfile};";
                         $cache .= "document.currentScript = document._currentScript;";
                         $js = self::fileGetContents($file);
                         if ($this->O->glob('debug') < 3) {
                             $jsmin = new \JSMin($js);
                             $js = $jsmin->min();
                         }
                         $cache .= $js . $line_cr;
                     } catch (\Exception $e) {
                     }
                 }
                 $Cdn->put($key, $cache);
             }
             echo '<script src="' . $Cdn->url($key) . '" type="text/javascript" ></script>' . $line_cr;
             break;
         }
         $this->cachedJs = array();
     }
     foreach ($this->scriptInline as $v) {
         echo $v . $line_cr;
     }
     $this->scriptInline = array();
 }
Example #15
0
File: jsmin.php Project: remo/miser
 public static function minify($js, $noComments = TRUE)
 {
     $jsmin = new JSMin($js);
     $jsmin->noComments = $noComments;
     return $jsmin->min();
 }
Example #16
0
 /**
  * Formal CSS, LESS and JS content.
  */
 public function format_content($content)
 {
     if ($this->compiler['type'] == 'style') {
         if ($this->compiler['format'] == 'less') {
             if (!class_exists('lessc')) {
                 require_once BEANS_API_COMPONENTS_PATH . 'compiler/vendors/lessc.php';
             }
             $less = new lessc();
             $content = $less->compile($content);
         }
         if (_beans_is_compiler_dev_mode() === false) {
             $content = $this->strip_whitespace($content);
         }
     }
     if ($this->compiler['type'] == 'script' && _beans_is_compiler_dev_mode() === false && $this->compiler['minify_js']) {
         if (!class_exists('JSMin')) {
             require_once BEANS_API_COMPONENTS_PATH . 'compiler/vendors/js-minifier.php';
         }
         $js_min = new JSMin($content);
         $content = $js_min->min();
     }
     return $content;
 }
Example #17
0
 /**
  * Minify Javascript
  *
  * @param string $js Javascript to be minified
  * @return string
  */
 public static function minify($js)
 {
     // look out for syntax like "++ +" and "- ++"
     $p = '\\+';
     $m = '\\-';
     /*if (preg_match("/([$p$m])(?:\\1 [$p$m]| (?:$p$p|$m$m))/", $js)) {
           // likely pre-minified and would be broken by JSMin
           return $js;
       }*/
     $jsmin = new JSMin($js);
     return $jsmin->min();
 }
Example #18
0
File: jsmin.php Project: erkie/cowl
 public static function minify($js)
 {
     $jsmin = new JSMin($js);
     return $jsmin->min();
 }
Example #19
0
 /**
  * Minify Javascript.
  *
  * @param string $js Javascript to be minified
  *
  * @return string
  */
 public static function minify($js)
 {
     
     $p = '\\+';
     $m = '\\-';
     if (preg_match("/([$p$m])(?:\\1 [$p$m]| (?:$p$p|$m$m))/", $js)) {
         // likely pre-minified and would be broken by JSMin
         return $js;
     }
     
     $jsmin = new JSMin($js);
     return $jsmin->min();
 }