Ejemplo n.º 1
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);
 }