public function display($tpl = null)
 {
     $doc = JFactory::getDocument();
     $my = JFactory::getUser();
     EDC::setPageTitle(JText::_('COM_EASYDISCUSS_PAGETITLE_ASSIGNED'));
     $this->setPathway(JText::_('COM_EASYDISCUSS_BREADCRUMB_ASSIGNED'));
     if (!EDC::isModerator()) {
         return JError::raiseError(404, JText::_('COM_EASYDISCUSS_YOU_ARE_NOT_ALLOWED_HERE'));
     }
     $subs = array();
     // [Model:Assigned]
     $model = EDC::getModel('Assigned');
     $posts = $model->getPosts();
     $posts = EDC::formatPost($posts);
     $posts = Discusshelper::getPostStatusAndTypes($posts);
     // Get total number of posts assigned to the current user.
     $totalAssigned = $model->getTotalAssigned($my->id);
     // Get total number of posts that is assigned to this user and resolved.
     // [Model:Assigned]
     $totalResolved = $model->getTotalSolved($my->id);
     // Calculate percentage
     $percentage = 0;
     if ($posts) {
         $percentage = round($totalResolved / $totalAssigned * 100, 2);
     }
     $theme = new DiscussThemes();
     $theme->set('totalAssigned', $totalAssigned);
     $theme->set('totalResolved', $totalResolved);
     $theme->set('percentage', $percentage);
     $theme->set('posts', $posts);
     echo $theme->fetch('assigned.php');
 }
Exemple #2
0
 /**
  * Retrieve similar question based on the keywords
  *
  * @access	public
  * @param	string	$keywords
  */
 public static function getSimilarQuestion($text = '')
 {
     if (empty($text)) {
         return '';
     }
     $config = Discusshelper::getConfig();
     if (!$config->get('main_similartopic', 0)) {
         return '';
     }
     // $text   = 'how to configure facebook integration?';
     $itemLimit = $config->get('main_similartopic_limit', '5');
     $db = DiscussHelper::getDBO();
     // remove punctuation from the string.
     $text = preg_replace("/(?![.=\$'â?])\\p{P}/u", "", $text);
     //$text = preg_replace("/(?![.=$'â?)\p{P}/u", "", $text);
     $queryExclude = '';
     if (!$config->get('main_similartopic_privatepost', 0)) {
         $excludeCats = DiscussHelper::getPrivateCategories();
         if (!empty($excludeCats)) {
             $queryExclude .= ' AND a.`category_id` NOT IN (' . implode(',', $excludeCats) . ')';
         }
     }
     // lets check if db has more than 2 records or not.
     $query = 'SELECT COUNT(1) FROM `#__discuss_posts` as a';
     $query .= ' WHERE a.`published` = ' . $db->Quote('1');
     $query .= ' AND a.`parent_id` = ' . $db->Quote('0');
     $query .= $queryExclude;
     $db->setQuery($query);
     $rCount = $db->loadResult();
     if ($rCount <= 2) {
         // full index search will fail if record has only two. So we do a normal like search.
         $phrase = 'or';
         $words = explode(' ', $text);
         $wheres = array();
         foreach ($words as $word) {
             $word = $db->Quote('%' . $db->getEscaped($word, true) . '%', false);
             $wheres2 = array();
             $wheres2[] = 'a.title LIKE ' . $word;
             $wheres2[] = 'a.content LIKE ' . $word;
             $wheres[] = implode(' OR ', $wheres2);
         }
         $whereString = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wheres) . ')';
         $query = 'select a.`id`,  a.`title`, 0 AS score';
         $query .= ' FROM `#__discuss_posts` as a';
         $query .= ' WHERE a.`published` = ' . $db->Quote('1');
         $query .= ' AND a.`parent_id` = ' . $db->Quote('0');
         $query .= ' AND ' . $whereString;
         $query .= $queryExclude;
         $query .= ' LIMIT ' . $itemLimit;
         $db->setQuery($query);
         $result = $db->loadObjectList();
         return $result;
     }
     // we know table has more than 3 records.
     // lets do a full index search.
     // lets get the tags match the keywords
     $tagkeywords = explode(' ', $text);
     for ($i = 0; $i < count($tagkeywords); $i++) {
         if (JString::strlen($tagkeywords[$i]) > 3) {
             $tagkeywords[$i] = $tagkeywords[$i] . '*';
         } else {
             $tagkeywords[$i] = $tagkeywords[$i];
         }
     }
     $tagkeywords = implode(' ', $tagkeywords);
     $query = 'select `id` FROM `#__discuss_tags`';
     $query .= ' WHERE MATCH(`title`) AGAINST (' . $db->Quote($tagkeywords) . ' IN BOOLEAN MODE)';
     $db->setQuery($query);
     $tagResults = $db->loadResultArray();
     // now try to get the main topic
     $query = 'select a.`id`,  a.`title`, MATCH(a.`title`,a.`content`) AGAINST (' . $db->Quote($text) . ' WITH QUERY EXPANSION) AS score';
     $query .= ' FROM `#__discuss_posts` as a';
     $query .= ' WHERE MATCH(a.`title`,a.`content`) AGAINST (' . $db->Quote($text) . ' WITH QUERY EXPANSION)';
     $query .= ' AND a.`published` = ' . $db->Quote('1');
     $query .= ' AND a.`parent_id` = ' . $db->Quote('0');
     $query .= $queryExclude;
     $tagQuery = '';
     if (count($tagResults) > 0) {
         $tagQuery = 'select a.`id`,  a.`title`, MATCH(a.`title`,a.`content`) AGAINST (' . $db->Quote($text) . ' WITH QUERY EXPANSION) AS score';
         $tagQuery .= ' FROM `#__discuss_posts` as a';
         $tagQuery .= ' 	INNER JOIN `#__discuss_posts_tags` as b ON a.id = b.post_id';
         $tagQuery .= ' WHERE MATCH(a.`title`,a.`content`) AGAINST (' . $db->Quote($text) . ' WITH QUERY EXPANSION)';
         $tagQuery .= ' AND a.`published` = ' . $db->Quote('1');
         $tagQuery .= ' AND a.`parent_id` = ' . $db->Quote('0');
         $tagQuery .= ' AND b.`tag_id` IN (' . implode(',', $tagResults) . ')';
         $tagQuery .= $queryExclude;
         $query = 'SELECT * FROM (' . $query . ' UNION ' . $tagQuery . ') AS x LIMIT ' . $itemLimit;
     } else {
         $query .= ' LIMIT ' . $itemLimit;
     }
     $db->setQuery($query);
     $result = $db->loadObjectList();
     return $result;
 }
    return;
}
require_once $path;
// require_once (dirname(__FILE__) . '/helper.php');
DiscussHelper::loadStylesheet("module", "mod_easydiscuss_your_discussions");
$my = JFactory::getUser();
$config = DiscussHelper::getConfig();
$profile = DiscussHelper::getTable('Profile');
$profile->load($my->id);
$postsModel = DiscussHelper::getModel('Posts');
$count = $params->get('count', 5);
$posts = array();
$posts = $postsModel->getPostsBy('user', $profile->id, 'latest', '0', '', '', $count);
$posts = DiscussHelper::formatPost($posts);
if (!empty($posts)) {
    $posts = Discusshelper::getPostStatusAndTypes($posts);
    // foreach( $posts as $post )
    // {
    // 	// Translate post status from integer to string
    // 	switch( $post->post_status )
    // 	{
    // 		case '0':
    // 			$post->post_status = '';
    // 			break;
    // 		case '1':
    // 			$post->post_status = JText::_( 'COM_EASYDISCUSS_POST_STATUS_ON_HOLD' );
    // 			break;
    // 		case '2':
    // 			$post->post_status = JText::_( 'COM_EASYDISCUSS_POST_STATUS_ACCEPTED' );
    // 			break;
    // 		case '3':
 public function tab()
 {
     // always reset the limitstart.
     JRequest::setVar('limitstart', 0);
     $type = JRequest::getVar('type');
     $profileId = JRequest::getVar('id');
     $ajax = DiscussHelper::getHelper('ajax');
     $model = DiscussHelper::getModel('Posts');
     $tagsModel = DiscussHelper::getModel('Tags');
     $config = DiscussHelper::getConfig();
     $template = new DiscussThemes();
     $html = '';
     $pagination = null;
     switch ($type) {
         case 'tags':
             $tags = $tagsModel->getTagCloud('', '', '', $profileId);
             $template->set('tags', $tags);
             $html = $template->fetch('profile.tags.php');
             break;
         case 'questions':
             $posts = $model->getPostsBy('user', $profileId);
             $posts = DiscussHelper::formatPost($posts);
             $pagination = $model->getPagination();
             $template->set('posts', $posts);
             $html = $template->fetch('profile.questions.php');
             break;
         case 'unresolved':
             $posts = $model->getUnresolvedFromUser($profileId);
             $posts = DiscussHelper::formatPost($posts);
             $pagination = $model->getPagination();
             $posts = Discusshelper::getPostStatusAndTypes($posts);
             $template->set('posts', $posts);
             $html = $template->fetch('profile.unresolved.php');
             break;
         case 'favourites':
             if (!$config->get('main_favorite')) {
                 return false;
             }
             $posts = $model->getData(true, 'latest', null, 'favourites', '', null, 'all', $profileId);
             $posts = DiscussHelper::formatPost($posts);
             $posts = Discusshelper::getPostStatusAndTypes($posts);
             $template->set('posts', $posts);
             $html = $template->fetch('profile.favourites.php');
             break;
         case 'replies':
             $posts = $model->getRepliesFromUser($profileId);
             $posts = DiscussHelper::formatPost($posts);
             $pagination = $model->getPagination();
             $posts = Discusshelper::getPostStatusAndTypes($posts);
             $template->set('posts', $posts);
             $html = $template->fetch('profile.replies.php');
             break;
         case 'tabEasyBlog':
             $helperFile = JPATH_ROOT . '/components/com_easyblog/helpers/helper.php';
             if (!JFile::exists($helperFile)) {
                 $html = JText::_('COM_EASYDISCUSS_EASYBLOG_DOES_NOT_EXIST');
             } else {
                 require_once $helperFile;
                 require_once JPATH_ROOT . '/components/com_easyblog/router.php';
                 $blogModel = EasyBlogHelper::getModel('Blog');
                 $blogs = $blogModel->getBlogsBy('blogger', $profileId);
                 $blogs = EasyBlogHelper::formatBlog($blogs);
                 $ebConfig = EasyBlogHelper::getConfig();
                 $user = JFactory::getUser($profileId);
                 $template->set('user', $user);
                 $template->set('ebConfig', $ebConfig);
                 $template->set('blogs', $blogs);
                 // Load EasyBlog's language file
                 JFactory::getLanguage()->load('com_easyblog', JPATH_ROOT);
                 $html = $template->fetch('profile.blogs.php');
             }
             break;
         case 'tabKomento':
             $helperFile = JPATH_ROOT . '/components/com_komento/helpers/helper.php';
             if (!JFile::exists($helperFile)) {
                 $html = JText::_('COM_EASYDISCUSS_KOMENTO_DOES_NOT_EXIST');
             } else {
                 require_once $helperFile;
                 $commentsModel = Komento::getModel('comments');
                 $commentHelper = Komento::getHelper('comment');
                 $options = array('sort' => 'latest', 'userid' => $profileId, 'threaded' => 0);
                 $comments = $commentsModel->getComments('all', 'all', $options);
                 foreach ($comments as &$comment) {
                     $comment = $commentHelper->process($comment);
                 }
                 $feedUrl = Komento::getHelper('router')->getFeedUrl('all', 'all', $profileId);
                 JFactory::getLanguage()->load('com_komento', JPATH_ROOT);
                 $template->set('feedUrl', $feedUrl);
                 $template->set('comments', $comments);
                 $html = $template->fetch('profile.comments.php');
             }
             break;
         case 'subscriptions':
             $subModel = DiscussHelper::getModel('subscribe');
             $rows = $subModel->getSubscriptions();
             $subs = array();
             if ($rows) {
                 foreach ($rows as $row) {
                     $obj = new stdClass();
                     $obj->id = $row->id;
                     $obj->type = $row->type;
                     $obj->unsublink = Discusshelper::getUnsubscribeLink($row, false);
                     switch ($row->type) {
                         case 'site':
                             $obj->title = '';
                             $obj->link = '';
                             break;
                         case 'post':
                             $post = DiscussHelper::getTable('Post');
                             $post->load($row->cid);
                             $obj->title = $post->title;
                             $obj->link = DiscussRouter::_('index.php?option=com_easydiscuss&view=post&id=' . $post->id);
                             break;
                         case 'category':
                             $category = DiscussHelper::getTable('Category');
                             $category->load($row->cid);
                             $obj->title = $category->title;
                             $obj->link = DiscussRouter::getCategoryRoute($category->id);
                             break;
                         case 'user':
                             $profile = DiscussHelper::getTable('Profile');
                             $profile->load($row->cid);
                             $obj->title = $profile->getName();
                             $obj->link = $profile->getLink();
                             break;
                         default:
                             unset($obj);
                             break;
                     }
                     if (!empty($obj)) {
                         $obj->title = DiscussStringHelper::escape($obj->title);
                         $subs[$row->type][] = $obj;
                         unset($obj);
                     }
                 }
             }
             $template->set('subscriptions', $subs);
             $html = $template->fetch('profile.subscriptions.php');
             break;
         default:
             break;
     }
     if ($pagination) {
         $filterArr = array();
         $filterArr['viewtype'] = $type;
         $filterArr['id'] = $profileId;
         $pagination = $pagination->getPagesLinks('profile', $filterArr, true);
     }
     $ajax->success($html, $pagination);
     $ajax->send();
 }
 /**
  * Filters discussion based on a given filter
  *
  * @since	3.2
  * @access	public
  * @param	string
  * @return	
  */
 public function filter()
 {
     $filterType = JRequest::getVar('filter');
     $sort = JRequest::getVar('sort', 'latest');
     $categoryId = JRequest::getVar('id', '0');
     if (!$categoryId) {
         $categoryId = array();
     } else {
         $categoryId = explode(',', $categoryId);
     }
     $view = JRequest::getVar('view', 'index');
     $ajax = DiscussHelper::getHelper('ajax');
     JRequest::setVar('filter', $filterType);
     $postModel = DiscussHelper::getModel('Posts');
     $registry = DiscussHelper::getRegistry();
     // Get the pagination limit
     $limit = $registry->get('limit');
     $limit = $limit == '-2' ? DiscussHelper::getListLimit() : $limit;
     $limit = $limit == '-1' ? DiscussHelper::getJConfig()->get('list_limit') : $limit;
     // Get normal discussion posts.
     $options = array('sort' => $sort, 'category' => $categoryId, 'filter' => $filterType, 'limit' => $limit, 'featured' => false);
     $posts = $postModel->getDiscussions($options);
     //$posts		= $postModel->getData( false , $sort , null , $filterType , $categoryId, null, '');
     $posts = DiscussHelper::formatPost($posts);
     $pagination = '';
     $pagination = $postModel->getPagination(0, $sort, $filterType, $categoryId, false);
     $filtering = array('category_id' => $categoryId, 'filter' => $filterType, 'sort' => $sort);
     $pagination = $pagination->getPagesLinks($view, $filtering, true);
     $html = '';
     $empty = '';
     if (count($posts) > 0) {
         $template = new DiscussThemes();
         $badgesTable = DiscussHelper::getTable('Profile');
         $onlineUsers = Discusshelper::getModel('Users')->getOnlineUsers();
         foreach ($posts as $post) {
             $badgesTable->load($post->user->id);
             $post->badges = $badgesTable->getBadges();
             // Translate post status from integer to string
             switch ($post->post_status) {
                 case '0':
                     $post->post_status_class = '';
                     $post->post_status = '';
                     break;
                 case '1':
                     $post->post_status_class = '-on-hold';
                     $post->post_status = JText::_('COM_EASYDISCUSS_POST_STATUS_ON_HOLD');
                     break;
                 case '2':
                     $post->post_status_class = '-accept';
                     $post->post_status = JText::_('COM_EASYDISCUSS_POST_STATUS_ACCEPTED');
                     break;
                 case '3':
                     $post->post_status_class = '-working-on';
                     $post->post_status = JText::_('COM_EASYDISCUSS_POST_STATUS_WORKING_ON');
                     break;
                 case '4':
                     $post->post_status_class = '-reject';
                     $post->post_status = JText::_('COM_EASYDISCUSS_POST_STATUS_REJECT');
                     break;
                 default:
                     $post->post_status_class = '';
                     $post->post_status = '';
                     break;
             }
             $alias = $post->post_type;
             $modelPostTypes = DiscussHelper::getModel('Post_types');
             // Get each post's post status title
             $title = $modelPostTypes->getTitle($alias);
             $post->post_type = $title;
             // Get each post's post status suffix
             $suffix = $modelPostTypes->getSuffix($alias);
             $post->suffix = $suffix;
             $template->set('post', $post);
             $html .= $template->fetch('frontpage.post.php');
         }
     } else {
         $template = new DiscussThemes();
         $html .= $template->fetch('frontpage.empty.php');
     }
     // This post is already favourite
     $ajax->resolve($html, $pagination);
     $ajax->send();
 }
Exemple #6
0
 /**
  * Displays the user's profile.
  *
  * @since	2.0
  * @access	public
  */
 function display($tmpl = null)
 {
     $doc = JFactory::getDocument();
     $app = JFactory::getApplication();
     $id = JRequest::getInt('id', null);
     $my = JFactory::getUser($id);
     $config = DiscussHelper::getConfig();
     // Custom parameters.
     $sort = JRequest::getString('sort', 'latest');
     $filteractive = JRequest::getString('filter', 'allposts');
     $viewType = JRequest::getString('viewtype', 'questions');
     $profile = DiscussHelper::getTable('Profile');
     $profile->load($my->id);
     // If profile is invalid, throw an error.
     if (!$profile->id) {
         // Show login form.
         $theme = new DiscussThemes();
         $theme->set('redirect', DiscussRouter::_('index.php?option=com_easydiscuss&view=profile', false));
         echo $theme->fetch('login.form.php');
         return;
     }
     $params = DiscussHelper::getRegistry($profile->params);
     $fields = array('facebook', 'linkedin', 'twitter', 'website');
     foreach ($fields as $site) {
         if ($params->get($site, '') != '') {
             if ($site == 'facebook' || $site == 'linkedin' || $site == 'twitter') {
                 $name = $params->get($site);
                 $url = 'www.' . $site . '.com/' . $name;
                 $params->set($site, DiscussUrlHelper::clean($url));
             }
             if ($site == 'website') {
                 $url = $params->get($site);
                 $params->set($site, DiscussUrlHelper::clean($url));
             }
         }
     }
     // Set the title for the page.
     DiscussHelper::setPageTitle(JText::sprintf('COM_EASYDISCUSS_PROFILE_PAGE_TITLE', $profile->getName()));
     // Set the pathway
     $this->setPathway(JText::_($profile->getName()));
     $postsModel = DiscussHelper::getModel('Posts');
     $tagsModel = DiscussHelper::getModel('Tags');
     $posts = array();
     $replies = array();
     $tagCloud = array();
     $badges = array();
     $unresolved = array();
     $pagination = null;
     $filterArr = array();
     $filterArr['viewtype'] = $viewType;
     $filterArr['id'] = $profile->id;
     switch ($viewType) {
         case 'replies':
             $replies = $postsModel->getRepliesFromUser($profile->id);
             $pagination = $postsModel->getPagination();
             $pagination = $pagination->getPagesLinks('profile', $filterArr, true);
             $replies = DiscussHelper::formatPost($replies);
             break;
         case 'unresolved':
             $unresolved = $postsModel->getUnresolvedFromUser($profile->id);
             $pagination = $postsModel->getPagination();
             $pagination = $pagination->getPagesLinks('profile', $filterArr, true);
             $unresolved = DiscussHelper::formatPost($unresolved);
             break;
         case 'questions':
         default:
             $posts = $postsModel->getPostsBy('user', $profile->id);
             $pagination = $postsModel->getPagination();
             $pagination = $pagination->getPagesLinks('profile', $filterArr, true);
             $posts = DiscussHelper::formatPost($posts);
             break;
     }
     // Get user badges
     $badges = $profile->getBadges();
     // @rule: Clear up any notifications that are visible for the user.
     $notifications = DiscussHelper::getModel('Notification');
     $notifications->markRead($profile->id, false, array(DISCUSS_NOTIFICATIONS_PROFILE, DISCUSS_NOTIFICATIONS_BADGE));
     $tpl = new DiscussThemes();
     // EasyBlog integrations
     $easyblogExists = $this->easyblogExists();
     $blogCount = 0;
     if ($easyblogExists && $config->get('integrations_easyblog_profile')) {
         $blogModel = EasyBlogHelper::getModel('Blog');
         $blogCount = $blogModel->getBlogPostsCount($profile->id, false);
     }
     $komentoExists = $this->komentoExists();
     $commentCount = 0;
     if ($komentoExists && $config->get('integrations_komento_profile')) {
         $commentsModel = Komento::getModel('comments');
         $commentCount = $commentsModel->getTotalComment($profile->id);
     }
     $posts = Discusshelper::getPostStatusAndTypes($posts);
     $favPosts = $postsModel->getData('true', 'latest', 'null', 'favourites');
     $favPosts = DiscussHelper::formatPost($favPosts);
     $tpl->set('sort', $sort);
     $tpl->set('filter', $filteractive);
     $tpl->set('tagCloud', $tagCloud);
     $tpl->set('paginationType', DISCUSS_USERQUESTIONS_TYPE);
     $tpl->set('parent_id', $profile->id);
     $tpl->set('pagination', $pagination);
     $tpl->set('posts', $posts);
     $tpl->set('badges', $badges);
     $tpl->set('favPosts', $favPosts);
     $tpl->set('profile', $profile);
     $tpl->set('replies', $replies);
     $tpl->set('unresolved', $unresolved);
     $tpl->set('params', $params);
     $tpl->set('viewType', $viewType);
     $tpl->set('easyblogExists', $easyblogExists);
     $tpl->set('komentoExists', $komentoExists);
     $tpl->set('blogCount', $blogCount);
     $tpl->set('commentCount', $commentCount);
     $filterArr = array();
     $filterArr['filter'] = $filteractive;
     $filterArr['id'] = $profile->id;
     $filterArr['sort'] = $sort;
     $filterArr['viewtype'] = $viewType;
     $tpl->set('filterArr', $filterArr);
     $tpl->set('page', 'profile');
     echo $tpl->fetch('profile.php');
 }
 public function tag($tmpl = null)
 {
     //initialise variables
     $mainframe = JFactory::getApplication();
     $doc = JFactory::getDocument();
     $user = JFactory::getUser();
     $config = DiscussHelper::getConfig();
     $tag = JRequest::getInt('id', 0);
     if (empty($tag)) {
         return JError::raiseError(404, JText::_('COM_EASYDISCUSS_INVALID_TAG'));
     }
     DiscussHelper::setMeta();
     $table = DiscussHelper::getTable('Tags');
     $table->load($tag);
     $doc = JFactory::getDocument();
     DiscussHelper::setPageTitle(JText::sprintf('COM_EASYDISCUSS_VIEWING_TAG_TITLE', $this->escape($table->title)));
     $this->setPathway(JText::_($table->title));
     $concatCode = DiscussHelper::getJConfig()->getValue('sef') ? '?' : '&';
     $doc->addHeadLink(JRoute::_('index.php?option=com_easydiscuss&view=tags&id=' . $tag) . $concatCode . 'format=feed&type=rss', 'alternate', 'rel', array('type' => 'application/rss+xml', 'title' => 'RSS 2.0'));
     $doc->addHeadLink(JRoute::_('index.php?option=com_easydiscuss&view=tags&id=' . $tag) . $concatCode . 'format=feed&type=atom', 'alternate', 'rel', array('type' => 'application/atom+xml', 'title' => 'Atom 1.0'));
     $filteractive = JRequest::getString('filter', 'allposts');
     $sort = JRequest::getString('sort', 'latest');
     if ($filteractive == 'unanswered' && ($sort == 'active' || $sort == 'popular')) {
         //reset the active to latest.
         $sort = 'latest';
     }
     $postModel = DiscussHelper::getModel('Posts');
     $posts = $postModel->getTaggedPost($tag, $sort, $filteractive);
     $pagination = $postModel->getPagination($sort, $filteractive);
     $authorIds = array();
     $topicIds = array();
     if (count($posts) > 0) {
         foreach ($posts as $item) {
             $authorIds[] = $item->user_id;
             $topicIds[] = $item->id;
         }
     }
     $lastReplyUser = $postModel->setLastReplyBatch($topicIds);
     $authorIds = array_merge($lastReplyUser, $authorIds);
     // Reduce SQL queries by pre-loading all author object.
     $authorIds = array_unique($authorIds);
     $profile = DiscussHelper::getTable('Profile');
     $profile->init($authorIds);
     $postLoader = DiscussHelper::getTable('Posts');
     $postLoader->loadBatch($topicIds);
     $postTagsModel = DiscussHelper::getModel('PostsTags');
     $postTagsModel->setPostTagsBatch($topicIds);
     $posts = DiscussHelper::formatPost($posts, false, true);
     $currentTag = $table->title;
     $posts = Discusshelper::getPostStatusAndTypes($posts);
     $tpl = new DiscussThemes();
     $tpl->set('rssLink', JRoute::_('index.php?option=com_easydiscuss&view=tags&id=' . $tag . '&format=feed'));
     $tpl->set('posts', $posts);
     $tpl->set('paginationType', DISCUSS_TAGS_TYPE);
     $tpl->set('pagination', $pagination);
     $tpl->set('sort', $sort);
     $tpl->set('filter', $filteractive);
     $tpl->set('showEmailSubscribe', true);
     $tpl->set('currentTag', $currentTag);
     $tpl->set('parent_id', $tag);
     $tpl->set('config', $config);
     echo $tpl->fetch('tag.php');
 }
Exemple #8
0
 private function processEmails($mailer = '', $category = '')
 {
     // @task: Only search for messages that are new.
     $unread = $mailer->searchMessages('UNSEEN');
     // If there is no unread emails, just skip this altogether
     if (!$unread) {
         echo JText::_('COM_EASYDISCUSS_NO_EMAILS_TO_PARSE');
         return false;
     }
     $config = DiscussHelper::getConfig();
     $acl = DiscussHelper::getHelper('ACL');
     $filter = JFilterInput::getInstance();
     $total = 0;
     $replyBreaker = $config->get('mail_reply_breaker');
     foreach ($unread as $sequence) {
         // Get the message info
         $info = $mailer->getMessageInfo($sequence);
         $from = $info->from;
         $senderName = $from[0]->personal;
         // Get the subject of the email and clean it to avoid any unclose html tags
         $subject = $filter->clean($info->subject);
         // @rule: Detect if this is actually a reply.
         preg_match('/\\[\\#(.*)\\]/is', $subject, $matches);
         $isReply = !empty($matches);
         $message = new DiscussMailerMessage($mailer->stream, $sequence);
         // Load up the post object
         $post = DiscussHelper::getTable('Post');
         // Get the html output
         $html = $message->getHTML();
         // Default allowed html codes
         $allowed = '<img>,<a>,<br>,<table>,<tbody>,<th>,<tr>,<td>,<div>,<span>,<p>,<h1>,<h2>,<h3>,<h4>,<h5>,<h6>';
         // Remove disallowed tags
         $html = strip_tags($html, $allowed);
         // Remove img tags because we do not support email embeded images
         $pattern = array();
         $pattern[] = '/<img.*?src=["|\'](.*?)["|\'].*?\\>/ims';
         $html = preg_replace($pattern, array(''), $html);
         // Insert default subject if emails do not contain title
         if (empty($subject)) {
             $subject = JText::_('COM_EASYDISCUSS_EMAIL_NO_SUBJECT');
         }
         $post->set('content', $html);
         $post->set('title', $subject);
         $post->set('published', DISCUSS_ID_PUBLISHED);
         $post->set('created', DiscussHelper::getDate()->toMySQL());
         $post->set('replied', DiscussHelper::getDate()->toMySQL());
         $post->set('modified', DiscussHelper::getDate()->toMySQL());
         // If this is a reply, and the site isn't configured to parse replies, skip this
         if ($isReply && !$config->get('main_email_parser_replies')) {
             continue;
         }
         // By default, set the category to the one pre-configured at the back end.
         $post->category_id = $config->get('main_email_parser_category');
         if ($isReply) {
             $parentId = (int) $matches[1];
             $post->set('parent_id', $parentId);
             // Trim content, get text before the defined line
             if ($replyBreaker) {
                 if ($pos = JString::strpos($post->content, $replyBreaker)) {
                     $post->content = JString::substr($post->content, 0, $pos);
                 }
             }
             // Since this is a reply, we need to determine the correct category for it based on the parent discussion.
             $parent = DiscussHelper::getTable('Post');
             $parent->load($parentId);
             $post->category_id = $parent->category_id;
         }
         // @rule: Map the sender's email with the user in Joomla?
         $replyToEmail = $info->fromemail;
         // Lookup for the user based on their email address.
         $user = DiscussHelper::getUserByEmail($replyToEmail);
         if ($user instanceof JUser) {
             $post->user_id = $user->id;
             $post->user_type = DISCUSS_POSTER_MEMBER;
         } else {
             // Guest posts
             $post->user_type = DISCUSS_POSTER_GUEST;
             $post->poster_name = $senderName;
             $post->poster_email = $replyToEmail;
         }
         // check if guest can post question or not. if not skip the processing.
         if ($post->get('user_type') == DISCUSS_POSTER_GUEST) {
             $acl = DiscussHelper::getHelper('ACL', '0');
             if (!$acl->allowed('add_question')) {
                 continue;
             }
         }
         // If the system is configured to moderate all emails, then we should update the state accordingly
         if ($config->get('main_email_parser_moderation')) {
             $post->set('published', DISCUSS_ID_PENDING);
         }
         // @rule: Process the post
         $post->store();
         // prepare email content and information.
         $profile = DiscussHelper::getTable('Profile');
         if (isset($user->id)) {
             $profile->load($user->id);
         }
         // For use within the emails.
         $emailData = array();
         $emailData['postTitle'] = $post->title;
         $emailData['postAuthor'] = $profile->id ? $profile->getName() : $post->poster_name;
         $emailData['postAuthorAvatar'] = $profile->getAvatar();
         $emailData['postLink'] = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=post&id=' . $post->id, false, true);
         $emailContent = $post->content;
         if ($post->content_type != 'html') {
             // the content is bbcode. we need to parse it.
             $emailContent = EasyDiscussParser::bbcode($emailContent);
             $emailContent = EasyDiscussParser::removeBrTag($emailContent);
         }
         // If post is html type we need to strip off html codes.
         if ($post->content_type == 'html') {
             $emailContent = strip_tags($post->content);
         }
         // Notify moderators when there's a new pending post
         if ($post->published == DISCUSS_ID_PENDING) {
             // Generate hashkeys to map this current request
             $hashkey = DiscussHelper::getTable('HashKeys');
             $hashkey->uid = $post->id;
             $hashkey->type = DISCUSS_QUESTION_TYPE;
             $hashkey->store();
             // Prepare the email template.
             $approveURL = DiscussHelper::getExternalLink('index.php?option=com_easydiscuss&controller=posts&task=approvePost&key=' . $hashkey->key);
             $rejectURL = DiscussHelper::getExternalLink('index.php?option=com_easydiscuss&controller=posts&task=rejectPost&key=' . $hashkey->key);
             $emailData['moderation'] = '<div style="display:inline-block;width:100%;padding:20px;border-top:1px solid #ccc;padding:20px 0 10px;margin-top:20px;line-height:19px;color:#555;font-family:\'Lucida Grande\',Tahoma,Arial;font-size:12px;text-align:left">';
             $emailData['moderation'] .= '<a href="' . $approveURL . '" style="display:inline-block;padding:5px 15px;background:#fc0;border:1px solid #caa200;border-bottom-color:#977900;color:#534200;text-shadow:0 1px 0 #ffe684;font-weight:bold;box-shadow:inset 0 1px 0 #ffe064;-moz-box-shadow:inset 0 1px 0 #ffe064;-webkit-box-shadow:inset 0 1px 0 #ffe064;border-radius:2px;moz-border-radius:2px;-webkit-border-radius:2px;text-decoration:none!important">' . JText::_('COM_EASYDISCUSS_EMAIL_APPROVE_POST') . '</a>';
             $emailData['moderation'] .= ' ' . JText::_('COM_EASYDISCUSS_OR') . ' <a href="' . $rejectURL . '" style="color:#477fda">' . JText::_('COM_EASYDISCUSS_REJECT') . '</a>';
             $emailData['moderation'] .= '</div>';
             $emailData['postContent'] = $post->content;
             $emailData['emailTemplate'] = 'email.subscription.site.moderate.php';
             $emailData['emailSubject'] = JText::sprintf('COM_EASYDISCUSS_NEW_QUESTION_MODERATE', $post->id, $post->title);
             // Notify the moderators now
             DiscussHelper::getHelper('Mailer')->notifyAdministrators($emailData, array($replyToEmail), $config->get('notify_admin'), $config->get('notify_moderator'));
         }
         $attachments = array();
         $attachments = $message->getAttachment();
         // process attached images
         if (!empty($attachments)) {
             $config = DiscussHelper::getConfig();
             $main_image_path = rtrim('images/easydiscuss_images/', '/');
             $file = JPATH_ROOT . DIRECTORY_SEPARATOR . $main_image_path;
             if (!JFolder::exists($file)) {
                 JFolder::create($file);
             }
             $senderMail = $info->fromemail;
             $user = DiscussHelper::getUserByEmail($senderMail);
             $userid = $user->get('id');
             $rel_upload_path = $main_image_path . '/' . $userid;
             $userUploadPath = JPATH_ROOT . DIRECTORY_SEPARATOR . $main_image_path . DIRECTORY_SEPARATOR . $userid;
             $userUploadPath = JPath::clean($userUploadPath);
             $dir = $userUploadPath . DIRECTORY_SEPARATOR;
             $tmp_dir = JPATH_ROOT . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR;
             $uri = JURI::base() . $main_image_path . '/' . $userid . '/';
             if (!JFolder::exists($dir)) {
                 JFolder::create($dir);
             }
             foreach ($attachments as $attachment) {
                 // clean up file name
                 if (strpos($attachment['name'], '/') !== FALSE) {
                     $attachment['name'] = substr($attachment['name'], strrpos($attachment['name'], '/') + 1);
                 } elseif (strpos($attachment['name'], '\\' !== FALSE)) {
                     $attachment['name'] = substr($attachment['name'], strrpos($attachment['name'], '\\') + 1);
                 }
                 // @task: check if the attachment has file extension. ( assuming is images )
                 $imgExts = array('jpg', 'png', 'gif', 'JPG', 'PNG', 'GIF', 'jpeg', 'JPEG');
                 $imageSegment = explode('.', $attachment['name']);
                 if (!in_array($imageSegment[count($imageSegment) - 1], $imgExts)) {
                     $attachment['name'] = $attachment['name'] . '.jpg';
                 }
                 // @task: Store the file into a temporary location first.
                 $attachment['tmp_name'] = $tmp_dir . $attachment['name'];
                 JFile::write($attachment['tmp_name'], $attachment['data']);
                 $atmTitle = $attachment['name'];
                 $atmURL = $uri . $attachment['name'];
                 // Bind file attachments
                 jimport('joomla.filesystem.file');
                 jimport('joomla.filesystem.folder');
                 jimport('joomla.utilities.utility');
                 // @rule: Create default media path
                 $path = DISCUSS_MEDIA . '/' . trim($config->get('attachment_path'), DIRECTORY_SEPARATOR);
                 if (!JFolder::exists($path)) {
                     JFolder::create($path);
                     JFile::copy(DISCUSS_ROOT . '/index.html', $path . '/index.html');
                 }
                 $maxSize = (double) $config->get('attachment_maxsize') * 1024 * 1024;
                 $extension = JFile::getExt($attachment['name']);
                 // Skip empty data's.
                 if (!$extension) {
                     continue;
                 }
                 $allowed = explode(',', $config->get('main_attachment_extension'));
                 // @rule: Check for allowed extensions
                 if (!isset($extension) || !in_array(strtolower($extension), $allowed)) {
                     echo 'Invalid extension.';
                 } else {
                     $size = $attachment['size'];
                     $name = $attachment['name'];
                     $mime = $attachment['mime'];
                     $tmpName = $attachment['tmp_name'];
                     // Check the mime contains the attachment type, if not we insert our own
                     $imgExts = array('jpg', 'png', 'gif', 'JPG', 'PNG', 'GIF', 'jpeg', 'JPEG');
                     if (in_array($mime, $imgExts)) {
                         $mime = 'image/' . $mime;
                     } else {
                         $mime = 'application/' . $mime;
                     }
                     // @rule: File size should not exceed maximum allowed size
                     if (!empty($size) && $size < $maxSize) {
                         $hash = DiscussHelper::getHash($name . DiscussHelper::getDate()->toMySQL());
                         $attachment = DiscussHelper::getTable('Attachments');
                         $attachment->set('path', $hash);
                         $attachment->set('title', $name);
                         $attachment->set('uid', $post->id);
                         $attachment->set('type', $isReply ? 'replies' : 'questions');
                         $attachment->set('created', DiscussHelper::getDate()->toMySQL());
                         $attachment->set('published', true);
                         $attachment->set('mime', $mime);
                         $attachment->set('size', $size);
                         if (!JFile::copy($tmpName, $path . '/' . $hash)) {
                             echo 'Copy failed from tmp to attachment folder';
                         }
                         $attachment->store();
                         // Create a thumbnail if attachment is an image
                         if (DiscussHelper::getHelper('Image')->isImage($name)) {
                             require_once DISCUSS_CLASSES . '/simpleimage.php';
                             $image = new SimpleImage();
                             $image->load($tmpName);
                             $image->resizeToFill(160, 120);
                             $image->save($path . '/' . $hash . '_thumb', $image->image_type);
                         }
                         // @task: Once the attachment is processed, delete the temporary file.
                         JFile::delete($tmpName);
                     } else {
                         echo 'Invalid extension ' . $name;
                     }
                 }
             }
         }
         // Send notification email to the subscribers in the thread.
         if ($isReply && $post->get('published') == DISCUSS_ID_PUBLISHED) {
             self::replyNotifyUsers($post, $user, $senderName);
         }
         // @task: Increment the count.
         $total += 1;
         // @rule: Only send autoresponders when it's a new post.
         if (!$isReply && $config->get('main_email_parser_receipt') && $post->get('published') == DISCUSS_ID_PUBLISHED) {
             $sendAsHTML = (bool) $config->get('notify_html_format');
             $theme = new DiscussThemes();
             $postId = $post->get('id');
             if ($isReply) {
                 $postId = $parentId;
             }
             $url = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=post&id=' . $postId, false, true);
             $emailData = array();
             $emailData['postLink'] = $url;
             if ($post->get('user_type') == DISCUSS_POSTER_GUEST) {
                 $emailData['postAuthor'] = $senderName;
             } else {
                 $profile = DiscussHelper::getTable('Profile');
                 $profile->load($user->id);
                 $emailData['postAuthor'] = $profile->getName();
             }
             require_once DISCUSS_CLASSES . '/notification.php';
             $notification = new DNotification();
             $output = $notification->getEmailTemplateContent('email.accepted.responder.php', $emailData);
             $app = JFactory::getApplication();
             if (!$sendAsHTML) {
                 $output = strip_tags($output);
             }
             // @rule: Send confirmation message.
             JUtility::sendMail($app->getCfg('mailfrom'), $app->getCfg('fromname'), $replyToEmail, '[#' . $post->id . ']: ' . $subject, $output, $sendAsHTML);
         }
         if (!$isReply && $post->get('published') == DISCUSS_ID_PUBLISHED) {
             // Send email to subscribers about new post has created
             Discusshelper::sendNotification($post, $post->parent_id, true, $post->user_id, DISCUSS_ID_PENDING);
         }
         echo JText::sprintf('COM_EASYDISCUSS_EMAIL_PARSED', $total);
     }
 }