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); }
public function get_recent_posts($uid) { $posts = array(); $id = (int) $uid; $access_conditions = ''; if ($id != \CODOF\User\CurrentUser\CurrentUser::id()) { $topic = new \CODOF\Forum\Topic(false); $access_conditions = "AND " . $topic->getViewTopicPermissionConditions(); } $qry = 'SELECT c.cat_alias,c.cat_img,p.omessage AS message, t.title, t.topic_id,' . ' u.id, u.name, u.avatar, t.topic_created,t.no_posts,t.no_views, p.post_created,p.post_id ' . ' FROM ' . PREFIX . 'codo_posts AS p ' . ' LEFT JOIN ' . PREFIX . 'codo_categories AS c ON p.cat_id=c.cat_id ' . ' LEFT JOIN ' . PREFIX . 'codo_topics AS t ON t.topic_id=p.topic_id ' . ' LEFT JOIN ' . PREFIX . 'codo_users AS u ON t.uid=u.id ' . ' WHERE p.uid = ' . $id . ' AND p.post_status<>0 ' . $access_conditions . ' ORDER BY p.post_created DESC ' . ' LIMIT 20 OFFSET 0'; $obj = $this->db->query($qry); if ($obj) { $posts = $this->gen_posts_arr($obj->fetchAll()); } $category = new \CODOF\Forum\Category(); return array("topics" => $posts, "RURI" => RURI, "DURI" => DURI, "CAT_IMGS" => CAT_IMGS, "CURR_THEME" => CURR_THEME, "reply_txt" => _t("replies"), "views_txt" => _t("views"), "posted" => _t("posted"), "created" => _t("created"), "no_topics" => _t("You have no recent posts"), "new_topic" => _t("Create new topic"), "can_create" => $category->canCreateTopicInAtleastOne()); }
public function delete($id) { //post id $tid = (int) $id; $topic = new \CODOF\Forum\Topic($this->db); $topic_info = $topic->get_topic_info($tid); $cid = $topic_info['cat_id']; $tuid = $topic_info['uid']; if ($topic->canViewTopic($tuid, $cid, $tid) && $topic->canDeleteTopic($tuid, $cid, $tid)) { $isSpam = $_POST['isSpam']; if ($isSpam == 'yes') { $text = \DB::table(PREFIX . 'codo_posts AS p')->join(PREFIX . 'codo_topics AS t', 'p.topic_id', '=', 't.topic_id')->where('t.topic_id', '=', $tid)->pluck('p.imessage'); $filter = new \CODOF\SpamFilter(); $filter->spam($text); } //Set topic as deleted $topic->delete($cid, $tid); //update all posts linked with this topic as deleted $post = new \CODOF\Forum\Post($this->db); $post->deleteOfTopic($cid, $tid); echo 'success'; } else { exit('access denied'); } }
private function base_query() { if ($this->count_rows && $this->isMySQL) { $count = 'SQL_CALC_FOUND_ROWS'; } else { $count = ''; } $qry = 'SELECT ' . $count . ' #SELECTORS# ' . 'FROM codo_posts AS p ' . 'LEFT JOIN codo_topics AS t ON t.topic_id=p.topic_id ' . 'LEFT JOIN codo_users AS u ON u.id=p.uid ' . 'LEFT JOIN codo_categories AS c ON c.cat_id=t.cat_id ' . 'LEFT JOIN codo_user_roles AS r ON r.uid=u.id AND r.is_primary=1 ' . 'WHERE t.topic_status<>0 ' . ' AND p.post_status=1' . ' #CONDITIONS# '; if ($this->cats != null) { $qry .= ' AND p.cat_id IN (?) '; } if ($this->tid != null) { if (strpos($this->tid, '=') === FALSE) { $this->tid = ' = ' . $this->tid; } $qry .= ' AND p.topic_id ' . $this->tid; } if ($this->pid != null) { $qry .= ' AND p.post_id ' . $this->pid; } if ($this->time_within != 'anytime') { $time = new \CODOF\Time(); $error = false; if ($this->time_within == 'hour') { $this->time_within = $time->unix_get_time_hour(); } else { if ($this->time_within == 'day') { $this->time_within = $time->unix_get_time_day(); } else { if ($this->time_within == 'week') { $this->time_within = $time->unix_get_time_day(7); } else { if ($this->time_within == 'month') { $this->time_within = $time->unix_get_time_day(31); } else { if ($this->time_within == 'year') { $this->time_within = $time->unix_get_time_day(365); } else { $error = true; } } } } } if (!$error) { $qry .= ' AND p.post_created > ' . $this->time_within; } } $topic = new \CODOF\Forum\Topic(false); $qry .= ' AND ' . $topic->getViewTopicPermissionConditions(); $qry .= ' ORDER BY #SORT# #ORDER# LIMIT ' . $this->num_results . ' OFFSET ' . $this->from; return $qry; }
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')); //); }
public function approveReply($_pid) { $db = \DB::getPDO(); $pid = (int) $_pid; $qry = 'SELECT p.post_status, p.cat_id, p.topic_id, p.uid,p.post_created, p.imessage FROM ' . PREFIX . 'codo_posts AS p' . ' WHERE p.post_id=' . $pid; $res = $db->query($qry); if ($res) { $row = $res->fetch(); $status = $row['post_status']; $cid = $row['cat_id']; $text = $row['imessage']; $user = \CODOF\User\User::get(); if ($user->can('moderate posts', $cid)) { $qry = 'UPDATE ' . PREFIX . 'codo_posts SET post_status=' . \CODOF\Forum\Forum::APPROVED . ' WHERE post_id=' . $pid; $db->query($qry); $post = new \CODOF\Forum\Post($db); $post->incPostCount($cid, $row['topic_id'], $row['uid']); $options = array(":pid" => $pid, ":uid" => $user->id, ":name" => $user->name, ":time" => $row['post_created'], ":tid" => $row['topic_id']); $topic = new \CODOF\Forum\Topic($db); $topic->update_last_post_details($options); //If a post considered as spam by filter is being approved //it means the filter needs to relearn that it is not spam if ($status == \CODOF\Forum\Forum::MODERATION_BY_FILTER) { $filter = new \CODOF\SpamFilter(); $filter->ham($text); } } } }
public function listTaggedTopics($tag, $page = 1) { $posts_per_page = \CODOF\Util::get_opt("num_posts_all_topics"); if ($page == null) { $page = 1; } $page = (int) $page; if ($page <= 1) { $from = 0; } else { $from = ($page - 1) * $posts_per_page; } $topics = new \Controller\Ajax\forum\topics(); $taggedTopics = $topics->getTaggedTopics($tag, $from); $topic = new \CODOF\Forum\Topic($this->db); $num_pages = $topic->get_num_pages($topic->getTaggedTopicsCount($tag), $posts_per_page); $url = 'tags/' . $tag . '/'; $curr_page = $page; //var_dump($taggedTopics); $this->smarty->assign('tag', $tag); $this->smarty->assign('curr_page', $curr_page); $this->smarty->assign('url', RURI . $url); $this->smarty->assign('num_pages', $num_pages); $this->smarty->assign('topics', json_encode($taggedTopics)); $this->smarty->assign('tags', json_encode($taggedTopics['tags'])); $this->css_files = array('tags'); $this->js_files = array(array('tags/tags.js', array('type' => 'defer'))); $this->view = 'forum/tags'; \CODOF\Store::set('sub_title', $tag . ' - ' . _t('Tags')); }
dispatch_get('Ajax/topic/inc_view', function () { if (Request::valid($_GET['token'])) { $topic = new Controller\Ajax\forum\topic(); $topic->inc_view(); } }); //TODO: Make it category/topic specific so that permissions may be checked dispatch_post('Ajax/topic/upload', function () { if (Request::valid($_POST['token'])) { $topic = new Controller\Ajax\forum\topic(); $topic->upload(); } }); //safe dispatch_get('Ajax/topic/:tid/:from/get_posts', function ($tid, $from) { $topic = new \CODOF\Forum\Topic(\DB::getPDO()); $topic_info = $topic->get_topic_info($tid); if ($topic->canViewTopic($topic_info['uid'], $topic_info['cat_id'], $topic_info['topic_id'])) { $topics = new Controller\Ajax\forum\topic(); echo json_encode($topics->get_posts($tid, $from, $topic_info)); } else { exit('Permission denied'); } }); //safe dispatch_post('Ajax/moderation/topics/approve', function () { if (Request::valid($_POST['token'])) { $mod = new Controller\Ajax\moderation(); $mod->approveTopics(); } });