public function get_bookmarks($ext_mode = '', $forums = array())
    {
        define('POSTS_BOOKMARKS_TABLE', $this->table_prefix . 'posts_bookmarks');
        $start = $this->request->variable('start', 0);
        $sql = 'SELECT COUNT(post_id) as posts_count
			FROM ' . POSTS_BOOKMARKS_TABLE . '
			WHERE user_id = ' . $this->user->data['user_id'];
        $result = $this->db->sql_query($sql);
        $posts_count = (int) $this->db->sql_fetchfield('posts_count');
        $this->db->sql_freeresult($result);
        $sql_where = $sql_fields = '';
        if ($ext_mode != 'find') {
            $sql_where = 'LEFT JOIN ' . USERS_TABLE . ' u ON (p.poster_id = u.user_id)';
            $sql_fields = ', p.post_time, u.user_id, u.username, u.user_colour';
        }
        $pagination_url = append_sid("{$this->phpbb_root_path}postbookmark", "mode=find");
        $this->pagination->generate_template_pagination($pagination_url, 'pagination', 'start', $posts_count, $this->config['topics_per_page'], $start);
        $sql = 'SELECT b.post_id AS b_post_id, b.user_id, b.bookmark_time, b.bookmark_desc, p.post_id, p.forum_id, p.topic_id, p.poster_id, p.post_subject, t.topic_title ' . $sql_fields . '
			FROM ' . POSTS_BOOKMARKS_TABLE . ' b
			LEFT JOIN ' . POSTS_TABLE . ' p ON( b.post_id = p.post_id)
			LEFT JOIN ' . TOPICS_TABLE . ' t ON( t.topic_id = p.topic_id)
			' . $sql_where . '
			WHERE b.user_id = ' . $this->user->data['user_id'] . '
			ORDER BY b.bookmark_time ASC';
        $result = $this->db->sql_query_limit($sql, $this->config['topics_per_page'], $start);
        while ($row = $this->db->sql_fetchrow($result)) {
            $topic_author = $sql_where ? get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']) : '';
            $post_time = $sql_where ? $this->user->format_date($row['post_time']) : '';
            // Send vars to template
            $this->template->assign_block_vars('postrow', array('POST_ID' => $row['b_post_id'], 'POST_TIME' => $post_time, 'BOOKMARK_TIME' => $this->user->format_date($row['bookmark_time']), 'BOOKMARK_DESC' => $row['bookmark_desc'], 'TOPIC_AUTHOR' => $topic_author, 'POST_TITLE' => $row['post_subject'] ? $row['post_subject'] : $row['topic_title'], 'U_VIEW_POST' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", "p=" . $row['post_id'] . "#p" . $row['post_id'] . ""), 'S_DELETED_TOPIC' => !$row['topic_id'] ? true : false, 'S_DELETED_POST' => !$row['post_id'] ? true : false, 'U_POST_BOOKMARK' => '[url=' . generate_board_url() . '/viewtopic.' . $this->php_ext . '?p=' . $row['post_id'] . '#p' . $row['post_id'] . ']' . ($row['post_subject'] ? $row['post_subject'] : $row['topic_title']) . '[/url]'));
        }
        $this->db->sql_freeresult($result);
        $this->template->assign_vars(array('TOTAL_BOOKMARKS' => $this->user->lang('TOTAL_BOOKMARKS', (int) $posts_count), 'PAGE_NUMBER' => $this->pagination->on_page($posts_count, $this->config['topics_per_page'], $start)));
    }
Beispiel #2
0
    /**
     * {@inheritdoc}
     */
    public function get_template_center($module_id)
    {
        $news = $this->request->variable('news_' . $module_id, -1);
        $news = $news > $this->config['board3_number_of_news_' . $module_id] - 1 ? -1 : $news;
        $this->user->add_lang('viewforum');
        $start = $this->request->variable('np_' . $module_id, 0);
        $start = $start < 0 ? 0 : $start;
        $total_news = 1;
        // Fetch news from portal functions.php with check if "read full" is requested.
        $portal_news_length = $news < 0 && !$this->config['board3_news_style_' . $module_id] ? $this->config['board3_news_length_' . $module_id] : 0;
        $this->fetch_posts->set_module_id($module_id);
        $fetch_news = $this->fetch_posts->get_posts($this->config['board3_news_forum_' . $module_id], $this->config['board3_news_permissions_' . $module_id], $this->config['board3_number_of_news_' . $module_id], $portal_news_length, 0, $this->config['board3_show_all_news_' . $module_id] ? 'news_all' : 'news', $start, (bool) $this->config['board3_news_exclude_' . $module_id]);
        $topic_icons = false;
        if (!empty($fetch_news['topic_icons'])) {
            $topic_icons = true;
        }
        // Standard news row
        $news_row = array('S_NEWEST_OR_FIRST' => $this->config['board3_news_show_last_' . $module_id] ? $this->user->lang['JUMP_NEWEST'] : $this->user->lang['JUMP_FIRST'], 'POSTED_BY_TEXT' => $this->config['board3_news_show_last_' . $module_id] ? $this->user->lang['LAST_POST'] : $this->user->lang['POSTED'], 'S_DISPLAY_NEWS_RVS' => $this->config['board3_show_news_replies_views_' . $module_id] ? true : false, 'S_TOPIC_ICONS' => $topic_icons, 'MODULE_ID' => $module_id);
        // Any news present? If not terminate it here.
        if (sizeof($fetch_news) == 0) {
            // Create standard news row
            $this->template->assign_block_vars('news', $news_row);
            $this->template->assign_block_vars('news.news_row', array('S_NO_TOPICS' => true, 'S_NOT_LAST' => false));
        } else {
            // Count number of posts for news archive, considering if permission check is dis- or enabled.
            if ($this->config['board3_news_archive_' . $module_id]) {
                $permissions = $this->config['board3_news_permissions_' . $module_id];
                $forum_from = $this->config['board3_news_forum_' . $module_id];
                $forum_from = strpos($forum_from, ',') !== false ? explode(',', $forum_from) : ($forum_from != '' ? array($forum_from) : array());
                $str_where = '';
                // Get disallowed forums
                $disallow_access = $this->modules_helper->get_disallowed_forums($permissions);
                if ($this->config['board3_news_exclude_' . $module_id] == true) {
                    $disallow_access = array_merge($disallow_access, $forum_from);
                    $forum_from = array();
                }
                if (sizeof($forum_from)) {
                    $disallow_access = array_diff($forum_from, $disallow_access);
                    if (!sizeof($disallow_access)) {
                        return array();
                    }
                    foreach ($disallow_access as $acc_id) {
                        $acc_id = (int) $acc_id;
                        $str_where .= "forum_id = {$acc_id} OR ";
                    }
                } else {
                    foreach ($disallow_access as $acc_id) {
                        $acc_id = (int) $acc_id;
                        $str_where .= "forum_id <> {$acc_id} AND ";
                    }
                }
                $str_where = strlen($str_where) > 0 ? 'AND (' . trim(substr($str_where, 0, -4)) . ')' : '';
                $topic_type = $this->config['board3_show_all_news_' . $module_id] ? '(topic_type <> ' . POST_ANNOUNCE . ') AND (topic_type <> ' . POST_GLOBAL . ')' : 'topic_type = ' . POST_NORMAL;
                $sql = 'SELECT COUNT(topic_id) AS num_topics
					FROM ' . TOPICS_TABLE . '
					WHERE ' . $topic_type . '
						AND topic_visibility = ' . ITEM_APPROVED . '
						AND topic_moved_id = 0
						' . $str_where;
                $result = $this->db->sql_query($sql, 300);
                $total_news = (int) $this->db->sql_fetchfield('num_topics');
                $this->db->sql_freeresult($result);
            }
            $topic_tracking_info = get_portal_tracking_info($fetch_news);
            // Create pagination if necessary
            if ($this->config['board3_news_archive_' . $module_id]) {
                $pagination = generate_portal_pagination($this->modules_helper->route('board3_portal_controller'), $total_news, $this->config['board3_number_of_news_' . $module_id], $start, $this->config['board3_show_all_news_' . $module_id] ? 'news_all' : 'news', $module_id);
            }
            if ($this->config['board3_number_of_news_' . $module_id] != 0 && $this->config['board3_news_archive_' . $module_id]) {
                $news_row = array_merge($news_row, array('NP_PAGINATION' => !empty($pagination) ? $pagination : '', 'TOTAL_NEWS' => $total_news == 1 ? sprintf($this->user->lang['VIEW_FORUM_TOPICS'][1], $total_news) : sprintf($this->user->lang['VIEW_FORUM_TOPICS'][2], $total_news), 'NP_PAGE_NUMBER' => $this->pagination->on_page($total_news, $this->config['board3_number_of_news_' . $module_id], $start)));
            }
            // Create standard news row
            $this->template->assign_block_vars('news', $news_row);
            // Show the news overview
            if ($news < 0) {
                $count = $fetch_news['topic_count'];
                for ($i = 0; $i < $count; $i++) {
                    if (isset($fetch_news[$i]['striped']) && $fetch_news[$i]['striped'] == true) {
                        $open_bracket = '[ ';
                        $close_bracket = ' ]';
                        $read_full = $this->user->lang['READ_FULL'];
                    } else {
                        $open_bracket = '';
                        $close_bracket = '';
                        $read_full = '';
                    }
                    // unread?
                    $forum_id = $fetch_news[$i]['forum_id'];
                    $topic_id = $fetch_news[$i]['topic_id'];
                    $unread_topic = isset($topic_tracking_info[$topic_id]) && $fetch_news[$i]['topic_last_post_time'] > $topic_tracking_info[$topic_id] ? true : false;
                    $read_full_url = $this->request->is_set('np_' . $module_id) ? "np_{$module_id}={$start}&amp;news_{$module_id}={$i}#n_{$module_id}_{$i}" : "news_{$module_id}={$i}#n_{$module_id}_{$i}";
                    $view_topic_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . ($fetch_news[$i]['forum_id'] ? $fetch_news[$i]['forum_id'] : $forum_id) . '&amp;t=' . $topic_id);
                    $replies = $this->auth->acl_get('m_approve', $forum_id) ? $fetch_news[$i]['topic_replies_real'] : $fetch_news[$i]['topic_replies'];
                    switch ($fetch_news[$i]['topic_type']) {
                        case POST_STICKY:
                            $folder = 'sticky_read';
                            $folder_new = 'sticky_unread';
                            break;
                        case POST_ANNOUNCE:
                            $folder = 'announce_read';
                            $folder_new = 'announce_unread';
                            break;
                        default:
                            $folder = 'topic_read';
                            $folder_new = 'topic_unread';
                            if ($this->config['hot_threshold'] && $replies >= $this->config['hot_threshold'] && $fetch_news[$i]['topic_status'] != ITEM_LOCKED) {
                                $folder .= '_hot';
                                $folder_new .= '_hot';
                            }
                            break;
                    }
                    if ($fetch_news[$i]['topic_status'] == ITEM_LOCKED) {
                        $folder .= '_locked';
                        $folder_new .= '_locked';
                    }
                    if ($fetch_news[$i]['topic_posted']) {
                        $folder .= '_mine';
                        $folder_new .= '_mine';
                    }
                    $folder_img = $unread_topic ? $folder_new : $folder;
                    $folder_alt = $unread_topic ? 'NEW_POSTS' : ($fetch_news[$i]['topic_status'] == ITEM_LOCKED ? 'TOPIC_LOCKED' : 'NO_NEW_POSTS');
                    // Grab icons
                    $icons = $this->cache->obtain_icons();
                    $this->template->assign_block_vars('news.news_row', array('ATTACH_ICON_IMG' => $fetch_news[$i]['attachment'] && $this->config['allow_attachments'] ? $this->user->img('icon_topic_attach', $this->user->lang['TOTAL_ATTACHMENTS']) : '', 'FORUM_NAME' => $forum_id ? $fetch_news[$i]['forum_name'] : '', 'TITLE' => $fetch_news[$i]['topic_title'], 'POSTER' => $fetch_news[$i]['username'], 'POSTER_FULL' => $fetch_news[$i]['username_full'], 'USERNAME_FULL_LAST' => $fetch_news[$i]['username_full_last'], 'U_USER_PROFILE' => ($fetch_news[$i]['user_type'] == USER_NORMAL || $fetch_news[$i]['user_type'] == USER_FOUNDER) && $fetch_news[$i]['user_id'] != ANONYMOUS ? append_sid("{$this->phpbb_root_path}memberlist.{$this->php_ext}", 'mode=viewprofile&amp;u=' . $fetch_news[$i]['user_id']) : '', 'TIME' => $fetch_news[$i]['topic_time'], 'LAST_POST_TIME' => $this->user->format_date($fetch_news[$i]['topic_last_post_time']), 'TEXT' => $fetch_news[$i]['post_text'], 'REPLIES' => $fetch_news[$i]['topic_replies'], 'TOPIC_VIEWS' => $fetch_news[$i]['topic_views'], 'N_ID' => $i, 'TOPIC_FOLDER_IMG' => $this->user->img($folder_img, $folder_alt), 'TOPIC_IMG_STYLE' => $folder_img, 'TOPIC_FOLDER_IMG_SRC' => $this->user->img($folder_img, $folder_alt, false, '', 'src'), 'TOPIC_FOLDER_IMG_ALT' => $this->user->lang[$folder_alt], 'TOPIC_ICON_IMG' => !empty($icons[$fetch_news[$i]['icon_id']]) ? $icons[$fetch_news[$i]['icon_id']]['img'] : '', 'TOPIC_ICON_IMG_WIDTH' => !empty($icons[$fetch_news[$i]['icon_id']]) ? $icons[$fetch_news[$i]['icon_id']]['width'] : '', 'TOPIC_ICON_IMG_HEIGHT' => !empty($icons[$fetch_news[$i]['icon_id']]) ? $icons[$fetch_news[$i]['icon_id']]['height'] : '', 'FOLDER_IMG' => $this->user->img('topic_read', 'NO_NEW_POSTS'), 'U_VIEWFORUM' => append_sid("{$this->phpbb_root_path}viewforum.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id']), 'U_LAST_COMMENTS' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id'] . '&amp;t=' . $fetch_news[$i]['topic_id'] . '&amp;p=' . $fetch_news[$i]['topic_last_post_id'] . '#p' . $fetch_news[$i]['topic_last_post_id']), 'U_VIEW_COMMENTS' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id'] . '&amp;t=' . $fetch_news[$i]['topic_id']), 'U_VIEW_UNREAD' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id'] . '&amp;t=' . $fetch_news[$i]['topic_id'] . '&amp;view=unread#unread'), 'U_POST_COMMENT' => append_sid("{$this->phpbb_root_path}posting.{$this->php_ext}", 'mode=reply&amp;f=' . $fetch_news[$i]['forum_id'] . '&amp;t=' . $fetch_news[$i]['topic_id']), 'U_READ_FULL' => $this->modules_helper->route('board3_portal_controller') . '?' . $read_full_url, 'L_READ_FULL' => $read_full, 'OPEN' => $open_bracket, 'CLOSE' => $close_bracket, 'S_NOT_LAST' => $i < sizeof($fetch_news) - 1 ? true : false, 'S_POLL' => $fetch_news[$i]['poll'], 'S_UNREAD_INFO' => $unread_topic, 'S_HAS_ATTACHMENTS' => !empty($fetch_news[$i]['attachments']) ? true : false));
                    // Assign pagination
                    $this->pagination->generate_template_pagination($view_topic_url, 'news.news_row.pagination', 'start', $fetch_news[$i]['topic_replies'] + 1, $this->config['posts_per_page'], 1);
                    if (!empty($fetch_news[$i]['attachments'])) {
                        foreach ($fetch_news[$i]['attachments'] as $attachment) {
                            $this->template->assign_block_vars('news.news_row.attachment', array('DISPLAY_ATTACHMENT' => $attachment));
                        }
                    }
                }
            } else {
                $i = $news;
                $forum_id = $fetch_news[$i]['forum_id'];
                $topic_id = $fetch_news[$i]['topic_id'];
                $unread_topic = isset($topic_tracking_info[$topic_id]) && $fetch_news[$i]['topic_last_post_time'] > $topic_tracking_info[$topic_id] ? true : false;
                $open_bracket = '[ ';
                $close_bracket = ' ]';
                $read_full = $this->user->lang['BACK'];
                $read_full_url = $this->request->is_set('np_' . $module_id) ? $this->modules_helper->route('board3_portal_controller') . "?np_{$module_id}={$start}#n_{$module_id}_{$i}" : $this->modules_helper->route('board3_portal_controller') . "#n_{$module_id}_{$i}";
                $view_topic_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . ($fetch_news[$i]['forum_id'] ? $fetch_news[$i]['forum_id'] : $forum_id) . '&amp;t=' . $topic_id);
                $this->template->assign_block_vars('news.news_row', array('ATTACH_ICON_IMG' => $fetch_news[$i]['attachment'] && $this->config['allow_attachments'] ? $this->user->img('icon_topic_attach', $this->user->lang['TOTAL_ATTACHMENTS']) : '', 'FORUM_NAME' => $forum_id ? $fetch_news[$i]['forum_name'] : '', 'TITLE' => $fetch_news[$i]['topic_title'], 'POSTER' => $fetch_news[$i]['username'], 'POSTER_FULL' => $fetch_news[$i]['username_full'], 'TIME' => $fetch_news[$i]['topic_time'], 'TEXT' => $fetch_news[$i]['post_text'], 'REPLIES' => $fetch_news[$i]['topic_replies'], 'TOPIC_VIEWS' => $fetch_news[$i]['topic_views'], 'N_ID' => $i, 'U_VIEWFORUM' => append_sid("{$this->phpbb_root_path}viewforum.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id']), 'U_LAST_COMMENTS' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'p=' . $fetch_news[$i]['topic_last_post_id'] . '#p' . $fetch_news[$i]['topic_last_post_id']), 'U_VIEW_COMMENTS' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id'] . '&amp;t=' . $fetch_news[$i]['topic_id']), 'U_POST_COMMENT' => append_sid("{$this->phpbb_root_path}posting.{$this->php_ext}", 'mode=reply&amp;f=' . $fetch_news[$i]['forum_id'] . '&amp;t=' . $fetch_news[$i]['topic_id']), 'S_POLL' => $fetch_news[$i]['poll'], 'S_UNREAD_INFO' => $unread_topic, 'U_READ_FULL' => $read_full_url, 'L_READ_FULL' => $read_full, 'OPEN' => $open_bracket, 'CLOSE' => $close_bracket, 'S_HAS_ATTACHMENTS' => !empty($fetch_news[$i]['attachments']) ? true : false));
                $this->pagination->generate_template_pagination($view_topic_url, 'news.news_row.pagination', 'start', $fetch_news[$i]['topic_replies'] + 1, $this->config['posts_per_page'], 1);
                if (!empty($fetch_news[$i]['attachments'])) {
                    foreach ($fetch_news[$i]['attachments'] as $attachment) {
                        $this->template->assign_block_vars('news.news_row.attachment', array('DISPLAY_ATTACHMENT' => $attachment));
                    }
                }
            }
        }
        $this->template->assign_vars(array('NEWEST_POST_IMG' => $this->user->img('icon_topic_newest', 'VIEW_NEWEST_POST'), 'READ_POST_IMG' => $this->user->img('icon_topic_latest', 'VIEW_LATEST_POST'), 'GOTO_PAGE_IMG' => $this->user->img('icon_post_target', 'GOTO_PAGE')));
        if ($this->config['board3_news_style_' . $module_id]) {
            return 'news_compact_center.html';
        } else {
            return 'news_center.html';
        }
    }
    public function main($mode, $author_id, $give)
    {
        $this->user->add_lang(array('memberlist', 'groups', 'search'));
        $this->user->add_lang_ext('gfksx/ThanksForPosts', 'thanks_mod');
        // Grab data
        $row_number = $total_users = 0;
        $givens = $reseved = $rowsp = $rowsu = $words = $where = array();
        $sthanks = false;
        $ex_fid_ary = array_keys($this->auth->acl_getf('!f_read', true));
        $ex_fid_ary = sizeof($ex_fid_ary) ? $ex_fid_ary : false;
        if (!$this->auth->acl_gets('u_viewthanks')) {
            if ($this->user->data['user_id'] != ANONYMOUS) {
                trigger_error('NO_VIEW_USERS_THANKS');
            }
            login_box('', isset($this->user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)]) ? $this->user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)] : $this->user->lang['LOGIN_EXPLAIN_MEMBERLIST']);
        }
        $top = $this->request->variable('top', 0);
        $start = $this->request->variable('start', 0);
        $submit = isset($_POST['submit']) ? true : false;
        $default_key = 'a';
        $sort_key = $this->request->variable('sk', $default_key);
        $sort_dir = $this->request->variable('sd', 'd');
        $topic_id = $this->request->variable('t', 0);
        $return_chars = $this->request->variable('ch', $topic_id ? -1 : 300);
        $order_by = '';
        switch ($mode) {
            case 'givens':
                $per_page = $this->config['posts_per_page'];
                $total_match_count = 0;
                $page_title = $this->user->lang['SEARCH'];
                $template_html = 'thanks_results.html';
                switch ($give) {
                    case 'true':
                        $u_search = $this->controller_helper->route('gfksx_ThanksForPosts_thankslist_controller_user', array('mode' => 'givens', 'author_id' => $author_id, 'give' => 'true', 'tslash' => ''));
                        $sql = 'SELECT COUNT(user_id) AS total_match_count
						FROM ' . $this->thanks_table . '
						WHERE (' . $this->db->sql_in_set('forum_id', $ex_fid_ary, true) . ' OR forum_id = 0) AND user_id = ' . $author_id;
                        $where = 'user_id';
                        break;
                    case 'false':
                        $u_search = $this->controller_helper->route('gfksx_ThanksForPosts_thankslist_controller_user', array('mode' => 'givens', 'author_id' => $author_id, 'give' => 'false', 'tslash' => ''));
                        $sql = 'SELECT COUNT(DISTINCT post_id) as total_match_count
						FROM ' . $this->thanks_table . '
						WHERE (' . $this->db->sql_in_set('forum_id', $ex_fid_ary, true) . ' OR forum_id = 0) AND poster_id = ' . $author_id;
                        $where = 'poster_id';
                        break;
                }
                $result = $this->db->sql_query($sql);
                if (!($row = $this->db->sql_fetchrow($result))) {
                    break;
                } else {
                    $total_match_count = (int) $row['total_match_count'];
                    $this->db->sql_freeresult($result);
                    $sql_array = array('SELECT' => 'u.username, u.user_colour, p.poster_id, p.post_id, p.topic_id, p.forum_id, p.post_time, p.post_subject, p.post_text, p.post_username, p.bbcode_bitfield, p.bbcode_uid, p.post_attachment, p.enable_bbcode, p. enable_smilies, p.enable_magic_url', 'FROM' => array($this->thanks_table => 't'), 'WHERE' => '(' . $this->db->sql_in_set('t.forum_id', $ex_fid_ary, true) . ' OR t.forum_id = 0) AND t.' . $where . "= {$author_id}");
                    $sql_array['LEFT_JOIN'][] = array('FROM' => array($this->users_table => 'u'), 'ON' => 't.poster_id = u.user_id');
                    $sql_array['LEFT_JOIN'][] = array('FROM' => array(POSTS_TABLE => 'p'), 'ON' => 't.post_id = p.post_id');
                    $sql = $this->db->sql_build_query('SELECT_DISTINCT', $sql_array);
                    $result = $this->db->sql_query_limit($sql, $per_page, $start);
                    if (!($row = $this->db->sql_fetchrow($result))) {
                        break;
                    } else {
                        $bbcode_bitfield = $text_only_message = '';
                        do {
                            // We pre-process some variables here for later usage
                            $row['post_text'] = censor_text($row['post_text']);
                            $text_only_message = $row['post_text'];
                            // make list items visible as such
                            if ($row['bbcode_uid']) {
                                // no BBCode in text only message
                                strip_bbcode($text_only_message, $row['bbcode_uid']);
                            }
                            if ($return_chars == -1 || utf8_strlen($text_only_message) < $return_chars + 3) {
                                $row['display_text_only'] = false;
                                $bbcode_bitfield = $bbcode_bitfield | base64_decode($row['bbcode_bitfield']);
                                // Does this post have an attachment? If so, add it to the list
                                if ($row['post_attachment'] && $config['allow_attachments']) {
                                    $attach_list[$row['forum_id']][] = $row['post_id'];
                                }
                            } else {
                                $row['post_text'] = $text_only_message;
                                $row['display_text_only'] = true;
                            }
                            unset($text_only_message);
                            if ($row['display_text_only']) {
                                // limit the message length to return_chars value
                                $row['post_text'] = get_context($row['post_text'], array(), $return_chars);
                                $row['post_text'] = bbcode_nl2br($row['post_text']);
                            } else {
                                $flags = ($row['enable_bbcode'] ? OPTION_FLAG_BBCODE : 0) + ($row['enable_smilies'] ? OPTION_FLAG_SMILIES : 0) + ($row['enable_magic_url'] ? OPTION_FLAG_LINKS : 0);
                                $row['post_text'] = generate_text_for_display($row['post_text'], $row['bbcode_uid'], $row['bbcode_bitfield'], $flags);
                            }
                            $this->template->assign_block_vars('searchresults', array('POST_AUTHOR_FULL' => get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']), 'POST_AUTHOR_COLOUR' => get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']), 'POST_AUTHOR' => get_username_string('username', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']), 'U_POST_AUTHOR' => get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']), 'POST_SUBJECT' => $this->auth->acl_get('f_read', $row['forum_id']) ? $row['post_subject'] : (!empty($row['forum_id']) ? '' : $row['post_subject']), 'POST_DATE' => !empty($row['post_time']) ? $this->user->format_date($row['post_time']) : '', 'MESSAGE' => $this->auth->acl_get('f_read', $row['forum_id']) ? $row['post_text'] : (!empty($row['forum_id']) ? $this->user->lang['SORRY_AUTH_READ'] : $row['post_text']), 'FORUM_ID' => $row['forum_id'], 'TOPIC_ID' => $row['topic_id'], 'POST_ID' => $row['post_id'], 'U_VIEW_TOPIC' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 't=' . $row['topic_id']), 'U_VIEW_FORUM' => append_sid("{$this->phpbb_root_path}viewforum.{$this->php_ext}", 'f=' . $row['forum_id']), 'U_VIEW_POST' => !empty($row['post_id']) ? append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", "t=" . $row['topic_id'] . '&amp;p=' . $row['post_id']) . '#p' . $row['post_id'] : ''));
                        } while ($row = $this->db->sql_fetchrow($result));
                        $this->db->sql_freeresult($result);
                    }
                }
                if ($total_match_count > 1000) {
                    $total_match_count--;
                    $l_search_matches = $this->user->lang('FOUND_MORE_SEARCH_MATCHES', $total_match_count);
                } else {
                    $l_search_matches = $this->user->lang('FOUND_SEARCH_MATCHES', $total_match_count);
                }
                $this->pagination->generate_template_pagination($u_search, 'pagination', 'start', $total_match_count, $per_page, $start);
                $this->template->assign_vars(array('PAGE_NUMBER' => $this->pagination->on_page($total_match_count, $per_page, $start), 'TOTAL_MATCHES' => $total_match_count, 'SEARCH_MATCHES' => $l_search_matches, 'U_THANKS' => $this->controller_helper->route('gfksx_ThanksForPosts_thankslist_controller', array('tslash' => ''))));
                break;
            default:
                $page_title = $this->user->lang['THANKS_USER'];
                $template_html = 'thankslist_body.html';
                // Grab relevant data thanks
                $sql = 'SELECT user_id, COUNT(user_id) AS tally
					FROM ' . $this->thanks_table . '
					WHERE ' . $this->db->sql_in_set('forum_id', $ex_fid_ary, true) . ' OR forum_id = 0
					GROUP BY user_id';
                $result = $this->db->sql_query($sql);
                while ($row = $this->db->sql_fetchrow($result)) {
                    $givens[$row['user_id']] = $row['tally'];
                }
                $this->db->sql_freeresult($result);
                $sql = 'SELECT poster_id, COUNT(user_id) AS tally
					FROM ' . $this->thanks_table . '
					WHERE ' . $this->db->sql_in_set('forum_id', $ex_fid_ary, true) . ' OR forum_id = 0
					GROUP BY poster_id';
                $result = $this->db->sql_query($sql);
                while ($row = $this->db->sql_fetchrow($result)) {
                    $reseved[$row['poster_id']] = $row['tally'];
                }
                $this->db->sql_freeresult($result);
                // Sorting
                $sort_key_text = array('a' => $this->user->lang['SORT_USERNAME'], 'b' => $this->user->lang['SORT_LOCATION'], 'c' => $this->user->lang['SORT_JOINED'], 'd' => $this->user->lang['SORT_POST_COUNT'], 'e' => 'R_THANKS', 'f' => 'G_THANKS');
                $sort_key_sql = array('a' => 'u.username_clean', 'b' => 'u.user_from', 'c' => 'u.user_regdate', 'd' => 'u.user_posts', 'e' => 'count_thanks', 'f' => 'count_thanks');
                $sort_dir_text = array('a' => $this->user->lang['ASCENDING'], 'd' => $this->user->lang['DESCENDING']);
                if ($this->auth->acl_get('u_viewonline')) {
                    $sort_key_text['l'] = $this->user->lang['SORT_LAST_ACTIVE'];
                    $sort_key_sql['l'] = 'u.user_lastvisit';
                }
                $s_sort_key = '';
                foreach ($sort_key_text as $key => $value) {
                    $selected = $sort_key == $key ? ' selected="selected"' : '';
                    $s_sort_key .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
                }
                $s_sort_dir = '';
                foreach ($sort_dir_text as $key => $value) {
                    $selected = $sort_dir == $key ? ' selected="selected"' : '';
                    $s_sort_dir .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
                }
                // Sorting and order
                if (!isset($sort_key_sql[$sort_key])) {
                    $sort_key = $default_key;
                }
                $order_by .= $sort_key_sql[$sort_key] . ' ' . ($sort_dir == 'a' ? 'ASC' : 'DESC');
                // Build a relevant pagination_url
                $params = array();
                $check_params = array('sk' => array('sk', $default_key), 'sd' => array('sd', 'a'));
                foreach ($check_params as $key => $call) {
                    if (!isset($_REQUEST[$key])) {
                        continue;
                    }
                    $param = call_user_func_array(array($this->request, 'variable'), $call);
                    $param = is_string($param) ? urlencode($param) : $param;
                    $params[$key] = $param;
                    if ($key != 'sk' && $key != 'sd') {
                        $sort_params[] = $param;
                    }
                }
                $pagination_url = $this->controller_helper->route('gfksx_ThanksForPosts_thankslist_controller', array_merge($params, array('tslash' => '')));
                // Grab relevant data
                $sql = 'SELECT DISTINCT poster_id
					FROM ' . $this->thanks_table;
                $result = $this->db->sql_query($sql);
                while ($row = $this->db->sql_fetchrow($result)) {
                    $rowsp[] = $row['poster_id'];
                }
                $sql = 'SELECT DISTINCT user_id
					FROM ' . $this->thanks_table;
                $result = $this->db->sql_query($sql);
                while ($row = $this->db->sql_fetchrow($result)) {
                    $rowsu[] = $row['user_id'];
                }
                if ($sort_key == 'e') {
                    $sortparam = 'poster';
                    $rows = $rowsp;
                } else {
                    if ($sort_key == 'f') {
                        $sortparam = 'user';
                        $rows = $rowsu;
                    } else {
                        $sortparam = '';
                        $rows = array_merge($rowsp, $rowsu);
                    }
                }
                $total_users = count(array_unique($rows));
                if (empty($rows)) {
                    break;
                }
                $sql_array = array('SELECT' => 'u.*', 'FROM' => array($this->users_table => 'u'), 'ORDER_BY' => $order_by);
                if ($top) {
                    $total_users = $top;
                    $start = 0;
                    $page_title = $this->user->lang['REPUT_TOPLIST'];
                } else {
                    $top = $this->config['topics_per_page'];
                }
                if ($sortparam) {
                    $sql_array['FROM'] = array($this->thanks_table => 't');
                    $sql_array['SELECT'] .= ', count(t.' . $sortparam . '_id) as count_thanks';
                    $sql_array['LEFT_JOIN'][] = array('FROM' => array($this->users_table => 'u'), 'ON' => 't.' . $sortparam . '_id = u.user_id');
                    $sql_array['GROUP_BY'] = 't.' . $sortparam . '_id';
                }
                $where[] = $rows[0];
                for ($i = 1, $end = sizeof($rows); $i < $end; ++$i) {
                    $where[] = $rows[$i];
                }
                $sql_array['WHERE'] = $this->db->sql_in_set('u.user_id', $where);
                $sql = $this->db->sql_build_query('SELECT', $sql_array);
                $result = $this->db->sql_query_limit($sql, $top, $start);
                if (!($row = $this->db->sql_fetchrow($result))) {
                    trigger_error('NO_USER');
                } else {
                    $sql = 'SELECT session_user_id, MAX(session_time) AS session_time
						FROM ' . SESSIONS_TABLE . '
						WHERE session_time >= ' . (time() - $this->config['session_length']) . '
							AND ' . $this->db->sql_in_set('session_user_id', $where) . '
						GROUP BY session_user_id';
                    $result_sessions = $this->db->sql_query($sql);
                    $session_times = array();
                    while ($session = $this->db->sql_fetchrow($result_sessions)) {
                        $session_times[$session['session_user_id']] = $session['session_time'];
                    }
                    $this->db->sql_freeresult($result_sessions);
                    $user_list = array();
                    $id_cache = array();
                    do {
                        $row['session_time'] = !empty($session_times[$session['user_id']]) ? $session_times[$session['user_id']] : 0;
                        $row['last_visit'] = !empty($session['session_time']) ? $session['session_time'] : $session['user_lastvisit'];
                        $user_list[] = (int) $row['user_id'];
                        $id_cache[$row['user_id']] = $row;
                    } while ($row = $this->db->sql_fetchrow($result));
                    $this->db->sql_freeresult($result);
                    // Load custom profile fields
                    if ($this->config['load_cpf_memberlist']) {
                        $cp_row = $this->profilefields_manager->generate_profile_fields_template_headlines('field_show_on_ml');
                        foreach ($cp_row as $profile_field) {
                            $this->template->assign_block_vars('custom_fields', $profile_field);
                        }
                        // Grab all profile fields from users in id cache for later use - similar to the poster cache
                        $profile_fields_cache = $this->profilefields_manager->grab_profile_fields_data($user_list);
                        // Filter the fields we don't want to show
                        foreach ($profile_fields_cache as $user_id => $user_profile_fields) {
                            foreach ($user_profile_fields as $field_ident => $profile_field) {
                                if (!$profile_field['data']['field_show_on_ml']) {
                                    unset($profile_fields_cache[$user_id][$field_ident]);
                                }
                            }
                        }
                    }
                    //do
                    for ($i = 0, $end = sizeof($user_list); $i < $end; ++$i) {
                        $user_id = $user_list[$i];
                        $row = $id_cache[$user_id];
                        $last_visit = $row['user_lastvisit'];
                        $rank_title = $rank_img = $rank_img_src = '';
                        include_once $this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext;
                        get_user_rank($row['user_rank'], $user_id == ANONYMOUS ? false : $row['user_posts'], $rank_title, $rank_img, $rank_img_src);
                        $sthanks = true;
                        // Custom Profile Fields
                        $cp_row = array();
                        if ($this->config['load_cpf_memberlist']) {
                            $cp_row = isset($profile_fields_cache[$user_id]) ? $this->profilefields_manager->generate_profile_fields_template_data($profile_fields_cache[$user_id], false) : array();
                        }
                        $memberrow = array_merge(phpbb_show_profile($row), array('ROW_NUMBER' => $row_number + ($start + 1), 'RANK_TITLE' => $rank_title, 'RANK_IMG' => $rank_img, 'RANK_IMG_SRC' => $rank_img_src, 'GIVENS' => !isset($givens[$user_id]) ? 0 : $givens[$user_id], 'RECEIVED' => !isset($reseved[$user_id]) ? 0 : $reseved[$user_id], 'JOINED' => $this->user->format_date($row['user_regdate']), 'VISITED' => empty($last_visit) ? ' - ' : $this->user->format_date($last_visit), 'POSTS' => $row['user_posts'] ? $row['user_posts'] : 0, 'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']), 'USER_COLOR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']), 'U_VIEW_PROFILE' => get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']), 'U_SEARCH_USER' => $this->auth->acl_get('u_search') ? append_sid("{$this->phpbb_root_path}search.{$this->php_ext}", "author_id={$user_id}&amp;sr=posts") : '', 'U_SEARCH_USER_GIVENS' => $this->auth->acl_get('u_search') ? $this->controller_helper->route('gfksx_ThanksForPosts_thankslist_controller_user', array('mode' => 'givens', 'author_id' => $user_id, 'give' => 'true', 'tslash' => '')) : '', 'U_SEARCH_USER_RECEIVED' => $this->auth->acl_get('u_search') ? $this->controller_helper->route('gfksx_ThanksForPosts_thankslist_controller_user', array('mode' => 'givens', 'author_id' => $user_id, 'give' => 'false', 'tslash' => '')) : '', 'L_VIEWING_PROFILE' => sprintf($this->user->lang['VIEWING_PROFILE'], $row['username']), 'VISITED' => empty($last_visit) ? ' - ' : $this->user->format_date($last_visit), 'S_CUSTOM_FIELDS' => isset($cp_row['row']) && sizeof($cp_row['row']) ? true : false));
                        if (isset($cp_row['row']) && sizeof($cp_row['row'])) {
                            $memberrow = array_merge($memberrow, $cp_row['row']);
                        }
                        $this->template->assign_block_vars('memberrow', $memberrow);
                        if (isset($cp_row['blockrow']) && sizeof($cp_row['blockrow'])) {
                            foreach ($cp_row['blockrow'] as $field_data) {
                                $this->template->assign_block_vars('memberrow.custom_fields', $field_data);
                            }
                        }
                        $row_number++;
                    }
                    $this->pagination->generate_template_pagination($pagination_url, 'pagination', 'start', $total_users, $this->config['topics_per_page'], $start);
                    $this->template->assign_vars(array('PAGE_NUMBER' => $this->pagination->on_page($total_users, $this->config['topics_per_page'], $start), 'U_SORT_POSTS' => $this->controller_helper->route('gfksx_ThanksForPosts_thankslist_controller', array('mode' => $mode, 'sk' => 'd', 'sd' => $sort_key == 'd' && $sort_dir == 'a' ? 'd' : 'a', 'tslash' => '')), 'U_SORT_USERNAME' => $this->controller_helper->route('gfksx_ThanksForPosts_thankslist_controller', array('mode' => $mode, 'sk' => 'a', 'sd' => $sort_key == 'a' && $sort_dir == 'a' ? 'd' : 'a', 'tslash' => '')), 'U_SORT_FROM' => $this->controller_helper->route('gfksx_ThanksForPosts_thankslist_controller', array('mode' => $mode, 'sk' => 'b', 'sd' => $sort_key == 'b' && $sort_dir == 'a' ? 'd' : 'a', 'tslash' => '')), 'U_SORT_JOINED' => $this->controller_helper->route('gfksx_ThanksForPosts_thankslist_controller', array('mode' => $mode, 'sk' => 'c', 'sd' => $sort_key == 'c' && $sort_dir == 'a' ? 'd' : 'a', 'tslash' => '')), 'U_SORT_THANKS_R' => $this->controller_helper->route('gfksx_ThanksForPosts_thankslist_controller', array('mode' => $mode, 'sk' => 'e', 'sd' => $sort_key == 'e' && $sort_dir == 'd' ? 'a' : 'd', 'tslash' => '')), 'U_SORT_THANKS_G' => $this->controller_helper->route('gfksx_ThanksForPosts_thankslist_controller', array('mode' => $mode, 'sk' => 'f', 'sd' => $sort_key == 'f' && $sort_dir == 'd' ? 'a' : 'd', 'tslash' => '')), 'U_SORT_ACTIVE' => $this->auth->acl_get('u_viewonline') ? $this->controller_helper->route('gfksx_ThanksForPosts_thankslist_controller', array('mode' => $mode, 'sk' => 'l', 'sd' => $sort_key == 'l' && $sort_dir == 'a' ? 'd' : 'a', 'tslash' => '')) : ''));
                }
                break;
        }
        // Output the page
        $this->template->assign_vars(array('TOTAL_USERS' => $this->user->lang('LIST_USERS', $total_users), 'U_THANKS' => $this->controller_helper->route('gfksx_ThanksForPosts_thankslist_controller', array('tslash' => '')), 'S_THANKS' => $sthanks));
        page_header($page_title);
        $this->template->set_filenames(array('body' => $template_html));
        make_jumpbox(append_sid("{$this->phpbb_root_path}viewforum.{$this->php_ext}"));
        page_footer();
        return new Response($this->template->return_display('body'), 200);
    }
    /**
     * Main reputation details controller 
     *
     * @param int $uid			User ID taken from the URL
     * @param string $sort_key	Sort key: id|username|time|point|action (default: id)
     * @param string $sort_dir	Sort direction: dsc|asc (descending|ascending) (default: dsc)
     * @param int $page			Page number taken from the URL
     * @return Symfony\Component\HttpFoundation\Response A Symfony Response object
     * @access public
     */
    public function details($uid, $sort_key, $sort_dir, $page)
    {
        $this->user->add_lang_ext('pico/reputation', array('reputation_system', 'reputation_rating'));
        // Check user permissions - if user can not view reputation details, throw the error
        if (!$this->auth->acl_get('u_rs_view')) {
            $meta_info = append_sid("{$this->root_path}index.{$this->php_ext}", "");
            $message = $user->lang['RS_VIEW_DISALLOWED'] . '<br /><br />' . $this->user->lang('RETURN_INDEX', '<a href="' . append_sid("{$this->root_path}index.{$this->php_ext}", "") . '">', '</a>');
            meta_refresh(3, $meta_info);
            trigger_error($message);
        }
        // User data
        $sql = 'SELECT *
			FROM ' . USERS_TABLE . "\n\t\t\tWHERE user_type <> 2\n\t\t\t\tAND user_id = {$uid}";
        $result = $this->db->sql_query($sql);
        $user_row = $this->db->sql_fetchrow($result);
        $this->db->sql_freeresult($result);
        // Check if an user exists - if not, throw the error and return to the index page
        if (empty($user_row)) {
            $meta_info = append_sid("{$this->root_path}index.{$this->php_ext}", "");
            $message = $this->user->lang['RS_NO_USER_ID'] . '<br /><br />' . $this->user->lang('RETURN_INDEX', '<a href="' . append_sid("{$this->root_path}index.{$this->php_ext}", "") . '">', '</a>');
            meta_refresh(3, $meta_info);
            trigger_error($message);
        }
        // Count reputation rows for the current user
        $sql = 'SELECT COUNT(reputation_id) AS total_reps
			FROM ' . $this->reputations_table . "\n\t\t\tWHERE user_id_to = {$uid}";
        $result = $this->db->sql_query($sql);
        $total_reps = (int) $this->db->sql_fetchfield('total_reps');
        $this->db->sql_freeresult($result);
        // Sort keys
        $sort_key_sql = array('username' => 'u.username_clean', 'time' => 'r.reputation_time', 'point' => 'r.reputation_points', 'action' => 'rt.reputation_type_name', 'id' => 'r.reputation_id');
        // Sql order depends on sort key
        $order_by = $sort_key_sql[$sort_key] . ' ' . ($sort_dir == 'dsc' ? 'DESC' : 'ASC');
        // Start value - it is based on page
        $start = ($page - 1) * $this->config['rs_per_page'];
        $post_type_id = (int) $this->reputation_manager->get_reputation_type_id('post');
        $sql_array = array('SELECT' => 'r.*, rt.reputation_type_name, u.group_id, u.username, u.user_colour, u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height, p.post_id, p.forum_id, p.post_subject', 'FROM' => array($this->reputations_table => 'r', $this->reputation_types_table => 'rt'), 'LEFT_JOIN' => array(array('FROM' => array(USERS_TABLE => 'u'), 'ON' => 'r.user_id_from = u.user_id '), array('FROM' => array(POSTS_TABLE => 'p'), 'ON' => 'p.post_id = r.reputation_item_id
						AND r.reputation_type_id = ' . $post_type_id)), 'WHERE' => 'r.user_id_to = ' . $uid . '
				AND r.reputation_type_id = rt.reputation_type_id', 'ORDER_BY' => $order_by);
        $sql = $this->db->sql_build_query('SELECT', $sql_array);
        $result = $this->db->sql_query_limit($sql, $this->config['rs_per_page'], $start);
        while ($row = $this->db->sql_fetchrow($result)) {
            $this->template->assign_block_vars('reputation', array('ID' => $row['reputation_id'], 'USERNAME' => get_username_string('full', $row['user_id_from'], $row['username'], $row['user_colour']), 'ACTION' => $this->user->lang('RS_' . strtoupper($row['reputation_type_name']) . '_RATING'), 'AVATAR' => phpbb_get_user_avatar($row), 'TIME' => $this->user->format_date($row['reputation_time']), 'COMMENT' => $row['reputation_comment'], 'POINTS' => $row['reputation_points'], 'POINTS_CLASS' => $this->reputation_helper->reputation_class($row['reputation_points']), 'POINTS_TITLE' => $this->user->lang('RS_POINTS_TITLE', $row['reputation_points']), 'U_DELETE' => $this->helper->route('reputation_delete_controller', array('rid' => $row['reputation_id'])), 'S_COMMENT' => !empty($row['reputation_comment']), 'S_DELETE' => $this->auth->acl_get('m_rs_moderate') || $row['user_id_from'] == $this->user->data['user_id'] && $this->auth->acl_get('u_rs_delete') ? true : false));
            // Generate post url
            $this->reputation_manager->generate_post_link($row);
        }
        $this->db->sql_freeresult($result);
        // User reputation rank
        if (!function_exists('phpbb_get_user_rank')) {
            include $this->root_path . 'includes/functions_display.' . $this->php_ext;
        }
        $user_rank_data = phpbb_get_user_rank($user_row, $user_row['user_posts']);
        // Reputation statistics
        $positive_count = $negative_count = 0;
        $positive_sum = $negative_sum = 0;
        $positive_week = $negative_week = 0;
        $positive_month = $negative_month = 0;
        $positive_6months = $negative_6months = 0;
        $post_count = $user_count = 0;
        $last_week = time() - 604800;
        $last_month = time() - 2678400;
        $last_6months = time() - 16070400;
        $user_type_id = (int) $this->reputation_manager->get_reputation_type_id('user');
        $sql = 'SELECT reputation_time, reputation_type_id, reputation_points
			FROM ' . $this->reputations_table . "\n\t\t\tWHERE user_id_to = {$uid}";
        $result = $this->db->sql_query($sql);
        while ($reputation_vote = $this->db->sql_fetchrow($result)) {
            if ($reputation_vote['reputation_points'] > 0) {
                $positive_count++;
                $positive_sum += $reputation_vote['reputation_points'];
                if ($reputation_vote['reputation_time'] >= $last_week) {
                    $positive_week++;
                }
                if ($reputation_vote['reputation_time'] >= $last_month) {
                    $positive_month++;
                }
                if ($reputation_vote['reputation_time'] >= $last_6months) {
                    $positive_6months++;
                }
            } else {
                if ($reputation_vote['reputation_points'] < 0) {
                    $negative_count++;
                    $negative_sum += $reputation_vote['reputation_points'];
                    if ($reputation_vote['reputation_time'] >= $last_week) {
                        $negative_week++;
                    }
                    if ($reputation_vote['reputation_time'] >= $last_month) {
                        $negative_month++;
                    }
                    if ($reputation_vote['reputation_time'] >= $last_6months) {
                        $negative_6months++;
                    }
                }
            }
            if ($reputation_vote['reputation_type_id'] == $post_type_id) {
                $post_count += $reputation_vote['reputation_points'];
            } else {
                if ($reputation_vote['reputation_type_id'] == $user_type_id) {
                    $user_count += $reputation_vote['reputation_points'];
                }
            }
        }
        $this->db->sql_freeresult($result);
        // User reputation power
        if ($this->config['rs_enable_power']) {
            $used_power = $this->reputation_power->used($user_row['user_id']);
            $user_max_voting_power = $this->reputation_power->get($user_row['user_posts'], $user_row['user_regdate'], $user_row['user_reputation'], $user_row['user_warnings'], $user_row['group_id']);
            $user_power_explain = $this->reputation_power->explain();
            $voting_power_left = '';
            if ($this->config['rs_power_renewal']) {
                $voting_power_left = $user_max_voting_power - $used_power;
                if ($voting_power_left < 0) {
                    $voting_power_left = 0;
                }
            }
            $this->template->assign_vars(array('S_RS_POWER_EXPLAIN' => $this->config['rs_power_explain'] ? true : false, 'S_RS_GROUP_POWER' => isset($user_power_explain['GROUP_VOTING_POWER']) ? true : false, 'RS_POWER' => $user_max_voting_power, 'RS_POWER_LEFT' => $this->config['rs_power_renewal'] ? $this->user->lang('RS_VOTE_POWER_LEFT', $voting_power_left, $user_max_voting_power) : '', 'RS_CFG_TOTAL_POSTS' => $this->config['rs_total_posts'] ? true : false, 'RS_CFG_MEMBERSHIP_DAYS' => $this->config['rs_membership_days'] ? true : false, 'RS_CFG_REP_POINT' => $this->config['rs_power_rep_point'] ? true : false, 'RS_CFG_LOOSE_WARN' => $this->config['rs_power_lose_warn'] ? true : false));
            $this->template->assign_vars($user_power_explain);
        }
        // Generate pagination
        $this->pagination->generate_template_pagination(array('routes' => 'reputation_details_controller', 'params' => array('uid' => $uid, 'sort_key' => $sort_key, 'sort_dir' => $sort_dir)), 'pagination', 'page', $total_reps, $this->config['rs_per_page'], $start);
        $this->template->assign_vars(array('USER_ID' => $user_row['user_id'], 'USERNAME' => get_username_string('username', $user_row['user_id'], $user_row['username'], $user_row['user_colour'], true), 'USERNAME_FULL' => get_username_string('full', $user_row['user_id'], $user_row['username'], $user_row['user_colour']), 'REPUTATION' => $user_row['user_reputation'], 'AVATAR_IMG' => phpbb_get_user_avatar($user_row), 'RANK_IMG' => $user_rank_data['img'], 'RANK_IMG_SRC' => $user_rank_data['img_src'], 'RANK_TITLE' => $user_rank_data['title'], 'REPUTATION_CLASS' => $this->reputation_helper->reputation_class($user_row['user_reputation']), 'PAGE_NUMBER' => $this->pagination->on_page($total_reps, $this->config['rs_per_page'], $start), 'TOTAL_REPS' => $this->user->lang('LIST_REPUTATIONS', $total_reps), 'U_SORT_USERNAME' => $this->helper->route('reputation_details_controller', array('uid' => $uid, 'sort_key' => 'username', 'sort_dir' => $sort_key == 'username' && $sort_dir == 'asc' ? 'dsc' : 'asc')), 'U_SORT_TIME' => $this->helper->route('reputation_details_controller', array('uid' => $uid, 'sort_key' => 'time', 'sort_dir' => $sort_key == 'time' && $sort_dir == 'asc' ? 'dsc' : 'asc')), 'U_SORT_POINT' => $this->helper->route('reputation_details_controller', array('uid' => $uid, 'sort_key' => 'point', 'sort_dir' => $sort_key == 'point' && $sort_dir == 'asc' ? 'dsc' : 'asc')), 'U_SORT_ACTION' => $this->helper->route('reputation_details_controller', array('uid' => $uid, 'sort_key' => 'action', 'sort_dir' => $sort_key == 'action' && $sort_dir == 'asc' ? 'dsc' : 'asc')), 'U_CLEAR' => $this->helper->route('reputation_clear_user_controller', array('uid' => $uid)), 'POST_COUNT' => $post_count, 'USER_COUNT' => $user_count, 'POSITIVE_COUNT' => $positive_count, 'POSITIVE_SUM' => $positive_sum, 'POSITIVE_WEEK' => $positive_week, 'POSITIVE_MONTH' => $positive_month, 'POSITIVE_6MONTHS' => $positive_6months, 'NEGATIVE_COUNT' => $negative_count, 'NEGATIVE_SUM' => $negative_sum, 'NEGATIVE_WEEK' => $negative_week, 'NEGATIVE_MONTH' => $negative_month, 'NEGATIVE_6MONTHS' => $negative_6months, 'S_RS_POST_RATING' => $this->config['rs_post_rating'] ? true : false, 'S_RS_USER_RATING' => $this->config['rs_user_rating'] ? true : false, 'S_RS_AVATAR' => $this->config['rs_display_avatar'] ? true : false, 'S_RS_COMMENT' => $this->config['rs_enable_comment'] ? true : false, 'S_RS_NEGATIVE' => $this->config['rs_negative_point'] ? true : false, 'S_RS_POWER_ENABLE' => $this->config['rs_enable_power'] ? true : false, 'S_CLEAR' => $this->auth->acl_gets('m_rs_moderate') ? true : false));
        return $this->helper->render('details.html', $this->user->lang('RS_DETAILS'));
    }
    public function main()
    {
        include_once $this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext;
        $this->user->add_lang(array('memberlist', 'groups', 'search'));
        $this->user->add_lang_ext('gfksx/ThanksForPosts', 'thanks_mod');
        // Grab data
        $mode = $this->request->variable('mode', '');
        $end_row_rating = isset($this->config['thanks_number_row_reput']) ? $this->config['thanks_number_row_reput'] : false;
        $full_post_rating = $full_topic_rating = $full_forum_rating = false;
        $u_search_post = $u_search_topic = $u_search_forum = '';
        $total_match_count = 0;
        //$page_title = $this->user->lang['REPUT_TOPLIST'];
        $topic_id = $this->request->variable('t', 0);
        $return_chars = $this->request->variable('ch', $topic_id ? -1 : 300);
        $words = array();
        $ex_fid_ary = array_keys($this->auth->acl_getf('!f_read', true));
        $ex_fid_ary = sizeof($ex_fid_ary) ? $ex_fid_ary : true;
        $pagination_url = append_sid("{$this->phpbb_root_path}toplist", 'mode=' . $mode);
        if (!$this->auth->acl_gets('u_viewtoplist')) {
            if ($this->user->data['user_id'] != ANONYMOUS) {
                trigger_error('RATING_NO_VIEW_TOPLIST');
            }
            login_box('', isset($this->user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)]) ? $this->user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)] : $this->user->lang['RETING_LOGIN_EXPLAIN']);
        }
        $notoplist = true;
        $start = $this->request->variable('start', 0);
        $max_post_thanks = $this->config['thanks_post_reput_view'] ? $this->gfksx_helper->get_max_post_thanks() : 1;
        $max_topic_thanks = $this->config['thanks_topic_reput_view'] ? $this->gfksx_helper->get_max_topic_thanks() : 1;
        $max_forum_thanks = $this->config['thanks_forum_reput_view'] ? $this->gfksx_helper->get_max_forum_thanks() : 1;
        switch ($mode) {
            case 'post':
                $sql = 'SELECT COUNT(DISTINCT post_id) as total_post_count
					FROM ' . $this->thanks_table . '
					WHERE ' . $this->db->sql_in_set('forum_id', $ex_fid_ary, true);
                $result = $this->db->sql_query($sql);
                $total_match_count = (int) $this->db->sql_fetchfield('total_post_count');
                $this->db->sql_freeresult($result);
                $full_post_rating = true;
                $notoplist = false;
                break;
            case 'topic':
                $sql = 'SELECT COUNT(DISTINCT topic_id) as total_topic_count
					FROM ' . $this->thanks_table . '
					WHERE ' . $this->db->sql_in_set('forum_id', $ex_fid_ary, true);
                $result = $this->db->sql_query($sql);
                $total_match_count = (int) $this->db->sql_fetchfield('total_topic_count');
                $this->db->sql_freeresult($result);
                $full_topic_rating = true;
                $notoplist = false;
                break;
            case 'forum':
                $sql = 'SELECT COUNT(DISTINCT forum_id) as total_forum_count
					FROM ' . $this->thanks_table . '
					WHERE ' . $this->db->sql_in_set('forum_id', $ex_fid_ary, true);
                $result = $this->db->sql_query($sql);
                $total_match_count = (int) $this->db->sql_fetchfield('total_forum_count');
                $this->db->sql_freeresult($result);
                $full_forum_rating = true;
                $notoplist = false;
                break;
            default:
                $page_title = $this->user->lang['REPUT_TOPLIST'];
                $total_match_count = 0;
        }
        $page_title = sprintf($this->user->lang['REPUT_TOPLIST'], $total_match_count);
        //post rating
        if (!$full_forum_rating && !$full_topic_rating && $this->config['thanks_post_reput_view']) {
            $end = $full_post_rating ? $this->config['topics_per_page'] : $end_row_rating;
            $sql_p_array['FROM'] = array($this->thanks_table => 't');
            $sql_p_array['SELECT'] = 'u.user_id, u.username, u.user_colour, p.post_subject, p.post_id, p.post_time, p.poster_id, p.post_username, p.topic_id, p.forum_id, p.post_text, p.bbcode_uid, p.bbcode_bitfield, p.post_attachment';
            $sql_p_array['SELECT'] .= ', t.post_id, COUNT(*) AS post_thanks';
            $sql_p_array['LEFT_JOIN'][] = array('FROM' => array($this->posts_table => 'p'), 'ON' => 't.post_id = p.post_id');
            $sql_p_array['LEFT_JOIN'][] = array('FROM' => array($this->users_table => 'u'), 'ON' => 'p.poster_id = u.user_id');
            $sql_p_array['GROUP_BY'] = 't.post_id';
            $sql_p_array['ORDER_BY'] = 'post_thanks DESC';
            $sql_p_array['WHERE'] = $this->db->sql_in_set('t.forum_id', $ex_fid_ary, true);
            $sql = $this->db->sql_build_query('SELECT', $sql_p_array);
            $result = $this->db->sql_query_limit($sql, $end, $start);
            $u_search_post = append_sid("{$this->phpbb_root_path}toplist", "mode=post");
            if (!($row = $this->db->sql_fetchrow($result))) {
                trigger_error('RATING_VIEW_TOPLIST_NO');
            } else {
                $notoplist = false;
                $bbcode_bitfield = $text_only_message = '';
                do {
                    // We pre-process some variables here for later usage
                    $row['post_text'] = censor_text($row['post_text']);
                    $text_only_message = $row['post_text'];
                    // make list items visible as such
                    if ($row['bbcode_uid']) {
                        $text_only_message = str_replace('[*:' . $row['bbcode_uid'] . ']', '&sdot;&nbsp;', $text_only_message);
                        // no BBCode in text only message
                        strip_bbcode($text_only_message, $row['bbcode_uid']);
                    }
                    if ($return_chars == -1 || utf8_strlen($text_only_message) < $return_chars + 3) {
                        $row['display_text_only'] = false;
                        $bbcode_bitfield = $bbcode_bitfield | base64_decode($row['bbcode_bitfield']);
                        // Does this post have an attachment? If so, add it to the list
                        if ($row['post_attachment'] && $this->config['allow_attachments']) {
                            $attach_list[$row['forum_id']][] = $row['post_id'];
                        }
                    } else {
                        $row['post_text'] = $text_only_message;
                        $row['display_text_only'] = true;
                    }
                    $rowset[] = $row;
                    unset($text_only_message);
                    // Instantiate BBCode if needed
                    if ($bbcode_bitfield !== '' and !class_exists('bbcode')) {
                        include $this->phpbb_root_path . 'includes/bbcode.' . $this->php_ext;
                        $bbcode = new \bbcode(base64_encode($bbcode_bitfield));
                    }
                    // Replace naughty words such as farty pants
                    $row['post_subject'] = censor_text($row['post_subject']);
                    if ($row['display_text_only']) {
                        $row['post_text'] = get_context($row['post_text'], $words, $return_chars);
                        $row['post_text'] = bbcode_nl2br($row['post_text']);
                    } else {
                        // Second parse bbcode here
                        if ($row['bbcode_bitfield']) {
                            $bbcode->bbcode_second_pass($row['post_text'], $row['bbcode_uid'], $row['bbcode_bitfield']);
                        }
                        $row['post_text'] = bbcode_nl2br($row['post_text']);
                        $row['post_text'] = smiley_text($row['post_text']);
                    }
                    $post_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'p=' . $row['post_id'] . '#p' . $row['post_id']);
                    $this->template->assign_block_vars('toppostrow', array('MESSAGE' => $this->auth->acl_get('f_read', $row['forum_id']) ? $row['post_text'] : (!empty($row['forum_id']) ? $this->user->lang['SORRY_AUTH_READ'] : $row['post_text']), 'POST_DATE' => !empty($row['post_time']) ? $this->user->format_date($row['post_time']) : '', 'MINI_POST_IMG' => $this->user->img('icon_post_target', 'POST'), 'POST_ID' => $post_url, 'POST_SUBJECT' => $this->auth->acl_get('f_read', $row['forum_id']) ? $row['post_subject'] : (!empty($row['forum_id']) ? '' : $row['post_subject']), 'POST_AUTHOR' => get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']), 'POST_REPUT' => round($row['post_thanks'] / ($max_post_thanks / 100), $this->config['thanks_number_digits']) . '%', 'POST_THANKS' => $row['post_thanks'], 'S_THANKS_POST_REPUT_VIEW' => isset($this->config['thanks_post_reput_view']) ? $this->config['thanks_post_reput_view'] : false, 'S_THANKS_REPUT_GRAPHIC' => isset($this->config['thanks_reput_graphic']) ? $this->config['thanks_reput_graphic'] : false, 'THANKS_REPUT_HEIGHT' => sprintf('%dpx', $this->config['thanks_reput_height']), 'THANKS_REPUT_GRAPHIC_WIDTH' => sprintf('%dpx', $this->config['thanks_reput_level'] * $this->config['thanks_reput_height']), 'THANKS_REPUT_IMAGE' => isset($this->config['thanks_reput_image']) ? $this->phpbb_root_path . $this->config['thanks_reput_image'] : '', 'THANKS_REPUT_IMAGE_BACK' => isset($this->config['thanks_reput_image_back']) ? $this->phpbb_root_path . $this->config['thanks_reput_image_back'] : ''));
                } while ($row = $this->db->sql_fetchrow($result));
                $this->db->sql_freeresult($result);
            }
        }
        //topic rating
        if (!$full_forum_rating && !$full_post_rating && $this->config['thanks_topic_reput_view']) {
            $end = $full_topic_rating ? $this->config['topics_per_page'] : $end_row_rating;
            $sql_t_array['FROM'] = array($this->thanks_table => 'f');
            $sql_t_array['SELECT'] = 'u.user_id, u.username, u.user_colour, t.topic_title, t.topic_id, t.topic_time, t.topic_poster, t.topic_first_poster_name, t.topic_first_poster_colour, t.forum_id, t.topic_type, t.topic_status, t.poll_start';
            $sql_t_array['SELECT'] .= ', f.topic_id, COUNT(*) AS topic_thanks';
            $sql_t_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TABLE => 't'), 'ON' => 'f.topic_id = t.topic_id');
            $sql_t_array['LEFT_JOIN'][] = array('FROM' => array($this->users_table => 'u'), 'ON' => 't.topic_poster = u.user_id');
            $sql_t_array['GROUP_BY'] = 'f.topic_id';
            $sql_t_array['ORDER_BY'] = 'topic_thanks DESC';
            $sql_t_array['WHERE'] = $this->db->sql_in_set('f.forum_id', $ex_fid_ary, true);
            $sql = $this->db->sql_build_query('SELECT', $sql_t_array);
            $result = $this->db->sql_query_limit($sql, $end, $start);
            $u_search_topic = append_sid("{$this->phpbb_root_path}toplist", "mode=topic");
            if (!($row = $this->db->sql_fetchrow($result))) {
                trigger_error('RATING_VIEW_TOPLIST_NO');
            } else {
                $notoplist = false;
                do {
                    // Get folder img, topic status/type related information
                    $folder_img = $folder_alt = $topic_type = '';
                    topic_status($row, 0, false, $folder_img, $folder_alt, $topic_type);
                    $view_topic_url_params = 'f=' . ($row['forum_id'] ? $row['forum_id'] : '') . '&amp;t=' . $row['topic_id'];
                    $view_topic_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", $view_topic_url_params);
                    $this->template->assign_block_vars('toptopicrow', array('TOPIC_IMG_STYLE' => $folder_img, 'TOPIC_FOLDER_IMG_SRC' => $row['forum_id'] ? 'topic_read' : 'announce_read', 'TOPIC_TITLE' => $this->auth->acl_get('f_read', $row['forum_id']) ? $row['topic_title'] : (!empty($row['forum_id']) ? $this->user->lang['SORRY_AUTH_READ'] : $row['topic_title']), 'U_VIEW_TOPIC' => $view_topic_url, 'TOPIC_AUTHOR' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'TOPIC_THANKS' => $row['topic_thanks'], 'TOPIC_REPUT' => round($row['topic_thanks'] / ($max_topic_thanks / 100), $this->config['thanks_number_digits']) . '%', 'S_THANKS_TOPIC_REPUT_VIEW' => isset($this->config['thanks_topic_reput_view']) ? $this->config['thanks_topic_reput_view'] : false, 'S_THANKS_REPUT_GRAPHIC' => isset($this->config['thanks_reput_graphic']) ? $this->config['thanks_reput_graphic'] : false, 'THANKS_REPUT_HEIGHT' => sprintf('%dpx', $this->config['thanks_reput_height']), 'THANKS_REPUT_GRAPHIC_WIDTH' => sprintf('%dpx', $this->config['thanks_reput_level'] * $this->config['thanks_reput_height']), 'THANKS_REPUT_IMAGE' => isset($this->config['thanks_reput_image']) ? $this->phpbb_root_path . $this->config['thanks_reput_image'] : '', 'THANKS_REPUT_IMAGE_BACK' => isset($this->config['thanks_reput_image_back']) ? $this->phpbb_root_path . $this->config['thanks_reput_image_back'] : ''));
                } while ($row = $this->db->sql_fetchrow($result));
                $this->db->sql_freeresult($result);
            }
        }
        //forum rating
        if (!$full_topic_rating && !$full_post_rating && $this->config['thanks_forum_reput_view']) {
            $end = $full_forum_rating ? $this->config['topics_per_page'] : $end_row_rating;
            $sql_f_array['FROM'] = array($this->thanks_table => 't');
            $sql_f_array['SELECT'] = 'f.forum_name, f.forum_id';
            $sql_f_array['SELECT'] .= ', t.forum_id, COUNT(*) AS forum_thanks';
            $sql_f_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 't.forum_id = f.forum_id');
            $sql_f_array['GROUP_BY'] = 't.forum_id';
            $sql_f_array['ORDER_BY'] = 'forum_thanks DESC';
            $sql_f_array['WHERE'] = $this->db->sql_in_set('t.forum_id', $ex_fid_ary, true);
            $sql = $this->db->sql_build_query('SELECT', $sql_f_array);
            $result = $this->db->sql_query_limit($sql, $end, $start);
            $u_search_forum = append_sid("{$this->phpbb_root_path}toplist", "mode=forum");
            if (!($row = $this->db->sql_fetchrow($result))) {
                trigger_error('RATING_VIEW_TOPLIST_NO');
            } else {
                $notoplist = false;
                do {
                    if (!empty($row['forum_id'])) {
                        $u_viewforum = append_sid("{$this->phpbb_root_path}viewforum.{$this->php_ext}", 'f=' . $row['forum_id']);
                        $folder_image = 'forum_read';
                        $this->template->assign_block_vars('topforumrow', array('FORUM_FOLDER_IMG_SRC' => $this->user->img('forum_read', 'NO_NEW_POSTS', false, '', 'src'), 'FORUM_IMG_STYLE' => $folder_image, 'FORUM_NAME' => $this->auth->acl_get('f_read', $row['forum_id']) ? $row['forum_name'] : (!empty($row['forum_id']) ? $this->user->lang['SORRY_AUTH_READ'] : $row['forum_name']), 'U_VIEW_FORUM' => $u_viewforum, 'FORUM_THANKS' => $row['forum_thanks'], 'FORUM_REPUT' => round($row['forum_thanks'] / ($max_forum_thanks / 100), $this->config['thanks_number_digits']) . '%', 'S_THANKS_FORUM_REPUT_VIEW' => isset($this->config['thanks_forum_reput_view']) ? $this->config['thanks_forum_reput_view'] : false, 'S_THANKS_REPUT_GRAPHIC' => isset($this->config['thanks_reput_graphic']) ? $this->config['thanks_reput_graphic'] : false, 'THANKS_REPUT_HEIGHT' => sprintf('%dpx', $this->config['thanks_reput_height']), 'THANKS_REPUT_GRAPHIC_WIDTH' => sprintf('%dpx', $this->config['thanks_reput_level'] * $this->config['thanks_reput_height']), 'THANKS_REPUT_IMAGE' => isset($this->config['thanks_reput_image']) ? $this->phpbb_root_path . $this->config['thanks_reput_image'] : '', 'THANKS_REPUT_IMAGE_BACK' => isset($this->config['thanks_reput_image_back']) ? $this->phpbb_root_path . $this->config['thanks_reput_image_back'] : ''));
                    }
                } while ($row = $this->db->sql_fetchrow($result));
                $this->db->sql_freeresult($result);
            }
        }
        if ($notoplist) {
            trigger_error('RATING_VIEW_TOPLIST_NO');
        }
        $this->pagination->generate_template_pagination($pagination_url, 'pagination', 'start', $total_match_count, $this->config['topics_per_page'], $start);
        // Output the page
        $this->template->assign_vars(array('PAGE_NUMBER' => $this->pagination->on_page($total_match_count, $this->config['posts_per_page'], $start), 'PAGE_TITLE' => $page_title, 'S_THANKS_FORUM_REPUT_VIEW' => isset($this->config['thanks_forum_reput_view']) ? $this->config['thanks_forum_reput_view'] : false, 'S_THANKS_TOPIC_REPUT_VIEW' => isset($this->config['thanks_topic_reput_view']) ? $this->config['thanks_topic_reput_view'] : false, 'S_THANKS_POST_REPUT_VIEW' => isset($this->config['thanks_post_reput_view']) ? $this->config['thanks_post_reput_view'] : false, 'S_FULL_POST_RATING' => $full_post_rating, 'S_FULL_TOPIC_RATING' => $full_topic_rating, 'S_FULL_FORUM_RATING' => $full_forum_rating, 'U_SEARCH_POST' => $u_search_post, 'U_SEARCH_TOPIC' => $u_search_topic, 'U_SEARCH_FORUM' => $u_search_forum));
        page_header($page_title);
        $this->template->set_filenames(array('body' => 'toplist_body.html'));
        make_jumpbox(append_sid("{$this->phpbb_root_path}viewforum.{$this->php_ext}"));
        page_footer();
        return new Response($this->template->return_display('body'), 200);
    }