Test Failed
Branch trunk (d809b8)
by SuperNova.WS
05:48
created

announce.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * announce.php
5
 *
6
 * @copyright (c) 2010-2016 Gorlum for http://supernova.ws
7
 */
8
9
$allow_anonymous = true;
10
include('common.' . substr(strrchr(__FILE__, '.'), 1));
11
12
global $config;
13
14
nws_mark_read($user);
15
$template = gettemplate('announce', true);
0 ignored issues
show
true is of type boolean, but the function expects a object<template>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
16
17
$announce_id = sys_get_param_id('id');
18
$text = sys_get_param_str('text');
19
$announce_time = sys_get_param_str('dtDateTime');
20
$detail_url = sys_get_param_str('detail_url');
21
$mode = sys_get_param_str('mode');
22
23
$announce = array();
24
if ($user['authlevel'] >= 3) {
25
  if (!empty($text)) {
26
    $announce_time = strtotime($announce_time, SN_TIME_NOW);
27
    $announce_time = $announce_time ? $announce_time : SN_TIME_NOW;
28
29
    if ($mode == 'edit') {
30
      doquery("UPDATE {{announce}} SET `tsTimeStamp` = FROM_UNIXTIME({$announce_time}), `strAnnounce`='{$text}', detail_url = '{$detail_url}' WHERE `idAnnounce`={$announce_id};");
31
      doquery("DELETE FROM {{survey}} WHERE `survey_announce_id` = {$announce_id};");
32
    } else {
33
      doquery("INSERT INTO {{announce}}
34
        SET `tsTimeStamp` = FROM_UNIXTIME({$announce_time}), `strAnnounce`='{$text}', detail_url = '{$detail_url}',
35
        `user_id` = {$user['id']}, `user_name` = '" . db_escape($user['username']) . "'");
36
      $announce_id = db_insert_id();
37
    }
38
    if (($survey_question = sys_get_param_str('survey_question')) && ($survey_answers = sys_get_param('survey_answers'))) {
39
      $survey_answers = explode("\r\n", $survey_answers);
40
      $survey_until = strtotime($survey_until = sys_get_param_str('survey_until'), SN_TIME_NOW);
41
      $survey_until = date(FMT_DATE_TIME_SQL, $survey_until ? $survey_until : SN_TIME_NOW + PERIOD_DAY * 1);
42
      doquery("INSERT INTO {{survey}} SET `survey_announce_id` = {$announce_id}, `survey_question` = '{$survey_question}', `survey_until` = '{$survey_until}'");
43
      $survey_id = db_insert_id();
44
      foreach ($survey_answers as $survey_answer) {
45
        $survey_answer = db_escape(trim($survey_answer));
46
        $survey_answer ? doquery("INSERT INTO {{survey_answers}} SET `survey_parent_id` = {$survey_id}, `survey_answer_text` = '{$survey_answer}'") : false;
47
      }
48
    }
49
50
    if ($announce_time <= SN_TIME_NOW) {
51
      if ($announce_time > classSupernova::$config->var_news_last && $announce_time == SN_TIME_NOW) {
0 ignored issues
show
The property var_news_last does not exist on object<classConfig>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
52
        classSupernova::$config->db_saveItem('var_news_last', $announce_time);
53
      }
54
55
      if (sys_get_param_int('news_mass_mail')) {
56
        $text = sys_get_param('text') . ($detail_url ? " <a href=\"{$detail_url}\"><span class=\"positive\">{$lang['news_more']}</span></a>" : '');
57
        msg_send_simple_message('*', 0, 0, MSG_TYPE_ADMIN, $lang['sys_administration'], $lang['news_title'], $text);
58
      }
59
    }
60
61
    $mode = '';
62
    $announce_id = 0;
63
  }
64
65
  $survey_answers = '';
66
  switch ($mode) {
67
    case 'del':
68
      doquery("DELETE FROM {{announce}} WHERE `idAnnounce` = {$announce_id} LIMIT 1;");
69
      $mode = '';
70
    break;
71
72
    case 'edit':
73
      $template->assign_var('ID', $announce_id);
74
    case 'copy':
75
      $announce = doquery(
76
        "SELECT a.*, s.survey_id, s.survey_question, s.survey_until
77
        FROM {{announce}} AS a
78
        LEFT JOIN {{survey}} AS s ON s.survey_announce_id = a.idAnnounce
79
        WHERE `idAnnounce` = {$announce_id} LIMIT 1;", true);
0 ignored issues
show
true is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
80
      if ($announce['survey_id']) {
81
        $query = doquery("SELECT survey_answer_text FROM {{survey_answers}} WHERE survey_parent_id = {$announce['survey_id']};");
82
        while ($row = db_fetch($query)) {
83
          $survey_answers[] = $row['survey_answer_text'];
84
        }
85
        $survey_answers = implode("\r\n", $survey_answers);
86
      }
87
    break;
88
  }
89
} else {
90
  $annQuery = 'WHERE UNIX_TIMESTAMP(`tsTimeStamp`) <= ' . SN_TIME_NOW;
91
}
92
93
nws_render($template, $annQuery, 20);
94
95
$template->assign_vars(array(
96
  'AUTHLEVEL'       => $user['authlevel'],
97
//  'total'           => db_num_rows($allAnnounces),
98
  'MODE'            => $mode,
99
  'tsTimeStamp'     => $announce['tsTimeStamp'],
100
  'strAnnounce'     => $announce['strAnnounce'],
101
  'DETAIL_URL'      => $announce['detail_url'],
102
  'SURVEY_QUESTION' => $announce['survey_question'],
103
  'SURVEY_UNTIL'    => $announce['survey_until'],
104
  'SURVEY_ANSWERS'  => $survey_answers,
105
));
106
107
display($template, $lang['news_title']);
108