forked from pouetnet/pouet2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtopic.php
186 lines (162 loc) · 5.4 KB
/
topic.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
176
177
178
179
180
181
182
183
184
185
186
<?
require_once("bootstrap.inc.php");
require_once("include_pouet/box-bbs-post.php");
require_once("include_pouet/box-modalmessage.php");
$POSTS_PER_PAGE = max(1,get_setting("topicposts"));
if ($_GET["post"]) // setting-independent post lookup
{
$topicID = SQLLib::SelectRow(sprintf_esc("select topic from bbs_posts where id = %d",$_GET["post"]))->topic;
if ($topicID)
{
$inner = sprintf_esc("select id, @rowID:=@rowID+1 as rowID from bbs_posts, (SELECT @rowID:=0) as init where topic = %d",$topicID);
$row = SQLLib::SelectRow(sprintf_esc("select * from (".$inner.") as t where id = %d",$_GET["post"]));
redirect(sprintf("topic.php?which=%d&page=%d#c%d",$topicID,(int)(($row->rowID - 1) / $POSTS_PER_PAGE) + 1,$_GET["post"]));
exit();
}
}
class PouetBoxBBSView extends PouetBox {
var $topic;
var $posts;
var $id;
var $page;
var $postcount;
function PouetBoxBBSView($id) {
parent::__construct();
$this->uniqueID = "pouetbox_bbsview";
$this->title = "comments";
$this->id = (int)$id;
}
function LoadFromDB() {
global $POSTS_PER_PAGE;
$s = new SQLSelect();
$s->AddTable("bbs_topics");
$s->AddWhere("bbs_topics.id=".$this->id);
$this->topic = SQLLib::SelectRow($s->GetQuery());
if(!$this->topic) return false;
$s = new SQLSelect();
$s->AddField("count(*) as c");
$s->AddTable("bbs_posts");
$s->AddWhere("bbs_posts.topic=".$this->id);
$this->postcount = SQLLib::SelectRow($s->GetQuery())->c;
$s = new BM_Query();
$s->AddTable("bbs_posts");
$s->AddField("bbs_posts.id as id");
$s->AddField("bbs_posts.post as post");
$s->AddField("bbs_posts.added as added");
$s->attach(array("bbs_posts"=>"author"),array("users as user"=>"id"));
$s->AddWhere("bbs_posts.topic=".$this->id);
//$s->SetLimit( $POSTS_PER_PAGE, (int)(($this->page - 1)*$POSTS_PER_PAGE) );
$this->paginator = new PouetPaginator();
$this->paginator->SetData( "topic.php?which=".$this->id, $this->postcount, $POSTS_PER_PAGE, $_GET["page"] );
$this->paginator->SetLimitOnQuery( $s );
$this->posts = $s->perform();
$this->title = _html($this->topic->topic);
}
function RenderBody() {
global $POSTS_PER_PAGE;
global $THREAD_CATEGORIES;
global $currentUser;
echo "<div class='threadcategory'>";
echo "<b>category:</b> "._html($this->topic->category);
if ($currentUser && $currentUser->CanEditBBS())
{
printf(" [<a href='admin_topic_edit.php?which=%d' class='adminlink'>edit</a>]\n",$this->id);
}
printf(" [<a href='gloperator_log.php?which=%d&what=topic'>glöplog</a>]\n",$this->id);
echo "</div>\n";
if ($this->postcount > $POSTS_PER_PAGE) {
echo $this->paginator->RenderNavbar();
} else {
echo "<div class='blank'> </div>\n";
}
foreach ($this->posts as $c) {
$p = $c->post;
$p = parse_message($p);
echo "<div class='content cite-".$c->user->id."' id='c".$c->id."'>".$p."</div>\n";
echo "<div class='foot'><span class='tools' data-cid='".$c->id."'></span> added on the <a href='topic.php?post=".$c->id."'>".$c->added."</a> by ".
$c->user->PrintLinkedName()." ".$c->user->PrintLinkedAvatar()."</div>\n\n";
}
if ($this->postcount > $POSTS_PER_PAGE) {
echo $this->paginator->RenderNavbar();
}
}
function RenderFooter() {
echo "</div>\n";
return $s;
}
};
if (!$_GET["which"])
{
redirect("bbs.php");
}
$topicid = (int)$_GET["which"];
$view = new PouetBoxBBSView($topicid);
$view->Load();
$post = new PouetBoxBBSPost($topicid);
$TITLE = $view->topic->topic;
require_once("include_pouet/header.php");
require("include_pouet/menu.inc.php");
echo "<div id='content'>\n";
if ($view->topic)
{
echo $view->Render();
if (!get_login_id())
{
require_once("include_pouet/box-login.php");
$box = new PouetBoxLogin();
$box->Render();
}
else
{
if ($view->topic->id == FIXMETHREAD_ID)
{
$msg = new PouetBoxModalMessage( true );
$msg->title = "want to add a new youtube link ?";
$msg->message = "we've made a new automated edit request system to modify prods - if you just want to add credits or links to prods, go to the prod page and click the edit link at the bottom!";
$msg->Render();
}
if ($view->topic->closed)
{
$msg = new PouetBoxModalMessage( true );
$msg->title = "thread closed";
$msg->message = "this thread now officially wants YOU to go make a demo about it instead. please comply.";
$msg->Render();
}
else
{
echo $post->Render();
?>
<script type="text/javascript">
<!--
document.observe("dom:loaded",function(){
$$(".tools").each(function(item){
var cid = item.readAttribute("data-cid");
item.update("<a href='#'>quote</a> |");
item.down("a").observe("click",function(e){
e.stop();
new Ajax.Request("ajax_bbspost.php",{
"method":"post",
"parameters":$H({"id":cid}).toQueryString(),
"onSuccess":function(transport){
$("message").value += "[quote]" + transport.responseJSON.post.strip() + "[/quote]";
}
});
try { $("message").scrollTo(); } catch(ex) {} // needs try-catch because of some dumbass popup blockers
});
});
PreparePostForm( $$("#pouetbox_bbspost form").first() );
});
//-->
</script>
<?
}
}
}
else
{
echo "bla bla bla topic missing bla";
}
echo "</div>\n";
require("include_pouet/menu.inc.php");
require_once("include_pouet/footer.php");
?>