当前位置: 首页>>代码示例>>PHP>>正文


PHP JSMinPlus::minify方法代码示例

本文整理汇总了PHP中JSMinPlus::minify方法的典型用法代码示例。如果您正苦于以下问题:PHP JSMinPlus::minify方法的具体用法?PHP JSMinPlus::minify怎么用?PHP JSMinPlus::minify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JSMinPlus的用法示例。


在下文中一共展示了JSMinPlus::minify方法的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;
    }
开发者ID:ErdemA,项目名称:wikihow,代码行数:25,代码来源:wikihowAds.class.php

示例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;
}
开发者ID:allenlinatoc,项目名称:assetmon,代码行数:36,代码来源:registry.functions.php

示例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";
    }
}
开发者ID:awwthentic1234,项目名称:hey,代码行数:32,代码来源:test_JSMinPlus.php

示例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;
    }
开发者ID:evltuma,项目名称:moodle,代码行数:35,代码来源:minify.php

示例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);
 }
开发者ID:techart,项目名称:tao,代码行数:8,代码来源:Postprocess.php

示例6: 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);
 }
开发者ID:yfix,项目名称:yf,代码行数:11,代码来源:yf_assets_filter_jsminplus.class.php

示例7: doProcessFile

 public function doProcessFile($file, $replace = false)
 {
     $optimizedContent = JSMinPlus::minify(file_get_contents($file));
     if ($replace) {
         return parent::replaceFile($file, $optimizedContent);
     } else {
         return $optimizedContent;
     }
 }
开发者ID:n1k0,项目名称:npAssetsOptimizerPlugin,代码行数:9,代码来源:npDriverJSMinPlus.class.php

示例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;
 }
开发者ID:JeroenJ3,项目名称:pkg_scriptmerge,代码行数:12,代码来源:jsminplus.php

示例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);
 }
开发者ID:techart,项目名称:tao,代码行数:16,代码来源:Minify.php

示例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 '");
                //*/
    }
}
开发者ID:RainyBlueSky,项目名称:PHProjekt,代码行数:46,代码来源:test_JSMinPlus.php

示例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);
 }
开发者ID:Vartacom,项目名称:bootstrapbase,代码行数:44,代码来源:js.php

示例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);
 }
开发者ID:bhavesh561988,项目名称:starter-public-edition-4,代码行数:20,代码来源:Parser_jsmin.php

示例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;
 }
开发者ID:shanky0110,项目名称:pimcore-custom,代码行数:20,代码来源:JavascriptMinify.php

示例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']);
     }
 }
开发者ID:evansd-archive,项目名称:kohana-module--assets,代码行数:20,代码来源:javascript.php

示例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);
     }
 }
开发者ID:ventoviro,项目名称:phoenix,代码行数:44,代码来源:MinifyCommand.php


注:本文中的JSMinPlus::minify方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。