Conditions | 329 |
Total Lines | 1484 |
Code Lines | 748 |
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; |
||
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 | // Editing an event? (but NOT previewing!?) |
||
300 | if (empty($context['event']['new']) && !isset($_REQUEST['subject'])) |
||
301 | { |
||
302 | // If the user doesn't have permission to edit the post in this topic, redirect them. |
||
303 | if ((empty($id_member_poster) || $id_member_poster != $user_info['id'] || !allowedTo('modify_own')) && !allowedTo('modify_any')) |
||
304 | { |
||
305 | require_once($sourcedir . '/Calendar.php'); |
||
306 | return CalendarPost(); |
||
307 | } |
||
308 | |||
309 | // Get the current event information. |
||
310 | $eventProperties = getEventProperties($context['event']['id']); |
||
311 | $context['event'] = array_merge($context['event'], $eventProperties); |
||
312 | } |
||
313 | else |
||
314 | { |
||
315 | // Get the current event information. |
||
316 | $eventProperties = getNewEventDatetimes(); |
||
317 | $context['event'] = array_merge($context['event'], $eventProperties); |
||
318 | |||
319 | // Make sure the year and month are in the valid range. |
||
320 | if ($context['event']['month'] < 1 || $context['event']['month'] > 12) |
||
321 | fatal_lang_error('invalid_month', false); |
||
322 | if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear']) |
||
323 | fatal_lang_error('invalid_year', false); |
||
324 | |||
325 | $context['event']['categories'] = $board_list; |
||
326 | } |
||
327 | |||
328 | // Find the last day of the month. |
||
329 | $context['event']['last_day'] = (int) 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'])); |
||
330 | |||
331 | // An all day event? Set up some nice defaults in case the user wants to change that |
||
332 | if ($context['event']['allday'] == true) |
||
333 | { |
||
334 | $context['event']['tz'] = getUserTimezone(); |
||
335 | $context['event']['start_time'] = timeformat(time(), $time_string); |
||
336 | $context['event']['end_time'] = timeformat(time() + 3600, $time_string); |
||
337 | } |
||
338 | // Otherwise, just adjust these to look nice on the input form |
||
339 | else |
||
340 | { |
||
341 | $context['event']['start_time'] = $context['event']['start_time_orig']; |
||
342 | $context['event']['end_time'] = $context['event']['end_time_orig']; |
||
343 | } |
||
344 | |||
345 | // Need this so the user can select a timezone for the event. |
||
346 | $context['all_timezones'] = smf_list_timezones($context['event']['start_date']); |
||
347 | unset($context['all_timezones']['']); |
||
348 | |||
349 | // If the event's timezone is not in SMF's standard list of time zones, prepend it to the list |
||
350 | if (!in_array($context['event']['tz'], array_keys($context['all_timezones']))) |
||
351 | { |
||
352 | $d = date_create($context['event']['start_datetime'] . ' ' . $context['event']['tz']); |
||
353 | $context['all_timezones'] = array($context['event']['tz'] => '[UTC' . date_format($d, 'P') . '] - ' . $context['event']['tz']) + $context['all_timezones']; |
||
354 | } |
||
355 | |||
356 | loadDatePicker('#event_time_input .date_input'); |
||
357 | loadTimePicker('#event_time_input .date_input', $time_string); |
||
358 | loadDatePair('#event_time_input', 'date_input', 'time_input'); |
||
359 | addInlineJavaScript(' |
||
360 | $("#allday").click(function(){ |
||
361 | $("#start_time").attr("disabled", this.checked); |
||
362 | $("#end_time").attr("disabled", this.checked); |
||
363 | $("#tz").attr("disabled", this.checked); |
||
364 | }); ', true); |
||
365 | |||
366 | $context['event']['board'] = !empty($board) ? $board : $modSettings['cal_defaultboard']; |
||
367 | $context['event']['topic'] = !empty($topic) ? $topic : 0; |
||
368 | } |
||
369 | |||
370 | // See if any new replies have come along. |
||
371 | // Huh, $_REQUEST['msg'] is set upon submit, so this doesn't get executed at submit |
||
372 | // only at preview |
||
373 | if (empty($_REQUEST['msg']) && !empty($topic)) |
||
374 | { |
||
375 | if (isset($_REQUEST['last_msg']) && $context['topic_last_message'] > $_REQUEST['last_msg']) |
||
376 | { |
||
377 | $request = $smcFunc['db_query']('', ' |
||
378 | SELECT COUNT(*) |
||
379 | FROM {db_prefix}messages |
||
380 | WHERE id_topic = {int:current_topic} |
||
381 | AND id_msg > {int:last_msg}' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : ' |
||
382 | AND approved = {int:approved}') . ' |
||
383 | LIMIT 1', |
||
384 | array( |
||
385 | 'current_topic' => $topic, |
||
386 | 'last_msg' => (int) $_REQUEST['last_msg'], |
||
387 | 'approved' => 1, |
||
388 | ) |
||
389 | ); |
||
390 | list ($context['new_replies']) = $smcFunc['db_fetch_row']($request); |
||
391 | $smcFunc['db_free_result']($request); |
||
392 | |||
393 | if (!empty($context['new_replies'])) |
||
394 | { |
||
395 | if ($context['new_replies'] == 1) |
||
396 | $txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply']; |
||
397 | else |
||
398 | $txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']); |
||
399 | |||
400 | $post_errors[] = 'new_replies'; |
||
401 | |||
402 | $modSettings['topicSummaryPosts'] = $context['new_replies'] > $modSettings['topicSummaryPosts'] ? max($modSettings['topicSummaryPosts'], 5) : $modSettings['topicSummaryPosts']; |
||
403 | } |
||
404 | } |
||
405 | } |
||
406 | |||
407 | // Get a response prefix (like 'Re:') in the default forum language. |
||
408 | if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) |
||
409 | { |
||
410 | if ($language === $user_info['language']) |
||
411 | $context['response_prefix'] = $txt['response_prefix']; |
||
412 | else |
||
413 | { |
||
414 | loadLanguage('index', $language, false); |
||
415 | $context['response_prefix'] = $txt['response_prefix']; |
||
416 | loadLanguage('index'); |
||
417 | } |
||
418 | cache_put_data('response_prefix', $context['response_prefix'], 600); |
||
419 | } |
||
420 | |||
421 | // Previewing, modifying, or posting? |
||
422 | // Do we have a body, but an error happened. |
||
423 | if (isset($_REQUEST['message']) || isset($_REQUEST['quickReply']) || !empty($context['post_error'])) |
||
424 | { |
||
425 | if (isset($_REQUEST['quickReply'])) |
||
426 | $_REQUEST['message'] = $_REQUEST['quickReply']; |
||
427 | |||
428 | // Validate inputs. |
||
429 | if (empty($context['post_error'])) |
||
430 | { |
||
431 | // This means they didn't click Post and get an error. |
||
432 | $really_previewing = true; |
||
433 | } |
||
434 | else |
||
435 | { |
||
436 | if (!isset($_REQUEST['subject'])) |
||
437 | $_REQUEST['subject'] = ''; |
||
438 | if (!isset($_REQUEST['message'])) |
||
439 | $_REQUEST['message'] = ''; |
||
440 | if (!isset($_REQUEST['icon'])) |
||
441 | $_REQUEST['icon'] = 'xx'; |
||
442 | |||
443 | // They are previewing if they asked to preview (i.e. came from quick reply). |
||
444 | $really_previewing = !empty($_POST['preview']); |
||
445 | } |
||
446 | |||
447 | // In order to keep the approval status flowing through, we have to pass it through the form... |
||
448 | $context['becomes_approved'] = empty($_REQUEST['not_approved']); |
||
449 | $context['show_approval'] = isset($_REQUEST['approve']) ? ($_REQUEST['approve'] ? 2 : 1) : allowedTo('approve_posts') ? 2 : 0; |
||
450 | $context['can_announce'] &= $context['becomes_approved']; |
||
451 | |||
452 | // Set up the inputs for the form. |
||
453 | $form_subject = strtr($smcFunc['htmlspecialchars']($_REQUEST['subject']), array("\r" => '', "\n" => '', "\t" => '')); |
||
454 | $form_message = $smcFunc['htmlspecialchars']($_REQUEST['message'], ENT_QUOTES); |
||
455 | |||
456 | // Make sure the subject isn't too long - taking into account special characters. |
||
457 | if ($smcFunc['strlen']($form_subject) > 100) |
||
458 | $form_subject = $smcFunc['substr']($form_subject, 0, 100); |
||
459 | |||
460 | if (isset($_REQUEST['poll'])) |
||
461 | { |
||
462 | $context['question'] = isset($_REQUEST['question']) ? $smcFunc['htmlspecialchars'](trim($_REQUEST['question'])) : ''; |
||
463 | |||
464 | $context['choices'] = array(); |
||
465 | $choice_id = 0; |
||
466 | |||
467 | $_POST['options'] = empty($_POST['options']) ? array() : htmlspecialchars__recursive($_POST['options']); |
||
468 | foreach ($_POST['options'] as $option) |
||
469 | { |
||
470 | if (trim($option) == '') |
||
471 | continue; |
||
472 | |||
473 | $context['choices'][] = array( |
||
474 | 'id' => $choice_id++, |
||
475 | 'number' => $choice_id, |
||
476 | 'label' => $option, |
||
477 | 'is_last' => false |
||
478 | ); |
||
479 | } |
||
480 | |||
481 | // One empty option for those with js disabled...I know are few... :P |
||
482 | $context['choices'][] = array( |
||
483 | 'id' => $choice_id++, |
||
484 | 'number' => $choice_id, |
||
485 | 'label' => '', |
||
486 | 'is_last' => false |
||
487 | ); |
||
488 | |||
489 | if (count($context['choices']) < 2) |
||
490 | { |
||
491 | $context['choices'][] = array( |
||
492 | 'id' => $choice_id++, |
||
493 | 'number' => $choice_id, |
||
494 | 'label' => '', |
||
495 | 'is_last' => false |
||
496 | ); |
||
497 | } |
||
498 | $context['last_choice_id'] = $choice_id; |
||
499 | $context['choices'][count($context['choices']) - 1]['is_last'] = true; |
||
500 | } |
||
501 | |||
502 | // Are you... a guest? |
||
503 | if ($user_info['is_guest']) |
||
504 | { |
||
505 | $_REQUEST['guestname'] = !isset($_REQUEST['guestname']) ? '' : trim($_REQUEST['guestname']); |
||
506 | $_REQUEST['email'] = !isset($_REQUEST['email']) ? '' : trim($_REQUEST['email']); |
||
507 | |||
508 | $_REQUEST['guestname'] = $smcFunc['htmlspecialchars']($_REQUEST['guestname']); |
||
509 | $context['name'] = $_REQUEST['guestname']; |
||
510 | $_REQUEST['email'] = $smcFunc['htmlspecialchars']($_REQUEST['email']); |
||
511 | $context['email'] = $_REQUEST['email']; |
||
512 | |||
513 | $user_info['name'] = $_REQUEST['guestname']; |
||
514 | } |
||
515 | |||
516 | // Only show the preview stuff if they hit Preview. |
||
517 | if (($really_previewing == true || isset($_REQUEST['xml'])) && !isset($_REQUEST['save_draft'])) |
||
518 | { |
||
519 | // Set up the preview message and subject and censor them... |
||
520 | $context['preview_message'] = $form_message; |
||
521 | preparsecode($form_message, true); |
||
522 | preparsecode($context['preview_message']); |
||
523 | |||
524 | // Do all bulletin board code tags, with or without smileys. |
||
525 | $context['preview_message'] = parse_bbc($context['preview_message'], isset($_REQUEST['ns']) ? 0 : 1); |
||
526 | censorText($context['preview_message']); |
||
527 | |||
528 | if ($form_subject != '') |
||
529 | { |
||
530 | $context['preview_subject'] = $form_subject; |
||
531 | |||
532 | censorText($context['preview_subject']); |
||
533 | } |
||
534 | else |
||
535 | $context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>'; |
||
536 | |||
537 | // Protect any CDATA blocks. |
||
538 | if (isset($_REQUEST['xml'])) |
||
539 | $context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>')); |
||
540 | } |
||
541 | |||
542 | // Set up the checkboxes. |
||
543 | $context['notify'] = !empty($_REQUEST['notify']); |
||
544 | $context['use_smileys'] = !isset($_REQUEST['ns']); |
||
545 | |||
546 | $context['icon'] = isset($_REQUEST['icon']) ? preg_replace('~[\./\\\\*\':"<>]~', '', $_REQUEST['icon']) : 'xx'; |
||
547 | |||
548 | // Set the destination action for submission. |
||
549 | $context['destination'] = 'post2;start=' . $_REQUEST['start'] . (isset($_REQUEST['msg']) ? ';msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id'] : '') . (isset($_REQUEST['poll']) ? ';poll' : ''); |
||
550 | $context['submit_label'] = isset($_REQUEST['msg']) ? $txt['save'] : $txt['post']; |
||
551 | |||
552 | // Previewing an edit? |
||
553 | if (isset($_REQUEST['msg']) && !empty($topic)) |
||
554 | { |
||
555 | // Get the existing message. Previewing. |
||
556 | $request = $smcFunc['db_query']('', ' |
||
557 | SELECT |
||
558 | m.id_member, m.modified_time, m.smileys_enabled, m.body, |
||
559 | m.poster_name, m.poster_email, m.subject, m.icon, m.approved, |
||
560 | COALESCE(a.size, -1) AS filesize, a.filename, a.id_attach, |
||
561 | a.approved AS attachment_approved, t.id_member_started AS id_member_poster, |
||
562 | m.poster_time, log.id_action |
||
563 | FROM {db_prefix}messages AS m |
||
564 | INNER JOIN {db_prefix}topics AS t ON (t.id_topic = {int:current_topic}) |
||
565 | LEFT JOIN {db_prefix}attachments AS a ON (a.id_msg = m.id_msg AND a.attachment_type = {int:attachment_type}) |
||
566 | LEFT JOIN {db_prefix}log_actions AS log ON (m.id_topic = log.id_topic AND log.action = {string:announce_action}) |
||
567 | WHERE m.id_msg = {int:id_msg} |
||
568 | AND m.id_topic = {int:current_topic}', |
||
569 | array( |
||
570 | 'current_topic' => $topic, |
||
571 | 'attachment_type' => 0, |
||
572 | 'id_msg' => $_REQUEST['msg'], |
||
573 | 'announce_action' => 'announce_topic', |
||
574 | ) |
||
575 | ); |
||
576 | // The message they were trying to edit was most likely deleted. |
||
577 | // @todo Change this error message? |
||
578 | if ($smcFunc['db_num_rows']($request) == 0) |
||
579 | fatal_lang_error('no_board', false); |
||
580 | $row = $smcFunc['db_fetch_assoc']($request); |
||
581 | |||
582 | $attachment_stuff = array($row); |
||
583 | while ($row2 = $smcFunc['db_fetch_assoc']($request)) |
||
584 | $attachment_stuff[] = $row2; |
||
585 | $smcFunc['db_free_result']($request); |
||
586 | |||
587 | if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any')) |
||
588 | { |
||
589 | // Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public. |
||
590 | if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) |
||
591 | fatal_lang_error('modify_post_time_passed', false); |
||
592 | elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) |
||
593 | isAllowedTo('modify_replies'); |
||
594 | else |
||
595 | isAllowedTo('modify_own'); |
||
596 | } |
||
597 | elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) |
||
598 | isAllowedTo('modify_replies'); |
||
599 | else |
||
600 | isAllowedTo('modify_any'); |
||
601 | |||
602 | if ($context['can_announce'] && !empty($row['id_action'])) |
||
603 | { |
||
604 | loadLanguage('Errors'); |
||
605 | $context['post_error']['messages'][] = $txt['error_topic_already_announced']; |
||
606 | } |
||
607 | |||
608 | if (!empty($modSettings['attachmentEnable'])) |
||
609 | { |
||
610 | $request = $smcFunc['db_query']('', ' |
||
611 | SELECT COALESCE(size, -1) AS filesize, filename, id_attach, approved, mime_type, id_thumb |
||
612 | FROM {db_prefix}attachments |
||
613 | WHERE id_msg = {int:id_msg} |
||
614 | AND attachment_type = {int:attachment_type} |
||
615 | ORDER BY id_attach', |
||
616 | array( |
||
617 | 'id_msg' => (int) $_REQUEST['msg'], |
||
618 | 'attachment_type' => 0, |
||
619 | ) |
||
620 | ); |
||
621 | |||
622 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
623 | { |
||
624 | if ($row['filesize'] <= 0) |
||
625 | continue; |
||
626 | $context['current_attachments'][$row['id_attach']] = array( |
||
627 | 'name' => $smcFunc['htmlspecialchars']($row['filename']), |
||
628 | 'size' => $row['filesize'], |
||
629 | 'attachID' => $row['id_attach'], |
||
630 | 'approved' => $row['approved'], |
||
631 | 'mime_type' => $row['mime_type'], |
||
632 | 'thumb' => $row['id_thumb'], |
||
633 | ); |
||
634 | } |
||
635 | $smcFunc['db_free_result']($request); |
||
636 | } |
||
637 | |||
638 | // Allow moderators to change names.... |
||
639 | if (allowedTo('moderate_forum') && !empty($topic)) |
||
640 | { |
||
641 | $request = $smcFunc['db_query']('', ' |
||
642 | SELECT id_member, poster_name, poster_email |
||
643 | FROM {db_prefix}messages |
||
644 | WHERE id_msg = {int:id_msg} |
||
645 | AND id_topic = {int:current_topic} |
||
646 | LIMIT 1', |
||
647 | array( |
||
648 | 'current_topic' => $topic, |
||
649 | 'id_msg' => (int) $_REQUEST['msg'], |
||
650 | ) |
||
651 | ); |
||
652 | $row = $smcFunc['db_fetch_assoc']($request); |
||
653 | $smcFunc['db_free_result']($request); |
||
654 | |||
655 | if (empty($row['id_member'])) |
||
656 | { |
||
657 | $context['name'] = $smcFunc['htmlspecialchars']($row['poster_name']); |
||
658 | $context['email'] = $smcFunc['htmlspecialchars']($row['poster_email']); |
||
659 | } |
||
660 | } |
||
661 | } |
||
662 | |||
663 | // No check is needed, since nothing is really posted. |
||
664 | checkSubmitOnce('free'); |
||
665 | } |
||
666 | // Editing a message... |
||
667 | elseif (isset($_REQUEST['msg']) && !empty($topic)) |
||
668 | { |
||
669 | $context['editing'] = true; |
||
670 | |||
671 | $_REQUEST['msg'] = (int) $_REQUEST['msg']; |
||
672 | |||
673 | // Get the existing message. Editing. |
||
674 | $request = $smcFunc['db_query']('', ' |
||
675 | SELECT |
||
676 | m.id_member, m.modified_time, m.modified_name, m.modified_reason, m.smileys_enabled, m.body, |
||
677 | m.poster_name, m.poster_email, m.subject, m.icon, m.approved, |
||
678 | COALESCE(a.size, -1) AS filesize, a.filename, a.id_attach, a.mime_type, a.id_thumb, |
||
679 | a.approved AS attachment_approved, t.id_member_started AS id_member_poster, |
||
680 | m.poster_time, log.id_action |
||
681 | FROM {db_prefix}messages AS m |
||
682 | INNER JOIN {db_prefix}topics AS t ON (t.id_topic = {int:current_topic}) |
||
683 | LEFT JOIN {db_prefix}attachments AS a ON (a.id_msg = m.id_msg AND a.attachment_type = {int:attachment_type}) |
||
684 | LEFT JOIN {db_prefix}log_actions AS log ON (m.id_topic = log.id_topic AND log.action = {string:announce_action}) |
||
685 | WHERE m.id_msg = {int:id_msg} |
||
686 | AND m.id_topic = {int:current_topic}', |
||
687 | array( |
||
688 | 'current_topic' => $topic, |
||
689 | 'attachment_type' => 0, |
||
690 | 'id_msg' => $_REQUEST['msg'], |
||
691 | 'announce_action' => 'announce_topic', |
||
692 | ) |
||
693 | ); |
||
694 | // The message they were trying to edit was most likely deleted. |
||
695 | if ($smcFunc['db_num_rows']($request) == 0) |
||
696 | fatal_lang_error('no_message', false); |
||
697 | $row = $smcFunc['db_fetch_assoc']($request); |
||
698 | |||
699 | $attachment_stuff = array($row); |
||
700 | while ($row2 = $smcFunc['db_fetch_assoc']($request)) |
||
701 | $attachment_stuff[] = $row2; |
||
702 | $smcFunc['db_free_result']($request); |
||
703 | |||
704 | if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any')) |
||
705 | { |
||
706 | // Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public. |
||
707 | if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) |
||
708 | fatal_lang_error('modify_post_time_passed', false); |
||
709 | elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) |
||
710 | isAllowedTo('modify_replies'); |
||
711 | else |
||
712 | isAllowedTo('modify_own'); |
||
713 | } |
||
714 | elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) |
||
715 | isAllowedTo('modify_replies'); |
||
716 | else |
||
717 | isAllowedTo('modify_any'); |
||
718 | |||
719 | if ($context['can_announce'] && !empty($row['id_action'])) |
||
720 | { |
||
721 | loadLanguage('Errors'); |
||
722 | $context['post_error']['messages'][] = $txt['error_topic_already_announced']; |
||
723 | } |
||
724 | |||
725 | // When was it last modified? |
||
726 | if (!empty($row['modified_time'])) |
||
727 | { |
||
728 | $context['last_modified'] = timeformat($row['modified_time']); |
||
729 | $context['last_modified_reason'] = censorText($row['modified_reason']); |
||
730 | $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']; |
||
731 | } |
||
732 | |||
733 | // Get the stuff ready for the form. |
||
734 | $form_subject = $row['subject']; |
||
735 | $form_message = un_preparsecode($row['body']); |
||
736 | censorText($form_message); |
||
737 | censorText($form_subject); |
||
738 | |||
739 | // Check the boxes that should be checked. |
||
740 | $context['use_smileys'] = !empty($row['smileys_enabled']); |
||
741 | $context['icon'] = $row['icon']; |
||
742 | |||
743 | // Leave the approval checkbox unchecked by default for unapproved messages. |
||
744 | if (!$row['approved'] && !empty($context['show_approval'])) |
||
745 | $context['show_approval'] = 1; |
||
746 | |||
747 | // Sort the attachments so they are in the order saved |
||
748 | $temp = array(); |
||
749 | foreach ($attachment_stuff as $attachment) |
||
750 | { |
||
751 | if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable'])) |
||
752 | $temp[$attachment['id_attach']] = $attachment; |
||
753 | } |
||
754 | ksort($temp); |
||
755 | |||
756 | // Load up 'em attachments! |
||
757 | foreach ($temp as $attachment) |
||
758 | { |
||
759 | $context['current_attachments'][$attachment['id_attach']] = array( |
||
760 | 'name' => $smcFunc['htmlspecialchars']($attachment['filename']), |
||
761 | 'size' => $attachment['filesize'], |
||
762 | 'attachID' => $attachment['id_attach'], |
||
763 | 'approved' => $attachment['attachment_approved'], |
||
764 | 'mime_type' => $attachment['mime_type'], |
||
765 | 'thumb' => $attachment['id_thumb'], |
||
766 | ); |
||
767 | } |
||
768 | |||
769 | // Allow moderators to change names.... |
||
770 | if (allowedTo('moderate_forum') && empty($row['id_member'])) |
||
771 | { |
||
772 | $context['name'] = $smcFunc['htmlspecialchars']($row['poster_name']); |
||
773 | $context['email'] = $smcFunc['htmlspecialchars']($row['poster_email']); |
||
774 | } |
||
775 | |||
776 | // Set the destination. |
||
777 | $context['destination'] = 'post2;start=' . $_REQUEST['start'] . ';msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id'] . (isset($_REQUEST['poll']) ? ';poll' : ''); |
||
778 | $context['submit_label'] = $txt['save']; |
||
779 | } |
||
780 | // Posting... |
||
781 | else |
||
782 | { |
||
783 | // By default.... |
||
784 | $context['use_smileys'] = true; |
||
785 | $context['icon'] = 'xx'; |
||
786 | |||
787 | if ($user_info['is_guest']) |
||
788 | { |
||
789 | $context['name'] = isset($_SESSION['guest_name']) ? $_SESSION['guest_name'] : ''; |
||
790 | $context['email'] = isset($_SESSION['guest_email']) ? $_SESSION['guest_email'] : ''; |
||
791 | } |
||
792 | $context['destination'] = 'post2;start=' . $_REQUEST['start'] . (isset($_REQUEST['poll']) ? ';poll' : ''); |
||
793 | |||
794 | $context['submit_label'] = $txt['post']; |
||
795 | |||
796 | // Posting a quoted reply? |
||
797 | if (!empty($topic) && !empty($_REQUEST['quote'])) |
||
798 | { |
||
799 | // Make sure they _can_ quote this post, and if so get it. |
||
800 | $request = $smcFunc['db_query']('', ' |
||
801 | SELECT m.subject, COALESCE(mem.real_name, m.poster_name) AS poster_name, m.poster_time, m.body |
||
802 | FROM {db_prefix}messages AS m |
||
803 | LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member) |
||
804 | WHERE {query_see_message_board} |
||
805 | AND m.id_msg = {int:id_msg}' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : ' |
||
806 | AND m.approved = {int:is_approved}') . ' |
||
807 | LIMIT 1', |
||
808 | array( |
||
809 | 'id_msg' => (int) $_REQUEST['quote'], |
||
810 | 'is_approved' => 1, |
||
811 | ) |
||
812 | ); |
||
813 | if ($smcFunc['db_num_rows']($request) == 0) |
||
814 | fatal_lang_error('quoted_post_deleted', false); |
||
815 | list ($form_subject, $mname, $mdate, $form_message) = $smcFunc['db_fetch_row']($request); |
||
816 | $smcFunc['db_free_result']($request); |
||
817 | |||
818 | // Add 'Re: ' to the front of the quoted subject. |
||
819 | if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) |
||
820 | $form_subject = $context['response_prefix'] . $form_subject; |
||
821 | |||
822 | // Censor the message and subject. |
||
823 | censorText($form_message); |
||
824 | censorText($form_subject); |
||
825 | |||
826 | // But if it's in HTML world, turn them into htmlspecialchar's so they can be edited! |
||
827 | if (strpos($form_message, '[html]') !== false) |
||
828 | { |
||
829 | $parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $form_message, -1, PREG_SPLIT_DELIM_CAPTURE); |
||
830 | for ($i = 0, $n = count($parts); $i < $n; $i++) |
||
831 | { |
||
832 | // It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat. |
||
833 | if ($i % 4 == 0) |
||
834 | $parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) |
||
835 | { |
||
836 | return '[html]' . preg_replace('~<br\s?/?' . '>~i', '<br /><br>', "$m[1]") . '[/html]'; |
||
837 | }, $parts[$i]); |
||
838 | } |
||
839 | $form_message = implode('', $parts); |
||
840 | } |
||
841 | |||
842 | $form_message = preg_replace('~<br ?/?' . '>~i', "\n", $form_message); |
||
843 | |||
844 | // Remove any nested quotes, if necessary. |
||
845 | if (!empty($modSettings['removeNestedQuotes'])) |
||
846 | $form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message); |
||
847 | |||
848 | // Add a quote string on the front and end. |
||
849 | $form_message = '[quote author=' . $mname . ' link=msg=' . (int) $_REQUEST['quote'] . ' date=' . $mdate . ']' . "\n" . rtrim($form_message) . "\n" . '[/quote]'; |
||
850 | } |
||
851 | // Posting a reply without a quote? |
||
852 | elseif (!empty($topic) && empty($_REQUEST['quote'])) |
||
853 | { |
||
854 | // Get the first message's subject. |
||
855 | $form_subject = $first_subject; |
||
856 | |||
857 | // Add 'Re: ' to the front of the subject. |
||
858 | if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) |
||
859 | $form_subject = $context['response_prefix'] . $form_subject; |
||
860 | |||
861 | // Censor the subject. |
||
862 | censorText($form_subject); |
||
863 | |||
864 | $form_message = ''; |
||
865 | } |
||
866 | else |
||
867 | { |
||
868 | $form_subject = isset($_GET['subject']) ? $_GET['subject'] : ''; |
||
869 | $form_message = ''; |
||
870 | } |
||
871 | } |
||
872 | |||
873 | $context['can_post_attachment'] = !empty($modSettings['attachmentEnable']) && $modSettings['attachmentEnable'] == 1 && (allowedTo('post_attachment', $boards, true) || ($modSettings['postmod_active'] && allowedTo('post_unapproved_attachments', $boards, true))); |
||
874 | |||
875 | if ($context['can_post_attachment']) |
||
876 | { |
||
877 | // If there are attachments, calculate the total size and how many. |
||
878 | $context['attachments']['total_size'] = 0; |
||
879 | $context['attachments']['quantity'] = 0; |
||
880 | |||
881 | // If this isn't a new post, check the current attachments. |
||
882 | if (isset($_REQUEST['msg'])) |
||
883 | { |
||
884 | $context['attachments']['quantity'] = count($context['current_attachments']); |
||
885 | foreach ($context['current_attachments'] as $attachment) |
||
886 | $context['attachments']['total_size'] += $attachment['size']; |
||
887 | } |
||
888 | |||
889 | // A bit of house keeping first. |
||
890 | if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) |
||
891 | unset($_SESSION['temp_attachments']); |
||
892 | |||
893 | if (!empty($_SESSION['temp_attachments'])) |
||
894 | { |
||
895 | // Is this a request to delete them? |
||
896 | if (isset($_GET['delete_temp'])) |
||
897 | { |
||
898 | foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
||
899 | { |
||
900 | if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
||
901 | if (file_exists($attachment['tmp_name'])) |
||
902 | unlink($attachment['tmp_name']); |
||
903 | } |
||
904 | $post_errors[] = 'temp_attachments_gone'; |
||
905 | $_SESSION['temp_attachments'] = array(); |
||
906 | } |
||
907 | // Hmm, coming in fresh and there are files in session. |
||
908 | elseif ($context['current_action'] != 'post2' || !empty($_POST['from_qr'])) |
||
909 | { |
||
910 | // Let's be nice and see if they belong here first. |
||
911 | 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'])) |
||
912 | { |
||
913 | // See if any files still exist before showing the warning message and the files attached. |
||
914 | foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
||
915 | { |
||
916 | if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false) |
||
917 | continue; |
||
918 | |||
919 | if (file_exists($attachment['tmp_name'])) |
||
920 | { |
||
921 | $post_errors[] = 'temp_attachments_new'; |
||
922 | $context['files_in_session_warning'] = $txt['attached_files_in_session']; |
||
923 | unset($_SESSION['temp_attachments']['post']['files']); |
||
924 | break; |
||
925 | } |
||
926 | } |
||
927 | } |
||
928 | else |
||
929 | { |
||
930 | // Since, they don't belong here. Let's inform the user that they exist.. |
||
931 | if (!empty($topic)) |
||
932 | $delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp'; |
||
933 | else |
||
934 | $delete_url = $scripturl . '?action=post' . (!empty($board) ? ';board=' . $board : '') . ';delete_temp'; |
||
935 | |||
936 | // Compile a list of the files to show the user. |
||
937 | $file_list = array(); |
||
938 | foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
||
939 | if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
||
940 | $file_list[] = $attachment['name']; |
||
941 | |||
942 | $_SESSION['temp_attachments']['post']['files'] = $file_list; |
||
943 | $file_list = '<div class="attachments">' . implode('<br>', $file_list) . '</div>'; |
||
944 | |||
945 | if (!empty($_SESSION['temp_attachments']['post']['msg'])) |
||
946 | { |
||
947 | // We have a message id, so we can link back to the old topic they were trying to edit.. |
||
948 | $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'; |
||
949 | |||
950 | $post_errors[] = array('temp_attachments_found', array($delete_url, $goback_url, $file_list)); |
||
951 | $context['ignore_temp_attachments'] = true; |
||
952 | } |
||
953 | else |
||
954 | { |
||
955 | $post_errors[] = array('temp_attachments_lost', array($delete_url, $file_list)); |
||
956 | $context['ignore_temp_attachments'] = true; |
||
957 | } |
||
958 | } |
||
959 | } |
||
960 | |||
961 | if (!empty($context['we_are_history'])) |
||
962 | $post_errors[] = $context['we_are_history']; |
||
963 | |||
964 | foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
||
965 | { |
||
966 | if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files'])) |
||
967 | break; |
||
968 | |||
969 | if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) |
||
970 | continue; |
||
971 | |||
972 | if ($attachID == 'initial_error') |
||
973 | { |
||
974 | $txt['error_attach_initial_error'] = $txt['attach_no_upload'] . '<div style="padding: 0 1em;">' . (is_array($attachment) ? vsprintf($txt[$attachment[0]], $attachment[1]) : $txt[$attachment]) . '</div>'; |
||
975 | $post_errors[] = 'attach_initial_error'; |
||
976 | unset($_SESSION['temp_attachments']); |
||
977 | break; |
||
978 | } |
||
979 | |||
980 | // Show any errors which might have occurred. |
||
981 | if (!empty($attachment['errors'])) |
||
982 | { |
||
983 | $txt['error_attach_errors'] = empty($txt['error_attach_errors']) ? '<br>' : ''; |
||
984 | $txt['error_attach_errors'] .= vsprintf($txt['attach_warning'], $attachment['name']) . '<div style="padding: 0 1em;">'; |
||
985 | foreach ($attachment['errors'] as $error) |
||
986 | $txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >'; |
||
987 | $txt['error_attach_errors'] .= '</div>'; |
||
988 | $post_errors[] = 'attach_errors'; |
||
989 | |||
990 | // Take out the trash. |
||
991 | unset($_SESSION['temp_attachments'][$attachID]); |
||
992 | if (file_exists($attachment['tmp_name'])) |
||
993 | unlink($attachment['tmp_name']); |
||
994 | continue; |
||
995 | } |
||
996 | |||
997 | // More house keeping. |
||
998 | if (!file_exists($attachment['tmp_name'])) |
||
999 | { |
||
1000 | unset($_SESSION['temp_attachments'][$attachID]); |
||
1001 | continue; |
||
1002 | } |
||
1003 | |||
1004 | $context['attachments']['quantity']++; |
||
1005 | $context['attachments']['total_size'] += $attachment['size']; |
||
1006 | if (!isset($context['files_in_session_warning'])) |
||
1007 | $context['files_in_session_warning'] = $txt['attached_files_in_session']; |
||
1008 | |||
1009 | $context['current_attachments'][$attachID] = array( |
||
1010 | 'name' => $smcFunc['htmlspecialchars']($attachment['name']), |
||
1011 | 'size' => $attachment['size'], |
||
1012 | 'attachID' => $attachID, |
||
1013 | 'unchecked' => false, |
||
1014 | 'approved' => 1, |
||
1015 | 'mime_type' => '', |
||
1016 | 'thumb' => 0, |
||
1017 | ); |
||
1018 | } |
||
1019 | } |
||
1020 | } |
||
1021 | |||
1022 | // Do we need to show the visual verification image? |
||
1023 | $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)); |
||
1024 | if ($context['require_verification']) |
||
1025 | { |
||
1026 | require_once($sourcedir . '/Subs-Editor.php'); |
||
1027 | $verificationOptions = array( |
||
1028 | 'id' => 'post', |
||
1029 | ); |
||
1030 | $context['require_verification'] = create_control_verification($verificationOptions); |
||
1031 | $context['visual_verification_id'] = $verificationOptions['id']; |
||
1032 | } |
||
1033 | |||
1034 | // If they came from quick reply, and have to enter verification details, give them some notice. |
||
1035 | if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification'])) |
||
1036 | $post_errors[] = 'need_qr_verification'; |
||
1037 | |||
1038 | /* |
||
1039 | * There are two error types: serious and minor. Serious errors |
||
1040 | * actually tell the user that a real error has occurred, while minor |
||
1041 | * errors are like warnings that let them know that something with |
||
1042 | * their post isn't right. |
||
1043 | */ |
||
1044 | $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'); |
||
1045 | |||
1046 | call_integration_hook('integrate_post_errors', array(&$post_errors, &$minor_errors)); |
||
1047 | |||
1048 | // Any errors occurred? |
||
1049 | if (!empty($post_errors)) |
||
1050 | { |
||
1051 | loadLanguage('Errors'); |
||
1052 | $context['error_type'] = 'minor'; |
||
1053 | foreach ($post_errors as $post_error) |
||
1054 | if (is_array($post_error)) |
||
1055 | { |
||
1056 | $post_error_id = $post_error[0]; |
||
1057 | $context['post_error'][$post_error_id] = vsprintf($txt['error_' . $post_error_id], $post_error[1]); |
||
1058 | |||
1059 | // If it's not a minor error flag it as such. |
||
1060 | if (!in_array($post_error_id, $minor_errors)) |
||
1061 | $context['error_type'] = 'serious'; |
||
1062 | } |
||
1063 | else |
||
1064 | { |
||
1065 | $context['post_error'][$post_error] = $txt['error_' . $post_error]; |
||
1066 | |||
1067 | // If it's not a minor error flag it as such. |
||
1068 | if (!in_array($post_error, $minor_errors)) |
||
1069 | $context['error_type'] = 'serious'; |
||
1070 | } |
||
1071 | } |
||
1072 | |||
1073 | // What are you doing? Posting a poll, modifying, previewing, new post, or reply... |
||
1074 | if (isset($_REQUEST['poll'])) |
||
1075 | $context['page_title'] = $txt['new_poll']; |
||
1076 | elseif ($context['make_event']) |
||
1077 | $context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit']; |
||
1078 | elseif (isset($_REQUEST['msg'])) |
||
1079 | $context['page_title'] = $txt['modify_msg']; |
||
1080 | elseif (isset($_REQUEST['subject'], $context['preview_subject'])) |
||
1081 | $context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']); |
||
1082 | elseif (empty($topic)) |
||
1083 | $context['page_title'] = $txt['start_new_topic']; |
||
1084 | else |
||
1085 | $context['page_title'] = $txt['post_reply']; |
||
1086 | |||
1087 | // Build the link tree. |
||
1088 | if (empty($topic)) |
||
1089 | $context['linktree'][] = array( |
||
1090 | 'name' => '<em>' . $txt['start_new_topic'] . '</em>' |
||
1091 | ); |
||
1092 | else |
||
1093 | $context['linktree'][] = array( |
||
1094 | 'url' => $scripturl . '?topic=' . $topic . '.' . $_REQUEST['start'], |
||
1095 | 'name' => $form_subject, |
||
1096 | 'extra_before' => '<span><strong class="nav">' . $context['page_title'] . ' (</strong></span>', |
||
1097 | 'extra_after' => '<span><strong class="nav">)</strong></span>' |
||
1098 | ); |
||
1099 | |||
1100 | $context['subject'] = addcslashes($form_subject, '"'); |
||
1101 | $context['message'] = str_replace(array('"', '<', '>', ' '), array('"', '<', '>', ' '), $form_message); |
||
1102 | |||
1103 | // Are post drafts enabled? |
||
1104 | $context['drafts_save'] = !empty($modSettings['drafts_post_enabled']) && allowedTo('post_draft'); |
||
1105 | $context['drafts_autosave'] = !empty($context['drafts_save']) && !empty($modSettings['drafts_autosave_enabled']) && allowedTo('post_autosave_draft'); |
||
1106 | |||
1107 | // Build a list of drafts that they can load in to the editor |
||
1108 | if (!empty($context['drafts_save'])) |
||
1109 | { |
||
1110 | require_once($sourcedir . '/Drafts.php'); |
||
1111 | ShowDrafts($user_info['id'], $topic); |
||
1112 | } |
||
1113 | |||
1114 | // Needed for the editor and message icons. |
||
1115 | require_once($sourcedir . '/Subs-Editor.php'); |
||
1116 | |||
1117 | // Now create the editor. |
||
1118 | $editorOptions = array( |
||
1119 | 'id' => 'message', |
||
1120 | 'value' => $context['message'], |
||
1121 | 'labels' => array( |
||
1122 | 'post_button' => $context['submit_label'], |
||
1123 | ), |
||
1124 | // add height and width for the editor |
||
1125 | 'height' => '275px', |
||
1126 | 'width' => '100%', |
||
1127 | // We do XML preview here. |
||
1128 | 'preview_type' => 2, |
||
1129 | 'required' => true, |
||
1130 | ); |
||
1131 | create_control_richedit($editorOptions); |
||
1132 | |||
1133 | // Store the ID. |
||
1134 | $context['post_box_name'] = $editorOptions['id']; |
||
1135 | |||
1136 | $context['attached'] = ''; |
||
1137 | $context['make_poll'] = isset($_REQUEST['poll']); |
||
1138 | |||
1139 | // Message icons - customized icons are off? |
||
1140 | $context['icons'] = getMessageIcons(!empty($board) ? $board : 0); |
||
1141 | |||
1142 | if (!empty($context['icons'])) |
||
1143 | $context['icons'][count($context['icons']) - 1]['is_last'] = true; |
||
1144 | |||
1145 | // Are we starting a poll? if set the poll icon as selected if its available |
||
1146 | if (isset($_REQUEST['poll'])) |
||
1147 | { |
||
1148 | foreach ($context['icons'] as $icons) |
||
1149 | { |
||
1150 | if (isset($icons['value']) && $icons['value'] == 'poll') |
||
1151 | { |
||
1152 | // if found we are done |
||
1153 | $context['icon'] = 'poll'; |
||
1154 | break; |
||
1155 | } |
||
1156 | } |
||
1157 | } |
||
1158 | |||
1159 | $context['icon_url'] = ''; |
||
1160 | for ($i = 0, $n = count($context['icons']); $i < $n; $i++) |
||
1161 | { |
||
1162 | $context['icons'][$i]['selected'] = $context['icon'] == $context['icons'][$i]['value']; |
||
1163 | if ($context['icons'][$i]['selected']) |
||
1164 | $context['icon_url'] = $context['icons'][$i]['url']; |
||
1165 | } |
||
1166 | if (empty($context['icon_url'])) |
||
1167 | { |
||
1168 | $context['icon_url'] = $settings[file_exists($settings['theme_dir'] . '/images/post/' . $context['icon'] . '.png') ? 'images_url' : 'default_images_url'] . '/post/' . $context['icon'] . '.png'; |
||
1169 | array_unshift($context['icons'], array( |
||
1170 | 'value' => $context['icon'], |
||
1171 | 'name' => $txt['current_icon'], |
||
1172 | 'url' => $context['icon_url'], |
||
1173 | 'is_last' => empty($context['icons']), |
||
1174 | 'selected' => true, |
||
1175 | )); |
||
1176 | } |
||
1177 | |||
1178 | if (!empty($topic) && !empty($modSettings['topicSummaryPosts'])) |
||
1179 | getTopic(); |
||
1180 | |||
1181 | // If the user can post attachments prepare the warning labels. |
||
1182 | if ($context['can_post_attachment']) |
||
1183 | { |
||
1184 | // 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. |
||
1185 | $context['num_allowed_attachments'] = min(ini_get('max_file_uploads'), (empty($modSettings['attachmentNumPerPostLimit']) ? 50 : $modSettings['attachmentNumPerPostLimit'] - count($context['current_attachments']))); |
||
1186 | $context['can_post_attachment_unapproved'] = allowedTo('post_attachment'); |
||
1187 | $context['attachment_restrictions'] = array(); |
||
1188 | $context['allowed_extensions'] = strtr(strtolower($modSettings['attachmentExtensions']), array(',' => ', ')); |
||
1189 | $attachmentRestrictionTypes = array('attachmentNumPerPostLimit', 'attachmentPostLimit', 'attachmentSizeLimit'); |
||
1190 | foreach ($attachmentRestrictionTypes as $type) |
||
1191 | if (!empty($modSettings[$type])) |
||
1192 | { |
||
1193 | // Show the max number of attachments if not 0. |
||
1194 | if ($type == 'attachmentNumPerPostLimit') |
||
1195 | $context['attachment_restrictions'][] = sprintf($txt['attach_remaining'], $modSettings['attachmentNumPerPostLimit'] - $context['attachments']['quantity']); |
||
1196 | } |
||
1197 | } |
||
1198 | |||
1199 | $context['back_to_topic'] = isset($_REQUEST['goback']) || (isset($_REQUEST['msg']) && !isset($_REQUEST['subject'])); |
||
1200 | $context['show_additional_options'] = !empty($_POST['additional_options']) || isset($_SESSION['temp_attachments']['post']) || isset($_GET['additionalOptions']); |
||
1201 | |||
1202 | $context['is_new_topic'] = empty($topic); |
||
1203 | $context['is_new_post'] = !isset($_REQUEST['msg']); |
||
1204 | $context['is_first_post'] = $context['is_new_topic'] || (isset($_REQUEST['msg']) && $_REQUEST['msg'] == $id_first_msg); |
||
1205 | |||
1206 | // WYSIWYG only works if BBC is enabled |
||
1207 | $modSettings['disable_wysiwyg'] = !empty($modSettings['disable_wysiwyg']) || empty($modSettings['enableBBC']); |
||
1208 | |||
1209 | // Register this form in the session variables. |
||
1210 | checkSubmitOnce('register'); |
||
1211 | |||
1212 | // Mentions |
||
1213 | if (!empty($modSettings['enable_mentions']) && allowedTo('mention')) |
||
1214 | { |
||
1215 | loadJavaScriptFile('jquery.caret.min.js', array('defer' => true), 'smf_caret'); |
||
1216 | loadJavaScriptFile('jquery.atwho.min.js', array('defer' => true), 'smf_atwho'); |
||
1217 | loadJavaScriptFile('mentions.js', array('defer' => true, 'minimize' => true), 'smf_mentions'); |
||
1218 | } |
||
1219 | |||
1220 | // quotedText.js |
||
1221 | loadJavaScriptFile('quotedText.js', array('defer' => true, 'minimize' => true), 'smf_quotedText'); |
||
1222 | |||
1223 | addInlineJavaScript(' |
||
1224 | var current_attachments = [];'); |
||
1225 | |||
1226 | if (!empty($context['current_attachments'])) |
||
1227 | { |
||
1228 | // Mock files to show already attached files. |
||
1229 | foreach ($context['current_attachments'] as $key => $mock) |
||
1230 | addInlineJavaScript(' |
||
1231 | current_attachments.push({ |
||
1232 | name: ' . JavaScriptEscape($mock['name']) . ', |
||
1233 | size: ' . $mock['size'] . ', |
||
1234 | attachID: ' . $mock['attachID'] . ', |
||
1235 | approved: ' . $mock['approved'] . ', |
||
1236 | type: ' . JavaScriptEscape(!empty($mock['mime_type']) ? $mock['mime_type'] : '') . ', |
||
1237 | thumbID: ' . (!empty($mock['thumb']) ? $mock['thumb'] : 0) . ' |
||
1238 | });'); |
||
1239 | } |
||
1240 | |||
1241 | // File Upload. |
||
1242 | if ($context['can_post_attachment']) |
||
1243 | { |
||
1244 | $acceptedFiles = implode(',', array_map(function ($val) use ($smcFunc) |
||
1245 | { |
||
1246 | return '.' . $smcFunc['htmltrim']($val); |
||
1247 | }, explode(',', $context['allowed_extensions']))); |
||
1248 | |||
1249 | loadJavaScriptFile('dropzone.min.js', array('defer' => true), 'smf_dropzone'); |
||
1250 | loadJavaScriptFile('smf_fileUpload.js', array('defer' => true, 'minimize' => true), 'smf_fileUpload'); |
||
1251 | addInlineJavaScript(' |
||
1252 | $(function() { |
||
1253 | smf_fileUpload({ |
||
1254 | dictDefaultMessage : ' . JavaScriptEscape($txt['attach_drop_zone']) . ', |
||
1255 | dictFallbackMessage : ' . JavaScriptEscape($txt['attach_drop_zone_no']) . ', |
||
1256 | dictCancelUpload : ' . JavaScriptEscape($txt['modify_cancel']) . ', |
||
1257 | genericError: ' . JavaScriptEscape($txt['attach_php_error']) . ', |
||
1258 | text_attachLeft: ' . JavaScriptEscape($txt['attachments_left']) . ', |
||
1259 | text_deleteAttach: ' . JavaScriptEscape($txt['attached_file_delete']) . ', |
||
1260 | text_attachDeleted: ' . JavaScriptEscape($txt['attached_file_deleted']) . ', |
||
1261 | text_insertBBC: ' . JavaScriptEscape($txt['attached_insert_bbc']) . ', |
||
1262 | text_attachUploaded: ' . JavaScriptEscape($txt['attached_file_uploaded']) . ', |
||
1263 | text_attach_unlimited: ' . JavaScriptEscape($txt['attach_drop_unlimited']) . ', |
||
1264 | text_totalMaxSize: ' . JavaScriptEscape($txt['attach_max_total_file_size_current']) . ', |
||
1265 | text_max_size_progress: ' . JavaScriptEscape($txt['attach_max_size_progress']) . ', |
||
1266 | dictMaxFilesExceeded: ' . JavaScriptEscape($txt['more_attachments_error']) . ', |
||
1267 | dictInvalidFileType: ' . JavaScriptEscape(sprintf($txt['cant_upload_type'], $context['allowed_extensions'])) . ', |
||
1268 | dictFileTooBig: ' . JavaScriptEscape(sprintf($txt['file_too_big'], comma_format($modSettings['attachmentSizeLimit'], 0))) . ', |
||
1269 | acceptedFiles: ' . JavaScriptEscape($acceptedFiles) . ', |
||
1270 | thumbnailWidth: ' . (!empty($modSettings['attachmentThumbWidth']) ? $modSettings['attachmentThumbWidth'] : 'null') . ', |
||
1271 | thumbnailHeight: ' . (!empty($modSettings['attachmentThumbHeight']) ? $modSettings['attachmentThumbHeight'] : 'null') . ', |
||
1272 | limitMultiFileUploadSize:' . round(max($modSettings['attachmentPostLimit'] - ($context['attachments']['total_size'] / 1024), 0)) * 1024 . ', |
||
1273 | maxFileAmount: ' . (!empty($context['num_allowed_attachments']) ? $context['num_allowed_attachments'] : 'null') . ', |
||
1274 | maxTotalSize: ' . (!empty($modSettings['attachmentPostLimit']) ? $modSettings['attachmentPostLimit'] : '0') . ', |
||
1275 | maxFileSize: ' . (!empty($modSettings['attachmentSizeLimit']) ? $modSettings['attachmentSizeLimit'] : '0') . ', |
||
1276 | }); |
||
1277 | });', true); |
||
1278 | } |
||
1279 | |||
1280 | // Knowing the current board ID might be handy. |
||
1281 | addInlineJavaScript(' |
||
1282 | var current_board = ' . (empty($context['current_board']) ? 'null' : $context['current_board']) . ';', false); |
||
1283 | |||
1284 | /* Now let's set up the fields for the posting form header... |
||
1285 | |||
1286 | Each item in $context['posting_fields'] is an array similar to one of |
||
1287 | the following: |
||
1288 | |||
1289 | $context['posting_fields']['foo'] = array( |
||
1290 | 'label' => array( |
||
1291 | 'text' => $txt['foo'], // required |
||
1292 | 'class' => 'foo', // optional |
||
1293 | ), |
||
1294 | 'input' => array( |
||
1295 | 'type' => 'text', // required |
||
1296 | 'attributes' => array( |
||
1297 | 'name' => 'foo', // optional, defaults to posting field's key |
||
1298 | 'value' => $foo, |
||
1299 | 'size' => 80, |
||
1300 | ), |
||
1301 | ), |
||
1302 | ); |
||
1303 | |||
1304 | $context['posting_fields']['bar'] = array( |
||
1305 | 'label' => array( |
||
1306 | 'text' => $txt['bar'], // required |
||
1307 | 'class' => 'bar', // optional |
||
1308 | ), |
||
1309 | 'input' => array( |
||
1310 | 'type' => 'select', // required |
||
1311 | 'attributes' => array( |
||
1312 | 'name' => 'bar', // optional, defaults to posting field's key |
||
1313 | ), |
||
1314 | 'options' => array( |
||
1315 | 'option_1' => array( |
||
1316 | 'label' => $txt['option_1'], |
||
1317 | 'value' => '1', |
||
1318 | 'selected' => true, |
||
1319 | ), |
||
1320 | 'option_2' => array( |
||
1321 | 'label' => $txt['option_2'], |
||
1322 | 'value' => '2', |
||
1323 | 'selected' => false, |
||
1324 | ), |
||
1325 | 'opt_group_1' => array( |
||
1326 | 'label' => $txt['opt_group_1'], |
||
1327 | 'options' => array( |
||
1328 | 'option_3' => array( |
||
1329 | 'label' => $txt['option_3'], |
||
1330 | 'value' => '3', |
||
1331 | 'selected' => false, |
||
1332 | ), |
||
1333 | 'option_4' => array( |
||
1334 | 'label' => $txt['option_4'], |
||
1335 | 'value' => '4', |
||
1336 | 'selected' => false, |
||
1337 | ), |
||
1338 | ), |
||
1339 | ), |
||
1340 | ), |
||
1341 | ), |
||
1342 | ); |
||
1343 | |||
1344 | $context['posting_fields']['baz'] = array( |
||
1345 | 'label' => array( |
||
1346 | 'text' => $txt['baz'], // required |
||
1347 | 'class' => 'baz', // optional |
||
1348 | ), |
||
1349 | 'input' => array( |
||
1350 | 'type' => 'radio_select', // required |
||
1351 | 'attributes' => array( |
||
1352 | 'name' => 'baz', // optional, defaults to posting field's key |
||
1353 | ), |
||
1354 | 'options' => array( |
||
1355 | 'option_1' => array( |
||
1356 | 'label' => $txt['option_1'], |
||
1357 | 'value' => '1', |
||
1358 | 'selected' => true, |
||
1359 | ), |
||
1360 | 'option_2' => array( |
||
1361 | 'label' => $txt['option_2'], |
||
1362 | 'value' => '2', |
||
1363 | 'selected' => false, |
||
1364 | ), |
||
1365 | ), |
||
1366 | ), |
||
1367 | ); |
||
1368 | |||
1369 | The label and input elements are required. The label text and input |
||
1370 | type are also required. Other elements may be required or optional |
||
1371 | depending on the situation. |
||
1372 | |||
1373 | The input type can be one of the following: |
||
1374 | |||
1375 | - text, password, color, date, datetime-local, email, month, number, |
||
1376 | range, tel, time, url, or week |
||
1377 | - textarea |
||
1378 | - checkbox |
||
1379 | - select |
||
1380 | - radio_select |
||
1381 | |||
1382 | When the input type is text (etc.), textarea, or checkbox, the |
||
1383 | 'attributes' element is used to specify the initial value and any |
||
1384 | other HTML attributes that might be necessary for the input field. |
||
1385 | |||
1386 | When the input type is select or radio_select, the options element |
||
1387 | is required in order to list the options that the user can select. |
||
1388 | For the select type, these will be used to generate a typical select |
||
1389 | menu. For the radio_select type, they will be used to make a div with |
||
1390 | some radio buttons in it. |
||
1391 | |||
1392 | Each option in the options array is itself an array of attributes. If |
||
1393 | an option contains a sub-array of more options, then it will be |
||
1394 | turned into an optgroup in the generated select menu. Note that the |
||
1395 | radio_select type only supports simple options, not grouped ones. |
||
1396 | |||
1397 | Both the label and the input can have a 'before' and/or 'after' |
||
1398 | element. If used, these define literal HTML strings to be inserted |
||
1399 | before or after the rest of the content of the label or input. |
||
1400 | |||
1401 | Finally, it is possible to define an 'html' element for the label |
||
1402 | and/or the input. If used, this will override the HTML that would |
||
1403 | normally be generated in the template file using the other |
||
1404 | information in the array. This should be avoided if at all possible. |
||
1405 | */ |
||
1406 | $context['posting_fields'] = array(); |
||
1407 | |||
1408 | // Guests must supply their name and email. |
||
1409 | if (isset($context['name']) && isset($context['email'])) |
||
1410 | { |
||
1411 | $context['posting_fields']['guestname'] = array( |
||
1412 | 'label' => array( |
||
1413 | 'text' => $txt['name'], |
||
1414 | 'class' => isset($context['post_error']['long_name']) || isset($context['post_error']['no_name']) || isset($context['post_error']['bad_name']) ? 'error' : '', |
||
1415 | ), |
||
1416 | 'input' => array( |
||
1417 | 'type' => 'text', |
||
1418 | 'attributes' => array( |
||
1419 | 'size' => 25, |
||
1420 | 'value' => $context['name'], |
||
1421 | 'required' => true, |
||
1422 | ), |
||
1423 | ), |
||
1424 | ); |
||
1425 | |||
1426 | if (empty($modSettings['guest_post_no_email'])) |
||
1427 | { |
||
1428 | $context['posting_fields']['email'] = array( |
||
1429 | 'label' => array( |
||
1430 | 'text' => $txt['email'], |
||
1431 | 'class' => isset($context['post_error']['no_email']) || isset($context['post_error']['bad_email']) ? 'error' : '', |
||
1432 | ), |
||
1433 | 'input' => array( |
||
1434 | 'type' => 'email', |
||
1435 | 'attributes' => array( |
||
1436 | 'size' => 25, |
||
1437 | 'value' => $context['email'], |
||
1438 | 'required' => true, |
||
1439 | ), |
||
1440 | ), |
||
1441 | ); |
||
1442 | } |
||
1443 | } |
||
1444 | |||
1445 | // Gotta post it somewhere. |
||
1446 | if (empty($board) && !$context['make_event']) |
||
1447 | { |
||
1448 | $context['posting_fields']['board'] = array( |
||
1449 | 'label' => array( |
||
1450 | 'text' => $txt['calendar_post_in'], |
||
1451 | ), |
||
1452 | 'input' => array( |
||
1453 | 'type' => 'select', |
||
1454 | 'options' => array(), |
||
1455 | ), |
||
1456 | ); |
||
1457 | foreach ($board_list as $category) |
||
1458 | { |
||
1459 | $context['posting_fields']['board']['input']['options'][$category['name']] = array('options' => array()); |
||
1460 | |||
1461 | foreach ($category['boards'] as $brd) |
||
1462 | $context['posting_fields']['board']['input']['options'][$category['name']]['options'][$brd['name']] = array( |
||
1463 | 'value' => $brd['id'], |
||
1464 | 'selected' => (bool) $brd['selected'], |
||
1465 | 'label' => ($brd['child_level'] > 0 ? str_repeat('==', $brd['child_level'] - 1) . '=>' : '') . ' ' . $brd['name'], |
||
1466 | ); |
||
1467 | } |
||
1468 | } |
||
1469 | |||
1470 | // Gotta have a subject. |
||
1471 | $context['posting_fields']['subject'] = array( |
||
1472 | 'label' => array( |
||
1473 | 'text' => $txt['subject'], |
||
1474 | 'class' => isset($context['post_error']['no_subject']) ? 'error' : '', |
||
1475 | ), |
||
1476 | 'input' => array( |
||
1477 | 'type' => 'text', |
||
1478 | 'attributes' => array( |
||
1479 | 'size' => 80, |
||
1480 | 'maxlength' => !empty($topic) ? 84 : 80, |
||
1481 | 'value' => $context['subject'], |
||
1482 | 'required' => true, |
||
1483 | ), |
||
1484 | ), |
||
1485 | ); |
||
1486 | |||
1487 | // Icons are fun. |
||
1488 | $context['posting_fields']['icon'] = array( |
||
1489 | 'label' => array( |
||
1490 | 'text' => $txt['message_icon'], |
||
1491 | ), |
||
1492 | 'input' => array( |
||
1493 | 'type' => 'select', |
||
1494 | 'attributes' => array( |
||
1495 | 'id' => 'icon', |
||
1496 | 'onchange' => 'showimage();', |
||
1497 | ), |
||
1498 | 'options' => array(), |
||
1499 | 'after' => ' <img id="icons" src="' . $context['icon_url'] . '">', |
||
1500 | ), |
||
1501 | ); |
||
1502 | foreach ($context['icons'] as $icon) |
||
1503 | { |
||
1504 | $context['posting_fields']['icon']['input']['options'][$icon['name']] = array( |
||
1505 | 'value' => $icon['value'], |
||
1506 | 'selected' => $icon['value'] == $context['icon'], |
||
1507 | ); |
||
1508 | } |
||
1509 | |||
1510 | // Finally, load the template. |
||
1511 | if (!isset($_REQUEST['xml'])) |
||
1512 | loadTemplate('Post'); |
||
1513 | |||
1514 | call_integration_hook('integrate_post_end'); |
||
1515 | } |
||
3160 | ?> |