From: Duck (Jakob Munih) Date: Thu, 5 Mar 2009 09:58:52 +0000 (+0100) Subject: Use VFS content, not attachments option as a path to get contents X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=ca295506fa6ea7311f1ae7e7557ad753f75acb60;p=horde.git Use VFS content, not attachments option as a path to get contents --- diff --git a/news/config/conf.xml b/news/config/conf.xml index 5b35801c2..223cf5113 100644 --- a/news/config/conf.xml +++ b/news/config/conf.xml @@ -1,5 +1,5 @@ - + @@ -34,7 +34,7 @@ TRUE TRUE false - + true diff --git a/news/files.php b/news/files.php index f673499c6..129f6ee50 100644 --- a/news/files.php +++ b/news/files.php @@ -28,16 +28,31 @@ $file_size = Util::getFormData('file_size'); switch ($actionID) { case 'download_file': + $data = News::getFile($file_id); + if ($data instanceof PEAR_Error) { + if (Auth::isAdmin('news:admin')) { + Horde::fatal($data, __FILE__, __LINE__); + } else { + header('HTTP/1.0 404 Not Found'); + echo '

HTTP/1.0 404 Not Found

'; + } + exit; + } + $browser->downloadHeaders($file_name, $file_type, false, $file_size); - readfile($conf['attributes']['attachments'] . '/' . $file_id); + echo $data; break; case 'view_file': - $data = file_get_contents($conf['attributes']['attachments'] . '/' . $file_id); - if ($data === false) { - header('HTTP/1.0 404 Not Found'); - echo 'HTTP/1.0 404 Not Found'; + $data = News::getFile($file_id); + if ($data instanceof PEAR_Error) { + if (Auth::isAdmin('news:admin')) { + Horde::fatal($data, __FILE__, __LINE__); + } else { + header('HTTP/1.0 404 Not Found'); + echo '

HTTP/1.0 404 Not Found

'; + } exit; } @@ -68,9 +83,8 @@ case 'download_zip_all': $file_id = sprintf(_("FilesOfNews-%s"), $news_id); $zipfiles = array(); foreach ($news->getFiles($news_id) as $file) { - - $file_path = $conf['attributes']['attachments'] . '/' . $file['file_id']; - if (!file_exists($file_path)) { + $data = News::getFile($file_id); + if ($data instanceof PEAR_Error) { continue; } $zipfiles[] = array('data' => $file_path, @@ -90,15 +104,18 @@ break; case 'download_zip': - $zipfiles = array('data' => file_get_contents($conf['attributes']['attachments'] . '/' . $file_id), - 'name' => $file_id); - - if ($zipfiles[0]['data'] === false) { - header('HTTP/1.0 404 Not Found'); - echo 'HTTP/1.0 404 Not Found'; + $data = News::getFile($file_id); + if ($data instanceof PEAR_Error) { + if (Auth::isAdmin('news:admin')) { + Horde::fatal($data, __FILE__, __LINE__); + } else { + header('HTTP/1.0 404 Not Found'); + echo '

HTTP/1.0 404 Not Found

'; + } exit; } + $zipfiles = array('data' => $data, 'name' => $file_id); $zip = Horde_Compress::singleton('zip'); $body = @$zip->compress($zipfiles); $browser->downloadHeaders($file_id . '.zip', 'application/zip', false, strlen($body)); diff --git a/news/lib/News.php b/news/lib/News.php index 48c81abc1..113d7fa3f 100644 --- a/news/lib/News.php +++ b/news/lib/News.php @@ -349,7 +349,7 @@ class News { /** * Store file * - * @param $file_id Image owner record id + * @param $file_id File id * @param $file_src File path */ static public function saveFile($file_id, $file_src) @@ -363,9 +363,24 @@ class News { } /** + * Get file contents + * + * @param $file_id File ID + */ + static public function getFile($file_id) + { + $vfs = self::loadVFS(); + if ($vfs instanceof PEAR_Error) { + return $vfs; + } + + return $vfs->read(self::VFS_PATH . '/files/', $file_id); + } + + /** * Delete file * - * @param $id Image owner record id + * @param $id File ID */ static public function deleteFile($file_id) {