Conditions | 348 |
Total Lines | 1542 |
Code Lines | 778 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
31 | function Post($post_errors = array()) |
||
32 | { |
||
33 | global $txt, $scripturl, $topic, $modSettings, $board; |
||
34 | global $user_info, $context, $settings; |
||
35 | global $sourcedir, $smcFunc, $language, $options; |
||
36 | |||
37 | loadLanguage('Post'); |
||
38 | if (!empty($modSettings['drafts_post_enabled'])) |
||
39 | loadLanguage('Drafts'); |
||
40 | |||
41 | // You can't reply with a poll... hacker. |
||
42 | if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg'])) |
||
43 | unset($_REQUEST['poll']); |
||
44 | |||
45 | // Posting an event? |
||
46 | $context['make_event'] = isset($_REQUEST['calendar']); |
||
47 | $context['robot_no_index'] = true; |
||
48 | |||
49 | call_integration_hook('integrate_post_start'); |
||
50 | |||
51 | // Get notification preferences for later |
||
52 | require_once($sourcedir . '/Subs-Notify.php'); |
||
53 | // use $temp to get around "Only variables should be passed by reference" |
||
54 | $temp = getNotifyPrefs($user_info['id']); |
||
55 | $context['notify_prefs'] = (array) array_pop($temp); |
||
56 | $context['auto_notify'] = !empty($context['notify_prefs']['msg_auto_notify']); |
||
57 | |||
58 | // Not in a board? Fine, but we'll make them pick one eventually. |
||
59 | if (empty($board) || $context['make_event']) |
||
60 | { |
||
61 | // Get ids of all the boards they can post in. |
||
62 | $post_permissions = array('post_new'); |
||
63 | if ($modSettings['postmod_active']) |
||
64 | $post_permissions[] = 'post_unapproved_topics'; |
||
65 | |||
66 | $boards = boardsAllowedTo($post_permissions); |
||
67 | if (empty($boards)) |
||
68 | fatal_lang_error('cannot_post_new', false); |
||
69 | |||
70 | // Get a list of boards for the select menu |
||
71 | require_once($sourcedir . '/Subs-MessageIndex.php'); |
||
72 | $boardListOptions = array( |
||
73 | 'included_boards' => in_array(0, $boards) ? null : $boards, |
||
74 | 'not_redirection' => true, |
||
75 | 'use_permissions' => true, |
||
76 | 'selected_board' => !empty($board) ? $board : ($context['make_event'] && !empty($modSettings['cal_defaultboard']) ? $modSettings['cal_defaultboard'] : $boards[0]), |
||
77 | ); |
||
78 | $board_list = getBoardList($boardListOptions); |
||
79 | } |
||
80 | // Let's keep things simple for ourselves below |
||
81 | else |
||
82 | $boards = array($board); |
||
83 | |||
84 | require_once($sourcedir . '/Subs-Post.php'); |
||
85 | |||
86 | if (isset($_REQUEST['xml'])) |
||
87 | { |
||
88 | $context['sub_template'] = 'post'; |
||
89 | |||
90 | // Just in case of an earlier error... |
||
91 | $context['preview_message'] = ''; |
||
92 | $context['preview_subject'] = ''; |
||
93 | } |
||
94 | |||
95 | // No message is complete without a topic. |
||
96 | if (empty($topic) && !empty($_REQUEST['msg'])) |
||
97 | { |
||
98 | $request = $smcFunc['db_query']('', ' |
||
99 | SELECT id_topic |
||
100 | FROM {db_prefix}messages |
||
101 | WHERE id_msg = {int:msg}', |
||
102 | array( |
||
103 | 'msg' => (int) $_REQUEST['msg'], |
||
104 | ) |
||
105 | ); |
||
106 | if ($smcFunc['db_num_rows']($request) != 1) |
||
107 | unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']); |
||
108 | else |
||
109 | list ($topic) = $smcFunc['db_fetch_row']($request); |
||
110 | $smcFunc['db_free_result']($request); |
||
111 | } |
||
112 | |||
113 | // Check if it's locked. It isn't locked if no topic is specified. |
||
114 | if (!empty($topic)) |
||
115 | { |
||
116 | $request = $smcFunc['db_query']('', ' |
||
117 | SELECT |
||
118 | t.locked, t.approved, COALESCE(ln.id_topic, 0) AS notify, t.is_sticky, t.id_poll, t.id_last_msg, mf.id_member, |
||
119 | t.id_first_msg, mf.subject, ml.modified_reason, |
||
120 | CASE WHEN ml.poster_time > ml.modified_time THEN ml.poster_time ELSE ml.modified_time END AS last_post_time |
||
121 | FROM {db_prefix}topics AS t |
||
122 | LEFT JOIN {db_prefix}log_notify AS ln ON (ln.id_topic = t.id_topic AND ln.id_member = {int:current_member}) |
||
123 | LEFT JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg) |
||
124 | LEFT JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg) |
||
125 | WHERE t.id_topic = {int:current_topic} |
||
126 | LIMIT 1', |
||
127 | array( |
||
128 | 'current_member' => $user_info['id'], |
||
129 | 'current_topic' => $topic, |
||
130 | ) |
||
131 | ); |
||
132 | list ($locked, $topic_approved, $context['notify'], $sticky, $pollID, $context['topic_last_message'], $id_member_poster, $id_first_msg, $first_subject, $editReason, $lastPostTime) = $smcFunc['db_fetch_row']($request); |
||
133 | $smcFunc['db_free_result']($request); |
||
134 | |||
135 | // If this topic already has a poll, they sure can't add another. |
||
136 | if (isset($_REQUEST['poll']) && $pollID > 0) |
||
137 | unset($_REQUEST['poll']); |
||
138 | |||
139 | if (empty($_REQUEST['msg'])) |
||
140 | { |
||
141 | if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any'))) |
||
142 | is_not_guest(); |
||
143 | |||
144 | // By default the reply will be approved... |
||
145 | $context['becomes_approved'] = true; |
||
146 | if ($id_member_poster != $user_info['id'] || $user_info['is_guest']) |
||
147 | { |
||
148 | if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) |
||
149 | $context['becomes_approved'] = false; |
||
150 | else |
||
151 | isAllowedTo('post_reply_any'); |
||
152 | } |
||
153 | elseif (!allowedTo('post_reply_any')) |
||
154 | { |
||
155 | if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any'))) |
||
156 | $context['becomes_approved'] = false; |
||
157 | else |
||
158 | isAllowedTo('post_reply_own'); |
||
159 | } |
||
160 | } |
||
161 | else |
||
162 | $context['becomes_approved'] = true; |
||
163 | |||
164 | $context['can_lock'] = allowedTo('lock_any') || ($user_info['id'] == $id_member_poster && allowedTo('lock_own')); |
||
165 | $context['can_sticky'] = allowedTo('make_sticky'); |
||
166 | $context['can_move'] = allowedTo('move_any'); |
||
167 | // You can only announce topics that will get approved... |
||
168 | $context['can_announce'] = allowedTo('announce_topic') && $context['becomes_approved']; |
||
169 | $context['show_approval'] = !allowedTo('approve_posts') ? 0 : ($context['becomes_approved'] ? 2 : 1); |
||
170 | |||
171 | // We don't always want the request vars to override what's in the db... |
||
172 | $context['already_locked'] = $locked; |
||
173 | $context['already_sticky'] = $sticky; |
||
174 | $context['sticky'] = isset($_REQUEST['sticky']) ? !empty($_REQUEST['sticky']) : $sticky; |
||
175 | |||
176 | // Check whether this is a really old post being bumped... |
||
177 | if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject'])) |
||
178 | $post_errors[] = array('old_topic', array($modSettings['oldTopicDays'])); |
||
179 | } |
||
180 | else |
||
181 | { |
||
182 | // @todo Should use JavaScript to hide and show the warning based on the selection in the board select menu |
||
183 | $context['becomes_approved'] = true; |
||
184 | if ($modSettings['postmod_active'] && !allowedTo('post_new', $boards, true) && allowedTo('post_unapproved_topics', $boards, true)) |
||
185 | $context['becomes_approved'] = false; |
||
186 | else |
||
187 | isAllowedTo('post_new', $boards, true); |
||
188 | |||
189 | $locked = 0; |
||
190 | $context['already_locked'] = 0; |
||
191 | $context['already_sticky'] = 0; |
||
192 | $context['sticky'] = !empty($_REQUEST['sticky']); |
||
193 | |||
194 | // What options should we show? |
||
195 | $context['can_lock'] = allowedTo(array('lock_any', 'lock_own'), $boards, true); |
||
196 | $context['can_sticky'] = allowedTo('make_sticky', $boards, true); |
||
197 | $context['can_move'] = allowedTo('move_any', $boards, true); |
||
198 | $context['can_announce'] = allowedTo('announce_topic', $boards, true) && $context['becomes_approved']; |
||
199 | $context['show_approval'] = !allowedTo('approve_posts', $boards, true) ? 0 : ($context['becomes_approved'] ? 2 : 1); |
||
200 | } |
||
201 | |||
202 | $context['notify'] = !empty($context['notify']); |
||
203 | |||
204 | $context['can_notify'] = !$context['user']['is_guest']; |
||
205 | $context['move'] = !empty($_REQUEST['move']); |
||
206 | $context['announce'] = !empty($_REQUEST['announce']); |
||
207 | $context['locked'] = !empty($locked) || !empty($_REQUEST['lock']); |
||
208 | $context['can_quote'] = empty($modSettings['disabledBBC']) || !in_array('quote', explode(',', $modSettings['disabledBBC'])); |
||
209 | |||
210 | // An array to hold all the attachments for this topic. |
||
211 | $context['current_attachments'] = array(); |
||
212 | |||
213 | // Clear out prior attachment activity when starting afresh |
||
214 | if (empty($_REQUEST['message']) && empty($_REQUEST['preview']) && !empty($_SESSION['already_attached'])) |
||
215 | { |
||
216 | require_once($sourcedir . '/ManageAttachments.php'); |
||
217 | foreach ($_SESSION['already_attached'] as $attachID => $attachment) |
||
218 | removeAttachments(array('id_attach' => $attachID)); |
||
219 | |||
220 | unset($_SESSION['already_attached']); |
||
221 | } |
||
222 | |||
223 | // Don't allow a post if it's locked and you aren't all powerful. |
||
224 | if ($locked && !allowedTo('moderate_board')) |
||
225 | fatal_lang_error('topic_locked', false); |
||
226 | // Check the users permissions - is the user allowed to add or post a poll? |
||
227 | if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1') |
||
228 | { |
||
229 | // New topic, new poll. |
||
230 | if (empty($topic)) |
||
231 | isAllowedTo('poll_post'); |
||
232 | // This is an old topic - but it is yours! Can you add to it? |
||
233 | elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any')) |
||
|
|||
234 | isAllowedTo('poll_add_own'); |
||
235 | // If you're not the owner, can you add to any poll? |
||
236 | else |
||
237 | isAllowedTo('poll_add_any'); |
||
238 | |||
239 | if (!empty($board)) |
||
240 | { |
||
241 | require_once($sourcedir . '/Subs-Members.php'); |
||
242 | $allowedVoteGroups = groupsAllowedTo('poll_vote', $board); |
||
243 | $guest_vote_enabled = in_array(-1, $allowedVoteGroups['allowed']); |
||
244 | } |
||
245 | // No board, so we'll have to check this again in Post2 |
||
246 | else |
||
247 | $guest_vote_enabled = true; |
||
248 | |||
249 | // Set up the poll options. |
||
250 | $context['poll_options'] = array( |
||
251 | 'max_votes' => empty($_POST['poll_max_votes']) ? '1' : max(1, $_POST['poll_max_votes']), |
||
252 | 'hide' => empty($_POST['poll_hide']) ? 0 : $_POST['poll_hide'], |
||
253 | 'expire' => !isset($_POST['poll_expire']) ? '' : $_POST['poll_expire'], |
||
254 | 'change_vote' => isset($_POST['poll_change_vote']), |
||
255 | 'guest_vote' => isset($_POST['poll_guest_vote']), |
||
256 | 'guest_vote_enabled' => $guest_vote_enabled, |
||
257 | ); |
||
258 | |||
259 | // Make all five poll choices empty. |
||
260 | $context['choices'] = array( |
||
261 | array('id' => 0, 'number' => 1, 'label' => '', 'is_last' => false), |
||
262 | array('id' => 1, 'number' => 2, 'label' => '', 'is_last' => false), |
||
263 | array('id' => 2, 'number' => 3, 'label' => '', 'is_last' => false), |
||
264 | array('id' => 3, 'number' => 4, 'label' => '', 'is_last' => false), |
||
265 | array('id' => 4, 'number' => 5, 'label' => '', 'is_last' => true) |
||
266 | ); |
||
267 | $context['last_choice_id'] = 4; |
||
268 | } |
||
269 | |||
270 | if ($context['make_event']) |
||
271 | { |
||
272 | // They might want to pick a board. |
||
273 | if (!isset($context['current_board'])) |
||
274 | $context['current_board'] = 0; |
||
275 | |||
276 | // Start loading up the event info. |
||
277 | $context['event'] = array(); |
||
278 | $context['event']['title'] = isset($_REQUEST['evtitle']) ? $smcFunc['htmlspecialchars'](stripslashes($_REQUEST['evtitle'])) : ''; |
||
279 | $context['event']['location'] = isset($_REQUEST['event_location']) ? $smcFunc['htmlspecialchars'](stripslashes($_REQUEST['event_location'])) : ''; |
||
280 | |||
281 | $context['event']['id'] = isset($_REQUEST['eventid']) ? (int) $_REQUEST['eventid'] : -1; |
||
282 | $context['event']['new'] = $context['event']['id'] == -1; |
||
283 | |||
284 | // Permissions check! |
||
285 | isAllowedTo('calendar_post'); |
||
286 | |||
287 | require_once($sourcedir . '/Subs-Calendar.php'); |
||
288 | |||
289 | // We want a fairly compact version of the time, but as close as possible to the user's settings. |
||
290 | $time_string = strtr(get_date_or_time_format('time'), array( |
||
291 | '%I' => '%l', |
||
292 | '%H' => '%k', |
||
293 | '%S' => '', |
||
294 | '%r' => '%l:%M %p', |
||
295 | '%R' => '%k:%M', |
||
296 | '%T' => '%l:%M', |
||
297 | )); |
||
298 | |||
299 | $time_string = preg_replace('~:(?=\s|$|%[pPzZ])~', '', $time_string); |
||
300 | |||
301 | // Editing an event? (but NOT previewing!?) |
||
302 | if (empty($context['event']['new']) && !isset($_REQUEST['subject'])) |
||
303 | { |
||
304 | // If the user doesn't have permission to edit the post in this topic, redirect them. |
||
305 | if ((empty($id_member_poster) || $id_member_poster != $user_info['id'] || !allowedTo('modify_own')) && !allowedTo('modify_any')) |
||
306 | { |
||
307 | require_once($sourcedir . '/Calendar.php'); |
||
308 | return CalendarPost(); |
||
309 | } |
||
310 | |||
311 | // Get the current event information. |
||
312 | $eventProperties = getEventProperties($context['event']['id']); |
||
313 | $context['event'] = array_merge($context['event'], $eventProperties); |
||
314 | } |
||
315 | else |
||
316 | { |
||
317 | // Get the current event information. |
||
318 | $eventProperties = getNewEventDatetimes(); |
||
319 | $context['event'] = array_merge($context['event'], $eventProperties); |
||
320 | |||
321 | // Make sure the year and month are in the valid range. |
||
322 | if ($context['event']['month'] < 1 || $context['event']['month'] > 12) |
||
323 | fatal_lang_error('invalid_month', false); |
||
324 | if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear']) |
||
325 | fatal_lang_error('invalid_year', false); |
||
326 | |||
327 | $context['event']['categories'] = $board_list; |
||
328 | } |
||
329 | |||
330 | // Find the last day of the month. |
||
331 | $context['event']['last_day'] = (int) smf_strftime('%d', mktime(0, 0, 0, $context['event']['month'] == 12 ? 1 : $context['event']['month'] + 1, 0, $context['event']['month'] == 12 ? $context['event']['year'] + 1 : $context['event']['year'])); |
||
332 | |||
333 | // An all day event? Set up some nice defaults in case the user wants to change that |
||
334 | if ($context['event']['allday'] == true) |
||
335 | { |
||
336 | $context['event']['tz'] = getUserTimezone(); |
||
337 | $context['event']['start_time'] = timeformat(time(), $time_string); |
||
338 | $context['event']['end_time'] = timeformat(time() + 3600, $time_string); |
||
339 | } |
||
340 | // Otherwise, just adjust these to look nice on the input form |
||
341 | else |
||
342 | { |
||
343 | $context['event']['start_time'] = $context['event']['start_time_orig']; |
||
344 | $context['event']['end_time'] = $context['event']['end_time_orig']; |
||
345 | } |
||
346 | |||
347 | // Need this so the user can select a timezone for the event. |
||
348 | $context['all_timezones'] = smf_list_timezones($context['event']['start_date']); |
||
349 | |||
350 | // If the event's timezone is not in SMF's standard list of time zones, try to fix it. |
||
351 | if (!isset($context['all_timezones'][$context['event']['tz']])) |
||
352 | { |
||
353 | $later = strtotime('@' . $context['event']['start_timestamp'] . ' + 1 year'); |
||
354 | $tzinfo = timezone_transitions_get(timezone_open($context['event']['tz']), $context['event']['start_timestamp'], $later); |
||
355 | |||
356 | $found = false; |
||
357 | foreach ($context['all_timezones'] as $possible_tzid => $dummy) |
||
358 | { |
||
359 | $possible_tzinfo = timezone_transitions_get(timezone_open($possible_tzid), $context['event']['start_timestamp'], $later); |
||
360 | |||
361 | if ($tzinfo === $possible_tzinfo) |
||
362 | { |
||
363 | $context['event']['tz'] = $possible_tzid; |
||
364 | $found = true; |
||
365 | break; |
||
366 | } |
||
367 | } |
||
368 | |||
369 | // Hm. That's weird. Well, just prepend it to the list and let the user deal with it. |
||
370 | if (!$found) |
||
371 | { |
||
372 | $d = date_create($context['event']['start_datetime'] . ' ' . $context['event']['tz']); |
||
373 | $context['all_timezones'] = array($context['event']['tz'] => '[UTC' . date_format($d, 'P') . '] - ' . $context['event']['tz']) + $context['all_timezones']; |
||
374 | } |
||
375 | } |
||
376 | |||
377 | loadDatePicker('#event_time_input .date_input'); |
||
378 | loadTimePicker('#event_time_input .time_input', $time_string); |
||
379 | loadDatePair('#event_time_input', 'date_input', 'time_input'); |
||
380 | addInlineJavaScript(' |
||
381 | $("#allday").click(function(){ |
||
382 | $("#start_time").attr("disabled", this.checked); |
||
383 | $("#end_time").attr("disabled", this.checked); |
||
384 | $("#tz").attr("disabled", this.checked); |
||
385 | }); ', true); |
||
386 | |||
387 | $context['event']['board'] = !empty($board) ? $board : $modSettings['cal_defaultboard']; |
||
388 | $context['event']['topic'] = !empty($topic) ? $topic : 0; |
||
389 | } |
||
390 | |||
391 | // See if any new replies have come along. |
||
392 | // Huh, $_REQUEST['msg'] is set upon submit, so this doesn't get executed at submit |
||
393 | // only at preview |
||
394 | if (empty($_REQUEST['msg']) && !empty($topic)) |
||
395 | { |
||
396 | if (empty($options['no_new_reply_warning']) && isset($_REQUEST['last_msg']) && $context['topic_last_message'] > $_REQUEST['last_msg']) |
||
397 | { |
||
398 | $request = $smcFunc['db_query']('', ' |
||
399 | SELECT COUNT(*) |
||
400 | FROM {db_prefix}messages |
||
401 | WHERE id_topic = {int:current_topic} |
||
402 | AND id_msg > {int:last_msg}' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : ' |
||
403 | AND approved = {int:approved}') . ' |
||
404 | LIMIT 1', |
||
405 | array( |
||
406 | 'current_topic' => $topic, |
||
407 | 'last_msg' => (int) $_REQUEST['last_msg'], |
||
408 | 'approved' => 1, |
||
409 | ) |
||
410 | ); |
||
411 | list ($context['new_replies']) = $smcFunc['db_fetch_row']($request); |
||
412 | $smcFunc['db_free_result']($request); |
||
413 | |||
414 | if (!empty($context['new_replies'])) |
||
415 | { |
||
416 | if ($context['new_replies'] == 1) |
||
417 | $txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply']; |
||
418 | else |
||
419 | $txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']); |
||
420 | |||
421 | $post_errors[] = 'new_replies'; |
||
422 | |||
423 | $modSettings['topicSummaryPosts'] = $context['new_replies'] > $modSettings['topicSummaryPosts'] ? max($modSettings['topicSummaryPosts'], 5) : $modSettings['topicSummaryPosts']; |
||
424 | } |
||
425 | } |
||
426 | } |
||
427 | |||
428 | // Get a response prefix (like 'Re:') in the default forum language. |
||
429 | if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) |
||
430 | { |
||
431 | if ($language === $user_info['language']) |
||
432 | $context['response_prefix'] = $txt['response_prefix']; |
||
433 | else |
||
434 | { |
||
435 | loadLanguage('index', $language, false); |
||
436 | $context['response_prefix'] = $txt['response_prefix']; |
||
437 | loadLanguage('index'); |
||
438 | } |
||
439 | cache_put_data('response_prefix', $context['response_prefix'], 600); |
||
440 | } |
||
441 | |||
442 | // Previewing, modifying, or posting? |
||
443 | // Do we have a body, but an error happened. |
||
444 | if (isset($_REQUEST['message']) || isset($_REQUEST['quickReply']) || !empty($context['post_error'])) |
||
445 | { |
||
446 | if (isset($_REQUEST['quickReply'])) |
||
447 | $_REQUEST['message'] = $_REQUEST['quickReply']; |
||
448 | |||
449 | // Validate inputs. |
||
450 | if (empty($context['post_error'])) |
||
451 | { |
||
452 | // This means they didn't click Post and get an error. |
||
453 | $really_previewing = true; |
||
454 | } |
||
455 | else |
||
456 | { |
||
457 | if (!isset($_REQUEST['subject'])) |
||
458 | $_REQUEST['subject'] = ''; |
||
459 | if (!isset($_REQUEST['message'])) |
||
460 | $_REQUEST['message'] = ''; |
||
461 | if (!isset($_REQUEST['icon'])) |
||
462 | $_REQUEST['icon'] = 'xx'; |
||
463 | |||
464 | // They are previewing if they asked to preview (i.e. came from quick reply). |
||
465 | $really_previewing = !empty($_POST['preview']); |
||
466 | } |
||
467 | |||
468 | // In order to keep the approval status flowing through, we have to pass it through the form... |
||
469 | $context['becomes_approved'] = empty($_REQUEST['not_approved']); |
||
470 | $context['show_approval'] = isset($_REQUEST['approve']) ? ($_REQUEST['approve'] ? 2 : 1) : (allowedTo('approve_posts') ? 2 : 0); |
||
471 | $context['can_announce'] &= $context['becomes_approved']; |
||
472 | |||
473 | // Set up the inputs for the form. |
||
474 | $form_subject = strtr($smcFunc['htmlspecialchars']($_REQUEST['subject']), array("\r" => '', "\n" => '', "\t" => '')); |
||
475 | $form_message = $smcFunc['htmlspecialchars']($_REQUEST['message'], ENT_QUOTES); |
||
476 | |||
477 | // Make sure the subject isn't too long - taking into account special characters. |
||
478 | if ($smcFunc['strlen']($form_subject) > 100) |
||
479 | $form_subject = $smcFunc['substr']($form_subject, 0, 100); |
||
480 | |||
481 | if (isset($_REQUEST['poll'])) |
||
482 | { |
||
483 | $context['question'] = isset($_REQUEST['question']) ? $smcFunc['htmlspecialchars'](trim($_REQUEST['question'])) : ''; |
||
484 | |||
485 | $context['choices'] = array(); |
||
486 | $choice_id = 0; |
||
487 | |||
488 | $_POST['options'] = empty($_POST['options']) ? array() : htmlspecialchars__recursive($_POST['options']); |
||
489 | foreach ($_POST['options'] as $option) |
||
490 | { |
||
491 | if (trim($option) == '') |
||
492 | continue; |
||
493 | |||
494 | $context['choices'][] = array( |
||
495 | 'id' => $choice_id++, |
||
496 | 'number' => $choice_id, |
||
497 | 'label' => $option, |
||
498 | 'is_last' => false |
||
499 | ); |
||
500 | } |
||
501 | |||
502 | // One empty option for those with js disabled...I know are few... :P |
||
503 | $context['choices'][] = array( |
||
504 | 'id' => $choice_id++, |
||
505 | 'number' => $choice_id, |
||
506 | 'label' => '', |
||
507 | 'is_last' => false |
||
508 | ); |
||
509 | |||
510 | if (count($context['choices']) < 2) |
||
511 | { |
||
512 | $context['choices'][] = array( |
||
513 | 'id' => $choice_id++, |
||
514 | 'number' => $choice_id, |
||
515 | 'label' => '', |
||
516 | 'is_last' => false |
||
517 | ); |
||
518 | } |
||
519 | $context['last_choice_id'] = $choice_id; |
||
520 | $context['choices'][count($context['choices']) - 1]['is_last'] = true; |
||
521 | } |
||
522 | |||
523 | // Are you... a guest? |
||
524 | if ($user_info['is_guest']) |
||
525 | { |
||
526 | $_REQUEST['guestname'] = !isset($_REQUEST['guestname']) ? '' : trim($_REQUEST['guestname']); |
||
527 | $_REQUEST['email'] = !isset($_REQUEST['email']) ? '' : trim($_REQUEST['email']); |
||
528 | |||
529 | $_REQUEST['guestname'] = $smcFunc['htmlspecialchars']($_REQUEST['guestname']); |
||
530 | $context['name'] = $_REQUEST['guestname']; |
||
531 | $_REQUEST['email'] = $smcFunc['htmlspecialchars']($_REQUEST['email']); |
||
532 | $context['email'] = $_REQUEST['email']; |
||
533 | |||
534 | $user_info['name'] = $_REQUEST['guestname']; |
||
535 | } |
||
536 | |||
537 | // Only show the preview stuff if they hit Preview. |
||
538 | if (($really_previewing == true || isset($_REQUEST['xml'])) && !isset($_REQUEST['save_draft'])) |
||
539 | { |
||
540 | // Set up the preview message and subject and censor them... |
||
541 | $context['preview_message'] = $form_message; |
||
542 | preparsecode($form_message, true); |
||
543 | preparsecode($context['preview_message']); |
||
544 | |||
545 | // Do all bulletin board code tags, with or without smileys. |
||
546 | $context['preview_message'] = parse_bbc($context['preview_message'], isset($_REQUEST['ns']) ? 0 : 1); |
||
547 | censorText($context['preview_message']); |
||
548 | |||
549 | if ($form_subject != '') |
||
550 | { |
||
551 | $context['preview_subject'] = $form_subject; |
||
552 | |||
553 | censorText($context['preview_subject']); |
||
554 | } |
||
555 | else |
||
556 | $context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>'; |
||
557 | |||
558 | call_integration_hook('integrate_preview_post', array(&$form_message, &$form_subject)); |
||
559 | |||
560 | // Protect any CDATA blocks. |
||
561 | if (isset($_REQUEST['xml'])) |
||
562 | $context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>')); |
||
563 | } |
||
564 | |||
565 | // Set up the checkboxes. |
||
566 | $context['notify'] = !empty($_REQUEST['notify']); |
||
567 | $context['use_smileys'] = !isset($_REQUEST['ns']); |
||
568 | |||
569 | $context['icon'] = isset($_REQUEST['icon']) ? preg_replace('~[\./\\\\*\':"<>]~', '', $_REQUEST['icon']) : 'xx'; |
||
570 | |||
571 | // Set the destination action for submission. |
||
572 | $context['destination'] = 'post2;start=' . $_REQUEST['start'] . (isset($_REQUEST['msg']) ? ';msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id'] : '') . (isset($_REQUEST['poll']) ? ';poll' : ''); |
||
573 | $context['submit_label'] = isset($_REQUEST['msg']) ? $txt['save'] : $txt['post']; |
||
574 | |||
575 | // Previewing an edit? |
||
576 | if (isset($_REQUEST['msg']) && !empty($topic)) |
||
577 | { |
||
578 | // Get the existing message. Previewing. |
||
579 | $request = $smcFunc['db_query']('', ' |
||
580 | SELECT |
||
581 | m.id_member, m.modified_time, m.smileys_enabled, m.body, |
||
582 | m.poster_name, m.poster_email, m.subject, m.icon, m.approved, |
||
583 | COALESCE(a.size, -1) AS filesize, a.filename, a.id_attach, |
||
584 | a.approved AS attachment_approved, t.id_member_started AS id_member_poster, |
||
585 | m.poster_time, log.id_action, t.id_first_msg |
||
586 | FROM {db_prefix}messages AS m |
||
587 | INNER JOIN {db_prefix}topics AS t ON (t.id_topic = {int:current_topic}) |
||
588 | LEFT JOIN {db_prefix}attachments AS a ON (a.id_msg = m.id_msg AND a.attachment_type = {int:attachment_type}) |
||
589 | LEFT JOIN {db_prefix}log_actions AS log ON (m.id_topic = log.id_topic AND log.action = {string:announce_action}) |
||
590 | WHERE m.id_msg = {int:id_msg} |
||
591 | AND m.id_topic = {int:current_topic}', |
||
592 | array( |
||
593 | 'current_topic' => $topic, |
||
594 | 'attachment_type' => 0, |
||
595 | 'id_msg' => $_REQUEST['msg'], |
||
596 | 'announce_action' => 'announce_topic', |
||
597 | ) |
||
598 | ); |
||
599 | // The message they were trying to edit was most likely deleted. |
||
600 | // @todo Change this error message? |
||
601 | if ($smcFunc['db_num_rows']($request) == 0) |
||
602 | fatal_lang_error('no_board', false); |
||
603 | $row = $smcFunc['db_fetch_assoc']($request); |
||
604 | |||
605 | $attachment_stuff = array($row); |
||
606 | while ($row2 = $smcFunc['db_fetch_assoc']($request)) |
||
607 | $attachment_stuff[] = $row2; |
||
608 | $smcFunc['db_free_result']($request); |
||
609 | |||
610 | if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any')) |
||
611 | { |
||
612 | // Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public. |
||
613 | if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) |
||
614 | fatal_lang_error('modify_post_time_passed', false); |
||
615 | elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) |
||
616 | isAllowedTo('modify_replies'); |
||
617 | else |
||
618 | isAllowedTo('modify_own'); |
||
619 | } |
||
620 | elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) |
||
621 | isAllowedTo('modify_replies'); |
||
622 | else |
||
623 | isAllowedTo('modify_any'); |
||
624 | |||
625 | if ($context['can_announce'] && !empty($row['id_action']) && $row['id_first_msg'] == $_REQUEST['msg']) |
||
626 | { |
||
627 | loadLanguage('Errors'); |
||
628 | $context['post_error']['already_announced'] = $txt['error_topic_already_announced']; |
||
629 | } |
||
630 | |||
631 | if (!empty($modSettings['attachmentEnable'])) |
||
632 | { |
||
633 | $request = $smcFunc['db_query']('', ' |
||
634 | SELECT COALESCE(size, -1) AS filesize, filename, id_attach, approved, mime_type, id_thumb |
||
635 | FROM {db_prefix}attachments |
||
636 | WHERE id_msg = {int:id_msg} |
||
637 | AND attachment_type = {int:attachment_type} |
||
638 | ORDER BY id_attach', |
||
639 | array( |
||
640 | 'id_msg' => (int) $_REQUEST['msg'], |
||
641 | 'attachment_type' => 0, |
||
642 | ) |
||
643 | ); |
||
644 | |||
645 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
646 | { |
||
647 | if ($row['filesize'] <= 0) |
||
648 | continue; |
||
649 | $context['current_attachments'][$row['id_attach']] = array( |
||
650 | 'name' => $smcFunc['htmlspecialchars']($row['filename']), |
||
651 | 'size' => $row['filesize'], |
||
652 | 'attachID' => $row['id_attach'], |
||
653 | 'approved' => $row['approved'], |
||
654 | 'mime_type' => $row['mime_type'], |
||
655 | 'thumb' => $row['id_thumb'], |
||
656 | ); |
||
657 | } |
||
658 | $smcFunc['db_free_result']($request); |
||
659 | } |
||
660 | |||
661 | // Allow moderators to change names.... |
||
662 | if (allowedTo('moderate_forum') && !empty($topic)) |
||
663 | { |
||
664 | $request = $smcFunc['db_query']('', ' |
||
665 | SELECT id_member, poster_name, poster_email |
||
666 | FROM {db_prefix}messages |
||
667 | WHERE id_msg = {int:id_msg} |
||
668 | AND id_topic = {int:current_topic} |
||
669 | LIMIT 1', |
||
670 | array( |
||
671 | 'current_topic' => $topic, |
||
672 | 'id_msg' => (int) $_REQUEST['msg'], |
||
673 | ) |
||
674 | ); |
||
675 | $row = $smcFunc['db_fetch_assoc']($request); |
||
676 | $smcFunc['db_free_result']($request); |
||
677 | |||
678 | if (empty($row['id_member'])) |
||
679 | { |
||
680 | $context['name'] = $smcFunc['htmlspecialchars']($row['poster_name']); |
||
681 | $context['email'] = $smcFunc['htmlspecialchars']($row['poster_email']); |
||
682 | } |
||
683 | } |
||
684 | } |
||
685 | |||
686 | // No check is needed, since nothing is really posted. |
||
687 | checkSubmitOnce('free'); |
||
688 | } |
||
689 | // Editing a message... |
||
690 | elseif (isset($_REQUEST['msg']) && !empty($topic)) |
||
691 | { |
||
692 | $context['editing'] = true; |
||
693 | |||
694 | $_REQUEST['msg'] = (int) $_REQUEST['msg']; |
||
695 | |||
696 | // Get the existing message. Editing. |
||
697 | $request = $smcFunc['db_query']('', ' |
||
698 | SELECT |
||
699 | m.id_member, m.modified_time, m.modified_name, m.modified_reason, m.smileys_enabled, m.body, |
||
700 | m.poster_name, m.poster_email, m.subject, m.icon, m.approved, |
||
701 | COALESCE(a.size, -1) AS filesize, a.filename, a.id_attach, a.mime_type, a.id_thumb, |
||
702 | a.approved AS attachment_approved, t.id_member_started AS id_member_poster, |
||
703 | m.poster_time, log.id_action, t.id_first_msg |
||
704 | FROM {db_prefix}messages AS m |
||
705 | INNER JOIN {db_prefix}topics AS t ON (t.id_topic = {int:current_topic}) |
||
706 | LEFT JOIN {db_prefix}attachments AS a ON (a.id_msg = m.id_msg AND a.attachment_type = {int:attachment_type}) |
||
707 | LEFT JOIN {db_prefix}log_actions AS log ON (m.id_topic = log.id_topic AND log.action = {string:announce_action}) |
||
708 | WHERE m.id_msg = {int:id_msg} |
||
709 | AND m.id_topic = {int:current_topic}', |
||
710 | array( |
||
711 | 'current_topic' => $topic, |
||
712 | 'attachment_type' => 0, |
||
713 | 'id_msg' => $_REQUEST['msg'], |
||
714 | 'announce_action' => 'announce_topic', |
||
715 | ) |
||
716 | ); |
||
717 | // The message they were trying to edit was most likely deleted. |
||
718 | if ($smcFunc['db_num_rows']($request) == 0) |
||
719 | fatal_lang_error('no_message', false); |
||
720 | $row = $smcFunc['db_fetch_assoc']($request); |
||
721 | |||
722 | $attachment_stuff = array($row); |
||
723 | while ($row2 = $smcFunc['db_fetch_assoc']($request)) |
||
724 | $attachment_stuff[] = $row2; |
||
725 | $smcFunc['db_free_result']($request); |
||
726 | |||
727 | if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any')) |
||
728 | { |
||
729 | // Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public. |
||
730 | if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) |
||
731 | fatal_lang_error('modify_post_time_passed', false); |
||
732 | elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) |
||
733 | isAllowedTo('modify_replies'); |
||
734 | else |
||
735 | isAllowedTo('modify_own'); |
||
736 | } |
||
737 | elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) |
||
738 | isAllowedTo('modify_replies'); |
||
739 | else |
||
740 | isAllowedTo('modify_any'); |
||
741 | |||
742 | if ($context['can_announce'] && !empty($row['id_action']) && $row['id_first_msg'] == $_REQUEST['msg']) |
||
743 | { |
||
744 | loadLanguage('Errors'); |
||
745 | $context['post_error']['already_announced'] = $txt['error_topic_already_announced']; |
||
746 | } |
||
747 | |||
748 | // When was it last modified? |
||
749 | if (!empty($row['modified_time'])) |
||
750 | { |
||
751 | $context['last_modified'] = timeformat($row['modified_time']); |
||
752 | $context['last_modified_reason'] = censorText($row['modified_reason']); |
||
753 | $context['last_modified_text'] = sprintf($txt['last_edit_by'], $context['last_modified'], $row['modified_name']) . empty($row['modified_reason']) ? '' : ' ' . $txt['last_edit_reason'] . ': ' . $row['modified_reason']; |
||
754 | } |
||
755 | |||
756 | // Get the stuff ready for the form. |
||
757 | $form_subject = $row['subject']; |
||
758 | $form_message = un_preparsecode($row['body']); |
||
759 | censorText($form_message); |
||
760 | censorText($form_subject); |
||
761 | |||
762 | // Check the boxes that should be checked. |
||
763 | $context['use_smileys'] = !empty($row['smileys_enabled']); |
||
764 | $context['icon'] = $row['icon']; |
||
765 | |||
766 | // Leave the approval checkbox unchecked by default for unapproved messages. |
||
767 | if (!$row['approved'] && !empty($context['show_approval'])) |
||
768 | $context['show_approval'] = 1; |
||
769 | |||
770 | // Sort the attachments so they are in the order saved |
||
771 | $temp = array(); |
||
772 | foreach ($attachment_stuff as $attachment) |
||
773 | { |
||
774 | if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable'])) |
||
775 | $temp[$attachment['id_attach']] = $attachment; |
||
776 | } |
||
777 | ksort($temp); |
||
778 | |||
779 | // Load up 'em attachments! |
||
780 | foreach ($temp as $attachment) |
||
781 | { |
||
782 | $context['current_attachments'][$attachment['id_attach']] = array( |
||
783 | 'name' => $smcFunc['htmlspecialchars']($attachment['filename']), |
||
784 | 'size' => $attachment['filesize'], |
||
785 | 'attachID' => $attachment['id_attach'], |
||
786 | 'approved' => $attachment['attachment_approved'], |
||
787 | 'mime_type' => $attachment['mime_type'], |
||
788 | 'thumb' => $attachment['id_thumb'], |
||
789 | ); |
||
790 | } |
||
791 | |||
792 | // Allow moderators to change names.... |
||
793 | if (allowedTo('moderate_forum') && empty($row['id_member'])) |
||
794 | { |
||
795 | $context['name'] = $smcFunc['htmlspecialchars']($row['poster_name']); |
||
796 | $context['email'] = $smcFunc['htmlspecialchars']($row['poster_email']); |
||
797 | } |
||
798 | |||
799 | // Set the destination. |
||
800 | $context['destination'] = 'post2;start=' . $_REQUEST['start'] . ';msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id'] . (isset($_REQUEST['poll']) ? ';poll' : ''); |
||
801 | $context['submit_label'] = $txt['save']; |
||
802 | } |
||
803 | // Posting... |
||
804 | else |
||
805 | { |
||
806 | // By default.... |
||
807 | $context['use_smileys'] = true; |
||
808 | $context['icon'] = 'xx'; |
||
809 | |||
810 | if ($user_info['is_guest']) |
||
811 | { |
||
812 | $context['name'] = isset($_SESSION['guest_name']) ? $_SESSION['guest_name'] : ''; |
||
813 | $context['email'] = isset($_SESSION['guest_email']) ? $_SESSION['guest_email'] : ''; |
||
814 | } |
||
815 | $context['destination'] = 'post2;start=' . $_REQUEST['start'] . (isset($_REQUEST['poll']) ? ';poll' : ''); |
||
816 | |||
817 | $context['submit_label'] = $txt['post']; |
||
818 | |||
819 | // Posting a quoted reply? |
||
820 | if (!empty($topic) && !empty($_REQUEST['quote'])) |
||
821 | { |
||
822 | // Make sure they _can_ quote this post, and if so get it. |
||
823 | $request = $smcFunc['db_query']('', ' |
||
824 | SELECT m.subject, COALESCE(mem.real_name, m.poster_name) AS poster_name, m.poster_time, m.body |
||
825 | FROM {db_prefix}messages AS m |
||
826 | LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : ' |
||
827 | INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)') . ' |
||
828 | WHERE {query_see_message_board} |
||
829 | AND m.id_msg = {int:id_msg}' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : ' |
||
830 | AND m.approved = {int:is_approved} |
||
831 | AND t.approved = {int:is_approved}') . ' |
||
832 | LIMIT 1', |
||
833 | array( |
||
834 | 'id_msg' => (int) $_REQUEST['quote'], |
||
835 | 'is_approved' => 1, |
||
836 | ) |
||
837 | ); |
||
838 | if ($smcFunc['db_num_rows']($request) == 0) |
||
839 | fatal_lang_error('quoted_post_deleted', false); |
||
840 | list ($form_subject, $mname, $mdate, $form_message) = $smcFunc['db_fetch_row']($request); |
||
841 | $smcFunc['db_free_result']($request); |
||
842 | |||
843 | // Add 'Re: ' to the front of the quoted subject. |
||
844 | if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) |
||
845 | $form_subject = $context['response_prefix'] . $form_subject; |
||
846 | |||
847 | // Censor the message and subject. |
||
848 | censorText($form_message); |
||
849 | censorText($form_subject); |
||
850 | |||
851 | // But if it's in HTML world, turn them into htmlspecialchar's so they can be edited! |
||
852 | if (strpos($form_message, '[html]') !== false) |
||
853 | { |
||
854 | $parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $form_message, -1, PREG_SPLIT_DELIM_CAPTURE); |
||
855 | for ($i = 0, $n = count($parts); $i < $n; $i++) |
||
856 | { |
||
857 | // It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat. |
||
858 | if ($i % 4 == 0) |
||
859 | $parts[$i] = preg_replace_callback( |
||
860 | '~\[html\](.+?)\[/html\]~is', |
||
861 | function($m) |
||
862 | { |
||
863 | return '[html]' . preg_replace('~<br\s?/?' . '>~i', '<br /><br>', "$m[1]") . '[/html]'; |
||
864 | }, |
||
865 | $parts[$i] |
||
866 | ); |
||
867 | } |
||
868 | $form_message = implode('', $parts); |
||
869 | } |
||
870 | |||
871 | $form_message = preg_replace('~<br ?/?' . '>~i', "\n", $form_message); |
||
872 | |||
873 | // Remove any nested quotes, if necessary. |
||
874 | if (!empty($modSettings['removeNestedQuotes'])) |
||
875 | $form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message); |
||
876 | |||
877 | // Add a quote string on the front and end. |
||
878 | $form_message = '[quote author=' . $mname . ' link=msg=' . (int) $_REQUEST['quote'] . ' date=' . $mdate . ']' . "\n" . rtrim($form_message) . "\n" . '[/quote]'; |
||
879 | } |
||
880 | // Posting a reply without a quote? |
||
881 | elseif (!empty($topic) && empty($_REQUEST['quote'])) |
||
882 | { |
||
883 | // Get the first message's subject. |
||
884 | $form_subject = $first_subject; |
||
885 | |||
886 | // Add 'Re: ' to the front of the subject. |
||
887 | if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) |
||
888 | $form_subject = $context['response_prefix'] . $form_subject; |
||
889 | |||
890 | // Censor the subject. |
||
891 | censorText($form_subject); |
||
892 | |||
893 | $form_message = ''; |
||
894 | } |
||
895 | else |
||
896 | { |
||
897 | $form_subject = isset($_GET['subject']) ? $_GET['subject'] : ''; |
||
898 | $form_message = ''; |
||
899 | } |
||
900 | } |
||
901 | |||
902 | $context['can_post_attachment'] = !empty($modSettings['attachmentEnable']) && $modSettings['attachmentEnable'] == 1 && (allowedTo('post_attachment', $boards, true) || ($modSettings['postmod_active'] && allowedTo('post_unapproved_attachments', $boards, true))); |
||
903 | |||
904 | if ($context['can_post_attachment']) |
||
905 | { |
||
906 | // If there are attachments, calculate the total size and how many. |
||
907 | $context['attachments']['total_size'] = 0; |
||
908 | $context['attachments']['quantity'] = 0; |
||
909 | |||
910 | // If this isn't a new post, check the current attachments. |
||
911 | if (isset($_REQUEST['msg'])) |
||
912 | { |
||
913 | $context['attachments']['quantity'] = count($context['current_attachments']); |
||
914 | foreach ($context['current_attachments'] as $attachment) |
||
915 | $context['attachments']['total_size'] += $attachment['size']; |
||
916 | } |
||
917 | |||
918 | // A bit of house keeping first. |
||
919 | if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) |
||
920 | unset($_SESSION['temp_attachments']); |
||
921 | |||
922 | if (!empty($_SESSION['temp_attachments'])) |
||
923 | { |
||
924 | // Is this a request to delete them? |
||
925 | if (isset($_GET['delete_temp'])) |
||
926 | { |
||
927 | foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
||
928 | { |
||
929 | if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
||
930 | if (file_exists($attachment['tmp_name'])) |
||
931 | unlink($attachment['tmp_name']); |
||
932 | } |
||
933 | $post_errors[] = 'temp_attachments_gone'; |
||
934 | $_SESSION['temp_attachments'] = array(); |
||
935 | } |
||
936 | // Hmm, coming in fresh and there are files in session. |
||
937 | elseif ($context['current_action'] != 'post2' || !empty($_POST['from_qr'])) |
||
938 | { |
||
939 | // Let's be nice and see if they belong here first. |
||
940 | if ((empty($_REQUEST['msg']) && empty($_SESSION['temp_attachments']['post']['msg']) && $_SESSION['temp_attachments']['post']['board'] == (!empty($board) ? $board : 0)) || (!empty($_REQUEST['msg']) && $_SESSION['temp_attachments']['post']['msg'] == $_REQUEST['msg'])) |
||
941 | { |
||
942 | // See if any files still exist before showing the warning message and the files attached. |
||
943 | foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
||
944 | { |
||
945 | if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false) |
||
946 | continue; |
||
947 | |||
948 | if (file_exists($attachment['tmp_name'])) |
||
949 | { |
||
950 | $post_errors[] = 'temp_attachments_new'; |
||
951 | $context['files_in_session_warning'] = $txt['attached_files_in_session']; |
||
952 | unset($_SESSION['temp_attachments']['post']['files']); |
||
953 | break; |
||
954 | } |
||
955 | } |
||
956 | } |
||
957 | else |
||
958 | { |
||
959 | // Since, they don't belong here. Let's inform the user that they exist.. |
||
960 | if (!empty($topic)) |
||
961 | $delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp'; |
||
962 | else |
||
963 | $delete_url = $scripturl . '?action=post' . (!empty($board) ? ';board=' . $board : '') . ';delete_temp'; |
||
964 | |||
965 | // Compile a list of the files to show the user. |
||
966 | $file_list = array(); |
||
967 | foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
||
968 | if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
||
969 | $file_list[] = $attachment['name']; |
||
970 | |||
971 | $_SESSION['temp_attachments']['post']['files'] = $file_list; |
||
972 | $file_list = '<div class="attachments">' . implode('<br>', $file_list) . '</div>'; |
||
973 | |||
974 | if (!empty($_SESSION['temp_attachments']['post']['msg'])) |
||
975 | { |
||
976 | // We have a message id, so we can link back to the old topic they were trying to edit.. |
||
977 | $goback_url = $scripturl . '?action=post' . (!empty($_SESSION['temp_attachments']['post']['msg']) ? (';msg=' . $_SESSION['temp_attachments']['post']['msg']) : '') . (!empty($_SESSION['temp_attachments']['post']['last_msg']) ? (';last_msg=' . $_SESSION['temp_attachments']['post']['last_msg']) : '') . ';topic=' . $_SESSION['temp_attachments']['post']['topic'] . ';additionalOptions'; |
||
978 | |||
979 | $post_errors[] = array('temp_attachments_found', array($delete_url, $goback_url, $file_list)); |
||
980 | $context['ignore_temp_attachments'] = true; |
||
981 | } |
||
982 | else |
||
983 | { |
||
984 | $post_errors[] = array('temp_attachments_lost', array($delete_url, $file_list)); |
||
985 | $context['ignore_temp_attachments'] = true; |
||
986 | } |
||
987 | } |
||
988 | } |
||
989 | |||
990 | if (!empty($context['we_are_history'])) |
||
991 | $post_errors[] = $context['we_are_history']; |
||
992 | |||
993 | foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
||
994 | { |
||
995 | if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files'])) |
||
996 | break; |
||
997 | |||
998 | if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) |
||
999 | continue; |
||
1000 | |||
1001 | if ($attachID == 'initial_error') |
||
1002 | { |
||
1003 | $txt['error_attach_initial_error'] = $txt['attach_no_upload'] . '<div style="padding: 0 1em;">' . (is_array($attachment) ? vsprintf($txt[$attachment[0]], (array) $attachment[1]) : $txt[$attachment]) . '</div>'; |
||
1004 | $post_errors[] = 'attach_initial_error'; |
||
1005 | unset($_SESSION['temp_attachments']); |
||
1006 | break; |
||
1007 | } |
||
1008 | |||
1009 | // Show any errors which might have occurred. |
||
1010 | if (!empty($attachment['errors'])) |
||
1011 | { |
||
1012 | $txt['error_attach_errors'] = empty($txt['error_attach_errors']) ? '<br>' : ''; |
||
1013 | $txt['error_attach_errors'] .= sprintf($txt['attach_warning'], $attachment['name']) . '<div style="padding: 0 1em;">'; |
||
1014 | foreach ($attachment['errors'] as $error) |
||
1015 | $txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], (array) $error[1]) : $txt[$error]) . '<br >'; |
||
1016 | $txt['error_attach_errors'] .= '</div>'; |
||
1017 | $post_errors[] = 'attach_errors'; |
||
1018 | |||
1019 | // Take out the trash. |
||
1020 | unset($_SESSION['temp_attachments'][$attachID]); |
||
1021 | if (file_exists($attachment['tmp_name'])) |
||
1022 | unlink($attachment['tmp_name']); |
||
1023 | continue; |
||
1024 | } |
||
1025 | |||
1026 | // More house keeping. |
||
1027 | if (!file_exists($attachment['tmp_name'])) |
||
1028 | { |
||
1029 | unset($_SESSION['temp_attachments'][$attachID]); |
||
1030 | continue; |
||
1031 | } |
||
1032 | |||
1033 | $context['attachments']['quantity']++; |
||
1034 | $context['attachments']['total_size'] += $attachment['size']; |
||
1035 | if (!isset($context['files_in_session_warning'])) |
||
1036 | $context['files_in_session_warning'] = $txt['attached_files_in_session']; |
||
1037 | |||
1038 | $context['current_attachments'][$attachID] = array( |
||
1039 | 'name' => $smcFunc['htmlspecialchars']($attachment['name']), |
||
1040 | 'size' => $attachment['size'], |
||
1041 | 'attachID' => $attachID, |
||
1042 | 'unchecked' => false, |
||
1043 | 'approved' => 1, |
||
1044 | 'mime_type' => '', |
||
1045 | 'thumb' => 0, |
||
1046 | ); |
||
1047 | } |
||
1048 | } |
||
1049 | } |
||
1050 | |||
1051 | // Allow user to see previews for all of this post's attachments, even if the post hasn't been submitted yet. |
||
1052 | if (!isset($_SESSION['attachments_can_preview'])) |
||
1053 | $_SESSION['attachments_can_preview'] = array(); |
||
1054 | |||
1055 | if (!empty($_SESSION['already_attached'])) |
||
1056 | $_SESSION['attachments_can_preview'] += array_fill_keys(array_keys($_SESSION['already_attached']), true); |
||
1057 | |||
1058 | foreach ($context['current_attachments'] as $attachID => $attachment) |
||
1059 | { |
||
1060 | $_SESSION['attachments_can_preview'][$attachID] = true; |
||
1061 | |||
1062 | if (!empty($attachment['thumb'])) |
||
1063 | $_SESSION['attachments_can_preview'][$attachment['thumb']] = true; |
||
1064 | } |
||
1065 | |||
1066 | // Do we need to show the visual verification image? |
||
1067 | $context['require_verification'] = !$user_info['is_mod'] && !$user_info['is_admin'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1)); |
||
1068 | if ($context['require_verification']) |
||
1069 | { |
||
1070 | require_once($sourcedir . '/Subs-Editor.php'); |
||
1071 | $verificationOptions = array( |
||
1072 | 'id' => 'post', |
||
1073 | ); |
||
1074 | $context['require_verification'] = create_control_verification($verificationOptions); |
||
1075 | $context['visual_verification_id'] = $verificationOptions['id']; |
||
1076 | } |
||
1077 | |||
1078 | // If they came from quick reply, and have to enter verification details, give them some notice. |
||
1079 | if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification'])) |
||
1080 | $post_errors[] = 'need_qr_verification'; |
||
1081 | |||
1082 | /* |
||
1083 | * There are two error types: serious and minor. Serious errors |
||
1084 | * actually tell the user that a real error has occurred, while minor |
||
1085 | * errors are like warnings that let them know that something with |
||
1086 | * their post isn't right. |
||
1087 | */ |
||
1088 | $minor_errors = array('not_approved', 'new_replies', 'old_topic', 'need_qr_verification', 'no_subject', 'topic_locked', 'topic_unlocked', 'topic_stickied', 'topic_unstickied', 'cannot_post_attachment'); |
||
1089 | |||
1090 | call_integration_hook('integrate_post_errors', array(&$post_errors, &$minor_errors, $form_message, $form_subject)); |
||
1091 | |||
1092 | // Any errors occurred? |
||
1093 | if (!empty($post_errors)) |
||
1094 | { |
||
1095 | loadLanguage('Errors'); |
||
1096 | $context['error_type'] = 'minor'; |
||
1097 | foreach ($post_errors as $post_error) |
||
1098 | if (is_array($post_error)) |
||
1099 | { |
||
1100 | $post_error_id = $post_error[0]; |
||
1101 | $context['post_error'][$post_error_id] = vsprintf($txt['error_' . $post_error_id], (array) $post_error[1]); |
||
1102 | |||
1103 | // If it's not a minor error flag it as such. |
||
1104 | if (!in_array($post_error_id, $minor_errors)) |
||
1105 | $context['error_type'] = 'serious'; |
||
1106 | } |
||
1107 | else |
||
1108 | { |
||
1109 | $context['post_error'][$post_error] = $txt['error_' . $post_error]; |
||
1110 | |||
1111 | // If it's not a minor error flag it as such. |
||
1112 | if (!in_array($post_error, $minor_errors)) |
||
1113 | $context['error_type'] = 'serious'; |
||
1114 | } |
||
1115 | } |
||
1116 | |||
1117 | // What are you doing? Posting a poll, modifying, previewing, new post, or reply... |
||
1118 | if (isset($_REQUEST['poll'])) |
||
1119 | $context['page_title'] = $txt['new_poll']; |
||
1120 | elseif ($context['make_event']) |
||
1121 | $context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit']; |
||
1122 | elseif (isset($_REQUEST['msg'])) |
||
1123 | $context['page_title'] = $txt['modify_msg']; |
||
1124 | elseif (isset($_REQUEST['subject'], $context['preview_subject'])) |
||
1125 | $context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']); |
||
1126 | elseif (empty($topic)) |
||
1127 | $context['page_title'] = $txt['start_new_topic']; |
||
1128 | else |
||
1129 | $context['page_title'] = $txt['post_reply']; |
||
1130 | |||
1131 | // Build the link tree. |
||
1132 | if (empty($topic)) |
||
1133 | $context['linktree'][] = array( |
||
1134 | 'name' => '<em>' . $txt['start_new_topic'] . '</em>' |
||
1135 | ); |
||
1136 | else |
||
1137 | $context['linktree'][] = array( |
||
1138 | 'url' => $scripturl . '?topic=' . $topic . '.' . $_REQUEST['start'], |
||
1139 | 'name' => $form_subject, |
||
1140 | 'extra_before' => '<span><strong class="nav">' . $context['page_title'] . ' (</strong></span>', |
||
1141 | 'extra_after' => '<span><strong class="nav">)</strong></span>' |
||
1142 | ); |
||
1143 | |||
1144 | $context['subject'] = addcslashes($form_subject, '"'); |
||
1145 | $context['message'] = str_replace(array('"', '<', '>', ' '), array('"', '<', '>', ' '), $form_message); |
||
1146 | |||
1147 | // Are post drafts enabled? |
||
1148 | $context['drafts_save'] = !empty($modSettings['drafts_post_enabled']) && allowedTo('post_draft'); |
||
1149 | $context['drafts_autosave'] = !empty($context['drafts_save']) && !empty($modSettings['drafts_autosave_enabled']) && allowedTo('post_autosave_draft') && !empty($options['drafts_autosave_enabled']); |
||
1150 | |||
1151 | // Build a list of drafts that they can load in to the editor |
||
1152 | if (!empty($context['drafts_save'])) |
||
1153 | { |
||
1154 | require_once($sourcedir . '/Drafts.php'); |
||
1155 | ShowDrafts($user_info['id'], $topic); |
||
1156 | } |
||
1157 | |||
1158 | // Needed for the editor and message icons. |
||
1159 | require_once($sourcedir . '/Subs-Editor.php'); |
||
1160 | |||
1161 | // Now create the editor. |
||
1162 | $editorOptions = array( |
||
1163 | 'id' => 'message', |
||
1164 | 'value' => $context['message'], |
||
1165 | 'labels' => array( |
||
1166 | 'post_button' => $context['submit_label'], |
||
1167 | ), |
||
1168 | // add height and width for the editor |
||
1169 | 'height' => '175px', |
||
1170 | 'width' => '100%', |
||
1171 | // We do XML preview here. |
||
1172 | 'preview_type' => 2, |
||
1173 | 'required' => true, |
||
1174 | ); |
||
1175 | create_control_richedit($editorOptions); |
||
1176 | |||
1177 | // Store the ID. |
||
1178 | $context['post_box_name'] = $editorOptions['id']; |
||
1179 | |||
1180 | $context['attached'] = ''; |
||
1181 | $context['make_poll'] = isset($_REQUEST['poll']); |
||
1182 | |||
1183 | // Message icons - customized icons are off? |
||
1184 | $context['icons'] = getMessageIcons(!empty($board) ? $board : 0); |
||
1185 | |||
1186 | if (!empty($context['icons'])) |
||
1187 | $context['icons'][count($context['icons']) - 1]['is_last'] = true; |
||
1188 | |||
1189 | // Are we starting a poll? if set the poll icon as selected if its available |
||
1190 | if (isset($_REQUEST['poll'])) |
||
1191 | { |
||
1192 | foreach ($context['icons'] as $icons) |
||
1193 | { |
||
1194 | if (isset($icons['value']) && $icons['value'] == 'poll') |
||
1195 | { |
||
1196 | // if found we are done |
||
1197 | $context['icon'] = 'poll'; |
||
1198 | break; |
||
1199 | } |
||
1200 | } |
||
1201 | } |
||
1202 | |||
1203 | $context['icon_url'] = ''; |
||
1204 | for ($i = 0, $n = count($context['icons']); $i < $n; $i++) |
||
1205 | { |
||
1206 | $context['icons'][$i]['selected'] = $context['icon'] == $context['icons'][$i]['value']; |
||
1207 | if ($context['icons'][$i]['selected']) |
||
1208 | $context['icon_url'] = $context['icons'][$i]['url']; |
||
1209 | } |
||
1210 | if (empty($context['icon_url'])) |
||
1211 | { |
||
1212 | $context['icon_url'] = $settings[file_exists($settings['theme_dir'] . '/images/post/' . $context['icon'] . '.png') ? 'images_url' : 'default_images_url'] . '/post/' . $context['icon'] . '.png'; |
||
1213 | array_unshift($context['icons'], array( |
||
1214 | 'value' => $context['icon'], |
||
1215 | 'name' => $txt['current_icon'], |
||
1216 | 'url' => $context['icon_url'], |
||
1217 | 'is_last' => empty($context['icons']), |
||
1218 | 'selected' => true, |
||
1219 | )); |
||
1220 | } |
||
1221 | |||
1222 | if (!empty($topic) && !empty($modSettings['topicSummaryPosts'])) |
||
1223 | getTopic(); |
||
1224 | |||
1225 | // If the user can post attachments prepare the warning labels. |
||
1226 | if ($context['can_post_attachment']) |
||
1227 | { |
||
1228 | // If they've unchecked an attachment, they may still want to attach that many more files, but don't allow more than num_allowed_attachments. |
||
1229 | $context['num_allowed_attachments'] = min(ini_get('max_file_uploads'), (empty($modSettings['attachmentNumPerPostLimit']) ? 50 : $modSettings['attachmentNumPerPostLimit'])); |
||
1230 | $context['can_post_attachment_unapproved'] = allowedTo('post_attachment'); |
||
1231 | $context['attachment_restrictions'] = array(); |
||
1232 | $context['allowed_extensions'] = !empty($modSettings['attachmentCheckExtensions']) ? (strtr(strtolower($modSettings['attachmentExtensions']), array(',' => ', '))) : ''; |
||
1233 | $attachmentRestrictionTypes = array('attachmentNumPerPostLimit', 'attachmentPostLimit', 'attachmentSizeLimit'); |
||
1234 | foreach ($attachmentRestrictionTypes as $type) |
||
1235 | if (!empty($modSettings[$type])) |
||
1236 | { |
||
1237 | $context['attachment_restrictions'][$type] = sprintf($txt['attach_restrict_' . $type . ($modSettings[$type] >= 1024 ? '_MB' : '')], comma_format($modSettings[$type] >= 1024 ? $modSettings[$type] / 1024 : $modSettings[$type], 2)); |
||
1238 | |||
1239 | // Show the max number of attachments if not 0. |
||
1240 | if ($type == 'attachmentNumPerPostLimit') |
||
1241 | { |
||
1242 | $context['attachment_restrictions'][$type] .= ' (' . sprintf($txt['attach_remaining'], max($modSettings['attachmentNumPerPostLimit'] - $context['attachments']['quantity'], 0)) . ')'; |
||
1243 | } |
||
1244 | elseif ($type == 'attachmentPostLimit' && $context['attachments']['total_size'] > 0) |
||
1245 | { |
||
1246 | $context['attachment_restrictions'][$type] .= '<span class="attach_available"> (' . sprintf($txt['attach_available'], max($modSettings['attachmentPostLimit'] - ($context['attachments']['total_size'] / 1024), 0)) . ')</span>'; |
||
1247 | } |
||
1248 | |||
1249 | } |
||
1250 | } |
||
1251 | |||
1252 | $context['back_to_topic'] = isset($_REQUEST['goback']) || (isset($_REQUEST['msg']) && !isset($_REQUEST['subject'])); |
||
1253 | $context['show_additional_options'] = !empty($_POST['additional_options']) || isset($_SESSION['temp_attachments']['post']) || isset($_GET['additionalOptions']); |
||
1254 | |||
1255 | $context['is_new_topic'] = empty($topic); |
||
1256 | $context['is_new_post'] = !isset($_REQUEST['msg']); |
||
1257 | $context['is_first_post'] = $context['is_new_topic'] || (isset($_REQUEST['msg']) && $_REQUEST['msg'] == $id_first_msg); |
||
1258 | |||
1259 | // Register this form in the session variables. |
||
1260 | checkSubmitOnce('register'); |
||
1261 | |||
1262 | // Mentions |
||
1263 | if (!empty($modSettings['enable_mentions']) && allowedTo('mention')) |
||
1264 | { |
||
1265 | loadJavaScriptFile('jquery.caret.min.js', array('defer' => true), 'smf_caret'); |
||
1266 | loadJavaScriptFile('jquery.atwho.min.js', array('defer' => true), 'smf_atwho'); |
||
1267 | loadJavaScriptFile('mentions.js', array('defer' => true, 'minimize' => true), 'smf_mentions'); |
||
1268 | } |
||
1269 | |||
1270 | // Load the drafts js file |
||
1271 | if ($context['drafts_autosave']) |
||
1272 | loadJavaScriptFile('drafts.js', array('defer' => false, 'minimize' => true), 'smf_drafts'); |
||
1273 | |||
1274 | // quotedText.js |
||
1275 | loadJavaScriptFile('quotedText.js', array('defer' => true, 'minimize' => true), 'smf_quotedText'); |
||
1276 | |||
1277 | addInlineJavaScript(' |
||
1278 | var current_attachments = [];'); |
||
1279 | |||
1280 | if (!empty($context['current_attachments'])) |
||
1281 | { |
||
1282 | // Mock files to show already attached files. |
||
1283 | foreach ($context['current_attachments'] as $key => $mock) |
||
1284 | addInlineJavaScript(' |
||
1285 | current_attachments.push({ |
||
1286 | name: ' . JavaScriptEscape($mock['name']) . ', |
||
1287 | size: ' . $mock['size'] . ', |
||
1288 | attachID: ' . $mock['attachID'] . ', |
||
1289 | approved: ' . $mock['approved'] . ', |
||
1290 | type: ' . JavaScriptEscape(!empty($mock['mime_type']) ? $mock['mime_type'] : '') . ', |
||
1291 | thumbID: ' . (!empty($mock['thumb']) ? $mock['thumb'] : 0) . ' |
||
1292 | });'); |
||
1293 | } |
||
1294 | |||
1295 | // File Upload. |
||
1296 | if ($context['can_post_attachment']) |
||
1297 | { |
||
1298 | $acceptedFiles = empty($context['allowed_extensions']) ? '' : implode(',', array_map( |
||
1299 | function ($val) use ($smcFunc) |
||
1300 | { |
||
1301 | return !empty($val) ? ('.' . $smcFunc['htmltrim']($val)) : ''; |
||
1302 | }, |
||
1303 | explode(',', $context['allowed_extensions']) |
||
1304 | )); |
||
1305 | |||
1306 | loadJavaScriptFile('dropzone.min.js', array('defer' => true), 'smf_dropzone'); |
||
1307 | loadJavaScriptFile('smf_fileUpload.js', array('defer' => true, 'minimize' => true), 'smf_fileUpload'); |
||
1308 | addInlineJavaScript(' |
||
1309 | $(function() { |
||
1310 | smf_fileUpload({ |
||
1311 | dictDefaultMessage : ' . JavaScriptEscape($txt['attach_drop_zone']) . ', |
||
1312 | dictFallbackMessage : ' . JavaScriptEscape($txt['attach_drop_zone_no']) . ', |
||
1313 | dictCancelUpload : ' . JavaScriptEscape($txt['modify_cancel']) . ', |
||
1314 | genericError: ' . JavaScriptEscape($txt['attach_php_error']) . ', |
||
1315 | text_attachLeft: ' . JavaScriptEscape($txt['attachments_left']) . ', |
||
1316 | text_deleteAttach: ' . JavaScriptEscape($txt['attached_file_delete']) . ', |
||
1317 | text_attachDeleted: ' . JavaScriptEscape($txt['attached_file_deleted']) . ', |
||
1318 | text_insertBBC: ' . JavaScriptEscape($txt['attached_insert_bbc']) . ', |
||
1319 | text_attachUploaded: ' . JavaScriptEscape($txt['attached_file_uploaded']) . ', |
||
1320 | text_attach_unlimited: ' . JavaScriptEscape($txt['attach_drop_unlimited']) . ', |
||
1321 | text_totalMaxSize: ' . JavaScriptEscape($txt['attach_max_total_file_size_current']) . ', |
||
1322 | text_max_size_progress: ' . JavaScriptEscape($txt['attach_max_size_progress']) . ', |
||
1323 | dictMaxFilesExceeded: ' . JavaScriptEscape($txt['more_attachments_error']) . ', |
||
1324 | dictInvalidFileType: ' . JavaScriptEscape(sprintf($txt['cant_upload_type'], $context['allowed_extensions'])) . ', |
||
1325 | dictFileTooBig: ' . JavaScriptEscape(sprintf($txt['file_too_big'], comma_format($modSettings['attachmentSizeLimit'], 0))) . ', |
||
1326 | acceptedFiles: ' . JavaScriptEscape($acceptedFiles) . ', |
||
1327 | thumbnailWidth: ' . (!empty($modSettings['attachmentThumbWidth']) ? $modSettings['attachmentThumbWidth'] : 'null') . ', |
||
1328 | thumbnailHeight: ' . (!empty($modSettings['attachmentThumbHeight']) ? $modSettings['attachmentThumbHeight'] : 'null') . ', |
||
1329 | limitMultiFileUploadSize:' . round(max($modSettings['attachmentPostLimit'] - ($context['attachments']['total_size'] / 1024), 0)) * 1024 . ', |
||
1330 | maxFileAmount: ' . (!empty($context['num_allowed_attachments']) ? $context['num_allowed_attachments'] : 'null') . ', |
||
1331 | maxTotalSize: ' . (!empty($modSettings['attachmentPostLimit']) ? $modSettings['attachmentPostLimit'] : '0') . ', |
||
1332 | maxFilesize: ' . (!empty($modSettings['attachmentSizeLimit']) ? $modSettings['attachmentSizeLimit'] : '0') . ', |
||
1333 | }); |
||
1334 | });', true); |
||
1335 | } |
||
1336 | |||
1337 | // Knowing the current board ID might be handy. |
||
1338 | addInlineJavaScript(' |
||
1339 | var current_board = ' . (empty($context['current_board']) ? 'null' : $context['current_board']) . ';', false); |
||
1340 | |||
1341 | /* Now let's set up the fields for the posting form header... |
||
1342 | |||
1343 | Each item in $context['posting_fields'] is an array similar to one of |
||
1344 | the following: |
||
1345 | |||
1346 | $context['posting_fields']['foo'] = array( |
||
1347 | 'label' => array( |
||
1348 | 'text' => $txt['foo'], // required |
||
1349 | 'class' => 'foo', // optional |
||
1350 | ), |
||
1351 | 'input' => array( |
||
1352 | 'type' => 'text', // required |
||
1353 | 'attributes' => array( |
||
1354 | 'name' => 'foo', // optional, defaults to posting field's key |
||
1355 | 'value' => $foo, |
||
1356 | 'size' => 80, |
||
1357 | ), |
||
1358 | ), |
||
1359 | ); |
||
1360 | |||
1361 | $context['posting_fields']['bar'] = array( |
||
1362 | 'label' => array( |
||
1363 | 'text' => $txt['bar'], // required |
||
1364 | 'class' => 'bar', // optional |
||
1365 | ), |
||
1366 | 'input' => array( |
||
1367 | 'type' => 'select', // required |
||
1368 | 'attributes' => array( |
||
1369 | 'name' => 'bar', // optional, defaults to posting field's key |
||
1370 | ), |
||
1371 | 'options' => array( |
||
1372 | 'option_1' => array( |
||
1373 | 'label' => $txt['option_1'], |
||
1374 | 'value' => '1', |
||
1375 | 'selected' => true, |
||
1376 | ), |
||
1377 | 'option_2' => array( |
||
1378 | 'label' => $txt['option_2'], |
||
1379 | 'value' => '2', |
||
1380 | 'selected' => false, |
||
1381 | ), |
||
1382 | 'opt_group_1' => array( |
||
1383 | 'label' => $txt['opt_group_1'], |
||
1384 | 'options' => array( |
||
1385 | 'option_3' => array( |
||
1386 | 'label' => $txt['option_3'], |
||
1387 | 'value' => '3', |
||
1388 | 'selected' => false, |
||
1389 | ), |
||
1390 | 'option_4' => array( |
||
1391 | 'label' => $txt['option_4'], |
||
1392 | 'value' => '4', |
||
1393 | 'selected' => false, |
||
1394 | ), |
||
1395 | ), |
||
1396 | ), |
||
1397 | ), |
||
1398 | ), |
||
1399 | ); |
||
1400 | |||
1401 | $context['posting_fields']['baz'] = array( |
||
1402 | 'label' => array( |
||
1403 | 'text' => $txt['baz'], // required |
||
1404 | 'class' => 'baz', // optional |
||
1405 | ), |
||
1406 | 'input' => array( |
||
1407 | 'type' => 'radio_select', // required |
||
1408 | 'attributes' => array( |
||
1409 | 'name' => 'baz', // optional, defaults to posting field's key |
||
1410 | ), |
||
1411 | 'options' => array( |
||
1412 | 'option_1' => array( |
||
1413 | 'label' => $txt['option_1'], |
||
1414 | 'value' => '1', |
||
1415 | 'selected' => true, |
||
1416 | ), |
||
1417 | 'option_2' => array( |
||
1418 | 'label' => $txt['option_2'], |
||
1419 | 'value' => '2', |
||
1420 | 'selected' => false, |
||
1421 | ), |
||
1422 | ), |
||
1423 | ), |
||
1424 | ); |
||
1425 | |||
1426 | The label and input elements are required. The label text and input |
||
1427 | type are also required. Other elements may be required or optional |
||
1428 | depending on the situation. |
||
1429 | |||
1430 | The input type can be one of the following: |
||
1431 | |||
1432 | - text, password, color, date, datetime-local, email, month, number, |
||
1433 | range, tel, time, url, or week |
||
1434 | - textarea |
||
1435 | - checkbox |
||
1436 | - select |
||
1437 | - radio_select |
||
1438 | |||
1439 | When the input type is text (etc.), textarea, or checkbox, the |
||
1440 | 'attributes' element is used to specify the initial value and any |
||
1441 | other HTML attributes that might be necessary for the input field. |
||
1442 | |||
1443 | When the input type is select or radio_select, the options element |
||
1444 | is required in order to list the options that the user can select. |
||
1445 | For the select type, these will be used to generate a typical select |
||
1446 | menu. For the radio_select type, they will be used to make a div with |
||
1447 | some radio buttons in it. |
||
1448 | |||
1449 | Each option in the options array is itself an array of attributes. If |
||
1450 | an option contains a sub-array of more options, then it will be |
||
1451 | turned into an optgroup in the generated select menu. Note that the |
||
1452 | radio_select type only supports simple options, not grouped ones. |
||
1453 | |||
1454 | Both the label and the input can have a 'before' and/or 'after' |
||
1455 | element. If used, these define literal HTML strings to be inserted |
||
1456 | before or after the rest of the content of the label or input. |
||
1457 | |||
1458 | Finally, it is possible to define an 'html' element for the label |
||
1459 | and/or the input. If used, this will override the HTML that would |
||
1460 | normally be generated in the template file using the other |
||
1461 | information in the array. This should be avoided if at all possible. |
||
1462 | */ |
||
1463 | $context['posting_fields'] = array(); |
||
1464 | |||
1465 | // Guests must supply their name and email. |
||
1466 | if (isset($context['name']) && isset($context['email'])) |
||
1467 | { |
||
1468 | $context['posting_fields']['guestname'] = array( |
||
1469 | 'label' => array( |
||
1470 | 'text' => $txt['name'], |
||
1471 | 'class' => isset($context['post_error']['long_name']) || isset($context['post_error']['no_name']) || isset($context['post_error']['bad_name']) ? 'error' : '', |
||
1472 | ), |
||
1473 | 'input' => array( |
||
1474 | 'type' => 'text', |
||
1475 | 'attributes' => array( |
||
1476 | 'size' => 25, |
||
1477 | 'maxlength' => 25, |
||
1478 | 'value' => $context['name'], |
||
1479 | 'required' => true, |
||
1480 | ), |
||
1481 | ), |
||
1482 | ); |
||
1483 | |||
1484 | if (empty($modSettings['guest_post_no_email'])) |
||
1485 | { |
||
1486 | $context['posting_fields']['email'] = array( |
||
1487 | 'label' => array( |
||
1488 | 'text' => $txt['email'], |
||
1489 | 'class' => isset($context['post_error']['no_email']) || isset($context['post_error']['bad_email']) ? 'error' : '', |
||
1490 | ), |
||
1491 | 'input' => array( |
||
1492 | 'type' => 'email', |
||
1493 | 'attributes' => array( |
||
1494 | 'size' => 25, |
||
1495 | 'value' => $context['email'], |
||
1496 | 'required' => true, |
||
1497 | ), |
||
1498 | ), |
||
1499 | ); |
||
1500 | } |
||
1501 | } |
||
1502 | |||
1503 | // Gotta post it somewhere. |
||
1504 | if (empty($board)) |
||
1505 | { |
||
1506 | $context['posting_fields']['board'] = array( |
||
1507 | 'label' => array( |
||
1508 | 'text' => $txt['calendar_post_in'], |
||
1509 | ), |
||
1510 | 'input' => array( |
||
1511 | 'type' => 'select', |
||
1512 | 'options' => array(), |
||
1513 | ), |
||
1514 | ); |
||
1515 | foreach ($board_list as $category) |
||
1516 | { |
||
1517 | $context['posting_fields']['board']['input']['options'][$category['name']] = array('options' => array()); |
||
1518 | |||
1519 | foreach ($category['boards'] as $brd) |
||
1520 | $context['posting_fields']['board']['input']['options'][$category['name']]['options'][$brd['name']] = array( |
||
1521 | 'value' => $brd['id'], |
||
1522 | 'selected' => (bool) $brd['selected'], |
||
1523 | 'label' => ($brd['child_level'] > 0 ? str_repeat('==', $brd['child_level'] - 1) . '=>' : '') . ' ' . $brd['name'], |
||
1524 | ); |
||
1525 | } |
||
1526 | } |
||
1527 | |||
1528 | // Gotta have a subject. |
||
1529 | $context['posting_fields']['subject'] = array( |
||
1530 | 'label' => array( |
||
1531 | 'text' => $txt['subject'], |
||
1532 | 'class' => isset($context['post_error']['no_subject']) ? 'error' : '', |
||
1533 | ), |
||
1534 | 'input' => array( |
||
1535 | 'type' => 'text', |
||
1536 | 'attributes' => array( |
||
1537 | 'size' => 80, |
||
1538 | 'maxlength' => 80 + (!empty($topic) ? $smcFunc['strlen']($context['response_prefix']) : 0), |
||
1539 | 'value' => $context['subject'], |
||
1540 | 'required' => true, |
||
1541 | ), |
||
1542 | ), |
||
1543 | ); |
||
1544 | |||
1545 | // Icons are fun. |
||
1546 | $context['posting_fields']['icon'] = array( |
||
1547 | 'label' => array( |
||
1548 | 'text' => $txt['message_icon'], |
||
1549 | ), |
||
1550 | 'input' => array( |
||
1551 | 'type' => 'select', |
||
1552 | 'attributes' => array( |
||
1553 | 'id' => 'icon', |
||
1554 | 'onchange' => 'showimage();', |
||
1555 | ), |
||
1556 | 'options' => array(), |
||
1557 | 'after' => ' <img id="icons" src="' . $context['icon_url'] . '">', |
||
1558 | ), |
||
1559 | ); |
||
1560 | foreach ($context['icons'] as $icon) |
||
1561 | { |
||
1562 | $context['posting_fields']['icon']['input']['options'][$icon['name']] = array( |
||
1563 | 'value' => $icon['value'], |
||
1564 | 'selected' => $icon['value'] == $context['icon'], |
||
1565 | ); |
||
1566 | } |
||
1567 | |||
1568 | // Finally, load the template. |
||
1569 | if (!isset($_REQUEST['xml'])) |
||
1570 | loadTemplate('Post'); |
||
1571 | |||
1572 | call_integration_hook('integrate_post_end'); |
||
1573 | } |
||
3246 | ?> |