Issues (15)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

code/ManyMonthsCalendar.php (5 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
5
class ManyMonthsCalendar extends ViewableData
6
{
7
8
    //settings
9
    private static $day_names = array( 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun');
10
    private static $month_names = array( 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' );
11
    private static $previous_month_nav_text = '&laquo';
12
    private static $next_month_nav_text = '&raquo';
13
    private static $start_day_of_the_week = 1;
14
    private static $show_year_in_calendar = true;
15
    private static $enable_navigation = true;
16
    private static $calendar_day_format = "j"; // see http://nz.php.net/manual/en/function.date.php for formatting options
17
    private static $table_cell_spacing = 0; // see http://nz.php.net/manual/en/function.date.php for formatting options
18
19
    //variables to be added at runtime
20
    private $events = array();
21
    private $calendarName = "MMC";
22
    private $pageLink = "pleasesetlink";
23
24
    //internal variables
25
    private static $count_of_calenders_shown = 0;
26
    private $month = 1;
27
    private $year = 1974;
28
    private $timeStamp = 0;
29
    private $daysInMonth = 25; //set to unrealistic number to make sure that it actually gets set correctly
30
31 View Code Duplication
    public static function setDayNames($dayArray)
32
    {
33
        if (!is_array($dayArray) || count($dayArray) != 7) {
34
            debug::show($dayArray);
35
            user_error('There should be seven days in the array passed tot he setDayNames function in the ManyMonthsCalendar Class', E_USER_ERROR);
36
        }
37
        self::$day_names = $dayArray;
38
    }
39
40 View Code Duplication
    public static function setMonthNames($monthArray)
41
    {
42
        if (!is_array($monthArray) || count($monthArray) != 12) {
43
            debug::show($monthArray);
44
            user_error('There should be twelve months in the array passed tot he setMonthNames function in the ManyMonthsCalendar Class', E_USER_ERROR);
45
        }
46
        self::$month_names = $monthArray;
47
    }
48
49
    public static function setPreviousMonthNavText($text)
50
    {
51
        self::$previous_month_nav_text = $text;
52
    }
53
54
    public static function setNextMonthNavText($text)
55
    {
56
        self::$next_month_nav_text = $text;
57
    }
58
59
    public static function setStartDayOfTheWeek($numericDay)
60
    {
61
        if (is_int($numericDay) && $numericDay >= 0 && $numericDay <=6) {
62
            self::$start_day_of_the_week = $numericDay;
63
            for ($i = 0 ; $i < $numericDay ; $i++) {
64
                array_unshift(self::$day_names, array_pop(self::$day_names));
65
            }
66
        } else {
67
            debug::show($numericDay);
68
            user_error('Start Day of the Week should be between 0 and 6, 0=monday, 1=sunday, 2=saturday etc...)', E_USER_ERROR);
69
        }
70
    }
71
72
    public static function setShowYearInCalendar($booleanValue)
73
    {
74
        self::$show_year_in_calendar = $booleanValue;
75
    }
76
77
    public static function setEnableNavigation($booleanValue)
78
    {
79
        self::$enable_navigation = $booleanValue;
80
    }
81
82
    public static function setCalendarDayFormat($format)
83
    {
84
        self::$calendar_day_format = $format;
85
    }
86
87
    public static function setTableCellSpacing($pixels)
88
    {
89
        if (is_int($pixels) && $pixels >= 0 && $pixels <=500) {
90
            self::$table_cell_spacing = $pixels;
91
        } else {
92
            debug::show($pixels);
93
            user_error('Please set the right number of pixels for table spacing (e.g. 0, 1, 2 or 3)', E_USER_ERROR);
94
        }
95
    }
96
97
    public function __construct($pageLink, $name, $year = 0, $month = 0)
98
    {
99
        $this->pageLink = $pageLink;
100
        // Assign name to calendar
101
        if (strpos($name, ' ') || strpos($name, '_') || is_numeric(substr($name, 0, 1))) {
102
            debug::show($name);
103
            user_error('Calendar should have a valid CSS name in the ManyMonthsCalendar Class', E_USER_ERROR);
104
        }
105
        $this->calendarName = $name;
106
        
107
        // Set day, month and year of calendar
108
        $this->month = (0 == $month) ?    date('n') : $month;
0 ignored issues
show
Documentation Bug introduced by
It seems like 0 == $month ? date('n') : $month can also be of type string. However, the property $month is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
109
        $this->year = (0 == $year) ? date('Y') : $year;
0 ignored issues
show
Documentation Bug introduced by
It seems like 0 == $year ? date('Y') : $year can also be of type string. However, the property $year is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
110
111
        // Check for valid input
112
        if (!preg_match('~[0-9]{4}~', $this->year)) {
113
            debug::show($this->year);
114
            user_error('Year should be a valid number in the ManyMonthsCalendar Class', E_USER_ERROR);
115
        }
116
        if (!is_numeric($this->month) || $this->month < 0 || $this->month > 13) {
117
            debug::show($this->month);
118
            user_error('Month should be a valid number in the ManyMonthsCalendar Class', E_USER_ERROR);
119
        }
120
        // Set the current timestamp
121
        $this->timeStamp = mktime(1, 1, 1, $this->month, 1, $this->year);
122
        // Set the number of days in the current month
123
        $this->daysInMonth = date('t', $this->timeStamp);
0 ignored issues
show
Documentation Bug introduced by
The property $daysInMonth was declared of type integer, but date('t', $this->timeStamp) is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
124
    }
125
126
127
128
    public function addEvent($timeStamp, $title, $link = '')
129
    {
130
        $this->events[$timeStamp][$this->cleanEventTitle($title)] = array(
131
            'Title' => $title,
132
            'Link' => $link
133
        );
134
    }
135
136
    public function removeEvent($timeStamp, $title)
137
    {
138
        if (isset($this->events[$timeStamp][$this->cleanEventTitle($title)])) {
139
            unset($this->events[$timeStamp][$this->cleanEventTitle($title)]);
140
        }
141
    }
142
143
    public function ManyMonthsCalendar()
144
    {
145
        Requirements::themedCSS("ManyMonthsCalendar");
146
        //make sure that all arrays added to calendarArray are DoSets in their own right
147
        self::$count_of_calenders_shown++;
148
        $calendarArray = array();
149
        //general variables
150
        $calendarArray["TableID"] = $this->calenderName.'-'.self::$count_of_calenders_shown;
0 ignored issues
show
The property calenderName does not seem to exist. Did you mean calendarName?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
151
        $calendarArray["TableClass"] = $this->calenderName;
0 ignored issues
show
The property calenderName does not seem to exist. Did you mean calendarName?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
152
        $calendarArray["EnableNavigation"] = self::$enable_navigation;
153
        $calendarArray["ColSpan"] = 5;
154
        $calendarArray["PageLink"] = $this->pageLink;
155
        $calendarArray["MonthName"] = $this->getMonthName();
156
        if (self::$show_year_in_calendar) {
157
            $calendarArray["YearName"] = $this->year;
158
        }
159
        $calendarArray["CellSpacing"] = self::$table_cell_spacing;
160
        $calendarArray["PreviousMonthNavText"] = self::$previous_month_nav_text;
161
        $calendarArray["NextMonthNavText"] = self::$next_month_nav_text;
162
        if (self::$enable_navigation) {
163
            $previousMonth = explode('-', date('n-Y', strtotime('-1 month', $this->timeStamp)));
164
            $calendarArray["PreviousMonthMonthNumber"] = $previousMonth[0];
165
            $calendarArray["PreviousMonthYearNumber"] = $previousMonth[1];
166
            $nextYear = explode('-', date('n-Y', strtotime('+1 month', $this->timeStamp)));
167
            $calendarArray["NextMonthMonthNumber"] = $nextYear[0];
168
            $calendarArray["NextMonthYearNumber"] = $nextYear[1];
169
            $calendarArray["ColSpan"] = 7;
170
        }
171
172
        $doSetDayNames = new DataObjectSet();
173
        //day name
174
        foreach (self::$day_names as $name) {
175
            $doSetDayNames->push(new ArrayData(array("DayName" => $name)));
176
        }
177
        $calendarArray["DayNames"] = $doSetDayNames;
178
179
        $extraDaysToBeAddedFromPreviousMonth = date('N', $this->timeStamp) + self::$start_day_of_the_week - 1;
180
        $position = 0;
181
182
        $doSetDates = new DataObjectSet();
183
        // previous month
184
        for ($e = 1 ; $e <= $extraDaysToBeAddedFromPreviousMonth ; $e++) {
185
            $position++;
186
            $timeStamp = $this->makeTimeStamp("-" . intval($extraDaysToBeAddedFromPreviousMonth -$e) . " days");
187
            $doSetDates->push($this->getDateDataObject($position, $timeStamp, false));
188
        }
189
190
        // current Month
191
        for ($i = 1 ; $i <= $this->daysInMonth ; $i++) {
192
            $position++;
193
            $timeStamp = $this->makeTimeStamp("+".($i-1)." days");
194
            $doSetDates->push($this->getDateDataObject($position, $timeStamp));
195
        }
196
197
        // next month
198
        for ($e2 = 1 ; $e2 < (7 - (($e + $this->daysInMonth -1) % 7)) ; $e2++) {
199
            $position++;
200
            $timeStamp = $this->makeTimeStamp("+$e2 days");
201
            $doSetDates->push($this->getDateDataObject($position, $timeStamp, false));
202
        }
203
        $calendarArray["Days"] = $doSetDates;
204
        return new ArrayData($calendarArray);
205
    }
206
207
    private function getDateDataObject($position, $timeStamp, $currentMonth = true)
208
    {
209
        $array = array();
210
        $array["Day"] = date(self::$calendar_day_format, $timeStamp);
211
        if ($currentMonth) {
212
            $array["OutsideCurrentMonth"] = true;
213
        } else {
214
            $array["OutsideCurrentMonth"] = false;
215
        }
216
        $eventsDoSet = new DataObjectSet();
217
        if (isset($this->events[$timeStamp])) {
218
            if (is_array($this->events[$timeStamp])) {
219
                foreach ($this->events[$timeStamp] as $event) {
220
                    $eventsDoSet->push(new ArrayData($event));
221
                }
222
            }
223
        }
224
        $array["Events"] = $eventsDoSet;
225
        if (($position % 7) == 0 /*&& $position < */) {
226
            $array["LastDayOfTheWeek"] = true;
227
        }
228
        if ($timeStamp == mktime(1, 1, 1, date('n'), date('j'), date('Y'))) {
229
            $array["IsCurrentDay"] = true;
230
        } else {
231
            $array["IsCurrentDay"] = false;
232
        }
233
        if ($position % 2) {
234
            $array["EvenCol"] = true;
235
        }
236
        if (round($position / 7) % 2) {
237
            $array["EvenRow"] = false;
238
        }
239
        return new ArrayData($array);
240
    }
241
242
    private function cleanEventTitle($title)
243
    {
244
        $title = eregi_replace("[^[:alnum:]]", " ", $title);
245
        $title = trim(eregi_replace(" +", "", $title)); //removes excess spaces
246
        return $title;
247
    }
248
249
    private function makeTimeStamp($offset)
250
    {
251
        return strtotime($offset, $this->timeStamp);
252
    }
253
254
    private function getMonthName()
255
    {
256
        return ucwords(self::$month_names[$this->month-1]);
257
    }
258
259
    public function forTemplate()
260
    {
261
        return $this->renderWith('ManyMonthsCalendar');
262
    }
263
}
264