@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | # OCDE caches can also be indirectly watched by watching cache lists: |
454 | 454 | if (Settings::get('OC_BRANCH') == 'oc.de') |
455 | 455 | { |
456 | - $tmp = Db::select_column(" |
|
456 | + $tmp = Db::select_column(" |
|
457 | 457 | select c.wp_oc |
458 | 458 | from |
459 | 459 | caches c, |
@@ -464,8 +464,8 @@ discard block |
||
464 | 464 | and clw.cache_list_id = cli.cache_list_id |
465 | 465 | and clw.user_id = '".Db::escape_string($request->token->user_id)."' |
466 | 466 | "); |
467 | - foreach ($tmp as $cache_code) |
|
468 | - $tmp2[$cache_code] = true; |
|
467 | + foreach ($tmp as $cache_code) |
|
468 | + $tmp2[$cache_code] = true; |
|
469 | 469 | } |
470 | 470 | |
471 | 471 | foreach ($results as $cache_code => &$result_ref) |
@@ -465,7 +465,7 @@ |
||
465 | 465 | $ggz_entry['ratings'] = array(); |
466 | 466 | $ratings_ref = &$ggz_entry['ratings']; |
467 | 467 | if (isset($cache_ref['rating'])){ |
468 | - $ratings_ref['awesomeness'] = $cache_ref['rating']; |
|
468 | + $ratings_ref['awesomeness'] = $cache_ref['rating']; |
|
469 | 469 | } |
470 | 470 | $ratings_ref['difficulty'] = $cache_ref['difficulty']; |
471 | 471 | if (!isset($cache_ref['size'])) { |
@@ -55,162 +55,162 @@ discard block |
||
55 | 55 | class OAuthClientException extends OAuthException {} |
56 | 56 | /** OAuth server errors. */ |
57 | 57 | abstract class OAuthServerException extends OAuthException { |
58 | - abstract public function getHttpStatusCode(); |
|
59 | - protected function provideExtras(&$extras) { |
|
58 | + abstract public function getHttpStatusCode(); |
|
59 | + protected function provideExtras(&$extras) { |
|
60 | 60 | $extras['reason_stack'][] = 'invalid_oauth_request'; |
61 | - } |
|
62 | - public function getOkapiJSON() { |
|
61 | + } |
|
62 | + public function getOkapiJSON() { |
|
63 | 63 | $extras = array( |
64 | - 'developer_message' => $this->getMessage(), |
|
65 | - 'reason_stack' => array(), |
|
64 | + 'developer_message' => $this->getMessage(), |
|
65 | + 'reason_stack' => array(), |
|
66 | 66 | ); |
67 | 67 | $this->provideExtras($extras); |
68 | 68 | $extras['more_info'] = "http://opencaching.pl/okapi/introduction.html#errors"; |
69 | 69 | return json_encode(array("error" => $extras)); |
70 | - } |
|
70 | + } |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | # More subclasses of server exceptions. |
74 | 74 | |
75 | 75 | /** OAuth server errors which should result in HTTP 400 response. */ |
76 | 76 | abstract class OAuthServer400Exception extends OAuthServerException { |
77 | - protected function provideExtras(&$extras) { |
|
77 | + protected function provideExtras(&$extras) { |
|
78 | 78 | parent::provideExtras($extras); |
79 | 79 | $extras['status'] = 400; |
80 | - } |
|
81 | - public function getHttpStatusCode() { return 400; } |
|
80 | + } |
|
81 | + public function getHttpStatusCode() { return 400; } |
|
82 | 82 | } |
83 | 83 | /** OAuth server errors which should result in HTTP 401 response. */ |
84 | 84 | abstract class OAuthServer401Exception extends OAuthServerException { |
85 | - protected function provideExtras(&$extras) { |
|
85 | + protected function provideExtras(&$extras) { |
|
86 | 86 | parent::provideExtras($extras); |
87 | 87 | $extras['status'] = 401; |
88 | - } |
|
89 | - public function getHttpStatusCode() { return 401; } |
|
88 | + } |
|
89 | + public function getHttpStatusCode() { return 401; } |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** Client asked for an unsupported OAuth version (not 1.0). */ |
93 | 93 | class OAuthVersionNotSupportedException extends OAuthServer400Exception { |
94 | - protected function provideExtras(&$extras) { |
|
94 | + protected function provideExtras(&$extras) { |
|
95 | 95 | parent::provideExtras($extras); |
96 | 96 | $extras['reason_stack'][] = 'unsupported_oauth_version'; |
97 | - } |
|
97 | + } |
|
98 | 98 | } |
99 | 99 | /** Client didn't provide one of the key OAuth parameters. */ |
100 | 100 | class OAuthMissingParameterException extends OAuthServer400Exception { |
101 | - protected $param_name; |
|
102 | - protected function provideExtras(&$extras) { |
|
101 | + protected $param_name; |
|
102 | + protected function provideExtras(&$extras) { |
|
103 | 103 | parent::provideExtras($extras); |
104 | 104 | $extras['reason_stack'][] = 'missing_parameter'; |
105 | 105 | $extras['parameter'] = $this->param_name; |
106 | - } |
|
107 | - public function __construct($param_name) { |
|
106 | + } |
|
107 | + public function __construct($param_name) { |
|
108 | 108 | parent::__construct("Missing '$param_name' parameter. This parameter is required."); |
109 | 109 | $this->param_name = $param_name; |
110 | - } |
|
111 | - public function getParamName() { return $this->param_name; } |
|
110 | + } |
|
111 | + public function getParamName() { return $this->param_name; } |
|
112 | 112 | } |
113 | 113 | /** Client used unsupported signature method. */ |
114 | 114 | class OAuthUnsupportedSignatureMethodException extends OAuthServer400Exception { |
115 | - protected function provideExtras(&$extras) { |
|
115 | + protected function provideExtras(&$extras) { |
|
116 | 116 | parent::provideExtras($extras); |
117 | 117 | $extras['reason_stack'][] = 'unsupported_signature_method'; |
118 | - } |
|
118 | + } |
|
119 | 119 | } |
120 | 120 | /** Client provided invalid Consumer Key. */ |
121 | 121 | class OAuthInvalidConsumerException extends OAuthServer401Exception { |
122 | - protected function provideExtras(&$extras) { |
|
122 | + protected function provideExtras(&$extras) { |
|
123 | 123 | parent::provideExtras($extras); |
124 | 124 | $extras['reason_stack'][] = 'invalid_consumer'; |
125 | - } |
|
125 | + } |
|
126 | 126 | } |
127 | 127 | /** Client provider invalid token (either Request Token or Access Token). */ |
128 | 128 | class OAuthInvalidTokenException extends OAuthServer401Exception { |
129 | - protected function provideExtras(&$extras) { |
|
129 | + protected function provideExtras(&$extras) { |
|
130 | 130 | parent::provideExtras($extras); |
131 | 131 | $extras['reason_stack'][] = 'invalid_token'; |
132 | - } |
|
132 | + } |
|
133 | 133 | } |
134 | 134 | /** Client's signature was invalid. */ |
135 | 135 | class OAuthInvalidSignatureException extends OAuthServer401Exception { |
136 | - protected function provideExtras(&$extras) { |
|
136 | + protected function provideExtras(&$extras) { |
|
137 | 137 | parent::provideExtras($extras); |
138 | 138 | $extras['reason_stack'][] = 'invalid_signature'; |
139 | - } |
|
139 | + } |
|
140 | 140 | } |
141 | 141 | /** Client used expired timestamp (or timestamp too far in future). */ |
142 | 142 | class OAuthExpiredTimestampException extends OAuthServer400Exception { |
143 | - protected $usersTimestamp; |
|
144 | - protected $ourTimestamp; |
|
145 | - protected $threshold; |
|
146 | - protected function provideExtras(&$extras) { |
|
143 | + protected $usersTimestamp; |
|
144 | + protected $ourTimestamp; |
|
145 | + protected $threshold; |
|
146 | + protected function provideExtras(&$extras) { |
|
147 | 147 | parent::provideExtras($extras); |
148 | 148 | $extras['reason_stack'][] = 'invalid_timestamp'; |
149 | 149 | $extras['yours'] = $this->usersTimestamp; |
150 | 150 | $extras['ours'] = $this->ourTimestamp; |
151 | 151 | $extras['difference'] = $this->ourTimestamp - $this->usersTimestamp; |
152 | 152 | $extras['threshold'] = $this->threshold; |
153 | - } |
|
154 | - public function __construct($users, $ours, $threshold) { |
|
153 | + } |
|
154 | + public function __construct($users, $ours, $threshold) { |
|
155 | 155 | $this->usersTimestamp = $users; |
156 | 156 | $this->ourTimestamp = $ours; |
157 | 157 | $this->threshold = $threshold; |
158 | 158 | parent::__construct("Expired timestamp, yours $this->usersTimestamp, ours $this->ourTimestamp (threshold $this->threshold)."); |
159 | - } |
|
160 | - public function getUsersTimestamp() { return $this->usersTimestamp; } |
|
161 | - public function getOurTimestamp() { return $this->ourTimestamp; } |
|
159 | + } |
|
160 | + public function getUsersTimestamp() { return $this->usersTimestamp; } |
|
161 | + public function getOurTimestamp() { return $this->ourTimestamp; } |
|
162 | 162 | } |
163 | 163 | /** Client used the same nonce for the second time. */ |
164 | 164 | class OAuthNonceAlreadyUsedException extends OAuthServer400Exception { |
165 | - protected function provideExtras(&$extras) { |
|
165 | + protected function provideExtras(&$extras) { |
|
166 | 166 | parent::provideExtras($extras); |
167 | 167 | $extras['reason_stack'][] = 'nonce_already_used'; |
168 | - } |
|
168 | + } |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | class OAuthConsumer { |
172 | - public $key; |
|
173 | - public $secret; |
|
172 | + public $key; |
|
173 | + public $secret; |
|
174 | 174 | |
175 | - function __construct($key, $secret, $callback_url=NULL) { |
|
175 | + function __construct($key, $secret, $callback_url=NULL) { |
|
176 | 176 | $this->key = $key; |
177 | 177 | $this->secret = $secret; |
178 | 178 | $this->callback_url = $callback_url; |
179 | - } |
|
179 | + } |
|
180 | 180 | |
181 | - function __toString() { |
|
181 | + function __toString() { |
|
182 | 182 | return "OAuthConsumer[key=$this->key,secret=$this->secret]"; |
183 | - } |
|
183 | + } |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | class OAuthToken { |
187 | - // access tokens and request tokens |
|
188 | - public $key; |
|
189 | - public $secret; |
|
190 | - |
|
191 | - /** |
|
192 | - * key = the token |
|
193 | - * secret = the token secret |
|
194 | - */ |
|
195 | - function __construct($key, $secret) { |
|
187 | + // access tokens and request tokens |
|
188 | + public $key; |
|
189 | + public $secret; |
|
190 | + |
|
191 | + /** |
|
192 | + * key = the token |
|
193 | + * secret = the token secret |
|
194 | + */ |
|
195 | + function __construct($key, $secret) { |
|
196 | 196 | $this->key = $key; |
197 | 197 | $this->secret = $secret; |
198 | - } |
|
198 | + } |
|
199 | 199 | |
200 | - /** |
|
201 | - * generates the basic string serialization of a token that a server |
|
202 | - * would respond to request_token and access_token calls with |
|
203 | - */ |
|
204 | - function to_string() { |
|
200 | + /** |
|
201 | + * generates the basic string serialization of a token that a server |
|
202 | + * would respond to request_token and access_token calls with |
|
203 | + */ |
|
204 | + function to_string() { |
|
205 | 205 | return "oauth_token=" . |
206 | - OAuthUtil::urlencode_rfc3986($this->key) . |
|
207 | - "&oauth_token_secret=" . |
|
208 | - OAuthUtil::urlencode_rfc3986($this->secret); |
|
209 | - } |
|
206 | + OAuthUtil::urlencode_rfc3986($this->key) . |
|
207 | + "&oauth_token_secret=" . |
|
208 | + OAuthUtil::urlencode_rfc3986($this->secret); |
|
209 | + } |
|
210 | 210 | |
211 | - function __toString() { |
|
211 | + function __toString() { |
|
212 | 212 | return $this->to_string(); |
213 | - } |
|
213 | + } |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | /** |
@@ -218,52 +218,52 @@ discard block |
||
218 | 218 | * See section 9 ("Signing Requests") in the spec |
219 | 219 | */ |
220 | 220 | abstract class OAuthSignatureMethod { |
221 | - /** |
|
222 | - * Needs to return the name of the Signature Method (ie HMAC-SHA1) |
|
223 | - * @return string |
|
224 | - */ |
|
225 | - abstract public function get_name(); |
|
226 | - |
|
227 | - /** |
|
228 | - * Build up the signature |
|
229 | - * NOTE: The output of this function MUST NOT be urlencoded. |
|
230 | - * the encoding is handled in OAuthRequest when the final |
|
231 | - * request is serialized |
|
232 | - * @param OAuthRequest $request |
|
233 | - * @param OAuthConsumer $consumer |
|
234 | - * @param OAuthToken $token |
|
235 | - * @return string |
|
236 | - */ |
|
237 | - abstract public function build_signature($request, $consumer, $token); |
|
238 | - |
|
239 | - /** |
|
240 | - * Verifies that a given signature is correct |
|
241 | - * @param OAuthRequest $request |
|
242 | - * @param OAuthConsumer $consumer |
|
243 | - * @param OAuthToken $token |
|
244 | - * @param string $signature |
|
245 | - * @return bool |
|
246 | - */ |
|
247 | - public function check_signature($request, $consumer, $token, $signature) { |
|
221 | + /** |
|
222 | + * Needs to return the name of the Signature Method (ie HMAC-SHA1) |
|
223 | + * @return string |
|
224 | + */ |
|
225 | + abstract public function get_name(); |
|
226 | + |
|
227 | + /** |
|
228 | + * Build up the signature |
|
229 | + * NOTE: The output of this function MUST NOT be urlencoded. |
|
230 | + * the encoding is handled in OAuthRequest when the final |
|
231 | + * request is serialized |
|
232 | + * @param OAuthRequest $request |
|
233 | + * @param OAuthConsumer $consumer |
|
234 | + * @param OAuthToken $token |
|
235 | + * @return string |
|
236 | + */ |
|
237 | + abstract public function build_signature($request, $consumer, $token); |
|
238 | + |
|
239 | + /** |
|
240 | + * Verifies that a given signature is correct |
|
241 | + * @param OAuthRequest $request |
|
242 | + * @param OAuthConsumer $consumer |
|
243 | + * @param OAuthToken $token |
|
244 | + * @param string $signature |
|
245 | + * @return bool |
|
246 | + */ |
|
247 | + public function check_signature($request, $consumer, $token, $signature) { |
|
248 | 248 | $built = $this->build_signature($request, $consumer, $token); |
249 | 249 | |
250 | 250 | // Check for zero length, although unlikely here |
251 | 251 | if (strlen($built) == 0 || strlen($signature) == 0) { |
252 | - return false; |
|
252 | + return false; |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | if (strlen($built) != strlen($signature)) { |
256 | - return false; |
|
256 | + return false; |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | // Avoid a timing leak with a (hopefully) time insensitive compare |
260 | 260 | $result = 0; |
261 | 261 | for ($i = 0; $i < strlen($signature); $i++) { |
262 | - $result |= ord($built{$i}) ^ ord($signature{$i}); |
|
262 | + $result |= ord($built{$i}) ^ ord($signature{$i}); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | return $result == 0; |
266 | - } |
|
266 | + } |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | /** |
@@ -274,24 +274,24 @@ discard block |
||
274 | 274 | * - Chapter 9.2 ("HMAC-SHA1") |
275 | 275 | */ |
276 | 276 | class OAuthSignatureMethod_HMAC_SHA1 extends OAuthSignatureMethod { |
277 | - function get_name() { |
|
277 | + function get_name() { |
|
278 | 278 | return "HMAC-SHA1"; |
279 | - } |
|
279 | + } |
|
280 | 280 | |
281 | - public function build_signature($request, $consumer, $token) { |
|
281 | + public function build_signature($request, $consumer, $token) { |
|
282 | 282 | $base_string = $request->get_signature_base_string(); |
283 | 283 | $request->base_string = $base_string; |
284 | 284 | |
285 | 285 | $key_parts = array( |
286 | - $consumer->secret, |
|
287 | - ($token) ? $token->secret : "" |
|
286 | + $consumer->secret, |
|
287 | + ($token) ? $token->secret : "" |
|
288 | 288 | ); |
289 | 289 | |
290 | 290 | $key_parts = OAuthUtil::urlencode_rfc3986($key_parts); |
291 | 291 | $key = implode('&', $key_parts); |
292 | 292 | |
293 | 293 | return base64_encode(hash_hmac('sha1', $base_string, $key, true)); |
294 | - } |
|
294 | + } |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | /** |
@@ -300,23 +300,23 @@ discard block |
||
300 | 300 | * - Chapter 9.4 ("PLAINTEXT") |
301 | 301 | */ |
302 | 302 | class OAuthSignatureMethod_PLAINTEXT extends OAuthSignatureMethod { |
303 | - public function get_name() { |
|
303 | + public function get_name() { |
|
304 | 304 | return "PLAINTEXT"; |
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * oauth_signature is set to the concatenated encoded values of the Consumer Secret and |
|
309 | - * Token Secret, separated by a '&' character (ASCII code 38), even if either secret is |
|
310 | - * empty. The result MUST be encoded again. |
|
311 | - * - Chapter 9.4.1 ("Generating Signatures") |
|
312 | - * |
|
313 | - * Please note that the second encoding MUST NOT happen in the SignatureMethod, as |
|
314 | - * OAuthRequest handles this! |
|
315 | - */ |
|
316 | - public function build_signature($request, $consumer, $token) { |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * oauth_signature is set to the concatenated encoded values of the Consumer Secret and |
|
309 | + * Token Secret, separated by a '&' character (ASCII code 38), even if either secret is |
|
310 | + * empty. The result MUST be encoded again. |
|
311 | + * - Chapter 9.4.1 ("Generating Signatures") |
|
312 | + * |
|
313 | + * Please note that the second encoding MUST NOT happen in the SignatureMethod, as |
|
314 | + * OAuthRequest handles this! |
|
315 | + */ |
|
316 | + public function build_signature($request, $consumer, $token) { |
|
317 | 317 | $key_parts = array( |
318 | - $consumer->secret, |
|
319 | - ($token) ? $token->secret : "" |
|
318 | + $consumer->secret, |
|
319 | + ($token) ? $token->secret : "" |
|
320 | 320 | ); |
321 | 321 | |
322 | 322 | $key_parts = OAuthUtil::urlencode_rfc3986($key_parts); |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | $request->base_string = $key; |
325 | 325 | |
326 | 326 | return $key; |
327 | - } |
|
327 | + } |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | /** |
@@ -336,25 +336,25 @@ discard block |
||
336 | 336 | * - Chapter 9.3 ("RSA-SHA1") |
337 | 337 | */ |
338 | 338 | abstract class OAuthSignatureMethod_RSA_SHA1 extends OAuthSignatureMethod { |
339 | - public function get_name() { |
|
339 | + public function get_name() { |
|
340 | 340 | return "RSA-SHA1"; |
341 | - } |
|
342 | - |
|
343 | - // Up to the SP to implement this lookup of keys. Possible ideas are: |
|
344 | - // (1) do a lookup in a table of trusted certs keyed off of consumer |
|
345 | - // (2) fetch via http using a url provided by the requester |
|
346 | - // (3) some sort of specific discovery code based on request |
|
347 | - // |
|
348 | - // Either way should return a string representation of the certificate |
|
349 | - protected abstract function fetch_public_cert(&$request); |
|
350 | - |
|
351 | - // Up to the SP to implement this lookup of keys. Possible ideas are: |
|
352 | - // (1) do a lookup in a table of trusted certs keyed off of consumer |
|
353 | - // |
|
354 | - // Either way should return a string representation of the certificate |
|
355 | - protected abstract function fetch_private_cert(&$request); |
|
356 | - |
|
357 | - public function build_signature($request, $consumer, $token) { |
|
341 | + } |
|
342 | + |
|
343 | + // Up to the SP to implement this lookup of keys. Possible ideas are: |
|
344 | + // (1) do a lookup in a table of trusted certs keyed off of consumer |
|
345 | + // (2) fetch via http using a url provided by the requester |
|
346 | + // (3) some sort of specific discovery code based on request |
|
347 | + // |
|
348 | + // Either way should return a string representation of the certificate |
|
349 | + protected abstract function fetch_public_cert(&$request); |
|
350 | + |
|
351 | + // Up to the SP to implement this lookup of keys. Possible ideas are: |
|
352 | + // (1) do a lookup in a table of trusted certs keyed off of consumer |
|
353 | + // |
|
354 | + // Either way should return a string representation of the certificate |
|
355 | + protected abstract function fetch_private_cert(&$request); |
|
356 | + |
|
357 | + public function build_signature($request, $consumer, $token) { |
|
358 | 358 | $base_string = $request->get_signature_base_string(); |
359 | 359 | $request->base_string = $base_string; |
360 | 360 | |
@@ -371,9 +371,9 @@ discard block |
||
371 | 371 | openssl_free_key($privatekeyid); |
372 | 372 | |
373 | 373 | return base64_encode($signature); |
374 | - } |
|
374 | + } |
|
375 | 375 | |
376 | - public function check_signature($request, $consumer, $token, $signature) { |
|
376 | + public function check_signature($request, $consumer, $token, $signature) { |
|
377 | 377 | $decoded_sig = base64_decode($signature); |
378 | 378 | |
379 | 379 | $base_string = $request->get_signature_base_string(); |
@@ -391,39 +391,39 @@ discard block |
||
391 | 391 | openssl_free_key($publickeyid); |
392 | 392 | |
393 | 393 | return $ok == 1; |
394 | - } |
|
394 | + } |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | class OAuthRequest { |
398 | - protected $parameters; |
|
399 | - protected $http_method; |
|
400 | - protected $http_url; |
|
401 | - // for debug purposes |
|
402 | - public $base_string; |
|
403 | - public static $version = '1.0'; |
|
404 | - public static $POST_INPUT = 'php://input'; |
|
405 | - |
|
406 | - function __construct($http_method, $http_url, $parameters=NULL) { |
|
398 | + protected $parameters; |
|
399 | + protected $http_method; |
|
400 | + protected $http_url; |
|
401 | + // for debug purposes |
|
402 | + public $base_string; |
|
403 | + public static $version = '1.0'; |
|
404 | + public static $POST_INPUT = 'php://input'; |
|
405 | + |
|
406 | + function __construct($http_method, $http_url, $parameters=NULL) { |
|
407 | 407 | $parameters = ($parameters) ? $parameters : array(); |
408 | 408 | $parameters = array_merge( OAuthUtil::parse_parameters(parse_url($http_url, PHP_URL_QUERY)), $parameters); |
409 | 409 | $this->parameters = $parameters; |
410 | 410 | $this->http_method = $http_method; |
411 | 411 | $this->http_url = $http_url; |
412 | - } |
|
412 | + } |
|
413 | 413 | |
414 | 414 | |
415 | - /** |
|
416 | - * attempt to build up a request from what was passed to the server |
|
417 | - */ |
|
418 | - public static function from_request($http_method=NULL, $http_url=NULL, $parameters=NULL) { |
|
415 | + /** |
|
416 | + * attempt to build up a request from what was passed to the server |
|
417 | + */ |
|
418 | + public static function from_request($http_method=NULL, $http_url=NULL, $parameters=NULL) { |
|
419 | 419 | $scheme = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on") |
420 | 420 | ? 'http' |
421 | 421 | : 'https'; |
422 | 422 | $http_url = ($http_url) ? $http_url : $scheme . |
423 | - '://' . $_SERVER['SERVER_NAME'] . |
|
424 | - ':' . |
|
425 | - $_SERVER['SERVER_PORT'] . |
|
426 | - $_SERVER['REQUEST_URI']; |
|
423 | + '://' . $_SERVER['SERVER_NAME'] . |
|
424 | + ':' . |
|
425 | + $_SERVER['SERVER_PORT'] . |
|
426 | + $_SERVER['REQUEST_URI']; |
|
427 | 427 | $http_method = ($http_method) ? $http_method : $_SERVER['REQUEST_METHOD']; |
428 | 428 | |
429 | 429 | // We weren't handed any parameters, so let's find the ones relevant to |
@@ -431,131 +431,131 @@ discard block |
||
431 | 431 | // If you run XML-RPC or similar you should use this to provide your own |
432 | 432 | // parsed parameter-list |
433 | 433 | if (!$parameters) { |
434 | - // Find request headers |
|
435 | - $request_headers = OAuthUtil::get_headers(); |
|
434 | + // Find request headers |
|
435 | + $request_headers = OAuthUtil::get_headers(); |
|
436 | 436 | |
437 | - // Parse the query-string to find GET parameters |
|
438 | - $parameters = OAuthUtil::parse_parameters($_SERVER['QUERY_STRING']); |
|
437 | + // Parse the query-string to find GET parameters |
|
438 | + $parameters = OAuthUtil::parse_parameters($_SERVER['QUERY_STRING']); |
|
439 | 439 | |
440 | - // It's a POST request of the proper content-type, so parse POST |
|
441 | - // parameters and add those overriding any duplicates from GET |
|
442 | - if ($http_method == "POST" |
|
440 | + // It's a POST request of the proper content-type, so parse POST |
|
441 | + // parameters and add those overriding any duplicates from GET |
|
442 | + if ($http_method == "POST" |
|
443 | 443 | && isset($request_headers['Content-Type']) |
444 | 444 | && strstr($request_headers['Content-Type'], |
445 | - 'application/x-www-form-urlencoded') |
|
446 | - ) { |
|
445 | + 'application/x-www-form-urlencoded') |
|
446 | + ) { |
|
447 | 447 | $post_data = OAuthUtil::parse_parameters( |
448 | - file_get_contents(self::$POST_INPUT) |
|
448 | + file_get_contents(self::$POST_INPUT) |
|
449 | 449 | ); |
450 | 450 | $parameters = array_merge($parameters, $post_data); |
451 | - } |
|
451 | + } |
|
452 | 452 | |
453 | - // We have a Authorization-header with OAuth data. Parse the header |
|
454 | - // and add those overriding any duplicates from GET or POST |
|
455 | - if (isset($request_headers['Authorization']) && substr($request_headers['Authorization'], 0, 6) == 'OAuth ') { |
|
453 | + // We have a Authorization-header with OAuth data. Parse the header |
|
454 | + // and add those overriding any duplicates from GET or POST |
|
455 | + if (isset($request_headers['Authorization']) && substr($request_headers['Authorization'], 0, 6) == 'OAuth ') { |
|
456 | 456 | $header_parameters = OAuthUtil::split_header( |
457 | - $request_headers['Authorization'] |
|
457 | + $request_headers['Authorization'] |
|
458 | 458 | ); |
459 | 459 | $parameters = array_merge($parameters, $header_parameters); |
460 | - } |
|
460 | + } |
|
461 | 461 | |
462 | 462 | } |
463 | 463 | |
464 | 464 | return new OAuthRequest($http_method, $http_url, $parameters); |
465 | - } |
|
465 | + } |
|
466 | 466 | |
467 | - /** |
|
468 | - * pretty much a helper function to set up the request |
|
469 | - */ |
|
470 | - public static function from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters=NULL) { |
|
467 | + /** |
|
468 | + * pretty much a helper function to set up the request |
|
469 | + */ |
|
470 | + public static function from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters=NULL) { |
|
471 | 471 | $parameters = ($parameters) ? $parameters : array(); |
472 | 472 | $defaults = array("oauth_version" => OAuthRequest::$version, |
473 | - "oauth_nonce" => OAuthRequest::generate_nonce(), |
|
474 | - "oauth_timestamp" => OAuthRequest::generate_timestamp(), |
|
475 | - "oauth_consumer_key" => $consumer->key); |
|
473 | + "oauth_nonce" => OAuthRequest::generate_nonce(), |
|
474 | + "oauth_timestamp" => OAuthRequest::generate_timestamp(), |
|
475 | + "oauth_consumer_key" => $consumer->key); |
|
476 | 476 | if ($token) |
477 | - $defaults['oauth_token'] = $token->key; |
|
477 | + $defaults['oauth_token'] = $token->key; |
|
478 | 478 | |
479 | 479 | $parameters = array_merge($defaults, $parameters); |
480 | 480 | |
481 | 481 | return new OAuthRequest($http_method, $http_url, $parameters); |
482 | - } |
|
482 | + } |
|
483 | 483 | |
484 | - public function set_parameter($name, $value, $allow_duplicates = true) { |
|
484 | + public function set_parameter($name, $value, $allow_duplicates = true) { |
|
485 | 485 | if ($allow_duplicates && isset($this->parameters[$name])) { |
486 | - // We have already added parameter(s) with this name, so add to the list |
|
487 | - if (is_scalar($this->parameters[$name])) { |
|
486 | + // We have already added parameter(s) with this name, so add to the list |
|
487 | + if (is_scalar($this->parameters[$name])) { |
|
488 | 488 | // This is the first duplicate, so transform scalar (string) |
489 | 489 | // into an array so we can add the duplicates |
490 | 490 | $this->parameters[$name] = array($this->parameters[$name]); |
491 | - } |
|
491 | + } |
|
492 | 492 | |
493 | - $this->parameters[$name][] = $value; |
|
493 | + $this->parameters[$name][] = $value; |
|
494 | 494 | } else { |
495 | - $this->parameters[$name] = $value; |
|
495 | + $this->parameters[$name] = $value; |
|
496 | + } |
|
496 | 497 | } |
497 | - } |
|
498 | 498 | |
499 | - public function get_parameter($name) { |
|
499 | + public function get_parameter($name) { |
|
500 | 500 | return isset($this->parameters[$name]) ? $this->parameters[$name] : null; |
501 | - } |
|
501 | + } |
|
502 | 502 | |
503 | - public function get_parameters() { |
|
503 | + public function get_parameters() { |
|
504 | 504 | return $this->parameters; |
505 | - } |
|
505 | + } |
|
506 | 506 | |
507 | - public function unset_parameter($name) { |
|
507 | + public function unset_parameter($name) { |
|
508 | 508 | unset($this->parameters[$name]); |
509 | - } |
|
509 | + } |
|
510 | 510 | |
511 | - /** |
|
512 | - * The request parameters, sorted and concatenated into a normalized string. |
|
513 | - * @return string |
|
514 | - */ |
|
515 | - public function get_signable_parameters() { |
|
511 | + /** |
|
512 | + * The request parameters, sorted and concatenated into a normalized string. |
|
513 | + * @return string |
|
514 | + */ |
|
515 | + public function get_signable_parameters() { |
|
516 | 516 | // Grab all parameters |
517 | 517 | $params = $this->parameters; |
518 | 518 | |
519 | 519 | // Remove oauth_signature if present |
520 | 520 | // Ref: Spec: 9.1.1 ("The oauth_signature parameter MUST be excluded.") |
521 | 521 | if (isset($params['oauth_signature'])) { |
522 | - unset($params['oauth_signature']); |
|
522 | + unset($params['oauth_signature']); |
|
523 | 523 | } |
524 | 524 | |
525 | 525 | return OAuthUtil::build_http_query($params); |
526 | - } |
|
527 | - |
|
528 | - /** |
|
529 | - * Returns the base string of this request |
|
530 | - * |
|
531 | - * The base string defined as the method, the url |
|
532 | - * and the parameters (normalized), each urlencoded |
|
533 | - * and the concated with &. |
|
534 | - */ |
|
535 | - public function get_signature_base_string() { |
|
526 | + } |
|
527 | + |
|
528 | + /** |
|
529 | + * Returns the base string of this request |
|
530 | + * |
|
531 | + * The base string defined as the method, the url |
|
532 | + * and the parameters (normalized), each urlencoded |
|
533 | + * and the concated with &. |
|
534 | + */ |
|
535 | + public function get_signature_base_string() { |
|
536 | 536 | $parts = array( |
537 | - $this->get_normalized_http_method(), |
|
538 | - $this->get_normalized_http_url(), |
|
539 | - $this->get_signable_parameters() |
|
537 | + $this->get_normalized_http_method(), |
|
538 | + $this->get_normalized_http_url(), |
|
539 | + $this->get_signable_parameters() |
|
540 | 540 | ); |
541 | 541 | |
542 | 542 | $parts = OAuthUtil::urlencode_rfc3986($parts); |
543 | 543 | |
544 | 544 | return implode('&', $parts); |
545 | - } |
|
545 | + } |
|
546 | 546 | |
547 | - /** |
|
548 | - * just uppercases the http method |
|
549 | - */ |
|
550 | - public function get_normalized_http_method() { |
|
547 | + /** |
|
548 | + * just uppercases the http method |
|
549 | + */ |
|
550 | + public function get_normalized_http_method() { |
|
551 | 551 | return strtoupper($this->http_method); |
552 | - } |
|
552 | + } |
|
553 | 553 | |
554 | - /** |
|
555 | - * parses the url and rebuilds it to be |
|
556 | - * scheme://host/path |
|
557 | - */ |
|
558 | - public function get_normalized_http_url() { |
|
554 | + /** |
|
555 | + * parses the url and rebuilds it to be |
|
556 | + * scheme://host/path |
|
557 | + */ |
|
558 | + public function get_normalized_http_url() { |
|
559 | 559 | $parts = parse_url($this->http_url); |
560 | 560 | |
561 | 561 | $scheme = (isset($parts['scheme'])) ? $parts['scheme'] : 'http'; |
@@ -565,118 +565,118 @@ discard block |
||
565 | 565 | |
566 | 566 | if (($scheme == 'https' && $port != '443') |
567 | 567 | || ($scheme == 'http' && $port != '80')) { |
568 | - $host = "$host:$port"; |
|
568 | + $host = "$host:$port"; |
|
569 | 569 | } |
570 | 570 | return "$scheme://$host$path"; |
571 | - } |
|
571 | + } |
|
572 | 572 | |
573 | - /** |
|
574 | - * builds a url usable for a GET request |
|
575 | - */ |
|
576 | - public function to_url() { |
|
573 | + /** |
|
574 | + * builds a url usable for a GET request |
|
575 | + */ |
|
576 | + public function to_url() { |
|
577 | 577 | $post_data = $this->to_postdata(); |
578 | 578 | $out = $this->get_normalized_http_url(); |
579 | 579 | if ($post_data) { |
580 | - $out .= '?'.$post_data; |
|
580 | + $out .= '?'.$post_data; |
|
581 | 581 | } |
582 | 582 | return $out; |
583 | - } |
|
583 | + } |
|
584 | 584 | |
585 | - /** |
|
586 | - * builds the data one would send in a POST request |
|
587 | - */ |
|
588 | - public function to_postdata() { |
|
585 | + /** |
|
586 | + * builds the data one would send in a POST request |
|
587 | + */ |
|
588 | + public function to_postdata() { |
|
589 | 589 | return OAuthUtil::build_http_query($this->parameters); |
590 | - } |
|
590 | + } |
|
591 | 591 | |
592 | - /** |
|
593 | - * builds the Authorization: header |
|
594 | - */ |
|
595 | - public function to_header($realm=null) { |
|
592 | + /** |
|
593 | + * builds the Authorization: header |
|
594 | + */ |
|
595 | + public function to_header($realm=null) { |
|
596 | 596 | $first = true; |
597 | 597 | if($realm) { |
598 | - $out = 'Authorization: OAuth realm="' . OAuthUtil::urlencode_rfc3986($realm) . '"'; |
|
599 | - $first = false; |
|
598 | + $out = 'Authorization: OAuth realm="' . OAuthUtil::urlencode_rfc3986($realm) . '"'; |
|
599 | + $first = false; |
|
600 | 600 | } else |
601 | - $out = 'Authorization: OAuth'; |
|
601 | + $out = 'Authorization: OAuth'; |
|
602 | 602 | |
603 | 603 | $total = array(); |
604 | 604 | foreach ($this->parameters as $k => $v) { |
605 | - if (substr($k, 0, 5) != "oauth") continue; |
|
606 | - if (is_array($v)) { |
|
605 | + if (substr($k, 0, 5) != "oauth") continue; |
|
606 | + if (is_array($v)) { |
|
607 | 607 | throw new OAuthClientException('Arrays not supported in headers.'); |
608 | - } |
|
609 | - $out .= ($first) ? ' ' : ','; |
|
610 | - $out .= OAuthUtil::urlencode_rfc3986($k) . |
|
611 | - '="' . |
|
612 | - OAuthUtil::urlencode_rfc3986($v) . |
|
613 | - '"'; |
|
614 | - $first = false; |
|
608 | + } |
|
609 | + $out .= ($first) ? ' ' : ','; |
|
610 | + $out .= OAuthUtil::urlencode_rfc3986($k) . |
|
611 | + '="' . |
|
612 | + OAuthUtil::urlencode_rfc3986($v) . |
|
613 | + '"'; |
|
614 | + $first = false; |
|
615 | 615 | } |
616 | 616 | return $out; |
617 | - } |
|
617 | + } |
|
618 | 618 | |
619 | - public function __toString() { |
|
619 | + public function __toString() { |
|
620 | 620 | return $this->to_url(); |
621 | - } |
|
621 | + } |
|
622 | 622 | |
623 | 623 | |
624 | - public function sign_request($signature_method, $consumer, $token) { |
|
624 | + public function sign_request($signature_method, $consumer, $token) { |
|
625 | 625 | $this->set_parameter( |
626 | - "oauth_signature_method", |
|
627 | - $signature_method->get_name(), |
|
628 | - false |
|
626 | + "oauth_signature_method", |
|
627 | + $signature_method->get_name(), |
|
628 | + false |
|
629 | 629 | ); |
630 | 630 | $signature = $this->build_signature($signature_method, $consumer, $token); |
631 | 631 | $this->set_parameter("oauth_signature", $signature, false); |
632 | - } |
|
632 | + } |
|
633 | 633 | |
634 | - public function build_signature($signature_method, $consumer, $token) { |
|
634 | + public function build_signature($signature_method, $consumer, $token) { |
|
635 | 635 | $signature = $signature_method->build_signature($this, $consumer, $token); |
636 | 636 | return $signature; |
637 | - } |
|
637 | + } |
|
638 | 638 | |
639 | - /** |
|
640 | - * util function: current timestamp |
|
641 | - */ |
|
642 | - private static function generate_timestamp() { |
|
639 | + /** |
|
640 | + * util function: current timestamp |
|
641 | + */ |
|
642 | + private static function generate_timestamp() { |
|
643 | 643 | return time(); |
644 | - } |
|
644 | + } |
|
645 | 645 | |
646 | - /** |
|
647 | - * util function: current nonce |
|
648 | - */ |
|
649 | - private static function generate_nonce() { |
|
646 | + /** |
|
647 | + * util function: current nonce |
|
648 | + */ |
|
649 | + private static function generate_nonce() { |
|
650 | 650 | $mt = microtime(); |
651 | 651 | $rand = mt_rand(); |
652 | 652 | |
653 | 653 | return md5($mt . $rand); // md5s look nicer than numbers |
654 | - } |
|
654 | + } |
|
655 | 655 | } |
656 | 656 | |
657 | 657 | class OAuthServer { |
658 | - protected $timestamp_threshold = 300; // in seconds, five minutes |
|
659 | - protected $version = '1.0'; // hi blaine |
|
660 | - protected $signature_methods = array(); |
|
658 | + protected $timestamp_threshold = 300; // in seconds, five minutes |
|
659 | + protected $version = '1.0'; // hi blaine |
|
660 | + protected $signature_methods = array(); |
|
661 | 661 | |
662 | - protected $data_store; |
|
662 | + protected $data_store; |
|
663 | 663 | |
664 | - function __construct($data_store) { |
|
664 | + function __construct($data_store) { |
|
665 | 665 | $this->data_store = $data_store; |
666 | - } |
|
666 | + } |
|
667 | 667 | |
668 | - public function add_signature_method($signature_method) { |
|
668 | + public function add_signature_method($signature_method) { |
|
669 | 669 | $this->signature_methods[$signature_method->get_name()] = |
670 | - $signature_method; |
|
671 | - } |
|
670 | + $signature_method; |
|
671 | + } |
|
672 | 672 | |
673 | - // high level functions |
|
673 | + // high level functions |
|
674 | 674 | |
675 | - /** |
|
676 | - * process a request_token request |
|
677 | - * returns the request token on success |
|
678 | - */ |
|
679 | - public function fetch_request_token(&$request) { |
|
675 | + /** |
|
676 | + * process a request_token request |
|
677 | + * returns the request token on success |
|
678 | + */ |
|
679 | + public function fetch_request_token(&$request) { |
|
680 | 680 | $this->get_version($request); |
681 | 681 | |
682 | 682 | $consumer = $this->get_consumer($request); |
@@ -691,13 +691,13 @@ discard block |
||
691 | 691 | $new_token = $this->data_store->new_request_token($consumer, $callback); |
692 | 692 | |
693 | 693 | return $new_token; |
694 | - } |
|
694 | + } |
|
695 | 695 | |
696 | - /** |
|
697 | - * process an access_token request |
|
698 | - * returns the access token on success |
|
699 | - */ |
|
700 | - public function fetch_access_token(&$request) { |
|
696 | + /** |
|
697 | + * process an access_token request |
|
698 | + * returns the access token on success |
|
699 | + */ |
|
700 | + public function fetch_access_token(&$request) { |
|
701 | 701 | $this->get_version($request); |
702 | 702 | |
703 | 703 | $consumer = $this->get_consumer($request); |
@@ -712,105 +712,105 @@ discard block |
||
712 | 712 | $new_token = $this->data_store->new_access_token($token, $consumer, $verifier); |
713 | 713 | |
714 | 714 | return $new_token; |
715 | - } |
|
715 | + } |
|
716 | 716 | |
717 | - /** |
|
718 | - * verify an api call, checks all the parameters |
|
719 | - */ |
|
720 | - public function verify_request(&$request) { |
|
717 | + /** |
|
718 | + * verify an api call, checks all the parameters |
|
719 | + */ |
|
720 | + public function verify_request(&$request) { |
|
721 | 721 | $this->get_version($request); |
722 | 722 | $consumer = $this->get_consumer($request); |
723 | 723 | $token = $this->get_token($request, $consumer, "access"); |
724 | 724 | $this->check_signature($request, $consumer, $token); |
725 | 725 | return array($consumer, $token); |
726 | - } |
|
726 | + } |
|
727 | 727 | |
728 | - // Internals from here |
|
729 | - /** |
|
730 | - * version 1 |
|
731 | - */ |
|
732 | - protected function get_version(&$request) { |
|
728 | + // Internals from here |
|
729 | + /** |
|
730 | + * version 1 |
|
731 | + */ |
|
732 | + protected function get_version(&$request) { |
|
733 | 733 | $version = $request->get_parameter("oauth_version"); |
734 | 734 | if (!$version) { |
735 | - // Service Providers MUST assume the protocol version to be 1.0 if this parameter is not present. |
|
736 | - // Chapter 7.0 ("Accessing Protected Ressources") |
|
737 | - $version = '1.0'; |
|
735 | + // Service Providers MUST assume the protocol version to be 1.0 if this parameter is not present. |
|
736 | + // Chapter 7.0 ("Accessing Protected Ressources") |
|
737 | + $version = '1.0'; |
|
738 | 738 | } |
739 | 739 | if ($version !== $this->version) { |
740 | - throw new OAuthVersionNotSupportedException("OAuth version '$version' not supported."); |
|
740 | + throw new OAuthVersionNotSupportedException("OAuth version '$version' not supported."); |
|
741 | 741 | } |
742 | 742 | return $version; |
743 | - } |
|
743 | + } |
|
744 | 744 | |
745 | - /** |
|
746 | - * figure out the signature with some defaults |
|
747 | - */ |
|
748 | - private function get_signature_method($request) { |
|
745 | + /** |
|
746 | + * figure out the signature with some defaults |
|
747 | + */ |
|
748 | + private function get_signature_method($request) { |
|
749 | 749 | $signature_method = $request instanceof OAuthRequest |
750 | 750 | ? $request->get_parameter("oauth_signature_method") |
751 | 751 | : NULL; |
752 | 752 | |
753 | 753 | if (!$signature_method) { |
754 | - // According to chapter 7 ("Accessing Protected Ressources") the signature-method |
|
755 | - // parameter is required, and we can't just fallback to PLAINTEXT |
|
756 | - throw new OAuthMissingParameterException('oauth_signature_method'); |
|
754 | + // According to chapter 7 ("Accessing Protected Ressources") the signature-method |
|
755 | + // parameter is required, and we can't just fallback to PLAINTEXT |
|
756 | + throw new OAuthMissingParameterException('oauth_signature_method'); |
|
757 | 757 | } |
758 | 758 | |
759 | 759 | if (!in_array($signature_method, |
760 | - array_keys($this->signature_methods))) { |
|
761 | - throw new OAuthUnsupportedSignatureMethodException( |
|
760 | + array_keys($this->signature_methods))) { |
|
761 | + throw new OAuthUnsupportedSignatureMethodException( |
|
762 | 762 | "Signature method '$signature_method' not supported " . |
763 | 763 | "try one of the following: " . |
764 | 764 | implode(", ", array_keys($this->signature_methods)) . "." |
765 | - ); |
|
765 | + ); |
|
766 | 766 | } |
767 | 767 | return $this->signature_methods[$signature_method]; |
768 | - } |
|
768 | + } |
|
769 | 769 | |
770 | - /** |
|
771 | - * try to find the consumer for the provided request's consumer key |
|
772 | - */ |
|
773 | - protected function get_consumer($request) { |
|
770 | + /** |
|
771 | + * try to find the consumer for the provided request's consumer key |
|
772 | + */ |
|
773 | + protected function get_consumer($request) { |
|
774 | 774 | $consumer_key = $request instanceof OAuthRequest |
775 | 775 | ? $request->get_parameter("oauth_consumer_key") |
776 | 776 | : NULL; |
777 | 777 | |
778 | 778 | if (!$consumer_key) { |
779 | - throw new OAuthMissingParameterException('oauth_consumer_key'); |
|
779 | + throw new OAuthMissingParameterException('oauth_consumer_key'); |
|
780 | 780 | } |
781 | 781 | |
782 | 782 | $consumer = $this->data_store->lookup_consumer($consumer_key); |
783 | 783 | if (!$consumer) { |
784 | - throw new OAuthInvalidConsumerException("Invalid consumer"); |
|
784 | + throw new OAuthInvalidConsumerException("Invalid consumer"); |
|
785 | 785 | } |
786 | 786 | |
787 | 787 | return $consumer; |
788 | - } |
|
788 | + } |
|
789 | 789 | |
790 | - /** |
|
791 | - * try to find the token for the provided request's token key |
|
792 | - */ |
|
793 | - protected function get_token($request, $consumer, $token_type="access") { |
|
790 | + /** |
|
791 | + * try to find the token for the provided request's token key |
|
792 | + */ |
|
793 | + protected function get_token($request, $consumer, $token_type="access") { |
|
794 | 794 | $token_field = $request instanceof OAuthRequest |
795 | 795 | ? $request->get_parameter('oauth_token') |
796 | 796 | : NULL; |
797 | 797 | if (!$token_field) { |
798 | - throw new OAuthMissingParameterException('oauth_token'); |
|
798 | + throw new OAuthMissingParameterException('oauth_token'); |
|
799 | 799 | } |
800 | 800 | $token = $this->data_store->lookup_token( |
801 | - $consumer, $token_type, $token_field |
|
801 | + $consumer, $token_type, $token_field |
|
802 | 802 | ); |
803 | 803 | if (!$token) { |
804 | - throw new OAuthInvalidTokenException("Invalid $token_type token: $token_field."); |
|
804 | + throw new OAuthInvalidTokenException("Invalid $token_type token: $token_field."); |
|
805 | 805 | } |
806 | 806 | return $token; |
807 | - } |
|
807 | + } |
|
808 | 808 | |
809 | - /** |
|
810 | - * all-in-one function to check the signature on a request |
|
811 | - * should guess the signature method appropriately |
|
812 | - */ |
|
813 | - protected function check_signature($request, $consumer, $token) { |
|
809 | + /** |
|
810 | + * all-in-one function to check the signature on a request |
|
811 | + * should guess the signature method appropriately |
|
812 | + */ |
|
813 | + protected function check_signature($request, $consumer, $token) { |
|
814 | 814 | // this should probably be in a different method |
815 | 815 | $timestamp = $request instanceof OAuthRequest |
816 | 816 | ? $request->get_parameter('oauth_timestamp') |
@@ -826,23 +826,23 @@ discard block |
||
826 | 826 | |
827 | 827 | $signature = $request->get_parameter('oauth_signature'); |
828 | 828 | $valid_sig = $signature_method->check_signature( |
829 | - $request, |
|
830 | - $consumer, |
|
831 | - $token, |
|
832 | - $signature |
|
829 | + $request, |
|
830 | + $consumer, |
|
831 | + $token, |
|
832 | + $signature |
|
833 | 833 | ); |
834 | 834 | |
835 | 835 | if (!$valid_sig) { |
836 | - throw new OAuthInvalidSignatureException("Invalid signature."); |
|
836 | + throw new OAuthInvalidSignatureException("Invalid signature."); |
|
837 | + } |
|
837 | 838 | } |
838 | - } |
|
839 | 839 | |
840 | - /** |
|
841 | - * check that the timestamp is new enough |
|
842 | - */ |
|
843 | - private function check_timestamp($timestamp) { |
|
840 | + /** |
|
841 | + * check that the timestamp is new enough |
|
842 | + */ |
|
843 | + private function check_timestamp($timestamp) { |
|
844 | 844 | if( ! $timestamp ) |
845 | - throw new OAuthMissingParameterException('oauth_timestamp'); |
|
845 | + throw new OAuthMissingParameterException('oauth_timestamp'); |
|
846 | 846 | |
847 | 847 | // Cast to integer. See issue #314. |
848 | 848 | $timestamp = $timestamp + 0; |
@@ -850,178 +850,178 @@ discard block |
||
850 | 850 | // verify that timestamp is recentish |
851 | 851 | $now = time(); |
852 | 852 | if (abs($now - $timestamp) > $this->timestamp_threshold) { |
853 | - throw new OAuthExpiredTimestampException($timestamp, $now, |
|
853 | + throw new OAuthExpiredTimestampException($timestamp, $now, |
|
854 | 854 | $this->timestamp_threshold); |
855 | 855 | } |
856 | - } |
|
856 | + } |
|
857 | 857 | |
858 | - /** |
|
859 | - * check that the nonce is not repeated |
|
860 | - */ |
|
861 | - private function check_nonce($consumer, $token, $nonce, $timestamp) { |
|
858 | + /** |
|
859 | + * check that the nonce is not repeated |
|
860 | + */ |
|
861 | + private function check_nonce($consumer, $token, $nonce, $timestamp) { |
|
862 | 862 | if( ! $nonce ) |
863 | - throw new OAuthMissingParameterException('oauth_nonce'); |
|
863 | + throw new OAuthMissingParameterException('oauth_nonce'); |
|
864 | 864 | |
865 | 865 | // verify that the nonce is uniqueish |
866 | 866 | $found = $this->data_store->lookup_nonce( |
867 | - $consumer, |
|
868 | - $token, |
|
869 | - $nonce, |
|
870 | - $timestamp |
|
867 | + $consumer, |
|
868 | + $token, |
|
869 | + $nonce, |
|
870 | + $timestamp |
|
871 | 871 | ); |
872 | 872 | if ($found) { |
873 | - throw new OAuthNonceAlreadyUsedException("Nonce already used: $nonce."); |
|
873 | + throw new OAuthNonceAlreadyUsedException("Nonce already used: $nonce."); |
|
874 | + } |
|
874 | 875 | } |
875 | - } |
|
876 | 876 | |
877 | 877 | } |
878 | 878 | |
879 | 879 | class OAuthDataStore { |
880 | - function lookup_consumer($consumer_key) { |
|
880 | + function lookup_consumer($consumer_key) { |
|
881 | 881 | // implement me |
882 | - } |
|
882 | + } |
|
883 | 883 | |
884 | - function lookup_token($consumer, $token_type, $token) { |
|
884 | + function lookup_token($consumer, $token_type, $token) { |
|
885 | 885 | // implement me |
886 | - } |
|
886 | + } |
|
887 | 887 | |
888 | - function lookup_nonce($consumer, $token, $nonce, $timestamp) { |
|
888 | + function lookup_nonce($consumer, $token, $nonce, $timestamp) { |
|
889 | 889 | // implement me |
890 | - } |
|
890 | + } |
|
891 | 891 | |
892 | - function new_request_token($consumer, $callback = null) { |
|
892 | + function new_request_token($consumer, $callback = null) { |
|
893 | 893 | // return a new token attached to this consumer |
894 | - } |
|
894 | + } |
|
895 | 895 | |
896 | - function new_access_token($token, $consumer, $verifier = null) { |
|
896 | + function new_access_token($token, $consumer, $verifier = null) { |
|
897 | 897 | // return a new access token attached to this consumer |
898 | 898 | // for the user associated with this token if the request token |
899 | 899 | // is authorized |
900 | 900 | // should also invalidate the request token |
901 | - } |
|
901 | + } |
|
902 | 902 | |
903 | 903 | } |
904 | 904 | |
905 | 905 | class OAuthUtil { |
906 | - public static function urlencode_rfc3986($input) { |
|
907 | - if (is_array($input)) { |
|
906 | + public static function urlencode_rfc3986($input) { |
|
907 | + if (is_array($input)) { |
|
908 | 908 | return array_map(array('\okapi\oauth\OAuthUtil', 'urlencode_rfc3986'), $input); |
909 | - } else if (is_scalar($input)) { |
|
909 | + } else if (is_scalar($input)) { |
|
910 | 910 | return str_replace( |
911 | - '+', |
|
912 | - ' ', |
|
913 | - str_replace('%7E', '~', rawurlencode($input)) |
|
911 | + '+', |
|
912 | + ' ', |
|
913 | + str_replace('%7E', '~', rawurlencode($input)) |
|
914 | 914 | ); |
915 | - } else { |
|
915 | + } else { |
|
916 | 916 | return ''; |
917 | - } |
|
917 | + } |
|
918 | 918 | } |
919 | 919 | |
920 | 920 | |
921 | - // This decode function isn't taking into consideration the above |
|
922 | - // modifications to the encoding process. However, this method doesn't |
|
923 | - // seem to be used anywhere so leaving it as is. |
|
924 | - public static function urldecode_rfc3986($string) { |
|
921 | + // This decode function isn't taking into consideration the above |
|
922 | + // modifications to the encoding process. However, this method doesn't |
|
923 | + // seem to be used anywhere so leaving it as is. |
|
924 | + public static function urldecode_rfc3986($string) { |
|
925 | 925 | return urldecode($string); |
926 | - } |
|
927 | - |
|
928 | - // Utility function for turning the Authorization: header into |
|
929 | - // parameters, has to do some unescaping |
|
930 | - // Can filter out any non-oauth parameters if needed (default behaviour) |
|
931 | - // May 28th, 2010 - method updated to tjerk.meesters for a speed improvement. |
|
932 | - // see http://code.google.com/p/oauth/issues/detail?id=163 |
|
933 | - public static function split_header($header, $only_allow_oauth_parameters = true) { |
|
926 | + } |
|
927 | + |
|
928 | + // Utility function for turning the Authorization: header into |
|
929 | + // parameters, has to do some unescaping |
|
930 | + // Can filter out any non-oauth parameters if needed (default behaviour) |
|
931 | + // May 28th, 2010 - method updated to tjerk.meesters for a speed improvement. |
|
932 | + // see http://code.google.com/p/oauth/issues/detail?id=163 |
|
933 | + public static function split_header($header, $only_allow_oauth_parameters = true) { |
|
934 | 934 | $params = array(); |
935 | 935 | if (preg_match_all('/('.($only_allow_oauth_parameters ? 'oauth_' : '').'[a-z_-]*)=(:?"([^"]*)"|([^,]*))/', $header, $matches)) { |
936 | - foreach ($matches[1] as $i => $h) { |
|
936 | + foreach ($matches[1] as $i => $h) { |
|
937 | 937 | $params[$h] = OAuthUtil::urldecode_rfc3986(empty($matches[3][$i]) ? $matches[4][$i] : $matches[3][$i]); |
938 | - } |
|
939 | - if (isset($params['realm'])) { |
|
938 | + } |
|
939 | + if (isset($params['realm'])) { |
|
940 | 940 | unset($params['realm']); |
941 | - } |
|
941 | + } |
|
942 | 942 | } |
943 | 943 | return $params; |
944 | - } |
|
944 | + } |
|
945 | 945 | |
946 | - // helper to try to sort out headers for people who aren't running apache |
|
947 | - public static function get_headers() { |
|
946 | + // helper to try to sort out headers for people who aren't running apache |
|
947 | + public static function get_headers() { |
|
948 | 948 | if (function_exists('apache_request_headers')) { |
949 | - // we need this to get the actual Authorization: header |
|
950 | - // because apache tends to tell us it doesn't exist |
|
951 | - $headers = apache_request_headers(); |
|
952 | - |
|
953 | - // sanitize the output of apache_request_headers because |
|
954 | - // we always want the keys to be Cased-Like-This and arh() |
|
955 | - // returns the headers in the same case as they are in the |
|
956 | - // request |
|
957 | - $out = array(); |
|
958 | - foreach ($headers AS $key => $value) { |
|
949 | + // we need this to get the actual Authorization: header |
|
950 | + // because apache tends to tell us it doesn't exist |
|
951 | + $headers = apache_request_headers(); |
|
952 | + |
|
953 | + // sanitize the output of apache_request_headers because |
|
954 | + // we always want the keys to be Cased-Like-This and arh() |
|
955 | + // returns the headers in the same case as they are in the |
|
956 | + // request |
|
957 | + $out = array(); |
|
958 | + foreach ($headers AS $key => $value) { |
|
959 | 959 | $key = str_replace( |
960 | 960 | " ", |
961 | 961 | "-", |
962 | 962 | ucwords(strtolower(str_replace("-", " ", $key))) |
963 | - ); |
|
963 | + ); |
|
964 | 964 | $out[$key] = $value; |
965 | - } |
|
965 | + } |
|
966 | 966 | } else { |
967 | - // otherwise we don't have apache and are just going to have to hope |
|
968 | - // that $_SERVER actually contains what we need |
|
969 | - $out = array(); |
|
970 | - if( isset($_SERVER['CONTENT_TYPE']) ) |
|
967 | + // otherwise we don't have apache and are just going to have to hope |
|
968 | + // that $_SERVER actually contains what we need |
|
969 | + $out = array(); |
|
970 | + if( isset($_SERVER['CONTENT_TYPE']) ) |
|
971 | 971 | $out['Content-Type'] = $_SERVER['CONTENT_TYPE']; |
972 | - if( isset($_ENV['CONTENT_TYPE']) ) |
|
972 | + if( isset($_ENV['CONTENT_TYPE']) ) |
|
973 | 973 | $out['Content-Type'] = $_ENV['CONTENT_TYPE']; |
974 | 974 | |
975 | - foreach ($_SERVER as $key => $value) { |
|
975 | + foreach ($_SERVER as $key => $value) { |
|
976 | 976 | if (substr($key, 0, 5) == "HTTP_") { |
977 | - // this is chaos, basically it is just there to capitalize the first |
|
978 | - // letter of every word that is not an initial HTTP and strip HTTP |
|
979 | - // code from przemek |
|
980 | - $key = str_replace( |
|
977 | + // this is chaos, basically it is just there to capitalize the first |
|
978 | + // letter of every word that is not an initial HTTP and strip HTTP |
|
979 | + // code from przemek |
|
980 | + $key = str_replace( |
|
981 | 981 | " ", |
982 | 982 | "-", |
983 | 983 | ucwords(strtolower(str_replace("_", " ", substr($key, 5)))) |
984 | - ); |
|
985 | - $out[$key] = $value; |
|
984 | + ); |
|
985 | + $out[$key] = $value; |
|
986 | + } |
|
986 | 987 | } |
987 | - } |
|
988 | 988 | } |
989 | 989 | return $out; |
990 | - } |
|
990 | + } |
|
991 | 991 | |
992 | - // This function takes a input like a=b&a=c&d=e and returns the parsed |
|
993 | - // parameters like this |
|
994 | - // array('a' => array('b','c'), 'd' => 'e') |
|
995 | - public static function parse_parameters( $input ) { |
|
992 | + // This function takes a input like a=b&a=c&d=e and returns the parsed |
|
993 | + // parameters like this |
|
994 | + // array('a' => array('b','c'), 'd' => 'e') |
|
995 | + public static function parse_parameters( $input ) { |
|
996 | 996 | if (!isset($input) || !$input) return array(); |
997 | 997 | |
998 | 998 | $pairs = explode('&', $input); |
999 | 999 | |
1000 | 1000 | $parsed_parameters = array(); |
1001 | 1001 | foreach ($pairs as $pair) { |
1002 | - $split = explode('=', $pair, 2); |
|
1003 | - $parameter = OAuthUtil::urldecode_rfc3986($split[0]); |
|
1004 | - $value = isset($split[1]) ? OAuthUtil::urldecode_rfc3986($split[1]) : ''; |
|
1002 | + $split = explode('=', $pair, 2); |
|
1003 | + $parameter = OAuthUtil::urldecode_rfc3986($split[0]); |
|
1004 | + $value = isset($split[1]) ? OAuthUtil::urldecode_rfc3986($split[1]) : ''; |
|
1005 | 1005 | |
1006 | - if (isset($parsed_parameters[$parameter])) { |
|
1006 | + if (isset($parsed_parameters[$parameter])) { |
|
1007 | 1007 | // We have already recieved parameter(s) with this name, so add to the list |
1008 | 1008 | // of parameters with this name |
1009 | 1009 | |
1010 | 1010 | if (is_scalar($parsed_parameters[$parameter])) { |
1011 | - // This is the first duplicate, so transform scalar (string) into an array |
|
1012 | - // so we can add the duplicates |
|
1013 | - $parsed_parameters[$parameter] = array($parsed_parameters[$parameter]); |
|
1011 | + // This is the first duplicate, so transform scalar (string) into an array |
|
1012 | + // so we can add the duplicates |
|
1013 | + $parsed_parameters[$parameter] = array($parsed_parameters[$parameter]); |
|
1014 | 1014 | } |
1015 | 1015 | |
1016 | 1016 | $parsed_parameters[$parameter][] = $value; |
1017 | - } else { |
|
1017 | + } else { |
|
1018 | 1018 | $parsed_parameters[$parameter] = $value; |
1019 | - } |
|
1019 | + } |
|
1020 | 1020 | } |
1021 | 1021 | return $parsed_parameters; |
1022 | - } |
|
1022 | + } |
|
1023 | 1023 | |
1024 | - public static function build_http_query($params) { |
|
1024 | + public static function build_http_query($params) { |
|
1025 | 1025 | if (!$params) return ''; |
1026 | 1026 | |
1027 | 1027 | // Urlencode both keys and values |
@@ -1035,22 +1035,22 @@ discard block |
||
1035 | 1035 | |
1036 | 1036 | $pairs = array(); |
1037 | 1037 | foreach ($params as $parameter => $value) { |
1038 | - if (is_array($value)) { |
|
1038 | + if (is_array($value)) { |
|
1039 | 1039 | // If two or more parameters share the same name, they are sorted by their value |
1040 | 1040 | // Ref: Spec: 9.1.1 (1) |
1041 | 1041 | // June 12th, 2010 - changed to sort because of issue 164 by hidetaka |
1042 | 1042 | sort($value, SORT_STRING); |
1043 | 1043 | foreach ($value as $duplicate_value) { |
1044 | - $pairs[] = $parameter . '=' . $duplicate_value; |
|
1044 | + $pairs[] = $parameter . '=' . $duplicate_value; |
|
1045 | 1045 | } |
1046 | - } else { |
|
1046 | + } else { |
|
1047 | 1047 | $pairs[] = $parameter . '=' . $value; |
1048 | - } |
|
1048 | + } |
|
1049 | 1049 | } |
1050 | 1050 | // For each parameter, the name is separated from the corresponding value by an '=' character (ASCII code 61) |
1051 | 1051 | // Each name-value pair is separated by an '&' character (ASCII code 38) |
1052 | 1052 | return implode('&', $pairs); |
1053 | - } |
|
1053 | + } |
|
1054 | 1054 | } |
1055 | 1055 | |
1056 | 1056 | ?> |
@@ -34,7 +34,7 @@ |
||
34 | 34 | ); |
35 | 35 | $context = stream_context_create($opts); |
36 | 36 | $changes_xml = file_get_contents( |
37 | - # TODO: load from OKAPI repo |
|
37 | + # TODO: load from OKAPI repo |
|
38 | 38 | 'https://raw.githubusercontent.com/opencaching/okapi/master/etc/changes.xml', |
39 | 39 | false, $context |
40 | 40 | ); |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | var $config = array();//updater configuration |
58 | 58 | |
59 | 59 | /** |
60 | - * Constructor |
|
61 | - * @access public |
|
62 | - */ |
|
60 | + * Constructor |
|
61 | + * @access public |
|
62 | + */ |
|
63 | 63 | function __construct() |
64 | 64 | { |
65 | 65 | $this->init(); |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
85 | - * merges current updater config with the given one |
|
86 | - * @param assoc_array $config new configuration values |
|
87 | - */ |
|
85 | + * merges current updater config with the given one |
|
86 | + * @param assoc_array $config new configuration values |
|
87 | + */ |
|
88 | 88 | function setConfig($config=array()) |
89 | 89 | { |
90 | 90 | if (is_array($config)) |
@@ -94,13 +94,13 @@ discard block |
||
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
97 | - * Returns array of update SQL with default options, $source, $dest - database structures |
|
98 | - * @access public |
|
99 | - * @param string $source structure dump of database to update |
|
100 | - * @param string $dest structure dump of the reference database |
|
101 | - * @param bool $asString if true - result will be a string, otherwise - array |
|
102 | - * @return array|string update sql statements - in array or string (separated with ';') |
|
103 | - */ |
|
97 | + * Returns array of update SQL with default options, $source, $dest - database structures |
|
98 | + * @access public |
|
99 | + * @param string $source structure dump of database to update |
|
100 | + * @param string $dest structure dump of the reference database |
|
101 | + * @param bool $asString if true - result will be a string, otherwise - array |
|
102 | + * @return array|string update sql statements - in array or string (separated with ';') |
|
103 | + */ |
|
104 | 104 | function getUpdates($source, $dest, $asString=false) |
105 | 105 | { |
106 | 106 | $result = $asString?'':array(); |
@@ -123,8 +123,8 @@ discard block |
||
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
126 | - * Filters comparison result and lefts only sync actions allowed by 'updateTypes' option |
|
127 | - */ |
|
126 | + * Filters comparison result and lefts only sync actions allowed by 'updateTypes' option |
|
127 | + */ |
|
128 | 128 | function filterDiffs($compRes) |
129 | 129 | { |
130 | 130 | $result = array(); |
@@ -183,9 +183,9 @@ discard block |
||
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
186 | - * Gets structured general info about the databases diff : |
|
187 | - * array(sourceOrphans=>array(...), destOrphans=>array(...), different=>array(...)) |
|
188 | - */ |
|
186 | + * Gets structured general info about the databases diff : |
|
187 | + * array(sourceOrphans=>array(...), destOrphans=>array(...), different=>array(...)) |
|
188 | + */ |
|
189 | 189 | function getDiffInfo($compRes) |
190 | 190 | { |
191 | 191 | if (!is_array($compRes)) |
@@ -212,19 +212,19 @@ discard block |
||
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
215 | - * Makes comparison of the given database structures, support some options |
|
216 | - * @access private |
|
217 | - * @param string $source and $dest are strings - database tables structures |
|
218 | - * @return array |
|
219 | - * - table (array) |
|
220 | - * - destOrphan (boolean) |
|
221 | - * - sourceOrphan (boolean) |
|
222 | - * - differs (array) OR (boolean) false if no diffs |
|
223 | - * - [0](array) |
|
224 | - * - source (string) structure definition line in the out-of-date table |
|
225 | - * - dest (string) structure definition line in the reference table |
|
226 | - * - [1](array) ... |
|
227 | - */ |
|
215 | + * Makes comparison of the given database structures, support some options |
|
216 | + * @access private |
|
217 | + * @param string $source and $dest are strings - database tables structures |
|
218 | + * @return array |
|
219 | + * - table (array) |
|
220 | + * - destOrphan (boolean) |
|
221 | + * - sourceOrphan (boolean) |
|
222 | + * - differs (array) OR (boolean) false if no diffs |
|
223 | + * - [0](array) |
|
224 | + * - source (string) structure definition line in the out-of-date table |
|
225 | + * - dest (string) structure definition line in the reference table |
|
226 | + * - [1](array) ... |
|
227 | + */ |
|
228 | 228 | function compare($source, $dest) |
229 | 229 | { |
230 | 230 | $this->sourceStruct = $source; |
@@ -272,10 +272,10 @@ discard block |
||
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
275 | - * Retrieves list of table names from the database structure dump |
|
276 | - * @access private |
|
277 | - * @param string $struct database structure listing |
|
278 | - */ |
|
275 | + * Retrieves list of table names from the database structure dump |
|
276 | + * @access private |
|
277 | + * @param string $struct database structure listing |
|
278 | + */ |
|
279 | 279 | function getTableList($struct) |
280 | 280 | { |
281 | 281 | $result = array(); |
@@ -290,13 +290,13 @@ discard block |
||
290 | 290 | } |
291 | 291 | |
292 | 292 | /** |
293 | - * Retrieves table structure definition from the database structure dump |
|
294 | - * @access private |
|
295 | - * @param string $struct database structure listing |
|
296 | - * @param string $tab table name |
|
297 | - * @param bool $removeDatabase - either to remove database name in "CREATE TABLE database.tab"-like declarations |
|
298 | - * @return string table structure definition |
|
299 | - */ |
|
293 | + * Retrieves table structure definition from the database structure dump |
|
294 | + * @access private |
|
295 | + * @param string $struct database structure listing |
|
296 | + * @param string $tab table name |
|
297 | + * @param bool $removeDatabase - either to remove database name in "CREATE TABLE database.tab"-like declarations |
|
298 | + * @return string table structure definition |
|
299 | + */ |
|
300 | 300 | function getTabSql($struct, $tab, $removeDatabase=true) |
301 | 301 | { |
302 | 302 | $result = ''; |
@@ -327,9 +327,9 @@ discard block |
||
327 | 327 | } |
328 | 328 | |
329 | 329 | /** |
330 | - * Splits table sql into indexed array |
|
331 | - * |
|
332 | - */ |
|
330 | + * Splits table sql into indexed array |
|
331 | + * |
|
332 | + */ |
|
333 | 333 | function splitTabSql($sql) |
334 | 334 | { |
335 | 335 | $result = array(); |
@@ -374,17 +374,17 @@ discard block |
||
374 | 374 | } |
375 | 375 | |
376 | 376 | /** |
377 | - * returns array of fields or keys definitions that differs in the given tables structure |
|
378 | - * @access private |
|
379 | - * @param sring $sourceSql table structure |
|
380 | - * @param sring $destSql right table structure |
|
381 | - * supports some $options |
|
382 | - * @return array |
|
383 | - * - [0] |
|
384 | - * - source (string) out-of-date table field definition |
|
385 | - * - dest (string) reference table field definition |
|
386 | - * - [1]... |
|
387 | - */ |
|
377 | + * returns array of fields or keys definitions that differs in the given tables structure |
|
378 | + * @access private |
|
379 | + * @param sring $sourceSql table structure |
|
380 | + * @param sring $destSql right table structure |
|
381 | + * supports some $options |
|
382 | + * @return array |
|
383 | + * - [0] |
|
384 | + * - source (string) out-of-date table field definition |
|
385 | + * - dest (string) reference table field definition |
|
386 | + * - [1]... |
|
387 | + */ |
|
388 | 388 | function compareSql($sourceSql, $destSql)//$sourceSql, $destSql |
389 | 389 | { |
390 | 390 | $result = array(); |
@@ -449,13 +449,13 @@ discard block |
||
449 | 449 | } |
450 | 450 | |
451 | 451 | /** |
452 | - * Transforms table structure defnition line into key=>value pair where the key is a string that uniquely |
|
453 | - * defines field or key desribed |
|
454 | - * @access private |
|
455 | - * @param string $line field definition string |
|
456 | - * @return array array with single key=>value pair as described in the description |
|
457 | - * implements some options |
|
458 | - */ |
|
452 | + * Transforms table structure defnition line into key=>value pair where the key is a string that uniquely |
|
453 | + * defines field or key desribed |
|
454 | + * @access private |
|
455 | + * @param string $line field definition string |
|
456 | + * @return array array with single key=>value pair as described in the description |
|
457 | + * implements some options |
|
458 | + */ |
|
459 | 459 | function processLine($line) |
460 | 460 | { |
461 | 461 | $options = $this->config; |
@@ -497,13 +497,13 @@ discard block |
||
497 | 497 | } |
498 | 498 | |
499 | 499 | /** |
500 | - * Takes an output of compare() method to generate the set of sql needed to update source table to make it |
|
501 | - * look as a destination one |
|
502 | - * @access private |
|
503 | - * @param array $diff compare() method output |
|
504 | - * @return array list of sql statements |
|
505 | - * supports query generation options |
|
506 | - */ |
|
500 | + * Takes an output of compare() method to generate the set of sql needed to update source table to make it |
|
501 | + * look as a destination one |
|
502 | + * @access private |
|
503 | + * @param array $diff compare() method output |
|
504 | + * @return array list of sql statements |
|
505 | + * supports query generation options |
|
506 | + */ |
|
507 | 507 | function getDiffSql($diff)//maybe add option to ommit or force 'IF NOT EXISTS', skip autoincrement |
508 | 508 | { |
509 | 509 | $options = $this->config; |
@@ -566,13 +566,13 @@ discard block |
||
566 | 566 | } |
567 | 567 | |
568 | 568 | /** |
569 | - * Compiles update sql |
|
570 | - * @access private |
|
571 | - * @param string $action - 'drop', 'add' or 'modify' |
|
572 | - * @param string $tab table name |
|
573 | - * @param string $sql definition of the element to change |
|
574 | - * @return string update sql |
|
575 | - */ |
|
569 | + * Compiles update sql |
|
570 | + * @access private |
|
571 | + * @param string $action - 'drop', 'add' or 'modify' |
|
572 | + * @param string $tab table name |
|
573 | + * @param string $sql definition of the element to change |
|
574 | + * @return string update sql |
|
575 | + */ |
|
576 | 576 | function getActionSql($action, $tab, $sql) |
577 | 577 | { |
578 | 578 | $result = 'ALTER TABLE `'.$tab.'` '; |
@@ -645,12 +645,12 @@ discard block |
||
645 | 645 | } |
646 | 646 | |
647 | 647 | /** |
648 | - * Searches for the position of the next delimiter which is not inside string literal like 'this ; ' or |
|
649 | - * like "this ; ". |
|
650 | - * |
|
651 | - * Handles escaped \" and \'. Also handles sql comments. |
|
652 | - * Actualy it is regex-based Finit State Machine (FSN) |
|
653 | - */ |
|
648 | + * Searches for the position of the next delimiter which is not inside string literal like 'this ; ' or |
|
649 | + * like "this ; ". |
|
650 | + * |
|
651 | + * Handles escaped \" and \'. Also handles sql comments. |
|
652 | + * Actualy it is regex-based Finit State Machine (FSN) |
|
653 | + */ |
|
654 | 654 | function getDelimPos($string, $offset=0, $delim=';', $skipInBrackets=false) |
655 | 655 | { |
656 | 656 | $stack = array(); |
@@ -732,9 +732,9 @@ discard block |
||
732 | 732 | } |
733 | 733 | |
734 | 734 | /** |
735 | - * works the same as getDelimPos except returns position of the first occurence of the delimiter starting from |
|
736 | - * the end of the string |
|
737 | - */ |
|
735 | + * works the same as getDelimPos except returns position of the first occurence of the delimiter starting from |
|
736 | + * the end of the string |
|
737 | + */ |
|
738 | 738 | function getDelimRpos($string, $offset=0, $delim=';', $skipInBrackets=false) |
739 | 739 | { |
740 | 740 | $pos = $this->getDelimPos($string, $offset, $delim, $skipInBrackets); |
@@ -8,8 +8,8 @@ |
||
8 | 8 | ****************************************************************************/ |
9 | 9 | |
10 | 10 | // search.php -> $tpl->error |
11 | - $outputformat_notexist = _('The selected output format is unknown!'); |
|
12 | - $error_query_not_found = _('The search operation could not be executed, please reenter the search data.'); |
|
11 | + $outputformat_notexist = _('The selected output format is unknown!'); |
|
12 | + $error_query_not_found = _('The search operation could not be executed, please reenter the search data.'); |
|
13 | 13 | $unknown_searchoption = _('unknown search option'); |
14 | 14 | $unknown_searchtype = _('unknown search type'); |
15 | 15 |
@@ -14,40 +14,40 @@ |
||
14 | 14 | * set template specific language variables |
15 | 15 | ****************************************************************************/ |
16 | 16 | |
17 | - $firstcache_note = t('If this is your first cache on %1, be sure to check out the <a href="articles.php?page=cacheinfo">description</a> of the individual fields.'); |
|
18 | - |
|
19 | - $submit = t('Submit cache'); |
|
20 | - $default_country = t('EN'); |
|
21 | - $default_lang = t('EN'); |
|
22 | - $show_all = t('Show all'); |
|
23 | - $default_NS = 'N'; |
|
24 | - $default_EW = 'E'; |
|
25 | - $date_time_format_message = ' ' . t('Format: DD-MM-YYYY'); |
|
26 | - |
|
27 | - $error_general = "<tr><td class='error' colspan='2'><b>" . t('Some errors occured, please check the marked fields.') . "</b></td></tr>"; |
|
28 | - $error_long_not_ok = '<span class="errormsg">' . t('Your chosen coordinated are invalid') . '</span>'; |
|
29 | - $error_lat_not_ok = $error_long_not_ok . "<br />"; |
|
30 | - $error_duplicate_coords = '<span class="errormsg">' . t('Another cache (<a href="viewcache.php?wp=%1">%1</a>) exists at these coords. Maybe you pressed "submit cache" twice. To publish a cache with identical coords, enter other coords first, then edit the listing and change coords.') . '</span>'; |
|
31 | - $time_not_ok_message = '<span class="errormsg">' . t('The entered time is invalid.') . '</span>'; |
|
32 | - $way_length_not_ok_message = '<span class="errormsg">' . t('The entered distance is invalid, Format: aa.aaa') . '</span>'; |
|
33 | - $date_not_ok_message = '<span class="errormsg">' . t('Invalid date, format:DD-MM-JJJJ') . '</span>'; |
|
34 | - $name_not_ok_message = ' <span class="errormsg">' . t('Cachename is invalid') . '</span>'; |
|
35 | - $tos_not_ok_message = '<br/><span class="errormsg">' . t('The cache can only be adopted if you agree our terms of use.') . '</span>'; |
|
36 | - $type_not_ok_message = ' <span class="errormsg">' . t('No cache-type is chosen.') . '</span>'; |
|
37 | - $size_not_ok_message = ' <span class="errormsg">' . t('No cache-size is chosen.') . '</span>'; |
|
38 | - $diff_not_ok_message = ' <span class="errormsg">' . t('Choose both valuations!') . '</span>'; |
|
39 | - $sizemismatch_message = ' <span class="errormsg">' . t('For virtual and webcam caches, the cache size has to be -no container-!') . '</span>'; |
|
40 | - $safari_not_allowed_message = '<span class="errormsg">' . t('Only virtual caches can be safari caches.') . '</span>'; |
|
41 | - $bad_wpgc_message = '<span class="errormsg">' . t('GC waypoint is invalid, must be GCxxxxx') . '</span>'; |
|
42 | - |
|
43 | - $cache_submitted = t('Your cache is successfully added to the database. You will be redirected to the cache page, now.'); |
|
44 | - |
|
45 | - $sel_message = t('Select'); |
|
46 | - |
|
47 | - $cache_attrib_js = "new Array({id}, {selected}, '{img_undef}', '{img_large}')"; |
|
48 | - $cache_attrib_pic = '<img id="attr{attrib_id}" src="{attrib_pic}" border="0" onmousedown="toggleAttr({attrib_id})" onmouseover="Tip(\'{html_desc}\', TITLE, \'{name}\', TITLEBGCOLOR, \'{color}\', TITLEFONTCOLOR, \'#000000\', BGCOLOR, \'#FFFFFF\', BORDERCOLOR, \'{color}\', CLICKCLOSE, true, DELAY, 0, FADEIN, false, FADEOUT, false, FONTCOLOR, \'#000080\', WIDTH, 500)" onmouseout="UnTip()" /> '; |
|
49 | - |
|
50 | - $cache_attrib_group = |
|
17 | + $firstcache_note = t('If this is your first cache on %1, be sure to check out the <a href="articles.php?page=cacheinfo">description</a> of the individual fields.'); |
|
18 | + |
|
19 | + $submit = t('Submit cache'); |
|
20 | + $default_country = t('EN'); |
|
21 | + $default_lang = t('EN'); |
|
22 | + $show_all = t('Show all'); |
|
23 | + $default_NS = 'N'; |
|
24 | + $default_EW = 'E'; |
|
25 | + $date_time_format_message = ' ' . t('Format: DD-MM-YYYY'); |
|
26 | + |
|
27 | + $error_general = "<tr><td class='error' colspan='2'><b>" . t('Some errors occured, please check the marked fields.') . "</b></td></tr>"; |
|
28 | + $error_long_not_ok = '<span class="errormsg">' . t('Your chosen coordinated are invalid') . '</span>'; |
|
29 | + $error_lat_not_ok = $error_long_not_ok . "<br />"; |
|
30 | + $error_duplicate_coords = '<span class="errormsg">' . t('Another cache (<a href="viewcache.php?wp=%1">%1</a>) exists at these coords. Maybe you pressed "submit cache" twice. To publish a cache with identical coords, enter other coords first, then edit the listing and change coords.') . '</span>'; |
|
31 | + $time_not_ok_message = '<span class="errormsg">' . t('The entered time is invalid.') . '</span>'; |
|
32 | + $way_length_not_ok_message = '<span class="errormsg">' . t('The entered distance is invalid, Format: aa.aaa') . '</span>'; |
|
33 | + $date_not_ok_message = '<span class="errormsg">' . t('Invalid date, format:DD-MM-JJJJ') . '</span>'; |
|
34 | + $name_not_ok_message = ' <span class="errormsg">' . t('Cachename is invalid') . '</span>'; |
|
35 | + $tos_not_ok_message = '<br/><span class="errormsg">' . t('The cache can only be adopted if you agree our terms of use.') . '</span>'; |
|
36 | + $type_not_ok_message = ' <span class="errormsg">' . t('No cache-type is chosen.') . '</span>'; |
|
37 | + $size_not_ok_message = ' <span class="errormsg">' . t('No cache-size is chosen.') . '</span>'; |
|
38 | + $diff_not_ok_message = ' <span class="errormsg">' . t('Choose both valuations!') . '</span>'; |
|
39 | + $sizemismatch_message = ' <span class="errormsg">' . t('For virtual and webcam caches, the cache size has to be -no container-!') . '</span>'; |
|
40 | + $safari_not_allowed_message = '<span class="errormsg">' . t('Only virtual caches can be safari caches.') . '</span>'; |
|
41 | + $bad_wpgc_message = '<span class="errormsg">' . t('GC waypoint is invalid, must be GCxxxxx') . '</span>'; |
|
42 | + |
|
43 | + $cache_submitted = t('Your cache is successfully added to the database. You will be redirected to the cache page, now.'); |
|
44 | + |
|
45 | + $sel_message = t('Select'); |
|
46 | + |
|
47 | + $cache_attrib_js = "new Array({id}, {selected}, '{img_undef}', '{img_large}')"; |
|
48 | + $cache_attrib_pic = '<img id="attr{attrib_id}" src="{attrib_pic}" border="0" onmousedown="toggleAttr({attrib_id})" onmouseover="Tip(\'{html_desc}\', TITLE, \'{name}\', TITLEBGCOLOR, \'{color}\', TITLEFONTCOLOR, \'#000000\', BGCOLOR, \'#FFFFFF\', BORDERCOLOR, \'{color}\', CLICKCLOSE, true, DELAY, 0, FADEIN, false, FADEOUT, false, FONTCOLOR, \'#000080\', WIDTH, 500)" onmouseout="UnTip()" /> '; |
|
49 | + |
|
50 | + $cache_attrib_group = |
|
51 | 51 | '<div class="attribgroup"><table cellspacing="0" style="display:inline;border-spacing:0px;"> |
52 | 52 | <tr><td bgcolor="{color}" style="line-height:9px;padding-top:2px;margin:0 0 0 0;border-left:1px solid gray;border-right:1px solid gray;border-top:1px solid gray;"><font size="1">{name}</font></td></tr> |
53 | 53 | <tr><td bgcolor="#F8F8F8" style="margin:0 0 0 0;border-left:1px solid gray;border-right:1px solid gray;border-bottom:1px solid gray;">{attribs}</td></tr> |
@@ -15,8 +15,8 @@ |
||
15 | 15 | |
16 | 16 | ****************************************************************************/ |
17 | 17 | |
18 | - $error_wrong_node = t('This log entry has been created on another Opencaching website. The cache can only be edited there.'); |
|
19 | - $removed_message_end = '---'; |
|
18 | + $error_wrong_node = t('This log entry has been created on another Opencaching website. The cache can only be edited there.'); |
|
19 | + $removed_message_end = '---'; |
|
20 | 20 | |
21 | 21 | |
22 | 22 | function removed_log_subject($lang) |
@@ -15,7 +15,7 @@ |
||
15 | 15 | |
16 | 16 | ****************************************************************************/ |
17 | 17 | |
18 | - $error_wrong_node = t('this description was created on another Opencaching-webserver and can only be deleted there.'); |
|
18 | + $error_wrong_node = t('this description was created on another Opencaching-webserver and can only be deleted there.'); |
|
19 | 19 | |
20 | - $commit = t('the cache description has been deleted'); |
|
21 | - $commit_title = t('delete this cache-description'); |
|
20 | + $commit = t('the cache description has been deleted'); |
|
21 | + $commit_title = t('delete this cache-description'); |