Ejemplo n.º 1
0
 public function actionThumbnail()
 {
     list($content, $album) = $this->_getVideoOrError();
     $contentDataModel = $this->_getVideoDataModel();
     if (!$content['canEdit']) {
         throw $this->_throwFriendlyNoPermission('sonnb_xengallery_you_do_not_have_permission_to_change_thumbnail_this_video');
     }
     if ($this->isConfirmedPost()) {
         $thumbnail = sonnb_XenGallery_Model_PhotoUpload::getUploadedFile('thumbnail');
         $contentDataModel->uploadVideoThumbnail($thumbnail, $content);
         return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildPublicLink('gallery/videos', $content), new XenForo_Phrase('redirect_changes_saved_successfully'));
     } else {
         $viewParams = array('content' => $content, 'album' => $album);
         return $this->responseView('sonnb_XenGallery_ViewPublic_Video_Thumbnail', 'sonnb_xengallery_video_thumbnail', $viewParams);
     }
 }
Ejemplo n.º 2
0
 public static function getUploadedFile($formField, array $source = null)
 {
     $files = sonnb_XenGallery_Model_PhotoUpload::getUploadedFiles($formField, $source);
     return reset($files);
 }
Ejemplo n.º 3
0
 public function actionDoUpload()
 {
     $this->_assertPostOnly();
     $input = $this->_input->filter(array('hash' => XenForo_Input::STRING, 'album_id' => XenForo_Input::UINT));
     if (!$input['hash']) {
         $input['hash'] = $this->_input->filterSingle('temp_hash', XenForo_Input::STRING);
     }
     $this->_assertPhpUploadError();
     $this->_assertCanUploadContents();
     $contentDataModel = $this->_getPhotoDataModel();
     $contentModel = $this->_getPhotoModel();
     $conditions = array('content_type' => sonnb_XenGallery_Model_Photo::$contentType);
     $existingPhotoData = $input['album_id'] ? $this->_getPhotoModel()->countContentsByAlbumId($input['album_id'], $conditions) : 0;
     $newPhotoData = $contentDataModel->countDataByHash($input['hash'], $conditions);
     $maxPhotoCounts = $contentModel->getPhotoCountLimit();
     if ($maxPhotoCounts > 0 && $existingPhotoData + $newPhotoData >= $maxPhotoCounts) {
         return $this->responseError(new XenForo_Phrase('sonnb_xengallery_you_may_upload_maximum_x_photos_to_this_album_only', array('total' => $maxPhotoCounts)));
     }
     $contentDataConstraints = $contentModel->getPhotoDataConstraints();
     if ($contentDataConstraints['count'] > 0) {
         $remainingUploads = $contentDataConstraints['count'] - (count($existingPhotoData) + count($newPhotoData));
         if ($remainingUploads <= 0) {
             return $this->responseError(new XenForo_Phrase('you_may_not_upload_more_files_with_message_allowed_x', array('total' => $contentDataConstraints['count'])));
         }
     }
     $file = sonnb_XenGallery_Model_PhotoUpload::getUploadedFile('upload');
     if (!$file) {
         return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, $this->_buildLink('gallery/photos/upload', false, array('hash' => $input['hash'], 'album_id' => $input['album_id'])));
     }
     $file->setConstraints($contentDataConstraints);
     if (!$file->isImage()) {
         return $this->responseError(new XenForo_Phrase('sonnb_xengallery_our_gallery_currently_accepts_images_only'));
     }
     if (!$file->isValid()) {
         return $this->responseError($file->getErrors());
     }
     if (!$contentModel->canResizeImage($file->getImageInfoField('width'), $file->getImageInfoField('height'))) {
         return $this->responseError(new XenForo_Phrase('sonnb_xengallery_your_photo_is_too_big'));
     }
     $xenOptions = XenForo_Application::getOptions();
     if ($xenOptions->sonnbXG_nudityFilter && $xenOptions->sonnbXG_nudityAction === 'refuse') {
         //TODO: Prevent timeout on slow server
         $score = sonnb_XenGallery_Model_PhotoFilter::getInstance()->getScore($file->getTempFile());
         if ($score > $xenOptions->sonnbXG_nudityScore) {
             return $this->responseError(new XenForo_Phrase('sonnb_xengallery_your_photo_might_contain_nudity_content'));
         }
     }
     if (!$xenOptions->sonnbXG_enableResize) {
         if ($contentDataConstraints['width'] && $file->getImageInfoField('width') > $contentDataConstraints['width'] || $contentDataConstraints['height'] && $file->getImageInfoField('height') > $contentDataConstraints['height']) {
             return $this->responseError(new XenForo_Phrase('sonnb_xengallery_your_photo_is_too_big'));
         }
     }
     $extras = array('temp_hash' => $input['hash'], 'content_type' => sonnb_XenGallery_Model_Photo::$contentType);
     $contentData = $contentDataModel->insertUploadedPhotoData($file, $extras);
     if (empty($contentData['content_data_id'])) {
         return $this->responseError(new XenForo_Phrase('sonnb_xengallery_error_occurred_while_uploading'));
     }
     $message = new XenForo_Phrase('upload_completed_successfully');
     if ($this->_noRedirect()) {
         $viewParams = array('album' => $this->_getAlbumModel()->getAlbumById($input['album_id']), 'content' => $contentDataModel->prepareDataSingle($contentData), 'message' => $message);
         return $this->responseView('sonnb_XenGallery_ViewPublic_Photo_DoUpload', '', $viewParams);
     } else {
         return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, $this->_buildLink('gallery/photos/upload', false, array('hash' => $input['hash'], 'album_id' => $input['album_id'])), $message);
     }
 }