コード例 #1
0
ファイル: Extension.php プロジェクト: bokultis/kardiomedika
 /**
  * Defined by Zend_Validate_Interface
  *
  * Returns true if and only if the imagesize of $value is at least min and
  * not bigger than max
  *
  * @param  string $value Real file to check for image size
  * @param  array  $file  File data from Zend_File_Transfer
  * @return boolean
  */
 public function isValid($value, $file = null)
 {
     if ($file === null) {
         $file = array('type' => null, 'name' => $value);
     }
     if (isset($this->_dir)) {
         $value = $this->_dir . "/" . $value;
     }
     return parent::isValid($value, $file);
 }
コード例 #2
0
ファイル: RenderImage.php プロジェクト: laiello/digitalus-cms
 /**
  * comments
  */
 public function renderImage($src, $height = '', $width = '', $attribs = array('class' => 'icon'))
 {
     $absPath = BASE_PATH . '/' . $src;
     $validator = new Zend_Validate_File_Extension(array('jpg', 'jpeg', 'gif', 'png'));
     if (!is_file($absPath) || !$validator->isValid($src)) {
         return '<span>' . $src . '</span>';
     }
     if ($src != '' && is_file($absPath)) {
         $imageSize = getimagesize($absPath);
         $srcHeight = $imageSize[0];
         $srcWidth = $imageSize[1];
         $percentage = 1.0;
         //if the height is greater than the width then adjust by the height
         //otherwise adjust by the width
         if (isset($height) && !empty($height) && $srcHeight > $srcWidth) {
             $percentage = $height / $srcHeight;
         } elseif (isset($width) && !empty($width)) {
             $percentage = $width / $srcWidth;
         }
         if (isset($height) && !empty($height)) {
             $height = 'height:' . round($srcHeight * $percentage) . 'px; ';
         } else {
             $height = '';
         }
         if (isset($width) && !empty($width)) {
             //gets the new value and applies the percentage, then rounds the value
             $width = 'width:' . round($srcWidth * $percentage) . 'px; ';
         } else {
             $width = '';
         }
         $attributes = null;
         if (is_array($attribs)) {
             foreach ($attribs as $k => $v) {
                 $attributes .= $k . "='" . $v . "' ";
             }
         }
         return '<img style="' . $width . $height . '" src="' . $this->view->getBaseUrl() . '/' . $src . '" ' . $attributes . ' />';
     }
 }
コード例 #3
0
 /**
  * Returns true if and only if the fileextension of $value is included in 
  * the set extension list.
  *
  * @param string $value Real file to check for extension.
  * @param array $file File data from Zend_File_Transfer.
  * @return boolean
  */
 public function isValid($value, $file = null)
 {
     // Is file readable ?
     require_once 'Zend/Loader.php';
     if (!Zend_Loader::isReadable($value)) {
         return $this->_throw($file, self::NOT_FOUND);
     }
     if ($file !== null) {
         $info['extension'] = substr($file['name'], strrpos($file['name'], '.') + 1);
     } else {
         $info = pathinfo($value);
     }
     //set the target extension
     $this->_targetExtension = $info['extension'];
     return parent::isValid($value, $file);
 }
コード例 #4
0
 /**
  * Defined by Zend_Validate_Interface
  *
  * Returns true if and only if the imagesize of $value is at least min and
  * not bigger than max
  *
  * @param  string $value Real file to check for image size
  * @param  array  $file  File data from Zend_File_Transfer
  * @return boolean
  */
 public function isValid($value, $file = null)
 {
     $this->_loadParams();
     $extensions = $this->_fields[$this->_fieldId]['params']['extensions'];
     if (is_array($extensions) && count($extensions)) {
         foreach ($extensions as $ext) {
             $this->addExtension($ext);
         }
     }
     if ($file === null) {
         $file = array('type' => null, 'name' => $value);
     }
     if (isset($this->_dir)) {
         $value = $this->_dir . "/" . $value;
     }
     return parent::isValid($value, $file);
 }
コード例 #5
0
 /**
  * Ensures that addExtension() returns expected value
  *
  * @return void
  */
 public function testAddExtension()
 {
     $validator = new Zend_Validate_File_Extension('mo');
     $validator->addExtension('gif');
     $this->assertEquals('mo,gif', $validator->getExtension());
     $this->assertEquals(array('mo', 'gif'), $validator->getExtension(true));
     $validator->addExtension('jpg, to');
     $this->assertEquals('mo,gif,jpg,to', $validator->getExtension());
     $this->assertEquals(array('mo', 'gif', 'jpg', 'to'), $validator->getExtension(true));
     $validator->addExtension(array('zip', 'ti'));
     $this->assertEquals('mo,gif,jpg,to,zip,ti', $validator->getExtension());
     $this->assertEquals(array('mo', 'gif', 'jpg', 'to', 'zip', 'ti'), $validator->getExtension(true));
 }
コード例 #6
0
 /**
  *
  * @param type $extensions
  * @param type $messages_prefixed
  * @return \Zend_Validate_File_Extension 
  */
 protected function _getValidatorFileExtensions($extensions, $messages_prefixed = "")
 {
     $file = new Zend_Validate_File_Extension($extensions);
     $file->setMessage(sprintf($this->_translate('ERROR_FILE_FALSE_EXTENSION'), $this->_translate($messages_prefixed)), Zend_Validate_File_Extension::FALSE_EXTENSION);
     return $file;
 }
コード例 #7
0
 public function uploadAction()
 {
     $page_id = $this->_getParam('page_id');
     if ($this->getRequest()->isPost()) {
         $uploadPath = APPLICATION_ROOT . '/public_html/images/page';
         //var_dump($uploadPath);die();
         $uploadAdapter = new Zend_File_Transfer_Adapter_Http();
         $uploadAdapter->setDestination($uploadPath);
         $uploadAdapter->setOptions(array('ignoreNoFile' => true));
         $extValidator = new Zend_Validate_File_Extension('jpg,png,gif');
         $extValidator->setMessage('Ongeldige foto extensie', Zend_Validate_File_Extension::FALSE_EXTENSION);
         $uploadAdapter->addValidator($extValidator);
         $uploadAdapter->receive();
         $messages = $uploadAdapter->getMessages();
         if (count($messages)) {
             $this->_helper->layout()->disableLayout();
             $this->view->result = Zend_Json::encode(array('success' => false));
             return;
         }
         $basePath = APPLICATION_ROOT . '/public_html/images/page/page_' . $page_id;
         $old_umask = umask(0);
         if (!is_dir($basePath)) {
             mkdir($basePath, 0777, true);
         }
         if (!is_dir($basePath . '/100x100')) {
             mkdir($basePath . '/100x100', 0777, true);
         }
         if (!is_dir($basePath . '/726x1035')) {
             mkdir($basePath . '/726x1035', 0777, true);
         }
         umask($old_umask);
         $files = $uploadAdapter->getFilename(null, false);
         if (!is_array($files)) {
             $files = array($files);
         }
         $text = $this->_getParam('text');
         foreach ($files as $key => $filename) {
             $picnumber = substr($key, 8, 1);
             $oFname = $uploadPath . '/' . $filename;
             if (!$oFname) {
                 continue;
             }
             $ext = '.' . strtolower(substr(strrchr($oFname, '.'), 1));
             $nFname = $basePath . '/' . md5(time() . $oFname) . $ext;
             rename($oFname, $nFname);
             $im = new Imagick($nFname);
             $im->cropThumbnailImage(100, 100);
             $im->writeImage($basePath . '/100x100/' . basename($nFname));
             $im = new Imagick($nFname);
             $im->cropThumbnailImage(726, 1035);
             $im->writeImage($basePath . '/726x1035/' . basename($nFname));
             //count al items in DB en doe +1 voor de laatste positite aan de foto toe te kennen
             $x = new SxCms_Page_Picture_Proxy();
             $x = $x->countByPage($page_id) + 1;
             //save pic
             $picture = new SxCms_Page_Picture();
             $picture->setPageId($page_id);
             $picture->setFile(basename($nFname));
             $picture->setText($text[$picnumber]);
             $picture->setSeason(0);
             $picture->setPlace($x);
             $picture->save();
         }
         $this->_helper->layout()->disableLayout();
         $this->view->result = Zend_Json::encode(array('success' => true));
         $this->render('result');
     }
 }
コード例 #8
0
ファイル: FileServer.php プロジェクト: bokultis/kardiomedika
 /**
  * Unzip file
  *
  * @param string $path
  * @return boolean
  */
 public function unzip($path, $newDir = false)
 {
     $filePath = $this->getRealPath($path);
     if (!file_exists($filePath)) {
         $this->returnError('File does not exists ' . $path);
         return false;
     }
     // get the absolute path to $file
     $dir = pathinfo($filePath, PATHINFO_DIRNAME);
     $packageName = pathinfo($filePath, PATHINFO_FILENAME);
     if ($newDir) {
         $dir .= DIRECTORY_SEPARATOR . $packageName;
     }
     $zip = new ZipArchive();
     $res = $zip->open($filePath);
     if (!$res) {
         $this->returnError('Cannot extract file');
         return false;
     }
     $tmpDir = APPLICATION_PATH . '/../tmp/' . session_id() . '-' . $packageName;
     $zip->extractTo($tmpDir);
     $zip->close();
     //check size
     $extractSize = $this->_helper->getDirSize($tmpDir);
     if ($extractSize > $this->_helper->getFreeSpace()) {
         $this->_rrmdir($tmpDir);
         $this->returnError('Not enough space on disk');
         return false;
     }
     $files = array();
     $this->_rlistFiles($tmpDir, $files);
     $mimeValidator = new Zend_Validate_File_MimeType($this->_helper->getDefaultMimeTypes());
     $extValidator = new Zend_Validate_File_Extension($this->_helper->getDefaultExtensions());
     foreach ($files as $currFile) {
         if (!$extValidator->isValid($currFile)) {
             $this->_rrmdir($tmpDir);
             $this->returnError(sprintf('File [%s] has invalid extension.', basename($currFile)));
             return false;
         }
         if (!$mimeValidator->isValid($currFile)) {
             $this->_rrmdir($tmpDir);
             $this->returnError(sprintf('File [%s] has invalid mime type.', basename($currFile)));
             return false;
         }
     }
     $this->_rcopy($tmpDir, $dir);
     $this->_rrmdir($tmpDir);
     return true;
 }