public function get_topics($catid, $page)
 {
     $topic = new \CODOF\Forum\Topic($this->db);
     $topics = array();
     $cid = (int) $catid;
     $num_pages = 'not_passed';
     if (isset($_GET['get_page_count']) && $_GET['get_page_count'] == 'yes') {
         $num_pages = 'calc_count';
     }
     $new_topics = array();
     $new_replies = array();
     if (isset($_GET['str']) && $_GET['str'] != "") {
         $user = \CODOF\User\User::get();
         if (!$user->can('use search')) {
             exit('permission denied');
         }
         $search = new \CODOF\Search\Search();
         $search->str = $_GET['str'];
         $search->num_results = \CODOF\Util::get_opt("num_posts_cat_topics");
         $search->from = ($page - 1) * $search->num_results;
         if ($num_pages == 'calc_count') {
             $search->count_rows = true;
         }
         $cats = (int) $_GET['catid'];
         $search->cats = $cats;
         $search->match_titles = $_GET['match_titles'];
         $search->order = $_GET['order'];
         $search->sort = $_GET['sort'];
         $search->time_within = $_GET['search_within'];
         $res = $search->search();
         if ($num_pages == 'calc_count') {
             $num_pages = $search->get_total_count();
         }
         $_topics = $topic->gen_topic_arr_all_topics($res, $search);
         $tids = array();
         foreach ($topics as $_topic) {
             $tids[] = $_topic['topic_id'];
         }
         //var_dump($topics);
     } else {
         //$num_pages = $topic->get_num_pages(
         //        $topic->get_num_topics($cid), \CODOF\Util::get_opt("num_posts_cat_topics")
         //);
         $num_pages = 'not_passed';
         $topics = $topic->get_topics($cid, $page);
         $tids = array();
         foreach ($topics as $_topic) {
             $tids[] = $_topic['topic_id'];
         }
         if (\CODOF\User\CurrentUser\CurrentUser::loggedIn()) {
             $tracker = new \CODOF\Forum\Tracker($this->db);
             $topic->new_topic_ids = $tracker->get_new_topic_ids($cid, $tids);
             $topic->new_replies = $tracker->get_new_reply_counts($tids);
         }
         $topic->tags = $topic->getAllTags($tids);
         $_topics = $topic->gen_topic_arr($topics, $cid);
     }
     return array("topics" => $_topics, "new_topics" => $topic->new_topic_ids, "page_no" => $page, "num_pages" => $num_pages);
 }
Example #2
0
 public function get_posts($tid, $from, $topic_info)
 {
     $post = new \CODOF\Forum\Post($this->db);
     $posts = array();
     $num_pages = 'not_passed';
     $posts_per_page = \CODOF\Util::get_opt("num_posts_per_topic");
     $title = \CODOF\Filter::URL_safe($topic_info['title']);
     if (isset($_GET['str'])) {
         $num_pages = 'calc_count';
     }
     if (isset($_GET['str']) && $_GET['str'] != "") {
         $user = \CODOF\User\User::get();
         if (!$user->can('use search')) {
             exit('permission denied');
         }
         $search = new \CODOF\Search\Search();
         $search->str = $_GET['str'];
         $search->num_results = $posts_per_page;
         $search->from = $from * $search->num_results;
         if ($num_pages == 'calc_count') {
             $search->count_rows = true;
         }
         $search->tid = $tid;
         $search->match_titles = 'No';
         $search->order = $_GET['order'];
         $search->sort = $_GET['sort'];
         $search->time_within = $_GET['search_within'];
         $res = $search->search();
         if ($num_pages == 'calc_count') {
             $num_pages = $post->get_num_pages($search->get_total_count(), $search->num_results);
         }
         $post->topic_post_id = $topic_info['post_id'];
         $post->tuid = $topic_info['uid'];
         $post->cat_id = $topic_info['cat_id'];
         $post->tid = $tid;
         $post->safe_title = $title;
         $post->from = $from;
         $posts = $post->gen_posts_arr($res, $search);
         //var_dump($topics);
     } else {
         $topic = new \CODOF\Forum\Topic($this->db);
         $num_pages = $topic->get_num_pages($topic_info['no_posts'], $posts_per_page);
         $post->topic_post_id = $topic_info['post_id'];
         $post->tuid = $topic_info['uid'];
         $post->cat_id = $topic_info['cat_id'];
         $post->tid = $tid;
         $post->safe_title = $title;
         $post->from = $from;
         $posts = $post->get_posts($tid, $from);
     }
     return array("posts" => $posts, "num_pages" => $num_pages);
 }
Example #3
0
 /**
  * 
  * Ajax/topics/get_topics/:page/filter=[str=:str,]/sort=[title,created]
  * 
  */
 public function get_topics($from, $search = false)
 {
     $from = (int) $from;
     $num_pages = 0;
     $num_posts = \CODOF\Util::get_opt('num_posts_all_topics');
     /* if(!$from) {
     
               $from = \CODOF\Util::get_opt('num_posts_all_topics');
               } */
     $topic = new \CODOF\Forum\Topic($this->db);
     $topic->ajax = true;
     $topics = array();
     if ($search) {
         $user = \CODOF\User\User::get();
         if (!$user->can('use search')) {
             exit('permission denied');
         }
         $search = new \CODOF\Search\Search();
         $search->str = $_GET['str'];
         $search->from = $from;
         $search->num_results = $num_posts;
         $search->count_rows = true;
         //include sub categories ?
         /* if ($_GET['search_subcats'] == 'Yes') {
         
                       $cat = new \CODOF\Forum\Category($this->db);
                       //get sub categories of all selected categories
                       $tree = $cat->generate_tree($cat->get_categories());
                       foreach ($tree as $branch) {
         
                       $this->get_children($branch, $_GET['cats']);
                       }
                       } */
         //$cat_ids = array_merge($this->ids, $_GET['cats']);
         //$cats = implode(",", $cat_ids);
         $search->cats = null;
         $search->match_titles = $_GET['match_titles'];
         $search->order = $_GET['order'];
         $search->sort = $_GET['sort'];
         $search->time_within = $_GET['search_within'];
         $res = $search->search($from);
         $num_pages = $search->get_total_count();
         $topics = $topic->gen_topic_arr_all_topics($res, $search);
         //var_dump($topics);
     } else {
         $_topics = $topic->get_all_topics($from);
         $tids = array();
         foreach ($_topics as $one_topic) {
             $tids[] = $one_topic['topic_id'];
         }
         if (\CODOF\User\CurrentUser\CurrentUser::loggedIn()) {
             $tracker = new \CODOF\Forum\Tracker($this->db);
             //0.76 = 3 queries
             $topic->new_topic_ids = $tracker->get_all_new_topic_ids($tids);
             $topic->new_replies = $tracker->get_new_reply_counts($tids);
         }
         $topic->tags = $topic->getAllTags($tids);
         $topics = $topic->gen_topic_arr_all_topics($_topics);
     }
     return array("topics" => $topics, "page_no" => $from ? $from / $num_posts : 1, "num_posts" => $num_posts, "num_pages" => $num_pages);
 }