public function executeAvatar(HTTPRequest $request)
 {
     ini_set("memory_limit", '256M');
     $this->page->smarty()->assign('avatar', $this->_profilePro->getAvatar());
     if ($request->fileExists('avatar')) {
         $avatar = $request->fileData('avatar');
         if ($avatar['error'] == 0) {
             $simpleImage = new SimpleImage();
             $simpleImage->load($avatar['tmp_name']);
             if (!is_null($simpleImage->image_type)) {
                 $height = $simpleImage->getHeight();
                 $width = $simpleImage->getWidth();
                 if ($height > $width) {
                     $simpleImage->resizeToHeight(150);
                 } else {
                     $simpleImage->resizeToWidth(150);
                 }
                 $filename = time() . '.jpg';
                 $simpleImage->save($_SERVER['DOCUMENT_ROOT'] . $this->_userDir . $filename);
                 if ($this->_profilePro->getAvatar() != ProfilePro::AVATAR_DEFAULT_PRO) {
                     unlink($_SERVER['DOCUMENT_ROOT'] . $this->_profilePro->getAvatar());
                 }
                 $this->_profilePro->setAvatar($this->_userDir . $filename);
                 $this->_profileProManager->save($this->_profilePro);
                 $this->app->user()->setFlash('avatar-updated');
             } else {
                 $this->app->user()->setFlash('avatar-error');
             }
         } else {
             $this->app->user()->setFlash('avatar-error');
         }
         $this->app->httpResponse()->redirect('/profile-pro');
     }
 }
 private function parsePhoto(HTTPRequest $request, AnnouncementPro $announce)
 {
     ini_set("memory_limit", '512M');
     if ($request->fileExists('photo-main')) {
         $photoMain = $request->fileData('photo-main');
         $this->savePhoto($announce, 'PhotoMain', $photoMain);
     }
     if ($request->fileExists('photo-option-1')) {
         $photoOption1 = $request->fileData('photo-option-1');
         $this->savePhoto($announce, 'PhotoOption1', $photoOption1);
     }
     if ($request->fileExists('photo-option-2')) {
         $photoOption2 = $request->fileData('photo-option-2');
         $this->savePhoto($announce, 'PhotoOption2', $photoOption2);
     }
 }
 private function parsePhoto(HTTPRequest $request, Announcement $announce)
 {
     ini_set("memory_limit", '512M');
     if ($request->postExists('delete-photo-main')) {
         unlink(MediaImage::getAnnounceDirectory($announce) . '/' . $announce->getPhotoMain());
         unlink(MediaImage::getAnnounceDirectory($announce) . '/' . Announcement::THUMBNAILS_PREFIX . $announce->getPhotoMain());
         $announce->setPhotoMain('');
     }
     if ($request->postExists('delete-photo-option-1')) {
         unlink(MediaImage::getAnnounceDirectory($announce) . '/' . $announce->getPhotoOption1());
         unlink(MediaImage::getAnnounceDirectory($announce) . '/' . Announcement::THUMBNAILS_PREFIX . $announce->getPhotoOption1());
         $announce->setPhotoOption1('');
     }
     if ($request->postExists('delete-photo-option-2')) {
         unlink(MediaImage::getAnnounceDirectory($announce) . '/' . $announce->getPhotoOption2());
         unlink(MediaImage::getAnnounceDirectory($announce) . '/' . Announcement::THUMBNAILS_PREFIX . $announce->getPhotoOption2());
         $announce->setPhotoOption2('');
     }
     if ($request->fileExists('photo-main')) {
         $photoMain = $request->fileData('photo-main');
         $this->savePhoto($announce, 'PhotoMain', $photoMain);
     }
     if ($request->fileExists('photo-option-1')) {
         $photoOption1 = $request->fileData('photo-option-1');
         $this->savePhoto($announce, 'PhotoOption1', $photoOption1);
     }
     if ($request->fileExists('photo-option-2')) {
         $photoOption2 = $request->fileData('photo-option-2');
         $this->savePhoto($announce, 'PhotoOption2', $photoOption2);
     }
 }