function cmdRepo() { $file = new File('/home/billy/1.tar.bz2', true); $target = new Dir('/home/billy/temp/1.unpack/includes', true); //Packer::unpack($file, $target); Packer::pack($target, new File(dirname(__FILE__) . '/2.tbz', true)); return; $pm = new PM(); $pm->startup(); $rb = PM::getRollback(); $rb->push('delete', dirname(__FILE__) . '/_files/source', dirname(__FILE__) . '/_files/target/includes/Controller.php'); //$rb->push('delete', './_files/source', '_files/target/includes/Controller.php' ); //$r = $rb->pop(); $r = $rb->stepBack(); print_r($r); return; $ps = PM::getPackageSequence(); print_r($ps->get()); print_r($ps->getAfter('news', '2.3')); //print_pre($ps->addPackage('news', '2.8')); print_pre($ps->removePackage('news', '2.8')); return; Autoload::addDir(Dir::get($this->root, true)->getDir('repo')); $rl = new RepositoryList($this->dataDir->getFile('source.list')); $r = $rl->search(explode(' ', 'qt package')); print_pre($r); $pm->shutdown(); }
public function main() { App::import('vendor', 'inc/packer'); $js_pack = Configure::read("Asset.filter.js"); $time = date('YmdHis', time()); $p = new Packer(); $js_out = $css_out = ''; //delete old file $old = nforum_cache_read('asset_pack'); if (is_array($old)) { @unlink(APP . 'www/js/' . $old['js']); @unlink(APP . 'www/css/' . $old['css']); } /* handle js*/ $js = array('jquery-1.7.2.min.js', 'jquery-ui-1.8.20.min.js', 'jquery-ui-timepicker-addon.js', 'underscore-min.js', 'backbone-min.js', 'plupload.min.js', 'jquery.tools.min.js', 'jquery.placeholder.min.js', 'jquery.cookie.js', 'jquery.simpletree.js', 'jquery.jplayer.min.js', 'jquery.xslider.min.js', 'forum.config.js', 'forum.lib.js', 'forum.xwidget.js', 'forum.xubb.js', 'forum.keyboard.js'); foreach ($js as $v) { $js_out .= $js_pack && !strstr($v, 'min.js') ? $p->pack(APP . 'www/js/' . $v, 'js', false) : file_get_contents(APP . 'www/js/' . $v); } $js_file = 'pack_' . $this->_hash($js_out) . '.js'; file_put_contents(APP . 'www/js/' . $js_file, $js_out); /* handle js end */ /* handle css */ $css = array('common.css', 'jquery-ui-1.8.20.css', 'jplayer.blue.monday.css', 'ansi.css', 'ubb.css', 'keyboard.css'); foreach ($css as $v) { $css_out .= $p->pack(APP . 'www/css/' . $v, 'css', false); } $css_file = 'pack_' . $this->_hash($css_out) . '.css'; file_put_contents(APP . 'www/css/' . $css_file, $css_out); /* handle css end */ $asset = array('js' => $js_file, 'css' => $css_file); nforum_cache_write('asset_pack', $asset); }
/** * Run the scrapers. */ public function scrape() { // TODO: This should be read from the ``shelter_pages'' table $mhsDog = new MhsDogScraper("http://montanapets.org/mhs/residentdog.html"); $mhsCat = new MhsCatScraper("http://montanapets.org/mhs/residentcat.html"); $packer = new Packer(); $packer->pack($mhsDog->scrape()); $packer->pack($mhsCat->scrape()); $loader = new Loader($packer->getPackedPets()); $loader->checkActive(); $loader->load(); // temporary fix for the slashes in some breeds // @todo: this should be done in the scraper $db = new Database(Site::getInstance()->getDbConf()); $db->execute("update animals set breed = replace(breed, '/', '-')"); }
<?php extract($_POST); if (isset($pack)) { require 'classes.php'; $packer = new Packer(); $output = $packer->pack($input, isset($base62), isset($shrink), isset($privates)); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title>Packer: Test Page</title> <meta name="copyright" content="© copyright 2004-2008, Dean Edwards"/> <meta name="description" content="A Javascript compressor."/> <meta name="keywords" content="packer,javascript,compressor,obfuscator"/> <link rel="stylesheet" href="../packer.css" type="text/css" media="screen, projection"/> <script type="text/javascript"> var packer = { clear: function() { var form = document.forms[0]; form.input.value = ""; form.output.value = ""; form.decode.disabled = true; form.input.focus(); this.showMessage("ready"); }, decode: function() { var form = document.forms[0]; try {
if ($type === "css") { header("Content-Type: text/css;charset={$encoding}"); } else { if ($type === "js") { header("Content-Type: text/javascript;charset={$encoding}"); } } foreach ($filter as $v) { if (strpos($file, $v) !== false) { echo file_get_contents($file); exit; } } APP::import('vendor', 'inc/packer'); $p = new Packer(); echo $p->pack($file, $type); function make_cache($switch = false, $modified = 0, $expires = null) { if ($switch) { if (is_null($expires)) { $expires = 300; } if (!is_int($modified)) { $modified = 0; } @($oldmodified = $_SERVER["HTTP_IF_MODIFIED_SINCE"]); if ($oldmodified != "") { if (($pos = strpos($oldmodified, ';')) !== false) { $oldmodified = substr($oldmodified, 0, $pos); } $oldtime = strtotime($oldmodified);
/** * @dataProvider getSamples */ public function testCanPackRepresentativeLargerSamples($test, $boxes, $items, $expectedBoxes, $expectedWeightVariance) { $expectedItemCount = 0; $packedItemCount = 0; $packer = new Packer(); foreach ($boxes as $box) { $packer->addBox($box); } foreach ($items as $item) { $packer->addItem(new TestItem($item['name'], $item['width'], $item['length'], $item['depth'], $item['weight']), $item['qty']); $expectedItemCount += $item['qty']; } $packedBoxes = $packer->pack(); foreach (clone $packedBoxes as $packedBox) { $packedItemCount += $packedBox->getItems()->count(); } self::assertEquals($expectedBoxes, $packedBoxes->count()); self::assertEquals($expectedItemCount, $packedItemCount); self::assertEquals($expectedWeightVariance, (int) $packedBoxes->getWeightVariance()); }
public function testIssue20() { $packer = new Packer(); $packer->addBox(new TestBox('Le grande box', 100, 100, 300, 1, 100, 100, 300, 1500)); $packer->addItem(new TestItem('Item 1', 150, 50, 50, 20, false)); $packedBoxes = $packer->pack(); self::assertEquals(1, $packedBoxes->count()); }
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 Packer($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"; }
<?php include 'classes.php'; if ($argc > 1) { $options = $argc > 2 ? $argv[2] : 's'; // options $base62 = preg_match('/e/', $options); $shrink = preg_match('/s/', $options); $privates = preg_match('/p/', $options); $script = file_get_contents($argv[1]); $packer = new Packer(); $output = $packer->pack($script, $base62, $shrink, $privates); fwrite(STDOUT, $output); } else { fwrite(STDOUT, ' Compress a JavaScript source file using Dean Edwards\' Packer. Version : 3.1 Syntax : /path/to/php.exe pack.php -esp Options : e: base62 encode s: shrink variables p: encode _private variables '); }
protected function _initAsset() { App::import('vendor', 'inc/packer'); $p = new Packer(); $js_out = $css_out = ''; $js_pack = Configure::read("Asset.filter.js"); $css_pack = Configure::read("Asset.filter.css"); /* handle js*/ $js_filter = array('js/plupload.min.js'); //get relative path with WWW_ROOT foreach ($this->js as $k => $v) { if ($k === "plugin") { foreach ($v as $pl => $_v) { foreach ($_v as $js) { $this->js[] = "plugins/{$pl}/js/{$js}"; } } unset($this->js['plugin']); } else { $this->js[$k] = "js/{$v}"; } } //check for direct output foreach ($this->js as $k => $v) { if (!in_array($v, $js_filter)) { $js_out .= $js_pack ? $p->pack(WWW_ROOT . $v, 'js') : file_get_contents(WWW_ROOT . $v); unset($this->js[$k]); } } if ($js_pack) { foreach ($this->js as &$js) { $js = str_replace("js/", "cjs/", $js); } } /* handle js end*/ /* handle css*/ $css_filter = array('css/xwidget.css'); //get relative path with WWW_ROOT foreach ($this->css as $k => $v) { if ($k === "plugin") { foreach ($v as $pl => $_v) { foreach ($_v as $css) { $this->css[] = "plugins/{$pl}/css/{$css}"; //filter plugin css $css_filter[] = "plugins/{$pl}/css/{$css}"; } } unset($this->css['plugin']); } else { $this->css[$k] = "css/{$v}"; } } /** * sometime css can output with html to reduce http request * but if css has image referrence, the image will hard to find * so I keep css file as a link */ //check for direct output foreach ($this->css as $k => $v) { if (!in_array($v, $css_filter)) { $css_out .= $css_pack ? $p->pack(WWW_ROOT . $v, 'css') : file_get_contents(WWW_ROOT . $v); unset($this->css[$k]); } } if ($css_pack) { foreach ($this->css as &$css) { $css = str_replace("css/", "ccss/", $css); } } /* handle css end*/ $this->set("js", $this->js); $this->set("js_out", $js_out); $this->set("css", $this->css); $this->set("css_out", $css_out); }
/** * @param int $int * @param int $bytes * @param int $endian * @return ByteBuffer */ public function writeInt($int, $bytes = 1, $endian = null) { if ($bytes > 8) { throw new \LengthException("Can't write integer larger 64 bit."); } if ($bytes > 4 && !$this->can64()) { throw new \LengthException('Your system not support 64 bit integers.'); } if ($endian === null) { $endian = $this->getEndian(); } $str = Packer::pack(Packer::getFormat('int', $bytes * 8, false, $endian), $int); return $this->write($str); }