Sophie

Sophie

distrib > Mandriva > 2010.2 > i586 > media > main-release-src > by-pkgid > 502daf9ac35e6405cde28565e7656784 > files > 2

kolab-horde-framework-2.1.0-10mdv2010.1.src.rpm


 http://www.kolab.org/pipermail/kolab-commits/2009q4/010721.html

--- Form/Form.php	2005-10-14 10:33:04.000000000 -0400
+++ Form/Form.php.oden	2010-05-26 06:23:05.000000000 -0400
@@ -1340,7 +1340,14 @@ class Horde_Form_Type_image extends Hord
      * Hash containing the previously uploaded image info.
      * @var array $_img
      */
-    var $_img = array();
+    var $_img;
+
+    /**
+     * A random id that identifies the image information in the session data.
+     *
+     * @var string
+     */
+    var $_random;
 
     function init($show_upload = true, $show_keeporig = false)
     {
@@ -1351,7 +1358,7 @@ class Horde_Form_Type_image extends Hord
     function onSubmit(&$var, &$vars)
     {
         /* Get the upload. */
-        $this->_getUpload($vars, $var);
+        $this->getImage($vars, $var);
 
         /* If this was done through the upload button override the submitted
          * value of the form. */
@@ -1362,23 +1369,26 @@ class Horde_Form_Type_image extends Hord
 
     function isValid(&$var, &$vars, $value, &$message)
     {
+
+         /* Get the upload. */
+        $this->getImage($vars, $var);
         $field = $vars->get($var->getVarName());
 
         /* The upload generated a PEAR Error. */
         if (is_a($this->_uploaded, 'PEAR_Error')) {
             /* Not required and no image upload attempted. */
-            if (!$var->isRequired() && empty($field['img']) &&
+            if (!$var->isRequired() && empty($field['hash']) &&
                 $this->_uploaded->getCode() == 4) {
                 return true;
             }
 
             /* TODO: Change error value to upload error constants when
              * PHP4.3.0 is required. Error 4: UPLOAD_ERR_NO_FILE, */
-            if ($this->_uploaded->getCode() == 4 && empty($field['img'])) {
+            if ($this->_uploaded->getCode() == 4 && empty($field['hash'])) {
                 /* Nothing uploaded and no older upload. */
                 $message = _("This field is required.");
                 return false;
-            } elseif (!empty($field['img'])) {
+            } elseif (!empty($field['hash'])) {
                 /* Nothing uploaded but older upload present. */
                 return true;
             } else {
@@ -1394,11 +1404,11 @@ class Horde_Form_Type_image extends Hord
     function getInfo(&$vars, &$var, &$info)
     {
         /* Get the upload. */
-        $this->_getUpload($vars, $var);
+        $this->getImage($vars, $var);
 
         /* Get image params stored in the hidden field. */
         $value = $var->getValue($vars);
-        $info = $this->_img;
+        $info = $this->_img['img'];
         if (empty($info['file'])) {
             unset($info['file']);
             return;
@@ -1452,7 +1462,7 @@ class Horde_Form_Type_image extends Hord
         if ($this->_uploaded === true) {
             /* A file has been uploaded on this submit. Save to temp dir for
              * preview work. */
-            $this->_img['type'] = $this->getUploadedFileType($varname . '[new]');
+            $this->_img['img']['type'] = $this->getUploadedFileType($varname . '[new]');
 
             /* Get the other parts of the upload. */
             require_once 'Horde/Array.php';
@@ -1460,19 +1470,22 @@ class Horde_Form_Type_image extends Hord
 
             /* Get the temporary file name. */
             $keys_path = array_merge(array($base, 'tmp_name'), $keys);
-            $this->_img['file'] = Horde_Array::getElement($_FILES, $keys_path);
+            $this->_img['img']['file'] = Horde_Array::getElement($_FILES, $keys_path);
 
             /* Get the actual file name. */
             $keys_path= array_merge(array($base, 'name'), $keys);
-            $this->_img['name'] = Horde_Array::getElement($_FILES, $keys_path);
+            $this->_img['img']['name'] = Horde_Array::getElement($_FILES, $keys_path);
 
             /* Get the file size. */
             $keys_path= array_merge(array($base, 'size'), $keys);
-            $this->_img['size'] = Horde_Array::getElement($_FILES, $keys_path);
+            $this->_img['img']['size'] = Horde_Array::getElement($_FILES, $keys_path);
 
             /* Get any existing values for the image upload field. */
             $upload = $vars->get($var->getVarName());
-            $upload['img'] = @unserialize($upload['img']);
+            if (!empty($upload['hash'])) {
+                $upload['img'] = $_SESSION['horde_form'][$upload['hash']];
+                unset($_SESSION['horde_form'][$upload['hash']]);
+            }
 
             /* Get the temp file if already one uploaded, otherwise create a
              * new temporary file. */
@@ -1483,17 +1496,16 @@ class Horde_Form_Type_image extends Hord
             }
 
             /* Move the browser created temp file to the new temp file. */
-            move_uploaded_file($this->_img['file'], $tmp_file);
-            $this->_img['file'] = basename($tmp_file);
-
-            /* Store the uploaded image file data to the hidden field. */
-            $upload['img'] = serialize($this->_img);
-            $vars->set($var->getVarName(), $upload);
+	    move_uploaded_file($this->_img['img']['file'], $tmp_file);
+            $this->_img['img']['file'] = basename($tmp_file);
         } elseif ($this->_uploaded) {
             /* File has not been uploaded. */
             $upload = $vars->get($var->getVarName());
-            if ($this->_uploaded->getCode() == 4 && !empty($upload['img'])) {
-                $this->_img = @unserialize($upload['img']);
+            if ($this->_uploaded->getCode() == 4 &&
+                !empty($upload['hash']) &&
+                isset($_SESSION['horde_form'][$upload['hash']])) {
+                $this->_img['img'] = $_SESSION['horde_form'][$upload['hash']];
+                unset($_SESSION['horde_form'][$upload['hash']]);
             }
         }
     }
@@ -1545,6 +1557,27 @@ class Horde_Form_Type_image extends Hord
     }
 
     /**
+     * Returns the current image information.
+     *
+     * @return array  The current image hash.
+     */
+    function getImage($vars, $var)
+    {
+        $this->_getUpload($vars, $var);
+        if (!isset($this->_img)) {
+            $image = $vars->get($var->getVarName());
+            if ($image) {
+                $this->loadImageData($image);
+                if (isset($image['img'])) {
+                    $this->_img = $image;
+                    $_SESSION['horde_form'][$this->getRandomId()] = $this->_img['img'];
+                }
+            }
+        }
+        return $this->_img;
+    }
+
+    /**
      * Loads any existing image data into the image field. Requires that the
      * array $image passed to it contains the structure:
      *   $image['load']['file'] - the filename of the image;
@@ -1568,10 +1601,18 @@ class Horde_Form_Type_image extends Hord
             fclose($fd);
         }
 
-        $image['img'] = serialize(array('file' => $image['load']['file']));
+        $image['img'] = array('file' => $image['load']['file']);
         unset($image['load']);
     }
 
+    function getRandomId()
+    {
+        if (!isset($this->_random)) {
+            $this->_random = uniqid(mt_rand());
+        }
+        return $this->_random;
+    }
+
     /**
      * Return info about field type.
      */