-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit.php
370 lines (293 loc) · 15 KB
/
edit.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
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
<?php
/**
* Edit post page.
*
* Modifies the contents of the specified post.
*
* @copyright (C) 2008-2012 PunBB, partially based on code (C) 2008-2009 FluxBB.org
* @license http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
* @package PunBB
*/
if (!defined('FORUM_ROOT'))
define('FORUM_ROOT', './');
require FORUM_ROOT.'include/common.php';
($hook = get_hook('ed_start')) ? eval($hook) : null;
if ($forum_user['g_read_board'] == '0')
message($lang_common['No view']);
// Load the post.php language file
require FORUM_ROOT.'lang/'.$forum_user['language'].'/post.php';
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
if ($id < 1)
not_found($lang_common['Bad request']);
// Fetch some info about the post, the topic and the forum
$query = array(
'SELECT' => 'f.id AS fid, f.forum_name, f.moderators, f.redirect_url, fp.post_replies, fp.post_topics, t.id AS tid, t.subject, t.posted, t.first_post_id, t.closed, p.poster, p.poster_id, p.message, p.hide_smilies',
'FROM' => 'posts AS p',
'JOINS' => array(
array(
'INNER JOIN' => 'topics AS t',
'ON' => 't.id=p.topic_id'
),
array(
'INNER JOIN' => 'forums AS f',
'ON' => 'f.id=t.forum_id'
),
array(
'LEFT JOIN' => 'forum_perms AS fp',
'ON' => '(fp.forum_id=f.id AND fp.group_id='.$forum_user['g_id'].')'
)
),
'WHERE' => '(fp.read_forum IS NULL OR fp.read_forum=1) AND p.id='.$id
);
($hook = get_hook('ed_qr_get_post_info')) ? eval($hook) : null;
$result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
$cur_post = $forum_db->fetch_assoc($result);
if (!$cur_post)
not_found($lang_common['Bad request']);
// Sort out who the moderators are and if we are currently a moderator (or an admin)
$mods_array = ($cur_post['moderators'] != '') ? unserialize($cur_post['moderators']) : array();
$forum_page['is_admmod'] = ($forum_user['g_id'] == FORUM_ADMIN || ($forum_user['g_moderator'] == '1' && array_key_exists($forum_user['username'], $mods_array))) ? true : false;
($hook = get_hook('ed_pre_permission_check')) ? eval($hook) : null;
// Do we have permission to edit this post?
if (($forum_user['g_edit_posts'] == '0' ||
$cur_post['poster_id'] != $forum_user['id'] ||
$cur_post['closed'] == '1') &&
!$forum_page['is_admmod'])
message($lang_common['No permission']);
$can_edit_subject = $id == $cur_post['first_post_id'];
($hook = get_hook('ed_post_selected')) ? eval($hook) : null;
// Start with a clean slate
$errors = array();
if (isset($_POST['form_sent']))
{
($hook = get_hook('ed_form_submitted')) ? eval($hook) : null;
// If it is a topic it must contain a subject
if ($can_edit_subject)
{
$subject = forum_trim($_POST['req_subject']);
if ($subject == '')
$errors[] = $lang_post['No subject'];
else if (utf8_strlen($subject) > FORUM_SUBJECT_MAXIMUM_LENGTH)
$errors[] = sprintf($lang_post['Too long subject'], FORUM_SUBJECT_MAXIMUM_LENGTH);
else if ($forum_config['p_subject_all_caps'] == '0' && check_is_all_caps($subject) && !$forum_page['is_admmod'])
$subject = utf8_ucwords(utf8_strtolower($subject));
}
// Clean up message from POST
$message = forum_linebreaks(forum_trim($_POST['req_message']));
if (strlen($message) > FORUM_MAX_POSTSIZE_BYTES)
$errors[] = sprintf($lang_post['Too long message'], forum_number_format(strlen($message)), forum_number_format(FORUM_MAX_POSTSIZE_BYTES));
else if ($forum_config['p_message_all_caps'] == '0' && check_is_all_caps($message) && !$forum_page['is_admmod'])
$message = utf8_ucwords(utf8_strtolower($message));
// Validate BBCode syntax
if ($forum_config['p_message_bbcode'] == '1' || $forum_config['o_make_links'] == '1')
{
if (!defined('FORUM_PARSER_LOADED'))
require FORUM_ROOT.'include/parser.php';
$message = preparse_bbcode($message, $errors);
}
if ($message == '')
$errors[] = $lang_post['No message'];
$hide_smilies = isset($_POST['hide_smilies']) ? 1 : 0;
($hook = get_hook('ed_end_validation')) ? eval($hook) : null;
// Did everything go according to plan?
if (empty($errors) && !isset($_POST['preview']))
{
($hook = get_hook('ed_pre_post_edited')) ? eval($hook) : null;
if (!defined('FORUM_SEARCH_IDX_FUNCTIONS_LOADED'))
require FORUM_ROOT.'include/search_idx.php';
if ($can_edit_subject)
{
// Update the topic and any redirect topics
$query = array(
'UPDATE' => 'topics',
'SET' => 'subject=\''.$forum_db->escape($subject).'\'',
'WHERE' => 'id='.$cur_post['tid'].' OR moved_to='.$cur_post['tid']
);
($hook = get_hook('ed_qr_update_subject')) ? eval($hook) : null;
$forum_db->query_build($query) or error(__FILE__, __LINE__);
// We changed the subject, so we need to take that into account when we update the search words
update_search_index('edit', $id, $message, $subject);
}
else
update_search_index('edit', $id, $message);
// Update the post
$query = array(
'UPDATE' => 'posts',
'SET' => 'message=\''.$forum_db->escape($message).'\', hide_smilies=\''.$hide_smilies.'\'',
'WHERE' => 'id='.$id
);
if (!isset($_POST['silent']) || !$forum_page['is_admmod'])
$query['SET'] .= ', edited='.time().', edited_by=\''.$forum_db->escape($forum_user['username']).'\'';
($hook = get_hook('ed_qr_update_post')) ? eval($hook) : null;
$forum_db->query_build($query) or error(__FILE__, __LINE__);
($hook = get_hook('ed_pre_redirect')) ? eval($hook) : null;
redirect(forum_link($forum_url['post'], $id), $lang_post['Edit redirect']);
}
}
// Setup error messages
if (!empty($errors))
{
$forum_page['errors'] = array();
foreach ($errors as $cur_error)
$forum_page['errors'][] = '<li><span>'.$cur_error.'</span></li>';
}
// Setup form
$forum_page['group_count'] = $forum_page['item_count'] = $forum_page['fld_count'] = 0;
$forum_page['form_action'] = forum_link($forum_url['edit'], $id);
$forum_page['form_attributes'] = array();
$forum_page['hidden_fields'] = array(
'form_sent' => '<input type="hidden" name="form_sent" value="1" />',
'csrf_token' => '<input type="hidden" name="csrf_token" value="'.generate_form_token($forum_page['form_action']).'" />'
);
// Setup help
$forum_page['main_head_options'] = array();
if ($forum_config['p_message_bbcode'] == '1')
$forum_page['text_options']['bbcode'] = '<span'.(empty($forum_page['text_options']) ? ' class="first-item"' : '').'><a class="exthelp" href="'.forum_link($forum_url['help'], 'bbcode').'" title="'.sprintf($lang_common['Help page'], $lang_common['BBCode']).'">'.$lang_common['BBCode'].'</a></span>';
if ($forum_config['p_message_img_tag'] == '1')
$forum_page['text_options']['img'] = '<span'.(empty($forum_page['text_options']) ? ' class="first-item"' : '').'><a class="exthelp" href="'.forum_link($forum_url['help'], 'img').'" title="'.sprintf($lang_common['Help page'], $lang_common['Images']).'">'.$lang_common['Images'].'</a></span>';
if ($forum_config['o_smilies'] == '1')
$forum_page['text_options']['smilies'] = '<span'.(empty($forum_page['text_options']) ? ' class="first-item"' : '').'><a class="exthelp" href="'.forum_link($forum_url['help'], 'smilies').'" title="'.sprintf($lang_common['Help page'], $lang_common['Smilies']).'">'.$lang_common['Smilies'].'</a></span>';
// Setup breadcrumbs
$forum_page['crumbs'] = array(
array($forum_config['o_board_title'], forum_link($forum_url['index'])),
array($cur_post['forum_name'], forum_link($forum_url['forum'], array($cur_post['fid'], sef_friendly($cur_post['forum_name'])))),
array($cur_post['subject'], forum_link($forum_url['topic'], array($cur_post['tid'], sef_friendly($cur_post['subject'])))),
(($id == $cur_post['first_post_id']) ? $lang_post['Edit topic'] : $lang_post['Edit reply'])
);
($hook = get_hook('ed_pre_header_load')) ? eval($hook) : null;
define('FORUM_PAGE', 'postedit');
require FORUM_ROOT.'header.php';
// START SUBST - <!-- forum_main -->
ob_start();
($hook = get_hook('ed_main_output_start')) ? eval($hook) : null;
?>
<div class="main-head">
<h2 class="hn"><span><?php echo ($id == $cur_post['first_post_id']) ? $lang_post['Edit topic'] : $lang_post['Edit reply'] ?></span></h2>
</div>
<?php
// If preview selected and there are no errors
if (isset($_POST['preview']) && empty($forum_page['errors']))
{
if (!defined('FORUM_PARSER_LOADED'))
require FORUM_ROOT.'include/parser.php';
// Generate the post heading
$forum_page['post_ident'] = array();
$forum_page['post_ident']['num'] = '<span class="post-num">#</span>';
$forum_page['post_ident']['byline'] = '<span class="post-byline">'.sprintf((($id == $cur_post['first_post_id']) ? $lang_post['Topic byline'] : $lang_post['Reply byline']), '<strong>'.forum_htmlencode($cur_post['poster']).'</strong>').'</span>';
$forum_page['post_ident']['link'] = '<span class="post-link">'.format_time(time()).'</span>';
$forum_page['preview_message'] = parse_message($message, $hide_smilies);
($hook = get_hook('ed_preview_pre_display')) ? eval($hook) : null;
?>
<div class="main-subhead">
<h2 class="hn"><span><?php echo $id == $cur_post['first_post_id'] ? $lang_post['Preview edited topic'] : $lang_post['Preview edited reply'] ?></span></h2>
</div>
<div id="post-preview" class="main-content main-frm">
<div class="post singlepost">
<div class="posthead">
<h3 class="hn"><?php echo implode(' ', $forum_page['post_ident']) ?></h3>
<?php ($hook = get_hook('ed_preview_new_post_head_option')) ? eval($hook) : null; ?>
</div>
<div class="postbody">
<div class="post-entry">
<div class="entry-content">
<?php echo $forum_page['preview_message']."\n" ?>
</div>
<?php ($hook = get_hook('ed_preview_new_post_entry_data')) ? eval($hook) : null; ?>
</div>
</div>
</div>
</div>
<?php
}
?>
<div class="main-subhead">
<h2 class="hn"><span><?php echo ($id != $cur_post['first_post_id']) ? $lang_post['Compose edited reply'] : $lang_post['Compose edited topic'] ?></span></h2>
</div>
<div id="post-form" class="main-content main-frm">
<?php
if (!empty($forum_page['text_options']))
echo "\t\t".'<p class="ct-options options">'.sprintf($lang_common['You may use'], implode(' ', $forum_page['text_options'])).'</p>'."\n";
// If there were any errors, show them
if (isset($forum_page['errors']))
{
?>
<div class="ct-box error-box">
<h2 class="warn hn"><span><?php echo $lang_post['Post errors'] ?></span></h2>
<ul class="error-list">
<?php echo implode("\n\t\t\t\t", $forum_page['errors'])."\n" ?>
</ul>
</div>
<?php
}
?>
<div id="req-msg" class="req-warn ct-box error-box">
<p class="important"><?php echo $lang_common['Required warn'] ?></p>
</div>
<form id="afocus" class="frm-form frm-ctrl-submit" method="post" accept-charset="utf-8" action="<?php echo $forum_page['form_action'] ?>"<?php if (!empty($forum_page['form_attributes'])) echo ' '.implode(' ', $forum_page['form_attributes']) ?>>
<div class="hidden">
<?php echo implode("\n\t\t\t\t", $forum_page['hidden_fields'])."\n" ?>
</div>
<?php ($hook = get_hook('ed_pre_main_fieldset')) ? eval($hook) : null; ?>
<fieldset class="frm-group group<?php echo ++$forum_page['group_count'] ?>">
<legend class="group-legend"><strong><?php echo $lang_post['Edit post legend'] ?></strong></legend>
<?php ($hook = get_hook('ed_pre_subject')) ? eval($hook) : null; ?>
<?php if ($can_edit_subject): ?> <div class="sf-set set<?php echo ++$forum_page['item_count'] ?>">
<div class="sf-box text required">
<label for="fld<?php echo ++ $forum_page['fld_count'] ?>"><span><?php echo $lang_post['Topic subject'] ?></span></label><br />
<span class="fld-input"><input id="fld<?php echo $forum_page['fld_count'] ?>" type="text" name="req_subject" size="<?php echo FORUM_SUBJECT_MAXIMUM_LENGTH < 95 ? FORUM_SUBJECT_MAXIMUM_LENGTH : 95 ?>" maxlength="<?php echo FORUM_SUBJECT_MAXIMUM_LENGTH ?>" value="<?php echo forum_htmlencode(isset($_POST['req_subject']) ? $_POST['req_subject'] : $cur_post['subject']) ?>" required /></span>
</div>
</div>
<?php endif; ($hook = get_hook('ed_pre_message_box')) ? eval($hook) : null; ?> <div class="txt-set set<?php echo ++$forum_page['item_count'] ?>">
<div class="txt-box textarea required">
<label for="fld<?php echo ++ $forum_page['fld_count'] ?>"><span><?php echo $lang_post['Write message'] ?></span></label>
<div class="txt-input"><span class="fld-input"><textarea id="fld<?php echo $forum_page['fld_count'] ?>" name="req_message" rows="15" cols="95" required spellcheck="true"><?php echo forum_htmlencode(isset($_POST['req_message']) ? $message : $cur_post['message']) ?></textarea></span></div>
</div>
</div>
<?php
$forum_page['checkboxes'] = array();
if ($forum_config['o_smilies'] == '1')
{
if (isset($_POST['hide_smilies']) || $cur_post['hide_smilies'] == '1')
$forum_page['checkboxes']['hide_smilies'] = '<div class="mf-item"><span class="fld-input"><input type="checkbox" id="fld'.(++$forum_page['fld_count']).'" name="hide_smilies" value="1" checked="checked" /></span> <label for="fld'.$forum_page['fld_count'].'">'.$lang_post['Hide smilies'].'</label></div>';
else
$forum_page['checkboxes']['hide_smilies'] = '<div class="mf-item"><span class="fld-input"><input type="checkbox" id="fld'.(++$forum_page['fld_count']).'" name="hide_smilies" value="1" /></span> <label for="fld'.$forum_page['fld_count'].'">'.$lang_post['Hide smilies'].'</label></div>';
}
if ($forum_page['is_admmod'])
{
if ((isset($_POST['form_sent']) && isset($_POST['silent'])) || !isset($_POST['form_sent']))
$forum_page['checkboxes']['silent'] = '<div class="mf-item"><span class="fld-input"><input type="checkbox" id="fld'.(++$forum_page['fld_count']).'" name="silent" value="1" checked="checked" /></span> <label for="fld'.$forum_page['fld_count'].'">'.$lang_post['Silent edit'].'</label></div>';
else
$forum_page['checkboxes']['silent'] = '<div class="mf-item"><span class="fld-input"><input type="checkbox" id="fld'.(++$forum_page['fld_count']).'" name="silent" value="1" /></span> <label for="fld'.$forum_page['fld_count'].'">'.$lang_post['Silent edit'].'</label></div>';
}
($hook = get_hook('ed_pre_checkbox_display')) ? eval($hook) : null;
if (!empty($forum_page['checkboxes']))
{
?>
<fieldset class="mf-set set<?php echo ++$forum_page['item_count'] ?>">
<div class="mf-box checkbox">
<?php echo implode("\n\t\t\t\t\t", $forum_page['checkboxes'])."\n" ?>
</div>
<?php ($hook = get_hook('ed_pre_checkbox_fieldset_end')) ? eval($hook) : null; ?>
</fieldset>
<?php
}
($hook = get_hook('ed_pre_main_fieldset_end')) ? eval($hook) : null;
?>
</fieldset>
<?php
($hook = get_hook('ed_main_fieldset_end')) ? eval($hook) : null;
?>
<div class="frm-buttons">
<span class="submit primary"><input type="submit" name="submit_button" value="<?php echo ($id != $cur_post['first_post_id']) ? $lang_post['Submit reply'] : $lang_post['Submit topic'] ?>" /></span>
<span class="submit"><input type="submit" name="preview" value="<?php echo ($id != $cur_post['first_post_id']) ? $lang_post['Preview reply'] : $lang_post['Preview topic'] ?>" /></span>
</div>
</form>
</div>
<?php
$forum_id = $cur_post['fid'];
($hook = get_hook('ed_end')) ? eval($hook) : null;
$tpl_temp = forum_trim(ob_get_contents());
$tpl_main = str_replace('<!-- forum_main -->', $tpl_temp, $tpl_main);
ob_end_clean();
// END SUBST - <!-- forum_main -->
require FORUM_ROOT.'footer.php';