Horde_Browser::wasFileUploaded() now throws an Exception
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 21 Jan 2010 18:49:33 +0000 (11:49 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 21 Jan 2010 18:49:33 +0000 (11:49 -0700)
18 files changed:
ansel/image.php
ansel/img/upload.php
ansel/xppublish.php
framework/Browser/lib/Horde/Browser.php
framework/Browser/lib/Horde/Browser/Exception.php [new file with mode: 0644]
framework/Browser/package.xml
framework/Data/Data.php
framework/Data/Data/tsv.php
framework/Form/Form/Type.php
framework/Model/lib/Horde/Form.php
gollem/manager.php
horde/services/problem.php
imp/folders.php
imp/lib/Compose.php
imp/pgp.php
imp/smime.php
news/add.php
wicked/lib/Page/AttachedFiles.php

index 78ef5d2..9142e93 100644 (file)
@@ -188,19 +188,21 @@ case 'save':
     if ($form->validate($vars)) {
          $form->getInfo($vars, $info);
         /* See if we were replacing photo */
-        if (!empty($info['file0']['file']) &&
-            !is_a(Horde_Browser::wasFileUploaded('file0'), 'PEAR_Error') &&
-            filesize($info['file0']['file'])) {
-
-            /* Read in the uploaded data. */
-            $data = file_get_contents($info['file0']['file']);
-
-            /* Try and make sure the image is in a recognizeable
-             * format. */
-            if (getimagesize($info['file0']['file']) === false) {
-                $notification->push(_("The file you uploaded does not appear to be a valid photo."), 'horde.error');
-                unset($data);
-            }
+        if (!empty($info['file0']['file'])) {
+            try {
+                Horde_Browser::wasFileUploaded('file0');
+                if (filesize($info['file0']['file'])) {
+                    /* Read in the uploaded data. */
+                    $data = file_get_contents($info['file0']['file']);
+
+                    /* Try and make sure the image is in a recognizeable
+                     * format. */
+                    if (getimagesize($info['file0']['file']) === false) {
+                        $notification->push(_("The file you uploaded does not appear to be a valid photo."), 'horde.error');
+                        unset($data);
+                    }
+                }
+            } catch (Horde_Browser_Exception $e) {}
         }
 
         $image = &$ansel_storage->getImage($image_id);
index dcf0186..7e17729 100644 (file)
@@ -36,168 +36,173 @@ if ($form->validate($vars)) {
         }
 
         /* Save new image. */
-        if (!is_a(Horde_Browser::wasFileUploaded('file' . $i), 'PEAR_Error') &&
-            filesize($info['file' . $i]['file'])) {
-
-            /* Check for a compressed file. */
-            if (in_array($info['file' . $i]['type'],
-                         array('x-extension/zip',
-                               'application/x-compressed',
-                               'application/x-zip-compressed',
-                               'application/zip')) ||
-                Horde_Mime_Magic::filenameToMime($info['file' . $i]['name']) == 'application/zip') {
-
-                /* See if we can use the zip extension for reading the file. */
-                if (Horde_Util::extensionExists('zip')) {
-                    $zip = new ZipArchive();
-                    if ($zip->open($info['file' . $i]['file']) !== true) {
-                        $notification->push(sprintf(_("There was an error processing the uploaded archive: %s"), $info['file' . $i]['file']), 'horde.error');
-                        continue;
-                    }
-
-                    for ($z = 0; $z < $zip->numFiles; $z++) {
-                        $zinfo = $zip->statIndex($z);
-
-                        /* Skip some known metadata files. */
-                        $len = strlen($zinfo['name']);
-                        if ($zinfo['name'][$len - 1] == '/') {
-                            continue;
-                        }
-                        if ($zinfo['name'] == 'Thumbs.db') {
-                            continue;
-                        }
-                        if (strrpos($zinfo['name'], '.DS_Store') == ($len - 9)) {
-                            continue;
-                        }
-                        if (strrpos($zinfo['name'], '.localized') == ($len - 10)) {
-                            continue;
-                        }
-                        if (strpos($zinfo['name'], '__MACOSX/') !== false) {
-                            continue;
-                        }
+        try {
+            Horde_Browser::wasFileUploaded('file' . $i);
+            if (!filesize($info['file' . $i]['file'])) {
+                throw new Horde_Browser_Exception();
+            }
+        } catch (Horde_Browser_Exception $e) {
+            if (!empty($info['file' . $i]['error'])) {
+                $notification->push(sprintf(_("There was a problem uploading the photo: %s"), $info['file' . $i]['error']), 'horde.error');
+            } elseif (!filesize($info['file' . $i]['file'])) {
+                $notification->push(_("The uploaded file appears to be empty. It may not exist on your computer."), 'horde.error');
+            }
+            $valid = false;
+            continue;
+        }
 
-                        $stream = $zip->getStream($zinfo['name']);
-                        $zdata = stream_get_contents($stream);
-                        if (!strlen($zdata)) {
-                            $notification->push(sprintf(_("There was an error processing the uploaded archive: %s"), $zinfo['name']), 'horde.error');
-                            break;
-                        }
 
-                        /* If we successfully got data, try adding the
-                         * image to the gallery. */
-                        $image_id = $gallery->addImage(array(
-                            'image_filename' => $zinfo['name'],
-                            'image_caption' => '',
-                            'data' => $zdata,
-                        ));
-                        unset($zdata);
-                        if (!is_a($image_id, 'PEAR_Error')) {
-                            ++$uploaded;
-                            if ($conf['image']['autogen'] > count($image_ids)) {
-                                $image_ids[] = $image_id;
-                            }
-                        } else {
-                            $notification->push(sprintf(_("There was a problem saving the photo: %s"), $image_id), 'horde.error');
-                        }
-                    }
+        /* Check for a compressed file. */
+        if (in_array($info['file' . $i]['type'],
+                     array('x-extension/zip',
+                           'application/x-compressed',
+                           'application/x-zip-compressed',
+                           'application/zip')) ||
+            Horde_Mime_Magic::filenameToMime($info['file' . $i]['name']) == 'application/zip') {
 
-                    $zip->close();
-                    unset($zip);
-                } else {
-                    /* Read in the uploaded data. */
-                    $data = file_get_contents($info['file' . $i]['file']);
+            /* See if we can use the zip extension for reading the file. */
+            if (Horde_Util::extensionExists('zip')) {
+                $zip = new ZipArchive();
+                if ($zip->open($info['file' . $i]['file']) !== true) {
+                    $notification->push(sprintf(_("There was an error processing the uploaded archive: %s"), $info['file' . $i]['file']), 'horde.error');
+                    continue;
+                }
 
-                    /* Get the list of files in the zipfile. */
-                    $zip = Horde_Compress::factory('zip');
-                    $files = $zip->decompress($data, array('action' => Horde_Compress_Zip::ZIP_LIST));
+                for ($z = 0; $z < $zip->numFiles; $z++) {
+                    $zinfo = $zip->statIndex($z);
 
-                    if (is_a($files, 'PEAR_Error')) {
-                        $notification->push(sprintf(_("There was an error processing the uploaded archive: %s"), $files->getMessage()), 'horde.error');
+                    /* Skip some known metadata files. */
+                    $len = strlen($zinfo['name']);
+                    if ($zinfo['name'][$len - 1] == '/') {
+                        continue;
+                    }
+                    if ($zinfo['name'] == 'Thumbs.db') {
+                        continue;
+                    }
+                    if (strrpos($zinfo['name'], '.DS_Store') == ($len - 9)) {
+                        continue;
+                    }
+                    if (strrpos($zinfo['name'], '.localized') == ($len - 10)) {
+                        continue;
+                    }
+                    if (strpos($zinfo['name'], '__MACOSX/') !== false) {
                         continue;
                     }
 
-                    foreach ($files as $key => $zinfo) {
-                        /* Skip some known metadata files. */
-                        $len = strlen($zinfo['name']);
-                        if ($zinfo['name'][$len - 1] == '/') {
-                            continue;
-                        }
-                        if ($zinfo['name'] == 'Thumbs.db') {
-                            continue;
-                        }
-                        if (strrpos($zinfo['name'], '.DS_Store') == ($len - 9)) {
-                            continue;
-                        }
-                        if (strrpos($zinfo['name'], '.localized') == ($len - 10)) {
-                            continue;
-                        }
-                        if (strpos($zinfo['name'], '__MACOSX/') !== false) {
-                            continue;
-                        }
-
-                        $zdata = $zip->decompress($data, array('action' => Horde_Compress_Zip::ZIP_DATA,
-                                                               'info' => $files,
-                                                               'key' => $key));
-                        if (is_a($zdata, 'PEAR_Error')) {
-                            $notification->push(sprintf(_("There was an error processing the uploaded archive: %s"), $zdata->getMessage()), 'horde.error');
-                            break;
-                        }
+                    $stream = $zip->getStream($zinfo['name']);
+                    $zdata = stream_get_contents($stream);
+                    if (!strlen($zdata)) {
+                        $notification->push(sprintf(_("There was an error processing the uploaded archive: %s"), $zinfo['name']), 'horde.error');
+                        break;
+                    }
 
-                        /* If we successfully got data, try adding the
-                         * image to the gallery. */
-                        $image_id = $gallery->addImage(array(
-                            'image_filename' => $zinfo['name'],
-                            'image_caption' => '',
-                            'data' => $zdata,
-                        ));
-                        unset($zdata);
-                        if (!is_a($image_id, 'PEAR_Error')) {
-                            ++$uploaded;
-                            if ($conf['image']['autogen'] > count($image_ids)) {
-                                $image_ids[] = $image_id;
-                            }
-                        } else {
-                            $notification->push(sprintf(_("There was a problem saving the photo: %s"), $image_id), 'horde.error');
+                    /* If we successfully got data, try adding the
+                     * image to the gallery. */
+                    $image_id = $gallery->addImage(array(
+                        'image_filename' => $zinfo['name'],
+                        'image_caption' => '',
+                        'data' => $zdata,
+                    ));
+                    unset($zdata);
+                    if (!is_a($image_id, 'PEAR_Error')) {
+                        ++$uploaded;
+                        if ($conf['image']['autogen'] > count($image_ids)) {
+                            $image_ids[] = $image_id;
                         }
+                    } else {
+                        $notification->push(sprintf(_("There was a problem saving the photo: %s"), $image_id), 'horde.error');
                     }
-
-                    unset($zip);
-                    unset($data);
                 }
+
+                $zip->close();
+                unset($zip);
             } else {
                 /* Read in the uploaded data. */
                 $data = file_get_contents($info['file' . $i]['file']);
 
-                /* Try and make sure the image is in a recognizeable
-                 * format. */
-                if (getimagesize($info['file' . $i]['file']) === false) {
-                    $notification->push(_("The file you uploaded does not appear to be a valid photo."), 'horde.error');
+                /* Get the list of files in the zipfile. */
+                $zip = Horde_Compress::factory('zip');
+                $files = $zip->decompress($data, array('action' => Horde_Compress_Zip::ZIP_LIST));
+
+                if (is_a($files, 'PEAR_Error')) {
+                    $notification->push(sprintf(_("There was an error processing the uploaded archive: %s"), $files->getMessage()), 'horde.error');
                     continue;
                 }
 
-                /* Add the image to the gallery */
-                $image_data = array('image_filename' => $info['file' . $i]['name'],
-                                    'image_caption' => $vars->get('image' . $i . '_desc'),
-                                    'image_type' => $info['file' . $i]['type'],
-                                    'data' => $data,
-                                    'tags' => (isset($info['image' . $i . '_tags']) ? explode(',', $info['image' . $i . '_tags']) : array()));
-                $image_id = $gallery->addImage($image_data, (bool)$vars->get('image' . $i . '_default'));
-                unset($data);
-                if (is_a($image_id, 'PEAR_Error')) {
-                    $notification->push(sprintf(_("There was a problem saving the photo: %s"), $image_id->getMessage()), 'horde.error');
-                    $valid = false;
-                } else {
-                    ++$uploaded;
-                    $image_ids[] = $image_id;
+                foreach ($files as $key => $zinfo) {
+                    /* Skip some known metadata files. */
+                    $len = strlen($zinfo['name']);
+                    if ($zinfo['name'][$len - 1] == '/') {
+                        continue;
+                    }
+                    if ($zinfo['name'] == 'Thumbs.db') {
+                        continue;
+                    }
+                    if (strrpos($zinfo['name'], '.DS_Store') == ($len - 9)) {
+                        continue;
+                    }
+                    if (strrpos($zinfo['name'], '.localized') == ($len - 10)) {
+                        continue;
+                    }
+                    if (strpos($zinfo['name'], '__MACOSX/') !== false) {
+                        continue;
+                    }
+
+                    $zdata = $zip->decompress($data, array('action' => Horde_Compress_Zip::ZIP_DATA,
+                                                           'info' => $files,
+                                                           'key' => $key));
+                    if (is_a($zdata, 'PEAR_Error')) {
+                        $notification->push(sprintf(_("There was an error processing the uploaded archive: %s"), $zdata->getMessage()), 'horde.error');
+                        break;
+                    }
+
+                    /* If we successfully got data, try adding the
+                     * image to the gallery. */
+                    $image_id = $gallery->addImage(array(
+                        'image_filename' => $zinfo['name'],
+                        'image_caption' => '',
+                        'data' => $zdata,
+                    ));
+                    unset($zdata);
+                    if (!is_a($image_id, 'PEAR_Error')) {
+                        ++$uploaded;
+                        if ($conf['image']['autogen'] > count($image_ids)) {
+                            $image_ids[] = $image_id;
+                        }
+                    } else {
+                        $notification->push(sprintf(_("There was a problem saving the photo: %s"), $image_id), 'horde.error');
+                    }
                 }
+
+                unset($zip);
+                unset($data);
             }
         } else {
-            if (!empty($info['file' . $i]['error'])) {
-                $notification->push(sprintf(_("There was a problem uploading the photo: %s"), $info['file' . $i]['error']), 'horde.error');
-            } elseif (!filesize($info['file' . $i]['file'])) {
-                $notification->push(_("The uploaded file appears to be empty. It may not exist on your computer."), 'horde.error');
+            /* Read in the uploaded data. */
+            $data = file_get_contents($info['file' . $i]['file']);
+
+            /* Try and make sure the image is in a recognizeable
+             * format. */
+            if (getimagesize($info['file' . $i]['file']) === false) {
+                $notification->push(_("The file you uploaded does not appear to be a valid photo."), 'horde.error');
+                continue;
+            }
+
+            /* Add the image to the gallery */
+            $image_data = array('image_filename' => $info['file' . $i]['name'],
+                                'image_caption' => $vars->get('image' . $i . '_desc'),
+                                'image_type' => $info['file' . $i]['type'],
+                                'data' => $data,
+                                'tags' => (isset($info['image' . $i . '_tags']) ? explode(',', $info['image' . $i . '_tags']) : array()));
+            $image_id = $gallery->addImage($image_data, (bool)$vars->get('image' . $i . '_default'));
+            unset($data);
+            if (is_a($image_id, 'PEAR_Error')) {
+                $notification->push(sprintf(_("There was a problem saving the photo: %s"), $image_id->getMessage()), 'horde.error');
+                $valid = false;
+            } else {
+                ++$uploaded;
+                $image_ids[] = $image_id;
             }
-            $valid = false;
         }
     }
 
index 339c4a1..a0e321c 100644 (file)
@@ -178,23 +178,26 @@ if ($cmd == 'add') {
     }
     if (!$name || $error) {
         $error = _("No file specified");
-    } elseif (is_a($result = Horde_Browser::wasFileUploaded('imagefile', _("photo")), 'PEAR_Error')) {
-        $error = $result->getMessage();
     } else {
-        $image = &Ansel::getImageFromFile($file, array('image_filename' => $name));
-        if (is_a($image, 'PEAR_Error')) {
-            $error = $image->getMessage();
-        }  else {
-            $gallery = $ansel_storage->getGallery($galleryId);
-            $image_id = $gallery->addImage($image);
-            if (is_a($image_id, 'PEAR_Error')) {
-                $error = _("There was a problem uploading the photo.");
+        try {
+            Horde_Browser::wasFileUploaded('imagefile', _("photo"));
+            $image = &Ansel::getImageFromFile($file, array('image_filename' => $name));
+            if (is_a($image, 'PEAR_Error')) {
+                $error = $image->getMessage();
             } else {
-                $error = false;
-            }
-            if (is_a($image_id, 'PEAR_Error')) {
-                $image_id = $image_id->getMessage();
+                $gallery = $ansel_storage->getGallery($galleryId);
+                $image_id = $gallery->addImage($image);
+                if (is_a($image_id, 'PEAR_Error')) {
+                    $error = _("There was a problem uploading the photo.");
+                } else {
+                    $error = false;
+                }
+                if (is_a($image_id, 'PEAR_Error')) {
+                    $image_id = $image_id->getMessage();
+                }
             }
+        } catch (Horde_Browser_Exception $e) {
+            $error = $e->getMessage();
         }
     }
 
index 63538c1..f0b1c63 100644 (file)
@@ -1037,7 +1037,7 @@ class Horde_Browser
      * @param string $name   The file description string to use in the error
      *                       message.  Default: 'file'.
      *
-     * @return mixed  True on success, PEAR_Error on error.
+     * @throws Horde_Browser_Exception
      */
     public function wasFileUploaded($field, $name = null)
     {
@@ -1046,7 +1046,7 @@ class Horde_Browser
         }
 
         if (!($uploadSize = self::allowFileUploads())) {
-            return PEAR::raiseError(_("File uploads not supported."));
+            throw new Horde_Browser_Exception('File uploads not supported.');
         }
 
         /* Get any index on the field name. */
@@ -1063,21 +1063,21 @@ class Horde_Browser
         } else {
             /* No index, simple set up of vars to check. */
             if (!isset($_FILES[$field])) {
-                return PEAR::raiseError(_("No file uploaded"), UPLOAD_ERR_NO_FILE);
+                throw new Horde_Browser_Exception('No file uploaded', UPLOAD_ERR_NO_FILE);
             }
             $error = $_FILES[$field]['error'];
             $tmp_name = $_FILES[$field]['tmp_name'];
         }
 
         if (!isset($_FILES) || ($error == UPLOAD_ERR_NO_FILE)) {
-            return PEAR::raiseError(sprintf(_("There was a problem with the file upload: No %s was uploaded."), $name), UPLOAD_ERR_NO_FILE);
+            throw new Horde_Browser_Exception(sprintf('There was a problem with the file upload: No %s was uploaded.', $name), UPLOAD_ERR_NO_FILE);
         } elseif (($error == UPLOAD_ERR_OK) && is_uploaded_file($tmp_name)) {
-            return true;
+            return;
         } elseif (($error == UPLOAD_ERR_INI_SIZE) ||
                   ($error == UPLOAD_ERR_FORM_SIZE)) {
-            return PEAR::raiseError(sprintf(_("There was a problem with the file upload: The %s was larger than the maximum allowed size (%d bytes)."), $name, min($uploadSize, Horde_Util::getFormData('MAX_FILE_SIZE'))), $error);
+            throw new Horde_Browser_Exception(sprintf('There was a problem with the file upload: The %s was larger than the maximum allowed size (%d bytes).', $name, min($uploadSize, Horde_Util::getFormData('MAX_FILE_SIZE'))), $error);
         } elseif ($error == UPLOAD_ERR_PARTIAL) {
-            return PEAR::raiseError(sprintf(_("There was a problem with the file upload: The %s was only partially uploaded."), $name), $error);
+            throw new Horde_Browser_Exception(sprintf('There was a problem with the file upload: The %s was only partially uploaded.', $name), $error);
         }
     }
 
diff --git a/framework/Browser/lib/Horde/Browser/Exception.php b/framework/Browser/lib/Horde/Browser/Exception.php
new file mode 100644 (file)
index 0000000..e2608c7
--- /dev/null
@@ -0,0 +1,16 @@
+<?php
+/**
+ * Exception handler for the Horde_Browser package.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author   Michael Slusarz <slusarz@horde.org>
+ * @category Horde
+ * @package  Horde_Browser
+ */
+class Horde_Browser_Exception extends Horde_Exception
+{
+}
index d21b5eb..77f91ef 100644 (file)
@@ -25,12 +25,14 @@ about the current user&apos;s browser and its capabilities.
   <api>beta</api>
  </stability>
  <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>* Initial Horde 4 package.</notes>
+ <notes>* Add Horde_Browser_Exception::.
+ * Initial Horde 4 package.</notes>
  <contents>
   <dir name="/">
    <dir name="lib">
     <dir name="Horde">
      <dir name="Browser">
+      <file name="Exception.php" role="php" />
       <file name="Imode.php" role="php" />
      </dir> <!-- /lib/Horde/Browser -->
      <file name="Browser.php" role="php" />
@@ -60,6 +62,7 @@ about the current user&apos;s browser and its capabilities.
  </dependencies>
  <phprelease>
   <filelist>
+   <install name="lib/Horde/Browser/Exception.php" as="Horde/Browser/Exception.php" />
    <install name="lib/Horde/Browser/Imode.php" as="Horde/Browser/Imode.php" />
    <install name="lib/Horde/Browser.php" as="Horde/Browser.php" />
   </filelist>
index 9a65cb2..1428713 100644 (file)
@@ -312,9 +312,10 @@ class Horde_Data extends PEAR {
         case self::IMPORT_FILE:
             /* Sanitize uploaded file. */
             $import_format = Horde_Util::getFormData('import_format');
-            $check_upload = Horde_Browser::wasFileUploaded('import_file', $param['file_types'][$import_format]);
-            if (is_a($check_upload, 'PEAR_Error')) {
-                return $check_upload;
+            try {
+                Horde_Browser::wasFileUploaded('import_file', $param['file_types'][$import_format]);
+            } catch (Horde_Exception ($e) {
+                PEAR::raiseError($e->getMessage());
             }
             if ($_FILES['import_file']['size'] <= 0) {
                 return PEAR::raiseError(_("The file contained no data."));
index d3377d4..9d00db0 100644 (file)
@@ -183,9 +183,10 @@ class Horde_Data_tsv extends Horde_Data {
 
             /* Move uploaded file so that we can read it again in the next step
                after the user gave some format details. */
-            $uploaded = Horde_Browser::wasFileUploaded('import_file', _("TSV file"));
-            if (is_a($uploaded, 'PEAR_Error')) {
-                return PEAR::raiseError($uploaded->getMessage());
+            try {
+                Horde_Browser::wasFileUploaded('import_file', _("TSV file"));
+            } catch (Horde_Browser_Exception $e) {
+                return PEAR::raiseError($e->getMessage());
             }
             $file_name = Horde::getTempFile('import', false);
             if (!move_uploaded_file($_FILES['import_file']['tmp_name'], $file_name)) {
index 1a14a87..905af4b 100644 (file)
@@ -870,9 +870,10 @@ class Horde_Form_Type_file extends Horde_Form_Type {
     function isValid(&$var, &$vars, $value, &$message)
     {
         if ($var->isRequired()) {
-            $uploaded = Horde_Browser::wasFileUploaded($var->getVarName());
-            if (is_a($uploaded, 'PEAR_Error')) {
-                $message = $uploaded->getMessage();
+            try {
+                Horde_Browser::wasFileUploaded($var->getVarName());
+            } catch (Horde_Browser_Exception $e) {
+                $message = $e->getMessage();
                 return false;
             }
         }
@@ -883,15 +884,15 @@ class Horde_Form_Type_file extends Horde_Form_Type {
     function getInfo(&$vars, &$var, &$info)
     {
         $name = $var->getVarName();
-        $uploaded = Horde_Browser::wasFileUploaded($name);
-        if ($uploaded === true) {
+        try {
+            Horde_Browser::wasFileUploaded($name);
             $info['name'] = Horde_Util::dispelMagicQuotes($_FILES[$name]['name']);
             $info['type'] = $_FILES[$name]['type'];
             $info['tmp_name'] = $_FILES[$name]['tmp_name'];
             $info['file'] = $_FILES[$name]['tmp_name'];
             $info['error'] = $_FILES[$name]['error'];
             $info['size'] = $_FILES[$name]['size'];
-        }
+        } catch (Horde_Browser_Exception $e) {}
     }
 
     /**
@@ -964,7 +965,7 @@ class Horde_Form_Type_image extends Horde_Form_Type {
          * value of the form. */
         if ($vars->get('_do_' . $var->getVarName())) {
             $var->form->setSubmitted(false);
-            if (is_a($this->_uploaded, 'PEAR_Error')) {
+            if ($this->_uploaded instanceof Horde_Browser_Exception) {
                 $this->_img = array('hash' => $this->getRandomId(),
                                     'error' => $this->_uploaded->getMessage());
             }
@@ -978,7 +979,7 @@ class Horde_Form_Type_image extends Horde_Form_Type {
         $field = $vars->get($var->getVarName());
 
         /* The upload generated a PEAR Error. */
-        if (is_a($this->_uploaded, 'PEAR_Error')) {
+        if ($this->_uploaded instanceof Horde_Browser_Exception) {
             /* Not required and no image upload attempted. */
             if (!$var->isRequired() && empty($field['hash']) &&
                 $this->_uploaded->getCode() == UPLOAD_ERR_NO_FILE) {
@@ -1030,7 +1031,7 @@ class Horde_Form_Type_image extends Horde_Form_Type {
             $info['keep_orig'] = !empty($value['keep_orig']);
         }
 
-        /* Set the uploaded value (either true or PEAR_Error). */
+        /* Set the uploaded value (either true or Horde_Browser_Exception). */
         $info['uploaded'] = &$this->_uploaded;
 
         /* If a modified file exists move it over the original. */
@@ -1071,9 +1072,11 @@ class Horde_Form_Type_image extends Horde_Form_Type {
 
         /* Check if file has been uploaded. */
         $varname = $var->getVarName();
-        $this->_uploaded = Horde_Browser::wasFileUploaded($varname . '[new]');
 
-        if ($this->_uploaded === true) {
+        try {
+            Horde_Browser::wasFileUploaded($varname . '[new]');
+            $this->_uploaded = true;
+
             /* A file has been uploaded on this submit. Save to temp dir for
              * preview work. */
             $this->_img['img']['type'] = $this->getUploadedFileType($varname . '[new]');
@@ -1112,7 +1115,9 @@ class Horde_Form_Type_image extends Horde_Form_Type {
             /* Move the browser created temp file to the new temp file. */
             move_uploaded_file($this->_img['img']['file'], $tmp_file);
             $this->_img['img']['file'] = basename($tmp_file);
-        } elseif ($this->_uploaded) {
+        } catch (Horde_Browser_Exception $e) {
+            $this->_uploaded = $e;
+
             /* File has not been uploaded. */
             $upload = $vars->get($var->getVarName());
             if ($this->_uploaded->getCode() == 4 &&
index ef895c5..18d60b8 100644 (file)
@@ -1089,9 +1089,10 @@ class Horde_Form_Type_file extends Horde_Form_Type {
     function isValid($var, $vars, $value, &$message)
     {
         if ($var->isRequired()) {
-            $uploaded = Horde_Browser::wasFileUploaded($var->getVarName());
-            if (is_a($uploaded, 'PEAR_Error')) {
-                $message = $uploaded->getMessage();
+            try {
+                Horde_Browser::wasFileUploaded($var->getVarName());
+            } catch (Horde_Browser_Exception $e) {
+                $message = $e->getMessage();
                 return false;
             }
         }
@@ -1102,15 +1103,15 @@ class Horde_Form_Type_file extends Horde_Form_Type {
     function getInfo($vars, $var, &$info)
     {
         $name = $var->getVarName();
-        $uploaded = Horde_Browser::wasFileUploaded($name);
-        if ($uploaded === true) {
+        try {
+            Horde_Browser::wasFileUploaded($name);
             $info['name'] = $_FILES[$name]['name'];
             $info['type'] = $_FILES[$name]['type'];
             $info['tmp_name'] = $_FILES[$name]['tmp_name'];
             $info['file'] = $_FILES[$name]['tmp_name'];
             $info['error'] = $_FILES[$name]['error'];
             $info['size'] = $_FILES[$name]['size'];
-        }
+        } catch (Horde_Browser_Exception $e) {}
     }
 
     /**
index 02bf714..0bdb548 100644 (file)
@@ -108,16 +108,18 @@ case 'upload_file':
         for ($i = 1, $l = count($_FILES); $i <= $l; ++$i) {
             $val = 'file_upload_' . $i;
             if (isset($_FILES[$val]) && ($_FILES[$val]['error'] != 4)) {
-                $res = Browser::wasFileUploaded($val);
-                if (!is_a($res, 'PEAR_Error')) {
+                try {
+                    Horde_Browser::wasFileUploaded($val);
                     $filename = Horde_Util::dispelMagicQuotes($_FILES[$val]['name']);
                     $res = Gollem::writeFile($old_dir, $filename, $_FILES[$val]['tmp_name']);
-                }
-                if (is_a($res, 'PEAR_Error')) {
-                    $notification->push($res, 'horde.error');
-                } else {
-                    Gollem::expireCache($old_dir);
-                    $notification->push(sprintf(_("File received: %s"), $filename), 'horde.success');
+                    if (is_a($res, 'PEAR_Error')) {
+                        $notification->push($res, 'horde.error');
+                    } else {
+                        Gollem::expireCache($old_dir);
+                        $notification->push(sprintf(_("File received: %s"), $filename), 'horde.success');
+                    }
+                } catch (Horde_Browser_Exception $e) {
+                    $notification->push($e, 'horde.error');
                 }
             }
         }
index ad1355e..a587ef8 100644 (file)
@@ -53,14 +53,14 @@ case 'send_problem_report':
         /* Check for attachments. */
         $attachment = null;
         if (!empty($conf['problems']['attachments'])) {
-            $result = Horde_Browser::wasFileUploaded('attachment', _("attachment"));
-            if (is_a($result, 'PEAR_Error')) {
-                if ($result->getCode() != UPLOAD_ERR_NO_FILE) {
-                    $notification->push($result, 'horde.error');
+            try {
+                Horde_Browser::wasFileUploaded('attachment', _("attachment"));
+                $attachment = $_FILES['attachment'];
+            } catch (Horde_Browser_Exception $e) {
+                if ($e->getCode() != UPLOAD_ERR_NO_FILE) {
+                    $notification->push($e, 'horde.error');
                     break;
                 }
-            } else {
-                $attachment = $_FILES['attachment'];
             }
         }
 
index 85fa93f..0e1e0e1 100644 (file)
@@ -136,8 +136,8 @@ case 'download_folder_zip':
 case 'import_mbox':
     $import_folder = Horde_Util::getFormData('import_folder');
     if (!empty($import_folder)) {
-        $res = $browser->wasFileUploaded('mbox_upload', _("mailbox file"));
-        if (!($res instanceof PEAR_Error)) {
+        try {
+            $browser->wasFileUploaded('mbox_upload', _("mailbox file"));
             $res = $imp_folder->importMbox(Horde_String::convertCharset($import_folder, $charset, 'UTF7-IMAP'), $_FILES['mbox_upload']['tmp_name']);
             $mbox_name = basename(Horde_Util::dispelMagicQuotes($_FILES['mbox_upload']['name']));
             if ($res === false) {
@@ -145,8 +145,8 @@ case 'import_mbox':
             } else {
                 $notification->push(sprintf(_("Imported %d messages from %s."), $res, $mbox_name), 'horde.success');
             }
-        } else {
-            $notification->push($res);
+        } catch (Horde_Browser_Exception $e) {
+            $notification->push($e);
         }
         $actionID = null;
     } else {
index ebd95fc..f72073b 100644 (file)
@@ -1671,9 +1671,10 @@ class IMP_Compose
     {
         global $conf;
 
-        $res = $GLOBALS['browser']->wasFileUploaded($name, _("attachment"));
-        if ($res instanceof PEAR_Error) {
-            throw new IMP_Compose_Exception($res);
+        try {
+            $GLOBALS['browser']->wasFileUploaded($name, _("attachment"));
+        } catch (Horde_Browser_Exception $e) {
+            throw new IMP_Compose_Exception($e);
         }
 
         $filename = Horde_Util::dispelMagicQuotes($_FILES[$name]['name']);
index 9f9c9c4..ef2c29b 100644 (file)
@@ -53,13 +53,12 @@ function _getImportKey()
         return $key;
     }
 
-    $res = $GLOBALS['browser']->wasFileUploaded('upload_key', _("key"));
-    if ($res instanceof PEAR_Error) {
-        $GLOBALS['notification']->push($res, 'horde.error');
-        return;
+    try {
+        $GLOBALS['browser']->wasFileUploaded('upload_key', _("key"));
+        return file_get_contents($_FILES['upload_key']['tmp_name']);
+    } catch (Horde_Browser_Exception $e) {
+        $GLOBALS['notification']->push($e, 'horde.error');
     }
-
-    return file_get_contents($_FILES['upload_key']['tmp_name']);
 }
 
 function _textWindowOutput($filename, $msg)
index 47e6f99..641ac80 100644 (file)
@@ -42,13 +42,12 @@ function _getImportKey()
         return $key;
     }
 
-    $res = $GLOBALS['browser']->wasFileUploaded('upload_key', _("key"));
-    if ($res instanceof PEAR_Error) {
-        $GLOBALS['notification']->push($res, 'horde.error');
-        return;
+    try {
+        $GLOBALS['browser']->wasFileUploaded('upload_key', _("key"));
+        return file_get_contents($_FILES['upload_key']['tmp_name']);
+    } catch (Horde_Browser_Exception $e) {
+        $GLOBALS['notification']->push($e, 'horde.error');
     }
-
-    return file_get_contents($_FILES['upload_key']['tmp_name']);
 }
 
 function _actionWindow()
index c605694..fbf73f2 100644 (file)
@@ -473,12 +473,8 @@ if ($form->validate()) {
         foreach ($conf['attributes']['languages'] as $key) {
             for ($i = 1; $i < 6; $i++) {
                 $input = 'file_' . $key . '_' . $i;
-                $uploaded = Horde_Browser::wasFileUploaded($input);
-                if ($uploaded instanceof PEAR_Error) {
-                    if ($uploaded->getCode() != UPLOAD_ERR_NO_FILE) {
-                        $notification->push($uploaded->getMessage(), 'horde.warning');
-                    }
-                } elseif ($uploaded) {
+                try {
+                    Horde_Browser::wasFileUploaded($input);
                     $file_id = $news->write_db->nextID($news->prefix . '_files');
                     if ($file_id instanceof PEAR_Error) {
                         $notification->push($file_id);
@@ -494,6 +490,10 @@ if ($form->validate()) {
                             }
                         }
                     }
+                } catch (Horde_Browser_Exception $e) {
+                    if ($e->getCode() != UPLOAD_ERR_NO_FILE) {
+                        $notification->push($e->getMessage(), 'horde.warning');
+                    }
                 }
             }
         }
index ea42d41..2324582 100644 (file)
@@ -212,9 +212,11 @@ class AttachedFiles extends Page {
         if (empty($filename)) {
             $filename = Horde_Util::dispelMagicQuotes($_FILES['attachment_file']['name']);
         }
-        $result = Horde_Browser::wasFileUploaded('attachment_file', _("attachment"));
-        if (is_a($result, 'PEAR_Error')) {
-            $notification->push($result, 'horde.error');
+
+        try {
+            Horde_Browser::wasFileUploaded('attachment_file', _("attachment"));
+        } catch (Horde_Browser_Exception $e) {
+            $notification->push($e, 'horde.error');
             return;
         }