/** * Sets up test case * */ public function setUp() { try { $this->classname = $this->testClassName(); $this->interfacename = $this->testClassName('I'); } catch (IllegalStateException $e) { throw new PrerequisitesNotMetError($e->getMessage()); } // Create an archive $this->tempfile = new TempFile($this->name); $archive = new Archive($this->tempfile); $archive->open(ARCHIVE_CREATE); $this->add($archive, $this->classname, ' uses("util.Comparator", "' . $this->interfacename . '"); class ' . $this->classname . ' extends Object implements ' . $this->interfacename . ', Comparator { public function compare($a, $b) { return strcmp($a, $b); } } '); $this->add($archive, $this->interfacename, 'interface ' . $this->interfacename . ' { } '); $archive->create(); // Setup classloader $this->classloader = new ArchiveClassLoader($archive); ClassLoader::getDefault()->registerLoader($this->classloader, TRUE); }
public function create($paths, $filename = FALSE) { $archive = new Archive('tar'); foreach ($paths as $set) { $archive->add($set[0], $set[1]); } $gzfile = bzcompress($archive->create()); if ($filename == FALSE) { return $gzfile; } if (substr($filename, -8) !== '.tar.bz2') { // Append tar extension $filename .= '.tar.bz2'; } // Create the file in binary write mode $file = fopen($filename, 'wb'); // Lock the file flock($file, LOCK_EX); // Write the tar file $return = fwrite($file, $gzfile); // Unlock the file flock($file, LOCK_UN); // Close the file fclose($file); return (bool) $return; }
public function readingArchiveV1() { $a = new Archive($this->getClass()->getPackage()->getResourceAsStream('v1.xar')); $a->open(ARCHIVE_READ); $this->assertEquals(1, $a->version); $this->assertTrue($a->contains('contained.txt')); $this->assertEntries($a, array('contained.txt' => "This file is contained in an archive!\n")); }
/** * Execute action * * @return int */ public function perform() { $this->archive->open(ARCHIVE_READ); $args = $this->getArguments(); if (!isset($args[0]) || !file_exists(current($args))) { throw new IllegalArgumentException('No archive to compare given or not found.'); } $cmp = new Archive(new File(current($args))); $cmp->open(ARCHIVE_READ); return $this->compare($this->archive, $cmp); }
public function archive($build = FALSE) { if ($build === 'build') { // Load archive $archive = new Archive('zip'); // Download the application/views directory $archive->add(APPPATH . 'views/', 'app_views/', TRUE); // Download the built archive $archive->download('test.zip'); } else { echo html::anchor(Router::$current_uri . '/build', 'Download views'); } }
/** * Get a list of deployments * * @return remote.server.deploy.Deployable[] */ public function scanDeployments() { clearstatcache(); $this->changed = FALSE; while ($entry = $this->folder->getEntry()) { if (!preg_match($this->pattern, $entry)) { continue; } $f = new File($this->folder->getURI() . $entry); if (isset($this->files[$entry]) && $f->lastModified() <= $this->files[$entry]) { // File already deployed continue; } $this->changed = TRUE; $ear = new Archive(new File($this->folder->getURI() . $entry)); try { $ear->open(ARCHIVE_READ) && ($meta = $ear->extract('META-INF/bean.properties')); } catch (Throwable $e) { $this->deployments[$entry] = new IncompleteDeployment($entry, $e); continue; } $prop = Properties::fromString($meta); $beanclass = $prop->readString('bean', 'class'); if (!$beanclass) { $this->deployments[$entry] = new IncompleteDeployment($entry, new FormatException('bean.class property missing!')); continue; } $d = new Deployment($entry); $d->setClassLoader(new ArchiveClassLoader($ear)); $d->setImplementation($beanclass); $d->setInterface($prop->readString('bean', 'remote')); $d->setDirectoryName($prop->readString('bean', 'lookup')); $this->deployments[$entry] = $d; $this->files[$entry] = time(); delete($f); } // Check existing deployments foreach (array_keys($this->deployments) as $entry) { $f = new File($this->folder->getURI() . $entry); if (!$f->exists()) { unset($this->deployments[$entry], $this->files[$entry]); $this->changed = TRUE; } delete($f); } $this->folder->close(); return $this->changed; }
function setFromPost() { parent::setFromPost(); if (isset($_POST["transcript_id"])) { $this->transcript_id = $_POST["transcript_id"]; } }
private function on_download() { Util::json_fail(Util::ERR_DISABLED, 'download disabled', !$this->context->query_option('download.enabled', false)); $as = $this->request->query('as'); $type = $this->request->query('type'); $base_href = $this->request->query('baseHref'); $hrefs = $this->request->query('hrefs'); $archive = new Archive($this->context); set_time_limit(0); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . $as . '"'); header('Connection: close'); $ok = $archive->output($type, $base_href, $hrefs); Util::json_fail(Util::ERR_FAILED, 'packaging failed', !$ok); exit; }
function setFromRequest() { parent::setFromRequest(); if (isset($_REQUEST["image"])) { $this->image_id = $_REQUEST["image"]; } }
public function __construct($theme = null) { parent::__construct(); $this->targetDirectory = DIR_FILES_THEMES; if ($theme) { $this->_theme = $theme; } }
public function __construct(\ZipArchive $zipArchive, $tmpFilePath = '/tmp') { $tmpFile = tempnam($tmpFilePath, 'zip'); parent::__construct($zipArchive, $tmpFile); register_shutdown_function(function ($filename) { unlink($filename); }, $tmpFile); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * * @param * integer the ID of the model to be loaded */ public function loadModel($id) { $model = Archive::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function unzip($file) { $fh = Loader::helper('file'); $dirBase = parent::unzip($file); $dirFull = $this->getArchiveDirectory($dirBase); $dirBase = substr(strrchr($dirFull, '/'), 1); return $fh->getTemporaryDirectory() . '/' . $file . '/' . $dirBase; }
public function afterSaved($payload) { unset($payload->attributes['created_at']); unset($payload->attributes['updated_at']); unset($payload->original['created_at']); unset($payload->original['updated_at']); if ($payload->attributes != $payload->original) { Archive::create(['token' => md5(time()), 'entity_id' => $payload->attributes['id'], 'entity_type' => get_class($payload), 'entity_data' => json_encode($payload->attributes)]); Log::info(get_class($payload) . ' #' . $payload->attributes['id'] . ' was archived'); } }
/** * */ public function testAddDirectory() { // create test files $dir = sys_get_temp_dir() . '/testarchive'; $zipfile = sys_get_temp_dir() . '/testarchive.zip'; mkdir($dir); file_put_contents($dir . '/one.txt', 'one1'); file_put_contents($dir . '/two', 'two2'); mkdir($dir . '/sub'); file_put_contents($dir . '/sub/three.txt', 'three3'); $zip = new Archive(); $zip->open($zipfile, \ZipArchive::CREATE); $zip->addDirectory($dir); $zip->close(); $zip = new Archive(); $zip->open($zipfile); $this->assertEquals('one1', $zip->getFromName('one.txt')); $this->assertEquals('two2', $zip->getFromName('two')); $this->assertEquals('three3', $zip->getFromName('sub' . DIRECTORY_SEPARATOR . 'three.txt')); $zip->close(); // clean up unlink($dir . '/sub/three.txt'); rmdir($dir . '/sub'); unlink($dir . '/two'); unlink($dir . '/one.txt'); rmdir($dir); unlink($zipfile); }
/** * @param string $destinationFile * @param string $extensionRequired * @dataProvider tarProvider */ public function testExtract($destinationFile, $extensionRequired) { if ($extensionRequired && !extension_loaded($extensionRequired)) { $this->markTestSkipped("The extension '{$extensionRequired}' is not enabled."); } $this->packed = $this->archive->pack($this->sourceFilePath, $this->destinationDir . $destinationFile); $this->assertFileExists($this->packed); $this->assertEquals($this->destinationDir . $destinationFile, $this->packed); $filename = pathinfo($this->sourceFilePath, PATHINFO_BASENAME); $this->unpacked = $this->archive->extract($filename, $this->packed, $this->destinationDir); $this->assertFileExists($this->unpacked); $this->assertStringStartsWith($this->destinationDir, $this->unpacked); }
public function finalize($totalSize, $treeHash) { $file = $this->getFile('data'); if (($f = fopen($file, 'r+')) === false) { return false; } ftruncate($f, $totalSize); fclose($f); $a = new Archive(true, $this->vault); $a->setParam('SHA256TreeHash', $treeHash); $a->setParam('Size', $totalSize); $a->setParam('Description', $this->getParam('Description')); rename($this->getFile('data'), $a->getFile('data')); $this->delete(); return $a; }
public function codiad_CFG($hash) { $dir_relative = GlobalMas::$filesPath_relative . $hash . "/"; $dir = GlobalMas::$filesPath_absolute . $hash . "/"; //----------------------------------------------------- if (!file_exists($dir . "codiad")) { Archive::extract(GlobalMas::$filesPath_absolute . "/codiad.zip", $dir); //----------------------------------------------------- $config_contents = FileFolder::file_get_contents($dir . "codiad/config.php"); $config_contents = str_replace("{BASE_PATH}", $dir . "codiad", $config_contents); $config_contents = str_replace("{BASE_URL}", GenFun::get_full_url($dir . "codiad"), $config_contents); FileFolder::file_put_contents($dir . "codiad/config.php", $config_contents); //--------------------------------------------------------- exec("ln -s " . $dir . "compile " . $dir . "codiad/workspace/compile" . " 2>&1", $output); exec("ln -s " . $dir . " " . $dir . "codiad/workspace/root" . " 2>&1", $output); //--------------------------------------------------------- if (strpos(join($output), "Errno::") !== false) { krumo($output); die; } } }
function previewPlan(&$user, $plan) { $timestamp = mktime(); /* format the journalled plan */ if ($this->getPreference('journal')) { if (!($divider = $this->getPreference('journal_divider'))) { $divider = PW_DIVIDER; } if ($this->getPreference('journal_order') == 'new') { // show current plan $tmp = Planworld::getDisplayDivider($divider, $timestamp) . "\n" . $plan . "\n"; // show archived plans for ($i = 0; $i < $this->getPreference('journal_entries'); $i++) { list($ts, $txt) = Archive::getEntryByIndex($this->userID, $i); if ($ts == 0) { break; } $tmp .= Planworld::getDisplayDivider($divider, $ts) . "\n"; $tmp .= $txt . "\n"; } $plan = $tmp; } else { $tmp = ''; for ($i = $this->getPreference('journal_entries') - 1; $i >= 0; $i--) { list($ts, $txt) = Archive::getEntryByIndex($this->userID, $i); if ($ts == 0) { break; } $tmp .= Planworld::getDisplayDivider($divider, $ts) . "\n"; $tmp .= $txt . "\n"; } // show current plan $tmp .= Planworld::getDisplayDivider($divider, $timestamp) . "\n" . $plan . "\n"; $plan = $tmp; } } return $this->displayPlan($user, $plan); }
public function creatingArchive() { $contents = array('lang/Object.class.php' => 'class Object { }', 'lang/Type.class.php' => 'class Type extends Object { }'); $a = new Archive(new Stream()); $a->open(ARCHIVE_CREATE); foreach ($contents as $filename => $bytes) { $a->addFileBytes($filename, NULL, NULL, $bytes); } $a->create(); $this->assertEntries($a, $contents); }
public function getArchive($id) { $ret = new Archive($id, $this); if (!$ret->exists()) { return false; } return $ret; }
<?php try { $Archive = new Archive(); $Archive->setFilename("index.php"); $Archive->setPage($_GET['page'], "page"); if (!$_COOKIE['login']) { $Archive->setPublic(1); } $Archive->DateList(); $AboutMe = array(array("title" => "Information", "info" => array("Alias" => "Compubomb", "Name" => "Robert Kraig", "Height" => "5'11")), array("title" => "Contact", "info" => array("ICQ" => "59128707", "AIM" => "c0mpub0mb", "YIM" => "compubomb", "MSN" => "compubomb at hotmail.com", "Email" => "robertkraig at gmail.com")), array("title" => "Community Sites", "info" => array("myspace.com" => "<a href=\"http://www.myspace.com/compubomb\">Here</a>", "okcupid.com" => "<a href=\"http://www.okcupid.com/profile?u=compubomb\">Here</a>")), array("title" => "Music Genres", "info" => array("Electronic" => "*Trance, Deep House, Disco House, Progressive House, Ibiza/Chillout", "Jazz" => "Smooth, Acid, Traditional", "POP" => "Everything that has a catchy beat")), array("title" => "Music Artists", "info" => array("Trance" => "Armin Van Burrent, DJ Tiesto, Ferry Corsten, Paul Van Dyke, Chicane", "Deep House" => "DJ Mark Farina", "Dream House" => "Robert Miles", "Chillout" => "Cafe Del Mar")), array("title" => "Community Sites", "info" => array("OS" => "Microsoft Windows XP sp3 Pro, Ubuntu", "Graphics" => "Adobe Photoshop CS3", "Desk.Pub" => "Indesign CS3", "Web Dev" => "Adobe Dreamweaver CS3, Zend Studio Eclipse, Notepad++, gvim 7.0"))); $smarty->assign(array("page_name" => "About Me", "load" => "aboutme.tpl", "filename" => $Archive->getFilename(), "archive_index" => $Archive->getIndex(), "sql_queries" => $Archive->getSQLQueries(), "aboutme" => $AboutMe)); $smarty->display('public/body/index.tpl'); echo "<!-- page rendered in approx {$timer->Stop()} -->"; } catch (Exception $e) { $smarty->assign(array("exception" => $e->getMessage())); $smarty->display('public/body/error.tpl'); }
public static function create($save_path, $files) { // Since files can be an array or a path... if (!is_array($files)) { $files = array($files); } $archive = new Archive(); // Loop through files...(or the one directory/file) foreach ($files as $file) { if (file_exists($file)) { $archive->add($file); } } // Save the file $archive->save($save_path); // Status return file_exists($save_path); }
private function on_download() { json_fail(1, "downloads disabled", !$this->options["download"]["enabled"]); $as = use_request_param("as"); $type = use_request_param("type"); $hrefs = use_request_param("hrefs"); $archive = new Archive($this->app); $hrefs = explode("|:|", trim($hrefs)); set_time_limit(0); header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"{$as}\""); header("Connection: close"); $rc = $archive->output($type, $hrefs); json_fail(2, "packaging failed", $rc !== 0); exit; }
/** * Triggers the necessary calculations when a page is added, edited or removed * * @author Woxxy */ public function on_change($chapter) { // cleanup the archive if there is one for this chapter $archives = new Archive(); $archives->where('comic_id', $chapter->comic_id)->group_start()->where('chapter_id', $chapter->id)->or_where('volume_id', $chapter->volume)->group_end()->get(); if ($archives->result_count()) { foreach ($archives as $archive) { $archive->remove(); } } }
<?php try { $Archive = new Archive(); $Archive->setPage($vars['page'], "page"); $Archive->setFilename("/Admin_Posts"); $Archive->setDay($vars['day']); $Archive->setMonth($vars['month']); $Archive->setYear($vars['year']); $Archive->setUserId($vars['user']); $Archive->setId($vars['post']); $Archive->setCatId($vars['cat']); $ArchiveCategories = new ArchiveCategories(); $Archive->BuildData(); $ArchiveCategories->BuildData(); if ($vars['cat']) { $title = " ( {$ArchiveCategories->getTitle($Archive->getCatId())} {$Archive->getLookupDate()}) : Page : " . (1 + $Archive->getPage()) . " of " . $Archive->getnumOfRecords(); } else { if ($Archive->getLibUseType() == "archive") { $title = " : Archive ( {$Archive->getLookupDate()} ) Page : " . (1 + $Archive->getPage()) . " of " . $Archive->getnumOfRecords(); } else { $title = " : Page : " . (1 + $Archive->getPage()) . " of " . $Archive->getnumOfRecords(); } } // $smarty->assign(array("page_name" => "Posts" . $title, "load" => "posts/view/posts.tpl", "loadindex" => "posts/view/post_index.tpl", "filename" => $Archive->getFilename(), "archive_index" => $Archive->getIndex(), "archiveCategory_index" => $ArchiveCategories->getRecords(), "records" => $Archive->getRecords(), "page_list" => $Archive->getCountDisplay())); $smarty->display('admin/body/index.tpl'); echo "<!-- page rendered in approx {$timer->Stop()} -->"; } catch (Exception $e) { print "Exception: " . $e->getMessage(); }
public function install($file) { parent::install($file, true); }
<?php require_once 'includes/inc.global.php'; // remove any previous game sessions unset($_SESSION['game_file']); unset($_SESSION['step']); $meta['title'] = 'Archive List'; $meta['head_data'] = ' <script type="text/javascript" src="scripts/archive.js"></script> '; // grab the list of games $list = Archive::get_list(); $contents = ''; $table_meta = array('sortable' => true, 'no_data' => '<p>There are no games to show</p>', 'caption' => 'Archived Games'); $table_format = array(array('SPECIAL_HTML', 'true', 'id="[[[short_file]]]"'), array('ID', 'game_id'), array('Name', 'clean_name'), array('Winner', '[[[winner]]]'), array('Extra Info', '<abbr title="Fortify: [[[get_fortify]]] | Kamikaze: [[[get_kamikaze]]] | Warmonger: [[[get_warmonger]]] | FoW Armies: [[[get_fog_of_war_armies]]] | FoW Colors: [[[get_fog_of_war_colors]]] | Conquer Limit: [[[get_conquer_limit]]] | Custom Rules: [[[clean_custom_rules]]]">Hover</abbr>'), array('Players', '[[[players]]]'), array('Start Date', '###ldate(Settings::read(\'long_date\'), strtotime(\'[[[start_date]]]\'))', null, ' class="date"')); $contents .= ' <div class="tableholder"> ' . get_table($table_format, $list, $table_meta) . ' </div>'; $hints = array('Select a game from the list and review play by clicking anywhere on the row.'); echo get_header($meta); echo get_item($contents, $hints, $meta['title']); call($GLOBALS); echo get_footer($meta);
public function init($obj) { //---------------------------------------------------------- //init var //---------------------------------------------------------- $chk = array("bool" => true, 'result' => array(), "func" => "init"); //---------------------------------------------------------- if (!is_null($obj)) { if (isset($obj['zip'])) { $getFile = GetTable::go("files", array("id" => $obj['zip'])); //------------------------------------------------------ if (!$getFile['bool']) { return $getFile; } if (sizeof($getFile['result']) > 0) { //-------------------------------------------------- $projectName = $obj['project_name']; $hash = $getFile['result'][0]['hash']; $dir_relative = GlobalMas::$filesPath_relative . $hash . "/"; $dir = GlobalMas::$filesPath_absolute . $hash . "/"; $zip_path = $dir . $getFile['result'][0]['name']; $savePath = dirname($zip_path) . "/compile/" . $projectName . "/"; //----------------------------------------------------- Archive::extract($zip_path, $this->extractTo = dirname($zip_path) . "/" . FileFolder::getFileName($zip_path)); //----------------------------------------------------- //if (isset($obj['take_file_name']) && $obj['take_file_name'] == "true") $projectName = FileFolder::getFileName($zip_path); //----------------------------------------------------- $url = GenFun::get_full_url(dirname($zip_path) . "/" . rawurlencode(FileFolder::getFileName($zip_path)) . "/"); //----------------------------------------------------- $bool = $this->htmlExist_CHK($this->extractTo); } } else { if (isset($obj['url']) || is_string($obj)) { $url = isset($obj['url']) ? $obj['url'] : $obj; $bool = $this->htmlExist_CHK($url_local = GenFun::get_local_url($url)); //------------------------------------------------------ $output = CurlUtil::go(array("url" => $url)); $projectName = $this->getTitle($output); //------------------------------------------------------ if (is_null($projectName)) { $projectName = date("YmdHis"); $hash = alphaID(strtotime($projectName)); $projectName = "untitled_" . $projectName; } //------------------------------------------------------ $savePath_relative = $hash . "/" . "compile/" . $projectName . "/"; $savePath = GlobalMas::$filesPath_absolute . $savePath_relative; /*if (isset($obj['take_file_name']) && $obj['take_file_name'] == "true")*/ $useTitle = true; } else { $chk = array(); $chk['bool'] = false; $chk['error'] = true; $chk['message'] = $this->notifications_CFG(["message" => "Url could not be obtained!!!"]); die(json_encode($chk)); } } //--------------------------------------------------------- $compiler = $this->compile_CFG($url, $projectName, $savePath); //--------------------------------------------------------- if (!is_null($compiler->error)) { return $compiler->error; } //--------------------------------------------------------- //$chk['bool'] = true; // $chk['compiler'] = $compiler; $notifications = $compiler->compilerGlobal->notifications; //--------------------------------------------------------- /*if (sizeof($notifications) > 0) { $chk = $this->deleteFile($getFile['result'][0]['id'], true); $chk['message'] = $this->notifications_CFG($notifications); $chk['bool'] = false; $chk['error'] = true; return $chk; }*/ //--------------------------------------------------------- $new_zip_path = Archive::zipDir($compiler->compilePath); //--------------------------------------------------------- $prop = array(); $prop['hash'] = "{hash}"; $prop['url'] = $url; $prop['name'] = $projectName; $prop['dir'] = $savePath_relative; $prop["filesize"] = FileFolder::getFileSize($new_zip_path); if (isset($obj['zip'])) { $prop['files_id'] = $obj['zip']; } //--------------------------------------------------------- $chk = InsertINTO::go("compiles", $prop); //--------------------------------------------------------- $chk['download_link'] = GenFun::get_full_url(Import::$uber_src_path . "server/werm/services/Download.php") . "?url=" . GenFun::get_full_url($new_zip_path); $chk["filesize"] = $prop["filesize"]; $chk["url"] = $url; //--------------------------------------------------------- //$chk['project_location'] = GenFun::get_full_url($compiler->compilePath); } return $chk; }
/** * Removes all the ZIPs * * @author Woxxy * @returns bool */ function remove_all() { $archives = new Archive(); $archives->get(); foreach ($archive->all as $archive) { $archive->remove(); } }