Example #1
0
 public function markforumread($id)
 {
     $tracked_topics = get_tracked_topics();
     $tracked_topics['forums'][$id] = time();
     Track::set_tracked_topics($tracked_topics);
     Url::redirect($this->feather->urlFor('Forum', array('id' => $id)), __('Mark forum read redirect'));
 }
Example #2
0
 public function handle_actions($topic_id, $action)
 {
     $action = Container::get('hooks')->fire('model.topic.handle_actions_start', $action, $topic_id);
     // If action=new, we redirect to the first new post (if any)
     if ($action == 'new') {
         if (!User::get()->is_guest) {
             // We need to check if this topic has been viewed recently by the user
             $tracked_topics = Track::get_tracked_topics();
             $last_viewed = isset($tracked_topics['topics'][$topic_id]) ? $tracked_topics['topics'][$topic_id] : User::get()->last_visit;
             $first_new_post_id = DB::for_table('posts')->where('topic_id', $topic_id)->where_gt('posted', $last_viewed)->min('id');
             $first_new_post_id = Container::get('hooks')->fire('model.topic.handle_actions_first_new', $first_new_post_id);
             if ($first_new_post_id) {
                 return Router::redirect(Router::pathFor('viewPost', ['pid' => $first_new_post_id]) . '#p' . $first_new_post_id);
             }
         }
         // If there is no new post, we go to the last post
         $action = 'last';
     }
     // If action=last, we redirect to the last post
     if ($action == 'last') {
         $last_post_id = DB::for_table('posts')->where('topic_id', $topic_id)->max('id');
         $last_post_id = Container::get('hooks')->fire('model.topic.handle_actions_last_post', $last_post_id);
         if ($last_post_id) {
             return Router::redirect(Router::pathFor('viewPost', ['pid' => $last_post_id]) . '#p' . $last_post_id);
         }
     }
     Container::get('hooks')->fire('model.topic.handle_actions', $action, $topic_id);
 }
Example #3
0
 protected function get_new_posts()
 {
     $this->hook->fire('get_new_posts_start');
     $query['select'] = array('f.id', 'f.last_post');
     $query['where'] = array(array('fp.read_forum' => 'IS NULL'), array('fp.read_forum' => '1'));
     $query = DB::for_table('forums')->table_alias('f')->select_many($query['select'])->left_outer_join('forum_perms', array('fp.forum_id', '=', 'f.id'), 'fp')->left_outer_join('forum_perms', array('fp.group_id', '=', $this->user->g_id), null, true)->where_any_is($query['where'])->where_gt('f.last_post', $this->user->last_visit);
     $query = $this->hook->fireDB('query_get_new_posts', $query);
     $query = $query->find_result_set();
     $forums = $new_topics = array();
     $tracked_topics = Track::get_tracked_topics();
     foreach ($query as $cur_forum) {
         if (!isset($tracked_topics['forums'][$cur_forum->id]) || $tracked_topics['forums'][$cur_forum->id] < $cur_forum->last_post) {
             $forums[$cur_forum->id] = $cur_forum->last_post;
         }
     }
     if (!empty($forums)) {
         if (empty($tracked_topics['topics'])) {
             $new_topics = $forums;
         } else {
             $query['select'] = array('forum_id', 'id', 'last_post');
             $query = DB::for_table('topics')->select_many($query['select'])->where_in('forum_id', array_keys($forums))->where_gt('last_post', $this->user->last_visit)->where_null('moved_to');
             $query = $this->hook->fireDB('get_new_posts_query', $query);
             $query = $query->find_result_set();
             foreach ($query as $cur_topic) {
                 if (!isset($new_topics[$cur_topic->forum_id]) && (!isset($tracked_topics['forums'][$cur_topic->forum_id]) || $tracked_topics['forums'][$cur_topic->forum_id] < $forums[$cur_topic->forum_id]) && (!isset($tracked_topics['topics'][$cur_topic->id]) || $tracked_topics['topics'][$cur_topic->id] < $cur_topic->last_post)) {
                     $new_topics[$cur_topic->forum_id] = $forums[$cur_topic->forum_id];
                 }
             }
         }
     }
     $new_topics = $this->hook->fire('get_new_posts', $new_topics);
     return $new_topics;
 }
Example #4
0
 public function login()
 {
     if (!$this->feather->user->is_guest) {
         Url::redirect($this->feather->urlFor('home'), 'Already logged in');
     }
     if ($this->feather->request->isPost()) {
         $this->feather->hooks->fire('login_start');
         $form_username = Utils::trim($this->feather->request->post('req_username'));
         $form_password = Utils::trim($this->feather->request->post('req_password'));
         $save_pass = (bool) $this->feather->request->post('save_pass');
         $user = ModelAuth::get_user_from_name($form_username);
         if (!empty($user->password)) {
             $form_password_hash = Random::hash($form_password);
             // Will result in a SHA-1 hash
             if ($user->password == $form_password_hash) {
                 if ($user->group_id == $this->feather->forum_env['FEATHER_UNVERIFIED']) {
                     ModelAuth::update_group($user->id, $this->feather->forum_settings['o_default_user_group']);
                     if (!$this->feather->cache->isCached('users_info')) {
                         $this->feather->cache->store('users_info', Cache::get_users_info());
                     }
                 }
                 ModelAuth::delete_online_by_ip($this->feather->request->getIp());
                 // Reset tracked topics
                 Track::set_tracked_topics(null);
                 $expire = $save_pass ? $this->feather->now + 1209600 : $this->feather->now + $this->feather->forum_settings['o_timeout_visit'];
                 $expire = $this->feather->hooks->fire('expire_login', $expire);
                 ModelAuth::feather_setcookie($user->id, $form_password_hash, $expire);
                 Url::redirect($this->feather->urlFor('home'), __('Login redirect'));
             }
         }
         throw new Error(__('Wrong user/pass') . ' <a href="' . $this->feather->urlFor('resetPassword') . '">' . __('Forgotten pass') . '</a>', 403);
     } else {
         $this->feather->template->setPageInfo(array('active_page' => 'login', 'title' => array(Utils::escape($this->feather->forum_settings['o_board_title']), __('Login')), 'required_fields' => array('req_username' => __('Username'), 'req_password' => __('Password')), 'focus_element' => array('login', 'req_username')))->addTemplate('login/form.php')->display();
     }
 }
Example #5
0
 public function display($req, $res, $args)
 {
     if (!isset($args['page'])) {
         $args['page'] = null;
     }
     if (!isset($args['pid'])) {
         $args['pid'] = null;
     }
     if (!isset($args['name'])) {
         $args['name'] = null;
     }
     Container::get('hooks')->fire('controller.topic.display', $args['id'], $args['name'], $args['page'], $args['pid']);
     // Antispam feature
     $lang_antispam_questions = (require ForumEnv::get('FEATHER_ROOT') . 'featherbb/lang/' . User::get()->language . '/antispam.php');
     $index_questions = rand(0, count($lang_antispam_questions) - 1);
     // Fetch some informations about the topic
     $cur_topic = $this->model->get_info_topic($args['id']);
     // Sort out who the moderators are and if we are currently a moderator (or an admin)
     $mods_array = $cur_topic['moderators'] != '' ? unserialize($cur_topic['moderators']) : array();
     $is_admmod = User::get()->g_id == ForumEnv::get('FEATHER_ADMIN') || User::get()->g_moderator == '1' && array_key_exists(User::get()->username, $mods_array) ? true : false;
     // Can we or can we not post replies?
     $post_link = $this->model->get_post_link($args['id'], $cur_topic['closed'], $cur_topic['post_replies'], $is_admmod);
     // Add/update this topic in our list of tracked topics
     if (!User::get()->is_guest) {
         $tracked_topics = Track::get_tracked_topics();
         $tracked_topics['topics'][$args['id']] = time();
         Track::set_tracked_topics($tracked_topics);
     }
     // Determine the post offset (based on $_GET['p'])
     $num_pages = ceil(($cur_topic['num_replies'] + 1) / User::get()->disp_posts);
     $p = !isset($args['page']) || $args['page'] <= 1 || $args['page'] > $num_pages ? 1 : intval($args['page']);
     $start_from = User::get()->disp_posts * ($p - 1);
     $url_topic = Url::url_friendly($cur_topic['subject']);
     $url_forum = Url::url_friendly($cur_topic['forum_name']);
     // Generate paging links
     $paging_links = '<span class="pages-label">' . __('Pages') . ' </span>' . Url::paginate($num_pages, $p, 'topic/' . $args['id'] . '/' . $url_topic . '/#');
     if (ForumSettings::get('o_censoring') == '1') {
         $cur_topic['subject'] = Utils::censor($cur_topic['subject']);
     }
     $quickpost = $this->model->is_quickpost($cur_topic['post_replies'], $cur_topic['closed'], $is_admmod);
     $subscraction = $this->model->get_subscraction($cur_topic['is_subscribed'] == User::get()->id, $args['id']);
     View::addAsset('canonical', Router::pathFor('Forum', ['id' => $args['id'], 'name' => $url_forum]));
     if ($num_pages > 1) {
         if ($p > 1) {
             View::addAsset('prev', Router::pathFor('ForumPaginate', ['id' => $args['id'], 'name' => $url_forum, 'page' => intval($p - 1)]));
         }
         if ($p < $num_pages) {
             View::addAsset('next', Router::pathFor('ForumPaginate', ['id' => $args['id'], 'name' => $url_forum, 'page' => intval($p + 1)]));
         }
     }
     if (ForumSettings::get('o_feed_type') == '1') {
         View::addAsset('feed', 'extern.php?action=feed&amp;fid=' . $args['id'] . '&amp;type=rss', array('title' => __('RSS forum feed')));
     } elseif (ForumSettings::get('o_feed_type') == '2') {
         View::addAsset('feed', 'extern.php?action=feed&amp;fid=' . $args['id'] . '&amp;type=atom', array('title' => __('Atom forum feed')));
     }
     View::setPageInfo(array('title' => array(Utils::escape(ForumSettings::get('o_board_title')), Utils::escape($cur_topic['forum_name']), Utils::escape($cur_topic['subject'])), 'active_page' => 'Topic', 'page_number' => $p, 'paging_links' => $paging_links, 'is_indexed' => true, 'id' => $args['id'], 'pid' => $args['pid'], 'tid' => $args['id'], 'fid' => $cur_topic['forum_id'], 'post_data' => $this->model->print_posts($args['id'], $start_from, $cur_topic, $is_admmod), 'cur_topic' => $cur_topic, 'subscraction' => $subscraction, 'post_link' => $post_link, 'start_from' => $start_from, 'quickpost' => $quickpost, 'index_questions' => $index_questions, 'lang_antispam_questions' => $lang_antispam_questions, 'url_forum' => $url_forum, 'url_topic' => $url_topic))->addTemplate('topic.php')->display();
     // Increment "num_views" for topic
     $this->model->increment_views($args['id']);
 }
Example #6
0
 public function markread()
 {
     Container::get('hooks')->fire('controller.index.markread');
     Auth::set_last_visit(User::get()->id, User::get()->logged);
     // Reset tracked topics
     Track::set_tracked_topics(null);
     return Router::redirect(Router::pathFor('home'), __('Mark read redirect'));
 }
Example #7
0
 public function display($id = null, $name = null, $page = null, $pid = null)
 {
     // Antispam feature
     require $this->feather->forum_env['FEATHER_ROOT'] . 'featherbb/lang/' . $this->feather->user->language . '/antispam.php';
     $index_questions = rand(0, count($lang_antispam_questions) - 1);
     // Fetch some informations about the topic
     $cur_topic = $this->model->get_info_topic($id);
     // Sort out who the moderators are and if we are currently a moderator (or an admin)
     $mods_array = $cur_topic['moderators'] != '' ? unserialize($cur_topic['moderators']) : array();
     $is_admmod = $this->feather->user->g_id == $this->feather->forum_env['FEATHER_ADMIN'] || $this->feather->user->g_moderator == '1' && array_key_exists($this->feather->user->username, $mods_array) ? true : false;
     if ($is_admmod) {
         $admin_ids = Utils::get_admin_ids();
     }
     // Can we or can we not post replies?
     $post_link = $this->model->get_post_link($id, $cur_topic['closed'], $cur_topic['post_replies'], $is_admmod);
     // Add/update this topic in our list of tracked topics
     if (!$this->feather->user->is_guest) {
         $tracked_topics = Track::get_tracked_topics();
         $tracked_topics['topics'][$id] = time();
         Track::set_tracked_topics($tracked_topics);
     }
     // Determine the post offset (based on $_GET['p'])
     $num_pages = ceil(($cur_topic['num_replies'] + 1) / $this->feather->user->disp_posts);
     $p = !isset($page) || $page <= 1 || $page > $num_pages ? 1 : intval($page);
     $start_from = $this->feather->user->disp_posts * ($p - 1);
     $url_topic = Url::url_friendly($cur_topic['subject']);
     $url_forum = Url::url_friendly($cur_topic['forum_name']);
     // Generate paging links
     $paging_links = '<span class="pages-label">' . __('Pages') . ' </span>' . Url::paginate($num_pages, $p, 'topic/' . $id . '/' . $url_topic . '/#');
     if ($this->feather->forum_settings['o_censoring'] == '1') {
         $cur_topic['subject'] = Utils::censor($cur_topic['subject']);
     }
     $quickpost = $this->model->is_quickpost($cur_topic['post_replies'], $cur_topic['closed'], $is_admmod);
     $subscraction = $this->model->get_subscraction($cur_topic['is_subscribed'], $id);
     $lang_bbeditor = array('btnBold' => __('btnBold'), 'btnItalic' => __('btnItalic'), 'btnUnderline' => __('btnUnderline'), 'btnColor' => __('btnColor'), 'btnLeft' => __('btnLeft'), 'btnRight' => __('btnRight'), 'btnJustify' => __('btnJustify'), 'btnCenter' => __('btnCenter'), 'btnLink' => __('btnLink'), 'btnPicture' => __('btnPicture'), 'btnList' => __('btnList'), 'btnQuote' => __('btnQuote'), 'btnCode' => __('btnCode'), 'promptImage' => __('promptImage'), 'promptUrl' => __('promptUrl'), 'promptQuote' => __('promptQuote'));
     $this->feather->template->addAsset('canonical', $this->feather->urlFor('Forum', ['id' => $id, 'name' => $url_forum]));
     if ($num_pages > 1) {
         if ($p > 1) {
             $this->feather->template->addAsset('prev', $this->feather->urlFor('ForumPaginate', ['id' => $id, 'name' => $url_forum, 'page' => intval($p - 1)]));
         }
         if ($p < $num_pages) {
             $this->feather->template->addAsset('next', $this->feather->urlFor('ForumPaginate', ['id' => $id, 'name' => $url_forum, 'page' => intval($p + 1)]));
         }
     }
     if ($this->feather->forum_settings['o_feed_type'] == '1') {
         $this->feather->template->addAsset('feed', 'extern.php?action=feed&amp;fid=' . $id . '&amp;type=rss', array('title' => __('RSS forum feed')));
     } elseif ($this->feather->forum_settings['o_feed_type'] == '2') {
         $this->feather->template->addAsset('feed', 'extern.php?action=feed&amp;fid=' . $id . '&amp;type=atom', array('title' => __('Atom forum feed')));
     }
     $this->feather->template->setPageInfo(array('title' => array(Utils::escape($this->feather->forum_settings['o_board_title']), Utils::escape($cur_topic['forum_name']), Utils::escape($cur_topic['subject'])), 'active_page' => 'Topic', 'page_number' => $p, 'paging_links' => $paging_links, 'is_indexed' => true, 'id' => $id, 'pid' => $pid, 'tid' => $id, 'fid' => $cur_topic['forum_id'], 'post_data' => $this->model->print_posts($id, $start_from, $cur_topic, $is_admmod), 'cur_topic' => $cur_topic, 'subscraction' => $subscraction, 'post_link' => $post_link, 'start_from' => $start_from, 'lang_antispam' => $lang_antispam, 'quickpost' => $quickpost, 'index_questions' => $index_questions, 'lang_antispam_questions' => $lang_antispam_questions, 'lang_bbeditor' => $lang_bbeditor, 'url_forum' => $url_forum, 'url_topic' => $url_topic))->addTemplate('Topic.php')->display();
     // Increment "num_views" for topic
     $this->model->increment_views($id);
 }
Example #8
0
 public function login()
 {
     $this->hook->fire('login_start');
     $form_username = Utils::trim($this->request->post('req_username'));
     $form_password = Utils::trim($this->request->post('req_password'));
     $save_pass = $this->request->post('save_pass');
     $user = DB::for_table('users')->where('username', $form_username);
     $user = $this->hook->fireDB('find_user_login', $user);
     $user = $user->find_one();
     $authorized = false;
     if (!empty($user->password)) {
         $form_password_hash = Random::hash($form_password);
         // Will result in a SHA-1 hash
         $authorized = $user->password == $form_password_hash;
     }
     $authorized = $this->hook->fire('authorized_login', $authorized);
     if (!$authorized) {
         throw new Error(__('Wrong user/pass') . ' <a href="' . $this->feather->urlFor('resetPassword') . '">' . __('Forgotten pass') . '</a>', 403);
     }
     // Update the status if this is the first time the user logged in
     if ($user->group_id == $this->feather->forum_env['FEATHER_UNVERIFIED']) {
         $update_usergroup = DB::for_table('users')->where('id', $user->id)->find_one()->set('group_id', $this->config['o_default_user_group']);
         $update_usergroup = $this->hook->fireDB('update_usergroup_login', $update_usergroup);
         $update_usergroup = $update_usergroup->save();
         // Regenerate the users info cache
         if (!$this->feather->cache->isCached('users_info')) {
             $this->feather->cache->store('users_info', Cache::get_users_info());
         }
         $stats = $this->feather->cache->retrieve('users_info');
     }
     // Remove this user's guest entry from the online list
     $delete_online = DB::for_table('online')->where('ident', $this->request->getIp());
     $delete_online = $this->hook->fireDB('delete_online_login', $delete_online);
     $delete_online = $delete_online->delete_many();
     $expire = $save_pass == '1' ? time() + 1209600 : time() + $this->config['o_timeout_visit'];
     $expire = $this->hook->fire('expire_login', $expire);
     $this->auth->feather_setcookie($user->id, $form_password_hash, $expire);
     // Reset tracked topics
     Track::set_tracked_topics(null);
     // Try to determine if the data in redirect_url is valid (if not, we redirect to index.php after login)
     $redirect_url = $this->request->post('redirect_url');
     $redirect_url = $this->hook->fire('redirect_url_login', $redirect_url);
     Url::redirect(Utils::escape($redirect_url), __('Login redirect'));
 }
Example #9
0
 public function update_online()
 {
     // Define this if you want this visit to affect the online list and the users last visit data
     if (!defined('FEATHER_QUIET_VISIT')) {
         // Update the online list
         if (!$this->app->user->logged) {
             $this->app->user->logged = $this->app->now;
             // With MySQL/MySQLi/SQLite, REPLACE INTO avoids a user having two rows in the online table
             switch ($this->app->forum_settings['db_type']) {
                 case 'mysql':
                 case 'mysqli':
                 case 'mysql_innodb':
                 case 'mysqli_innodb':
                 case 'sqlite':
                 case 'sqlite3':
                     DB::for_table('online')->raw_execute('REPLACE INTO ' . $this->app->forum_settings['db_prefix'] . 'online (user_id, ident, logged) VALUES(:user_id, :ident, :logged)', array(':user_id' => $this->app->user->id, ':ident' => $this->app->user->username, ':logged' => $this->app->user->logged));
                     break;
                 default:
                     DB::for_table('online')->raw_execute('INSERT INTO ' . $this->app->forum_settings['db_prefix'] . 'online (user_id, ident, logged) SELECT :user_id, :ident, :logged WHERE NOT EXISTS (SELECT 1 FROM ' . $this->app->db->prefix . 'online WHERE user_id=:user_id)', array(':user_id' => $this->app->user->id, ':ident' => $this->app->user->username, ':logged' => $this->app->user->logged));
                     break;
             }
             // Reset tracked topics
             Track::set_tracked_topics(null);
         } else {
             // Special case: We've timed out, but no other user has browsed the forums since we timed out
             if ($this->app->user->logged < $this->app->now - $this->app->forum_settings['o_timeout_visit']) {
                 DB::for_table('users')->where('id', $this->app->user->id)->find_one()->set('last_visit', $this->app->user->logged)->save();
                 $this->app->user->last_visit = $this->app->user->logged;
             }
             $idle_sql = $this->app->user->idle == '1' ? ', idle=0' : '';
             DB::for_table('online')->raw_execute('UPDATE ' . $this->app->forum_settings['db_prefix'] . 'online SET logged=' . $this->app->now . $idle_sql . ' WHERE user_id=:user_id', array(':user_id' => $this->app->user->id));
             // Update tracked topics with the current expire time
             $cookie_tracked_topics = $this->app->getCookie($this->app->forum_settings['cookie_name'] . '_track');
             if (isset($cookie_tracked_topics)) {
                 Track::set_tracked_topics(json_decode($cookie_tracked_topics, true));
             }
         }
     } else {
         if (!$this->app->user->logged) {
             $this->app->user->logged = $this->app->user->last_visit;
         }
     }
 }
Example #10
0
 public function login($req, $res, $args)
 {
     if (!User::get()->is_guest) {
         return Router::redirect(Router::pathFor('home'), 'Already logged in');
     }
     if (Request::isPost()) {
         Container::get('hooks')->fire('controller.login');
         $form_username = Input::post('req_username');
         $form_password = Input::post('req_password');
         $save_pass = (bool) Input::post('save_pass');
         $user = ModelAuth::get_user_from_name($form_username);
         if (!empty($user->password)) {
             $form_password_hash = Random::hash($form_password);
             // Will result in a SHA-1 hash
             if ($user->password == $form_password_hash) {
                 if ($user->group_id == ForumEnv::get('FEATHER_UNVERIFIED')) {
                     ModelAuth::update_group($user->id, ForumSettings::get('o_default_user_group'));
                     if (!Container::get('cache')->isCached('users_info')) {
                         Container::get('cache')->store('users_info', Cache::get_users_info());
                     }
                 }
                 ModelAuth::delete_online_by_ip(Utils::getIp());
                 // Reset tracked topics
                 Track::set_tracked_topics(null);
                 $expire = $save_pass ? Container::get('now') + 1209600 : Container::get('now') + ForumSettings::get('o_timeout_visit');
                 $expire = Container::get('hooks')->fire('controller.expire_login', $expire);
                 $jwt = ModelAuth::generate_jwt($user, $expire);
                 ModelAuth::feather_setcookie('Bearer ' . $jwt, $expire);
                 return Router::redirect(Router::pathFor('home'), __('Login redirect'));
             } else {
                 throw new Error(__('Wrong user/pass') . ' <a href="' . Router::pathFor('resetPassword') . '">' . __('Forgotten pass') . '</a>', 403);
             }
         }
     } else {
         View::setPageInfo(array('active_page' => 'login', 'title' => array(Utils::escape(ForumSettings::get('o_board_title')), __('Login')), 'required_fields' => array('req_username' => __('Username'), 'req_password' => __('Password')), 'focus_element' => array('login', 'req_username')))->addTemplate('login/form.php')->display();
     }
 }
Example #11
0
 public function display_search_results($search)
 {
     $search = $this->hook->fire('display_search_results_start', $search);
     // Get topic/forum tracking data
     if (!$this->user->is_guest) {
         $tracked_topics = Track::get_tracked_topics();
     }
     $post_count = $topic_count = 0;
     foreach ($search['search_set'] as $cur_search) {
         $forum_name = Url::url_friendly($cur_search['forum_name']);
         $forum = '<a href="' . $this->feather->urlFor('Forum', ['id' => $cur_search['forum_id'], 'name' => $forum_name]) . '">' . Utils::escape($cur_search['forum_name']) . '</a>';
         $url_topic = Url::url_friendly($cur_search['subject']);
         if ($this->config['o_censoring'] == '1') {
             $cur_search['subject'] = Utils::censor($cur_search['subject']);
         }
         if ($search['show_as'] == 'posts') {
             ++$post_count;
             $cur_search['icon_type'] = 'icon';
             if (!$this->user->is_guest && $cur_search['last_post'] > $this->user->last_visit && (!isset($tracked_topics['topics'][$cur_search['tid']]) || $tracked_topics['topics'][$cur_search['tid']] < $cur_search['last_post']) && (!isset($tracked_topics['forums'][$cur_search['forum_id']]) || $tracked_topics['forums'][$cur_search['forum_id']] < $cur_search['last_post'])) {
                 $cur_search['item_status'] = 'inew';
                 $cur_search['icon_type'] = 'icon icon-new';
                 $cur_search['icon_text'] = __('New icon');
             } else {
                 $cur_search['item_status'] = '';
                 $cur_search['icon_text'] = '<!-- -->';
             }
             if ($this->config['o_censoring'] == '1') {
                 $cur_search['message'] = Utils::censor($cur_search['message']);
             }
             $cur_search['message'] = $this->feather->parser->parse_message($cur_search['message'], $cur_search['hide_smilies']);
             $pposter = Utils::escape($cur_search['pposter']);
             if ($cur_search['poster_id'] > 1 && $this->user->g_view_users == '1') {
                 $cur_search['pposter_disp'] = '<strong><a href="' . $this->feather->urlFor('userProfile', ['id' => $cur_search['poster_id']]) . '">' . $pposter . '</a></strong>';
             } else {
                 $cur_search['pposter_disp'] = '<strong>' . $pposter . '</strong>';
             }
             $this->feather->template->setPageInfo(array('post_count' => $post_count, 'url_topic' => $url_topic, 'cur_search' => $cur_search, 'forum' => $forum));
         } else {
             ++$topic_count;
             $status_text = array();
             $cur_search['item_status'] = $topic_count % 2 == 0 ? 'roweven' : 'rowodd';
             $cur_search['icon_type'] = 'icon';
             $subject = '<a href="' . $this->feather->urlFor('Topic', ['id' => $cur_search['tid'], 'name' => $url_topic]) . '">' . Utils::escape($cur_search['subject']) . '</a> <span class="byuser">' . __('by') . ' ' . Utils::escape($cur_search['poster']) . '</span>';
             if ($cur_search['sticky'] == '1') {
                 $cur_search['item_status'] .= ' isticky';
                 $status_text[] = '<span class="stickytext">' . __('Sticky') . '</span>';
             }
             if ($cur_search['closed'] != '0') {
                 $status_text[] = '<span class="closedtext">' . __('Closed') . '</span>';
                 $cur_search['item_status'] .= ' iclosed';
             }
             if (!$this->user->is_guest && $cur_search['last_post'] > $this->user->last_visit && (!isset($tracked_topics['topics'][$cur_search['tid']]) || $tracked_topics['topics'][$cur_search['tid']] < $cur_search['last_post']) && (!isset($tracked_topics['forums'][$cur_search['forum_id']]) || $tracked_topics['forums'][$cur_search['forum_id']] < $cur_search['last_post'])) {
                 $cur_search['item_status'] .= ' inew';
                 $cur_search['icon_type'] = 'icon icon-new';
                 $subject = '<strong>' . $subject . '</strong>';
                 $subject_new_posts = '<span class="newtext">[ <a href="' . $this->feather->urlFor('topicAction', ['id' => $cur_search['tid'], 'action' => 'new']) . '" title="' . __('New posts info') . '">' . __('New posts') . '</a> ]</span>';
             } else {
                 $subject_new_posts = null;
             }
             // Insert the status text before the subject
             $subject = implode(' ', $status_text) . ' ' . $subject;
             $num_pages_topic = ceil(($cur_search['num_replies'] + 1) / $this->user->disp_posts);
             if ($num_pages_topic > 1) {
                 $subject_multipage = '<span class="pagestext">[ ' . Url::paginate($num_pages_topic, -1, 'topic/' . $cur_search['tid'] . '/' . $url_topic . '/#') . ' ]</span>';
             } else {
                 $subject_multipage = null;
             }
             // Should we show the "New posts" and/or the multipage links?
             if (!empty($subject_new_posts) || !empty($subject_multipage)) {
                 $subject .= !empty($subject_new_posts) ? ' ' . $subject_new_posts : '';
                 $subject .= !empty($subject_multipage) ? ' ' . $subject_multipage : '';
             }
             if (!isset($cur_search['start_from'])) {
                 $start_from = 0;
             } else {
                 $start_from = $cur_search['start_from'];
             }
             $this->feather->template->setPageInfo(array('cur_search' => $cur_search, 'start_from' => $start_from, 'topic_count' => $topic_count, 'subject' => $subject, 'forum' => $forum, 'post_count' => $post_count, 'url_topic' => $url_topic));
         }
     }
     $search = $this->hook->fire('display_search_results', $search);
 }
Example #12
0
 public function display_topics($fid, $sort_by, $start_from)
 {
     $this->hook->fire('display_topics_start', $fid, $sort_by, $start_from);
     $topic_data = array();
     // Get topic/forum tracking data
     if (!$this->user->is_guest) {
         $tracked_topics = Track::get_tracked_topics();
     }
     // Retrieve a list of topic IDs, LIMIT is (really) expensive so we only fetch the IDs here then later fetch the remaining data
     $result = DB::for_table('topics')->select('id')->where('forum_id', $fid)->order_by_expr('sticky DESC, ' . $sort_by)->limit($this->user->disp_topics)->offset($start_from);
     $result = $this->hook->fireDB('display_topics_list_ids', $result);
     $result = $result->find_many();
     // If there are topics in this forum
     if ($result) {
         foreach ($result as $id) {
             $topic_ids[] = $id['id'];
         }
         unset($result);
         // Select topics
         $result['select'] = array('id', 'poster', 'subject', 'posted', 'last_post', 'last_post_id', 'last_poster', 'num_views', 'num_replies', 'closed', 'sticky', 'moved_to');
         $result = DB::for_table('topics')->select_many($result['select'])->where_in('id', $topic_ids)->order_by_desc('sticky')->order_by_expr($sort_by)->order_by_desc('id');
         $result = $this->hook->fireDB('display_topics_query', $result);
         $result = $result->find_many();
         $topic_count = 0;
         foreach ($result as $cur_topic) {
             ++$topic_count;
             $status_text = array();
             $cur_topic['item_status'] = $topic_count % 2 == 0 ? 'roweven' : 'rowodd';
             $cur_topic['icon_type'] = 'icon';
             $url_topic = Url::url_friendly($cur_topic['subject']);
             if (is_null($cur_topic['moved_to'])) {
                 $cur_topic['last_post_disp'] = '<a href="' . $this->feather->urlFor('viewPost', ['pid' => $cur_topic['last_post_id']]) . '#p' . $cur_topic['last_post_id'] . '">' . $this->feather->utils->format_time($cur_topic['last_post']) . '</a> <span class="byuser">' . __('by') . ' ' . Utils::escape($cur_topic['last_poster']) . '</span>';
                 $cur_topic['ghost_topic'] = false;
             } else {
                 $cur_topic['last_post_disp'] = '- - -';
                 $cur_topic['ghost_topic'] = true;
             }
             if ($this->config['o_censoring'] == '1') {
                 $cur_topic['subject'] = Utils::censor($cur_topic['subject']);
             }
             if ($cur_topic['sticky'] == '1') {
                 $cur_topic['item_status'] .= ' isticky';
                 $status_text[] = '<span class="stickytext">' . __('Sticky') . '</span>';
             }
             if ($cur_topic['moved_to'] != 0) {
                 $cur_topic['subject_disp'] = '<a href="' . $this->feather->urlFor('Topic', ['id' => $cur_topic['moved_to'], 'name' => $url_topic]) . '">' . Utils::escape($cur_topic['subject']) . '</a> <span class="byuser">' . __('by') . ' ' . Utils::escape($cur_topic['poster']) . '</span>';
                 $status_text[] = '<span class="movedtext">' . __('Moved') . '</span>';
                 $cur_topic['item_status'] .= ' imoved';
             } elseif ($cur_topic['closed'] == '0') {
                 $cur_topic['subject_disp'] = '<a href="' . $this->feather->urlFor('Topic', ['id' => $cur_topic['id'], 'name' => $url_topic]) . '">' . Utils::escape($cur_topic['subject']) . '</a> <span class="byuser">' . __('by') . ' ' . Utils::escape($cur_topic['poster']) . '</span>';
             } else {
                 $cur_topic['subject_disp'] = '<a href="' . $this->feather->urlFor('Topic', ['id' => $cur_topic['id'], 'name' => $url_topic]) . '">' . Utils::escape($cur_topic['subject']) . '</a> <span class="byuser">' . __('by') . ' ' . Utils::escape($cur_topic['poster']) . '</span>';
                 $status_text[] = '<span class="closedtext">' . __('Closed') . '</span>';
                 $cur_topic['item_status'] .= ' iclosed';
             }
             if (!$cur_topic['ghost_topic'] && $cur_topic['last_post'] > $this->user->last_visit && (!isset($tracked_topics['topics'][$cur_topic['id']]) || $tracked_topics['topics'][$cur_topic['id']] < $cur_topic['last_post']) && (!isset($tracked_topics['forums'][$fid]) || $tracked_topics['forums'][$fid] < $cur_topic['last_post'])) {
                 $cur_topic['item_status'] .= ' inew';
                 $cur_topic['icon_type'] = 'icon icon-new';
                 $cur_topic['subject_disp'] = '<strong>' . $cur_topic['subject_disp'] . '</strong>';
                 $subject_new_posts = '<span class="newtext">[ <a href="' . $this->feather->urlFor('Topic', ['id' => $cur_topic['id'], 'action' => 'new']) . '" title="' . __('New posts info') . '">' . __('New posts') . '</a> ]</span>';
             } else {
                 $subject_new_posts = null;
             }
             // Insert the status text before the subject
             $cur_topic['subject_disp'] = implode(' ', $status_text) . ' ' . $cur_topic['subject_disp'];
             $num_pages_topic = ceil(($cur_topic['num_replies'] + 1) / $this->user->disp_posts);
             if ($num_pages_topic > 1) {
                 $subject_multipage = '<span class="pagestext">[ ' . Url::paginate($num_pages_topic, -1, 'topic/' . $cur_topic['id'] . '/' . $url_topic . '/#') . ' ]</span>';
             } else {
                 $subject_multipage = null;
             }
             // Should we show the "New posts" and/or the multipage links?
             if (!empty($subject_new_posts) || !empty($subject_multipage)) {
                 $cur_topic['subject_disp'] .= !empty($subject_new_posts) ? ' ' . $subject_new_posts : '';
                 $cur_topic['subject_disp'] .= !empty($subject_multipage) ? ' ' . $subject_multipage : '';
             }
             $topic_data[] = $cur_topic;
         }
     }
     $topic_data = $this->hook->fire('display_topics', $topic_data);
     return $topic_data;
 }
Example #13
0
 public function increment_post_count($post, $new_tid)
 {
     Container::get('hooks')->fire('model.post.increment_post_count_start', $post, $new_tid);
     if (!User::get()->is_guest) {
         $increment = DB::for_table('users')->where('id', User::get()->id)->find_one()->set('last_post', $post['time'])->set_expr('num_posts', 'num_posts+1');
         $increment = Container::get('hooks')->fireDB('model.post.increment_post_count_query', $increment);
         $increment = $increment->save();
         // Promote this user to a new group if enabled
         if (User::get()->g_promote_next_group != 0 && User::get()->num_posts + 1 >= User::get()->g_promote_min_posts) {
             $new_group_id = User::get()->g_promote_next_group;
             $promote = DB::for_table('users')->where('id', User::get()->id)->find_one()->set('group_id', $new_group_id);
             $promote = Container::get('hooks')->fireDB('model.post.increment_post_count_query', $promote);
             $promote = $promote->save();
         }
         // Topic tracking stuff...
         $tracked_topics = Track::get_tracked_topics();
         $tracked_topics['topics'][$new_tid] = time();
         Track::set_tracked_topics($tracked_topics);
     } else {
         // Update the last_post field for guests
         $last_post = DB::for_table('online')->where('ident', Utils::getIp())->find_one()->set('last_post', $post['time']);
         $last_post = Container::get('hooks')->fireDB('model.post.increment_post_count_last_post', $last_post);
         $last_post = $last_post->save();
     }
     Container::get('hooks')->fire('model.post.increment_post_count');
 }
Example #14
0
 public function markread($req, $res, $args)
 {
     Container::get('hooks')->fire('controller.forum.markread');
     $tracked_topics = Track::get_tracked_topics();
     $tracked_topics['forums'][$args['id']] = time();
     Track::set_tracked_topics($tracked_topics);
     return Router::redirect(Router::pathFor('Forum', ['id' => $args['id']]), __('Mark forum read redirect'));
 }