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


PHP JavaScriptPacker::pack方法代码示例

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


在下文中一共展示了JavaScriptPacker::pack方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: packedScriptSrc

 /**
  * Combines, minifies and caches internal js files
  *
  * @param $files an array of internal js filenames. should be in modules/jQuery - EX: 	array('soundmanager2.js', 'jquery.omniplayer.js')
  * @param $useCache the default is to use a cached version, but for testing changes you might want to set to false
  */
 public function packedScriptSrc($files, $useCache = true)
 {
     $hash = md5(join(',', $files));
     $fileName = $hash . '.min.js';
     $dir = $this->installPath . '/js/';
     $scriptDir = '/accelsite/js/';
     $metaKey = 'accel_js_cached_packed_' . $hash;
     $externalPath = $scriptDir . $fileName;
     if ($useCache) {
         if ($cachedSrc = SiteInfo::findThis()->getMeta($metaKey, 0)) {
             if (file_exists($dir . $fileName)) {
                 return $cachedSrc;
             }
         }
     }
     foreach ($files as $src) {
         $script .= file_get_contents($this->includePath . '/modules/jQuery/' . $src) . ";";
     }
     $packer = new JavaScriptPacker($script, 'Normal', true, false);
     if (!file_exists($dir)) {
         mkdir($dir);
     }
     file_put_contents($dir . $fileName, $packer->pack() . "/*  cached:  " . date('r') . " */");
     SiteInfo::findThis()->setMeta($metaKey, $externalPath);
     return $externalPath;
 }
开发者ID:netacceleration,项目名称:accelpress,代码行数:32,代码来源:AccelJS.php

示例2: tocpjs

 public function tocpjs($path)
 {
     if (!is_dir($this->devpath . $path)) {
         if (strpos(strtolower($path), '.js') == strlen($path) - 3) {
             if (file_exists($this->propath . $path) && filemtime($this->devpath . $path) < filemtime($this->propath . $path)) {
                 return;
             }
             File::creat_dir_with_filepath($this->propath . $path);
             $buffer = file_get_contents($this->devpath . $path);
             //如果传入的是JS文件则压缩
             if (!$this->needcomp) {
                 file_put_contents($this->propath . $path, $buffer);
             } else {
                 $packer = new JavaScriptPacker($buffer, 'Normal', true, false);
                 file_put_contents($this->propath . $path, $packer->pack());
             }
         } else {
             @copy($this->devpath . $path, $this->propath . $path);
         }
         return;
     }
     //如果传入的参数是目录
     $handle = File::scandir($this->devpath . $path);
     foreach ($handle as $file) {
         if ($file != '.' && $file != '..') {
             $dir = $path . '/' . $file;
             //当前文件$dir为文件目录+文件
             $this->tocpjs($dir);
         }
     }
     return;
 }
开发者ID:codingoneapp,项目名称:codingone,代码行数:32,代码来源:compress.php

示例3: filterDump

 public function filterDump(AssetInterface $asset)
 {
     $script = $asset->getContent();
     $packer = new \JavaScriptPacker($script, $this->_encoding, $this->_fastDecode, $this->_specialChars);
     $script = $packer->pack();
     $asset->setContent(str_replace(";;", ";", trim($script) . ";"));
 }
开发者ID:icedream,项目名称:javascriptpackerbundle,代码行数:7,代码来源:JavaScriptPackerFilter.php

示例4: smarty_function_script

/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */
function smarty_function_script($params, &$smarty)
{
    static $scripts = array();
    static $packer_loaded = false;
    /*if (!empty($params['include'])) {
    		return implode("\n", $scripts);
    	}*/
    if (!isset($scripts[$params['src']])) {
        $path = Registry::get('config.current_path');
        if (Registry::get('config.tweaks.js_compression') == true && strpos($params['src'], 'lib/') === false) {
            if (!file_exists(DIR_CACHE . $params['src'])) {
                if ($packer_loaded == false) {
                    include_once DIR_LIB . 'packer/class.JavaScriptPacker.php';
                    $packer_loaded = true;
                }
                fn_mkdir(dirname(DIR_CACHE . $params['src']));
                $packer = new JavaScriptPacker(fn_get_contents(DIR_ROOT . '/' . $params['src']));
                fn_put_contents(DIR_CACHE . $params['src'], $packer->pack());
            }
            $path = Registry::get('config.cache_path');
        }
        $scripts[$params['src']] = '<script type="text/javascript" src="' . $path . '/' . $params['src'] . '"></script>';
        // If output is captured, don't print script tag in the buffer, it will be printed directly to the screen
        if (!empty($smarty->_in_capture)) {
            $buff = array_pop($smarty->_in_capture);
            $smarty->_in_capture[] = $buff;
            $smarty->_scripts[$buff][] = $scripts[$params['src']];
            return '';
        }
        return $scripts[$params['src']];
    }
}
开发者ID:diedsmiling,项目名称:busenika,代码行数:37,代码来源:function.script.php

示例5: 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;
 }
开发者ID:primeminister,项目名称:phpjs,代码行数:25,代码来源:Pack.php

示例6: _js_compress

 private function _js_compress($content)
 {
     App::import('vendor', 'inc/jspacker');
     $js = new JavaScriptPacker($content, $this->_js_encode, true, false);
     $this->setEncode(0);
     return $js->pack();
 }
开发者ID:tilitala,项目名称:nForum,代码行数:7,代码来源:packer.php

示例7: pack_cQuery

function pack_cQuery($chemin) {
	$flux = spip_file_get_contents($chemin);
	$flux = str_replace('jQuery', 'cQuery', $flux);

	// On ne compacte PAS deux fois (c'est inutile et en plus ca bugge)
	if (!strlen($flux)
	// mode debug des crayons
	OR _request('debug_crayons')
	// le vieil auto_compress_js
	OR ($GLOBALS['meta']['auto_compress_js'] == 'oui'
	  AND @file_exists(_DIR_RESTREINT.'inc/compacte_js.php'))
	// ou l'espace prive
	OR !function_exists('test_espace_prive')
	OR test_espace_prive())
		return $flux;

	include_spip('lib/JavaScriptPacker/class.JavaScriptPacker');
	$packer = new JavaScriptPacker($flux, 0, true, false);

	// en cas d'echec (?) renvoyer l'original
	if (strlen($t = $packer->pack()))
		return $t;

	// erreur
	spip_log('erreur de pack_js');
	return $flux;
}
开发者ID:rhertzog,项目名称:lcs,代码行数:27,代码来源:crayons.js_fonctions.php

示例8: concatListAndPack

 /**
  * Perform actual compression
  * @param $src
  * @param $out
  * @param $mode
  * @return bool
  */
 function concatListAndPack($src, $out, $mode)
 {
     if (!is_file($src) || !is_readable($src)) {
         return false;
     }
     // Concat List into one big string
     $jscode = '';
     $handle = @fopen($src, 'r');
     if ($handle) {
         while (!feof($handle)) {
             $jsline = fgets($handle, 4096);
             if (rtrim($jsline, "\n") != "") {
                 $code = file_get_contents(AJXP_INSTALL_PATH . "/" . CLIENT_RESOURCES_FOLDER . "/" . rtrim($jsline, "\n\r"));
                 if ($code) {
                     $jscode .= $code;
                 }
             }
         }
         fclose($handle);
     }
     // Pack and write to file
     require_once "packer/class.JavaScriptPacker.php";
     $packer = new JavaScriptPacker($jscode, $mode, true, false);
     $packed = $packer->pack();
     if ($mode == "None") {
         // css case, hack for I.E.
         $packed = str_replace("solid#", "solid #", $packed);
     }
     @file_put_contents($out, $packed);
     return true;
 }
开发者ID:crodriguezn,项目名称:administrator-files,代码行数:38,代码来源:class.AJXP_JSPacker.php

示例9: foreach

 function allowed_components()
 {
     $sOutput = '';
     $bSendPack = $this->config->item("send_pack");
     $sFileProd = $this->config->item("file_prod");
     $sFileDebug = $this->config->item("file_debug");
     $aFiels = get_filenames($sFileDebug);
     foreach ($aFiels as $sFile) {
         $aFileData = pathinfo($sFile);
         if (isset($aFileData["extension"]) && $aFileData["extension"] != "js") {
             continue;
         }
         if ($bSendPack) {
             $script = file_get_contents($sFileDebug . $sFile);
             $filemtime = @filemtime($sFileDebug . $sFile);
             $filemtimeCache = @filemtime($sFileProd . $sFile);
             $t1 = microtime(true);
             if (!$filemtimeCache || $filemtime > $filemtimeCache) {
                 $packer = new JavaScriptPacker($script, 'Normal', true, false);
                 $packed = $packer->pack();
                 file_put_contents($sFileProd . $sFile, $packed);
             }
             $t2 = microtime(true);
             $time = sprintf('%.4f', $t2 - $t1);
             $sOutput .= '/* Script ' . $sFile . ' packed in ' . $time . " s. */\n";
             $sOutput .= read_file($sFileProd . $sFile) . "\n\n";
         } else {
             $sOutput .= read_file($sFileDebug . $sFile) . "\n\n";
         }
     }
     header("Content-type: application/javascript");
     echo $sOutput;
     die;
 }
开发者ID:bardascat,项目名称:blogify,代码行数:34,代码来源:provider.php

示例10: pack

 public function pack($file)
 {
     $file = realpath($file);
     $home = dirname(__FILE__);
     $jar = realpath("{$home}/compiler.jar");
     $java = "java";
     exec("{$java} -version", &$output, &$result);
     if ($result != 0) {
         throw new BuildException("Java not found.");
     }
     // first we pack the file using DOJO shrinksafe
     $cmd = "{$java} -jar \"{$jar}\" --js=\"{$file}\" --js_output_file=\"{$file}.tmp\"";
     exec($cmd, &$output, &$result);
     if ($result != 0) {
         throw new BuildException("Java error.");
     }
     unlink($file);
     rename("{$file}.tmp", $file);
     // after DOJO, we use the Packer to tighten it up.
     $script = file_get_contents($file);
     $packer = new JavaScriptPacker($script, 62, true, false);
     $packed = $packer->pack();
     file_put_contents($file, $packed);
     $this->log("{$file} packed.", Project::MSG_INFO);
 }
开发者ID:superchangme,项目名称:jsplugin,代码行数:25,代码来源:PackerTask.php

示例11: packJavascript

function packJavascript($version)
{
    $jsDir = 'resources/htdocs/js';
    $packFile = "{$jsDir}/packed-{$version}.js";
    $unpackFile = "{$jsDir}/unpacked-{$version}.js";
    $licenses = '';
    $allScript = '';
    $preloadFiles = array('jquery.js', 'sockso.js');
    $postloadFiles = array('init.js');
    foreach ($preloadFiles as $preloadFile) {
        $allScript .= file_get_contents("{$jsDir}/{$preloadFile}");
        $licenses .= extractLicenses($allScript);
    }
    $d = opendir($jsDir);
    $dirlist = array();
    // then read in all javascript files and pack them up
    while ($file = readdir($d)) {
        $dirlist[] = $file;
    }
    sort($dirlist);
    foreach ($dirlist as $key => $file) {
        $path = "{$jsDir}/{$file}";
        // remove old pack files
        if (preg_match('/packed-/', $file)) {
            unlink($path);
        } elseif (!in_array($file, array_merge($preloadFiles, $postloadFiles)) && substr($file, -2) == 'js' && !preg_match('/locale.\\w+/', $file)) {
            echo "Include: {$path}\n";
            $script = file_get_contents($path);
            $licenses .= extractLicenses($script);
            $allScript .= $script;
        }
    }
    foreach ($postloadFiles as $file) {
        $allScript .= file_get_contents("{$jsDir}/{$file}");
        $licenses .= extractLicenses($allScript);
    }
    // write unpacked javascript
    $f = fopen($unpackFile, 'w');
    fwrite($f, $allScript);
    fclose($f);
    // write packed javascript
    $f = fopen($packFile, 'w');
    switch (PACK_TYPE) {
        case PACK_PACKER:
            include 'lib/php/JavaScriptPacker.class.php';
            $packer = new JavaScriptPacker($allScript, 'Normal', true, false);
            fwrite($f, $licenses . $packer->pack());
            break;
        case PACK_YUI:
            fwrite($f, $allScript);
            system(sprintf('java -jar lib/dev/yuicompressor-2.4.2.jar --type js -o "%s" "%s"', $packFile, $unpackFile));
            break;
        case PACK_NONE:
            fwrite($f, $allScript);
            // not packed
            break;
    }
    fclose($f);
}
开发者ID:nguillaumin,项目名称:sockso,代码行数:59,代码来源:pack-resources.php

示例12: combine_getArchive

function combine_getArchive($aFiles, $fileType)
{
    $sDocRoot = $_SERVER['DOCUMENT_ROOT'];
    $iETag = (int) $_GET['version'];
    $sLastModified = gmdate('D, d M Y H:i:s', $iETag) . ' GMT';
    // see if the user has an updated copy in browser cache
    if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $_SERVER['HTTP_IF_MODIFIED_SINCE'] == $sLastModified || isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $iETag) {
        header("{$_SERVER['SERVER_PROTOCOL']} 304 Not Modified");
        exit;
    }
    // create a directory for storing current and archive versions
    if (CREATE_ARCHIVE && !is_dir("{$sDocRoot}/" . ARCHIVE_FOLDER)) {
        mkdir("{$sDocRoot}/" . ARCHIVE_FOLDER);
    }
    // get code from archive folder if it exists, otherwise grab latest files, merge and save in archive folder
    if (CREATE_ARCHIVE && file_exists("{$sDocRoot}/" . ARCHIVE_FOLDER . "/{$iETag}.cache")) {
        $sCode = file_get_contents("{$sDocRoot}/" . ARCHIVE_FOLDER . "/{$iETag}.cache");
    } else {
        // get and merge code
        $sCode = '';
        $aLastModifieds = array();
        foreach ($aFiles as $sFile) {
            $aLastModifieds[] = filemtime("{$sDocRoot}/{$sFile}");
            $sCode .= file_get_contents("{$sDocRoot}/{$sFile}") . "\n";
        }
        // sort dates, newest first
        rsort($aLastModifieds);
        if (CREATE_ARCHIVE) {
            if ($iETag == $aLastModifieds[0]) {
                // check for valid etag, we don't want invalid requests to fill up archive folder
                $oFile = fopen("{$sDocRoot}/" . ARCHIVE_FOLDER . "/{$iETag}.cache", 'w');
                if (flock($oFile, LOCK_EX)) {
                    fwrite($oFile, $sCode);
                    flock($oFile, LOCK_UN);
                }
                fclose($oFile);
            } else {
                // archive file no longer exists or invalid etag specified
                header("{$_SERVER['SERVER_PROTOCOL']} 404 Not Found");
                exit;
            }
        }
    }
    // send HTTP headers to ensure aggressive caching
    header('Expires: ' . gmdate('D, d M Y H:i:s', time() + CACHE_LENGTH) . ' GMT');
    // 1 year from now
    header('Content-Type: ' . $fileType);
    header('Content-Length: ' . strlen($sCode));
    header("Last-Modified: {$sLastModified}");
    header("ETag: {$iETag}");
    header('Cache-Control: max-age=' . CACHE_LENGTH);
    // output merged code
    if (PACK == 1) {
        $packer = new JavaScriptPacker($sCode);
        $sCode = $packer->pack();
    }
    echo $sCode;
}
开发者ID:Imagenomad,项目名称:Unsupported,代码行数:58,代码来源:merge.php

示例13: compress

 public function compress($script_in)
 {
     try {
         $packer = new JavaScriptPacker($script_in);
     } catch (Exception $e) {
         throw new PreprocessFailureException(array('processor' => 'JavaScriptPacker'));
     }
     return $packer->pack();
 }
开发者ID:ronnyvv,项目名称:ResourcesController,代码行数:9,代码来源:JsProcessorComponent.php

示例14: _compression_js

 protected function _compression_js($script)
 {
     $this->load->library('web_apps/JavaScriptPacker');
     //$packer = new JavaScriptPacker($script, 'Normal', true, false);
     //$packer = new JavaScriptPacker($script, 62, false, true);
     $packer = new JavaScriptPacker($script, 62, false, true);
     $packed = $packer->pack();
     return $packed;
 }
开发者ID:119155012,项目名称:kals,代码行数:9,代码来源:admin_apps_controller.php

示例15: compile_files

 private function compile_files()
 {
     foreach ($this->scripts as $value) {
         $script = file_get_contents($value);
         if ($this->compress_file) {
             $packer = new JavaScriptPacker($script, 'None', false, false);
             $script = $packer->pack();
         }
         $scripts[] = $script;
     }
     return $scripts;
 }
开发者ID:shaunfreeman,项目名称:Uthando-CMS,代码行数:12,代码来源:JsLoader.php


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