public function upload() { JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $app = JFactory::getApplication(); /** @var $app JApplicationSite */ $userId = JFactory::getUser()->get('id'); $response = new Prism\Response\Json(); if (!$userId) { $response->setTitle(JText::_('COM_SOCIALCOMMUNITY_FAILUREURE'))->setText(JText::_('COM_SOCIALCOMMUNITY_ERROR_INVALID_PROFILE'))->failure(); echo $response; $app->close(); } try { // Get image $image = $this->input->files->get('profile_image', array(), 'array'); $file = null; // Upload image if (!empty($image['name'])) { $params = JComponentHelper::getParams('com_socialcommunity'); $filesystemHelper = new Prism\Filesystem\Helper($params); $model = $this->getModel(); $fileData = $model->uploadImage($image, $filesystemHelper->getTemporaryMediaFolder(JPATH_BASE)); if (!empty($fileData['filename'])) { $file = JUri::base() . $filesystemHelper->getTemporaryMediaFolderUri() . '/' . $fileData['filename']; $app->setUserState(Socialcommunity\Constants::TEMPORARY_IMAGE_CONTEXT, $fileData['filename']); } } } catch (Exception $e) { throw new Exception(JText::_('COM_SOCIALCOMMUNITY_ERROR_SYSTEM')); } if (!$file) { $response->setTitle(JText::_('COM_SOCIALCOMMUNITY_FAILUREURE'))->setText(JText::_('COM_SOCIALCOMMUNITY_ERROR_FILE_CANNOT_BE_UPLOADED'))->failure(); } else { $response->setTitle(JText::_('COM_SOCIALCOMMUNITY_SUCCESS'))->setText(JText::_('COM_SOCIALCOMMUNITY_FILE_UPLOADED_SUCCESSFULLY'))->setData(array('image' => $file))->success(); } echo $response; $app->close(); }
protected function prepareAvatar() { $model = JModelLegacy::getInstance('Avatar', 'SocialCommunityModel', $config = array('ignore_request' => false)); $this->state = $model->getState(); $this->params = $this->state->get('params'); $filesystemHelper = new Prism\Filesystem\Helper($this->params); $this->mediaFolder = $filesystemHelper->getMediaFolderUri($this->userId); $this->item = $model->getItem($this->userId); $file = basename($this->app->getUserState(Socialcommunity\Constants::TEMPORARY_IMAGE_CONTEXT)); $this->fileForCropping = !$file ? null : JUri::base() . $filesystemHelper->getTemporaryMediaFolderUri() . '/' . $file; $this->displayRemoveButton = 'none'; $js = ' var socialCommunityOptions = {'; if (!$this->params->get('image_aspect_ratio', '')) { $js .= ' aspectRatio: ""'; } else { $js .= ' aspectRatio: ' . $this->params->get('image_aspect_ratio', ''); } $js .= ' }'; $this->document->addScriptDeclaration($js); }