Use VFS content, not attachments option as a path to get contents
authorDuck (Jakob Munih) <duck@obala.net>
Thu, 5 Mar 2009 09:58:52 +0000 (10:58 +0100)
committerDuck (Jakob Munih) <duck@obala.net>
Thu, 5 Mar 2009 09:58:52 +0000 (10:58 +0100)
news/config/conf.xml
news/files.php
news/lib/News.php

index 5b35801..223cf51 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0"?>
-<!-- $Id$ -->
+<!-- $Horde: news/config/conf.xml,v 1.2 2004/01/20 18:17:25 jan Exp $ -->
 <configuration>
 
 <configtab name="storage" desc="Storage Settings">
@@ -34,7 +34,7 @@
         <configboolean name="ansel-images" desc="Link to Ansel galleries">TRUE</configboolean>
         <configstring name="ansel-url" desc="Ansel images url">TRUE</configstring>
         <configboolean name="tags" desc="Use tags">false</configboolean>
-        <configstring name="attachments" desc="Attachments dir"></configstring>
+        <configboolean name="attachments" desc="Allow attachments">true</configboolean>
         <configmultienum name="languages" desc="Select all languages that should be activated">
             <values>
                 <configspecial name="list-horde-languages" />
index f673499..129f6ee 100644 (file)
@@ -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 '<h1>HTTP/1.0 404 Not Found</h1>';
+        }
+        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 '<h1>HTTP/1.0 404 Not Found</h1>';
+        }
         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 '<h1>HTTP/1.0 404 Not Found</h1>';
+        }
         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));
index 48c81ab..113d7fa 100644 (file)
@@ -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)
     {