/** * Delete image */ public function removeImage() { // Check for request forgeries. JSession::checkToken('get') or jexit(JText::_('JINVALID_TOKEN')); $itemId = $this->input->getInt('id', 0); $profile = new Socialcommunity\Profile\Profile(JFactory::getDbo()); $profile->load($itemId); $redirectOptions = array('view' => 'profile', 'id' => $itemId); if (!$profile->getId()) { $this->displayNotice(JText::_('COM_SOCIALCOMMUNITY_INVALID_PROFILE'), $redirectOptions); return; } try { $params = JComponentHelper::getParams('com_socialcommunity'); $filesystemHelper = new Prism\Filesystem\Helper($params); jimport('Prism.libs.init'); $storageFilesystem = $filesystemHelper->getFilesystem(); $mediaFolder = $filesystemHelper->getMediaFolder($profile->getUserId()); $model = $this->getModel(); $model->removeImage($itemId, $mediaFolder, $storageFilesystem); } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception(JText::_('COM_SOCIALCOMMUNITY_ERROR_SYSTEM')); } $this->displayMessage(JText::_('COM_SOCIALCOMMUNITY_IMAGE_DELETED'), $redirectOptions); }
/** * 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); } }
/** * Create profiles for orphan users. */ public static function createProfiles() { $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('a.id, a.name')->from($db->quoteName('#__users', 'a'))->leftJoin($db->quoteName('#__itpsc_profiles', 'b') . ' ON a.id = b.user_id')->where('b.user_id IS NULL'); $db->setQuery($query); $results = $db->loadAssocList(); if ($results !== null and count($results) > 0) { foreach ($results as $result) { $profile = new Socialcommunity\Profile\Profile($db); $data = array('user_id' => $result['id'], 'name' => $result['name'], 'alias' => $result['name'], 'active' => Prism\Constants::ACTIVE); $profile->bind($data); $profile->store(); } } }
/** * 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(); }
private function createProfile($userId, $name) { $data = array('user_id' => (int) $userId, 'name' => $name, 'alias' => $name, 'active' => Prism\Constants::ACTIVE); $profile = new Socialcommunity\Profile\Profile($this->db); $profile->bind($data); $profile->store(); $params = JComponentHelper::getParams('com_socialcommunity'); /** @var $params Joomla\Registry\Registry */ $filesystemHelper = new Prism\Filesystem\Helper($params); // If the filesystem is local, create a user folder. if ($filesystemHelper->isLocal()) { $mediaFolder = JPath::clean(JPATH_BASE . '/' . $filesystemHelper->getMediaFolder($userId), '/'); if (!JFolder::exists($mediaFolder)) { JFolder::create($mediaFolder); } } }