-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforum_edit.php
More file actions
162 lines (138 loc) · 5.46 KB
/
forum_edit.php
File metadata and controls
162 lines (138 loc) · 5.46 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
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
<?php
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2008 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
// Using this page you can edit a post.
// First it displays a box to edit in, and when you submit the changes
// it will call the methods on the post to make the changes.
//
require_once('../inc/forum.inc');
require_once('../inc/bbcode_html.inc');
check_get_args(array("id", "tnow", "ttok"));
$logged_in_user = get_logged_in_user();
BoincForumPrefs::lookup($logged_in_user);
$postid = get_int("id");
$post = BoincPost::lookup_id($postid);
if (!$post) error_page("no such post");
$thread = BoincThread::lookup_id($post->thread);
if (!$thread) error_page("no such thread");
$forum = BoincForum::lookup_id($thread->forum);
if (!is_moderator($logged_in_user, $forum)) {
if (time() > $post->timestamp + MAXIMUM_EDIT_TIME) {
error_page(tra("You can no longer edit this post.<br/>Posts can only be edited at most %1 minutes after they have been created.", (MAXIMUM_EDIT_TIME/60)));
}
}
$post_owner = BoincUser::lookup_id($post->user);
if (($logged_in_user->id != $post_owner->id) || (can_reply($thread, $forum, $logged_in_user) == false)) {
error_page (tra("You are not authorized to edit this post."));
}
$thread_owner = BoincUser::lookup_id($thread->owner);
// If this post belongs to the creator of the thread and is at top-level
// (ie. not a response to another post)
// allow the user to modify the thread title
//
$can_edit_title = ($post->parent_post==0 && $thread_owner->id==$logged_in_user->id && !is_banished($logged_in_user));
$content = post_str("content", true);
$title = post_str("title", true);
$preview = post_str("preview", true);
if (post_str('submit',true) && (!$preview)) {
if (POST_MAX_LINKS
&& link_count($content) > POST_MAX_LINKS
&& !is_moderator($logged_in_user, $forum)
) {
error_page("Can't update post");
}
check_tokens($logged_in_user->authenticator);
$add_signature = (post_str('add_signature', true) == "1")?1:0;
$content = substr($content, 0, 64000);
$content = trim($content);
if (strlen($content)) {
$content = BoincDb::escape_string($content);
$now = time();
$post->update("signature=$add_signature, content='$content', modified=$now");
if ($can_edit_title){
$title = trim($title);
$title = sanitize_tags($title);
$title = BoincDb::escape_string($title);
$thread->update("title='$title'");
}
header("Location: forum_thread.php?id=$thread->id&postid=$postid");
} else {
delete_post($post, $thread, $forum);
header("Location: forum_forum.php?id=$forum->id");
}
}
page_head(tra("Edit post"),'','','', $bbcode_js);
switch ($forum->parent_type) {
case 0:
$category = BoincCategory::lookup_id($forum->category);
show_forum_title($category, $forum, $thread);
break;
case 1:
show_team_forum_title($forum, $thread);
break;
}
echo "<p></p>";
if ($preview == tra("Preview")) {
panel(tra('Preview'),
function() use($content) {
echo output_transform($content, null);
}
);
}
echo "<form action=\"forum_edit.php?id=".$post->id."\" method=\"POST\" name=\"post\" onsubmit=\"return checkForm(this)\">\n";
echo form_tokens($logged_in_user->authenticator);
start_table();
row1(tra("Edit your message"));
if ($can_edit_title) {
//If this is the user can edit the thread title display a way of doing so
if ($preview) {
row2(
tra("Title").bbcode_info(),
"<input type=\"text\" name=\"title\" value=\"".htmlspecialchars($title)."\">"
);
} else {
row2(
tra("Title").bbcode_info(),
'<input type="text" name="title" value="'.htmlspecialchars($thread->title).'">'
);
}
};
if ($preview) {
row2(
tra("Message").bbcode_info().post_warning(),
start_table_str().$bbcode_html.end_table_str()."<textarea name=\"content\" rows=\"12\" cols=\"80\">".htmlspecialchars($content)."</textarea>"
);
} else {
row2(
tra("Message").bbcode_info().post_warning(),
start_table_str().$bbcode_html.end_table_str().'<textarea name="content" rows="12" cols="80">'.htmlspecialchars($post->content).'</textarea>'
);
}
if ($post->signature) {
$enable_signature="checked=\"true\"";
} else {
$enable_signature="";
}
row2("", "<input id=\"add_signature\" name=\"add_signature\" value=\"1\" ".$enable_signature." type=\"checkbox\">
<label for=\"add_signature\">".tra("Add my signature to this post")."</label>");
row2("", "<input class=\"btn btn-primary\" type=\"submit\" name=\"preview\" value=\"".tra("Preview")."\"> <input class=\"btn btn-success\" type=\"submit\" name=\"submit\" value=\"OK\">"
);
end_table();
echo "</form>";
page_tail();
$cvs_version_tracker[]="\$Id$"; //Generated automatically - do not edit
?>