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
 /**
  * Build pagination and send to template
  * $this->url_location and $this->url_parameters will over-ride the settings given here for $page, $params.
  * The reason is that the place that calls build_pagination is typically in a completely different area, in an area that can't say for certain the correct URL (other than the current page)
  *
  * @param string $page path/page to be used in pagination url
  * @param array $params to be used in pagination url
  * @return $this
  */
 public function build_pagination($page, $params = array())
 {
     if ($this->url_location) {
         $page = $this->url_location;
     }
     if ($this->url_parameters) {
         $params = $this->url_parameters;
     }
     // Spring cleaning
     unset($params[$this->start_name], $params[$this->limit_name], $params[$this->sort_key_name], $params[$this->sort_dir_name]);
     // Add the limit to the URL if required
     if ($this->limit != $this->default_limit) {
         $params[$this->limit_name] = $this->limit;
     }
     // Don't include the sort key/dir in the sort action url
     $sort_url = $this->path_helper->append_url_params($page, $params);
     // Add the sort key to the URL if required
     if ($this->sort_key != $this->default_sort_key) {
         $params[$this->sort_key_name] = $this->sort_key;
     }
     // Add the sort dir to the URL if required
     if ($this->sort_dir != $this->default_sort_dir) {
         $params[$this->sort_dir_name] = $this->sort_dir;
     }
     $pagination_url = $this->path_helper->append_url_params($page, $params);
     $this->pagination->generate_template_pagination($pagination_url, $this->template_block, 'start', $this->total, $this->limit, $this->start);
     if ($this->template_block == 'pagination') {
         $this->template->assign_vars(array($this->template_vars['S_SORT_ACTION'] => $sort_url, $this->template_vars['S_PAGINATION_ACTION'] => $pagination_url, $this->template_vars['S_NUM_POSTS'] => $this->total, $this->template_vars['S_SELECT_SORT_KEY'] => $this->get_sort_key_list(), $this->template_vars['S_SELECT_SORT_DIR'] => $this->get_sort_dir_list(), $this->template_vars['SORT_KEYS_NAME'] => $this->sort_key_name, $this->template_vars['SORT_DIR_NAME'] => $this->sort_dir_name, $this->template_vars['TOTAL_ITEMS'] => $this->total, $this->template_vars['TOTAL_RESULTS'] => $this->user->lang($this->result_lang, $this->total)));
     }
     return $this;
 }
Beispiel #3
0
    public function handle_downloadlog()
    {
        if (!$this->auth->acl_get('a_')) {
            trigger_error('Access Denied');
        } else {
            $this->user->add_lang_ext('dmzx/downloadlog', 'common');
            $fileid = $this->request->variable('file', 0);
            $start = $this->request->variable('start', 0);
            // Pagination number from ACP
            $dll = $this->config['downloadlog_value'];
            // Generate pagination
            $sql = 'SELECT COUNT(downloadslog_id) AS total_downloadlogs
				FROM ' . $this->userdownloadslog_table . '
				WHERE user_id = user_id
				AND file_id = ' . $fileid;
            $result = $this->db->sql_query($sql);
            $total_downloadlogs = (int) $this->db->sql_fetchfield('total_downloadlogs');
            $sql = 'SELECT d.user_id, d.down_date, u.user_id, u.username, u.user_colour
				FROM ' . $this->userdownloadslog_table . ' d, ' . USERS_TABLE . ' u
				WHERE u.user_id = d.user_id
				AND file_id = ' . $fileid . '
				ORDER BY d.down_date DESC';
            $top_result = $this->db->sql_query_limit($sql, $dll, $start);
            while ($row = $this->db->sql_fetchrow($top_result)) {
                $this->template->assign_block_vars('downloaders', array('D_USERNAME' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'D_TIME' => $this->user->format_date($row['down_date'])));
            }
        }
        $pagination_url = $this->helper->route('dmzx_downloadlog_controller', array('file' => $fileid));
        //Start pagination
        $this->pagination->generate_template_pagination($pagination_url, 'pagination', 'start', $total_downloadlogs, $dll, $start);
        $this->template->assign_vars(array('DOWNLOADERS_USERS' => $total_downloadlogs == 1 ? $this->user->lang['DOWNLOADERS_COUNT'] : sprintf($this->user->lang['DOWNLOADERS_COUNTS'], $total_downloadlogs), 'DOWNLOADERS_VERSION' => $this->config['downloadlog_version']));
        page_header('Downloaders Log', false);
        $this->template->set_filenames(array('body' => 'DownloadLog.html'));
        page_footer();
    }
    /**
     * Display popup comment
     *
     * @param	int		$link_id		The category ID
     * @param	int		$page			Page number taken from the URL
     * @param	string	$mode			add|edit
     * @return	\Symfony\Component\HttpFoundation\Response	A Symfony Response object
     * @throws	\phpbb\exception\http_exception
     */
    public function view($link_id, $page, $mode = 'new')
    {
        $this->_check_comments_enable($link_id);
        $comment_id = $this->request->variable('c', 0);
        $view = $this->request->variable('view', '');
        $start = ($page - 1) * $this->config['dir_comments_per_page'];
        $this->s_hidden_fields = array_merge($this->s_hidden_fields, array('page' => $page));
        $this->_populate_form($link_id, $mode);
        $sql = 'SELECT COUNT(comment_id) AS nb_comments
			FROM ' . DIR_COMMENT_TABLE . '
			WHERE comment_link_id = ' . (int) $link_id;
        $result = $this->db->sql_query($sql);
        $nb_comments = (int) $this->db->sql_fetchfield('nb_comments');
        $this->db->sql_freeresult($result);
        // Make sure $start is set to the last page if it exceeds the amount
        $start = $this->pagination->validate_start($start, $this->config['dir_comments_per_page'], $nb_comments);
        $sql_array = array('SELECT' => 'a.comment_id, a.comment_user_id, a. comment_user_ip, a.comment_date, a.comment_text, a.comment_uid, a.comment_bitfield, a.comment_flags, u.username, u.user_id, u.user_colour, z.foe', 'FROM' => array(DIR_COMMENT_TABLE => 'a'), 'LEFT_JOIN' => array(array('FROM' => array(USERS_TABLE => 'u'), 'ON' => 'a.comment_user_id = u.user_id'), array('FROM' => array(ZEBRA_TABLE => 'z'), 'ON' => 'z.user_id = ' . $this->user->data['user_id'] . ' AND z.zebra_id = a.comment_user_id')), 'WHERE' => 'a.comment_link_id = ' . (int) $link_id, 'ORDER_BY' => 'a.comment_date DESC');
        $sql = $this->db->sql_build_query('SELECT', $sql_array);
        $result = $this->db->sql_query_limit($sql, $this->config['dir_comments_per_page'], $start);
        $have_result = false;
        while ($comments = $this->db->sql_fetchrow($result)) {
            $have_result = true;
            $edit_allowed = $this->user->data['is_registered'] && ($this->auth->acl_get('m_edit_comment_dir') || $this->user->data['user_id'] == $comments['comment_user_id'] && $this->auth->acl_get('u_edit_comment_dir'));
            $delete_allowed = $this->user->data['is_registered'] && ($this->auth->acl_get('m_delete_comment_dir') || $this->user->data['user_id'] == $comments['comment_user_id'] && $this->auth->acl_get('u_delete_comment_dir'));
            $this->template->assign_block_vars('comment', array('MINI_POST_IMG' => $this->user->img('icon_post_target', 'POST'), 'S_USER' => get_username_string('full', $comments['comment_user_id'], $comments['username'], $comments['user_colour']), 'S_USER_IP' => $comments['comment_user_ip'], 'S_DATE' => $this->user->format_date($comments['comment_date']), 'S_COMMENT' => generate_text_for_display($comments['comment_text'], $comments['comment_uid'], $comments['comment_bitfield'], $comments['comment_flags']), 'S_ID' => $comments['comment_id'], 'U_EDIT' => $edit_allowed ? $this->helper->route('ernadoo_phpbbdirectory_comment_edit_controller', array('link_id' => (int) $link_id, 'comment_id' => (int) $comments['comment_id'])) : '', 'U_DELETE' => $delete_allowed ? $this->helper->route('ernadoo_phpbbdirectory_comment_delete_controller', array('link_id' => (int) $link_id, 'comment_id' => (int) $comments['comment_id'], '_referer' => $this->helper->get_current_url())) : '', 'S_IGNORE_POST' => $comments['foe'] && ($view != 'show' || $comment_id != $comments['comment_id']) ? true : false, 'L_IGNORE_POST' => $comments['foe'] ? $this->user->lang('POST_BY_FOE', get_username_string('full', $comments['comment_user_id'], $comments['username'], $comments['user_colour']), '<a href="' . $this->helper->url('directory/link/' . $link_id . '/comment' . ($page > 1 ? '/' . $page : '') . '?view=show#c' . (int) $comments['comment_id']) . '">', '</a>') : '', 'L_POST_DISPLAY' => $comments['foe'] ? $this->user->lang('POST_DISPLAY', '<a class="display_post" data-post-id="' . $comments['comment_id'] . '" href="' . $this->helper->url('directory/link/' . $link_id . '/comment' . ($page > 1 ? '/' . $page : '') . '?c=' . (int) $comments['comment_id'] . '&view=show#c' . (int) $comments['comment_id']) . '">', '</a>') : '', 'S_INFO' => $this->auth->acl_get('m_info')));
        }
        $base_url = array('routes' => 'ernadoo_phpbbdirectory_comment_view_controller', 'params' => array('link_id' => (int) $link_id));
        $this->pagination->generate_template_pagination($base_url, 'pagination', 'page', $nb_comments, $this->config['dir_comments_per_page'], $start);
        $this->template->assign_vars(array('TOTAL_COMMENTS' => $this->user->lang('DIR_NB_COMMS', (int) $nb_comments), 'S_HAVE_RESULT' => $have_result ? true : false));
        return $this->helper->render('comments.html', $this->user->lang['DIR_COMMENT_TITLE']);
    }
    /**
     * Display the flags
     *
     * @return null
     * @access public
     */
    public function display_flags()
    {
        $start = $this->request->variable('start', 0);
        $pagination_url = $this->u_action;
        $this->user->add_lang_ext('rmcgirr83/nationalflags', 'common');
        $sql = 'SELECT f.*, COUNT(u.user_flag) as user_count
			FROM ' . $this->flags_table . ' f
				LEFT JOIN ' . USERS_TABLE . " u on f.flag_id = u.user_flag\n\t\t\tGROUP BY f.flag_id\n\t\t\tORDER BY f.flag_name ASC";
        $result = $this->db->sql_query_limit($sql, $this->config['topics_per_page'], $start);
        // for counting of all the flags
        // used for pagination
        $result2 = $this->db->sql_query($sql);
        $row2 = $this->db->sql_fetchrowset($result2);
        $total_count = (int) sizeof($row2);
        $this->db->sql_freeresult($result2);
        unset($row2);
        while ($row = $this->db->sql_fetchrow($result)) {
            $user_count = $this->user->lang('FLAG_USERS', (int) $row['user_count']);
            $this->template->assign_block_vars('flags', array('FLAG_NAME' => $row['flag_name'], 'FLAG_IMG' => $this->ext_path_web . 'flags/' . strtolower($row['flag_image']), 'FLAG_ID' => $row['flag_id'], 'USER_COUNT' => $user_count, 'U_FLAG' => $this->helper->route('rmcgirr83_nationalflags_getflags', array('flag_id' => $row['flag_id'])), 'U_EDIT' => $this->u_action . "&amp;flag_id={$row['flag_id']}&amp;action=edit", 'U_DELETE' => $this->u_action . "&amp;flag_id={$row['flag_id']}&amp;action=delete"));
        }
        $this->db->sql_freeresult($result);
        $start = $this->pagination->validate_start($start, $this->config['topics_per_page'], $total_count);
        $this->pagination->generate_template_pagination($pagination_url, 'pagination', 'start', $total_count, $this->config['topics_per_page'], $start);
        $this->template->assign_vars(array('TOTAL_FLAGS' => $total_count, 'S_FLAGS' => true));
    }
    /**
     * Display the output for this extension
     *
     * @return null
     * @access public
     */
    public function display_output()
    {
        // Add the language file
        $this->language->add_lang('acp_activesessions', 'david63/activesessions');
        // Start initial var setup
        $action = $this->request->variable('action', '');
        $start = $this->request->variable('start', 0);
        $fc = $this->request->variable('fc', '');
        $sort_key = $this->request->variable('sk', 's');
        $sd = $sort_dir = $this->request->variable('sd', 'd');
        $sort_dir = $sort_dir == 'd' ? ' DESC' : ' ASC';
        $order_ary = array('i' => 's.session_ip' . $sort_dir . ', u.username_clean ASC', 's' => 's.session_start' . $sort_dir . ', u.username_clean ASC', 'u' => 'u.username_clean' . $sort_dir);
        $filter_by = '';
        if ($fc == 'other') {
            for ($i = ord($this->language->lang('START_CHARACTER')); $i <= ord($this->language->lang('END_CHARACTER')); $i++) {
                $filter_by .= ' AND u.username_clean ' . $this->db->sql_not_like_expression(utf8_clean_string(chr($i)) . $this->db->get_any_char());
            }
        } else {
            if ($fc) {
                $filter_by .= ' AND u.username_clean ' . $this->db->sql_like_expression(utf8_clean_string(substr($fc, 0, 1)) . $this->db->get_any_char());
            }
        }
        $sql = $this->db->sql_build_query('SELECT', array('SELECT' => 'u.user_id, u.username, u.username_clean, u.user_colour, s.*, f.forum_id, f.forum_name', 'FROM' => array(USERS_TABLE => 'u', SESSIONS_TABLE => 's'), 'LEFT_JOIN' => array(array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 's.session_forum_id = f.forum_id')), 'WHERE' => 'u.user_id = s.session_user_id
				AND s.session_time >= ' . (time() - $this->config['session_length'] * 60) . $filter_by, 'ORDER_BY' => $sort_key == '' ? 'u.username_clean' : $order_ary[$sort_key]));
        $result = $this->db->sql_query_limit($sql, $this->config['topics_per_page'], $start);
        while ($row = $this->db->sql_fetchrow($result)) {
            $this->template->assign_block_vars('active_sessions', array('ADMIN' => $row['session_admin'] ? $this->language->lang('YES') : $this->language->lang('NO'), 'AUTO_LOGIN' => $row['session_autologin'] ? $this->language->lang('YES') : $this->language->lang('NO'), 'BROWSER' => $row['session_browser'], 'FORUM' => $row['forum_id'] > 0 ? $row['forum_name'] : '', 'LAST_VISIT' => $this->user->format_date($row['session_last_visit']), 'SESSION_FORWARD' => $row['session_forwarded_for'], 'SESSION_ID' => $row['session_id'], 'SESSION_IP' => $row['session_ip'], 'SESSION_KEY' => $row['session_id'] . $row['user_id'], 'SESSION_ONLINE' => $row['session_viewonline'] ? $this->language->lang('YES') : $this->language->lang('NO'), 'SESSION_PAGE' => $row['session_page'], 'SESSION_START' => $this->user->format_date($row['session_start']), 'SESSION_TIME' => $this->user->format_date($row['session_time']), 'USERNAME' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'])));
        }
        $this->db->sql_freeresult($result);
        $sort_by_text = array('u' => $this->language->lang('SORT_USERNAME'), 'i' => $this->language->lang('SESSION_IP'), 's' => $this->language->lang('SESSION_START'));
        $limit_days = array();
        $s_sort_key = $s_limit_days = $s_sort_dir = $u_sort_param = '';
        gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sd, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
        // Get total session count for output
        $sql = $this->db->sql_build_query('SELECT', array('SELECT' => 'COUNT(s.session_id) AS total_sessions', 'FROM' => array(USERS_TABLE => 'u', SESSIONS_TABLE => 's'), 'WHERE' => 'u.user_id = s.session_user_id' . $filter_by));
        $result = $this->db->sql_query($sql);
        $session_count = (int) $this->db->sql_fetchfield('total_sessions');
        $this->db->sql_freeresult($result);
        $action = "{$this->u_action}&amp;sk={$sort_key}&amp;sd={$sd}";
        $link = $session_count ? adm_back_link($action . '&amp;start=' . $start) : '';
        if ($session_count == 0) {
            trigger_error($this->language->lang('NO_SESSION_DATA') . $link);
        }
        $start = $this->pagination->validate_start($start, $this->config['topics_per_page'], $session_count);
        $this->pagination->generate_template_pagination($action, 'pagination', 'start', $session_count, $this->config['topics_per_page'], $start);
        $first_characters = array();
        $first_characters[''] = $this->language->lang('ALL');
        for ($i = ord($this->language->lang('START_CHARACTER')); $i <= ord($this->language->lang('END_CHARACTER')); $i++) {
            $first_characters[chr($i)] = chr($i);
        }
        $first_characters['other'] = $this->language->lang('OTHER');
        foreach ($first_characters as $char => $desc) {
            $this->template->assign_block_vars('first_char', array('DESC' => $desc, 'U_SORT' => $action . '&amp;fc=' . $char));
        }
        $this->template->assign_vars(array('ACTIVE_SESSIONS_VERSION' => ext::ACTIVE_SESSIONS_VERSION, 'S_SORT_DIR' => $s_sort_dir, 'S_SORT_KEY' => $s_sort_key, 'TOTAL_USERS' => $this->language->lang('TOTAL_SESSIONS', (int) $session_count), 'U_ACTION' => $action));
    }
Beispiel #7
0
 public function view_stat_click($top_id, $top_count = 0)
 {
     $start = $this->request->variable('top', 0);
     $sql = 'SELECT * FROM ' . RATING_CLICK_TABLE . "\n\t\t\tWHERE top_id = " . (int) $top_id;
     $result = $this->db->sql_query_limit($sql, $this->config['top_per_page'], $start);
     while ($row = $this->db->sql_fetchrow($result)) {
         $this->template->assign_block_vars('statrow', array('TOP_ID' => $row['top_id'], 'TOP_TIME' => $this->user->format_date($row['top_time'], false, false), 'TOP_TYPE' => !empty($this->user->lang['TOP_' . strtoupper($row['top_type'])]) ? $this->user->lang['TOP_' . strtoupper($row['top_type'])] : $row['top_type'], 'TOP_IP' => $row['top_ip'], 'TOP_DEVICE' => $row['top_device'], 'TOP_PROV_ID' => $row['top_prov_id'], 'TOP_COUNT' => $row['top_count']));
     }
     $this->db->sql_freeresult($result);
     $page_url = $this->helper->route("bb3top_rating_click", array('top_id' => $top_id));
     $this->pagination->generate_template_pagination($page_url, 'pagination', 'top', $top_count, $this->config['top_per_page'], $start);
 }
 /**
  * @param string $mode phpbb acp-mode
  * @param string $u_action phpbb acp-u_action
  * @param string $id the modules-id (url-param "i")
  */
 public function manage_tags($mode, $u_action, $id)
 {
     $action = $this->request->variable('action', '');
     switch ($action) {
         case 'delete':
             $this->handle_delete($mode, $u_action, $id);
             break;
         case 'edit':
             $this->handle_edit($u_action);
             break;
         case 'edit_non_ajax':
             $this->handle_edit($u_action, false);
             break;
         default:
             // show all tags
             $sort_key = $this->request->variable('sort_key', self::SORT_NAME_ASC);
             $sort_field = 'tag';
             switch ($sort_key) {
                 case self::SORT_COUNT_ASC:
                     // no break
                 // no break
                 case self::SORT_COUNT_DESC:
                     $sort_field = 'count';
                     break;
                 case self::SORT_NAME_ASC:
                     // no break
                 // no break
                 case self::SORT_NAME_DESC:
                     // no break
                 // no break
                 default:
                     $sort_field = 'tag';
                     break;
             }
             $ordering = $sort_key % 2 == self::SORT_ASC;
             $start = $this->request->variable('start', 0);
             $limit = $this->config['topics_per_page'];
             $tags_count = $this->tags_manager->count_tags();
             $start = $this->pagination->validate_start($start, $limit, $tags_count);
             $base_url = $u_action . "&amp;sort_key={$sort_key}";
             $tags = $this->tags_manager->get_all_tags($start, $limit, $sort_field, $ordering);
             $this->pagination->generate_template_pagination($base_url, 'pagination', 'start', $tags_count, $limit, $start);
             foreach ($tags as $tag) {
                 $this->template->assign_block_vars('tags', array('NAME' => $tag['tag'], 'ASSIGNMENTS' => $tag['count'], 'U_DELETE_TAG' => $this->get_tag_link($u_action, $tag['id']) . '&amp;action=delete', 'U_EDIT_TAG' => $this->get_tag_link($u_action, $tag['id']) . '&amp;action=edit_non_ajax'));
             }
             $this->template->assign_vars(array('SELECT_SORT_KEY' => $this->create_sort_selects($sort_key), 'U_ACTION' => $u_action . "&amp;sort_key={$sort_key}&amp;start={$start}"));
             break;
     }
 }
    /**
     * Display website list for (dis)approval
     *
     * @return null
     */
    public function display_websites()
    {
        global $phpbb_admin_path;
        // Sort keys
        $sort_days = $this->request->variable('st', 0);
        $sort_key = $this->request->variable('sk', 't');
        $sort_dir = $this->request->variable('sd', 'd');
        // Number of entries to display
        $per_page = $this->request->variable('links_per_page', (int) $this->config['dir_show']);
        $start = $this->request->variable('start', 0);
        // Categorie ordering options
        $limit_days = array(0 => $this->user->lang['SEE_ALL'], 1 => $this->user->lang['1_DAY'], 7 => $this->user->lang['7_DAYS'], 14 => $this->user->lang['2_WEEKS'], 30 => $this->user->lang['1_MONTH'], 90 => $this->user->lang['3_MONTHS'], 180 => $this->user->lang['6_MONTHS'], 365 => $this->user->lang['1_YEAR']);
        $sort_by_text = array('a' => $this->user->lang['AUTHOR'], 't' => $this->user->lang['POST_TIME']);
        $sort_by_sql = array('a' => 'u.username_clean', 't' => array('l.link_time', 'l.link_id'));
        $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
        gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
        // Define where and sort sql for use in displaying logs
        $sql_where = $sort_days ? time() - $sort_days * 86400 : 0;
        $direction = $sort_dir == 'd' ? 'DESC' : 'ASC';
        if (is_array($sort_by_sql[$sort_key])) {
            $sql_sort_order = implode(' ' . $direction . ', ', $sort_by_sql[$sort_key]) . ' ' . $direction;
        } else {
            $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . $direction;
        }
        $sql = 'SELECT COUNT(1) AS total_links
			FROM ' . DIR_LINK_TABLE . '
			WHERE link_active = 0' . ($sql_where ? " AND link_time >= {$sql_where}" : '');
        $result = $this->db->sql_query($sql);
        $total_links = (int) $this->db->sql_fetchfield('total_links');
        $this->db->sql_freeresult($result);
        // Make sure $start is set to the last page if it exceeds the amount
        $start = $this->pagination->validate_start($start, $per_page, $total_links);
        $sql_array = array('SELECT' => 'l.link_id, l.link_name, l.link_url, l.link_description, l.link_cat, l.link_user_id, l.link_guest_email, l.link_uid, l.link_bitfield, l.link_flags, l.link_banner, l.link_time, c.cat_name, u.user_id, u.username, u.user_colour', 'FROM' => array(DIR_LINK_TABLE => 'l'), 'LEFT_JOIN' => array(array('FROM' => array(DIR_CAT_TABLE => 'c'), 'ON' => 'c.cat_id = l.link_cat'), array('FROM' => array(USERS_TABLE => 'u'), 'ON' => 'u.user_id = l.link_user_id')), 'WHERE' => 'l.link_active = 0' . ($sql_where ? " AND l.link_time >= {$sql_where}" : ''), 'ORDER_BY' => $sql_sort_order);
        $sql = $this->db->sql_build_query('SELECT', $sql_array);
        $result = $this->db->sql_query_limit($sql, $per_page, $start);
        while ($row = $this->db->sql_fetchrow($result)) {
            $s_banner = $this->link->display_bann($row);
            $username = $row['link_user_id'] == ANONYMOUS ? $row['link_guest_email'] : $row['username'];
            $link_row = array('LINK_URL' => $row['link_url'], 'LINK_NAME' => $row['link_name'], 'LINK_DESC' => generate_text_for_display($row['link_description'], $row['link_uid'], $row['link_bitfield'], $row['link_flags']), 'L_DIR_USER_PROP' => $this->user->lang('DIR_USER_PROP', get_username_string('full', $row['link_user_id'], $username, $row['user_colour'], false, append_sid("{$phpbb_admin_path}index.{$this->php_ext}", 'i=users&amp;mode=overview')), '<select name=c' . $row['link_id'] . '>' . $this->categorie->make_cat_select((int) $row['link_cat']) . '</select>', $this->user->format_date($row['link_time'])), 'BANNER' => $s_banner, 'LINK_ID' => $row['link_id']);
            $this->template->assign_block_vars('linkrow', $link_row);
        }
        $this->db->sql_freeresult($result);
        $option_ary = array('approved' => 'DIR_LINK_ACTIVATE', 'disapproved' => 'DIR_LINK_DELETE');
        $base_url = $this->u_action . "&amp;{$u_sort_param}&amp;links_per_page={$per_page}";
        $this->pagination->generate_template_pagination($base_url, 'pagination', 'start', $total_links, $per_page, $start);
        $this->template->assign_vars(array('S_LINKS_OPTIONS' => build_select($option_ary), 'S_LIMIT_DAYS' => $s_limit_days, 'S_SORT_KEY' => $s_sort_key, 'S_SORT_DIR' => $s_sort_dir, 'LINKS_PER_PAGE' => $per_page, 'U_ACTION' => $this->u_action . "&amp;{$u_sort_param}&amp;links_per_page={$per_page}&amp;start={$start}"));
    }
Beispiel #10
0
    public function view_versions($article)
    {
        if (!$this->auth->acl_get('u_wiki_versions')) {
            trigger_error('NOT_AUTHORISED');
        }
        $sql = 'SELECT *
			FROM ' . $this->article_table . '
			WHERE article_url = "' . $this->db->sql_escape($article) . '"
			ORDER BY article_last_edit DESC';
        $result = $this->db->sql_query_limit($sql, 1);
        $this->data = $this->db->sql_fetchrow($result);
        $this->db->sql_freeresult($result);
        $this->template->assign_vars(array('ARTICLE_TITLE' => $this->data['article_title'], 'S_SET_ACTIVE' => $this->auth->acl_get('u_wiki_set_active'), 'S_DELETE' => $this->auth->acl_get('m_wiki_delete'), 'S_DELETE_ARTICLE' => $this->auth->acl_get('m_wiki_delete_article'), 'U_ACTION' => $this->helper->route('tas2580_wiki_article', array('article' => $article, 'action' => 'compare')), 'U_DELETE_ARTICLE' => $this->helper->route('tas2580_wiki_article', array('article' => $article, 'action' => 'detele_article')), 'U_SET_INACTIV' => $this->helper->route('tas2580_wiki_article', array('article' => $article, 'action' => 'deactivate'))));
        if (!empty($article)) {
            $this->template->assign_block_vars('navlinks', array('FORUM_NAME' => $this->data['article_title'], 'U_VIEW_FORUM' => $this->helper->route('tas2580_wiki_article', array('article' => $article))));
        }
        $start = $this->request->variable('start', 0);
        $sql_array = array('SELECT' => 'a.article_id, a.article_title, a.article_last_edit, a.article_approved, a.article_edit_reason, u.user_id, u.username, u.user_colour', 'FROM' => array($this->article_table => 'a'), 'LEFT_JOIN' => array(array('FROM' => array(USERS_TABLE => 'u'), 'ON' => 'u.user_id = a.article_user_id')), 'WHERE' => 'article_url = "' . $this->db->sql_escape($article) . '"', 'ORDER_BY' => 'a.article_last_edit DESC');
        $sql = $this->db->sql_build_query('SELECT', $sql_array);
        $result = $this->db->sql_query_limit($sql, $this->config['topics_per_page'], $start);
        $result2 = $this->db->sql_query($sql);
        $row2 = $this->db->sql_fetchrowset($result2);
        $total_count = (int) sizeof($row2);
        $this->db->sql_freeresult($result2);
        unset($row2);
        $i = 1;
        $has_active_version = false;
        while ($this->data = $this->db->sql_fetchrow($result)) {
            if (!$has_active_version) {
                $has_active_version = $this->data['article_approved'] == 1 ? true : false;
            }
            $this->template->assign_block_vars('version_list', array('ID' => $this->data['article_id'], 'NR' => $i++, 'ARTICLE_TITLE' => $this->data['article_title'], 'EDIT_REASON' => $this->data['article_edit_reason'], 'S_ACTIVE' => $this->data['article_approved'] == 1 ? true : false, 'USER' => get_username_string('full', $this->data['user_id'], $this->data['username'], $this->data['user_colour']), 'EDIT_TIME' => $this->user->format_date($this->data['article_last_edit']), 'U_VERSION' => $this->helper->route('tas2580_wiki_article', array('id' => $this->data['article_id'])), 'U_DELETE' => $this->helper->route('tas2580_wiki_article', array('action' => 'delete', 'id' => $this->data['article_id'])), 'U_SET_ACTIVE' => $this->helper->route('tas2580_wiki_article', array('action' => 'active', 'id' => $this->data['article_id']))));
        }
        $this->db->sql_freeresult($result);
        // No active versions and no right to view inactive articles
        if (!$has_active_version && !$this->auth->acl_get('m_wiki_view_inactive')) {
            trigger_error('NOT_AUTHORISED');
        }
        $pagination_url = $this->helper->route('tas2580_wiki_article', array('article' => $article, 'action' => 'versions'));
        $start = $this->pagination->validate_start($start, $this->config['topics_per_page'], $total_count);
        $this->pagination->generate_template_pagination($pagination_url, 'pagination', 'start', $total_count, $this->config['topics_per_page'], $start);
        $this->template->assign_vars(array('TOTAL_ITEMS' => $this->user->lang('TOTAL_ITEMS', (int) $total_count)));
        return $this->helper->render('article_versions.html', $this->user->lang['VERSIONS_WIKI']);
    }
Beispiel #11
0
 private function show_reports($status)
 {
     global $request, $phpbb_root_path, $phpEx;
     global $template, $db, $user, $config, $action;
     $start = $request->variable('start', 0);
     switch ($action) {
         case 'close':
         case 'delete':
             $report_id_list = $request->variable('report_id_list', array(0));
             if (!sizeof($report_id_list)) {
                 trigger_error('NO_REPORT_SELECTED');
             }
             $this->manager->close_reports($report_id_list, $action);
             break;
     }
     $reports = $this->manager->get_reported_feedbacks($start, self::NUM_PER_PAGE, $status);
     $report_count = $this->manager->get_reports_count($status);
     if ($user->data['user_timezone']) {
         $timezone = new \DateTimeZone($user->data['user_timezone']);
     } else {
         $timezone = new \DateTimeZone($config['board_timezone']);
     }
     foreach ($reports as $key => $report) {
         $comments = $this->manager->getLatestFeedbackComment($report['feedback_id']);
         $report['short_comment'] = $comments['short_comment'];
         $report['long_comment'] = $comments['long_comment'];
         $report['to_username'] = $this->get_username_full($db, $report['to_user_id']);
         $report['from_username'] = $this->get_username_full($db, $report['from_user_id']);
         $report['f_date_created'] = new \DateTime('@' . $report['f_date_created']);
         $report['f_date_created']->setTimezone($timezone);
         $report['r_date_created'] = new \DateTime('@' . $report['r_date_created']);
         $report['r_date_created']->setTimezone($timezone);
         $report['U_VIEW_DETAILS'] = append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=' . $this->id . '&amp;mode=trader_report_details&amp;report_id=' . $report['report_id']);
         $reports[$key] = $report;
     }
     $template->assign_vars(array('REPORTS' => $reports, 'OPEN' => $status, 'S_CLOSED' => $status ? false : true));
     $base_url = append_sid("{$phpbb_root_path}mcp.{$phpEx}", "i={$this->id}&amp;mode=open_trader_reports");
     $this->pagination->generate_template_pagination($base_url, 'pagination', 'start', $report_count, self::NUM_PER_PAGE, $start);
     add_form_key('mcp_trader');
     $this->tpl_name = 'mcp_trader_reports';
 }
    /**
     * Display flag
     *
     * @param $flag_id		int		the id of the flag
     * @param $start		int		page number we start at
     * @param $limit		int		limit to display for pagination
     * @return null
     * @access public
     */
    protected function display_flag($flag_id, $start, $limit)
    {
        //let's get the flag requested
        $sql = 'SELECT flag_id, flag_name, flag_image
			FROM ' . $this->flags_table . '
			WHERE flag_id = ' . (int) $flag_id;
        $result = $this->db->sql_query($sql);
        $row = $this->db->sql_fetchrow($result);
        $this->db->sql_freeresult($result);
        // now users that have the flag
        $sql = 'SELECT *
			FROM ' . USERS_TABLE . '
			WHERE user_flag = ' . (int) $row['flag_id'] . '
				AND ' . $this->db->sql_in_set('user_type', array(USER_NORMAL, USER_FOUNDER)) . '
			ORDER BY username_clean';
        $result = $this->db->sql_query_limit($sql, $limit, $start);
        $rows = $this->db->sql_fetchrowset($result);
        $this->db->sql_freeresult($result);
        // for counting of total flag users
        $result = $this->db->sql_query($sql);
        $row2 = $this->db->sql_fetchrowset($result);
        $total_users = (int) count($row2);
        $this->db->sql_freeresult($result);
        unset($row2);
        foreach ($rows as $userrow) {
            $user_id = $userrow['user_id'];
            $username = $this->auth->acl_get('u_viewprofile') ? get_username_string('full', $user_id, $userrow['username'], $userrow['user_colour']) : get_username_string('no_profile', $user_id, $userrow['username'], $userrow['user_colour']);
            $this->template->assign_block_vars('user_row', array('JOINED' => $this->user->format_date($userrow['user_regdate']), 'VISITED' => empty($userrow['user_lastvisit']) ? ' - ' : $this->user->format_date($userrow['user_lastvisit']), 'POSTS' => $userrow['user_posts'] ? $userrow['user_posts'] : 0, 'USERNAME_FULL' => $username, 'U_SEARCH_USER' => $this->auth->acl_get('u_search') ? append_sid("{$this->root_path}search.{$this->php_ext}", "author_id={$user_id}&amp;sr=posts") : ''));
        }
        $this->pagination->generate_template_pagination(array('routes' => array('rmcgirr83_nationalflags_getflags', 'rmcgirr83_nationalflags_getflags_page'), 'params' => array('flag_id' => $flag_id)), 'pagination', 'page', $total_users, $limit, $start);
        $flag_image = $this->functions->get_user_flag($row['flag_id']);
        $users_count = $total_users;
        $total_users = $this->user->lang('FLAG_USERS', (int) $total_users);
        $this->template->assign_vars(array('FLAG' => html_entity_decode($row['flag_name']), 'FLAG_IMAGE' => $flag_image, 'TOTAL_USERS' => $total_users, 'S_VIEWONLINE' => $this->auth->acl_get('u_viewonline'), 'S_FLAGS' => true, 'S_FLAG_USERS' => !empty($users_count) ? true : false, 'MESSAGE_TEXT' => empty($users_count) ? $this->user->lang['NO_USER_HAS_FLAG'] : ''));
        // Assign breadcrumb template vars for the flags page
        $this->template->assign_block_vars('navlinks', array('U_VIEW_FORUM' => $this->helper->route('rmcgirr83_nationalflags_display'), 'FORUM_NAME' => $this->user->lang('NATIONAL_FLAGS')));
        // Assign breadcrumb template vars for the flags page
        $this->template->assign_block_vars('navlinks', array('U_VIEW_FORUM' => $this->helper->route('rmcgirr83_nationalflags_getflags', array('flag_id' => $flag_id)), 'FORUM_NAME' => $row['flag_name']));
    }
    public function handle_ultimatepoints_list()
    {
        // UPlist disabled
        if (!$this->config['points_enable']) {
            trigger_error($this->user->lang['POINTS_LIST_DISABLE'], E_USER_NOTICE);
        }
        // Get some values
        $sql_array = array('SELECT' => '*', 'FROM' => array($this->points_values_table => 'v'));
        $sql = $this->db->sql_build_query('SELECT', $sql_array);
        $result = $this->db->sql_query($sql);
        $points_values = $this->db->sql_fetchrow($result);
        $this->db->sql_freeresult($result);
        // Generate donors list
        $start = $this->request->variable('start', 0);
        $limit = $points_values['number_show_per_page'];
        $sql = 'SELECT *
			FROM ' . USERS_TABLE . '
			WHERE user_points > 0
			ORDER BY user_points DESC';
        $result = $this->db->sql_query_limit($sql, $limit, $start);
        while ($row = $this->db->sql_fetchrow($result)) {
            $this->template->assign_block_vars('ultimatelist', array('USERNAME' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'POINT' => sprintf($this->functions_points->number_format_points($row['user_points']))));
        }
        $this->db->sql_freeresult($result);
        // Generate pagination
        $sql = 'SELECT COUNT(user_points) AS ultimatepoints_total
			FROM ' . USERS_TABLE . '
			WHERE user_points > 0';
        $result = $this->db->sql_query($sql);
        $ultimatepoints_total = (int) $this->db->sql_fetchfield('ultimatepoints_total');
        //Start pagination
        $pagination_url = $this->helper->route('dmzx_ultimatepoints_list_controller');
        $this->pagination->generate_template_pagination($pagination_url, 'pagination', 'start', $ultimatepoints_total, $limit, $start);
        $this->template->assign_vars(array('TOTAL_ULTIMATEPOINTS_LIST' => $ultimatepoints_total == 1 ? $this->user->lang['POINTS_LIST_USER'] : sprintf($this->user->lang['POINTS_LIST_USERS'], $ultimatepoints_total), 'POINTSLIST' => $this->config['points_name']));
        // Output the page
        page_header($this->user->lang['POINTS_LIST_TOTAL']);
        $this->template->set_filenames(array('body' => 'points/points_list.html'));
        page_footer();
    }
Beispiel #14
0
 /**
  * Renders data for a page
  *
  * @param $page The page we are rendering for, one of index|custom|archive
  */
 protected function render_page($page)
 {
     // Add lang file
     $this->user->add_lang('posting');
     // If the static message is defined in the language file use it, else the entry in the database is used
     if (isset($this->user->lang['STATIC_MESSAGE'])) {
         $this->config['mchat_static_message'] = $this->user->lang('STATIC_MESSAGE');
     }
     $this->template->assign_vars(array('MCHAT_FILE_NAME' => $this->helper->route('dmzx_mchat_controller'), 'MCHAT_REFRESH_JS' => 1000 * $this->config['mchat_refresh'], 'MCHAT_INPUT_TYPE' => $this->user->data['user_mchat_input_area'], 'MCHAT_RULES' => !empty($this->user->lang['MCHAT_RULES']) || !empty($this->config['mchat_rules']), 'MCHAT_ALLOW_USE' => $this->auth->acl_get('u_mchat_use'), 'MCHAT_ALLOW_SMILES' => $this->config['allow_smilies'] && $this->auth->acl_get('u_mchat_smilies'), 'MCHAT_ALLOW_BBCODES' => $this->config['allow_bbcode'] && $this->auth->acl_get('u_mchat_bbcode'), 'MCHAT_MESSAGE_TOP' => $this->config['mchat_message_top'], 'MCHAT_ARCHIVE_URL' => $this->helper->route('dmzx_mchat_page_controller', array('page' => 'archive')), 'MCHAT_INDEX_HEIGHT' => $this->config['mchat_index_height'], 'MCHAT_CUSTOM_HEIGHT' => $this->config['mchat_custom_height'], 'MCHAT_READ_ARCHIVE_BUTTON' => $this->auth->acl_get('u_mchat_archive'), 'MCHAT_FOUNDER' => $this->user->data['user_type'] == USER_FOUNDER, 'MCHAT_STATIC_MESS' => !empty($this->config['mchat_static_message']) ? htmlspecialchars_decode($this->config['mchat_static_message']) : '', 'L_MCHAT_COPYRIGHT' => base64_decode('PGEgaHJlZj0iaHR0cHM6Ly9lbnRyb3B5LmZpL2tlc2t1c3RlbHUvbWVtYmVybGlzdC5waHA/bW9kZT12aWV3cHJvZmlsZSZ1PTI5MiI+VGhlSDwvYT4gJmNvcHk7IDxhIGhyZWY9Imh0dHA6Ly9ybWNnaXJyODMub3JnIj5STWNHaXJyODM8L2E+ICZjb3B5OyA8YSBocmVmPSJodHRwOi8vd3d3LmRtengtd2ViLm5ldCIgdGl0bGU9Ind3dy5kbXp4LXdlYi5uZXQiPmRteng8L2E+'), 'MCHAT_MESSAGE_LNGTH' => $this->config['mchat_max_message_lngth'], 'MCHAT_MESS_LONG' => sprintf($this->user->lang('MCHAT_MESS_LONG'), $this->config['mchat_max_message_lngth']), 'MCHAT_USER_TIMEOUT_TIME' => gmdate('H:i:s', (int) $this->config['mchat_timeout']), 'MCHAT_WHOIS_REFRESH' => $this->config['mchat_whois'] ? 1000 * $this->config['mchat_whois_refresh'] : 0, 'MCHAT_WHOIS_REFRESH_EXPLAIN' => sprintf($this->user->lang('WHO_IS_REFRESH_EXPLAIN'), $this->config['mchat_whois_refresh']), 'MCHAT_PAUSE_ON_INPUT' => $this->config['mchat_pause_on_input'], 'MCHAT_REFRESH_YES' => sprintf($this->user->lang('MCHAT_REFRESH_YES'), $this->config['mchat_refresh']), 'MCHAT_LIVE_UPDATES' => $this->config['mchat_live_updates'], 'S_MCHAT_LOCATION' => $this->config['mchat_location'], 'S_MCHAT_SOUND_YES' => $this->user->data['user_mchat_sound'], 'U_MORE_SMILIES' => generate_board_url() . append_sid("/{$this->root_path}/posting.{$this->php_ext}", 'mode=smilies'), 'U_MCHAT_RULES' => $this->helper->route('dmzx_mchat_page_controller', array('page' => 'rules')), 'S_MCHAT_ON_INDEX' => $this->config['mchat_on_index'] && !empty($this->user->data['user_mchat_index']), 'S_MCHAT_MOBILE_BEFORE' => $this->user->data['user_mchat_mobile_before'], 'S_MCHAT_TITLEFLASHDURATION' => $this->user->data['user_mchat_titleflash_duration'], 'S_MCHAT_FOLLOW' => $this->user->data['user_mchat_follow'], 'S_MCHAT_ON_VIEWTOPIC' => $this->config['mchat_on_viewtopic'], 'S_MCHAT_ON_VIEWFORUM' => $this->config['mchat_on_viewforum'], 'S_MCHAT_SIMPLE_MSG' => $this->config['mchat_simple_msg']));
     $sql_where = $this->user->data['user_mchat_topics'] ? '' : 'm.forum_id = 0';
     $limit = $page == 'archive' ? $this->config['mchat_archive_limit'] : $this->config[$page == 'index' ? 'mchat_message_num' : 'mchat_message_limit'];
     $start = $page == 'archive' ? $this->request->variable('start', 0) : 0;
     $rows = $this->functions_mchat->mchat_get_messages($sql_where, $limit, $start);
     $this->assign_global_template_data();
     $this->assign_messages($rows);
     // Render pagination
     if ($page == 'archive') {
         $archive_url = $this->helper->route('dmzx_mchat_page_controller', array('page' => 'archive'));
         $total_messages = $this->functions_mchat->mchat_total_message_count();
         $this->pagination->generate_template_pagination($archive_url, 'pagination', 'start', $total_messages, $limit, $start);
         $this->template->assign_var('MCHAT_TOTAL_MESSAGES', sprintf($this->user->lang('MCHAT_TOTALMESSAGES'), $total_messages));
     }
     // Render legend
     if ($page != 'index' && $this->config['mchat_whois']) {
         $legend = $this->functions_mchat->mchat_legend();
         $this->template->assign_var('LEGEND', implode(', ', $legend));
     }
     if ($this->auth->acl_get('u_mchat_use')) {
         add_form_key('mchat');
     }
     $this->is_mchat_rendered = true;
     /**
      * Event render_helper_aft
      *
      * @event dmzx.mchat.core.render_helper_aft
      * @since 0.1.2
      */
     $this->dispatcher->dispatch('dmzx.mchat.core.render_helper_aft');
 }
Beispiel #15
0
    /**
     * Display the search page
     *
     * @param type $start
     * @return type
     */
    public function search($start = 1)
    {
        if (!$this->auth->acl_get('u_usermap_search')) {
            trigger_error('NOT_AUTHORISED');
        }
        $this->template->assign_block_vars('navlinks', array('FORUM_NAME' => $this->user->lang('USERMAP_TITLE'), 'U_VIEW_FORUM' => $this->helper->route('tas2580_usermap_index', array())));
        $data = array('lon' => substr($this->request->variable('lon', ''), 0, 10), 'lat' => substr($this->request->variable('lat', ''), 0, 10), 'dst' => (int) $this->request->variable('dst', $this->config['tas2580_usermap_search_distance']));
        $validate_array = array('lon' => array('match', false, self::REGEX_LON), 'lat' => array('match', false, self::REGEX_LAT));
        if (!function_exists('validate_data')) {
            include $this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext;
        }
        $error = validate_data($data, $validate_array);
        if (sizeof($error)) {
            $error = array_map(array($this->user, 'lang'), $error);
            trigger_error(implode('<br>', $error) . '<br><br><a href="' . $this->helper->route('tas2580_usermap_index', array()) . '">' . $this->user->lang('BACK_TO_USERMAP') . '</a>');
        }
        $alpha = 180 * $data['dst'] / (6378137 / 1000 * 3.14159);
        $min_lon = (double) ($data['lon'] - $alpha);
        $max_lon = (double) ($data['lon'] + $alpha);
        $min_lat = (double) ($data['lat'] - $alpha);
        $max_lat = (double) ($data['lat'] + $alpha);
        $where = " WHERE ( user_usermap_lon * 1 >= {$min_lon} AND user_usermap_lon * 1 <= {$max_lon}) AND ( user_usermap_lat * 1 >= {$min_lat} AND user_usermap_lat * 1 <= {$max_lat})";
        $limit = (int) $this->config['topics_per_page'];
        $sql = 'SELECT COUNT(user_id) AS num_users
			FROM ' . USERS_TABLE . $where;
        $result = $this->db->sql_query($sql);
        $total_users = (int) $this->db->sql_fetchfield('num_users');
        $this->db->sql_freeresult($result);
        $sql = 'SELECT user_id, username, user_colour, user_regdate, user_posts, group_id, user_usermap_lon, user_usermap_lat
			FROM ' . USERS_TABLE . $where;
        $result = $this->db->sql_query_limit($sql, $limit, ($start - 1) * $limit);
        while ($row = $this->db->sql_fetchrow($result)) {
            $distance = $this->get_distance($data['lon'], $data['lat'], $row['user_usermap_lon'], $row['user_usermap_lat']);
            $this->template->assign_block_vars('memberrow', array('USER_ID' => $row['user_id'], 'USERNAME' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'JOINED' => $this->user->format_date($row['user_regdate']), 'POSTS' => $row['user_posts'], 'GROUP_ID' => $row['group_id'], 'DISTANCE' => $distance));
        }
        $this->pagination->generate_template_pagination(array('routes' => array('tas2580_usermap_search', 'tas2580_usermap_search_page'), 'params' => array()), 'pagination', 'start', $total_users, $limit, ($start - 1) * $limit);
        $this->template->assign_vars(array('TOTAL_USERS' => $this->user->lang('TOTAL_USERS', (int) $total_users), 'L_SEARCH_EXPLAIN' => $this->user->lang('SEARCH_EXPLAIN', $data['dst'], $data['lon'], $data['lat'])));
        return $this->helper->render('usermap_search.html', $this->user->lang('USERMAP_SEARCH'));
    }
    public function handle_video()
    {
        if (!$this->auth->acl_get('u_video_view_full')) {
            trigger_error($this->user->lang['UNAUTHED']);
        }
        // Initial var setup
        $video_id = $this->request->variable('id', 0);
        $video_url = $this->request->variable('video_url', '', true);
        $video_title = $this->request->variable('video_title', '', true);
        $video_cat_id = $this->request->variable('cid', 0);
        $video_cat_ids = $this->request->variable('id', 0);
        $username = $this->request->variable('username', '', true);
        $user_id = $this->request->variable('user_id', 0);
        $youtube_id = $this->request->variable('youtube_id', '', true);
        $create_time = $this->request->variable('create_time', '');
        $video_views = $this->request->variable('video_views', 0);
        $sql_start = $this->request->variable('start', 0);
        $sql_limit = $this->request->variable('limit', 10);
        $sql_limits = $this->request->variable('limit', $this->config['comments_per_page']);
        //comments
        // Comments
        $cmnt_id = $this->request->variable('cmntid', 0);
        $cmnt_video_id = $this->request->variable('v', 0);
        $cmnt_text = utf8_normalize_nfc($this->request->variable('cmnt_text', '', true));
        $mode = $this->request->variable('mode', '');
        $submit = isset($_POST['submit']) ? true : false;
        // Determine board url - we may need it later
        $board_url = generate_board_url() . '/';
        $web_path = defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH ? $board_url : $this->phpbb_root_path;
        if (!$this->config['google_api_key']) {
            if ($this->auth->acl_get('a_')) {
                trigger_error($this->user->lang['NO_KEY_ADMIN']);
            } else {
                trigger_error($this->user->lang['NO_KEY_USER']);
            }
        }
        /**
         * Get youtube video ID from URL
         * From: http://halgatewood.com/php-get-the-youtube-video-id-from-a-youtube-url/
         */
        function getYouTubeIdFromURL($url)
        {
            $pattern = '/(?:youtube\\.com\\/(?:[^\\/]+\\/.+\\/|(?:v|e(?:mbed)?)\\/|.*[?&]v=)|youtu\\.be\\/)([^"&?\\/ ]{11})/i';
            preg_match($pattern, $url, $matches);
            return isset($matches[1]) ? $matches[1] : false;
        }
        $youtube_id = getYouTubeIdFromURL($video_url);
        $jsonURL = file_get_contents("https://www.googleapis.com/youtube/v3/videos?id={$youtube_id}&key={$this->config['google_api_key']}&type=video&part=snippet");
        $json = json_decode($jsonURL);
        if (isset($json->items[0]->snippet)) {
            $video_title = $json->items[0]->snippet->title;
        }
        $sql_ary = array('video_id' => $video_id, 'video_url' => $video_url, 'video_title' => $video_title, 'video_cat_id' => $video_cat_id, 'username' => $username, 'user_id' => $user_id, 'youtube_id' => $youtube_id, 'create_time' => (int) time(), 'video_views' => $video_views);
        $error = $row = array();
        $current_time = time();
        $this->template->assign_vars(array('S_NEW_VIDEO' => $this->auth->acl_get('u_video_post') ? true : false, 'SCRIPT_NAME' => 'video', 'U_VIDEO' => $this->helper->route('dmzx_youtubegallery_controller')));
        $this->template->assign_block_vars('navlinks', array('FORUM_NAME' => $this->user->lang['VIDEO_INDEX'], 'U_VIEW_FORUM' => $this->helper->route('dmzx_youtubegallery_controller')));
        switch ($mode) {
            case 'submit':
                // User is a bot?!
                if ($this->user->data['is_bot']) {
                    redirect(append_sid("{$this->phpbb_root_path}index.{$this->phpEx}"));
                }
                $redirect_url = $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'submit'));
                // Is a guest?!
                if ($this->user->data['user_id'] == ANONYMOUS) {
                    login_box($redirect_url);
                }
                // Can post?!
                if (!$this->auth->acl_get('u_video_post')) {
                    trigger_error($this->user->lang['UNAUTHED']);
                }
                $l_title = $this->user->lang['VIDEO_SUBMIT'];
                $template_html = 'video_editor.html';
                $s_action = $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'submit'));
                $s_hidden_fields = '';
                $form_enctype = '';
                add_form_key('postform');
                // List of categories
                $sql = 'SELECT *
					FROM ' . $this->video_cat_table . '
					ORDER BY video_cat_id DESC';
                $result = $this->db->sql_query($sql);
                while ($row = $this->db->sql_fetchrow($result)) {
                    $this->template->assign_block_vars('cat', array('VIDEO_CAT_ID' => censor_text($row['video_cat_id']), 'VIDEO_CAT_TITLE' => censor_text($row['video_cat_title'])));
                }
                // Start assigning vars for main posting page ...
                $this->template->assign_vars(array('S_USER_ID' => $this->user->data['user_id'], 'S_USERNAME' => $this->user->data['username'], 'S_FORM_ENCTYPE' => $form_enctype, 'S_POST_ACTION' => $s_action, 'S_HIDDEN_FIELDS' => $s_hidden_fields, 'ERROR' => sizeof($error) ? implode('<br />', $error) : ''));
                $this->template->assign_block_vars('navlinks', array('FORUM_NAME' => $this->user->lang['VIDEO_SUBMIT']));
                add_form_key('postform');
                if ($submit) {
                    if (!check_form_key('postform')) {
                        trigger_error('FORM_INVALID');
                    }
                }
                switch ($submit) {
                    case 'add':
                        if ($video_url == '') {
                            $meta_info = $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'submit'));
                            $message = $this->user->lang['NEED_VIDEO_URL'];
                            meta_refresh(3, $meta_info);
                            $message .= '<br /><br />' . sprintf($this->user->lang['PAGE_RETURN'], '<a href="' . $meta_info . '">', '</a>');
                            trigger_error($message);
                        } else {
                            $this->db->sql_query('INSERT INTO ' . $this->video_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary));
                            $u_action = $this->helper->route('dmzx_youtubegallery_controller');
                            $meta_info = $this->helper->route('dmzx_youtubegallery_controller');
                            $message = $this->user->lang['VIDEO_CREATED'];
                            meta_refresh(3, $meta_info);
                            $message .= '<br /><br />' . sprintf($this->user->lang['PAGE_RETURN'], '<a href="' . $meta_info . '">', '</a>');
                            trigger_error($message);
                        }
                        break;
                }
                break;
            case 'comment':
                $l_title = $this->user->lang['VIDEO_CMNT_SUBMIT'];
                $template_html = '@dmzx_youtubegallery/video_cmnt_editor.html';
                if (!$this->config['enable_comments']) {
                    trigger_error($this->user->lang['COMMENTS_DISABLED']);
                }
                // User is a bot?!
                if ($this->user->data['is_bot']) {
                    redirect(append_sid("{$this->phpbb_root_path}index.{$this->phpEx}"));
                }
                // Can post?!
                if (!$this->auth->acl_get('u_video_comment')) {
                    trigger_error($this->user->lang['UNAUTHED']);
                }
                $redirect_url = $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'comment', 'v' => (int) $video_id));
                // Is a guest?!
                if ($this->user->data['user_id'] == ANONYMOUS) {
                    login_box($redirect_url);
                }
                if (!function_exists('generate_smilies')) {
                    include $this->phpbb_root_path . 'includes/functions_posting.' . $this->phpEx;
                }
                if (!function_exists('display_custom_bbcodes')) {
                    include $this->phpbb_root_path . 'includes/functions_display.' . $this->phpEx;
                }
                //Settings for comments
                $this->user->setup('posting');
                display_custom_bbcodes();
                generate_smilies('inline', 0);
                $bbcode_status = $this->config['allow_bbcode'] ? true : false;
                $smilies_status = $this->config['allow_smilies'] ? true : false;
                $img_status = $bbcode_status ? true : false;
                $url_status = $this->config['allow_post_links'] ? true : false;
                $flash_status = $bbcode_status && $this->config['allow_post_flash'] ? true : false;
                $quote_status = true;
                $video_id = $this->request->variable('v', 0);
                $uid = $bitfield = $options = '';
                $allow_bbcode = $allow_urls = $allow_smilies = true;
                $s_action = $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'comment', 'v' => (int) $video_id));
                $s_hidden_fields = '';
                $form_enctype = '';
                add_form_key('postform');
                // Start assigning vars for main posting page ...
                $this->template->assign_vars(array('VIDEO_ID' => (int) $video_id, 'S_FORM_ENCTYPE' => $form_enctype, 'S_POST_ACTION' => $s_action, 'S_HIDDEN_FIELDS' => $s_hidden_fields, 'ERROR' => sizeof($error) ? implode('<br />', $error) : '', 'S_BBCODE_ALLOWED' => $bbcode_status ? 1 : 0, 'S_SMILIES_ALLOWED' => $smilies_status, 'S_BBCODE_IMG' => $img_status, 'S_BBCODE_URL' => $url_status, 'S_LINKS_ALLOWED' => $url_status, 'S_BBCODE_QUOTE' => $quote_status));
                if (isset($_POST['submit'])) {
                    if (!check_form_key('postform')) {
                        trigger_error('FORM_INVALID');
                    }
                    $video_id = $this->request->variable('v', 0);
                    // Get video to redirect :D
                    $message = $this->request->variable('cmnt_text', '', true);
                    generate_text_for_storage($message, $uid, $bitfield, $options, $allow_bbcode, $allow_urls, $allow_smilies);
                    $data = array('cmnt_video_id' => $this->request->variable('cmnt_video_id', 0), 'cmnt_poster_id' => $this->user->data['user_id'], 'cmnt_text' => $message, 'create_time' => time(), 'bbcode_uid' => $uid, 'bbcode_bitfield' => $bitfield, 'bbcode_options' => $options);
                    if ($message == '') {
                        $meta_info = $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'comment', 'v' => (int) $video_id));
                        $message = $this->user->lang['NEED_VIDEO_MESSAGE'];
                        meta_refresh(3, $meta_info);
                        $message .= '<br /><br />' . sprintf($this->user->lang['PAGE_RETURN'], '<a href="' . $meta_info . '">', '</a>');
                        trigger_error($message);
                    } else {
                        $this->db->sql_query('INSERT INTO ' . $this->video_cmnts_table . ' ' . $this->db->sql_build_array('INSERT', $data));
                        $meta_info = $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'view', 'id' => (int) $video_id));
                        $message = $this->user->lang['COMMENT_CREATED'];
                        meta_refresh(3, $meta_info);
                        $message .= '<br /><br />' . sprintf($this->user->lang['PAGE_RETURN'], '<a href="' . $meta_info . '">', '</a>');
                        trigger_error($message);
                    }
                }
                $this->template->assign_block_vars('navlinks', array('FORUM_NAME' => $this->user->lang['VIDEO_CMNT_SUBMIT']));
                break;
            case 'delcmnt':
                if (!$this->auth->acl_get('u_video_comment_delete')) {
                    trigger_error($this->user->lang['UNAUTHED']);
                }
                $video_id = $this->request->variable('v', 0);
                // Get video to redirect :D
                if (confirm_box(true)) {
                    $sql = 'DELETE FROM ' . $this->video_cmnts_table . '
						WHERE cmnt_id = ' . (int) $cmnt_id;
                    $this->db->sql_query($sql);
                    $meta_info = $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'view', 'id' => (int) $video_id));
                    $message = $this->user->lang['COMMENT_DELETED_SUCCESS'];
                    meta_refresh(1, $meta_info);
                    $message .= '<br /><br />' . sprintf($this->user->lang['PAGE_RETURN'], '<a href="' . $meta_info . '">', '</a>');
                    trigger_error($message);
                } else {
                    $s_hidden_fields = build_hidden_fields(array('id' => $cmnt_id, 'mode' => 'delcmnt'));
                    confirm_box(false, $this->user->lang['DELETE_COMMENT_CONFIRM'], $s_hidden_fields);
                    $meta_info = $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'view', 'id' => (int) $video_id));
                    meta_refresh(1, $meta_info);
                }
                break;
            case 'delete':
                if (!$this->auth->acl_get('u_video_delete')) {
                    trigger_error($this->user->lang['UNAUTHED']);
                }
                $l_title = $this->user->lang['DELETE_VIDEO'];
                if (confirm_box(true)) {
                    $sql = 'DELETE FROM ' . $this->video_table . '
						WHERE video_id = ' . $video_id;
                    $this->db->sql_query($sql);
                    $meta_info = $this->helper->route('dmzx_youtubegallery_controller');
                    $message = $this->user->lang['VIDEO_DELETED'];
                    meta_refresh(3, $meta_info);
                    $message .= '<br /><br />' . sprintf($this->user->lang['PAGE_RETURN'], '<a href="' . $meta_info . '">', '</a>');
                    trigger_error($message);
                } else {
                    $s_hidden_fields = build_hidden_fields(array('mode' => 'delete', 'submit' => true, 'video_id' => $video_id));
                    confirm_box(false, $this->user->lang['DELETE_VIDEO'], $s_hidden_fields);
                    $meta_info = $this->helper->route('dmzx_youtubegallery_controller');
                    $message = $this->user->lang['RETURN_TO_VIDEO_INDEX'];
                    meta_refresh(3, $meta_info);
                    $message .= '<br /><br />' . sprintf($this->user->lang['PAGE_RETURN'], '<a href="' . $meta_info . '">', '</a>');
                    trigger_error($message);
                }
                break;
            case 'view':
                if (!$this->auth->acl_get('u_video_view')) {
                    trigger_error($this->user->lang['VIDEO_UNAUTHED']);
                }
                // Update video view... but only for humans
                if (isset($this->user->data['session_page']) && !$this->user->data['is_bot']) {
                    $sql = 'UPDATE ' . $this->video_table . '
					SET video_views = video_views + 1
					WHERE video_id = ' . $video_id;
                    $this->db->sql_query($sql);
                }
                $sql_ary = array('SELECT' => 'v.*, u.*', 'FROM' => array($this->video_table => 'v', USERS_TABLE => 'u'), 'WHERE' => 'v.video_id = ' . (int) $video_id . ' and u.user_id = v.user_id', 'ORDER_BY' => 'v.video_id DESC');
                $sql = $this->db->sql_build_query('SELECT', $sql_ary);
                $result = $this->db->sql_query($sql);
                $row = $this->db->sql_fetchrow($result);
                $this->db->sql_freeresult($result);
                $page_title = $row['video_title'];
                $user_id = $row['user_id'];
                $flash_status = $this->config['allow_post_flash'] ? true : false;
                $delete_allowed = ($this->auth->acl_get('a_') or $this->auth->acl_get('m_') || $this->user->data['is_registered'] && $this->user->data['user_id'] == $row['user_id'] && $this->auth->acl_get('u_video_delete'));
                $this->template->assign_vars(array('VIDEO_ID' => censor_text($row['video_id']), 'VIDEO_TITLE' => censor_text($row['video_title']), 'VIDEO_VIEWS' => $row['video_views'], 'USERNAME' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'YOUTUBE_ID' => censor_text($row['youtube_id']), 'VIDEO_TIME' => $this->user->format_date($row['create_time']), 'YOUTUBE_VIDEO' => 'http://www.youtube.com/watch?v=' . $row['youtube_id'], 'VIDEO_LINK' => generate_board_url() . $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'view', 'id' => $row['video_id'])), 'VIDEO_LINK_FLASH' => 'http://www.youtube.com/v/' . $row['youtube_id'], 'U_USER_VIDEOS' => $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'user_videos', 'user_id' => $this->user->data['user_id'])), 'U_DELETE' => $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'delete', 'id' => $row['video_id'])), 'DELETE_ALLOW' => $delete_allowed, 'S_BBCODE_FLASH' => $flash_status, 'FLASH_STATUS' => $flash_status ? $this->user->lang['FLASH_IS_ON'] : $this->user->lang['FLASH_IS_OFF'], 'S_VIDEO_WIDTH' => $this->config['video_width'], 'S_VIDEO_HEIGHT' => $this->config['video_height'], 'U_POST_COMMENT' => $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'comment', 'v' => $row['video_id'])), 'S_ENABLE_COMMENTS' => $this->config['enable_comments'], 'S_POST_COMMENT' => $this->auth->acl_get('u_video_comment')));
                // Comments
                $pagination_url = $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'view', 'id' => $video_id));
                $sql_ary = array('SELECT' => 'v.*, cmnt.*, u.username,u.user_colour,u.user_id', 'FROM' => array($this->video_table => 'v', $this->video_cmnts_table => 'cmnt', USERS_TABLE => 'u'), 'WHERE' => 'v.video_id = ' . (int) $video_id . '
						AND cmnt.cmnt_video_id = v.video_id
						AND u.user_id = cmnt.cmnt_poster_id', 'ORDER_BY' => 'cmnt.cmnt_id DESC');
                $sql = $this->db->sql_build_query('SELECT', $sql_ary);
                $result = $this->db->sql_query_limit($sql, $sql_limits, $sql_start);
                while ($row = $this->db->sql_fetchrow($result)) {
                    $delete_cmnt_allowed = ($this->auth->acl_get('a_') or $this->auth->acl_get('m_') || $this->user->data['is_registered'] && $this->user->data['user_id'] == $row['user_id'] && $this->auth->acl_get('u_video_comment_delete'));
                    $text = generate_text_for_display($row['cmnt_text'], $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options']);
                    $this->template->assign_block_vars('commentrow', array('COMMENT_ID' => $row['cmnt_id'], 'COMMENT_TEXT' => $text, 'COMMENT_TIME' => $this->user->format_date($row['create_time']), 'USERNAME' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'S_DELETE_ALLOWED' => $delete_cmnt_allowed, 'U_DELETE' => $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'delcmnt', 'cmntid' => (int) $row['cmnt_id'], 'v' => (int) $row['cmnt_video_id']))));
                }
                $this->db->sql_freeresult($result);
                // We need another query for the video count
                $sql = 'SELECT COUNT(*) as comment_count
				FROM ' . $this->video_cmnts_table . '
				WHERE cmnt_video_id = ' . (int) $video_id;
                $result = $this->db->sql_query($sql);
                $videorow['comment_count'] = $this->db->sql_fetchfield('comment_count');
                $this->db->sql_freeresult($result);
                //Start pagination
                $start = $this->request->variable('start', 0);
                $this->pagination->generate_template_pagination($pagination_url, 'pagination', 'start', $videorow['comment_count'], $sql_limits, $sql_start);
                $this->template->assign_vars(array('TOTAL_COMMENTS' => $videorow['comment_count'] == 1 ? $this->user->lang['LIST_COMMENT'] : sprintf($this->user->lang['LIST_COMMENTS'], $videorow['comment_count'])));
                //End pagination
                // Count the videos user video ...
                $sql = 'SELECT COUNT(video_id) AS total_videos
				FROM ' . $this->video_table . '
				WHERE user_id = ' . (int) $user_id;
                $result = $this->db->sql_query($sql);
                $total_videos = (int) $this->db->sql_fetchfield('total_videos');
                $this->db->sql_freeresult($result);
                $this->template->assign_vars(array('TOTAL_VIDEOS' => $total_videos));
                // Count the video comments ...
                $sql_cmnts = 'SELECT COUNT(cmnt_id) AS total_comments
				FROM ' . $this->video_cmnts_table . '
				WHERE cmnt_video_id = ' . (int) $video_id;
                $result = $this->db->sql_query($sql_cmnts);
                $total_comments = (int) $this->db->sql_fetchfield('total_comments');
                $this->db->sql_freeresult($result);
                $this->template->assign_vars(array('TOTAL_COMMENTS_TITLE' => $total_comments));
                $l_title = $page_title;
                $template_html = 'video_view.html';
                $this->template->assign_block_vars('navlinks', array('FORUM_NAME' => $page_title));
                break;
            case 'cat':
                $sql_limit = $sql_limit > 10 ? 10 : $sql_limit;
                $pagination_url = $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'cat', 'id' => $video_cat_ids));
                $sql_ary = array('SELECT' => 'v.*,
				ct.video_cat_title,ct.video_cat_id,
				u.username,u.user_colour,u.user_id', 'FROM' => array($this->video_table => 'v', $this->video_cat_table => 'ct', USERS_TABLE => 'u'), 'WHERE' => 'v.video_cat_id = ' . $video_cat_ids . '
					AND ct.video_cat_id = ' . $video_cat_ids . '
					AND v.user_id = u.user_id', 'ORDER_BY' => 'v.video_id DESC');
                $sql = $this->db->sql_build_query('SELECT', $sql_ary);
                $result = $this->db->sql_query_limit($sql, $sql_limit, $sql_start);
                while ($row = $this->db->sql_fetchrow($result)) {
                    $this->template->assign_block_vars('video', array('VIDEO_TITLE' => $row['video_title'], 'VIDEO_CAT_ID' => $row['video_cat_id'], 'VIDEO_CAT_TITLE' => $row['video_cat_title'], 'VIDEO_VIEWS' => $row['video_views'], 'U_CAT' => $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'cat', 'id' => $row['video_cat_id'])), 'VIDEO_TIME' => $this->user->format_date($row['create_time']), 'VIDEO_ID' => censor_text($row['video_id']), 'U_VIEW_VIDEO' => $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'view', 'id' => $row['video_id'])), 'U_POSTER' => append_sid("{$this->phpbb_root_path}memberlist.{$this->phpEx}", array('mode' => 'viewprofile', 'u' => $row['user_id'])), 'USERNAME' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'S_VIDEO_THUMBNAIL' => 'http://img.youtube.com/vi/' . censor_text($row['youtube_id']) . '/default.jpg'));
                }
                $this->db->sql_freeresult($result);
                // We need another query for the video count
                $sql = 'SELECT COUNT(*) as video_count
				FROM ' . $this->video_table . '
				WHERE video_cat_id = ' . (int) $video_cat_ids;
                $result = $this->db->sql_query($sql);
                $videorow['video_count'] = $this->db->sql_fetchfield('video_count');
                $this->db->sql_freeresult($result);
                $start = $this->request->variable('start', 0);
                $this->pagination->generate_template_pagination($pagination_url, 'pagination', 'start', $videorow['video_count'], $sql_limit, $sql_start);
                $this->template->assign_vars(array('TOTAL_VIDEOS' => $videorow['video_count'] == 1 ? $this->user->lang['LIST_VIDEO'] : sprintf($this->user->lang['LIST_VIDEOS'], $videorow['video_count'])));
                $sql = 'SELECT *
				FROM ' . $this->video_cat_table . '
				WHERE video_cat_id = ' . (int) $video_cat_ids;
                $result = $this->db->sql_query($sql);
                $row = $this->db->sql_fetchrow($result);
                $this->db->sql_freeresult($result);
                $this->template->assign_vars(array('CAT_NAME' => $row['video_cat_title']));
                $l_title = $row['video_cat_title'];
                $template_html = 'video_cat.html';
                $this->template->assign_block_vars('navlinks', array('FORUM_NAME' => $row['video_cat_title']));
                break;
            case 'user_videos':
                $this->template->assign_vars(array('S_SEARCH_USER_VIDEO' => true));
                $sql_limit = $sql_limit > 10 ? 10 : $sql_limit;
                $pagination_url = $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'user_videos', 'user_id' => $user_id));
                $sql_ary = array('SELECT' => 'v.*,
				ct.video_cat_title,ct.video_cat_id,
				u.username,u.user_colour,u.user_id', 'FROM' => array($this->video_table => 'v', $this->video_cat_table => 'ct', USERS_TABLE => 'u'), 'WHERE' => 'u.user_id = v.user_id
					AND ct.video_cat_id = v.video_cat_id
					AND u.user_id = ' . $user_id, 'ORDER_BY' => 'v.video_id DESC');
                $sql = $this->db->sql_build_query('SELECT', $sql_ary);
                $result = $this->db->sql_query_limit($sql, $sql_limit, $sql_start);
                while ($row = $this->db->sql_fetchrow($result)) {
                    $this->template->assign_block_vars('video', array('VIDEO_TITLE' => $row['video_title'], 'VIDEO_CAT_ID' => $row['video_cat_id'], 'VIDEO_CAT_TITLE' => $row['video_cat_title'], 'VIDEO_VIEWS' => $row['video_views'], 'U_CAT' => $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'cat', 'id' => $row['video_cat_id'])), 'VIDEO_TIME' => $this->user->format_date($row['create_time']), 'VIDEO_ID' => censor_text($row['video_id']), 'U_VIEW_VIDEO' => $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'view', 'id' => $row['video_id'])), 'U_POSTER' => append_sid("{$this->phpbb_root_path}memberlist.{$this->phpEx}", array('mode' => 'viewprofile', 'u' => $row['user_id'])), 'USERNAME' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'S_VIDEO_THUMBNAIL' => 'http://img.youtube.com/vi/' . censor_text($row['youtube_id']) . '/default.jpg'));
                }
                $this->db->sql_freeresult($result);
                // We need another query for the video count
                $sql = 'SELECT COUNT(*) as video_count
				FROM ' . $this->video_table . '
				WHERE user_id = ' . $user_id;
                $result = $this->db->sql_query($sql);
                $videorow['video_count'] = $this->db->sql_fetchfield('video_count');
                $this->db->sql_freeresult($result);
                $start = $this->request->variable('start', 0);
                $this->pagination->generate_template_pagination($pagination_url, 'pagination', 'start', $videorow['video_count'], $sql_limit, $sql_start);
                $this->template->assign_vars(array('TOTAL_VIDEOS' => $videorow['video_count'] == 1 ? $this->user->lang['LIST_VIDEO'] : sprintf($this->user->lang['LIST_VIDEOS'], $videorow['video_count'])));
                $l_title = $this->user->lang['USER_VIDEOS'];
                $template_html = 'video_search.html';
                break;
            default:
                //Listing categories
                $sql = 'SELECT *
				FROM ' . $this->video_cat_table . "\n\t\t\t\tORDER BY video_cat_id";
                $res = $this->db->sql_query($sql);
                while ($row = $this->db->sql_fetchrow($res)) {
                    $this->template->assign_block_vars('videocat', array('VIDEO_CAT_ID' => $row['video_cat_id'], 'VIDEO_CAT_TITLE' => $row['video_cat_title'], 'U_CAT' => $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'cat', 'id' => $row['video_cat_id']))));
                }
                // Count the videos ...
                $sql = 'SELECT COUNT(video_id) AS total_videos
				FROM ' . $this->video_table;
                $result = $this->db->sql_query($sql);
                $total_videos = (int) $this->db->sql_fetchfield('total_videos');
                $this->db->sql_freeresult($result);
                // Count the videos categories ...
                $sql = 'SELECT COUNT(video_cat_id) AS total_categories
				FROM ' . $this->video_cat_table . '';
                $result = $this->db->sql_query($sql);
                $total_categories = (int) $this->db->sql_fetchfield('total_categories');
                $this->db->sql_freeresult($result);
                // Count the videos views ...
                $sql = 'SELECT SUM(video_views) AS total_views
				FROM ' . $this->video_table;
                $result = $this->db->sql_query($sql);
                $total_views = (int) $this->db->sql_fetchfield('total_views');
                $this->db->sql_freeresult($result);
                $total_videos;
                // Count the videos comments ...
                $sql = 'SELECT COUNT(cmnt_id) AS total_comments
				FROM ' . $this->video_cmnts_table;
                $result = $this->db->sql_query($sql);
                $total_comments = (int) $this->db->sql_fetchfield('total_comments');
                $this->db->sql_freeresult($result);
                $l_title = $this->user->lang['VIDEO_INDEX'];
                $template_html = 'video_body.html';
                $l_total_video_s = $total_videos == 0 ? 'TOTAL_VIDEO_ZERO' : 'TOTAL_VIDEOS_OTHER';
                $l_total_category_s = $total_categories == 0 ? 'TOTAL_CATEGORY_ZERO' : 'TOTAL_CATEGORIES_OTHER';
                $l_total_view_s = $total_views == 0 ? 'TOTAL_VIEW_ZERO' : 'TOTAL_VIEWS_OTHER';
                $l_total_comment_s = $total_comments == 0 ? 'TOTAL_COMMENT_ZERO' : 'TOTAL_COMMENTS_OTHER';
                $this->template->assign_vars(array('U_VIDEO_SUBMIT' => $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'submit')), 'VIDEOSUBMIT' => $this->auth->acl_get('u_video_post'), 'U_MY_VIDEOS' => $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'user_videos', 'user_id' => $this->user->data['user_id'])), 'BUTTON_VIDEO_NEW' => "{$web_path}styles/" . $this->user->lang_name . '/button_video_new.gif', 'TOTAL_VIDEOS_INDEX' => sprintf($this->user->lang[$l_total_video_s], $total_videos), 'TOTAL_CATEGORIES' => sprintf($this->user->lang[$l_total_category_s], $total_categories), 'TOTAL_VIEWS' => sprintf($this->user->lang[$l_total_view_s], $total_views), 'TOTAL_COMMENTS' => sprintf($this->user->lang[$l_total_comment_s], $total_comments)));
                $sql_limit = $sql_limit > 10 ? 10 : $sql_limit;
                $pagination_url = $this->helper->route('dmzx_youtubegallery_controller');
                $sql_ary = array('SELECT' => 'v.*,
				ct.video_cat_title,ct.video_cat_id,
				u.username,u.user_colour,u.user_id', 'FROM' => array($this->video_table => 'v', $this->video_cat_table => 'ct', USERS_TABLE => 'u'), 'WHERE' => 'ct.video_cat_id = v.video_cat_id AND u.user_id = v.user_id', 'ORDER_BY' => 'v.video_id DESC');
                $sql = $this->db->sql_build_query('SELECT', $sql_ary);
                $result = $this->db->sql_query_limit($sql, $sql_limit, $sql_start);
                while ($row = $this->db->sql_fetchrow($result)) {
                    $this->template->assign_block_vars('video', array('VIDEO_TITLE' => $row['video_title'], 'VIDEO_CAT_ID' => $row['video_cat_id'], 'VIDEO_CAT_TITLE' => $row['video_cat_title'], 'VIDEO_VIEWS' => $row['video_views'], 'U_CAT' => $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'cat', 'id' => $row['video_cat_id'])), 'VIDEO_TIME' => $this->user->format_date($row['create_time']), 'VIDEO_ID' => censor_text($row['video_id']), 'U_VIEW_VIDEO' => $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'view', 'id' => $row['video_id'])), 'U_POSTER' => append_sid("{$this->phpbb_root_path}memberlist.{$this->phpEx}", array('mode' => 'viewprofile', 'u' => $row['user_id'])), 'USERNAME' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'YOUTUBE_ID' => censor_text($row['youtube_id'])));
                }
                $this->db->sql_freeresult($result);
                // We need another query for the video count
                $sql = 'SELECT COUNT(*) as video_count
				FROM ' . $this->video_table;
                $result = $this->db->sql_query($sql);
                $videorow['video_count'] = $this->db->sql_fetchfield('video_count');
                $this->db->sql_freeresult($result);
                $start = $this->request->variable('start', 0);
                $this->pagination->generate_template_pagination($pagination_url, 'pagination', 'start', $videorow['video_count'], $sql_limit, $sql_start);
                $this->template->assign_vars(array('TOTAL_VIDEOS' => $videorow['video_count'] == 1 ? $this->user->lang['LIST_VIDEO'] : sprintf($this->user->lang['LIST_VIDEOS'], $videorow['video_count'])));
                break;
        }
        if (!$row) {
            $this->template->assign_vars(array('NO_ENTRY' => $this->user->lang['NO_VIDEOS']));
        }
        // Output page
        page_header($l_title, false);
        $this->template->set_filenames(array('body' => $template_html));
        make_jumpbox(append_sid("{$this->phpbb_root_path}viewforum.{$this->phpEx}"));
        page_footer();
    }
    function main($checked_user)
    {
        // Get all values
        $sql = 'SELECT *
				FROM ' . $this->points_values_table;
        $result = $this->db->sql_query($sql);
        $points_values = $this->db->sql_fetchrow($result);
        $this->db->sql_freeresult($result);
        // Check if user is allowed to use the logs
        if (!$this->auth->acl_get('u_use_logs')) {
            $message = $this->user->lang['NOT_AUTHORISED'] . '<br /><br /><a href="' . append_sid("{$this->phpbb_root_path}ultimatepoints") . '">&laquo; ' . $this->user->lang['BACK_TO_PREV'] . '</a>';
            trigger_error($message);
        }
        // Add part to bar
        $this->template->assign_block_vars('navlinks', array('U_VIEW_FORUM' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'logs')), 'FORUM_NAME' => sprintf($this->user->lang['LOGS_TITLE'], $this->config['points_name'])));
        // Preparing the sort order
        $start = $this->request->variable('start', 0);
        $number = $points_values['number_show_per_page'];
        $sort_days = $this->request->variable('st', 0);
        $sort_key = $this->request->variable('sk', 'date');
        $sort_dir = $this->request->variable('sd', 'd');
        $limit_days = array(0 => $this->user->lang['ALL_POSTS'], 1 => $this->user->lang['1_DAY'], 7 => $this->user->lang['7_DAYS'], 14 => $this->user->lang['2_WEEKS'], 30 => $this->user->lang['1_MONTH'], 90 => $this->user->lang['3_MONTHS'], 180 => $this->user->lang['6_MONTHS'], 365 => $this->user->lang['1_YEAR']);
        $sort_by_text = array('date' => $this->user->lang['LOGS_SORT_DATE'], 'to' => $this->user->lang['LOGS_SORT_TONAME'], 'from' => $this->user->lang['LOGS_SORT_FROMNAME'], 'comment' => $this->user->lang['LOGS_SORT_COMMENT']);
        $sort_by_sql = array('date' => 'point_date', 'to' => 'point_recv', 'from' => 'point_send', 'comment' => 'point_comment');
        $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
        gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
        $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . ($sort_dir == 'd' ? 'DESC' : 'ASC');
        // The different log types
        $types = array(0 => '--', 1 => $this->user->lang['LOGS_RECV'], 2 => $this->user->lang['LOGS_SENT'], 3 => $this->user->lang['LOGS_ROBBERY_WON'], 4 => $this->user->lang['LOGS_ROBBERY_LOST']);
        // Grab the total amount of logs for this user
        $sql_array = array('SELECT' => 'COUNT(*) AS total', 'FROM' => array($this->points_log_table => 'l'), 'WHERE' => 'point_send = ' . (int) $this->user->data['user_id'] . '
				OR point_recv = ' . (int) $this->user->data['user_id']);
        $sql = $this->db->sql_build_query('SELECT', $sql_array);
        $result = $this->db->sql_query($sql);
        $max = (int) $this->db->sql_fetchfield('total');
        // Grab the actual logs based on all account movements
        $sql_array = array('SELECT' => '*', 'FROM' => array($this->points_log_table => 'l'), 'WHERE' => 'point_send = ' . (int) $this->user->data['user_id'] . '
				OR point_recv = ' . (int) $this->user->data['user_id'], 'ORDER_BY' => $sql_sort_order);
        $sql = $this->db->sql_build_query('SELECT', $sql_array);
        $result = $this->db->sql_query_limit($sql, $number, $start);
        // Start looping all the logs
        while ($row = $this->db->sql_fetchrow($result)) {
            switch ($row['point_type']) {
                case 1:
                    //Transfer
                    $transfer_user = $row['point_send'] == $checked_user['user_id'] ? $row['point_recv'] : $row['point_send'];
                    $sql_array = array('SELECT' => '*', 'FROM' => array(USERS_TABLE => 'u'), 'WHERE' => 'user_id = ' . (int) $transfer_user);
                    $sql = $this->db->sql_build_query('SELECT', $sql_array);
                    $result1 = $this->db->sql_query($sql);
                    $opponent = $this->db->sql_fetchrow($result1);
                    $this->db->sql_freeresult($result1);
                    if ($row['point_send'] == $checked_user['user_id']) {
                        $who = get_username_string('full', $checked_user['user_id'], $checked_user['username'], $checked_user['user_colour']) . "<br />(" . $this->functions_points->number_format_points($row['point_sendold']) . "->" . $this->functions_points->number_format_points($row['point_sendold'] - $row['point_amount']) . ")";
                        $to = get_username_string('full', $opponent['user_id'], $opponent['username'], $opponent['user_colour']) . "<br />(" . $this->functions_points->number_format_points($row['point_recvold']) . "->" . $this->functions_points->number_format_points($row['point_recvold'] + (100 - $points_values['transfer_fee']) / 100 * $row['point_amount']) . ")";
                        $rows = 2;
                    } else {
                        $to = get_username_string('full', $checked_user['user_id'], $checked_user['username'], $checked_user['user_colour']) . "<br />(" . $this->functions_points->number_format_points($row['point_recvold']) . "->" . $this->functions_points->number_format_points($row['point_recvold'] + (100 - $points_values['transfer_fee']) / 100 * $row['point_amount']) . ")";
                        $who = get_username_string('full', $opponent['user_id'], $opponent['username'], $opponent['user_colour']) . "<br />(" . $this->functions_points->number_format_points($row['point_sendold']) . "->" . $this->functions_points->number_format_points($row['point_sendold'] - $row['point_amount']) . ")";
                        $rows = 1;
                    }
                    $who .= " (-" . $this->functions_points->number_format_points($row['point_amount']) . ")";
                    $to .= " (+" . $this->functions_points->number_format_points((100 - $points_values['transfer_fee']) / 100 * $row['point_amount']) . ")";
                    break;
                case 2:
                    //Locked
                    $who = get_username_string('full', $opponent['user_id'], $opponent['username'], $opponent['user_colour']);
                    $to = "--";
                    break;
                case 3:
                    //Robbery
                    $transfer_user = $row['point_send'] == $checked_user['user_id'] ? $row['point_recv'] : $row['point_send'];
                    $sql_array = array('SELECT' => '*', 'FROM' => array(USERS_TABLE => 'u'), 'WHERE' => 'user_id = ' . (int) $transfer_user);
                    $sql = $this->db->sql_build_query('SELECT', $sql_array);
                    $result1 = $this->db->sql_query($sql);
                    $opponent = $this->db->sql_fetchrow($result1);
                    $this->db->sql_freeresult($result1);
                    if ($row['point_send'] == $checked_user['user_id']) {
                        $who = get_username_string('full', $checked_user['user_id'], $checked_user['username'], $checked_user['user_colour']) . "<br />(" . $this->functions_points->number_format_points($row['point_sendold']) . "->" . $this->functions_points->number_format_points($row['point_sendold'] + $row['point_amount']) . ")";
                        $to = get_username_string('full', $opponent['user_id'], $opponent['username'], $opponent['user_colour']) . "<br />(" . $this->functions_points->number_format_points($row['point_recvold']) . "->" . $this->functions_points->number_format_points($row['point_recvold'] - $row['point_amount']) . ")";
                        $rows = 3;
                    } else {
                        $to = get_username_string('full', $checked_user['user_id'], $checked_user['username'], $checked_user['user_colour']) . "<br />(" . $this->functions_points->number_format_points($row['point_recvold']) . "->" . $this->functions_points->number_format_points($row['point_recvold'] - $row['point_amount']) . ")";
                        $who = get_username_string('full', $opponent['user_id'], $opponent['username'], $opponent['user_colour']) . "<br />(" . $this->functions_points->number_format_points($row['point_sendold']) . "->" . $this->functions_points->number_format_points($row['point_sendold'] + $row['point_amount']) . ")";
                        $rows = 4;
                    }
                    $who .= " (+" . $this->functions_points->number_format_points($row['point_amount']) . ")";
                    $to .= " (-" . $this->functions_points->number_format_points($row['point_amount']) . ")";
                    break;
            }
            // Add the items to the template
            $this->template->assign_block_vars('logs', array('DATE' => $this->user->format_date($row['point_date']), 'COMMENT' => nl2br($row['point_comment']), 'TYPE' => $types[$rows], 'ROW' => $rows, 'WHO' => $who, 'TO' => $to));
        }
        $this->db->sql_freeresult($result);
        //Start pagination
        $this->pagination->generate_template_pagination($this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'logs', 'sk' => $sort_key, 'sd' => $sort_dir)), 'pagination', 'start', $max, $number, $start);
        // Generate the page template
        $this->template->assign_vars(array('PAGINATION' => $this->user->lang('POINTS_LOG_COUNT', $max), 'LOTTERY_NAME' => $points_values['lottery_name'], 'BANK_NAME' => $points_values['bank_name'], 'S_LOGS_ACTION' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'logs')), 'S_SELECT_SORT_DIR' => $s_sort_dir, 'S_SELECT_SORT_KEY' => $s_sort_key, 'U_TRANSFER_USER' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'transfer_user')), 'U_LOGS' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'logs')), 'U_LOTTERY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')), 'U_BANK' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'bank')), 'U_ROBBERY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'robbery')), 'U_INFO' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'info')), 'U_USE_TRANSFER' => $this->auth->acl_get('u_use_transfer'), 'U_USE_LOGS' => $this->auth->acl_get('u_use_logs'), 'U_USE_LOTTERY' => $this->auth->acl_get('u_use_lottery'), 'U_USE_BANK' => $this->auth->acl_get('u_use_bank'), 'U_USE_ROBBERY' => $this->auth->acl_get('u_use_robbery')));
        // Generate the page header
        page_header(sprintf($this->user->lang['LOGS_TITLE'], $checked_user['username']));
        // Generate the page template
        $this->template->set_filenames(array('body' => 'points/points_logs.html'));
        page_footer();
    }
Beispiel #18
0
    public function display_recent_topics($tpl_loopname = 'recent_topics', $spec_forum_id = 0, $include_subforums = true)
    {
        $this->user->add_lang_ext('paybas/recenttopics', 'recenttopics');
        /**
         * Set some internal needed variables
         */
        $topics_per_page = $this->config['rt_number'];
        $num_pages = $this->config['rt_page_number'];
        $min_topic_level = $this->config['rt_min_topic_level'];
        $excluded_topics = $this->config['rt_anti_topics'];
        $display_parent_forums = $this->config['rt_parents'];
        $unread_only = $this->config['rt_unreadonly'];
        $sort_topics = $this->config['rt_sort_start_time'] ? 'topic_time' : 'topic_last_post_time';
        $persistent_display = $this->config['rt_persistent_display'];
        if ($persistent_display) {
            $this->template->assign_vars(array(strtoupper($tpl_loopname) . '_DISPLAY' => true));
        }
        $start = $this->request->variable($tpl_loopname . '_start', 0);
        $excluded_topic_ids = explode(', ', $excluded_topics);
        $total_limit = $topics_per_page * $num_pages;
        if (!function_exists('display_forums')) {
            include $this->root_path . 'includes/functions_display.' . $this->phpEx;
        }
        /**
         * Get the forums we take our topics from
         */
        // Get the allowed forums
        $forum_ary = array();
        $forum_read_ary = $this->auth->acl_getf('f_read');
        foreach ($forum_read_ary as $forum_id => $allowed) {
            if ($allowed['f_read']) {
                $forum_ary[] = (int) $forum_id;
            }
        }
        $forum_ids = array_unique($forum_ary);
        if (!sizeof($forum_ids)) {
            // No forums with f_read
            return;
        }
        $spec_forum_ary = array();
        if ($spec_forum_id) {
            // Only take a special-forum
            if (!$include_subforums) {
                if (!in_array($spec_forum_id, $forum_ids)) {
                    return;
                }
                $forum_ids = array();
                $sql = 'SELECT 1 as display_forum
					FROM ' . FORUMS_TABLE . '
					WHERE forum_id = ' . intval($spec_forum_id) . '
						AND forum_recent_topics = 1';
                $result = $this->db->sql_query_limit($sql, 1);
                $display_forum = (bool) $this->db->sql_fetchfield('display_forum');
                $this->db->sql_freeresult($result);
                if ($display_forum) {
                    $forum_ids = array($spec_forum_id);
                }
            } else {
                // ... and it's subforums
                $sql = 'SELECT f2.forum_id
					FROM ' . FORUMS_TABLE . ' f1
					LEFT JOIN ' . FORUMS_TABLE . " f2\n\t\t\t\t\t\tON (f2.left_id BETWEEN f1.left_id AND f1.right_id\n\t\t\t\t\t\t\tAND f2.forum_recent_topics = 1)\n\t\t\t\t\tWHERE f1.forum_id = {$spec_forum_id}\n\t\t\t\t\t\tAND f1.forum_recent_topics = 1\n\t\t\t\t\tORDER BY f2.left_id DESC";
                $result = $this->db->sql_query($sql);
                while ($row = $this->db->sql_fetchrow($result)) {
                    $spec_forum_ary[] = $row['forum_id'];
                }
                $this->db->sql_freeresult($result);
                $forum_ids = array_intersect($forum_ids, $spec_forum_ary);
                if (!sizeof($forum_ids)) {
                    return;
                }
            }
        } else {
            $sql = 'SELECT forum_id
				FROM ' . FORUMS_TABLE . '
				WHERE ' . $this->db->sql_in_set('forum_id', $forum_ids) . '
					AND forum_recent_topics = 1';
            $result = $this->db->sql_query($sql);
            $forum_ids = array();
            while ($row = $this->db->sql_fetchrow($result)) {
                $forum_ids[] = $row['forum_id'];
            }
            $this->db->sql_freeresult($result);
        }
        // No forums with f_read or recent topics enabled
        if (!sizeof($forum_ids)) {
            return;
        }
        // Remove duplicated ids
        $forum_ids = array_unique($forum_ids);
        $forums = $topic_list = array();
        $topics_count = 0;
        $obtain_icons = false;
        // Either use the phpBB core function to get unread topics, or the custom function for default behavior
        if ($unread_only && $this->user->data['user_id'] != ANONYMOUS) {
            // Get unread topics
            $sql_extra = ' AND ' . $this->db->sql_in_set('t.topic_id', $excluded_topic_ids, true);
            $sql_extra .= ' AND ' . $this->content_visibility->get_forums_visibility_sql('topic', $forum_ids, $table_alias = 't.');
            $unread_topics = get_unread_topics(false, $sql_extra, '', $total_limit);
            foreach ($unread_topics as $topic_id => $mark_time) {
                $topics_count++;
                if ($topics_count > $start && $topics_count <= $start + $topics_per_page) {
                    $topic_list[] = $topic_id;
                }
            }
        } else {
            // Get the allowed topics
            $sql_array = array('SELECT' => 't.forum_id, t.topic_id, t.topic_type, t.icon_id, tt.mark_time, ft.mark_time as f_mark_time', 'FROM' => array(TOPICS_TABLE => 't'), 'LEFT_JOIN' => array(array('FROM' => array(TOPICS_TRACK_TABLE => 'tt'), 'ON' => 'tt.topic_id = t.topic_id AND tt.user_id = ' . $this->user->data['user_id']), array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.forum_id = t.forum_id AND ft.user_id = ' . $this->user->data['user_id'])), 'WHERE' => $this->db->sql_in_set('t.topic_id', $excluded_topic_ids, true) . '
					AND t.topic_status <> ' . ITEM_MOVED . '
					AND ' . $this->content_visibility->get_forums_visibility_sql('topic', $forum_ids, $table_alias = 't.'), 'ORDER_BY' => 't.' . $sort_topics . ' DESC');
            // Check if we want all topics, or only stickies/announcements/globals
            if ($min_topic_level > 0) {
                $sql_array['WHERE'] .= ' AND t.topic_type >= ' . $min_topic_level;
            }
            /**
             * Event to modify the SQL query before the allowed topics list data is retrieved
             *
             * @event paybas.recenttopics.sql_pull_topics_list
             * @var    array    sql_array        The SQL array
             * @since 2.0.4
             */
            $vars = array('sql_array');
            extract($this->dispatcher->trigger_event('paybas.recenttopics.sql_pull_topics_list', compact($vars)));
            $sql = $this->db->sql_build_query('SELECT', $sql_array);
            $result = $this->db->sql_query_limit($sql, $total_limit);
            while ($row = $this->db->sql_fetchrow($result)) {
                $topics_count++;
                if ($topics_count > $start && $topics_count <= $start + $topics_per_page) {
                    $topic_list[] = $row['topic_id'];
                    $rowset[$row['topic_id']] = $row;
                    if (!isset($forums[$row['forum_id']]) && $this->user->data['is_registered'] && $this->config['load_db_lastread']) {
                        $forums[$row['forum_id']]['mark_time'] = $row['f_mark_time'];
                    }
                    $forums[$row['forum_id']]['topic_list'][] = $row['topic_id'];
                    $forums[$row['forum_id']]['rowset'][$row['topic_id']] =& $rowset[$row['topic_id']];
                    if ($row['icon_id'] && $this->auth->acl_get('f_icons', $row['forum_id'])) {
                        $obtain_icons = true;
                    }
                }
            }
            $this->db->sql_freeresult($result);
        }
        // No topics to display
        if (!sizeof($topic_list)) {
            return;
        }
        // Grab icons
        if ($obtain_icons) {
            $icons = $this->cache->obtain_icons();
        } else {
            $icons = array();
        }
        // Borrowed from search.php
        foreach ($forums as $forum_id => $forum) {
            if ($this->user->data['is_registered'] && $this->config['load_db_lastread']) {
                $topic_tracking_info[$forum_id] = get_topic_tracking($forum_id, $forum['topic_list'], $forum['rowset'], array($forum_id => $forum['mark_time']), $forum_id ? false : $forum['topic_list']);
            } else {
                if ($this->config['load_anon_lastread'] || $this->user->data['is_registered']) {
                    $tracking_topics = $this->request->variable($this->config['cookie_name'] . '_track', '', true, \phpbb\request\request_interface::COOKIE);
                    $tracking_topics = $tracking_topics ? tracking_unserialize($tracking_topics) : array();
                    $topic_tracking_info[$forum_id] = get_complete_topic_tracking($forum_id, $forum['topic_list'], $forum_id ? false : $forum['topic_list']);
                    if (!$this->user->data['is_registered']) {
                        $this->user->data['user_lastmark'] = isset($tracking_topics['l']) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $this->config['board_startdate']) : 0;
                    }
                }
            }
        }
        // Now only pull the data of the requested topics
        $sql_array = array('SELECT' => 't.*, tp.topic_posted, f.forum_name', 'FROM' => array(TOPICS_TABLE => 't'), 'LEFT_JOIN' => array(array('FROM' => array(TOPICS_POSTED_TABLE => 'tp'), 'ON' => 't.topic_id = tp.topic_id AND tp.user_id = ' . $this->user->data['user_id']), array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 'f.forum_id = t.forum_id')), 'WHERE' => $this->db->sql_in_set('t.topic_id', $topic_list), 'ORDER_BY' => 't.' . $sort_topics . ' DESC');
        if ($display_parent_forums) {
            $sql_array['SELECT'] .= ', f.parent_id, f.forum_parents, f.left_id, f.right_id';
        }
        /**
         * Event to modify the SQL query before the topics data is retrieved
         *
         * @event paybas.recenttopics.sql_pull_topics_data
         * @var    array    sql_array        The SQL array
         * @since 2.0.0
         */
        $vars = array('sql_array');
        extract($this->dispatcher->trigger_event('paybas.recenttopics.sql_pull_topics_data', compact($vars)));
        $sql = $this->db->sql_build_query('SELECT', $sql_array);
        $result = $this->db->sql_query_limit($sql, $topics_per_page);
        $rowset = $topic_icons = array();
        while ($row = $this->db->sql_fetchrow($result)) {
            $rowset[] = $row;
        }
        $this->db->sql_freeresult($result);
        // No topics returned by the DB
        if (!sizeof($rowset)) {
            return;
        }
        /**
         * Event to modify the topics list data before we start the display loop
         *
         * @event paybas.recenttopics.modify_topics_list
         * @var    array    topic_list        Array of all the topic IDs
         * @var    array    rowset            The full topics list array
         * @since 2.0.1
         */
        $vars = array('topic_list', 'rowset');
        extract($this->dispatcher->trigger_event('paybas.recenttopics.modify_topics_list', compact($vars)));
        foreach ($rowset as $row) {
            $topic_id = $row['topic_id'];
            $forum_id = $row['forum_id'];
            $s_type_switch_test = $row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL ? 1 : 0;
            //$replies = ($this->auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];
            $replies = $this->content_visibility->get_count('topic_posts', $row, $forum_id) - 1;
            if ($unread_only) {
                topic_status($row, $replies, true, $folder_img, $folder_alt, $topic_type);
                $unread_topic = true;
            } else {
                topic_status($row, $replies, isset($topic_tracking_info[$forum_id][$row['topic_id']]) && $row['topic_last_post_time'] > $topic_tracking_info[$forum_id][$row['topic_id']] ? true : false, $folder_img, $folder_alt, $topic_type);
                $unread_topic = isset($topic_tracking_info[$forum_id][$row['topic_id']]) && $row['topic_last_post_time'] > $topic_tracking_info[$forum_id][$row['topic_id']] ? true : false;
            }
            $view_topic_url = append_sid("{$this->root_path}viewtopic.{$this->phpEx}", 'f=' . $forum_id . '&amp;t=' . $topic_id);
            $view_forum_url = append_sid("{$this->root_path}viewforum.{$this->phpEx}", 'f=' . $forum_id);
            $topic_unapproved = $row['topic_visibility'] == ITEM_UNAPPROVED && $this->auth->acl_get('m_approve', $forum_id);
            $posts_unapproved = $row['topic_visibility'] == ITEM_APPROVED && $row['topic_posts_unapproved'] && $this->auth->acl_get('m_approve', $forum_id);
            $u_mcp_queue = $topic_unapproved || $posts_unapproved ? append_sid("{$this->root_path}mcp.{$this->phpEx}", 'i=queue&amp;mode=' . ($topic_unapproved ? 'approve_details' : 'unapproved_posts') . "&amp;t={$topic_id}", true, $this->user->session_id) : '';
            $s_type_switch = $row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL ? 1 : 0;
            if (!empty($icons[$row['icon_id']])) {
                $topic_icons[] = $topic_id;
            }
            // Get folder img, topic status/type related information
            $folder_img = $folder_alt = $topic_type = '';
            topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
            $tpl_ary = array('FORUM_ID' => $forum_id, 'TOPIC_ID' => $topic_id, 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'FIRST_POST_TIME' => $this->user->format_date($row['topic_time']), 'LAST_POST_SUBJECT' => censor_text($row['topic_last_post_subject']), 'LAST_POST_TIME' => $this->user->format_date($row['topic_last_post_time']), 'LAST_VIEW_TIME' => $this->user->format_date($row['topic_last_view_time']), 'LAST_POST_AUTHOR' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'REPLIES' => $replies, 'VIEWS' => $row['topic_views'], 'TOPIC_TITLE' => censor_text($row['topic_title']), 'FORUM_NAME' => $row['forum_name'], 'TOPIC_TYPE' => $topic_type, 'TOPIC_IMG_STYLE' => $folder_img, 'TOPIC_FOLDER_IMG' => $this->user->img($folder_img, $folder_alt), 'TOPIC_FOLDER_IMG_ALT' => $this->user->lang[$folder_alt], 'TOPIC_ICON_IMG' => !empty($icons[$row['icon_id']]) ? $icons[$row['icon_id']]['img'] : '', 'TOPIC_ICON_IMG_WIDTH' => !empty($icons[$row['icon_id']]) ? $icons[$row['icon_id']]['width'] : '', 'TOPIC_ICON_IMG_HEIGHT' => !empty($icons[$row['icon_id']]) ? $icons[$row['icon_id']]['height'] : '', 'ATTACH_ICON_IMG' => $this->auth->acl_get('u_download') && $this->auth->acl_get('f_download', $forum_id) && $row['topic_attachment'] ? $this->user->img('icon_topic_attach', $this->user->lang['TOTAL_ATTACHMENTS']) : '', 'UNAPPROVED_IMG' => $topic_unapproved || $posts_unapproved ? $this->user->img('icon_topic_unapproved', $topic_unapproved ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '', 'REPORTED_IMG' => $row['topic_reported'] && $this->auth->acl_get('m_report', $forum_id) ? $this->user->img('icon_topic_reported', 'TOPIC_REPORTED') : '', 'S_HAS_POLL' => $row['poll_start'] ? true : false, 'S_TOPIC_TYPE' => $row['topic_type'], 'S_USER_POSTED' => isset($row['topic_posted']) && $row['topic_posted'] ? true : false, 'S_UNREAD_TOPIC' => $unread_topic, 'S_TOPIC_REPORTED' => $row['topic_reported'] && $this->auth->acl_get('m_report', $forum_id) ? true : false, 'S_TOPIC_UNAPPROVED' => $topic_unapproved, 'S_POSTS_UNAPPROVED' => $posts_unapproved, 'S_POST_ANNOUNCE' => $row['topic_type'] == POST_ANNOUNCE ? true : false, 'S_POST_GLOBAL' => $row['topic_type'] == POST_GLOBAL ? true : false, 'S_POST_STICKY' => $row['topic_type'] == POST_STICKY ? true : false, 'S_TOPIC_LOCKED' => $row['topic_status'] == ITEM_LOCKED ? true : false, 'S_TOPIC_MOVED' => $row['topic_status'] == ITEM_MOVED ? true : false, 'S_TOPIC_TYPE_SWITCH' => $s_type_switch == $s_type_switch_test ? -1 : $s_type_switch_test, 'U_NEWEST_POST' => $view_topic_url . '&amp;view=unread#unread', 'U_LAST_POST' => $view_topic_url . '&amp;p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id'], 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'U_VIEW_TOPIC' => $view_topic_url, 'U_VIEW_FORUM' => $view_forum_url, 'U_MCP_REPORT' => append_sid("{$this->root_path}mcp.{$this->phpEx}", 'i=reports&amp;mode=reports&amp;f=' . $forum_id . '&amp;t=' . $topic_id, true, $this->user->session_id), 'U_MCP_QUEUE' => $u_mcp_queue);
            /**
             * Modify the topic data before it is assigned to the template
             *
             * @event paybas.recenttopics.modify_tpl_ary
             * @var    array    row            Array with topic data
             * @var    array    tpl_ary        Template block array with topic data
             * @since 2.0.0
             */
            $vars = array('row', 'tpl_ary');
            extract($this->dispatcher->trigger_event('paybas.recenttopics.modify_tpl_ary', compact($vars)));
            $this->template->assign_block_vars($tpl_loopname, $tpl_ary);
            $this->pagination->generate_template_pagination($view_topic_url, $tpl_loopname . '.pagination', 'start', $replies + 1, $this->config['posts_per_page'], 1, true, true);
            if ($display_parent_forums) {
                $forum_parents = get_forum_parents($row);
                foreach ($forum_parents as $parent_id => $data) {
                    $this->template->assign_block_vars($tpl_loopname . '.parent_forums', array('FORUM_ID' => $parent_id, 'FORUM_NAME' => $data[0], 'U_VIEW_FORUM' => append_sid("{$this->root_path}viewforum.{$this->phpEx}", 'f=' . $parent_id)));
                }
            }
        }
        // Get URL-parameters for pagination
        $url_params = explode('&', $this->user->page['query_string']);
        $append_params = false;
        foreach ($url_params as $param) {
            if (!$param) {
                continue;
            }
            if (strpos($param, '=') === false) {
                // Fix MSSTI Advanced BBCode MOD
                $append_params[$param] = '1';
                continue;
            }
            list($name, $value) = explode('=', $param);
            if ($name != $tpl_loopname . '_start') {
                $append_params[$name] = $value;
            }
        }
        $pagination_url = append_sid($this->root_path . $this->user->page['page_name'], $append_params);
        $this->pagination->generate_template_pagination($pagination_url, 'rt_pagination', $tpl_loopname . '_start', $topics_count, $topics_per_page, $start);
        $this->template->assign_vars(array('RT_SORT_START_TIME' => $sort_topics === 'topic_time' ? true : false, 'S_TOPIC_ICONS' => sizeof($topic_icons) ? true : false, 'NEWEST_POST_IMG' => $this->user->img('icon_topic_newest', 'VIEW_NEWEST_POST'), 'LAST_POST_IMG' => $this->user->img('icon_topic_latest', 'VIEW_LATEST_POST'), 'POLL_IMG' => $this->user->img('icon_topic_poll', 'TOPIC_POLL'), strtoupper($tpl_loopname) . '_DISPLAY' => true));
    }
Beispiel #19
0
    /**
     * Get similar topics by matching topic titles
     *
     * NOTE: Currently requires MySQL due to the use of FULLTEXT indexes
     * and MATCH and AGAINST and UNIX_TIMESTAMP. MySQL FULLTEXT has built-in
     * English ignore words. We use phpBB's ignore words for non-English
     * languages. We also remove any admin-defined special ignore words.
     *
     * @param	array	$topic_data	Array with topic data
     * @return 	null
     * @access	public
     */
    public function display_similar_topics($topic_data)
    {
        $topic_title = $this->clean_topic_title($topic_data['topic_title']);
        // If the cleaned up topic_title is empty, no need to continue
        if (empty($topic_title)) {
            return;
        }
        // Similar Topics query
        $sql_array = array('SELECT' => "f.forum_id, f.forum_name, t.*,\n\t\t\t\tMATCH (t.topic_title) AGAINST ('" . $this->db->sql_escape($topic_title) . "') AS score", 'FROM' => array(TOPICS_TABLE => 't'), 'LEFT_JOIN' => array(array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 'f.forum_id = t.forum_id')), 'WHERE' => "MATCH (t.topic_title) AGAINST ('" . $this->db->sql_escape($topic_title) . "') >= 0.5\n\t\t\t\tAND t.topic_status <> " . ITEM_MOVED . '
				AND t.topic_visibility = ' . ITEM_APPROVED . '
				AND t.topic_time > (UNIX_TIMESTAMP() - ' . $this->config['similar_topics_time'] . ')
				AND t.topic_id <> ' . (int) $topic_data['topic_id']);
        // Add topic tracking data to the query (only if query caching is off)
        if ($this->user->data['is_registered'] && $this->config['load_db_lastread'] && !$this->config['similar_topics_cache']) {
            $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TRACK_TABLE => 'tt'), 'ON' => 'tt.topic_id = t.topic_id AND tt.user_id = ' . $this->user->data['user_id']);
            $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.forum_id = f.forum_id AND ft.user_id = ' . $this->user->data['user_id']);
            $sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time as f_mark_time';
        } else {
            if ($this->config['load_anon_lastread'] || $this->user->data['is_registered']) {
                // Cookie based tracking copied from search.php
                $tracking_topics = $this->request->variable($this->config['cookie_name'] . '_track', '', true, \phpbb\request\request_interface::COOKIE);
                $tracking_topics = $tracking_topics ? tracking_unserialize($tracking_topics) : array();
            }
        }
        // We need to exclude passworded forums so we do not leak the topic title
        $passworded_forums = $this->user->get_passworded_forums();
        // See if the admin set this forum to only search a specific group of other forums, and include them
        if (!empty($topic_data['similar_topic_forums'])) {
            // Remove any passworded forums from this group of forums we will be searching
            $included_forums = array_diff(explode(',', $topic_data['similar_topic_forums']), $passworded_forums);
            // if there's nothing left to display (user has no access to the forums we want to search)
            if (empty($included_forums)) {
                return;
            }
            $sql_array['WHERE'] .= ' AND ' . $this->db->sql_in_set('f.forum_id', $included_forums);
        } else {
            if (!empty($this->config['similar_topics_ignore'])) {
                // Add passworded forums to the exlude array
                $excluded_forums = array_unique(array_merge(explode(',', $this->config['similar_topics_ignore']), $passworded_forums));
                $sql_array['WHERE'] .= ' AND ' . $this->db->sql_in_set('f.forum_id', $excluded_forums, true);
            } else {
                if (!empty($passworded_forums)) {
                    $sql_array['WHERE'] .= ' AND ' . $this->db->sql_in_set('f.forum_id', $passworded_forums, true);
                }
            }
        }
        /**
         * Event to modify the sql_array for similar topics
         *
         * @event vse.similartopics.get_topic_data
         * @var	array	sql_array	SQL array to get similar topics data
         * @since 1.3.0
         */
        $vars = array('sql_array');
        extract($this->dispatcher->trigger_event('vse.similartopics.get_topic_data', compact($vars)));
        $sql = $this->db->sql_build_query('SELECT', $sql_array);
        $result = $this->db->sql_query_limit($sql, $this->config['similar_topics_limit'], 0, $this->config['similar_topics_cache']);
        // Grab icons
        $icons = $this->cache->obtain_icons();
        $rowset = array();
        while ($row = $this->db->sql_fetchrow($result)) {
            $similar_forum_id = (int) $row['forum_id'];
            $similar_topic_id = (int) $row['topic_id'];
            $rowset[$similar_topic_id] = $row;
            if ($this->auth->acl_get('f_read', $similar_forum_id)) {
                // Get topic tracking info
                if ($this->user->data['is_registered'] && $this->config['load_db_lastread'] && !$this->config['similar_topics_cache']) {
                    $topic_tracking_info = get_topic_tracking($similar_forum_id, $similar_topic_id, $rowset, array($similar_forum_id => $row['f_mark_time']));
                } else {
                    if ($this->config['load_anon_lastread'] || $this->user->data['is_registered']) {
                        $topic_tracking_info = get_complete_topic_tracking($similar_forum_id, $similar_topic_id);
                        if (!$this->user->data['is_registered']) {
                            $this->user->data['user_lastmark'] = isset($tracking_topics['l']) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $this->config['board_startdate']) : 0;
                        }
                    }
                }
                // Replies
                $replies = $this->content_visibility->get_count('topic_posts', $row, $similar_forum_id) - 1;
                // Get folder img, topic status/type related information
                $folder_img = $folder_alt = $topic_type = '';
                $unread_topic = isset($topic_tracking_info[$similar_topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$similar_topic_id] ? true : false;
                topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
                $topic_unapproved = $row['topic_visibility'] == ITEM_UNAPPROVED && $this->auth->acl_get('m_approve', $similar_forum_id) ? true : false;
                $posts_unapproved = $row['topic_visibility'] == ITEM_APPROVED && $row['topic_posts_unapproved'] && $this->auth->acl_get('m_approve', $similar_forum_id) ? true : false;
                //$topic_deleted = $row['topic_visibility'] == ITEM_DELETED;
                $u_mcp_queue = $topic_unapproved || $posts_unapproved ? append_sid("{$this->root_path}mcp.{$this->php_ext}", 'i=queue&amp;mode=' . ($topic_unapproved ? 'approve_details' : 'unapproved_posts') . "&amp;t={$similar_topic_id}", true, $this->user->session_id) : '';
                //$u_mcp_queue = (!$u_mcp_queue && $topic_deleted) ? append_sid("{$this->root_path}mcp.{$this->php_ext}", "i=queue&amp;mode=deleted_topics&amp;t=$similar_topic_id", true, $this->user->session_id) : $u_mcp_queue;
                $base_url = append_sid("{$this->root_path}viewtopic.{$this->php_ext}", 'f=' . $similar_forum_id . '&amp;t=' . $similar_topic_id);
                $topic_row = array('TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'FIRST_POST_TIME' => $this->user->format_date($row['topic_time']), 'LAST_POST_TIME' => $this->user->format_date($row['topic_last_post_time']), 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'TOPIC_REPLIES' => $replies, 'TOPIC_VIEWS' => $row['topic_views'], 'TOPIC_TITLE' => $row['topic_title'], 'FORUM_TITLE' => $row['forum_name'], 'TOPIC_IMG_STYLE' => $folder_img, 'TOPIC_FOLDER_IMG' => $this->user->img($folder_img, $folder_alt), 'TOPIC_FOLDER_IMG_ALT' => $this->user->lang($folder_alt), 'TOPIC_ICON_IMG' => !empty($icons[$row['icon_id']]) ? $icons[$row['icon_id']]['img'] : '', 'TOPIC_ICON_IMG_WIDTH' => !empty($icons[$row['icon_id']]) ? $icons[$row['icon_id']]['width'] : '', 'TOPIC_ICON_IMG_HEIGHT' => !empty($icons[$row['icon_id']]) ? $icons[$row['icon_id']]['height'] : '', 'ATTACH_ICON_IMG' => $this->auth->acl_get('u_download') && $this->auth->acl_get('f_download', $similar_forum_id) && $row['topic_attachment'] ? $this->user->img('icon_topic_attach', $this->user->lang('TOTAL_ATTACHMENTS')) : '', 'UNAPPROVED_IMG' => $topic_unapproved || $posts_unapproved ? $this->user->img('icon_topic_unapproved', $topic_unapproved ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '', 'S_UNREAD_TOPIC' => $unread_topic, 'S_TOPIC_REPORTED' => !empty($row['topic_reported']) && $this->auth->acl_get('m_report', $similar_forum_id) ? true : false, 'S_TOPIC_UNAPPROVED' => $topic_unapproved, 'S_POSTS_UNAPPROVED' => $posts_unapproved, 'S_HAS_POLL' => $row['poll_start'] ? true : false, 'U_NEWEST_POST' => append_sid("{$this->root_path}viewtopic.{$this->php_ext}", 'f=' . $similar_forum_id . '&amp;t=' . $similar_topic_id . '&amp;view=unread') . '#unread', 'U_LAST_POST' => append_sid("{$this->root_path}viewtopic.{$this->php_ext}", 'f=' . $similar_forum_id . '&amp;t=' . $similar_topic_id . '&amp;p=' . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'], 'U_VIEW_TOPIC' => append_sid("{$this->root_path}viewtopic.{$this->php_ext}", 'f=' . $similar_forum_id . '&amp;t=' . $similar_topic_id), 'U_VIEW_FORUM' => append_sid("{$this->root_path}viewforum.{$this->php_ext}", 'f=' . $similar_forum_id), 'U_MCP_REPORT' => append_sid("{$this->root_path}mcp.{$this->php_ext}", 'i=reports&amp;mode=reports&amp;f=' . $similar_forum_id . '&amp;t=' . $similar_topic_id, true, $this->user->session_id), 'U_MCP_QUEUE' => $u_mcp_queue);
                /**
                 * Event to modify the similar topics template block
                 *
                 * @event vse.similartopics.modify_topicrow
                 * @var	array	row			Array with similar topic data
                 * @var	array	topic_row	Template block array
                 * @since 1.3.0
                 */
                $vars = array('row', 'topic_row');
                extract($this->dispatcher->trigger_event('vse.similartopics.modify_topicrow', compact($vars)));
                $this->template->assign_block_vars('similar', $topic_row);
                $this->pagination->generate_template_pagination($base_url, 'similar.pagination', 'start', $replies + 1, $this->config['posts_per_page'], 1, true, true);
            }
        }
        $this->db->sql_freeresult($result);
        $this->user->add_lang_ext('vse/similartopics', 'similar_topics');
        $this->template->assign_vars(array('L_SIMILAR_TOPICS' => $this->user->lang('SIMILAR_TOPICS'), 'NEWEST_POST_IMG' => $this->user->img('icon_topic_newest', 'VIEW_NEWEST_POST'), 'LAST_POST_IMG' => $this->user->img('icon_topic_latest', 'VIEW_LATEST_POST'), 'REPORTED_IMG' => $this->user->img('icon_topic_reported', 'TOPIC_REPORTED'), 'POLL_IMG' => $this->user->img('icon_topic_poll', 'TOPIC_POLL')));
    }
    /**
     * Display the output for this extension
     *
     * @return null
     * @access public
     */
    public function display_output()
    {
        // Check that the user has permission to access here
        if (!$this->auth->acl_get('a_comms_pm_stats')) {
            trigger_error('NOT_AUTHORISED', E_USER_WARNING);
        }
        // Add the language file
        $this->language->add_lang('acp_pmstats', 'david63/pmstats');
        // Get message count
        $sql = 'SELECT COUNT(msg_id) AS total_msg
			FROM ' . PRIVMSGS_TO_TABLE;
        $result = $this->db->sql_query($sql);
        $total_msg = (int) $this->db->sql_fetchfield('total_msg');
        $this->db->sql_freeresult($result);
        // If no data then no point going any further
        if ($total_msg == 0) {
            trigger_error($this->language->lang('NO_PM_DATA'));
        }
        // Start initial var setup
        $action = $this->request->variable('action', '');
        $fc = $this->request->variable('fc', '');
        $sort_key = $this->request->variable('sk', 't');
        $start = $this->request->variable('start', 0);
        $sd = $sort_dir = $this->request->variable('sd', 'd');
        $sort_dir = $sort_dir == 'd' ? ' DESC' : ' ASC';
        $order_ary = array('d' => 'p.pm_deleted' . $sort_dir . ', u.username_clean ASC', 'f' => 'p.pm_forwarded' . $sort_dir . ', u.username_clean ASC', 'h' => 'holdbox' . $sort_dir . ', u.username_clean ASC', 'i' => 'inbox' . $sort_dir . ', u.username_clean ASC', 'm' => 'p.pm_marked' . $sort_dir . ', u.username_clean ASC', 'n' => 'p.pm_new' . $sort_dir . ', u.username_clean ASC', 'nb' => 'nobox' . $sort_dir . ', u.username_clean ASC', 't' => 'total' . $sort_dir . ', u.username_clean ASC', 'o' => 'outbox' . $sort_dir . ', u.username_clean ASC', 'r' => 'p.pm_replied' . $sort_dir . ', u.username_clean ASC', 's' => 'sentbox' . $sort_dir . ', u.username_clean ASC', 'sv' => 'savedbox' . $sort_dir . ', u.username_clean ASC', 'u' => 'u.username_clean' . $sort_dir, 'un' => 'p.pm_unread' . $sort_dir . ', u.username_clean ASC');
        $filter_by = '';
        if ($fc == 'other') {
            for ($i = ord($this->language->lang('START_CHARACTER')); $i <= ord($this->language->lang('END_CHARACTER')); $i++) {
                $filter_by .= ' AND u.username_clean ' . $this->db->sql_not_like_expression(utf8_clean_string(chr($i)) . $this->db->get_any_char());
            }
        } else {
            if ($fc) {
                $filter_by .= ' AND u.username_clean ' . $this->db->sql_like_expression(utf8_clean_string(substr($fc, 0, 1)) . $this->db->get_any_char());
            }
        }
        $sql = $this->db->sql_build_query('SELECT', array('SELECT' => 'u.user_id, u.username, u.username_clean, u.user_colour, p.pm_deleted, p.pm_new, p.pm_unread, p.pm_replied, p.pm_marked, p.pm_forwarded, SUM(IF(p.folder_id = ' . PRIVMSGS_INBOX . ', 1, 0)) AS inbox, SUM(IF(p.folder_id = ' . PRIVMSGS_SENTBOX . ', 1, 0)) AS sentbox, SUM(IF(p.folder_id = ' . PRIVMSGS_OUTBOX . ', 1, 0)) AS outbox, SUM(IF(p.folder_id = ' . PRIVMSGS_NO_BOX . ', 1, 0)) AS nobox, SUM(IF(p.folder_id = ' . PRIVMSGS_HOLD_BOX . ', 1, 0)) AS holdbox, SUM(IF(p.folder_id > ' . PRIVMSGS_INBOX . ', 1, 0)) AS savedbox, COUNT(p.folder_id) AS total', 'FROM' => array(USERS_TABLE => 'u'), 'LEFT_JOIN' => array(array('FROM' => array(PRIVMSGS_TO_TABLE => 'p'), 'ON' => 'u.user_id = p.user_id')), 'WHERE' => 'u.user_type <> ' . USER_IGNORE . $filter_by, 'ORDER_BY' => $sort_key == '' ? 'total DESC' : $order_ary[$sort_key], 'GROUP_BY' => 'u.username_clean'));
        $result = $this->db->sql_query_limit($sql, $this->config['topics_per_page'], $start);
        while ($row = $this->db->sql_fetchrow($result)) {
            $this->template->assign_block_vars('pm_statistics', array('DELETED' => (int) $row['pm_deleted'], 'FORWARDED' => (int) $row['pm_forwarded'], 'HOLDBOX' => $row['holdbox'], 'INBOX' => $row['inbox'], 'MARKED' => (int) $row['pm_marked'], 'NEW' => (int) $row['pm_new'], 'NOBOX' => $row['nobox'], 'OUTBOX' => $row['outbox'], 'REPLIED' => (int) $row['pm_replied'], 'SAVEDBOX' => $row['savedbox'], 'SENTBOX' => $row['sentbox'], 'UNREAD' => (int) $row['pm_unread'], 'USERNAME' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'TOTAL' => $row['total']));
        }
        $this->db->sql_freeresult($result);
        $sort_by_text = array('u' => $this->language->lang('SORT_USERNAME'), 't' => $this->language->lang('SORT_TOTAL_MESSAGES'), 'i' => $this->language->lang('SORT_INBOX'), 'n' => $this->language->lang('SORT_NEW'), 'un' => $this->language->lang('SORT_UNREAD'), 'o' => $this->language->lang('SORT_OUTBOX'), 's' => $this->language->lang('SORT_SENT'), 'sv' => $this->language->lang('SORT_SAVED'), 'h' => $this->language->lang('SORT_HOLD'), 'd' => $this->language->lang('SORT_DELETED'), 'm' => $this->language->lang('SORT_MARKED'), 'r' => $this->language->lang('SORT_REPLY'), 'f' => $this->language->lang('SORT_FORWARDED'), 'nb' => $this->language->lang('SORT_NO_BOX'));
        $limit_days = array();
        $s_sort_key = $s_limit_days = $s_sort_dir = $u_sort_param = '';
        gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sd, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
        // Get total user count for pagination
        $sql = 'SELECT COUNT(u.user_id) AS total_users
			FROM ' . USERS_TABLE . ' u
			WHERE u.user_type <> ' . USER_IGNORE . $filter_by;
        $result = $this->db->sql_query($sql);
        $user_count = (int) $this->db->sql_fetchfield('total_users');
        $this->db->sql_freeresult($result);
        $action = $this->u_action . '&amp;sk=' . $sort_key . '&amp;sd=' . $sd;
        $this->pagination->generate_template_pagination($action, 'pagination', 'start', $user_count, $this->config['topics_per_page'], $start);
        $first_characters = array();
        $first_characters[''] = $this->language->lang('ALL');
        for ($i = ord($this->language->lang('START_CHARACTER')); $i <= ord($this->language->lang('END_CHARACTER')); $i++) {
            $first_characters[chr($i)] = chr($i);
        }
        $first_characters['other'] = $this->language->lang('OTHER');
        foreach ($first_characters as $char => $desc) {
            $this->template->assign_block_vars('first_char', array('DESC' => $desc, 'U_SORT' => $action . '&amp;fc=' . $char));
        }
        $this->template->assign_vars(array('MESSAGE_COUNT' => $total_msg, 'S_SORT_DIR' => $s_sort_dir, 'S_SORT_KEY' => $s_sort_key, 'U_ACTION' => $action, 'PM_STATS_VERSION' => ext::PM_STATS_VERSION));
    }
Beispiel #21
0
    public function handle_emaillist()
    {
        // add lang file
        $this->user->add_lang_ext('dmzx/emaillist', 'common');
        // add a mode for a CSV Listing
        $mode = $this->request->variable('mode', '');
        $start = $this->request->variable('start', 0);
        // Founders only access
        if ($this->user->data['user_type'] != USER_FOUNDER) {
            trigger_error('NOT_AUTHORISED');
        }
        if ($mode == 'list') {
            $csv_output = trim($this->config['sitename']) . ' ' . $this->user->lang['EMAIL'];
            $csv_output .= "\n";
            $csv_output .= '#,' . $this->user->lang['USERNAME'] . ',' . $this->user->lang['EMAIL_ADDRESS'] . ',' . $this->user->lang['SORT_JOINED'] . ',' . $this->user->lang['LAST_VISIT'];
            $csv_output .= "\n";
            //Pull Users from the database
            $sql = 'SELECT FROM_UNIXTIME(user_regdate) AS regdate, user_id, username, user_email, FROM_UNIXTIME(user_lastvisit) AS lastvisit
				FROM ' . USERS_TABLE . '
				WHERE user_type <> ' . USER_IGNORE . '
				ORDER BY user_id';
            $result = $this->db->sql_query($sql);
            while ($row = $this->db->sql_fetchrow($result)) {
                $csv_output .= $row['user_id'] . ',' . $row['username'] . ',' . $row['user_email'] . ',' . $row['regdate'] . ',' . $row['lastvisit'];
                $csv_output .= "\n";
            }
            $this->db->sql_freeresult($result);
            header("Content-type: application/vnd.ms-excel");
            header("Content-disposition:\tattachment; filename=" . str_replace(" ", "_", $this->config['sitename']) . '_' . $this->user->lang['EMAIL'] . 's_' . date("Y-m-d") . ".csv");
            print $csv_output;
            exit;
        }
        // How many Users do we have?
        $sql = 'SELECT COUNT(user_id) AS total_users
			FROM ' . USERS_TABLE . '
			WHERE user_type <> ' . USER_IGNORE;
        $result = $this->db->sql_query($sql);
        $total_users = (int) $this->db->sql_fetchfield('total_users');
        $this->db->sql_freeresult($result);
        $pagination_url = $this->helper->route('dmzx_emaillist_controller');
        // want more to display...change the 20 to a higher number
        $tf = 20;
        //Pull Users from the database
        $sql = 'SELECT *
			FROM ' . USERS_TABLE . '
			WHERE user_type <> ' . USER_IGNORE . '
			ORDER BY user_id';
        $result = $this->db->sql_query_limit($sql, $tf, $start);
        // Assign specific vars
        while ($row = $this->db->sql_fetchrow($result)) {
            $this->template->assign_block_vars('list', array('ID' => $row['user_id'], 'EMAIL' => $row['user_email'], 'REGDATE' => $this->user->format_date($row['user_regdate']), 'LASTVISIT' => $this->user->format_date($row['user_lastvisit']), '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'])));
        }
        $this->db->sql_freeresult($result);
        //Start pagination
        $this->pagination->generate_template_pagination($pagination_url, 'pagination', 'start', $total_users, $tf, $start);
        $this->template->assign_vars(array('U_CSV_LIST' => $this->helper->route('dmzx_emaillist_controller', array('mode' => 'list')), 'TOTAL_USERS' => $total_users == 1 ? $this->user->lang['USER_COUNT'] : sprintf($this->user->lang['USER_COUNTS'], $total_users)));
        // Output page
        page_header($this->user->lang['EMAIL_LIST']);
        $this->template->set_filenames(array('body' => 'email_list_body.html'));
        page_footer();
    }
Beispiel #22
0
    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'));
    }
    function main($checked_user)
    {
        // Get all values
        $sql = 'SELECT *
				FROM ' . $this->points_values_table;
        $result = $this->db->sql_query($sql);
        $points_values = $this->db->sql_fetchrow($result);
        $this->db->sql_freeresult($result);
        // Get all point config names and config values
        $sql = 'SELECT config_name, config_value
				FROM ' . $this->points_config_table;
        $result = $this->db->sql_query($sql);
        while ($row = $this->db->sql_fetchrow($result)) {
            $points_config[$row['config_name']] = $row['config_value'];
        }
        $this->db->sql_freeresult($result);
        // Set some variables
        $start = $this->request->variable('start', 0);
        $number = $points_values['number_show_per_page'];
        add_form_key('lottery_tickets');
        // Check, if lottery is enabled
        if (!$points_config['lottery_enable']) {
            $message = $this->user->lang['LOTTERY_DISABLED'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller') . '">&laquo; ' . $this->user->lang['BACK_TO_PREV'] . '</a>';
            trigger_error($message);
        }
        // Check, if user is allowed to use the lottery
        if (!$this->auth->acl_get('u_use_lottery')) {
            $message = $this->user->lang['NOT_AUTHORISED'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller') . '">&laquo; ' . $this->user->lang['BACK_TO_PREV'] . '</a>';
            trigger_error($message);
        }
        // Add part to bar
        $this->template->assign_block_vars('navlinks', array('U_VIEW_FORUM' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')), 'FORUM_NAME' => $points_values['lottery_name']));
        // Add lottery base amount in description
        $this->template->assign_vars(array('L_LOTTERY_BASE_AMOUNT' => sprintf($this->user->lang['LOTTERY_DESCRIPTION'], sprintf($this->functions_points->number_format_points($points_values['lottery_base_amount'])), $this->config['points_name'])));
        // Recheck, if lottery was run, for those boards only having one user per day and which don't call the index page first
        if ($points_values['lottery_draw_period'] != 0 && time() > $points_values['lottery_last_draw_time'] + $points_values['lottery_draw_period']) {
            $this->functions_points->run_lottery();
        }
        // Check, if user has purchased tickets
        if ($this->request->variable('purchase_ticket', false) && $this->user->data['user_id'] != ANONYMOUS) {
            if (!check_form_key('lottery_tickets')) {
                trigger_error('FORM_INVALID');
            }
            // How many tickets have been bought?
            $total_tickets_bought = $this->request->variable('total_tickets', 0);
            // Check, if user already bought tickets
            $sql_array = array('SELECT' => 'COUNT(ticket_id) AS number_of_tickets', 'FROM' => array($this->points_lottery_tickets_table => 't'), 'WHERE' => 'user_id = ' . (int) $this->user->data['user_id']);
            $sql = $this->db->sql_build_query('SELECT', $sql_array);
            $result = $this->db->sql_query($sql);
            $number_tickets = $this->db->sql_fetchfield('number_of_tickets');
            $this->db->sql_freeresult($result);
            // Check, if the user tries to buy more tickets than allowed
            if ($total_tickets_bought > $points_values['lottery_max_tickets']) {
                $message = sprintf($this->user->lang['LOTTERY_MAX_TICKETS_REACH'], $points_values['lottery_max_tickets']) . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')) . '">&laquo; ' . $this->user->lang['BACK_TO_PREV'] . '</a>';
                trigger_error($message);
            }
            // Check in user try to buy negative tickets
            if ($total_tickets_bought <= 0) {
                $message = $this->user->lang['LOTTERY_NEGATIVE_TICKETS'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')) . '">&laquo; ' . $this->user->lang['BACK_TO_PREV'] . '</a>';
                trigger_error($message);
            }
            // Check, if the already bought tickets and the new request are higher than the max set number of tickets
            if ($number_tickets + $total_tickets_bought > $points_values['lottery_max_tickets']) {
                $message = sprintf($this->user->lang['LOTTERY_MAX_TICKETS_LEFT'], $points_values['lottery_max_tickets'] - $number_tickets) . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')) . '">&laquo; ' . $this->user->lang['BACK_TO_PREV'] . '</a>';
                trigger_error($message);
            }
            // Check, if the user sent an empty value
            if (!$total_tickets_bought) {
                $message = $this->user->lang['LOTTERY_INVALID_INPUT'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')) . '">&laquo; ' . $this->user->lang['BACK_TO_PREV'] . '</a>';
                trigger_error($message);
            }
            // Check. if lottery is enabled
            if ($points_config['lottery_enable'] != 0 && $points_values['lottery_ticket_cost'] != 0) {
                // Grab users total cash
                $sql_array = array('SELECT' => '*', 'FROM' => array(USERS_TABLE => 'u'), 'WHERE' => 'user_id = ' . (int) $this->user->data['user_id']);
                $sql = $this->db->sql_build_query('SELECT', $sql_array);
                $result = $this->db->sql_query($sql);
                $purchaser = $this->db->sql_fetchrow($result);
                $this->db->sql_freeresult($result);
                // Check, if the user has enough cash to buy tickets
                if ($points_values['lottery_ticket_cost'] * $total_tickets_bought > $purchaser['user_points']) {
                    $message = $this->user->lang['LOTTERY_LACK_FUNDS'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')) . '">&laquo; ' . $this->user->lang['BACK_TO_PREV'] . '</a>';
                    trigger_error($message);
                }
            }
            // Loop through total purchased tickets and create insert array
            for ($i = 0, $total_tickets_bought; $i < $total_tickets_bought; $i++) {
                $sql_insert_ary[] = array('user_id' => $this->user->data['user_id']);
            }
            $this->db->sql_multi_insert($this->points_lottery_tickets_table, $sql_insert_ary);
            // Check again, if lottery is enabled
            if ($points_config['lottery_enable'] != 0) {
                // Deduct cost
                $viewer_cash = $purchaser['user_points'] - $points_values['lottery_ticket_cost'] * $total_tickets_bought;
                $this->functions_points->set_points($this->user->data['user_id'], $viewer_cash);
                // Update jackpot
                $this->functions_points->set_points_values('lottery_jackpot', $points_values['lottery_jackpot'] + $points_values['lottery_ticket_cost'] * $total_tickets_bought);
            }
            $message = $this->user->lang['LOTTERY_TICKET_PURCHASED'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')) . '">&laquo; ' . $this->user->lang['BACK_TO_PREV'] . '</a>';
            trigger_error($message);
            $this->template->assign_vars(array('U_ACTION' => $this->u_action));
        }
        // Display main page
        $history_mode = $this->request->variable('history', '');
        if ($history_mode) {
            // If no one has ever won, why bother doing anything else?
            if ($points_values['points_winners_total'] = 0) {
                $message = $this->user->lang['LOTTERY_NO_WINNERS'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')) . '">&laquo; ' . $this->user->lang['BACK_TO_PREV'] . '</a>';
                trigger_error($message);
            }
            $total_wins = $points_values['points_winners_total'];
            // Check, if no entries returned, only self search would turn up empty at this point
            if ($history_mode == 'ego') {
                $sql_array = array('SELECT' => 'COUNT(id) AS viewer_history', 'FROM' => array($this->points_lottery_history_table => 'h'), 'WHERE' => 'user_id = ' . (int) $this->user->data['user_id']);
                $sql = $this->db->sql_build_query('SELECT', $sql_array);
                $result = $this->db->sql_query($sql);
                $total_wins = (int) $this->db->sql_fetchfield('viewer_history');
                $this->db->sql_freeresult($result);
                if ($total_wins == 0) {
                    $message = $this->user->lang['LOTTERY_NEVER_WON'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')) . '">&laquo; ' . $this->user->lang['BACK_TO_PREV'] . '</a>';
                    trigger_error($message);
                }
                $this->template->assign_vars(array('U_VIEW_HISTORY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery', 'history' => 'all')), 'U_TRANSFER_USER' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'transfer_user')), 'U_LOGS' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'logs')), 'U_LOTTERY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')), 'U_BANK' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'bank')), 'U_ROBBERY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'robbery'))));
            }
            // Check, if user is viewing all or own entries
            if ($history_mode == 'all') {
                $sql_array = array('SELECT' => 'COUNT(id) AS total_entries', 'FROM' => array($this->points_lottery_history_table => 'h'));
                $sql = $this->db->sql_build_query('SELECT', $sql_array);
                $result = $this->db->sql_query($sql);
                $total_entries = (int) $this->db->sql_fetchfield('total_entries');
                $this->db->sql_freeresult($result);
                $sql_array = array('SELECT' => 'h.*, u.*', 'FROM' => array($this->points_lottery_history_table => 'h'), 'LEFT_JOIN' => array(array('FROM' => array(USERS_TABLE => 'u'), 'ON' => 'h.user_id = u.user_id')), 'ORDER_BY' => 'time DESC');
            } else {
                $sql_array = array('SELECT' => 'COUNT(id) AS total_entries', 'FROM' => array($this->points_lottery_history_table => 'h'), 'WHERE' => 'user_id = ' . (int) $this->user->data['user_id']);
                $sql = $this->db->sql_build_query('SELECT', $sql_array);
                $result = $this->db->sql_query($sql);
                $total_entries = (int) $this->db->sql_fetchfield('total_entries');
                $this->db->sql_freeresult($result);
                $sql_array = array('SELECT' => 'h.*, u.*', 'FROM' => array($this->points_lottery_history_table => 'h'), 'LEFT_JOIN' => array(array('FROM' => array(USERS_TABLE => 'u'), 'ON' => 'h.user_id = u.user_id')), 'WHERE' => 'h.user_id = ' . (int) $this->user->data['user_id'], 'ORDER_BY' => 'time DESC');
            }
            $sql = $this->db->sql_build_query('SELECT', $sql_array);
            $result = $this->db->sql_query_limit($sql, $number, $start);
            $row_color = $start;
            while ($row = $this->db->sql_fetchrow($result)) {
                $row_color++;
                // Check, if winner is user
                if ($row['user_id'] != 0) {
                    $history_member = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
                } else {
                    $history_member = $this->user->lang['LOTTERY_NO_WINNER'];
                }
                $this->template->assign_block_vars('history_row', array('NUMBER' => $row_color, 'U_WINNER_PROFILE' => $history_member, 'WINNER_PROFILE' => $history_member, 'USERNAME' => $row['username'], 'WINNINGS' => sprintf($this->functions_points->number_format_points($row['amount'])), 'DATE' => $this->user->format_date($row['time']), 'ROW_COLOR' => $row_color));
                $this->template->assign_vars(array('U_VIEW_HISTORY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery', 'history' => 'all')), 'U_VIEW_SELF_HISTORY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery', 'history' => 'ego')), 'U_INFO' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'info')), 'U_TRANSFER_USER' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'transfer_user')), 'U_LOGS' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'logs')), 'U_LOTTERY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')), 'U_BANK' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'bank')), 'U_ROBBERY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'robbery'))));
            }
            //Start pagination
            $this->pagination->generate_template_pagination($this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery', 'history' => $history_mode)), 'pagination', 'start', $total_entries, $number, $start);
            // Viewing a history page
            $this->template->assign_vars(array('CASH_NAME' => $this->config['points_name'], 'PAGINATION' => $this->user->lang('POINTS_LOG_COUNT', $total_entries), 'LOTTERY_NAME' => $points_values['lottery_name'], 'BANK_NAME' => $points_values['bank_name'], 'S_VIEW_HISTORY' => true, 'U_BACK_TO_LOTTERY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')), 'U_VIEW_SELF_HISTORY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery', 'history' => 'ego')), 'U_TRANSFER_USER' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'transfer_user')), 'U_LOGS' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'logs')), 'U_LOTTERY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')), 'U_BANK' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'bank')), 'U_ROBBERY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'robbery'))));
        } else {
            // Show main lottery page
            $viewer_total_tickets = '';
            if ($this->user->data['user_id'] != ANONYMOUS) {
                //Select total tickets viewer owns
                $sql_array = array('SELECT' => 'COUNT(ticket_id) AS num_tickets', 'FROM' => array($this->points_lottery_tickets_table => 'h'), 'WHERE' => 'user_id = ' . (int) $this->user->data['user_id']);
                $sql = $this->db->sql_build_query('SELECT', $sql_array);
                $result = $this->db->sql_query($sql);
                $viewer_total_tickets = (int) $this->db->sql_fetchfield('num_tickets');
                $this->db->sql_freeresult($result);
            }
            // User color selection
            $sql_array = array('SELECT' => 'user_id, username, user_colour', 'FROM' => array(USERS_TABLE => 'u'), 'WHERE' => 'user_id = ' . (int) $points_values['lottery_prev_winner_id']);
            $sql = $this->db->sql_build_query('SELECT', $sql_array);
            $result = $this->db->sql_query($sql);
            $row = $this->db->sql_fetchrow($result);
            if ($row == null) {
                $username_colored = $this->user->lang['LOTTERY_NO_WINNER'];
            } else {
                $username_colored = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
            }
            // Check, if previous winner is a user
            if ($points_values['lottery_prev_winner_id'] != 0) {
                $link_member = append_sid("{$this->phpbb_root_path}memberlist.{$this->phpEx}", "mode=viewprofile&amp;u=" . $points_values['lottery_prev_winner_id']);
            } else {
                $link_member = '';
            }
            // Select the total number of tickets
            $sql_array = array('SELECT' => 'COUNT(ticket_id) AS no_of_tickets', 'FROM' => array($this->points_lottery_tickets_table => 't'));
            $sql = $this->db->sql_build_query('SELECT', $sql_array);
            $result = $this->db->sql_query($sql);
            $row = $this->db->sql_fetchrow($result);
            $no_of_tickets = $row['no_of_tickets'];
            $this->db->sql_freeresult($result);
            // Select the total number of players
            $sql_array = array('SELECT' => 'user_id', 'FROM' => array($this->points_lottery_tickets_table => 't'));
            $sql = $this->db->sql_build_query('SELECT_DISTINCT', $sql_array);
            $result = $this->db->sql_query($sql);
            $no_of_players = 0;
            while ($row = $this->db->sql_fetchrow($result)) {
                $no_of_players += 1;
            }
            $this->db->sql_freeresult($result);
            $this->template->assign_vars(array('JACKPOT' => sprintf($this->functions_points->number_format_points($points_values['lottery_jackpot']), $this->config['points_name']), 'POINTS_NAME' => $this->config['points_name'], 'TICKET_COST' => sprintf($this->functions_points->number_format_points($points_values['lottery_ticket_cost'])), 'PREVIOUS_WINNER' => $username_colored, 'NEXT_DRAWING' => $this->user->format_date($points_values['lottery_last_draw_time'] + $points_values['lottery_draw_period'], false, true), 'LOTTERY_NAME' => $points_values['lottery_name'], 'BANK_NAME' => $points_values['bank_name'], 'VIEWER_TICKETS_TOTAL' => $viewer_total_tickets, 'LOTTERY_TICKETS' => $no_of_tickets, 'LOTTERY_PLAYERS' => $no_of_players, 'MAX_TICKETS' => $points_values['lottery_max_tickets'], 'S_PURCHASE_SINGLE' => $viewer_total_tickets == 0 && $points_config['lottery_multi_ticket_enable'] == 0 && $points_config['lottery_enable'] == 1 ? true : false, 'S_PURCHASE_MULTI' => $viewer_total_tickets < $points_values['lottery_max_tickets'] && $points_config['lottery_multi_ticket_enable'] == 1 && $points_config['lottery_enable'] == 1 ? true : false, 'S_MULTI_TICKETS' => $points_config['lottery_multi_ticket_enable'] == 1 ? true : false, 'S_LOTTERY_ENABLE' => $points_config['lottery_enable'] == 1 ? true : false, 'S_DRAWING_ENABLED' => $points_values['lottery_draw_period'] ? true : false, 'U_PREVIOUS_WINNER' => $link_member, 'U_VIEW_HISTORY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery', 'history' => 'all')), 'U_VIEW_SELF_HISTORY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery', 'history' => 'ego')), 'U_TRANSFER_USER' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'transfer_user')), 'U_LOGS' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'logs')), 'U_LOTTERY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')), 'U_BANK' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'bank')), 'U_ROBBERY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'robbery')), 'U_INFO' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'info')), 'U_USE_TRANSFER' => $this->auth->acl_get('u_use_transfer'), 'U_USE_LOGS' => $this->auth->acl_get('u_use_logs'), 'U_USE_LOTTERY' => $this->auth->acl_get('u_use_lottery'), 'U_USE_BANK' => $this->auth->acl_get('u_use_bank'), 'U_USE_ROBBERY' => $this->auth->acl_get('u_use_robbery'), 'USER_POINTS' => sprintf($this->functions_points->number_format_points($checked_user['user_points']))));
        }
        // Generate the page header
        page_header($points_values['lottery_name']);
        // Generate the page template
        $this->template->set_filenames(array('body' => 'points/points_lottery.html'));
        page_footer();
    }
Beispiel #25
0
 public function viewUserFeedbackAction()
 {
     // Trigger an error if user does not have view feedback permissions
     if (!$this->manager->hasViewFeedbackPermission()) {
         trigger_error($this->user->lang('E_CANNOT_VIEW_FEEDBACK'));
     }
     $user_id = $this->request->variable('u', 0);
     $tab = $this->request->variable('tab', 'all');
     $start = $this->request->variable('start', 0);
     $is_edit_mod = $this->isEditMod();
     $action = $this->request->variable('action', 'list');
     if ($action == 'list') {
         $valid_tabs = array('all' => RatingsManager::TAB_TYPE_ALL, 'buy' => RatingsManager::TOPIC_TYPE_BUY, 'sell' => RatingsManager::TOPIC_TYPE_SELL, 'trade' => RatingsManager::TOPIC_TYPE_TRADE, 'left' => RatingsManager::TAB_TYPE_LEFT);
         if (!isset($valid_tabs[$tab])) {
             $tab = 'all';
         }
         if (!$user_id) {
             trigger_error("No user provided - cannot display Trader Feedback");
         }
         $user_page_row = $this->fetch_user_row($this->db, $user_id);
         if (!$user_page_row) {
             trigger_error("Could not find specified user!");
         }
         $trader_stats = $this->manager->getUserFeedbackStats($user_id, true);
         if (!$trader_stats) {
             trigger_error("Feedback Statistics could not be retrieved");
         }
         if ($tab == 'buy') {
             $filter = $valid_tabs['sell'];
         } else {
             if ($tab == 'sell') {
                 $filter = $valid_tabs['buy'];
             } else {
                 $filter = $valid_tabs[$tab];
             }
         }
         // stores the number of total feedbacks that are filtered on a given tab - for pagination purposes
         // this number is updated by reference by the call to the manager
         $num_feedbacks = 0;
         $feedbacks = $this->manager->get_users_feedback($start, self::NUM_PER_PAGE, $user_id, $filter, $is_edit_mod, $num_feedbacks);
         if ($this->user->data['user_timezone']) {
             $timezone = new \DateTimeZone($this->user->data['user_timezone']);
         } else {
             $timezone = new \DateTimeZone($this->config['board_timezone']);
         }
         foreach ($feedbacks as $key => $feedback) {
             // fetch the appropriate user's information based on the selected tab
             // if the tab is 'Left for Others' we need to use the to_user_id (the recipient)
             if ($tab == "left") {
                 $user_row = $this->fetch_user_row($this->db, $feedback['to_user_id']);
                 $view_feedback_url = $this->helper->route('rfd_trader_view', array('u' => $feedback['to_user_id']));
             } else {
                 $user_row = $this->fetch_user_row($this->db, $feedback['from_user_id']);
                 $view_feedback_url = $this->helper->route('rfd_trader_view', array('u' => $feedback['from_user_id']));
             }
             $feedback['U_VIEW_FEEDBACK'] = $view_feedback_url;
             $feedback['table_username'] = $user_row['username'];
             $feedback['table_user_trader_rating'] = $user_row['user_trader_positive'] - $user_row['user_trader_negative'];
             $feedback['show_left_for_others'] = $tab == "left";
             $comments = $this->manager->getLatestFeedbackComment($feedback['feedback_id']);
             if ($comments) {
                 $feedback['short_comment'] = $comments['short_comment'];
                 if ($is_edit_mod || $feedback['from_user_id'] == $this->user->data['user_id'] || $feedback['to_user_id'] == $this->user->data['user_id']) {
                     $feedback['long_comment'] = $comments['long_comment'];
                 }
             }
             if ($is_edit_mod || $this->canEditFeedback($feedback['date_created'], $feedback['from_user_id'])) {
                 $edit_feedback_url = $this->helper->route('rfd_trader_edit_feedback', array('feedback_id' => $feedback['feedback_id'], 'u' => $user_id));
                 $feedback['U_EDIT_FEEDBACK'] = $edit_feedback_url;
             }
             if ($this->canReplyToFeedback($feedback['from_user_id'], $feedback['to_user_id'], $feedback['topic_id'])) {
                 $feedback['U_REPLY_FEEDBACK'] = $this->helper->route('rfd_trader_feedback', array('reply_id' => $feedback['feedback_id'], 'u' => $user_id));
             }
             $has_open_report = $this->manager->has_open_report($feedback['feedback_id']);
             // Show report button if the feedback is for the current user viewing the page
             if ($feedback['to_user_id'] == $this->user->data['user_id'] && !$has_open_report) {
                 $feedback['U_REPORT_FEEDBACK'] = append_sid(generate_board_url() . '/trader/view-feedback/?action=report&amp;id=' . $feedback['feedback_id']);
             }
             $feedback['topic_url'] = append_sid(generate_board_url() . "/viewtopic.php?t=" . $feedback['topic_id']);
             $feedback['date_created'] = new \DateTime('@' . $feedback['date_created']);
             $feedback['date_created']->setTimezone($timezone);
             $feedbacks[$key] = $feedback;
         }
         $trader_username_full = get_username_string('full', $user_page_row['user_id'], $user_page_row['username'], $user_page_row['user_colour']);
         $this->template->assign_vars(array('TRADER_USERNAME_FULL' => $trader_username_full, 'TRADER_USERNAME' => $user_page_row['username'], 'U_TRADER_PROFILE' => append_sid("{$this->phpbb_root_path}memberlist.{$this->phpEx}", 'mode=viewprofile&amp;u=' . $user_page_row['user_id']), 'trader_stats' => $trader_stats, 'recent_feedback' => $this->manager->getRecentUserFeedbackCounts($user_id), 'U_ACTION_TAB_ALL' => $this->helper->route("rfd_trader_view", array('u' => $user_id, 'tab' => 'all')), 'U_ACTION_TAB_BUY' => $this->helper->route("rfd_trader_view", array('u' => $user_id, 'tab' => 'buy')), 'U_ACTION_TAB_SELL' => $this->helper->route("rfd_trader_view", array('u' => $user_id, 'tab' => 'sell')), 'U_ACTION_TAB_TRADE' => $this->helper->route("rfd_trader_view", array('u' => $user_id, 'tab' => 'trade')), 'U_ACTION_TAB_LEFT' => $this->helper->route("rfd_trader_view", array('u' => $user_id, 'tab' => 'left')), 'CURRENT_TAB' => $tab, 'feedbacks' => $feedbacks, 'TOTAL_FEEDBACKS' => $num_feedbacks));
         $base_url = $this->helper->route('rfd_trader_view', array('u' => $user_id));
         $this->pagination->generate_template_pagination($base_url, 'pagination', 'start', $num_feedbacks, self::NUM_PER_PAGE, $start);
     } else {
         if ($action == 'report') {
             $this->report_feedback_action($this->request, $this->user);
         } else {
             trigger_error("Unknown Action!");
         }
     }
     return $this->helper->render('view_user_feedback.html', $this->user->lang['TRADER_FEEDBACK_FOR'] . '&nbsp;' . $user_page_row['username']);
 }
Beispiel #26
0
    private function view($cat_id, $topic_id = 0)
    {
        $start = $this->request->variable('start', 0);
        $sort_key = $this->request->variable('sk', 'a');
        $sort_dir = $this->request->variable('sd', 'a');
        // Select box eventually
        $sort_key_text = array('a' => $this->user->lang['SORT_FILENAME'], 'b' => $this->user->lang['SORT_COMMENT'], 'c' => $this->user->lang['SORT_EXTENSION'], 'd' => $this->user->lang['SORT_SIZE'], 'e' => $this->user->lang['SORT_DOWNLOADS'], 'f' => $this->user->lang['SORT_POST_TIME'], 'g' => $this->user->lang['SORT_TOPIC_TITLE']);
        $sort_key_sql = array('a' => 'a.real_filename', 'b' => 'a.attach_comment', 'c' => 'a.extension', 'd' => 'a.filesize', 'e' => 'a.download_count', 'f' => 'a.filetime', 'g' => 't.topic_title');
        $sort_dir_text = array('a' => $this->user->lang['ASCENDING'], 'd' => $this->user->lang['DESCENDING']);
        $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>';
        }
        if (!isset($sort_key_sql[$sort_key])) {
            $sort_key = 'a';
        }
        $order_by = $sort_key_sql[$sort_key] . ' ' . ($sort_dir == 'a' ? 'ASC' : 'DESC');
        if ($cat_id) {
            $sql_topic = $topic_id ? " AND a.topic_id = " . (int) $topic_id : '';
            $sql = "SELECT e.extension, COUNT(a.attach_id) AS num_attachments\n\t\t\t\tFROM " . EXTENSIONS_TABLE . " e, " . ATTACHMENTS_TABLE . " a\n\t\t\t\tWHERE e.group_id = " . (int) $cat_id . "\n\t\t\t\t\t{$sql_topic}\n\t\t\t\t\tAND a.extension = e.extension\n\t\t\t\t\tAND a.is_orphan = 0\n\t\t\t\t\tAND a.in_message = 0\n\t\t\t\tGROUP BY a.extension";
            $result = $this->db->sql_query($sql);
            $extension = array();
            while ($row = $this->db->sql_fetchrow($result)) {
                $extension[] = $row['extension'];
                $num_attachments = isset($num_attachments) ? $num_attachments + $row['num_attachments'] : $row['num_attachments'];
            }
            $this->db->sql_freeresult($result);
            if (!sizeof($extension)) {
                return;
            }
            $sql_where = 'WHERE ' . $this->db->sql_in_set('a.extension', $extension);
            $sql_where .= $sql_topic . ' AND a.in_message = 0';
        } else {
            $sql_where = $topic_id ? "WHERE a.topic_id = " . (int) $topic_id . " AND " : "WHERE ";
            $sql_where = "{$sql_where} a.in_message = 0";
            $sql = 'SELECT COUNT(attach_id) as num_attachments
				FROM ' . ATTACHMENTS_TABLE . " a\n\t\t\t\t{$sql_where}\n\t\t\t\t\tAND a.is_orphan = 0";
            $result = $this->db->sql_query($sql);
            $num_attachments = $this->db->sql_fetchfield('num_attachments');
            $this->db->sql_freeresult($result);
        }
        // Ensure start is a valid value
        $start = $this->pagination->validate_start($start, $this->config['topics_per_page'], $num_attachments);
        $sql = 'SELECT a.*, t.forum_id, t.topic_title
			FROM ' . ATTACHMENTS_TABLE . ' a
				LEFT JOIN ' . TOPICS_TABLE . ' t ON (a.topic_id = t.topic_id AND a.in_message = 0)
			' . $sql_where . "\n\t\t\t\tAND a.is_orphan = 0\n\t\t\tORDER BY {$order_by}";
        $result = $this->db->sql_query_limit($sql, $this->config['topics_per_page'], $start);
        $row_count = 0;
        while ($row = $this->db->sql_fetchrow($result)) {
            $view_topic = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", "t={$row['topic_id']}&amp;p={$row['post_msg_id']}") . "#p{$row['post_msg_id']}";
            $this->template->assign_block_vars('attachrow', array('ROW_NUMBER' => $row_count + ($start + 1), 'FILENAME' => $row['real_filename'], 'COMMENT' => bbcode_nl2br($row['attach_comment']), 'EXTENSION' => $row['extension'], 'SIZE' => get_formatted_filesize($row['filesize']), 'DOWNLOAD_COUNT' => $row['download_count'], 'POST_TIME' => $this->user->format_date($row['filetime']), 'TOPIC_TITLE' => $row['topic_title'], 'ATTACH_ID' => $row['attach_id'], 'POST_ID' => $row['post_msg_id'], 'TOPIC_ID' => $row['topic_id'], 'AUTH_DOWNLOAD' => $this->auth->acl_get('f_download', $row['forum_id']), 'U_VIEW_ATTACHMENT' => $this->helper->route("bb3mobi_attach_file", array('attach_id' => $row['attach_id'])), 'U_DOWN_ATTACHMENT' => append_sid("{$this->phpbb_root_path}download/file.{$this->php_ext}", 'id=' . $row['attach_id']), 'U_VIEW_TOPIC' => $view_topic));
            $row_count++;
        }
        $this->db->sql_freeresult($result);
        if ($cat_id) {
            $route = "bb3mobi_attach_view";
            $view_ary = array('cat_id' => $cat_id);
            $view_ary += $topic_id ? array('t' => $topic_id) : array();
        } else {
            $route = "bb3mobi_attach_cat";
            $view_ary = $topic_id ? array('t' => $topic_id) : array();
        }
        $base_url = $this->helper->route($route, array_merge($view_ary, array('sk' => $sort_key, 'sd' => $sort_dir)));
        $this->pagination->generate_template_pagination($base_url, 'pagination', 'start', $num_attachments, $this->config['topics_per_page'], $start);
        if ($start) {
            $view_ary = array_merge($view_ary, array('start' => $start));
        }
        $this->template->assign_vars(array('DESCRIPTION' => $this->user->lang('ATTACHMENTS_EXPLAIN'), 'NUM_ATTACHMENTS' => $this->user->lang('NUM_ATTACHMENTS', $num_attachments), 'ATTACHMENTS_BY' => $row_count ? $this->user->lang('ATTACHMENTS_BY', '<a href="http://bb3.mobi">Download by</a>') : '', 'CAT_ID' => $cat_id, 'U_CANONICAL' => $this->helper->route($route, $view_ary, false, '', true), 'U_SORT_FILENAME' => $this->helper->route($route, array_merge($view_ary, array('sk' => 'a', 'sd' => $sort_key == 'a' && $sort_dir == 'a' ? 'd' : 'a'))), 'U_SORT_FILE_COMMENT' => $this->helper->route($route, array_merge($view_ary, array('sk' => 'b', 'sd' => $sort_key == 'b' && $sort_dir == 'a' ? 'd' : 'a'))), 'U_SORT_EXTENSION' => $this->helper->route($route, array_merge($view_ary, array('sk' => 'c', 'sd' => $sort_key == 'c' && $sort_dir == 'a' ? 'd' : 'a'))), 'U_SORT_FILESIZE' => $this->helper->route($route, array_merge($view_ary, array('sk' => 'd', 'sd' => $sort_key == 'd' && $sort_dir == 'a' ? 'd' : 'a'))), 'U_SORT_DOWNLOADS' => $this->helper->route($route, array_merge($view_ary, array('sk' => 'e', 'sd' => $sort_key == 'e' && $sort_dir == 'a' ? 'd' : 'a'))), 'U_SORT_POST_TIME' => $this->helper->route($route, array_merge($view_ary, array('sk' => 'f', 'sd' => $sort_key == 'f' && $sort_dir == 'a' ? 'd' : 'a'))), 'U_SORT_TOPIC_TITLE' => $this->helper->route($route, array_merge($view_ary, array('sk' => 'g', 'sd' => $sort_key == 'g' && $sort_dir == 'a' ? 'd' : 'a'))), 'S_DISPLAY_MARK_ALL' => $num_attachments ? true : false, 'S_DISPLAY_PAGINATION' => $num_attachments ? true : false, 'S_ATTACH_ACTION' => $this->helper->route($route, $view_ary), 'S_SORT_OPTIONS' => $s_sort_key, 'S_ORDER_SELECT' => $s_sort_dir));
        return $start ? ' - ' . $this->user->lang('PAGE_TITLE_NUMBER', $this->pagination->get_on_page($this->config['topics_per_page'], $start)) : '';
    }
Beispiel #27
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';
        }
    }
    /**
     * View controller for display a category
     *
     * @param	int		$cat_id		The category ID
     * @param	int		$page		Page number taken from the URL
     * @param	int		$sort_days	Specifies the maximum amount of days a link may be old
     * @param	string	$sort_key	is the key of $sort_by_sql for the selected sorting: a|t|r|s|v|p
     * @param	string	$sort_dir	is either a or d representing ASC and DESC (ascending|descending)
     * @param	string	$mode		watch|unwatch
     * @return	\Symfony\Component\HttpFoundation\Response	A Symfony Response object
     * @throws	\phpbb\exception\http_exception
     */
    public function view($cat_id, $page, $sort_days, $sort_key, $sort_dir, $mode = '')
    {
        if (false === $this->categorie->get($cat_id)) {
            throw new \phpbb\exception\http_exception(404, 'DIR_ERROR_NO_CATS');
        }
        $start = ($page - 1) * $this->config['dir_show'];
        $default_sort_days = 0;
        $default_sort_key = (string) substr($this->config['dir_default_order'], 0, 1);
        $default_sort_dir = (string) substr($this->config['dir_default_order'], 2);
        $sort_days = !$sort_days ? $this->request->variable('st', $default_sort_days) : $sort_days;
        $sort_key = !$sort_key ? $this->request->variable('sk', $default_sort_key) : $sort_key;
        $sort_dir = !$sort_dir ? $this->request->variable('sd', $default_sort_dir) : $sort_dir;
        $link_list = $rowset = array();
        // Categorie ordering options
        $limit_days = array(0 => $this->user->lang['SEE_ALL'], 1 => $this->user->lang['1_DAY'], 7 => $this->user->lang['7_DAYS'], 14 => $this->user->lang['2_WEEKS'], 30 => $this->user->lang['1_MONTH'], 90 => $this->user->lang['3_MONTHS'], 180 => $this->user->lang['6_MONTHS'], 365 => $this->user->lang['1_YEAR']);
        $sort_by_text = array('a' => $this->user->lang['AUTHOR'], 't' => $this->user->lang['POST_TIME'], 'r' => $this->user->lang['DIR_COMMENTS_ORDER'], 's' => $this->user->lang['DIR_NAME_ORDER'], 'v' => $this->user->lang['DIR_NB_CLICKS_ORDER']);
        $sort_by_sql = array('a' => 'u.username_clean', 't' => array('l.link_time', 'l.link_id'), 'r' => 'l.link_comment', 's' => 'LOWER(l.link_name)', 'v' => 'l.link_view');
        if ($this->config['dir_activ_pagerank']) {
            $sort_by_text['p'] = $this->user->lang['DIR_PR_ORDER'];
            $sort_by_sql['p'] = 'l.link_pagerank';
        }
        $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
        gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param, $default_sort_days, $default_sort_key, $default_sort_dir);
        $u_sort_param = $sort_days === $default_sort_days && $sort_key == $default_sort_key && $sort_dir == $default_sort_dir ? array() : array('sort_days' => $sort_days, 'sort_key' => $sort_key, 'sort_dir' => $sort_dir);
        // Are we watching this categorie?
        $s_watching_categorie = array('link' => '', 'link_toggle' => '', 'title' => '', 'title_toggle' => '', 'is_watching' => false);
        if ($this->config['email_enable'] && $this->user->data['is_registered']) {
            $notify_status = isset($this->categorie->data['notify_status']) ? $this->categorie->data['notify_status'] : null;
            if ($message = $this->categorie->watch_categorie($mode, $s_watching_categorie, $this->user->data['user_id'], $cat_id, $notify_status)) {
                return $this->helper->message($message);
            }
        }
        // A deadline has been selected
        if ($sort_days) {
            $min_post_time = time() - $sort_days * 86400;
            $sql = 'SELECT COUNT(link_id) AS nb_links
				FROM ' . DIR_LINK_TABLE . '
				WHERE link_cat = ' . (int) $cat_id . '
					AND link_time >= ' . $min_post_time;
            $result = $this->db->sql_query($sql);
            $nb_links = (int) $this->db->sql_fetchfield('nb_links');
            $this->db->sql_freeresult($result);
            if ($this->request->is_set_post('sort')) {
                $start = 0;
            }
            $sql_limit_time = " AND l.link_time >= {$min_post_time}";
        } else {
            $sql_limit_time = '';
            $nb_links = (int) $this->categorie->data['cat_links'];
        }
        // Make sure $start is set to the last page if it exceeds the amount
        $start = $this->pagination->validate_start($start, $this->config['dir_show'], $nb_links);
        // Build navigation links
        $this->categorie->generate_dir_nav($this->categorie->data);
        // Jumpbox
        $this->categorie->make_cat_jumpbox();
        $base_url = array('routes' => 'ernadoo_phpbbdirectory_page_controller', 'params' => array_merge(array('cat_id' => $cat_id), $u_sort_param));
        $this->pagination->generate_template_pagination($base_url, 'pagination', 'page', $nb_links, $this->config['dir_show'], $start);
        $this->template->assign_vars(array('S_SELECT_SORT_DIR' => $s_sort_dir, 'S_SELECT_SORT_KEY' => $s_sort_key, 'S_SELECT_SORT_DAYS' => $s_limit_days, 'S_CATLIST' => $this->categorie->make_cat_select($cat_id), 'S_PAGE_ACTION' => $this->helper->route('ernadoo_phpbbdirectory_page_controller', array('cat_id' => $cat_id, 'page' => $page)), 'S_CAT_ID' => $cat_id, 'TOTAL_LINKS' => $this->user->lang('DIR_NB_LINKS', (int) $nb_links), 'U_NEW_SITE' => $this->helper->route('ernadoo_phpbbdirectory_new_controller', array('cat_id' => $cat_id)), 'U_WATCH_CAT' => $s_watching_categorie['link'], 'U_WATCH_CAT_TOGGLE' => $s_watching_categorie['link_toggle'], 'S_WATCH_CAT_TITLE' => $s_watching_categorie['title'], 'S_WATCH_CAT_TOGGLE' => $s_watching_categorie['title_toggle'], 'S_WATCHING_CAT' => $s_watching_categorie['is_watching']));
        // If the user is trying to reach late pages, start searching from the end
        $store_reverse = false;
        $sql_limit = $this->config['dir_show'];
        if ($start > $nb_links / 2) {
            $store_reverse = true;
            // Select the sort order
            $direction = $sort_dir == 'd' ? 'ASC' : 'DESC';
            $sql_limit = $this->pagination->reverse_limit($start, $sql_limit, $nb_links);
            $sql_start = $this->pagination->reverse_start($start, $sql_limit, $nb_links);
        } else {
            // Select the sort order
            $direction = $sort_dir == 'd' ? 'DESC' : 'ASC';
            $sql_start = $start;
        }
        if (is_array($sort_by_sql[$sort_key])) {
            $sql_sort_order = implode(' ' . $direction . ', ', $sort_by_sql[$sort_key]) . ' ' . $direction;
        } else {
            $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . $direction;
        }
        // Grab just the sorted link ids
        $sql_array = array('SELECT' => 'l.link_id', 'FROM' => array(DIR_LINK_TABLE => 'l'), 'LEFT_JOIN' => array(array('FROM' => array(USERS_TABLE => 'u'), 'ON' => 'l.link_user_id = u.user_id')), 'WHERE' => "l.link_cat = {$cat_id}\n\t\t\t\tAND l.link_active = 1\n\t\t\t\t\t{$sql_limit_time}", 'ORDER_BY' => $sql_sort_order);
        $sql = $this->db->sql_build_query('SELECT', $sql_array);
        $result = $this->db->sql_query_limit($sql, $sql_limit, $sql_start);
        while ($row = $this->db->sql_fetchrow($result)) {
            $link_list[] = (int) $row['link_id'];
        }
        $this->db->sql_freeresult($result);
        if (sizeof($link_list)) {
            // We get links, informations about poster, votes and number of comments
            $sql_array = array('SELECT' => 'l.link_id, l.link_cat, l.link_url, l.link_user_id, l.link_comment, l. link_description, l.link_banner, l.link_rss, l. link_uid, l.link_bitfield, l.link_flags, l.link_vote, l.link_note, l.link_view, l.link_time, l.link_name, l.link_flag, l.link_pagerank, l.link_thumb, u.user_id, u.username, u.user_colour, v.vote_user_id', 'FROM' => array(DIR_LINK_TABLE => 'l'), 'LEFT_JOIN' => array(array('FROM' => array(USERS_TABLE => 'u'), 'ON' => 'l.link_user_id = u.user_id'), array('FROM' => array(DIR_VOTE_TABLE => 'v'), 'ON' => 'l.link_id = v.vote_link_id AND v.vote_user_id = ' . $this->user->data['user_id'])), 'WHERE' => $this->db->sql_in_set('l.link_id', $link_list));
            $sql = $this->db->sql_build_query('SELECT', $sql_array);
            $result = $this->db->sql_query($sql);
            while ($site = $this->db->sql_fetchrow($result)) {
                $rowset[$site['link_id']] = $site;
            }
            $this->db->sql_freeresult($result);
            $link_list = $store_reverse ? array_reverse($link_list) : $link_list;
            $votes_status = $this->categorie->data['cat_allow_votes'] ? true : false;
            $comments_status = $this->categorie->data['cat_allow_comments'] ? true : false;
            foreach ($link_list as $link_id) {
                $site =& $rowset[$link_id];
                $s_flag = $this->link->display_flag($site);
                $s_note = $this->link->display_note($site['link_note'], $site['link_vote'], $votes_status);
                $s_thumb = $this->link->display_thumb($site);
                $s_vote = $this->link->display_vote($site);
                $s_banner = $this->link->display_bann($site);
                $s_pr = $this->link->display_pagerank($site);
                $s_rss = $this->link->display_rss($site);
                $edit_allowed = $this->user->data['is_registered'] && ($this->auth->acl_get('m_edit_dir') || $this->user->data['user_id'] == $site['link_user_id'] && $this->auth->acl_get('u_edit_dir'));
                $delete_allowed = $this->user->data['is_registered'] && ($this->auth->acl_get('m_delete_dir') || $this->user->data['user_id'] == $site['link_user_id'] && $this->auth->acl_get('u_delete_dir'));
                $this->template->assign_block_vars('site', array('BANNER' => $s_banner, 'COUNT' => $this->user->lang('DIR_NB_CLICKS', (int) $site['link_view']), 'DESCRIPTION' => generate_text_for_display($site['link_description'], $site['link_uid'], $site['link_bitfield'], $site['link_flags']), 'LINK_ID' => $site['link_id'], 'NAME' => $site['link_name'], 'NB_COMMENT' => $comments_status ? $this->user->lang('DIR_NB_COMMS', (int) $site['link_comment']) : '', 'NB_VOTE' => $this->user->lang('DIR_NB_VOTES', (int) $site['link_vote']), 'NOTE' => $s_note, 'PAGERANK' => $s_pr, 'RSS' => $s_rss, 'TIME' => $site['link_time'] ? $this->user->format_date($site['link_time']) : '', 'USER' => get_username_string('full', $site['link_user_id'], $site['username'], $site['user_colour']), 'VOTE_LIST' => $votes_status ? $s_vote : '', 'IMG_FLAG' => $s_flag, 'ON_CLICK' => "onclick=\"window.open('" . $this->helper->route('ernadoo_phpbbdirectory_view_controller', array('link_id' => (int) $site['link_id'])) . "'); return false;\"", 'S_NEW_LINK' => (time() - $site['link_time']) / 86400 <= $this->config['dir_new_time'] ? true : false, 'U_COMMENT' => $comments_status ? $this->helper->route('ernadoo_phpbbdirectory_comment_view_controller', array('link_id' => (int) $site['link_id'])) : '', 'U_DELETE' => $delete_allowed ? $this->helper->route('ernadoo_phpbbdirectory_delete_controller', array('cat_id' => (int) $cat_id, 'link_id' => (int) $site['link_id'], '_referer' => $this->helper->get_current_url())) : '', 'U_EDIT' => $edit_allowed ? $this->helper->route('ernadoo_phpbbdirectory_edit_controller', array('cat_id' => (int) $cat_id, 'link_id' => (int) $site['link_id'])) : '', 'U_FORM_VOTE' => $votes_status ? $this->helper->route('ernadoo_phpbbdirectory_vote_controller', array('cat_id' => (int) $site['link_cat'], 'link_id' => (int) $site['link_id'])) : '', 'U_LINK' => $site['link_url'], 'U_THUMB' => $s_thumb));
            }
        } else {
            $this->template->assign_block_vars('no_draw_link', array());
        }
        $page_title = $this->user->lang['DIRECTORY'] . ' - ' . $this->categorie->data['cat_name'];
        $this->categorie->display();
        return $this->helper->render('view_cat.html', $page_title);
    }
    /**
     * Display the output for this extension
     *
     * @return null
     * @access public
     */
    public function display_output()
    {
        // Add the language file
        $this->language->add_lang('acp_pmmonitor', 'david63/pmmonitor');
        // Check that the user has permission to access here
        if (!$this->auth->acl_get('a_comms_pm_manage')) {
            trigger_error('NOT_AUTHORISED', E_USER_WARNING);
        }
        // Get message count
        $sql = 'SELECT COUNT(msg_id) AS total_msg
			FROM ' . PRIVMSGS_TO_TABLE;
        $result = $this->db->sql_query($sql);
        $total_msg = (int) $this->db->sql_fetchfield('total_msg');
        $this->db->sql_freeresult($result);
        // If no data then no point going any further
        if ($total_msg == 0) {
            trigger_error($this->language->lang('NO_PM_DATA'));
        }
        // Start initial var setup
        $start = $this->request->variable('start', 0);
        $sort_key = $this->request->variable('sk', 'd');
        $sd = $sort_dir = $this->request->variable('sd', 'd');
        if ($this->request->is_set_post('delete')) {
            $pm_monitor_list = $this->request->variable('mark', array(''));
            if (!sizeof($pm_monitor_list)) {
                trigger_error($this->language->lang('NO_PM_SELECTED') . adm_back_link($this->u_action));
            }
            if (confirm_box(true)) {
                // Restore the array to its correct format
                $pm_monitor_list = str_replace("'", '"', $pm_monitor_list);
                foreach ($pm_monitor_list as $pm_msg_list) {
                    $pm_list[] = json_decode($pm_msg_list);
                }
                if (!function_exists('delete_pm')) {
                    include $this->phpbb_root_path . 'includes/functions_privmsgs.' . $this->phpEx;
                }
                foreach ($pm_list as $row) {
                    delete_pm($row['user_id'], $row['msg_ids'], $row['folder_id']);
                }
                // Add option settings change action to the admin log
                $phpbb_log = $this->container->get('log');
                $phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_PM_MONITOR');
            } else {
                confirm_box(false, $this->language->lang('CONFIRM_DELETE'), build_hidden_fields(array('mark' => $pm_monitor_list, 'delete' => 'delete')));
            }
        }
        $sort_dir = $sort_dir == 'd' ? ' DESC' : ' ASC';
        switch ($sort_key) {
            case 'b':
                $order_by = 'u.username_clean' . $sort_dir;
                $order_sql = ' AND t.user_id = u.user_id ';
                break;
            case 'd':
                $order_by = 'p.message_time' . $sort_dir;
                $order_sql = ' AND t.user_id = u.user_id ';
                break;
            case 'f':
                $order_by = 'u.username_clean' . $sort_dir;
                $order_sql = ' AND t.author_id = u.user_id ';
                break;
            case 'i':
                $order_by = 'p.author_ip' . $sort_dir . ', u.username_clean ASC';
                $order_sql = ' AND t.user_id = u.user_id ';
                break;
            case 'p':
                $order_by = 't.folder_id' . $sort_dir . ', u.username_clean ASC';
                $order_sql = ' AND t.user_id = u.user_id ';
                break;
            case 't':
                $order_by = 'to_username' . $sort_dir;
                $order_sql = ' AND t.user_id = u.user_id ';
                break;
        }
        $pm_box_ary = array(PRIVMSGS_HOLD_BOX => $this->language->lang('PM_HOLDBOX'), PRIVMSGS_NO_BOX => $this->language->lang('PM_NOBOX'), PRIVMSGS_OUTBOX => $this->language->lang('PM_OUTBOX'), PRIVMSGS_SENTBOX => $this->language->lang('PM_SENTBOX'), PRIVMSGS_INBOX => $this->language->lang('PM_INBOX'));
        $flags = ($this->config['auth_bbcode_pm'] ? OPTION_FLAG_BBCODE : 0) + ($this->config['auth_smilies_pm'] ? OPTION_FLAG_SMILIES : 0) + ($this->config['allow_post_links'] ? OPTION_FLAG_LINKS : 0);
        $sql = 'SELECT p.msg_id, p.message_subject, p.message_text, p.bbcode_uid, p.bbcode_bitfield, p.message_time, p.bcc_address, p.to_address, p.author_ip, t.user_id, t.author_id, t.folder_id, LOWER(u.username) AS to_username
			FROM ' . PRIVMSGS_TABLE . ' p, ' . PRIVMSGS_TO_TABLE . ' t, ' . USERS_TABLE . ' u
			WHERE p.msg_id = t.msg_id ' . $order_sql . '
			ORDER BY ' . $order_by;
        $result = $this->db->sql_query_limit($sql, $this->config['topics_per_page'], $start);
        while ($row = $this->db->sql_fetchrow($result)) {
            $this->template->assign_block_vars('pm_row', array('AUTHOR_IP' => $row['author_ip'], 'BCC' => $row['bcc_address'] ? $this->get_msg_user_data($row['user_id'], $row['author_id']) : '', 'DATE' => $this->user->format_date($row['message_time']), 'FOLDER' => $row['folder_id'] > PRIVMSGS_INBOX ? $this->language->lang('PM_SAVED') : $pm_box_ary[$row['folder_id']], 'FROM' => $this->get_msg_user_data($row['author_id']), 'IS_GROUP' => strstr($row['to_address'], 'g') ? $this->language->lang('IS_GROUP') : '', 'LAST_VISIT_FROM' => $this->get_last_visit($row['author_id']), 'LAST_VISIT_TO' => $row['to_address'] ? $this->get_last_visit($row['user_id'], $row['author_id']) : '', 'PM_ID' => str_replace('"', "'", json_encode(array('msg_ids' => $row['msg_id'], 'user_id' => $row['user_id'], 'folder_id' => $row['folder_id']))), 'PM_KEY' => $row['msg_id'] . $row['user_id'], 'PM_SUBJECT' => $row['message_subject'], 'PM_TEXT' => generate_text_for_display($row['message_text'], $row['bbcode_uid'], $row['bbcode_bitfield'], $flags), 'TO' => $row['to_address'] ? $this->get_msg_user_data($row['user_id'], $row['author_id']) : ''));
        }
        $this->db->sql_freeresult($result);
        $sort_by_text = array('f' => $this->language->lang('SORT_FROM'), 't' => $this->language->lang('SORT_TO'), 'b' => $this->language->lang('SORT_BCC'), 'p' => $this->language->lang('SORT_PM_BOX'), 'i' => $this->language->lang('SORT_IP'), 'd' => $this->language->lang('SORT_DATE'));
        $limit_days = array();
        $s_sort_key = $s_limit_days = $s_sort_dir = $u_sort_param = '';
        gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sd, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
        $action = $this->u_action . '&amp;sk=' . $sort_key . '&amp;sd=' . $sd;
        $this->pagination->generate_template_pagination($action, 'pagination', 'start', $total_msg, $this->config['topics_per_page'], $start);
        $this->template->assign_vars(array('MESSAGE_COUNT' => $total_msg, 'PM_MONITOR_VERSION' => ext::PM_MONITOR_VERSION, 'S_CAN_READ' => $this->auth->acl_get('a_comms_pm_manage') ? true : false, 'S_SORT_KEY' => $s_sort_key, 'S_SORT_DIR' => $s_sort_dir, 'U_ACTION' => $this->u_action . '&amp;action=delete'));
    }
    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);
    }