/**
  *
  * @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;
 }
 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');
     }
 }