Пример #1
0
 public function actionUploadAvatar()
 {
     $this->_assertPostOnly();
     if (!XenForo_Visitor::getInstance()->canUploadAvatar()) {
         return $this->responseNoPermission();
     }
     $avatar = XenForo_Upload::getUploadedFile('upload');
     $avatarModel = $this->getModelFromCache('XenForo_Model_Avatar');
     $visitor = XenForo_Visitor::getInstance();
     // upload new avatar
     if ($avatar) {
         try {
             $avatarData = $avatarModel->uploadAvatar($avatar, $visitor['user_id'], $visitor->getPermissions());
         } catch (Exception $e) {
             json_error($e->getMessages());
         }
     }
     // merge new data into $visitor, if there is any
     if (isset($avatarData) && is_array($avatarData)) {
         foreach ($avatarData as $key => $val) {
             $visitor[$key] = $val;
         }
     }
     return array('success' => true);
 }
Пример #2
0
 public function doUpload($formField, $hash, $contentType, array $contentData = array())
 {
     if (isset($contentData['forum_id']) and !isset($contentData['node_id'])) {
         $contentData['node_id'] = $contentData['forum_id'];
     }
     $this->_assertCanUploadAndManageAttachments($hash, $contentType, $contentData);
     $attachmentModel = $this->_getAttachmentModel();
     $attachmentHandler = $attachmentModel->getAttachmentHandler($contentType);
     // known to be valid
     $contentId = $attachmentHandler->getContentIdFromContentData($contentData);
     $existingAttachments = $contentId ? $attachmentModel->getAttachmentsByContentId($contentType, $contentId) : array();
     $newAttachments = $attachmentModel->getAttachmentsByTempHash($hash);
     $attachmentConstraints = $attachmentHandler->getAttachmentConstraints();
     if ($attachmentConstraints['count'] > 0) {
         $remainingUploads = $attachmentConstraints['count'] - (count($existingAttachments) + count($newAttachments));
         if ($remainingUploads <= 0) {
             return $this->_controller->responseError(new XenForo_Phrase('you_may_not_upload_more_files_with_message_allowed_x', array('total' => $attachmentConstraints['count'])), 403);
         }
     }
     $file = XenForo_Upload::getUploadedFile($formField);
     if (!$file) {
         return $this->_controller->responseError(new XenForo_Phrase('bdapi_requires_upload_x', array('field' => $formField)), 400);
     }
     $file->setConstraints($attachmentConstraints);
     if (!$file->isValid()) {
         return $this->_controller->responseError($file->getErrors(), 403);
     }
     $dataId = $attachmentModel->insertUploadedAttachmentData($file, XenForo_Visitor::getUserId());
     $attachmentId = $attachmentModel->insertTemporaryAttachment($dataId, $hash);
     return $attachmentModel->getAttachmentById($attachmentId);
 }
Пример #3
0
 public function actionSigPicUpload()
 {
     $this->_assertPostOnly();
     if (!XenForo_Visitor::getInstance()->hasPermission('signature', 'sigpic')) {
         return $this->responseNoPermission();
     }
     $sigpic = XenForo_Upload::getUploadedFile('sigpic');
     $sigpicModel = $this->getModelFromCache('TPUSigPic_Model_SigPic');
     $visitor = XenForo_Visitor::getInstance();
     $inputData = $this->_input->filter(array('delete' => XenForo_Input::UINT));
     if ($sigpic) {
         $sigpicData = $sigpicModel->uploadSigPic($sigpic, $visitor['user_id'], $visitor->getPermissions());
     } else {
         if ($inputData['delete']) {
             $sigpicData = $sigpicModel->deleteSigPic(XenForo_Visitor::getUserId());
         }
     }
     if (isset($sigpicData) && is_array($sigpicData)) {
         foreach ($sigpicData as $key => $val) {
             $visitor[$key] = $val;
         }
     }
     $message = new XenForo_Phrase('upload_completed_successfully');
     if ($this->_noRedirect()) {
         // TODO
     } else {
         return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildPublicLink('account/signature'), $message);
     }
 }
Пример #4
0
 /**
  * Displays a form to allow choice of content type and upload box.
  *
  * @return XenForo_ControllerResponse_Abstract
  */
 public function actionUpload()
 {
     $adminImageModel = $this->_getAdminImageModel();
     $adminImages = XenForo_Upload::getUploadedFiles('admin_image');
     $input = $this->_input->filter(array('type' => XenForo_Input::STRING, 'type_id' => array(XenForo_Input::UINT, 'array' => true)));
     if (empty($adminImages) || !$input['type'] || !$input['type_id']) {
         $typeHandlers = $this->_getAdminImageModel()->getAdminImageHandlers();
         $contentTypes = array_keys($typeHandlers);
         if (!$input['type']) {
             $input['type'] = reset($contentTypes);
         }
         $viewParams = array('type' => $input['type'], 'typeId' => $input['type_id'], 'typeHandlers' => $typeHandlers);
         return $this->responseView('ThemeHouse_AdminImages_ViewAdmin_AdminImage_Upload', 'th_admin_image_upload_adminimages', $viewParams);
     }
     $this->_assertPostOnly();
     $handler = $adminImageModel->getAdminImageHandlers($input['type']);
     $contentId = isset($input['type_id'][$input['type']]) ? $input['type_id'][$input['type']] : 0;
     if (!$handler->getContentTitle($contentId)) {
         return $this->responseError(new XenForo_Phrase('th_please_select_a_valid_attach_to_item_adminimages'), 404);
     }
     $adminImage = reset($adminImages);
     $attachmentModel = $this->_getAttachmentModel();
     if ($adminImage->isImage()) {
         $dataId = $attachmentModel->insertUploadedAttachmentData($adminImage, XenForo_Visitor::getUserId());
         $attachmentId = $attachmentModel->insertTemporaryAttachment($dataId, 'adminimage-' . $input['type'] . '-' . $input['type_id'][$input['type']]);
         $this->_getAdminImageModel()->associateAttachment($input['type'], $input['type_id'][$input['type']]);
     } else {
         throw $this->responseException($this->responseError(new XenForo_Phrase('th_uploaded_file_is_not_an_image_adminimages')));
     }
     return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildAdminLink('images'));
 }
Пример #5
0
 /**
  *
  * @return XenForo_ControllerResponse_Abstract
  */
 public function actionImport()
 {
     $fieldModel = $this->_getFieldModel();
     if ($this->isConfirmedPost()) {
         $input = $this->_input->filter(array('target' => XenForo_Input::STRING, 'display_group' => XenForo_Input::STRING, 'overwrite_field_id' => XenForo_Input::STRING));
         $upload = XenForo_Upload::getUploadedFile('upload');
         if (!$upload) {
             return $this->responseError(new XenForo_Phrase('please_upload_valid_field_xml_file'));
         }
         if ($input['target'] == 'overwrite') {
             $field = $this->_getFieldOrError($input['overwrite_field_id']);
             $input['display_group'] = $field['display_group'];
         }
         $document = $this->getHelper('Xml')->getXmlFromFile($upload);
         $caches = $fieldModel->importFieldXml($document, $input['display_group'], $input['overwrite_field_id']);
         if (XenForo_Application::$versionId < 1020000) {
             return XenForo_CacheRebuilder_Abstract::getRebuilderResponse($this, $caches, XenForo_Link::buildAdminLink('user-fields'));
         } else {
             return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildAdminLink('user-fields'));
         }
     } else {
         $fieldModel = $this->_getFieldModel();
         $viewParams = array('displayGroups' => $fieldModel->getUserFieldGroups(), 'fields' => $fieldModel->prepareUserFields($fieldModel->getUserFields()));
         return $this->responseView('Waindigo_CustomFields_ViewAdmin_UserField_Import', 'user_field_import', $viewParams);
     }
 }
 public function insertUploadedAttachmentData(XenForo_Upload $file, $userId, array $extra = array())
 {
     $filename = $file->getFileName();
     $extension = XenForo_Helper_File::getFileExtension($filename);
     if ($extension == 'svg') {
         list($svgfile, $dimensions) = $this->extractDimensionsForSVG($file->getTempFile(), XenForo_Application::getOptions()->SV_RejectAttachmentWithBadTags);
         if (!empty($svgfile) && !empty($dimensions)) {
             if ($dimensions['thumbnail_width'] && $dimensions['thumbnail_height']) {
                 $tempThumbFile = tempnam(XenForo_Helper_File::getTempDir(), 'xf');
                 if ($tempThumbFile) {
                     // update the width/height attributes
                     $svgfile['width'] = (string) $dimensions['thumbnail_width'];
                     $svgfile['height'] = (string) $dimensions['thumbnail_height'];
                     $svgfile->asXML($tempThumbFile);
                     SV_AttachmentImprovements_Globals::$tempThumbFile = $tempThumbFile;
                 }
             }
             SV_AttachmentImprovements_Globals::$forcedDimensions = $dimensions;
         }
     }
     return parent::insertUploadedAttachmentData($file, $userId, $extra);
 }
Пример #7
0
 public function actionImport()
 {
     $moderatorModel = $this->_getModeratorModel();
     if ($this->isConfirmedPost()) {
         $input = $this->_input->filter(array('overwrite' => XenForo_Input::UINT));
         $upload = XenForo_Upload::getUploadedFile('upload');
         if (!$upload) {
             return $this->responseError(new XenForo_Phrase('th_please_upload_valid_moderator_xml_file_moderators'));
         }
         $document = $this->getHelper('Xml')->getXmlFromFile($upload);
         $caches = $moderatorModel->importModeratorsXml($document, $input['overwrite']);
         return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildAdminLink('moderators'));
     } else {
         return $this->responseView('ThemeHouse_Moderators_ViewAdmin_Moderator_Import', 'th_moderator_import_moderators');
     }
 }
Пример #8
0
 public function actionImportXml()
 {
     if ($this->isConfirmedPost()) {
         /* @var $smilieModel XenForo_Model_Smilie */
         $smilieModel = $this->_getSmilieModel();
         $input = $this->_input->filter(array('overwrite' => XenForo_Input::UINT));
         $upload = XenForo_Upload::getUploadedFile('upload');
         if (!$upload) {
             return $this->responseError(new XenForo_Phrase('waindigo_please_upload_valid_smilies_xml_file_smilieimporter'));
         }
         $document = $this->getHelper('Xml')->getXmlFromFile($upload);
         $caches = $smilieModel->importSmiliesXml($document, $input['overwrite']);
         return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildAdminLink('smilies'));
     } else {
         return $this->responseView('Waindigo_SmilieImporter_ViewAdmin_Smilie_Import', 'waindigo_smilie_import_smilieimporter');
     }
 }
Пример #9
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);
 }
Пример #10
0
 public function actionIconUpload()
 {
     $this->_assertPostOnly();
     $nodeId = $this->_input->filterSingle('node_id', XenForo_Input::INT);
     $number = 1;
     $category = $this->_getNodeModel()->getNodeById($nodeId);
     $icons = XenForo_Upload::getUploadedFiles('icon');
     $icon = reset($icons);
     $iconModel = $this->getModelFromCache('Brivium_CustomNodeStyle_Model_Icon');
     if ($icon) {
         $iconModel->uploadIcon($icon, $category, $number, 'category');
     } else {
         if ($this->_input->filterSingle('delete', XenForo_Input::UINT)) {
             $iconModel->deleteIcon($category['node_id'], $number, true, 'category');
         }
     }
     return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildAdminLink('nodes/edit', $category));
 }
Пример #11
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);
 }
Пример #12
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);
 }
Пример #13
0
 public function actionImport()
 {
     $userGroupModel = $this->_getUserGroupModel();
     if ($this->isConfirmedPost()) {
         $input = $this->_input->filter(array('target' => XenForo_Input::STRING, 'overwrite_user_group_id' => XenForo_Input::UINT));
         $upload = XenForo_Upload::getUploadedFile('upload');
         if (!$upload) {
             return $this->responseError(new XenForo_Phrase('th_please_upload_valid_user_group_xml_file_usergroups'));
         }
         if ($input['target'] == 'overwrite') {
             $this->_getUserGroupOrError($input['overwrite_user_group_id']);
         } else {
             $input['overwrite_user_group_id'] = 0;
         }
         $document = $this->getHelper('Xml')->getXmlFromFile($upload);
         $caches = $userGroupModel->importUserGroupXml($document, $input['overwrite_user_group_id']);
         return XenForo_CacheRebuilder_Abstract::getRebuilderResponse($this, $caches, XenForo_Link::buildAdminLink('user-groups'));
     } else {
         $viewParams = array('userGroups' => $userGroupModel->getAllUserGroups());
         return $this->responseView('ThemeHouse_UserGroups_ViewAdmin_UserGroup_Import', 'th_user_group_import_usergroups', $viewParams);
     }
 }
Пример #14
0
 public function actionUploadAttachment()
 {
     $vals = $this->_input->filter(array('poststarttime' => XenForo_Input::STRING, 'forumid' => XenForo_Input::UINT));
     try {
         $this->_assertCanUploadAndManageAttachments($vals['poststarttime'], 'post', array('node_id' => $vals['forumid']));
     } catch (Exception $e) {
         json_error($e->getControllerResponse()->errorText->render(), RV_UPLOAD_ERROR);
     }
     $contentid = 0;
     $attachment_model = $this->_getAttachmentModel();
     $attachment_handler = $attachment_model->getAttachmentHandler('post');
     $existing = array();
     $new_attachments = $attachment_model->getAttachmentsByTempHash($vals['poststarttime']);
     $max = $attachment_handler->getAttachmentCountLimit();
     if ($max !== true) {
         $remaining = $max - (count($existing) + count($new));
         if ($remaining <= 0) {
             $error = new XenForo_Phrase('you_may_not_upload_more_files_with_message');
             json_error($error->render(), RV_UPLOAD_ERROR);
         }
     }
     $cons = $attachment_model->getAttachmentConstraints();
     $file = XenForo_Upload::getUploadedFile('attachment');
     if (!$file) {
         $error = new XenForo_Phrase('do_not_have_permission');
         json_error($error->render(), RV_UPLOAD_ERROR);
     }
     $file->setConstraints($cons);
     if (!$file->isValid()) {
         $error_text = '';
         foreach ($file->getErrors() as $error) {
             $error_text .= $error->render() . "\n";
         }
         json_error($error_text, RV_UPLOAD_ERROR);
     }
     $dataid = $attachment_model->insertUploadedAttachmentData($file, XenForo_Visitor::getUserId());
     $attachmentid = $attachment_model->insertTemporaryAttachment($dataid, $vals['poststarttime']);
     return array('attachmentid' => $attachmentid);
 }
Пример #15
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);
 }
Пример #16
0
 public function actionImportForm()
 {
     $this->_assertPostOnly();
     $input = $this->_input->filter(array('mode' => XenForo_Input::STRING, 'directory' => XenForo_Input::STRING));
     $smilieModel = $this->_getSmilieModel();
     $smilieCategoryOptions = $smilieModel->getSmilieCategoryOptions();
     if ($input['mode'] == 'upload') {
         $upload = XenForo_Upload::getUploadedFile('upload');
         if (!$upload) {
             return $this->responseError(new XenForo_Phrase('please_upload_valid_smilies_xml_file'));
         }
         $document = $this->getHelper('Xml')->getXmlFromFile($upload);
         $smilieData = $smilieModel->getSmilieDataFromXml($document, $smilieCategoryOptions);
     } else {
         $smilieData = $smilieModel->getSmilieDataFromDirectory($input['directory']);
     }
     $viewParams = array('uploadMode' => $input['mode'] == 'upload', 'smilies' => $smilieData['smilies'], 'newSmilieCategories' => $smilieData['newSmilieCategories'], 'newSmilieCategoryOptions' => $smilieData['newSmilieCategoryOptions'], 'smilieCategoryOptions' => $smilieCategoryOptions);
     return $this->responseView('XenForo_ViewAdmin_Smilie_ImportForm', 'smilie_import_form', $viewParams);
 }
Пример #17
0
 /**
  * Inserts uploaded attachment data.
  *
  * @param XenForo_Upload $file Uploaded attachment info. Assumed to be valid
  * @param integer $userId User ID uploading
  * @param array $extra Extra params to set
  *
  * @return integer Attachment data ID
  */
 public function insertUploadedAttachmentData(XenForo_Upload $file, $userId, array $extra = array())
 {
     if ($file->isImage() && XenForo_Image_Abstract::canResize($file->getImageInfoField('width'), $file->getImageInfoField('height'))) {
         $dimensions = array('width' => $file->getImageInfoField('width'), 'height' => $file->getImageInfoField('height'));
         $tempThumbFile = tempnam(XenForo_Helper_File::getTempDir(), 'xf');
         if ($tempThumbFile) {
             $image = XenForo_Image_Abstract::createFromFile($file->getTempFile(), $file->getImageInfoField('type'));
             if ($image) {
                 if ($image->thumbnail(XenForo_Application::get('options')->attachmentThumbnailDimensions)) {
                     $image->output($file->getImageInfoField('type'), $tempThumbFile);
                 } else {
                     copy($file->getTempFile(), $tempThumbFile);
                     // no resize necessary, use the original
                 }
                 $dimensions['thumbnail_width'] = $image->getWidth();
                 $dimensions['thumbnail_height'] = $image->getHeight();
                 unset($image);
             }
         }
     } else {
         $tempThumbFile = '';
         $dimensions = array();
     }
     try {
         $dataDw = XenForo_DataWriter::create('XenForo_DataWriter_AttachmentData');
         $dataDw->bulkSet($extra);
         $dataDw->set('user_id', $userId);
         $dataDw->set('filename', $file->getFileName());
         $dataDw->bulkSet($dimensions);
         $dataDw->setExtraData(XenForo_DataWriter_AttachmentData::DATA_TEMP_FILE, $file->getTempFile());
         if ($tempThumbFile) {
             $dataDw->setExtraData(XenForo_DataWriter_AttachmentData::DATA_TEMP_THUMB_FILE, $tempThumbFile);
         }
         $dataDw->save();
     } catch (Exception $e) {
         if ($tempThumbFile) {
             @unlink($tempThumbFile);
         }
         throw $e;
     }
     if ($tempThumbFile) {
         @unlink($tempThumbFile);
     }
     // TODO: add support for "on rollback" behavior
     return $dataDw->get('data_id');
 }
Пример #18
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);
 }
Пример #19
0
 public function actionImport()
 {
     $styleModel = $this->_getStyleModel();
     if ($this->isConfirmedPost()) {
         $input = $this->_input->filter(array('target' => XenForo_Input::STRING, 'parent_style_id' => XenForo_Input::UINT, 'overwrite_style_id' => XenForo_Input::UINT));
         $upload = XenForo_Upload::getUploadedFile('upload');
         if (!$upload) {
             return $this->responseError(new XenForo_Phrase('please_upload_valid_style_xml_file'));
         }
         if ($input['target'] == 'overwrite') {
             $this->_getStyleOrError($input['overwrite_style_id']);
             $input['parent_style_id'] = 0;
         } else {
             $input['overwrite_style_id'] = 0;
         }
         $document = $this->getHelper('Xml')->getXmlFromFile($upload);
         $styleModel->importStyleXml($document, $input['parent_style_id'], $input['overwrite_style_id']);
         return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildAdminLink('styles'));
     } else {
         $viewParams = array('styles' => $styleModel->getAllStylesAsFlattenedTree());
         return $this->responseView('XenForo_ViewAdmin_Style_Import', 'style_import', $viewParams);
     }
 }
Пример #20
0
 /**
  * Gets the file that was uploaded into the specified form field (via HTTP POST).
  *
  * @param string $formField Name of the form field
  * @param array|null $source Source array ($_FILES by default).
  *
  * @return XenForo_Upload (or false)
  */
 public static function getUploadedFile($formField, array $source = null)
 {
     $files = XenForo_Upload::getUploadedFiles($formField, $source);
     return reset($files);
 }
Пример #21
0
 public function actionImport()
 {
     $fieldModel = $this->_getFieldModel();
     if ($this->isConfirmedPost()) {
         $input = $this->_input->filter(array('target' => XenForo_Input::STRING, 'field_group_id' => XenForo_Input::UINT, 'overwrite_field_id' => XenForo_Input::STRING));
         $upload = XenForo_Upload::getUploadedFile('upload');
         if (!$upload) {
             return $this->responseError(new XenForo_Phrase('please_upload_valid_field_xml_file'));
         }
         if ($input['target'] == 'overwrite') {
             $field = $this->_getFieldOrError($input['overwrite_field_id']);
             $input['field_group_id'] = $field['field_group_id'];
         }
         $document = $this->getHelper('Xml')->getXmlFromFile($upload);
         $caches = $fieldModel->importFieldXml($document, $input['field_group_id'], $input['overwrite_field_id']);
         return XenForo_CacheRebuilder_Abstract::getRebuilderResponse($this, $caches, XenForo_Link::buildAdminLink('thread-fields'));
     } else {
         $fieldModel = $this->_getFieldModel();
         $viewParams = array('fieldGroupOptions' => $fieldModel->getThreadFieldGroupOptions(), 'fields' => $fieldModel->prepareThreadFields($fieldModel->getThreadFields()));
         return $this->responseView('Waindigo_CustomFields_ViewAdmin_ThreadField_Import', 'thread_field_import', $viewParams);
     }
 }
Пример #22
0
 public function actionCoverUpload()
 {
     $this->_assertPostOnly();
     $cover = XenForo_Upload::getUploadedFile('cover');
     $user = $this->_getAuthorOrError();
     if (!$this->_getGalleryModel()->canManageCover($user)) {
         throw $this->_throwFriendlyNoPermission();
     }
     $input = $this->_input->filter(array('crop_x' => XenForo_Input::UINT, 'crop_y' => XenForo_Input::UINT, 'width' => XenForo_Input::UINT, 'height' => XenForo_Input::UINT, 'delete' => XenForo_Input::UINT));
     if ($cover) {
         $oldCover = $this->_getGalleryModel()->getAuthorCoverFile($user);
         $return = $this->_getGalleryModel()->uploadAuthorCover($cover, $user['user_id']);
         if ($return) {
             if (isset($user['sonnb_xengallery_cover']['bdattachmentstore_engine'])) {
                 $engine = $user['sonnb_xengallery_cover']['bdattachmentstore_engine'];
                 $options = $user['sonnb_xengallery_cover']['bdattachmentstore_options'];
                 $keepLocalCopy = !empty($options['keepLocalCopy']);
                 if (empty($engine) || !empty($engine) && $keepLocalCopy) {
                     $oldLocalCover = $this->_getGalleryModel()->getAuthorCoverFile($user, true);
                     @unlink($oldLocalCover);
                 }
                 if (!empty($engine)) {
                     $this->_bdAttachmentStore_getFileModel()->deleteFile($engine, $options, $oldCover);
                 }
             } else {
                 $oldLocalCover = $this->_getGalleryModel()->getAuthorCoverFile($user, true);
                 @unlink($oldLocalCover);
             }
         }
     } elseif ($input['delete']) {
         $return = $this->_getGalleryModel()->deleteAuthorCover($user);
     } elseif ($input['crop_x'] || $input['crop_y'] || $input['height']) {
         $return = $this->_getGalleryModel()->cropAuthorCover($user, $input['crop_x'], $input['crop_y'], $input['width'], $input['height']);
     } else {
         return $this->responseView('sonnb_XenGallery_ViewPublic_Author_CoverUpload', 'sonnb_xengallery_cover_upload', array('cover' => "", 'url' => "", 'message' => ""));
     }
     if ($return === false) {
         throw $this->_throwFriendlyNoPermission('unexpected_error_occurred');
     } else {
         $user['sonnb_xengallery_cover'] = $return;
     }
     $message = new XenForo_Phrase('sonnb_xengallery_your_cover_has_been_saved');
     if ($this->_noRedirect()) {
         return $this->responseView('sonnb_XenGallery_ViewPublic_Author_CoverUpload', 'sonnb_xengallery_cover_upload', array('cover' => $user['sonnb_xengallery_cover'], 'url' => $this->_getGalleryModel()->getAuthorCoverUrl($user), 'message' => $message));
     } else {
         return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildPublicLink('gallery/authors'), $message);
     }
 }
Пример #23
0
 public function actionIconUpload()
 {
     $this->_assertPostOnly();
     $category = $this->_getCategoryOrError();
     $icon = XenForo_Upload::getUploadedFiles('icon');
     $icon = reset($icon);
     $categoryModel = $this->_getCategoryModel();
     if ($icon) {
         $categoryModel->uploadCategoryIcon($icon, $category['team_category_id']);
     } else {
         if ($this->_input->filterSingle('delete', XenForo_Input::UINT)) {
             $categoryModel->deleteCategoryIcon($category['team_category_id']);
         }
     }
     return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildAdminLink('team-categories') . $this->getLastHash($category['team_category_id']));
 }
Пример #24
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);
 }
Пример #25
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);
 }
Пример #26
0
 public function actionPostAvatar()
 {
     $user = $this->_getUserOrError();
     $visitor = XenForo_Visitor::getInstance();
     if ($user['user_id'] != $visitor->get('user_id')) {
         return $this->responseNoPermission();
     }
     if (!$visitor->canUploadAvatar()) {
         return $this->responseNoPermission();
     }
     $avatar = XenForo_Upload::getUploadedFile('avatar');
     if (empty($avatar)) {
         return $this->responseError(new XenForo_Phrase('bdapi_requires_upload_x', array('field' => 'avatar')), 400);
     }
     /* @var $avatarModel XenForo_Model_Avatar */
     $avatarModel = $this->getModelFromCache('XenForo_Model_Avatar');
     $avatarModel->uploadAvatar($avatar, $visitor->get('user_id'), $visitor->getPermissions());
     return $this->responseMessage(new XenForo_Phrase('upload_completed_successfully'));
 }
Пример #27
0
 public function actionAvatarUpload()
 {
     $this->_assertPostOnly();
     if (!XenForo_Visitor::getInstance()->canUploadAvatar()) {
         return $this->responseNoPermission();
     }
     $avatar = XenForo_Upload::getUploadedFile('avatar');
     /* @var $avatarModel XenForo_Model_Avatar */
     $avatarModel = $this->getModelFromCache('XenForo_Model_Avatar');
     /* @var $visitor XenForo_Visitor */
     $visitor = XenForo_Visitor::getInstance();
     $inputData = $this->_input->filter(array('delete' => XenForo_Input::UINT, 'avatar_crop_x' => XenForo_Input::UINT, 'avatar_crop_y' => XenForo_Input::UINT, 'gravatar' => XenForo_Input::STRING, 'use_gravatar' => XenForo_Input::UINT));
     // upload new avatar
     if ($avatar) {
         $avatarData = $avatarModel->uploadAvatar($avatar, $visitor['user_id'], $visitor->getPermissions());
     } else {
         if ($inputData['delete']) {
             $avatarData = $avatarModel->deleteAvatar(XenForo_Visitor::getUserId());
         } else {
             if (XenForo_Application::get('options')->gravatarEnable && $inputData['use_gravatar']) {
                 if (!$inputData['gravatar']) {
                     $inputData['gravatar'] = $visitor['email'];
                 }
                 if (!XenForo_Model_Avatar::gravatarExists($inputData['gravatar'], $errorText)) {
                     return $this->responseError($errorText);
                 } else {
                     $avatarData = array('gravatar' => $inputData['gravatar']);
                     $this->_saveVisitorSettings($avatarData, $errors);
                 }
             } else {
                 if ($inputData['avatar_crop_x'] != $visitor['avatar_crop_x'] || $inputData['avatar_crop_y'] != $visitor['avatar_crop_y']) {
                     $avatarData = $avatarModel->recropAvatar(XenForo_Visitor::getUserId(), $inputData['avatar_crop_x'], $inputData['avatar_crop_y']);
                 } else {
                     if ($visitor['gravatar'] && !$inputData['use_gravatar']) {
                         $avatarData = array('gravatar' => '');
                         $this->_saveVisitorSettings($avatarData, $errors);
                     }
                 }
             }
         }
     }
     // merge new data into $visitor, if there is any
     if (isset($avatarData) && is_array($avatarData)) {
         foreach ($avatarData as $key => $val) {
             $visitor[$key] = $val;
         }
     }
     $message = new XenForo_Phrase('upload_completed_successfully');
     // return a view if noredirect has been requested and we are not deleting
     if ($this->_noRedirect()) {
         return $this->responseView('XenForo_ViewPublic_Account_AvatarUpload', 'account_avatar_upload', array('user' => $visitor->toArray(), 'sizeCode' => 'm', 'maxWidth' => XenForo_Model_Avatar::getSizeFromCode('m'), 'maxDimension' => $visitor['avatar_width'] > $visitor['avatar_height'] ? 'height' : 'width', 'width' => $visitor['avatar_width'], 'height' => $visitor['avatar_height'], 'cropX' => $visitor['avatar_crop_x'], 'cropY' => $visitor['avatar_crop_y'], 'user_id' => $visitor['user_id'], 'avatar_date' => $visitor['avatar_date'], 'gravatar' => $visitor['gravatar'], 'message' => $message));
     } else {
         return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildPublicLink('account/personal-details'), $message);
     }
 }
Пример #28
0
 public function actionIcon()
 {
     list($resource, $category) = $this->_getResourceHelper()->assertResourceValidAndViewable();
     $resourceModel = $this->_getResourceModel();
     if (!$resourceModel->canEditResourceIcon($resource, $category, $errorPhraseKey)) {
         throw $this->getErrorOrNoPermissionResponseException($errorPhraseKey);
     }
     if ($this->isConfirmedPost()) {
         $icon = XenForo_Upload::getUploadedFile('icon');
         $delete = $this->_input->filterSingle('delete', XenForo_Input::BOOLEAN);
         if ($icon) {
             $resourceModel->uploadResourceIcon($icon, $resource['resource_id']);
         } else {
             if ($delete) {
                 $resourceModel->deleteResourceIcon($resource['resource_id']);
             }
         }
         return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildPublicLink('resources', $resource));
     } else {
         $viewParams = array('resource' => $resource, 'category' => $category, 'iconSize' => XenResource_Model_Resource::$iconSize);
         return $this->responseView('XenResource_ViewPublic_Resource_Icon', 'resource_icon', $viewParams);
     }
 }
Пример #29
0
 public function actionDoDownload()
 {
     $mediaHelper = $this->_getMediaHelper();
     $mediaHelper->assertCanAddMedia();
     $this->_assertPostOnly();
     $input = $this->_input->filter(array('hash' => XenForo_Input::STRING, 'content_type' => XenForo_Input::STRING, 'upload_type' => XenForo_Input::STRING, 'content_data' => array(XenForo_Input::UINT, 'array' => true), 'key' => XenForo_Input::STRING, 'image_url' => XenForo_Input::STRING, 'unique_key' => XenForo_Input::STRING));
     if (!$input['hash']) {
         $input['hash'] = $this->_input->filterSingle('temp_hash', XenForo_Input::STRING);
     }
     $this->_assertCanUploadAndManageAttachments($input['hash'], $input['content_type'], $input['content_data']);
     $attachmentModel = $this->_getAttachmentModel();
     $attachmentHandler = $attachmentModel->getAttachmentHandler($input['content_type']);
     // known to be valid
     $contentId = $attachmentHandler->getContentIdFromContentData($input['content_data']);
     $existingAttachments = $contentId ? $attachmentModel->getAttachmentsByContentId($input['content_type'], $contentId) : array();
     $newAttachments = $attachmentModel->getAttachmentsByTempHash($input['hash']);
     $attachmentConstraints = $attachmentHandler->getUploadConstraints($input['upload_type']);
     if ($attachmentConstraints['count'] > 0) {
         $remainingUploads = $attachmentConstraints['count'] - (count($existingAttachments) + count($newAttachments));
         if ($remainingUploads <= 0) {
             return $this->responseError(new XenForo_Phrase('you_may_not_upload_more_files_with_message_allowed_x', array('total' => $attachmentConstraints['count'])));
         }
     }
     $fileModel = $this->_getFileModel();
     $url = $input['image_url'];
     if (!($tempName = $fileModel->addToFilesFromUrl($input['unique_key'], $url, $error))) {
         return $this->responseError($error);
     }
     $file = XenForo_Upload::getUploadedFile($input['unique_key']);
     if (!$file) {
         return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildPublicLink('xengallery/files/upload', false, array('hash' => $input['hash'], 'content_type' => $input['content_type'], 'content_data' => $input['content_data'], 'key' => $input['key'])));
     }
     $file->setConstraints($attachmentConstraints);
     if (!$file->isValid()) {
         return $this->responseError($file->getErrors());
     }
     if (!$file->isImage()) {
         return $this->responseError(new XenForo_Phrase('xengallery_files_added_by_url_must_be_images'));
     }
     $dataId = $fileModel->insertUploadedAttachmentData($file, XenForo_Visitor::getUserId());
     $attachmentId = $attachmentModel->insertTemporaryAttachment($dataId, $input['hash']);
     $message = new XenForo_Phrase('upload_completed_successfully');
     @unlink($tempName);
     // return a view if noredirect has been requested and we are not deleting
     if ($this->_noRedirect()) {
         return $this->_getUploadResponse($attachmentId, $input, $message);
     } else {
         return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildPublicLink('xengallery/files/upload', false, array('hash' => $input['hash'], 'content_type' => $input['content_type'], 'content_data' => $input['content_data'], 'key' => $input['key'])), $message);
     }
 }
Пример #30
0
 /**
  * Updates a user's avatar.
  *
  * @return XenForo_ControllerResponse_Abstract
  */
 public function actionAvatarUpload()
 {
     $this->_assertPostOnly();
     $userId = $this->_input->filterSingle('user_id', XenForo_Input::UINT);
     $user = $this->_getUserOrError($userId);
     $this->getHelper('Admin')->checkSuperAdminEdit($user);
     $avatars = XenForo_Upload::getUploadedFiles('avatar');
     $avatar = reset($avatars);
     /* @var $avatarModel XenForo_Model_Avatar */
     $avatarModel = $this->getModelFromCache('XenForo_Model_Avatar');
     if ($avatar) {
         $avatarModel->uploadAvatar($avatar, $user['user_id'], false);
     } else {
         if ($this->_input->filterSingle('delete', XenForo_Input::UINT)) {
             $avatarModel->deleteAvatar($user['user_id']);
         }
     }
     return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildAdminLink('users/edit', $user));
 }