/
threads.php
102 lines (90 loc) · 2.82 KB
/
threads.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
<?php
class SCThreadsController {
public function show() {
SC::loginRequired();
global $current_user;
$api = new SCApi();
$thread = $api->threads_show();
//$current_user->setThreadViews($thread->messageid, sizeof($thread->messages())-1);
$vars = array(
"thread"=>$thread
);
switch ($_GET["__content_type"]) {
case "json":
$output = array(
"content"=>SCPartial::renderToString("thread/thread_messages", $vars)
);
echo SC::jsonify($output);
break;
case "html":
default:
$cs = array(
"title"=>$thread->subject,
"head"=>SCPartial::renderToString("shared/head"),
"util_links"=>SCPartial::renderToString("thread/util_links", $vars),
"content"=>SCPartial::renderToString("thread/thread", $vars)
);
SCLayout::render("main", $vars, $cs);
}
}
public function _new() {
SC::loginRequired();
global $current_user;
$type = $_GET["type"] or $type = "text";
$parent = new SCBoard($_GET["boardid"]);
$route_params = array("boardid"=>$parent->boardid);
$vars = array(
"subject"=>SC::getParam("subject", true),
"text"=>SC::getParam("text", true),
"type"=>$type,
"parent"=>$parent,
"controller"=>"threads",
"route_params"=>$route_params,
"action"=>SCRoutes::set("threads", "create", $route_params)
);
switch ($_GET["__content_type"]) {
case "json":
$output = array(
"content"=>SCPartial::renderToString("message/new", $vars)
);
echo SC::jsonify($output);
break;
case "html":
default:
$cs = array(
"title"=>"Create Thread",
"head"=>SCPartial::renderToString("shared/head"),
"util_links"=>SCPartial::renderToString("board/newthread_util_links", $vars),
"content"=>SCPartial::renderToString("message/new", $vars)
);
SCLayout::render("main", $vars, $cs);
}
}
public function create() {
SC::loginRequired();
global $current_user;
switch ($_GET["__content_type"]) {
case "json":
$api = new SCApi();
$thread = $api->boards_threads_create();
$output = array(
"transfer"=>SCRoutes::set("threads", "show", array("boardid"=>$thread->boardid,"threadid"=>$thread->messageid))
);
echo SC::jsonify($output);
break;
case "html":
default:
try {
$api = new SCApi();
$thread = $api->boards_threads_create();
SC::transfer(SCRoutes::set("threads", "show", array("boardid"=>$thread->boardid,"threadid"=>$thread->messageid)));
}
catch(Exception $ex) {
SC::setFlashMessage($ex->getMessage(), "error");
$this->_new();
}
}
}
}
$controller = new SCThreadsController();
?>