Issues (1369)

classes/Pages/Deprecated/PageMessage.php (25 issues)

1
<?php /** @noinspection PhpDeprecationInspection */
2
/** @noinspection SqlIdentifier */
3
/** @noinspection SqlRedundantOrderingDirection */
4
/** @noinspection SqlResolve */
5
6
/**
7
 * Created by Gorlum 08.10.2017 17:14
8
 */
9
10
namespace Pages\Deprecated;
11
12
use DBAL\db_mysql;
13
use \SN;
0 ignored issues
show
The type \SN was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use \classLocale;
0 ignored issues
show
The type \classLocale was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use DBAL\DbSqlPaging;
16
use Fleet\MissionEspionageReport;
17
use General\Helpers\PagingRenderer;
18
use Pm\DecodeEspionage;
19
use SnTemplate;
20
use \template;
0 ignored issues
show
The type \template was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
22
/**
23
 * Class PageMessage
24
 * @package Deprecated
25
 *
26
 * Refactor of /messages.php
27
 */
28
class PageMessage extends PageDeprecated {
29
  /**
30
   * List messages amount per category
31
   */
32
  const MESSAGES_MODE_CATEGORIES = '';
33
  /**
34
   * Delete message(s)
35
   */
36
  const MESSAGES_MODE_DELETE = 'delete';
37
  /**
38
   * Write personal message
39
   */
40
  const MESSAGES_MODE_COMPOSE = 'write';
41
  /**
42
   * Show messages in category
43
   */
44
  const MESSAGES_MODE_MESSAGES = 'show';
45
46
  const MESSAGES_DELETE_RANGE_NONE = '';
47
//  const MESSAGES_DELETE_RANGE_UNCHECKED = 'unchecked';
48
  const MESSAGES_DELETE_RANGE_CHECKED = 'checked';
49
  const MESSAGES_DELETE_RANGE_CLASS = 'class';
50
  const MESSAGES_DELETE_RANGE_ALL = 'all';
51
52
  const MESSAGES_DELETE_RANGES_ALLOWED = [
53
//    self::MESSAGES_DELETE_RANGE_UNCHECKED,
54
    self::MESSAGES_DELETE_RANGE_CHECKED,
55
    self::MESSAGES_DELETE_RANGE_CLASS,
56
    self::MESSAGES_DELETE_RANGE_ALL,
57
  ];
58
59
  /**
60
   * @var array[] $messageClassList - [int => ['name' => string, 'switchable' => bool, 'email' => bool]]
61
   */
62
  protected $messageClassList = [];
63
64
  /**
65
   * @var classLocale $lang
66
   */
67
  protected $lang;
68
69
  /**
70
   * Current page mode
71
   *
72
   * @var $mode
0 ignored issues
show
Documentation Bug introduced by
The doc comment $mode at position 0 could not be parsed: Unknown type name '$mode' at position 0 in $mode.
Loading history...
73
   * // TODO - change type to INT when finish
74
   */
75
  protected $mode;
76
77
  /**
78
   * @var int $current_class
79
   */
80
  protected $current_class;
81
82
  /**
83
   * @var string $recipient_name_unsafe
84
   */
85
  // TODO - UNSAFE USAGES!
86
  protected $recipient_name_unsafe = '';
87
88
  /**
89
   * @var int|string $recipient_id_unsafe
90
   */
91
  protected $recipient_id_unsafe = 0;
92
93
  protected $showAll = false;
94
95
  /**
96
   * @var string $subject_unsafe
97
   */
98
  protected $subject_unsafe = '';
99
100
  /**
101
   * Text to send
102
   *
103
   * @var string $sendText_unsafe
104
   */
105
  protected $sendText_unsafe = '';
106
107
  /**
108
   * Reference to current PLAYER DB record
109
   *
110
   * @var array $user
111
   */
112
  protected $user;
113
114
  /**
115
   * @var int|string
116
   */
117
  protected $playerId = 0;
118
119
  /**
120
   * @var mixed $doSend
121
   */
122
  protected $doSend = false;
123
124
  /**
125
   * @var string $deleteRange
126
   */
127
  protected $deleteRange = '';
128
129
  /**
130
   * @var db_mysql $db
131
   */
132
  protected $db;
133
134
  /**
135
   * @var array
136
   */
137
  protected $markedMessageIdList = [];
138
139
140
  /**
141
   * PageMessage constructor.
142
   */
143
  public function __construct() {
144
    parent::__construct();
145
146
    global $sn_message_class_list;
147
148
    $this->lang = SN::$lang;
149
    $this->messageClassList = $sn_message_class_list;
150
151
    $this->db = SN::$gc->db;
152
153
    $this->loadParams();
154
  }
155
156
  public function route() {
157
    $this->getUserRef();
158
159
    $template = null;
160
161
    switch ($this->mode) {
162
      case static::MESSAGES_MODE_COMPOSE:
163
        $this->modelCompose();
164
        $template = $this->viewCompose();
165
      break;
166
167
      /** @noinspection PhpMissingBreakStatementInspection */
168
      case static::MESSAGES_MODE_DELETE:
169
        $this->modelDelete();
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment if this fall-through is intended.
Loading history...
170
171
      case static::MESSAGES_MODE_MESSAGES:
172
        if (sys_get_param_int('return')) {
173
          sys_redirect('messages.php');
174
        }
175
176
        $template = $this->viewMessageList();
177
      break;
178
179
      default:
180
        $template = $this->viewCategories();
181
      break;
182
    }
183
184
    SnTemplate::display($template, $this->lang['msg_page_header']);
185
  }
186
187
  protected function modelCompose() {
188
    $this->getRecipientData();
189
190
    if ($this->recipient_id_unsafe == $this->playerId) {
191
      $this->resultAdd($this->lang['msg_err_self_send'], ERR_ERROR);
192
    }
193
194
    if ($this->doSend) {
195
      if (empty($this->recipient_id_unsafe)) {
196
        $this->resultAdd($this->lang['msg_err_player_not_found'], ERR_ERROR);
197
      }
198
199
      if (!$this->sendText_unsafe) {
200
        $this->resultAdd($this->lang['msg_err_no_text'], ERR_ERROR);
201
      }
202
203
      if (!$this->resultCount()) {
204
        $this->wrapSendPm();
205
206
        $this->sendText_unsafe = '';
207
208
        $this->resultAdd($this->lang['msg_not_message_sent'], ERR_NONE);
209
      }
210
    }
211
  }
212
213
  /**
214
   * @return template
215
   */
216
  protected function viewCompose() {
217
    $template = SnTemplate::gettemplate('msg_message_compose', true);
0 ignored issues
show
true of type true is incompatible with the type null|template expected by parameter $template of SnTemplate::gettemplate(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

217
    $template = SnTemplate::gettemplate('msg_message_compose', /** @scrutinizer ignore-type */ true);
Loading history...
218
    $template->assign_vars([
219
      'RECIPIENT_ID'   => $this->recipient_id_unsafe,
220
      'RECIPIENT_NAME' => htmlspecialchars($this->recipient_name_unsafe),
221
      'SUBJECT'        => htmlspecialchars($this->subject_unsafe),
222
      'TEXT'           => htmlspecialchars($this->sendText_unsafe),
223
    ]);
224
225
    $this->resultTemplatize($template);
226
227
    $recipientIdSafe = SN::$db->db_escape($this->recipient_id_unsafe);
228
    $message_query = doquery(
0 ignored issues
show
Deprecated Code introduced by
The function doquery() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

228
    $message_query = /** @scrutinizer ignore-deprecated */ doquery(
Loading history...
229
      "SELECT * FROM {{messages}}
230
        WHERE
231
          `message_type` = '" . MSG_TYPE_PLAYER . "' AND
232
          ((`message_owner` = '{$this->playerId}' AND `message_sender` = '{$recipientIdSafe}')
233
          OR
234
          (`message_sender` = '{$this->playerId}' AND `message_owner` = '{$recipientIdSafe}')) 
235
        ORDER BY `message_time` DESC LIMIT 20;");
236
    while ($message_row = db_fetch($message_query)) {
0 ignored issues
show
Deprecated Code introduced by
The function db_fetch() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

236
    while ($message_row = /** @scrutinizer ignore-deprecated */ db_fetch($message_query)) {
Loading history...
237
      $template->assign_block_vars('messages', array(
238
        'ID'   => $message_row['message_id'],
239
        'DATE' => date(FMT_DATE_TIME, $message_row['message_time'] + SN_CLIENT_TIME_DIFF),
240
        'FROM' => htmlspecialchars($message_row['message_from']),
241
        'SUBJ' => htmlspecialchars($message_row['message_subject']),
242
        'TEXT' => in_array($message_row['message_type'], array(MSG_TYPE_PLAYER, MSG_TYPE_ALLIANCE)) && $message_row['message_sender'] ? nl2br(htmlspecialchars($message_row['message_text'])) : nl2br($message_row['message_text']),
243
244
        'FROM_ID' => $message_row['message_sender'],
245
//        'SUBJ_SANITIZED' => htmlspecialchars($message_row['message_subject']),
246
      ));
247
    }
248
249
    return $template;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $template returns the type template which is incompatible with the documented return type \template.
Loading history...
250
  }
251
252
253
  protected function modelDelete() {
254
    // No range specified - nothing to do
255
    if ($this->deleteRange == static::MESSAGES_DELETE_RANGE_NONE) {
256
      return;
257
    }
258
    // Сurrent range is CHECKED and NO messages marked - nothing to do
259
    if ($this->deleteRange == static::MESSAGES_DELETE_RANGE_CHECKED && empty($this->markedMessageIdList)) {
260
      return;
261
    }
262
263
    $query_add = '';
264
265
    switch ($this->deleteRange) {
266
//      case static::MESSAGES_DELETE_RANGE_UNCHECKED:
267
      /** @noinspection PhpMissingBreakStatementInspection */
268
      case static::MESSAGES_DELETE_RANGE_CHECKED:
269
        $query_add = implode(',', $this->markedMessageIdList);
270
        if ($query_add) {
271
          $query_add = "IN ({$query_add})";
272
//          if ($this->deleteRange == static::MESSAGES_DELETE_RANGE_UNCHECKED) {
273
//            $query_add = "NOT {$query_add}";
274
//          }
275
          $query_add = " AND `message_id` {$query_add}";
276
        }
277
278
      /** @noinspection PhpMissingBreakStatementInspection */
279
      case static::MESSAGES_DELETE_RANGE_CLASS:
280
        if ($this->current_class != MSG_TYPE_OUTBOX && $this->current_class != MSG_TYPE_NEW) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment if this fall-through is intended.
Loading history...
281
          $query_add .= " AND `message_type` = {$this->current_class}";
282
        }
283
      case static::MESSAGES_DELETE_RANGE_ALL:
284
        $query_add = $query_add ? $query_add : true;
285
      break;
286
    }
287
288
    if ($this->deleteRange && $query_add) {
289
      $query_add = $query_add === true ? '' : $query_add;
290
      doquery("DELETE FROM `{{messages}}` WHERE `message_owner` = '{$this->playerId}'{$query_add};");
0 ignored issues
show
Deprecated Code introduced by
The function doquery() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

290
      /** @scrutinizer ignore-deprecated */ doquery("DELETE FROM `{{messages}}` WHERE `message_owner` = '{$this->playerId}'{$query_add};");
Loading history...
291
    }
292
  }
293
294
  /**
295
   * @return template
296
   */
297
  protected function viewMessageList() {
298
    require_once('includes/includes/coe_simulator_helpers.php');
299
300
    $pager = null;
301
302
    if ($this->current_class == MSG_TYPE_OUTBOX) {
303
      $message_query = "SELECT {{messages}}.message_id, {{messages}}.message_owner, {{users}}.id AS message_sender, {{messages}}.message_time,
304
          {{messages}}.message_type, {{users}}.username AS message_from, {{messages}}.message_subject, {{messages}}.message_text
305
       FROM
306
         {{messages}} LEFT JOIN {{users}} ON {{users}}.id = {{messages}}.message_owner WHERE `message_sender` = '{$this->playerId}' AND `message_type` = 1
307
       ORDER BY `message_time` DESC;";
308
    } else {
309
      if ($this->current_class == MSG_TYPE_NEW) {
310
        $SubUpdateQry = array();
311
        foreach ($this->messageClassList as $message_class_id => $message_class) {
312
          if ($message_class_id != MSG_TYPE_OUTBOX) {
313
            $SubUpdateQry[] = "`{$message_class['name']}` = '0'";
314
            $this->user[$message_class['name']] = 0;
315
          }
316
        }
317
        $SubUpdateQry = implode(',', $SubUpdateQry);
318
        $SubSelectQry = '';
319
      } else {
320
        $messageClassNameNew = $this->messageClassList[MSG_TYPE_NEW]['name'];
321
        $messageClassNameCurrent = $this->messageClassList[$this->current_class]['name'];
322
        $SubUpdateQry = "`{$messageClassNameCurrent}` = '0', `{$messageClassNameNew}` = `{$messageClassNameNew}` - '{$this->user[$messageClassNameCurrent]}'";
323
        $SubSelectQry = "AND `message_type` = '{$this->current_class}'";
324
325
        $this->user[$messageClassNameNew] -= $this->user[$messageClassNameCurrent];
326
        $this->user[$messageClassNameCurrent] = 0;
327
      }
328
329
      db_user_set_by_id($this->playerId, $SubUpdateQry);
0 ignored issues
show
Deprecated Code introduced by
The function db_user_set_by_id() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

329
      /** @scrutinizer ignore-deprecated */ db_user_set_by_id($this->playerId, $SubUpdateQry);
Loading history...
330
      $message_query =
331
        "SELECT m.*, sender.authlevel as sender_auth 
332
        FROM `{{messages}}` as m 
333
          LEFT JOIN `{{users}}` as sender on sender.id = m.message_sender
334
        WHERE m.`message_owner` = '{$this->playerId}' {$SubSelectQry} 
335
        ORDER BY m.`message_time` DESC;";
336
    }
337
338
    if ($this->showAll) {
339
      $message_query = $this->db->selectIterator($message_query);
340
    } else {
341
      $message_query = new DbSqlPaging($message_query, PAGING_PAGE_SIZE_DEFAULT_MESSAGES, sys_get_param_int(PagingRenderer::KEYWORD));
342
      $pager = new PagingRenderer($message_query, 'messages.php?mode=show&message_class=' . $this->current_class);
343
    }
344
345
    $wasIgnored = 0;
346
    $template = SnTemplate::gettemplate('msg_message_list', true);
0 ignored issues
show
true of type true is incompatible with the type null|template expected by parameter $template of SnTemplate::gettemplate(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

346
    $template = SnTemplate::gettemplate('msg_message_list', /** @scrutinizer ignore-type */ true);
Loading history...
347
    foreach ($message_query as $message_row) {
348
      if(
349
        $message_row['message_type'] == MSG_TYPE_PLAYER
350
        &&
351
        SN::$gc->ignores->isIgnored(floatval($message_row['message_owner']), floatval($message_row['message_sender']))
352
      ) {
353
        $wasIgnored++;
354
        continue;
355
      }
356
357
      $text = $message_row['message_text'];
358
      if ($message_row['message_json']) {
359
        switch ($message_row['message_type']) {
360
          case MSG_TYPE_SPY:
361
            $text = DecodeEspionage::decode(MissionEspionageReport::fromJson($text));
362
          break;
363
          default:
364
            $text = '{ Unauthorised access - please contact Administration! }';
365
          break;
366
367
        }
368
      } else {
369
        if (in_array($message_row['message_type'], [MSG_TYPE_PLAYER, MSG_TYPE_ALLIANCE]) && $message_row['message_sender']) {
370
          if ($message_row['sender_auth'] >= AUTH_LEVEL_ADMINISTRATOR) {
371
            $text = SN::$gc->bbCodeParser->expandBbCode($message_row['message_text'], intval($message_row['sender_auth']), HTML_ENCODE_NONE);
372
          } else {
373
            $text = htmlspecialchars($message_row['message_text']);
374
          }
375
        }
376
        $text = nl2br($text);
377
      }
378
379
      $template->assign_block_vars('messages', array(
380
        'ID'   => $message_row['message_id'],
381
        'DATE' => date(FMT_DATE_TIME, $message_row['message_time'] + SN_CLIENT_TIME_DIFF),
382
        'FROM' => htmlspecialchars($message_row['message_from']),
383
        'SUBJ' => htmlspecialchars($message_row['message_subject']),
384
        'TEXT' => $text,
385
386
        'CAN_IGNORE' => $message_row['message_type'] == MSG_TYPE_PLAYER,
387
388
        'FROM_ID'        => $message_row['message_sender'],
389
        'SUBJ_SANITIZED' => htmlspecialchars($message_row['message_subject']),
390
        'STYLE'          => $this->current_class == MSG_TYPE_OUTBOX ? $this->messageClassList[MSG_TYPE_OUTBOX]['name'] : $this->messageClassList[$message_row['message_type']]['name'],
391
      ));
392
    }
393
394
    $current_class_text = $this->lang['msg_class'][$this->current_class];
395
396
    $template->assign_vars(array(
397
      "MESSAGE_CLASS"      => $this->current_class,
398
      "MESSAGE_CLASS_TEXT" => $current_class_text,
399
      "PAGER_MESSAGES"     => $pager ? $pager->render() : '',
400
      "MESSAGES_IGNORED"   => $wasIgnored,
401
    ));
402
403
    return $template;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $template returns the type template which is incompatible with the documented return type \template.
Loading history...
404
  }
405
406
  /**
407
   * @return template
408
   */
409
  protected function viewCategories() {
410
    $messages_total = [];
411
412
    $query = doquery(
0 ignored issues
show
Deprecated Code introduced by
The function doquery() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

412
    $query = /** @scrutinizer ignore-deprecated */ doquery(
Loading history...
413
      "SELECT `message_owner`, `message_type`, COUNT(`message_id`) AS `message_count` 
414
         FROM `{{messages}}` 
415
         WHERE `message_owner` = {$this->playerId} 
416
         GROUP BY `message_owner`, `message_type` 
417
         ORDER BY `message_owner` ASC, `message_type`;"
418
    );
419
    while ($message_row = db_fetch($query)) {
0 ignored issues
show
Deprecated Code introduced by
The function db_fetch() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

419
    while ($message_row = /** @scrutinizer ignore-deprecated */ db_fetch($query)) {
Loading history...
420
      $messages_total[$message_row['message_type']] = $message_row['message_count'];
421
      $messages_total[MSG_TYPE_NEW] += $message_row['message_count'];
422
    }
423
424
    $query = doquery(
0 ignored issues
show
Deprecated Code introduced by
The function doquery() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

424
    $query = /** @scrutinizer ignore-deprecated */ doquery(
Loading history...
425
      "SELECT COUNT(`message_id`) AS message_count 
426
         FROM `{{messages}}` 
427
         WHERE `message_sender` = {$this->playerId} AND `message_type` = " . MSG_TYPE_PLAYER .
428
      " GROUP BY `message_sender`;",
429
      '',
430
      true
431
    );
432
    $messages_total[MSG_TYPE_OUTBOX] = intval($query['message_count']);
433
434
    $template = SnTemplate::gettemplate('msg_message_class', true);
0 ignored issues
show
true of type true is incompatible with the type null|template expected by parameter $template of SnTemplate::gettemplate(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

434
    $template = SnTemplate::gettemplate('msg_message_class', /** @scrutinizer ignore-type */ true);
Loading history...
435
    foreach ($this->messageClassList as $message_class_id => $message_class) {
436
      $template->assign_block_vars('message_class', array(
437
        'ID'     => $message_class_id,
438
        'STYLE'  => $message_class['name'],
439
        'TEXT'   => $this->lang['msg_class'][$message_class_id],
440
        'UNREAD' => $this->user[$message_class['name']],
441
        'TOTAL'  => intval($messages_total[$message_class_id]),
442
      ));
443
    }
444
445
    $template->assign_vars(array(
446
      'PAGE_HINT' => $this->lang['msg_page_hint_class'],
447
    ));
448
449
    return $template;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $template returns the type template which is incompatible with the documented return type \template.
Loading history...
450
  }
451
452
453
  protected function getRecipientData() {
454
    if (!empty($this->recipient_name_unsafe)) {
455
      $recipient_row = db_user_by_username($this->recipient_name_unsafe);
0 ignored issues
show
Deprecated Code introduced by
The function db_user_by_username() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

455
      $recipient_row = /** @scrutinizer ignore-deprecated */ db_user_by_username($this->recipient_name_unsafe);
Loading history...
Are you sure the assignment to $recipient_row is correct as db_user_by_username($this->recipient_name_unsafe) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
456
    }
457
458
    if (empty($recipient_row) && !empty($this->recipient_id_unsafe)) {
459
      $recipient_row = db_user_by_id($this->recipient_id_unsafe);
0 ignored issues
show
Deprecated Code introduced by
The function db_user_by_id() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

459
      $recipient_row = /** @scrutinizer ignore-deprecated */ db_user_by_id($this->recipient_id_unsafe);
Loading history...
It seems like $this->recipient_id_unsafe can also be of type string; however, parameter $user_id_unsafe of db_user_by_id() does only seem to accept integer, 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 ignore-type  annotation

459
      $recipient_row = db_user_by_id(/** @scrutinizer ignore-type */ $this->recipient_id_unsafe);
Loading history...
460
    }
461
462
    if (is_array($recipient_row) && !empty($recipient_row)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $recipient_row does not seem to be defined for all execution paths leading up to this point.
Loading history...
463
      $this->recipient_id_unsafe = $recipient_row['id'];
464
      $this->recipient_name_unsafe = $recipient_row['username'];
465
    } else {
466
      $this->recipient_id_unsafe = 0;
467
      $this->recipient_name_unsafe = '';
468
    }
469
  }
470
471
  protected function getUserRef() {
472
    global $user;
473
474
    $this->user = &$user;
475
    $this->playerId = idval($user['id']);
476
  }
477
478
  /**
479
   * Working on subject
480
   */
481
  protected function transformSubject() {
482
    $re = 0;
483
    // Removing extra Re:Re:Re:... from subject start
484
    if ($this->subject_unsafe) {
485
      $reLength = strlen($this->lang['msg_answer_prefix']);
486
      while (strpos($this->subject_unsafe, $this->lang['msg_answer_prefix']) === 0) {
487
        $this->subject_unsafe = trim(substr($this->subject_unsafe, $reLength));
488
        $re++;
489
      }
490
    }
491
492
    if ($this->subject_unsafe) {
493
      $re ? $this->subject_unsafe = $this->lang['msg_answer_prefix'] . $this->subject_unsafe : false;
494
    } else {
495
      $this->subject_unsafe = $this->lang['msg_subject_default'];
496
    }
497
  }
498
499
  protected function loadParams() {
500
    parent::loadParams();
501
502
    $this->current_class = sys_get_param_int('message_class');
503
    if (!isset($this->messageClassList[$this->current_class])) {
504
      $this->current_class = 0;
505
      $this->mode = static::MESSAGES_MODE_CATEGORIES;
506
    } else {
507
      $this->mode = sys_get_param_str('msg_delete') ? static::MESSAGES_MODE_DELETE : sys_get_param_str('mode');
508
    }
509
510
    if ($this->showAll = sys_get_param_str('msg_show_all') ? true : false) {
511
      $this->mode = static::MESSAGES_MODE_MESSAGES;
512
    }
513
514
    $this->loadParamsCompose();
515
    $this->loadParamsDelete();
516
  }
517
518
  protected function loadParamsCompose() {
519
    $this->recipient_name_unsafe = sys_get_param_str_unsafe('recipient_name');
520
    $this->recipient_id_unsafe = sys_get_param_id('id');
521
    // Removing starting and trailing blank chars
522
    $this->subject_unsafe = trim(sys_get_param_str_unsafe('subject'));
523
    $this->transformSubject();
524
    $this->sendText_unsafe = sys_get_param_str_unsafe('text');
525
    $this->doSend = sys_get_param_str('msg_send');
526
  }
527
528
  protected function loadParamsDelete() {
529
    $this->deleteRange = sys_get_param_str('message_range', static::MESSAGES_DELETE_RANGE_NONE);
530
    // Incorrect range - do nothing
531
    if (!in_array($this->deleteRange, static::MESSAGES_DELETE_RANGES_ALLOWED)) {
532
      return;
533
    }
534
535
    $this->markedMessageIdList = [];
536
    $unsafeMarkList = sys_get_param('mark', []);
0 ignored issues
show
array() of type array is incompatible with the type string expected by parameter $default of sys_get_param(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

536
    $unsafeMarkList = sys_get_param('mark', /** @scrutinizer ignore-type */ []);
Loading history...
537
538
    foreach ($unsafeMarkList as $unsafeMark) {
539
      if (!empty($unsafeMark = idval($unsafeMark))) {
540
        $this->markedMessageIdList[] = $unsafeMark;
541
      }
542
    }
543
  }
544
545
  protected function wrapSendPm() {
546
    msg_send_simple_message(
547
      $this->recipient_id_unsafe,
548
      $this->playerId,
549
      SN_TIME_NOW,
550
      MSG_TYPE_PLAYER,
551
      "{$this->user['username']} [{$this->user['galaxy']}:{$this->user['system']}:{$this->user['planet']}]",
552
      $this->subject_unsafe,
553
      $this->sendText_unsafe,
554
      STRING_NEED_ESCAPING
555
    );
556
  }
557
558
}
559