本文整理汇总了PHP中JSMin::minify方法的典型用法代码示例。如果您正苦于以下问题:PHP JSMin::minify方法的具体用法?PHP JSMin::minify怎么用?PHP JSMin::minify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSMin
的用法示例。
在下文中一共展示了JSMin::minify方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeAction
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);
}
示例2: pack
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;
}
示例3: minify
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";
}
示例4: minifyJs
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);
}
}
}
}
示例5: moodbile_performance_minify_js
function moodbile_performance_minify_js($js)
{
global $CFG;
require_once $CFG['basepath'] . 'misc/jsmin.php';
$js = JSMin::minify($js);
return $js;
}
示例6: js
/**
* 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);
}
示例7: minifyjs
/**
* 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;
}
}
示例8: getJsContents
/**
* 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("&", "&", $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;
}
示例9: getCompressed
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);
}
示例10: load
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;
}
示例11: minify
public function minify()
{
if ($this->contentType != 'text/css') {
G::LoadThirdParty('jsmin', 'jsmin');
$this->content = JSMin::minify($this->content);
}
}
示例12: get_js_html
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);
}
示例13: combine
/**
* 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));
}
示例14: run
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";
}
示例15: addjstext
function addjstext($output, $minify = true)
{
if ($minify == true && (MINIFY == true || MINIFY == 1)) {
$output = JSMin::minify($output);
}
return $output;
}