예제 #1
0
 function display($tmpl = null)
 {
     $document = JFactory::getDocument();
     $config = DiscussHelper::getConfig();
     $doc = JFactory::getDocument();
     DiscussHelper::setPageTitle(JText::_('COM_EASYDISCUSS_MEMBERS_TITLE'));
     $this->setPathway(JText::_('COM_EASYDISCUSS_BREADCRUMBS_MEMBERS'));
     $model = $this->getModel('Users');
     $userQuery = JRequest::getString('userQuery', '');
     $result = $model->getData($userQuery);
     $pagination = $model->getPagination();
     $sort = JRequest::getString('sort', 'latest');
     $filteractive = JRequest::getString('filter', 'allposts');
     $users = DiscussHelper::formatUsers($result);
     $sort = JRequest::getCmd('sort', 'name');
     $uids = $config->get('main_exclude_members');
     if (!empty($uids)) {
         // Remove white space
         $uids = str_replace(' ', '', $uids);
         $excludeId = explode(',', $uids);
         $temp = array();
         foreach ($users as $user) {
             if (!in_array($user->id, $excludeId)) {
                 $temp[] = $user;
             }
         }
         $users = $temp;
     }
     $theme = new DiscussThemes();
     $theme->set('users', $users);
     $theme->set('pagination', $pagination);
     $theme->set('sort', $sort);
     $theme->set('userQuery', $userQuery);
     echo $theme->fetch('users.php');
 }
예제 #2
0
 public function listings()
 {
     $app = JFactory::getApplication();
     $config = DiscussHelper::getConfig();
     $id = JRequest::getInt('id');
     if (empty($id)) {
         $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=badges', false), JText::_('COM_EASYDISCUSS_INVALID_BADGE'));
         $app->close();
     }
     $badge = DiscussHelper::getTable('Badges');
     $badge->load($id);
     $this->setPathway(JText::_('COM_EASYDISCUSS_BADGES'), DiscussRouter::_('index.php?option=com_easydiscuss&view=badges'));
     $this->setPathway(JText::_($badge->get('title')));
     DiscussHelper::setPageTitle(JText::sprintf('COM_EASYDISCUSS_VIEWING_BADGE_TITLE', $this->escape($badge->title)));
     $users = $badge->getUsers();
     $theme = new DiscussThemes();
     $theme->set('badge', $badge);
     $theme->set('users', $users);
     echo $theme->fetch('badge.php');
 }
예제 #3
0
 function display($tpl = null)
 {
     $config = DiscussHelper::getConfig();
     $app = JFactory::getApplication();
     if (!$config->get('main_favorite')) {
         DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_FEATURE_IS_DISABLED'), DISCUSS_QUEUE_ERROR);
         $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss', false));
         $app->close();
     }
     DiscussHelper::setPageTitle(JText::_('COM_EASYDISCUSS_FAVOURITES_TITLE'));
     // @task: Add view
     $this->logView();
     DiscussHelper::setMeta();
     $postModel = DiscussHelper::getModel('Posts');
     $posts = $postModel->getData(true, 'latest', null, 'favourites');
     $posts = DiscussHelper::formatPost($posts);
     $theme = new DiscussThemes();
     $theme->set('posts', $posts);
     echo $theme->fetch('favourites.php');
 }
예제 #4
0
 public function display($tpl = null)
 {
     // Initialise variables
     $doc = JFactory::getDocument();
     $my = JFactory::getUser();
     $config = DiscussHelper::getConfig();
     $app = JFactory::getApplication();
     $registry = DiscussHelper::getRegistry();
     $categoryId = JRequest::getInt('category_id', 0);
     // Perform redirection if there is a category_id in the index view.
     if (!empty($categoryId)) {
         $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=categories&layout=listings&category_id=' . $categoryId, false));
         $app->close();
     }
     // Try to detect if there's any category id being set in the menu parameter.
     $activeMenu = $app->getMenu()->getActive();
     if ($activeMenu && !$categoryId) {
         // Load menu params to the registry.
         $registry->loadString($activeMenu->params);
         if ($registry->get('category_id')) {
             $categoryId = $registry->get('category_id');
         }
     }
     // Get the current logged in user's access.
     $acl = DiscussHelper::getHelper('ACL');
     // Todo: Perhaps we should fix the confused naming of filter and sort to type and sort
     $filter = JRequest::getString('filter', $registry->get('filter'));
     $sort = JRequest::getString('sort', $registry->get('sort'));
     // Get the pagination limit
     $limit = $registry->get('limit');
     $limit = $limit == '-2' ? DiscussHelper::getListLimit() : $limit;
     $limit = $limit == '-1' ? DiscussHelper::getJConfig()->get('list_limit') : $limit;
     // Add view to this page.
     $this->logView();
     // set page title.
     DiscussHelper::setPageTitle();
     // Set the meta of the page.
     DiscussHelper::setMeta();
     // Add rss feed into headers
     DiscussHelper::getHelper('Feeds')->addHeaders('index.php?option=com_easydiscuss&view=index');
     // Get list of categories on the site.
     $catModel = $this->getModel('Categories');
     // Pagination is by default disabled.
     $pagination = false;
     // Get the model.
     $postModel = DiscussHelper::getModel('Posts');
     // Get a list of accessible categories
     $cats = $this->getAccessibleCategories($categoryId);
     // Get featured posts from this particular category.
     $featured = array();
     if ($config->get('layout_featuredpost_frontpage')) {
         $options = array('pagination' => false, 'category' => $cats, 'sort' => $sort, 'filter' => $filter, 'limit' => $config->get('layout_featuredpost_limit', $limit), 'featured' => true);
         $featured = $postModel->getDiscussions($options);
         if (is_null($featured)) {
             $featured = array();
         }
     }
     // Get normal discussion posts.
     $options = array('sort' => $sort, 'category' => $cats, 'filter' => $filter, 'limit' => $limit, 'featured' => false);
     $posts = $postModel->getDiscussions($options);
     if (is_null($posts)) {
         $posts = array();
     }
     $authorIds = array();
     $topicIds = array();
     $tmpPostsArr = array_merge($featured, $posts);
     if (count($tmpPostsArr) > 0) {
         foreach ($tmpPostsArr as $tmpArr) {
             $authorIds[] = $tmpArr->user_id;
             $topicIds[] = $tmpArr->id;
         }
     }
     $pagination = $postModel->getPagination(0, 'latest', '', $cats, false);
     $postLoader = EDC::getTable('Posts');
     $postLoader->loadBatch($topicIds);
     $postTagsModel = EDC::getModel('PostsTags');
     $postTagsModel->setPostTagsBatch($topicIds);
     $model = EDC::getModel('Posts');
     $lastReplyUser = $model->setLastReplyBatch($topicIds);
     // Reduce SQL queries by pre-loading all author object.
     $authorIds = array_merge($lastReplyUser, $authorIds);
     $authorIds = array_unique($authorIds);
     // Initialize the list of user's so we run lesser sql queries.
     $profile = EDC::getTable('Profile');
     $profile->init($authorIds);
     // Format featured entries.
     $featured = EDC::formatPost($featured, false, true);
     // Format normal entries
     $posts = EDC::formatPost($posts, false, true);
     // Get unread count
     $unreadCount = $model->getUnreadCount($cats, false);
     // Get unresolved count
     // Change the "all" to TRUE or FALSE to include/exclude featured post count
     $unresolvedCount = $model->getUnresolvedCount('', $cats, '', 'all');
     // Get resolved count
     $resolvedCount = $model->getTotalResolved();
     // Get unanswered count
     $unansweredCount = EDC::getUnansweredCount($cats, true);
     // Get assigned post count that isn't answered yet.
     $assignedCount = 0;
     if (EDC::isSiteAdmin() || EDC::isModerator()) {
         $assignedModel = EDC::getModel('Assigned');
         $assignedCount = $assignedModel->getTotalUnresolved();
     }
     $activeFilter = $config->get('layout_frontpage_sorting');
     // Let's render the layout now.
     $theme = new DiscussThemes();
     $theme->set('assignedCount', $assignedCount);
     $theme->set('activeFilter', $activeFilter);
     $theme->set('activeSort', $sort);
     $theme->set('categories', $categoryId);
     $theme->set('unreadCount', $unreadCount);
     $theme->set('unansweredCount', $unansweredCount);
     $theme->set('resolvedCount', $resolvedCount);
     $theme->set('unresolvedCount', $unresolvedCount);
     $theme->set('posts', $posts);
     $theme->set('featured', $featured);
     $theme->set('pagination', $pagination);
     echo $theme->fetch('frontpage.index.php');
 }
예제 #5
0
 private function setPageHeaders($post)
 {
     // Set page title.
     DiscussHelper::setPageTitle($post->getTitle());
     $doc = JFactory::getDocument();
     $doc->setMetadata('keywords', $post->title);
     $doc->setMetadata('description', preg_replace('/\\s+/', ' ', substr(strip_tags(EasyDiscussParser::bbcode($post->content)), 0, 160)));
     // Set canonical link to avoid URL duplication.
     $doc->addHeadLink(DISCUSS_JURIROOT . DiscussRouter::getPostRoute($post->id), 'canonical', 'rel');
 }
예제 #6
0
 /**
  * Displays a list of recent discussions from a particular category.
  *
  * @since	3.0
  * @access	public
  */
 public function listings()
 {
     // Initialise variables
     $doc = JFactory::getDocument();
     $my = JFactory::getUser();
     $config = DiscussHelper::getConfig();
     $app = JFactory::getApplication();
     $registry = DiscussHelper::getRegistry();
     $categoryId = JRequest::getInt('category_id', 0);
     // Try to detect if there's any category id being set in the menu parameter.
     $activeMenu = $app->getMenu()->getActive();
     if ($activeMenu) {
         // Load menu params to the registry.
         $registry->loadString($activeMenu->params);
         // Set the active category id if exists.
         $categoryId = $registry->get('category_id') ? $registry->get('category_id') : $categoryId;
     }
     // Get the current logged in user's access.
     $acl = DiscussHelper::getHelper('ACL');
     // Todo: Perhaps we should fix the confused naming of filter and sort to type and sort
     $activeFilter = JRequest::getString('filter', $registry->get('filter'));
     $sort = JRequest::getString('sort', $registry->get('sort'));
     // Get the pagination limit
     $limit = $registry->get('limit');
     $limit = $limit == '-2' ? DiscussHelper::getListLimit() : $limit;
     $limit = $limit == '-1' ? DiscussHelper::getJConfig()->get('list_limit') : $limit;
     // Get the active category id if there is any
     $activeCategory = DiscussHelper::getTable('Category');
     $activeCategory->load($categoryId);
     DiscussHelper::setPageTitle($activeCategory->title);
     // Add breadcrumbs for active category.
     if ($activeCategory->id != 0) {
         // Test if user is really allowed to access this category.
         if (!$activeCategory->canAccess()) {
             $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=index', false), JText::_('COM_EASYDISCUSS_SYSTEM_INSUFFICIENT_PERMISSIONS'));
             $app->close();
             return;
         }
         // Add pathway for category here.
         DiscussHelper::getHelper('Pathway')->setCategoryPathway($activeCategory);
     }
     // Add view to this page.
     $this->logView();
     // Set the meta of the page.
     DiscussHelper::setMeta();
     $doc = JFactory::getDocument();
     $doc->setMetadata('description', strip_tags($activeCategory->getDescription()));
     // Add rss feed into headers
     DiscussHelper::getHelper('Feeds')->addHeaders('index.php?option=com_easydiscuss&view=index');
     // Get list of categories on the site.
     $catModel = $this->getModel('Categories');
     // Pagination is by default disabled.
     $pagination = false;
     if ($categoryId) {
         $category = DiscussHelper::getTable('Category');
         $category->load($categoryId);
         $categories[] = $category;
     } else {
         $categories = $catModel->getCategories($categoryId);
         if (count($categories) > 1) {
             $ids = array();
             foreach ($categories as $row) {
                 $ids[] = $row->id;
             }
             // iniCounts should only called in index page.
             $category = DiscussHelper::getTable('Category');
             $category->initCounts($ids, true);
         }
     }
     // Get the model.
     $postModel = DiscussHelper::getModel('Posts');
     $authorIds = array();
     $topicIds = array();
     for ($i = 0; $i < count($categories); $i++) {
         $category =& $categories[$i];
         // building category childs lickage.
         $category->childs = null;
         $nestedLinks = '';
         // In category page
         if ($config->get('layout_show_all_subcategories', '1')) {
             // By default show all the subcategories of the selected category
             DiscussHelper::buildNestedCategories($category->id, $category, false, true);
         } else {
             // Show one level of subcategories of the selected category only
             $category->childs = $catModel->getChildCategories($category->id);
         }
         DiscussHelper::accessNestedCategories($category, $nestedLinks, '0', '', 'listlink', ', ');
         $category->nestedLink = $nestedLinks;
         // Get featured posts from this particular category.
         $featured = $postModel->getDiscussions(array('pagination' => false, 'sort' => $sort, 'filter' => $activeFilter, 'category' => $category->id, 'limit' => $config->get('layout_featuredpost_limit', $limit), 'featured' => true));
         // Get normal discussion posts.
         $posts = $postModel->getDiscussions(array('sort' => $sort, 'filter' => $activeFilter, 'category' => $category->id, 'limit' => $limit, 'featured' => false));
         $tmpPostsArr = array_merge($featured, $posts);
         if (count($tmpPostsArr) > 0) {
             foreach ($tmpPostsArr as $tmpArr) {
                 $authorIds[] = $tmpArr->user_id;
                 $topicIds[] = $tmpArr->id;
             }
         }
         if ($categoryId) {
             $pagination = $postModel->getPagination(0, 'latest', '', $categoryId, false);
         }
         // Set these items into the category object.
         $category->featured = $featured;
         $category->posts = $posts;
         // Set active filter for the category
         $category->activeFilter = $activeFilter;
         $category->activeSort = $sort;
     }
     $lastReplyUser = $postModel->setLastReplyBatch($topicIds);
     $authorIds = array_merge($lastReplyUser, $authorIds);
     // load all author object 1st.
     $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);
     // perform data formating here.
     for ($i = 0; $i < count($categories); $i++) {
         $category =& $categories[$i];
         // perform data formating here.
         if ($category->featured) {
             $category->featured = DiscussHelper::formatPost($category->featured, false, true);
         }
         if ($category->posts) {
             $category->posts = DiscussHelper::formatPost($category->posts, false, true);
         }
     }
     // Let's render the layout now.
     $theme = new DiscussThemes();
     $theme->set('activeFilter', $activeFilter);
     $theme->set('activeSort', $sort);
     $theme->set('categories', $categories);
     $theme->set('pagination', $pagination);
     echo $theme->fetch('frontpage.php');
 }
예제 #7
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');
 }
예제 #8
0
 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');
 }
예제 #9
0
 public function display($tmpl = null)
 {
     $document = JFactory::getDocument();
     $mainframe = JFactory::getApplication();
     $user = JFactory::getUser();
     $config = DiscussHelper::getConfig();
     $category = JRequest::getInt('category_id', 0);
     // Add breadcrumbs
     $this->setPathway(JText::_('COM_EASYDISCUSS_SEARCH'));
     DiscussHelper::setPageTitle();
     // Set the meta of the page.
     DiscussHelper::setMeta();
     $query = JRequest::getString('query', '');
     $limitstart = null;
     $posts = null;
     $pagination = null;
     if (!empty($query)) {
         $searchModel = DiscussHelper::getModel('Search');
         $posts = $searchModel->getData(true, 'latest', null, 'allposts', $category);
         $pagination = $searchModel->getPagination(0, 'latest', 'allposts', $category);
         $posts = DiscussHelper::formatPost($posts, true);
         $badgesTable = DiscussHelper::getTable('Profile');
         if (count($posts) > 0) {
             $searchworda = preg_replace('#\\xE3\\x80\\x80#s', ' ', $query);
             $searchwords = preg_split("/\\s+/u", $searchworda);
             $needle = $searchwords[0];
             $searchwords = array_unique($searchwords);
             for ($i = 0; $i < count($posts); $i++) {
                 $row =& $posts[$i];
                 if (!$row->isProtected()) {
                     if ($config->get('layout_editor') != 'bbcode') {
                         $introtext = strip_tags($row->content);
                         $introtext = preg_replace('/\\s+/', ' ', $introtext);
                     } else {
                         $introtext = preg_replace('/\\s+/', ' ', strip_tags(DiscussHelper::parseContent($row->content)));
                         // clean it to 1 liner
                     }
                     $pos = strpos($introtext, $needle);
                     if ($pos !== false) {
                         $text = '...';
                         $startpos = $pos - 10 >= 0 ? $pos - 10 : 0;
                         //$endpos     = ( $pos - 10 ) >= 0 ? 10 : JString::strlen($needle) + 1;
                         $endpos = $pos - 10 >= 0 ? 10 : $pos - $startpos;
                         $front = JString::substr($introtext, $startpos, $endpos);
                         if (JString::strlen($introtext) > $endpos) {
                             $endpos = $pos + JString::strlen($needle);
                             $end = JString::substr($introtext, $endpos, 10);
                             if (JString::strlen($front) > 0) {
                                 $text = $text . $front;
                             }
                             $text = $text . $needle;
                             if (JString::strlen($end) > 0) {
                                 $text = $text . $end . '...';
                             }
                         } else {
                             $text = $front;
                         }
                         $introtext = $text;
                     }
                 } else {
                     //password protected content.
                     $introtext = $row->content;
                     // when come to here, the content is already contain the password input form ( via formatPost function.)
                 }
                 //$introtext	= JString::substr($introtext, 0, $config->get( 'layout_introtextlength' ));
                 $searchRegex = '#(';
                 $x = 0;
                 foreach ($searchwords as $k => $hlword) {
                     $searchRegex .= $x == 0 ? '' : '|';
                     $searchRegex .= preg_quote($hlword, '#');
                     $x++;
                 }
                 $searchRegex .= '(?!(?>[^<]*(?:<(?!/?a\\b)[^<]*)*)</a>))#iu';
                 $row->title = preg_replace($searchRegex, '<span class="highlight">\\0</span>', $row->title);
                 $row->introtext = $row->isProtected() ? $introtext : preg_replace($searchRegex, '<span class="highlight">\\0</span>', $introtext);
                 //display password input form.
                 if ($row->isProtected()) {
                     $row->content = $row->content;
                     // when come to here, the content is already contain the password input form ( via formatPost function.)
                 } else {
                     $row->content = preg_replace($searchRegex, '<span class="highlight">\\0</span>', $introtext);
                 }
                 $badgesTable->load($row->user->id);
                 $row->badges = $badgesTable->getBadges();
             }
         }
     }
     $tpl = new DiscussThemes();
     $tpl->set('query', $query);
     $tpl->set('posts', $posts);
     $tpl->set('paginationType', DISCUSS_SEARCH_TYPE);
     $tpl->set('pagination', $pagination);
     $tpl->set('parent_id', $query);
     echo $tpl->fetch('search.php');
 }
예제 #10
0
 /**
  * Displays the conversation.
  *
  * @since	3.0
  * @access	public
  */
 public function read()
 {
     $id = JRequest::getInt('id');
     $app = JFactory::getApplication();
     $my = JFactory::getUser();
     // Do not allow non logged in users to view anything in conversation.
     if (!$my->id) {
         $returnURL = base64_encode(JRequest::getURI());
         //DiscussHelper::setMessageQueue( JText::_( 'COM_EASYDISCUSS_NOT_ALLOWED' ) , DISCUSS_QUEUE_ERROR );
         //$app->redirect( DiscussRouter::_( 'index.php?option=com_easydiscuss&view=index' , false ) );
         $app->redirect(DiscussHelper::getLoginLink($returnURL));
         $app->close();
     }
     // Try to load the conversation
     $conversation = DiscussHelper::getTable('Conversation');
     $state = $conversation->load($id);
     // The conversation id needs to be valid.
     if (!$state) {
         DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_CONVERSATION_INVALID'), DISCUSS_QUEUE_ERROR);
         $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=index', false));
         $app->close();
     }
     // Check if the current logged in user has access to this conversation.
     $model = DiscussHelper::getModel('Conversation');
     if (!$model->hasAccess($conversation->id, $my->id)) {
         DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_NOT_ALLOWED'), DISCUSS_QUEUE_ERROR);
         $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=index', false));
         $app->close();
     }
     $doc = JFactory::getDocument();
     $result = $conversation->getParticipants($my->id);
     $user = DiscussHelper::getTable('Profile');
     $user->load($result[0]);
     DiscussHelper::setPageTitle(JText::sprintf('COM_EASYDISCUSS_VIEW_CONVERSATION_TITLE', $this->escape($user->getName())));
     // Mark this message as read for the current logged in user.
     $conversation->markAsRead($my->id);
     // Check if it is view all messages
     $viewAll = JRequest::getVar('show');
     $count = JRequest::getInt('count');
     if ($viewAll == 'all') {
         // For future use
         $count = '';
     }
     if ($viewAll == 'previous') {
         $count = JRequest::getInt('count');
         // Check if the value is integer, we do no want any weird values
         if (isset($count) && is_int($count)) {
             // Convert to absolute number
             $count = abs($count);
         }
     }
     // Get replies in the conversation
     $replies = $model->getMessages($conversation->id, $my->id, $viewAll, $count);
     // Format conversation replies.
     DiscussHelper::formatConversationReplies($replies);
     // Format the conversation object.
     $data = array($conversation);
     DiscussHelper::formatConversations($data);
     $theme = new DiscussThemes();
     $theme->set('replies', $replies);
     $theme->set('conversation', $data[0]);
     echo $theme->fetch('conversation.read.php');
 }
예제 #11
0
 /**
  *	Method is called when the new form is called.
  *
  * @since	1.0
  * @access	public
  */
 public function display($tpl = null)
 {
     $app = JFactory::getApplication();
     $doc = JFactory::getDocument();
     $my = JFactory::getUser();
     $acl = DiscussHelper::getHelper('ACL');
     $config = DiscussHelper::getConfig();
     // Load post item
     $id = JRequest::getInt('id', 0);
     $post = DiscussHelper::getTable('Post');
     $post->load($id);
     $post->content_raw = $post->content;
     $editing = (bool) $post->id;
     if (!$editing) {
         // try to get from session if there are any.
         $this->getSessionData($post);
         $post->content_raw = $post->content;
     }
     $categoryId = JRequest::getInt('category', $post->category_id);
     // Load category item.
     $category = DiscussHelper::getTable('Category');
     $category->load($categoryId);
     // Check if user is allowed to post a discussion, we also need to check against the category acl
     if (empty($my->id) && !$acl->allowed('add_question', 0)) {
         DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_PLEASE_KINDLY_LOGIN_TO_CREATE_A_POST'));
         $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=index', false));
         $app->close();
         return;
     }
     if ($my->id != 0 && !$acl->allowed('add_question', '0') && !$category->canPost()) {
         $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=index', false), JText::_('COM_EASYDISCUSS_SYSTEM_INSUFFICIENT_PERMISSIONS'));
         $app->close();
         return;
     }
     // Set the breadcrumbs.
     $this->setPathway(JText::_('COM_EASYDISCUSS_BREADCRUMBS_ASK'));
     // Set the page title.
     $title = JText::_('COM_EASYDISCUSS_TITLE_ASK');
     if ($id && $post->id) {
         $title = JText::sprintf('COM_EASYDISCUSS_TITLE_EDIT_QUESTION', $post->getTitle());
     }
     // Set the page title
     DiscussHelper::setPageTitle($title);
     if ($editing) {
         $isModerator = DiscussHelper::getHelper('Moderator')->isModerator($post->category_id);
         if (!DiscussHelper::isMine($post->user_id) && !DiscussHelper::isSiteAdmin() && !$acl->allowed('edit_question') && !$isModerator) {
             $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=post&id=' . $postid, false), JText::_('COM_EASYDISCUSS_SYSTEM_INSUFFICIENT_PERMISSIONS'));
             $app->close();
         }
         $tagsModel = DiscussHelper::getModel('PostsTags');
         $post->tags = $tagsModel->getPostTags($post->id);
     } else {
         if ($categoryId) {
             // set the default category
             $post->category_id = $categoryId;
         }
     }
     $attachments = $post->getAttachments();
     if (isset($post->sessiondata)) {
         $attachments = '';
     }
     $model = DiscussHelper::getModel('Posts');
     $postCount = count($model->getPostsBy('user', $my->id));
     $onlyPublished = empty($post->id) ? true : false;
     // @rule: If there is a category id passed through the query, respect it first.
     $showPrivateCat = empty($post->id) && $my->id == 0 ? false : true;
     // [model:category]
     $categoryModel = $this->getModel('Category');
     $defaultCategory = $categoryModel->getDefaultCategory();
     if ($categoryId == 0 && $defaultCategory !== false) {
         $categoryId = $defaultCategory->id;
     }
     $nestedCategories = '';
     $categories = '';
     if ($config->get('layout_category_selection') == 'multitier') {
         $categoriesModel = $this->getModel('Categories');
         $categories = $categoriesModel->getCategories(array('acl_type' => DISCUSS_CATEGORY_ACL_ACTION_SELECT));
     } else {
         $nestedCategories = DiscussHelper::populateCategories('', '', 'select', 'category_id', $categoryId, true, $onlyPublished, $showPrivateCat, true);
     }
     // if( $config->get( 'layout_editor' ) == 'bbcode' )
     // {
     // 	// Legacy fix when switching from WYSIWYG editor to bbcode.
     // 	$post->content	= EasyDiscussParser::html2bbcode( $post->content );
     // }
     // else
     // {
     // 	$post->content = DiscussHelper::parseContent( $post->content, true );
     // }
     $editor = '';
     if ($config->get('layout_editor') != 'bbcode') {
         $editor = JFactory::getEditor($config->get('layout_editor'));
     }
     // Get list of moderators from the site.
     $moderatorList = array();
     if ($config->get('main_assign_user')) {
         $moderatorList = DiscussHelper::getHelper('Moderator')->getSelectOptions($post->category_id);
     }
     // Get post types list
     $postTypesModel = DiscussHelper::getModel('Post_types');
     $postTypes = $postTypesModel->getTypes();
     $composer = new DiscussComposer("creating", $post);
     // Set the discussion object.
     $access = $post->getAccess($category);
     $theme = new DiscussThemes();
     // Test if reference is passed in query string.
     $reference = JRequest::getWord('reference');
     $referenceId = JRequest::getInt('reference_id', 0);
     $redirect = JRequest::getVar('redirect', '');
     $theme->set('redirect', $redirect);
     $theme->set('reference', $reference);
     $theme->set('referenceId', $referenceId);
     $theme->set('isEditMode', $editing);
     $theme->set('post', $post);
     $theme->set('composer', $composer);
     $theme->set('nestedCategories', $nestedCategories);
     $theme->set('attachments', $attachments);
     $theme->set('editor', $editor);
     $theme->set('moderatorList', $moderatorList);
     $theme->set('categories', $categories);
     $theme->set('access', $access);
     $theme->set('postTypes', $postTypes);
     // Deprecated since 3.0. Will be removed in 4.0
     $theme->set('config', $config);
     echo $theme->fetch('form.new.php');
 }