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);
}
/* 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;
}
}
}
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();
}
}
* @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)
{
}
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. */
} 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);
}
}
--- /dev/null
+<?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
+{
+}
<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" />
</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>
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."));
/* 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)) {
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;
}
}
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) {}
}
/**
* 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());
}
$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) {
$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. */
/* 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]');
/* 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 &&
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;
}
}
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) {}
}
/**
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');
}
}
}
/* 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'];
}
}
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) {
} 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 {
{
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']);
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)
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()
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);
}
}
}
+ } catch (Horde_Browser_Exception $e) {
+ if ($e->getCode() != UPLOAD_ERR_NO_FILE) {
+ $notification->push($e->getMessage(), 'horde.warning');
+ }
}
}
}
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;
}