function main() { $tar = new tar(); $tar->addFile('./test.pdf'); $tar->toTar('./test_create.tar', false); $tar1 = new tar(); $opened = $tar1->openTAR('./test_create.tar'); if ($opened) { $soubor = $tar1->getFile('./test.pdf'); echo $soubor["file"]; } else { echo "FAILED TO OPEN ARCHIVE"; } }
/** * export user layout * @return void */ function procLayoutAdminUserLayoutExport() { $layout_srl = Context::get('layout_srl'); if (!$layout_srl) { return new Object('-1', 'msg_invalid_request'); } require_once _XE_PATH_ . 'libs/tar.class.php'; $oLayoutModel = getModel('layout'); // Copy files to temp path $file_path = $oLayoutModel->getUserLayoutPath($layout_srl); $target_path = $oLayoutModel->getUserLayoutPath(0); FileHandler::copyDir($file_path, $target_path); // replace path and ini config $ini_config = $oLayoutModel->getUserLayoutIniConfig(0); $file_list = $oLayoutModel->getUserLayoutFileList($layout_srl); unset($file_list[2]); foreach ($file_list as $file) { if (strncasecmp('images', $file, 6) === 0) { continue; } // replace path $file = $target_path . $file; $content = FileHandler::readFile($file); $pattern = '/(http:\\/\\/[^ ]+)?(\\.\\/)?' . str_replace('/', '\\/', str_replace('./', '', $file_path)) . '/'; if (basename($file) == 'faceoff.css' || basename($file) == 'layout.css') { $content = preg_replace($pattern, '../', $content); } else { $content = preg_replace($pattern, './', $content); } // replace ini config foreach ($ini_config as $key => $value) { $content = str_replace('{$layout_info->faceoff_ini_config[\'' . $key . '\']}', $value, $content); } FileHandler::writeFile($file, $content); } // make info.xml $info_file = $target_path . 'conf/info.xml'; FileHandler::copyFile('./modules/layout/faceoff/conf/info.xml', $info_file); $content = FileHandler::readFile($info_file); $content = str_replace('type="faceoff"', '', $content); FileHandler::writeFile($info_file, $content); $file_list[] = 'conf/info.xml'; // make css file $css_file = $target_path . 'css/layout.css'; FileHandler::copyFile('./modules/layout/faceoff/css/layout.css', $css_file); $content = FileHandler::readFile('./modules/layout/tpl/css/widget.css'); FileHandler::writeFile($css_file, "\n" . $content, 'a'); $content = FileHandler::readFile($target_path . 'faceoff.css'); FileHandler::writeFile($css_file, "\n" . $content, 'a'); $content = FileHandler::readFile($target_path . 'layout.css'); FileHandler::writeFile($css_file, "\n" . $content, 'a'); // css load $content = FileHandler::readFile($target_path . 'layout.html'); $content = "<load target=\"css/layout.css\" />\n" . $content; FileHandler::writeFile($target_path . 'layout.html', $content); unset($file_list[3]); unset($file_list[1]); $file_list[] = 'css/layout.css'; // Compress the files $tar = new tar(); $user_layout_path = FileHandler::getRealPath($oLayoutModel->getUserLayoutPath(0)); chdir($user_layout_path); foreach ($file_list as $key => $file) { $tar->addFile($file); } $stream = $tar->toTarStream(); $filename = 'faceoff_' . date('YmdHis') . '.tar'; header("Cache-Control: "); header("Pragma: "); header("Content-Type: application/x-compressed"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // header("Content-Length: " .strlen($stream)); ?? why?? header('Content-Disposition: attachment; filename="' . $filename . '"'); header("Content-Transfer-Encoding: binary\n"); echo $stream; // Close Context and then exit Context::close(); // delete temp path FileHandler::removeDir($target_path); exit; }
/** * @param $mods_path * @param $info_file * @return bool|string */ function package($mods_path, $info_file) { $oldir = getcwd(); if (chdir($mods_path) === FALSE) { $err = sprintf(tra("Can't chdir to '%s'"), $mods_path); return $err; } include_once $oldir . '/lib/tar.class.php'; $info_file = 'Packages/' . $this->type . '-' . $this->name . '.info.txt'; $err = $this->readinfo($info_file); if ($err !== FALSE) { chdir($oldir); return $err; } if (is_file("Dist/" . $this->type . '-' . $this->name . '-' . $this->revision . '.tgz')) { unlink("Dist/" . $this->type . '-' . $this->name . '-' . $this->revision . '.tgz'); } $tar = new tar(); $tar->addFile($info_file); if (is_array($this->files)) { foreach ($this->files as $f) { $tar->addFile($f[0]); } } $filename = 'Dist/' . $this->type . '-' . $this->name . '-' . $this->revision . '.tgz'; $tar->toTar($filename, 1); if (!function_exists('md5_file')) { $this->md5 = md5(implode('', file($filename))); } else { $this->md5 = md5_file($filename); } chmod($filename, 0644); // needed on some servers chdir($oldir); return $err; }
function logMerge($title, $t_d, $t_m, $t_y, $f_d = 1, $f_m = 1, $f_y = 1980) { $logs = rcms_scandir($this->logging); $f = mktime(0, 0, 0, $f_m, $f_d, $f_y); $t = mktime(0, 0, 0, $t_m, $t_d, $t_y); $to_merge = array(); foreach ($logs as $log_entry) { if (preg_match("/^(.*?)-(.*?)-(.*?)\\.log(|.gz)\$/i", $log_entry, $matches)) { $c = mktime(0, 0, 0, $matches[2], $matches[3], $matches[1]); if ($c >= $f && $c <= $t) { $to_merge[] = $log_entry; } } } if (!empty($to_merge)) { if ($this->logging_gz) { $suffix = '.gz'; } else { $suffix = ''; } $merged_file = $this->logging . $title . '.tar' . $suffix; $merged = new tar(); $merged->isGzipped = $this->logging_gz; $merged->filename = $merged_file; $path = getcwd(); chdir($this->logging); foreach ($to_merge as $file) { $merged->addFile($file, substr($file, -3) == '.gz'); } chdir($path); if ($merged->saveTar()) { foreach ($to_merge as $file) { rcms_delete_files($this->logging . $file); } } } return true; }
function dump() { global $tikidomain, $wikiHomePage, $style; $dump_path = "dump"; if ($tikidomain) { $dump_path .= "/{$tikidomain}"; } @unlink("{$dump_path}/new.tar"); $tar = new tar(); $tar->addFile("styles/{$style}"); // Foreach page $query = "select * from `tiki_pages`"; $result = $this->query($query, array()); while ($res = $result->fetchRow()) { $pageName = $res["pageName"] . '.html'; $dat = $this->parse_data($res["data"]); // Now change index.php?page=foo to foo.html // and index.php to HomePage.html $dat = preg_replace("/tiki-index.php\\?page=([^\\'\"\$]+)/", "\$1.html", $dat); $dat = preg_replace("/tiki-editpage.php\\?page=([^\\'\"\$]+)/", "", $dat); //preg_match_all("/tiki-index.php\?page=([^ ]+)/",$dat,$cosas); //print_r($cosas); $data = "<html><head><title>" . $res["pageName"] . "</title><link rel='StyleSheet' href='styles/{$style}' type='text/css'></head><body><a class='wiki' href='{$wikiHomePage}.html'>home</a><br /><h1>" . $res["pageName"] . "</h1><div class='wikitext'>" . $dat . '</div></body></html>'; $tar->addData($pageName, $data, $res["lastModif"]); } $tar->toTar("{$dump_path}/new.tar", FALSE); unset($tar); $action = "dump created"; $t = date("U"); $query = "insert into `tiki_actionlog`(`action`,`pageName`,`lastModif`,`user`,`ip`,`comment`) values(?,?,?,?,?,?)"; $result = $this->query($query, array($action, $wikiHomePage, $t, 'admin', $_SERVER["REMOTE_ADDR"], '')); }
function dump() { global $tikidomain, $prefs; $parserlib = TikiLib::lib('parser'); $dump_path = "dump"; if ($tikidomain) { $dump_path .= "/{$tikidomain}"; } @unlink("{$dump_path}/new.tar"); $tar = new tar(); $tar->addFile('styles/' . $prefs['style']); // Foreach page $query = "select * from `tiki_pages`"; $result = $this->query($query, array()); while ($res = $result->fetchRow()) { $pageName = $res["pageName"] . '.html'; $dat = $parserlib->parse_data($res["data"]); // Now change index.php?page=foo to foo.html // and index.php to HomePage.html $dat = preg_replace("/tiki-index.php\\?page=([^\\'\"\$]+)/", "\$1.html", $dat); $dat = preg_replace("/tiki-editpage.php\\?page=([^\\'\"\$]+)/", "", $dat); //preg_match_all("/tiki-index.php\?page=([^ ]+)/",$dat,$cosas); //print_r($cosas); $data = "<html><head><title>" . $res["pageName"] . "</title><link rel='StyleSheet' href='styles/" . $prefs['style'] . "' type='text/css'></head><body><a class='wiki' href='" . $prefs['wikiHomePage'] . ".html'>home</a><br /><h1>" . $res["pageName"] . "</h1><div class='wikitext'>" . $dat . '</div></body></html>'; $tar->addData($pageName, $data, $res["lastModif"]); } $tar->toTar("{$dump_path}/new.tar", FALSE); unset($tar); $logslib = TikiLib::lib('logs'); $logslib->add_log('dump', 'dump created'); }
/** * user skin export * @return Object */ public function procShopToolUserSkinExport(){ if(!$this->module_srl) return new Object('-1','msg_invalid_request'); $oShopModel = $this->model; $skin_path = FileHandler::getRealPath($oShopModel->getShopPath($this->module_srl)); $tar_list = FileHandler::readDir($skin_path,'/(\.css|\.html|\.htm|\.js)$/'); $img_list = FileHandler::readDir($skin_path."img",'/(\.png|\.jpeg|\.jpg|\.gif|\.swf)$/'); for($i=0,$c=count($img_list);$i<$c;$i++) $tar_list[] = 'img/' . $img_list[$i]; $userimages_list = FileHandler::readDir($skin_path."user_images",'/(\.png|\.jpeg|\.jpg|\.gif|\.swf)$/'); for($i=0,$c=count($userimages_list);$i<$c;$i++) $tar_list[] = 'user_images/' . $userimages_list[$i]; require_once(_XE_PATH_.'libs/tar.class.php'); chdir($skin_path); $tar = new tar(); $replace_path = getNumberingPath($this->module_srl,3); foreach($tar_list as $key => $file) $tar->addFile($file,$replace_path,'__SHOP_SKIN_PATH__'); $stream = $tar->toTarStream(); $filename = 'ShopUserSkin_' . date('YmdHis') . '.tar'; header("Cache-Control: "); header("Pragma: "); header("Content-Type: application/x-compressed"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header('Content-Disposition: attachment; filename="'. $filename .'"'); header("Content-Transfer-Encoding: binary\n"); echo $stream; Context::close(); exit(); }
foreach ($tar->files as $id => $information) { echo " {$information['directory']}/{$information['name']}<br>\n"; } } else { echo " There are no files described in this tar archive.<br>\n"; } echo "<br>\n"; // Check if a file exists in the tar file if ($tar->containsFile("fake.php")) { echo "<b>This TAR Archive does contain a file called fake.php!</b><br>\n"; } else { echo "<b>This TAR Archive does not contain any files called fake.php!</b><br>\n"; } echo "<br>\n"; // Add a file to the archive if ($tar->addFile("example.php")) { echo "Added 'example.php' to archive!<br>\n"; } else { echo "Could not add 'example.php' to archive!<br>\n"; } echo "<br>\n"; // Save changes to a NEW tar file if (!$tar->toTar("test.tgz", TRUE)) { echo "Could not save Gzipped TAR Archive!<br>\n"; } else { echo "New Gzipped TAR File generated successfully!<br>\n"; } // Save changes to currently opened tar file using existing filename and gzip method // already set when loading (main.tar, no gzip in this example) if (!$tar->saveTar()) { echo "Could not save TAR Archive!<br>\n";
/** * @brief faceoff export * **/ function procLayoutAdminUserLayoutExport() { $layout_srl = Context::get('layout_srl'); if (!$layout_srl) { return new Object('-1', 'msg_invalid_request'); } require_once _XE_PATH_ . 'libs/tar.class.php'; // 압축할 파일 목록을 가져온다 $oLayoutModel =& getModel('layout'); $file_list = $oLayoutModel->getUserLayoutFileList($layout_srl); // 압축을 한다. $tar = new tar(); $user_layout_path = FileHandler::getRealPath($oLayoutModel->getUserLayoutPath($layout_srl)); chdir($user_layout_path); $replace_path = getNumberingPath($layout_srl, 3); foreach ($file_list as $key => $file) { $tar->addFile($file, $replace_path, '__LAYOUT_PATH__'); } $stream = $tar->toTarStream(); $filename = 'faceoff_' . date('YmdHis') . '.tar'; header("Cache-Control: "); header("Pragma: "); header("Content-Type: application/x-compressed"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // header("Content-Length: " .strlen($stream)); ?? why?? header('Content-Disposition: attachment; filename="' . $filename . '"'); header("Content-Transfer-Encoding: binary\n"); echo $stream; // Context를 강제로 닫고 종료한다. Context::close(); exit; }
<?php echo "<font face=\"Verdana\" size=\"2\">"; echo "<b>TAR Archive Class</b><br><br>\n\n"; function text2html($html, $repeat = ' ') { $html = htmlentities($html); $html = str_replace("\n", "<br>", $html); $html = str_replace("\t", "{$repeat}", $html); return $html; } // Include TAR Class include "tar.class.php"; // Creating a NEW Tar file $tar = new tar(); $tar->addFile("exmaple.php"); $tar->addFile("example2.php"); $tar->addFile("tar.class.php"); $tar->toTar("new.tar", FALSE); // Normal TAR // $tar->toFile("new.tgz",TRUE); // Gzipped TAR unset($tar); // Appending 2 tar files together, saving in gzipped format (Gzipping requires zlib) $tar = new tar(); $tar->openTAR("my.tar", FALSE); $tar->appendTar("another.tar", FALSE); $tar->toTar("combined.tgz", TRUE); unset($tar); // Removing 2 files from the new.tar file created above $tar = new tar(); $tar->openTar("new.tar", FALSE);
function package($path, $type, $package) { $oldir = getcwd(); chdir($path); include_once $oldir . '/lib/tar.class.php'; $file = 'Packages/' . $type . '-' . $package . '.info.txt'; $info = $this->readconf($file); if (is_file("Dist/" . $type . '-' . $package . '-' . $info['revision'][0] . '.tgz')) { unlink("Dist/" . $type . '-' . $package . '-' . $info['revision'][0] . '.tgz'); } $tar = new tar(); $tar->addFile($file); if (isset($info['files']) and count($info['files'])) { foreach ($info['files'] as $f) { $tar->addFile($f[0]); } } $filename = 'Dist/' . $type . '-' . $package . '-' . $info['revision'][0] . '.tgz'; $tar->toTar($filename, 1); if (!function_exists('md5_file')) { $md5 = md5(implode('', file($filename))); } else { $md5 = md5_file($filename); } chdir($oldir); return $md5; }