elkarte /
Elkarte
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | /** |
||||||
| 4 | * The job of this file is to handle everything related to posting replies, |
||||||
| 5 | * new topics, quotes, and modifications to existing posts. It also handles |
||||||
| 6 | * quoting posts by way of javascript. |
||||||
| 7 | * |
||||||
| 8 | * @package ElkArte Forum |
||||||
| 9 | * @copyright ElkArte Forum contributors |
||||||
| 10 | * @license BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file) |
||||||
| 11 | * |
||||||
| 12 | * This file contains code covered by: |
||||||
| 13 | * copyright: 2011 Simple Machines (http://www.simplemachines.org) |
||||||
| 14 | * |
||||||
| 15 | * @version 2.0 dev |
||||||
| 16 | * |
||||||
| 17 | */ |
||||||
| 18 | |||||||
| 19 | namespace ElkArte\Controller; |
||||||
| 20 | |||||||
| 21 | use BBC\ParserWrapper; |
||||||
| 22 | use BBC\PreparseCode; |
||||||
| 23 | use ElkArte\AbstractController; |
||||||
| 24 | use ElkArte\Cache\Cache; |
||||||
| 25 | use ElkArte\Errors\ErrorContext; |
||||||
| 26 | use ElkArte\Exceptions\ControllerRedirectException; |
||||||
| 27 | use ElkArte\Exceptions\Exception; |
||||||
| 28 | use ElkArte\Helper\DataValidator; |
||||||
| 29 | use ElkArte\Helper\Util; |
||||||
| 30 | use ElkArte\Languages\Txt; |
||||||
| 31 | use ElkArte\Notifications\Notifications; |
||||||
| 32 | use ElkArte\Notifications\NotificationsTask; |
||||||
| 33 | use ElkArte\Themes\TemplateLayers; |
||||||
| 34 | use ElkArte\User; |
||||||
| 35 | |||||||
| 36 | /** |
||||||
| 37 | * Everything related to posting new replies and topics and modifications of them |
||||||
| 38 | */ |
||||||
| 39 | class Post extends AbstractController |
||||||
| 40 | { |
||||||
| 41 | /** @var null|ErrorContext The post (messages) errors object */ |
||||||
| 42 | protected $_post_errors; |
||||||
| 43 | |||||||
| 44 | /** @var null|TemplateLayers The template layers object */ |
||||||
| 45 | protected $_template_layers; |
||||||
| 46 | |||||||
| 47 | /** @var array An array of attributes of the topic (if not new) */ |
||||||
| 48 | protected $_topic_attributes = []; |
||||||
| 49 | |||||||
| 50 | /** @var string The message subject */ |
||||||
| 51 | protected $_form_subject = ''; |
||||||
| 52 | |||||||
| 53 | /** @var string The message */ |
||||||
| 54 | protected $_form_message = ''; |
||||||
| 55 | |||||||
| 56 | /** @var PreparseCode */ |
||||||
| 57 | protected $preparse; |
||||||
| 58 | |||||||
| 59 | /** |
||||||
| 60 | 6 | * Sets up common stuff for all or most of the actions. |
|||||
| 61 | */ |
||||||
| 62 | 6 | public function pre_dispatch() |
|||||
| 63 | 6 | { |
|||||
| 64 | $this->_post_errors = ErrorContext::context('post', 1); |
||||||
| 65 | 6 | $this->_template_layers = theme()->getLayers(); |
|||||
| 66 | |||||||
| 67 | 6 | $this->preparse = PreparseCode::instance($this->user->name); |
|||||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||||||
| 68 | 6 | ||||||
| 69 | 6 | require_once(SUBSDIR . '/Post.subs.php'); |
|||||
| 70 | 6 | require_once(SUBSDIR . '/Messages.subs.php'); |
|||||
| 71 | require_once(SUBSDIR . '/Topic.subs.php'); |
||||||
| 72 | } |
||||||
| 73 | |||||||
| 74 | /** |
||||||
| 75 | * Dispatch to the right action method for the request. |
||||||
| 76 | * |
||||||
| 77 | * @see AbstractController::action_index |
||||||
| 78 | */ |
||||||
| 79 | public function action_index() |
||||||
| 80 | { |
||||||
| 81 | // Figure out the right action to do. |
||||||
| 82 | // hint: I'm post controller. :P |
||||||
| 83 | $this->action_post(); |
||||||
| 84 | } |
||||||
| 85 | |||||||
| 86 | /** |
||||||
| 87 | * Handles showing the post screen, loading the post to be modified, loading any post quoted, previews, |
||||||
| 88 | * display of errors and polls. |
||||||
| 89 | * |
||||||
| 90 | * What it does: |
||||||
| 91 | * |
||||||
| 92 | * - Validates that we're posting in a board. |
||||||
| 93 | * - Find the topic id if a message id is passed, else assume it's a new message |
||||||
| 94 | * - Get the response prefix in the default forum language. |
||||||
| 95 | * - Triggers events associated with posting. |
||||||
| 96 | * - prepare_post, prepare_context, prepare_modifying, prepare_editing, |
||||||
| 97 | * - prepare_posting, post_errors, finalize_post_form |
||||||
| 98 | * - Additionally handles previews of posts. |
||||||
| 99 | * - Requires different permissions depending on the actions, but most notably post_new, post_reply_own, and post_reply_any. |
||||||
| 100 | * - Shows options for the editing and posting of calendar events and attachments, and as the posting of polls (using modules). |
||||||
| 101 | * - Accessed from ?action=post or called from action_post2 in the event of errors or preview from quick reply. |
||||||
| 102 | * |
||||||
| 103 | * @uses the Post template and language file, main sub template. |
||||||
| 104 | * @uses Errors language |
||||||
| 105 | */ |
||||||
| 106 | public function action_post() |
||||||
| 107 | { |
||||||
| 108 | global $context; |
||||||
| 109 | |||||||
| 110 | // Initialize the post area |
||||||
| 111 | $this->_beforePreparePost(); |
||||||
| 112 | |||||||
| 113 | // Trigger the prepare_post event |
||||||
| 114 | $this->_events->trigger('prepare_post', ['topic_attributes' => &$this->_topic_attributes]); |
||||||
| 115 | |||||||
| 116 | // Sets post form options / checkbox / etc |
||||||
| 117 | $this->_beforePrepareContext(); |
||||||
| 118 | |||||||
| 119 | // Trigger the prepare_context event |
||||||
| 120 | try |
||||||
| 121 | { |
||||||
| 122 | $this->_events->trigger('prepare_context', ['id_member_poster' => (int) $this->_topic_attributes['id_member']]); |
||||||
| 123 | } |
||||||
| 124 | catch (ControllerRedirectException $controllerRedirectException) |
||||||
| 125 | { |
||||||
| 126 | return $controllerRedirectException->doRedirect($this); |
||||||
| 127 | } |
||||||
| 128 | |||||||
| 129 | // Load up the message details if this is an existing msg |
||||||
| 130 | $this->_generatingMessage(); |
||||||
| 131 | |||||||
| 132 | // Trigger post_errors event |
||||||
| 133 | $this->_events->trigger('post_errors'); |
||||||
| 134 | |||||||
| 135 | $this->_preparingPage(); |
||||||
| 136 | |||||||
| 137 | // Needed for the editor and message icons. |
||||||
| 138 | require_once(SUBSDIR . '/Editor.subs.php'); |
||||||
| 139 | |||||||
| 140 | // Now create the editor. |
||||||
| 141 | $editorOptions = [ |
||||||
| 142 | 'id' => 'message', |
||||||
| 143 | 'value' => $context['message'], |
||||||
| 144 | 'labels' => [ |
||||||
| 145 | 'post_button' => $context['submit_label'], |
||||||
| 146 | ], |
||||||
| 147 | // add height and width for the editor |
||||||
| 148 | 'height' => '275px', |
||||||
| 149 | 'width' => '100%', |
||||||
| 150 | // We do XML preview here. |
||||||
| 151 | 'preview_type' => 2, |
||||||
| 152 | 'smiley_container' => 'smileyBox_message', |
||||||
| 153 | 'bbc_container' => 'bbcBox_message', |
||||||
| 154 | 'live_errors' => 1 |
||||||
| 155 | ]; |
||||||
| 156 | |||||||
| 157 | // Trigger the finalize_post_form event |
||||||
| 158 | $this->_events->trigger('finalize_post_form', ['destination' => &$context['destination'], 'page_title' => &$context['page_title'], 'show_additional_options' => &$context['show_additional_options'], 'editorOptions' => &$editorOptions]); |
||||||
| 159 | |||||||
| 160 | // Initialize the editor |
||||||
| 161 | create_control_richedit($editorOptions); |
||||||
| 162 | |||||||
| 163 | $this->_finalizePage(); |
||||||
| 164 | } |
||||||
| 165 | |||||||
| 166 | /** |
||||||
| 167 | * Load language files, templates and prepare posting basics |
||||||
| 168 | */ |
||||||
| 169 | protected function _beforePreparePost(): void |
||||||
| 170 | { |
||||||
| 171 | global $context; |
||||||
| 172 | |||||||
| 173 | Txt::load('Post'); |
||||||
| 174 | Txt::load('Errors'); |
||||||
| 175 | |||||||
| 176 | $context['robot_no_index'] = true; |
||||||
| 177 | $this->_template_layers->add('postarea'); |
||||||
|
0 ignored issues
–
show
The method
add() does not exist on null.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||
| 178 | $this->_topic_attributes = [ |
||||||
| 179 | 'locked' => 0, |
||||||
| 180 | 'notify' => 0, |
||||||
| 181 | 'is_sticky' => 0, |
||||||
| 182 | 'id_last_msg' => 0, |
||||||
| 183 | 'id_member' => 0, |
||||||
| 184 | 'id_first_msg' => 0, |
||||||
| 185 | 'subject' => '', |
||||||
| 186 | 'last_post_time' => 0 |
||||||
| 187 | ]; |
||||||
| 188 | } |
||||||
| 189 | |||||||
| 190 | /** |
||||||
| 191 | * Does some basic checking and if everything is valid will |
||||||
| 192 | * load $context with needed post form options |
||||||
| 193 | * |
||||||
| 194 | * - Ensures we have a topic id |
||||||
| 195 | * - Checks if a topic is locked |
||||||
| 196 | * - Determines if this msg will be pre approved or member requires approval |
||||||
| 197 | * |
||||||
| 198 | * @throws Exception |
||||||
| 199 | */ |
||||||
| 200 | protected function _beforePrepareContext(): void |
||||||
| 201 | { |
||||||
| 202 | global $topic, $modSettings, $board, $context; |
||||||
| 203 | |||||||
| 204 | // You must be posting to *some* board. |
||||||
| 205 | if (empty($board) && !$context['make_event']) |
||||||
| 206 | { |
||||||
| 207 | throw new Exception('no_board', false); |
||||||
| 208 | } |
||||||
| 209 | |||||||
| 210 | // All those wonderful modifiers and attachments |
||||||
| 211 | $this->_template_layers->add('additional_options', 200); |
||||||
| 212 | |||||||
| 213 | if ($this->getApi() !== false) |
||||||
| 214 | { |
||||||
| 215 | $context['sub_template'] = 'post'; |
||||||
| 216 | |||||||
| 217 | // Just in case of an earlier error... |
||||||
| 218 | $context['preview_message'] = ''; |
||||||
| 219 | $context['preview_subject'] = ''; |
||||||
| 220 | } |
||||||
| 221 | |||||||
| 222 | // No message is complete without a topic. |
||||||
| 223 | if (empty($topic) && !empty($_REQUEST['msg'])) |
||||||
| 224 | { |
||||||
| 225 | $topic = associatedTopic((int) $_REQUEST['msg']); |
||||||
| 226 | if (empty($topic)) |
||||||
| 227 | { |
||||||
| 228 | $this->_req->clearValue('msg', 'both'); |
||||||
| 229 | } |
||||||
| 230 | } |
||||||
| 231 | |||||||
| 232 | // Check if it's locked. It isn't locked if no topic is specified. |
||||||
| 233 | if (!empty($topic)) |
||||||
| 234 | { |
||||||
| 235 | $this->_topic_attributes = topicUserAttributes($topic, $this->user->id); |
||||||
|
0 ignored issues
–
show
The property
id does not exist on ElkArte\Helper\ValuesContainer. Since you implemented __get, consider adding a @property annotation.
Loading history...
|
|||||||
| 236 | $context['notify'] = $this->_topic_attributes['notify']; |
||||||
| 237 | $context['topic_last_message'] = $this->_topic_attributes['id_last_msg']; |
||||||
| 238 | $msg = $this->_req->getRequest('msg', 'intval', 0); |
||||||
| 239 | |||||||
| 240 | if (empty($msg)) |
||||||
| 241 | { |
||||||
| 242 | if ($this->user->is_guest && !allowedTo('post_reply_any') |
||||||
|
0 ignored issues
–
show
The property
is_guest does not exist on ElkArte\Helper\ValuesContainer. Since you implemented __get, consider adding a @property annotation.
Loading history...
|
|||||||
| 243 | && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any'))) |
||||||
| 244 | { |
||||||
| 245 | is_not_guest(); |
||||||
| 246 | } |
||||||
| 247 | |||||||
| 248 | // By default, the reply will be approved... |
||||||
| 249 | $context['becomes_approved'] = true; |
||||||
| 250 | if ($this->_topic_attributes['id_member'] != $this->user->id) |
||||||
| 251 | { |
||||||
| 252 | if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') |
||||||
| 253 | && !allowedTo('post_reply_any')) |
||||||
| 254 | { |
||||||
| 255 | $context['becomes_approved'] = false; |
||||||
| 256 | } |
||||||
| 257 | else |
||||||
| 258 | { |
||||||
| 259 | isAllowedTo('post_reply_any'); |
||||||
| 260 | } |
||||||
| 261 | } |
||||||
| 262 | elseif (!allowedTo('post_reply_any')) |
||||||
| 263 | { |
||||||
| 264 | if ($modSettings['postmod_active']) |
||||||
| 265 | { |
||||||
| 266 | if (allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) |
||||||
| 267 | { |
||||||
| 268 | $context['becomes_approved'] = false; |
||||||
| 269 | } |
||||||
| 270 | // Guests do not have post_unapproved_replies_own permission, so it's always post_unapproved_replies_any |
||||||
| 271 | elseif ($this->user->is_guest && allowedTo('post_unapproved_replies_any')) |
||||||
| 272 | { |
||||||
| 273 | $context['becomes_approved'] = false; |
||||||
| 274 | } |
||||||
| 275 | else |
||||||
| 276 | { |
||||||
| 277 | isAllowedTo('post_reply_own'); |
||||||
| 278 | } |
||||||
| 279 | } |
||||||
| 280 | else |
||||||
| 281 | { |
||||||
| 282 | isAllowedTo('post_reply_own'); |
||||||
| 283 | } |
||||||
| 284 | } |
||||||
| 285 | } |
||||||
| 286 | else |
||||||
| 287 | { |
||||||
| 288 | $context['becomes_approved'] = true; |
||||||
| 289 | } |
||||||
| 290 | |||||||
| 291 | $context['can_lock'] = allowedTo('lock_any') || ($this->user->id == $this->_topic_attributes['id_member'] && allowedTo('lock_own')); |
||||||
| 292 | $context['can_sticky'] = allowedTo('make_sticky'); |
||||||
| 293 | $context['notify'] = !empty($context['notify']); |
||||||
| 294 | $context['sticky'] = isset($_REQUEST['sticky']) ? !empty($_REQUEST['sticky']) : $this->_topic_attributes['is_sticky']; |
||||||
| 295 | } |
||||||
| 296 | else |
||||||
| 297 | { |
||||||
| 298 | $this->_topic_attributes['id_member'] = 0; |
||||||
| 299 | $context['becomes_approved'] = true; |
||||||
| 300 | if (empty($context['make_event']) || !empty($board)) |
||||||
| 301 | { |
||||||
| 302 | if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) |
||||||
| 303 | { |
||||||
| 304 | $context['becomes_approved'] = false; |
||||||
| 305 | } |
||||||
| 306 | else |
||||||
| 307 | { |
||||||
| 308 | isAllowedTo('post_new'); |
||||||
| 309 | } |
||||||
| 310 | } |
||||||
| 311 | |||||||
| 312 | $this->_topic_attributes['locked'] = 0; |
||||||
| 313 | |||||||
| 314 | // @todo These won't work if you're making an event. |
||||||
| 315 | $context['can_lock'] = allowedTo(['lock_any', 'lock_own']); |
||||||
| 316 | $context['can_sticky'] = allowedTo('make_sticky'); |
||||||
| 317 | |||||||
| 318 | $context['notify'] = !empty($context['notify']); |
||||||
| 319 | $context['sticky'] = !empty($_REQUEST['sticky']); |
||||||
| 320 | } |
||||||
| 321 | |||||||
| 322 | // @todo These won't work if you're posting an event! |
||||||
| 323 | $context['can_notify'] = allowedTo('mark_any_notify'); |
||||||
| 324 | $context['can_move'] = allowedTo('move_any'); |
||||||
| 325 | $context['move'] = !empty($_REQUEST['move']); |
||||||
| 326 | $context['announce'] = !empty($_REQUEST['announce']); |
||||||
| 327 | $context['id_draft'] = $this->_req->getPost('id_draft', 'intval', 0); |
||||||
| 328 | |||||||
| 329 | // You can only announce topics that will get approved... |
||||||
| 330 | $context['can_announce'] = allowedTo('announce_topic') && $context['becomes_approved']; |
||||||
| 331 | $context['locked'] = !empty($this->_topic_attributes['locked']) || !empty($_REQUEST['lock']); |
||||||
| 332 | $context['can_quote'] = empty($modSettings['disabledBBC']) || !in_array('quote', explode(',', $modSettings['disabledBBC'])); |
||||||
| 333 | |||||||
| 334 | // Generally don't show the approval box... (Assume we want things approved) |
||||||
| 335 | $context['show_approval'] = allowedTo('approve_posts') && $context['becomes_approved'] ? 2 : (allowedTo('approve_posts') ? 1 : 0); |
||||||
| 336 | |||||||
| 337 | // Don't allow a post if it's locked and you aren't all powerful. |
||||||
| 338 | if (!$this->_topic_attributes['locked']) |
||||||
| 339 | { |
||||||
| 340 | return; |
||||||
| 341 | } |
||||||
| 342 | |||||||
| 343 | if (allowedTo('moderate_board')) |
||||||
| 344 | { |
||||||
| 345 | return; |
||||||
| 346 | } |
||||||
| 347 | |||||||
| 348 | throw new Exception('topic_locked', false); |
||||||
| 349 | } |
||||||
| 350 | |||||||
| 351 | /** |
||||||
| 352 | * Get the message setup for ... |
||||||
| 353 | * |
||||||
| 354 | * - Sets up the form for preview / modify / new message status. Items |
||||||
| 355 | * such as icons, text, etc. |
||||||
| 356 | * - Look if a new topic was posted while working on this prose |
||||||
| 357 | * - Shows the message preview if requested |
||||||
| 358 | * - Triggers prepare_modifying, prepare_editing, prepare_posting |
||||||
| 359 | */ |
||||||
| 360 | protected function _generatingMessage(): void |
||||||
| 361 | { |
||||||
| 362 | global $txt, $topic, $modSettings, $context, $options, $board_info; |
||||||
| 363 | |||||||
| 364 | // Convert / Clean the input elements |
||||||
| 365 | $msg = $this->_req->getRequest('msg', 'intval', null); |
||||||
| 366 | $last_msg = $this->_req->getRequest('last_msg', 'intval', null); |
||||||
| 367 | $message = $this->_req->getPost('message', 'trim', null); |
||||||
| 368 | $subject = $this->_req->getPost('subject', 'trim', ''); |
||||||
| 369 | |||||||
| 370 | // See if any new replies have come along. |
||||||
| 371 | if (empty($msg) |
||||||
| 372 | && !empty($topic) |
||||||
| 373 | && empty($options['no_new_reply_warning']) |
||||||
| 374 | && isset($last_msg) |
||||||
| 375 | && $context['topic_last_message'] > $last_msg) |
||||||
| 376 | { |
||||||
| 377 | $context['new_replies'] = countMessagesSince($topic, (int) $_REQUEST['last_msg'], false, $modSettings['postmod_active'] && !allowedTo('approve_posts')); |
||||||
| 378 | |||||||
| 379 | if (!empty($context['new_replies'])) |
||||||
| 380 | { |
||||||
| 381 | if ($context['new_replies'] == 1) |
||||||
| 382 | { |
||||||
| 383 | $txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply']; |
||||||
| 384 | } |
||||||
| 385 | else |
||||||
| 386 | { |
||||||
| 387 | $txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']); |
||||||
| 388 | } |
||||||
| 389 | |||||||
| 390 | $this->_post_errors->addError('new_replies', 0); |
||||||
|
0 ignored issues
–
show
The method
addError() does not exist on null.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||
| 391 | |||||||
| 392 | $modSettings['topicSummaryPosts'] = $context['new_replies'] > $modSettings['topicSummaryPosts'] ? max($modSettings['topicSummaryPosts'], 5) : $modSettings['topicSummaryPosts']; |
||||||
| 393 | } |
||||||
| 394 | } |
||||||
| 395 | |||||||
| 396 | // Get a response prefix (like 'Re:') in the default forum language. |
||||||
| 397 | $context['response_prefix'] = response_prefix(); |
||||||
| 398 | $context['destination'] = 'post2;start=' . $this->_req->getRequest('start', 'intval', 0); |
||||||
| 399 | |||||||
| 400 | // Previewing, modifying, or posting? |
||||||
| 401 | // Do we have a body, but an error happened. |
||||||
| 402 | if (isset($message) || $this->_post_errors->hasErrors()) |
||||||
| 403 | { |
||||||
| 404 | $this->_previewPost($msg, $topic, $message, $subject); |
||||||
| 405 | } |
||||||
| 406 | // Editing a message... |
||||||
| 407 | elseif (isset($msg) && !empty($topic)) |
||||||
| 408 | { |
||||||
| 409 | $this->_editPost($msg, $topic); |
||||||
| 410 | } |
||||||
| 411 | // Posting... |
||||||
| 412 | else |
||||||
| 413 | { |
||||||
| 414 | $this->_makePost($topic, $subject); |
||||||
| 415 | } |
||||||
| 416 | |||||||
| 417 | // Check whether this is a really old post being bumped... |
||||||
| 418 | if (!empty($topic) |
||||||
| 419 | && !empty($board_info['old_posts']) |
||||||
| 420 | && !empty($modSettings['oldTopicDays']) |
||||||
| 421 | && $this->_topic_attributes['last_post_time'] + $modSettings['oldTopicDays'] * 86400 < time() |
||||||
| 422 | && empty($this->_topic_attributes['is_sticky']) |
||||||
| 423 | && !isset($_REQUEST['subject'])) |
||||||
| 424 | { |
||||||
| 425 | $this->_post_errors->addError(['old_topic', [$modSettings['oldTopicDays']]], 0); |
||||||
| 426 | } |
||||||
| 427 | } |
||||||
| 428 | |||||||
| 429 | /** |
||||||
| 430 | * Preview a post, |
||||||
| 431 | * - From pressing preview |
||||||
| 432 | * - When errors are generated when trying to post. |
||||||
| 433 | * |
||||||
| 434 | * @param int $msg |
||||||
| 435 | * @param int $topic |
||||||
| 436 | * @param string $message |
||||||
| 437 | * @param string $subject |
||||||
| 438 | */ |
||||||
| 439 | private function _previewPost($msg, $topic, $message, $subject): void |
||||||
| 440 | { |
||||||
| 441 | global $txt, $modSettings, $context; |
||||||
| 442 | |||||||
| 443 | $preview = $this->_req->getPost('preview', 'isset', false); |
||||||
| 444 | $more_options = $this->_req->getPost('more_options', 'isset', false); |
||||||
| 445 | $ns = $this->_req->getPost('ns', 'isset', false); |
||||||
| 446 | $notify = $this->_req->getPost('notify', 'intval', 0); |
||||||
| 447 | $quote = $this->_req->getRequest('quote', 'intval', 0); |
||||||
| 448 | $followup = $this->_req->getRequest('followup', 'intval', 0); |
||||||
| 449 | $not_approved = $this->_req->getPost('not_approved', 'empty', true); |
||||||
| 450 | $last_msg = $this->_req->getRequest('last_msg', 'intval', null); |
||||||
| 451 | $icon = $this->_req->getPost('icon', 'trim', 'xx'); |
||||||
| 452 | $msg_id = 0; |
||||||
| 453 | |||||||
| 454 | // Validate inputs if they are not just moving the full post form (from QR / QT) |
||||||
| 455 | if (!$more_options && !$this->_post_errors->hasErrors()) |
||||||
| 456 | { |
||||||
| 457 | // This means they didn't click Post and get an error. |
||||||
| 458 | $really_previewing = true; |
||||||
| 459 | } |
||||||
| 460 | else |
||||||
| 461 | { |
||||||
| 462 | if (!isset($message)) |
||||||
| 463 | { |
||||||
| 464 | $message = ''; |
||||||
| 465 | } |
||||||
| 466 | |||||||
| 467 | // They are previewing if they asked to preview (i.e. came from quick reply). |
||||||
| 468 | $really_previewing = !empty($preview) || ($this->getApi() === 'xml'); |
||||||
| 469 | } |
||||||
| 470 | |||||||
| 471 | // Trigger the prepare_modifying event |
||||||
| 472 | $this->_events->trigger('prepare_modifying', [ |
||||||
| 473 | 'post_errors' => $this->_post_errors, |
||||||
| 474 | 'really_previewing' => &$really_previewing] |
||||||
| 475 | ); |
||||||
| 476 | |||||||
| 477 | // In order to keep the approval status flowing through, we have to pass it through the form... |
||||||
| 478 | $context['becomes_approved'] = $not_approved; |
||||||
| 479 | $context['show_approval'] = isset($this->_req->post->approve) ? ($this->_req->post->approve ? 2 : 1) : 0; |
||||||
| 480 | $context['can_announce'] = $context['can_announce'] && $context['becomes_approved']; |
||||||
| 481 | |||||||
| 482 | // Set up the inputs for the form. |
||||||
| 483 | $this->_form_subject = strtr(Util::htmlspecialchars($subject), ["\r" => '', "\n" => '', "\t" => '']); |
||||||
| 484 | $this->_form_message = Util::htmlspecialchars($message, ENT_QUOTES, 'UTF-8', true); |
||||||
| 485 | |||||||
| 486 | // Make sure the subject isn't too long - taking into account special characters. |
||||||
| 487 | if (Util::strlen($this->_form_subject) > 100) |
||||||
| 488 | { |
||||||
| 489 | $this->_form_subject = Util::substr($this->_form_subject, 0, 100); |
||||||
| 490 | } |
||||||
| 491 | |||||||
| 492 | // Are you... a guest? |
||||||
| 493 | if ($this->user->is_guest) |
||||||
|
0 ignored issues
–
show
The property
is_guest does not exist on ElkArte\Helper\ValuesContainer. Since you implemented __get, consider adding a @property annotation.
Loading history...
|
|||||||
| 494 | { |
||||||
| 495 | $context['name'] = $this->_req->getPost('guestname', 'Util::htmlspecialchars', ''); |
||||||
| 496 | $context['email'] = $this->_req->getPost('email', 'Util::htmlspecialchars', ''); |
||||||
| 497 | $this->user->name = $context['name']; |
||||||
|
0 ignored issues
–
show
The property
name does not exist on ElkArte\Helper\ValuesContainer. Since you implemented __set, consider adding a @property annotation.
Loading history...
|
|||||||
| 498 | } |
||||||
| 499 | |||||||
| 500 | // Only show the preview stuff if they really hit Preview, not post, not more options |
||||||
| 501 | if ($really_previewing) |
||||||
| 502 | { |
||||||
| 503 | $this->_setupPreviewContext(!$ns); |
||||||
| 504 | } |
||||||
| 505 | |||||||
| 506 | // Set up the checkboxes. |
||||||
| 507 | $context['notify'] = $notify; |
||||||
| 508 | $context['use_smileys'] = !$ns; |
||||||
| 509 | $context['icon'] = preg_replace('~[\./\\\\*\':"<>]~', '', $icon); |
||||||
| 510 | |||||||
| 511 | // Set the destination action for submission. |
||||||
| 512 | $context['destination'] .= isset($msg) ? ';msg=' . $msg . ';' . $context['session_var'] . '=' . $context['session_id'] : ''; |
||||||
| 513 | $context['submit_label'] = isset($msg) ? $txt['save'] : $txt['post']; |
||||||
| 514 | |||||||
| 515 | // Previewing an edit? Modifying an existing message? |
||||||
| 516 | if (isset($msg) && !empty($topic)) |
||||||
| 517 | { |
||||||
| 518 | // Get the existing message. |
||||||
| 519 | $message = messageDetails($msg, $topic); |
||||||
| 520 | |||||||
| 521 | // The message they were trying to edit was most likely deleted. |
||||||
| 522 | if ($message === false) |
||||||
|
0 ignored issues
–
show
|
|||||||
| 523 | { |
||||||
| 524 | throw new Exception('no_message', false); |
||||||
| 525 | } |
||||||
| 526 | |||||||
| 527 | $errors = checkMessagePermissions($message['message']); |
||||||
| 528 | if (!empty($errors)) |
||||||
| 529 | { |
||||||
| 530 | foreach ($errors as $error) |
||||||
| 531 | { |
||||||
| 532 | $this->_post_errors->addError($error); |
||||||
| 533 | } |
||||||
| 534 | } |
||||||
| 535 | |||||||
| 536 | prepareMessageContext($message); |
||||||
| 537 | } |
||||||
| 538 | elseif (isset($last_msg)) |
||||||
| 539 | { |
||||||
| 540 | // @todo: sort out what kind of combinations are actually possible |
||||||
| 541 | // Posting a quoted reply? |
||||||
| 542 | if ((!empty($topic) && !empty($quote)) |
||||||
| 543 | || (!empty($modSettings['enableFollowup']) && !empty($followup))) |
||||||
| 544 | { |
||||||
| 545 | $msg_id = empty($quote) ? $followup : $quote; |
||||||
| 546 | $case = 2; |
||||||
| 547 | } |
||||||
| 548 | // Posting a reply without a quote? |
||||||
| 549 | elseif (!empty($topic) && empty($quote)) |
||||||
| 550 | { |
||||||
| 551 | $this->_topic_attributes['subject'] = $subject; |
||||||
| 552 | $case = 3; |
||||||
| 553 | } |
||||||
| 554 | else |
||||||
| 555 | { |
||||||
| 556 | $case = 4; |
||||||
| 557 | } |
||||||
| 558 | |||||||
| 559 | [$this->_form_subject,] = getFormMsgSubject($case, $topic, $this->_topic_attributes['subject'], $msg_id); |
||||||
| 560 | } |
||||||
| 561 | |||||||
| 562 | // No check is needed, since nothing is really posted. |
||||||
| 563 | checkSubmitOnce('free'); |
||||||
| 564 | } |
||||||
| 565 | |||||||
| 566 | /** |
||||||
| 567 | * Going back to a message to make changes, like damn I should watch what |
||||||
| 568 | * my fingers are typing. |
||||||
| 569 | * |
||||||
| 570 | * @param int $msg |
||||||
| 571 | * @param int $topic |
||||||
| 572 | */ |
||||||
| 573 | private function _editPost($msg, $topic): void |
||||||
| 574 | { |
||||||
| 575 | global $txt, $context; |
||||||
| 576 | |||||||
| 577 | $message = getFormMsgSubject(1, $topic, '', $msg); |
||||||
| 578 | |||||||
| 579 | // The message they were trying to edit was most likely deleted. |
||||||
| 580 | if ($message === false) |
||||||
|
0 ignored issues
–
show
|
|||||||
| 581 | { |
||||||
| 582 | throw new Exception('no_message', false); |
||||||
| 583 | } |
||||||
| 584 | |||||||
| 585 | // Trigger the prepare_editing event |
||||||
| 586 | $this->_events->trigger('prepare_editing', ['topic' => $topic, 'message' => &$message]); |
||||||
| 587 | |||||||
| 588 | if (!empty($message['errors'])) |
||||||
| 589 | { |
||||||
| 590 | foreach ($message['errors'] as $error) |
||||||
| 591 | { |
||||||
| 592 | $this->_post_errors->addError($error); |
||||||
| 593 | } |
||||||
| 594 | } |
||||||
| 595 | |||||||
| 596 | // Get the stuff ready for the form. |
||||||
| 597 | $this->_form_subject = censor($message['message']['subject']); |
||||||
| 598 | $this->_form_message = censor($this->preparse->un_preparsecode($message['message']['body'])); |
||||||
| 599 | |||||||
| 600 | // Check the boxes that should be checked. |
||||||
| 601 | $context['use_smileys'] = !empty($message['message']['smileys_enabled']); |
||||||
| 602 | $context['icon'] = $message['message']['icon']; |
||||||
| 603 | |||||||
| 604 | // Set the destination. |
||||||
| 605 | $context['destination'] .= ';msg=' . $msg . ';' . $context['session_var'] . '=' . $context['session_id']; |
||||||
| 606 | $context['submit_label'] = $txt['save']; |
||||||
| 607 | } |
||||||
| 608 | |||||||
| 609 | /** |
||||||
| 610 | * Think you are done and ready to make a post |
||||||
| 611 | * |
||||||
| 612 | * @param int $topic |
||||||
| 613 | * @param string $subject |
||||||
| 614 | */ |
||||||
| 615 | private function _makePost($topic, $subject): void |
||||||
| 616 | { |
||||||
| 617 | global $context, $txt, $modSettings; |
||||||
| 618 | |||||||
| 619 | $quote = $this->_req->getRequest('quote', 'intval', 0); |
||||||
| 620 | $followup = $this->_req->getRequest('followup', 'intval', 0); |
||||||
| 621 | |||||||
| 622 | // By default.... |
||||||
| 623 | $context['use_smileys'] = true; |
||||||
| 624 | $context['icon'] = 'xx'; |
||||||
| 625 | $msg_id = 0; |
||||||
| 626 | |||||||
| 627 | if ($this->user->is_guest) |
||||||
|
0 ignored issues
–
show
The property
is_guest does not exist on ElkArte\Helper\ValuesContainer. Since you implemented __get, consider adding a @property annotation.
Loading history...
|
|||||||
| 628 | { |
||||||
| 629 | $context['name'] = $_SESSION['guest_name'] ?? ''; |
||||||
| 630 | $context['email'] = $_SESSION['guest_email'] ?? ''; |
||||||
| 631 | } |
||||||
| 632 | |||||||
| 633 | // Trigger the prepare_posting event |
||||||
| 634 | $this->_events->trigger('prepare_posting'); |
||||||
| 635 | |||||||
| 636 | $context['submit_label'] = $txt['post']; |
||||||
| 637 | |||||||
| 638 | // @todo: sort out what kind of combinations are actually possible |
||||||
| 639 | // Posting a quoted reply? |
||||||
| 640 | if ((!empty($topic) && $quote !== 0) |
||||||
| 641 | || (!empty($modSettings['enableFollowup']) && $followup !== 0)) |
||||||
| 642 | { |
||||||
| 643 | $case = 2; |
||||||
| 644 | $msg_id = empty($quote) ? $followup : $quote; |
||||||
| 645 | } |
||||||
| 646 | // Posting a reply without a quote? |
||||||
| 647 | elseif (!empty($topic) && $quote === 0) |
||||||
| 648 | { |
||||||
| 649 | $case = 3; |
||||||
| 650 | } |
||||||
| 651 | else |
||||||
| 652 | { |
||||||
| 653 | $this->_topic_attributes['subject'] = $subject; |
||||||
| 654 | $case = 4; |
||||||
| 655 | } |
||||||
| 656 | |||||||
| 657 | [$this->_form_subject, $this->_form_message] = getFormMsgSubject($case, $topic, $this->_topic_attributes['subject'], $msg_id); |
||||||
| 658 | } |
||||||
| 659 | |||||||
| 660 | /** |
||||||
| 661 | * Loads up the context global with a preview of the post |
||||||
| 662 | * |
||||||
| 663 | * @param bool $ns no smiley flag |
||||||
| 664 | */ |
||||||
| 665 | private function _setupPreviewContext($ns): void |
||||||
| 666 | { |
||||||
| 667 | global $txt, $modSettings, $context; |
||||||
| 668 | |||||||
| 669 | // Set up the preview message and subject |
||||||
| 670 | $context['preview_message'] = $this->_form_message; |
||||||
| 671 | $this->preparse->preparsecode($this->_form_message, true); |
||||||
| 672 | |||||||
| 673 | // Do all bulletin board code thing on the message |
||||||
| 674 | $bbc_parser = ParserWrapper::instance(); |
||||||
| 675 | $this->preparse->preparsecode($context['preview_message']); |
||||||
| 676 | $context['preview_message'] = $bbc_parser->parseMessage($context['preview_message'], $ns); |
||||||
| 677 | $context['preview_message'] = censor($context['preview_message']); |
||||||
| 678 | |||||||
| 679 | // Don't forget the subject |
||||||
| 680 | $context['preview_subject'] = censor($this->_form_subject); |
||||||
| 681 | |||||||
| 682 | // Any errors we should tell them about? |
||||||
| 683 | if ($this->_form_subject === '') |
||||||
| 684 | { |
||||||
| 685 | $this->_post_errors->addError('no_subject'); |
||||||
| 686 | $context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>'; |
||||||
| 687 | } |
||||||
| 688 | |||||||
| 689 | if ($context['preview_message'] === '') |
||||||
| 690 | { |
||||||
| 691 | $this->_post_errors->addError('no_message'); |
||||||
| 692 | } |
||||||
| 693 | elseif (!empty($modSettings['max_messageLength']) && Util::strlen($this->_form_message) > $modSettings['max_messageLength']) |
||||||
| 694 | { |
||||||
| 695 | $this->_post_errors->addError(['long_message', [$modSettings['max_messageLength']]]); |
||||||
| 696 | } |
||||||
| 697 | |||||||
| 698 | // Protect any CDATA blocks. |
||||||
| 699 | if ($this->getApi() === 'xml') |
||||||
| 700 | { |
||||||
| 701 | $context['preview_message'] = strtr($context['preview_message'], [']]>' => ']]]]><![CDATA[>']); |
||||||
| 702 | } |
||||||
| 703 | } |
||||||
| 704 | |||||||
| 705 | /** |
||||||
| 706 | * Preparing the page for post preview or error handling. |
||||||
| 707 | */ |
||||||
| 708 | protected function _preparingPage(): void |
||||||
| 709 | { |
||||||
| 710 | global $txt, $topic, $modSettings, $board, $context; |
||||||
| 711 | |||||||
| 712 | // Any errors occurred? |
||||||
| 713 | $context['post_error'] = [ |
||||||
| 714 | 'errors' => $this->_post_errors->prepareErrors(), |
||||||
| 715 | 'type' => $this->_post_errors->getErrorType() === 0 ? 'minor' : 'serious', |
||||||
| 716 | 'title' => $this->_post_errors->getErrorType() === 0 ? $txt['warning_while_submitting'] : $txt['error_while_submitting'], |
||||||
| 717 | ]; |
||||||
| 718 | |||||||
| 719 | // What are you doing? Posting, modifying, previewing, new post, or reply... |
||||||
| 720 | if (empty($context['page_title'])) |
||||||
| 721 | { |
||||||
| 722 | if (isset($_REQUEST['msg'])) |
||||||
| 723 | { |
||||||
| 724 | $context['page_title'] = $txt['modify_msg']; |
||||||
| 725 | } |
||||||
| 726 | elseif (isset($_REQUEST['subject'], $context['preview_subject'])) |
||||||
| 727 | { |
||||||
| 728 | $context['page_title'] = $txt['post_reply']; |
||||||
| 729 | } |
||||||
| 730 | elseif (empty($topic)) |
||||||
| 731 | { |
||||||
| 732 | $context['page_title'] = $txt['start_new_topic']; |
||||||
| 733 | } |
||||||
| 734 | else |
||||||
| 735 | { |
||||||
| 736 | $context['page_title'] = $txt['post_reply']; |
||||||
| 737 | } |
||||||
| 738 | } |
||||||
| 739 | |||||||
| 740 | // Update the topic summary, needed to show new posts in a preview |
||||||
| 741 | if (!empty($topic) && !empty($modSettings['topicSummaryPosts'])) |
||||||
| 742 | { |
||||||
| 743 | $only_approved = $modSettings['postmod_active'] && !allowedTo('approve_posts'); |
||||||
| 744 | |||||||
| 745 | if ($this->getApi() === 'xml') |
||||||
| 746 | { |
||||||
| 747 | $limit = empty($context['new_replies']) ? 0 : (int) $context['new_replies']; |
||||||
| 748 | } |
||||||
| 749 | else |
||||||
| 750 | 6 | { |
|||||
| 751 | $limit = $modSettings['topicSummaryPosts']; |
||||||
| 752 | 6 | } |
|||||
| 753 | 6 | ||||||
| 754 | $before = isset($_REQUEST['msg']) ? ['before' => (int) $_REQUEST['msg']] : []; |
||||||
| 755 | |||||||
| 756 | 6 | $counter = 0; |
|||||
| 757 | $context['previous_posts'] = empty($limit) ? [] : selectMessages($topic, 0, $limit, $before, $only_approved); |
||||||
| 758 | foreach ($context['previous_posts'] as &$post) |
||||||
| 759 | { |
||||||
| 760 | $post['is_new'] = !empty($context['new_replies']); |
||||||
| 761 | $post['counter'] = $counter++; |
||||||
| 762 | $post['is_ignored'] = !empty($modSettings['enable_buddylist']) && in_array($post['id_poster'], $this->user->ignoreusers); |
||||||
|
0 ignored issues
–
show
It seems like
$this->user->ignoreusers can also be of type null; however, parameter $haystack of in_array() does only seem to accept array, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
The property
ignoreusers does not exist on ElkArte\Helper\ValuesContainer. Since you implemented __get, consider adding a @property annotation.
Loading history...
|
|||||||
| 763 | |||||||
| 764 | if (!empty($context['new_replies'])) |
||||||
| 765 | { |
||||||
| 766 | $context['new_replies']--; |
||||||
| 767 | 6 | } |
|||||
| 768 | } |
||||||
| 769 | |||||||
| 770 | // If there are previous posts, enable QQ for them |
||||||
| 771 | if (count($context['previous_posts']) > 0) |
||||||
| 772 | { |
||||||
| 773 | 6 | loadJavascriptFile('quickQuote.js', ['defer' => true]); |
|||||
| 774 | theme()->addInlineJavascript(" |
||||||
| 775 | document.addEventListener('DOMContentLoaded', () => new Elk_QuickQuote(), false);", true |
||||||
| 776 | 6 | ); |
|||||
| 777 | } |
||||||
| 778 | } |
||||||
| 779 | 6 | ||||||
| 780 | // Just ajax previewing then lets stop now |
||||||
| 781 | if ($this->getApi() === 'xml') |
||||||
| 782 | { |
||||||
| 783 | obExit(); |
||||||
| 784 | } |
||||||
| 785 | |||||||
| 786 | $context['subject'] = addcslashes($this->_form_subject, '"'); |
||||||
| 787 | $context['message'] = str_replace(['"', '<', '>', ' '], ['"', '<', '>', ' '], $this->_form_message); |
||||||
| 788 | |||||||
| 789 | 6 | // Message icons - customized or not, retrieve them... |
|||||
| 790 | require_once(SUBSDIR . '/MessageIcons.subs.php'); |
||||||
| 791 | $context['icons'] = array_values(getMessageIcons($board)); |
||||||
| 792 | 6 | ||||||
| 793 | $context['icon_url'] = ''; |
||||||
| 794 | |||||||
| 795 | if (!empty($context['icons'])) |
||||||
| 796 | { |
||||||
| 797 | 6 | $context['icons'][count($context['icons']) - 1]['is_last'] = true; |
|||||
| 798 | 6 | $context['icons'][0]['selected'] = true; |
|||||
| 799 | |||||||
| 800 | // $context['icon'] is set when editing a message |
||||||
| 801 | 6 | if (!isset($context['icon'])) |
|||||
| 802 | { |
||||||
| 803 | $context['icon'] = $context['icons'][0]['value']; |
||||||
| 804 | 6 | } |
|||||
| 805 | |||||||
| 806 | $found = false; |
||||||
| 807 | 6 | foreach ($context['icons'] as $icon) |
|||||
| 808 | { |
||||||
| 809 | 4 | if ($icon['value'] === $context['icon']) |
|||||
| 810 | { |
||||||
| 811 | $found = true; |
||||||
| 812 | 4 | $context['icon_url'] = $icon['url']; |
|||||
| 813 | break; |
||||||
| 814 | } |
||||||
| 815 | } |
||||||
| 816 | |||||||
| 817 | // Fail safe |
||||||
| 818 | 4 | if (!$found) |
|||||
| 819 | { |
||||||
| 820 | $context['icon'] = $context['icons'][0]['value']; |
||||||
| 821 | $context['icon_url'] = $context['icons'][0]['url']; |
||||||
| 822 | } |
||||||
| 823 | } |
||||||
| 824 | |||||||
| 825 | 6 | $context['show_additional_options'] = !empty($_POST['additional_options']) || isset($_GET['additionalOptions']); |
|||||
| 826 | } |
||||||
| 827 | |||||||
| 828 | 2 | /** |
|||||
| 829 | * Finalizes the page setup for the post form, including the link tree, context flags, and template loading. |
||||||
| 830 | * - Determines whether the action is for creating a new topic, a new post, or editing an existing post. |
||||||
| 831 | * - Updates breadcrumb navigation based on the topic or new topic creation. |
||||||
| 832 | * - Registers the form to prevent duplicate submissions. |
||||||
| 833 | * - Loads the appropriate template for rendering the post form if not using an API. |
||||||
| 834 | 2 | * |
|||||
| 835 | 2 | * @return void |
|||||
| 836 | */ |
||||||
| 837 | 2 | protected function _finalizePage(): void |
|||||
| 838 | { |
||||||
| 839 | global $txt, $scripturl, $topic, $context; |
||||||
| 840 | |||||||
| 841 | // Build the link tree. |
||||||
| 842 | if (empty($topic)) |
||||||
| 843 | 2 | { |
|||||
| 844 | $context['breadcrumbs'][] = [ |
||||||
| 845 | 'name' => '<em>' . $txt['start_new_topic'] . '</em>' |
||||||
| 846 | ]; |
||||||
| 847 | } |
||||||
| 848 | else |
||||||
| 849 | { |
||||||
| 850 | $context['breadcrumbs'][] = [ |
||||||
| 851 | 'url' => $scripturl . '?topic=' . $topic . '.' . $_REQUEST['start'], |
||||||
| 852 | 'name' => $this->_form_subject, |
||||||
| 853 | 'extra_before' => '<span><strong class="nav">' . $context['page_title'] . ' ( </strong></span>', |
||||||
| 854 | 'extra_after' => '<span><strong class="nav"> )</strong></span>' |
||||||
| 855 | ]; |
||||||
| 856 | } |
||||||
| 857 | |||||||
| 858 | $context['back_to_topic'] = isset($_REQUEST['goback']) || (isset($_REQUEST['msg']) && !isset($_REQUEST['subject'])); |
||||||
| 859 | $context['is_new_topic'] = empty($topic); |
||||||
| 860 | $context['is_new_post'] = !isset($_REQUEST['msg']); |
||||||
| 861 | $context['is_first_post'] = $context['is_new_topic'] || (isset($_REQUEST['msg']) && $_REQUEST['msg'] == $this->_topic_attributes['id_first_msg']); |
||||||
| 862 | $context['current_action'] = 'post'; |
||||||
| 863 | |||||||
| 864 | // Register this form in the session variables. |
||||||
| 865 | checkSubmitOnce('register'); |
||||||
| 866 | 2 | ||||||
| 867 | // Finally, load the template. |
||||||
| 868 | if ($this->getApi() === false) |
||||||
| 869 | { |
||||||
| 870 | theme()->getTemplates()->load('Post'); |
||||||
| 871 | $context['sub_template'] = 'post_page'; |
||||||
| 872 | 2 | } |
|||||
| 873 | } |
||||||
| 874 | |||||||
| 875 | /** |
||||||
| 876 | * Posts or saves the message composed with Post(). |
||||||
| 877 | * |
||||||
| 878 | 2 | * What it does: |
|||||
| 879 | * |
||||||
| 880 | * - Requires various permissions depending on the action. |
||||||
| 881 | 2 | * - Handles attachment, post, and calendar saving. |
|||||
| 882 | * - Sends off notifications, and allows for announcements and moderation. |
||||||
| 883 | * - Accessed from ?action=post2. |
||||||
| 884 | * - Triggers events associated with the actual posting |
||||||
| 885 | * - prepare_save_post, save_replying, save_new_topic, save_modify |
||||||
| 886 | * - before_save_post, pre_save_post, after_save_post |
||||||
| 887 | */ |
||||||
| 888 | public function action_post2() |
||||||
| 889 | { |
||||||
| 890 | global $board, $topic, $txt, $modSettings, $context, $board_info, $options; |
||||||
| 891 | |||||||
| 892 | 2 | // Sneaking off, are we? |
|||||
| 893 | if (empty($_POST) && empty($topic)) |
||||||
| 894 | { |
||||||
| 895 | if (empty($_SERVER['CONTENT_LENGTH'])) |
||||||
| 896 | { |
||||||
| 897 | redirectexit('action=post;board=' . $board . '.0'); |
||||||
| 898 | 2 | } |
|||||
| 899 | else |
||||||
| 900 | { |
||||||
| 901 | 2 | throw new Exception('post_upload_error', false); |
|||||
| 902 | 2 | } |
|||||
| 903 | } |
||||||
| 904 | elseif (empty($_POST) && !empty($topic)) |
||||||
| 905 | { |
||||||
| 906 | redirectexit('action=post;topic=' . $topic . '.0'); |
||||||
| 907 | } |
||||||
| 908 | 2 | ||||||
| 909 | // No need! |
||||||
| 910 | $context['robot_no_index'] = true; |
||||||
| 911 | |||||||
| 912 | 2 | // We are now in post2 action |
|||||
| 913 | $context['current_action'] = 'post2'; |
||||||
| 914 | 2 | ||||||
| 915 | // If the session has timed out, let the user re-submit their form. |
||||||
| 916 | if (checkSession('post', '', false) !== '') |
||||||
| 917 | { |
||||||
| 918 | $this->_post_errors->addError('session_timeout'); |
||||||
| 919 | 2 | ||||||
| 920 | // Disable the preview so that any potentially malicious code is not executed |
||||||
| 921 | $_REQUEST['preview'] = false; |
||||||
| 922 | |||||||
| 923 | return $this->action_post(); |
||||||
| 924 | 2 | } |
|||||
| 925 | |||||||
| 926 | $topic_info = []; |
||||||
| 927 | 2 | ||||||
| 928 | // Previewing? Go back to start. |
||||||
| 929 | 2 | if (isset($_REQUEST['preview']) || isset($_POST['more_options'])) |
|||||
| 930 | { |
||||||
| 931 | 2 | return $this->action_post(); |
|||||
| 932 | } |
||||||
| 933 | 2 | ||||||
| 934 | require_once(SUBSDIR . '/Boards.subs.php'); |
||||||
| 935 | Txt::load('Post'); |
||||||
| 936 | |||||||
| 937 | // Trigger the prepare_save_post event |
||||||
| 938 | $this->_events->trigger('prepare_save_post', ['topic_info' => &$topic_info]); |
||||||
| 939 | 2 | ||||||
| 940 | // Prevent double submission of this form. |
||||||
| 941 | 2 | checkSubmitOnce('check'); |
|||||
| 942 | |||||||
| 943 | // If this isn't a new topic load the topic info that we need. |
||||||
| 944 | if (!empty($topic)) |
||||||
| 945 | { |
||||||
| 946 | 2 | $topic_info = getTopicInfo($topic); |
|||||
| 947 | |||||||
| 948 | 2 | // Though the topic should be there, it might have vanished. |
|||||
| 949 | if (empty($topic_info)) |
||||||
| 950 | { |
||||||
| 951 | throw new Exception('topic_doesnt_exist'); |
||||||
| 952 | 2 | } |
|||||
| 953 | |||||||
| 954 | // Did this topic suddenly move? Just checking... |
||||||
| 955 | if ($topic_info['id_board'] != $board) |
||||||
| 956 | { |
||||||
| 957 | 2 | throw new Exception('not_a_topic'); |
|||||
| 958 | } |
||||||
| 959 | } |
||||||
| 960 | |||||||
| 961 | // Replying to a topic? |
||||||
| 962 | if (!empty($topic) && !isset($_REQUEST['msg'])) |
||||||
| 963 | { |
||||||
| 964 | // Don't allow a post if it's locked. |
||||||
| 965 | if ($topic_info['locked'] != 0 && !allowedTo('moderate_board')) |
||||||
| 966 | { |
||||||
| 967 | throw new Exception('topic_locked', false); |
||||||
| 968 | } |
||||||
| 969 | |||||||
| 970 | // Do the permissions and approval stuff... |
||||||
| 971 | $becomesApproved = true; |
||||||
| 972 | 2 | if ($topic_info['id_member_started'] != $this->user->id) |
|||||
| 973 | { |
||||||
| 974 | if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) |
||||||
| 975 | { |
||||||
| 976 | $becomesApproved = false; |
||||||
| 977 | } |
||||||
| 978 | else |
||||||
| 979 | { |
||||||
| 980 | isAllowedTo('post_reply_any'); |
||||||
| 981 | 2 | } |
|||||
| 982 | } |
||||||
| 983 | elseif (!allowedTo('post_reply_any')) |
||||||
| 984 | 2 | { |
|||||
| 985 | if ($modSettings['postmod_active']) |
||||||
| 986 | { |
||||||
| 987 | if (allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) |
||||||
| 988 | { |
||||||
| 989 | $becomesApproved = false; |
||||||
| 990 | 2 | } |
|||||
| 991 | // Guests do not have post_unapproved_replies_own permission, so it's always post_unapproved_replies_any |
||||||
| 992 | elseif ($this->user->is_guest && allowedTo('post_unapproved_replies_any')) |
||||||
| 993 | 2 | { |
|||||
| 994 | 2 | $becomesApproved = false; |
|||||
| 995 | 2 | } |
|||||
| 996 | else |
||||||
| 997 | 2 | { |
|||||
| 998 | isAllowedTo('post_reply_own'); |
||||||
| 999 | 2 | } |
|||||
| 1000 | 2 | } |
|||||
| 1001 | } |
||||||
| 1002 | |||||||
| 1003 | if (isset($_POST['lock'])) |
||||||
| 1004 | { |
||||||
| 1005 | 6 | $_POST['lock'] = $this->_checkLocked($_POST['lock'], $topic_info); |
|||||
| 1006 | } |
||||||
| 1007 | 6 | ||||||
| 1008 | 6 | // So you wanna (un)sticky this...let's see. |
|||||
| 1009 | if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky'))) |
||||||
| 1010 | { |
||||||
| 1011 | unset($_POST['sticky']); |
||||||
| 1012 | 6 | } |
|||||
| 1013 | |||||||
| 1014 | // Trigger the save_replying event |
||||||
| 1015 | $this->_events->trigger('save_replying', ['topic_info' => &$topic_info]); |
||||||
| 1016 | |||||||
| 1017 | // If the number of replies has changed, if the setting is enabled, go back to action_post() - which handles the error. |
||||||
| 1018 | if (empty($options['no_new_reply_warning']) && isset($_POST['last_msg']) && $topic_info['id_last_msg'] > $_POST['last_msg']) |
||||||
| 1019 | { |
||||||
| 1020 | $context['scroll_to_top'] = true; |
||||||
| 1021 | |||||||
| 1022 | return $this->action_post(); |
||||||
| 1023 | } |
||||||
| 1024 | |||||||
| 1025 | $posterIsGuest = $this->user->is_guest; |
||||||
| 1026 | } |
||||||
| 1027 | // Posting a new topic. |
||||||
| 1028 | elseif (empty($topic)) |
||||||
| 1029 | { |
||||||
| 1030 | // Now don't be silly, new topics will get their own id_msg soon enough. |
||||||
| 1031 | unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']); |
||||||
| 1032 | |||||||
| 1033 | // Do like, the permissions, for safety and stuff... |
||||||
| 1034 | $becomesApproved = true; |
||||||
| 1035 | if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) |
||||||
| 1036 | { |
||||||
| 1037 | $becomesApproved = false; |
||||||
| 1038 | } |
||||||
| 1039 | else |
||||||
| 1040 | { |
||||||
| 1041 | isAllowedTo('post_new'); |
||||||
| 1042 | } |
||||||
| 1043 | |||||||
| 1044 | // Trigger the save new topic event |
||||||
| 1045 | $this->_events->trigger('save_new_topic', ['becomesApproved' => &$becomesApproved]); |
||||||
| 1046 | |||||||
| 1047 | if (isset($_POST['lock'])) |
||||||
| 1048 | { |
||||||
| 1049 | $_POST['lock'] = $this->_checkLocked($_POST['lock']); |
||||||
| 1050 | } |
||||||
| 1051 | |||||||
| 1052 | if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky'))) |
||||||
| 1053 | 6 | { |
|||||
| 1054 | unset($_POST['sticky']); |
||||||
| 1055 | } |
||||||
| 1056 | |||||||
| 1057 | $posterIsGuest = $this->user->is_guest; |
||||||
| 1058 | } |
||||||
| 1059 | // Modifying an existing message? |
||||||
| 1060 | elseif (isset($_REQUEST['msg']) && !empty($topic)) |
||||||
| 1061 | 6 | { |
|||||
| 1062 | $_REQUEST['msg'] = (int) $_REQUEST['msg']; |
||||||
| 1063 | |||||||
| 1064 | $msgInfo = basicMessageInfo($_REQUEST['msg'], true, false, false); |
||||||
| 1065 | |||||||
| 1066 | 6 | if (empty($msgInfo)) |
|||||
| 1067 | { |
||||||
| 1068 | throw new Exception('cant_find_messages', false); |
||||||
| 1069 | } |
||||||
| 1070 | 6 | ||||||
| 1071 | // Trigger teh save_modify event |
||||||
| 1072 | $this->_events->trigger('save_modify', ['msgInfo' => &$msgInfo]); |
||||||
| 1073 | |||||||
| 1074 | if (!empty($topic_info['locked']) && !allowedTo('moderate_board')) |
||||||
| 1075 | { |
||||||
| 1076 | throw new Exception('topic_locked', false); |
||||||
| 1077 | 6 | } |
|||||
| 1078 | |||||||
| 1079 | if (isset($_POST['lock'])) |
||||||
| 1080 | 6 | { |
|||||
| 1081 | $_POST['lock'] = $this->_checkLocked($_POST['lock'], $topic_info); |
||||||
| 1082 | } |
||||||
| 1083 | |||||||
| 1084 | // Change the sticky status of this topic? |
||||||
| 1085 | 6 | if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky'])) |
|||||
| 1086 | { |
||||||
| 1087 | 6 | unset($_POST['sticky']); |
|||||
| 1088 | } |
||||||
| 1089 | |||||||
| 1090 | 6 | if ($msgInfo['id_member'] == $this->user->id && !allowedTo('modify_any')) |
|||||
| 1091 | { |
||||||
| 1092 | if ((!$modSettings['postmod_active'] || $msgInfo['approved']) && !empty($modSettings['edit_disable_time']) && $msgInfo['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) |
||||||
| 1093 | { |
||||||
| 1094 | throw new Exception('modify_post_time_passed', false); |
||||||
| 1095 | } |
||||||
| 1096 | 6 | if ($topic_info['id_member_started'] == $this->user->id && !allowedTo('modify_own')) |
|||||
| 1097 | { |
||||||
| 1098 | isAllowedTo('modify_replies'); |
||||||
| 1099 | } |
||||||
| 1100 | else |
||||||
| 1101 | { |
||||||
| 1102 | isAllowedTo('modify_own'); |
||||||
| 1103 | } |
||||||
| 1104 | } |
||||||
| 1105 | elseif ($topic_info['id_member_started'] == $this->user->id && !allowedTo('modify_any')) |
||||||
| 1106 | 6 | { |
|||||
| 1107 | isAllowedTo('modify_replies'); |
||||||
| 1108 | 4 | ||||||
| 1109 | 4 | // If you're modifying a reply, I say it better be logged... |
|||||
| 1110 | $moderationAction = true; |
||||||
| 1111 | } |
||||||
| 1112 | else |
||||||
| 1113 | 6 | { |
|||||
| 1114 | isAllowedTo('modify_any'); |
||||||
| 1115 | |||||||
| 1116 | // Log it, assuming you're not modifying your own post. |
||||||
| 1117 | if ($msgInfo['id_member'] != $this->user->id) |
||||||
| 1118 | { |
||||||
| 1119 | $moderationAction = true; |
||||||
| 1120 | } |
||||||
| 1121 | } |
||||||
| 1122 | |||||||
| 1123 | $posterIsGuest = empty($msgInfo['id_member']); |
||||||
| 1124 | |||||||
| 1125 | // Can they approve it? |
||||||
| 1126 | $can_approve = allowedTo('approve_posts'); |
||||||
| 1127 | $becomesApproved = $modSettings['postmod_active'] ? ($can_approve && !$msgInfo['approved'] ? (empty($_REQUEST['approve']) ? 0 : 1) : $msgInfo['approved']) : 1; |
||||||
| 1128 | $approve_has_changed = $msgInfo['approved'] != $becomesApproved; |
||||||
| 1129 | |||||||
| 1130 | if (!allowedTo('moderate_forum') || !$posterIsGuest) |
||||||
| 1131 | { |
||||||
| 1132 | 6 | $_POST['guestname'] = $msgInfo['poster_name']; |
|||||
| 1133 | $_POST['email'] = $msgInfo['poster_email']; |
||||||
| 1134 | } |
||||||
| 1135 | } |
||||||
| 1136 | |||||||
| 1137 | // In case we want to override |
||||||
| 1138 | if (!isset($_REQUEST['from_qr']) && allowedTo('approve_posts')) |
||||||
| 1139 | { |
||||||
| 1140 | $becomesApproved = !isset($_REQUEST['approve']) || !empty($_REQUEST['approve']) ? 1 : 0; |
||||||
| 1141 | $approve_has_changed = isset($msgInfo['approved']) && $msgInfo['approved'] != $becomesApproved; |
||||||
| 1142 | } |
||||||
| 1143 | |||||||
| 1144 | // If the poster is a guest evaluate the legality of name and email. |
||||||
| 1145 | if ($posterIsGuest) |
||||||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||||
| 1146 | 6 | { |
|||||
| 1147 | $_POST['guestname'] = isset($_POST['guestname']) ? Util::htmlspecialchars(trim($_POST['guestname'])) : ''; |
||||||
| 1148 | 4 | $_POST['email'] = isset($_POST['email']) ? Util::htmlspecialchars(trim($_POST['email'])) : ''; |
|||||
| 1149 | |||||||
| 1150 | if ($_POST['guestname'] === '' || $_POST['guestname'] === '_') |
||||||
| 1151 | { |
||||||
| 1152 | 6 | $this->_post_errors->addError('no_name'); |
|||||
| 1153 | 6 | } |
|||||
| 1154 | |||||||
| 1155 | if (Util::strlen($_POST['guestname']) > 25) |
||||||
| 1156 | 6 | { |
|||||
| 1157 | 6 | $this->_post_errors->addError('long_name'); |
|||||
| 1158 | 6 | } |
|||||
| 1159 | |||||||
| 1160 | if (empty($modSettings['guest_post_no_email'])) |
||||||
| 1161 | 6 | { |
|||||
| 1162 | // Only check if they changed it! |
||||||
| 1163 | if ((!isset($msgInfo) || $msgInfo['poster_email'] !== $_POST['email']) && (!allowedTo('moderate_forum') && !DataValidator::is_valid($_POST, ['email' => 'valid_email|required'], ['email' => 'trim']))) |
||||||
| 1164 | { |
||||||
| 1165 | empty($_POST['email']) ? $this->_post_errors->addError('no_email') : $this->_post_errors->addError('bad_email'); |
||||||
| 1166 | } |
||||||
| 1167 | 6 | ||||||
| 1168 | // Now make sure this email address is not banned from posting. |
||||||
| 1169 | isBannedEmail($_POST['email'], 'cannot_post', sprintf($txt['you_are_post_banned'], $txt['guest_title'])); |
||||||
| 1170 | } |
||||||
| 1171 | 6 | ||||||
| 1172 | 6 | // In case they are making multiple posts this visit, help them along by storing their name. |
|||||
| 1173 | 6 | if (!$this->_post_errors->hasErrors()) |
|||||
| 1174 | 6 | { |
|||||
| 1175 | 6 | $_SESSION['guest_name'] = $_POST['guestname']; |
|||||
| 1176 | 6 | $_SESSION['guest_email'] = $_POST['email']; |
|||||
| 1177 | } |
||||||
| 1178 | } |
||||||
| 1179 | |||||||
| 1180 | 6 | // Trigger before_save_post event |
|||||
| 1181 | 6 | try |
|||||
| 1182 | 6 | { |
|||||
| 1183 | 6 | $this->_events->trigger('before_save_post', ['post_errors' => $this->_post_errors, 'topic_info' => $topic_info]); |
|||||
| 1184 | } |
||||||
| 1185 | 6 | catch (ControllerRedirectException $controllerRedirectException) |
|||||
| 1186 | { |
||||||
| 1187 | return $controllerRedirectException->doRedirect($this); |
||||||
| 1188 | } |
||||||
| 1189 | 6 | ||||||
| 1190 | 6 | // Check the subject and message. |
|||||
| 1191 | 6 | if (!isset($_POST['subject']) || Util::htmltrim(Util::htmlspecialchars($_POST['subject'])) === '') |
|||||
| 1192 | 6 | { |
|||||
| 1193 | $this->_post_errors->addError('no_subject'); |
||||||
| 1194 | } |
||||||
| 1195 | |||||||
| 1196 | 6 | if (!isset($_POST['message']) || Util::htmltrim(Util::htmlspecialchars($_POST['message'], ENT_QUOTES)) === '') |
|||||
| 1197 | { |
||||||
| 1198 | $this->_post_errors->addError('no_message'); |
||||||
| 1199 | 6 | } |
|||||
| 1200 | elseif (!empty($modSettings['max_messageLength']) && Util::strlen($_POST['message']) > $modSettings['max_messageLength']) |
||||||
| 1201 | { |
||||||
| 1202 | 2 | $this->_post_errors->addError(['long_message', [$modSettings['max_messageLength']]]); |
|||||
| 1203 | } |
||||||
| 1204 | else |
||||||
| 1205 | { |
||||||
| 1206 | // Prepare the message a bit for some additional testing. |
||||||
| 1207 | $_POST['message'] = Util::htmlspecialchars($_POST['message'], ENT_QUOTES, 'UTF-8', true); |
||||||
| 1208 | |||||||
| 1209 | 2 | // Preparse code. (Zef) |
|||||
| 1210 | if ($this->user->is_guest) |
||||||
| 1211 | 2 | { |
|||||
| 1212 | $this->user->name = $_POST['guestname']; |
||||||
| 1213 | } |
||||||
| 1214 | 2 | ||||||
| 1215 | $this->preparse->preparsecode($_POST['message']); |
||||||
| 1216 | |||||||
| 1217 | $bbc_parser = ParserWrapper::instance(); |
||||||
| 1218 | |||||||
| 1219 | // Let's see if there's still some content left without the tags. |
||||||
| 1220 | if (Util::htmltrim(strip_tags($bbc_parser->parseMessage($_POST['message'], false), '<img>')) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false)) |
||||||
| 1221 | 4 | { |
|||||
| 1222 | $this->_post_errors->addError('no_message'); |
||||||
| 1223 | } |
||||||
| 1224 | } |
||||||
| 1225 | |||||||
| 1226 | if ($posterIsGuest) |
||||||
| 1227 | { |
||||||
| 1228 | // If user is a guest, make sure the chosen name isn't taken. |
||||||
| 1229 | require_once(SUBSDIR . '/Members.subs.php'); |
||||||
| 1230 | if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($msgInfo['poster_name']) || $_POST['guestname'] !== $msgInfo['poster_name'])) |
||||||
| 1231 | { |
||||||
| 1232 | 4 | $this->_post_errors->addError('bad_name'); |
|||||
| 1233 | } |
||||||
| 1234 | 4 | } |
|||||
| 1235 | // If the user isn't a guest, get his or her name and email. |
||||||
| 1236 | 4 | elseif (!isset($_REQUEST['msg'])) |
|||||
| 1237 | { |
||||||
| 1238 | $_POST['guestname'] = $this->user->username; |
||||||
| 1239 | $_POST['email'] = $this->user->email; |
||||||
| 1240 | } |
||||||
| 1241 | 6 | ||||||
| 1242 | // Posting somewhere else? Are we sure you can? |
||||||
| 1243 | if (!empty($_REQUEST['post_in_board'])) |
||||||
| 1244 | { |
||||||
| 1245 | 6 | $new_board = (int) $_REQUEST['post_in_board']; |
|||||
| 1246 | if (!allowedTo('post_new', $new_board)) |
||||||
| 1247 | 6 | { |
|||||
| 1248 | $post_in_board = boardInfo($new_board); |
||||||
| 1249 | |||||||
| 1250 | 6 | if (!empty($post_in_board)) |
|||||
| 1251 | { |
||||||
| 1252 | $this->_post_errors->addError(['post_new_board', [$post_in_board['name']]]); |
||||||
| 1253 | } |
||||||
| 1254 | else |
||||||
| 1255 | 6 | { |
|||||
| 1256 | $this->_post_errors->addError('post_new'); |
||||||
| 1257 | } |
||||||
| 1258 | } |
||||||
| 1259 | } |
||||||
| 1260 | |||||||
| 1261 | // Any mistakes? |
||||||
| 1262 | 6 | if ($this->_post_errors->hasErrors()) |
|||||
| 1263 | { |
||||||
| 1264 | $context['scroll_to_top'] = true; |
||||||
| 1265 | |||||||
| 1266 | 6 | $_REQUEST['preview'] = false; |
|||||
| 1267 | |||||||
| 1268 | 4 | return $this->action_post(); |
|||||
| 1269 | } |
||||||
| 1270 | |||||||
| 1271 | // Make sure the user isn't spamming the board. |
||||||
| 1272 | 6 | if (!isset($_REQUEST['msg'])) |
|||||
| 1273 | { |
||||||
| 1274 | spamProtection('post'); |
||||||
| 1275 | } |
||||||
| 1276 | |||||||
| 1277 | 6 | // At about this point, we're posting and that's that. |
|||||
| 1278 | ignore_user_abort(true); |
||||||
| 1279 | 2 | detectServer()->setTimeLimit(300); |
|||||
| 1280 | |||||||
| 1281 | // Add special html entities to the subject, name, and email. |
||||||
| 1282 | 6 | $_POST['subject'] = strtr(Util::htmlspecialchars($_POST['subject']), ["\r" => '', "\n" => '', "\t" => '']); |
|||||
| 1283 | $_POST['guestname'] = htmlspecialchars($_POST['guestname'], ENT_COMPAT, 'UTF-8'); |
||||||
| 1284 | $_POST['email'] = htmlspecialchars($_POST['email'], ENT_COMPAT, 'UTF-8'); |
||||||
| 1285 | |||||||
| 1286 | // At this point, we want to make sure the subject isn't too long. |
||||||
| 1287 | if (Util::strlen($_POST['subject']) > 100) |
||||||
| 1288 | 6 | { |
|||||
| 1289 | $_POST['subject'] = Util::substr($_POST['subject'], 0, 100); |
||||||
| 1290 | 6 | } |
|||||
| 1291 | 6 | ||||||
| 1292 | // Creating a new topic? |
||||||
| 1293 | $newTopic = empty($_REQUEST['msg']) && empty($topic); |
||||||
| 1294 | 2 | ||||||
| 1295 | 2 | // Collect all parameters for the creation or modification of a post. |
|||||
| 1296 | 2 | $msgOptions = [ |
|||||
| 1297 | 2 | 'id' => empty($_REQUEST['msg']) ? 0 : (int) $_REQUEST['msg'], |
|||||
| 1298 | 2 | 'subject' => $_POST['subject'], |
|||||
| 1299 | 2 | 'body' => $_POST['message'], |
|||||
| 1300 | 2 | 'icon' => preg_replace('~[\./\\\\*:"\'<>]~', '', $_POST['icon']), |
|||||
| 1301 | 2 | 'smileys_enabled' => !isset($_POST['ns']), |
|||||
| 1302 | 'approved' => $becomesApproved, |
||||||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||||
| 1303 | 2 | ]; |
|||||
| 1304 | |||||||
| 1305 | 4 | $topicOptions = [ |
|||||
| 1306 | 'id' => empty($topic) ? 0 : $topic, |
||||||
| 1307 | 'board' => $board, |
||||||
| 1308 | 2 | 'lock_mode' => isset($_POST['lock']) ? (int) $_POST['lock'] : null, |
|||||
| 1309 | 'sticky_mode' => isset($_POST['sticky']) ? (int) $_POST['sticky'] : null, |
||||||
| 1310 | 2 | 'mark_as_read' => true, |
|||||
| 1311 | 'is_approved' => !$modSettings['postmod_active'] || empty($topic) || !empty($board_info['cur_topic_approved']), |
||||||
| 1312 | ]; |
||||||
| 1313 | |||||||
| 1314 | $posterOptions = [ |
||||||
| 1315 | 'id' => $this->user->id, |
||||||
| 1316 | 'name' => $_POST['guestname'], |
||||||
| 1317 | 'email' => $_POST['email'], |
||||||
| 1318 | 'update_post_count' => $this->user->is_guest === false && !isset($_REQUEST['msg']) && $board_info['posts_count'], |
||||||
| 1319 | 6 | ]; |
|||||
| 1320 | |||||||
| 1321 | // Trigger the pre_save_post event |
||||||
| 1322 | $this->_events->trigger('pre_save_post', ['msgOptions' => &$msgOptions, 'topicOptions' => &$topicOptions, 'posterOptions' => &$posterOptions]); |
||||||
| 1323 | |||||||
| 1324 | 6 | // This is an already existing message. Edit it. |
|||||
| 1325 | if (!empty($_REQUEST['msg'])) |
||||||
| 1326 | { |
||||||
| 1327 | $posterOptions['id_starter'] = $msgInfo['id_member'] ?? $this->user->id; |
||||||
| 1328 | |||||||
| 1329 | 6 | // Have admins allowed people to hide their screwups? |
|||||
| 1330 | if (time() - $msgInfo['poster_time'] > $modSettings['edit_wait_time'] || $this->user->id != $msgInfo['id_member']) |
||||||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||||
| 1331 | { |
||||||
| 1332 | $msgOptions['modify_time'] = time(); |
||||||
| 1333 | $msgOptions['modify_name'] = $this->user->name; |
||||||
| 1334 | } |
||||||
| 1335 | 6 | ||||||
| 1336 | // This will save some time... |
||||||
| 1337 | if (empty($approve_has_changed)) |
||||||
| 1338 | { |
||||||
| 1339 | 6 | unset($msgOptions['approved']); |
|||||
| 1340 | } |
||||||
| 1341 | |||||||
| 1342 | modifyPost($msgOptions, $topicOptions, $posterOptions); |
||||||
| 1343 | } |
||||||
| 1344 | // This is a new topic or an already existing one. Save it. |
||||||
| 1345 | else |
||||||
| 1346 | 6 | { |
|||||
| 1347 | // We also have to fake the board: |
||||||
| 1348 | 6 | // if it's valid and it's not the current, let's forget about the "current" and load the new one |
|||||
| 1349 | if (!empty($new_board) && $board !== $new_board) |
||||||
| 1350 | { |
||||||
| 1351 | $board = $new_board; |
||||||
| 1352 | loadBoard(); |
||||||
| 1353 | |||||||
| 1354 | // Some details changed |
||||||
| 1355 | $topicOptions['board'] = $board; |
||||||
| 1356 | $topicOptions['is_approved'] = !$modSettings['postmod_active'] || empty($topic) || !empty($board_info['cur_topic_approved']); |
||||||
| 1357 | $posterOptions['update_post_count'] = $this->user->is_guest === false && !isset($_REQUEST['msg']) && $board_info['posts_count']; |
||||||
| 1358 | 2 | } |
|||||
| 1359 | |||||||
| 1360 | createPost($msgOptions, $topicOptions, $posterOptions); |
||||||
| 1361 | 2 | ||||||
| 1362 | $topic = $topicOptions['id']; |
||||||
| 1363 | } |
||||||
| 1364 | |||||||
| 1365 | // Trigger the after_save_post event |
||||||
| 1366 | $this->_events->trigger('after_save_post', ['board' => $board, 'topic' => $topic, 'msgOptions' => $msgOptions, 'topicOptions' => $topicOptions, 'becomesApproved' => $becomesApproved, 'posterOptions' => $posterOptions]); |
||||||
| 1367 | |||||||
| 1368 | // Marking boards as read. |
||||||
| 1369 | // (You just posted and they will be unread.) |
||||||
| 1370 | if ($this->user->is_guest === false) |
||||||
| 1371 | { |
||||||
| 1372 | $board_list = empty($board_info['parent_boards']) ? [] : array_keys($board_info['parent_boards']); |
||||||
| 1373 | |||||||
| 1374 | // Returning to the topic? |
||||||
| 1375 | if (!empty($_REQUEST['goback'])) |
||||||
| 1376 | { |
||||||
| 1377 | $board_list[] = $board; |
||||||
| 1378 | } |
||||||
| 1379 | |||||||
| 1380 | if (!empty($board_list)) |
||||||
| 1381 | 2 | { |
|||||
| 1382 | markBoardsRead($board_list, false, false); |
||||||
| 1383 | } |
||||||
| 1384 | } |
||||||
| 1385 | |||||||
| 1386 | 2 | // Turn notification on or off. |
|||||
| 1387 | if (!empty($_POST['notify']) && allowedTo('mark_any_notify')) |
||||||
| 1388 | { |
||||||
| 1389 | setTopicNotification($this->user->id, $topic, true); |
||||||
| 1390 | } |
||||||
| 1391 | 2 | elseif (!$newTopic) |
|||||
| 1392 | { |
||||||
| 1393 | setTopicNotification($this->user->id, $topic, false); |
||||||
| 1394 | } |
||||||
| 1395 | |||||||
| 1396 | // Log an act of moderation - modifying. |
||||||
| 1397 | if (!empty($moderationAction)) |
||||||
| 1398 | { |
||||||
| 1399 | logAction('modify', ['topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $msgInfo['id_member'], 'board' => $board]); |
||||||
| 1400 | } |
||||||
| 1401 | |||||||
| 1402 | if (isset($_POST['lock']) && $_POST['lock'] != 2) |
||||||
| 1403 | { |
||||||
| 1404 | logAction(empty($_POST['lock']) ? 'unlock' : 'lock', ['topic' => $topicOptions['id'], 'board' => $topicOptions['board']]); |
||||||
| 1405 | } |
||||||
| 1406 | |||||||
| 1407 | 2 | if (isset($_POST['sticky'])) |
|||||
| 1408 | { |
||||||
| 1409 | logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', ['topic' => $topicOptions['id'], 'board' => $topicOptions['board']]); |
||||||
| 1410 | 2 | } |
|||||
| 1411 | |||||||
| 1412 | // Notify any members who have notification turned on for this topic/board - only do this if it's going to be approved(!) |
||||||
| 1413 | if ($becomesApproved) |
||||||
| 1414 | { |
||||||
| 1415 | require_once(SUBSDIR . '/Notification.subs.php'); |
||||||
| 1416 | if ($newTopic) |
||||||
| 1417 | { |
||||||
| 1418 | $notifyData = [ |
||||||
| 1419 | 'body' => $_POST['message'], |
||||||
| 1420 | 'subject' => $_POST['subject'], |
||||||
| 1421 | 'name' => $this->user->name, |
||||||
| 1422 | 'poster' => $this->user->id, |
||||||
| 1423 | 'msg' => $msgOptions['id'], |
||||||
| 1424 | 'board' => $board, |
||||||
| 1425 | 'topic' => $topic, |
||||||
| 1426 | 'signature' => User::$settings->signature(''), |
||||||
| 1427 | ]; |
||||||
| 1428 | sendBoardNotifications($notifyData); |
||||||
| 1429 | } |
||||||
| 1430 | elseif (empty($_REQUEST['msg'])) |
||||||
| 1431 | { |
||||||
| 1432 | // Only send it to everyone if the topic is approved, otherwise just to the topic starter if they want it. |
||||||
| 1433 | if ($topic_info['approved']) |
||||||
| 1434 | { |
||||||
| 1435 | sendNotifications($topic, 'reply'); |
||||||
| 1436 | } |
||||||
| 1437 | else |
||||||
| 1438 | { |
||||||
| 1439 | sendNotifications($topic, 'reply', [], $topic_info['id_member_started']); |
||||||
| 1440 | } |
||||||
| 1441 | } |
||||||
| 1442 | } |
||||||
| 1443 | |||||||
| 1444 | if ($board_info['num_topics'] == 0) |
||||||
| 1445 | { |
||||||
| 1446 | Cache::instance()->remove('board-' . $board); |
||||||
| 1447 | } |
||||||
| 1448 | |||||||
| 1449 | if (!empty($_POST['announce_topic'])) |
||||||
| 1450 | { |
||||||
| 1451 | redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback')); |
||||||
| 1452 | } |
||||||
| 1453 | |||||||
| 1454 | if (!empty($_POST['move']) && allowedTo('move_any')) |
||||||
| 1455 | { |
||||||
| 1456 | redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback')); |
||||||
| 1457 | } |
||||||
| 1458 | |||||||
| 1459 | // Return to post if the mod is on. |
||||||
| 1460 | if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback'])) |
||||||
| 1461 | { |
||||||
| 1462 | redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']); |
||||||
| 1463 | } |
||||||
| 1464 | elseif (!empty($_REQUEST['goback'])) |
||||||
| 1465 | { |
||||||
| 1466 | redirectexit('topic=' . $topic . '.new#new'); |
||||||
| 1467 | } |
||||||
| 1468 | // Dut-dut-duh-duh-DUH-duh-dut-duh-duh! *dances to the Final Fantasy Fanfare...* |
||||||
| 1469 | else |
||||||
| 1470 | { |
||||||
| 1471 | redirectexit('board=' . $board . '.0'); |
||||||
| 1472 | } |
||||||
| 1473 | } |
||||||
| 1474 | |||||||
| 1475 | /** |
||||||
| 1476 | * Toggle a post lock status |
||||||
| 1477 | * |
||||||
| 1478 | * @param int|null $lock |
||||||
| 1479 | * @param string|null $topic_info |
||||||
| 1480 | * |
||||||
| 1481 | * @return int|null |
||||||
| 1482 | */ |
||||||
| 1483 | protected function _checkLocked($lock, $topic_info = null): ?int |
||||||
| 1484 | { |
||||||
| 1485 | // A new topic |
||||||
| 1486 | if ($topic_info === null) |
||||||
| 1487 | { |
||||||
| 1488 | // New topics are by default not locked. |
||||||
| 1489 | if (empty($lock)) |
||||||
| 1490 | { |
||||||
| 1491 | return null; |
||||||
| 1492 | } |
||||||
| 1493 | // Besides, you need permission. |
||||||
| 1494 | if (!allowedTo(['lock_any', 'lock_own'])) |
||||||
| 1495 | { |
||||||
| 1496 | return null; |
||||||
| 1497 | } |
||||||
| 1498 | // A moderator-lock (1) can override a user-lock (2). |
||||||
| 1499 | else |
||||||
| 1500 | { |
||||||
| 1501 | return allowedTo('lock_any') ? 1 : 2; |
||||||
| 1502 | } |
||||||
| 1503 | } |
||||||
| 1504 | // Nothing changes to the lock status. |
||||||
| 1505 | if ((empty($lock) && empty($topic_info['locked'])) || (!empty($lock) && !empty($topic_info['locked']))) |
||||||
| 1506 | { |
||||||
| 1507 | return null; |
||||||
| 1508 | } |
||||||
| 1509 | // You're simply not allowed to (un)lock this. |
||||||
| 1510 | if (!allowedTo(['lock_any', 'lock_own']) || (!allowedTo('lock_any') && $this->user->id != $topic_info['id_member_started'])) |
||||||
|
0 ignored issues
–
show
The property
id does not exist on ElkArte\Helper\ValuesContainer. Since you implemented __get, consider adding a @property annotation.
Loading history...
|
|||||||
| 1511 | { |
||||||
| 1512 | return null; |
||||||
| 1513 | } |
||||||
| 1514 | // You're only allowed to lock your own topics. |
||||||
| 1515 | if (!allowedTo('lock_any')) |
||||||
| 1516 | { |
||||||
| 1517 | // You're not allowed to break a moderator's lock. |
||||||
| 1518 | if ($topic_info['locked'] == 1) |
||||||
| 1519 | { |
||||||
| 1520 | return null; |
||||||
| 1521 | } |
||||||
| 1522 | $lock = empty($lock) ? 0 : 2; |
||||||
| 1523 | } |
||||||
| 1524 | // You must be the moderator. |
||||||
| 1525 | else |
||||||
| 1526 | { |
||||||
| 1527 | $lock = empty($lock) ? 0 : 1; |
||||||
| 1528 | } |
||||||
| 1529 | |||||||
| 1530 | return $lock; |
||||||
| 1531 | } |
||||||
| 1532 | |||||||
| 1533 | /** |
||||||
| 1534 | * Loads a post and inserts it into the current editing text box. |
||||||
| 1535 | * Used to quick edit a post as well as to quote a post and place it in the quick reply box |
||||||
| 1536 | * Can be used to quick edit just the subject from the topic listing |
||||||
| 1537 | * |
||||||
| 1538 | * uses the Post language file. |
||||||
| 1539 | * uses special (sadly browser dependent) javascript to parse entities for internationalization reasons. |
||||||
| 1540 | * accessed with ?action=quotefast and ?action=quotefast;modify |
||||||
| 1541 | */ |
||||||
| 1542 | public function action_quotefast(): void |
||||||
| 1543 | { |
||||||
| 1544 | global $context; |
||||||
| 1545 | |||||||
| 1546 | Txt::load('Post'); |
||||||
| 1547 | |||||||
| 1548 | // Where we going if we need to? |
||||||
| 1549 | $context['post_box_name'] = $_GET['pb'] ?? ''; |
||||||
| 1550 | |||||||
| 1551 | $row = quoteMessageInfo((int) $_REQUEST['quote'], isset($_REQUEST['modify'])); |
||||||
| 1552 | |||||||
| 1553 | $context['sub_template'] = 'quotefast'; |
||||||
| 1554 | if (!empty($row)) |
||||||
| 1555 | { |
||||||
| 1556 | $can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $this->user->id) || allowedTo('approve_posts', $row['id_board']); |
||||||
|
0 ignored issues
–
show
The property
id does not exist on ElkArte\Helper\ValuesContainer. Since you implemented __get, consider adding a @property annotation.
Loading history...
|
|||||||
| 1557 | } |
||||||
| 1558 | |||||||
| 1559 | if (!empty($can_view_post)) |
||||||
| 1560 | { |
||||||
| 1561 | // Remove special formatting we don't want anymore. |
||||||
| 1562 | $row['body'] = $this->preparse->un_preparsecode($row['body']); |
||||||
| 1563 | |||||||
| 1564 | // Censor the message! |
||||||
| 1565 | $row['body'] = censor($row['body']); |
||||||
| 1566 | |||||||
| 1567 | $row['body'] = preg_replace('~<br ?/?>~i', "\n", $row['body']); |
||||||
| 1568 | |||||||
| 1569 | // Want to modify a single message by double clicking it? |
||||||
| 1570 | if (isset($_REQUEST['modify'])) |
||||||
| 1571 | { |
||||||
| 1572 | $row['subject'] = censor($row['subject']); |
||||||
| 1573 | |||||||
| 1574 | $context['sub_template'] = 'modifyfast'; |
||||||
| 1575 | $context['message'] = [ |
||||||
| 1576 | 'id' => $_REQUEST['quote'], |
||||||
| 1577 | 'body' => $row['body'], |
||||||
| 1578 | 'subject' => addcslashes($row['subject'], '"'), |
||||||
| 1579 | ]; |
||||||
| 1580 | |||||||
| 1581 | return; |
||||||
| 1582 | } |
||||||
| 1583 | |||||||
| 1584 | // Remove any nested quotes. |
||||||
| 1585 | $row['body'] = removeNestedQuotes($row['body']); |
||||||
| 1586 | |||||||
| 1587 | // Add a quote string on the front and end. |
||||||
| 1588 | $context['quote']['xml'] = '[quote author=' . $row['poster_name'] . ' link=msg=' . (int) $_REQUEST['quote'] . ' date=' . $row['poster_time'] . "]\n" . $row['body'] . "\n[/quote]"; |
||||||
| 1589 | $context['quote']['text'] = strtr(un_htmlspecialchars($context['quote']['xml']), ["'" => '\\\'', '\\' => '\\\\', "\n" => '\\n', '</script>' => "</' + 'script>"]); |
||||||
| 1590 | $context['quote']['xml'] = strtr($context['quote']['xml'], [' ' => ' ', '<' => '<', '>' => '>']); |
||||||
| 1591 | } |
||||||
| 1592 | //@todo Needs a nicer interface. |
||||||
| 1593 | // In case our message has been removed in the meantime. |
||||||
| 1594 | elseif (isset($_REQUEST['modify'])) |
||||||
| 1595 | { |
||||||
| 1596 | $context['sub_template'] = 'modifyfast'; |
||||||
| 1597 | $context['message'] = [ |
||||||
| 1598 | 'id' => 0, |
||||||
| 1599 | 'body' => '', |
||||||
| 1600 | 'subject' => '', |
||||||
| 1601 | ]; |
||||||
| 1602 | } |
||||||
| 1603 | else |
||||||
| 1604 | { |
||||||
| 1605 | $context['quote'] = [ |
||||||
| 1606 | 'xml' => '', |
||||||
| 1607 | 'text' => '', |
||||||
| 1608 | ]; |
||||||
| 1609 | } |
||||||
| 1610 | } |
||||||
| 1611 | |||||||
| 1612 | /** |
||||||
| 1613 | * Used to edit the body or subject of a message inline |
||||||
| 1614 | * called from action=jsmodify from script and topic js |
||||||
| 1615 | */ |
||||||
| 1616 | public function action_jsmodify(): void |
||||||
| 1617 | { |
||||||
| 1618 | global $modSettings, $board, $topic, $context; |
||||||
| 1619 | |||||||
| 1620 | // We have to have a topic! |
||||||
| 1621 | if (empty($topic)) |
||||||
| 1622 | { |
||||||
| 1623 | obExit(false); |
||||||
| 1624 | } |
||||||
| 1625 | |||||||
| 1626 | checkSession('request'); |
||||||
| 1627 | |||||||
| 1628 | $row = getTopicInfoByMsg($topic, empty($_REQUEST['msg']) ? 0 : (int) $_REQUEST['msg']); |
||||||
| 1629 | |||||||
| 1630 | if (empty($row)) |
||||||
| 1631 | { |
||||||
| 1632 | throw new Exception('no_board', false); |
||||||
| 1633 | } |
||||||
| 1634 | |||||||
| 1635 | // Change either body or subject requires permissions to modify messages. |
||||||
| 1636 | if (isset($_POST['message']) || isset($_POST['subject']) || isset($_REQUEST['icon'])) |
||||||
| 1637 | { |
||||||
| 1638 | if (!empty($row['locked'])) |
||||||
| 1639 | { |
||||||
| 1640 | isAllowedTo('moderate_board'); |
||||||
| 1641 | } |
||||||
| 1642 | |||||||
| 1643 | if ($row['id_member'] == $this->user->id && !allowedTo('modify_any')) |
||||||
| 1644 | { |
||||||
| 1645 | if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) |
||||||
| 1646 | { |
||||||
| 1647 | throw new Exception('modify_post_time_passed', false); |
||||||
| 1648 | } |
||||||
| 1649 | if ($row['id_member_started'] == $this->user->id && !allowedTo('modify_own')) |
||||||
| 1650 | { |
||||||
| 1651 | isAllowedTo('modify_replies'); |
||||||
| 1652 | } |
||||||
| 1653 | else |
||||||
| 1654 | { |
||||||
| 1655 | isAllowedTo('modify_own'); |
||||||
| 1656 | } |
||||||
| 1657 | } |
||||||
| 1658 | elseif ($row['id_member_started'] == $this->user->id && !allowedTo('modify_any')) |
||||||
| 1659 | { |
||||||
| 1660 | isAllowedTo('modify_replies'); |
||||||
| 1661 | } |
||||||
| 1662 | else |
||||||
| 1663 | { |
||||||
| 1664 | isAllowedTo('modify_any'); |
||||||
| 1665 | } |
||||||
| 1666 | |||||||
| 1667 | // Only log this action if it wasn't your message. |
||||||
| 1668 | $moderationAction = $row['id_member'] != $this->user->id; |
||||||
| 1669 | } |
||||||
| 1670 | |||||||
| 1671 | if (isset($_POST['subject']) && Util::htmltrim(Util::htmlspecialchars($_POST['subject'])) !== '') |
||||||
| 1672 | { |
||||||
| 1673 | $_POST['subject'] = strtr(Util::htmlspecialchars($_POST['subject']), ["\r" => '', "\n" => '', "\t" => '']); |
||||||
| 1674 | |||||||
| 1675 | // Maximum number of characters. |
||||||
| 1676 | if (Util::strlen($_POST['subject']) > 100) |
||||||
| 1677 | { |
||||||
| 1678 | $_POST['subject'] = Util::substr($_POST['subject'], 0, 100); |
||||||
| 1679 | } |
||||||
| 1680 | } |
||||||
| 1681 | elseif (isset($_POST['subject'])) |
||||||
| 1682 | { |
||||||
| 1683 | $this->_post_errors->addError('no_subject'); |
||||||
| 1684 | unset($_POST['subject']); |
||||||
| 1685 | } |
||||||
| 1686 | |||||||
| 1687 | if (isset($_POST['message'])) |
||||||
| 1688 | { |
||||||
| 1689 | if (Util::htmltrim(Util::htmlspecialchars($_POST['message'])) === '') |
||||||
| 1690 | { |
||||||
| 1691 | $this->_post_errors->addError('no_message'); |
||||||
| 1692 | unset($_POST['message']); |
||||||
| 1693 | } |
||||||
| 1694 | elseif (!empty($modSettings['max_messageLength']) && Util::strlen($_POST['message']) > $modSettings['max_messageLength']) |
||||||
| 1695 | { |
||||||
| 1696 | $this->_post_errors->addError(['long_message', [$modSettings['max_messageLength']]]); |
||||||
| 1697 | unset($_POST['message']); |
||||||
| 1698 | } |
||||||
| 1699 | else |
||||||
| 1700 | { |
||||||
| 1701 | $_POST['message'] = Util::htmlspecialchars($_POST['message'], ENT_QUOTES, 'UTF-8', true); |
||||||
| 1702 | |||||||
| 1703 | $this->preparse->preparsecode($_POST['message']); |
||||||
| 1704 | $bbc_parser = ParserWrapper::instance(); |
||||||
| 1705 | |||||||
| 1706 | if (Util::htmltrim(strip_tags($bbc_parser->parseMessage($_POST['message'], false), '<img>')) === '') |
||||||
| 1707 | { |
||||||
| 1708 | $this->_post_errors->addError('no_message'); |
||||||
| 1709 | unset($_POST['message']); |
||||||
| 1710 | } |
||||||
| 1711 | } |
||||||
| 1712 | } |
||||||
| 1713 | |||||||
| 1714 | if (isset($_POST['lock'])) |
||||||
| 1715 | { |
||||||
| 1716 | $_POST['lock'] = $this->_checkLocked($_POST['lock'], $row); |
||||||
| 1717 | } |
||||||
| 1718 | |||||||
| 1719 | if (isset($_POST['sticky']) && !allowedTo('make_sticky')) |
||||||
| 1720 | { |
||||||
| 1721 | unset($_POST['sticky']); |
||||||
| 1722 | } |
||||||
| 1723 | |||||||
| 1724 | if (!$this->_post_errors->hasErrors()) |
||||||
| 1725 | { |
||||||
| 1726 | if (!empty($modSettings['mentions_enabled'])) |
||||||
| 1727 | { |
||||||
| 1728 | if (!empty($_REQUEST['uid'])) |
||||||
| 1729 | { |
||||||
| 1730 | $query_params = []; |
||||||
| 1731 | $query_params['member_ids'] = array_unique(array_map('intval', $_REQUEST['uid'])); |
||||||
| 1732 | |||||||
| 1733 | require_once(SUBSDIR . '/Members.subs.php'); |
||||||
| 1734 | $mentioned_members = membersBy('member_ids', $query_params, true); |
||||||
| 1735 | $replacements = 0; |
||||||
| 1736 | $actually_mentioned = []; |
||||||
| 1737 | foreach ($mentioned_members as $member) |
||||||
| 1738 | { |
||||||
| 1739 | $_POST['message'] = str_replace('@' . $member['real_name'], '[member=' . $member['id_member'] . ']' . $member['real_name'] . '[/member]', $_POST['message'], $replacements); |
||||||
| 1740 | if ($replacements > 0) |
||||||
| 1741 | { |
||||||
| 1742 | $actually_mentioned[] = $member['id_member']; |
||||||
| 1743 | } |
||||||
| 1744 | } |
||||||
| 1745 | } |
||||||
| 1746 | |||||||
| 1747 | if (!empty($actually_mentioned)) |
||||||
| 1748 | { |
||||||
| 1749 | $notifier = Notifications::instance(); |
||||||
| 1750 | $notifier->add(new NotificationsTask( |
||||||
| 1751 | 'Mentionmem', |
||||||
| 1752 | $row['id_msg'], |
||||||
| 1753 | $row['id_member'], |
||||||
| 1754 | ['id_members' => $actually_mentioned, 'status' => $row['approved'] ? 'new' : 'unapproved'] |
||||||
| 1755 | )); |
||||||
| 1756 | } |
||||||
| 1757 | } |
||||||
| 1758 | |||||||
| 1759 | $msgOptions = [ |
||||||
| 1760 | 'id' => $row['id_msg'], |
||||||
| 1761 | 'subject' => $_POST['subject'] ?? null, |
||||||
| 1762 | 'body' => $_POST['message'] ?? null, |
||||||
| 1763 | 'icon' => isset($_REQUEST['icon']) ? preg_replace('~[\./\\\\*\':"<>]~', '', $_REQUEST['icon']) : null, |
||||||
| 1764 | ]; |
||||||
| 1765 | |||||||
| 1766 | $topicOptions = [ |
||||||
| 1767 | 'id' => $topic, |
||||||
| 1768 | 'board' => $board, |
||||||
| 1769 | 'lock_mode' => isset($_POST['lock']) ? (int) $_POST['lock'] : null, |
||||||
| 1770 | 'sticky_mode' => isset($_POST['sticky']) ? (int) $_POST['sticky'] : null, |
||||||
| 1771 | 'mark_as_read' => false, |
||||||
| 1772 | ]; |
||||||
| 1773 | |||||||
| 1774 | $posterOptions = []; |
||||||
| 1775 | |||||||
| 1776 | // Only consider marking as editing if they have edited the subject, message or icon. |
||||||
| 1777 | if ((isset($_POST['subject']) && $_POST['subject'] !== $row['subject']) || (isset($_POST['message']) && $_POST['message'] !== $row['body']) || (isset($_REQUEST['icon']) && $_REQUEST['icon'] !== $row['icon'])) |
||||||
| 1778 | { |
||||||
| 1779 | // And even then only if the time has passed... |
||||||
| 1780 | if (time() - $row['poster_time'] > $modSettings['edit_wait_time'] || $this->user->id != $row['id_member']) |
||||||
| 1781 | { |
||||||
| 1782 | $msgOptions['modify_time'] = time(); |
||||||
| 1783 | $msgOptions['modify_name'] = $this->user->name; |
||||||
| 1784 | } |
||||||
| 1785 | } |
||||||
| 1786 | // If nothing was changed there's no need to add an entry to the moderation log. |
||||||
| 1787 | else |
||||||
| 1788 | { |
||||||
| 1789 | $moderationAction = false; |
||||||
| 1790 | } |
||||||
| 1791 | |||||||
| 1792 | modifyPost($msgOptions, $topicOptions, $posterOptions); |
||||||
| 1793 | |||||||
| 1794 | // If we didn't change anything this time but had before put back the old info. |
||||||
| 1795 | if (!isset($msgOptions['modify_time']) && !empty($row['modified_time'])) |
||||||
| 1796 | { |
||||||
| 1797 | $msgOptions['modify_time'] = $row['modified_time']; |
||||||
| 1798 | $msgOptions['modify_name'] = $row['modified_name']; |
||||||
| 1799 | } |
||||||
| 1800 | |||||||
| 1801 | // Changing the first subject updates other subjects to 'Re: new_subject'. |
||||||
| 1802 | if (isset($_POST['subject'], $_REQUEST['change_all_subjects']) && $row['id_first_msg'] == $row['id_msg'] && !empty($row['num_replies']) && (allowedTo('modify_any') || ($row['id_member_started'] == $this->user->id && allowedTo('modify_replies')))) |
||||||
| 1803 | { |
||||||
| 1804 | // Get the proper (default language) response prefix first. |
||||||
| 1805 | $context['response_prefix'] = response_prefix(); |
||||||
| 1806 | |||||||
| 1807 | topicSubject(['id_topic' => $topic, 'id_first_msg' => $row['id_first_msg']], $_POST['subject'], $context['response_prefix'], true); |
||||||
| 1808 | } |
||||||
| 1809 | |||||||
| 1810 | if (!empty($moderationAction)) |
||||||
| 1811 | { |
||||||
| 1812 | logAction('modify', ['topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board]); |
||||||
| 1813 | } |
||||||
| 1814 | } |
||||||
| 1815 | |||||||
| 1816 | if ($this->getApi() === 'xml') |
||||||
| 1817 | { |
||||||
| 1818 | $bbc_parser = ParserWrapper::instance(); |
||||||
| 1819 | |||||||
| 1820 | theme()->getTemplates()->load('Xml'); |
||||||
| 1821 | theme()->getLayers()->removeAll(); |
||||||
| 1822 | $context['sub_template'] = 'modifydone'; |
||||||
| 1823 | |||||||
| 1824 | if (isset($msgOptions['subject'], $msgOptions['body']) && !$this->_post_errors->hasErrors()) |
||||||
| 1825 | { |
||||||
| 1826 | $context['message'] = [ |
||||||
| 1827 | 'id' => $row['id_msg'], |
||||||
| 1828 | 'modified' => [ |
||||||
| 1829 | 'time' => isset($msgOptions['modify_time']) ? standardTime($msgOptions['modify_time']) : '', |
||||||
| 1830 | 'html_time' => isset($msgOptions['modify_time']) ? htmlTime($msgOptions['modify_time']) : '', |
||||||
| 1831 | 'timestamp' => isset($msgOptions['modify_time']) ? forum_time(true, $msgOptions['modify_time']) : 0, |
||||||
| 1832 | 'name' => isset($msgOptions['modify_time']) ? $msgOptions['modify_name'] : '', |
||||||
| 1833 | ], |
||||||
| 1834 | 'subject' => $msgOptions['subject'], |
||||||
| 1835 | 'first_in_topic' => $row['id_msg'] == $row['id_first_msg'], |
||||||
| 1836 | 'body' => strtr($msgOptions['body'], [']]>' => ']]]]><![CDATA[>']), |
||||||
| 1837 | ]; |
||||||
| 1838 | |||||||
| 1839 | $context['message']['subject'] = censor($context['message']['subject']); |
||||||
| 1840 | $context['message']['body'] = censor($context['message']['body']); |
||||||
| 1841 | |||||||
| 1842 | $context['message']['body'] = $bbc_parser->parseMessage($context['message']['body'], $row['smileys_enabled']); |
||||||
| 1843 | } |
||||||
| 1844 | // Topic? |
||||||
| 1845 | elseif (!$this->_post_errors->hasErrors()) |
||||||
| 1846 | { |
||||||
| 1847 | $context['sub_template'] = 'modifytopicdone'; |
||||||
| 1848 | $context['message'] = [ |
||||||
| 1849 | 'id' => $row['id_msg'], |
||||||
| 1850 | 'modified' => [ |
||||||
| 1851 | 'time' => isset($msgOptions['modify_time']) ? standardTime($msgOptions['modify_time']) : '', |
||||||
| 1852 | 'html_time' => isset($msgOptions['modify_time']) ? htmlTime($msgOptions['modify_time']) : '', |
||||||
| 1853 | 'timestamp' => isset($msgOptions['modify_time']) ? forum_time(true, $msgOptions['modify_time']) : 0, |
||||||
| 1854 | 'name' => isset($msgOptions['modify_time']) ? $msgOptions['modify_name'] : '', |
||||||
| 1855 | ], |
||||||
| 1856 | 'subject' => $msgOptions['subject'] ?? '', |
||||||
| 1857 | ]; |
||||||
| 1858 | |||||||
| 1859 | $context['message']['subject'] = censor($context['message']['subject']); |
||||||
| 1860 | } |
||||||
| 1861 | else |
||||||
| 1862 | { |
||||||
| 1863 | $context['message'] = [ |
||||||
| 1864 | 'id' => $row['id_msg'], |
||||||
| 1865 | 'errors' => [], |
||||||
| 1866 | 'error_in_subject' => $this->_post_errors->hasError('no_subject'), |
||||||
| 1867 | 'error_in_body' => $this->_post_errors->hasError('no_message') || $this->_post_errors->hasError('long_message'), |
||||||
| 1868 | ]; |
||||||
| 1869 | $context['message']['errors'] = $this->_post_errors->prepareErrors(); |
||||||
| 1870 | } |
||||||
| 1871 | } |
||||||
| 1872 | else |
||||||
| 1873 | { |
||||||
| 1874 | obExit(false); |
||||||
| 1875 | } |
||||||
| 1876 | } |
||||||
| 1877 | } |
||||||
| 1878 |