/**
  * Remove all sessions for the user name
  *
  * Method is called after user data is deleted from the database
  *
  * @param   array   $user    Holds the user data
  * @param   boolean $success True if user was successfully stored in the database
  * @param   string  $msg     Message
  *
  * @return  boolean
  *
  * @since   1.6
  */
 public function onUserAfterDelete($user, $success, $msg)
 {
     $userId = Joomla\Utilities\ArrayHelper::getValue($user, 'id', 0, 'int');
     if (!$success or !$userId) {
         return false;
     }
     // Remove profile images.
     $profile = new Socialcommunity\Profile\Profile($this->db);
     $profile->load(array('user_id' => $userId));
     if ($profile->getId()) {
         // Remove profile record.
         $query = $this->db->getQuery(true);
         $query->delete($this->db->quoteName('#__itpsc_profiles'))->where($this->db->quoteName('user_id') . '=' . (int) $userId);
         $this->db->setQuery($query);
         $this->db->execute();
         // Remove profile images.
         $params = JComponentHelper::getParams('com_socialcommunity');
         /** @var $params Joomla\Registry\Registry */
         jimport('Prism.libs.init');
         $filesystemHelper = new Prism\Filesystem\Helper($params);
         $mediaFolder = $filesystemHelper->getMediaFolder($userId);
         $filesystem = $filesystemHelper->getFilesystem();
         $profile->removeImages($filesystem, $mediaFolder);
     }
     return true;
 }
 /**
  * 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);
     }
 }
 /**
  * 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();
 }