コード例 #1
0
ファイル: WysiwygZip.php プロジェクト: NetCommons3/Wysiwyg
 /**
  * createWysiwygZip
  *
  * @param string $data wysiswyg editor content
  * @param string $fileName wysiwygのテキストをまとめるファイル名
  * @return string 作成したZIPファイルへのパス
  * @throws InternalErrorException
  */
 public function createWysiwygZip($data, $fileName = 'document.txt')
 {
     $zip = new ZipDownloader();
     // UPLOADされているファイル情報を取り出す
     $tmpStr = $data;
     $tmpStr = str_replace('<img', "\n<img", $tmpStr);
     $tmpStr = str_replace('<a', "\n<a", $tmpStr);
     $matchCount = preg_match_all(self::WYSIWYG_FILE_KEY_PATTERN, $tmpStr, $matches);
     if ($matchCount > 0) {
         // ファイルのUPLOAD_IDを取り出す
         foreach ($matches[3] as $uploadId) {
             // ファイル情報を取得してくる
             $uploadFile = $this->UploadFile->findById($uploadId);
             if ($uploadFile) {
                 $uploadFile = $uploadFile['UploadFile'];
                 // ルームチェック
                 if ($uploadFile['room_id']) {
                     $roomId = Current::read('Room.id');
                     if ($uploadFile['room_id'] != $roomId) {
                         CakeLog::error('Can not find wysiwyg file ' . $uploadId);
                         throw new InternalErrorException();
                     }
                 }
                 if ($uploadFile['block_key']) {
                     // block_keyによるガード
                     $Block = ClassRegistry::init('Blocks.Block');
                     $uploadFileBlock = $Block->findByKeyAndLanguageId($uploadFile['block_key'], Current::read('Language.id'));
                     if ($Block->isVisible($uploadFileBlock) === false) {
                         CakeLog::error('Can not find wysiwyg file ' . $uploadId);
                         throw new InternalErrorException();
                     }
                 }
                 // そのファイルをZIPに含める
                 $path = WWW_ROOT . trim($uploadFile['path'], '/') . '/' . $uploadId . '/' . $uploadFile['real_file_name'];
                 $zip->addFile($path, $uploadId . '.' . $uploadFile['extension']);
             }
         }
     }
     $zip->addFromString($fileName, $data);
     $zip->close();
     return $zip->path;
 }
コード例 #2
0
 /**
  * 動画のzipダウンロード
  *
  * @return CakeResponse
  * @throws NotFoundException 表示できない記事へのアクセス
  * @throws ForbiddenException アクセス権なし
  * @see DownloadComponent::doDownload()
  */
 public function download()
 {
     // ダウンロードリンク使わないなら、400
     if (!$this->useDownloadLink) {
         return $this->setAction('throwBadRequest');
     }
     // ブロック編集許可(編集長以上)持っていないなら403
     if (!Current::permission('block_editable')) {
         throw new ForbiddenException();
     }
     // ここから元コンテンツを取得する処理
     //$this->_prepare();
     $key = $this->params['key'];
     $conditions = $this->Video->getConditions();
     $conditions['Video.key'] = $key;
     $query = array('conditions' => $conditions);
     $video = $this->Video->find('first', $query);
     // ここまで元コンテンツを取得する処理
     // ダウンロード実行
     if (!$video) {
         // 表示できない記事へのアクセスなら404
         throw new NotFoundException(__d('videos', 'Invalid video entry'));
     }
     // 圧縮用パスワードキーを求める
     if (!empty($this->request->data['AuthorizationKey']['authorization_key'])) {
         $zipPassword = $this->request->data['AuthorizationKey']['authorization_key'];
     } else {
         $this->_setFlashMessageAndRedirect($key, __d('authorization_keys', 'please input compression password'));
         return;
     }
     // ダウンロードファイル名はタイトルにする
     $fileName = $video['Video']['title'];
     $zipFileName = $fileName . '.zip';
     $videoFileName = $fileName . '.mp4';
     $realFilePath = APP . WEBROOT_DIR . DS . $video['UploadFile'][Video::VIDEO_FILE_FIELD]['path'] . $video['UploadFile'][Video::VIDEO_FILE_FIELD]['id'] . DS . $video['UploadFile'][Video::VIDEO_FILE_FIELD]['real_file_name'];
     $zip = new ZipDownloader();
     $zip->addFile($realFilePath, $videoFileName);
     $zip->setPassword($zipPassword);
     $zip->close();
     return $zip->download($zipFileName);
 }
コード例 #3
0
ファイル: CsvFileWriter.php プロジェクト: s-nakajima/files
 /**
  * zip download
  *
  * @param string $zipFilename Zipファイル名
  * @param string $csvFilename ZipされるCsvファイル名
  * @param string|null $password Zipにつけるパスワード
  * @return CakeResponse
  */
 public function zipDownload($zipFilename, $csvFilename, $password = null)
 {
     // csvファイルを$csvFilenameへリネーム
     $this->_rename($csvFilename);
     // zipFile作成
     $zip = new ZipDownloader();
     $zip->addFile($this->path);
     // zipのダウンロードを実行
     if (strlen($password)) {
         $zip->setPassword($password);
     }
     $zip->close();
     return $zip->download($zipFilename);
 }