Completed
Branch master (c3ca5f)
by Seth
04:51
created
phpicalendar/config.inc.php 2 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -25,19 +25,19 @@  discard block
 block discarded – undo
25 25
 
26 26
 The salt parameter is used to obfuscate things like webcal links that may have usernames and passwords.  This should be changed.
27 27
 */
28
-     'calendar_path'        => '/var/www-data/canvas/ics-sync',
28
+	 'calendar_path'        => '/var/www-data/canvas/ics-sync',
29 29
 #     'default_path'         => '', 	
30 30
 #     'save_parsed_cals'     => 'yes', 
31 31
 #     'cookie_uri'           => '', 
32 32
 #     'download_uri'         => '', 	
33
-     'allow_webcals'          => 'yes',
33
+	 'allow_webcals'          => 'yes',
34 34
 #     'recursive_path'          => 'yes',
35
-     'salt'                => 'AjeoRZ9rC5pDzV6xk9nD',
35
+	 'salt'                => 'AjeoRZ9rC5pDzV6xk9nD',
36 36
 
37 37
 /*     ** Timezones **
38 38
 If timezone is not set, all events show in the local time of the source calendar.  This isn't a problem if all your calendars are in the same timezone.  If you set a timezone for the server, events in other timezones are shown when they occur at the server's time.
39 39
 */
40
-     'timezone'             => 'US/Eastern',
40
+	 'timezone'             => 'US/Eastern',
41 41
 #     'second_offset'        => $secs,
42 42
 
43 43
 /*     ** Appearance **      
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 #     'language'             => 'English',
52 52
 #     'default_cal'          => 'US Holidays',	   // Exact filename of calendar without .ics.
53 53
 #     'template'             => 'green',           // Template support: change this to have a different "skin" for your installation.     
54
-    'default_view'         => 'year',           // Default view for calendars'     => 'day', 'week', 'month', 'year'
54
+	'default_view'         => 'year',           // Default view for calendars'     => 'day', 'week', 'month', 'year'
55 55
 #      'printview_default'    => 'yes',	           // Set print view as the default view. Uses'default_view (listed above).
56 56
 #     'gridLength'           => 10,                // Grid size in day and week views. Allowed values are 1,2,3,4,10,12,15,20,30,60. Default is 15
57 57
 #     'minical_view'         => 'current',	       // Where do the mini-calendars go when clicked?'     => 'day', 'week', 'month', 'current'
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 #     'language'             => 'English',
52 52
 #     'default_cal'          => 'US Holidays',	   // Exact filename of calendar without .ics.
53 53
 #     'template'             => 'green',           // Template support: change this to have a different "skin" for your installation.     
54
-    'default_view'         => 'year',           // Default view for calendars'     => 'day', 'week', 'month', 'year'
54
+    'default_view'         => 'year', // Default view for calendars'     => 'day', 'week', 'month', 'year'
55 55
 #      'printview_default'    => 'yes',	           // Set print view as the default view. Uses'default_view (listed above).
56 56
 #     'gridLength'           => 10,                // Grid size in day and week views. Allowed values are 1,2,3,4,10,12,15,20,30,60. Default is 15
57 57
 #     'minical_view'         => 'current',	       // Where do the mini-calendars go when clicked?'     => 'day', 'week', 'month', 'current'
@@ -111,13 +111,13 @@  discard block
 block discarded – undo
111 111
 these arrays provide extra calendar options.
112 112
 
113 113
 */
114
-$locked_map['user1:pass'] = array('');             // Map username:password accounts to locked calendars that should be
115
-$locked_map['user2:pass'] = array('');             // unlocked if logged in. Calendar names should be the same as what is
116
-$locked_map['user3:pass'] = array('');             // listed in the $locked_cals, again without the .ics suffix.
117
-$locked_map['user4:pass'] = array('');             // Example: $locked_map['username:password'] = array('Locked1', 'Locked2');
114
+$locked_map['user1:pass'] = array(''); // Map username:password accounts to locked calendars that should be
115
+$locked_map['user2:pass'] = array(''); // unlocked if logged in. Calendar names should be the same as what is
116
+$locked_map['user3:pass'] = array(''); // listed in the $locked_cals, again without the .ics suffix.
117
+$locked_map['user4:pass'] = array(''); // Example: $locked_map['username:password'] = array('Locked1', 'Locked2');
118 118
 // add more lines as necessary
119 119
 
120
-$apache_map['user1'] = array('');                  // Map HTTP authenticated users to specific calendars. Users listed here and
121
-$apache_map['user2'] = array('');                  // authenticated via HTTP will not see the public calendars, and will not be
122
-$apache_map['user3'] = array('');                  // given any login/logout options. Calendar names not include the .ics suffix.
123
-$apache_map['user4'] = array('');                  // Example: $apache_map['username'] = array('Calendar1', 'Calendar2');
120
+$apache_map['user1'] = array(''); // Map HTTP authenticated users to specific calendars. Users listed here and
121
+$apache_map['user2'] = array(''); // authenticated via HTTP will not see the public calendars, and will not be
122
+$apache_map['user3'] = array(''); // given any login/logout options. Calendar names not include the .ics suffix.
123
+$apache_map['user4'] = array(''); // Example: $apache_map['username'] = array('Calendar1', 'Calendar2');
Please login to merge, or discard this patch.
phpicalendar/error.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,23 +1,23 @@
 block discarded – undo
1 1
 <?php
2
-if (!defined('BASE')) define('BASE','./');
2
+if (!defined('BASE')) define('BASE', './');
3 3
 require_once(BASE.'functions/template.php');
4 4
 
5 5
 
6
-function error($error_msg='There was an error processing the request.', $file='NONE', $error_base='') {
6
+function error($error_msg = 'There was an error processing the request.', $file = 'NONE', $error_base = '') {
7 7
 	global $getdate, $rss_powered, $lang, $phpiCal_config, $cal;
8 8
 	if (!isset($template))					$template = $phpiCal_config->template;
9 9
 		
10
-	$error_calendar 	= sprintf($lang['l_error_calendar'], print_r($file,true));
10
+	$error_calendar 	= sprintf($lang['l_error_calendar'], print_r($file, true));
11 11
 	$current_view 		= 'error';
12 12
 	$display_date 		= $lang['l_error_title'];
13 13
 	$calendar_name 		= $lang['l_error_title'];
14 14
 	
15 15
 	$default_path = $phpiCal_config->default_path;
16 16
 	if (empty($phpiCal_config->default_path)) {
17
-		if (isset($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) == 'on' ) {
18
-			$default_path = 'https://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].substr($_SERVER['PHP_SELF'],0,strpos($_SERVER['PHP_SELF'],'/rss/'));
17
+		if (isset($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) == 'on') {
18
+			$default_path = 'https://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].substr($_SERVER['PHP_SELF'], 0, strpos($_SERVER['PHP_SELF'], '/rss/'));
19 19
 		} else {
20
-			$default_path = 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].substr($_SERVER['PHP_SELF'],0,strpos($_SERVER['PHP_SELF'],'/rss/'));
20
+			$default_path = 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].substr($_SERVER['PHP_SELF'], 0, strpos($_SERVER['PHP_SELF'], '/rss/'));
21 21
 		}
22 22
 	}
23 23
 	$page = new Page(BASE.'templates/'.$template.'/error.tpl');
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,11 +1,15 @@
 block discarded – undo
1 1
 <?php
2
-if (!defined('BASE')) define('BASE','./');
2
+if (!defined('BASE')) {
3
+	define('BASE','./');
4
+}
3 5
 require_once(BASE.'functions/template.php');
4 6
 
5 7
 
6 8
 function error($error_msg='There was an error processing the request.', $file='NONE', $error_base='') {
7 9
 	global $getdate, $rss_powered, $lang, $phpiCal_config, $cal;
8
-	if (!isset($template))					$template = $phpiCal_config->template;
10
+	if (!isset($template)) {
11
+		$template = $phpiCal_config->template;
12
+	}
9 13
 		
10 14
 	$error_calendar 	= sprintf($lang['l_error_calendar'], print_r($file,true));
11 15
 	$current_view 		= 'error';
Please login to merge, or discard this patch.
phpicalendar/preferences.php 3 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -58,8 +58,8 @@
 block discarded – undo
58 58
 			include(BASE.'languages/'.strtolower($_POST['cookie_language']).'.inc.php');
59 59
 	}
60 60
 	$_COOKIE[$cookie_name] = $the_cookie;
61
-    $cpath = $cookie_cpath;
62
-    $cal = $cookie_calendar;
61
+	$cpath = $cookie_cpath;
62
+	$cal = $cookie_calendar;
63 63
 }
64 64
 
65 65
 if (isset($_COOKIE[$cookie_name])) {
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-define('BASE','./');
2
+define('BASE', './');
3 3
 $current_view = 'preferences';
4 4
 require_once(BASE.'functions/init.inc.php');
5 5
 require_once(BASE.'functions/template.php');
@@ -19,21 +19,21 @@  discard block
 block discarded – undo
19 19
 	$action = '';
20 20
 } 
21 21
 
22
-$startdays = array ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
22
+$startdays = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
23 23
 
24 24
 if ($action == 'setcookie') { 
25 25
 	$cookie_language 	= urldecode($_POST['cookie_language']);
26
-   	$cookie_cpath     	= $_POST['cpath'];
26
+   	$cookie_cpath = $_POST['cpath'];
27 27
 	$cookie_calendar 	= $_POST['cookie_calendar'];
28
-	$cookie_view 		= $_POST['cookie_view'];
29
-	$cookie_style 		= $_POST['cookie_style'];
28
+	$cookie_view = $_POST['cookie_view'];
29
+	$cookie_style = $_POST['cookie_style'];
30 30
 	$cookie_startday	= $_POST['cookie_startday'];
31
-	$cookie_time		= $_POST['cookie_time'];
32
-	$cookie_timeformat	= urldecode($_POST['cookie_timeformat']);
31
+	$cookie_time = $_POST['cookie_time'];
32
+	$cookie_timeformat = urldecode($_POST['cookie_timeformat']);
33 33
 	$cookie_endtime		= $_POST['cookie_endtime'];
34 34
 	$cookie_timezone	= $_POST['cookie_timezone'];
35
-	$cookie_unset		= @$_POST['unset'];
36
-	$the_cookie = array (
35
+	$cookie_unset = @$_POST['unset'];
36
+	$the_cookie = array(
37 37
 		"cookie_language"   => "$cookie_language", 
38 38
 		"cookie_calendar"   => "$cookie_calendar", 
39 39
 		"cookie_view"       => "$cookie_view", 
@@ -45,11 +45,11 @@  discard block
 block discarded – undo
45 45
 		"cookie_cpath"      => "$cookie_cpath", 
46 46
 		"cookie_timezone"   => "$cookie_timezone"
47 47
 		);
48
-	$the_cookie 		= addslashes(serialize($the_cookie));
48
+	$the_cookie = addslashes(serialize($the_cookie));
49 49
 	if (isset($cookie_unset)) { 
50
-		setcookie("$cookie_name","$the_cookie",time()-(60*60*24*7) ,"/","$phpiCal_config->cookie_uri",0);
50
+		setcookie("$cookie_name", "$the_cookie", time() - (60*60*24*7), "/", "$phpiCal_config->cookie_uri", 0);
51 51
 	} else {
52
-		setcookie("$cookie_name","$the_cookie",time()+(60*60*24*7*12*10) ,"/","$phpiCal_config->cookie_uri",0);
52
+		setcookie("$cookie_name", "$the_cookie", time() + (60*60*24*7*12*10), "/", "$phpiCal_config->cookie_uri", 0);
53 53
 		if (isset($_POST['cookie_view'])) 
54 54
 			$phpiCal_config->default_view = $_POST['cookie_view'];
55 55
 		if (isset($_POST['cookie_style']) && is_dir(BASE.'templates/'.$_POST['cookie_style'].'/')) 
@@ -63,15 +63,15 @@  discard block
 block discarded – undo
63 63
 }
64 64
 
65 65
 if (isset($_COOKIE[$cookie_name])) {
66
-	$phpicalendar 		= unserialize(stripslashes($_COOKIE[$cookie_name]));
66
+	$phpicalendar = unserialize(stripslashes($_COOKIE[$cookie_name]));
67 67
 	$cookie_language 	= $phpicalendar['cookie_language'];
68 68
 	$cookie_calendar 	= $phpicalendar['cookie_calendar'];
69
-	$cookie_view 		= $phpicalendar['cookie_view'];
70
-	$cookie_style 		= $phpicalendar['cookie_style'];
69
+	$cookie_view = $phpicalendar['cookie_view'];
70
+	$cookie_style = $phpicalendar['cookie_style'];
71 71
 	$cookie_startday	= $phpicalendar['cookie_startday'];
72
-	$cookie_time		= $phpicalendar['cookie_time'];
72
+	$cookie_time = $phpicalendar['cookie_time'];
73 73
 	$cookie_endtime		= $phpicalendar['cookie_endtime'];
74
-	$cookie_timeformat	= $phpicalendar['cookie_timeformat'];
74
+	$cookie_timeformat = $phpicalendar['cookie_timeformat'];
75 75
 	$cookie_timezone	= $phpicalendar['cookie_timezone'];
76 76
 	if ($cookie_unset) { 
77 77
 		unset ($cookie_language, $cookie_calendar, $cookie_view, $cookie_style, $cookie_startday, $cookie_time, $cookie_endtime, $cookie_timeformat, $cookie_timezone);
@@ -87,8 +87,8 @@  discard block
 block discarded – undo
87 87
 	$cookie_startday 	= $phpiCal_config->week_start_day;
88 88
 	$cookie_time    	= $phpiCal_config->day_start;
89 89
 	$cookie_endtime 	= $phpiCal_config->day_end;
90
-	$cookie_timeformat 	= $timeFormat;
91
-	$cookie_timezone 	= $phpiCal_config->timezone;
90
+	$cookie_timeformat = $timeFormat;
91
+	$cookie_timezone = $phpiCal_config->timezone;
92 92
 }
93 93
 
94 94
 if ($action == 'setcookie') { 
@@ -118,12 +118,12 @@  discard block
 block discarded – undo
118 118
 closedir($dir_handle);
119 119
 
120 120
 // select for calendars
121
-$calendar_select = display_ical_list(availableCalendars($username, $password, $phpiCal_config->ALL_CALENDARS_COMBINED),TRUE);
122
-$calendar_select .="<option value=\"$phpiCal_config->ALL_CALENDARS_COMBINED\">$all_cal_comb_lang</option>";
123
-$calendar_select = str_replace("<option value=\"$cookie_calendar\">","<option value=\"$cookie_calendar\" selected='selected'>",$calendar_select);
121
+$calendar_select = display_ical_list(availableCalendars($username, $password, $phpiCal_config->ALL_CALENDARS_COMBINED), TRUE);
122
+$calendar_select .= "<option value=\"$phpiCal_config->ALL_CALENDARS_COMBINED\">$all_cal_comb_lang</option>";
123
+$calendar_select = str_replace("<option value=\"$cookie_calendar\">", "<option value=\"$cookie_calendar\" selected='selected'>", $calendar_select);
124 124
 // select for dayview
125
-$view_select 	 = ($phpiCal_config->default_view == 'day'  ) ? '<option value="day" selected="selected">{L_DAY}</option>'     : '<option value="day">{L_DAY}</option>';
126
-$view_select    .= ($phpiCal_config->default_view == 'week' ) ? '<option value="week" selected="selected">{L_WEEK}</option>'   : '<option value="week">{L_WEEK}</option>';
125
+$view_select = ($phpiCal_config->default_view == 'day') ? '<option value="day" selected="selected">{L_DAY}</option>' : '<option value="day">{L_DAY}</option>';
126
+$view_select    .= ($phpiCal_config->default_view == 'week') ? '<option value="week" selected="selected">{L_WEEK}</option>' : '<option value="week">{L_WEEK}</option>';
127 127
 $view_select    .= ($phpiCal_config->default_view == 'month') ? '<option value="month" selected="selected">{L_MONTH}</option>' : '<option value="month">{L_MONTH}</option>';
128 128
 
129 129
 // select for time
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 }
168 168
 
169 169
 // select for day of week
170
-$i=0;
170
+$i = 0;
171 171
 $startday_select = '';
172 172
 foreach ($daysofweek_lang as $daysofweek) {
173 173
 	if ($startdays[$i] == $cookie_startday) {
Please login to merge, or discard this patch.
Braces   +12 added lines, -7 removed lines patch added patch discarded remove patch
@@ -11,7 +11,9 @@  discard block
 block discarded – undo
11 11
 
12 12
 $current_view = "preferences";
13 13
 $back_page = BASE.$phpiCal_config->default_view.'.php?cal='.$cal.'&amp;getdate='.$getdate.'&amp;cpath='.$cpath;
14
-if ($phpiCal_config->allow_preferences == 'no') header("Location: $back_page");
14
+if ($phpiCal_config->allow_preferences == 'no') {
15
+	header("Location: $back_page");
16
+}
15 17
 
16 18
 if (isset($_GET['action'])) {
17 19
 	$action = $_GET['action'];
@@ -50,12 +52,15 @@  discard block
 block discarded – undo
50 52
 		setcookie("$cookie_name","$the_cookie",time()-(60*60*24*7) ,"/","$phpiCal_config->cookie_uri",0);
51 53
 	} else {
52 54
 		setcookie("$cookie_name","$the_cookie",time()+(60*60*24*7*12*10) ,"/","$phpiCal_config->cookie_uri",0);
53
-		if (isset($_POST['cookie_view'])) 
54
-			$phpiCal_config->default_view = $_POST['cookie_view'];
55
-		if (isset($_POST['cookie_style']) && is_dir(BASE.'templates/'.$_POST['cookie_style'].'/')) 
56
-			$phpiCal_config->template = $_POST['cookie_style'];
57
-		if (isset($_POST['cookie_language']) && is_file(BASE.'languages/'.strtolower($_POST['cookie_language']).'.inc.php')) 
58
-			include(BASE.'languages/'.strtolower($_POST['cookie_language']).'.inc.php');
55
+		if (isset($_POST['cookie_view'])) {
56
+					$phpiCal_config->default_view = $_POST['cookie_view'];
57
+		}
58
+		if (isset($_POST['cookie_style']) && is_dir(BASE.'templates/'.$_POST['cookie_style'].'/')) {
59
+					$phpiCal_config->template = $_POST['cookie_style'];
60
+		}
61
+		if (isset($_POST['cookie_language']) && is_file(BASE.'languages/'.strtolower($_POST['cookie_language']).'.inc.php')) {
62
+					include(BASE.'languages/'.strtolower($_POST['cookie_language']).'.inc.php');
63
+		}
59 64
 	}
60 65
 	$_COOKIE[$cookie_name] = $the_cookie;
61 66
     $cpath = $cookie_cpath;
Please login to merge, or discard this patch.
phpicalendar/lib/HTTP/CalDAV/Tools/ICalendarParser.php 2 patches
Indentation   +253 added lines, -253 removed lines patch added patch discarded remove patch
@@ -41,259 +41,259 @@
 block discarded – undo
41 41
  */
42 42
 class ICalendarParser
43 43
 {
44
-    /**
45
-     * Input stream handle
46
-     *
47
-     * @var resource
48
-     * @access private
49
-     */
50
-    var $_handle;
51
-
52
-    /**
53
-     * Line of input
54
-     *
55
-     * @var string
56
-     * @access private
57
-     */
58
-    var $_line;
59
-
60
-    /**
61
-     * Offset of line
62
-     *
63
-     * @var int
64
-     * @access private
65
-     */
66
-    var $_offset;
67
-
68
-    /**
69
-     * Success state flag
70
-     *
71
-     * @var bool
72
-     * @access public
73
-     */
74
-    var $success = true;
75
-
76
-    /**
77
-     * Parsed components are collected here in post-order
78
-     *
79
-     * @var array
80
-     * @access public
81
-     */
82
-    var $comps = array();
83
-
84
-    /**
85
-     * Parsed components' offsets are collected here in post-order
86
-     *
87
-     * @var array
88
-     * @access public
89
-     */
90
-    var $offsets = array();
91
-
92
-    /**
93
-     * Component stack for parsing nested components
94
-     *
95
-     * @var array
96
-     * @access private
97
-     */
98
-    var $_compStack = array();
99
-
100
-    /**
101
-     * Begin offset stack for tracking start offsets of nested components
102
-     *
103
-     * @var array
104
-     * @access private
105
-     */
106
-    var $_startOffsetStack = array();
107
-
108
-    /**
109
-     * Offsets stack for parsing within specific ranges
110
-     *
111
-     * @var array
112
-     * @access private
113
-     */
114
-    var $_offsetStack = array();
115
-
116
-    /**
117
-     * Value stack for parsing only specific components & properties
118
-     *
119
-     * @var array
120
-     * @access private
121
-     */
122
-    var $_valueStack = array();
123
-
124
-    /**
125
-     * Filter stack for parsing only components & properties which match
126
-     * specific filters
127
-     *
128
-     * @var array
129
-     * @access private
130
-     */
131
-    var $_filterStack = array();
132
-
133
-    /**
134
-     * Parse RFC2445 date-time
135
-     *
136
-     * May eventually get moved someplace more appropriate
137
-     * TODO Timezone support
138
-     *
139
-     * @param string RFC2445 date-time
140
-     * @return int timestamp
141
-     * @access public
142
-     */
143
-    function datetime_to_timestamp($datetime)
144
-    {
145
-        return gmmktime(substr($datetime, 9, 2), substr($datetime, 11, 2), substr($datetime, 13, 2), substr($datetime, 4, 2), substr($datetime, 6, 2), substr($datetime, 0, 4));
146
-    }
147
-
148
-    /**
149
-     * Constructor
150
-     *
151
-     * @param resource input stream handle
152
-     * @access public
153
-     */
154
-    function ICalendarParser($handle, $offsets=null, $value=null, $filters=null)
155
-    {
156
-        $this->_handle = $handle;
157
-        $this->_offsetStack[] = $offsets;
158
-
159
-        // FIXME Separate comps & props stacks?
160
-        $this->_valueStack[] = array('comps' => $value);
161
-        $this->_filterStack[] = $filters;
162
-        while ($this->success &&
163
-                ($this->_offset = ftell($this->_handle)) !== false &&
164
-                ($this->_line = fgets($this->_handle, 4096)) !== false) {
165
-            if (is_array($this->_offsetStack[count($this->_offsetStack) - 1]['offsets'])) {
166
-                if ($this->_offset > $this->_offsetStack[count($this->_offsetStack) - 1]['offsets'][0][1]) {
167
-                    if (array_shift($this->_offsetStack[count($this->_offsetStack) - 1]['offsets']) !== null) {
168
-                        if (fseek($this->_offsetStack[count($this->_offsetStack) - 1]['offsets'][0][0])) {
169
-                            $this->success = false;
170
-                            return;
171
-                        }
172
-
173
-                        continue;
174
-                    }
175
-
176
-                    if (!empty($this->_compStack)) {
177
-                        $name = $this->_compStack[count($this->_compStack) - 1]->name;
178
-                        while (($line = fgets($this->_handle, 4096)) !== false) {
179
-                            if (trim($line) == "END:$name") {
180
-                                return;
181
-                            }
182
-                        }
183
-
184
-                        $this->_endComp($name);
185
-                        continue;
186
-                    }
187
-
188
-                    return;
189
-                }
190
-            }
191
-
192
-            $line = explode(':', trim($this->_line));
193
-
194
-            if ($line[0] == 'BEGIN') {
195
-                $this->_startComp($line[1]);
196
-                continue;
197
-            }
198
-
199
-            if ($line[0] == 'END') {
200
-                $this->_endComp($line[1]);
201
-                continue;
202
-            }
203
-
204
-            $line[0] = explode(';=', $line[0]);
205
-            $name = array_shift($line[0]);
206
-            if (is_array($this->_valueStack[count($this->_valueStack) - 1]['props']) && !in_array($name, $this->_valueStack[count($this->_valueStack) - 1]['props'])) {
207
-                continue;
208
-            }
209
-
210
-            $params = array();
211
-            while (!empty($line[0])) {
212
-                $params[array_shift($line[0])] = array_shift($line[0]);
213
-            }
214
-            $this->_compStack[count($this->_compStack) - 1]->add_property($name, $line[1], $params);
215
-        }
216
-
217
-        if (!feof($this->_handle)) {
218
-            $this->success = false;
219
-        }
220
-    }
221
-
222
-    function _startComp($name)
223
-    {
224
-        if (is_array($this->_valueStack[count($this->_valueStack) - 1]['comps']) &&
225
-                !isset($this->_valueStack[count($this->_valueStack) - 1]['comps'][$name])) {
226
-            while (($line = fgets($this->_handle, 4096)) !== false) {
227
-                if (trim($line) == "END:$name") {
228
-                    return;
229
-                }
230
-            }
231
-
232
-            $this->success = false;
233
-            return;
234
-        }
235
-
236
-        $class = 'iCalendar_' . ltrim(strtolower($name), 'v');
237
-        if ($name == 'VCALENDAR') {
238
-            $class = 'iCalendar';
239
-        }
240
-
241
-        if (!class_exists($class)) {
242
-            while (($line = fgets($this->_handle, 4096)) !== false) {
243
-                if (trim($line) == "END:$name") {
244
-                    return;
245
-                }
246
-            }
247
-
248
-            $this->success = false;
249
-            return;
250
-        }
251
-
252
-        $this->_compStack[] = new $class;
253
-        $this->_startOffsetStack[] = $this->_offset;
254
-        $this->_offsetStack[] = $this->_offsetStack[count($this->_offsetStack) - 1]['comps'][$name];
255
-        $this->_valueStack[] = $this->_valueStack[count($this->_valueStack) - 1]['comps'][$name];
256
-        $this->_filterStack[] = $this->_filterStack[count($this->_filterStack) - 1]['comps'][$name];
257
-    }
258
-
259
-    function _endComp($name)
260
-    {
261
-        if ($name != $this->_compStack[count($this->_compStack) - 1]->name) {
262
-            $this->success = false;
263
-            return;
264
-        }
265
-
266
-        if (is_array($this->_filterStack[count($this->_filterStack) - 1]['filters'])) {
267
-            foreach ($this->_filterStack[count($this->_filterStack) - 1]['filters'] as $filter) {
268
-                if ($filter['name'] == 'time-range') {
269
-                    if ($filter['value']['start'] > $this->_compStack[count($this->_compStack) - 1]->properties['DTEND'][0]->value || $filter['value']['end'] < $this->_compStack[count($this->_compStack) - 1]->properties['DTSTART'][0]->value) {
270
-                        array_pop($this->_compStack);
271
-                        array_pop($this->_startOffsetStack);
272
-                        array_pop($this->_offsetStack);
273
-                        array_pop($this->_valueStack);
274
-                        array_pop($this->_filterStack);
275
-                        return;
276
-                    }
277
-                }
278
-            }
279
-        }
280
-
281
-        if (count($this->_compStack) > 1 && !$this->_compStack[count($this->_compStack) - 2]->add_component($this->_compStack[count($this->_compStack) - 1])) {
282
-            $this->success = false;
283
-            return;
284
-        }
285
-
286
-        if (($offset = ftell($this->_handle)) === false) {
287
-            $this->success = false;
288
-            return;
289
-        }
290
-
291
-        $this->comps[] = array_pop($this->_compStack);
292
-        $this->offsets[] = array(array_pop($this->_startOffsetStack), $offset);
293
-        array_pop($this->_offsetStack);
294
-        array_pop($this->_valueStack);
295
-        array_pop($this->_filterStack);
296
-    }
44
+	/**
45
+	 * Input stream handle
46
+	 *
47
+	 * @var resource
48
+	 * @access private
49
+	 */
50
+	var $_handle;
51
+
52
+	/**
53
+	 * Line of input
54
+	 *
55
+	 * @var string
56
+	 * @access private
57
+	 */
58
+	var $_line;
59
+
60
+	/**
61
+	 * Offset of line
62
+	 *
63
+	 * @var int
64
+	 * @access private
65
+	 */
66
+	var $_offset;
67
+
68
+	/**
69
+	 * Success state flag
70
+	 *
71
+	 * @var bool
72
+	 * @access public
73
+	 */
74
+	var $success = true;
75
+
76
+	/**
77
+	 * Parsed components are collected here in post-order
78
+	 *
79
+	 * @var array
80
+	 * @access public
81
+	 */
82
+	var $comps = array();
83
+
84
+	/**
85
+	 * Parsed components' offsets are collected here in post-order
86
+	 *
87
+	 * @var array
88
+	 * @access public
89
+	 */
90
+	var $offsets = array();
91
+
92
+	/**
93
+	 * Component stack for parsing nested components
94
+	 *
95
+	 * @var array
96
+	 * @access private
97
+	 */
98
+	var $_compStack = array();
99
+
100
+	/**
101
+	 * Begin offset stack for tracking start offsets of nested components
102
+	 *
103
+	 * @var array
104
+	 * @access private
105
+	 */
106
+	var $_startOffsetStack = array();
107
+
108
+	/**
109
+	 * Offsets stack for parsing within specific ranges
110
+	 *
111
+	 * @var array
112
+	 * @access private
113
+	 */
114
+	var $_offsetStack = array();
115
+
116
+	/**
117
+	 * Value stack for parsing only specific components & properties
118
+	 *
119
+	 * @var array
120
+	 * @access private
121
+	 */
122
+	var $_valueStack = array();
123
+
124
+	/**
125
+	 * Filter stack for parsing only components & properties which match
126
+	 * specific filters
127
+	 *
128
+	 * @var array
129
+	 * @access private
130
+	 */
131
+	var $_filterStack = array();
132
+
133
+	/**
134
+	 * Parse RFC2445 date-time
135
+	 *
136
+	 * May eventually get moved someplace more appropriate
137
+	 * TODO Timezone support
138
+	 *
139
+	 * @param string RFC2445 date-time
140
+	 * @return int timestamp
141
+	 * @access public
142
+	 */
143
+	function datetime_to_timestamp($datetime)
144
+	{
145
+		return gmmktime(substr($datetime, 9, 2), substr($datetime, 11, 2), substr($datetime, 13, 2), substr($datetime, 4, 2), substr($datetime, 6, 2), substr($datetime, 0, 4));
146
+	}
147
+
148
+	/**
149
+	 * Constructor
150
+	 *
151
+	 * @param resource input stream handle
152
+	 * @access public
153
+	 */
154
+	function ICalendarParser($handle, $offsets=null, $value=null, $filters=null)
155
+	{
156
+		$this->_handle = $handle;
157
+		$this->_offsetStack[] = $offsets;
158
+
159
+		// FIXME Separate comps & props stacks?
160
+		$this->_valueStack[] = array('comps' => $value);
161
+		$this->_filterStack[] = $filters;
162
+		while ($this->success &&
163
+				($this->_offset = ftell($this->_handle)) !== false &&
164
+				($this->_line = fgets($this->_handle, 4096)) !== false) {
165
+			if (is_array($this->_offsetStack[count($this->_offsetStack) - 1]['offsets'])) {
166
+				if ($this->_offset > $this->_offsetStack[count($this->_offsetStack) - 1]['offsets'][0][1]) {
167
+					if (array_shift($this->_offsetStack[count($this->_offsetStack) - 1]['offsets']) !== null) {
168
+						if (fseek($this->_offsetStack[count($this->_offsetStack) - 1]['offsets'][0][0])) {
169
+							$this->success = false;
170
+							return;
171
+						}
172
+
173
+						continue;
174
+					}
175
+
176
+					if (!empty($this->_compStack)) {
177
+						$name = $this->_compStack[count($this->_compStack) - 1]->name;
178
+						while (($line = fgets($this->_handle, 4096)) !== false) {
179
+							if (trim($line) == "END:$name") {
180
+								return;
181
+							}
182
+						}
183
+
184
+						$this->_endComp($name);
185
+						continue;
186
+					}
187
+
188
+					return;
189
+				}
190
+			}
191
+
192
+			$line = explode(':', trim($this->_line));
193
+
194
+			if ($line[0] == 'BEGIN') {
195
+				$this->_startComp($line[1]);
196
+				continue;
197
+			}
198
+
199
+			if ($line[0] == 'END') {
200
+				$this->_endComp($line[1]);
201
+				continue;
202
+			}
203
+
204
+			$line[0] = explode(';=', $line[0]);
205
+			$name = array_shift($line[0]);
206
+			if (is_array($this->_valueStack[count($this->_valueStack) - 1]['props']) && !in_array($name, $this->_valueStack[count($this->_valueStack) - 1]['props'])) {
207
+				continue;
208
+			}
209
+
210
+			$params = array();
211
+			while (!empty($line[0])) {
212
+				$params[array_shift($line[0])] = array_shift($line[0]);
213
+			}
214
+			$this->_compStack[count($this->_compStack) - 1]->add_property($name, $line[1], $params);
215
+		}
216
+
217
+		if (!feof($this->_handle)) {
218
+			$this->success = false;
219
+		}
220
+	}
221
+
222
+	function _startComp($name)
223
+	{
224
+		if (is_array($this->_valueStack[count($this->_valueStack) - 1]['comps']) &&
225
+				!isset($this->_valueStack[count($this->_valueStack) - 1]['comps'][$name])) {
226
+			while (($line = fgets($this->_handle, 4096)) !== false) {
227
+				if (trim($line) == "END:$name") {
228
+					return;
229
+				}
230
+			}
231
+
232
+			$this->success = false;
233
+			return;
234
+		}
235
+
236
+		$class = 'iCalendar_' . ltrim(strtolower($name), 'v');
237
+		if ($name == 'VCALENDAR') {
238
+			$class = 'iCalendar';
239
+		}
240
+
241
+		if (!class_exists($class)) {
242
+			while (($line = fgets($this->_handle, 4096)) !== false) {
243
+				if (trim($line) == "END:$name") {
244
+					return;
245
+				}
246
+			}
247
+
248
+			$this->success = false;
249
+			return;
250
+		}
251
+
252
+		$this->_compStack[] = new $class;
253
+		$this->_startOffsetStack[] = $this->_offset;
254
+		$this->_offsetStack[] = $this->_offsetStack[count($this->_offsetStack) - 1]['comps'][$name];
255
+		$this->_valueStack[] = $this->_valueStack[count($this->_valueStack) - 1]['comps'][$name];
256
+		$this->_filterStack[] = $this->_filterStack[count($this->_filterStack) - 1]['comps'][$name];
257
+	}
258
+
259
+	function _endComp($name)
260
+	{
261
+		if ($name != $this->_compStack[count($this->_compStack) - 1]->name) {
262
+			$this->success = false;
263
+			return;
264
+		}
265
+
266
+		if (is_array($this->_filterStack[count($this->_filterStack) - 1]['filters'])) {
267
+			foreach ($this->_filterStack[count($this->_filterStack) - 1]['filters'] as $filter) {
268
+				if ($filter['name'] == 'time-range') {
269
+					if ($filter['value']['start'] > $this->_compStack[count($this->_compStack) - 1]->properties['DTEND'][0]->value || $filter['value']['end'] < $this->_compStack[count($this->_compStack) - 1]->properties['DTSTART'][0]->value) {
270
+						array_pop($this->_compStack);
271
+						array_pop($this->_startOffsetStack);
272
+						array_pop($this->_offsetStack);
273
+						array_pop($this->_valueStack);
274
+						array_pop($this->_filterStack);
275
+						return;
276
+					}
277
+				}
278
+			}
279
+		}
280
+
281
+		if (count($this->_compStack) > 1 && !$this->_compStack[count($this->_compStack) - 2]->add_component($this->_compStack[count($this->_compStack) - 1])) {
282
+			$this->success = false;
283
+			return;
284
+		}
285
+
286
+		if (($offset = ftell($this->_handle)) === false) {
287
+			$this->success = false;
288
+			return;
289
+		}
290
+
291
+		$this->comps[] = array_pop($this->_compStack);
292
+		$this->offsets[] = array(array_pop($this->_startOffsetStack), $offset);
293
+		array_pop($this->_offsetStack);
294
+		array_pop($this->_valueStack);
295
+		array_pop($this->_filterStack);
296
+	}
297 297
 }
298 298
 
299 299
 /*
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
      * @param resource input stream handle
152 152
      * @access public
153 153
      */
154
-    function ICalendarParser($handle, $offsets=null, $value=null, $filters=null)
154
+    function ICalendarParser($handle, $offsets = null, $value = null, $filters = null)
155 155
     {
156 156
         $this->_handle = $handle;
157 157
         $this->_offsetStack[] = $offsets;
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
             return;
234 234
         }
235 235
 
236
-        $class = 'iCalendar_' . ltrim(strtolower($name), 'v');
236
+        $class = 'iCalendar_'.ltrim(strtolower($name), 'v');
237 237
         if ($name == 'VCALENDAR') {
238 238
             $class = 'iCalendar';
239 239
         }
Please login to merge, or discard this patch.
phpicalendar/lib/bennu/bennu.class.php 2 patches
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -14,46 +14,46 @@
 block discarded – undo
14 14
  */
15 15
 
16 16
 class Bennu {
17
-    function timestamp_to_datetime($t = NULL) {
18
-        if($t === NULL) {
19
-            $t = time();
20
-        }
21
-        return gmstrftime('%Y%m%dT%H%M%SZ', $t);
22
-    }
17
+	function timestamp_to_datetime($t = NULL) {
18
+		if($t === NULL) {
19
+			$t = time();
20
+		}
21
+		return gmstrftime('%Y%m%dT%H%M%SZ', $t);
22
+	}
23 23
 
24
-    function generate_guid() {
25
-        // Implemented as per the Network Working Group draft on UUIDs and GUIDs
24
+	function generate_guid() {
25
+		// Implemented as per the Network Working Group draft on UUIDs and GUIDs
26 26
     
27
-        // These two octets get special treatment
28
-        $time_hi_and_version       = sprintf('%02x', (1 << 6) + mt_rand(0, 15)); // 0100 plus 4 random bits
29
-        $clock_seq_hi_and_reserved = sprintf('%02x', (1 << 7) + mt_rand(0, 63)); // 10 plus 6 random bits
27
+		// These two octets get special treatment
28
+		$time_hi_and_version       = sprintf('%02x', (1 << 6) + mt_rand(0, 15)); // 0100 plus 4 random bits
29
+		$clock_seq_hi_and_reserved = sprintf('%02x', (1 << 7) + mt_rand(0, 63)); // 10 plus 6 random bits
30 30
     
31
-        // Need another 14 random octects
32
-        $pool = '';
33
-        for($i = 0; $i < 7; ++$i) {
34
-            $pool .= sprintf('%04x', mt_rand(0, 65535));
35
-        }
31
+		// Need another 14 random octects
32
+		$pool = '';
33
+		for($i = 0; $i < 7; ++$i) {
34
+			$pool .= sprintf('%04x', mt_rand(0, 65535));
35
+		}
36 36
     
37
-        // time_low = 4 octets
38
-        $random  = substr($pool, 0, 8).'-';
37
+		// time_low = 4 octets
38
+		$random  = substr($pool, 0, 8).'-';
39 39
     
40
-        // time_mid = 2 octets
41
-        $random .= substr($pool, 8, 4).'-';
40
+		// time_mid = 2 octets
41
+		$random .= substr($pool, 8, 4).'-';
42 42
     
43
-        // time_high_and_version = 2 octets
44
-        $random .= $time_hi_and_version.substr($pool, 12, 2).'-';
43
+		// time_high_and_version = 2 octets
44
+		$random .= $time_hi_and_version.substr($pool, 12, 2).'-';
45 45
     
46
-        // clock_seq_high_and_reserved = 1 octet
47
-        $random .= $clock_seq_hi_and_reserved;
46
+		// clock_seq_high_and_reserved = 1 octet
47
+		$random .= $clock_seq_hi_and_reserved;
48 48
     
49
-        // clock_seq_low = 1 octet
50
-        $random .= substr($pool, 13, 2).'-';
49
+		// clock_seq_low = 1 octet
50
+		$random .= substr($pool, 13, 2).'-';
51 51
     
52
-        // node = 6 octets
53
-        $random .= substr($pool, 14, 12);
52
+		// node = 6 octets
53
+		$random .= substr($pool, 14, 12);
54 54
     
55
-        return $random;
56
-    }
55
+		return $random;
56
+	}
57 57
 }
58 58
 
59 59
 ?>
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 
16 16
 class Bennu {
17 17
     function timestamp_to_datetime($t = NULL) {
18
-        if($t === NULL) {
18
+        if ($t === NULL) {
19 19
             $t = time();
20 20
         }
21 21
         return gmstrftime('%Y%m%dT%H%M%SZ', $t);
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
     
31 31
         // Need another 14 random octects
32 32
         $pool = '';
33
-        for($i = 0; $i < 7; ++$i) {
33
+        for ($i = 0; $i < 7; ++$i) {
34 34
             $pool .= sprintf('%04x', mt_rand(0, 65535));
35 35
         }
36 36
     
Please login to merge, or discard this patch.
phpicalendar/lib/bennu/iCalendar_components.php 3 patches
Indentation   +342 added lines, -342 removed lines patch added patch discarded remove patch
@@ -14,377 +14,377 @@
 block discarded – undo
14 14
  */
15 15
 
16 16
 class iCalendar_component {
17
-    var $name             = NULL;
18
-    var $properties       = NULL;
19
-    var $components       = NULL;
20
-    var $valid_properties = NULL;
21
-    var $valid_components = NULL;
22
-
23
-    function iCalendar_component() {
24
-        $this->construct();
25
-    }
26
-
27
-    function construct() {
28
-        // Initialize the components array
29
-        if(empty($this->components)) {
30
-            $this->components = array();
31
-            foreach($this->valid_components as $name) {
32
-                $this->components[$name] = array();
33
-            }
34
-        }
35
-    }
36
-
37
-    function get_name() {
38
-        return $this->name;
39
-    }
40
-
41
-    function add_property($name, $value = NULL, $parameters = NULL) {
42
-
43
-        // Uppercase first of all
44
-        $name = strtoupper($name);
45
-
46
-        // Are we trying to add a valid property?
47
-        $xname = false;
48
-        if(!isset($this->valid_properties[$name])) {
49
-            // If not, is it an x-name as per RFC 2445?
50
-            if(!rfc2445_is_xname($name)) {
51
-                return false;
52
-            }
53
-            // Since this is an xname, all components are supposed to allow this property
54
-            $xname = true;
55
-        }
56
-
57
-        // Create a property object of the correct class
58
-        if($xname) {
59
-            $property = new iCalendar_property_x;
60
-            $property->set_name($name);
61
-        }
62
-        else {
63
-            $classname = 'iCalendar_property_'.strtolower(str_replace('-', '_', $name));
64
-            $property = new $classname;
65
-        }
66
-
67
-        // If $value is NULL, then this property must define a default value.
68
-        if($value === NULL) {
69
-            $value = $property->default_value();
70
-            if($value === NULL) {
71
-                return false;
72
-            }
73
-        }
74
-
75
-        // Set this property's parent component to ourselves, because some
76
-        // properties behave differently according to what component they apply to.
77
-        $property->set_parent_component($this->name);
78
-
79
-        // Set parameters before value; this helps with some properties which
80
-        // accept a VALUE parameter, and thus change their default value type.
81
-
82
-        // The parameters must be valid according to property specifications
83
-        if(!empty($parameters)) {
84
-            foreach($parameters as $paramname => $paramvalue) {
85
-                if(!$property->set_parameter($paramname, $paramvalue)) {
86
-                    return false;
87
-                }
88
-            }
89
-
90
-            // Some parameters interact among themselves (e.g. ENCODING and VALUE)
91
-            // so make sure that after the dust settles, these invariants hold true
92
-            if(!$property->invariant_holds()) {
93
-                return false;
94
-            }
95
-        }
96
-
97
-        // $value MUST be valid according to the property data type
98
-        if(!$property->set_value($value)) {
99
-            return false;
100
-        }
101
-
102
-        // If this property is restricted to only once, blindly overwrite value
103
-        if(!$xname && $this->valid_properties[$name] & RFC2445_ONCE) {
104
-            $this->properties[$name] = array($property);
105
-        }
106
-
107
-        // Otherwise add it to the instance array for this property
108
-        else {
109
-            $this->properties[$name][] = $property;
110
-        }
111
-
112
-        // Finally: after all these, does the component invariant hold?
113
-        if(!$this->invariant_holds()) {
114
-            // If not, completely undo the property addition
115
-            array_pop($this->properties[$name]);
116
-            if(empty($this->properties[$name])) {
117
-                unset($this->properties[$name]);
118
-            }
119
-            return false;
120
-        }
121
-
122
-        return true;        
17
+	var $name             = NULL;
18
+	var $properties       = NULL;
19
+	var $components       = NULL;
20
+	var $valid_properties = NULL;
21
+	var $valid_components = NULL;
22
+
23
+	function iCalendar_component() {
24
+		$this->construct();
25
+	}
26
+
27
+	function construct() {
28
+		// Initialize the components array
29
+		if(empty($this->components)) {
30
+			$this->components = array();
31
+			foreach($this->valid_components as $name) {
32
+				$this->components[$name] = array();
33
+			}
34
+		}
35
+	}
36
+
37
+	function get_name() {
38
+		return $this->name;
39
+	}
40
+
41
+	function add_property($name, $value = NULL, $parameters = NULL) {
42
+
43
+		// Uppercase first of all
44
+		$name = strtoupper($name);
45
+
46
+		// Are we trying to add a valid property?
47
+		$xname = false;
48
+		if(!isset($this->valid_properties[$name])) {
49
+			// If not, is it an x-name as per RFC 2445?
50
+			if(!rfc2445_is_xname($name)) {
51
+				return false;
52
+			}
53
+			// Since this is an xname, all components are supposed to allow this property
54
+			$xname = true;
55
+		}
56
+
57
+		// Create a property object of the correct class
58
+		if($xname) {
59
+			$property = new iCalendar_property_x;
60
+			$property->set_name($name);
61
+		}
62
+		else {
63
+			$classname = 'iCalendar_property_'.strtolower(str_replace('-', '_', $name));
64
+			$property = new $classname;
65
+		}
66
+
67
+		// If $value is NULL, then this property must define a default value.
68
+		if($value === NULL) {
69
+			$value = $property->default_value();
70
+			if($value === NULL) {
71
+				return false;
72
+			}
73
+		}
74
+
75
+		// Set this property's parent component to ourselves, because some
76
+		// properties behave differently according to what component they apply to.
77
+		$property->set_parent_component($this->name);
78
+
79
+		// Set parameters before value; this helps with some properties which
80
+		// accept a VALUE parameter, and thus change their default value type.
81
+
82
+		// The parameters must be valid according to property specifications
83
+		if(!empty($parameters)) {
84
+			foreach($parameters as $paramname => $paramvalue) {
85
+				if(!$property->set_parameter($paramname, $paramvalue)) {
86
+					return false;
87
+				}
88
+			}
89
+
90
+			// Some parameters interact among themselves (e.g. ENCODING and VALUE)
91
+			// so make sure that after the dust settles, these invariants hold true
92
+			if(!$property->invariant_holds()) {
93
+				return false;
94
+			}
95
+		}
96
+
97
+		// $value MUST be valid according to the property data type
98
+		if(!$property->set_value($value)) {
99
+			return false;
100
+		}
101
+
102
+		// If this property is restricted to only once, blindly overwrite value
103
+		if(!$xname && $this->valid_properties[$name] & RFC2445_ONCE) {
104
+			$this->properties[$name] = array($property);
105
+		}
106
+
107
+		// Otherwise add it to the instance array for this property
108
+		else {
109
+			$this->properties[$name][] = $property;
110
+		}
111
+
112
+		// Finally: after all these, does the component invariant hold?
113
+		if(!$this->invariant_holds()) {
114
+			// If not, completely undo the property addition
115
+			array_pop($this->properties[$name]);
116
+			if(empty($this->properties[$name])) {
117
+				unset($this->properties[$name]);
118
+			}
119
+			return false;
120
+		}
121
+
122
+		return true;        
123 123
         
124
-    }
125
-
126
-    function add_component($component) {
127
-
128
-        // With the detailed interface, you can add only components with this function
129
-        if(!is_object($component) || !is_subclass_of($component, 'iCalendar_component')) {
130
-            return false;
131
-        }
132
-
133
-        $name = $component->get_name();
134
-
135
-        // Only valid components as specified by this component are allowed
136
-        if(!in_array($name, $this->valid_components)) {
137
-            return false;
138
-        }
139
-
140
-        // Add it
141
-        $this->components[$name][] = $component;
142
-
143
-        return true;
144
-    }
145
-
146
-    function get_property_list($name) {
147
-    }
148
-
149
-    function invariant_holds() {
150
-        return true;
151
-    }
152
-
153
-    function is_valid() {
154
-        // If we have any child components, check that they are all valid
155
-        if(!empty($this->components)) {
156
-            foreach($this->components as $component => $instances) {
157
-                foreach($instances as $number => $instance) {
158
-                    if(!$instance->is_valid()) {
159
-                        return false;
160
-                    }
161
-                }
162
-            }
163
-        }
164
-
165
-        // Finally, check the valid property list for any mandatory properties
166
-        // that have not been set and do not have a default value
167
-        foreach($this->valid_properties as $property => $propdata) {
168
-            if(($propdata & RFC2445_REQUIRED) && empty($this->properties[$property])) {
169
-                $classname = 'iCalendar_property_'.strtolower(str_replace('-', '_', $property));
170
-                $object    = new $classname;
171
-                if($object->default_value() === NULL) {
172
-                    return false;
173
-                }
174
-                unset($object);
175
-            }
176
-        }
177
-
178
-        return true;
179
-    }
124
+	}
125
+
126
+	function add_component($component) {
127
+
128
+		// With the detailed interface, you can add only components with this function
129
+		if(!is_object($component) || !is_subclass_of($component, 'iCalendar_component')) {
130
+			return false;
131
+		}
132
+
133
+		$name = $component->get_name();
134
+
135
+		// Only valid components as specified by this component are allowed
136
+		if(!in_array($name, $this->valid_components)) {
137
+			return false;
138
+		}
139
+
140
+		// Add it
141
+		$this->components[$name][] = $component;
142
+
143
+		return true;
144
+	}
145
+
146
+	function get_property_list($name) {
147
+	}
148
+
149
+	function invariant_holds() {
150
+		return true;
151
+	}
152
+
153
+	function is_valid() {
154
+		// If we have any child components, check that they are all valid
155
+		if(!empty($this->components)) {
156
+			foreach($this->components as $component => $instances) {
157
+				foreach($instances as $number => $instance) {
158
+					if(!$instance->is_valid()) {
159
+						return false;
160
+					}
161
+				}
162
+			}
163
+		}
164
+
165
+		// Finally, check the valid property list for any mandatory properties
166
+		// that have not been set and do not have a default value
167
+		foreach($this->valid_properties as $property => $propdata) {
168
+			if(($propdata & RFC2445_REQUIRED) && empty($this->properties[$property])) {
169
+				$classname = 'iCalendar_property_'.strtolower(str_replace('-', '_', $property));
170
+				$object    = new $classname;
171
+				if($object->default_value() === NULL) {
172
+					return false;
173
+				}
174
+				unset($object);
175
+			}
176
+		}
177
+
178
+		return true;
179
+	}
180 180
     
181
-    function serialize() {
182
-        // Start tag
183
-        $string = rfc2445_fold('BEGIN:'.$this->name) . RFC2445_CRLF;
184
-
185
-        // List of properties
186
-        if(!empty($this->properties)) {
187
-            foreach($this->properties as $name => $properties) {
188
-                foreach($properties as $property) {
189
-                    $string .= $property->serialize();
190
-                }
191
-            }
192
-        }
193
-
194
-        // List of components
195
-        if(!empty($this->components)) {
196
-            foreach($this->components as $name => $components) {
197
-                foreach($components as $component) {
198
-                    $string .= $component->serialize();
199
-                }
200
-            }
201
-        }
202
-
203
-        // End tag
204
-        $string .= rfc2445_fold('END:'.$this->name) . RFC2445_CRLF;
205
-
206
-        return $string;
207
-    }
181
+	function serialize() {
182
+		// Start tag
183
+		$string = rfc2445_fold('BEGIN:'.$this->name) . RFC2445_CRLF;
184
+
185
+		// List of properties
186
+		if(!empty($this->properties)) {
187
+			foreach($this->properties as $name => $properties) {
188
+				foreach($properties as $property) {
189
+					$string .= $property->serialize();
190
+				}
191
+			}
192
+		}
193
+
194
+		// List of components
195
+		if(!empty($this->components)) {
196
+			foreach($this->components as $name => $components) {
197
+				foreach($components as $component) {
198
+					$string .= $component->serialize();
199
+				}
200
+			}
201
+		}
202
+
203
+		// End tag
204
+		$string .= rfc2445_fold('END:'.$this->name) . RFC2445_CRLF;
205
+
206
+		return $string;
207
+	}
208 208
 }
209 209
 
210 210
 class iCalendar extends iCalendar_component {
211
-    var $name = 'VCALENDAR';
212
-
213
-    function construct() {
214
-        $this->valid_properties = array(
215
-            'CALSCALE'    => RFC2445_OPTIONAL | RFC2445_ONCE,
216
-            'METHOD'      => RFC2445_OPTIONAL | RFC2445_ONCE,
217
-            'PRODID'      => RFC2445_REQUIRED | RFC2445_ONCE,
218
-            'VERSION'     => RFC2445_REQUIRED | RFC2445_ONCE,
219
-            RFC2445_XNAME => RFC2445_OPTIONAL 
220
-        );
221
-
222
-        $this->valid_components = array(
223
-            'VEVENT'
224
-            // TODO: add support for the other component types
225
-            //, 'VTODO', 'VJOURNAL', 'VFREEBUSY', 'VTIMEZONE', 'VALARM'
226
-        );
227
-        parent::construct();
228
-    }
211
+	var $name = 'VCALENDAR';
212
+
213
+	function construct() {
214
+		$this->valid_properties = array(
215
+			'CALSCALE'    => RFC2445_OPTIONAL | RFC2445_ONCE,
216
+			'METHOD'      => RFC2445_OPTIONAL | RFC2445_ONCE,
217
+			'PRODID'      => RFC2445_REQUIRED | RFC2445_ONCE,
218
+			'VERSION'     => RFC2445_REQUIRED | RFC2445_ONCE,
219
+			RFC2445_XNAME => RFC2445_OPTIONAL 
220
+		);
221
+
222
+		$this->valid_components = array(
223
+			'VEVENT'
224
+			// TODO: add support for the other component types
225
+			//, 'VTODO', 'VJOURNAL', 'VFREEBUSY', 'VTIMEZONE', 'VALARM'
226
+		);
227
+		parent::construct();
228
+	}
229 229
 }
230 230
 
231 231
 class iCalendar_event extends iCalendar_component {
232 232
 
233
-    var $name       = 'VEVENT';
234
-    var $properties;
233
+	var $name       = 'VEVENT';
234
+	var $properties;
235 235
     
236
-    function construct() {
236
+	function construct() {
237 237
         
238
-        $this->valid_components = array('VALARM');
239
-
240
-        $this->valid_properties = array(
241
-            'CLASS'          => RFC2445_OPTIONAL | RFC2445_ONCE,
242
-            'CREATED'        => RFC2445_OPTIONAL | RFC2445_ONCE,
243
-            'DESCRIPTION'    => RFC2445_OPTIONAL | RFC2445_ONCE,
244
-            // Standard ambiguous here: in 4.6.1 it says that DTSTAMP in optional,
245
-            // while in 4.8.7.2 it says it's REQUIRED. Go with REQUIRED.
246
-            'DTSTAMP'        => RFC2445_REQUIRED | RFC2445_ONCE,
247
-            // Standard ambiguous here: in 4.6.1 it says that DTSTART in optional,
248
-            // while in 4.8.2.4 it says it's REQUIRED. Go with REQUIRED.
249
-            'DTSTART'        => RFC2445_REQUIRED | RFC2445_ONCE,
250
-            'GEO'            => RFC2445_OPTIONAL | RFC2445_ONCE,
251
-            'LAST-MODIFIED'  => RFC2445_OPTIONAL | RFC2445_ONCE,
252
-            'LOCATION'       => RFC2445_OPTIONAL | RFC2445_ONCE,
253
-            'ORGANIZER'      => RFC2445_OPTIONAL | RFC2445_ONCE,
254
-            'PRIORITY'       => RFC2445_OPTIONAL | RFC2445_ONCE,
255
-            'SEQUENCE'       => RFC2445_OPTIONAL | RFC2445_ONCE,
256
-            'STATUS'         => RFC2445_OPTIONAL | RFC2445_ONCE,
257
-            'SUMMARY'        => RFC2445_OPTIONAL | RFC2445_ONCE,
258
-            'TRANSP'         => RFC2445_OPTIONAL | RFC2445_ONCE,
259
-            // Standard ambiguous here: in 4.6.1 it says that UID in optional,
260
-            // while in 4.8.4.7 it says it's REQUIRED. Go with REQUIRED.
261
-            'UID'            => RFC2445_REQUIRED | RFC2445_ONCE,
262
-            'URL'            => RFC2445_OPTIONAL | RFC2445_ONCE,
263
-            'RECURRENCE-ID'  => RFC2445_OPTIONAL | RFC2445_ONCE,
264
-            'DTEND'          => RFC2445_OPTIONAL | RFC2445_ONCE,
265
-            'DURATION'       => RFC2445_OPTIONAL | RFC2445_ONCE,
266
-            'ATTACH'         => RFC2445_OPTIONAL,
267
-            'ATTENDEE'       => RFC2445_OPTIONAL,
268
-            'CATEGORIES'     => RFC2445_OPTIONAL,
269
-            'COMMENT'        => RFC2445_OPTIONAL,
270
-            'CONTACT'        => RFC2445_OPTIONAL,
271
-            'EXDATE'         => RFC2445_OPTIONAL,
272
-            'EXRULE'         => RFC2445_OPTIONAL,
273
-            'REQUEST-STATUS' => RFC2445_OPTIONAL,
274
-            'RELATED-TO'     => RFC2445_OPTIONAL,
275
-            'RESOURCES'      => RFC2445_OPTIONAL,
276
-            'RDATE'          => RFC2445_OPTIONAL,
277
-            'RRULE'          => RFC2445_OPTIONAL,
278
-            RFC2445_XNAME    => RFC2445_OPTIONAL
279
-        );
280
-
281
-        parent::construct();
282
-    }
283
-
284
-    function invariant_holds() {
285
-        // DTEND and DURATION must not appear together
286
-        if(isset($this->properties['DTEND']) && isset($this->properties['DURATION'])) {
287
-            return false;
288
-        }
238
+		$this->valid_components = array('VALARM');
239
+
240
+		$this->valid_properties = array(
241
+			'CLASS'          => RFC2445_OPTIONAL | RFC2445_ONCE,
242
+			'CREATED'        => RFC2445_OPTIONAL | RFC2445_ONCE,
243
+			'DESCRIPTION'    => RFC2445_OPTIONAL | RFC2445_ONCE,
244
+			// Standard ambiguous here: in 4.6.1 it says that DTSTAMP in optional,
245
+			// while in 4.8.7.2 it says it's REQUIRED. Go with REQUIRED.
246
+			'DTSTAMP'        => RFC2445_REQUIRED | RFC2445_ONCE,
247
+			// Standard ambiguous here: in 4.6.1 it says that DTSTART in optional,
248
+			// while in 4.8.2.4 it says it's REQUIRED. Go with REQUIRED.
249
+			'DTSTART'        => RFC2445_REQUIRED | RFC2445_ONCE,
250
+			'GEO'            => RFC2445_OPTIONAL | RFC2445_ONCE,
251
+			'LAST-MODIFIED'  => RFC2445_OPTIONAL | RFC2445_ONCE,
252
+			'LOCATION'       => RFC2445_OPTIONAL | RFC2445_ONCE,
253
+			'ORGANIZER'      => RFC2445_OPTIONAL | RFC2445_ONCE,
254
+			'PRIORITY'       => RFC2445_OPTIONAL | RFC2445_ONCE,
255
+			'SEQUENCE'       => RFC2445_OPTIONAL | RFC2445_ONCE,
256
+			'STATUS'         => RFC2445_OPTIONAL | RFC2445_ONCE,
257
+			'SUMMARY'        => RFC2445_OPTIONAL | RFC2445_ONCE,
258
+			'TRANSP'         => RFC2445_OPTIONAL | RFC2445_ONCE,
259
+			// Standard ambiguous here: in 4.6.1 it says that UID in optional,
260
+			// while in 4.8.4.7 it says it's REQUIRED. Go with REQUIRED.
261
+			'UID'            => RFC2445_REQUIRED | RFC2445_ONCE,
262
+			'URL'            => RFC2445_OPTIONAL | RFC2445_ONCE,
263
+			'RECURRENCE-ID'  => RFC2445_OPTIONAL | RFC2445_ONCE,
264
+			'DTEND'          => RFC2445_OPTIONAL | RFC2445_ONCE,
265
+			'DURATION'       => RFC2445_OPTIONAL | RFC2445_ONCE,
266
+			'ATTACH'         => RFC2445_OPTIONAL,
267
+			'ATTENDEE'       => RFC2445_OPTIONAL,
268
+			'CATEGORIES'     => RFC2445_OPTIONAL,
269
+			'COMMENT'        => RFC2445_OPTIONAL,
270
+			'CONTACT'        => RFC2445_OPTIONAL,
271
+			'EXDATE'         => RFC2445_OPTIONAL,
272
+			'EXRULE'         => RFC2445_OPTIONAL,
273
+			'REQUEST-STATUS' => RFC2445_OPTIONAL,
274
+			'RELATED-TO'     => RFC2445_OPTIONAL,
275
+			'RESOURCES'      => RFC2445_OPTIONAL,
276
+			'RDATE'          => RFC2445_OPTIONAL,
277
+			'RRULE'          => RFC2445_OPTIONAL,
278
+			RFC2445_XNAME    => RFC2445_OPTIONAL
279
+		);
280
+
281
+		parent::construct();
282
+	}
283
+
284
+	function invariant_holds() {
285
+		// DTEND and DURATION must not appear together
286
+		if(isset($this->properties['DTEND']) && isset($this->properties['DURATION'])) {
287
+			return false;
288
+		}
289 289
 
290 290
         
291
-        if(isset($this->properties['DTEND']) && isset($this->properties['DTSTART'])) {
292
-            // DTEND must be later than DTSTART
293
-            // The standard is not clear on how to hande different value types though
294
-            // TODO: handle this correctly even if the value types are different
295
-            if($this->properties['DTEND'][0]->value <= $this->properties['DTSTART'][0]->value) {
296
-                return false;
297
-            }
298
-
299
-            // DTEND and DTSTART must have the same value type
300
-            if($this->properties['DTEND'][0]->val_type != $this->properties['DTSTART'][0]->val_type) {
301
-                return false;
302
-            }
303
-
304
-        }
305
-        return true;
306
-    }
291
+		if(isset($this->properties['DTEND']) && isset($this->properties['DTSTART'])) {
292
+			// DTEND must be later than DTSTART
293
+			// The standard is not clear on how to hande different value types though
294
+			// TODO: handle this correctly even if the value types are different
295
+			if($this->properties['DTEND'][0]->value <= $this->properties['DTSTART'][0]->value) {
296
+				return false;
297
+			}
298
+
299
+			// DTEND and DTSTART must have the same value type
300
+			if($this->properties['DTEND'][0]->val_type != $this->properties['DTSTART'][0]->val_type) {
301
+				return false;
302
+			}
303
+
304
+		}
305
+		return true;
306
+	}
307 307
 }
308 308
 
309 309
 class iCalendar_todo extends iCalendar_component {
310
-    var $name       = 'VTODO';
311
-    var $properties;
312
-
313
-    function construct() {
314
-
315
-        $this->properties = array(
316
-            'class'       => RFC2445_OPTIONAL | RFC2445_ONCE,
317
-            'completed'   => RFC2445_OPTIONAL | RFC2445_ONCE,
318
-            'created'     => RFC2445_OPTIONAL | RFC2445_ONCE,
319
-            'description' => RFC2445_OPTIONAL | RFC2445_ONCE,
320
-            'dtstamp'     => RFC2445_OPTIONAL | RFC2445_ONCE,
321
-            'dtstart'     => RFC2445_OPTIONAL | RFC2445_ONCE,
322
-            'geo'         => RFC2445_OPTIONAL | RFC2445_ONCE,
323
-            'last-modified'    => RFC2445_OPTIONAL | RFC2445_ONCE,
324
-            'location'    => RFC2445_OPTIONAL | RFC2445_ONCE,
325
-            'organizer'   => RFC2445_OPTIONAL | RFC2445_ONCE,
326
-            'percent'     => RFC2445_OPTIONAL | RFC2445_ONCE,
327
-            'priority'    => RFC2445_OPTIONAL | RFC2445_ONCE,
328
-            'recurid'     => RFC2445_OPTIONAL | RFC2445_ONCE,
329
-            'sequence'    => RFC2445_OPTIONAL | RFC2445_ONCE,
330
-            'status'      => RFC2445_OPTIONAL | RFC2445_ONCE,
331
-            'summary'     => RFC2445_OPTIONAL | RFC2445_ONCE,
332
-            'uid'         => RFC2445_OPTIONAL | RFC2445_ONCE,
333
-            'url'         => RFC2445_OPTIONAL | RFC2445_ONCE,
334
-            'due'         => RFC2445_OPTIONAL | RFC2445_ONCE,
335
-            'duration'    => RFC2445_OPTIONAL | RFC2445_ONCE,
336
-            'attach'      => RFC2445_OPTIONAL,
337
-            'attendee'    => RFC2445_OPTIONAL,
338
-            'categories'  => RFC2445_OPTIONAL,
339
-            'comment'     => RFC2445_OPTIONAL,
340
-            'contact'     => RFC2445_OPTIONAL,
341
-            'exdate'      => RFC2445_OPTIONAL,
342
-            'exrule'      => RFC2445_OPTIONAL,
343
-            'rstatus'     => RFC2445_OPTIONAL,
344
-            'related'     => RFC2445_OPTIONAL,
345
-            'resources'   => RFC2445_OPTIONAL,
346
-            'rdate'       => RFC2445_OPTIONAL,
347
-            'rrule'       => RFC2445_OPTIONAL,
348
-            'xprop'       => RFC2445_OPTIONAL
349
-        );
350
-
351
-        parent::construct();
352
-        // TODO:
353
-        // either 'due' or 'duration' may appear in  a 'eventprop', but 'due'
354
-        // and 'duration' MUST NOT occur in the same 'eventprop'
355
-    }
310
+	var $name       = 'VTODO';
311
+	var $properties;
312
+
313
+	function construct() {
314
+
315
+		$this->properties = array(
316
+			'class'       => RFC2445_OPTIONAL | RFC2445_ONCE,
317
+			'completed'   => RFC2445_OPTIONAL | RFC2445_ONCE,
318
+			'created'     => RFC2445_OPTIONAL | RFC2445_ONCE,
319
+			'description' => RFC2445_OPTIONAL | RFC2445_ONCE,
320
+			'dtstamp'     => RFC2445_OPTIONAL | RFC2445_ONCE,
321
+			'dtstart'     => RFC2445_OPTIONAL | RFC2445_ONCE,
322
+			'geo'         => RFC2445_OPTIONAL | RFC2445_ONCE,
323
+			'last-modified'    => RFC2445_OPTIONAL | RFC2445_ONCE,
324
+			'location'    => RFC2445_OPTIONAL | RFC2445_ONCE,
325
+			'organizer'   => RFC2445_OPTIONAL | RFC2445_ONCE,
326
+			'percent'     => RFC2445_OPTIONAL | RFC2445_ONCE,
327
+			'priority'    => RFC2445_OPTIONAL | RFC2445_ONCE,
328
+			'recurid'     => RFC2445_OPTIONAL | RFC2445_ONCE,
329
+			'sequence'    => RFC2445_OPTIONAL | RFC2445_ONCE,
330
+			'status'      => RFC2445_OPTIONAL | RFC2445_ONCE,
331
+			'summary'     => RFC2445_OPTIONAL | RFC2445_ONCE,
332
+			'uid'         => RFC2445_OPTIONAL | RFC2445_ONCE,
333
+			'url'         => RFC2445_OPTIONAL | RFC2445_ONCE,
334
+			'due'         => RFC2445_OPTIONAL | RFC2445_ONCE,
335
+			'duration'    => RFC2445_OPTIONAL | RFC2445_ONCE,
336
+			'attach'      => RFC2445_OPTIONAL,
337
+			'attendee'    => RFC2445_OPTIONAL,
338
+			'categories'  => RFC2445_OPTIONAL,
339
+			'comment'     => RFC2445_OPTIONAL,
340
+			'contact'     => RFC2445_OPTIONAL,
341
+			'exdate'      => RFC2445_OPTIONAL,
342
+			'exrule'      => RFC2445_OPTIONAL,
343
+			'rstatus'     => RFC2445_OPTIONAL,
344
+			'related'     => RFC2445_OPTIONAL,
345
+			'resources'   => RFC2445_OPTIONAL,
346
+			'rdate'       => RFC2445_OPTIONAL,
347
+			'rrule'       => RFC2445_OPTIONAL,
348
+			'xprop'       => RFC2445_OPTIONAL
349
+		);
350
+
351
+		parent::construct();
352
+		// TODO:
353
+		// either 'due' or 'duration' may appear in  a 'eventprop', but 'due'
354
+		// and 'duration' MUST NOT occur in the same 'eventprop'
355
+	}
356 356
 }
357 357
 
358 358
 class iCalendar_journal extends iCalendar_component {
359
-    // TODO: implement
359
+	// TODO: implement
360 360
 }
361 361
 
362 362
 class iCalendar_freebusy extends iCalendar_component {
363
-    // TODO: implement
363
+	// TODO: implement
364 364
 }
365 365
 
366 366
 class iCalendar_alarm extends iCalendar_component {
367
-    // TODO: implement
367
+	// TODO: implement
368 368
 }
369 369
 
370 370
 class iCalendar_timezone extends iCalendar_component {
371
-    var $name       = 'VTIMEZONE';
372
-    var $properties;
373
-
374
-    function construct() {
375
-
376
-        $this->properties = array(
377
-            'tzid'        => RFC2445_REQUIRED | RFC2445_ONCE,
378
-            'last-modified'    => RFC2445_OPTIONAL | RFC2445_ONCE,
379
-            'tzurl'       => RFC2445_OPTIONAL | RFC2445_ONCE,
380
-            // TODO: the next two are components of their own!
381
-            'standardc'   => RFC2445_REQUIRED,
382
-            'daylightc'   => RFC2445_REQUIRED,
383
-            'x-prop'      => RFC2445_OPTIONAL
384
-        );
371
+	var $name       = 'VTIMEZONE';
372
+	var $properties;
373
+
374
+	function construct() {
375
+
376
+		$this->properties = array(
377
+			'tzid'        => RFC2445_REQUIRED | RFC2445_ONCE,
378
+			'last-modified'    => RFC2445_OPTIONAL | RFC2445_ONCE,
379
+			'tzurl'       => RFC2445_OPTIONAL | RFC2445_ONCE,
380
+			// TODO: the next two are components of their own!
381
+			'standardc'   => RFC2445_REQUIRED,
382
+			'daylightc'   => RFC2445_REQUIRED,
383
+			'x-prop'      => RFC2445_OPTIONAL
384
+		);
385 385
         
386
-        parent::construct();
387
-    }
386
+		parent::construct();
387
+	}
388 388
 }
389 389
 
390 390
 // REMINDER: DTEND must be later than DTSTART for all components which support both
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -26,9 +26,9 @@  discard block
 block discarded – undo
26 26
 
27 27
     function construct() {
28 28
         // Initialize the components array
29
-        if(empty($this->components)) {
29
+        if (empty($this->components)) {
30 30
             $this->components = array();
31
-            foreach($this->valid_components as $name) {
31
+            foreach ($this->valid_components as $name) {
32 32
                 $this->components[$name] = array();
33 33
             }
34 34
         }
@@ -45,9 +45,9 @@  discard block
 block discarded – undo
45 45
 
46 46
         // Are we trying to add a valid property?
47 47
         $xname = false;
48
-        if(!isset($this->valid_properties[$name])) {
48
+        if (!isset($this->valid_properties[$name])) {
49 49
             // If not, is it an x-name as per RFC 2445?
50
-            if(!rfc2445_is_xname($name)) {
50
+            if (!rfc2445_is_xname($name)) {
51 51
                 return false;
52 52
             }
53 53
             // Since this is an xname, all components are supposed to allow this property
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
         }
56 56
 
57 57
         // Create a property object of the correct class
58
-        if($xname) {
58
+        if ($xname) {
59 59
             $property = new iCalendar_property_x;
60 60
             $property->set_name($name);
61 61
         }
@@ -65,9 +65,9 @@  discard block
 block discarded – undo
65 65
         }
66 66
 
67 67
         // If $value is NULL, then this property must define a default value.
68
-        if($value === NULL) {
68
+        if ($value === NULL) {
69 69
             $value = $property->default_value();
70
-            if($value === NULL) {
70
+            if ($value === NULL) {
71 71
                 return false;
72 72
             }
73 73
         }
@@ -80,27 +80,27 @@  discard block
 block discarded – undo
80 80
         // accept a VALUE parameter, and thus change their default value type.
81 81
 
82 82
         // The parameters must be valid according to property specifications
83
-        if(!empty($parameters)) {
84
-            foreach($parameters as $paramname => $paramvalue) {
85
-                if(!$property->set_parameter($paramname, $paramvalue)) {
83
+        if (!empty($parameters)) {
84
+            foreach ($parameters as $paramname => $paramvalue) {
85
+                if (!$property->set_parameter($paramname, $paramvalue)) {
86 86
                     return false;
87 87
                 }
88 88
             }
89 89
 
90 90
             // Some parameters interact among themselves (e.g. ENCODING and VALUE)
91 91
             // so make sure that after the dust settles, these invariants hold true
92
-            if(!$property->invariant_holds()) {
92
+            if (!$property->invariant_holds()) {
93 93
                 return false;
94 94
             }
95 95
         }
96 96
 
97 97
         // $value MUST be valid according to the property data type
98
-        if(!$property->set_value($value)) {
98
+        if (!$property->set_value($value)) {
99 99
             return false;
100 100
         }
101 101
 
102 102
         // If this property is restricted to only once, blindly overwrite value
103
-        if(!$xname && $this->valid_properties[$name] & RFC2445_ONCE) {
103
+        if (!$xname && $this->valid_properties[$name] & RFC2445_ONCE) {
104 104
             $this->properties[$name] = array($property);
105 105
         }
106 106
 
@@ -110,10 +110,10 @@  discard block
 block discarded – undo
110 110
         }
111 111
 
112 112
         // Finally: after all these, does the component invariant hold?
113
-        if(!$this->invariant_holds()) {
113
+        if (!$this->invariant_holds()) {
114 114
             // If not, completely undo the property addition
115 115
             array_pop($this->properties[$name]);
116
-            if(empty($this->properties[$name])) {
116
+            if (empty($this->properties[$name])) {
117 117
                 unset($this->properties[$name]);
118 118
             }
119 119
             return false;
@@ -126,14 +126,14 @@  discard block
 block discarded – undo
126 126
     function add_component($component) {
127 127
 
128 128
         // With the detailed interface, you can add only components with this function
129
-        if(!is_object($component) || !is_subclass_of($component, 'iCalendar_component')) {
129
+        if (!is_object($component) || !is_subclass_of($component, 'iCalendar_component')) {
130 130
             return false;
131 131
         }
132 132
 
133 133
         $name = $component->get_name();
134 134
 
135 135
         // Only valid components as specified by this component are allowed
136
-        if(!in_array($name, $this->valid_components)) {
136
+        if (!in_array($name, $this->valid_components)) {
137 137
             return false;
138 138
         }
139 139
 
@@ -152,10 +152,10 @@  discard block
 block discarded – undo
152 152
 
153 153
     function is_valid() {
154 154
         // If we have any child components, check that they are all valid
155
-        if(!empty($this->components)) {
156
-            foreach($this->components as $component => $instances) {
157
-                foreach($instances as $number => $instance) {
158
-                    if(!$instance->is_valid()) {
155
+        if (!empty($this->components)) {
156
+            foreach ($this->components as $component => $instances) {
157
+                foreach ($instances as $number => $instance) {
158
+                    if (!$instance->is_valid()) {
159 159
                         return false;
160 160
                     }
161 161
                 }
@@ -164,11 +164,11 @@  discard block
 block discarded – undo
164 164
 
165 165
         // Finally, check the valid property list for any mandatory properties
166 166
         // that have not been set and do not have a default value
167
-        foreach($this->valid_properties as $property => $propdata) {
168
-            if(($propdata & RFC2445_REQUIRED) && empty($this->properties[$property])) {
167
+        foreach ($this->valid_properties as $property => $propdata) {
168
+            if (($propdata & RFC2445_REQUIRED) && empty($this->properties[$property])) {
169 169
                 $classname = 'iCalendar_property_'.strtolower(str_replace('-', '_', $property));
170 170
                 $object    = new $classname;
171
-                if($object->default_value() === NULL) {
171
+                if ($object->default_value() === NULL) {
172 172
                     return false;
173 173
                 }
174 174
                 unset($object);
@@ -180,28 +180,28 @@  discard block
 block discarded – undo
180 180
     
181 181
     function serialize() {
182 182
         // Start tag
183
-        $string = rfc2445_fold('BEGIN:'.$this->name) . RFC2445_CRLF;
183
+        $string = rfc2445_fold('BEGIN:'.$this->name).RFC2445_CRLF;
184 184
 
185 185
         // List of properties
186
-        if(!empty($this->properties)) {
187
-            foreach($this->properties as $name => $properties) {
188
-                foreach($properties as $property) {
186
+        if (!empty($this->properties)) {
187
+            foreach ($this->properties as $name => $properties) {
188
+                foreach ($properties as $property) {
189 189
                     $string .= $property->serialize();
190 190
                 }
191 191
             }
192 192
         }
193 193
 
194 194
         // List of components
195
-        if(!empty($this->components)) {
196
-            foreach($this->components as $name => $components) {
197
-                foreach($components as $component) {
195
+        if (!empty($this->components)) {
196
+            foreach ($this->components as $name => $components) {
197
+                foreach ($components as $component) {
198 198
                     $string .= $component->serialize();
199 199
                 }
200 200
             }
201 201
         }
202 202
 
203 203
         // End tag
204
-        $string .= rfc2445_fold('END:'.$this->name) . RFC2445_CRLF;
204
+        $string .= rfc2445_fold('END:'.$this->name).RFC2445_CRLF;
205 205
 
206 206
         return $string;
207 207
     }
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 
231 231
 class iCalendar_event extends iCalendar_component {
232 232
 
233
-    var $name       = 'VEVENT';
233
+    var $name = 'VEVENT';
234 234
     var $properties;
235 235
     
236 236
     function construct() {
@@ -283,21 +283,21 @@  discard block
 block discarded – undo
283 283
 
284 284
     function invariant_holds() {
285 285
         // DTEND and DURATION must not appear together
286
-        if(isset($this->properties['DTEND']) && isset($this->properties['DURATION'])) {
286
+        if (isset($this->properties['DTEND']) && isset($this->properties['DURATION'])) {
287 287
             return false;
288 288
         }
289 289
 
290 290
         
291
-        if(isset($this->properties['DTEND']) && isset($this->properties['DTSTART'])) {
291
+        if (isset($this->properties['DTEND']) && isset($this->properties['DTSTART'])) {
292 292
             // DTEND must be later than DTSTART
293 293
             // The standard is not clear on how to hande different value types though
294 294
             // TODO: handle this correctly even if the value types are different
295
-            if($this->properties['DTEND'][0]->value <= $this->properties['DTSTART'][0]->value) {
295
+            if ($this->properties['DTEND'][0]->value <= $this->properties['DTSTART'][0]->value) {
296 296
                 return false;
297 297
             }
298 298
 
299 299
             // DTEND and DTSTART must have the same value type
300
-            if($this->properties['DTEND'][0]->val_type != $this->properties['DTSTART'][0]->val_type) {
300
+            if ($this->properties['DTEND'][0]->val_type != $this->properties['DTSTART'][0]->val_type) {
301 301
                 return false;
302 302
             }
303 303
 
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
 }
308 308
 
309 309
 class iCalendar_todo extends iCalendar_component {
310
-    var $name       = 'VTODO';
310
+    var $name = 'VTODO';
311 311
     var $properties;
312 312
 
313 313
     function construct() {
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
 }
369 369
 
370 370
 class iCalendar_timezone extends iCalendar_component {
371
-    var $name       = 'VTIMEZONE';
371
+    var $name = 'VTIMEZONE';
372 372
     var $properties;
373 373
 
374 374
     function construct() {
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -58,8 +58,7 @@
 block discarded – undo
58 58
         if($xname) {
59 59
             $property = new iCalendar_property_x;
60 60
             $property->set_name($name);
61
-        }
62
-        else {
61
+        } else {
63 62
             $classname = 'iCalendar_property_'.strtolower(str_replace('-', '_', $name));
64 63
             $property = new $classname;
65 64
         }
Please login to merge, or discard this patch.
phpicalendar/calendars/publish.php 3 patches
Switch Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -129,92 +129,92 @@
 block discarded – undo
129 129
 
130 130
 switch ($_SERVER['REQUEST_METHOD']){
131 131
 	// unpublishing
132
-	case 'DELETE':
133
-		// get calendar filename
134
-		$calendar_file = $calendar_path.substr($_SERVER['REQUEST_URI'] , ( strrpos($_SERVER['REQUEST_URI'], '/') + 1) ) ;
135
-		$calendar_file = urldecode($calendar_file);
136
-		logmsg('received request to delete '.$calendar_file);
137
-		// remove calendar file
138
-		if(!unlink($calendar_file)){
139
-			logmsg('unable to delete the calendar file');
140
-		}else{
141
-			logmsg('deleted');
142
-		}
143
-		break;
144
-	// publishing
145
-	case 'PUT':
146
-		logmsg('PUT request');
147
-		// get calendar data
148
-		# php://input allows you to read raw POST data
149
-		if($datain = fopen('php://input','r')){
150
-			while(!@feof($datain)){
151
-				$data .= fgets($datain,4096);
152
-			}
153
-			@fclose($datain);
154
-		}else{
155
-			logmsg('unable to read input data');
156
-		}
157
-		if(isset($data)){
158
-			if (isset($_SERVER['PATH_INFO'])) {
159
-				preg_match("/\/([\w\-\.\+ ]*).ics/i",$_SERVER['PATH_INFO'],$matches);
160
-				$calendar_name = urldecode($matches[1]);
132
+		case 'DELETE':
133
+			// get calendar filename
134
+			$calendar_file = $calendar_path.substr($_SERVER['REQUEST_URI'] , ( strrpos($_SERVER['REQUEST_URI'], '/') + 1) ) ;
135
+			$calendar_file = urldecode($calendar_file);
136
+			logmsg('received request to delete '.$calendar_file);
137
+			// remove calendar file
138
+			if(!unlink($calendar_file)){
139
+				logmsg('unable to delete the calendar file');
140
+			}else{
141
+				logmsg('deleted');
161 142
 			}
162
-			// If we don't have it from path info, use the supplied calendar name
163
-			if( ! isset($calendar_name) ) {
164
-				$cal_arr = explode("\n",$data);
165
-				foreach($cal_arr as $k => $v){
166
-					if(strstr($v,'X-WR-CALNAME:')){
167
-						$arr = explode(':',$v);
168
-						$calendar_name = trim($arr[1]);
169
-						break;
170
-					}
143
+			break;
144
+		// publishing
145
+		case 'PUT':
146
+			logmsg('PUT request');
147
+			// get calendar data
148
+			# php://input allows you to read raw POST data
149
+			if($datain = fopen('php://input','r')){
150
+				while(!@feof($datain)){
151
+					$data .= fgets($datain,4096);
171 152
 				}
172
-			}
173
-			logmsg('Received request to update: ' . $calendar_name);
174
-			// Remove any invalid characters from the filename
175
-			$calendar_name = preg_replace( "/[^\w\.\- ]/", '', $calendar_name );
176
-			if( ( ! isset($calendar_name) ) || ( $calendar_name == '' ) ) {
177
-				header('HTTP/1.1 401 Invalid calendar name');
178
-				header('WWW-Authenticate: Basic realm="ERROR: Invalid calendar name."');
179
-				echo 'Invalid calendar name.';
180
-			}
181
-			// If we don't have a name, assume default
182
-			$calendar_name = isset($calendar_name) ? $calendar_name : 'default';
183
-			logmsg('Updating calendar: ' . $calendar_name);
184
-			// If this is Apple iCal, an event with a blank summary is private - mark as such
185
-			if( preg_match( "/Apple.*iCal/", $_SERVER['HTTP_USER_AGENT'] ) ) {
186
-				$data = preg_replace(
187
-					"/^\s*SUMMARY:\s*$/m",
188
-					"SUMMARY: **PRIVATE**\nCLASS:PRIVATE",
189
-					$data
190
-				);
191
-			}
192
-			// write to file
193
-			if($dataout = fopen($calendar_path.$calendar_name.'.ics','w+')){
194
-				fputs($dataout, $data, strlen($data) );
195
-				@fclose($dataout);
153
+				@fclose($datain);
196 154
 			}else{
197
-				logmsg( 'could not open file '.$calendar_path.$calendar_name.'.ics' );
155
+				logmsg('unable to read input data');
198 156
 			}
157
+			if(isset($data)){
158
+				if (isset($_SERVER['PATH_INFO'])) {
159
+					preg_match("/\/([\w\-\.\+ ]*).ics/i",$_SERVER['PATH_INFO'],$matches);
160
+					$calendar_name = urldecode($matches[1]);
161
+				}
162
+				// If we don't have it from path info, use the supplied calendar name
163
+				if( ! isset($calendar_name) ) {
164
+					$cal_arr = explode("\n",$data);
165
+					foreach($cal_arr as $k => $v){
166
+						if(strstr($v,'X-WR-CALNAME:')){
167
+							$arr = explode(':',$v);
168
+							$calendar_name = trim($arr[1]);
169
+							break;
170
+						}
171
+					}
172
+				}
173
+				logmsg('Received request to update: ' . $calendar_name);
174
+				// Remove any invalid characters from the filename
175
+				$calendar_name = preg_replace( "/[^\w\.\- ]/", '', $calendar_name );
176
+				if( ( ! isset($calendar_name) ) || ( $calendar_name == '' ) ) {
177
+					header('HTTP/1.1 401 Invalid calendar name');
178
+					header('WWW-Authenticate: Basic realm="ERROR: Invalid calendar name."');
179
+					echo 'Invalid calendar name.';
180
+				}
181
+				// If we don't have a name, assume default
182
+				$calendar_name = isset($calendar_name) ? $calendar_name : 'default';
183
+				logmsg('Updating calendar: ' . $calendar_name);
184
+				// If this is Apple iCal, an event with a blank summary is private - mark as such
185
+				if( preg_match( "/Apple.*iCal/", $_SERVER['HTTP_USER_AGENT'] ) ) {
186
+					$data = preg_replace(
187
+						"/^\s*SUMMARY:\s*$/m",
188
+						"SUMMARY: **PRIVATE**\nCLASS:PRIVATE",
189
+						$data
190
+					);
191
+				}
192
+				// write to file
193
+				if($dataout = fopen($calendar_path.$calendar_name.'.ics','w+')){
194
+					fputs($dataout, $data, strlen($data) );
195
+					@fclose($dataout);
196
+				}else{
197
+					logmsg( 'could not open file '.$calendar_path.$calendar_name.'.ics' );
198
+				}
199 199
 
200
-		}else {
201
-			logmsg('PUT ERROR - No data supplied.');
202
-		}
203
-		break;
204
-	case 'GET':
205
-		if (isset($_SERVER['PATH_INFO'])) {
206
-			preg_match("/\/([ A-Za-z0-9._]*).ics/i",$_SERVER['PATH_INFO'],$matches);
207
-			$icsfile = urldecode($matches[1]);
200
+			}else {
201
+				logmsg('PUT ERROR - No data supplied.');
202
+			}
203
+			break;
204
+		case 'GET':
205
+			if (isset($_SERVER['PATH_INFO'])) {
206
+				preg_match("/\/([ A-Za-z0-9._]*).ics/i",$_SERVER['PATH_INFO'],$matches);
207
+				$icsfile = urldecode($matches[1]);
208 208
 	
209
-			// get calendar data
210
-			if (file_exists($calendar_path . $icsfile . '.ics') &&
211
-				is_readable($calendar_path . $icsfile . '.ics') &&
212
-				is_file($calendar_path . $icsfile . '.ics')
213
-			) {
214
-				echo file_get_contents($calendar_path . $icsfile . '.ics');
215
-				logmsg('downloaded calendar ' . $icsfile);
209
+				// get calendar data
210
+				if (file_exists($calendar_path . $icsfile . '.ics') &&
211
+					is_readable($calendar_path . $icsfile . '.ics') &&
212
+					is_file($calendar_path . $icsfile . '.ics')
213
+				) {
214
+					echo file_get_contents($calendar_path . $icsfile . '.ics');
215
+					logmsg('downloaded calendar ' . $icsfile);
216
+				}
216 217
 			}
217
-		}
218 218
 }
219 219
 
220 220
 if(defined('PHPICALENDAR_LOG_PUBLISHING') && PHPICALENDAR_LOG_PUBLISHING == 1) {
Please login to merge, or discard this patch.
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -78,9 +78,9 @@  discard block
 block discarded – undo
78 78
 
79 79
 // allow/disallow publishing
80 80
 $phpicalendar_publishing = isset($phpiCal_config->phpicalendar_publishing) ? $phpiCal_config->phpicalendar_publishing : 0;
81
-define( 'PHPICALENDAR_PUBLISHING', $phpicalendar_publishing );
81
+define('PHPICALENDAR_PUBLISHING', $phpicalendar_publishing);
82 82
 // only allow publishing if explicitly enabled
83
-if(PHPICALENDAR_PUBLISHING != 1) {
83
+if (PHPICALENDAR_PUBLISHING != 1) {
84 84
 	header('WWW-Authenticate: Basic realm="ERROR: Calendar Publishing is disabled on this server"');
85 85
 	header('HTTP/1.1 401 Unauthorized');
86 86
 	echo 'Calendar Publishing is disabled on this server!';
@@ -89,15 +89,15 @@  discard block
 block discarded – undo
89 89
 
90 90
 // set calendar path, or just use current directory...make sure there's a trailing slash
91 91
 if (isset($phpiCal_config->calendar_path) && $phpiCal_config->calendar_path != '') {
92
-	if (substr($phpiCal_config->calendar_path, -1, 1) !='/') $calendar_path = $calendar_path.'/';
92
+	if (substr($phpiCal_config->calendar_path, -1, 1) != '/') $calendar_path = $calendar_path.'/';
93 93
 } else {
94 94
 	$calendar_path = '';
95 95
 }
96 96
 
97 97
 // toggle logging
98
-define( 'PHPICALENDAR_LOG_PUBLISHING', 1 );
99
-if(defined('PHPICALENDAR_LOG_PUBLISHING') && PHPICALENDAR_LOG_PUBLISHING == 1) {
100
-	if( ! $logfile = fopen('publish_log.txt','a+') ) {
98
+define('PHPICALENDAR_LOG_PUBLISHING', 1);
99
+if (defined('PHPICALENDAR_LOG_PUBLISHING') && PHPICALENDAR_LOG_PUBLISHING == 1) {
100
+	if (!$logfile = fopen('publish_log.txt', 'a+')) {
101 101
 		header('HTTP/1.1 401 Unauthorized');
102 102
 		header('WWW-Authenticate: Basic realm="ERROR: Unable to open log file"');
103 103
 		echo 'Unable to open log file.';
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	// Require authentication 
111 111
 	if (isset($_SERVER['HTTP_AUTHORIZATION'])) {
112 112
 		list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])
113
-			= explode( ':', base64_decode( substr($_SERVER['HTTP_AUTHORIZATION'], 6) ) );
113
+			= explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
114 114
 	}
115 115
 	if (!isset($_SERVER['PHP_AUTH_USER'])) {
116 116
 		header('WWW-Authenticate: Basic realm="phpICalendar"');
@@ -127,17 +127,17 @@  discard block
 block discarded – undo
127 127
 	}
128 128
 }
129 129
 
130
-switch ($_SERVER['REQUEST_METHOD']){
130
+switch ($_SERVER['REQUEST_METHOD']) {
131 131
 	// unpublishing
132 132
 	case 'DELETE':
133 133
 		// get calendar filename
134
-		$calendar_file = $calendar_path.substr($_SERVER['REQUEST_URI'] , ( strrpos($_SERVER['REQUEST_URI'], '/') + 1) ) ;
134
+		$calendar_file = $calendar_path.substr($_SERVER['REQUEST_URI'], (strrpos($_SERVER['REQUEST_URI'], '/') + 1));
135 135
 		$calendar_file = urldecode($calendar_file);
136 136
 		logmsg('received request to delete '.$calendar_file);
137 137
 		// remove calendar file
138
-		if(!unlink($calendar_file)){
138
+		if (!unlink($calendar_file)) {
139 139
 			logmsg('unable to delete the calendar file');
140
-		}else{
140
+		} else {
141 141
 			logmsg('deleted');
142 142
 		}
143 143
 		break;
@@ -146,43 +146,43 @@  discard block
 block discarded – undo
146 146
 		logmsg('PUT request');
147 147
 		// get calendar data
148 148
 		# php://input allows you to read raw POST data
149
-		if($datain = fopen('php://input','r')){
150
-			while(!@feof($datain)){
151
-				$data .= fgets($datain,4096);
149
+		if ($datain = fopen('php://input', 'r')) {
150
+			while (!@feof($datain)) {
151
+				$data .= fgets($datain, 4096);
152 152
 			}
153 153
 			@fclose($datain);
154
-		}else{
154
+		} else {
155 155
 			logmsg('unable to read input data');
156 156
 		}
157
-		if(isset($data)){
157
+		if (isset($data)) {
158 158
 			if (isset($_SERVER['PATH_INFO'])) {
159
-				preg_match("/\/([\w\-\.\+ ]*).ics/i",$_SERVER['PATH_INFO'],$matches);
159
+				preg_match("/\/([\w\-\.\+ ]*).ics/i", $_SERVER['PATH_INFO'], $matches);
160 160
 				$calendar_name = urldecode($matches[1]);
161 161
 			}
162 162
 			// If we don't have it from path info, use the supplied calendar name
163
-			if( ! isset($calendar_name) ) {
164
-				$cal_arr = explode("\n",$data);
165
-				foreach($cal_arr as $k => $v){
166
-					if(strstr($v,'X-WR-CALNAME:')){
167
-						$arr = explode(':',$v);
163
+			if (!isset($calendar_name)) {
164
+				$cal_arr = explode("\n", $data);
165
+				foreach ($cal_arr as $k => $v) {
166
+					if (strstr($v, 'X-WR-CALNAME:')) {
167
+						$arr = explode(':', $v);
168 168
 						$calendar_name = trim($arr[1]);
169 169
 						break;
170 170
 					}
171 171
 				}
172 172
 			}
173
-			logmsg('Received request to update: ' . $calendar_name);
173
+			logmsg('Received request to update: '.$calendar_name);
174 174
 			// Remove any invalid characters from the filename
175
-			$calendar_name = preg_replace( "/[^\w\.\- ]/", '', $calendar_name );
176
-			if( ( ! isset($calendar_name) ) || ( $calendar_name == '' ) ) {
175
+			$calendar_name = preg_replace("/[^\w\.\- ]/", '', $calendar_name);
176
+			if ((!isset($calendar_name)) || ($calendar_name == '')) {
177 177
 				header('HTTP/1.1 401 Invalid calendar name');
178 178
 				header('WWW-Authenticate: Basic realm="ERROR: Invalid calendar name."');
179 179
 				echo 'Invalid calendar name.';
180 180
 			}
181 181
 			// If we don't have a name, assume default
182 182
 			$calendar_name = isset($calendar_name) ? $calendar_name : 'default';
183
-			logmsg('Updating calendar: ' . $calendar_name);
183
+			logmsg('Updating calendar: '.$calendar_name);
184 184
 			// If this is Apple iCal, an event with a blank summary is private - mark as such
185
-			if( preg_match( "/Apple.*iCal/", $_SERVER['HTTP_USER_AGENT'] ) ) {
185
+			if (preg_match("/Apple.*iCal/", $_SERVER['HTTP_USER_AGENT'])) {
186 186
 				$data = preg_replace(
187 187
 					"/^\s*SUMMARY:\s*$/m",
188 188
 					"SUMMARY: **PRIVATE**\nCLASS:PRIVATE",
@@ -190,34 +190,34 @@  discard block
 block discarded – undo
190 190
 				);
191 191
 			}
192 192
 			// write to file
193
-			if($dataout = fopen($calendar_path.$calendar_name.'.ics','w+')){
194
-				fputs($dataout, $data, strlen($data) );
193
+			if ($dataout = fopen($calendar_path.$calendar_name.'.ics', 'w+')) {
194
+				fputs($dataout, $data, strlen($data));
195 195
 				@fclose($dataout);
196
-			}else{
197
-				logmsg( 'could not open file '.$calendar_path.$calendar_name.'.ics' );
196
+			} else {
197
+				logmsg('could not open file '.$calendar_path.$calendar_name.'.ics');
198 198
 			}
199 199
 
200
-		}else {
200
+		} else {
201 201
 			logmsg('PUT ERROR - No data supplied.');
202 202
 		}
203 203
 		break;
204 204
 	case 'GET':
205 205
 		if (isset($_SERVER['PATH_INFO'])) {
206
-			preg_match("/\/([ A-Za-z0-9._]*).ics/i",$_SERVER['PATH_INFO'],$matches);
206
+			preg_match("/\/([ A-Za-z0-9._]*).ics/i", $_SERVER['PATH_INFO'], $matches);
207 207
 			$icsfile = urldecode($matches[1]);
208 208
 	
209 209
 			// get calendar data
210
-			if (file_exists($calendar_path . $icsfile . '.ics') &&
211
-				is_readable($calendar_path . $icsfile . '.ics') &&
212
-				is_file($calendar_path . $icsfile . '.ics')
210
+			if (file_exists($calendar_path.$icsfile.'.ics') &&
211
+				is_readable($calendar_path.$icsfile.'.ics') &&
212
+				is_file($calendar_path.$icsfile.'.ics')
213 213
 			) {
214
-				echo file_get_contents($calendar_path . $icsfile . '.ics');
215
-				logmsg('downloaded calendar ' . $icsfile);
214
+				echo file_get_contents($calendar_path.$icsfile.'.ics');
215
+				logmsg('downloaded calendar '.$icsfile);
216 216
 			}
217 217
 		}
218 218
 }
219 219
 
220
-if(defined('PHPICALENDAR_LOG_PUBLISHING') && PHPICALENDAR_LOG_PUBLISHING == 1) {
220
+if (defined('PHPICALENDAR_LOG_PUBLISHING') && PHPICALENDAR_LOG_PUBLISHING == 1) {
221 221
 	fclose($logfile);
222 222
 }
223 223
 
@@ -226,18 +226,18 @@  discard block
 block discarded – undo
226 226
 
227 227
 
228 228
 // for logging
229
-function logmsg($str){
229
+function logmsg($str) {
230 230
 	global $logfile;
231 231
 
232
-	if(defined('PHPICALENDAR_LOG_PUBLISHING') && PHPICALENDAR_LOG_PUBLISHING == 1) {
233
-		if( $_SERVER['PHP_AUTH_USER'] )
234
-			$user =  $_SERVER['PHP_AUTH_USER'];
232
+	if (defined('PHPICALENDAR_LOG_PUBLISHING') && PHPICALENDAR_LOG_PUBLISHING == 1) {
233
+		if ($_SERVER['PHP_AUTH_USER'])
234
+			$user = $_SERVER['PHP_AUTH_USER'];
235 235
 		else
236
-			$user =  $_SERVER['REMOTE_USER'];
236
+			$user = $_SERVER['REMOTE_USER'];
237 237
 
238
-		$logline = date('Y-m-d H:i:s ') . $_SERVER['REMOTE_ADDR'] . ' ' . $user . ' ' . $str . "\n";
238
+		$logline = date('Y-m-d H:i:s ').$_SERVER['REMOTE_ADDR'].' '.$user.' '.$str."\n";
239 239
 
240
-		fputs($logfile, $logline, strlen($logline) );
240
+		fputs($logfile, $logline, strlen($logline));
241 241
 	}
242 242
 }
243 243
 ?>
244 244
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +13 added lines, -10 removed lines patch added patch discarded remove patch
@@ -89,8 +89,10 @@  discard block
 block discarded – undo
89 89
 
90 90
 // set calendar path, or just use current directory...make sure there's a trailing slash
91 91
 if (isset($phpiCal_config->calendar_path) && $phpiCal_config->calendar_path != '') {
92
-	if (substr($phpiCal_config->calendar_path, -1, 1) !='/') $calendar_path = $calendar_path.'/';
93
-} else {
92
+	if (substr($phpiCal_config->calendar_path, -1, 1) !='/') {
93
+		$calendar_path = $calendar_path.'/';
94
+	}
95
+	} else {
94 96
 	$calendar_path = '';
95 97
 }
96 98
 
@@ -137,7 +139,7 @@  discard block
 block discarded – undo
137 139
 		// remove calendar file
138 140
 		if(!unlink($calendar_file)){
139 141
 			logmsg('unable to delete the calendar file');
140
-		}else{
142
+		} else{
141 143
 			logmsg('deleted');
142 144
 		}
143 145
 		break;
@@ -151,7 +153,7 @@  discard block
 block discarded – undo
151 153
 				$data .= fgets($datain,4096);
152 154
 			}
153 155
 			@fclose($datain);
154
-		}else{
156
+		} else{
155 157
 			logmsg('unable to read input data');
156 158
 		}
157 159
 		if(isset($data)){
@@ -193,11 +195,11 @@  discard block
 block discarded – undo
193 195
 			if($dataout = fopen($calendar_path.$calendar_name.'.ics','w+')){
194 196
 				fputs($dataout, $data, strlen($data) );
195 197
 				@fclose($dataout);
196
-			}else{
198
+			} else{
197 199
 				logmsg( 'could not open file '.$calendar_path.$calendar_name.'.ics' );
198 200
 			}
199 201
 
200
-		}else {
202
+		} else {
201 203
 			logmsg('PUT ERROR - No data supplied.');
202 204
 		}
203 205
 		break;
@@ -230,10 +232,11 @@  discard block
 block discarded – undo
230 232
 	global $logfile;
231 233
 
232 234
 	if(defined('PHPICALENDAR_LOG_PUBLISHING') && PHPICALENDAR_LOG_PUBLISHING == 1) {
233
-		if( $_SERVER['PHP_AUTH_USER'] )
234
-			$user =  $_SERVER['PHP_AUTH_USER'];
235
-		else
236
-			$user =  $_SERVER['REMOTE_USER'];
235
+		if( $_SERVER['PHP_AUTH_USER'] ) {
236
+					$user =  $_SERVER['PHP_AUTH_USER'];
237
+		} else {
238
+					$user =  $_SERVER['REMOTE_USER'];
239
+		}
237 240
 
238 241
 		$logline = date('Y-m-d H:i:s ') . $_SERVER['REMOTE_ADDR'] . ' ' . $user . ' ' . $str . "\n";
239 242
 
Please login to merge, or discard this patch.
phpicalendar/year.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -48,8 +48,8 @@  discard block
 block discarded – undo
48 48
 	'header'			=> BASE.'templates/'.$template.'/header.tpl',
49 49
 	'event_js'			=> BASE.'functions/event.js',
50 50
 	'footer'			=> BASE.'templates/'.$template.'/footer.tpl',
51
-    'sidebar'           => BASE.'templates/'.$template.'/sidebar_year.tpl',
52
-    'search_box'        => BASE.'templates/'.$template.'/search_box.tpl'
51
+	'sidebar'           => BASE.'templates/'.$template.'/sidebar_year.tpl',
52
+	'search_box'        => BASE.'templates/'.$template.'/search_box.tpl'
53 53
 	));
54 54
 
55 55
 $page->replace_tags(array(
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 	'default_path'		=> $phpiCal_config->default_path,
62 62
 	'cal'				=> $cal,
63 63
 	'getcpath'			=> "&cpath=$cpath",
64
-    'cpath'             => $cpath,
64
+	'cpath'             => $cpath,
65 65
 	'getdate'			=> $getdate,
66 66
 	'calendar_name'		=> $cal_displayname,
67 67
 	'display_date'		=> $this_year,
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -5,20 +5,20 @@  discard block
 block discarded – undo
5 5
 require_once(BASE.'functions/list_functions.php');
6 6
 require_once(BASE.'functions/template.php');
7 7
 
8
-ereg ("([0-9]{4})([0-9]{2})([0-9]{2})", $getdate, $day_array2);
9
-$this_day 	= $day_array2[3]; 
8
+ereg("([0-9]{4})([0-9]{2})([0-9]{2})", $getdate, $day_array2);
9
+$this_day = $day_array2[3]; 
10 10
 $this_month = $day_array2[2];
11 11
 $this_year 	= $day_array2[1];
12
-$next_year 	= strtotime ("+1 year", strtotime($getdate));
13
-$next_year 	= date ("Ymd", $next_year);
14
-$prev_year 	= strtotime ("-1 year", strtotime($getdate));
15
-$prev_year 	= date ("Ymd", $prev_year);
12
+$next_year 	= strtotime("+1 year", strtotime($getdate));
13
+$next_year 	= date("Ymd", $next_year);
14
+$prev_year 	= strtotime("-1 year", strtotime($getdate));
15
+$prev_year 	= date("Ymd", $prev_year);
16 16
 
17
-$sidebar_date 		= localizeDate($dateFormat_week_list, strtotime($getdate));
17
+$sidebar_date = localizeDate($dateFormat_week_list, strtotime($getdate));
18 18
 
19 19
 // For the side months
20
-ereg ("([0-9]{4})([0-9]{2})([0-9]{2})", $getdate, $day_array2);
21
-$this_day 	= $day_array2[3]; 
20
+ereg("([0-9]{4})([0-9]{2})([0-9]{2})", $getdate, $day_array2);
21
+$this_day = $day_array2[3]; 
22 22
 $this_month = $day_array2[2];
23 23
 $this_year 	= $day_array2[1];
24 24
 
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 $available		= availableCalendars($username, $password, $phpiCal_config->ALL_CALENDARS_COMBINED);
27 27
 $list_icals 	= display_ical_list($available);
28 28
 $list_years 	= list_years();
29
-$list_months 	= list_months();
29
+$list_months = list_months();
30 30
 $list_weeks 	= list_weeks();
31 31
 $list_jumps 	= list_jumps();
32 32
 $list_calcolors = '<img src="templates/'.$template.'/images/allday_dot.gif" alt=" " width="11" height="10" border="0" />'.$lang['l_all_day'].'<br>
Please login to merge, or discard this patch.
phpicalendar/month.php 3 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -66,8 +66,8 @@
 block discarded – undo
66 66
 	'header'			=> BASE.'templates/'.$phpiCal_config->template.'/header.tpl',
67 67
 	'event_js'			=> BASE.'functions/event.js',
68 68
 	'footer'			=> BASE.'templates/'.$phpiCal_config->template.'/footer.tpl',
69
-    'calendar_nav'      => BASE.'templates/'.$phpiCal_config->template.'/calendar_nav.tpl',
70
-    'search_box'        => BASE.'templates/'.$phpiCal_config->template.'/search_box.tpl'
69
+	'calendar_nav'      => BASE.'templates/'.$phpiCal_config->template.'/calendar_nav.tpl',
70
+	'search_box'        => BASE.'templates/'.$phpiCal_config->template.'/search_box.tpl'
71 71
 	));
72 72
 
73 73
 $page->replace_tags(array(
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -15,41 +15,41 @@
 block discarded – undo
15 15
 		break;
16 16
 }
17 17
 
18
-$unix_time 				= strtotime($getdate);
19
-$today_today 			= date('Ymd', time() + $phpiCal_config->second_offset); 
20
-$tomorrows_date 		= date('Ymd', strtotime("+1 day",  $unix_time));
21
-$yesterdays_date 		= date('Ymd', strtotime("-1 day",  $unix_time));
22
-$sidebar_date 			= localizeDate($dateFormat_week_list, $unix_time);
18
+$unix_time = strtotime($getdate);
19
+$today_today = date('Ymd', time() + $phpiCal_config->second_offset); 
20
+$tomorrows_date = date('Ymd', strtotime("+1 day", $unix_time));
21
+$yesterdays_date = date('Ymd', strtotime("-1 day", $unix_time));
22
+$sidebar_date = localizeDate($dateFormat_week_list, $unix_time);
23 23
 if (!isset($style_select)) $style_select = '';
24 24
 
25 25
 // find out next month
26
-$next_month_month 		= ($this_month+1 == '13') ? '1' : ($this_month+1);
27
-$next_month_day 		= $this_day;
28
-$next_month_year 		= ($next_month_month == '1') ? ($this_year+1) : $this_year;
29
-while (!checkdate($next_month_month,$next_month_day,$next_month_year)) $next_month_day--;
30
-$next_month_time 		= mktime(0,0,0,$next_month_month,$next_month_day,$next_month_year);
26
+$next_month_month = ($this_month + 1 == '13') ? '1' : ($this_month + 1);
27
+$next_month_day = $this_day;
28
+$next_month_year 		= ($next_month_month == '1') ? ($this_year + 1) : $this_year;
29
+while (!checkdate($next_month_month, $next_month_day, $next_month_year)) $next_month_day--;
30
+$next_month_time 		= mktime(0, 0, 0, $next_month_month, $next_month_day, $next_month_year);
31 31
 
32 32
 // find out last month
33
-$prev_month_month 		= ($this_month-1 == '0') ? '12' : ($this_month-1);
34
-$prev_month_day 		= $this_day;
35
-$prev_month_year 		= ($prev_month_month == '12') ? ($this_year-1) : $this_year;
36
-while (!checkdate($prev_month_month,$prev_month_day,$prev_month_year)) $prev_month_day--;
37
-$prev_month_time 		= mktime(0,0,0,$prev_month_month,$prev_month_day,$prev_month_year);
33
+$prev_month_month = ($this_month - 1 == '0') ? '12' : ($this_month - 1);
34
+$prev_month_day = $this_day;
35
+$prev_month_year 		= ($prev_month_month == '12') ? ($this_year - 1) : $this_year;
36
+while (!checkdate($prev_month_month, $prev_month_day, $prev_month_year)) $prev_month_day--;
37
+$prev_month_time 		= mktime(0, 0, 0, $prev_month_month, $prev_month_day, $prev_month_year);
38 38
 
39 39
 $next_month 			= date("Ymd", $next_month_time);
40 40
 $prev_month 			= date("Ymd", $prev_month_time);
41
-$display_date 			= localizeDate ($dateFormat_month, $unix_time);
42
-$parse_month 			= date ("Ym", $unix_time);
43
-$first_of_month 		= $this_year.$this_month."01";
41
+$display_date = localizeDate($dateFormat_month, $unix_time);
42
+$parse_month = date("Ym", $unix_time);
43
+$first_of_month = $this_year.$this_month."01";
44 44
 $start_month_day 		= dateOfWeek($first_of_month, $phpiCal_config->week_start_day);
45
-$thisday2 				= localizeDate($dateFormat_week_list, $unix_time);
45
+$thisday2 = localizeDate($dateFormat_week_list, $unix_time);
46 46
 $num_of_events2 			= 0;
47 47
 
48 48
 // select for calendars
49
-$available		= availableCalendars($username, $password, $phpiCal_config->ALL_CALENDARS_COMBINED);
49
+$available = availableCalendars($username, $password, $phpiCal_config->ALL_CALENDARS_COMBINED);
50 50
 $list_icals 	= display_ical_list($available);
51 51
 $list_years 	= list_years();
52
-$list_months 	= list_months();
52
+$list_months = list_months();
53 53
 $list_weeks 	= list_weeks();
54 54
 $list_jumps 	= list_jumps();
55 55
 $list_calcolors = list_calcolors();
Please login to merge, or discard this patch.
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -20,20 +20,26 @@
 block discarded – undo
20 20
 $tomorrows_date 		= date('Ymd', strtotime("+1 day",  $unix_time));
21 21
 $yesterdays_date 		= date('Ymd', strtotime("-1 day",  $unix_time));
22 22
 $sidebar_date 			= localizeDate($dateFormat_week_list, $unix_time);
23
-if (!isset($style_select)) $style_select = '';
23
+if (!isset($style_select)) {
24
+	$style_select = '';
25
+}
24 26
 
25 27
 // find out next month
26 28
 $next_month_month 		= ($this_month+1 == '13') ? '1' : ($this_month+1);
27 29
 $next_month_day 		= $this_day;
28 30
 $next_month_year 		= ($next_month_month == '1') ? ($this_year+1) : $this_year;
29
-while (!checkdate($next_month_month,$next_month_day,$next_month_year)) $next_month_day--;
31
+while (!checkdate($next_month_month,$next_month_day,$next_month_year)) {
32
+	$next_month_day--;
33
+}
30 34
 $next_month_time 		= mktime(0,0,0,$next_month_month,$next_month_day,$next_month_year);
31 35
 
32 36
 // find out last month
33 37
 $prev_month_month 		= ($this_month-1 == '0') ? '12' : ($this_month-1);
34 38
 $prev_month_day 		= $this_day;
35 39
 $prev_month_year 		= ($prev_month_month == '12') ? ($this_year-1) : $this_year;
36
-while (!checkdate($prev_month_month,$prev_month_day,$prev_month_year)) $prev_month_day--;
40
+while (!checkdate($prev_month_month,$prev_month_day,$prev_month_year)) {
41
+	$prev_month_day--;
42
+}
37 43
 $prev_month_time 		= mktime(0,0,0,$prev_month_month,$prev_month_day,$prev_month_year);
38 44
 
39 45
 $next_month 			= date("Ymd", $next_month_time);
Please login to merge, or discard this patch.