Esempio n. 1
0
 /**
  * Fetch the field values from a given array of variables.
  *
  * @access private
  *
  * @param array  $variables  An array of Horde_Form_Variable objects to
  *                           fetch from.
  * @param object $vars       The Variables object.
  * @param array  $info       The array to be filled with the submitted
  *                           field values.
  */
 function _getInfoFromVariables($variables, &$vars, &$info)
 {
     foreach ($variables as $var) {
         $value = $var->getValue($vars);
         if (empty($value)) {
             continue;
         }
         require_once 'Horde/Array.php';
         if (Horde_Array::getArrayParts($var->getVarName(), $base, $keys)) {
             if (!isset($info[$base])) {
                 $info[$base] = array();
             }
             $pointer =& $info[$base];
             while (count($keys)) {
                 $key = array_shift($keys);
                 if (!isset($pointer[$key])) {
                     $pointer[$key] = array();
                 }
                 $pointer =& $pointer[$key];
             }
             $var->getInfo($vars, $pointer);
         } else {
             $var->getInfo($vars, $info[$var->getVarName()]);
         }
     }
 }
Esempio n. 2
0
 function getUploadedFileType($field)
 {
     /* Get any index on the field name. */
     $index = Horde_Array::getArrayParts($field, $base, $keys);
     if ($index) {
         /* Index present, fetch the mime type var to check. */
         $keys_path = array_merge(array($base, 'type'), $keys);
         $type = Horde_Array::getElement($_FILES, $keys_path);
         $keys_path = array_merge(array($base, 'tmp_name'), $keys);
         $tmp_name = Horde_Array::getElement($_FILES, $keys_path);
     } else {
         /* No index, simple set up of vars to check. */
         $type = $_FILES[$field]['type'];
         $tmp_name = $_FILES[$field]['tmp_name'];
     }
     if (empty($type) || $type == 'application/octet-stream') {
         /* Type wasn't set on upload, try analising the upload. */
         if (!($type = Horde_Mime_Magic::analyzeFile($tmp_name, isset($GLOBALS['conf']['mime']['magic_db']) ? $GLOBALS['conf']['mime']['magic_db'] : null))) {
             if ($index) {
                 /* Get the name value. */
                 $keys_path = array_merge(array($base, 'name'), $keys);
                 $name = Horde_Array::getElement($_FILES, $keys_path);
                 /* Work out the type from the file name. */
                 $type = Horde_Mime_Magic::filenameToMime($name);
                 /* Set the type. */
                 $keys_path = array_merge(array($base, 'type'), $keys);
                 Horde_Array::getElement($_FILES, $keys_path, $type);
             } else {
                 /* Work out the type from the file name. */
                 $type = Horde_Mime_Magic::filenameToMime($_FILES[$field]['name']);
                 /* Set the type. */
                 $_FILES[$field]['type'] = Horde_Mime_Magic::filenameToMime($_FILES[$field]['name']);
             }
         }
     }
     return $type;
 }
Esempio n. 3
0
 /**
  * Determines if the file was uploaded or not.  If not, will return the
  * appropriate error message.
  *
  * @param string $field  The name of the field containing the uploaded
  *                       file.
  * @param string $name   The file description string to use in the error
  *                       message.  Default: 'file'.
  *
  * @throws Horde_Browser_Exception
  */
 public function wasFileUploaded($field, $name = null)
 {
     if (is_null($name)) {
         $name = 'file';
     }
     if (!($uploadSize = self::allowFileUploads())) {
         throw new Horde_Browser_Exception(Horde_Browser_Translation::t("File uploads not supported."));
     }
     /* Get any index on the field name. */
     $index = Horde_Array::getArrayParts($field, $base, $keys);
     if ($index) {
         /* Index present, fetch the error var to check. */
         $keys_path = array_merge(array($base, 'error'), $keys);
         $error = Horde_Array::getElement($_FILES, $keys_path);
         /* Index present, fetch the tmp_name var to check. */
         $keys_path = array_merge(array($base, 'tmp_name'), $keys);
         $tmp_name = Horde_Array::getElement($_FILES, $keys_path);
     } else {
         /* No index, simple set up of vars to check. */
         if (!isset($_FILES[$field])) {
             throw new Horde_Browser_Exception(Horde_Browser_Translation::t("No file uploaded"), UPLOAD_ERR_NO_FILE);
         }
         $error = $_FILES[$field]['error'];
         if (is_array($error)) {
             $error = reset($error);
         }
         $tmp_name = $_FILES[$field]['tmp_name'];
         if (is_array($tmp_name)) {
             $tmp_name = reset($tmp_name);
         }
     }
     if (empty($_FILES)) {
         $error = UPLOAD_ERR_NO_FILE;
     }
     switch ($error) {
         case UPLOAD_ERR_NO_FILE:
             throw new Horde_Browser_Exception(sprintf(Horde_Browser_Translation::t("There was a problem with the file upload: No %s was uploaded."), $name), UPLOAD_ERR_NO_FILE);
         case UPLOAD_ERR_OK:
             if (is_uploaded_file($tmp_name) && !filesize($tmp_name)) {
                 throw new Horde_Browser_Exception(Horde_Browser_Translation::t("The uploaded file appears to be empty. It may not exist on your computer."), UPLOAD_ERR_NO_FILE);
             }
             // SUCCESS
             break;
         case UPLOAD_ERR_INI_SIZE:
         case UPLOAD_ERR_FORM_SIZE:
             throw new Horde_Browser_Exception(sprintf(Horde_Browser_Translation::t("There was a problem with the file upload: The %s was larger than the maximum allowed size (%d bytes)."), $name, $uploadSize), $error);
         case UPLOAD_ERR_PARTIAL:
             throw new Horde_Browser_Exception(sprintf(Horde_Browser_Translation::t("There was a problem with the file upload: The %s was only partially uploaded."), $name), $error);
         case UPLOAD_ERR_NO_TMP_DIR:
             throw new Horde_Browser_Exception(Horde_Browser_Translation::t("There was a problem with the file upload: The temporary folder used to store the upload data is missing."), $error);
         case UPLOAD_ERR_CANT_WRITE:
             // No reason to try to explain to user what a "PHP extension" is.
         // No reason to try to explain to user what a "PHP extension" is.
         case UPLOAD_ERR_EXTENSION:
             throw new Horde_Browser_Exception(Horde_Browser_Translation::t("There was a problem with the file upload: Can't write the uploaded data to the server."), $error);
     }
 }
Esempio n. 4
0
 /**
  * Fetch the field values from a given array of variables.
  *
  * @access private
  *
  * @param array  $variables  An array of Horde_Form_Variable objects to
  *                           fetch from.
  * @param object $vars       The Variables object.
  * @param array  $info       The array to be filled with the submitted
  *                           field values.
  */
 function _getInfoFromVariables($variables, &$vars, &$info)
 {
     foreach ($variables as $var) {
         if ($var->isDisabled()) {
             // Disabled fields are not submitted by some browsers, so don't
             // pretend they were.
             continue;
         }
         if ($var->isArrayVal()) {
             $var->getInfo($vars, $values);
             if (is_array($values)) {
                 $varName = str_replace('[]', '', $var->getVarName());
                 foreach ($values as $i => $val) {
                     $info[$i][$varName] = $val;
                 }
             }
         } else {
             if (Horde_Array::getArrayParts($var->getVarName(), $base, $keys)) {
                 if (!isset($info[$base])) {
                     $info[$base] = array();
                 }
                 $pointer =& $info[$base];
                 while (count($keys)) {
                     $key = array_shift($keys);
                     if (!isset($pointer[$key])) {
                         $pointer[$key] = array();
                     }
                     $pointer =& $pointer[$key];
                 }
                 $var->getInfo($vars, $pointer);
             } else {
                 $var->getInfo($vars, $info[$var->getVarName()]);
             }
         }
     }
 }
Esempio n. 5
0
 /**
  * Determines if the file was uploaded or not.  If not, will return the
  * appropriate error message.
  *
  * @param string $field  The name of the field containing the uploaded
  *                       file.
  * @param string $name   The file description string to use in the error
  *                       message.  Default: 'file'.
  *
  * @throws Horde_Browser_Exception
  */
 public function wasFileUploaded($field, $name = null)
 {
     if (is_null($name)) {
         $name = 'file';
     }
     if (!($uploadSize = self::allowFileUploads())) {
         throw new Horde_Browser_Exception(Horde_Browser_Translation::t("File uploads not supported."));
     }
     /* Get any index on the field name. */
     $index = Horde_Array::getArrayParts($field, $base, $keys);
     if ($index) {
         /* Index present, fetch the error var to check. */
         $keys_path = array_merge(array($base, 'error'), $keys);
         $error = Horde_Array::getElement($_FILES, $keys_path);
         /* Index present, fetch the tmp_name var to check. */
         $keys_path = array_merge(array($base, 'tmp_name'), $keys);
         $tmp_name = Horde_Array::getElement($_FILES, $keys_path);
     } else {
         /* No index, simple set up of vars to check. */
         if (!isset($_FILES[$field])) {
             throw new Horde_Browser_Exception(Horde_Browser_Translation::t("No file uploaded"), UPLOAD_ERR_NO_FILE);
         }
         $error = $_FILES[$field]['error'];
         $tmp_name = $_FILES[$field]['tmp_name'];
     }
     if (empty($_FILES) || $error == UPLOAD_ERR_NO_FILE) {
         throw new Horde_Browser_Exception(sprintf(Horde_Browser_Translation::t("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)) {
         if (!filesize($tmp_name)) {
             throw new Horde_Browser_Exception(Horde_Browser_Translation::t("The uploaded file appears to be empty. It may not exist on your computer."), UPLOAD_ERR_NO_FILE);
         }
         // SUCCESS
     } elseif ($error == UPLOAD_ERR_INI_SIZE || $error == UPLOAD_ERR_FORM_SIZE) {
         throw new Horde_Browser_Exception(sprintf(Horde_Browser_Translation::t("There was a problem with the file upload: The %s was larger than the maximum allowed size (%d bytes)."), $name, $uploadSize), $error);
     } elseif ($error == UPLOAD_ERR_PARTIAL) {
         throw new Horde_Browser_Exception(sprintf(Horde_Browser_Translation::t("There was a problem with the file upload: The %s was only partially uploaded."), $name), $error);
     }
 }
Esempio n. 6
0
File: Form.php Progetto: horde/horde
 /**
  * Fetch the field values from a given array of variables.
  *
  * @access private
  *
  * @param array  $variables  An array of Horde_Core_Form_Variable objects to
  *                           fetch from.
  * @param array  $info       The array to be filled with the submitted
  *                           field values.
  */
 protected function _getInfoFromVariables($variables, &$info)
 {
     foreach ($variables as $var) {
         if ($var->isArrayVal()) {
             $var->getInfo($this->_vars, $values);
             if (is_array($values)) {
                 $varName = str_replace('[]', '', $var->getVarName());
                 foreach ($values as $i => $val) {
                     $info[$i][$varName] = $val;
                 }
             }
         } else {
             if (Horde_Array::getArrayParts($var->getVarName(), $base, $keys)) {
                 if (!isset($info[$base])) {
                     $info[$base] = array();
                 }
                 $pointer =& $info[$base];
                 while (count($keys)) {
                     $key = array_shift($keys);
                     if (!isset($pointer[$key])) {
                         $pointer[$key] = array();
                     }
                     $pointer =& $pointer[$key];
                 }
                 $var->getInfo($this->_vars, $pointer);
             } else {
                 $var->getInfo($this->_vars, $info[$var->getVarName()]);
             }
         }
     }
 }
Esempio n. 7
0
 /**
  * Fetch the requested variable ($varname) into $value, and return
  * whether or not the variable was set in $array.
  *
  * @param array $array     The array to search in (usually either
  *                         $this->_vars or $this->_expected).
  * @param string $varname  The name of the variable to look for.
  * @param mixed &$value    $varname's value gets assigned to this variable.
  *
  * @return boolean  Whether or not the variable was set (or, if we've
  *                  checked $this->_expected, should have been set).
  */
 protected function _getExists($array, $varname, &$value)
 {
     if (Horde_Array::getArrayParts($varname, $base, $keys)) {
         if (!isset($array[$base])) {
             $value = null;
             return false;
         }
         $searchspace =& $array[$base];
         $i = count($keys);
         while ($i--) {
             $key = array_shift($keys);
             if (!isset($searchspace[$key])) {
                 $value = null;
                 return false;
             }
             $searchspace =& $searchspace[$key];
         }
         $value = $searchspace;
         return true;
     }
     $value = isset($array[$varname]) ? $array[$varname] : null;
     return !is_null($value);
 }