forked from featherbb/featherbb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit.php
More file actions
219 lines (177 loc) · 8.63 KB
/
edit.php
File metadata and controls
219 lines (177 loc) · 8.63 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?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 model;
use DB;
class edit
{
public function __construct()
{
$this->feather = \Slim\Slim::getInstance();
$this->start = $this->feather->start;
$this->config = $this->feather->config;
$this->user = $this->feather->user;
$this->request = $this->feather->request;
}
// Fetch some info about the post, the topic and the forum
public function get_info_edit($id)
{
global $lang_common;
$select_get_info_edit = array('fid' => 'f.id', 'f.forum_name', 'f.moderators', 'f.redirect_url', 'fp.post_topics', 'tid' => 't.id', 't.subject', 't.posted', 't.first_post_id', 't.sticky', 't.closed', 'p.poster', 'p.poster_id', 'p.message', 'p.hide_smilies');
$where_get_info_edit = array(
array('fp.read_forum' => 'IS NULL'),
array('fp.read_forum' => '1')
);
$cur_post = DB::for_table('posts')
->table_alias('p')
->select_many($select_get_info_edit)
->inner_join('topics', array('t.id', '=', 'p.topic_id'), 't')
->inner_join('forums', array('f.id', '=', 't.forum_id'), 'f')
->left_outer_join('forum_perms', array('fp.forum_id', '=', 'f.id'), 'fp')
->left_outer_join('forum_perms', array('fp.group_id', '=', $this->user->g_id), null, true)
->where_any_is($where_get_info_edit)
->where('p.id', $id)
->find_one();
if (!$cur_post) {
message($lang_common['Bad request'], '404');
}
return $cur_post;
}
public function check_errors_before_edit($id, $can_edit_subject, $errors)
{
global $lang_post, $pd;
// If it's a topic it must contain a subject
if ($can_edit_subject) {
$subject = feather_trim($this->request->post('req_subject'));
if ($this->config['o_censoring'] == '1') {
$censored_subject = feather_trim(censor_words($subject));
}
if ($subject == '') {
$errors[] = $lang_post['No subject'];
} elseif ($this->config['o_censoring'] == '1' && $censored_subject == '') {
$errors[] = $lang_post['No subject after censoring'];
} elseif (feather_strlen($subject) > 70) {
$errors[] = $lang_post['Too long subject'];
} elseif ($this->config['p_subject_all_caps'] == '0' && is_all_uppercase($subject) && !$this->user->is_admmod) {
$errors[] = $lang_post['All caps subject'];
}
}
// Clean up message from POST
$message = feather_linebreaks(feather_trim($this->request->post('req_message')));
// Here we use strlen() not feather_strlen() as we want to limit the post to FEATHER_MAX_POSTSIZE bytes, not characters
if (strlen($message) > FEATHER_MAX_POSTSIZE) {
$errors[] = sprintf($lang_post['Too long message'], forum_number_format(FEATHER_MAX_POSTSIZE));
} elseif ($this->config['p_message_all_caps'] == '0' && is_all_uppercase($message) && !$this->user->is_admmod) {
$errors[] = $lang_post['All caps message'];
}
// Validate BBCode syntax
if ($this->config['p_message_bbcode'] == '1') {
require FEATHER_ROOT.'include/parser.php';
$message = preparse_bbcode($message, $errors);
}
if (empty($errors)) {
if ($message == '') {
$errors[] = $lang_post['No message'];
} elseif ($this->config['o_censoring'] == '1') {
// Censor message to see if that causes problems
$censored_message = feather_trim(censor_words($message));
if ($censored_message == '') {
$errors[] = $lang_post['No message after censoring'];
}
}
}
return $errors;
}
// If the previous check went OK, setup some variables used later
public function setup_variables($cur_post, $is_admmod, $can_edit_subject, $errors)
{
global $pd;
$post = array();
$post['hide_smilies'] = $this->request->post('hide_smilies') ? '1' : '0';
$post['stick_topic'] = $this->request->post('stick_topic') ? '1' : '0';
if (!$is_admmod) {
$post['stick_topic'] = $cur_post['sticky'];
}
// Clean up message from POST
$post['message'] = feather_linebreaks(feather_trim($this->request->post('req_message')));
// Validate BBCode syntax
if ($this->config['p_message_bbcode'] == '1') {
require_once FEATHER_ROOT.'include/parser.php';
$post['message'] = preparse_bbcode($post['message'], $errors);
}
// Replace four-byte characters (MySQL cannot handle them)
$post['message'] = strip_bad_multibyte_chars($post['message']);
// Get the subject
if ($can_edit_subject) {
$post['subject'] = feather_trim($this->request->post('req_subject'));
}
return $post;
}
public function edit_post($id, $can_edit_subject, $post, $cur_post, $is_admmod)
{
require FEATHER_ROOT.'include/search_idx.php';
if ($can_edit_subject) {
// Update the topic and any redirect topics
$where_topic = array(
array('id' => $cur_post['tid']),
array('moved_to' => $cur_post['tid'])
);
$update_topic = array(
'subject' => $post['subject'],
'sticky' => $post['stick_topic']
);
DB::for_table('topics')->where_any_is($where_topic)
->find_one()
->set($update_topic)
->save();
// We changed the subject, so we need to take that into account when we update the search words
update_search_index('edit', $id, $post['message'], $post['subject']);
} else {
update_search_index('edit', $id, $post['message']);
}
// Update the post
$update_post = array(
'message' => $post['message'],
'hide_smilies' => $post['hide_smilies']
);
if (!$this->request->post('silent') || !$is_admmod) {
$update_post['edited'] = time();
$update_post['edited_by'] = $this->user->username;
}
DB::for_table('posts')->where('id', $id)
->find_one()
->set($update_post)
->save();
}
public function get_checkboxes($can_edit_subject, $is_admmod, $cur_post, $cur_index)
{
global $lang_post, $lang_common;
$checkboxes = array();
if ($can_edit_subject && $is_admmod) {
if ($this->request->post('stick_topic') || $cur_post['sticky'] == '1') {
$checkboxes[] = '<label><input type="checkbox" name="stick_topic" value="1" checked="checked" tabindex="'.($cur_index++).'" />'.$lang_common['Stick topic'].'<br /></label>';
} else {
$checkboxes[] = '<label><input type="checkbox" name="stick_topic" value="1" tabindex="'.($cur_index++).'" />'.$lang_common['Stick topic'].'<br /></label>';
}
}
if ($this->config['o_smilies'] == '1') {
if ($this->request->post('hide_smilies') || $cur_post['hide_smilies'] == '1') {
$checkboxes[] = '<label><input type="checkbox" name="hide_smilies" value="1" checked="checked" tabindex="'.($cur_index++).'" />'.$lang_post['Hide smilies'].'<br /></label>';
} else {
$checkboxes[] = '<label><input type="checkbox" name="hide_smilies" value="1" tabindex="'.($cur_index++).'" />'.$lang_post['Hide smilies'].'<br /></label>';
}
}
if ($is_admmod) {
if ($this->request->isPost() && $this->request->post('silent') || $this->request->isPost() == '') {
$checkboxes[] = '<label><input type="checkbox" name="silent" value="1" tabindex="'.($cur_index++).'" checked="checked" />'.$lang_post['Silent edit'].'<br /></label>';
} else {
$checkboxes[] = '<label><input type="checkbox" name="silent" value="1" tabindex="'.($cur_index++).'" />'.$lang_post['Silent edit'].'<br /></label>';
}
}
return $checkboxes;
}
}