コード例 #1
0
ファイル: Controller.php プロジェクト: rmaiwald/MUBoard
 /**
  * Get allowed filesize
  */
 public static function maxSize()
 {
     $maxSize = ModUtil::getVar('MUBoard', 'allowedSizeOfImages');
     $dom = ZLanguage::getModuleDomain('MUBoard');
     if ($maxSize > 0) {
         $maxSizeKB = $maxSize / 1024;
         if ($maxSizeKB < 1024) {
             $maxSizeKB = DataUtil::formatNumber($maxSizeKB);
             $allowedSize = $maxSizeKB . ' KB';
             return $allowedSize;
         }
         $maxSizeMB = $maxSizeKB / 1024;
         $maxSizeMB = DataUtil::formatNumber($maxSizeMB);
         $allowedSize = $maxSizeMB . ' MB';
         return $allowedSize;
     } else {
         $allowedSize = __('No limit');
     }
     return $allowedSize;
 }
コード例 #2
0
/**
 * Format number.
 *
 * Example:
 *   {$MyVar|formatnumber}
 *
 * @param string $string         The contents to transform.
 * @param mixed  $decimal_points Desc : null=default locale, false=precision, int=precision.
 *
 * @return string The modified output.
 */
function smarty_modifier_formatNumber($string, $decimal_points = null)
{
    return DataUtil::formatNumber($string, $decimal_points);
}
コード例 #3
0
ファイル: FloatInput.php プロジェクト: projectesIF/Sirius
 /**
  * Render event handler.
  *
  * @param Zikula_Form_View $view Reference to Zikula_Form_View object.
  *
  * @return string The rendered output
  */
 public function render(Zikula_Form_View $view)
 {
     $this->text = DataUtil::formatNumber($this->text, $this->precision);
     return Zikula_Form_Plugin_TextInput::render($view);
 }
コード例 #4
0
ファイル: UploadHandler.php プロジェクト: robbrandt/MUVideo
 /**
  * Check if an upload file meets all validation criteria.
  *
  * @param string $objectType Currently treated entity type.
  * @param array $file Reference to data of uploaded file.
  * @param string $fieldName  Name of upload field.
  *
  * @return boolean true if file is valid else false
  */
 protected function validateFileUpload($objectType, $file, $fieldName)
 {
     $dom = ZLanguage::getModuleDomain('MUVideo');
     $serviceManager = ServiceUtil::getManager();
     // check if a file has been uploaded properly without errors
     if (!is_array($file) || is_array($file) && $file['error'] != '0') {
         if (is_array($file)) {
             return $this->handleError($file);
         }
         return LogUtil::registerError(__('Error! No file found.', $dom));
     }
     // extract file extension
     $fileName = $file['name'];
     $fileNameParts = explode('.', $fileName);
     $extension = strtolower($fileNameParts[count($fileNameParts) - 1]);
     $extension = str_replace('jpeg', 'jpg', $extension);
     // validate extension
     $isValidExtension = $this->isAllowedFileExtension($objectType, $fieldName, $extension);
     if ($isValidExtension === false) {
         return LogUtil::registerError(__('Error! This file type is not allowed. Please choose another file format.', $dom));
     }
     // validate file size
     $maxSize = $this->allowedFileSizes[$objectType][$fieldName];
     if ($maxSize > 0) {
         $fileSize = filesize($file['tmp_name']);
         if ($fileSize > $maxSize) {
             $maxSizeKB = $maxSize / 1024;
             if ($maxSizeKB < 1024) {
                 $maxSizeKB = DataUtil::formatNumber($maxSizeKB);
                 return LogUtil::registerError(__f('Error! Your file is too big. Please keep it smaller than %s kilobytes.', array($maxSizeKB), $dom));
             }
             $maxSizeMB = $maxSizeKB / 1024;
             $maxSizeMB = DataUtil::formatNumber($maxSizeMB);
             return LogUtil::registerError(__f('Error! Your file is too big. Please keep it smaller than %s megabytes.', array($maxSizeMB), $dom));
         }
     }
     // validate image file
     $isImage = in_array($extension, $this->imageFileTypes);
     if ($isImage) {
         $imgInfo = getimagesize($file['tmp_name']);
         if (!is_array($imgInfo) || !$imgInfo[0] || !$imgInfo[1]) {
             return LogUtil::registerError(__('Error! This file type seems not to be a valid image.', $dom));
         }
     }
     return true;
 }
コード例 #5
0
ファイル: FloatInput.php プロジェクト: planetenkiller/core
 /**
  * Format the value to specific format.
  *
  * @param Zikula_Form_View $view  Reference to Zikula_Form_View object.
  * @param string           $value The value to format.
  *
  * @return string Formatted value.
  */
 function formatValue(Zikula_Form_View $view, $value)
 {
     return DataUtil::formatNumber($value, $this->precision);
 }