本文整理汇总了PHP中JSMinPlus类的典型用法代码示例。如果您正苦于以下问题:PHP JSMinPlus类的具体用法?PHP JSMinPlus怎么用?PHP JSMinPlus使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JSMinPlus类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSetup
public static function getSetup()
{
global $wgUser, $IP, $wgMemc;
$isHHM = wikihowAds::isHHM();
$isABTest = wikihowAds::isABTestArticle();
$cachekey = wfMemcKey('ads_setup', intval($isHHM), intval($isABTest), WH_SITEREV);
//$html = $wgMemc->get($cachekey);
$html = null;
if ($html === null) {
$js = wfMsg('Wikihowads_setup', $isHHM, intVal($isABTest));
require_once "{$IP}/extensions/min/lib/JSMinPlus.php";
$adsClass = file_get_contents("{$IP}/extensions/wikihow/wikihowAds/wikihowAds.js");
$min = JSMinPlus::minify($adsClass . $js);
$html = <<<EOHTML
<!-- MediaWiki:wikihowads_setup -->
<script type='text/javascript'>
<!--
{$min}
//-->
</script>
EOHTML;
$wgMemc->set($cachekey, $html);
}
return $html;
}
示例2: summarize_registry
/**
* Summarize the file registry in a way like
* [ 'ext1' => 'contents', 'ext2' => 'contents' ]
*
* @return array
*/
function summarize_registry()
{
$summasummarum = array();
$keys = array_keys($_SESSION['files_registry']);
foreach ($keys as $filename) {
$summarized = "";
$last_dot_pos = strrpos($filename, ".");
$ext = strtolower(substr($filename, $last_dot_pos + 1, strlen($filename) - $last_dot_pos - 1));
if (!$_SESSION['files_registry'][$filename]['good']) {
unset($_SESSION['files_registry'][$filename]);
echo sprintf("[Deleted] %s\n-- %s\n\n", date('H:i:s'), $filename);
continue;
}
$summarized .= trim(file_get_contents($filename));
if (!isset($summasummarum[$ext])) {
$summasummarum[$ext] = "";
}
if ($ext == 'css') {
$summarized = Minify_CSS::minify(file_get_contents($filename));
} else {
if ($ext == 'js') {
$summarized = JSMinPlus::minify(file_get_contents($filename));
} else {
$summarized = trim(file_get_contents($filename));
}
}
$summasummarum[$ext] .= $summarized;
}
return $summasummarum;
}
示例3: test_JSMinPlus
function test_JSMinPlus()
{
global $thisDir;
$src = file_get_contents($thisDir . '/_test_files/js/condcomm.js');
$minExpected = file_get_contents($thisDir . '/_test_files/js/condcomm.min_plus.js');
$minOutput = JSMinPlus::minify($src);
$passed = assertTrue($minExpected == $minOutput, 'JSMinPlus : Conditional Comments');
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
echo "\n---Output: " . countBytes($minOutput) . " bytes\n\n{$minOutput}\n\n";
echo "---Expected: " . countBytes($minExpected) . " bytes\n\n{$minExpected}\n\n";
echo "---Source: " . countBytes($src) . " bytes\n\n{$src}\n\n\n";
}
return;
$src = file_get_contents($thisDir . '/_test_files/js/before.js');
$minExpected = file_get_contents($thisDir . '/_test_files/js/before.min_plus.js');
$minOutput = JSMinPlus::minify($src);
$passed = assertTrue($minExpected == $minOutput, 'JSMinPlus : Overall');
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
echo "\n---Output: " . countBytes($minOutput) . " bytes\n\n{$minOutput}\n\n";
echo "---Expected: " . countBytes($minExpected) . " bytes\n\n{$minExpected}\n\n";
echo "---Source: " . countBytes($src) . " bytes\n\n{$src}\n\n\n";
}
$src = file_get_contents($thisDir . '/_test_files/js/issue74.js');
$minExpected = file_get_contents($thisDir . '/_test_files/js/issue74.min_plus.js');
$minOutput = JSMinPlus::minify($src);
$passed = assertTrue($minExpected == $minOutput, 'JSMinPlus : Quotes in RegExp literals (Issue 74)');
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
echo "\n---Output: " . countBytes($minOutput) . " bytes\n\n{$minOutput}\n\n";
echo "---Expected: " . countBytes($minExpected) . " bytes\n\n{$minExpected}\n\n";
echo "---Source: " . countBytes($src) . " bytes\n\n{$src}\n\n\n";
}
}
示例4: js
/**
* Minify JS code.
*
* @param string $content
* @return string minified JS code
*/
public static function js($content)
{
global $CFG;
require_once "{$CFG->libdir}/minify/lib/JSMinPlus.php";
try {
ob_start();
// JSMinPlus just echos errors, weird...
$compressed = JSMinPlus::minify($content);
if ($compressed !== false) {
ob_end_clean();
return $compressed;
}
$error = ob_get_clean();
} catch (Exception $e) {
ob_end_clean();
$error = $e->getMessage();
}
$return = <<<EOD
try {console.log('Error: Minimisation of JavaScript failed!');} catch (e) {}
// Error: {$error}
// Problem detected during JavaScript minimisation, please review the following code
// =================================================================================
EOD;
return $return . $content;
}
示例5: postprocess
public function postprocess(&$path, &$content)
{
if (!class_exists('JSMinPlus')) {
$dir = Templates_HTML_Postprocess::option('minify_php_dir');
require_once $dir . 'JSMin/JSMin.php';
}
$content = JSMinPlus::minify($content);
}
示例6: doProcessFile
public function doProcessFile($file, $replace = false)
{
$optimizedContent = JSMinPlus::minify(file_get_contents($file));
if ($replace) {
return parent::replaceFile($file, $optimizedContent);
} else {
return $optimizedContent;
}
}
示例7: apply
/**
*/
public function apply($in, $params = [])
{
require_php_lib('jsminplus');
if (!class_exists('\\JSMinPlus')) {
throw new Exception('Assets: class \\JSMinPlus not found');
return $in;
}
return \JSMinPlus::minify($in);
}
示例8: compress
public function compress($string)
{
// Compress the js-code
$jsMinPhp = JPATH_SITE . '/components/com_scriptmerge/lib/jsminplus.php';
if (file_exists($jsMinPhp)) {
include_once $jsMinPhp;
if (class_exists('JSMinPlus')) {
$string = JSMinPlus::minify($string);
}
}
return $string;
}
示例9: postprocess
public function postprocess($path, $data, $content = null)
{
if (!class_exists('JSMinPlus')) {
$dir = Templates_HTML_Assets_Postprocess_Minify::option('minify_php_dir');
require_once $dir . 'JSMinPlus/JSMinPlus.php';
}
if ($this->filter($path, $data)) {
if (empty($content)) {
list($content, $path) = $this->load($path);
}
if (!empty($content)) {
$content = JSMinPlus::minify($content);
}
}
return array($path, $content);
}
示例10: test_JSMinPlus
function test_JSMinPlus()
{
global $thisDir;
$src = file_get_contents($thisDir . '/_test_files/js/condcomm.js');
$minExpected = file_get_contents($thisDir . '/_test_files/js/condcomm.min_plus.js');
$minOutput = JSMinPlus::minify($src);
$passed = assertTrue($minExpected == $minOutput, 'JSMinPlus : Conditional Comments');
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
echo "\n---Output: " . strlen($minOutput) . " bytes\n\n{$minOutput}\n\n";
echo "---Expected: " . strlen($minExpected) . " bytes\n\n{$minExpected}\n\n";
echo "---Source: " . strlen($src) . " bytes\n\n{$src}\n\n\n";
}
return;
$src = file_get_contents($thisDir . '/_test_files/js/before.js');
$minExpected = file_get_contents($thisDir . '/_test_files/js/before.min_plus.js');
$minOutput = JSMinPlus::minify($src);
$passed = assertTrue($minExpected == $minOutput, 'JSMinPlus : Overall');
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
echo "\n---Output: " . strlen($minOutput) . " bytes\n\n{$minOutput}\n\n";
echo "---Expected: " . strlen($minExpected) . " bytes\n\n{$minExpected}\n\n";
echo "---Source: " . strlen($src) . " bytes\n\n{$src}\n\n\n";
}
$src = file_get_contents($thisDir . '/_test_files/js/issue74.js');
$minExpected = file_get_contents($thisDir . '/_test_files/js/issue74.min_plus.js');
$minOutput = JSMinPlus::minify($src);
$passed = assertTrue($minExpected == $minOutput, 'JSMinPlus : Quotes in RegExp literals (Issue 74)');
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
echo "\n---Output: " . strlen($minOutput) . " bytes\n\n{$minOutput}\n\n";
echo "---Expected: " . strlen($minExpected) . " bytes\n\n{$minExpected}\n\n";
echo "---Source: " . strlen($src) . " bytes\n\n{$src}\n\n\n";
/*
test_JSMin_exception('"Hello'
,'Unterminated String'
,'JSMin_UnterminatedStringException'
,"Unterminated String: '\"Hello'");
test_JSMin_exception("return /regexp\n}"
,'Unterminated RegExp'
,'JSMin_UnterminatedRegExpException'
,"Unterminated RegExp: '/regexp\n'");
test_JSMin_exception("/* Comment "
,'Unterminated Comment'
,'JSMin_UnterminatedCommentException'
,"Unterminated Comment: '/* Comment '");
//*/
}
}
示例11: compile
public function compile()
{
$doc = JFactory::getDocument();
$headers = $doc->getHeadData();
$javascripts = JArrayHelper::getValue($headers, 'scripts');
$dest = JPath::clean($this->paths->get('js.compressed'));
$compile = $this->params->get('minify_js', 1);
$changed = (bool) $this->isJsUpdated();
JLog::add('Javascript cache changed: ' . ((bool) $changed ? 'true' : 'false'), JLog::DEBUG, $this->logger);
$force = (bool) ($compile == 2);
$changed = (bool) ($compile == 1 && $changed);
JLog::add('Force Javascript minification: ' . ((bool) $force ? 'true' : 'false'), JLog::DEBUG, $this->logger);
JLog::add('Minify Javascript: ' . ((bool) $changed ? 'true' : 'false'), JLog::DEBUG, $this->logger);
$uncompressed = '';
foreach (array_keys($javascripts) as $script) {
$url = new JUri($script);
if (!$url->getScheme()) {
$url = new JUri(JUri::base());
$url->setPath($script);
}
$key = str_replace(JUri::base(), JPATH_ROOT . '/', (string) $url);
if (array_search($key, $this->paths->get('js.uncompressed')) !== false) {
unset($headers['scripts'][$script]);
if (!JFile::exists($dest) || $changed || $force) {
JLog::add('Compressing: ' . $key . ' to ' . $dest, JLog::DEBUG, $this->logger);
$stream = new JStream();
$stream->open($key);
$response = $stream->read($stream->filesize());
$stream->close();
$uncompressed .= $response;
}
}
}
if ($uncompressed) {
file_put_contents($dest, JSMinPlus::minify($uncompressed, $dest));
$this->updateCache(self::CACHEKEY . '.files.js', $this->paths->get('js.uncompressed'));
}
// workaround. There needs to be at least one script.
if (count($headers['scripts']) == 0) {
$url = str_replace(JPATH_ROOT . '/', JUri::base(), $dest);
$headers['scripts'][$url] = array('mime' => 'text/javascript', 'defer' => false, 'async' => false);
}
$doc->setHeadData($headers);
}
示例12: parse_string
public function parse_string($template, $data = array(), $return = FALSE, $options = array())
{
if (!is_array($options)) {
$options = array();
}
$options = array_merge($this->config, $options);
$ci = $this->ci;
$is_mx = false;
if (!$return) {
list($ci, $is_mx) = $this->detect_mx();
}
ob_start();
$template = JSMinPlus::minify($template);
$exception_message = ob_get_contents();
ob_end_clean();
if ($exception_message != '') {
throw new Exception('JSMinPlus: ' . $exception_message);
}
return $this->output($template, $return, $ci, $is_mx);
}
示例13: minify
public function minify($js)
{
try {
if ($this->conf->outputfilters->javascriptminifyalgorithm == "jsminplus") {
$js = JSMinPlus::minify($js);
} else {
if ($this->conf->outputfilters->javascriptminifyalgorithm == "yuicompressor") {
Minify_YUICompressor::$tempDir = PIMCORE_TEMPORARY_DIRECTORY;
Minify_YUICompressor::$jarFile = PIMCORE_PATH . "/lib/Minify/yuicompressor-2.4.2.jar";
$js = Minify_YUICompressor::minifyJs($js);
} else {
$js = JSMin::minify($js);
}
}
} catch (Exception $e) {
Logger::error("Unable to minify javascript");
Logger::error($e);
}
return $js;
}
示例14: compress
protected function compress($data, $config)
{
switch ($config['type']) {
case 'jsmin':
include_once Kohana::find_file('vendor', 'JSMin');
return JSMin::minify($data);
case 'jsminplus':
include_once Kohana::find_file('vendor', 'jsminplus');
return JSMinPlus::minify($data);
case 'packer':
include_once Kohana::find_file('vendor', 'JavaScriptPacker');
$packer = new JavaScriptPacker($data, empty($config['level']) ? 'Normal' : $config['level']);
return $packer->pack();
case 'yuicompressor':
$options = isset($config['options']) ? $config['options'] : '';
return yuicompressor::compress($data, 'js', $options);
default:
throw new Kohana_User_Exception('Unknown Javascript Compression Type', 'Unknown type: ' . $config['type']);
}
}
示例15: doExecute
/**
* doExecute
*
* @return int
*/
protected function doExecute()
{
$path = $this->getArgument(0);
$package = $this->getOption('p');
$folder = $this->console->get('asset.folder', 'asset');
if ($package = PackageHelper::getPackage($package)) {
$path = $package->getDir() . '/Resources/asset/' . $path;
} else {
$path = WINDWALKER_PUBLIC . '/' . trim($folder, '/') . '/' . $path;
}
if (is_file($path)) {
$files = array(new \SplFileInfo($path));
} elseif (is_dir($path)) {
$files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \FilesystemIterator::FOLLOW_SYMLINKS));
} else {
throw new \InvalidArgumentException('No path');
}
/** @var \SplFileInfo $file */
foreach ($files as $file) {
$ext = File::getExtension($file->getPathname());
if (StringHelper::endsWith($file->getBasename(), '.min.' . $ext)) {
continue;
}
if ($ext == 'css') {
$this->out('[<comment>Compressing</comment>] ' . $file);
$data = \Minify_CSS_Compressor::process(file_get_contents($file));
$data = str_replace("\n", ' ', $data);
} elseif ($ext == 'js') {
$this->out('[<comment>Compressing</comment>] ' . $file);
$data = \JSMinPlus::minify(file_get_contents($file));
$data = str_replace("\n", ';', $data);
} else {
continue;
}
$newName = $file->getPath() . '/' . File::stripExtension($file->getBasename()) . '.min.' . $ext;
file_put_contents($newName, $data);
$this->out('[<info>Compressed</info>] ' . $newName);
}
}