コード例 #1
0
ファイル: Backup.php プロジェクト: Dulciane/jaws
 /**
  * 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);
 }
コード例 #2
0
ファイル: Themes.php プロジェクト: juniortux/jaws
 /**
  * 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;
 }
コード例 #3
0
ファイル: Upload.php プロジェクト: jonatanolofsson/solidba.se
 function saveChanges()
 {
     global $CONFIG;
     $_REQUEST->setType('uncompress', 'any');
     if (isset($_FILES['uFiles']) && $this->may($USER, EDIT)) {
         $u = false;
         $ue = false;
         $extensions = $CONFIG->Files->filter;
         foreach ($_FILES['uFiles']['error'] as $i => $e) {
             $parts = explode('.', $_FILES['uFiles']['name'][$i]);
             $extension = array_pop($parts);
             if ($e == UPLOAD_ERR_NO_FILE) {
                 continue;
             }
             $newPath = $this->that->path . '/' . $_FILES['uFiles']['name'][$i];
             if ($e == UPLOAD_ERR_OK) {
                 if ($_REQUEST['uncompress'] && in_array(strtolower(strrchr($_FILES['uFiles']['name'][$i], '.')), array('.tar', '.gz', '.tgz', '.bz2', '.tbz', '.zip', '.ar', '.deb'))) {
                     $tmpfile = $_FILES['uFiles']['tmp_name'][$i] . $_FILES['uFiles']['name'][$i];
                     rename($_FILES['uFiles']['tmp_name'][$i], $tmpfile);
                     $u = true;
                     require_once "File/Archive.php";
                     error_reporting(E_ALL);
                     $curdir = getcwd();
                     chdir($this->path);
                     //FIXME: FIXME!
                     if (@File_Archive::extract(File_Archive::filter(File_Archive::predExtension($extensions), File_Archive::read($tmpfile . '/*')), File_Archive::toFiles()) == null) {
                         $ue = true;
                     } else {
                         Flash::queue(__('Extraction failed'));
                     }
                     chdir($curdir);
                 } elseif (!in_array(strtolower($extension), $extensions)) {
                     Flash::queue(__('Invalid format:') . ' ' . $_FILES['uFiles']['name'][$i], 'warning');
                     continue;
                 } else {
                     $u = (bool) @move_uploaded_file($_FILES['uFiles']['tmp_name'][$i], $newPath);
                 }
             }
             if (!$u) {
                 Flash::queue(__('Upload of file') . ' "' . $_FILES['uFiles']['name'][$i] . '" ' . __('failed') . ' (' . ($e ? $e : __('Check permissions')) . ')', 'warning');
             }
         }
         if ($u) {
             $this->loadStructure(true);
             Flash::queue(__('Your file(s) were uploaded'));
             return true;
         }
         if ($ue) {
             $this->loadStructure(true);
             Flash::queue(__('Your file(s) were uploaded and extracted'));
             return true;
         }
         return false;
     }
 }
コード例 #4
0
ファイル: Export.php プロジェクト: Dulciane/jaws
 /**
  * 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();
 }
コード例 #5
0
ファイル: Logs.php プロジェクト: Dulciane/jaws
 /**
  * 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();
 }
コード例 #6
0
ファイル: Archive.php プロジェクト: kosmosby/medicine-prof
 /**
  * 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;
 }
コード例 #7
0
ファイル: index.php プロジェクト: neofreko/anthologize
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;
}
コード例 #8
0
ファイル: hive_request.php プロジェクト: recruitcojp/WebHive
	}
	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();
}
コード例 #9
0
ファイル: test.php プロジェクト: andychang88/jianzhanseo.com
 function _testDirectories()
 {
     $this->assertTrue(!PEAR::isError(File_Archive::extract(File_Archive::read('../Archive'), File_Archive::toArchive('up.tbz', File_Archive::toFiles()))));
 }
コード例 #10
0
 /**
  * ルームバックアップ処理
  * @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;
 }
コード例 #11
0
/**
 * 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)));
}
コード例 #12
0
 /**
  * 圧縮処理
  *
  * @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;
 }
コード例 #13
0
 /**
  * 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 "&nbsp;";
                     }
                 }
                 $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;
 }