Ejemplo n.º 1
0
 private function _bootStrap($packed, $keywords)
 {
     $ENCODE = $this->_safeRegExp('$encode\\($count\\)');
     // $packed: the packed script
     $packed = "'" . $this->_escape($packed) . "'";
     // $ascii: base for encoding
     $ascii = min(count($keywords['sorted']), $this->_encoding);
     if ($ascii == 0) {
         $ascii = 1;
     }
     // $count: number of words contained in the script
     $count = count($keywords['sorted']);
     // $keywords: list of words contained in the script
     foreach ($keywords['protected'] as $i => $value) {
         $keywords['sorted'][$i] = '';
     }
     // convert from a string to an array
     ksort($keywords['sorted']);
     $keywords = "'" . implode('|', $keywords['sorted']) . "'.split('|')";
     $encode = $this->_encoding > 62 ? '_encode95' : $this->_getEncoder($ascii);
     $encode = $this->_getJSFunction($encode);
     $encode = preg_replace('/_encoding/', '$ascii', $encode);
     $encode = preg_replace('/arguments\\.callee/', '$encode', $encode);
     $inline = '\\$count' . ($ascii > 10 ? '.toString(\\$ascii)' : '');
     // $decode: code snippet to speed up decoding
     if ($this->_fastDecode) {
         // create the decoder
         $decode = $this->_getJSFunction('_decodeBody');
         if ($this->_encoding > 62) {
             $decode = preg_replace('/\\\\w/', '[\\xa1-\\xff]', $decode);
         } elseif ($ascii < 36) {
             $decode = preg_replace($ENCODE, $inline, $decode);
         }
         // special case: when $count==0 there are no keywords. I want to keep
         //  the basic shape of the unpacking funcion so i'll frig the code...
         if ($count == 0) {
             $decode = preg_replace($this->_safeRegExp('($count)\\s*=\\s*1'), '$1=0', $decode, 1);
         }
     }
     // boot function
     $unpack = $this->_getJSFunction('_unpack');
     if ($this->_fastDecode) {
         // insert the decoder
         $this->buffer = $decode;
         $unpack = preg_replace_callback('/\\{/', array(&$this, '_insertFastDecode'), $unpack, 1);
     }
     $unpack = preg_replace('/"/', "'", $unpack);
     if ($this->_encoding > 62) {
         // high-ascii
         // get rid of the word-boundaries for regexp matches
         $unpack = preg_replace('/\'\\\\\\\\b\'\\s*\\+|\\+\\s*\'\\\\\\\\b\'/', '', $unpack);
     }
     if ($ascii > 36 || $this->_encoding > 62 || $this->_fastDecode) {
         // insert the encode function
         $this->buffer = $encode;
         $unpack = preg_replace_callback('/\\{/', array(&$this, '_insertFastEncode'), $unpack, 1);
     } else {
         // perform the encoding inline
         $unpack = preg_replace($ENCODE, $inline, $unpack);
     }
     // pack the boot function too
     $unpackPacker = new Jspacker_lib($unpack, 0, false, true);
     $unpack = $unpackPacker->pack();
     // arguments
     $params = array($packed, $ascii, $count, $keywords);
     if ($this->_fastDecode) {
         $params[] = 0;
         $params[] = '{}';
     }
     $params = implode(',', $params);
     // the whole thing
     return 'eval(' . $unpack . '(' . $params . "))\n";
 }
/**
 * 合并js为一个文件
 *
 * @param unknown_type $urls        	
 * @param unknown_type $path        	
 * @return unknown
 */
function merge_script($js_urls, $path = "/public/data/assets/js", $filename = '')
{
    if (!is_array($js_urls)) {
        $js_urls[] = $js_urls;
    }
    if (!file_exists(FCPATH . $path)) {
        mkdir(FCPATH . $path, 0777);
    }
    if (empty($filename)) {
        $filename = md5(implode(',', $js_urls));
    }
    $js_url = $path . "/" . $filename . ".js";
    if (true || !file_exists(FCPATH . $js_url)) {
        require_once "app/libraries/jspacker_lib.php";
        $js_content = '';
        foreach ($js_urls as $url) {
            $append_content = @file_get_contents(FCPATH . $url) . "\r\n";
            $packer = new Jspacker_lib($append_content);
            $append_content = $packer->pack();
            $js_content .= $append_content;
        }
        @file_put_contents(FCPATH . $js_url, $js_content);
    }
    return $js_url;
}