831 |
florian |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
////////////////////////////////////////////////////////////////////////////////
|
|
|
4 |
// //
|
|
|
5 |
// Copyright (C) 2006 Phorum Development Team //
|
|
|
6 |
// http://www.phorum.org //
|
|
|
7 |
// //
|
|
|
8 |
// This program is free software. You can redistribute it and/or modify //
|
|
|
9 |
// it under the terms of either the current Phorum License (viewable at //
|
|
|
10 |
// phorum.org) or the Phorum License that was distributed with this file //
|
|
|
11 |
// //
|
|
|
12 |
// This program is distributed in the hope that it will be useful, //
|
|
|
13 |
// but WITHOUT ANY WARRANTY, without even the implied warranty of //
|
|
|
14 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. //
|
|
|
15 |
// //
|
|
|
16 |
// You should have received a copy of the Phorum License //
|
|
|
17 |
// along with this program. //
|
|
|
18 |
////////////////////////////////////////////////////////////////////////////////
|
|
|
19 |
|
|
|
20 |
// This script can initially be called in multiple ways to indicate what
|
|
|
21 |
// type of posting mode will be used. The parameters are:
|
|
|
22 |
//
|
|
|
23 |
// 1) The forum id.
|
|
|
24 |
//
|
|
|
25 |
// 2) The mode to use. Possibilities are:
|
|
|
26 |
//
|
|
|
27 |
// - post Post a new message (default if no mode is issued)
|
|
|
28 |
// - edit User edit of an already posted message
|
|
|
29 |
// - moderation Moderator edit of an already posted message
|
|
|
30 |
// - reply Reply to a message
|
|
|
31 |
// - quote Reply to a message, with quoting of the original message
|
|
|
32 |
//
|
|
|
33 |
// 3) If edit, moderation or reply is used: the message id.
|
|
|
34 |
//
|
|
|
35 |
// Examples:
|
|
|
36 |
// http://yoursite/phorum/posting.php?10,quote,15
|
|
|
37 |
// http://yoursite/phorum/posting.php?10,edit,20
|
|
|
38 |
// http://yoursite/phorum/posting.php?10,post
|
|
|
39 |
//
|
|
|
40 |
// This script can also be included in another page (for putting the editor
|
|
|
41 |
// screen inline in a page), by setting up the $PHORUM["postingargs"] before
|
|
|
42 |
// including:
|
|
|
43 |
//
|
|
|
44 |
// $PHORUM["postingargs"]["as_include"] any true value, to flag included state
|
|
|
45 |
// $PHORUM["postingargs"][0] the forum id
|
|
|
46 |
// $PHORUM["postingargs"][1] the mode to use (post,reply,quote,edit,moderation)
|
|
|
47 |
// $PHORUM["postingargs"][2] the message id to work with (omit for "post")
|
|
|
48 |
//
|
|
|
49 |
|
|
|
50 |
// ----------------------------------------------------------------------
|
|
|
51 |
// Basic setup and checks
|
|
|
52 |
// ----------------------------------------------------------------------
|
|
|
53 |
|
|
|
54 |
if (! defined('phorum_page')) {
|
|
|
55 |
define('phorum_page', 'post');
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
include_once("./common.php");
|
|
|
59 |
include_once("include/format_functions.php");
|
|
|
60 |
|
|
|
61 |
// Check if the Phorum is in read-only mode.
|
|
|
62 |
if(isset($PHORUM["status"]) && $PHORUM["status"]=="read-only"){
|
|
|
63 |
phorum_build_common_urls();
|
|
|
64 |
$PHORUM["DATA"]["MESSAGE"] = $PHORUM["DATA"]["LANG"]["ReadOnlyMessage"];
|
|
|
65 |
// Only show header and footer when not included in another page.
|
|
|
66 |
if (phorum_page == "post") {
|
|
|
67 |
include phorum_get_template("header");
|
|
|
68 |
phorum_hook("after_header");
|
|
|
69 |
}
|
|
|
70 |
include phorum_get_template("message");
|
|
|
71 |
if (phorum_page == "post") {
|
|
|
72 |
phorum_hook("before_footer");
|
|
|
73 |
include phorum_get_template("footer");
|
|
|
74 |
}
|
|
|
75 |
return;
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
// No forum id was set. Take the user back to the index.
|
|
|
79 |
if(empty($PHORUM["forum_id"])){
|
|
|
80 |
$dest_url = phorum_get_url(PHORUM_INDEX_URL);
|
|
|
81 |
phorum_redirect_by_url($dest_url);
|
|
|
82 |
exit();
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
// Somehow we got to a folder in posting.php. Take the
|
|
|
86 |
// user back to the folder.
|
|
|
87 |
if($PHORUM["folder_flag"]){
|
|
|
88 |
$dest_url = phorum_get_url(PHORUM_INDEX_URL, $PHORUM["forum_id"]);
|
|
|
89 |
phorum_redirect_by_url($dest_url);
|
|
|
90 |
exit();
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
// ----------------------------------------------------------------------
|
|
|
94 |
// Definitions
|
|
|
95 |
// ----------------------------------------------------------------------
|
|
|
96 |
|
|
|
97 |
// A list of valid posting modes.
|
|
|
98 |
$valid_modes = array(
|
|
|
99 |
"post", // Post a new message
|
|
|
100 |
"reply", // Post a reply to a message
|
|
|
101 |
"quote", // Post a reply with quoting of the message replied to
|
|
|
102 |
"edit", // Edit a message
|
|
|
103 |
"moderation", // Edit a message in moderator modus
|
|
|
104 |
);
|
|
|
105 |
|
|
|
106 |
// Configuration that we use for fields that we use in the editor form.
|
|
|
107 |
// Format for the array elements:
|
|
|
108 |
// [0] The type of field (string, integer, boolean, array).
|
|
|
109 |
// [1] Whether the value must be included as a hidden form field
|
|
|
110 |
// if the field is read-write flagged. So this is used for
|
|
|
111 |
// identifying values which are always implemented as a
|
|
|
112 |
// hidden form fields.
|
|
|
113 |
// [2] Whether the field is read-only or not. Within the editing process,
|
|
|
114 |
// this parameter can be changed to make the field writable.
|
|
|
115 |
// (for example if a moderator is editing a message).
|
|
|
116 |
// [3] A default value to initialize the form field with.
|
|
|
117 |
//
|
|
|
118 |
$PHORUM["post_fields"] = array(
|
|
|
119 |
"message_id" => array("integer", true, true, 0),
|
|
|
120 |
"user_id" => array("integer", true, true, 0),
|
|
|
121 |
"datestamp" => array("string", true, true, ''),
|
|
|
122 |
"status" => array("integer", false, true, 0),
|
|
|
123 |
"author" => array("string", false, true, ''),
|
|
|
124 |
"email" => array("string", false, true, ''),
|
|
|
125 |
"subject" => array("string", false, false, ''),
|
|
|
126 |
"body" => array("string", false, false, ''),
|
|
|
127 |
"forum_id" => array("integer", true, true, $PHORUM["forum_id"]),
|
|
|
128 |
"thread" => array("integer", true, true, 0),
|
|
|
129 |
"parent_id" => array("integer", true, true, 0),
|
|
|
130 |
"allow_reply" => array("boolean", false, true, 1),
|
|
|
131 |
"special" => array("string", false, true, ''),
|
|
|
132 |
"email_notify" => array("boolean", false, false, 0),
|
|
|
133 |
"show_signature" => array("boolean", false, false, 0),
|
|
|
134 |
"attachments" => array("array", true, true, array()),
|
|
|
135 |
"meta" => array("array", true, true, array()),
|
|
|
136 |
"thread_count" => array("integer", true, true, 0),
|
|
|
137 |
"mode" => array("string", true, true, ''),
|
|
|
138 |
);
|
|
|
139 |
|
|
|
140 |
// Indices for referencing the fields in $post_fields.
|
|
|
141 |
define("pf_TYPE", 0);
|
|
|
142 |
define("pf_HIDDEN", 1);
|
|
|
143 |
define("pf_READONLY", 2);
|
|
|
144 |
define("pf_INIT", 3);
|
|
|
145 |
|
|
|
146 |
// Definitions for a clear $apply_readonly parameter in
|
|
|
147 |
// the function phorum_posting_merge_db2form().
|
|
|
148 |
define("ALLFIELDS", false);
|
|
|
149 |
define("READONLYFIELDS", true);
|
|
|
150 |
|
|
|
151 |
// ----------------------------------------------------------------------
|
|
|
152 |
// Gather information about the editor state and start processing
|
|
|
153 |
// ----------------------------------------------------------------------
|
|
|
154 |
|
|
|
155 |
// Is this an initial request?
|
|
|
156 |
$initial = ! isset($_POST["message_id"]);
|
|
|
157 |
|
|
|
158 |
// Is finish, cancel of preview clicked?
|
|
|
159 |
$finish = (! $initial && isset($_POST["finish"]));
|
|
|
160 |
$cancel = (! $initial && isset($_POST["cancel"]));
|
|
|
161 |
$preview = (! $initial && isset($_POST["preview"]));
|
|
|
162 |
|
|
|
163 |
// Do we already have postingargs or do we use the global args?
|
|
|
164 |
if (! isset($PHORUM["postingargs"])) {
|
|
|
165 |
$PHORUM["postingargs"] = $PHORUM["args"];
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
// Find out what editing mode we're running in.
|
|
|
169 |
if ($initial) {
|
|
|
170 |
$mode = isset($PHORUM["postingargs"][1]) ? $PHORUM["postingargs"][1] : "post";
|
|
|
171 |
|
|
|
172 |
// Quote may also be passed as a phorum parameter (quote=1).
|
|
|
173 |
if ($mode == "reply" && isset($PHORUM["postingargs"]["quote"]) && $PHORUM["postingargs"]["quote"]) {
|
|
|
174 |
$mode = "quote";
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
} else {
|
|
|
178 |
if (! isset($_POST["mode"])) {
|
|
|
179 |
die("Missing parameter \"mode\" in request");
|
|
|
180 |
}
|
|
|
181 |
$mode = $_POST["mode"];
|
|
|
182 |
}
|
|
|
183 |
if (! in_array($mode, $valid_modes)) {
|
|
|
184 |
die("Illegal mode issued: $mode");
|
|
|
185 |
}
|
|
|
186 |
|
|
|
187 |
// Find out if we are attaching or detaching something.
|
|
|
188 |
// For detaching $do_detach will be set to the attachment's file_id.
|
|
|
189 |
$do_detach = false;
|
|
|
190 |
$do_attach = false;
|
|
|
191 |
foreach ($_POST as $var => $val) {
|
|
|
192 |
if (substr($var, 0, 7) == "detach:") {
|
|
|
193 |
$do_detach = substr($var, 7);
|
|
|
194 |
} elseif ($var == "attach") {
|
|
|
195 |
$do_attach = true;
|
|
|
196 |
}
|
|
|
197 |
}
|
|
|
198 |
|
|
|
199 |
// In case users click on post or preview, without uploading
|
|
|
200 |
// their attachment first, we fake an upload action.
|
|
|
201 |
if (count($_FILES)) {
|
|
|
202 |
list($name, $data) = each($_FILES);
|
|
|
203 |
if ($data["size"]) $do_attach = true;
|
|
|
204 |
reset($_FILES);
|
|
|
205 |
}
|
|
|
206 |
|
|
|
207 |
// Set all our URL's
|
|
|
208 |
phorum_build_common_urls();
|
|
|
209 |
$PHORUM["DATA"]["URL"]["ACTION"] = phorum_get_url(PHORUM_POSTING_URL);
|
|
|
210 |
|
|
|
211 |
// Keep track of errors.
|
|
|
212 |
$error_flag = false;
|
|
|
213 |
$PHORUM["DATA"]["MESSAGE"] = null;
|
|
|
214 |
$PHORUM["DATA"]["ERROR"] = null;
|
|
|
215 |
|
|
|
216 |
// Do things that are specific for first time or followup requests.
|
|
|
217 |
if ($initial) {
|
|
|
218 |
include("./include/posting/request_first.php");
|
|
|
219 |
} else {
|
|
|
220 |
include("./include/posting/request_followup.php");
|
|
|
221 |
}
|
|
|
222 |
|
|
|
223 |
// Store the posting mode in the form parameters, so we can remember
|
|
|
224 |
// the mode throughout the editing cycle (for example to be able to
|
|
|
225 |
// create page titles which match the editing mode).
|
|
|
226 |
$PHORUM["DATA"]["MODE"] = $mode;
|
|
|
227 |
|
|
|
228 |
// ----------------------------------------------------------------------
|
|
|
229 |
// Permission and ability handling
|
|
|
230 |
// ----------------------------------------------------------------------
|
|
|
231 |
|
|
|
232 |
// Make a descision on what posting mode we're really handling, based on
|
|
|
233 |
// the data that we have. The posting modes "reply" and "quote" will
|
|
|
234 |
// both be called "reply" from here. Modes "edit" and "moderation" will
|
|
|
235 |
// be called "edit" from here. The exact editor behaviour for editing is
|
|
|
236 |
// based on the user's permissions, not on posting mode.
|
|
|
237 |
$mode = "post";
|
|
|
238 |
if ($message["message_id"]) {
|
|
|
239 |
$mode = "edit";
|
|
|
240 |
} elseif ($message["parent_id"]) {
|
|
|
241 |
$mode = "reply";
|
|
|
242 |
}
|
|
|
243 |
|
|
|
244 |
// Do ban list checks. Only check the bans on entering and
|
|
|
245 |
// on finishing up. No checking is needed on intermediate requests.
|
|
|
246 |
if (! $error_flag && ($initial || $finish || $preview)) {
|
|
|
247 |
include("./include/posting/check_banlist.php");
|
|
|
248 |
}
|
|
|
249 |
|
|
|
250 |
// Determine the abilities that the current user has.
|
|
|
251 |
if (! $error_flag)
|
|
|
252 |
{
|
|
|
253 |
// Is the forum running in a moderated state?
|
|
|
254 |
$PHORUM["DATA"]["MODERATED"] =
|
|
|
255 |
$PHORUM["moderation"] == PHORUM_MODERATE_ON &&
|
|
|
256 |
!phorum_user_access_allowed(PHORUM_USER_ALLOW_MODERATE_MESSAGES);
|
|
|
257 |
|
|
|
258 |
// Does the user have administrator permissions?
|
|
|
259 |
$PHORUM["DATA"]["ADMINISTRATOR"] = $PHORUM["user"]["admin"];
|
|
|
260 |
|
|
|
261 |
// Does the user have moderator permissions?
|
|
|
262 |
$PHORUM["DATA"]["MODERATOR"] =
|
|
|
263 |
phorum_user_access_allowed(PHORUM_USER_ALLOW_MODERATE_MESSAGES);
|
|
|
264 |
|
|
|
265 |
// Ability: Do we allow attachments?
|
|
|
266 |
$PHORUM["DATA"]["ATTACHMENTS"] = $PHORUM["max_attachments"] > 0 && phorum_user_access_allowed(PHORUM_USER_ALLOW_ATTACH);
|
|
|
267 |
|
|
|
268 |
$PHORUM["DATA"]["EMAILNOTIFY"] =
|
|
|
269 |
(isset($PHORUM['allow_email_notify']) && !empty($PHORUM['allow_email_notify']))? 1 : 0;
|
|
|
270 |
|
|
|
271 |
// What special options can this user set for a message?
|
|
|
272 |
$PHORUM["DATA"]["OPTION_ALLOWED"] = array(
|
|
|
273 |
"sticky" => false, // Sticky flag for message sorting
|
|
|
274 |
"announcement" => false, // Announcement flag for message sorting
|
|
|
275 |
"allow_reply" => false, // Wheter replies are allowed in the thread
|
|
|
276 |
);
|
|
|
277 |
// For moderators and administrators.
|
|
|
278 |
if (($PHORUM["DATA"]["MODERATOR"] || $PHORUM["DATA"]["ADMINISTRATOR"]) && $message["parent_id"] == 0) {
|
|
|
279 |
$PHORUM["DATA"]["OPTION_ALLOWED"]["sticky"] = true;
|
|
|
280 |
$PHORUM["DATA"]["OPTION_ALLOWED"]["allow_reply"] = true;
|
|
|
281 |
}
|
|
|
282 |
// For administrators only.
|
|
|
283 |
if ($PHORUM["DATA"]["ADMINISTRATOR"]) {
|
|
|
284 |
$PHORUM["DATA"]["OPTION_ALLOWED"]["announcement"] = true;
|
|
|
285 |
}
|
|
|
286 |
}
|
|
|
287 |
|
|
|
288 |
if (! $error_flag)
|
|
|
289 |
{
|
|
|
290 |
// A hook to allow modules to change the abilities from above.
|
|
|
291 |
phorum_hook("posting_permission");
|
|
|
292 |
|
|
|
293 |
// Show special sort options in the editor? These only are
|
|
|
294 |
// honoured for the thread starter messages, so we check the
|
|
|
295 |
// parent_id for that.
|
|
|
296 |
$PHORUM["DATA"]["SHOW_SPECIALOPTIONS"] =
|
|
|
297 |
$message["parent_id"] == 0 &&
|
|
|
298 |
($PHORUM["DATA"]["OPTION_ALLOWED"]["announcement"] ||
|
|
|
299 |
$PHORUM["DATA"]["OPTION_ALLOWED"]["sticky"]);
|
|
|
300 |
|
|
|
301 |
// Show special sort options or allow_reply in the editor?
|
|
|
302 |
$PHORUM["DATA"]["SHOW_THREADOPTIONS"] =
|
|
|
303 |
$PHORUM["DATA"]["SHOW_SPECIALOPTIONS"] ||
|
|
|
304 |
$PHORUM["DATA"]["OPTION_ALLOWED"]["allow_reply"];
|
|
|
305 |
}
|
|
|
306 |
|
|
|
307 |
// Set extra writeable fields, based on the user's abilities.
|
|
|
308 |
if (isset($PHORUM["DATA"]["ATTACHMENTS"]) && $PHORUM["DATA"]["ATTACHMENTS"]) {
|
|
|
309 |
// Keep it as a hidden field.
|
|
|
310 |
$PHORUM["post_fields"]["attachments"][pf_READONLY] = false;
|
|
|
311 |
}
|
|
|
312 |
if (isset($PHORUM["DATA"]["MODERATOR"]) && $PHORUM["DATA"]["MODERATOR"]) {
|
|
|
313 |
if (! $message["user_id"]) {
|
|
|
314 |
$PHORUM["post_fields"]["author"][pf_READONLY] = false;
|
|
|
315 |
$PHORUM["post_fields"]["email"][pf_READONLY] = false;
|
|
|
316 |
}
|
|
|
317 |
}
|
|
|
318 |
if (isset($PHORUM["DATA"]["SHOW_SPECIALOPTIONS"]) && $PHORUM["DATA"]["SHOW_SPECIALOPTIONS"]) {
|
|
|
319 |
$PHORUM["post_fields"]["special"][pf_READONLY] = false;
|
|
|
320 |
}
|
|
|
321 |
if (isset($PHORUM["DATA"]["OPTION_ALLOWED"]["allow_reply"]) && $PHORUM["DATA"]["OPTION_ALLOWED"]["allow_reply"]) {
|
|
|
322 |
$PHORUM["post_fields"]["allow_reply"][pf_READONLY] = false;
|
|
|
323 |
}
|
|
|
324 |
|
|
|
325 |
// Check permissions and apply read-only data.
|
|
|
326 |
// Only do this on entering and on finishing up.
|
|
|
327 |
// No checking is needed on intermediate requests.
|
|
|
328 |
if (! $error_flag && ($initial || $finish)) {
|
|
|
329 |
include("./include/posting/check_permissions.php");
|
|
|
330 |
}
|
|
|
331 |
|
|
|
332 |
// Do permission checks for attachment management.
|
|
|
333 |
if (! $error_flag && ($do_attach || $do_detach)) {
|
|
|
334 |
if (! $PHORUM["DATA"]["ATTACHMENTS"]) {
|
|
|
335 |
$PHORUM["DATA"]["MESSAGE"] =
|
|
|
336 |
$PHORUM["DATA"]["LANG"]["AttachNotAllowed"];
|
|
|
337 |
$error_flag = true;
|
|
|
338 |
}
|
|
|
339 |
}
|
|
|
340 |
|
|
|
341 |
// ----------------------------------------------------------------------
|
|
|
342 |
// Perform actions
|
|
|
343 |
// ----------------------------------------------------------------------
|
|
|
344 |
|
|
|
345 |
// Only check the integrity of the data on finishing up. During the
|
|
|
346 |
// editing process, the user may produce garbage as much as he likes.
|
|
|
347 |
if (! $error_flag && $finish) {
|
|
|
348 |
include("./include/posting/check_integrity.php");
|
|
|
349 |
}
|
|
|
350 |
|
|
|
351 |
// Handle cancel request.
|
|
|
352 |
if (! $error_flag && $cancel) {
|
|
|
353 |
include("./include/posting/action_cancel.php");
|
|
|
354 |
}
|
|
|
355 |
|
|
|
356 |
// Count the number and total size of active attachments
|
|
|
357 |
// that we currently have.
|
|
|
358 |
$attach_count = 0;
|
|
|
359 |
$attach_totalsize = 0;
|
|
|
360 |
foreach ($message["attachments"] as $attachment) {
|
|
|
361 |
if ($attachment["keep"]) {
|
|
|
362 |
$attach_count ++;
|
|
|
363 |
$attach_totalsize += $attachment["size"];
|
|
|
364 |
}
|
|
|
365 |
}
|
|
|
366 |
|
|
|
367 |
// Attachment management. This will update the
|
|
|
368 |
// $attach_count and $attach_totalsize variables.
|
|
|
369 |
if (! $error_flag && ($do_attach || $do_detach)) {
|
|
|
370 |
include("./include/posting/action_attachments.php");
|
|
|
371 |
}
|
|
|
372 |
|
|
|
373 |
// Handle finishing actions.
|
|
|
374 |
if (! $error_flag && $finish)
|
|
|
375 |
{
|
|
|
376 |
// Posting mode
|
|
|
377 |
if ($mode == "post" || $mode == "reply") {
|
|
|
378 |
include("./include/posting/action_post.php");
|
|
|
379 |
}
|
|
|
380 |
// Editing mode.
|
|
|
381 |
elseif ($mode == "edit") {
|
|
|
382 |
include("./include/posting/action_edit.php");
|
|
|
383 |
}
|
|
|
384 |
// A little safety net.
|
|
|
385 |
else {
|
|
|
386 |
die("Internal error: finish action for \"$mode\" not available");
|
|
|
387 |
}
|
|
|
388 |
}
|
|
|
389 |
|
|
|
390 |
// ----------------------------------------------------------------------
|
|
|
391 |
// Display the page
|
|
|
392 |
// ----------------------------------------------------------------------
|
|
|
393 |
|
|
|
394 |
// Make up the text which must be used on the posting form's submit button.
|
|
|
395 |
$button_txtid = $mode == "edit" ? "SaveChanges" : "Post";
|
|
|
396 |
$message["submitbutton_text"] = $PHORUM["DATA"]["LANG"][$button_txtid];
|
|
|
397 |
|
|
|
398 |
// Attachment config
|
|
|
399 |
if($PHORUM["max_attachments"]){
|
|
|
400 |
|
|
|
401 |
$php_limit = ini_get('upload_max_filesize')*1024;
|
|
|
402 |
$max_packetsize = phorum_db_maxpacketsize();
|
|
|
403 |
if ($max_packetsize == NULL) {
|
|
|
404 |
$db_limit = $php_limit;
|
|
|
405 |
} else {
|
|
|
406 |
$db_limit = $max_packetsize/1024*.6;
|
|
|
407 |
}
|
|
|
408 |
if($PHORUM["max_attachment_size"]==0) $PHORUM["max_attachment_size"]=$php_limit;
|
|
|
409 |
$PHORUM["max_attachment_size"] = min($PHORUM["max_attachment_size"], $php_limit, $db_limit);
|
|
|
410 |
if ($PHORUM["max_totalattachment_size"]) {
|
|
|
411 |
if ($PHORUM["max_totalattachment_size"] < $PHORUM["max_attachment_size"]) {
|
|
|
412 |
$PHORUM["max_attachment_size"] = $PHORUM["max_totalattachment_size"];
|
|
|
413 |
}
|
|
|
414 |
}
|
|
|
415 |
|
|
|
416 |
// Data for attachment explanation.
|
|
|
417 |
if ($PHORUM["allow_attachment_types"]) {
|
|
|
418 |
$PHORUM["DATA"]["ATTACH_FILE_TYPES"] = str_replace(";", ", ", $PHORUM["allow_attachment_types"]);
|
|
|
419 |
$PHORUM["DATA"]["EXPLAIN_ATTACH_FILE_TYPES"] = str_replace("%types%", $PHORUM["DATA"]["ATTACH_FILE_TYPES"], $PHORUM["DATA"]["LANG"]["AttachFileTypes"]);
|
|
|
420 |
}
|
|
|
421 |
if ($PHORUM["max_attachment_size"]) {
|
|
|
422 |
$PHORUM["DATA"]["ATTACH_FILE_SIZE"] = $PHORUM["max_attachment_size"];
|
|
|
423 |
$PHORUM["DATA"]["ATTACH_FORMATTED_FILE_SIZE"] = phorum_filesize($PHORUM["max_attachment_size"] * 1024);
|
|
|
424 |
$PHORUM["DATA"]["EXPLAIN_ATTACH_FILE_SIZE"] = str_replace("%size%", $PHORUM["DATA"]["ATTACH_FORMATTED_FILE_SIZE"], $PHORUM["DATA"]["LANG"]["AttachFileSize"]);
|
|
|
425 |
}
|
|
|
426 |
if ($PHORUM["max_totalattachment_size"] && $PHORUM["max_attachments"]>1) {
|
|
|
427 |
$PHORUM["DATA"]["ATTACH_TOTALFILE_SIZE"] = $PHORUM["max_totalattachment_size"];
|
|
|
428 |
$PHORUM["DATA"]["ATTACH_FORMATTED_TOTALFILE_SIZE"] = phorum_filesize($PHORUM["max_totalattachment_size"] * 1024);
|
|
|
429 |
$PHORUM["DATA"]["EXPLAIN_ATTACH_TOTALFILE_SIZE"] = str_replace("%size%", $PHORUM["DATA"]["ATTACH_FORMATTED_TOTALFILE_SIZE"], $PHORUM["DATA"]["LANG"]["AttachTotalFileSize"]);
|
|
|
430 |
}
|
|
|
431 |
if ($PHORUM["max_attachments"] && $PHORUM["max_attachments"]>1) {
|
|
|
432 |
$PHORUM["DATA"]["ATTACH_MAX_ATTACHMENTS"] = $PHORUM["max_attachments"];
|
|
|
433 |
$PHORUM["DATA"]["ATTACH_REMAINING_ATTACHMENTS"] = $PHORUM["max_attachments"] - $attach_count;
|
|
|
434 |
$PHORUM["DATA"]["EXPLAIN_ATTACH_MAX_ATTACHMENTS"] = str_replace("%count%", $PHORUM["DATA"]["ATTACH_REMAINING_ATTACHMENTS"], $PHORUM["DATA"]["LANG"]["AttachMaxAttachments"]);
|
|
|
435 |
}
|
|
|
436 |
|
|
|
437 |
// A flag for the template building to be able to see if the
|
|
|
438 |
// attachment storage space is full.
|
|
|
439 |
$PHORUM["DATA"]["ATTACHMENTS_FULL"] =
|
|
|
440 |
$attach_count >= $PHORUM["max_attachments"] ||
|
|
|
441 |
($PHORUM["max_totalattachment_size"] &&
|
|
|
442 |
$attach_totalsize >= $PHORUM["max_totalattachment_size"]*1024);
|
|
|
443 |
}
|
|
|
444 |
|
|
|
445 |
// Let the templates know if we're running as an include.
|
|
|
446 |
$PHORUM["DATA"]["EDITOR_AS_INCLUDE"] =
|
|
|
447 |
isset($PHORUM["postingargs"]["as_include"]) && $PHORUM["postingargs"]["as_include"];
|
|
|
448 |
|
|
|
449 |
// Process data for previewing.
|
|
|
450 |
if ($preview) {
|
|
|
451 |
include("./include/posting/action_preview.php");
|
|
|
452 |
}
|
|
|
453 |
|
|
|
454 |
// Always put the current mode in the message, so hook
|
|
|
455 |
// writers can use this for identifying what we're doing.
|
|
|
456 |
$message["mode"] = $mode;
|
|
|
457 |
|
|
|
458 |
// Create hidden form field code. Fields which are read-only are
|
|
|
459 |
// all added as a hidden form fields in the form. Also the fields
|
|
|
460 |
// for which the pf_HIDDEN flag is set will be added to the
|
|
|
461 |
// hidden fields.
|
|
|
462 |
$hidden = "";
|
|
|
463 |
foreach ($PHORUM["post_fields"] as $var => $spec)
|
|
|
464 |
{
|
|
|
465 |
if ($var == "mode") {
|
|
|
466 |
$val = $mode;
|
|
|
467 |
} elseif ($spec[pf_TYPE] == "array") {
|
|
|
468 |
$val = htmlspecialchars(serialize($message[$var]));
|
|
|
469 |
} else {
|
|
|
470 |
$val = htmlentities($message[$var], ENT_COMPAT, $PHORUM["DATA"]["CHARSET"]);
|
|
|
471 |
}
|
|
|
472 |
if ($spec[pf_READONLY] || $spec[pf_HIDDEN]) {
|
|
|
473 |
$hidden .= '<input type="hidden" name="' . $var . '" ' .
|
|
|
474 |
'value="' . $val . "\" />\n";
|
|
|
475 |
}
|
|
|
476 |
}
|
|
|
477 |
$PHORUM["DATA"]["POST_VARS"] .= $hidden;
|
|
|
478 |
|
|
|
479 |
// Process data for XSS prevention.
|
|
|
480 |
foreach ($message as $var => $val)
|
|
|
481 |
{
|
|
|
482 |
// The meta information should not be used in templates, because
|
|
|
483 |
// nothing is escaped here. But we might want to use the data in
|
|
|
484 |
// mods which are run after this code. We continue here, so the
|
|
|
485 |
// data won't be stripped from the message data later on.
|
|
|
486 |
if ($var == "meta") continue;
|
|
|
487 |
|
|
|
488 |
if ($var == "attachments") {
|
|
|
489 |
if (is_array($val)) {
|
|
|
490 |
foreach ($val as $nr => $data)
|
|
|
491 |
{
|
|
|
492 |
// Do not show attachments which are not kept.
|
|
|
493 |
if (! $data["keep"]) {
|
|
|
494 |
unset($message["attachments"][$nr]);
|
|
|
495 |
continue;
|
|
|
496 |
}
|
|
|
497 |
|
|
|
498 |
$message[$var][$nr]["name"] = htmlspecialchars($data["name"]);
|
|
|
499 |
$message[$var][$nr]["size"] = phorum_filesize(round($data["size"]));
|
|
|
500 |
}
|
|
|
501 |
}
|
|
|
502 |
} else {
|
|
|
503 |
if (is_scalar($val)) {
|
|
|
504 |
$message[$var] = htmlspecialchars($val);
|
|
|
505 |
} else {
|
|
|
506 |
// Not used in the template, unless proven otherwise.
|
|
|
507 |
$message[$var] = '[removed from template data]';
|
|
|
508 |
}
|
|
|
509 |
}
|
|
|
510 |
}
|
|
|
511 |
|
|
|
512 |
// A cancel button is not needed if the editor is included in a page.
|
|
|
513 |
// This can also be used by the before_editor hook to disable the
|
|
|
514 |
// cancel button in all pages.
|
|
|
515 |
$PHORUM["DATA"]["SHOW_CANCEL_BUTTON"] = (isset($PHORUM["postingargs"]["as_include"]) ? false : true);
|
|
|
516 |
|
|
|
517 |
// A hook to give modules a last chance to update the message data.
|
|
|
518 |
$message = phorum_hook("before_editor", $message);
|
|
|
519 |
|
|
|
520 |
// Make the message data available to the template engine.
|
|
|
521 |
$PHORUM["DATA"]["POST"] = $message;
|
|
|
522 |
|
|
|
523 |
// Set the field to focus.
|
|
|
524 |
$focus = "phorum_subject";
|
|
|
525 |
if (!empty($message["subject"])) $focus = "phorum_textarea";
|
|
|
526 |
$PHORUM["DATA"]["FOCUS_TO_ID"] = $focus;
|
|
|
527 |
|
|
|
528 |
// Load page header.
|
|
|
529 |
if (! isset($PHORUM["postingargs"]["as_include"])) {
|
|
|
530 |
include phorum_get_template("header");
|
|
|
531 |
phorum_hook("after_header");
|
|
|
532 |
}
|
|
|
533 |
|
|
|
534 |
// Load page content.
|
|
|
535 |
if (isset($PHORUM["DATA"]["MESSAGE"])) {
|
|
|
536 |
include phorum_get_template("message");
|
|
|
537 |
} else {
|
|
|
538 |
include phorum_get_template("posting");
|
|
|
539 |
}
|
|
|
540 |
|
|
|
541 |
// Load page footer.
|
|
|
542 |
if (! isset($PHORUM["postingargs"]["as_include"])) {
|
|
|
543 |
phorum_hook("before_footer");
|
|
|
544 |
include phorum_get_template("footer");
|
|
|
545 |
}
|
|
|
546 |
|
|
|
547 |
// ----------------------------------------------------------------------
|
|
|
548 |
// Functions
|
|
|
549 |
// ----------------------------------------------------------------------
|
|
|
550 |
|
|
|
551 |
// Merge data from a database message record into the form fields
|
|
|
552 |
// that we use. If $apply_readonly is set to a true value, then
|
|
|
553 |
// only the fields which are flagged as read-only will be copied.
|
|
|
554 |
function phorum_posting_merge_db2form($form, $db, $apply_readonly = false)
|
|
|
555 |
{
|
|
|
556 |
$PHORUM = $GLOBALS['PHORUM'];
|
|
|
557 |
|
|
|
558 |
// If we have a user linked to the current message, then get the
|
|
|
559 |
// user data from the database, if it has to be applied as
|
|
|
560 |
// read-only data.
|
|
|
561 |
if ($PHORUM["post_fields"]["email"][pf_READONLY] || $PHORUM["post_fields"]["author"][pf_READONLY]) {
|
|
|
562 |
if ($db["user_id"]) {
|
|
|
563 |
$user_info = phorum_user_get($db["user_id"], false);
|
|
|
564 |
$user_info["author"] = $user_info["username"];
|
|
|
565 |
}
|
|
|
566 |
}
|
|
|
567 |
|
|
|
568 |
foreach ($PHORUM["post_fields"] as $key => $info)
|
|
|
569 |
{
|
|
|
570 |
// Skip writeable fields if we only have to apply read-only ones.
|
|
|
571 |
if ($apply_readonly && ! $info[pf_READONLY]) continue;
|
|
|
572 |
|
|
|
573 |
switch ($key) {
|
|
|
574 |
case "show_signature": {
|
|
|
575 |
$form[$key] = !empty($db["meta"]["show_signature"]);
|
|
|
576 |
break;
|
|
|
577 |
}
|
|
|
578 |
|
|
|
579 |
case "allow_reply": {
|
|
|
580 |
$form[$key] = ! $db["closed"];
|
|
|
581 |
break;
|
|
|
582 |
}
|
|
|
583 |
|
|
|
584 |
case "email_notify": {
|
|
|
585 |
$form[$key] = phorum_db_get_if_subscribed(
|
|
|
586 |
$db["forum_id"], $db["thread"], $db["user_id"]);
|
|
|
587 |
break;
|
|
|
588 |
}
|
|
|
589 |
|
|
|
590 |
case "forum_id": {
|
|
|
591 |
$form["forum_id"] = $db["forum_id"] ? $db["forum_id"] : $PHORUM["forum_id"];
|
|
|
592 |
break;
|
|
|
593 |
}
|
|
|
594 |
|
|
|
595 |
case "attachments": {
|
|
|
596 |
$form[$key] = array();
|
|
|
597 |
if (isset($db["meta"]["attachments"])) {
|
|
|
598 |
foreach ($db["meta"]["attachments"] as $data) {
|
|
|
599 |
$data["keep"] = true;
|
|
|
600 |
$data["linked"] = true;
|
|
|
601 |
$form["attachments"][] = $data;
|
|
|
602 |
}
|
|
|
603 |
}
|
|
|
604 |
break;
|
|
|
605 |
}
|
|
|
606 |
|
|
|
607 |
case "author":
|
|
|
608 |
case "email": {
|
|
|
609 |
if ($db["user_id"]) {
|
|
|
610 |
$form[$key] = $user_info[$key];
|
|
|
611 |
} else {
|
|
|
612 |
$form[$key] = $db[$key];
|
|
|
613 |
}
|
|
|
614 |
break;
|
|
|
615 |
}
|
|
|
616 |
|
|
|
617 |
case "special": {
|
|
|
618 |
if ($db["sort"] == PHORUM_SORT_ANNOUNCEMENT) {
|
|
|
619 |
$form["special"] = "announcement";
|
|
|
620 |
} elseif ($db["sort"] == PHORUM_SORT_STICKY) {
|
|
|
621 |
$form["special"] = "sticky";
|
|
|
622 |
} else {
|
|
|
623 |
$form["special"] = "";
|
|
|
624 |
}
|
|
|
625 |
break;
|
|
|
626 |
}
|
|
|
627 |
|
|
|
628 |
case "mode": {
|
|
|
629 |
// NOOP
|
|
|
630 |
break;
|
|
|
631 |
}
|
|
|
632 |
|
|
|
633 |
default:
|
|
|
634 |
$form[$key] = $db[$key];
|
|
|
635 |
}
|
|
|
636 |
}
|
|
|
637 |
return $form;
|
|
|
638 |
}
|
|
|
639 |
|
|
|
640 |
?>
|