Exemplo n.º 1
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'));
 }
Exemplo n.º 2
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));
 }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
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));
 }
Exemplo n.º 5
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']));
 }