forked from f446843/banshee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
forum.php
175 lines (149 loc) · 5.61 KB
/
forum.php
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
class forum_controller extends controller {
private $url = null;
private function show_forum_overview() {
if (($forums = $this->model->get_forums()) === false) {
$this->output->add_tag("result", "Database error.", $this->url);
} else {
$this->output->open_tag("forums");
foreach ($forums as $forum) {
$this->output->record($forum, "forum");
}
$this->output->close_tag();
}
}
private function show_topic_form($topic) {
$this->output->add_javascript("forum.js");
$this->output->record($topic, "newtopic");
$this->show_smilies();
}
private function show_forum($forum_id) {
if (($count = $this->model->count_topics($forum_id)) === false) {
$this->output->add_tag("result", "Database error while counting topics.");
return;
}
$paging = new pagination($this->output, "forum_".$forum_id, $this->settings->forum_page_size, $count);
if (($forum = $this->model->get_forum($forum_id, $paging->offset, $paging->size)) === false) {
$this->output->add_tag("result", "Forum not found.", $this->url);
return;
}
$this->output->title = $forum["title"]." - Forum";
$this->output->open_tag("forum", array("id" => $forum["id"]));
$this->output->add_tag("title", $forum["title"]);
$this->output->open_tag("topics");
foreach ($forum["topics"] as $topic) {
if ($this->user->logged_in) {
$topic["unread"] = show_boolean($this->model->last_topic_view($topic["id"]) < $topic["timestamp"]);
}
$topic["starter"] = isset($topic["visitor"]) ? $topic["visitor"] : $topic["user"];
$topic["timestamp"] = date("j F Y, H:i", $topic["timestamp"]);
$this->output->record($topic, "topic");
}
$this->output->close_tag();
$paging->show_browse_links();
$this->output->close_tag();
}
private function show_smilies() {
$smilies = config_file("smilies");
$this->output->open_tag("smilies");
foreach ($smilies as $smiley) {
$smiley = explode("\t", chop($smiley));
$text = array_shift($smiley);
$image = array_pop($smiley);
$this->output->add_tag("smiley", $image, array("text" => $text));
}
$this->output->close_tag();
}
private function show_topic($topic_id, $response = null) {
$moderate = $this->user->access_allowed("cms/forum");
if (($topic = $this->model->get_topic($topic_id)) == false) {
$this->output->add_tag("result", "Topic not found.", $this->url);
} else {
$this->output->add_javascript("forum.js");
$this->output->title = $topic["subject"]." - Forum";
$this->output->open_tag("topic", array("id" => $topic["id"], "forum_id" => $topic["forum_id"]));
$this->output->add_tag("subject", $topic["subject"]);
if ($this->user->logged_in) {
$last_view = $this->model->last_topic_view($topic["id"], true);
}
foreach ($topic["messages"] as $message) {
if ($this->user->logged_in) {
$message["unread"] = show_boolean($last_view < $message["timestamp"]);
}
if ($message["user_id"] == "") {
$message["author"] = $message["username"];
$message["usertype"] = "unregistered";
} else {
$message["usertype"] = "registered";
}
$message["timestamp"] = date("j F Y, H:i", $message["timestamp"]);
$message["content"] = preg_replace("/\[(config|code|quote)\]([\r\n]*)/", "[$1]", $message["content"]);
$post = new message($message["content"]);
$post->unescaped_output();
$post->translate_bbcodes();
$post->translate_smilies();
$message["content"] = $post->content;
unset($post);
$this->output->record($message, "message", array("moderate" => show_boolean($moderate)));
}
if ($response != null) {
$this->output->record($response, "response");
}
$this->output->close_tag();
$this->show_smilies();
}
}
public function execute() {
$this->output->description = "Banshee forum";
$this->output->keywords = "forum";
$this->output->title = "Forum";
$this->url = array("url" => $this->page->page);
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if ($_POST["submit_button"] == "Create topic") {
/* Create new topic
*/
if ($this->model->topic_oke($_POST) == false) {
$this->show_topic_form($_POST);
} else if ($this->model->create_topic($_POST) == false) {
$this->output->add_message("Database error while creating topic.");
$this->show_topic_form($_POST);
} else {
$this->output->add_tag("result", "Topic has been created.", array("url" => $this->page->page."/".$_POST["forum_id"]));
}
} else if ($_POST["submit_button"] == "Post response") {
/* Respond to topic
*/
if ($this->model->response_oke($_POST) == false) {
$this->show_topic($_POST["topic_id"], $_POST);
} else if ($this->model->create_response($_POST) == false) {
$this->output->add_message("Database error while saving response.");
$this->show_topic_form($_POST);
} else {
$this->output->add_tag("result", "Response has been saved.", array("url" => $this->page->page."/topic/".$_POST["topic_id"]));
}
} else {
$this->show_forum_overview();
}
} else if ($this->page->pathinfo[1] == "topic") {
/* Show topic
*/
$this->show_topic($this->page->pathinfo[2]);
} else if (valid_input($this->page->pathinfo[1], VALIDATE_NUMBERS, VALIDATE_NONEMPTY)) {
if ($this->page->pathinfo[2] == "new") {
/* Start new topic
*/
$topic = array("forum_id" => $this->page->pathinfo[1]);
$this->show_topic_form($topic);
} else {
/* Show forum
*/
$this->show_forum($this->page->pathinfo[1]);
}
} else {
/* Show forums
*/
$this->show_forum_overview();
}
}
}
?>