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