本文整理汇总了PHP中JSMin::min方法的典型用法代码示例。如果您正苦于以下问题:PHP JSMin::min方法的具体用法?PHP JSMin::min怎么用?PHP JSMin::min使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSMin
的用法示例。
在下文中一共展示了JSMin::min方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: minify
/**
* 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;
}
示例2: minify
function minify($js)
{
$jsmin = new JSMin($js);
$output = $jsmin->min();
if ($output === false) {
return $js;
}
return $output;
}
示例3: minify
public static function minify($js, $level=3) {
$jsmin = new JSMin($js, $level);
return $jsmin->min();
}
示例4: minify
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;
}
示例5: Minificar_JS_CSS
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";
}
}
示例6: minify
/**
* 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();
}
示例7: minify
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;
}
}
}
示例8: minify
static function minify($L)
{
$J = new JSMin($L);
return $J->min();
}
示例9: minify_js
private function minify_js($contents)
{
$jsmin = new JSMin($contents);
$contents = $jsmin->min();
return $contents;
}
示例10: minify
/**
* 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();
}
示例11: minify
public static function minify($js, $filename = '')
{
static $instance;
// this is a singleton
if (!$instance) {
$instance = new JSMin();
}
return $instance->min($js, $filename);
}
示例12: format_content
/**
* 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;
}
示例13: js_minify
/**
* 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();
}
示例14: makeJs
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();
}
示例15: minify
public static function minify($js, $noComments = TRUE)
{
$jsmin = new JSMin($js);
$jsmin->noComments = $noComments;
return $jsmin->min();
}