Beispiel #1
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)) : '';
    }