forked from featherbb/featherbb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewforum.php
More file actions
102 lines (84 loc) · 4.44 KB
/
Copy pathviewforum.php
File metadata and controls
102 lines (84 loc) · 4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/**
* Copyright (C) 2015 FeatherBB
* based on code by (C) 2008-2012 FluxBB
* and Rickard Andersson (C) 2002-2008 PunBB
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
*/
namespace controller;
class viewforum
{
public function __construct()
{
$this->feather = \Slim\Slim::getInstance();
$this->model = new \model\viewforum();
load_textdomain('featherbb', FEATHER_ROOT.'lang/'.$this->feather->user->language.'/forum.mo');
}
public function __autoload($class_name)
{
require FEATHER_ROOT . $class_name . '.php';
}
public function display($id, $name = null, $page = null)
{
if ($this->feather->user->g_read_board == '0') {
throw new \FeatherBB\Error(__('No view'), 403);
}
if ($id < 1) {
throw new \FeatherBB\Error(__('Bad request'), 404);
}
// Fetch some informations about the forum
$cur_forum = $this->model->get_info_forum($id);
// Is this a redirect forum? In that case, redirect!
if ($cur_forum['redirect_url'] != '') {
header('Location: '.$cur_forum['redirect_url']);
exit;
}
// Sort out who the moderators are and if we are currently a moderator (or an admin)
$mods_array = ($cur_forum['moderators'] != '') ? unserialize($cur_forum['moderators']) : array();
$is_admmod = ($this->feather->user->g_id == FEATHER_ADMIN || ($this->feather->user->g_moderator == '1' && array_key_exists($this->feather->user->username, $mods_array))) ? true : false;
$sort_by = $this->model->sort_forum_by($cur_forum['sort_by']);
// Can we or can we not post new topics?
if (($cur_forum['post_topics'] == '' && $this->feather->user->g_post_topics == '1') || $cur_forum['post_topics'] == '1' || $is_admmod) {
$post_link = "\t\t\t".'<p class="postlink conr"><a href="'.$this->feather->url->get('post/new-topic/'.$id.'/').'">'.__('Post topic').'</a></p>'."\n";
} else {
$post_link = '';
}
// Determine the topic offset (based on $page)
$num_pages = ceil($cur_forum['num_topics'] / $this->feather->user->disp_topics);
$p = (!isset($page) || $page <= 1 || $page > $num_pages) ? 1 : intval($page);
$start_from = $this->feather->user->disp_topics * ($p - 1);
$url_forum = $this->feather->url->url_friendly($cur_forum['forum_name']);
// Generate paging links
$paging_links = '<span class="pages-label">'.__('Pages').' </span>'.$this->feather->url->paginate($num_pages, $p, 'forum/'.$id.'/'.$url_forum.'/#');
$forum_actions = $this->model->get_forum_actions($id, $this->feather->forum_settings['o_forum_subscriptions'], $cur_forum['is_subscribed']);
$this->feather->view2->addAsset('canonical', $this->feather->url->get('forum/'.$id.'/'.$url_forum.'/'));
if ($num_pages > 1) {
if ($p > 1) {
$this->feather->view2->addAsset('prev', $this->feather->url->get('forum/'.$id.'/'.$url_forum.'/page/'.($p - 1).'/'));
}
if ($p < $num_pages) {
$this->feather->view2->addAsset('next', $this->feather->url->get('forum/'.$id.'/'.$url_forum.'/page/'.($p + 1).'/'));
}
}
if ($this->feather->forum_settings['o_feed_type'] == '1') {
$this->feather->view2->addAsset('feed', 'extern.php?action=feed&fid='.$id.'&type=rss', array('title' => __('RSS forum feed')));
} elseif ($this->feather->forum_settings['o_feed_type'] == '2') {
$this->feather->view2->addAsset('feed', 'extern.php?action=feed&fid='.$id.'&type=atom', array('title' => __('Atom forum feed')));
}
$this->feather->view2->setPageInfo(array(
'title' => array($this->feather->utils->escape($this->feather->forum_settings['o_board_title']), $this->feather->utils->escape($cur_forum['forum_name'])),
'active_page' => 'viewforum',
'page_number' => $p,
'paging_links' => $paging_links,
'is_indexed' => true,
'id' => $id,
'fid' => $id,
'forum_data' => $this->model->print_topics($id, $sort_by, $start_from),
'cur_forum' => $cur_forum,
'post_link' => $post_link,
'start_from' => $start_from,
'url_forum' => $url_forum,
'forum_actions' => $forum_actions,
))->addTemplate('viewforum.php')->display();
}
}