Пример #1
0
 /**
  * Processes an image upload for a content.
  *
  * @param XenForo_Upload $upload The uploaded image.
  * @param integer $contentId Content ID image belongs to
  * @param array|false $permissions User's permissions. False to skip permission checks
  *
  * @return array Changed image fields
  */
 public function uploadImage(XenForo_Upload $upload, $contentId, $permissions)
 {
     $largestDimension = $this->getSizeFromCode('l');
     if (!$upload->isValid()) {
         throw new XenForo_Exception($upload->getErrors(), true);
     }
     if (!$upload->isImage()) {
         throw new XenForo_Exception(new XenForo_Phrase('uploaded_file_is_not_valid_image'), true);
     }
     $imageType = $upload->getImageInfoField('type');
     //prd($imageType);
     if (!in_array($imageType, array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
         throw new XenForo_Exception(new XenForo_Phrase('uploaded_file_is_not_valid_image'), true);
     }
     $baseTempFile = $upload->getTempFile();
     $width = $upload->getImageInfoField('width');
     $height = $upload->getImageInfoField('height');
     return $this->applyImage($contentId, $baseTempFile, $imageType, $width, $height, $permissions);
 }
Пример #2
0
 public function uploadAvatar(XenForo_Upload $upload, $teamId)
 {
     if (!$teamId) {
         throw new Nobita_Teams_Exception_Abstract('Missing team ID.');
     }
     if (!$upload->isValid()) {
         throw new Nobita_Teams_Exception_Abstract($upload->getErrors(), true);
     }
     if (!$upload->isImage()) {
         throw new Nobita_Teams_Exception_Abstract(new XenForo_Phrase('uploaded_file_is_not_valid_image'), true);
     }
     $imageType = $upload->getImageInfoField('type');
     if (!in_array($imageType, array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
         throw new Nobita_Teams_Exception_Abstract(new XenForo_Phrase('uploaded_file_is_not_valid_image'), true);
     }
     $baseTempFile = $upload->getTempFile();
     $width = $upload->getImageInfoField('width');
     $height = $upload->getImageInfoField('height');
     if ($width < 280 || $height < 280) {
         throw new Nobita_Teams_Exception_Abstract(new XenForo_Phrase('Teams_avatar_required_least_280x280_pixels'), true);
     }
     return $this->applyAvatar($teamId, $baseTempFile, $imageType, $width, $height);
 }
Пример #3
0
 /**
  * Processes an cover upload for a user.
  *
  * @param XenForo_Upload $upload The uploaded cover.
  * @param integer $teamId User ID cover belongs to
  *
  * @return array Changed cover fields
  */
 public function uploadCoverPhoto(XenForo_Upload $upload, $teamId, $existingCoverDate)
 {
     if (!$teamId) {
         throw new Nobita_Teams_Exception_Abstract("Missing team ID");
     }
     if (!$upload->isValid()) {
         throw new Nobita_Teams_Exception_Abstract($upload->getErrors(), true);
     }
     if (!$upload->isImage()) {
         throw new Nobita_Teams_Exception_Abstract(new XenForo_Phrase('uploaded_file_is_not_valid_image'), true);
     }
     $imageType = $upload->getImageInfoField('type');
     if (!in_array($imageType, array(IMAGETYPE_PNG, IMAGETYPE_JPEG))) {
         throw new Nobita_Teams_Exception_Abstract(new XenForo_Phrase('uploaded_file_is_not_valid_image'), true);
     }
     $baseTempFile = $upload->getTempFile();
     $width = $upload->getImageInfoField('width');
     $height = $upload->getImageInfoField('height');
     if ($height < self::$minHeight) {
         throw new Nobita_Teams_Exception_Abstract(new XenForo_Phrase('Teams_upload_image_greater_x', array('min' => self::$minHeight)), true);
     }
     return $this->applyCover($teamId, $baseTempFile, $imageType, $width, $height, $existingCoverDate);
 }
Пример #4
0
 /**
  * Processes an avatar upload for a user.
  *
  * @param XenForo_Upload $upload The uploaded avatar.
  * @param integer $userId User ID avatar belongs to
  * @param array|false $permissions User's permissions. False to skip permission checks
  *
  * @return array Changed avatar fields
  */
 public function uploadAvatar(XenForo_Upload $upload, $userId, $permissions)
 {
     if (!$userId) {
         throw new XenForo_Exception('Missing user ID.');
     }
     if ($permissions !== false && !is_array($permissions)) {
         throw new XenForo_Exception('Invalid permission set.');
     }
     $largestDimension = $this->getSizeFromCode('l');
     if (!$upload->isValid()) {
         throw new XenForo_Exception($upload->getErrors(), true);
     }
     if (!$upload->isImage()) {
         throw new XenForo_Exception(new XenForo_Phrase('uploaded_file_is_not_valid_image'), true);
     }
     $imageType = $upload->getImageInfoField('type');
     if (!in_array($imageType, array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
         throw new XenForo_Exception(new XenForo_Phrase('uploaded_file_is_not_valid_image'), true);
     }
     $baseTempFile = $upload->getTempFile();
     $width = $upload->getImageInfoField('width');
     $height = $upload->getImageInfoField('height');
     return $this->applyAvatar($userId, $baseTempFile, $imageType, $width, $height, $permissions);
 }
Пример #5
0
 public function uploadAuthorCover(XenForo_Upload $cover, $userId)
 {
     if (!$userId) {
         return false;
     }
     if (!$cover->isValid()) {
         throw new XenForo_Exception($cover->getErrors(), true);
     }
     if (!$cover->isImage()) {
         throw new XenForo_Exception(new XenForo_Phrase('uploaded_file_is_not_valid_image'), true);
     }
     $imageType = $cover->getImageInfoField('type');
     if (!isset(sonnb_XenGallery_Model_ContentData::$extensionMap[$imageType])) {
         throw new XenForo_Exception(new XenForo_Phrase('uploaded_file_is_not_valid_image'), true);
     }
     $baseTempFile = $cover->getTempFile();
     $width = $cover->getImageInfoField('width');
     $height = $cover->getImageInfoField('height');
     return $this->applyAuthorCover($baseTempFile, $userId, $imageType, $width, $height);
 }
Пример #6
0
 public function uploadVideoThumbnail(XenForo_Upload $upload, array $video)
 {
     if (!$video) {
         return false;
     }
     if (!$upload->isValid()) {
         throw new XenForo_Exception($upload->getErrors(), true);
     }
     if (!$upload->isImage()) {
         throw new XenForo_Exception(new XenForo_Phrase('uploaded_file_is_not_valid_image'), true);
     }
     $baseTempFile = $upload->getTempFile();
     $imageType = $upload->getImageInfoField('type');
     $width = $upload->getImageInfoField('width');
     $height = $upload->getImageInfoField('height');
     return $this->applyVideoThumbnail($video, $baseTempFile, $imageType, $width, $height);
 }
Пример #7
0
 public function uploadCategoryIcon(XenForo_Upload $upload, $categoryId)
 {
     if (!$categoryId) {
         throw new XenForo_Exception("Missing category ID.");
     }
     if (!$upload->isValid()) {
         throw new XenForo_Exception($upload->getErrors(), true);
     }
     if (!$upload->isImage()) {
         throw new XenForo_Exception(new XenForo_Phrase('uploaded_file_is_not_valid_image'), true);
     }
     $baseTempFile = $upload->getTempFile();
     $imageType = $upload->getImageInfoField('type');
     $width = $upload->getImageInfoField('width');
     $height = $upload->getImageInfoField('height');
     return $this->applyCategoryIcon($categoryId, $baseTempFile, $imageType, $width, $height);
 }
Пример #8
0
 public function uploadMediaThumbnail(XenForo_Upload $upload, array $media)
 {
     if (!$media) {
         throw new XenForo_Exception('Missing media record.');
     }
     if (!$upload->isValid()) {
         throw new XenForo_Exception($upload->getErrors(), true);
     }
     if (!$upload->isImage()) {
         throw new XenForo_Exception(new XenForo_Phrase('uploaded_file_is_not_valid_image'), true);
     }
     $baseTempFile = $upload->getTempFile();
     $imageType = $upload->getImageInfoField('type');
     $width = $upload->getImageInfoField('width');
     $height = $upload->getImageInfoField('height');
     return $this->processMediaThumbnail($media, $baseTempFile, $imageType, $width, $height);
 }