Exemplo n.º 1
0
 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());
 }
Exemplo n.º 2
0
function delete_category($id, $delete_children)
{
    $cids = array();
    if ($delete_children === 'yes') {
        $category = new CODOF\Forum\Category(\DB::getPDO());
        $cats_tree = $category->generate_tree($category->get_categories());
        $children = $category->get_sub_categories($cats_tree, $id);
        $cids = get_cids($children);
        if ($cids !== NULL) {
            DB::table(PREFIX . 'codo_categories')->whereIn('cat_id', $cids)->delete();
        } else {
            $cids = array();
        }
    } else {
        DB::table(PREFIX . 'codo_categories')->where('cat_pid', '=', $id)->update(array('cat_pid' => 0));
    }
    DB::table(PREFIX . 'codo_categories')->where('cat_id', $id)->delete();
    //delete all topics
    if ($delete_children !== 'yes') {
        $ids = array($id);
    } else {
        $ids = array_merge(array($id), $cids);
    }
    DB::table(PREFIX . 'codo_topics')->whereIn('cat_id', $ids)->delete();
    DB::table(PREFIX . 'codo_unread_topics')->whereIn('cat_id', $ids)->delete();
    DB::table(PREFIX . 'codo_unread_categories')->whereIn('cat_id', $ids)->delete();
    //DB::table(PREFIX . 'codo_tags AS g')
    //        ->join(PREFIX . 'codo_topics AS t', 't.topic_id', '=', 'g.topic_id')
    //        ->whereIn('t.cat_id', $ids)->delete();
    $q = 'DELETE codo_tags FROM ' . PREFIX . 'codo_tags ' . ' LEFT JOIN ' . PREFIX . 'codo_topics ON ' . PREFIX . 'codo_tags.topic_id=' . PREFIX . 'codo_topics.topic_id ' . ' WHERE ' . PREFIX . 'codo_topics.cat_id IN (' . implode(',', $ids) . ')';
    \DB::delete($q);
    DB::table(PREFIX . 'codo_notify_subscribers')->whereIn('cid', $ids)->delete();
    DB::table(PREFIX . 'codo_permissions')->whereIn('cid', $ids)->delete();
    $qry = 'UPDATE ' . PREFIX . 'codo_users AS u,' . PREFIX . 'codo_posts As p SET no_posts=no_posts-' . '(SELECT COUNT(post_id) FROM codo_posts WHERE cat_id=' . $id . ' AND post_status <> 0 AND uid=u.id) 
            WHERE p.cat_id=' . $id . ' AND u.id=p.uid';
    DB::getPDO()->query($qry);
    DB::table(PREFIX . 'codo_posts')->whereIn('cat_id', $ids)->delete();
}
Exemplo n.º 3
0
 public static function load($tpl, $css_files = array(), $js_files = array())
 {
     \CODOF\Util::inc_global_views();
     //This sets all variables which will be used by the theme
     require CURR_THEME_PATH . 'theme.php';
     $page = array();
     \CODOF\Hook::call('before_site_head');
     \CODOF\Hook::call('tpl_before_' . str_replace("/", "_", $tpl));
     $asset = new \CODOF\Asset\Stream();
     $page["head"]["css"] = $asset->dumpCSS();
     //\CODOF\Theme\Js::sort_js();
     $page["head"]["js"] = $asset->dumpJS('head');
     $page["body"]["js"] = $asset->dumpJS('body');
     $page["defer"] = json_encode($asset->deferred());
     //after all modification its time for smarty to display the mod data
     $smarty = Single::get_instance();
     $site_title = \CODOF\Util::get_opt('site_title');
     $sub_title = \CODOF\Store::get('sub_title');
     $smarty->assign('site_title', $site_title);
     $smarty->assign('sub_title', $sub_title);
     $smarty->assign('home_title', \CODOF\Store::get('home_title', _t('All topics')));
     $smarty->assign('site_url', \CODOF\Util::get_opt('site_url'));
     $smarty->assign('logged_in', \CODOF\User\CurrentUser\CurrentUser::loggedIn());
     $smarty->assign('login_url', \CODOF\User\User::getLoginUrl());
     $smarty->assign('logout_url', \CODOF\User\User::getLogoutUrl());
     $smarty->assign('register_url', \CODOF\User\User::getRegisterUrl());
     $smarty->assign('profile_url', \CODOF\User\User::getProfileUrl());
     $smarty->assign('page', $page);
     $smarty->assign('CSRF_token', \CODOF\Access\CSRF::get_token());
     $smarty->assign('php_time_now', time());
     $category = new \CODOF\Forum\Category();
     $canCreateTopicInAtleastOneCategory = $category->canCreateTopicInAtleastOne();
     $smarty->assign('canCreateTopicInAtleastOneCategory', $canCreateTopicInAtleastOneCategory);
     $page = \CODOF\Store::get('rel:canonical_page', isset($_GET['u']) ? $_GET['u'] : '');
     $smarty->assign('canonical', rtrim(RURI, '/') . strip_tags($page));
     if (\CODOF\Store::has('rel:prev')) {
         $smarty->assign('rel_prev', \CODOF\Store::get('rel:prev'));
     }
     if (\CODOF\Store::has('rel:next')) {
         $smarty->assign('rel_next', \CODOF\Store::get('rel:next'));
     }
     if (\CODOF\Store::has('meta:robots')) {
         $smarty->assign('meta_robots', \CODOF\Store::get('meta:robots'));
     }
     $og = array("type" => \CODOF\Store::get('og:type', 'website'), "title" => \CODOF\Store::get('og:title', $sub_title . ' | ' . $site_title));
     if (\CODOF\Store::has('og:url')) {
         $og['url'] = \CODOF\Store::get('og:url');
     }
     if (\CODOF\Store::has('og:desc')) {
         $og['desc'] = \CODOF\Store::get('og:desc');
     } else {
         $og['desc'] = \CODOF\Util::get_opt('site_description');
     }
     if (\CODOF\Store::has('og:image')) {
         $og['image'] = \CODOF\Store::get('og:image');
     }
     $smarty->assign('og', $og);
     if (\CODOF\Store::has('article:published')) {
         $smarty->assign('article_published', \CODOF\Store::get('article:published'));
     }
     if (\CODOF\Store::has('article:modified')) {
         $smarty->assign('article_modified', \CODOF\Store::get('article:modified'));
     }
     $I = \CODOF\User\User::get();
     //current user details
     $smarty->assign('I', $I);
     $smarty->assign('can_moderate_posts', $I->can('moderate posts'));
     if (\CODOF\User\CurrentUser\CurrentUser::loggedIn()) {
         $notifier = new \CODOF\Forum\Notification\Notifier();
         $smarty->assign('unread_notifications', $notifier->getNoOfUnread());
     }
     $html = $smarty->fetch("{$tpl}.tpl");
     require_once SYSPATH . 'Ext/simplehtmldom/simple_html_dom.php';
     $dom = new \simple_html_dom();
     $dom->load($html, true, false);
     //let plugins modify html
     \CODOF\Hook::call('tpl_after_' . str_replace("/", "_", $tpl), $dom);
     \CODOF\Hook::call('after_site_head', $dom);
     echo $dom->save();
 }
Exemplo n.º 4
0
 public function create()
 {
     //hacking attempt
     if ($_POST['end_of_line'] != "") {
         exit;
     }
     if (isset($_POST['title']) && isset($_POST['cat']) && isset($_POST['imesg']) && isset($_POST['omesg'])) {
         $catid = (int) $_POST['cat'];
         $category = new \CODOF\Forum\Category($this->db);
         if (!$category->exists($catid) || !$category->canCreateTopicIn($catid)) {
             exit(_t("No such category exists!"));
         }
         $post = new \CODOF\Forum\Post($this->db);
         $topic = new \CODOF\Forum\Topic($this->db);
         $notifier = new \CODOF\Forum\Notification\Notifier();
         $subscriber = new \CODOF\Forum\Notification\Subscriber();
         $title = \CODOF\Format::title($_POST['title']);
         $filter = new \CODOF\SpamFilter();
         $needsModeration = false;
         $sticky = $_POST['sticky'] === "true" ? 'yes' : 'no';
         $frontpage = $_POST['frontpage'] === "true" ? 'yes' : 'no';
         if ($filter->isSpam($_POST['imesg'])) {
             $needsModeration = true;
         }
         $user = \CODOF\User\User::get();
         if ($sticky == 'yes' && $user->can('make sticky')) {
             if ($frontpage == 'yes') {
                 $tid = $topic->ins_topic($catid, $title, $needsModeration, \CODOF\Forum\Forum::STICKY);
             } else {
                 $tid = $topic->ins_topic($catid, $title, $needsModeration, \CODOF\Forum\Forum::STICKY_ONLY_CATEGORY);
             }
         } else {
             $tid = $topic->ins_topic($catid, $title, $needsModeration, \CODOF\Forum\Forum::APPROVED);
         }
         $pid = $post->ins_post($catid, $tid, $_POST['imesg'], $_POST['omesg']);
         $topic->link_topic_post($pid, $tid);
         //get any @mentions from the topic post
         $mentions = $subscriber->getMentions($_POST['imesg']);
         //get userids from mentions that actually exists in the database
         $ids = $subscriber->getIdsThatExisits($mentions);
         //subscribe self to topic as a Subscriber::NOTIFIED
         $subscriber->toTopic($catid, $tid, \CODOF\Forum\Notification\Subscriber::$NOTIFIED);
         //if post was inserted successfully
         if ($pid) {
             $topicData = array("label" => 'New topic', "cid" => $catid, "tid" => $tid, "tuid" => $user->id, "pid" => $pid, "mentions" => $ids, "message" => \CODOF\Util::start_cut(\CODOF\Format::imessage($_POST['imesg']), 120), "notification" => "%actor% created <b>%title%</b>", "bindings" => array("title" => \CODOF\Util::start_cut($title, 100)));
             $notifier->queueNotify('new_topic', $topicData);
             //$notifier->dequeueNotify();
             \CODOF\Hook::call('after_topic_insert', $topicData);
         }
         //insert tags if any present in the topic
         if (isset($_POST['tags']) && $user->can('add tags')) {
             //the method does the filtering
             $topic->insertTags($tid, $_POST['tags']);
         }
         echo json_encode(array('tid' => $tid));
     }
 }
Exemplo n.º 5
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']));
         }
     }
 }