/** * Returns downloadable backup file * * @access public * @return void */ function Backup() { $this->gadget->CheckPermission('Backup'); $tmpDir = sys_get_temp_dir(); $domain = preg_replace("/^(www.)|(:{$_SERVER['SERVER_PORT']})\$|[^a-z0-9\\-\\.]/", '', strtolower($_SERVER['HTTP_HOST'])); $nameArchive = $domain . '-' . date('Y-m-d') . '.tar.gz'; $pathArchive = $tmpDir . DIRECTORY_SEPARATOR . $nameArchive; //Dump database data $dbFileName = 'dbdump.xml'; $dbFilePath = $tmpDir . DIRECTORY_SEPARATOR . $dbFileName; Jaws_DB::getInstance()->Dump($dbFilePath); $files = array(); require_once PEAR_PATH . 'File/Archive.php'; $files[] = File_Archive::read(JAWS_DATA); $files[] = File_Archive::read($dbFilePath, $dbFileName); File_Archive::extract($files, File_Archive::toArchive($pathArchive, File_Archive::toFiles())); Jaws_Utils::Delete($dbFilePath); // browser must download file from server instead of cache header("Expires: 0"); header("Pragma: public"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); // force download dialog header("Content-Type: application/force-download"); // set data type, size and filename header("Content-Disposition: attachment; filename=\"{$nameArchive}\""); header("Content-Transfer-Encoding: binary"); header('Content-Length: ' . @filesize($pathArchive)); @readfile($pathArchive); Jaws_Utils::Delete($pathArchive); }
/** * Creates a .zip file of the theme in themes/ directory * * @access public * @param string $theme Name of the theme * @param string $srcDir Source directory * @param string $destDir Target directory * @param bool $copy_example_to_repository If copy example.png too or not * @return bool Returns true if: * - Theme exists * - Theme exists and could be packed * Returns false if: * - Theme doesn't exist * - Theme doesn't exists and couldn't be packed */ function packTheme($theme, $srcDir, $destDir, $copy_example_to_repository = true) { $themeSrc = $srcDir . '/' . $theme; if (!is_dir($themeSrc)) { return new Jaws_Error(_t('TMS_ERROR_THEME_DOES_NOT_EXISTS', $theme)); } if (!Jaws_Utils::is_writable($destDir)) { return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_DIRECTORY_UNWRITABLE', $destDir), $this->gadget->name); } $themeDest = $destDir . '/' . $theme . '.zip'; //If file exists.. delete it if (file_exists($themeDest)) { @unlink($themeDest); } require_once PEAR_PATH . 'File/Archive.php'; $reader = File_Archive::read($themeSrc, $theme); $innerWriter = File_Archive::toFiles(); $writer = File_Archive::toArchive($themeDest, $innerWriter); $res = File_Archive::extract($reader, $writer); if (PEAR::isError($res)) { return new Jaws_Error(_t('TMS_ERROR_COULD_NOT_PACK_THEME')); } Jaws_Utils::chmod($themeDest); if ($copy_example_to_repository) { //Copy image to repository/images if (file_exists($srcDir . '/example.png')) { @copy($srcDir . '/example.png', JAWS_DATA . "themes/repository/Resources/images/{$theme}.png"); Jaws_Utils::chmod(JAWS_DATA . 'themes/repository/Resources/images/' . $theme . '.png'); } } return $themeDest; }
function exportUploadedFiles($gid) { require_once "File/Archive.php"; File_Archive::setOption('zipCompressionLevel', 0); $baseDir = CUSTOMER_IMAGE_DIR . $gid; $files = list_files_dir($baseDir); File_Archive::extract($files, File_Archive::toArchive("campaign_" . $gid . "_uploadedfiles_" . date('dFY') . ".zip", File_Archive::toOutput())); }
/** * Export language * * @access public * @return void */ function Export() { $lang = jaws()->request->fetch('lang', 'get'); require_once PEAR_PATH . 'File/Archive.php'; $tmpDir = sys_get_temp_dir(); $tmpFileName = "{$lang}.tar"; $tmpArchiveName = $tmpDir . DIRECTORY_SEPARATOR . $tmpFileName; $writerObj = File_Archive::toFiles(); $src = File_Archive::read(JAWS_DATA . "languages/{$lang}", $lang); $dst = File_Archive::toArchive($tmpArchiveName, $writerObj); $res = File_Archive::extract($src, $dst); if (!PEAR::isError($res)) { return Jaws_Utils::Download($tmpArchiveName, $tmpFileName); } Jaws_Header::Referrer(); }
/** * ダウンロードメイン表示クラス * * @access public */ function execute() { $header = <<<EOD <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <title>NetCommons</title> </head> <body> EOD; $footer = <<<EOD </body> </html> EOD; require_once "File/Archive.php"; $dest = File_Archive::toArchive("document.zip", File_Archive::toOutput()); $dest->newFile("document.html"); $download_url = "?action=" . $this->download_action . "&upload_id="; $count = substr_count($this->content, $download_url); if (!$count) { $dest->writeData($header . $this->content . $footer); $dest->close(); exit; } $upload_id = array(); $files = array(); $trans = array(); $parts = explode($download_url, $this->content); for ($i = 1; $i <= $count; $i++) { $id = substr($parts[$i], 0, strpos($parts[$i], '"')); if (!isset($upload_id[$id])) { $upload_id[$id] = true; list($pathname, $filename, $physical_file_name, $space_type) = $this->uploadsView->downloadCheck($id, null, 0, "common_download_main"); if ($pathname != null) { $files[] = $pathname . $physical_file_name; $trans[BASE_URL . '/' . $download_url . $id] = "./" . $physical_file_name; $trans[$download_url . $id] = $physical_file_name; } } } clearstatcache(); $dest->writeData($header . strtr($this->content, $trans) . $footer); File_Archive::extract($files, $dest); }
/** * Create a writer that can be used to append files to an archive inside a source * If the archive can't be found in the source, it will be created * If source is set to null, File_Archive::toFiles will be assumed * If type is set to null, the type of the archive will be determined looking at * the extension in the URL * stat is the array of stat (returned by stat() PHP function of Reader getStat()) * to use if the archive must be created * * This function allows to create or append data to nested archives. Only one * archive will be created and if your creation requires creating several nested * archives, a PEAR error will be returned * * After this call, $source will be closed and should not be used until the * returned writer is closed. * * @param File_Archive_Reader $source A reader where some files will be appended * @param string $URL URL to reach the archive in the source. * if $URL is null, a writer to append files to the $source reader will * be returned * @param bool $unique If true, the duplicate files will be deleted on close * Default is false (and setting it to true may have some performance * consequences) * @param string $type Extension of the archive (or null to use the one in the URL) * @param array $stat Used only if archive is created, array of stat as returned * by PHP stat function or Reader getStat function: stats of the archive) * Time (index 9) will be overwritten to current time * @return File_Archive_Writer a writer that you can use to append files to the reader */ function appenderFromSource(&$toConvert, $URL = null, $unique = null, $type = null, $stat = array()) { $source =& File_Archive::_convertToReader($toConvert); if (PEAR::isError($source)) { return $source; } if ($unique == null) { $unique = File_Archive::getOption("appendRemoveDuplicates"); } //Do not report the fact that the archive does not exist as an error PEAR::pushErrorHandling(PEAR_ERROR_RETURN); if ($URL === null) { $result =& $source; } else { if ($type === null) { $result = File_Archive::_readSource($source, $URL . '/', $reachable, $baseDir); } else { $result = File_Archive::readArchive($type, File_Archive::_readSource($source, $URL, $reachable, $baseDir)); } } PEAR::popErrorHandling(); if (!PEAR::isError($result)) { if ($unique) { require_once dirname(__FILE__) . "/Archive/Writer/UniqueAppender.php"; return new File_Archive_Writer_UniqueAppender($result); } else { return $result->makeAppendWriter(); } } //The source can't be found and has to be created $stat[9] = $stat['mtime'] = time(); if (empty($baseDir)) { if ($source !== null) { $writer =& $source->makeWriter(); } else { $writer =& File_Archive::toFiles(); } if (PEAR::isError($writer)) { return $writer; } PEAR::pushErrorHandling(PEAR_ERROR_RETURN); $result = File_Archive::toArchive($reachable, $writer, $type); PEAR::popErrorHandling(); if (PEAR::isError($result)) { $result = File_Archive::toFiles($reachable); } } else { $reachedSource = File_Archive::readSource($source, $reachable); if (PEAR::isError($reachedSource)) { return $reachedSource; } $writer = $reachedSource->makeWriter(); if (PEAR::isError($writer)) { return $writer; } PEAR::pushErrorHandling(PEAR_ERROR_RETURN); $result = File_Archive::toArchive($baseDir, $writer, $type); PEAR::popErrorHandling(); if (PEAR::isError($result)) { require_once dirname(__FILE__) . "/Archive/Writer/AddBaseName.php"; $result = new File_Archive_Writer_AddBaseName($baseDir, $writer); if (PEAR::isError($result)) { return $result; } } } return $result; }
function zip_it($source, $destination) { $source = realpath($source); if (is_readable($source) === true) { if (extension_loaded('zip') === true) { $zip = new ZipArchive(); if ($zip->open($destination, ZIPARCHIVE::CREATE) === true) { $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST); // Iterate through files & directories and add to archive object foreach ($files as $file) { if (is_dir($file) === true) { $zip->addEmptyDir(str_replace($source . '/', '', $file . '/')); } else { if (is_file($file) === true) { $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file)); } } } } else { echo "Couldn't create zip file<br />"; } return $zip->close(); } else { $original_dir = getcwd(); chdir($source); File_Archive::extract(File_Archive::read('.'), File_Archive::toArchive($destination, File_Archive::toFiles(), 'zip')); chdir($original_dir); // TODO: add filesize check? if (is_readable($destination)) { return true; } } } else { echo "Source content does not exist or is not readable<br />"; } return false; }
<?php /** * FIXME ... just fixme, like 99% of it. Count this as a draft or something. * * * * @package test * * Trying out File_Archive */ require_once '../../autoload.php'; try { Module::require('File_Archive'); } catch (Exception $e) { die('Script requires PEAR File_Archive to work.'); } // Set cache dir for Cache Lite $options = array('cacheDir' => 'tmp'); if (Module::isLoaded('Cache_Lite')) { File_Archive::setOption('cache', new Cache_Lite($options)); } File_Archive::setOption('zipCompressionLevel', 0); // $files is an array of path to the files that must be added to the archive File_Archive::extract($files, File_Archive::toArchive('myFiles.zip', File_Archive::toOutput()));
/** * Execute action when called for explicitly by the user * * This function also contains the actions available in the interface provided, including file * uploading, compressed file extraction and the creation of folders. * @return void */ function run() { global $Templates, $USER, $Controller, $ID, $CONFIG; /** * User input types */ $_REQUEST->setType('action', 'string'); $_REQUEST->setType('popup', 'string'); $_REQUEST->setType('filter', 'string'); if (!$this->may($USER, READ)) { errorPage(401); } else { if (!in_array($CMPRExtension = $CONFIG->files->compression_format, array('tar', 'gz', 'tgz', 'tbz', 'zip', 'ar', 'deb'))) { $CONFIG->files->compression_format = $CMPRExtension = 'zip'; } $render = true; switch ($_REQUEST['action']) { // All users case 'download': global $PREVENT_CSIZE_HEADER; $PREVENT_CSIZE_HEADER = true; while (ob_get_level()) { echo ob_get_clean(); } require_once "File/Archive.php"; File_Archive::extract($this->path, File_Archive::toArchive($this->filename . '.' . $CMPRExtension, File_Archive::toOutput())); die; default: $this->setContent("main", $this->genHTML()); break; } if ($render) { $t = 'admin'; if ($_REQUEST['popup']) { $t = 'popup'; } $Templates->{$t}->render(); } } }
function _testRemove($extension) { $writer = File_Archive::toArchive("test.{$extension}", File_Archive::toVariable($x)); $writer->newFile('foo.txt'); $writer->writeData('ABCDEF'); $writer->newFile('bla_to_remove.txt'); $writer->writeData('GHIJKL'); $writer->newFile('bar.txt'); $writer->writeData('MNOP'); $writer->close(); File_Archive::removeFromSource(File_Archive::predEreg('_to_remove'), $source = File_Archive::readSource(File_Archive::readMemory($x, "test.{$extension}"), "test.{$extension}/")); $this->assertEquals("foo.txt\nbar.txt", implode("\n", $source->getFileList())); }
/** * ルームバックアップ処理 * @param array page * @return boolean true or false * @access private */ function _roomBackUp(&$page) { // // uploadsテーブルInsert // $file_path = "backup/"; $extension = BACKUP_COMPRESS_EXT; $download_action_name = BACKUP_DOWNLOAD_ACTION_NAME; $file_name = $page['page_name'] . "." . BACKUP_COMPRESS_EXT; $mimetype = $this->uploadsView->mimeinfo("type", $file_name); $garbage_flag = _ON; $params = array('room_id' => 0, 'module_id' => $this->module_id, 'unique_id' => 0, 'file_name' => $file_name, 'physical_file_name' => "", 'file_path' => $file_path, 'action_name' => $download_action_name, 'file_size' => 0, 'mimetype' => $mimetype, 'extension' => $extension, 'garbage_flag' => $garbage_flag); $upload_id = $this->uploadsAction->insUploads($params); if ($upload_id === false) { return false; } $params = array('upload_id' => $upload_id, 'site_id' => $this->session->getParameter("_site_id"), 'url' => '', 'parent_id' => $page['parent_id'], 'thread_num' => $page['thread_num'], 'space_type' => $page['space_type'], 'private_flag' => $page['private_flag'], 'room_id' => $page['page_id']); $result = $this->db->insertExecute("backup_uploads", $params, true); if ($result === false) { $this->_delUploads(); return false; } if ($upload_id > 0) { $this->_upload_id = $upload_id; // バックアップ処理中をセッションに保持 $this->session->setParameter(array("backup", "backingup", $this->_upload_id), _ON); $temporary_file_path = FILEUPLOADS_DIR . "backup/" . BACKUP_TEMPORARY_DIR_NAME . "/" . BACKUP_BACKUP_DIR_NAME . "/" . $page['page_id'] . "/"; if (file_exists($temporary_file_path)) { // 現在、同じバックアップファイル作成中 // エラーとする $this->_delUploads(); $this->errorList->add("backup", BACKUP_BACKINGUP); return false; } $this->backupRestore->mkdirTemporary(BACKUP_BACKUP_DIR_NAME); if (mkdir($temporary_file_path, 0755)) { // // BackUp XML 作成 // $write_xml_data = "<?xml version=\"1.0\" encoding=\"" . _CHARSET . "\"?>\n<rooms>\n"; // // Version情報書き込み // $options = array(XML_SERIALIZER_OPTION_ROOT_NAME => "version", XML_SERIALIZER_OPTION_INDENT => "\t", XML_SERIALIZER_OPTION_XML_DECL_ENABLED => false, XML_SERIALIZER_OPTION_ENTITIES => XML_UTIL_ENTITIES_NONE); $serializer = new XML_Serializer($options); $data_arr = array(); $data_arr['_version'] = _NC_VERSION; $modules = $this->modulesView->getModules(array("system_flag" => _OFF)); if ($modules === false) { $this->_delUploads(); return false; } if (isset($modules[0])) { foreach ($modules as $module) { $pathList = explode("_", $module['action_name']); $dirname = $pathList[0]; $data_arr[$dirname] = $module['version']; $data_arr["_" . $dirname] = "<![CDATA[" . $module['module_name'] . "]]>"; $data_arr["__" . $module['module_id']] = $dirname; } } $serializer->serialize($data_arr); $xml_data = $serializer->getSerializedData(); if ($xml_data != "") { $xml_data .= "\n"; } $write_xml_data .= $xml_data; //fwrite ($this->xml_handle, $xml_data); // // ルーム情報書き込み // $options = array(XML_SERIALIZER_OPTION_ROOT_NAME => "_room_inf", XML_SERIALIZER_OPTION_INDENT => "\t", XML_SERIALIZER_OPTION_XML_DECL_ENABLED => false, XML_SERIALIZER_OPTION_DEFAULT_TAG => "row", XML_SERIALIZER_OPTION_ENTITIES => XML_UTIL_ENTITIES_NONE); $serializer = new XML_Serializer($options); $data_arr = $this->_serializeXML("pages", array("page_id" => $page['page_id']), null, ""); $serializer->serialize($data_arr); $xml_data = $serializer->getSerializedData(); if ($xml_data != "") { $xml_data .= "\n"; } $write_xml_data .= $xml_data; //fwrite ($this->xml_handle, $xml_data); // // アップロードファイルコピー処理 // if (!$this->_uploadCopy($temporary_file_path, $page)) { $this->_delUploads(); return false; } $write_xml_data .= $this->_createDumpXML($page['page_id']); //if(!$this->_createDumpXML($page['page_id'])) return false; // 子グループがあれば、その子グループもバックアップ対象とする $where_params = array("parent_id" => $page['page_id'], "page_id = room_id" => null); $child_pages = $this->pagesView->getPages($where_params); if ($child_pages === false) { return false; } if (count($child_pages) > 0) { foreach ($child_pages as $child_page) { if (!$this->_uploadCopy($temporary_file_path, $child_page)) { $this->_delUploads(); return false; } $write_xml_data .= $this->_createDumpXML($child_page['page_id'], true); } } // // 書き込み // $write_xml_data .= "</rooms>"; $xml_handle = fopen($temporary_file_path . BACKUP_ROOM_XML_FILE_NAME, "w"); if (!$xml_handle) { $this->_delUploads(); $this->errorList->add("backup", BACKUP_MKDIR_ERROR); return false; } $result = fwrite($xml_handle, $write_xml_data); fclose($xml_handle); if ($result === false) { $this->errorList->add("backup", BACKUP_MKDIR_ERROR); return false; } // // 暗号化したペアキーの有効期限書き込み // $ini_handle = fopen($temporary_file_path . BACKUP_ROOM_XML_INI_NAME, "w"); if (!$ini_handle) { $this->errorList->add("backup", BACKUP_MKDIR_ERROR); $this->_delUploads(); return false; } // ハッシュ化データを秘密鍵で暗号化 $encryption = $this->encryption->getEncryptionKeys(); $hash_text = sha1($write_xml_data); $encrypt_text = $this->encryption->encrypt($hash_text, $encryption['private_key']); $xml_data = "<?xml version=\"1.0\" encoding=\"" . _CHARSET . "\"?>\n" . "<_expiration>\n" . "\t<encrypt_text>" . $encrypt_text . "</encrypt_text>\n" . "\t<host_field><![CDATA[" . BASE_URL . INDEX_FILE_NAME . "]]></host_field>\n" . "\t<expiration_time>" . $encryption['expiration_time'] . "</expiration_time>\n" . "</_expiration>\n"; fwrite($ini_handle, $xml_data); fclose($ini_handle); // // 圧縮 // //$physical_file = FILEUPLOADS_DIR."backup/".$upload_id.".".$extension; if (!is_dir(FILEUPLOADS_DIR . "backup/")) { mkdir(FILEUPLOADS_DIR . "backup/", 0755); } $target_file = FILEUPLOADS_DIR . "backup/" . $upload_id . "." . $extension; //$target_file = mb_convert_encoding($file_obj["file_name"], $this->encode, "auto").".".$file_obj["extension"]; if (file_exists($temporary_file_path)) { File_Archive::extract(File_Archive::read($temporary_file_path), File_Archive::toArchive($target_file, File_Archive::toFiles())); // テンポラリーファイル削除 $this->fileAction->delDir($temporary_file_path); // file_size 更新 $params = array('file_size' => $this->fileView->getSize($target_file), 'garbage_flag' => _OFF); $where_params = array("upload_id" => $upload_id); $result = $this->uploadsAction->updUploads($params, $where_params); if ($result === false) { $this->_delUploads(); return false; } } // // バックアップ暗号データ履歴登録 // $params = array("encrypt_data" => $encrypt_text, "room_id" => $this->backup_page_id); $result = $this->db->insertExecute("backup_encrypt_history", $params, true); if ($result === false) { return $result; } } else { $this->errorList->add("backup", BACKUP_MKDIR_ERROR); $this->_delUploads(); return false; } //$physical_file_name = "${upload_id}.${extension}"; //$this->fileUpload->move($i, FILEUPLOADS_DIR.$file_path.$physical_file_name); } return true; }
/** * cmdGetDoc() * * @param string $sPath * @return void */ function cmdGetDoc($sPath) { if (isset($_SERVER['PWD'])) { chdir($_SERVER['PWD']); } File_Archive::extract(File_Archive::read(BLOCKEN_DOC_DIR), File_Archive::toArchive('BlockenDoc.zip', File_Archive::toFiles($sPath))); }
/** * 圧縮処理 * * @return boolean * @access public */ function compressFile() { $cabinet = $this->_request->getParameter("cabinet"); $file = $this->_request->getParameter("file"); $module_id = $this->_request->getParameter("module_id"); $configView =& $this->_container->getComponent("configView"); $config = $configView->getConfigByConfname($module_id, "compress_ext"); if ($config === false) { return false; } if (defined($config['conf_value'])) { $extension = constant($config['conf_value']); } else { $extension = $config['conf_value']; } $file_path = "cabinet/"; if (!file_exists(FILEUPLOADS_DIR . "/" . $file_path)) { mkdir(FILEUPLOADS_DIR . "/" . $file_path, octdec(_UPLOAD_FOLDER_MODE)); } $file_name = $this->_cabinetView->renameFile($file["org_file_name"], $extension); $params = array("room_id" => $this->_request->getParameter("room_id"), "module_id" => $module_id, "unique_id" => $file["cabinet_id"], "file_name" => $file_name . "." . $extension, "physical_file_name" => "", "file_path" => $file_path, "action_name" => "common_download_main", "file_size" => 0, "mimetype" => $this->_uploadsView->mimeinfo("type", $file_name . "." . $extension), "extension" => $extension, "garbage_flag" => _ON); $upload_id = $this->_uploadsAction->insUploads($params); if ($upload_id === false) { return false; } $archive_file_name = $upload_id; $this->archive_full_path = FILEUPLOADS_DIR . "/" . $file_path . "/" . $archive_file_name . "." . $extension; if (stristr($_SERVER['HTTP_USER_AGENT'], "Mac")) { // Macの場合 $this->encode = "UTF-8"; } else { if (stristr($_SERVER['HTTP_USER_AGENT'], "Windows")) { // Windowsの場合 $this->encode = "SJIS"; } else { $this->encode = _CHARSET; } } if ($file["file_type"] == CABINET_FILETYPE_FOLDER) { $result = $this->_compressFile($file["file_id"], mb_convert_encoding($file["org_file_name"], $this->encode, "auto") . "/"); if ($result === false) { return false; } if (count($this->_source) > 0) { File_Archive::extract($this->_source, File_Archive::toArchive($this->archive_full_path, File_Archive::toFiles())); } } else { $sql = "SELECT F.file_id, F.parent_id, F.file_type, F.file_name, F.extension, U.file_path, U.physical_file_name " . "FROM {cabinet_file} F " . "LEFT JOIN {uploads} U ON (F.upload_id=U.upload_id) "; $sql .= "WHERE F.cabinet_id = ? "; $sql .= "AND F.file_id = ? "; $params = array("cabinet_id" => $file["cabinet_id"], "file_id" => $file["file_id"]); $result = $this->_db->execute($sql, $params); if ($result === false) { $this->_db->addError(); return false; } $physical_file = FILEUPLOADS_DIR . $result[0]["file_path"] . $result[0]["physical_file_name"]; $target_file = mb_convert_encoding($file["org_file_name"], $this->encode, "auto") . "." . $file["extension"]; if (file_exists($physical_file)) { File_Archive::extract(File_Archive::read($physical_file, $target_file), File_Archive::toArchive($this->archive_full_path, File_Archive::toFiles())); } } if (file_exists($this->archive_full_path)) { $file_size = filesize($this->archive_full_path); } else { return false; } if ($cabinet["compress_download"] == _OFF) { $result = $this->_uploadsAction->updUploads(array("file_size" => $file_size, "garbage_flag" => _OFF), array("upload_id" => $upload_id)); if ($result === false) { return false; } $params = array("cabinet_id" => $file["cabinet_id"], "upload_id" => $upload_id, "parent_id" => $file["parent_id"], "file_name" => $file_name, "extension" => $extension, "depth" => $file["depth"], "size" => $file_size, "download_num" => 0, "file_type" => CABINET_FILETYPE_FILE, "display_sequence" => 0); $file_id = $this->_db->insertExecute("cabinet_file", $params, true, "file_id"); $params = array("file_id" => $file_id, "comment" => ""); $result = $this->_db->insertExecute("cabinet_comment", $params, true); if ($result === false) { return false; } } else { $result = $this->_uploadsAction->updUploads(array("file_size" => $file_size), array("upload_id" => $upload_id)); if ($result === false) { return false; } $pathname = FILEUPLOADS_DIR . $file_path; $filename = $file_name . "." . $extension; $physical_file_name = $archive_file_name . "." . $extension; clearstatcache(); $this->_uploadsView->headerOutput($pathname, $filename, $physical_file_name); $result = $this->_uploadsAction->delUploadsById($upload_id); if ($file['file_type'] == CABINET_FILETYPE_FILE) { $this->setDownload($file['file_id']); } exit; } return true; }
/** * Export Logs * * @access public * @return void */ function ExportLogs() { $this->gadget->CheckPermission('ExportLogs'); $filters = jaws()->request->fetch(array('from_date', 'to_date', 'gname', 'user', 'priority', 'status'), 'get'); $filters['gadget'] = $filters['gname']; unset($filters['gname']); $model = $this->gadget->model->load('Logs'); $logs = $model->GetLogs($filters); if (Jaws_Error::IsError($logs) || count($logs) < 1) { return; } $tmpDir = sys_get_temp_dir(); $tmpCSVFileName = uniqid(rand(), true) . '.csv'; $fp = fopen($tmpDir . DIRECTORY_SEPARATOR . $tmpCSVFileName, 'w'); $date = Jaws_Date::getInstance(); foreach ($logs as $log) { $exportData = ''; $exportData .= $log['id'] . ','; $exportData .= $log['username'] . ','; $exportData .= $log['gadget'] . ','; $exportData .= $log['action'] . ','; $exportData .= $log['priority'] . ','; $exportData .= $log['apptype'] . ','; $exportData .= $log['backend'] . ','; $exportData .= long2ip($log['ip']) . ','; $exportData .= $log['status'] . ','; $exportData .= $date->Format($log['insert_time'], 'Y-m-d H:i:s'); $exportData .= PHP_EOL; fwrite($fp, $exportData); } fclose($fp); require_once PEAR_PATH . 'File/Archive.php'; $tmpFileName = uniqid(rand(), true) . '.tar.gz'; $tmpArchiveName = $tmpDir . DIRECTORY_SEPARATOR . $tmpFileName; $writerObj = File_Archive::toFiles(); $src = File_Archive::read($tmpDir . DIRECTORY_SEPARATOR . $tmpCSVFileName); $dst = File_Archive::toArchive($tmpArchiveName, $writerObj); $res = File_Archive::extract($src, $dst); if (!PEAR::isError($res)) { return Jaws_Utils::Download($tmpArchiveName, $tmpFileName); } Jaws_Header::Referrer(); }
} if ( $file_cnt >= OUTPUT_FILE_LIMIT ){ WriteFinFile($fin_file,"WAR:file size limit over\n"); break; } $file_size += $row_len; $zip_file=sprintf("%s/%s/%s_%03d.zip",DIR_RESULT,$hive_uid,$hive_id,$file_cnt); $zip_file_in=sprintf("%s_%03d.csv",$hive_id,$file_cnt); //出力ファイルのオープン if ( $sv_zip_file != $zip_file ){ if ( $sv_zip_file != "" ){ WriteFinFile($fin_file,"OUT:$sv_zip_file\n"); $ofp->close(); } $ofp = File_Archive::toArchive($zip_file, File_Archive::toFiles(),"zip"); $ofp->newFile($zip_file_in); } $sv_zip_file=$zip_file; //出力 $row=mb_convert_encoding($row,"SJIS-WIN","UTF-8"); $ofp->writeData($row); } pclose($ifp); if ( $sv_zip_file != "" ){ WriteFinFile($fin_file,"OUT:$sv_zip_file\n"); $ofp->close(); }
/** * handle export */ private function handleExportGet() { $request = Request::getInstance(); if (!$request->exists('id')) { throw new Exception('Thema ontbreekt.'); } $id = intval($request->getValue('id')); $key = array('id' => $id); $themedetail = $this->getDetail($key); $theme = $this->director->themeManager->getThemeFromId($key); $tempPath = $this->director->getTempPath() . "/theme" . session_id(); $themePath = $themedetail['themePath']; $configPath = $theme->getConfigFile(); mkdir($tempPath); Utils::copyRecursive($themePath, $tempPath); copy($configPath, $tempPath . "/" . basename($configPath)); copy($themePath . "/script/ThemeInstaller.php", $tempPath . "/ThemeInstaller.php"); $filename = sprintf("dif_%s_%s.tar.gz", strtolower($themedetail['classname']), $theme->getVersion()); File_Archive::extract($tempPath, File_Archive::toArchive($filename, File_Archive::toOutput())); Utils::removeRecursive($tempPath); exit; /* $view = ViewManager::getInstance(); $url = new Url(true); $url_back = clone $url; $url_back->setParameter($view->getUrlId(), ViewManager::ADMIN_OVERVIEW); $template->setVariable('href_back', $url_back->getUrl(true), false); $theme->addBreadcrumb(array('name' => $themedetail['name'], 'path' => $url_back->getUrl(true))); $theme->addBreadcrumb(array('name' => $view->getName(), 'path' => $url->getUrl(true))); $this->template[$this->director->theme->getExport()->main_tag] = $template; */ }
/** * Zip the temp folder */ function createZipFile($bEchoStatus = FALSE) { if (empty($this->aPaths)) { return PEAR::raiseError(_kt("No folders or documents found to compress")); } $config = KTConfig::getSingleton(); $useBinary = $config->get('export/useBinary', false); // Set environment language to output character encoding $loc = $this->sOutputEncoding; putenv("LANG={$loc}"); putenv("LANGUAGE={$loc}"); $loc = setlocale(LC_ALL, $loc); if ($useBinary) { $sManifest = sprintf("%s/%s", $this->sTmpPath, "MANIFEST"); file_put_contents($sManifest, join("\n", $this->aPaths)); } $sZipFile = sprintf("%s/%s." . $this->extension, $this->sTmpPath, $this->sZipFileName); $sZipFile = str_replace('<', '', str_replace('</', '', str_replace('>', '', $sZipFile))); if ($useBinary) { $sZipCommand = KTUtil::findCommand("export/zip", "zip"); $aCmd = array($sZipCommand, "-r", $sZipFile, ".", "-i@MANIFEST"); $sOldPath = getcwd(); chdir($this->sTmpPath); // Note that the popen means that pexec will return a file descriptor $aOptions = array('popen' => 'r'); $fh = KTUtil::pexec($aCmd, $aOptions); if ($bEchoStatus) { $last_beat = time(); while (!feof($fh)) { if ($i % 1000 == 0) { $this_beat = time(); if ($last_beat + 1 < $this_beat) { $last_beat = $this_beat; print " "; } } $contents = fread($fh, 4096); if ($contents) { print nl2br($this->_convertEncoding($contents, false)); } $i++; } } pclose($fh); } else { // Create the zip archive using the PEAR File_Archive File_Archive::extract(File_Archive::read($this->sTmpPath . '/Root Folder'), File_Archive::toArchive($this->sZipFileName . '.' . $this->extension, File_Archive::toFiles($this->sTmpPath), $this->extension)); } // Save the zip file and path into session $_SESSION['zipcompression'] = KTUtil::arrayGet($_SESSION, 'zipcompression', array()); $sExportCode = $this->exportCode; $_SESSION['zipcompression'][$sExportCode] = array('file' => $sZipFile, 'dir' => $this->sTmpPath); $_SESSION['zipcompression']['exportcode'] = $sExportCode; $this->sZipFile = $sZipFile; return $sExportCode; }