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