Esempio n. 1
0
 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);
 }
Esempio n. 2
0
 public function topic($tid, $page)
 {
     $topic = new \CODOF\Forum\Topic($this->db);
     $post = new \CODOF\Forum\Post($this->db);
     $topic_info = $topic->get_topic_info($tid);
     if ($topic_info['topic_status'] == \CODOF\Forum\Forum::MERGED_REDIRECT_ONLY) {
         $tid = $topic_info['redirect_to'];
         $topic_info = $topic->get_topic_info($tid);
     }
     if ($topic_info['topic_status'] == \CODOF\Forum\Forum::MODERATION_BY_FILTER) {
         $topic_is_spam = true;
     } else {
         $topic_is_spam = false;
     }
     $this->smarty->assign('topic_is_spam', $topic_is_spam);
     $user = \CODOF\User\User::get();
     if ($topic_is_spam) {
         if (!($user->can('moderate topics') || $user->id == $topic_info['uid'])) {
             $this->view = 'access_denied';
             return false;
         }
     }
     if (!$topic->canViewTopic($topic_info['uid'], $topic_info['cat_id'], $topic_info['topic_id'])) {
         //\CODOF\Hook::call('page not found', array('type' => 'topic', 'id' => $tid));
         \CODOF\Store::set('sub_title', _t('Access denied'));
         $this->view = 'access_denied';
         return;
     }
     $tracker = new \CODOF\Forum\Tracker($this->db);
     $tracker->mark_topic_as_read($topic_info['cat_id'], $tid);
     if (!$topic_info) {
         $this->view = 'not_found';
     } else {
         $posts_per_page = \CODOF\Util::get_opt("num_posts_per_topic");
         if (strpos($page, "post-") !== FALSE) {
             $pid = (int) str_replace("post-", "", $page);
             $prev_posts = $post->get_num_prev_posts($tid, $pid);
             $from = floor($prev_posts / $posts_per_page);
         } else {
             $from = (int) $page - 1;
         }
         $topic_info['no_replies'] = $topic_info['no_posts'] - 1;
         $name = \CODOF\Filter::URL_safe($topic_info['title']);
         $subscriber = new \CODOF\Forum\Notification\Subscriber();
         $this->smarty->assign('no_followers', $subscriber->followersOfTopic($topic_info['topic_id']));
         if (\CODOF\User\CurrentUser\CurrentUser::loggedIn()) {
             $this->smarty->assign('my_subscription_type', $subscriber->levelForTopic($topic_info['topic_id']));
         }
         $this->smarty->assign('tags', $topic->getTags($topic_info['topic_id']));
         $api = new Ajax\forum\topic();
         $posts_data = $api->get_posts($tid, $from, $topic_info);
         $num_pages = $posts_data['num_pages'];
         $posts = $posts_data['posts'];
         $posts_tpl = \CODOF\HB\Render::tpl('forum/topic', $posts_data);
         $this->smarty->assign('posts', $posts_tpl);
         $this->smarty->assign('topic_info', $topic_info);
         $this->smarty->assign('title', htmlentities($topic_info['title'], ENT_QUOTES, "UTF-8"));
         $search_data = array();
         if (isset($_GET['str'])) {
             $search_data = array('str' => strip_tags($_GET['str']));
         }
         $this->smarty->assign('search_data', json_encode($search_data));
         $url = 'topic/' . $topic_info['topic_id'] . '/' . $name . '/';
         $this->smarty->assign('pagination', $post->paginate($num_pages, $from + 1, $url, false, $search_data));
         if (ceil(($topic_info['no_posts'] + 1) / $posts_per_page) > $num_pages) {
             //next reply will go to next page
             $this->smarty->assign('new_page', 'yes');
         } else {
             $this->smarty->assign('new_page', 'nope');
         }
         $cat = new \CODOF\Forum\Category($this->db);
         $cats = $cat->get_categories();
         $cid = $topic_info['cat_id'];
         $parents = $cat->find_parents($cats, $cid);
         array_push($parents, array("name" => $topic_info['cat_name'], "alias" => $topic_info['cat_alias']));
         $this->smarty->assign('can_search', $user->can('use search'));
         $this->smarty->assign('parents', $parents);
         $this->smarty->assign('num_pages', $num_pages);
         $this->smarty->assign('curr_page', $from + 1);
         //starts from 1
         $this->smarty->assign('url', RURI . $url);
         $this->assign_editor_vars();
         $tuid = $topic_info['uid'];
         $this->assign_admin_vars($tuid);
         $this->css_files = array('topic', 'editor', 'jquery.textcomplete');
         $arr = array(array('topic/topic.js', array('type' => 'defer')), array('modal.js', array('type' => 'defer')), array('bootstrap-slider.js', array('type' => 'defer')));
         $this->js_files = array_merge($arr, $post->get_js_editor_files());
         \CODOF\Hook::call('on_topic_view', array($topic_info));
         $this->view = 'forum/topic';
         \CODOF\Store::set('sub_title', $topic_info['title']);
         \CODOF\Store::set('og:type', 'article');
         \CODOF\Store::set('og:title', $topic_info['title']);
         \CODOF\Store::set('og:url', RURI . $url);
         $mesg = $posts[0]['imessage'];
         \CODOF\Store::set('og:desc', strlen($mesg) > 200 ? substr($mesg, 0, 197) . "..." : $mesg);
         if ($from > 0) {
             //previous page exists
             \CODOF\Store::set('rel:prev', RURI . $url . $from);
         }
         $curr_page = $from + 1;
         if ($curr_page < $num_pages) {
             //next page exists
             \CODOF\Store::set('rel:next', RURI . $url . ($curr_page + 1));
         }
         \CODOF\Store::set('article:published', date('c', $topic_info['topic_created']));
         if ($topic_info['topic_updated'] > 0) {
             \CODOF\Store::set('article:modified', date('c', $topic_info['topic_updated']));
         }
     }
 }
Esempio n. 3
0
 public function getTaggedTopics($tag, $from)
 {
     $new_topic_ids = array();
     $new_replies = array();
     $topic = new \CODOF\Forum\Topic($this->db);
     $topic->ajax = true;
     $topics = $topic->getTaggedTopics($tag, $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
         $new_topic_ids = $tracker->get_all_new_topic_ids($tids);
         $new_replies = $tracker->get_new_reply_counts($tids);
     }
     //echo json_encode(
     return array("topics" => $topics, "tags" => $topic->getAllTags($tids), "new_topic_ids" => $new_topic_ids, "find_topics_tagged" => _t("find topics tagged"), "new_replies" => $new_replies, "new" => _t("new"), "new_topic" => _t("new topic"), "new_replies_txt" => _t("new replies"), "RURI" => RURI, "DURI" => DURI, "CAT_IMGS" => CAT_IMGS, "CURR_THEME" => CURR_THEME, "reply_txt" => _t("replies"), "views_txt" => _t("views"), "recent_txt" => _t('recent by'), "num_posts" => \CODOF\Util::get_opt('num_posts_all_topics'));
     //);
 }
Esempio n. 4
0
});
dispatch_get('Ajax/topics/mark_read', function () {
    if (Request::valid($_GET['token'])) {
        $tracker = new CODOF\Forum\Tracker();
        $tracker->mark_forum_as_read();
    }
});
dispatch_get('Ajax/topics/mark_read/:cid', function ($cid) {
    if (Request::valid($_GET['token'])) {
        $tracker = new CODOF\Forum\Tracker();
        $tracker->mark_category_as_read($cid);
    }
});
dispatch_get('Ajax/topics/mark_read/:cid/:tid', function ($cid, $tid) {
    if (Request::valid($_GET['token'])) {
        $tracker = new CODOF\Forum\Tracker();
        $tracker->mark_topic_as_read($cid, $tid);
    }
});
dispatch_get('Ajax/user/profile/:uid/get_recent_posts', function ($uid) {
    if (Request::valid($_GET['token'])) {
        $profile = new \Controller\Ajax\user\profile();
        echo json_encode($profile->get_recent_posts($uid));
    }
});
Request::post('Ajax/user/profile/update_preferences', function () {
    //whitelisted column names
    $updates = array("notification_frequency" => $_POST['notification_frequency'], "send_emails_when_online" => $_POST['send_emails_when_online'], "real_time_notifications" => $_POST['real_time_notifications'], "desktop_notifications" => $_POST['desktop_notifications'], "notification_type_on_create_topic" => $_POST['notification_levels']['on_create_topic'], "notification_type_on_reply_topic" => $_POST['notification_levels']['on_reply_topic']);
    $user = CODOF\User\User::get();
    $user->updatePreferences($updates);
});