Esempio n. 1
0
 function __construct()
 {
     parent::__construct();
     $mainframe = JFactory::getApplication();
     $limit = $mainframe->getUserStateFromRequest('com_easydiscuss.posts.limit', 'limit', DiscussHelper::getListLimit(), 'int');
     $limitstart = JRequest::getVar('limitstart', 0, '', 'int');
     $this->setState('limit', $limit);
     $this->setState('limitstart', $limitstart);
 }
Esempio n. 2
0
 public function __construct()
 {
     parent::__construct(array());
     $app = JFactory::getApplication();
     $limit = $app->getUserStateFromRequest('com_easydiscuss.labels.limit', 'limit', DiscussHelper::getListLimit(), 'int');
     $limitstart = JRequest::getVar('limitstart', 0, '', 'int');
     $this->setState('limit', $limit);
     $this->setState('limitstart', $limitstart);
 }
Esempio n. 3
0
 function __construct()
 {
     parent::__construct();
     $mainframe = JFactory::getApplication();
     $limit = $mainframe->getCfg('list_limit') == 0 ? 5 : DiscussHelper::getListLimit();
     $limitstart = JRequest::getVar('limitstart', 0, 'REQUEST');
     // In case limit has been changed, adjust it
     $limitstart = $limit != 0 ? floor($limitstart / $limit) * $limit : 0;
     $this->setState('limit', $limit);
     $this->setState('limitstart', $limitstart);
 }
Esempio n. 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');
 }
Esempio n. 5
0
 public function filter($viewtype = 'user-post', $profileId = null)
 {
     $ajax = new Disjax();
     $mainframe = JFactory::getApplication();
     $config = DiscussHelper::getConfig();
     $acl = DiscussHelper::getHelper('ACL');
     $sort = 'latest';
     $data = null;
     $pagination = null;
     $model = $this->getModel('Posts');
     $tagsModel = $this->getModel('Tags');
     switch ($viewtype) {
         case 'user-achievements':
             $profile = DiscussHelper::getTable('Profile');
             $profile->load($profileId);
             $data = $profile->getBadges();
             break;
         case 'user-tags':
             $data = $tagsModel->getTagCloud('', '', '', $profileId);
             break;
         case 'user-replies':
             $data = $model->getRepliesFromUser($profileId);
             $pagination = $model->getPagination();
             DiscussHelper::formatPost($data);
             break;
         case 'user-unresolved':
             $data = $model->getUnresolvedFromUser($profileId);
             $pagination = $model->getPagination();
             DiscussHelper::formatPost($data);
             break;
         case 'user-post':
         default:
             if (is_null($profileId)) {
                 break;
             }
             $model = $this->getModel('Posts');
             $data = $model->getPostsBy('user', $profileId);
             $data = DiscussHelper::formatPost($data);
             $pagination = $model->getPagination();
             break;
     }
     // replace the content
     $content = '';
     $tpl = new DiscussThemes();
     $tpl->set('profileId', $profileId);
     if ($viewtype == 'user-post' || $viewtype == 'user-replies' || $viewtype == 'user-unresolved') {
         $nextLimit = DiscussHelper::getListLimit();
         if ($nextLimit >= $pagination->total) {
             // $ajax->remove( 'dc_pagination' );
             $ajax->assign($viewtype . ' #dc_pagination', '');
         }
         $tpl->set('posts', $data);
         $content = $tpl->fetch('main.item.php');
         $ajax->assign($viewtype . ' #dc_list', $content);
         //reset the next start limi
         $ajax->value('pagination-start', $nextLimit);
         if ($nextLimit < $pagination->total) {
             $filterArr = array();
             $filterArr['viewtype'] = $viewtype;
             $filterArr['id'] = $profileId;
             $ajax->assign($viewtype . ' #dc_pagination', $pagination->getPagesLinks('profile', $filterArr, true));
         }
     } else {
         if ($viewtype == 'user-tags') {
             $tpl->set('tagCloud', $data);
             $content = $tpl->fetch('tags.item.php');
             $ajax->assign('discuss-tag-list', $content);
         } else {
             if ($viewtype == 'user-achievements') {
                 $tpl->set('badges', $data);
                 $content = $tpl->fetch('users.achievements.list.php');
                 $ajax->assign('user-achievements', $content);
             }
         }
     }
     $ajax->script('discuss.spinner.hide( "profile-loading" );');
     //$ajax->assign( 'sort-wrapper' , $sort );
     //$ajax->script( 'EasyDiscuss.$("#pagination-filter").val("'.$viewtype.'");');
     $ajax->script('EasyDiscuss.$("#' . $viewtype . '").show();');
     $ajax->script('EasyDiscuss.$("#' . $viewtype . ' #dc_pagination").show();');
     $ajax->send();
 }
Esempio n. 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');
 }
Esempio n. 7
0
 public function sort($sort = null, $filter = null, $categoryId = null)
 {
     $ajax = new Disjax();
     $mainframe = JFactory::getApplication();
     $user = JFactory::getUser();
     $config = DiscussHelper::getConfig();
     $acl = DiscussHelper::getHelper('ACL');
     $activeCategory = DiscussHelper::getTable('Category');
     $activeCategory->load($categoryId);
     //todo: check against the config
     $showAllPosts = 'all';
     $postModel = $this->getModel('Posts');
     $posts = $postModel->getData(true, $sort, null, $filter, $categoryId, null, $showAllPosts);
     $pagination = $postModel->getPagination('0', $sort, $filter, $categoryId, $showAllPosts);
     $posts = DiscussHelper::formatPost($posts);
     $nextLimit = DiscussHelper::getListLimit();
     if ($nextLimit >= $pagination->total) {
         $ajax->remove('dc_pagination .pagination-wrap');
     }
     $tpl = new DiscussThemes();
     $tpl->set('posts', $posts);
     $content = $tpl->fetch('main.item.php');
     //reset the next start limi
     $ajax->value('pagination-start', $nextLimit);
     if ($nextLimit < $pagination->total) {
         $filterArr = array();
         $filterArr['filter'] = $filter;
         $filterArr['category_id'] = $categoryId;
         $filterArr['sort'] = $sort;
         $ajax->assign('dc_pagination', $pagination->getPagesLinks('index', $filterArr, true));
     }
     $ajax->script('discuss.spinner.hide( "index-loading" );');
     $ajax->script('EasyDiscuss.$("#pagination-sorting").val("' . $sort . '");');
     $ajax->assign('dc_list', $content);
     $ajax->script('EasyDiscuss.$("#dc_list").show();');
     $ajax->script('EasyDiscuss.$("#dc_pagination").show();');
     $ajax->send();
 }