/**
     * 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));
    }
 /**
  * @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 #6
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']);
    }
    /**
     * 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);
    }
Beispiel #8
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)) : '';
    }