@@ -240,6 +240,9 @@ discard block |
||
240 | 240 | return $this->call(CANVAS_API_PUT, $path, $data, $throwsExceptions); |
241 | 241 | } |
242 | 242 | |
243 | + /** |
|
244 | + * @param string $page |
|
245 | + */ |
|
243 | 246 | private function pageLink($page) { |
244 | 247 | if (array_key_exists($page, $this->lastCall['pagination'])) { |
245 | 248 | $this->pagePest = new Pest($this->lastCall['pagination'][$page]); |
@@ -264,6 +267,9 @@ discard block |
||
264 | 267 | return $this->pageLink('last'); |
265 | 268 | } |
266 | 269 | |
270 | + /** |
|
271 | + * @param string $page |
|
272 | + */ |
|
267 | 273 | private function getPageNumber($page) { |
268 | 274 | if (array_key_exists($page, $this->lastCall['pagination'])) { |
269 | 275 | parse_str(parse_url($this->lastCall['pagination'][$page], PHP_URL_QUERY), $query); |
@@ -1,15 +1,15 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -require_once(__DIR__ . '/../../config.inc.php'); |
|
4 | -require_once(APP_PATH . '/include/debug.inc.php'); |
|
3 | +require_once(__DIR__.'/../../config.inc.php'); |
|
4 | +require_once(APP_PATH.'/include/debug.inc.php'); |
|
5 | 5 | |
6 | -if(!defined('API_CLIENT_ERROR_RETRIES')) { |
|
6 | +if (!defined('API_CLIENT_ERROR_RETRIES')) { |
|
7 | 7 | define('API_CLIENT_ERROR_RETRIES', 5); |
8 | - debug_log('Using default API_CLIENT_ERROR_RETRIES = ' . API_CLIENT_ERROR_RETRIES); |
|
8 | + debug_log('Using default API_CLIENT_ERROR_RETRIES = '.API_CLIENT_ERROR_RETRIES); |
|
9 | 9 | } |
10 | -if(!defined('API_SERVER_ERROR_RETRIES')) { |
|
11 | - define('API_SERVER_ERROR_RETRIES', API_CLIENT_ERROR_RETRIES * 5); |
|
12 | - debug_log('Using default API_SERVER_ERROR_RETRIES = ' . API_SERVER_ERROR_RETRIES); |
|
10 | +if (!defined('API_SERVER_ERROR_RETRIES')) { |
|
11 | + define('API_SERVER_ERROR_RETRIES', API_CLIENT_ERROR_RETRIES*5); |
|
12 | + debug_log('Using default API_SERVER_ERROR_RETRIES = '.API_SERVER_ERROR_RETRIES); |
|
13 | 13 | } |
14 | 14 | |
15 | 15 | /* the verbs available within the Canvas REST API */ |
@@ -35,10 +35,10 @@ discard block |
||
35 | 35 | // TODO: we could extend this to include more specificity about the Pest exceptions... |
36 | 36 | |
37 | 37 | /* we use Pest to interact with the RESTful API */ |
38 | -require_once(APP_PATH . '/include/Pest.php'); |
|
38 | +require_once(APP_PATH.'/include/Pest.php'); |
|
39 | 39 | |
40 | 40 | /* handles HTML page generation */ |
41 | -require_once(APP_PATH . '/include/page-generator.inc.php'); |
|
41 | +require_once(APP_PATH.'/include/page-generator.inc.php'); |
|
42 | 42 | |
43 | 43 | class CanvasApiProcess { |
44 | 44 | |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | } |
86 | 86 | |
87 | 87 | private function buildCanvasAuthorizationHeader() { |
88 | - return array ('Authorization' => 'Bearer ' . $this->authorizationToken); |
|
88 | + return array('Authorization' => 'Bearer '.$this->authorizationToken); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | /* who knows what goes on in the server's mind... try again */ |
137 | 137 | $serverRetryCount++; |
138 | 138 | $retry = true; |
139 | - debug_log('Retrying after Canvas API server error. ' . substr($e->getMessage(), 0, CANVAS_API_EXCEPTION_MAX_LENGTH)); |
|
139 | + debug_log('Retrying after Canvas API server error. '.substr($e->getMessage(), 0, CANVAS_API_EXCEPTION_MAX_LENGTH)); |
|
140 | 140 | } |
141 | 141 | } catch (Pest_ClientError $e) { |
142 | 142 | if ($throwsExceptions & CANVAS_API_EXCEPTION_CLIENT) { |
@@ -146,14 +146,14 @@ discard block |
||
146 | 146 | I was authorized. Everything gets retried a few times before I give up */ |
147 | 147 | $clientRetryCount++; |
148 | 148 | $retry = true; |
149 | - debug_log('Retrying after Canvas API client error. ' . substr($e->getMessage(), 0, CANVAS_API_EXCEPTION_MAX_LENGTH)); |
|
149 | + debug_log('Retrying after Canvas API client error. '.substr($e->getMessage(), 0, CANVAS_API_EXCEPTION_MAX_LENGTH)); |
|
150 | 150 | } |
151 | 151 | } catch (Exception $e) { |
152 | 152 | // treat an empty reply as a server error (which, BTW, it dang well is) |
153 | 153 | if ($e->getMessage() == 'Empty reply from server') { |
154 | 154 | $serverRetryCount++; |
155 | 155 | $retry = true; |
156 | - debug_log('Retrying after empty reply from server. ' . substr($e->getMessage(), 0, CANVAS_API_EXCEPTION_MAX_LENGTH)); |
|
156 | + debug_log('Retrying after empty reply from server. '.substr($e->getMessage(), 0, CANVAS_API_EXCEPTION_MAX_LENGTH)); |
|
157 | 157 | } else { |
158 | 158 | displayError( |
159 | 159 | array( |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | ), |
183 | 183 | true, |
184 | 184 | 'Probable Client Error', |
185 | - 'After trying ' . API_CLIENT_ERROR_RETRIES . ' times, we still got this error message from the API. (Remember to check to be sure that the object ID passed to the API is valid and exists if the API tells you that you\'re not authorized... because you\'re not authorized to work with things that don\'t exist!)' |
|
185 | + 'After trying '.API_CLIENT_ERROR_RETRIES.' times, we still got this error message from the API. (Remember to check to be sure that the object ID passed to the API is valid and exists if the API tells you that you\'re not authorized... because you\'re not authorized to work with things that don\'t exist!)' |
|
186 | 186 | ); |
187 | 187 | exit; |
188 | 188 | } |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | ), |
199 | 199 | true, |
200 | 200 | 'Probable Server Error', |
201 | - 'After trying ' . API_CLIENT_ERROR_RETRIES . ' times, we still got this error message from the API.' |
|
201 | + 'After trying '.API_CLIENT_ERROR_RETRIES.' times, we still got this error message from the API.' |
|
202 | 202 | ); |
203 | 203 | exit; |
204 | 204 | } |
@@ -217,7 +217,7 @@ |
||
217 | 217 | /** |
218 | 218 | * Do CURL request |
219 | 219 | * @param resource $curl |
220 | - * @return mixed |
|
220 | + * @return string |
|
221 | 221 | * @throws Pest_Curl_Exec |
222 | 222 | * @throws Pest_Curl_Meta |
223 | 223 | */ |
@@ -9,514 +9,514 @@ |
||
9 | 9 | */ |
10 | 10 | class Pest |
11 | 11 | { |
12 | - /** |
|
13 | - * @var array Default CURL options |
|
14 | - */ |
|
15 | - public $curl_opts = array( |
|
16 | - CURLOPT_RETURNTRANSFER => true, // return result instead of echoing |
|
17 | - CURLOPT_SSL_VERIFYPEER => false, // stop cURL from verifying the peer's certificate |
|
18 | - CURLOPT_FOLLOWLOCATION => false, // follow redirects, Location: headers |
|
19 | - CURLOPT_MAXREDIRS => 10, // but dont redirect more than 10 times |
|
20 | - CURLOPT_HTTPHEADER => array() |
|
21 | - ); |
|
22 | - |
|
23 | - /** |
|
24 | - * @var string Base URL |
|
25 | - */ |
|
26 | - public $base_url; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var array Last response |
|
30 | - */ |
|
31 | - public $last_response; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var array Last request |
|
35 | - */ |
|
36 | - public $last_request; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var array Last headers |
|
40 | - */ |
|
41 | - public $last_headers; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var bool Throw exceptions on HTTP error codes |
|
45 | - */ |
|
46 | - public $throw_exceptions = true; |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * Class constructor |
|
51 | - * @param string $base_url |
|
52 | - * @throws Exception |
|
53 | - */ |
|
54 | - public function __construct($base_url) |
|
55 | - { |
|
56 | - if (!function_exists('curl_init')) { |
|
57 | - throw new Exception('CURL module not available! Pest requires CURL. See http://php.net/manual/en/book.curl.php'); |
|
58 | - } |
|
59 | - |
|
60 | - /* |
|
12 | + /** |
|
13 | + * @var array Default CURL options |
|
14 | + */ |
|
15 | + public $curl_opts = array( |
|
16 | + CURLOPT_RETURNTRANSFER => true, // return result instead of echoing |
|
17 | + CURLOPT_SSL_VERIFYPEER => false, // stop cURL from verifying the peer's certificate |
|
18 | + CURLOPT_FOLLOWLOCATION => false, // follow redirects, Location: headers |
|
19 | + CURLOPT_MAXREDIRS => 10, // but dont redirect more than 10 times |
|
20 | + CURLOPT_HTTPHEADER => array() |
|
21 | + ); |
|
22 | + |
|
23 | + /** |
|
24 | + * @var string Base URL |
|
25 | + */ |
|
26 | + public $base_url; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var array Last response |
|
30 | + */ |
|
31 | + public $last_response; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var array Last request |
|
35 | + */ |
|
36 | + public $last_request; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var array Last headers |
|
40 | + */ |
|
41 | + public $last_headers; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var bool Throw exceptions on HTTP error codes |
|
45 | + */ |
|
46 | + public $throw_exceptions = true; |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * Class constructor |
|
51 | + * @param string $base_url |
|
52 | + * @throws Exception |
|
53 | + */ |
|
54 | + public function __construct($base_url) |
|
55 | + { |
|
56 | + if (!function_exists('curl_init')) { |
|
57 | + throw new Exception('CURL module not available! Pest requires CURL. See http://php.net/manual/en/book.curl.php'); |
|
58 | + } |
|
59 | + |
|
60 | + /* |
|
61 | 61 | * Only enable CURLOPT_FOLLOWLOCATION if safe_mode and open_base_dir are |
62 | 62 | * not in use |
63 | 63 | */ |
64 | - if (ini_get('open_basedir') == '' && strtolower(ini_get('safe_mode')) == 'off') { |
|
65 | - $this->curl_opts['CURLOPT_FOLLOWLOCATION'] = true; |
|
66 | - } |
|
67 | - |
|
68 | - $this->base_url = $base_url; |
|
69 | - |
|
70 | - // The callback to handle return headers |
|
71 | - // Using PHP 5.2, it cannot be initialised in the static context |
|
72 | - $this->curl_opts[CURLOPT_HEADERFUNCTION] = array($this, 'handle_header'); |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Setup authentication |
|
77 | - * |
|
78 | - * @param string $user |
|
79 | - * @param string $pass |
|
80 | - * @param string $auth Can be 'basic' or 'digest' |
|
81 | - */ |
|
82 | - public function setupAuth($user, $pass, $auth = 'basic') |
|
83 | - { |
|
84 | - $this->curl_opts[CURLOPT_HTTPAUTH] = constant('CURLAUTH_' . strtoupper($auth)); |
|
85 | - $this->curl_opts[CURLOPT_USERPWD] = $user . ":" . $pass; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Setup proxy |
|
90 | - * @param string $host |
|
91 | - * @param int $port |
|
92 | - * @param string $user Optional. |
|
93 | - * @param string $pass Optional. |
|
94 | - */ |
|
95 | - public function setupProxy($host, $port, $user = NULL, $pass = NULL) |
|
96 | - { |
|
97 | - $this->curl_opts[CURLOPT_PROXYTYPE] = 'HTTP'; |
|
98 | - $this->curl_opts[CURLOPT_PROXY] = $host; |
|
99 | - $this->curl_opts[CURLOPT_PROXYPORT] = $port; |
|
100 | - if ($user && $pass) { |
|
101 | - $this->curl_opts[CURLOPT_PROXYUSERPWD] = $user . ":" . $pass; |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Perform HTTP GET request |
|
107 | - * |
|
108 | - * @param string $url |
|
109 | - * @param array $data |
|
110 | - * @param array $headers |
|
111 | - * @return string |
|
112 | - */ |
|
113 | - public function get($url, $data = array(), $headers=array()) |
|
114 | - { |
|
115 | - if (!empty($data)) { |
|
116 | - $pos = strpos($url, '?'); |
|
117 | - if ($pos !== false) { |
|
118 | - $url = substr($url, 0, $pos); |
|
119 | - } |
|
120 | - $url .= '?' . http_build_query($data); |
|
121 | - } |
|
122 | - |
|
123 | - $curl_opts = $this->curl_opts; |
|
64 | + if (ini_get('open_basedir') == '' && strtolower(ini_get('safe_mode')) == 'off') { |
|
65 | + $this->curl_opts['CURLOPT_FOLLOWLOCATION'] = true; |
|
66 | + } |
|
67 | + |
|
68 | + $this->base_url = $base_url; |
|
69 | + |
|
70 | + // The callback to handle return headers |
|
71 | + // Using PHP 5.2, it cannot be initialised in the static context |
|
72 | + $this->curl_opts[CURLOPT_HEADERFUNCTION] = array($this, 'handle_header'); |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Setup authentication |
|
77 | + * |
|
78 | + * @param string $user |
|
79 | + * @param string $pass |
|
80 | + * @param string $auth Can be 'basic' or 'digest' |
|
81 | + */ |
|
82 | + public function setupAuth($user, $pass, $auth = 'basic') |
|
83 | + { |
|
84 | + $this->curl_opts[CURLOPT_HTTPAUTH] = constant('CURLAUTH_' . strtoupper($auth)); |
|
85 | + $this->curl_opts[CURLOPT_USERPWD] = $user . ":" . $pass; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Setup proxy |
|
90 | + * @param string $host |
|
91 | + * @param int $port |
|
92 | + * @param string $user Optional. |
|
93 | + * @param string $pass Optional. |
|
94 | + */ |
|
95 | + public function setupProxy($host, $port, $user = NULL, $pass = NULL) |
|
96 | + { |
|
97 | + $this->curl_opts[CURLOPT_PROXYTYPE] = 'HTTP'; |
|
98 | + $this->curl_opts[CURLOPT_PROXY] = $host; |
|
99 | + $this->curl_opts[CURLOPT_PROXYPORT] = $port; |
|
100 | + if ($user && $pass) { |
|
101 | + $this->curl_opts[CURLOPT_PROXYUSERPWD] = $user . ":" . $pass; |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Perform HTTP GET request |
|
107 | + * |
|
108 | + * @param string $url |
|
109 | + * @param array $data |
|
110 | + * @param array $headers |
|
111 | + * @return string |
|
112 | + */ |
|
113 | + public function get($url, $data = array(), $headers=array()) |
|
114 | + { |
|
115 | + if (!empty($data)) { |
|
116 | + $pos = strpos($url, '?'); |
|
117 | + if ($pos !== false) { |
|
118 | + $url = substr($url, 0, $pos); |
|
119 | + } |
|
120 | + $url .= '?' . http_build_query($data); |
|
121 | + } |
|
122 | + |
|
123 | + $curl_opts = $this->curl_opts; |
|
124 | 124 | |
125 | - $curl_opts[CURLOPT_HTTPHEADER] = $this->prepHeaders($headers); |
|
126 | - |
|
127 | - $curl = $this->prepRequest($curl_opts, $url); |
|
128 | - $body = $this->doRequest($curl); |
|
129 | - $body = $this->processBody($body); |
|
130 | - |
|
131 | - return $body; |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Prepare request |
|
136 | - * |
|
137 | - * @param array $opts |
|
138 | - * @param string $url |
|
139 | - * @return resource |
|
140 | - * @throws Pest_Curl_Init |
|
141 | - */ |
|
142 | - protected function prepRequest($opts, $url) |
|
143 | - { |
|
144 | - if (strncmp($url, $this->base_url, strlen($this->base_url)) != 0) { |
|
145 | - $url = rtrim($this->base_url, '/') . '/' . ltrim($url, '/'); |
|
146 | - } |
|
147 | - |
|
148 | - $curl = curl_init($url); |
|
149 | - if ($curl === false) { |
|
150 | - throw new Pest_Curl_Init($this->processError(curl_error($curl), 'curl')); |
|
151 | - } |
|
152 | - |
|
153 | - foreach ($opts as $opt => $val) |
|
154 | - curl_setopt($curl, $opt, $val); |
|
155 | - |
|
156 | - $this->last_request = array( |
|
157 | - 'url' => $url |
|
158 | - ); |
|
159 | - |
|
160 | - if (isset($opts[CURLOPT_CUSTOMREQUEST])) |
|
161 | - $this->last_request['method'] = $opts[CURLOPT_CUSTOMREQUEST]; |
|
162 | - else |
|
163 | - $this->last_request['method'] = 'GET'; |
|
164 | - |
|
165 | - if (isset($opts[CURLOPT_POSTFIELDS])) |
|
166 | - $this->last_request['data'] = $opts[CURLOPT_POSTFIELDS]; |
|
167 | - |
|
168 | - return $curl; |
|
169 | - } |
|
125 | + $curl_opts[CURLOPT_HTTPHEADER] = $this->prepHeaders($headers); |
|
126 | + |
|
127 | + $curl = $this->prepRequest($curl_opts, $url); |
|
128 | + $body = $this->doRequest($curl); |
|
129 | + $body = $this->processBody($body); |
|
130 | + |
|
131 | + return $body; |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Prepare request |
|
136 | + * |
|
137 | + * @param array $opts |
|
138 | + * @param string $url |
|
139 | + * @return resource |
|
140 | + * @throws Pest_Curl_Init |
|
141 | + */ |
|
142 | + protected function prepRequest($opts, $url) |
|
143 | + { |
|
144 | + if (strncmp($url, $this->base_url, strlen($this->base_url)) != 0) { |
|
145 | + $url = rtrim($this->base_url, '/') . '/' . ltrim($url, '/'); |
|
146 | + } |
|
147 | + |
|
148 | + $curl = curl_init($url); |
|
149 | + if ($curl === false) { |
|
150 | + throw new Pest_Curl_Init($this->processError(curl_error($curl), 'curl')); |
|
151 | + } |
|
152 | + |
|
153 | + foreach ($opts as $opt => $val) |
|
154 | + curl_setopt($curl, $opt, $val); |
|
155 | + |
|
156 | + $this->last_request = array( |
|
157 | + 'url' => $url |
|
158 | + ); |
|
159 | + |
|
160 | + if (isset($opts[CURLOPT_CUSTOMREQUEST])) |
|
161 | + $this->last_request['method'] = $opts[CURLOPT_CUSTOMREQUEST]; |
|
162 | + else |
|
163 | + $this->last_request['method'] = 'GET'; |
|
164 | + |
|
165 | + if (isset($opts[CURLOPT_POSTFIELDS])) |
|
166 | + $this->last_request['data'] = $opts[CURLOPT_POSTFIELDS]; |
|
167 | + |
|
168 | + return $curl; |
|
169 | + } |
|
170 | 170 | |
171 | - /** |
|
172 | - * Determines if a given array is numerically indexed or not |
|
173 | - * |
|
174 | - * @param array $array |
|
175 | - * @return boolean |
|
176 | - */ |
|
177 | - protected function _isNumericallyIndexedArray($array) |
|
178 | - { |
|
179 | - return !(bool)count(array_filter(array_keys($array), 'is_string')); |
|
180 | - } |
|
171 | + /** |
|
172 | + * Determines if a given array is numerically indexed or not |
|
173 | + * |
|
174 | + * @param array $array |
|
175 | + * @return boolean |
|
176 | + */ |
|
177 | + protected function _isNumericallyIndexedArray($array) |
|
178 | + { |
|
179 | + return !(bool)count(array_filter(array_keys($array), 'is_string')); |
|
180 | + } |
|
181 | 181 | |
182 | - /** |
|
183 | - * Flatten headers from an associative array to a numerically indexed array of "Name: Value" |
|
184 | - * style entries like CURLOPT_HTTPHEADER expects. Numerically indexed arrays are not modified. |
|
185 | - * |
|
186 | - * @param array $headers |
|
187 | - * @return array |
|
188 | - */ |
|
189 | - protected function prepHeaders($headers) |
|
190 | - { |
|
191 | - if ($this->_isNumericallyIndexedArray($headers)) { |
|
192 | - return $headers; |
|
193 | - } |
|
182 | + /** |
|
183 | + * Flatten headers from an associative array to a numerically indexed array of "Name: Value" |
|
184 | + * style entries like CURLOPT_HTTPHEADER expects. Numerically indexed arrays are not modified. |
|
185 | + * |
|
186 | + * @param array $headers |
|
187 | + * @return array |
|
188 | + */ |
|
189 | + protected function prepHeaders($headers) |
|
190 | + { |
|
191 | + if ($this->_isNumericallyIndexedArray($headers)) { |
|
192 | + return $headers; |
|
193 | + } |
|
194 | 194 | |
195 | - $flattened = array(); |
|
196 | - foreach ($headers as $name => $value) { |
|
197 | - $flattened[] = $name . ': ' . $value; |
|
198 | - } |
|
195 | + $flattened = array(); |
|
196 | + foreach ($headers as $name => $value) { |
|
197 | + $flattened[] = $name . ': ' . $value; |
|
198 | + } |
|
199 | 199 | |
200 | - return $flattened; |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * Process error |
|
205 | - * @param string $body |
|
206 | - * @return string |
|
207 | - */ |
|
208 | - protected function processError($body) |
|
209 | - { |
|
210 | - // Override this in classes that extend Pest. |
|
211 | - // The body of every erroneous (non-2xx/3xx) GET/POST/PUT/DELETE |
|
212 | - // response goes through here prior to being used as the 'message' |
|
213 | - // of the resulting Pest_Exception |
|
214 | - return $body; |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * Do CURL request |
|
219 | - * @param resource $curl |
|
220 | - * @return mixed |
|
221 | - * @throws Pest_Curl_Exec |
|
222 | - * @throws Pest_Curl_Meta |
|
223 | - */ |
|
224 | - private function doRequest($curl) |
|
225 | - { |
|
226 | - $this->last_headers = array(); |
|
227 | - $this->last_response = array(); |
|
228 | - |
|
229 | - // curl_error() needs to be tested right after function failure |
|
230 | - $this->last_response["body"] = curl_exec($curl); |
|
231 | - if ($this->last_response["body"] === false && $this->throw_exceptions) { |
|
232 | - throw new Pest_Curl_Exec(curl_error($curl)); |
|
233 | - } |
|
234 | - |
|
235 | - $this->last_response["meta"] = curl_getinfo($curl); |
|
236 | - if ($this->last_response["meta"] === false && $this->throw_exceptions) { |
|
237 | - throw new Pest_Curl_Meta(curl_error($curl)); |
|
238 | - } |
|
239 | - |
|
240 | - curl_close($curl); |
|
241 | - |
|
242 | - $this->checkLastResponseForError(); |
|
243 | - |
|
244 | - return $this->last_response["body"]; |
|
245 | - } |
|
246 | - |
|
247 | - /** |
|
248 | - * Check last response for error |
|
249 | - * |
|
250 | - * @throws Pest_Conflict |
|
251 | - * @throws Pest_Gone |
|
252 | - * @throws Pest_Unauthorized |
|
253 | - * @throws Pest_ClientError |
|
254 | - * @throws Pest_MethodNotAllowed |
|
255 | - * @throws Pest_NotFound |
|
256 | - * @throws Pest_BadRequest |
|
257 | - * @throws Pest_UnknownResponse |
|
258 | - * @throws Pest_InvalidRecord |
|
259 | - * @throws Pest_ServerError |
|
260 | - * @throws Pest_Forbidden |
|
261 | - */ |
|
262 | - protected function checkLastResponseForError() |
|
263 | - { |
|
264 | - if (!$this->throw_exceptions) |
|
265 | - return; |
|
266 | - |
|
267 | - $meta = $this->last_response['meta']; |
|
268 | - $body = $this->last_response['body']; |
|
269 | - |
|
270 | - if ($meta === false) |
|
271 | - return; |
|
272 | - |
|
273 | - $err = null; |
|
274 | - switch ($meta['http_code']) { |
|
275 | - case 400: |
|
276 | - throw new Pest_BadRequest($this->processError($body)); |
|
277 | - break; |
|
278 | - case 401: |
|
279 | - throw new Pest_Unauthorized($this->processError($body)); |
|
280 | - break; |
|
281 | - case 403: |
|
282 | - throw new Pest_Forbidden($this->processError($body)); |
|
283 | - break; |
|
284 | - case 404: |
|
285 | - throw new Pest_NotFound($this->processError($body)); |
|
286 | - break; |
|
287 | - case 405: |
|
288 | - throw new Pest_MethodNotAllowed($this->processError($body)); |
|
289 | - break; |
|
290 | - case 409: |
|
291 | - throw new Pest_Conflict($this->processError($body)); |
|
292 | - break; |
|
293 | - case 410: |
|
294 | - throw new Pest_Gone($this->processError($body)); |
|
295 | - break; |
|
296 | - case 422: |
|
297 | - // Unprocessable Entity -- see http://www.iana.org/assignments/http-status-codes |
|
298 | - // This is now commonly used (in Rails, at least) to indicate |
|
299 | - // a response to a request that is syntactically correct, |
|
300 | - // but semantically invalid (for example, when trying to |
|
301 | - // create a resource with some required fields missing) |
|
302 | - throw new Pest_InvalidRecord($this->processError($body)); |
|
303 | - break; |
|
304 | - default: |
|
305 | - if ($meta['http_code'] >= 400 && $meta['http_code'] <= 499) |
|
306 | - throw new Pest_ClientError($this->processError($body)); |
|
307 | - elseif ($meta['http_code'] >= 500 && $meta['http_code'] <= 599) |
|
308 | - throw new Pest_ServerError($this->processError($body)); elseif (!isset($meta['http_code']) || $meta['http_code'] >= 600) { |
|
309 | - throw new Pest_UnknownResponse($this->processError($body)); |
|
310 | - } |
|
311 | - } |
|
312 | - } |
|
313 | - |
|
314 | - /** |
|
315 | - * Process body |
|
316 | - * @param string $body |
|
317 | - * @return string |
|
318 | - */ |
|
319 | - protected function processBody($body) |
|
320 | - { |
|
321 | - // Override this in classes that extend Pest. |
|
322 | - // The body of every GET/POST/PUT/DELETE response goes through |
|
323 | - // here prior to being returned. |
|
324 | - return $body; |
|
325 | - } |
|
326 | - |
|
327 | - /** |
|
328 | - * Perform HTTP HEAD request |
|
329 | - * @param string $url |
|
330 | - * @return string |
|
331 | - */ |
|
332 | - public function head($url) |
|
333 | - { |
|
334 | - $curl_opts = $this->curl_opts; |
|
335 | - $curl_opts[CURLOPT_NOBODY] = true; |
|
336 | - |
|
337 | - $curl = $this->prepRequest($this->curl_opts, $url); |
|
338 | - $body = $this->doRequest($curl); |
|
339 | - |
|
340 | - $body = $this->processBody($body); |
|
341 | - |
|
342 | - return $body; |
|
343 | - } |
|
344 | - |
|
345 | - /** |
|
346 | - * Perform HTTP POST request |
|
347 | - * |
|
348 | - * @param string $url |
|
349 | - * @param array $data |
|
350 | - * @param array $headers |
|
351 | - * @return string |
|
352 | - */ |
|
353 | - public function post($url, $data, $headers = array()) |
|
354 | - { |
|
355 | - $data = $this->prepData($data); |
|
356 | - |
|
357 | - $curl_opts = $this->curl_opts; |
|
358 | - $curl_opts[CURLOPT_CUSTOMREQUEST] = 'POST'; |
|
359 | - if (!is_array($data)) $headers[] = 'Content-Length: ' . strlen($data); |
|
360 | - $curl_opts[CURLOPT_HTTPHEADER] = $this->prepHeaders($headers); |
|
361 | - $curl_opts[CURLOPT_POSTFIELDS] = $data; |
|
362 | - |
|
363 | - $curl = $this->prepRequest($curl_opts, $url); |
|
364 | - $body = $this->doRequest($curl); |
|
365 | - |
|
366 | - $body = $this->processBody($body); |
|
367 | - |
|
368 | - return $body; |
|
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * Prepare data |
|
373 | - * @param array $data |
|
374 | - * @return array|string |
|
375 | - */ |
|
376 | - public function prepData($data) |
|
377 | - { |
|
378 | - if (is_array($data)) { |
|
379 | - $multipart = false; |
|
380 | - |
|
381 | - foreach ($data as $item) { |
|
382 | - if (is_string($item) && strncmp($item, "@", 1) == 0 && is_file(substr($item, 1))) { |
|
383 | - $multipart = true; |
|
384 | - break; |
|
385 | - } |
|
386 | - } |
|
387 | - |
|
388 | - return ($multipart) ? $data : http_build_query($data); |
|
389 | - } else { |
|
390 | - return $data; |
|
391 | - } |
|
392 | - } |
|
393 | - |
|
394 | - /** |
|
395 | - * Perform HTTP PUT request |
|
396 | - * |
|
397 | - * @param string $url |
|
398 | - * @param array $data |
|
399 | - * @param array $headers |
|
400 | - * @return string |
|
401 | - */ |
|
402 | - public function put($url, $data, $headers = array()) |
|
403 | - { |
|
404 | - $data = $this->prepData($data); |
|
405 | - |
|
406 | - $curl_opts = $this->curl_opts; |
|
407 | - $curl_opts[CURLOPT_CUSTOMREQUEST] = 'PUT'; |
|
408 | - if (!is_array($data)) $headers[] = 'Content-Length: ' . strlen($data); |
|
409 | - $curl_opts[CURLOPT_HTTPHEADER] = $this->prepHeaders($headers); |
|
410 | - $curl_opts[CURLOPT_POSTFIELDS] = $data; |
|
411 | - |
|
412 | - $curl = $this->prepRequest($curl_opts, $url); |
|
413 | - $body = $this->doRequest($curl); |
|
414 | - |
|
415 | - $body = $this->processBody($body); |
|
416 | - |
|
417 | - return $body; |
|
418 | - } |
|
419 | - |
|
420 | - /** |
|
421 | - * Perform HTTP PATCH request |
|
422 | - * |
|
423 | - * @param string $url |
|
424 | - * @param array $data |
|
425 | - * @param array $headers |
|
426 | - * @return string |
|
427 | - */ |
|
428 | - public function patch($url, $data, $headers = array()) |
|
429 | - { |
|
430 | - $data = (is_array($data)) ? http_build_query($data) : $data; |
|
431 | - |
|
432 | - $curl_opts = $this->curl_opts; |
|
433 | - $curl_opts[CURLOPT_CUSTOMREQUEST] = 'PATCH'; |
|
434 | - $headers[] = 'Content-Length: ' . strlen($data); |
|
435 | - $curl_opts[CURLOPT_HTTPHEADER] = $this->prepHeaders($headers); |
|
436 | - $curl_opts[CURLOPT_POSTFIELDS] = $data; |
|
437 | - |
|
438 | - $curl = $this->prepRequest($curl_opts, $url); |
|
439 | - $body = $this->doRequest($curl); |
|
440 | - |
|
441 | - $body = $this->processBody($body); |
|
442 | - |
|
443 | - return $body; |
|
444 | - } |
|
445 | - |
|
446 | - /** |
|
447 | - * Perform HTTP DELETE request |
|
448 | - * |
|
449 | - * @param string $url |
|
450 | - * @param array $headers |
|
451 | - * @return string |
|
452 | - */ |
|
453 | - public function delete($url, $data, $headers=array()) |
|
454 | - { |
|
455 | - $data = $this->prepData($data); |
|
456 | - |
|
457 | - $curl_opts = $this->curl_opts; |
|
458 | - $curl_opts[CURLOPT_CUSTOMREQUEST] = 'DELETE'; |
|
459 | - if (!is_array($data)) $headers[] = 'Content-Length: ' . strlen($data); |
|
460 | - $curl_opts[CURLOPT_HTTPHEADER] = $this->prepHeaders($headers); |
|
461 | - $curl_opts[CURLOPT_POSTFIELDS] = $data; |
|
462 | - |
|
463 | - $curl = $this->prepRequest($curl_opts, $url); |
|
464 | - $body = $this->doRequest($curl); |
|
465 | - |
|
466 | - $body = $this->processBody($body); |
|
467 | - |
|
468 | - return $body; |
|
469 | - } |
|
470 | - |
|
471 | - /** |
|
472 | - * Get last response body |
|
473 | - * |
|
474 | - * @return string |
|
475 | - */ |
|
476 | - public function lastBody() |
|
477 | - { |
|
478 | - return $this->last_response['body']; |
|
479 | - } |
|
480 | - |
|
481 | - /** |
|
482 | - * Get last response status |
|
483 | - * |
|
484 | - * @return int |
|
485 | - */ |
|
486 | - public function lastStatus() |
|
487 | - { |
|
488 | - return $this->last_response['meta']['http_code']; |
|
489 | - } |
|
490 | - |
|
491 | - /** |
|
492 | - * Return the last response header (case insensitive) or NULL if not present. |
|
493 | - * HTTP allows empty headers (e.g. RFC 2616, Section 14.23), thus is_null() |
|
494 | - * and not negation or empty() should be used. |
|
495 | - * |
|
496 | - * @param string $header |
|
497 | - * @return string |
|
498 | - */ |
|
499 | - public function lastHeader($header) |
|
500 | - { |
|
501 | - if (empty($this->last_headers[strtolower($header)])) { |
|
502 | - return NULL; |
|
503 | - } |
|
504 | - return $this->last_headers[strtolower($header)]; |
|
505 | - } |
|
506 | - |
|
507 | - /** |
|
508 | - * Handle header |
|
509 | - * @param $ch |
|
510 | - * @param $str |
|
511 | - * @return int |
|
512 | - */ |
|
513 | - private function handle_header($ch, $str) |
|
514 | - { |
|
515 | - if (preg_match('/([^:]+):\s(.+)/m', $str, $match)) { |
|
516 | - $this->last_headers[strtolower($match[1])] = trim($match[2]); |
|
517 | - } |
|
518 | - return strlen($str); |
|
519 | - } |
|
200 | + return $flattened; |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * Process error |
|
205 | + * @param string $body |
|
206 | + * @return string |
|
207 | + */ |
|
208 | + protected function processError($body) |
|
209 | + { |
|
210 | + // Override this in classes that extend Pest. |
|
211 | + // The body of every erroneous (non-2xx/3xx) GET/POST/PUT/DELETE |
|
212 | + // response goes through here prior to being used as the 'message' |
|
213 | + // of the resulting Pest_Exception |
|
214 | + return $body; |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * Do CURL request |
|
219 | + * @param resource $curl |
|
220 | + * @return mixed |
|
221 | + * @throws Pest_Curl_Exec |
|
222 | + * @throws Pest_Curl_Meta |
|
223 | + */ |
|
224 | + private function doRequest($curl) |
|
225 | + { |
|
226 | + $this->last_headers = array(); |
|
227 | + $this->last_response = array(); |
|
228 | + |
|
229 | + // curl_error() needs to be tested right after function failure |
|
230 | + $this->last_response["body"] = curl_exec($curl); |
|
231 | + if ($this->last_response["body"] === false && $this->throw_exceptions) { |
|
232 | + throw new Pest_Curl_Exec(curl_error($curl)); |
|
233 | + } |
|
234 | + |
|
235 | + $this->last_response["meta"] = curl_getinfo($curl); |
|
236 | + if ($this->last_response["meta"] === false && $this->throw_exceptions) { |
|
237 | + throw new Pest_Curl_Meta(curl_error($curl)); |
|
238 | + } |
|
239 | + |
|
240 | + curl_close($curl); |
|
241 | + |
|
242 | + $this->checkLastResponseForError(); |
|
243 | + |
|
244 | + return $this->last_response["body"]; |
|
245 | + } |
|
246 | + |
|
247 | + /** |
|
248 | + * Check last response for error |
|
249 | + * |
|
250 | + * @throws Pest_Conflict |
|
251 | + * @throws Pest_Gone |
|
252 | + * @throws Pest_Unauthorized |
|
253 | + * @throws Pest_ClientError |
|
254 | + * @throws Pest_MethodNotAllowed |
|
255 | + * @throws Pest_NotFound |
|
256 | + * @throws Pest_BadRequest |
|
257 | + * @throws Pest_UnknownResponse |
|
258 | + * @throws Pest_InvalidRecord |
|
259 | + * @throws Pest_ServerError |
|
260 | + * @throws Pest_Forbidden |
|
261 | + */ |
|
262 | + protected function checkLastResponseForError() |
|
263 | + { |
|
264 | + if (!$this->throw_exceptions) |
|
265 | + return; |
|
266 | + |
|
267 | + $meta = $this->last_response['meta']; |
|
268 | + $body = $this->last_response['body']; |
|
269 | + |
|
270 | + if ($meta === false) |
|
271 | + return; |
|
272 | + |
|
273 | + $err = null; |
|
274 | + switch ($meta['http_code']) { |
|
275 | + case 400: |
|
276 | + throw new Pest_BadRequest($this->processError($body)); |
|
277 | + break; |
|
278 | + case 401: |
|
279 | + throw new Pest_Unauthorized($this->processError($body)); |
|
280 | + break; |
|
281 | + case 403: |
|
282 | + throw new Pest_Forbidden($this->processError($body)); |
|
283 | + break; |
|
284 | + case 404: |
|
285 | + throw new Pest_NotFound($this->processError($body)); |
|
286 | + break; |
|
287 | + case 405: |
|
288 | + throw new Pest_MethodNotAllowed($this->processError($body)); |
|
289 | + break; |
|
290 | + case 409: |
|
291 | + throw new Pest_Conflict($this->processError($body)); |
|
292 | + break; |
|
293 | + case 410: |
|
294 | + throw new Pest_Gone($this->processError($body)); |
|
295 | + break; |
|
296 | + case 422: |
|
297 | + // Unprocessable Entity -- see http://www.iana.org/assignments/http-status-codes |
|
298 | + // This is now commonly used (in Rails, at least) to indicate |
|
299 | + // a response to a request that is syntactically correct, |
|
300 | + // but semantically invalid (for example, when trying to |
|
301 | + // create a resource with some required fields missing) |
|
302 | + throw new Pest_InvalidRecord($this->processError($body)); |
|
303 | + break; |
|
304 | + default: |
|
305 | + if ($meta['http_code'] >= 400 && $meta['http_code'] <= 499) |
|
306 | + throw new Pest_ClientError($this->processError($body)); |
|
307 | + elseif ($meta['http_code'] >= 500 && $meta['http_code'] <= 599) |
|
308 | + throw new Pest_ServerError($this->processError($body)); elseif (!isset($meta['http_code']) || $meta['http_code'] >= 600) { |
|
309 | + throw new Pest_UnknownResponse($this->processError($body)); |
|
310 | + } |
|
311 | + } |
|
312 | + } |
|
313 | + |
|
314 | + /** |
|
315 | + * Process body |
|
316 | + * @param string $body |
|
317 | + * @return string |
|
318 | + */ |
|
319 | + protected function processBody($body) |
|
320 | + { |
|
321 | + // Override this in classes that extend Pest. |
|
322 | + // The body of every GET/POST/PUT/DELETE response goes through |
|
323 | + // here prior to being returned. |
|
324 | + return $body; |
|
325 | + } |
|
326 | + |
|
327 | + /** |
|
328 | + * Perform HTTP HEAD request |
|
329 | + * @param string $url |
|
330 | + * @return string |
|
331 | + */ |
|
332 | + public function head($url) |
|
333 | + { |
|
334 | + $curl_opts = $this->curl_opts; |
|
335 | + $curl_opts[CURLOPT_NOBODY] = true; |
|
336 | + |
|
337 | + $curl = $this->prepRequest($this->curl_opts, $url); |
|
338 | + $body = $this->doRequest($curl); |
|
339 | + |
|
340 | + $body = $this->processBody($body); |
|
341 | + |
|
342 | + return $body; |
|
343 | + } |
|
344 | + |
|
345 | + /** |
|
346 | + * Perform HTTP POST request |
|
347 | + * |
|
348 | + * @param string $url |
|
349 | + * @param array $data |
|
350 | + * @param array $headers |
|
351 | + * @return string |
|
352 | + */ |
|
353 | + public function post($url, $data, $headers = array()) |
|
354 | + { |
|
355 | + $data = $this->prepData($data); |
|
356 | + |
|
357 | + $curl_opts = $this->curl_opts; |
|
358 | + $curl_opts[CURLOPT_CUSTOMREQUEST] = 'POST'; |
|
359 | + if (!is_array($data)) $headers[] = 'Content-Length: ' . strlen($data); |
|
360 | + $curl_opts[CURLOPT_HTTPHEADER] = $this->prepHeaders($headers); |
|
361 | + $curl_opts[CURLOPT_POSTFIELDS] = $data; |
|
362 | + |
|
363 | + $curl = $this->prepRequest($curl_opts, $url); |
|
364 | + $body = $this->doRequest($curl); |
|
365 | + |
|
366 | + $body = $this->processBody($body); |
|
367 | + |
|
368 | + return $body; |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * Prepare data |
|
373 | + * @param array $data |
|
374 | + * @return array|string |
|
375 | + */ |
|
376 | + public function prepData($data) |
|
377 | + { |
|
378 | + if (is_array($data)) { |
|
379 | + $multipart = false; |
|
380 | + |
|
381 | + foreach ($data as $item) { |
|
382 | + if (is_string($item) && strncmp($item, "@", 1) == 0 && is_file(substr($item, 1))) { |
|
383 | + $multipart = true; |
|
384 | + break; |
|
385 | + } |
|
386 | + } |
|
387 | + |
|
388 | + return ($multipart) ? $data : http_build_query($data); |
|
389 | + } else { |
|
390 | + return $data; |
|
391 | + } |
|
392 | + } |
|
393 | + |
|
394 | + /** |
|
395 | + * Perform HTTP PUT request |
|
396 | + * |
|
397 | + * @param string $url |
|
398 | + * @param array $data |
|
399 | + * @param array $headers |
|
400 | + * @return string |
|
401 | + */ |
|
402 | + public function put($url, $data, $headers = array()) |
|
403 | + { |
|
404 | + $data = $this->prepData($data); |
|
405 | + |
|
406 | + $curl_opts = $this->curl_opts; |
|
407 | + $curl_opts[CURLOPT_CUSTOMREQUEST] = 'PUT'; |
|
408 | + if (!is_array($data)) $headers[] = 'Content-Length: ' . strlen($data); |
|
409 | + $curl_opts[CURLOPT_HTTPHEADER] = $this->prepHeaders($headers); |
|
410 | + $curl_opts[CURLOPT_POSTFIELDS] = $data; |
|
411 | + |
|
412 | + $curl = $this->prepRequest($curl_opts, $url); |
|
413 | + $body = $this->doRequest($curl); |
|
414 | + |
|
415 | + $body = $this->processBody($body); |
|
416 | + |
|
417 | + return $body; |
|
418 | + } |
|
419 | + |
|
420 | + /** |
|
421 | + * Perform HTTP PATCH request |
|
422 | + * |
|
423 | + * @param string $url |
|
424 | + * @param array $data |
|
425 | + * @param array $headers |
|
426 | + * @return string |
|
427 | + */ |
|
428 | + public function patch($url, $data, $headers = array()) |
|
429 | + { |
|
430 | + $data = (is_array($data)) ? http_build_query($data) : $data; |
|
431 | + |
|
432 | + $curl_opts = $this->curl_opts; |
|
433 | + $curl_opts[CURLOPT_CUSTOMREQUEST] = 'PATCH'; |
|
434 | + $headers[] = 'Content-Length: ' . strlen($data); |
|
435 | + $curl_opts[CURLOPT_HTTPHEADER] = $this->prepHeaders($headers); |
|
436 | + $curl_opts[CURLOPT_POSTFIELDS] = $data; |
|
437 | + |
|
438 | + $curl = $this->prepRequest($curl_opts, $url); |
|
439 | + $body = $this->doRequest($curl); |
|
440 | + |
|
441 | + $body = $this->processBody($body); |
|
442 | + |
|
443 | + return $body; |
|
444 | + } |
|
445 | + |
|
446 | + /** |
|
447 | + * Perform HTTP DELETE request |
|
448 | + * |
|
449 | + * @param string $url |
|
450 | + * @param array $headers |
|
451 | + * @return string |
|
452 | + */ |
|
453 | + public function delete($url, $data, $headers=array()) |
|
454 | + { |
|
455 | + $data = $this->prepData($data); |
|
456 | + |
|
457 | + $curl_opts = $this->curl_opts; |
|
458 | + $curl_opts[CURLOPT_CUSTOMREQUEST] = 'DELETE'; |
|
459 | + if (!is_array($data)) $headers[] = 'Content-Length: ' . strlen($data); |
|
460 | + $curl_opts[CURLOPT_HTTPHEADER] = $this->prepHeaders($headers); |
|
461 | + $curl_opts[CURLOPT_POSTFIELDS] = $data; |
|
462 | + |
|
463 | + $curl = $this->prepRequest($curl_opts, $url); |
|
464 | + $body = $this->doRequest($curl); |
|
465 | + |
|
466 | + $body = $this->processBody($body); |
|
467 | + |
|
468 | + return $body; |
|
469 | + } |
|
470 | + |
|
471 | + /** |
|
472 | + * Get last response body |
|
473 | + * |
|
474 | + * @return string |
|
475 | + */ |
|
476 | + public function lastBody() |
|
477 | + { |
|
478 | + return $this->last_response['body']; |
|
479 | + } |
|
480 | + |
|
481 | + /** |
|
482 | + * Get last response status |
|
483 | + * |
|
484 | + * @return int |
|
485 | + */ |
|
486 | + public function lastStatus() |
|
487 | + { |
|
488 | + return $this->last_response['meta']['http_code']; |
|
489 | + } |
|
490 | + |
|
491 | + /** |
|
492 | + * Return the last response header (case insensitive) or NULL if not present. |
|
493 | + * HTTP allows empty headers (e.g. RFC 2616, Section 14.23), thus is_null() |
|
494 | + * and not negation or empty() should be used. |
|
495 | + * |
|
496 | + * @param string $header |
|
497 | + * @return string |
|
498 | + */ |
|
499 | + public function lastHeader($header) |
|
500 | + { |
|
501 | + if (empty($this->last_headers[strtolower($header)])) { |
|
502 | + return NULL; |
|
503 | + } |
|
504 | + return $this->last_headers[strtolower($header)]; |
|
505 | + } |
|
506 | + |
|
507 | + /** |
|
508 | + * Handle header |
|
509 | + * @param $ch |
|
510 | + * @param $str |
|
511 | + * @return int |
|
512 | + */ |
|
513 | + private function handle_header($ch, $str) |
|
514 | + { |
|
515 | + if (preg_match('/([^:]+):\s(.+)/m', $str, $match)) { |
|
516 | + $this->last_headers[strtolower($match[1])] = trim($match[2]); |
|
517 | + } |
|
518 | + return strlen($str); |
|
519 | + } |
|
520 | 520 | } |
521 | 521 | |
522 | 522 | class Pest_Exception extends Exception |
@@ -81,8 +81,8 @@ discard block |
||
81 | 81 | */ |
82 | 82 | public function setupAuth($user, $pass, $auth = 'basic') |
83 | 83 | { |
84 | - $this->curl_opts[CURLOPT_HTTPAUTH] = constant('CURLAUTH_' . strtoupper($auth)); |
|
85 | - $this->curl_opts[CURLOPT_USERPWD] = $user . ":" . $pass; |
|
84 | + $this->curl_opts[CURLOPT_HTTPAUTH] = constant('CURLAUTH_'.strtoupper($auth)); |
|
85 | + $this->curl_opts[CURLOPT_USERPWD] = $user.":".$pass; |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | $this->curl_opts[CURLOPT_PROXY] = $host; |
99 | 99 | $this->curl_opts[CURLOPT_PROXYPORT] = $port; |
100 | 100 | if ($user && $pass) { |
101 | - $this->curl_opts[CURLOPT_PROXYUSERPWD] = $user . ":" . $pass; |
|
101 | + $this->curl_opts[CURLOPT_PROXYUSERPWD] = $user.":".$pass; |
|
102 | 102 | } |
103 | 103 | } |
104 | 104 | |
@@ -110,14 +110,14 @@ discard block |
||
110 | 110 | * @param array $headers |
111 | 111 | * @return string |
112 | 112 | */ |
113 | - public function get($url, $data = array(), $headers=array()) |
|
113 | + public function get($url, $data = array(), $headers = array()) |
|
114 | 114 | { |
115 | 115 | if (!empty($data)) { |
116 | 116 | $pos = strpos($url, '?'); |
117 | 117 | if ($pos !== false) { |
118 | 118 | $url = substr($url, 0, $pos); |
119 | 119 | } |
120 | - $url .= '?' . http_build_query($data); |
|
120 | + $url .= '?'.http_build_query($data); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | $curl_opts = $this->curl_opts; |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | protected function prepRequest($opts, $url) |
143 | 143 | { |
144 | 144 | if (strncmp($url, $this->base_url, strlen($this->base_url)) != 0) { |
145 | - $url = rtrim($this->base_url, '/') . '/' . ltrim($url, '/'); |
|
145 | + $url = rtrim($this->base_url, '/').'/'.ltrim($url, '/'); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | $curl = curl_init($url); |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | |
195 | 195 | $flattened = array(); |
196 | 196 | foreach ($headers as $name => $value) { |
197 | - $flattened[] = $name . ': ' . $value; |
|
197 | + $flattened[] = $name.': '.$value; |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | return $flattened; |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | |
357 | 357 | $curl_opts = $this->curl_opts; |
358 | 358 | $curl_opts[CURLOPT_CUSTOMREQUEST] = 'POST'; |
359 | - if (!is_array($data)) $headers[] = 'Content-Length: ' . strlen($data); |
|
359 | + if (!is_array($data)) $headers[] = 'Content-Length: '.strlen($data); |
|
360 | 360 | $curl_opts[CURLOPT_HTTPHEADER] = $this->prepHeaders($headers); |
361 | 361 | $curl_opts[CURLOPT_POSTFIELDS] = $data; |
362 | 362 | |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | |
406 | 406 | $curl_opts = $this->curl_opts; |
407 | 407 | $curl_opts[CURLOPT_CUSTOMREQUEST] = 'PUT'; |
408 | - if (!is_array($data)) $headers[] = 'Content-Length: ' . strlen($data); |
|
408 | + if (!is_array($data)) $headers[] = 'Content-Length: '.strlen($data); |
|
409 | 409 | $curl_opts[CURLOPT_HTTPHEADER] = $this->prepHeaders($headers); |
410 | 410 | $curl_opts[CURLOPT_POSTFIELDS] = $data; |
411 | 411 | |
@@ -431,7 +431,7 @@ discard block |
||
431 | 431 | |
432 | 432 | $curl_opts = $this->curl_opts; |
433 | 433 | $curl_opts[CURLOPT_CUSTOMREQUEST] = 'PATCH'; |
434 | - $headers[] = 'Content-Length: ' . strlen($data); |
|
434 | + $headers[] = 'Content-Length: '.strlen($data); |
|
435 | 435 | $curl_opts[CURLOPT_HTTPHEADER] = $this->prepHeaders($headers); |
436 | 436 | $curl_opts[CURLOPT_POSTFIELDS] = $data; |
437 | 437 | |
@@ -450,13 +450,13 @@ discard block |
||
450 | 450 | * @param array $headers |
451 | 451 | * @return string |
452 | 452 | */ |
453 | - public function delete($url, $data, $headers=array()) |
|
453 | + public function delete($url, $data, $headers = array()) |
|
454 | 454 | { |
455 | 455 | $data = $this->prepData($data); |
456 | 456 | |
457 | 457 | $curl_opts = $this->curl_opts; |
458 | 458 | $curl_opts[CURLOPT_CUSTOMREQUEST] = 'DELETE'; |
459 | - if (!is_array($data)) $headers[] = 'Content-Length: ' . strlen($data); |
|
459 | + if (!is_array($data)) $headers[] = 'Content-Length: '.strlen($data); |
|
460 | 460 | $curl_opts[CURLOPT_HTTPHEADER] = $this->prepHeaders($headers); |
461 | 461 | $curl_opts[CURLOPT_POSTFIELDS] = $data; |
462 | 462 |
@@ -150,20 +150,23 @@ discard block |
||
150 | 150 | throw new Pest_Curl_Init($this->processError(curl_error($curl), 'curl')); |
151 | 151 | } |
152 | 152 | |
153 | - foreach ($opts as $opt => $val) |
|
154 | - curl_setopt($curl, $opt, $val); |
|
153 | + foreach ($opts as $opt => $val) { |
|
154 | + curl_setopt($curl, $opt, $val); |
|
155 | + } |
|
155 | 156 | |
156 | 157 | $this->last_request = array( |
157 | 158 | 'url' => $url |
158 | 159 | ); |
159 | 160 | |
160 | - if (isset($opts[CURLOPT_CUSTOMREQUEST])) |
|
161 | - $this->last_request['method'] = $opts[CURLOPT_CUSTOMREQUEST]; |
|
162 | - else |
|
163 | - $this->last_request['method'] = 'GET'; |
|
161 | + if (isset($opts[CURLOPT_CUSTOMREQUEST])) { |
|
162 | + $this->last_request['method'] = $opts[CURLOPT_CUSTOMREQUEST]; |
|
163 | + } else { |
|
164 | + $this->last_request['method'] = 'GET'; |
|
165 | + } |
|
164 | 166 | |
165 | - if (isset($opts[CURLOPT_POSTFIELDS])) |
|
166 | - $this->last_request['data'] = $opts[CURLOPT_POSTFIELDS]; |
|
167 | + if (isset($opts[CURLOPT_POSTFIELDS])) { |
|
168 | + $this->last_request['data'] = $opts[CURLOPT_POSTFIELDS]; |
|
169 | + } |
|
167 | 170 | |
168 | 171 | return $curl; |
169 | 172 | } |
@@ -261,14 +264,16 @@ discard block |
||
261 | 264 | */ |
262 | 265 | protected function checkLastResponseForError() |
263 | 266 | { |
264 | - if (!$this->throw_exceptions) |
|
265 | - return; |
|
267 | + if (!$this->throw_exceptions) { |
|
268 | + return; |
|
269 | + } |
|
266 | 270 | |
267 | 271 | $meta = $this->last_response['meta']; |
268 | 272 | $body = $this->last_response['body']; |
269 | 273 | |
270 | - if ($meta === false) |
|
271 | - return; |
|
274 | + if ($meta === false) { |
|
275 | + return; |
|
276 | + } |
|
272 | 277 | |
273 | 278 | $err = null; |
274 | 279 | switch ($meta['http_code']) { |
@@ -302,10 +307,11 @@ discard block |
||
302 | 307 | throw new Pest_InvalidRecord($this->processError($body)); |
303 | 308 | break; |
304 | 309 | default: |
305 | - if ($meta['http_code'] >= 400 && $meta['http_code'] <= 499) |
|
306 | - throw new Pest_ClientError($this->processError($body)); |
|
307 | - elseif ($meta['http_code'] >= 500 && $meta['http_code'] <= 599) |
|
308 | - throw new Pest_ServerError($this->processError($body)); elseif (!isset($meta['http_code']) || $meta['http_code'] >= 600) { |
|
310 | + if ($meta['http_code'] >= 400 && $meta['http_code'] <= 499) { |
|
311 | + throw new Pest_ClientError($this->processError($body)); |
|
312 | + } elseif ($meta['http_code'] >= 500 && $meta['http_code'] <= 599) { |
|
313 | + throw new Pest_ServerError($this->processError($body)); |
|
314 | + } elseif (!isset($meta['http_code']) || $meta['http_code'] >= 600) { |
|
309 | 315 | throw new Pest_UnknownResponse($this->processError($body)); |
310 | 316 | } |
311 | 317 | } |
@@ -356,7 +362,9 @@ discard block |
||
356 | 362 | |
357 | 363 | $curl_opts = $this->curl_opts; |
358 | 364 | $curl_opts[CURLOPT_CUSTOMREQUEST] = 'POST'; |
359 | - if (!is_array($data)) $headers[] = 'Content-Length: ' . strlen($data); |
|
365 | + if (!is_array($data)) { |
|
366 | + $headers[] = 'Content-Length: ' . strlen($data); |
|
367 | + } |
|
360 | 368 | $curl_opts[CURLOPT_HTTPHEADER] = $this->prepHeaders($headers); |
361 | 369 | $curl_opts[CURLOPT_POSTFIELDS] = $data; |
362 | 370 | |
@@ -405,7 +413,9 @@ discard block |
||
405 | 413 | |
406 | 414 | $curl_opts = $this->curl_opts; |
407 | 415 | $curl_opts[CURLOPT_CUSTOMREQUEST] = 'PUT'; |
408 | - if (!is_array($data)) $headers[] = 'Content-Length: ' . strlen($data); |
|
416 | + if (!is_array($data)) { |
|
417 | + $headers[] = 'Content-Length: ' . strlen($data); |
|
418 | + } |
|
409 | 419 | $curl_opts[CURLOPT_HTTPHEADER] = $this->prepHeaders($headers); |
410 | 420 | $curl_opts[CURLOPT_POSTFIELDS] = $data; |
411 | 421 | |
@@ -456,7 +466,9 @@ discard block |
||
456 | 466 | |
457 | 467 | $curl_opts = $this->curl_opts; |
458 | 468 | $curl_opts[CURLOPT_CUSTOMREQUEST] = 'DELETE'; |
459 | - if (!is_array($data)) $headers[] = 'Content-Length: ' . strlen($data); |
|
469 | + if (!is_array($data)) { |
|
470 | + $headers[] = 'Content-Length: ' . strlen($data); |
|
471 | + } |
|
460 | 472 | $curl_opts[CURLOPT_HTTPHEADER] = $this->prepHeaders($headers); |
461 | 473 | $curl_opts[CURLOPT_POSTFIELDS] = $data; |
462 | 474 |
@@ -34,6 +34,9 @@ |
||
34 | 34 | return $basePath; |
35 | 35 | } |
36 | 36 | |
37 | + /** |
|
38 | + * @param string $absolutePath |
|
39 | + */ |
|
37 | 40 | function deletePath($absolutePath) { |
38 | 41 | $dirs = array(); |
39 | 42 | $paths = array(); |
@@ -1,17 +1,17 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | define('BASE', './'); |
3 | -require_once(BASE . 'functions/init.inc.php'); |
|
4 | -require_once(BASE . 'functions/calendar_functions.php'); |
|
3 | +require_once(BASE.'functions/init.inc.php'); |
|
4 | +require_once(BASE.'functions/calendar_functions.php'); |
|
5 | 5 | |
6 | 6 | //require_once(BASE . 'lib/HTTP/WebDAV/Server.php'); |
7 | 7 | require_once('/home/jablko/public_html/gallery2/modules/webdav/lib/HTTP/WebDAV/Server.php'); |
8 | -require_once(BASE . 'lib/HTTP/CalDAV/Server.php'); |
|
8 | +require_once(BASE.'lib/HTTP/CalDAV/Server.php'); |
|
9 | 9 | |
10 | -require_once(BASE . 'lib/bennu/bennu.class.php'); |
|
11 | -require_once(BASE . 'lib/bennu/iCalendar_components.php'); |
|
12 | -require_once(BASE . 'lib/bennu/iCalendar_parameters.php'); |
|
13 | -require_once(BASE . 'lib/bennu/iCalendar_properties.php'); |
|
14 | -require_once(BASE . 'lib/bennu/iCalendar_rfc2445.php'); |
|
10 | +require_once(BASE.'lib/bennu/bennu.class.php'); |
|
11 | +require_once(BASE.'lib/bennu/iCalendar_components.php'); |
|
12 | +require_once(BASE.'lib/bennu/iCalendar_parameters.php'); |
|
13 | +require_once(BASE.'lib/bennu/iCalendar_properties.php'); |
|
14 | +require_once(BASE.'lib/bennu/iCalendar_rfc2445.php'); |
|
15 | 15 | |
16 | 16 | class HTTP_CalDAV_Server_PHPiCalendar extends HTTP_CalDAV_Server { |
17 | 17 | function getBasePath() { |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | } |
70 | 70 | |
71 | 71 | function delete($options) { |
72 | - $absolutePath = HTTP_CalDAV_Server_PHPiCalendar::getBasePath() . '/' . |
|
72 | + $absolutePath = HTTP_CalDAV_Server_PHPiCalendar::getBasePath().'/'. |
|
73 | 73 | $options['path']; |
74 | 74 | if (!file_exists($absolutePath)) { |
75 | 75 | return '404 Not Found'; |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | } |
80 | 80 | |
81 | 81 | function get(&$options) { |
82 | - $absolutePath = HTTP_CalDAV_Server_PHPiCalendar::getBasePath() . '/' . |
|
82 | + $absolutePath = HTTP_CalDAV_Server_PHPiCalendar::getBasePath().'/'. |
|
83 | 83 | $options['path']; |
84 | 84 | |
85 | 85 | if (!file_exists($absolutePath)) { |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | return '502 Bad Gateway'; |
112 | 112 | } |
113 | 113 | |
114 | - $absolutePath = HTTP_CalDAV_Server_PHPiCalendar::getBasePath() . '/' . |
|
114 | + $absolutePath = HTTP_CalDAV_Server_PHPiCalendar::getBasePath().'/'. |
|
115 | 115 | $options['path']; |
116 | 116 | |
117 | 117 | if (!file_exists($absolutePath)) { |
@@ -122,8 +122,8 @@ discard block |
||
122 | 122 | return '400 Bad Request'; |
123 | 123 | } |
124 | 124 | |
125 | - $newAbsolutePath = HTTP_CalDAV_Server_PHPiCalendar::getBasePath() . |
|
126 | - '/' . $options['dest']; |
|
125 | + $newAbsolutePath = HTTP_CalDAV_Server_PHPiCalendar::getBasePath(). |
|
126 | + '/'.$options['dest']; |
|
127 | 127 | if (!is_dir(dirname($newAbsolutePath))) { |
128 | 128 | return '409 Conflict'; |
129 | 129 | } |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | $file = array(); |
159 | 159 | $file['path'] = $path; |
160 | 160 | |
161 | - $absolutePath = HTTP_CalDAV_Server_PHPiCalendar::getBasePath() . |
|
162 | - '/' . $path; |
|
161 | + $absolutePath = HTTP_CalDAV_Server_PHPiCalendar::getBasePath(). |
|
162 | + '/'.$path; |
|
163 | 163 | $stat = stat($absolutePath); |
164 | 164 | $file['props'] = array(); |
165 | 165 | $file['props'][] = $this->mkprop('creationdate', $stat['ctime']); |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | } |
198 | 198 | |
199 | 199 | function put(&$options) { |
200 | - $absolutePath = HTTP_CalDAV_Server_PHPiCalendar::getBasePath() . '/' . |
|
200 | + $absolutePath = HTTP_CalDAV_Server_PHPiCalendar::getBasePath().'/'. |
|
201 | 201 | $options['path']; |
202 | 202 | if (!is_dir(dirname($absolutePath))) { |
203 | 203 | return '409 Conflict'; |
@@ -221,8 +221,8 @@ discard block |
||
221 | 221 | $file = array(); |
222 | 222 | $file['path'] = $path; |
223 | 223 | |
224 | - $absolutePath = HTTP_CalDAV_Server_PHPiCalendar::getBasePath() . |
|
225 | - '/' . $path; |
|
224 | + $absolutePath = HTTP_CalDAV_Server_PHPiCalendar::getBasePath(). |
|
225 | + '/'.$path; |
|
226 | 226 | $stat = stat($absolutePath); |
227 | 227 | $file['props'] = array(); |
228 | 228 | $file['props'][] = $this->mkprop('creationdate', $stat['ctime']); |
@@ -208,6 +208,9 @@ |
||
208 | 208 | // |
209 | 209 | // arg0: string version of php to check against |
210 | 210 | // return boolean true if $version is >= current php version |
211 | +/** |
|
212 | + * @param string $version |
|
213 | + */ |
|
211 | 214 | function check_php_version($version) { |
212 | 215 | // intval used for version like "4.0.4pl1" |
213 | 216 | $testVer=intval(str_replace(".", "",$version)); |
@@ -222,15 +222,15 @@ |
||
222 | 222 | // arg0: string filename |
223 | 223 | // returns boolean is the uploaded a file |
224 | 224 | function is_uploaded_file_v4 ($filename) { |
225 | - if (!$tmp_file = get_cfg_var('upload_tmp_dir')) { |
|
226 | - $tmp_file = dirname(tempnam('', '')); |
|
227 | - } |
|
228 | - $tmp_file .= '/' . basename($filename); |
|
229 | - // For Windows compat |
|
230 | - $filename = str_replace ("\\", "/", $filename); |
|
231 | - $tmp_file = str_replace ("\\", "/", $tmp_file); |
|
232 | - // User might have trailing slash in php.ini... |
|
233 | - return (ereg_replace('/+', '/', $tmp_file) == $filename); |
|
225 | + if (!$tmp_file = get_cfg_var('upload_tmp_dir')) { |
|
226 | + $tmp_file = dirname(tempnam('', '')); |
|
227 | + } |
|
228 | + $tmp_file .= '/' . basename($filename); |
|
229 | + // For Windows compat |
|
230 | + $filename = str_replace ("\\", "/", $filename); |
|
231 | + $tmp_file = str_replace ("\\", "/", $tmp_file); |
|
232 | + // User might have trailing slash in php.ini... |
|
233 | + return (ereg_replace('/+', '/', $tmp_file) == $filename); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | // return the appropriate error message if the file upload had an error |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | // Is the user logged in |
3 | 3 | // |
4 | 4 | // returns boolean is the user logged in |
5 | -function is_loggedin () { |
|
5 | +function is_loggedin() { |
|
6 | 6 | global $_SESSION; |
7 | 7 | if (!isset($_SESSION['phpical_loggedin']) || $_SESSION['phpical_loggedin'] == FALSE) { |
8 | 8 | return FALSE; |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | // arg0: string username |
17 | 17 | // arg1: string password |
18 | 18 | // returns boolean was the login successful |
19 | -function login ($username, $password) { |
|
19 | +function login($username, $password) { |
|
20 | 20 | global $_SESSION; |
21 | 21 | global $phpiCal_config; |
22 | 22 | |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | // arg0: string username |
47 | 47 | // arg1: string password |
48 | 48 | // returns boolean was login successful |
49 | -function login_ftp ($username, $password) { |
|
49 | +function login_ftp($username, $password) { |
|
50 | 50 | global $phpiCal_config; |
51 | 51 | |
52 | 52 | // set up basic connection |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | // arg0: string username |
72 | 72 | // arg1: string password |
73 | 73 | // returns boolean was login successful |
74 | -function login_internal ($username, $password) { |
|
74 | +function login_internal($username, $password) { |
|
75 | 75 | global $phpiCal_config; |
76 | 76 | |
77 | 77 | if ($phpiCal_config->auth_internal_username == $username && $phpiCal_config->auth_internal_password == $password) |
@@ -84,14 +84,14 @@ discard block |
||
84 | 84 | // |
85 | 85 | // arg0: string calendar file - not the full path |
86 | 86 | // returns boolean was delete successful |
87 | -function delete_cal ($filename) { |
|
87 | +function delete_cal($filename) { |
|
88 | 88 | global $_SESSION; |
89 | 89 | global $phpiCal_config; |
90 | 90 | global $calendar_path; |
91 | 91 | echo $filename; |
92 | 92 | |
93 | 93 | if ($phpiCal_config->auth_method == 'ftp') { |
94 | - $filename = get_ftp_calendar_path() . "/" . $filename; |
|
94 | + $filename = get_ftp_calendar_path()."/".$filename; |
|
95 | 95 | |
96 | 96 | // set up basic connection |
97 | 97 | $conn_id = @ftp_connect($phpiCal_config->ftp_server); |
@@ -119,11 +119,11 @@ discard block |
||
119 | 119 | $delete = unlink($filename); |
120 | 120 | clearstatcache(); |
121 | 121 | if (@file_exists($filename)) { |
122 | - $filesys = eregi_replace("/","\\", $filename); |
|
122 | + $filesys = eregi_replace("/", "\\", $filename); |
|
123 | 123 | $delete = system("rm -f $filesys"); |
124 | 124 | clearstatcache(); |
125 | 125 | if (@file_exists($filename)) { |
126 | - $delete = chmod ($filename, 0775); |
|
126 | + $delete = chmod($filename, 0775); |
|
127 | 127 | $delete = unlink($filename); |
128 | 128 | $delete = system("del $filesys"); |
129 | 129 | } |
@@ -145,14 +145,14 @@ discard block |
||
145 | 145 | // arg0: string full path to calendar file |
146 | 146 | // arg1: string destination filename |
147 | 147 | // returns boolean was copy successful |
148 | -function copy_cal ($source, $destination) { |
|
148 | +function copy_cal($source, $destination) { |
|
149 | 149 | global $_SESSION; |
150 | 150 | global $phpiCal_config; |
151 | 151 | global $calendar_path; |
152 | 152 | |
153 | 153 | if ($phpiCal_config->auth_method == 'ftp') { |
154 | - $destination = get_ftp_calendar_path() . "/" . basename($destination); |
|
155 | - $destination = str_replace ("\\", "/", realpath($destination)); |
|
154 | + $destination = get_ftp_calendar_path()."/".basename($destination); |
|
155 | + $destination = str_replace("\\", "/", realpath($destination)); |
|
156 | 156 | |
157 | 157 | // set up basic connection |
158 | 158 | $conn_id = ftp_connect($phpiCal_config->ftp_server); |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | return TRUE; |
178 | 178 | } |
179 | 179 | else { |
180 | - $destination = $calendar_path . "/" . basename($destination); |
|
180 | + $destination = $calendar_path."/".basename($destination); |
|
181 | 181 | |
182 | 182 | if (check_php_version('4.0.3')) { |
183 | 183 | return move_uploaded_file($source, $destination); |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | if ($phpiCal_config->ftp_calendar_path != '') |
201 | 201 | return $phpiCal_config->ftp_calendar_path; |
202 | 202 | else { |
203 | - return str_replace ("\\", "/", realpath($calendar_path)); |
|
203 | + return str_replace("\\", "/", realpath($calendar_path)); |
|
204 | 204 | } |
205 | 205 | } |
206 | 206 | |
@@ -210,9 +210,9 @@ discard block |
||
210 | 210 | // return boolean true if $version is >= current php version |
211 | 211 | function check_php_version($version) { |
212 | 212 | // intval used for version like "4.0.4pl1" |
213 | - $testVer=intval(str_replace(".", "",$version)); |
|
214 | - $curVer=intval(str_replace(".", "",phpversion())); |
|
215 | - if( $curVer < $testVer ) |
|
213 | + $testVer = intval(str_replace(".", "", $version)); |
|
214 | + $curVer = intval(str_replace(".", "", phpversion())); |
|
215 | + if ($curVer < $testVer) |
|
216 | 216 | return FALSE; |
217 | 217 | return TRUE; |
218 | 218 | } |
@@ -221,14 +221,14 @@ discard block |
||
221 | 221 | // |
222 | 222 | // arg0: string filename |
223 | 223 | // returns boolean is the uploaded a file |
224 | -function is_uploaded_file_v4 ($filename) { |
|
224 | +function is_uploaded_file_v4($filename) { |
|
225 | 225 | if (!$tmp_file = get_cfg_var('upload_tmp_dir')) { |
226 | 226 | $tmp_file = dirname(tempnam('', '')); |
227 | 227 | } |
228 | - $tmp_file .= '/' . basename($filename); |
|
228 | + $tmp_file .= '/'.basename($filename); |
|
229 | 229 | // For Windows compat |
230 | - $filename = str_replace ("\\", "/", $filename); |
|
231 | - $tmp_file = str_replace ("\\", "/", $tmp_file); |
|
230 | + $filename = str_replace("\\", "/", $filename); |
|
231 | + $tmp_file = str_replace("\\", "/", $tmp_file); |
|
232 | 232 | // User might have trailing slash in php.ini... |
233 | 233 | return (ereg_replace('/+', '/', $tmp_file) == $filename); |
234 | 234 | } |
@@ -237,24 +237,24 @@ discard block |
||
237 | 237 | // |
238 | 238 | // arg0: array error number from $_FILES[file]['error'] |
239 | 239 | // returns string error message |
240 | -function get_upload_error ($upload_error) { |
|
240 | +function get_upload_error($upload_error) { |
|
241 | 241 | global $php_error_lang; |
242 | 242 | global $upload_error_lang; |
243 | 243 | global $upload_error_gen_lang; |
244 | 244 | |
245 | 245 | if (isset($upload_error)) { |
246 | 246 | // This is only available in PHP >= 4.2.0 |
247 | - $error = $php_error_lang . " "; |
|
248 | - switch($upload_error) { |
|
247 | + $error = $php_error_lang." "; |
|
248 | + switch ($upload_error) { |
|
249 | 249 | case 0: //no error; possible file attack! |
250 | 250 | case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini |
251 | 251 | case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form |
252 | 252 | case 3: //uploaded file was only partially uploaded |
253 | 253 | case 4: //no file was uploaded |
254 | - $error = $error . $upload_error . ": " . $upload_error_lang[$upload_error]; |
|
254 | + $error = $error.$upload_error.": ".$upload_error_lang[$upload_error]; |
|
255 | 255 | break; |
256 | 256 | default: //a default error, just in case! :) |
257 | - $error = $error . $upload_error . ": " . $upload_error_gen_lang; |
|
257 | + $error = $error.$upload_error.": ".$upload_error_gen_lang; |
|
258 | 258 | break; |
259 | 259 | } |
260 | 260 | } |
@@ -269,9 +269,9 @@ discard block |
||
269 | 269 | // |
270 | 270 | // arg0: string filename |
271 | 271 | // returns booloean does the filename end in .ics |
272 | -function is_uploaded_ics ($filename) { |
|
272 | +function is_uploaded_ics($filename) { |
|
273 | 273 | // Check the file extension for .ics. Can also check the the mime type, but it's not reliable so why bother... |
274 | - if(preg_match("/.ics$/i", $filename)) { |
|
274 | + if (preg_match("/.ics$/i", $filename)) { |
|
275 | 275 | return TRUE; |
276 | 276 | } |
277 | 277 | else { |
@@ -6,10 +6,10 @@ discard block |
||
6 | 6 | global $_SESSION; |
7 | 7 | if (!isset($_SESSION['phpical_loggedin']) || $_SESSION['phpical_loggedin'] == FALSE) { |
8 | 8 | return FALSE; |
9 | + } else { |
|
10 | + return TRUE; |
|
11 | + } |
|
9 | 12 | } |
10 | - else |
|
11 | - return TRUE; |
|
12 | -} |
|
13 | 13 | |
14 | 14 | // Attempt to login. If login is valid, set the session variable 'phpical_loggedin' to TRUE and store the username and password in the session |
15 | 15 | // |
@@ -51,7 +51,9 @@ discard block |
||
51 | 51 | |
52 | 52 | // set up basic connection |
53 | 53 | $conn_id = @ftp_connect($phpiCal_config->ftp_server, $phpiCal_config->ftp_port); |
54 | - if (!$conn_id) exit(error('Cannot connect to FTP server', $filename)); |
|
54 | + if (!$conn_id) { |
|
55 | + exit(error('Cannot connect to FTP server', $filename)); |
|
56 | + } |
|
55 | 57 | // login with username and password |
56 | 58 | $login_result = @ftp_login($conn_id, $username, $password); |
57 | 59 | |
@@ -74,11 +76,12 @@ discard block |
||
74 | 76 | function login_internal ($username, $password) { |
75 | 77 | global $phpiCal_config; |
76 | 78 | |
77 | - if ($phpiCal_config->auth_internal_username == $username && $phpiCal_config->auth_internal_password == $password) |
|
78 | - return TRUE; |
|
79 | - else |
|
80 | - return FALSE; |
|
81 | -} |
|
79 | + if ($phpiCal_config->auth_internal_username == $username && $phpiCal_config->auth_internal_password == $password) { |
|
80 | + return TRUE; |
|
81 | + } else { |
|
82 | + return FALSE; |
|
83 | + } |
|
84 | + } |
|
82 | 85 | |
83 | 86 | // Delete a calendar. If using ftp for authentication, use ftp to delete. Otherwise, use file system functions. |
84 | 87 | // |
@@ -100,15 +103,17 @@ discard block |
||
100 | 103 | $login_result = @ftp_login($conn_id, $_SESSION['phpical_username'], $_SESSION['phpical_password']); |
101 | 104 | |
102 | 105 | // check connection |
103 | - if ((!$conn_id) || (!$login_result)) |
|
104 | - return FALSE; |
|
106 | + if ((!$conn_id) || (!$login_result)) { |
|
107 | + return FALSE; |
|
108 | + } |
|
105 | 109 | |
106 | 110 | // delete the file |
107 | 111 | $delete = @ftp_delete($conn_id, $filename); |
108 | 112 | |
109 | 113 | // check delete status |
110 | - if (!$delete) |
|
111 | - return FALSE; |
|
114 | + if (!$delete) { |
|
115 | + return FALSE; |
|
116 | + } |
|
112 | 117 | |
113 | 118 | // close the FTP stream |
114 | 119 | @ftp_close($conn_id); |
@@ -131,8 +136,7 @@ discard block |
||
131 | 136 | clearstatcache(); |
132 | 137 | if (@file_exists($filename)) { |
133 | 138 | return FALSE; |
134 | - } |
|
135 | - else { |
|
139 | + } else { |
|
136 | 140 | return TRUE; |
137 | 141 | } |
138 | 142 | |
@@ -161,28 +165,28 @@ discard block |
||
161 | 165 | $login_result = ftp_login($conn_id, $_SESSION['phpical_username'], $_SESSION['phpical_password']); |
162 | 166 | |
163 | 167 | // check connection |
164 | - if ((!$conn_id) || (!$login_result)) |
|
165 | - return FALSE; |
|
168 | + if ((!$conn_id) || (!$login_result)) { |
|
169 | + return FALSE; |
|
170 | + } |
|
166 | 171 | |
167 | 172 | // upload the file |
168 | 173 | $upload = ftp_put($conn_id, $destination, $source, FTP_ASCII); |
169 | 174 | |
170 | 175 | // check upload status |
171 | - if (!$upload) |
|
172 | - return FALSE; |
|
176 | + if (!$upload) { |
|
177 | + return FALSE; |
|
178 | + } |
|
173 | 179 | |
174 | 180 | // close the FTP stream |
175 | 181 | ftp_close($conn_id); |
176 | 182 | |
177 | 183 | return TRUE; |
178 | - } |
|
179 | - else { |
|
184 | + } else { |
|
180 | 185 | $destination = $calendar_path . "/" . basename($destination); |
181 | 186 | |
182 | 187 | if (check_php_version('4.0.3')) { |
183 | 188 | return move_uploaded_file($source, $destination); |
184 | - } |
|
185 | - else { |
|
189 | + } else { |
|
186 | 190 | return copy($source, $destination); |
187 | 191 | } |
188 | 192 | } |
@@ -197,9 +201,9 @@ discard block |
||
197 | 201 | global $phpiCal_config; |
198 | 202 | global $calendar_path; |
199 | 203 | |
200 | - if ($phpiCal_config->ftp_calendar_path != '') |
|
201 | - return $phpiCal_config->ftp_calendar_path; |
|
202 | - else { |
|
204 | + if ($phpiCal_config->ftp_calendar_path != '') { |
|
205 | + return $phpiCal_config->ftp_calendar_path; |
|
206 | + } else { |
|
203 | 207 | return str_replace ("\\", "/", realpath($calendar_path)); |
204 | 208 | } |
205 | 209 | } |
@@ -212,8 +216,9 @@ discard block |
||
212 | 216 | // intval used for version like "4.0.4pl1" |
213 | 217 | $testVer=intval(str_replace(".", "",$version)); |
214 | 218 | $curVer=intval(str_replace(".", "",phpversion())); |
215 | - if( $curVer < $testVer ) |
|
216 | - return FALSE; |
|
219 | + if( $curVer < $testVer ) { |
|
220 | + return FALSE; |
|
221 | + } |
|
217 | 222 | return TRUE; |
218 | 223 | } |
219 | 224 | |
@@ -257,8 +262,7 @@ discard block |
||
257 | 262 | $error = $error . $upload_error . ": " . $upload_error_gen_lang; |
258 | 263 | break; |
259 | 264 | } |
260 | - } |
|
261 | - else { |
|
265 | + } else { |
|
262 | 266 | $error = $upload_error_gen_lang; |
263 | 267 | } |
264 | 268 | |
@@ -273,8 +277,7 @@ discard block |
||
273 | 277 | // Check the file extension for .ics. Can also check the the mime type, but it's not reliable so why bother... |
274 | 278 | if(preg_match("/.ics$/i", $filename)) { |
275 | 279 | return TRUE; |
276 | - } |
|
277 | - else { |
|
280 | + } else { |
|
278 | 281 | return FALSE; |
279 | 282 | } |
280 | 283 | } |
@@ -75,6 +75,9 @@ discard block |
||
75 | 75 | * Resolve relative paths |
76 | 76 | * Utility function for remote_filemtime() |
77 | 77 | */ |
78 | +/** |
|
79 | + * @param string $rel_path |
|
80 | + */ |
|
78 | 81 | function resolve_path($url, $rel_path) { |
79 | 82 | if (parse_url($rel_path) !== FALSE) { |
80 | 83 | // Path is a URL |
@@ -224,6 +227,9 @@ discard block |
||
224 | 227 | // $have is the current offset (ie, '-0500') |
225 | 228 | // $want is the wanted offset (ie, '-0700') |
226 | 229 | // $time is the unixtime relative to $have |
230 | +/** |
|
231 | + * @param integer $time |
|
232 | + */ |
|
227 | 233 | function calcTime($have, $want, $time) { |
228 | 234 | if ($have == 'none' || $want == 'none') return $time; |
229 | 235 | $have_secs = calcOffset($have); |
@@ -233,6 +239,9 @@ discard block |
||
233 | 239 | return $time; |
234 | 240 | } |
235 | 241 | |
242 | +/** |
|
243 | + * @param integer $time |
|
244 | + */ |
|
236 | 245 | function chooseOffset($time, $timezone = '') { |
237 | 246 | global $tz_array, $summary; |
238 | 247 | switch ($timezone) { |
@@ -21,20 +21,18 @@ discard block |
||
21 | 21 | $uri = parse_url($url); |
22 | 22 | $uri['proto'] = ( |
23 | 23 | (isset($uri['proto']) && ($uri['proto'] == 'https')) ? |
24 | - 'ssl://' : |
|
25 | - '' |
|
24 | + 'ssl://' : '' |
|
26 | 25 | ); |
27 | 26 | $uri['port'] = isset($uri['port']) ? $uri['port'] : 80; |
28 | 27 | $uri['path'] = isset($uri['path']) ? $uri['path'] : '/'; |
29 | - $uri['query'] = isset($uri['query']) ? ('?' . $uri['query']) : ''; |
|
30 | - $path = $uri['path'] . $uri['query']; |
|
28 | + $uri['query'] = isset($uri['query']) ? ('?'.$uri['query']) : ''; |
|
29 | + $path = $uri['path'].$uri['query']; |
|
31 | 30 | $auth = ( |
32 | 31 | (isset($uri['user']) || isset($uri['pass'])) ? |
33 | - ('Authentication: Basic ' . base64_encode(@$uri['user'] . ':' . @$uri['pass']) . "\r\n") : |
|
34 | - '' |
|
32 | + ('Authentication: Basic '.base64_encode(@$uri['user'].':'.@$uri['pass'])."\r\n") : '' |
|
35 | 33 | ); |
36 | 34 | |
37 | - $handle = @fsockopen($uri['proto'] . $uri['host'], $uri['port']); |
|
35 | + $handle = @fsockopen($uri['proto'].$uri['host'], $uri['port']); |
|
38 | 36 | if (!$handle) { |
39 | 37 | $remote_files[$url] = 0; |
40 | 38 | return 0; |
@@ -83,29 +81,28 @@ discard block |
||
83 | 81 | |
84 | 82 | // Path is relative to this domain |
85 | 83 | $uri = parse_url($url); |
86 | - $uri['proto'] = (isset($uri['proto']) ? $uri['proto'] : 'http://'); |
|
87 | - $uri['port'] = (isset($uri['port']) ? (':' . $uri['port']) : ''); |
|
84 | + $uri['proto'] = (isset($uri['proto']) ? $uri['proto'] : 'http://'); |
|
85 | + $uri['port'] = (isset($uri['port']) ? (':'.$uri['port']) : ''); |
|
88 | 86 | $auth = ( |
89 | 87 | (isset($uri['user']) || isset($uri['pass'])) ? |
90 | - (urlencode(@$uri['user']) . ':' . urlencode(@$uri['pass']) . '@') : |
|
91 | - '' |
|
88 | + (urlencode(@$uri['user']).':'.urlencode(@$uri['pass']).'@') : '' |
|
92 | 89 | ); |
93 | 90 | |
94 | 91 | $rel_path = str_replace('\\', '/', $rel_path); |
95 | 92 | if ($rel_path{0} == '/') { |
96 | 93 | // Absolute path |
97 | - return $uri['proto'] . '://' . $auth . $uri['host'] . $uri['port'] . $rel_path; |
|
94 | + return $uri['proto'].'://'.$auth.$uri['host'].$uri['port'].$rel_path; |
|
98 | 95 | } |
99 | 96 | |
100 | 97 | // Relative path |
101 | - return $uri['proto'] . '://' . $auth . $uri['host'] . $uri['port'] . @$uri['path'] . '/' . $rel_path; |
|
98 | + return $uri['proto'].'://'.$auth.$uri['host'].$uri['port'].@$uri['path'].'/'.$rel_path; |
|
102 | 99 | } |
103 | 100 | |
104 | 101 | // takes iCalendar 2 day format and makes it into 3 characters |
105 | 102 | // if $txt is true, it returns the 3 letters, otherwise it returns the |
106 | 103 | // integer of that day; 0=Sun, 1=Mon, etc. |
107 | -function two2threeCharDays($day, $txt=true) { |
|
108 | - switch($day) { |
|
104 | +function two2threeCharDays($day, $txt = true) { |
|
105 | + switch ($day) { |
|
109 | 106 | case 'SU': return ($txt ? 'sun' : '0'); |
110 | 107 | case 'MO': return ($txt ? 'mon' : '1'); |
111 | 108 | case 'TU': return ($txt ? 'tue' : '2'); |
@@ -124,12 +121,12 @@ discard block |
||
124 | 121 | if (isset($phpiCal_config->week_start_day)) $week_start_day = $phpiCal_config->week_start_day; |
125 | 122 | $timestamp = strtotime($Ymd); |
126 | 123 | $num = date('w', strtotime($week_start_day)); |
127 | - $start_day_time = strtotime((date('w',$timestamp)==$num ? "$week_start_day" : "last $week_start_day"), $timestamp); |
|
128 | - $ret_unixtime = strtotime($day,$start_day_time); |
|
124 | + $start_day_time = strtotime((date('w', $timestamp) == $num ? "$week_start_day" : "last $week_start_day"), $timestamp); |
|
125 | + $ret_unixtime = strtotime($day, $start_day_time); |
|
129 | 126 | // Fix for 992744 |
130 | 127 | // $ret_unixtime = strtotime('+12 hours', $ret_unixtime); |
131 | - $ret_unixtime += (12 * 60 * 60); |
|
132 | - $ret = date('Ymd',$ret_unixtime); |
|
128 | + $ret_unixtime += (12*60*60); |
|
129 | + $ret = date('Ymd', $ret_unixtime); |
|
133 | 130 | return $ret; |
134 | 131 | } |
135 | 132 | |
@@ -140,7 +137,7 @@ discard block |
||
140 | 137 | $sun_now = dateOfWeek($now, "Sunday"); |
141 | 138 | $sun_then = dateOfWeek($then, "Sunday"); |
142 | 139 | $seconds_now = strtotime($sun_now); |
143 | - $seconds_then = strtotime($sun_then); |
|
140 | + $seconds_then = strtotime($sun_then); |
|
144 | 141 | $diff_weeks = round(($seconds_now - $seconds_then)/(60*60*24*7)); |
145 | 142 | return $diff_weeks; |
146 | 143 | } |
@@ -149,7 +146,7 @@ discard block |
||
149 | 146 | // that differ between them. |
150 | 147 | function dayCompare($now, $then) { |
151 | 148 | $seconds_now = strtotime($now); |
152 | - $seconds_then = strtotime($then); |
|
149 | + $seconds_then = strtotime($then); |
|
153 | 150 | $diff_seconds = $seconds_now - $seconds_then; |
154 | 151 | $diff_minutes = $diff_seconds/60; |
155 | 152 | $diff_hours = $diff_minutes/60; |
@@ -161,22 +158,22 @@ discard block |
||
161 | 158 | // function to compare to dates in Ymd and return the number of months |
162 | 159 | // that differ between them. |
163 | 160 | function monthCompare($now, $then) { |
164 | - ereg ("([0-9]{4})([0-9]{2})([0-9]{2})", $now, $date_now); |
|
165 | - ereg ("([0-9]{4})([0-9]{2})([0-9]{2})", $then, $date_then); |
|
161 | + ereg("([0-9]{4})([0-9]{2})([0-9]{2})", $now, $date_now); |
|
162 | + ereg("([0-9]{4})([0-9]{2})([0-9]{2})", $then, $date_then); |
|
166 | 163 | $diff_years = $date_now[1] - $date_then[1]; |
167 | 164 | $diff_months = $date_now[2] - $date_then[2]; |
168 | 165 | if ($date_now[2] < $date_then[2]) { |
169 | 166 | $diff_years -= 1; |
170 | - $diff_months = ($diff_months + 12) % 12; |
|
167 | + $diff_months = ($diff_months + 12)%12; |
|
171 | 168 | } |
172 | - $diff_months = ($diff_years * 12) + $diff_months; |
|
169 | + $diff_months = ($diff_years*12) + $diff_months; |
|
173 | 170 | |
174 | 171 | return $diff_months; |
175 | 172 | } |
176 | 173 | |
177 | 174 | function yearCompare($now, $then) { |
178 | - ereg ("([0-9]{4})([0-9]{2})([0-9]{2})", $now, $date_now); |
|
179 | - ereg ("([0-9]{4})([0-9]{2})([0-9]{2})", $then, $date_then); |
|
175 | + ereg("([0-9]{4})([0-9]{2})([0-9]{2})", $now, $date_now); |
|
176 | + ereg("([0-9]{4})([0-9]{2})([0-9]{2})", $then, $date_then); |
|
180 | 177 | $diff_years = $date_now[1] - $date_then[1]; |
181 | 178 | return $diff_years; |
182 | 179 | } |
@@ -192,7 +189,7 @@ discard block |
||
192 | 189 | function localizeDate($format, $timestamp) { |
193 | 190 | global $daysofweek_lang, $daysofweekshort_lang, $daysofweekreallyshort_lang, $monthsofyear_lang, $monthsofyear_lang, $monthsofyearshort_lang; |
194 | 191 | $year = date("Y", $timestamp); |
195 | - $month = date("n", $timestamp)-1; |
|
192 | + $month = date("n", $timestamp) - 1; |
|
196 | 193 | $day = date("j", $timestamp); |
197 | 194 | $dayofweek = date("w", $timestamp); |
198 | 195 | $weeknumber = date("W", $timestamp); |
@@ -215,7 +212,7 @@ discard block |
||
215 | 212 | $sign = substr($offset_str, 0, 1); |
216 | 213 | $hours = substr($offset_str, 1, 2); |
217 | 214 | $mins = substr($offset_str, 3, 2); |
218 | - $secs = ((int)$hours * 3600) + ((int)$mins * 60); |
|
215 | + $secs = ((int)$hours*3600) + ((int)$mins*60); |
|
219 | 216 | if ($sign == '-') $secs = 0 - $secs; |
220 | 217 | return $secs; |
221 | 218 | } |
@@ -274,10 +271,10 @@ discard block |
||
274 | 271 | } |
275 | 272 | |
276 | 273 | if (!empty($arr['location'])) { |
277 | - $title .= "\nLocation: " . chopToWordCount(sanitizeForWeb(urldecode($arr['location'])), 20); |
|
274 | + $title .= "\nLocation: ".chopToWordCount(sanitizeForWeb(urldecode($arr['location'])), 20); |
|
278 | 275 | } |
279 | 276 | if (!empty($arr['description'])) { |
280 | - $title .= "\n\n" . chopToWordCount(sanitizeForWeb(urldecode($arr['description'])), 80); |
|
277 | + $title .= "\n\n".chopToWordCount(sanitizeForWeb(urldecode($arr['description'])), 80); |
|
281 | 278 | } |
282 | 279 | $title = trim($title); |
283 | 280 | |
@@ -306,8 +303,8 @@ discard block |
||
306 | 303 | # build tooltip |
307 | 304 | $title = makeTitle($arr, $time); |
308 | 305 | # for iCal pseudo tag <http> comptability |
309 | - if (ereg('<([[:alpha:]]+://)([^<>[:space:]]+)>',$event_text,$matches)) { |
|
310 | - $full_event_text = $matches[1] . $matches[2]; |
|
306 | + if (ereg('<([[:alpha:]]+://)([^<>[:space:]]+)>', $event_text, $matches)) { |
|
307 | + $full_event_text = $matches[1].$matches[2]; |
|
311 | 308 | $event_text = $matches[2]; |
312 | 309 | } else { |
313 | 310 | $full_event_text = $event_text; |
@@ -317,7 +314,7 @@ discard block |
||
317 | 314 | if (!empty($link_class)) $link_class = ' class="'.$link_class.'"'; |
318 | 315 | |
319 | 316 | if (!empty($event_text)) { |
320 | - $title = strip_tags(str_replace('<br />',"\n",$title)); |
|
317 | + $title = strip_tags(str_replace('<br />', "\n", $title)); |
|
321 | 318 | if ($lines > 0) { |
322 | 319 | $event_text = word_wrap($event_text, $length, $lines); |
323 | 320 | } |
@@ -326,7 +323,7 @@ discard block |
||
326 | 323 | $escaped_date = addslashes($event_date); |
327 | 324 | $escaped_time = addslashes($time); |
328 | 325 | $escaped_uid = addslashes($uid); |
329 | - $event_data = addslashes(serialize ($arr)); |
|
326 | + $event_data = addslashes(serialize($arr)); |
|
330 | 327 | // fix for URL-length bug in IE: populate and submit a hidden form on click |
331 | 328 | static $popup_data_index = 0; |
332 | 329 | $return = " |
@@ -357,10 +354,10 @@ discard block |
||
357 | 354 | */ |
358 | 355 | function extractDateTime($data, $property, $field) { |
359 | 356 | global $tz_array, $phpiCal_config, $calendar_tz; |
360 | - $allday =''; #suppress error on returning undef. |
|
357 | + $allday = ''; #suppress error on returning undef. |
|
361 | 358 | // Check for zulu time. |
362 | 359 | $zulu_time = false; |
363 | - if (substr($data,-1) == 'Z') $zulu_time = true; |
|
360 | + if (substr($data, -1) == 'Z') $zulu_time = true; |
|
364 | 361 | // Pull out the timezone, or use GMT if zulu time was indicated. |
365 | 362 | if (preg_match('/^'.$property.';TZID=/i', $field)) { |
366 | 363 | $tz_tmp = explode('=', $field); |
@@ -370,9 +367,9 @@ discard block |
||
370 | 367 | } |
371 | 368 | |
372 | 369 | // Extract date-only values. |
373 | - if ((preg_match('/^'.$property.';VALUE=DATE:/i', $field)) || (ereg ('^([0-9]{4})([0-9]{2})([0-9]{2})$', $data))) { |
|
370 | + if ((preg_match('/^'.$property.';VALUE=DATE:/i', $field)) || (ereg('^([0-9]{4})([0-9]{2})([0-9]{2})$', $data))) { |
|
374 | 371 | // Pull out the date value. Minimum year is 1970. |
375 | - ereg ('([0-9]{4})([0-9]{2})([0-9]{2})', $data, $dt_check); |
|
372 | + ereg('([0-9]{4})([0-9]{2})([0-9]{2})', $data, $dt_check); |
|
376 | 373 | if ($dt_check[1] < 1970) { |
377 | 374 | $dt_check[1] = '1970'; |
378 | 375 | } |
@@ -383,13 +380,13 @@ discard block |
||
383 | 380 | } |
384 | 381 | // Extract date-time values. |
385 | 382 | // Pull out the date and time values. Minimum year is 1970. |
386 | - preg_match ('/([0-9]{4})([0-9]{2})([0-9]{2})T{0,1}([0-9]{0,2})([0-9]{0,2})/', $data, $regs); |
|
383 | + preg_match('/([0-9]{4})([0-9]{2})([0-9]{2})T{0,1}([0-9]{0,2})([0-9]{0,2})/', $data, $regs); |
|
387 | 384 | if (!isset ($regs[1])) return; |
388 | 385 | if ($regs[1] < 1970) { |
389 | 386 | $regs[1] = '1970'; |
390 | 387 | } |
391 | - $date = $regs[1] . $regs[2] . $regs[3]; |
|
392 | - $time = $regs[4] . $regs[5]; |
|
388 | + $date = $regs[1].$regs[2].$regs[3]; |
|
389 | + $time = $regs[4].$regs[5]; |
|
393 | 390 | $unixtime = mktime($regs[4], $regs[5], 0, $regs[2], $regs[3], $regs[1]); |
394 | 391 | # chooseOffset checks for Daylight Saving Time |
395 | 392 | $server_offset_tmp = chooseOffset($unixtime, $phpiCal_config->timezone); |
@@ -418,11 +415,11 @@ discard block |
||
418 | 415 | |
419 | 416 | Need to return the part that matches a key in $tz_array |
420 | 417 | */ |
421 | -function match_tz($data){ |
|
418 | +function match_tz($data) { |
|
422 | 419 | global $tz_array; |
423 | 420 | if (isset($tz_array[$data])) return $data; |
424 | - foreach ($tz_array as $key=>$val){ |
|
425 | - if (strpos(" $data",$key) > 0) return $key; |
|
421 | + foreach ($tz_array as $key=>$val) { |
|
422 | + if (strpos(" $data", $key) > 0) return $key; |
|
426 | 423 | } |
427 | 424 | return $data; |
428 | 425 | }?> |
429 | 426 | \ No newline at end of file |
@@ -12,11 +12,15 @@ discard block |
||
12 | 12 | */ |
13 | 13 | function remote_filemtime($url, $recurse = 0) { |
14 | 14 | // We hate infinite loops! |
15 | - if (++$recurse > 5) return 0; |
|
15 | + if (++$recurse > 5) { |
|
16 | + return 0; |
|
17 | + } |
|
16 | 18 | |
17 | 19 | // Caching the remote mtime is a Really Good Idea. |
18 | 20 | static $remote_files = array(); |
19 | - if (isset($remote_files[$url])) return $remote_files[$url]; |
|
21 | + if (isset($remote_files[$url])) { |
|
22 | + return $remote_files[$url]; |
|
23 | + } |
|
20 | 24 | |
21 | 25 | $uri = parse_url($url); |
22 | 26 | $uri['proto'] = ( |
@@ -44,7 +48,9 @@ discard block |
||
44 | 48 | $headers = array(); |
45 | 49 | while (!feof($handle)) { |
46 | 50 | $line = trim(fgets($handle, 1024)); |
47 | - if (empty($line)) break; |
|
51 | + if (empty($line)) { |
|
52 | + break; |
|
53 | + } |
|
48 | 54 | $headers[] = $line; |
49 | 55 | } |
50 | 56 | fclose($handle); |
@@ -64,7 +70,9 @@ discard block |
||
64 | 70 | $result = strtotime($value); |
65 | 71 | break; |
66 | 72 | } |
67 | - if ($result) break; |
|
73 | + if ($result) { |
|
74 | + break; |
|
75 | + } |
|
68 | 76 | } |
69 | 77 | |
70 | 78 | $remote_files[$url] = $result; |
@@ -121,7 +129,9 @@ discard block |
||
121 | 129 | function dateOfWeek($Ymd, $day) { |
122 | 130 | global $phpiCal_config; |
123 | 131 | $week_start_day = 'Sunday'; |
124 | - if (isset($phpiCal_config->week_start_day)) $week_start_day = $phpiCal_config->week_start_day; |
|
132 | + if (isset($phpiCal_config->week_start_day)) { |
|
133 | + $week_start_day = $phpiCal_config->week_start_day; |
|
134 | + } |
|
125 | 135 | $timestamp = strtotime($Ymd); |
126 | 136 | $num = date('w', strtotime($week_start_day)); |
127 | 137 | $start_day_time = strtotime((date('w',$timestamp)==$num ? "$week_start_day" : "last $week_start_day"), $timestamp); |
@@ -216,7 +226,9 @@ discard block |
||
216 | 226 | $hours = substr($offset_str, 1, 2); |
217 | 227 | $mins = substr($offset_str, 3, 2); |
218 | 228 | $secs = ((int)$hours * 3600) + ((int)$mins * 60); |
219 | - if ($sign == '-') $secs = 0 - $secs; |
|
229 | + if ($sign == '-') { |
|
230 | + $secs = 0 - $secs; |
|
231 | + } |
|
220 | 232 | return $secs; |
221 | 233 | } |
222 | 234 | |
@@ -225,7 +237,9 @@ discard block |
||
225 | 237 | // $want is the wanted offset (ie, '-0700') |
226 | 238 | // $time is the unixtime relative to $have |
227 | 239 | function calcTime($have, $want, $time) { |
228 | - if ($have == 'none' || $want == 'none') return $time; |
|
240 | + if ($have == 'none' || $want == 'none') { |
|
241 | + return $time; |
|
242 | + } |
|
229 | 243 | $have_secs = calcOffset($have); |
230 | 244 | $want_secs = calcOffset($want); |
231 | 245 | $diff = $want_secs - $have_secs; |
@@ -265,12 +279,16 @@ discard block |
||
265 | 279 | $start = localizeDate($dateFormat_week, $arr['start_unixtime']); |
266 | 280 | $end = localizeDate($dateFormat_week, ($arr['end_unixtime'] - 60)); |
267 | 281 | $title = $event_text; |
268 | - if ($start != $end) $title .= "\n$start - $end"; |
|
282 | + if ($start != $end) { |
|
283 | + $title .= "\n$start - $end"; |
|
284 | + } |
|
269 | 285 | } else { |
270 | 286 | $start = date($timeFormat, $arr['start_unixtime']); |
271 | 287 | $end = date($timeFormat, $arr['end_unixtime']); |
272 | 288 | $title = "$start: $event_text"; |
273 | - if ($start != $end) $title = "$event_text\n$start - $end"; |
|
289 | + if ($start != $end) { |
|
290 | + $title = "$event_text\n$start - $end"; |
|
291 | + } |
|
274 | 292 | } |
275 | 293 | |
276 | 294 | if (!empty($arr['location'])) { |
@@ -314,7 +332,9 @@ discard block |
||
314 | 332 | $event_text = strip_tags($event_text, '<b><i><u><img>'); |
315 | 333 | } |
316 | 334 | |
317 | - if (!empty($link_class)) $link_class = ' class="'.$link_class.'"'; |
|
335 | + if (!empty($link_class)) { |
|
336 | + $link_class = ' class="'.$link_class.'"'; |
|
337 | + } |
|
318 | 338 | |
319 | 339 | if (!empty($event_text)) { |
320 | 340 | $title = strip_tags(str_replace('<br />',"\n",$title)); |
@@ -360,7 +380,9 @@ discard block |
||
360 | 380 | $allday =''; #suppress error on returning undef. |
361 | 381 | // Check for zulu time. |
362 | 382 | $zulu_time = false; |
363 | - if (substr($data,-1) == 'Z') $zulu_time = true; |
|
383 | + if (substr($data,-1) == 'Z') { |
|
384 | + $zulu_time = true; |
|
385 | + } |
|
364 | 386 | // Pull out the timezone, or use GMT if zulu time was indicated. |
365 | 387 | if (preg_match('/^'.$property.';TZID=/i', $field)) { |
366 | 388 | $tz_tmp = explode('=', $field); |
@@ -384,7 +406,9 @@ discard block |
||
384 | 406 | // Extract date-time values. |
385 | 407 | // Pull out the date and time values. Minimum year is 1970. |
386 | 408 | preg_match ('/([0-9]{4})([0-9]{2})([0-9]{2})T{0,1}([0-9]{0,2})([0-9]{0,2})/', $data, $regs); |
387 | - if (!isset ($regs[1])) return; |
|
409 | + if (!isset ($regs[1])) { |
|
410 | + return; |
|
411 | + } |
|
388 | 412 | if ($regs[1] < 1970) { |
389 | 413 | $regs[1] = '1970'; |
390 | 414 | } |
@@ -403,10 +427,14 @@ discard block |
||
403 | 427 | $tz_dt = $phpiCal_config->timezone; |
404 | 428 | } |
405 | 429 | // Set the values. |
406 | - if ($allday == '') $unixtime = calcTime($offset_tmp, $server_offset_tmp, $unixtime); |
|
430 | + if ($allday == '') { |
|
431 | + $unixtime = calcTime($offset_tmp, $server_offset_tmp, $unixtime); |
|
432 | + } |
|
407 | 433 | #echo "offset_tmp $offset_tmp, server_offset_tmp $server_offset_tmp, $unixtime =".date("Ymd His",$unixtime)." $time<br>"; |
408 | 434 | $date = date('Ymd', $unixtime); |
409 | - if ($allday == '') $time = date('Hi', $unixtime); |
|
435 | + if ($allday == '') { |
|
436 | + $time = date('Hi', $unixtime); |
|
437 | + } |
|
410 | 438 | |
411 | 439 | // Return the results. |
412 | 440 | return array($unixtime, $date, $time, $allday, $tz_dt); |
@@ -420,9 +448,13 @@ discard block |
||
420 | 448 | */ |
421 | 449 | function match_tz($data){ |
422 | 450 | global $tz_array; |
423 | - if (isset($tz_array[$data])) return $data; |
|
451 | + if (isset($tz_array[$data])) { |
|
452 | + return $data; |
|
453 | + } |
|
424 | 454 | foreach ($tz_array as $key=>$val){ |
425 | - if (strpos(" $data",$key) > 0) return $key; |
|
455 | + if (strpos(" $data",$key) > 0) { |
|
456 | + return $key; |
|
457 | + } |
|
426 | 458 | } |
427 | 459 | return $data; |
428 | 460 | }?> |
429 | 461 | \ No newline at end of file |
@@ -38,6 +38,9 @@ discard block |
||
38 | 38 | |
39 | 39 | // word wrap function that returns specified number of lines |
40 | 40 | // when lines is 0, it returns the entire string as wordwrap() does it |
41 | +/** |
|
42 | + * @param integer $length |
|
43 | + */ |
|
41 | 44 | function word_wrap($str, $length, $lines=0) { |
42 | 45 | if ($lines > 0) { |
43 | 46 | $len = $length * $lines; |
@@ -51,6 +54,10 @@ discard block |
||
51 | 54 | |
52 | 55 | // String intercept By Bleakwind |
53 | 56 | // utf-8:$byte=3 | gb2312:$byte=2 | big5:$byte=2 |
57 | +/** |
|
58 | + * @param integer $start |
|
59 | + * @param double $len |
|
60 | + */ |
|
54 | 61 | function bite_str($string, $start, $len, $byte=3){ |
55 | 62 | $str = ""; |
56 | 63 | $count = 0; |
@@ -1,76 +1,76 @@ |
||
1 | 1 | <?php |
2 | 2 | # drawEventTimes returns starttime and endtime and event length for drawing into a grid |
3 | -function drawEventTimes ($start, $end, $long_event = FALSE) { |
|
3 | +function drawEventTimes($start, $end, $long_event = FALSE) { |
|
4 | 4 | global $phpiCal_config; |
5 | 5 | $sta_h = $sta_min = $end_h = $end_min = "00"; |
6 | 6 | $gridLength = $phpiCal_config->gridLength; |
7 | - if (preg_match ('/([0-9]{2})([0-9]{2})/', $start, $time)){ |
|
7 | + if (preg_match('/([0-9]{2})([0-9]{2})/', $start, $time)) { |
|
8 | 8 | $sta_h = $time[1]; |
9 | 9 | $sta_min = $time[2]; |
10 | 10 | } |
11 | - $sta_min = sprintf("%02d", floor($sta_min / $gridLength) * $gridLength); |
|
11 | + $sta_min = sprintf("%02d", floor($sta_min/$gridLength)*$gridLength); |
|
12 | 12 | if ($sta_min == 60) { |
13 | 13 | $sta_h = sprintf("%02d", ($sta_h + 1)); |
14 | 14 | $sta_min = "00"; |
15 | 15 | } |
16 | 16 | |
17 | - if (preg_match ('/([0-9]{2})([0-9]{2})/', $end, $time)){ |
|
17 | + if (preg_match('/([0-9]{2})([0-9]{2})/', $end, $time)) { |
|
18 | 18 | $end_h = $time[1]; |
19 | 19 | $end_min = $time[2]; |
20 | 20 | } |
21 | - $end_min = sprintf("%02d", floor($end_min / $gridLength) * $gridLength); |
|
21 | + $end_min = sprintf("%02d", floor($end_min/$gridLength)*$gridLength); |
|
22 | 22 | if ($end_min == 60) { |
23 | 23 | $end_h = sprintf("%02d", ($end_h + 1)); |
24 | 24 | $end_min = "00"; |
25 | 25 | } |
26 | 26 | |
27 | - if ((!$long_event) && (($sta_h . $sta_min) == ($end_h . $end_min))) { |
|
27 | + if ((!$long_event) && (($sta_h.$sta_min) == ($end_h.$end_min))) { |
|
28 | 28 | $end_min += $gridLength; |
29 | 29 | if ($end_min == 60) { |
30 | 30 | $end_h = sprintf("%02d", ($end_h + 1)); |
31 | 31 | $end_min = "00"; |
32 | 32 | } |
33 | 33 | } |
34 | - $draw_len = ($end_h * 60 + $end_min) - ($sta_h * 60 + $sta_min); |
|
34 | + $draw_len = ($end_h*60 + $end_min) - ($sta_h*60 + $sta_min); |
|
35 | 35 | |
36 | - return array ("draw_start" => ($sta_h . $sta_min), "draw_end" => ($end_h . $end_min), "draw_length" => $draw_len); |
|
36 | + return array("draw_start" => ($sta_h.$sta_min), "draw_end" => ($end_h.$end_min), "draw_length" => $draw_len); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | // word wrap function that returns specified number of lines |
40 | 40 | // when lines is 0, it returns the entire string as wordwrap() does it |
41 | -function word_wrap($str, $length, $lines=0) { |
|
41 | +function word_wrap($str, $length, $lines = 0) { |
|
42 | 42 | if ($lines > 0) { |
43 | - $len = $length * $lines; |
|
43 | + $len = $length*$lines; |
|
44 | 44 | //if ($len < strlen($str)) { |
45 | 45 | // $str = substr($str,0,$len).'...'; |
46 | 46 | //} |
47 | - $rstr=bite_str($str,0,$len+1); |
|
47 | + $rstr = bite_str($str, 0, $len + 1); |
|
48 | 48 | } |
49 | 49 | return $rstr; |
50 | 50 | } |
51 | 51 | |
52 | 52 | // String intercept By Bleakwind |
53 | 53 | // utf-8:$byte=3 | gb2312:$byte=2 | big5:$byte=2 |
54 | -function bite_str($string, $start, $len, $byte=3){ |
|
54 | +function bite_str($string, $start, $len, $byte = 3) { |
|
55 | 55 | $str = ""; |
56 | 56 | $count = 0; |
57 | 57 | $str_len = strlen($string); |
58 | - for ($i=0; $i<$str_len; $i++) { |
|
59 | - if (($count+1-$start)>$len) { |
|
58 | + for ($i = 0; $i < $str_len; $i++) { |
|
59 | + if (($count + 1 - $start) > $len) { |
|
60 | 60 | $str .= "..."; |
61 | 61 | break; |
62 | - } elseif ((ord(substr($string,$i,1)) <= 128) && ($count < $start)){ |
|
62 | + } elseif ((ord(substr($string, $i, 1)) <= 128) && ($count < $start)) { |
|
63 | 63 | $count++; |
64 | - } elseif ((ord(substr($string,$i,1)) > 128) && ($count < $start)){ |
|
65 | - $count = $count+2; |
|
66 | - $i = $i+$byte-1; |
|
67 | - } elseif ((ord(substr($string,$i,1)) <= 128) && ($count >= $start)){ |
|
68 | - $str .= substr($string,$i,1); |
|
64 | + } elseif ((ord(substr($string, $i, 1)) > 128) && ($count < $start)) { |
|
65 | + $count = $count + 2; |
|
66 | + $i = $i + $byte - 1; |
|
67 | + } elseif ((ord(substr($string, $i, 1)) <= 128) && ($count >= $start)) { |
|
68 | + $str .= substr($string, $i, 1); |
|
69 | 69 | $count++; |
70 | - } elseif ((ord(substr($string,$i,1)) > 128) && ($count >= $start)){ |
|
71 | - $str .= substr($string,$i,$byte); |
|
72 | - $count = $count+2; |
|
73 | - $i = $i+$byte-1; |
|
70 | + } elseif ((ord(substr($string, $i, 1)) > 128) && ($count >= $start)) { |
|
71 | + $str .= substr($string, $i, $byte); |
|
72 | + $count = $count + 2; |
|
73 | + $i = $i + $byte - 1; |
|
74 | 74 | } |
75 | 75 | } |
76 | 76 | return $str; |
@@ -35,6 +35,7 @@ discard block |
||
35 | 35 | |
36 | 36 | /** |
37 | 37 | * Truncate a string to a specific number of words |
38 | + * @param integer $count |
|
38 | 39 | */ |
39 | 40 | function chopToWordCount($string, $count) { |
40 | 41 | $wc = str_word_count($string); |
@@ -49,6 +50,7 @@ discard block |
||
49 | 50 | |
50 | 51 | /** |
51 | 52 | * Strip "dangerous" HTML to make it safe to print to web browsers |
53 | + * @param string $string |
|
52 | 54 | */ |
53 | 55 | function sanitizeForWeb($string) { |
54 | 56 | $string = preg_replace('/<br\s*\/?>/', "\n", $string); |
@@ -14,22 +14,22 @@ discard block |
||
14 | 14 | * @return mixed |
15 | 15 | */ |
16 | 16 | function recursiveSanitize($value) { |
17 | - if (is_array($value)) { |
|
18 | - $valmod = array(); |
|
19 | - foreach ($value as $key => $subval) { |
|
20 | - if (is_array($subval)) { |
|
21 | - $subval = recursiveSanitize($subval); |
|
22 | - } else { |
|
23 | - $subval = strip_tags($subval); |
|
24 | - } |
|
25 | - $valmod[$key] = $subval; |
|
26 | - } |
|
27 | - $value = $valmod; |
|
28 | - } else { |
|
29 | - $value = strip_tags($value); |
|
30 | - } |
|
17 | + if (is_array($value)) { |
|
18 | + $valmod = array(); |
|
19 | + foreach ($value as $key => $subval) { |
|
20 | + if (is_array($subval)) { |
|
21 | + $subval = recursiveSanitize($subval); |
|
22 | + } else { |
|
23 | + $subval = strip_tags($subval); |
|
24 | + } |
|
25 | + $valmod[$key] = $subval; |
|
26 | + } |
|
27 | + $value = $valmod; |
|
28 | + } else { |
|
29 | + $value = strip_tags($value); |
|
30 | + } |
|
31 | 31 | |
32 | - return $value; |
|
32 | + return $value; |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | |
@@ -37,34 +37,34 @@ discard block |
||
37 | 37 | * Truncate a string to a specific number of words |
38 | 38 | */ |
39 | 39 | function chopToWordCount($string, $count) { |
40 | - $wc = str_word_count($string); |
|
41 | - if ($wc > $count) { |
|
40 | + $wc = str_word_count($string); |
|
41 | + if ($wc > $count) { |
|
42 | 42 | $words = str_word_count($string, 2); |
43 | 43 | $last_word = array_slice($words, $count, 1, true); |
44 | 44 | $pos = key($last_word); |
45 | 45 | $string = substr($string, 0, $pos) . '...'; |
46 | - } |
|
47 | - return $string; |
|
46 | + } |
|
47 | + return $string; |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
51 | 51 | * Strip "dangerous" HTML to make it safe to print to web browsers |
52 | 52 | */ |
53 | 53 | function sanitizeForWeb($string) { |
54 | - $string = preg_replace('/<br\s*\/?>/', "\n", $string); |
|
54 | + $string = preg_replace('/<br\s*\/?>/', "\n", $string); |
|
55 | 55 | |
56 | - $string = str_replace('$', '$', $string); |
|
57 | - $string = str_replace('&', '&', $string); |
|
58 | - $string = str_replace('<', '<', $string); |
|
59 | - $string = str_replace('>', '>', $string); |
|
60 | - $string = str_replace('\'', ''', $string); |
|
61 | - $string = str_replace('"', '"', $string); |
|
62 | - $string = str_replace('$', '$', $string); |
|
56 | + $string = str_replace('$', '$', $string); |
|
57 | + $string = str_replace('&', '&', $string); |
|
58 | + $string = str_replace('<', '<', $string); |
|
59 | + $string = str_replace('>', '>', $string); |
|
60 | + $string = str_replace('\'', ''', $string); |
|
61 | + $string = str_replace('"', '"', $string); |
|
62 | + $string = str_replace('$', '$', $string); |
|
63 | 63 | |
64 | - $string = str_replace("\n", '<br />', $string); |
|
65 | - $string = str_replace("\t", ' ', $string); |
|
64 | + $string = str_replace("\n", '<br />', $string); |
|
65 | + $string = str_replace("\t", ' ', $string); |
|
66 | 66 | |
67 | - return $string; |
|
67 | + return $string; |
|
68 | 68 | } |
69 | 69 | |
70 | 70 |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | $words = str_word_count($string, 2); |
43 | 43 | $last_word = array_slice($words, $count, 1, true); |
44 | 44 | $pos = key($last_word); |
45 | - $string = substr($string, 0, $pos) . '...'; |
|
45 | + $string = substr($string, 0, $pos).'...'; |
|
46 | 46 | } |
47 | 47 | return $string; |
48 | 48 | } |
@@ -72,12 +72,12 @@ discard block |
||
72 | 72 | $_SERVER = &$HTTP_SERVER_VARS; |
73 | 73 | } |
74 | 74 | |
75 | -foreach ($_REQUEST as $key=>$val){ |
|
76 | - switch ($key){ |
|
75 | +foreach ($_REQUEST as $key=>$val) { |
|
76 | + switch ($key) { |
|
77 | 77 | case 'event_data': |
78 | 78 | # modify this to allow or disallow different HTML tags in event popups |
79 | 79 | $allowed = "<p><br><b><i><em><a><img><div><span><ul><ol><li><h1><h2><h3><h4><h5><h6><hr><em><strong><small><table><tr><td><th>"; |
80 | - $val = strip_tags($val,$allowed); |
|
80 | + $val = strip_tags($val, $allowed); |
|
81 | 81 | break; |
82 | 82 | default: |
83 | 83 | # cpath |
@@ -86,11 +86,11 @@ discard block |
||
86 | 86 | |
87 | 87 | $_REQUEST[$key] = $val; |
88 | 88 | } |
89 | -foreach ($_POST as $key=>$val){ |
|
90 | - switch ($key){ |
|
89 | +foreach ($_POST as $key=>$val) { |
|
90 | + switch ($key) { |
|
91 | 91 | case 'action': |
92 | - $actions = array('login','logout','addupdate','delete'); |
|
93 | - if (!in_array($val,$actions)) $val = ''; |
|
92 | + $actions = array('login', 'logout', 'addupdate', 'delete'); |
|
93 | + if (!in_array($val, $actions)) $val = ''; |
|
94 | 94 | break; |
95 | 95 | case 'date': |
96 | 96 | case 'time': |
@@ -102,16 +102,16 @@ discard block |
||
102 | 102 | $_POST[$key] = $val; |
103 | 103 | |
104 | 104 | } |
105 | -foreach ($_GET as $key=>$val){ |
|
106 | - switch ($key){ |
|
105 | +foreach ($_GET as $key=>$val) { |
|
106 | + switch ($key) { |
|
107 | 107 | case 'cal': |
108 | - if (!is_array($val)){ |
|
108 | + if (!is_array($val)) { |
|
109 | 109 | $val = strip_tags($val); |
110 | 110 | $_GET['cal'] = strip_tags($val); |
111 | - }else{ |
|
111 | + } else { |
|
112 | 112 | unset ($_GET['cal']); |
113 | - foreach($val as $cal){ |
|
114 | - $_GET['cal'][]= strip_tags($cal); |
|
113 | + foreach ($val as $cal) { |
|
114 | + $_GET['cal'][] = strip_tags($cal); |
|
115 | 115 | } |
116 | 116 | } |
117 | 117 | break; |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | if ($key != 'cal') $_GET[$key] = $val; |
125 | 125 | |
126 | 126 | } |
127 | -foreach ($_COOKIE as $key=>$val){ |
|
128 | - switch ($key){ |
|
127 | +foreach ($_COOKIE as $key=>$val) { |
|
128 | + switch ($key) { |
|
129 | 129 | case 'time': |
130 | 130 | if (!is_numeric($val)) $val = ''; |
131 | 131 | break; |
@@ -90,11 +90,15 @@ discard block |
||
90 | 90 | switch ($key){ |
91 | 91 | case 'action': |
92 | 92 | $actions = array('login','logout','addupdate','delete'); |
93 | - if (!in_array($val,$actions)) $val = ''; |
|
93 | + if (!in_array($val,$actions)) { |
|
94 | + $val = ''; |
|
95 | + } |
|
94 | 96 | break; |
95 | 97 | case 'date': |
96 | 98 | case 'time': |
97 | - if (!is_numeric($val)) $val = ''; |
|
99 | + if (!is_numeric($val)) { |
|
100 | + $val = ''; |
|
101 | + } |
|
98 | 102 | break; |
99 | 103 | default: |
100 | 104 | $val = recursiveSanitize($val); |
@@ -108,7 +112,7 @@ discard block |
||
108 | 112 | if (!is_array($val)){ |
109 | 113 | $val = strip_tags($val); |
110 | 114 | $_GET['cal'] = strip_tags($val); |
111 | - }else{ |
|
115 | + } else{ |
|
112 | 116 | unset ($_GET['cal']); |
113 | 117 | foreach($val as $cal){ |
114 | 118 | $_GET['cal'][]= strip_tags($cal); |
@@ -116,18 +120,24 @@ discard block |
||
116 | 120 | } |
117 | 121 | break; |
118 | 122 | case 'getdate': |
119 | - if (!is_numeric($val)) $val = ''; |
|
123 | + if (!is_numeric($val)) { |
|
124 | + $val = ''; |
|
125 | + } |
|
120 | 126 | break; |
121 | 127 | default: |
122 | 128 | $val = recursiveSanitize($val); |
123 | 129 | } |
124 | - if ($key != 'cal') $_GET[$key] = $val; |
|
130 | + if ($key != 'cal') { |
|
131 | + $_GET[$key] = $val; |
|
132 | + } |
|
125 | 133 | |
126 | 134 | } |
127 | 135 | foreach ($_COOKIE as $key=>$val){ |
128 | 136 | switch ($key){ |
129 | 137 | case 'time': |
130 | - if (!is_numeric($val)) $val = ''; |
|
138 | + if (!is_numeric($val)) { |
|
139 | + $val = ''; |
|
140 | + } |
|
131 | 141 | break; |
132 | 142 | default: |
133 | 143 | $val = recursiveSanitize($val); |
@@ -2,6 +2,9 @@ |
||
2 | 2 | /* values are offset in hhmm (not seconds!) relative to GMT |
3 | 3 | case The first value is for standard, and the second value is for daylight |
4 | 4 | */ |
5 | +/** |
|
6 | + * @param string $timezone |
|
7 | + */ |
|
5 | 8 | function is_daylight($time, $timezone){ |
6 | 9 | global $tz_array, $summary; |
7 | 10 | # default to std time, overwrite if daylight. |
@@ -2,22 +2,22 @@ discard block |
||
2 | 2 | /* values are offset in hhmm (not seconds!) relative to GMT |
3 | 3 | case The first value is for standard, and the second value is for daylight |
4 | 4 | */ |
5 | -function is_daylight($time, $timezone){ |
|
5 | +function is_daylight($time, $timezone) { |
|
6 | 6 | global $tz_array, $summary; |
7 | 7 | # default to std time, overwrite if daylight. |
8 | 8 | $dlst = 0; |
9 | 9 | # Subtract the offset for std time. This will be slightly off in some cases, but will be closer than using nothing (?). |
10 | 10 | $time = $time - calcOffset($tz_array[$timezone][0]); |
11 | 11 | $year = date("Y", $time); |
12 | - $month = date("m",$time); |
|
13 | - $day = date("d",$time); |
|
14 | - $hour = date("H",$time); |
|
12 | + $month = date("m", $time); |
|
13 | + $day = date("d", $time); |
|
14 | + $hour = date("H", $time); |
|
15 | 15 | |
16 | - if(isset($tz_array[$timezone]['dt_start'][$year]) && isset($tz_array[$timezone]['st_start'][$year])){ |
|
17 | - $start = $tz_array[$timezone]['dt_start'][$year]; |
|
18 | - $end = $tz_array[$timezone]['st_start'][$year]; |
|
19 | - }else{ |
|
20 | - switch ($timezone){ |
|
16 | + if (isset($tz_array[$timezone]['dt_start'][$year]) && isset($tz_array[$timezone]['st_start'][$year])) { |
|
17 | + $start = $tz_array[$timezone]['dt_start'][$year]; |
|
18 | + $end = $tz_array[$timezone]['st_start'][$year]; |
|
19 | + } else { |
|
20 | + switch ($timezone) { |
|
21 | 21 | case 'US/Samoa': # array('-1100', '-1100'); |
22 | 22 | case 'America/Adak': # array('-1000', '-0900'); |
23 | 23 | case 'America/Atka': |
@@ -80,18 +80,18 @@ discard block |
||
80 | 80 | case 'Canada/Newfoundland': |
81 | 81 | case 'America/Godthab': # array('-0300', '-0200'); |
82 | 82 | case 'America/Miquelon': |
83 | - if ($year < 2007){ |
|
84 | - $start = strtotime("+1 Sun",strtotime($year."0331")); |
|
85 | - $end = strtotime("-1 Sun",strtotime($year."1101")); |
|
86 | - }else{ |
|
87 | - $start = strtotime("+2 Sun",strtotime($year."0300")); |
|
88 | - $end = strtotime("+1 Sun",strtotime($year."1031")); |
|
83 | + if ($year < 2007) { |
|
84 | + $start = strtotime("+1 Sun", strtotime($year."0331")); |
|
85 | + $end = strtotime("-1 Sun", strtotime($year."1101")); |
|
86 | + } else { |
|
87 | + $start = strtotime("+2 Sun", strtotime($year."0300")); |
|
88 | + $end = strtotime("+1 Sun", strtotime($year."1031")); |
|
89 | 89 | } |
90 | 90 | break; |
91 | 91 | case 'America/Havana': |
92 | 92 | case 'Cuba': |
93 | - $start = strtotime("+3 Sun",strtotime($year."0300")); |
|
94 | - $end = strtotime("-1 Sun",strtotime($year."1101")); |
|
93 | + $start = strtotime("+3 Sun", strtotime($year."0300")); |
|
94 | + $end = strtotime("-1 Sun", strtotime($year."1101")); |
|
95 | 95 | break; |
96 | 96 | case 'America/Cancun': |
97 | 97 | case 'America/Chihuahua': |
@@ -104,8 +104,8 @@ discard block |
||
104 | 104 | case 'Mexico/BajaNorte': |
105 | 105 | case 'Mexico/General': |
106 | 106 | case 'America/Mazatlan': |
107 | - $start = strtotime("+1 Sun",strtotime($year."0331")); |
|
108 | - $end = strtotime("-1 Sun",strtotime($year."1101")); |
|
107 | + $start = strtotime("+1 Sun", strtotime($year."0331")); |
|
108 | + $end = strtotime("-1 Sun", strtotime($year."1101")); |
|
109 | 109 | break; |
110 | 110 | case 'Chile/EasterIsland': # array('-0500', '-0600'); |
111 | 111 | case 'Pacific/Easter': |
@@ -190,8 +190,8 @@ discard block |
||
190 | 190 | case 'Europe/Uzhgorod': |
191 | 191 | case 'Europe/Zaporozhye': |
192 | 192 | case 'EET': |
193 | - $start = strtotime("-1 Sun",strtotime($year."0401")); |
|
194 | - $end = strtotime("-1 Sun",strtotime($year."1101")); |
|
193 | + $start = strtotime("-1 Sun", strtotime($year."0401")); |
|
194 | + $end = strtotime("-1 Sun", strtotime($year."1101")); |
|
195 | 195 | break; |
196 | 196 | case 'Africa/Windhoek': # array('+0200', '+0100'); |
197 | 197 | |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | $dlst = date('I', $time); |
288 | 288 | } |
289 | 289 | } |
290 | - if (isset($start,$end) && $time >= $start && $time < $end) $dlst = 1; |
|
290 | + if (isset($start, $end) && $time >= $start && $time < $end) $dlst = 1; |
|
291 | 291 | #echo "$summary $dlst <br>"; |
292 | 292 | |
293 | 293 | return $dlst; |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | if(isset($tz_array[$timezone]['dt_start'][$year]) && isset($tz_array[$timezone]['st_start'][$year])){ |
17 | 17 | $start = $tz_array[$timezone]['dt_start'][$year]; |
18 | 18 | $end = $tz_array[$timezone]['st_start'][$year]; |
19 | - }else{ |
|
19 | + } else{ |
|
20 | 20 | switch ($timezone){ |
21 | 21 | case 'US/Samoa': # array('-1100', '-1100'); |
22 | 22 | case 'America/Adak': # array('-1000', '-0900'); |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | if ($year < 2007){ |
84 | 84 | $start = strtotime("+1 Sun",strtotime($year."0331")); |
85 | 85 | $end = strtotime("-1 Sun",strtotime($year."1101")); |
86 | - }else{ |
|
86 | + } else{ |
|
87 | 87 | $start = strtotime("+2 Sun",strtotime($year."0300")); |
88 | 88 | $end = strtotime("+1 Sun",strtotime($year."1031")); |
89 | 89 | } |
@@ -287,7 +287,9 @@ discard block |
||
287 | 287 | $dlst = date('I', $time); |
288 | 288 | } |
289 | 289 | } |
290 | - if (isset($start,$end) && $time >= $start && $time < $end) $dlst = 1; |
|
290 | + if (isset($start,$end) && $time >= $start && $time < $end) { |
|
291 | + $dlst = 1; |
|
292 | + } |
|
291 | 293 | #echo "$summary $dlst <br>"; |
292 | 294 | |
293 | 295 | return $dlst; |
@@ -1,6 +1,9 @@ |
||
1 | 1 | <?php |
2 | 2 | // function to determine maximum necessary columns per day |
3 | 3 | // actually an algorithm to get the smallest multiple for two numbers |
4 | +/** |
|
5 | + * @param integer $b |
|
6 | + */ |
|
4 | 7 | function kgv($a, $b) { |
5 | 8 | $x = $a; |
6 | 9 | $y = $b; |
@@ -5,8 +5,11 @@ discard block |
||
5 | 5 | $x = $a; |
6 | 6 | $y = $b; |
7 | 7 | while ($x != $y) { |
8 | - if ($x < $y) $x += $a; |
|
9 | - else $y += $b; |
|
8 | + if ($x < $y) { |
|
9 | + $x += $a; |
|
10 | + } else { |
|
11 | + $y += $b; |
|
12 | + } |
|
10 | 13 | } |
11 | 14 | return $x; |
12 | 15 | } |
@@ -63,8 +66,9 @@ discard block |
||
63 | 66 | |
64 | 67 | $count = 0; |
65 | 68 | foreach ($ol_ranges as $loop_range) { |
66 | - if ($count < $loop_range['count']) |
|
67 | - $count = $loop_range['count']; |
|
69 | + if ($count < $loop_range['count']) { |
|
70 | + $count = $loop_range['count']; |
|
71 | + } |
|
68 | 72 | } |
69 | 73 | |
70 | 74 | return $count; |
@@ -87,8 +91,12 @@ discard block |
||
87 | 91 | // check if blocks overlap |
88 | 92 | if (($loop_block['blockStart'] < $new_block['blockEnd']) && ($loop_block['blockEnd'] > $new_block['blockStart'])) { |
89 | 93 | // define start and end of merged overlap block |
90 | - if ($new_block['blockStart'] > $loop_block['blockStart']) $ol_blocks[$new_block_key]['blockStart'] = $loop_block['blockStart']; |
|
91 | - if ($new_block['blockEnd'] < $loop_block['blockEnd']) $ol_blocks[$new_block_key]['blockEnd'] = $loop_block['blockEnd']; |
|
94 | + if ($new_block['blockStart'] > $loop_block['blockStart']) { |
|
95 | + $ol_blocks[$new_block_key]['blockStart'] = $loop_block['blockStart']; |
|
96 | + } |
|
97 | + if ($new_block['blockEnd'] < $loop_block['blockEnd']) { |
|
98 | + $ol_blocks[$new_block_key]['blockEnd'] = $loop_block['blockEnd']; |
|
99 | + } |
|
92 | 100 | $ol_blocks[$new_block_key]['events'] = array_merge($new_block['events'], $loop_block['events']); |
93 | 101 | $new_block['events'] = $ol_blocks[$new_block_key]['events']; |
94 | 102 | foreach ($loop_block['overlapRanges'] as $ol_range) { |
@@ -134,7 +142,9 @@ discard block |
||
134 | 142 | // 'end' - end_time for the overlap block. |
135 | 143 | function checkOverlap($event_date, $event_time, $uid) { |
136 | 144 | global $master_array, $overlap_array; |
137 | - if (!isset($event_date)) return; |
|
145 | + if (!isset($event_date)) { |
|
146 | + return; |
|
147 | + } |
|
138 | 148 | $event = $master_array[$event_date][$event_time][$uid]; |
139 | 149 | // Copy out the array - we replace this at the end. |
140 | 150 | $ol_day_array = @$overlap_array[$event_date]; |
@@ -150,8 +160,12 @@ discard block |
||
150 | 160 | // ... unless it's already in the $ol_block |
151 | 161 | if (!in_array(array('time' => $drawTimes['draw_start'], 'key' => $uid), $loop_ol_block['events'])) { |
152 | 162 | $loop_ol_block['events'][] = array('time' => $drawTimes['draw_start'], 'key' => $uid); |
153 | - if ($loop_ol_block['blockStart'] > $drawTimes['draw_start']) $loop_ol_block['blockStart'] = $drawTimes['draw_start']; |
|
154 | - if ($loop_ol_block['blockEnd'] < $drawTimes['draw_end']) $loop_ol_block['blockEnd'] = $drawTimes['draw_end']; |
|
163 | + if ($loop_ol_block['blockStart'] > $drawTimes['draw_start']) { |
|
164 | + $loop_ol_block['blockStart'] = $drawTimes['draw_start']; |
|
165 | + } |
|
166 | + if ($loop_ol_block['blockEnd'] < $drawTimes['draw_end']) { |
|
167 | + $loop_ol_block['blockEnd'] = $drawTimes['draw_end']; |
|
168 | + } |
|
155 | 169 | |
156 | 170 | // Merge in the new overlap range |
157 | 171 | $loop_ol_block['overlapRanges'] = merge_range($loop_ol_block['overlapRanges'], $drawTimes['draw_start'], $drawTimes['draw_end']); |