function upload($incVersion) { $vs = qg::remoteGet($this->name); if (!is_dir(sysPATH . $this->name)) { return false; } $v = explode('.', $vs['version']); $v = @array((int) $v[0], (int) $v[1], (int) $v[2]); foreach ($v as $i => $vp) { if ($i >= $incVersion) { $v[$i] = 0; } } isset($v[$incVersion - 1]) && ++$v[$incVersion - 1]; $vs['version'] = implode('.', $v); $tmpFile = appPATH . 'cache/tmp/module_export1.zip'; is_file($tmpFile) && unlink($tmpFile); // zzz unlink??? ini_set('max_execution_time', '600'); $zip = new Zip(); $zip->open($tmpFile, Zip::CREATE); $zip->addDir(sysPATH . $this->name, null, '/(\\.svn)|(zzz)/'); $zip->close(); $vs['size'] = filesize($tmpFile); $this->local_version = $vs['version']; @qg::Ftp()->mkdir('/module/' . $this->name . '/'); qg::Ftp()->put('/module/' . $this->name . '/' . $vs['version'] . '.zip', $tmpFile, FTP_BINARY); qg::remoteSet($this->name, $vs); return $vs['version']; }
/** * Compresses the directory with ZIP. * @param string $fileName The file name of the ZIP archive. * @param int $flags [optional] The mode to use to open the archive. * @return mixed The ZIP archive or an error code on failure. */ public function compress($fileName, $flags = \ZipArchive::CREATE) { $zip = new Zip(); if (($res = $zip->open($fileName, $flags)) === true) { $zip->addDir($this->path); $zip->close(); return $zip; } return $res; }
function run($args) { if (empty($args[1])) { echo $this->getHelp(); return; } $path = $args[0]; $version = $args[1]; echo "Preparing {$path} release.\n"; require dirname(__FILE__) . '/GenerateDocsCommand.php'; $docProcessor = new GenerateDocsCommand($this->getName(), $this->getCommandRunner()); $outFiles = $docProcessor->processDocuments($path); // copy extension dir to temp $extPath = Yii::getPathOfAlias('ext') . '/' . $path; $copiedExtRoot = Yii::getPathOfAlias('application.runtime.extension'); echo "Removing {$copiedExtRoot}.\n"; if (file_exists($copiedExtRoot)) { $this->recursiveDelete($copiedExtRoot); } $copiedExtPath = $copiedExtRoot . '/' . $path; if (!file_exists($copiedExtPath)) { mkdir($copiedExtPath, 0777, true); } echo "Copying extension files from {$extPath} to {$copiedExtPath}.\n"; CFileHelper::copyDirectory($extPath, $copiedExtPath, array('exclude' => array('.svn', 'readme_en.txt', 'readme_ru.txt'))); echo "Copying documentation to {$copiedExtPath}.\n"; foreach ($outFiles as $file) { copy($file, $copiedExtPath . '/' . basename($file)); } $pathExp = explode('/', $path); $zipName = end($pathExp) . '_' . $version . '.zip'; $releasePath = Yii::getPathOfAlias('application.releases'); if (!file_exists($releasePath)) { mkdir($releasePath, 0777, true); } $zipPath = "{$releasePath}/{$zipName}"; if (file_exists($zipPath)) { unlink($zipPath); } //touch($zipPath); echo "Creating Zip {$zipPath}.\n"; require dirname(__FILE__) . '/Zip.php'; $zip = new Zip(); if ($zip->open($zipPath, ZipArchive::OVERWRITE | ZipArchive::CREATE) !== TRUE) { die("Failed to open Zip {$zipPath}.\n"); } if (!$zip->addDir($copiedExtRoot)) { die("Failed adding {$copiedExtRoot} to Zip.\n"); } if ($zip->close()) { echo "Done.\n"; } else { die("Failed to write Zip {$zipPath}.\n"); } }
static function download($name, $beta = false) { $vs = self::remoteGet($name, $beta); self::ftp()->get(appPATH . 'cache/tmp/pri/remoteModule.zip', '/module/' . $name . '/' . $vs['version'] . '.zip', FTP_BINARY); $zip = new Zip(); $go = $zip->open(appPATH . 'cache/tmp/pri/remoteModule.zip'); if (!$go) { return; } rrmdir(sysPATH . $name); $zip->extractTo(sysPATH); $zip->close(); return $vs; }
public function export() { $condition['project_id'] = Request::input('project_id'); //todo $projectName = 'catphp'; $fields = array('name', '_id', 'content'); $rs = $this->mongo->find('document', $condition, array('sort' => array('sort' => 1)), $fields); $mk = new Parsedown(); $docs = array(); foreach ($rs as $row) { $doc = array(); $doc['name'] = $row['name']; $doc['content'] = $mk->parse($row['content']); $docs[] = $doc; } $this->assign("docs", $docs); $content = $this->render('views/document.html', false); // $this->staticize('runtime/index.html'); $download_config = CatConfig::getInstance(APP_PATH . '/config/download.conf.php'); $download_zip_name = APP_PATH . '/runtime/' . $projectName . date('YmdHis') . '.zip'; $zip = new Zip($download_zip_name, ZipArchive::OVERWRITE); $zip->addContent($content, 'index.html'); foreach ($download_config->get('default') as $file) { $zip->addFile(APP_PATH . '/runtime/' . $file, $file); } $zip->close(); $this->download($download_zip_name, $projectName . '.zip'); // $this->zip($this->render('views/document.html')); // var_dump($download_config->get('default')); }
/** * Импорт и экспорт */ public function tools_action() { $this->hookSiteSettingsMenu(); template('Admin/templates/tools')->show(); $form = new Form('Admin/forms/import'); if ($result = $form->result()) { if ($file = $result->file) { $zip = new Zip(array('file' => $file->path, 'check' => array('type' => 'config'))); if ($zip->extract(ROOT)) { success(t('<b>Архив успешно распакован!</b> Новый файл конфигурации установлен.')); } $zip->close(); unlink($file->path); } } $form->show(); }
} if (isset($_GET['qgCms_page_files_as_zip'])) { $P = Page($_GET['qgCms_page_files_as_zip']); if (!$P->access() > 1) { exit('no access'); } if (!$P->Files()) { exit('no files'); } $Zip = new Zip(); $tmpfname = appPATH . 'cache/tmp/pri/' . randString() . '.zip'; $Zip->open($tmpfname, Zip::CREATE); foreach ($P->Files() as $File) { $Zip->addFile($File->path, $File->name()); } $Zip->close(); $filename = isset($_GET['filename']) ? $_GET['filename'] : 'files_' . $P . '.zip'; header('Content-Type: application/zip'); header('Content-Disposition: attachment; filename=' . $filename); header('Content-Length: ' . filesize($tmpfname)); readfile($tmpfname); unlink($tmpfname); exit; } }); qg::on('dbFile::access', function ($e) { if ($e['access']) { return; } foreach (D()->query("SELECT page_id FROM page_file WHERE file_id = " . $e['File']) as $vs) { $P = Page($vs['page_id']);
/* add mysql export */ $structExport = ''; @mkdir('/tmp/'); @mkdir('/tmp/qgdbexport1/'); chmod('/tmp/qgdbexport1/', 0777); foreach (D()->Tables() as $T) { $file = realpath('/tmp/qgdbexport1/') . '/' . $T . '.csv'; @unlink($file); D()->query("SELECT * INTO OUTFILE " . D()->quote($file) . " FROM " . $T); $zip->addFile($file, 'mysql/' . $T); $tmp = D()->row("SHOW CREATE TABLE " . $T); $structExport .= $tmp['Create Table'] . ";\n\n"; } $zip->addFromString('mysql.struct.sql', $structExport); $zip->close(); /* send */ header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private", false); header("Content-Type: application/force-download"); header("Content-Disposition: attachment; filename=\"export.zip\";"); header("Content-Transfer-Encoding: binary"); while (ob_get_level()) { ob_end_clean(); } readfile($tmpFile); exit; /**/ }
/** * */ public function index_action($action = 'import') { $this->hookAdminMenu(1); $this->hookAdminMenu(3); switch ($action) { case 'import': $form = new Form('Lang/forms/import'); if ($result = $form->result()) { if ($file = $result->file) { $zip = new Zip(array('file' => $file->path, 'check' => array('type' => 'lang'))); if ($zip->extract(LANG)) { $info = $zip->info(); $langs = $this->getLangs(array($info['lang'])); success(t('<b>Архив успешно распакован!</b> Индекс для языка <b>«%s»</b> установлен.', implode($langs)), '', 'content'); } $zip->close(); unlink($file->path); } } $form->show(); break; case 'export': template('Lang/templates/download')->show(); break; case 'download': $file = ROOT . $this->prepareFilePath(); $archive = TEMP . DS . pathinfo($file, PATHINFO_FILENAME) . '.zip'; $zip = new Zip(array('file' => $archive, 'create' => TRUE)); $zip->add($file); $zip->info(array('type' => 'lang', 'lang' => config('lang.lang'))); $zip->close(); File::download($archive, basename($archive), TRUE); break; } }
/** * Загрузка тем */ public function upload_action() { $this->hookAdminMenu(); $this->hookAdminMenu(2); $form = new Form('Gears/forms/add'); if ($result = $form->result()) { if ($file = $result->file ? $result->file : $result->url) { $zip = new Zip(array('file' => UPLOADS . $file, 'check' => array('type' => 'gears'))); if ($zip->extract(GEARS)) { $info = $zip->info(); success(t('<b>Архив успешно распакован!</b> <p>Он содержал в себе следующие шестерёнки: <ul><li>%s</li></ul>', implode('</li><li>', $info['gears'])), '', 'content'); } $zip->close(); unlink(UPLOADS . $file); } } $form->show(); }