/** * Pre-processor for $table->delete($pk) * * @param mixed $pk An optional primary key value to delete. If not set the instance property value is used. * * @return void * * @since 3.1.2 * @throws UnexpectedValueException */ public function onBeforeDelete($pk) { $db = $this->table->getDbo(); jimport('Socialcommunity.profile'); $profile = new Socialcommunity\Profile\Profile($db); $profile->load($this->table->id); if ($profile->getId()) { $params = JComponentHelper::getParams('com_socialcommunity'); /** @var $params Joomla\Registry\Registry */ $filesystemHelper = new Prism\Filesystem\Helper($params); $mediaFolder = $filesystemHelper->getMediaFolderUri($profile->getId()); $filesystem = $filesystemHelper->getFilesystem(); $profile->removeImages($filesystem, $mediaFolder); } }
/** * This method store a post by user. */ public function storePost() { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ $content = $this->input->getString('content'); $user = JFactory::getUser(); $userId = $user->get('id'); $content = JString::trim(strip_tags($content)); $content = JHtmlString::truncate($content, 140); if (!$userId) { $app->close(); } $userTimeZone = !$user->getParam('timezone') ? null : $user->getParam('timezone'); try { $date = new JDate('now', $userTimeZone); $entity = new Socialcommunity\Wall\User\Post(JFactory::getDbo()); $entity->setUserId($userId); $entity->setContent($content); $entity->setCreated($date->toSql(true)); $entity->store(); } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception(JText::_('COM_SOCIALCOMMUNITY_ERROR_SYSTEM')); } $params = JComponentHelper::getParams('com_socialcommunity'); $filesystemHelper = new Prism\Filesystem\Helper($params); $mediaFolder = $filesystemHelper->getMediaFolderUri($userId); $profile = new Socialcommunity\Profile\Profile(JFactory::getDbo()); $profile->load(['user_id' => $userId]); $displayData = new stdClass(); $displayData->id = $entity->getId(); $displayData->profileLink = JRoute::_(SocialCommunityHelperRoute::getProfileRoute($profile->getSlug()), false); $displayData->name = htmlentities($profile->getName(), ENT_QUOTES, 'utf-8'); $displayData->alias = htmlentities($profile->getAlias(), ENT_QUOTES, 'utf-8'); $displayData->imageSquare = $mediaFolder . '/' . $profile->getImageSquare(); $displayData->imageAlt = $displayData->name; $displayData->content = $entity->getContent(); $displayData->created = JHtml::_('socialcommunity.created', $entity->getCreated(), $userTimeZone); $layout = new JLayoutFile('wall_post'); echo $layout->render($displayData); $app->close(); }
public function display($tpl = null) { $this->option = JFactory::getApplication()->input->get('option'); $this->state = $this->get('State'); $this->item = $this->get('Item'); $this->form = $this->get('Form'); $this->params = $this->state->get('params'); if (!$this->item->id) { $app = JFactory::getApplication(); $app->enqueueMessage(JText::_('COM_SOCIALCOMMUNITY_NO_PROFILE'), 'notice'); $app->redirect(JRoute::_('index.php?option=com_socialcommunity&view=profiles', false)); return; } $filesystemHelper = new Prism\Filesystem\Helper($this->params); $this->mediaFolder = $filesystemHelper->getMediaFolderUri($this->item->user_id); // Prepare actions, behaviors, scripts and document $this->addToolbar(); $this->setDocument(); parent::display($tpl); }
public function display($tpl = null) { $this->app = JFactory::getApplication(); $this->option = $this->app->input->get('option'); /** @var $model SocialCommunityModelProfile */ $model = $this->getModel(); $this->state = $model->getState(); $this->item = $model->getItem(); $this->params = $this->state->get('params'); $this->visitorId = $this->state->get($this->option . '.visitor.id'); $this->isOwner = $this->state->get($this->option . '.visitor.is_owner'); $this->targetId = $this->state->get($this->option . '.target.user_id'); // If I am not logged in, and I try to load profile page without user ID as a parameter, // I must load the layout of registration and login form. if (!$this->visitorId and !$this->item) { $this->setLayout('registration'); } // If there is target ID but there is no valid item, // go on the view "No Profile". The profile does not exists. if ($this->targetId and !$this->item) { $this->setLayout('noprofile'); } switch ($this->getLayout()) { case 'registration': $this->prepareRegistration(); break; case 'noprofile': $this->prepareNoProfile(); break; default: // default layout $filesystemHelper = new Prism\Filesystem\Helper($this->params); $this->mediaFolder = $filesystemHelper->getMediaFolderUri($this->item->user_id); // Display details layout if // - visitor is not registered and there is target ID. // - visitor is registered but he is not the owner of the profile. if (!$this->visitorId and $this->targetId or $this->visitorId and !$this->isOwner) { $this->setLayout('details'); // Details page. } else { $this->setLayout('default'); // Profile owner's wall. } // If the wall has been disabled, display profile details. if (!$this->params->get('profile_wall', Prism\Constants::ENABLED)) { $this->setLayout('details'); // Details page. } $pluginContext = 'com_socialcommunity.profile'; switch ($this->getLayout()) { case 'default': $pluginContext .= '.wall'; // If I am logged in and I try to load profile page, // but I do not provide valid profile ID, // I have to display error message. if (!$this->item and $this->visitor->id > 0) { $menu = $this->app->getMenu(); $menuItem = $menu->getDefault(); $this->app->enqueueMessage(JText::_('COM_SOCIALCOMMUNITY_ERROR_INVALID_PROFILE'), 'notice'); $this->app->redirect(JRoute::_('index.php?Itemid=' . $menuItem->id, false)); return; } $this->prepareWall(); break; default: // details $pluginContext .= '.details'; $this->prepareDetails(); break; } // Import content plugins JPluginHelper::importPlugin('content'); // Events $dispatcher = JEventDispatcher::getInstance(); $this->item->event = new stdClass(); $offset = 0; $results = $dispatcher->trigger('onContentBeforeDisplay', array($pluginContext, &$this->item, &$this->params, $offset)); $this->item->event->beforeDisplayContent = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentBeforeDisplayProfile', array($pluginContext, &$this->item, &$this->params)); $this->item->event->beforeDisplayProfileContent = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentAfterDisplayProfile', array($pluginContext, &$this->item, &$this->params)); $this->item->event->afterDisplayProfileContent = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentAfterDisplay', array($pluginContext, &$this->item, &$this->params, $offset)); $this->item->event->afterDisplayContent = trim(implode("\n", $results)); break; } $this->prepareDocument(); parent::display($tpl); }
public function cropImage() { // Check for request forgeries. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $app = JFactory::getApplication(); /** @var $app JApplicationSite */ $response = new Prism\Response\Json(); $userId = JFactory::getUser()->get('id'); if (!$userId) { $response->setTitle(JText::_('COM_SOCIALCOMMUNITY_FAILURE'))->setText(JText::_('COM_SOCIALCOMMUNITY_ERROR_NOT_LOG_IN'))->failure(); echo $response; $app->close(); } // Get the model $model = $this->getModel(); /** @var $model SocialcommunityModelAvatar */ $params = JComponentHelper::getParams('com_socialcommunity'); $filesystemHelper = new Prism\Filesystem\Helper($params); // Get the filename from the session. $fileName = basename($app->getUserState(Socialcommunity\Constants::TEMPORARY_IMAGE_CONTEXT)); $temporaryFolder = $filesystemHelper->getTemporaryMediaFolder(JPATH_BASE); $temporaryFile = JPath::clean($temporaryFolder . '/' . $fileName); if (!$fileName or !JFile::exists($temporaryFile)) { $response->setTitle(JText::_('COM_SOCIALCOMMUNITY_FAILURE'))->setText(JText::_('COM_SOCIALCOMMUNITY_ERROR_FILE_DOES_NOT_EXIST'))->failure(); echo $response; $app->close(); } $imageUrl = ''; try { // Get the folder where the images will be stored $params = JComponentHelper::getParams('com_socialcommunity'); $options = array('width' => $this->input->getFloat('width'), 'height' => $this->input->getFloat('height'), 'x' => $this->input->getFloat('x'), 'y' => $this->input->getFloat('y'), 'destination' => $temporaryFolder); // Resize the picture. $images = $model->cropImage($temporaryFile, $options, $params); jimport('Prism.libs.init'); $temporaryAdapter = new League\Flysystem\Adapter\Local($temporaryFolder); $temporaryFilesystem = new League\Flysystem\Filesystem($temporaryAdapter); $storageFilesystem = $filesystemHelper->getFilesystem(); $manager = new League\Flysystem\MountManager(['temporary' => $temporaryFilesystem, 'storage' => $storageFilesystem]); $mediaFolder = $filesystemHelper->getMediaFolder($userId); $model->moveImages($images, $mediaFolder, $manager); $model->storeImages($userId, $images, $mediaFolder, $storageFilesystem); // Prepare URL to the image. $imageName = basename(Joomla\Utilities\ArrayHelper::getValue($images, 'image_profile')); $imageUrl = $filesystemHelper->getMediaFolderUri($userId) . '/' . $imageName; $app->setUserState(Socialcommunity\Constants::TEMPORARY_IMAGE_CONTEXT, null); } catch (RuntimeException $e) { $response->setTitle(JText::_('COM_SOCIALCOMMUNITY_FAILURE'))->setText($e->getMessage())->failure(); echo $response; $app->close(); } catch (Exception $e) { JLog::add($e->getMessage(), JLog::DEBUG); $response->setTitle(JText::_('COM_SOCIALCOMMUNITY_FAILURE'))->setText(JText::_('COM_SOCIALCOMMUNITY_ERROR_SYSTEM'))->failure(); echo $response; $app->close(); } $response->setTitle(JText::_('COM_SOCIALCOMMUNITY_SUCCESS'))->setText(JText::_('COM_SOCIALCOMMUNITY_IMAGE_SAVED'))->setData($imageUrl)->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); }