@@ -42,7 +42,7 @@ |
||
42 | 42 | * @access public |
43 | 43 | * @param string $sCode code of the url between "routes" and "route" in Route.conf |
44 | 44 | * @param array $aParams parameters to create the url |
45 | - * @return void |
|
45 | + * @return string |
|
46 | 46 | * |
47 | 47 | * @tutorial If I have this route I could make my URL: |
48 | 48 | * |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | |
83 | 83 | $aRoutes = array(); |
84 | 84 | |
85 | - foreach($oHost->routes as $sKey => $oRoute) { |
|
85 | + foreach ($oHost->routes as $sKey => $oRoute) { |
|
86 | 86 | |
87 | 87 | if ($sKey === $sCode) { |
88 | 88 | |
@@ -135,8 +135,8 @@ discard block |
||
135 | 135 | throw new \Exception(); |
136 | 136 | } |
137 | 137 | |
138 | - $sStringToEncode = str_replace(['à','á','â','ã','ä','ç','è','é','ê','ë','ì','í','î','ï','ñ','ò','ó','ô','õ','ö','ù','ú','û','ü','ý','ÿ','À','Á','Â','Ã','Ä','Ç','È','É','Ê','Ë','Ì','Í','Î','Ï','Ñ','Ò','Ó','Ô','Õ','Ö','Ù','Ú','Û','Ü','Ý'], |
|
139 | - ['a','a','a','a','a','c','e','e','e','e','i','i','i','i','n','o','o','o','o','o','u','u','u','u','y','y','A','A','A','A','A','C','E','E','E','E','I','I','I','I','N','O','O','O','O','O','U','U','U','U','Y'], |
|
138 | + $sStringToEncode = str_replace(['à', 'á', 'â', 'ã', 'ä', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ù', 'Ú', 'Û', 'Ü', 'Ý'], |
|
139 | + ['a', 'a', 'a', 'a', 'a', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'A', 'A', 'A', 'A', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'N', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y'], |
|
140 | 140 | $sStringToEncode); |
141 | 141 | |
142 | 142 | $sStringToEncode = preg_replace('/[^a-zA-Z0-9_]+/', '_', preg_quote($sStringToEncode)); |
@@ -96,12 +96,10 @@ |
||
96 | 96 | |
97 | 97 | if (preg_match('#'.$sType.'#', $aParams[$sName])) { |
98 | 98 | |
99 | - if ($aParams[$sName]) { $sRoute = str_replace('[/:'.$sName.']', '/'.$aParams[$sName], $sRoute); } |
|
100 | - else { $sRoute = str_replace('[/:'.$sName.']', '', $sRoute); } |
|
99 | + if ($aParams[$sName]) { $sRoute = str_replace('[/:'.$sName.']', '/'.$aParams[$sName], $sRoute); } else { $sRoute = str_replace('[/:'.$sName.']', '', $sRoute); } |
|
101 | 100 | $sRoute = str_replace('[:'.$sName.']', $aParams[$sName], $sRoute); |
102 | 101 | continue; |
103 | - } |
|
104 | - else if (isset($oRoute->defaults_constraints) |
|
102 | + } else if (isset($oRoute->defaults_constraints) |
|
105 | 103 | && isset($oRoute->defaults_constraints->{$sName}) |
106 | 104 | && preg_match('#'.$sType.'#', $oRoute->defaults_constraints->{$sName})) { |
107 | 105 |
@@ -503,7 +503,7 @@ discard block |
||
503 | 503 | * Get the UID of the connected user, or 0 |
504 | 504 | * if the Facebook user is not connected. |
505 | 505 | * |
506 | - * @return string the UID if available. |
|
506 | + * @return integer the UID if available. |
|
507 | 507 | */ |
508 | 508 | public function getUser() { |
509 | 509 | if ($this->user !== null) { |
@@ -757,6 +757,7 @@ discard block |
||
757 | 757 | * either logged in to Facebook or has granted an offline access permission. |
758 | 758 | * |
759 | 759 | * @param string $code An authorization code. |
760 | + * @param string $redirect_uri |
|
760 | 761 | * @return mixed An access token exchanged for the authorization code, or |
761 | 762 | * false if an access token could not be generated. |
762 | 763 | */ |
@@ -1135,7 +1136,7 @@ discard block |
||
1135 | 1136 | /** |
1136 | 1137 | * Build the URL for given domain alias, path and parameters. |
1137 | 1138 | * |
1138 | - * @param $name string The name of the domain |
|
1139 | + * @param string $name string The name of the domain |
|
1139 | 1140 | * @param $path string Optional path (without a leading slash) |
1140 | 1141 | * @param $params array Optional query parameters |
1141 | 1142 | * |
@@ -1402,6 +1403,9 @@ discard block |
||
1402 | 1403 | return self::endsWith($big, '.'.$small); |
1403 | 1404 | } |
1404 | 1405 | |
1406 | + /** |
|
1407 | + * @param string $small |
|
1408 | + */ |
|
1405 | 1409 | protected static function endsWith($big, $small) { |
1406 | 1410 | $len = strlen($small); |
1407 | 1411 | if ($len === 0) { |
@@ -40,24 +40,24 @@ discard block |
||
40 | 40 | * @param array $result The result from the API server |
41 | 41 | */ |
42 | 42 | public function __construct($result) { |
43 | - $this->result = $result; |
|
44 | - |
|
45 | - $code = isset($result['error_code']) ? $result['error_code'] : 0; |
|
46 | - |
|
47 | - if (isset($result['error_description'])) { |
|
48 | - // OAuth 2.0 Draft 10 style |
|
49 | - $msg = $result['error_description']; |
|
50 | - } else if (isset($result['error']) && is_array($result['error'])) { |
|
51 | - // OAuth 2.0 Draft 00 style |
|
52 | - $msg = $result['error']['message']; |
|
53 | - } else if (isset($result['error_msg'])) { |
|
54 | - // Rest server style |
|
55 | - $msg = $result['error_msg']; |
|
56 | - } else { |
|
57 | - $msg = 'Unknown Error. Check getResult()'; |
|
58 | - } |
|
59 | - |
|
60 | - parent::__construct($msg, $code); |
|
43 | + $this->result = $result; |
|
44 | + |
|
45 | + $code = isset($result['error_code']) ? $result['error_code'] : 0; |
|
46 | + |
|
47 | + if (isset($result['error_description'])) { |
|
48 | + // OAuth 2.0 Draft 10 style |
|
49 | + $msg = $result['error_description']; |
|
50 | + } else if (isset($result['error']) && is_array($result['error'])) { |
|
51 | + // OAuth 2.0 Draft 00 style |
|
52 | + $msg = $result['error']['message']; |
|
53 | + } else if (isset($result['error_msg'])) { |
|
54 | + // Rest server style |
|
55 | + $msg = $result['error_msg']; |
|
56 | + } else { |
|
57 | + $msg = 'Unknown Error. Check getResult()'; |
|
58 | + } |
|
59 | + |
|
60 | + parent::__construct($msg, $code); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @return array The result from the API server |
67 | 67 | */ |
68 | 68 | public function getResult() { |
69 | - return $this->result; |
|
69 | + return $this->result; |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -76,20 +76,20 @@ discard block |
||
76 | 76 | * @return string |
77 | 77 | */ |
78 | 78 | public function getType() { |
79 | - if (isset($this->result['error'])) { |
|
80 | - $error = $this->result['error']; |
|
81 | - if (is_string($error)) { |
|
82 | - // OAuth 2.0 Draft 10 style |
|
83 | - return $error; |
|
84 | - } else if (is_array($error)) { |
|
85 | - // OAuth 2.0 Draft 00 style |
|
86 | - if (isset($error['type'])) { |
|
87 | - return $error['type']; |
|
88 | - } |
|
89 | - } |
|
90 | - } |
|
91 | - |
|
92 | - return 'Exception'; |
|
79 | + if (isset($this->result['error'])) { |
|
80 | + $error = $this->result['error']; |
|
81 | + if (is_string($error)) { |
|
82 | + // OAuth 2.0 Draft 10 style |
|
83 | + return $error; |
|
84 | + } else if (is_array($error)) { |
|
85 | + // OAuth 2.0 Draft 00 style |
|
86 | + if (isset($error['type'])) { |
|
87 | + return $error['type']; |
|
88 | + } |
|
89 | + } |
|
90 | + } |
|
91 | + |
|
92 | + return 'Exception'; |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -98,11 +98,11 @@ discard block |
||
98 | 98 | * @return string The string representation of the error |
99 | 99 | */ |
100 | 100 | public function __toString() { |
101 | - $str = $this->getType() . ': '; |
|
102 | - if ($this->code != 0) { |
|
103 | - $str .= $this->code . ': '; |
|
104 | - } |
|
105 | - return $str . $this->message; |
|
101 | + $str = $this->getType() . ': '; |
|
102 | + if ($this->code != 0) { |
|
103 | + $str .= $this->code . ': '; |
|
104 | + } |
|
105 | + return $str . $this->message; |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | |
@@ -131,10 +131,10 @@ discard block |
||
131 | 131 | * Default options for curl. |
132 | 132 | */ |
133 | 133 | public static $CURL_OPTS = array( |
134 | - CURLOPT_CONNECTTIMEOUT => 10, |
|
135 | - CURLOPT_RETURNTRANSFER => true, |
|
136 | - CURLOPT_TIMEOUT => 60, |
|
137 | - CURLOPT_USERAGENT => 'facebook-php-3.2', |
|
134 | + CURLOPT_CONNECTTIMEOUT => 10, |
|
135 | + CURLOPT_RETURNTRANSFER => true, |
|
136 | + CURLOPT_TIMEOUT => 60, |
|
137 | + CURLOPT_USERAGENT => 'facebook-php-3.2', |
|
138 | 138 | ); |
139 | 139 | |
140 | 140 | /** |
@@ -142,21 +142,21 @@ discard block |
||
142 | 142 | * the current URL. |
143 | 143 | */ |
144 | 144 | protected static $DROP_QUERY_PARAMS = array( |
145 | - 'code', |
|
146 | - 'state', |
|
147 | - 'signed_request', |
|
145 | + 'code', |
|
146 | + 'state', |
|
147 | + 'signed_request', |
|
148 | 148 | ); |
149 | 149 | |
150 | 150 | /** |
151 | 151 | * Maps aliases to Facebook domains. |
152 | 152 | */ |
153 | 153 | public static $DOMAIN_MAP = array( |
154 | - 'api' => 'https://api.facebook.com/', |
|
155 | - 'api_video' => 'https://api-video.facebook.com/', |
|
156 | - 'api_read' => 'https://api-read.facebook.com/', |
|
157 | - 'graph' => 'https://graph.facebook.com/', |
|
158 | - 'graph_video' => 'https://graph-video.facebook.com/', |
|
159 | - 'www' => 'https://www.facebook.com/', |
|
154 | + 'api' => 'https://api.facebook.com/', |
|
155 | + 'api_video' => 'https://api-video.facebook.com/', |
|
156 | + 'api_read' => 'https://api-read.facebook.com/', |
|
157 | + 'graph' => 'https://graph.facebook.com/', |
|
158 | + 'graph_video' => 'https://graph-video.facebook.com/', |
|
159 | + 'www' => 'https://www.facebook.com/', |
|
160 | 160 | ); |
161 | 161 | |
162 | 162 | /** |
@@ -223,18 +223,18 @@ discard block |
||
223 | 223 | * @param array $config The application configuration |
224 | 224 | */ |
225 | 225 | public function __construct($config) { |
226 | - $this->setAppId($config['appId']); |
|
227 | - $this->setAppSecret($config['secret']); |
|
228 | - if (isset($config['fileUpload'])) { |
|
229 | - $this->setFileUploadSupport($config['fileUpload']); |
|
230 | - } |
|
231 | - if (isset($config['trustForwarded']) && $config['trustForwarded']) { |
|
232 | - $this->trustForwarded = true; |
|
233 | - } |
|
234 | - $state = $this->getPersistentData('state'); |
|
235 | - if (!empty($state)) { |
|
236 | - $this->state = $state; |
|
237 | - } |
|
226 | + $this->setAppId($config['appId']); |
|
227 | + $this->setAppSecret($config['secret']); |
|
228 | + if (isset($config['fileUpload'])) { |
|
229 | + $this->setFileUploadSupport($config['fileUpload']); |
|
230 | + } |
|
231 | + if (isset($config['trustForwarded']) && $config['trustForwarded']) { |
|
232 | + $this->trustForwarded = true; |
|
233 | + } |
|
234 | + $state = $this->getPersistentData('state'); |
|
235 | + if (!empty($state)) { |
|
236 | + $this->state = $state; |
|
237 | + } |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
@@ -244,8 +244,8 @@ discard block |
||
244 | 244 | * @return BaseFacebook |
245 | 245 | */ |
246 | 246 | public function setAppId($appId) { |
247 | - $this->appId = $appId; |
|
248 | - return $this; |
|
247 | + $this->appId = $appId; |
|
248 | + return $this; |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | /** |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | * @return string the Application ID |
255 | 255 | */ |
256 | 256 | public function getAppId() { |
257 | - return $this->appId; |
|
257 | + return $this->appId; |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | /** |
@@ -265,8 +265,8 @@ discard block |
||
265 | 265 | * @deprecated |
266 | 266 | */ |
267 | 267 | public function setApiSecret($apiSecret) { |
268 | - $this->setAppSecret($apiSecret); |
|
269 | - return $this; |
|
268 | + $this->setAppSecret($apiSecret); |
|
269 | + return $this; |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | /** |
@@ -276,8 +276,8 @@ discard block |
||
276 | 276 | * @return BaseFacebook |
277 | 277 | */ |
278 | 278 | public function setAppSecret($appSecret) { |
279 | - $this->appSecret = $appSecret; |
|
280 | - return $this; |
|
279 | + $this->appSecret = $appSecret; |
|
280 | + return $this; |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | /** |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | * @deprecated |
288 | 288 | */ |
289 | 289 | public function getApiSecret() { |
290 | - return $this->getAppSecret(); |
|
290 | + return $this->getAppSecret(); |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | /** |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | * @return string the App Secret |
297 | 297 | */ |
298 | 298 | public function getAppSecret() { |
299 | - return $this->appSecret; |
|
299 | + return $this->appSecret; |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | /** |
@@ -306,8 +306,8 @@ discard block |
||
306 | 306 | * @return BaseFacebook |
307 | 307 | */ |
308 | 308 | public function setFileUploadSupport($fileUploadSupport) { |
309 | - $this->fileUploadSupport = $fileUploadSupport; |
|
310 | - return $this; |
|
309 | + $this->fileUploadSupport = $fileUploadSupport; |
|
310 | + return $this; |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | /** |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | * @return boolean true if and only if the server supports file upload. |
317 | 317 | */ |
318 | 318 | public function getFileUploadSupport() { |
319 | - return $this->fileUploadSupport; |
|
319 | + return $this->fileUploadSupport; |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | /** |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | * @return boolean true if and only if the server supports file upload. |
328 | 328 | */ |
329 | 329 | public function useFileUploadSupport() { |
330 | - return $this->getFileUploadSupport(); |
|
330 | + return $this->getFileUploadSupport(); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | /** |
@@ -339,8 +339,8 @@ discard block |
||
339 | 339 | * @return BaseFacebook |
340 | 340 | */ |
341 | 341 | public function setAccessToken($access_token) { |
342 | - $this->accessToken = $access_token; |
|
343 | - return $this; |
|
342 | + $this->accessToken = $access_token; |
|
343 | + return $this; |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | /** |
@@ -349,41 +349,41 @@ discard block |
||
349 | 349 | * for the workaround. |
350 | 350 | */ |
351 | 351 | public function setExtendedAccessToken() { |
352 | - try { |
|
353 | - // need to circumvent json_decode by calling _oauthRequest |
|
354 | - // directly, since response isn't JSON format. |
|
355 | - $access_token_response = $this->_oauthRequest( |
|
356 | - $this->getUrl('graph', '/oauth/access_token'), |
|
357 | - $params = array( |
|
358 | - 'client_id' => $this->getAppId(), |
|
359 | - 'client_secret' => $this->getAppSecret(), |
|
360 | - 'grant_type' => 'fb_exchange_token', |
|
361 | - 'fb_exchange_token' => $this->getAccessToken(), |
|
362 | - ) |
|
363 | - ); |
|
364 | - } |
|
365 | - catch (FacebookApiException $e) { |
|
366 | - // most likely that user very recently revoked authorization. |
|
367 | - // In any event, we don't have an access token, so say so. |
|
368 | - return false; |
|
369 | - } |
|
370 | - |
|
371 | - if (empty($access_token_response)) { |
|
372 | - return false; |
|
373 | - } |
|
374 | - |
|
375 | - $response_params = array(); |
|
376 | - parse_str($access_token_response, $response_params); |
|
377 | - |
|
378 | - if (!isset($response_params['access_token'])) { |
|
379 | - return false; |
|
380 | - } |
|
381 | - |
|
382 | - $this->destroySession(); |
|
383 | - |
|
384 | - $this->setPersistentData( |
|
385 | - 'access_token', $response_params['access_token'] |
|
386 | - ); |
|
352 | + try { |
|
353 | + // need to circumvent json_decode by calling _oauthRequest |
|
354 | + // directly, since response isn't JSON format. |
|
355 | + $access_token_response = $this->_oauthRequest( |
|
356 | + $this->getUrl('graph', '/oauth/access_token'), |
|
357 | + $params = array( |
|
358 | + 'client_id' => $this->getAppId(), |
|
359 | + 'client_secret' => $this->getAppSecret(), |
|
360 | + 'grant_type' => 'fb_exchange_token', |
|
361 | + 'fb_exchange_token' => $this->getAccessToken(), |
|
362 | + ) |
|
363 | + ); |
|
364 | + } |
|
365 | + catch (FacebookApiException $e) { |
|
366 | + // most likely that user very recently revoked authorization. |
|
367 | + // In any event, we don't have an access token, so say so. |
|
368 | + return false; |
|
369 | + } |
|
370 | + |
|
371 | + if (empty($access_token_response)) { |
|
372 | + return false; |
|
373 | + } |
|
374 | + |
|
375 | + $response_params = array(); |
|
376 | + parse_str($access_token_response, $response_params); |
|
377 | + |
|
378 | + if (!isset($response_params['access_token'])) { |
|
379 | + return false; |
|
380 | + } |
|
381 | + |
|
382 | + $this->destroySession(); |
|
383 | + |
|
384 | + $this->setPersistentData( |
|
385 | + 'access_token', $response_params['access_token'] |
|
386 | + ); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | /** |
@@ -396,21 +396,21 @@ discard block |
||
396 | 396 | * @return string The access token |
397 | 397 | */ |
398 | 398 | public function getAccessToken() { |
399 | - if ($this->accessToken !== null) { |
|
400 | - // we've done this already and cached it. Just return. |
|
401 | - return $this->accessToken; |
|
402 | - } |
|
403 | - |
|
404 | - // first establish access token to be the application |
|
405 | - // access token, in case we navigate to the /oauth/access_token |
|
406 | - // endpoint, where SOME access token is required. |
|
407 | - $this->setAccessToken($this->getApplicationAccessToken()); |
|
408 | - $user_access_token = $this->getUserAccessToken(); |
|
409 | - if ($user_access_token) { |
|
410 | - $this->setAccessToken($user_access_token); |
|
411 | - } |
|
412 | - |
|
413 | - return $this->accessToken; |
|
399 | + if ($this->accessToken !== null) { |
|
400 | + // we've done this already and cached it. Just return. |
|
401 | + return $this->accessToken; |
|
402 | + } |
|
403 | + |
|
404 | + // first establish access token to be the application |
|
405 | + // access token, in case we navigate to the /oauth/access_token |
|
406 | + // endpoint, where SOME access token is required. |
|
407 | + $this->setAccessToken($this->getApplicationAccessToken()); |
|
408 | + $user_access_token = $this->getUserAccessToken(); |
|
409 | + if ($user_access_token) { |
|
410 | + $this->setAccessToken($user_access_token); |
|
411 | + } |
|
412 | + |
|
413 | + return $this->accessToken; |
|
414 | 414 | } |
415 | 415 | |
416 | 416 | /** |
@@ -424,60 +424,60 @@ discard block |
||
424 | 424 | * could not be determined. |
425 | 425 | */ |
426 | 426 | protected function getUserAccessToken() { |
427 | - // first, consider a signed request if it's supplied. |
|
428 | - // if there is a signed request, then it alone determines |
|
429 | - // the access token. |
|
430 | - $signed_request = $this->getSignedRequest(); |
|
431 | - if ($signed_request) { |
|
432 | - // apps.facebook.com hands the access_token in the signed_request |
|
433 | - if (array_key_exists('oauth_token', $signed_request)) { |
|
434 | - $access_token = $signed_request['oauth_token']; |
|
435 | - $this->setPersistentData('access_token', $access_token); |
|
436 | - return $access_token; |
|
437 | - } |
|
438 | - |
|
439 | - // the JS SDK puts a code in with the redirect_uri of '' |
|
440 | - if (array_key_exists('code', $signed_request)) { |
|
441 | - $code = $signed_request['code']; |
|
442 | - if ($code && $code == $this->getPersistentData('code')) { |
|
443 | - // short-circuit if the code we have is the same as the one presented |
|
444 | - return $this->getPersistentData('access_token'); |
|
445 | - } |
|
446 | - |
|
447 | - $access_token = $this->getAccessTokenFromCode($code, ''); |
|
448 | - if ($access_token) { |
|
449 | - $this->setPersistentData('code', $code); |
|
450 | - $this->setPersistentData('access_token', $access_token); |
|
451 | - return $access_token; |
|
452 | - } |
|
453 | - } |
|
454 | - |
|
455 | - // signed request states there's no access token, so anything |
|
456 | - // stored should be cleared. |
|
457 | - $this->clearAllPersistentData(); |
|
458 | - return false; // respect the signed request's data, even |
|
459 | - // if there's an authorization code or something else |
|
460 | - } |
|
461 | - |
|
462 | - $code = $this->getCode(); |
|
463 | - if ($code && $code != $this->getPersistentData('code')) { |
|
464 | - $access_token = $this->getAccessTokenFromCode($code); |
|
465 | - if ($access_token) { |
|
466 | - $this->setPersistentData('code', $code); |
|
467 | - $this->setPersistentData('access_token', $access_token); |
|
468 | - return $access_token; |
|
469 | - } |
|
470 | - |
|
471 | - // code was bogus, so everything based on it should be invalidated. |
|
472 | - $this->clearAllPersistentData(); |
|
473 | - return false; |
|
474 | - } |
|
475 | - |
|
476 | - // as a fallback, just return whatever is in the persistent |
|
477 | - // store, knowing nothing explicit (signed request, authorization |
|
478 | - // code, etc.) was present to shadow it (or we saw a code in $_REQUEST, |
|
479 | - // but it's the same as what's in the persistent store) |
|
480 | - return $this->getPersistentData('access_token'); |
|
427 | + // first, consider a signed request if it's supplied. |
|
428 | + // if there is a signed request, then it alone determines |
|
429 | + // the access token. |
|
430 | + $signed_request = $this->getSignedRequest(); |
|
431 | + if ($signed_request) { |
|
432 | + // apps.facebook.com hands the access_token in the signed_request |
|
433 | + if (array_key_exists('oauth_token', $signed_request)) { |
|
434 | + $access_token = $signed_request['oauth_token']; |
|
435 | + $this->setPersistentData('access_token', $access_token); |
|
436 | + return $access_token; |
|
437 | + } |
|
438 | + |
|
439 | + // the JS SDK puts a code in with the redirect_uri of '' |
|
440 | + if (array_key_exists('code', $signed_request)) { |
|
441 | + $code = $signed_request['code']; |
|
442 | + if ($code && $code == $this->getPersistentData('code')) { |
|
443 | + // short-circuit if the code we have is the same as the one presented |
|
444 | + return $this->getPersistentData('access_token'); |
|
445 | + } |
|
446 | + |
|
447 | + $access_token = $this->getAccessTokenFromCode($code, ''); |
|
448 | + if ($access_token) { |
|
449 | + $this->setPersistentData('code', $code); |
|
450 | + $this->setPersistentData('access_token', $access_token); |
|
451 | + return $access_token; |
|
452 | + } |
|
453 | + } |
|
454 | + |
|
455 | + // signed request states there's no access token, so anything |
|
456 | + // stored should be cleared. |
|
457 | + $this->clearAllPersistentData(); |
|
458 | + return false; // respect the signed request's data, even |
|
459 | + // if there's an authorization code or something else |
|
460 | + } |
|
461 | + |
|
462 | + $code = $this->getCode(); |
|
463 | + if ($code && $code != $this->getPersistentData('code')) { |
|
464 | + $access_token = $this->getAccessTokenFromCode($code); |
|
465 | + if ($access_token) { |
|
466 | + $this->setPersistentData('code', $code); |
|
467 | + $this->setPersistentData('access_token', $access_token); |
|
468 | + return $access_token; |
|
469 | + } |
|
470 | + |
|
471 | + // code was bogus, so everything based on it should be invalidated. |
|
472 | + $this->clearAllPersistentData(); |
|
473 | + return false; |
|
474 | + } |
|
475 | + |
|
476 | + // as a fallback, just return whatever is in the persistent |
|
477 | + // store, knowing nothing explicit (signed request, authorization |
|
478 | + // code, etc.) was present to shadow it (or we saw a code in $_REQUEST, |
|
479 | + // but it's the same as what's in the persistent store) |
|
480 | + return $this->getPersistentData('access_token'); |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | /** |
@@ -487,16 +487,16 @@ discard block |
||
487 | 487 | * @return string the signed request, if available, or null otherwise. |
488 | 488 | */ |
489 | 489 | public function getSignedRequest() { |
490 | - if (!$this->signedRequest) { |
|
491 | - if (!empty($_REQUEST['signed_request'])) { |
|
492 | - $this->signedRequest = $this->parseSignedRequest( |
|
493 | - $_REQUEST['signed_request']); |
|
494 | - } else if (!empty($_COOKIE[$this->getSignedRequestCookieName()])) { |
|
495 | - $this->signedRequest = $this->parseSignedRequest( |
|
496 | - $_COOKIE[$this->getSignedRequestCookieName()]); |
|
497 | - } |
|
498 | - } |
|
499 | - return $this->signedRequest; |
|
490 | + if (!$this->signedRequest) { |
|
491 | + if (!empty($_REQUEST['signed_request'])) { |
|
492 | + $this->signedRequest = $this->parseSignedRequest( |
|
493 | + $_REQUEST['signed_request']); |
|
494 | + } else if (!empty($_COOKIE[$this->getSignedRequestCookieName()])) { |
|
495 | + $this->signedRequest = $this->parseSignedRequest( |
|
496 | + $_COOKIE[$this->getSignedRequestCookieName()]); |
|
497 | + } |
|
498 | + } |
|
499 | + return $this->signedRequest; |
|
500 | 500 | } |
501 | 501 | |
502 | 502 | /** |
@@ -506,12 +506,12 @@ discard block |
||
506 | 506 | * @return string the UID if available. |
507 | 507 | */ |
508 | 508 | public function getUser() { |
509 | - if ($this->user !== null) { |
|
510 | - // we've already determined this and cached the value. |
|
511 | - return $this->user; |
|
512 | - } |
|
509 | + if ($this->user !== null) { |
|
510 | + // we've already determined this and cached the value. |
|
511 | + return $this->user; |
|
512 | + } |
|
513 | 513 | |
514 | - return $this->user = $this->getUserFromAvailableData(); |
|
514 | + return $this->user = $this->getUserFromAvailableData(); |
|
515 | 515 | } |
516 | 516 | |
517 | 517 | /** |
@@ -523,45 +523,45 @@ discard block |
||
523 | 523 | * or 0 if no such user exists. |
524 | 524 | */ |
525 | 525 | protected function getUserFromAvailableData() { |
526 | - // if a signed request is supplied, then it solely determines |
|
527 | - // who the user is. |
|
528 | - $signed_request = $this->getSignedRequest(); |
|
529 | - if ($signed_request) { |
|
530 | - if (array_key_exists('user_id', $signed_request)) { |
|
531 | - $user = $signed_request['user_id']; |
|
532 | - |
|
533 | - if($user != $this->getPersistentData('user_id')){ |
|
534 | - $this->clearAllPersistentData(); |
|
535 | - } |
|
536 | - |
|
537 | - $this->setPersistentData('user_id', $signed_request['user_id']); |
|
538 | - return $user; |
|
539 | - } |
|
540 | - |
|
541 | - // if the signed request didn't present a user id, then invalidate |
|
542 | - // all entries in any persistent store. |
|
543 | - $this->clearAllPersistentData(); |
|
544 | - return 0; |
|
545 | - } |
|
546 | - |
|
547 | - $user = $this->getPersistentData('user_id', $default = 0); |
|
548 | - $persisted_access_token = $this->getPersistentData('access_token'); |
|
549 | - |
|
550 | - // use access_token to fetch user id if we have a user access_token, or if |
|
551 | - // the cached access token has changed. |
|
552 | - $access_token = $this->getAccessToken(); |
|
553 | - if ($access_token && |
|
554 | - $access_token != $this->getApplicationAccessToken() && |
|
555 | - !($user && $persisted_access_token == $access_token)) { |
|
556 | - $user = $this->getUserFromAccessToken(); |
|
557 | - if ($user) { |
|
558 | - $this->setPersistentData('user_id', $user); |
|
559 | - } else { |
|
560 | - $this->clearAllPersistentData(); |
|
561 | - } |
|
562 | - } |
|
563 | - |
|
564 | - return $user; |
|
526 | + // if a signed request is supplied, then it solely determines |
|
527 | + // who the user is. |
|
528 | + $signed_request = $this->getSignedRequest(); |
|
529 | + if ($signed_request) { |
|
530 | + if (array_key_exists('user_id', $signed_request)) { |
|
531 | + $user = $signed_request['user_id']; |
|
532 | + |
|
533 | + if($user != $this->getPersistentData('user_id')){ |
|
534 | + $this->clearAllPersistentData(); |
|
535 | + } |
|
536 | + |
|
537 | + $this->setPersistentData('user_id', $signed_request['user_id']); |
|
538 | + return $user; |
|
539 | + } |
|
540 | + |
|
541 | + // if the signed request didn't present a user id, then invalidate |
|
542 | + // all entries in any persistent store. |
|
543 | + $this->clearAllPersistentData(); |
|
544 | + return 0; |
|
545 | + } |
|
546 | + |
|
547 | + $user = $this->getPersistentData('user_id', $default = 0); |
|
548 | + $persisted_access_token = $this->getPersistentData('access_token'); |
|
549 | + |
|
550 | + // use access_token to fetch user id if we have a user access_token, or if |
|
551 | + // the cached access token has changed. |
|
552 | + $access_token = $this->getAccessToken(); |
|
553 | + if ($access_token && |
|
554 | + $access_token != $this->getApplicationAccessToken() && |
|
555 | + !($user && $persisted_access_token == $access_token)) { |
|
556 | + $user = $this->getUserFromAccessToken(); |
|
557 | + if ($user) { |
|
558 | + $this->setPersistentData('user_id', $user); |
|
559 | + } else { |
|
560 | + $this->clearAllPersistentData(); |
|
561 | + } |
|
562 | + } |
|
563 | + |
|
564 | + return $user; |
|
565 | 565 | } |
566 | 566 | |
567 | 567 | /** |
@@ -577,23 +577,23 @@ discard block |
||
577 | 577 | * @return string The URL for the login flow |
578 | 578 | */ |
579 | 579 | public function getLoginUrl($params=array()) { |
580 | - $this->establishCSRFTokenState(); |
|
581 | - $currentUrl = $this->getCurrentUrl(); |
|
582 | - |
|
583 | - // if 'scope' is passed as an array, convert to comma separated list |
|
584 | - $scopeParams = isset($params['scope']) ? $params['scope'] : null; |
|
585 | - if ($scopeParams && is_array($scopeParams)) { |
|
586 | - $params['scope'] = implode(',', $scopeParams); |
|
587 | - } |
|
588 | - |
|
589 | - return $this->getUrl( |
|
590 | - 'www', |
|
591 | - 'dialog/oauth', |
|
592 | - array_merge(array( |
|
593 | - 'client_id' => $this->getAppId(), |
|
594 | - 'redirect_uri' => $currentUrl, // possibly overwritten |
|
595 | - 'state' => $this->state), |
|
596 | - $params)); |
|
580 | + $this->establishCSRFTokenState(); |
|
581 | + $currentUrl = $this->getCurrentUrl(); |
|
582 | + |
|
583 | + // if 'scope' is passed as an array, convert to comma separated list |
|
584 | + $scopeParams = isset($params['scope']) ? $params['scope'] : null; |
|
585 | + if ($scopeParams && is_array($scopeParams)) { |
|
586 | + $params['scope'] = implode(',', $scopeParams); |
|
587 | + } |
|
588 | + |
|
589 | + return $this->getUrl( |
|
590 | + 'www', |
|
591 | + 'dialog/oauth', |
|
592 | + array_merge(array( |
|
593 | + 'client_id' => $this->getAppId(), |
|
594 | + 'redirect_uri' => $currentUrl, // possibly overwritten |
|
595 | + 'state' => $this->state), |
|
596 | + $params)); |
|
597 | 597 | } |
598 | 598 | |
599 | 599 | /** |
@@ -606,14 +606,14 @@ discard block |
||
606 | 606 | * @return string The URL for the logout flow |
607 | 607 | */ |
608 | 608 | public function getLogoutUrl($params=array()) { |
609 | - return $this->getUrl( |
|
610 | - 'www', |
|
611 | - 'logout.php', |
|
612 | - array_merge(array( |
|
613 | - 'next' => $this->getCurrentUrl(), |
|
614 | - 'access_token' => $this->getUserAccessToken(), |
|
615 | - ), $params) |
|
616 | - ); |
|
609 | + return $this->getUrl( |
|
610 | + 'www', |
|
611 | + 'logout.php', |
|
612 | + array_merge(array( |
|
613 | + 'next' => $this->getCurrentUrl(), |
|
614 | + 'access_token' => $this->getUserAccessToken(), |
|
615 | + ), $params) |
|
616 | + ); |
|
617 | 617 | } |
618 | 618 | |
619 | 619 | /** |
@@ -628,17 +628,17 @@ discard block |
||
628 | 628 | * @return string The URL for the logout flow |
629 | 629 | */ |
630 | 630 | public function getLoginStatusUrl($params=array()) { |
631 | - return $this->getUrl( |
|
632 | - 'www', |
|
633 | - 'extern/login_status.php', |
|
634 | - array_merge(array( |
|
635 | - 'api_key' => $this->getAppId(), |
|
636 | - 'no_session' => $this->getCurrentUrl(), |
|
637 | - 'no_user' => $this->getCurrentUrl(), |
|
638 | - 'ok_session' => $this->getCurrentUrl(), |
|
639 | - 'session_version' => 3, |
|
640 | - ), $params) |
|
641 | - ); |
|
631 | + return $this->getUrl( |
|
632 | + 'www', |
|
633 | + 'extern/login_status.php', |
|
634 | + array_merge(array( |
|
635 | + 'api_key' => $this->getAppId(), |
|
636 | + 'no_session' => $this->getCurrentUrl(), |
|
637 | + 'no_user' => $this->getCurrentUrl(), |
|
638 | + 'ok_session' => $this->getCurrentUrl(), |
|
639 | + 'session_version' => 3, |
|
640 | + ), $params) |
|
641 | + ); |
|
642 | 642 | } |
643 | 643 | |
644 | 644 | /** |
@@ -647,12 +647,12 @@ discard block |
||
647 | 647 | * @return mixed The decoded response |
648 | 648 | */ |
649 | 649 | public function api(/* polymorphic */) { |
650 | - $args = func_get_args(); |
|
651 | - if (is_array($args[0])) { |
|
652 | - return $this->_restserver($args[0]); |
|
653 | - } else { |
|
654 | - return call_user_func_array(array($this, '_graph'), $args); |
|
655 | - } |
|
650 | + $args = func_get_args(); |
|
651 | + if (is_array($args[0])) { |
|
652 | + return $this->_restserver($args[0]); |
|
653 | + } else { |
|
654 | + return call_user_func_array(array($this, '_graph'), $args); |
|
655 | + } |
|
656 | 656 | } |
657 | 657 | |
658 | 658 | /** |
@@ -665,7 +665,7 @@ discard block |
||
665 | 665 | * the signed request value. |
666 | 666 | */ |
667 | 667 | protected function getSignedRequestCookieName() { |
668 | - return 'fbsr_'.$this->getAppId(); |
|
668 | + return 'fbsr_'.$this->getAppId(); |
|
669 | 669 | } |
670 | 670 | |
671 | 671 | /** |
@@ -676,7 +676,7 @@ discard block |
||
676 | 676 | * @return string the name of the cookie that would house metadata. |
677 | 677 | */ |
678 | 678 | protected function getMetadataCookieName() { |
679 | - return 'fbm_'.$this->getAppId(); |
|
679 | + return 'fbm_'.$this->getAppId(); |
|
680 | 680 | } |
681 | 681 | |
682 | 682 | /** |
@@ -688,22 +688,22 @@ discard block |
||
688 | 688 | * code could not be determined. |
689 | 689 | */ |
690 | 690 | protected function getCode() { |
691 | - if (isset($_REQUEST['code'])) { |
|
692 | - if ($this->state !== null && |
|
693 | - isset($_REQUEST['state']) && |
|
694 | - $this->state === $_REQUEST['state']) { |
|
695 | - |
|
696 | - // CSRF state has done its job, so clear it |
|
697 | - $this->state = null; |
|
698 | - $this->clearPersistentData('state'); |
|
699 | - return $_REQUEST['code']; |
|
700 | - } else { |
|
701 | - self::errorLog('CSRF state token does not match one provided.'); |
|
702 | - return false; |
|
703 | - } |
|
704 | - } |
|
705 | - |
|
706 | - return false; |
|
691 | + if (isset($_REQUEST['code'])) { |
|
692 | + if ($this->state !== null && |
|
693 | + isset($_REQUEST['state']) && |
|
694 | + $this->state === $_REQUEST['state']) { |
|
695 | + |
|
696 | + // CSRF state has done its job, so clear it |
|
697 | + $this->state = null; |
|
698 | + $this->clearPersistentData('state'); |
|
699 | + return $_REQUEST['code']; |
|
700 | + } else { |
|
701 | + self::errorLog('CSRF state token does not match one provided.'); |
|
702 | + return false; |
|
703 | + } |
|
704 | + } |
|
705 | + |
|
706 | + return false; |
|
707 | 707 | } |
708 | 708 | |
709 | 709 | /** |
@@ -717,12 +717,12 @@ discard block |
||
717 | 717 | * if the Facebook user could not be determined. |
718 | 718 | */ |
719 | 719 | protected function getUserFromAccessToken() { |
720 | - try { |
|
721 | - $user_info = $this->api('/me'); |
|
722 | - return $user_info['id']; |
|
723 | - } catch (FacebookApiException $e) { |
|
724 | - return 0; |
|
725 | - } |
|
720 | + try { |
|
721 | + $user_info = $this->api('/me'); |
|
722 | + return $user_info['id']; |
|
723 | + } catch (FacebookApiException $e) { |
|
724 | + return 0; |
|
725 | + } |
|
726 | 726 | } |
727 | 727 | |
728 | 728 | /** |
@@ -733,7 +733,7 @@ discard block |
||
733 | 733 | * public information about users and applications. |
734 | 734 | */ |
735 | 735 | protected function getApplicationAccessToken() { |
736 | - return $this->appId.'|'.$this->appSecret; |
|
736 | + return $this->appId.'|'.$this->appSecret; |
|
737 | 737 | } |
738 | 738 | |
739 | 739 | /** |
@@ -742,10 +742,10 @@ discard block |
||
742 | 742 | * @return void |
743 | 743 | */ |
744 | 744 | protected function establishCSRFTokenState() { |
745 | - if ($this->state === null) { |
|
746 | - $this->state = md5(uniqid(mt_rand(), true)); |
|
747 | - $this->setPersistentData('state', $this->state); |
|
748 | - } |
|
745 | + if ($this->state === null) { |
|
746 | + $this->state = md5(uniqid(mt_rand(), true)); |
|
747 | + $this->setPersistentData('state', $this->state); |
|
748 | + } |
|
749 | 749 | } |
750 | 750 | |
751 | 751 | /** |
@@ -761,41 +761,41 @@ discard block |
||
761 | 761 | * false if an access token could not be generated. |
762 | 762 | */ |
763 | 763 | protected function getAccessTokenFromCode($code, $redirect_uri = null) { |
764 | - if (empty($code)) { |
|
765 | - return false; |
|
766 | - } |
|
767 | - |
|
768 | - if ($redirect_uri === null) { |
|
769 | - $redirect_uri = $this->getCurrentUrl(); |
|
770 | - } |
|
771 | - |
|
772 | - try { |
|
773 | - // need to circumvent json_decode by calling _oauthRequest |
|
774 | - // directly, since response isn't JSON format. |
|
775 | - $access_token_response = |
|
776 | - $this->_oauthRequest( |
|
777 | - $this->getUrl('graph', '/oauth/access_token'), |
|
778 | - $params = array('client_id' => $this->getAppId(), |
|
779 | - 'client_secret' => $this->getAppSecret(), |
|
780 | - 'redirect_uri' => $redirect_uri, |
|
781 | - 'code' => $code)); |
|
782 | - } catch (FacebookApiException $e) { |
|
783 | - // most likely that user very recently revoked authorization. |
|
784 | - // In any event, we don't have an access token, so say so. |
|
785 | - return false; |
|
786 | - } |
|
787 | - |
|
788 | - if (empty($access_token_response)) { |
|
789 | - return false; |
|
790 | - } |
|
791 | - |
|
792 | - $response_params = array(); |
|
793 | - parse_str($access_token_response, $response_params); |
|
794 | - if (!isset($response_params['access_token'])) { |
|
795 | - return false; |
|
796 | - } |
|
797 | - |
|
798 | - return $response_params['access_token']; |
|
764 | + if (empty($code)) { |
|
765 | + return false; |
|
766 | + } |
|
767 | + |
|
768 | + if ($redirect_uri === null) { |
|
769 | + $redirect_uri = $this->getCurrentUrl(); |
|
770 | + } |
|
771 | + |
|
772 | + try { |
|
773 | + // need to circumvent json_decode by calling _oauthRequest |
|
774 | + // directly, since response isn't JSON format. |
|
775 | + $access_token_response = |
|
776 | + $this->_oauthRequest( |
|
777 | + $this->getUrl('graph', '/oauth/access_token'), |
|
778 | + $params = array('client_id' => $this->getAppId(), |
|
779 | + 'client_secret' => $this->getAppSecret(), |
|
780 | + 'redirect_uri' => $redirect_uri, |
|
781 | + 'code' => $code)); |
|
782 | + } catch (FacebookApiException $e) { |
|
783 | + // most likely that user very recently revoked authorization. |
|
784 | + // In any event, we don't have an access token, so say so. |
|
785 | + return false; |
|
786 | + } |
|
787 | + |
|
788 | + if (empty($access_token_response)) { |
|
789 | + return false; |
|
790 | + } |
|
791 | + |
|
792 | + $response_params = array(); |
|
793 | + parse_str($access_token_response, $response_params); |
|
794 | + if (!isset($response_params['access_token'])) { |
|
795 | + return false; |
|
796 | + } |
|
797 | + |
|
798 | + return $response_params['access_token']; |
|
799 | 799 | } |
800 | 800 | |
801 | 801 | /** |
@@ -807,29 +807,29 @@ discard block |
||
807 | 807 | * @throws FacebookApiException |
808 | 808 | */ |
809 | 809 | protected function _restserver($params) { |
810 | - // generic application level parameters |
|
811 | - $params['api_key'] = $this->getAppId(); |
|
812 | - $params['format'] = 'json-strings'; |
|
813 | - |
|
814 | - $result = json_decode($this->_oauthRequest( |
|
815 | - $this->getApiUrl($params['method']), |
|
816 | - $params |
|
817 | - ), true); |
|
818 | - |
|
819 | - // results are returned, errors are thrown |
|
820 | - if (is_array($result) && isset($result['error_code'])) { |
|
821 | - $this->throwAPIException($result); |
|
822 | - // @codeCoverageIgnoreStart |
|
823 | - } |
|
824 | - // @codeCoverageIgnoreEnd |
|
825 | - |
|
826 | - $method = strtolower($params['method']); |
|
827 | - if ($method === 'auth.expiresession' || |
|
828 | - $method === 'auth.revokeauthorization') { |
|
829 | - $this->destroySession(); |
|
830 | - } |
|
831 | - |
|
832 | - return $result; |
|
810 | + // generic application level parameters |
|
811 | + $params['api_key'] = $this->getAppId(); |
|
812 | + $params['format'] = 'json-strings'; |
|
813 | + |
|
814 | + $result = json_decode($this->_oauthRequest( |
|
815 | + $this->getApiUrl($params['method']), |
|
816 | + $params |
|
817 | + ), true); |
|
818 | + |
|
819 | + // results are returned, errors are thrown |
|
820 | + if (is_array($result) && isset($result['error_code'])) { |
|
821 | + $this->throwAPIException($result); |
|
822 | + // @codeCoverageIgnoreStart |
|
823 | + } |
|
824 | + // @codeCoverageIgnoreEnd |
|
825 | + |
|
826 | + $method = strtolower($params['method']); |
|
827 | + if ($method === 'auth.expiresession' || |
|
828 | + $method === 'auth.revokeauthorization') { |
|
829 | + $this->destroySession(); |
|
830 | + } |
|
831 | + |
|
832 | + return $result; |
|
833 | 833 | } |
834 | 834 | |
835 | 835 | /** |
@@ -841,10 +841,10 @@ discard block |
||
841 | 841 | * @return boolean true if this is video post |
842 | 842 | */ |
843 | 843 | protected function isVideoPost($path, $method = 'GET') { |
844 | - if ($method == 'POST' && preg_match("/^(\/)(.+)(\/)(videos)$/", $path)) { |
|
845 | - return true; |
|
846 | - } |
|
847 | - return false; |
|
844 | + if ($method == 'POST' && preg_match("/^(\/)(.+)(\/)(videos)$/", $path)) { |
|
845 | + return true; |
|
846 | + } |
|
847 | + return false; |
|
848 | 848 | } |
849 | 849 | |
850 | 850 | /** |
@@ -858,31 +858,31 @@ discard block |
||
858 | 858 | * @throws FacebookApiException |
859 | 859 | */ |
860 | 860 | protected function _graph($path, $method = 'GET', $params = array()) { |
861 | - if (is_array($method) && empty($params)) { |
|
862 | - $params = $method; |
|
863 | - $method = 'GET'; |
|
864 | - } |
|
865 | - $params['method'] = $method; // method override as we always do a POST |
|
866 | - |
|
867 | - if ($this->isVideoPost($path, $method)) { |
|
868 | - $domainKey = 'graph_video'; |
|
869 | - } else { |
|
870 | - $domainKey = 'graph'; |
|
871 | - } |
|
872 | - |
|
873 | - $result = json_decode($this->_oauthRequest( |
|
874 | - $this->getUrl($domainKey, $path), |
|
875 | - $params |
|
876 | - ), true); |
|
877 | - |
|
878 | - // results are returned, errors are thrown |
|
879 | - if (is_array($result) && isset($result['error'])) { |
|
880 | - $this->throwAPIException($result); |
|
881 | - // @codeCoverageIgnoreStart |
|
882 | - } |
|
883 | - // @codeCoverageIgnoreEnd |
|
884 | - |
|
885 | - return $result; |
|
861 | + if (is_array($method) && empty($params)) { |
|
862 | + $params = $method; |
|
863 | + $method = 'GET'; |
|
864 | + } |
|
865 | + $params['method'] = $method; // method override as we always do a POST |
|
866 | + |
|
867 | + if ($this->isVideoPost($path, $method)) { |
|
868 | + $domainKey = 'graph_video'; |
|
869 | + } else { |
|
870 | + $domainKey = 'graph'; |
|
871 | + } |
|
872 | + |
|
873 | + $result = json_decode($this->_oauthRequest( |
|
874 | + $this->getUrl($domainKey, $path), |
|
875 | + $params |
|
876 | + ), true); |
|
877 | + |
|
878 | + // results are returned, errors are thrown |
|
879 | + if (is_array($result) && isset($result['error'])) { |
|
880 | + $this->throwAPIException($result); |
|
881 | + // @codeCoverageIgnoreStart |
|
882 | + } |
|
883 | + // @codeCoverageIgnoreEnd |
|
884 | + |
|
885 | + return $result; |
|
886 | 886 | } |
887 | 887 | |
888 | 888 | /** |
@@ -895,22 +895,22 @@ discard block |
||
895 | 895 | * @throws FacebookApiException |
896 | 896 | */ |
897 | 897 | protected function _oauthRequest($url, $params) { |
898 | - if (!isset($params['access_token'])) { |
|
899 | - $params['access_token'] = $this->getAccessToken(); |
|
900 | - } |
|
901 | - |
|
902 | - if (isset($params['access_token'])) { |
|
903 | - $params['appsecret_proof'] = $this->getAppSecretProof($params['access_token']); |
|
904 | - } |
|
905 | - |
|
906 | - // json_encode all params values that are not strings |
|
907 | - foreach ($params as $key => $value) { |
|
908 | - if (!is_string($value)) { |
|
909 | - $params[$key] = json_encode($value); |
|
910 | - } |
|
911 | - } |
|
912 | - |
|
913 | - return $this->makeRequest($url, $params); |
|
898 | + if (!isset($params['access_token'])) { |
|
899 | + $params['access_token'] = $this->getAccessToken(); |
|
900 | + } |
|
901 | + |
|
902 | + if (isset($params['access_token'])) { |
|
903 | + $params['appsecret_proof'] = $this->getAppSecretProof($params['access_token']); |
|
904 | + } |
|
905 | + |
|
906 | + // json_encode all params values that are not strings |
|
907 | + foreach ($params as $key => $value) { |
|
908 | + if (!is_string($value)) { |
|
909 | + $params[$key] = json_encode($value); |
|
910 | + } |
|
911 | + } |
|
912 | + |
|
913 | + return $this->makeRequest($url, $params); |
|
914 | 914 | } |
915 | 915 | |
916 | 916 | /** |
@@ -923,7 +923,7 @@ discard block |
||
923 | 923 | * @return string The sha256 hash of the access_token |
924 | 924 | */ |
925 | 925 | protected function getAppSecretProof($access_token) { |
926 | - return hash_hmac('sha256', $access_token, $this->getAppSecret()); |
|
926 | + return hash_hmac('sha256', $access_token, $this->getAppSecret()); |
|
927 | 927 | } |
928 | 928 | |
929 | 929 | /** |
@@ -938,71 +938,71 @@ discard block |
||
938 | 938 | * @return string The response text |
939 | 939 | */ |
940 | 940 | protected function makeRequest($url, $params, $ch=null) { |
941 | - if (!$ch) { |
|
942 | - $ch = curl_init(); |
|
943 | - } |
|
944 | - |
|
945 | - $opts = self::$CURL_OPTS; |
|
946 | - if ($this->getFileUploadSupport()) { |
|
947 | - $opts[CURLOPT_POSTFIELDS] = $params; |
|
948 | - } else { |
|
949 | - $opts[CURLOPT_POSTFIELDS] = http_build_query($params, null, '&'); |
|
950 | - } |
|
951 | - $opts[CURLOPT_URL] = $url; |
|
952 | - |
|
953 | - // disable the 'Expect: 100-continue' behaviour. This causes CURL to wait |
|
954 | - // for 2 seconds if the server does not support this header. |
|
955 | - if (isset($opts[CURLOPT_HTTPHEADER])) { |
|
956 | - $existing_headers = $opts[CURLOPT_HTTPHEADER]; |
|
957 | - $existing_headers[] = 'Expect:'; |
|
958 | - $opts[CURLOPT_HTTPHEADER] = $existing_headers; |
|
959 | - } else { |
|
960 | - $opts[CURLOPT_HTTPHEADER] = array('Expect:'); |
|
961 | - } |
|
962 | - |
|
963 | - curl_setopt_array($ch, $opts); |
|
964 | - $result = curl_exec($ch); |
|
965 | - |
|
966 | - if (curl_errno($ch) == 60) { // CURLE_SSL_CACERT |
|
967 | - self::errorLog('Invalid or no certificate authority found, '. |
|
968 | - 'using bundled information'); |
|
969 | - curl_setopt($ch, CURLOPT_CAINFO, |
|
970 | - dirname(__FILE__) . '/fb_ca_chain_bundle.crt'); |
|
971 | - $result = curl_exec($ch); |
|
972 | - } |
|
973 | - |
|
974 | - // With dual stacked DNS responses, it's possible for a server to |
|
975 | - // have IPv6 enabled but not have IPv6 connectivity. If this is |
|
976 | - // the case, curl will try IPv4 first and if that fails, then it will |
|
977 | - // fall back to IPv6 and the error EHOSTUNREACH is returned by the |
|
978 | - // operating system. |
|
979 | - if ($result === false && empty($opts[CURLOPT_IPRESOLVE])) { |
|
980 | - $matches = array(); |
|
981 | - $regex = '/Failed to connect to ([^:].*): Network is unreachable/'; |
|
982 | - if (preg_match($regex, curl_error($ch), $matches)) { |
|
983 | - if (strlen(@inet_pton($matches[1])) === 16) { |
|
984 | - self::errorLog('Invalid IPv6 configuration on server, '. |
|
985 | - 'Please disable or get native IPv6 on your server.'); |
|
986 | - self::$CURL_OPTS[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4; |
|
987 | - curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); |
|
988 | - $result = curl_exec($ch); |
|
989 | - } |
|
990 | - } |
|
991 | - } |
|
992 | - |
|
993 | - if ($result === false) { |
|
994 | - $e = new FacebookApiException(array( |
|
995 | - 'error_code' => curl_errno($ch), |
|
996 | - 'error' => array( |
|
997 | - 'message' => curl_error($ch), |
|
998 | - 'type' => 'CurlException', |
|
999 | - ), |
|
1000 | - )); |
|
1001 | - curl_close($ch); |
|
1002 | - throw $e; |
|
1003 | - } |
|
1004 | - curl_close($ch); |
|
1005 | - return $result; |
|
941 | + if (!$ch) { |
|
942 | + $ch = curl_init(); |
|
943 | + } |
|
944 | + |
|
945 | + $opts = self::$CURL_OPTS; |
|
946 | + if ($this->getFileUploadSupport()) { |
|
947 | + $opts[CURLOPT_POSTFIELDS] = $params; |
|
948 | + } else { |
|
949 | + $opts[CURLOPT_POSTFIELDS] = http_build_query($params, null, '&'); |
|
950 | + } |
|
951 | + $opts[CURLOPT_URL] = $url; |
|
952 | + |
|
953 | + // disable the 'Expect: 100-continue' behaviour. This causes CURL to wait |
|
954 | + // for 2 seconds if the server does not support this header. |
|
955 | + if (isset($opts[CURLOPT_HTTPHEADER])) { |
|
956 | + $existing_headers = $opts[CURLOPT_HTTPHEADER]; |
|
957 | + $existing_headers[] = 'Expect:'; |
|
958 | + $opts[CURLOPT_HTTPHEADER] = $existing_headers; |
|
959 | + } else { |
|
960 | + $opts[CURLOPT_HTTPHEADER] = array('Expect:'); |
|
961 | + } |
|
962 | + |
|
963 | + curl_setopt_array($ch, $opts); |
|
964 | + $result = curl_exec($ch); |
|
965 | + |
|
966 | + if (curl_errno($ch) == 60) { // CURLE_SSL_CACERT |
|
967 | + self::errorLog('Invalid or no certificate authority found, '. |
|
968 | + 'using bundled information'); |
|
969 | + curl_setopt($ch, CURLOPT_CAINFO, |
|
970 | + dirname(__FILE__) . '/fb_ca_chain_bundle.crt'); |
|
971 | + $result = curl_exec($ch); |
|
972 | + } |
|
973 | + |
|
974 | + // With dual stacked DNS responses, it's possible for a server to |
|
975 | + // have IPv6 enabled but not have IPv6 connectivity. If this is |
|
976 | + // the case, curl will try IPv4 first and if that fails, then it will |
|
977 | + // fall back to IPv6 and the error EHOSTUNREACH is returned by the |
|
978 | + // operating system. |
|
979 | + if ($result === false && empty($opts[CURLOPT_IPRESOLVE])) { |
|
980 | + $matches = array(); |
|
981 | + $regex = '/Failed to connect to ([^:].*): Network is unreachable/'; |
|
982 | + if (preg_match($regex, curl_error($ch), $matches)) { |
|
983 | + if (strlen(@inet_pton($matches[1])) === 16) { |
|
984 | + self::errorLog('Invalid IPv6 configuration on server, '. |
|
985 | + 'Please disable or get native IPv6 on your server.'); |
|
986 | + self::$CURL_OPTS[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4; |
|
987 | + curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); |
|
988 | + $result = curl_exec($ch); |
|
989 | + } |
|
990 | + } |
|
991 | + } |
|
992 | + |
|
993 | + if ($result === false) { |
|
994 | + $e = new FacebookApiException(array( |
|
995 | + 'error_code' => curl_errno($ch), |
|
996 | + 'error' => array( |
|
997 | + 'message' => curl_error($ch), |
|
998 | + 'type' => 'CurlException', |
|
999 | + ), |
|
1000 | + )); |
|
1001 | + curl_close($ch); |
|
1002 | + throw $e; |
|
1003 | + } |
|
1004 | + curl_close($ch); |
|
1005 | + return $result; |
|
1006 | 1006 | } |
1007 | 1007 | |
1008 | 1008 | /** |
@@ -1012,27 +1012,27 @@ discard block |
||
1012 | 1012 | * @return array The payload inside it or null if the sig is wrong |
1013 | 1013 | */ |
1014 | 1014 | protected function parseSignedRequest($signed_request) { |
1015 | - list($encoded_sig, $payload) = explode('.', $signed_request, 2); |
|
1016 | - |
|
1017 | - // decode the data |
|
1018 | - $sig = self::base64UrlDecode($encoded_sig); |
|
1019 | - $data = json_decode(self::base64UrlDecode($payload), true); |
|
1020 | - |
|
1021 | - if (strtoupper($data['algorithm']) !== self::SIGNED_REQUEST_ALGORITHM) { |
|
1022 | - self::errorLog( |
|
1023 | - 'Unknown algorithm. Expected ' . self::SIGNED_REQUEST_ALGORITHM); |
|
1024 | - return null; |
|
1025 | - } |
|
1026 | - |
|
1027 | - // check sig |
|
1028 | - $expected_sig = hash_hmac('sha256', $payload, |
|
1029 | - $this->getAppSecret(), $raw = true); |
|
1030 | - if ($sig !== $expected_sig) { |
|
1031 | - self::errorLog('Bad Signed JSON signature!'); |
|
1032 | - return null; |
|
1033 | - } |
|
1034 | - |
|
1035 | - return $data; |
|
1015 | + list($encoded_sig, $payload) = explode('.', $signed_request, 2); |
|
1016 | + |
|
1017 | + // decode the data |
|
1018 | + $sig = self::base64UrlDecode($encoded_sig); |
|
1019 | + $data = json_decode(self::base64UrlDecode($payload), true); |
|
1020 | + |
|
1021 | + if (strtoupper($data['algorithm']) !== self::SIGNED_REQUEST_ALGORITHM) { |
|
1022 | + self::errorLog( |
|
1023 | + 'Unknown algorithm. Expected ' . self::SIGNED_REQUEST_ALGORITHM); |
|
1024 | + return null; |
|
1025 | + } |
|
1026 | + |
|
1027 | + // check sig |
|
1028 | + $expected_sig = hash_hmac('sha256', $payload, |
|
1029 | + $this->getAppSecret(), $raw = true); |
|
1030 | + if ($sig !== $expected_sig) { |
|
1031 | + self::errorLog('Bad Signed JSON signature!'); |
|
1032 | + return null; |
|
1033 | + } |
|
1034 | + |
|
1035 | + return $data; |
|
1036 | 1036 | } |
1037 | 1037 | |
1038 | 1038 | /** |
@@ -1042,17 +1042,17 @@ discard block |
||
1042 | 1042 | * @return string The signed request. |
1043 | 1043 | */ |
1044 | 1044 | protected function makeSignedRequest($data) { |
1045 | - if (!is_array($data)) { |
|
1046 | - throw new InvalidArgumentException( |
|
1047 | - 'makeSignedRequest expects an array. Got: ' . print_r($data, true)); |
|
1048 | - } |
|
1049 | - $data['algorithm'] = self::SIGNED_REQUEST_ALGORITHM; |
|
1050 | - $data['issued_at'] = time(); |
|
1051 | - $json = json_encode($data); |
|
1052 | - $b64 = self::base64UrlEncode($json); |
|
1053 | - $raw_sig = hash_hmac('sha256', $b64, $this->getAppSecret(), $raw = true); |
|
1054 | - $sig = self::base64UrlEncode($raw_sig); |
|
1055 | - return $sig.'.'.$b64; |
|
1045 | + if (!is_array($data)) { |
|
1046 | + throw new InvalidArgumentException( |
|
1047 | + 'makeSignedRequest expects an array. Got: ' . print_r($data, true)); |
|
1048 | + } |
|
1049 | + $data['algorithm'] = self::SIGNED_REQUEST_ALGORITHM; |
|
1050 | + $data['issued_at'] = time(); |
|
1051 | + $json = json_encode($data); |
|
1052 | + $b64 = self::base64UrlEncode($json); |
|
1053 | + $raw_sig = hash_hmac('sha256', $b64, $this->getAppSecret(), $raw = true); |
|
1054 | + $sig = self::base64UrlEncode($raw_sig); |
|
1055 | + return $sig.'.'.$b64; |
|
1056 | 1056 | } |
1057 | 1057 | |
1058 | 1058 | /** |
@@ -1062,74 +1062,74 @@ discard block |
||
1062 | 1062 | * @return string The URL for the given parameters |
1063 | 1063 | */ |
1064 | 1064 | protected function getApiUrl($method) { |
1065 | - static $READ_ONLY_CALLS = |
|
1066 | - array('admin.getallocation' => 1, |
|
1067 | - 'admin.getappproperties' => 1, |
|
1068 | - 'admin.getbannedusers' => 1, |
|
1069 | - 'admin.getlivestreamvialink' => 1, |
|
1070 | - 'admin.getmetrics' => 1, |
|
1071 | - 'admin.getrestrictioninfo' => 1, |
|
1072 | - 'application.getpublicinfo' => 1, |
|
1073 | - 'auth.getapppublickey' => 1, |
|
1074 | - 'auth.getsession' => 1, |
|
1075 | - 'auth.getsignedpublicsessiondata' => 1, |
|
1076 | - 'comments.get' => 1, |
|
1077 | - 'connect.getunconnectedfriendscount' => 1, |
|
1078 | - 'dashboard.getactivity' => 1, |
|
1079 | - 'dashboard.getcount' => 1, |
|
1080 | - 'dashboard.getglobalnews' => 1, |
|
1081 | - 'dashboard.getnews' => 1, |
|
1082 | - 'dashboard.multigetcount' => 1, |
|
1083 | - 'dashboard.multigetnews' => 1, |
|
1084 | - 'data.getcookies' => 1, |
|
1085 | - 'events.get' => 1, |
|
1086 | - 'events.getmembers' => 1, |
|
1087 | - 'fbml.getcustomtags' => 1, |
|
1088 | - 'feed.getappfriendstories' => 1, |
|
1089 | - 'feed.getregisteredtemplatebundlebyid' => 1, |
|
1090 | - 'feed.getregisteredtemplatebundles' => 1, |
|
1091 | - 'fql.multiquery' => 1, |
|
1092 | - 'fql.query' => 1, |
|
1093 | - 'friends.arefriends' => 1, |
|
1094 | - 'friends.get' => 1, |
|
1095 | - 'friends.getappusers' => 1, |
|
1096 | - 'friends.getlists' => 1, |
|
1097 | - 'friends.getmutualfriends' => 1, |
|
1098 | - 'gifts.get' => 1, |
|
1099 | - 'groups.get' => 1, |
|
1100 | - 'groups.getmembers' => 1, |
|
1101 | - 'intl.gettranslations' => 1, |
|
1102 | - 'links.get' => 1, |
|
1103 | - 'notes.get' => 1, |
|
1104 | - 'notifications.get' => 1, |
|
1105 | - 'pages.getinfo' => 1, |
|
1106 | - 'pages.isadmin' => 1, |
|
1107 | - 'pages.isappadded' => 1, |
|
1108 | - 'pages.isfan' => 1, |
|
1109 | - 'permissions.checkavailableapiaccess' => 1, |
|
1110 | - 'permissions.checkgrantedapiaccess' => 1, |
|
1111 | - 'photos.get' => 1, |
|
1112 | - 'photos.getalbums' => 1, |
|
1113 | - 'photos.gettags' => 1, |
|
1114 | - 'profile.getinfo' => 1, |
|
1115 | - 'profile.getinfooptions' => 1, |
|
1116 | - 'stream.get' => 1, |
|
1117 | - 'stream.getcomments' => 1, |
|
1118 | - 'stream.getfilters' => 1, |
|
1119 | - 'users.getinfo' => 1, |
|
1120 | - 'users.getloggedinuser' => 1, |
|
1121 | - 'users.getstandardinfo' => 1, |
|
1122 | - 'users.hasapppermission' => 1, |
|
1123 | - 'users.isappuser' => 1, |
|
1124 | - 'users.isverified' => 1, |
|
1125 | - 'video.getuploadlimits' => 1); |
|
1126 | - $name = 'api'; |
|
1127 | - if (isset($READ_ONLY_CALLS[strtolower($method)])) { |
|
1128 | - $name = 'api_read'; |
|
1129 | - } else if (strtolower($method) == 'video.upload') { |
|
1130 | - $name = 'api_video'; |
|
1131 | - } |
|
1132 | - return self::getUrl($name, 'restserver.php'); |
|
1065 | + static $READ_ONLY_CALLS = |
|
1066 | + array('admin.getallocation' => 1, |
|
1067 | + 'admin.getappproperties' => 1, |
|
1068 | + 'admin.getbannedusers' => 1, |
|
1069 | + 'admin.getlivestreamvialink' => 1, |
|
1070 | + 'admin.getmetrics' => 1, |
|
1071 | + 'admin.getrestrictioninfo' => 1, |
|
1072 | + 'application.getpublicinfo' => 1, |
|
1073 | + 'auth.getapppublickey' => 1, |
|
1074 | + 'auth.getsession' => 1, |
|
1075 | + 'auth.getsignedpublicsessiondata' => 1, |
|
1076 | + 'comments.get' => 1, |
|
1077 | + 'connect.getunconnectedfriendscount' => 1, |
|
1078 | + 'dashboard.getactivity' => 1, |
|
1079 | + 'dashboard.getcount' => 1, |
|
1080 | + 'dashboard.getglobalnews' => 1, |
|
1081 | + 'dashboard.getnews' => 1, |
|
1082 | + 'dashboard.multigetcount' => 1, |
|
1083 | + 'dashboard.multigetnews' => 1, |
|
1084 | + 'data.getcookies' => 1, |
|
1085 | + 'events.get' => 1, |
|
1086 | + 'events.getmembers' => 1, |
|
1087 | + 'fbml.getcustomtags' => 1, |
|
1088 | + 'feed.getappfriendstories' => 1, |
|
1089 | + 'feed.getregisteredtemplatebundlebyid' => 1, |
|
1090 | + 'feed.getregisteredtemplatebundles' => 1, |
|
1091 | + 'fql.multiquery' => 1, |
|
1092 | + 'fql.query' => 1, |
|
1093 | + 'friends.arefriends' => 1, |
|
1094 | + 'friends.get' => 1, |
|
1095 | + 'friends.getappusers' => 1, |
|
1096 | + 'friends.getlists' => 1, |
|
1097 | + 'friends.getmutualfriends' => 1, |
|
1098 | + 'gifts.get' => 1, |
|
1099 | + 'groups.get' => 1, |
|
1100 | + 'groups.getmembers' => 1, |
|
1101 | + 'intl.gettranslations' => 1, |
|
1102 | + 'links.get' => 1, |
|
1103 | + 'notes.get' => 1, |
|
1104 | + 'notifications.get' => 1, |
|
1105 | + 'pages.getinfo' => 1, |
|
1106 | + 'pages.isadmin' => 1, |
|
1107 | + 'pages.isappadded' => 1, |
|
1108 | + 'pages.isfan' => 1, |
|
1109 | + 'permissions.checkavailableapiaccess' => 1, |
|
1110 | + 'permissions.checkgrantedapiaccess' => 1, |
|
1111 | + 'photos.get' => 1, |
|
1112 | + 'photos.getalbums' => 1, |
|
1113 | + 'photos.gettags' => 1, |
|
1114 | + 'profile.getinfo' => 1, |
|
1115 | + 'profile.getinfooptions' => 1, |
|
1116 | + 'stream.get' => 1, |
|
1117 | + 'stream.getcomments' => 1, |
|
1118 | + 'stream.getfilters' => 1, |
|
1119 | + 'users.getinfo' => 1, |
|
1120 | + 'users.getloggedinuser' => 1, |
|
1121 | + 'users.getstandardinfo' => 1, |
|
1122 | + 'users.hasapppermission' => 1, |
|
1123 | + 'users.isappuser' => 1, |
|
1124 | + 'users.isverified' => 1, |
|
1125 | + 'video.getuploadlimits' => 1); |
|
1126 | + $name = 'api'; |
|
1127 | + if (isset($READ_ONLY_CALLS[strtolower($method)])) { |
|
1128 | + $name = 'api_read'; |
|
1129 | + } else if (strtolower($method) == 'video.upload') { |
|
1130 | + $name = 'api_video'; |
|
1131 | + } |
|
1132 | + return self::getUrl($name, 'restserver.php'); |
|
1133 | 1133 | } |
1134 | 1134 | |
1135 | 1135 | /** |
@@ -1142,59 +1142,59 @@ discard block |
||
1142 | 1142 | * @return string The URL for the given parameters |
1143 | 1143 | */ |
1144 | 1144 | protected function getUrl($name, $path='', $params=array()) { |
1145 | - $url = self::$DOMAIN_MAP[$name]; |
|
1146 | - if ($path) { |
|
1147 | - if ($path[0] === '/') { |
|
1148 | - $path = substr($path, 1); |
|
1149 | - } |
|
1150 | - $url .= $path; |
|
1151 | - } |
|
1152 | - if ($params) { |
|
1153 | - $url .= '?' . http_build_query($params, null, '&'); |
|
1154 | - } |
|
1155 | - |
|
1156 | - return $url; |
|
1145 | + $url = self::$DOMAIN_MAP[$name]; |
|
1146 | + if ($path) { |
|
1147 | + if ($path[0] === '/') { |
|
1148 | + $path = substr($path, 1); |
|
1149 | + } |
|
1150 | + $url .= $path; |
|
1151 | + } |
|
1152 | + if ($params) { |
|
1153 | + $url .= '?' . http_build_query($params, null, '&'); |
|
1154 | + } |
|
1155 | + |
|
1156 | + return $url; |
|
1157 | 1157 | } |
1158 | 1158 | |
1159 | 1159 | protected function getHttpHost() { |
1160 | - if ($this->trustForwarded && isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
1161 | - return $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
1162 | - } |
|
1163 | - return $_SERVER['HTTP_HOST']; |
|
1160 | + if ($this->trustForwarded && isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
1161 | + return $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
1162 | + } |
|
1163 | + return $_SERVER['HTTP_HOST']; |
|
1164 | 1164 | } |
1165 | 1165 | |
1166 | 1166 | protected function getHttpProtocol() { |
1167 | - if ($this->trustForwarded && isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) { |
|
1168 | - if ($_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
1169 | - return 'https'; |
|
1170 | - } |
|
1171 | - return 'http'; |
|
1172 | - } |
|
1173 | - /*apache + variants specific way of checking for https*/ |
|
1174 | - if (isset($_SERVER['HTTPS']) && |
|
1175 | - ($_SERVER['HTTPS'] === 'on' || $_SERVER['HTTPS'] == 1)) { |
|
1176 | - return 'https'; |
|
1177 | - } |
|
1178 | - /*nginx way of checking for https*/ |
|
1179 | - if (isset($_SERVER['SERVER_PORT']) && |
|
1180 | - ($_SERVER['SERVER_PORT'] === '443')) { |
|
1181 | - return 'https'; |
|
1182 | - } |
|
1183 | - return 'http'; |
|
1167 | + if ($this->trustForwarded && isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) { |
|
1168 | + if ($_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
1169 | + return 'https'; |
|
1170 | + } |
|
1171 | + return 'http'; |
|
1172 | + } |
|
1173 | + /*apache + variants specific way of checking for https*/ |
|
1174 | + if (isset($_SERVER['HTTPS']) && |
|
1175 | + ($_SERVER['HTTPS'] === 'on' || $_SERVER['HTTPS'] == 1)) { |
|
1176 | + return 'https'; |
|
1177 | + } |
|
1178 | + /*nginx way of checking for https*/ |
|
1179 | + if (isset($_SERVER['SERVER_PORT']) && |
|
1180 | + ($_SERVER['SERVER_PORT'] === '443')) { |
|
1181 | + return 'https'; |
|
1182 | + } |
|
1183 | + return 'http'; |
|
1184 | 1184 | } |
1185 | 1185 | |
1186 | 1186 | /** |
1187 | 1187 | * Get the base domain used for the cookie. |
1188 | 1188 | */ |
1189 | 1189 | protected function getBaseDomain() { |
1190 | - // The base domain is stored in the metadata cookie if not we fallback |
|
1191 | - // to the current hostname |
|
1192 | - $metadata = $this->getMetadataCookie(); |
|
1193 | - if (array_key_exists('base_domain', $metadata) && |
|
1194 | - !empty($metadata['base_domain'])) { |
|
1195 | - return trim($metadata['base_domain'], '.'); |
|
1196 | - } |
|
1197 | - return $this->getHttpHost(); |
|
1190 | + // The base domain is stored in the metadata cookie if not we fallback |
|
1191 | + // to the current hostname |
|
1192 | + $metadata = $this->getMetadataCookie(); |
|
1193 | + if (array_key_exists('base_domain', $metadata) && |
|
1194 | + !empty($metadata['base_domain'])) { |
|
1195 | + return trim($metadata['base_domain'], '.'); |
|
1196 | + } |
|
1197 | + return $this->getHttpHost(); |
|
1198 | 1198 | } |
1199 | 1199 | |
1200 | 1200 | /** |
@@ -1206,36 +1206,36 @@ discard block |
||
1206 | 1206 | * @return string The current URL |
1207 | 1207 | */ |
1208 | 1208 | protected function getCurrentUrl() { |
1209 | - $protocol = $this->getHttpProtocol() . '://'; |
|
1210 | - $host = $this->getHttpHost(); |
|
1211 | - $currentUrl = $protocol.$host.$_SERVER['REQUEST_URI']; |
|
1212 | - $parts = parse_url($currentUrl); |
|
1213 | - |
|
1214 | - $query = ''; |
|
1215 | - if (!empty($parts['query'])) { |
|
1216 | - // drop known fb params |
|
1217 | - $params = explode('&', $parts['query']); |
|
1218 | - $retained_params = array(); |
|
1219 | - foreach ($params as $param) { |
|
1220 | - if ($this->shouldRetainParam($param)) { |
|
1221 | - $retained_params[] = $param; |
|
1222 | - } |
|
1223 | - } |
|
1224 | - |
|
1225 | - if (!empty($retained_params)) { |
|
1226 | - $query = '?'.implode($retained_params, '&'); |
|
1227 | - } |
|
1228 | - } |
|
1229 | - |
|
1230 | - // use port if non default |
|
1231 | - $port = |
|
1232 | - isset($parts['port']) && |
|
1233 | - (($protocol === 'http://' && $parts['port'] !== 80) || |
|
1234 | - ($protocol === 'https://' && $parts['port'] !== 443)) |
|
1235 | - ? ':' . $parts['port'] : ''; |
|
1236 | - |
|
1237 | - // rebuild |
|
1238 | - return $protocol . $parts['host'] . $port . $parts['path'] . $query; |
|
1209 | + $protocol = $this->getHttpProtocol() . '://'; |
|
1210 | + $host = $this->getHttpHost(); |
|
1211 | + $currentUrl = $protocol.$host.$_SERVER['REQUEST_URI']; |
|
1212 | + $parts = parse_url($currentUrl); |
|
1213 | + |
|
1214 | + $query = ''; |
|
1215 | + if (!empty($parts['query'])) { |
|
1216 | + // drop known fb params |
|
1217 | + $params = explode('&', $parts['query']); |
|
1218 | + $retained_params = array(); |
|
1219 | + foreach ($params as $param) { |
|
1220 | + if ($this->shouldRetainParam($param)) { |
|
1221 | + $retained_params[] = $param; |
|
1222 | + } |
|
1223 | + } |
|
1224 | + |
|
1225 | + if (!empty($retained_params)) { |
|
1226 | + $query = '?'.implode($retained_params, '&'); |
|
1227 | + } |
|
1228 | + } |
|
1229 | + |
|
1230 | + // use port if non default |
|
1231 | + $port = |
|
1232 | + isset($parts['port']) && |
|
1233 | + (($protocol === 'http://' && $parts['port'] !== 80) || |
|
1234 | + ($protocol === 'https://' && $parts['port'] !== 443)) |
|
1235 | + ? ':' . $parts['port'] : ''; |
|
1236 | + |
|
1237 | + // rebuild |
|
1238 | + return $protocol . $parts['host'] . $port . $parts['path'] . $query; |
|
1239 | 1239 | } |
1240 | 1240 | |
1241 | 1241 | /** |
@@ -1250,13 +1250,13 @@ discard block |
||
1250 | 1250 | * @return boolean |
1251 | 1251 | */ |
1252 | 1252 | protected function shouldRetainParam($param) { |
1253 | - foreach (self::$DROP_QUERY_PARAMS as $drop_query_param) { |
|
1254 | - if (strpos($param, $drop_query_param.'=') === 0) { |
|
1255 | - return false; |
|
1256 | - } |
|
1257 | - } |
|
1253 | + foreach (self::$DROP_QUERY_PARAMS as $drop_query_param) { |
|
1254 | + if (strpos($param, $drop_query_param.'=') === 0) { |
|
1255 | + return false; |
|
1256 | + } |
|
1257 | + } |
|
1258 | 1258 | |
1259 | - return true; |
|
1259 | + return true; |
|
1260 | 1260 | } |
1261 | 1261 | |
1262 | 1262 | /** |
@@ -1268,25 +1268,25 @@ discard block |
||
1268 | 1268 | * by a failed API call. |
1269 | 1269 | */ |
1270 | 1270 | protected function throwAPIException($result) { |
1271 | - $e = new FacebookApiException($result); |
|
1272 | - switch ($e->getType()) { |
|
1273 | - // OAuth 2.0 Draft 00 style |
|
1274 | - case 'OAuthException': |
|
1275 | - // OAuth 2.0 Draft 10 style |
|
1276 | - case 'invalid_token': |
|
1277 | - // REST server errors are just Exceptions |
|
1278 | - case 'Exception': |
|
1279 | - $message = $e->getMessage(); |
|
1280 | - if ((strpos($message, 'Error validating access token') !== false) || |
|
1281 | - (strpos($message, 'Invalid OAuth access token') !== false) || |
|
1282 | - (strpos($message, 'An active access token must be used') !== false) |
|
1283 | - ) { |
|
1284 | - $this->destroySession(); |
|
1285 | - } |
|
1286 | - break; |
|
1287 | - } |
|
1288 | - |
|
1289 | - throw $e; |
|
1271 | + $e = new FacebookApiException($result); |
|
1272 | + switch ($e->getType()) { |
|
1273 | + // OAuth 2.0 Draft 00 style |
|
1274 | + case 'OAuthException': |
|
1275 | + // OAuth 2.0 Draft 10 style |
|
1276 | + case 'invalid_token': |
|
1277 | + // REST server errors are just Exceptions |
|
1278 | + case 'Exception': |
|
1279 | + $message = $e->getMessage(); |
|
1280 | + if ((strpos($message, 'Error validating access token') !== false) || |
|
1281 | + (strpos($message, 'Invalid OAuth access token') !== false) || |
|
1282 | + (strpos($message, 'An active access token must be used') !== false) |
|
1283 | + ) { |
|
1284 | + $this->destroySession(); |
|
1285 | + } |
|
1286 | + break; |
|
1287 | + } |
|
1288 | + |
|
1289 | + throw $e; |
|
1290 | 1290 | } |
1291 | 1291 | |
1292 | 1292 | |
@@ -1296,14 +1296,14 @@ discard block |
||
1296 | 1296 | * @param string $msg Log message |
1297 | 1297 | */ |
1298 | 1298 | protected static function errorLog($msg) { |
1299 | - // disable error log if we are running in a CLI environment |
|
1300 | - // @codeCoverageIgnoreStart |
|
1301 | - if (php_sapi_name() != 'cli') { |
|
1302 | - error_log($msg); |
|
1303 | - } |
|
1304 | - // uncomment this if you want to see the errors on the page |
|
1305 | - // print 'error_log: '.$msg."\n"; |
|
1306 | - // @codeCoverageIgnoreEnd |
|
1299 | + // disable error log if we are running in a CLI environment |
|
1300 | + // @codeCoverageIgnoreStart |
|
1301 | + if (php_sapi_name() != 'cli') { |
|
1302 | + error_log($msg); |
|
1303 | + } |
|
1304 | + // uncomment this if you want to see the errors on the page |
|
1305 | + // print 'error_log: '.$msg."\n"; |
|
1306 | + // @codeCoverageIgnoreEnd |
|
1307 | 1307 | } |
1308 | 1308 | |
1309 | 1309 | /** |
@@ -1317,7 +1317,7 @@ discard block |
||
1317 | 1317 | * @return string |
1318 | 1318 | */ |
1319 | 1319 | protected static function base64UrlDecode($input) { |
1320 | - return base64_decode(strtr($input, '-_', '+/')); |
|
1320 | + return base64_decode(strtr($input, '-_', '+/')); |
|
1321 | 1321 | } |
1322 | 1322 | |
1323 | 1323 | /** |
@@ -1330,38 +1330,38 @@ discard block |
||
1330 | 1330 | * @return string base64Url encoded string |
1331 | 1331 | */ |
1332 | 1332 | protected static function base64UrlEncode($input) { |
1333 | - $str = strtr(base64_encode($input), '+/', '-_'); |
|
1334 | - $str = str_replace('=', '', $str); |
|
1335 | - return $str; |
|
1333 | + $str = strtr(base64_encode($input), '+/', '-_'); |
|
1334 | + $str = str_replace('=', '', $str); |
|
1335 | + return $str; |
|
1336 | 1336 | } |
1337 | 1337 | |
1338 | 1338 | /** |
1339 | 1339 | * Destroy the current session |
1340 | 1340 | */ |
1341 | 1341 | public function destroySession() { |
1342 | - $this->accessToken = null; |
|
1343 | - $this->signedRequest = null; |
|
1344 | - $this->user = null; |
|
1345 | - $this->clearAllPersistentData(); |
|
1346 | - |
|
1347 | - // Javascript sets a cookie that will be used in getSignedRequest that we |
|
1348 | - // need to clear if we can |
|
1349 | - $cookie_name = $this->getSignedRequestCookieName(); |
|
1350 | - if (array_key_exists($cookie_name, $_COOKIE)) { |
|
1351 | - unset($_COOKIE[$cookie_name]); |
|
1352 | - if (!headers_sent()) { |
|
1353 | - $base_domain = $this->getBaseDomain(); |
|
1354 | - setcookie($cookie_name, '', 1, '/', '.'.$base_domain); |
|
1355 | - } else { |
|
1356 | - // @codeCoverageIgnoreStart |
|
1357 | - self::errorLog( |
|
1358 | - 'There exists a cookie that we wanted to clear that we couldn\'t '. |
|
1359 | - 'clear because headers was already sent. Make sure to do the first '. |
|
1360 | - 'API call before outputing anything.' |
|
1361 | - ); |
|
1362 | - // @codeCoverageIgnoreEnd |
|
1363 | - } |
|
1364 | - } |
|
1342 | + $this->accessToken = null; |
|
1343 | + $this->signedRequest = null; |
|
1344 | + $this->user = null; |
|
1345 | + $this->clearAllPersistentData(); |
|
1346 | + |
|
1347 | + // Javascript sets a cookie that will be used in getSignedRequest that we |
|
1348 | + // need to clear if we can |
|
1349 | + $cookie_name = $this->getSignedRequestCookieName(); |
|
1350 | + if (array_key_exists($cookie_name, $_COOKIE)) { |
|
1351 | + unset($_COOKIE[$cookie_name]); |
|
1352 | + if (!headers_sent()) { |
|
1353 | + $base_domain = $this->getBaseDomain(); |
|
1354 | + setcookie($cookie_name, '', 1, '/', '.'.$base_domain); |
|
1355 | + } else { |
|
1356 | + // @codeCoverageIgnoreStart |
|
1357 | + self::errorLog( |
|
1358 | + 'There exists a cookie that we wanted to clear that we couldn\'t '. |
|
1359 | + 'clear because headers was already sent. Make sure to do the first '. |
|
1360 | + 'API call before outputing anything.' |
|
1361 | + ); |
|
1362 | + // @codeCoverageIgnoreEnd |
|
1363 | + } |
|
1364 | + } |
|
1365 | 1365 | } |
1366 | 1366 | |
1367 | 1367 | /** |
@@ -1370,44 +1370,44 @@ discard block |
||
1370 | 1370 | * @return an array mapping key to value |
1371 | 1371 | */ |
1372 | 1372 | protected function getMetadataCookie() { |
1373 | - $cookie_name = $this->getMetadataCookieName(); |
|
1374 | - if (!array_key_exists($cookie_name, $_COOKIE)) { |
|
1375 | - return array(); |
|
1376 | - } |
|
1377 | - |
|
1378 | - // The cookie value can be wrapped in "-characters so remove them |
|
1379 | - $cookie_value = trim($_COOKIE[$cookie_name], '"'); |
|
1380 | - |
|
1381 | - if (empty($cookie_value)) { |
|
1382 | - return array(); |
|
1383 | - } |
|
1384 | - |
|
1385 | - $parts = explode('&', $cookie_value); |
|
1386 | - $metadata = array(); |
|
1387 | - foreach ($parts as $part) { |
|
1388 | - $pair = explode('=', $part, 2); |
|
1389 | - if (!empty($pair[0])) { |
|
1390 | - $metadata[urldecode($pair[0])] = |
|
1391 | - (count($pair) > 1) ? urldecode($pair[1]) : ''; |
|
1392 | - } |
|
1393 | - } |
|
1394 | - |
|
1395 | - return $metadata; |
|
1373 | + $cookie_name = $this->getMetadataCookieName(); |
|
1374 | + if (!array_key_exists($cookie_name, $_COOKIE)) { |
|
1375 | + return array(); |
|
1376 | + } |
|
1377 | + |
|
1378 | + // The cookie value can be wrapped in "-characters so remove them |
|
1379 | + $cookie_value = trim($_COOKIE[$cookie_name], '"'); |
|
1380 | + |
|
1381 | + if (empty($cookie_value)) { |
|
1382 | + return array(); |
|
1383 | + } |
|
1384 | + |
|
1385 | + $parts = explode('&', $cookie_value); |
|
1386 | + $metadata = array(); |
|
1387 | + foreach ($parts as $part) { |
|
1388 | + $pair = explode('=', $part, 2); |
|
1389 | + if (!empty($pair[0])) { |
|
1390 | + $metadata[urldecode($pair[0])] = |
|
1391 | + (count($pair) > 1) ? urldecode($pair[1]) : ''; |
|
1392 | + } |
|
1393 | + } |
|
1394 | + |
|
1395 | + return $metadata; |
|
1396 | 1396 | } |
1397 | 1397 | |
1398 | 1398 | protected static function isAllowedDomain($big, $small) { |
1399 | - if ($big === $small) { |
|
1400 | - return true; |
|
1401 | - } |
|
1402 | - return self::endsWith($big, '.'.$small); |
|
1399 | + if ($big === $small) { |
|
1400 | + return true; |
|
1401 | + } |
|
1402 | + return self::endsWith($big, '.'.$small); |
|
1403 | 1403 | } |
1404 | 1404 | |
1405 | 1405 | protected static function endsWith($big, $small) { |
1406 | - $len = strlen($small); |
|
1407 | - if ($len === 0) { |
|
1408 | - return true; |
|
1409 | - } |
|
1410 | - return substr($big, -$len) === $small; |
|
1406 | + $len = strlen($small); |
|
1407 | + if ($len === 0) { |
|
1408 | + return true; |
|
1409 | + } |
|
1410 | + return substr($big, -$len) === $small; |
|
1411 | 1411 | } |
1412 | 1412 | |
1413 | 1413 | /** |
@@ -98,11 +98,11 @@ discard block |
||
98 | 98 | * @return string The string representation of the error |
99 | 99 | */ |
100 | 100 | public function __toString() { |
101 | - $str = $this->getType() . ': '; |
|
101 | + $str = $this->getType().': '; |
|
102 | 102 | if ($this->code != 0) { |
103 | - $str .= $this->code . ': '; |
|
103 | + $str .= $this->code.': '; |
|
104 | 104 | } |
105 | - return $str . $this->message; |
|
105 | + return $str.$this->message; |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | |
@@ -530,7 +530,7 @@ discard block |
||
530 | 530 | if (array_key_exists('user_id', $signed_request)) { |
531 | 531 | $user = $signed_request['user_id']; |
532 | 532 | |
533 | - if($user != $this->getPersistentData('user_id')){ |
|
533 | + if ($user != $this->getPersistentData('user_id')) { |
|
534 | 534 | $this->clearAllPersistentData(); |
535 | 535 | } |
536 | 536 | |
@@ -576,7 +576,7 @@ discard block |
||
576 | 576 | * @param array $params Provide custom parameters |
577 | 577 | * @return string The URL for the login flow |
578 | 578 | */ |
579 | - public function getLoginUrl($params=array()) { |
|
579 | + public function getLoginUrl($params = array()) { |
|
580 | 580 | $this->establishCSRFTokenState(); |
581 | 581 | $currentUrl = $this->getCurrentUrl(); |
582 | 582 | |
@@ -605,7 +605,7 @@ discard block |
||
605 | 605 | * @param array $params Provide custom parameters |
606 | 606 | * @return string The URL for the logout flow |
607 | 607 | */ |
608 | - public function getLogoutUrl($params=array()) { |
|
608 | + public function getLogoutUrl($params = array()) { |
|
609 | 609 | return $this->getUrl( |
610 | 610 | 'www', |
611 | 611 | 'logout.php', |
@@ -627,7 +627,7 @@ discard block |
||
627 | 627 | * @param array $params Provide custom parameters |
628 | 628 | * @return string The URL for the logout flow |
629 | 629 | */ |
630 | - public function getLoginStatusUrl($params=array()) { |
|
630 | + public function getLoginStatusUrl($params = array()) { |
|
631 | 631 | return $this->getUrl( |
632 | 632 | 'www', |
633 | 633 | 'extern/login_status.php', |
@@ -937,7 +937,7 @@ discard block |
||
937 | 937 | * |
938 | 938 | * @return string The response text |
939 | 939 | */ |
940 | - protected function makeRequest($url, $params, $ch=null) { |
|
940 | + protected function makeRequest($url, $params, $ch = null) { |
|
941 | 941 | if (!$ch) { |
942 | 942 | $ch = curl_init(); |
943 | 943 | } |
@@ -967,7 +967,7 @@ discard block |
||
967 | 967 | self::errorLog('Invalid or no certificate authority found, '. |
968 | 968 | 'using bundled information'); |
969 | 969 | curl_setopt($ch, CURLOPT_CAINFO, |
970 | - dirname(__FILE__) . '/fb_ca_chain_bundle.crt'); |
|
970 | + dirname(__FILE__).'/fb_ca_chain_bundle.crt'); |
|
971 | 971 | $result = curl_exec($ch); |
972 | 972 | } |
973 | 973 | |
@@ -1020,7 +1020,7 @@ discard block |
||
1020 | 1020 | |
1021 | 1021 | if (strtoupper($data['algorithm']) !== self::SIGNED_REQUEST_ALGORITHM) { |
1022 | 1022 | self::errorLog( |
1023 | - 'Unknown algorithm. Expected ' . self::SIGNED_REQUEST_ALGORITHM); |
|
1023 | + 'Unknown algorithm. Expected '.self::SIGNED_REQUEST_ALGORITHM); |
|
1024 | 1024 | return null; |
1025 | 1025 | } |
1026 | 1026 | |
@@ -1044,7 +1044,7 @@ discard block |
||
1044 | 1044 | protected function makeSignedRequest($data) { |
1045 | 1045 | if (!is_array($data)) { |
1046 | 1046 | throw new InvalidArgumentException( |
1047 | - 'makeSignedRequest expects an array. Got: ' . print_r($data, true)); |
|
1047 | + 'makeSignedRequest expects an array. Got: '.print_r($data, true)); |
|
1048 | 1048 | } |
1049 | 1049 | $data['algorithm'] = self::SIGNED_REQUEST_ALGORITHM; |
1050 | 1050 | $data['issued_at'] = time(); |
@@ -1141,7 +1141,7 @@ discard block |
||
1141 | 1141 | * |
1142 | 1142 | * @return string The URL for the given parameters |
1143 | 1143 | */ |
1144 | - protected function getUrl($name, $path='', $params=array()) { |
|
1144 | + protected function getUrl($name, $path = '', $params = array()) { |
|
1145 | 1145 | $url = self::$DOMAIN_MAP[$name]; |
1146 | 1146 | if ($path) { |
1147 | 1147 | if ($path[0] === '/') { |
@@ -1150,7 +1150,7 @@ discard block |
||
1150 | 1150 | $url .= $path; |
1151 | 1151 | } |
1152 | 1152 | if ($params) { |
1153 | - $url .= '?' . http_build_query($params, null, '&'); |
|
1153 | + $url .= '?'.http_build_query($params, null, '&'); |
|
1154 | 1154 | } |
1155 | 1155 | |
1156 | 1156 | return $url; |
@@ -1206,7 +1206,7 @@ discard block |
||
1206 | 1206 | * @return string The current URL |
1207 | 1207 | */ |
1208 | 1208 | protected function getCurrentUrl() { |
1209 | - $protocol = $this->getHttpProtocol() . '://'; |
|
1209 | + $protocol = $this->getHttpProtocol().'://'; |
|
1210 | 1210 | $host = $this->getHttpHost(); |
1211 | 1211 | $currentUrl = $protocol.$host.$_SERVER['REQUEST_URI']; |
1212 | 1212 | $parts = parse_url($currentUrl); |
@@ -1232,10 +1232,10 @@ discard block |
||
1232 | 1232 | isset($parts['port']) && |
1233 | 1233 | (($protocol === 'http://' && $parts['port'] !== 80) || |
1234 | 1234 | ($protocol === 'https://' && $parts['port'] !== 443)) |
1235 | - ? ':' . $parts['port'] : ''; |
|
1235 | + ? ':'.$parts['port'] : ''; |
|
1236 | 1236 | |
1237 | 1237 | // rebuild |
1238 | - return $protocol . $parts['host'] . $port . $parts['path'] . $query; |
|
1238 | + return $protocol.$parts['host'].$port.$parts['path'].$query; |
|
1239 | 1239 | } |
1240 | 1240 | |
1241 | 1241 | /** |
@@ -361,8 +361,7 @@ |
||
361 | 361 | 'fb_exchange_token' => $this->getAccessToken(), |
362 | 362 | ) |
363 | 363 | ); |
364 | - } |
|
365 | - catch (FacebookApiException $e) { |
|
364 | + } catch (FacebookApiException $e) { |
|
366 | 365 | // most likely that user very recently revoked authorization. |
367 | 366 | // In any event, we don't have an access token, so say so. |
368 | 367 | return false; |
@@ -150,6 +150,9 @@ |
||
150 | 150 | return self::FBSS_COOKIE_NAME . '_' . $this->getAppId(); |
151 | 151 | } |
152 | 152 | |
153 | + /** |
|
154 | + * @param string $key |
|
155 | + */ |
|
153 | 156 | protected function constructSessionVariableName($key) { |
154 | 157 | $parts = array('fb', $this->getAppId(), $key); |
155 | 158 | if ($this->sharedSessionID) { |
@@ -45,52 +45,52 @@ discard block |
||
45 | 45 | * @see BaseFacebook::__construct in facebook.php |
46 | 46 | */ |
47 | 47 | public function __construct($config) { |
48 | - if (!session_id()) { |
|
49 | - session_start(); |
|
50 | - } |
|
51 | - parent::__construct($config); |
|
52 | - if (!empty($config['sharedSession'])) { |
|
53 | - $this->initSharedSession(); |
|
54 | - } |
|
48 | + if (!session_id()) { |
|
49 | + session_start(); |
|
50 | + } |
|
51 | + parent::__construct($config); |
|
52 | + if (!empty($config['sharedSession'])) { |
|
53 | + $this->initSharedSession(); |
|
54 | + } |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | protected static $kSupportedKeys = |
58 | - array('state', 'code', 'access_token', 'user_id'); |
|
58 | + array('state', 'code', 'access_token', 'user_id'); |
|
59 | 59 | |
60 | 60 | protected function initSharedSession() { |
61 | - $cookie_name = $this->getSharedSessionCookieName(); |
|
62 | - if (isset($_COOKIE[$cookie_name])) { |
|
63 | - $data = $this->parseSignedRequest($_COOKIE[$cookie_name]); |
|
64 | - if ($data && !empty($data['domain']) && |
|
65 | - self::isAllowedDomain($this->getHttpHost(), $data['domain'])) { |
|
66 | - // good case |
|
67 | - $this->sharedSessionID = $data['id']; |
|
68 | - return; |
|
69 | - } |
|
70 | - // ignoring potentially unreachable data |
|
71 | - } |
|
72 | - // evil/corrupt/missing case |
|
73 | - $base_domain = $this->getBaseDomain(); |
|
74 | - $this->sharedSessionID = md5(uniqid(mt_rand(), true)); |
|
75 | - $cookie_value = $this->makeSignedRequest( |
|
76 | - array( |
|
77 | - 'domain' => $base_domain, |
|
78 | - 'id' => $this->sharedSessionID, |
|
79 | - ) |
|
80 | - ); |
|
81 | - $_COOKIE[$cookie_name] = $cookie_value; |
|
82 | - if (!headers_sent()) { |
|
83 | - $expire = time() + self::FBSS_COOKIE_EXPIRE; |
|
84 | - setcookie($cookie_name, $cookie_value, $expire, '/', '.'.$base_domain); |
|
85 | - } else { |
|
86 | - // @codeCoverageIgnoreStart |
|
87 | - self::errorLog( |
|
88 | - 'Shared session ID cookie could not be set! You must ensure you '. |
|
89 | - 'create the Facebook instance before headers have been sent. This '. |
|
90 | - 'will cause authentication issues after the first request.' |
|
91 | - ); |
|
92 | - // @codeCoverageIgnoreEnd |
|
93 | - } |
|
61 | + $cookie_name = $this->getSharedSessionCookieName(); |
|
62 | + if (isset($_COOKIE[$cookie_name])) { |
|
63 | + $data = $this->parseSignedRequest($_COOKIE[$cookie_name]); |
|
64 | + if ($data && !empty($data['domain']) && |
|
65 | + self::isAllowedDomain($this->getHttpHost(), $data['domain'])) { |
|
66 | + // good case |
|
67 | + $this->sharedSessionID = $data['id']; |
|
68 | + return; |
|
69 | + } |
|
70 | + // ignoring potentially unreachable data |
|
71 | + } |
|
72 | + // evil/corrupt/missing case |
|
73 | + $base_domain = $this->getBaseDomain(); |
|
74 | + $this->sharedSessionID = md5(uniqid(mt_rand(), true)); |
|
75 | + $cookie_value = $this->makeSignedRequest( |
|
76 | + array( |
|
77 | + 'domain' => $base_domain, |
|
78 | + 'id' => $this->sharedSessionID, |
|
79 | + ) |
|
80 | + ); |
|
81 | + $_COOKIE[$cookie_name] = $cookie_value; |
|
82 | + if (!headers_sent()) { |
|
83 | + $expire = time() + self::FBSS_COOKIE_EXPIRE; |
|
84 | + setcookie($cookie_name, $cookie_value, $expire, '/', '.'.$base_domain); |
|
85 | + } else { |
|
86 | + // @codeCoverageIgnoreStart |
|
87 | + self::errorLog( |
|
88 | + 'Shared session ID cookie could not be set! You must ensure you '. |
|
89 | + 'create the Facebook instance before headers have been sent. This '. |
|
90 | + 'will cause authentication issues after the first request.' |
|
91 | + ); |
|
92 | + // @codeCoverageIgnoreEnd |
|
93 | + } |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -100,61 +100,61 @@ discard block |
||
100 | 100 | * access tokens. |
101 | 101 | */ |
102 | 102 | protected function setPersistentData($key, $value) { |
103 | - if (!in_array($key, self::$kSupportedKeys)) { |
|
104 | - self::errorLog('Unsupported key passed to setPersistentData.'); |
|
105 | - return; |
|
106 | - } |
|
103 | + if (!in_array($key, self::$kSupportedKeys)) { |
|
104 | + self::errorLog('Unsupported key passed to setPersistentData.'); |
|
105 | + return; |
|
106 | + } |
|
107 | 107 | |
108 | - $session_var_name = $this->constructSessionVariableName($key); |
|
109 | - $_SESSION[$session_var_name] = $value; |
|
108 | + $session_var_name = $this->constructSessionVariableName($key); |
|
109 | + $_SESSION[$session_var_name] = $value; |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | protected function getPersistentData($key, $default = false) { |
113 | - if (!in_array($key, self::$kSupportedKeys)) { |
|
114 | - self::errorLog('Unsupported key passed to getPersistentData.'); |
|
115 | - return $default; |
|
116 | - } |
|
117 | - |
|
118 | - $session_var_name = $this->constructSessionVariableName($key); |
|
119 | - return isset($_SESSION[$session_var_name]) ? |
|
120 | - $_SESSION[$session_var_name] : $default; |
|
113 | + if (!in_array($key, self::$kSupportedKeys)) { |
|
114 | + self::errorLog('Unsupported key passed to getPersistentData.'); |
|
115 | + return $default; |
|
116 | + } |
|
117 | + |
|
118 | + $session_var_name = $this->constructSessionVariableName($key); |
|
119 | + return isset($_SESSION[$session_var_name]) ? |
|
120 | + $_SESSION[$session_var_name] : $default; |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | protected function clearPersistentData($key) { |
124 | - if (!in_array($key, self::$kSupportedKeys)) { |
|
125 | - self::errorLog('Unsupported key passed to clearPersistentData.'); |
|
126 | - return; |
|
127 | - } |
|
124 | + if (!in_array($key, self::$kSupportedKeys)) { |
|
125 | + self::errorLog('Unsupported key passed to clearPersistentData.'); |
|
126 | + return; |
|
127 | + } |
|
128 | 128 | |
129 | - $session_var_name = $this->constructSessionVariableName($key); |
|
130 | - unset($_SESSION[$session_var_name]); |
|
129 | + $session_var_name = $this->constructSessionVariableName($key); |
|
130 | + unset($_SESSION[$session_var_name]); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | protected function clearAllPersistentData() { |
134 | - foreach (self::$kSupportedKeys as $key) { |
|
135 | - $this->clearPersistentData($key); |
|
136 | - } |
|
137 | - if ($this->sharedSessionID) { |
|
138 | - $this->deleteSharedSessionCookie(); |
|
139 | - } |
|
134 | + foreach (self::$kSupportedKeys as $key) { |
|
135 | + $this->clearPersistentData($key); |
|
136 | + } |
|
137 | + if ($this->sharedSessionID) { |
|
138 | + $this->deleteSharedSessionCookie(); |
|
139 | + } |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | protected function deleteSharedSessionCookie() { |
143 | - $cookie_name = $this->getSharedSessionCookieName(); |
|
144 | - unset($_COOKIE[$cookie_name]); |
|
145 | - $base_domain = $this->getBaseDomain(); |
|
146 | - setcookie($cookie_name, '', 1, '/', '.'.$base_domain); |
|
143 | + $cookie_name = $this->getSharedSessionCookieName(); |
|
144 | + unset($_COOKIE[$cookie_name]); |
|
145 | + $base_domain = $this->getBaseDomain(); |
|
146 | + setcookie($cookie_name, '', 1, '/', '.'.$base_domain); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | protected function getSharedSessionCookieName() { |
150 | - return self::FBSS_COOKIE_NAME . '_' . $this->getAppId(); |
|
150 | + return self::FBSS_COOKIE_NAME . '_' . $this->getAppId(); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | protected function constructSessionVariableName($key) { |
154 | - $parts = array('fb', $this->getAppId(), $key); |
|
155 | - if ($this->sharedSessionID) { |
|
156 | - array_unshift($parts, $this->sharedSessionID); |
|
157 | - } |
|
158 | - return implode('_', $parts); |
|
154 | + $parts = array('fb', $this->getAppId(), $key); |
|
155 | + if ($this->sharedSessionID) { |
|
156 | + array_unshift($parts, $this->sharedSessionID); |
|
157 | + } |
|
158 | + return implode('_', $parts); |
|
159 | 159 | } |
160 | 160 | } |
@@ -147,7 +147,7 @@ |
||
147 | 147 | } |
148 | 148 | |
149 | 149 | protected function getSharedSessionCookieName() { |
150 | - return self::FBSS_COOKIE_NAME . '_' . $this->getAppId(); |
|
150 | + return self::FBSS_COOKIE_NAME.'_'.$this->getAppId(); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | protected function constructSessionVariableName($key) { |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * @param string $sName name of the session |
38 | 38 | * @param int $iFlags flags |
39 | 39 | * @param int $iTimeout expiration of cache |
40 | - * @return mixed |
|
40 | + * @return boolean |
|
41 | 41 | */ |
42 | 42 | public function get(string $sName, int &$iFlags = null, int $iTimeout = 0) |
43 | 43 | { |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * @param mixed $mValue value of this sesion var |
53 | 53 | * @param int $iFlag unused |
54 | 54 | * @param int $iExpire expiration of cache |
55 | - * @return \Venus\lib\Cache\Apc |
|
55 | + * @return boolean |
|
56 | 56 | */ |
57 | 57 | public function set(string $sName, $mValue, int $iFlag = 0, int $iExpire = false) |
58 | 58 | { |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | * flush the cache |
64 | 64 | * |
65 | 65 | * @access public |
66 | - * @return mixed |
|
66 | + * @return boolean |
|
67 | 67 | */ |
68 | 68 | public function flush() |
69 | 69 | { |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * |
76 | 76 | * @access public |
77 | 77 | * @param string $sName name of the session |
78 | - * @return mixed |
|
78 | + * @return boolean |
|
79 | 79 | */ |
80 | 80 | public function delete(string $sName) |
81 | 81 | { |
@@ -88,9 +88,8 @@ discard block |
||
88 | 88 | * @access public |
89 | 89 | * @param string $sName name of the session |
90 | 90 | * @param mixed $mValue value of this sesion var |
91 | - * @param int $iFlag unused |
|
92 | 91 | * @param int $iExpire expiration of cache |
93 | - * @return mixed |
|
92 | + * @return boolean |
|
94 | 93 | */ |
95 | 94 | public function add($sName, $mValue, $iExpire = false) |
96 | 95 | { |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function get(string $sName, int &$iFlags = null, int $iTimeout = 0) |
43 | 43 | { |
44 | - return false; |
|
44 | + return false; |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | */ |
80 | 80 | public function delete(string $sName) |
81 | 81 | { |
82 | - return false; |
|
82 | + return false; |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -61,7 +61,7 @@ |
||
61 | 61 | * @param int $iTimeout expiration of cache |
62 | 62 | * @return mixed |
63 | 63 | */ |
64 | - public function get(string $sName, int &$iFlags = null, int $iTimeout = 0) |
|
64 | + public function get(string $sName, int&$iFlags = null, int $iTimeout = 0) |
|
65 | 65 | { |
66 | 66 | return parent::get($sName); |
67 | 67 | } |
@@ -192,8 +192,6 @@ |
||
192 | 192 | * set name of image |
193 | 193 | * |
194 | 194 | * @access public |
195 | - * @param int $iWeek number of week |
|
196 | - * @param int $iYear year |
|
197 | 195 | * @return array |
198 | 196 | */ |
199 | 197 | public static function getActualMiddleWeek() : array |
@@ -41,12 +41,12 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public static function getWeek(int $iWeek, int $iYear, string $sFormat = "Y-m-d") : Date |
43 | 43 | { |
44 | - $iFirstDayInYear = date("N",mktime(0, 0, 0, 1, 1, $iYear)); |
|
44 | + $iFirstDayInYear = date("N", mktime(0, 0, 0, 1, 1, $iYear)); |
|
45 | 45 | |
46 | 46 | if ($iFirstDayInYear < 5) { $iShift = -($iFirstDayInYear - 1) * 86400; } |
47 | 47 | else { $iShift = (8 - $iFirstDayInYear) * 86400; } |
48 | 48 | |
49 | - if ($iWeek > 1) { $iWeekInSeconds = ($iWeek-1) * 604800; } |
|
49 | + if ($iWeek > 1) { $iWeekInSeconds = ($iWeek - 1) * 604800; } |
|
50 | 50 | else { $iWeekInSeconds = 0; } |
51 | 51 | |
52 | 52 | $iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift; |
@@ -158,12 +158,12 @@ discard block |
||
158 | 158 | */ |
159 | 159 | public static function getMiddleWeek(int $iWeek, int $iYear, string $sFormat = "Y-m-d") : array |
160 | 160 | { |
161 | - $iFirstDayInYear = date("N",mktime(0, 0, 0, 1, 1, $iYear)); |
|
161 | + $iFirstDayInYear = date("N", mktime(0, 0, 0, 1, 1, $iYear)); |
|
162 | 162 | |
163 | 163 | if ($iFirstDayInYear < 5) { $iShift = -($iFirstDayInYear - 1) * 86400; } |
164 | 164 | else { $iShift = (8 - $iFirstDayInYear) * 86400; } |
165 | 165 | |
166 | - if ($iWeek > 1) { $iWeekInSeconds = ($iWeek-1) * 604800; } |
|
166 | + if ($iWeek > 1) { $iWeekInSeconds = ($iWeek - 1) * 604800; } |
|
167 | 167 | else { $iWeekInSeconds = 0; } |
168 | 168 | |
169 | 169 | if (date('N') > 2) { |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | if (preg_replace('/^([0-9]+)-[0-9]+-[0-9]+$/', '$1', $aDates[0]) != date('Y')) { |
183 | 183 | |
184 | 184 | $aDates[0] = preg_replace('/^[0-9]+(-[0-9]+-[0-9]+)$/', date('Y').'$1', $aDates[0]); |
185 | - $aDates[1] = preg_replace('/^[0-9]+(-[0-9]+-[0-9]+)$/', (date('Y')+1).'$1', $aDates[1]); |
|
185 | + $aDates[1] = preg_replace('/^[0-9]+(-[0-9]+-[0-9]+)$/', (date('Y') + 1).'$1', $aDates[1]); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | return $aDates; |
@@ -225,10 +225,10 @@ discard block |
||
225 | 225 | $oDateTime = DateTime::createFromFormat('Y-m-d H:i:s', $sDateTime); |
226 | 226 | $iTimeStamp = time() - $oDateTime->getTimestamp(); |
227 | 227 | |
228 | - if ($iTimeStamp < 3600) { return $sStartReturn.' '.(int)($iTimeStamp/60).' '.$sMinutes.$sEndReturn; } |
|
229 | - if ($iTimeStamp < 86400) { return $sStartReturn.' '.(int)($iTimeStamp/3600).' '.$sHours.$sEndReturn; } |
|
230 | - if ($iTimeStamp < 2592000) { return $sStartReturn.' '.(int)($iTimeStamp/86400).' '.$sDays.$sEndReturn; } |
|
231 | - if ($iTimeStamp < 31536000) { return $sStartReturn.' '.(int)($iTimeStamp/2592000).' '.$sMonths.$sEndReturn; } |
|
232 | - else { return $sStartReturn.' '.(int)($iTimeStamp/31536000).' '.$sYears.$sEndReturn; } |
|
228 | + if ($iTimeStamp < 3600) { return $sStartReturn.' '.(int)($iTimeStamp / 60).' '.$sMinutes.$sEndReturn; } |
|
229 | + if ($iTimeStamp < 86400) { return $sStartReturn.' '.(int)($iTimeStamp / 3600).' '.$sHours.$sEndReturn; } |
|
230 | + if ($iTimeStamp < 2592000) { return $sStartReturn.' '.(int)($iTimeStamp / 86400).' '.$sDays.$sEndReturn; } |
|
231 | + if ($iTimeStamp < 31536000) { return $sStartReturn.' '.(int)($iTimeStamp / 2592000).' '.$sMonths.$sEndReturn; } |
|
232 | + else { return $sStartReturn.' '.(int)($iTimeStamp / 31536000).' '.$sYears.$sEndReturn; } |
|
233 | 233 | } |
234 | 234 | } |
@@ -43,11 +43,9 @@ discard block |
||
43 | 43 | { |
44 | 44 | $iFirstDayInYear = date("N",mktime(0, 0, 0, 1, 1, $iYear)); |
45 | 45 | |
46 | - if ($iFirstDayInYear < 5) { $iShift = -($iFirstDayInYear - 1) * 86400; } |
|
47 | - else { $iShift = (8 - $iFirstDayInYear) * 86400; } |
|
46 | + if ($iFirstDayInYear < 5) { $iShift = -($iFirstDayInYear - 1) * 86400; } else { $iShift = (8 - $iFirstDayInYear) * 86400; } |
|
48 | 47 | |
49 | - if ($iWeek > 1) { $iWeekInSeconds = ($iWeek-1) * 604800; } |
|
50 | - else { $iWeekInSeconds = 0; } |
|
48 | + if ($iWeek > 1) { $iWeekInSeconds = ($iWeek-1) * 604800; } else { $iWeekInSeconds = 0; } |
|
51 | 49 | |
52 | 50 | $iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift; |
53 | 51 | $iTimestampLastDay = mktime(0, 0, 0, 1, 6, $iYear) + $iWeekInSeconds + $iShift + 604800; |
@@ -78,18 +76,7 @@ discard block |
||
78 | 76 | { |
79 | 77 | if ($sLanguage == 'fr') { |
80 | 78 | |
81 | - if ($sMonth == '01' || $sMonth == 1) { return 'Janvier'; } |
|
82 | - else if ($sMonth == '02' || $sMonth == 2) { return 'Février'; } |
|
83 | - else if ($sMonth == '03' || $sMonth == 3) { return 'Mars'; } |
|
84 | - else if ($sMonth == '04' || $sMonth == 4) { return 'Avril'; } |
|
85 | - else if ($sMonth == '05' || $sMonth == 5) { return 'Mai'; } |
|
86 | - else if ($sMonth == '06' || $sMonth == 6) { return 'Juin'; } |
|
87 | - else if ($sMonth == '07' || $sMonth == 7) { return 'Juillet'; } |
|
88 | - else if ($sMonth == '08' || $sMonth == 8) { return 'Août'; } |
|
89 | - else if ($sMonth == '09' || $sMonth == 9) { return 'Septembre'; } |
|
90 | - else if ($sMonth == 10) { return 'Octobre'; } |
|
91 | - else if ($sMonth == 11) { return 'Novembre'; } |
|
92 | - else if ($sMonth == 12) { return 'Décembre'; } |
|
79 | + if ($sMonth == '01' || $sMonth == 1) { return 'Janvier'; } else if ($sMonth == '02' || $sMonth == 2) { return 'Février'; } else if ($sMonth == '03' || $sMonth == 3) { return 'Mars'; } else if ($sMonth == '04' || $sMonth == 4) { return 'Avril'; } else if ($sMonth == '05' || $sMonth == 5) { return 'Mai'; } else if ($sMonth == '06' || $sMonth == 6) { return 'Juin'; } else if ($sMonth == '07' || $sMonth == 7) { return 'Juillet'; } else if ($sMonth == '08' || $sMonth == 8) { return 'Août'; } else if ($sMonth == '09' || $sMonth == 9) { return 'Septembre'; } else if ($sMonth == 10) { return 'Octobre'; } else if ($sMonth == 11) { return 'Novembre'; } else if ($sMonth == 12) { return 'Décembre'; } |
|
93 | 80 | } |
94 | 81 | } |
95 | 82 | |
@@ -105,13 +92,7 @@ discard block |
||
105 | 92 | { |
106 | 93 | if ($sLanguage == 'fr') { |
107 | 94 | |
108 | - if ($sDay == 0) { return 'dimanche'; } |
|
109 | - else if ($sDay == 1) { return 'lundi'; } |
|
110 | - else if ($sDay == 2) { return 'mardi'; } |
|
111 | - else if ($sDay == 3) { return 'mercredi'; } |
|
112 | - else if ($sDay == 4) { return 'jeudi'; } |
|
113 | - else if ($sDay == 5) { return 'vendredi'; } |
|
114 | - else if ($sDay == 6) { return 'samedi'; } |
|
95 | + if ($sDay == 0) { return 'dimanche'; } else if ($sDay == 1) { return 'lundi'; } else if ($sDay == 2) { return 'mardi'; } else if ($sDay == 3) { return 'mercredi'; } else if ($sDay == 4) { return 'jeudi'; } else if ($sDay == 5) { return 'vendredi'; } else if ($sDay == 6) { return 'samedi'; } |
|
115 | 96 | } |
116 | 97 | } |
117 | 98 | |
@@ -138,8 +119,7 @@ discard block |
||
138 | 119 | if ($iMonth == $aToday['mois']) { |
139 | 120 | |
140 | 121 | if ($iDay > $aToday['jour']) { $iYears--; } |
141 | - } |
|
142 | - else { |
|
122 | + } else { |
|
143 | 123 | |
144 | 124 | $iYears--; |
145 | 125 | } |
@@ -160,18 +140,15 @@ discard block |
||
160 | 140 | { |
161 | 141 | $iFirstDayInYear = date("N",mktime(0, 0, 0, 1, 1, $iYear)); |
162 | 142 | |
163 | - if ($iFirstDayInYear < 5) { $iShift = -($iFirstDayInYear - 1) * 86400; } |
|
164 | - else { $iShift = (8 - $iFirstDayInYear) * 86400; } |
|
143 | + if ($iFirstDayInYear < 5) { $iShift = -($iFirstDayInYear - 1) * 86400; } else { $iShift = (8 - $iFirstDayInYear) * 86400; } |
|
165 | 144 | |
166 | - if ($iWeek > 1) { $iWeekInSeconds = ($iWeek-1) * 604800; } |
|
167 | - else { $iWeekInSeconds = 0; } |
|
145 | + if ($iWeek > 1) { $iWeekInSeconds = ($iWeek-1) * 604800; } else { $iWeekInSeconds = 0; } |
|
168 | 146 | |
169 | 147 | if (date('N') > 2) { |
170 | 148 | |
171 | 149 | $iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift + 172800; |
172 | 150 | $iTimestampLastDay = $iTimestamp + 604800; |
173 | - } |
|
174 | - else { |
|
151 | + } else { |
|
175 | 152 | |
176 | 153 | $iTimestamp = mktime(0, 0, 0, 1, 1, $iYear) + $iWeekInSeconds + $iShift - 432000; |
177 | 154 | $iTimestampLastDay = $iTimestamp + 604800; |
@@ -228,7 +205,6 @@ discard block |
||
228 | 205 | if ($iTimeStamp < 3600) { return $sStartReturn.' '.(int)($iTimeStamp/60).' '.$sMinutes.$sEndReturn; } |
229 | 206 | if ($iTimeStamp < 86400) { return $sStartReturn.' '.(int)($iTimeStamp/3600).' '.$sHours.$sEndReturn; } |
230 | 207 | if ($iTimeStamp < 2592000) { return $sStartReturn.' '.(int)($iTimeStamp/86400).' '.$sDays.$sEndReturn; } |
231 | - if ($iTimeStamp < 31536000) { return $sStartReturn.' '.(int)($iTimeStamp/2592000).' '.$sMonths.$sEndReturn; } |
|
232 | - else { return $sStartReturn.' '.(int)($iTimeStamp/31536000).' '.$sYears.$sEndReturn; } |
|
208 | + if ($iTimeStamp < 31536000) { return $sStartReturn.' '.(int)($iTimeStamp/2592000).' '.$sMonths.$sEndReturn; } else { return $sStartReturn.' '.(int)($iTimeStamp/31536000).' '.$sYears.$sEndReturn; } |
|
233 | 209 | } |
234 | 210 | } |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | * get global object form |
305 | 305 | * |
306 | 306 | * @access public |
307 | - * @return object |
|
307 | + * @return \stdClass |
|
308 | 308 | */ |
309 | 309 | public function getFormInObject() |
310 | 310 | { |
@@ -411,7 +411,6 @@ discard block |
||
411 | 411 | * set the entity to synchronize with the formular |
412 | 412 | * |
413 | 413 | * @access public |
414 | - * @param string $sSeparator separator between the fields |
|
415 | 414 | * @param int $iId id of the primary key |
416 | 415 | * @return \Venus\lib\Form |
417 | 416 | */ |
@@ -141,14 +141,14 @@ discard block |
||
141 | 141 | */ |
142 | 142 | public function add($sName, $mType, $sLabel = null, $mValue = null, $mOptions = null) |
143 | 143 | { |
144 | - if ($mType instanceof Container) { |
|
144 | + if ($mType instanceof Container) { |
|
145 | 145 | |
146 | - $this->_aElement[$sName] = $mType; |
|
147 | - } |
|
146 | + $this->_aElement[$sName] = $mType; |
|
147 | + } |
|
148 | 148 | else if ($mType === 'text' || $mType === 'submit' || $mType === 'password' || $mType === 'file' || $mType === 'tel' |
149 | - || $mType === 'url' || $mType === 'email' || $mType === 'search' || $mType === 'date' || $mType === 'time' |
|
150 | - || $mType === 'datetime' || $mType === 'month' || $mType === 'week' || $mType === 'number' || $mType === 'range' |
|
151 | - || $mType === 'color') { |
|
149 | + || $mType === 'url' || $mType === 'email' || $mType === 'search' || $mType === 'date' || $mType === 'time' |
|
150 | + || $mType === 'datetime' || $mType === 'month' || $mType === 'week' || $mType === 'number' || $mType === 'range' |
|
151 | + || $mType === 'color') { |
|
152 | 152 | |
153 | 153 | $this->_aElement[$sName] = new Input($sName, $mType, $sLabel, $mValue); |
154 | 154 | } |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | |
295 | 295 | $oContainer = new Container; |
296 | 296 | $oContainer->setView($sFormContent) |
297 | - ->setForm($this); |
|
297 | + ->setForm($this); |
|
298 | 298 | |
299 | 299 | return $oContainer; |
300 | 300 | } |
@@ -308,67 +308,67 @@ discard block |
||
308 | 308 | */ |
309 | 309 | public function getFormInObject() |
310 | 310 | { |
311 | - if ($this->_iIdEntity > 0 && $this->_sSynchronizeEntity !== null && count($_POST) < 1) { |
|
311 | + if ($this->_iIdEntity > 0 && $this->_sSynchronizeEntity !== null && count($_POST) < 1) { |
|
312 | 312 | |
313 | - $sModelName = str_replace('Entity', 'Model', $this->_sSynchronizeEntity); |
|
314 | - $oModel = new $sModelName; |
|
313 | + $sModelName = str_replace('Entity', 'Model', $this->_sSynchronizeEntity); |
|
314 | + $oModel = new $sModelName; |
|
315 | 315 | |
316 | - $oEntity = new $this->_sSynchronizeEntity; |
|
317 | - $sPrimaryKey = LibEntity::getPrimaryKeyNameWithoutMapping($oEntity); |
|
318 | - $sMethodName = 'findOneBy'.$sPrimaryKey; |
|
319 | - $oCompleteEntity = call_user_func_array(array(&$oModel, $sMethodName), array($this->_iIdEntity)); |
|
316 | + $oEntity = new $this->_sSynchronizeEntity; |
|
317 | + $sPrimaryKey = LibEntity::getPrimaryKeyNameWithoutMapping($oEntity); |
|
318 | + $sMethodName = 'findOneBy'.$sPrimaryKey; |
|
319 | + $oCompleteEntity = call_user_func_array(array(&$oModel, $sMethodName), array($this->_iIdEntity)); |
|
320 | 320 | |
321 | - if (is_object($oCompleteEntity)) { |
|
321 | + if (is_object($oCompleteEntity)) { |
|
322 | 322 | |
323 | - foreach ($this->_aElement as $sKey => $sValue) { |
|
323 | + foreach ($this->_aElement as $sKey => $sValue) { |
|
324 | 324 | |
325 | - if ($sValue instanceof \Venus\lib\Form\Radio) { |
|
325 | + if ($sValue instanceof \Venus\lib\Form\Radio) { |
|
326 | 326 | |
327 | - $sExKey = $sKey; |
|
328 | - $sKey = substr($sKey, 0, -6); |
|
329 | - } |
|
327 | + $sExKey = $sKey; |
|
328 | + $sKey = substr($sKey, 0, -6); |
|
329 | + } |
|
330 | 330 | |
331 | - if ($sValue instanceof Form) { |
|
331 | + if ($sValue instanceof Form) { |
|
332 | 332 | |
333 | - ; |
|
334 | - } |
|
335 | - else { |
|
333 | + ; |
|
334 | + } |
|
335 | + else { |
|
336 | 336 | |
337 | - $sMethodNameInEntity = 'get_'.$sKey; |
|
338 | - $mValue = $oCompleteEntity->$sMethodNameInEntity(); |
|
337 | + $sMethodNameInEntity = 'get_'.$sKey; |
|
338 | + $mValue = $oCompleteEntity->$sMethodNameInEntity(); |
|
339 | 339 | |
340 | - if ($sValue instanceof \Venus\lib\Form\Radio && method_exists($this->_aElement[$sExKey], 'setValueChecked')) { |
|
340 | + if ($sValue instanceof \Venus\lib\Form\Radio && method_exists($this->_aElement[$sExKey], 'setValueChecked')) { |
|
341 | 341 | |
342 | - $this->_aElement[$sExKey]->setValueChecked($mValue); |
|
343 | - } |
|
344 | - else if (isset($mValue) && method_exists($this->_aElement[$sKey], 'setValue')) { |
|
342 | + $this->_aElement[$sExKey]->setValueChecked($mValue); |
|
343 | + } |
|
344 | + else if (isset($mValue) && method_exists($this->_aElement[$sKey], 'setValue')) { |
|
345 | 345 | |
346 | - $this->_aElement[$sKey]->setValue($mValue); |
|
347 | - } |
|
348 | - } |
|
349 | - } |
|
350 | - } |
|
351 | - } |
|
346 | + $this->_aElement[$sKey]->setValue($mValue); |
|
347 | + } |
|
348 | + } |
|
349 | + } |
|
350 | + } |
|
351 | + } |
|
352 | 352 | |
353 | - $oForm = new \StdClass(); |
|
354 | - $oForm->start = '<form name="form'.$this->_iFormNumber.'" method="post"><input type="hidden" value="1" name="validform'.$this->_iFormNumber.'">'; |
|
355 | - $oForm->form = array(); |
|
353 | + $oForm = new \StdClass(); |
|
354 | + $oForm->start = '<form name="form'.$this->_iFormNumber.'" method="post"><input type="hidden" value="1" name="validform'.$this->_iFormNumber.'">'; |
|
355 | + $oForm->form = array(); |
|
356 | 356 | |
357 | - foreach ($this->_aElement as $sKey => $sValue) { |
|
357 | + foreach ($this->_aElement as $sKey => $sValue) { |
|
358 | 358 | |
359 | - if ($sValue instanceof Container) { |
|
359 | + if ($sValue instanceof Container) { |
|
360 | 360 | |
361 | - $oForm->form[$sKey] = $sValue; |
|
362 | - } |
|
363 | - else { |
|
361 | + $oForm->form[$sKey] = $sValue; |
|
362 | + } |
|
363 | + else { |
|
364 | 364 | |
365 | - $oForm->form[$sKey] = $sValue->fetch(); |
|
366 | - } |
|
367 | - } |
|
365 | + $oForm->form[$sKey] = $sValue->fetch(); |
|
366 | + } |
|
367 | + } |
|
368 | 368 | |
369 | - $oForm->end = '</form>'; |
|
369 | + $oForm->end = '</form>'; |
|
370 | 370 | |
371 | - return $oForm; |
|
371 | + return $oForm; |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | /** |
@@ -449,7 +449,7 @@ discard block |
||
449 | 449 | */ |
450 | 450 | public function getElement() { |
451 | 451 | |
452 | - return $this->_aElement; |
|
452 | + return $this->_aElement; |
|
453 | 453 | } |
454 | 454 | |
455 | 455 | /** |
@@ -460,7 +460,7 @@ discard block |
||
460 | 460 | */ |
461 | 461 | public function getIdEntity() { |
462 | 462 | |
463 | - return $this->_iIdEntity; |
|
463 | + return $this->_iIdEntity; |
|
464 | 464 | } |
465 | 465 | |
466 | 466 | /** |
@@ -471,6 +471,6 @@ discard block |
||
471 | 471 | */ |
472 | 472 | public function getSynchronizeEntity() { |
473 | 473 | |
474 | - return $this->_sSynchronizeEntity; |
|
474 | + return $this->_sSynchronizeEntity; |
|
475 | 475 | } |
476 | 476 | } |
@@ -181,13 +181,13 @@ discard block |
||
181 | 181 | } |
182 | 182 | else if ($mType === 'radio') { |
183 | 183 | |
184 | - $this->_aElement[$sName.rand(100000,999999)] = new Radio($sName, $sLabel, $mValue, $mOptions); |
|
184 | + $this->_aElement[$sName.rand(100000, 999999)] = new Radio($sName, $sLabel, $mValue, $mOptions); |
|
185 | 185 | } |
186 | 186 | else if ($mType === 'date') { |
187 | 187 | |
188 | 188 | $aDay = array(); |
189 | 189 | |
190 | - for ($i = 1 ; $i <= 31 ; $i++) { |
|
190 | + for ($i = 1; $i <= 31; $i++) { |
|
191 | 191 | |
192 | 192 | if ($i < 10) { $aDay['0'.$i] = '0'.$i; } |
193 | 193 | else { $aDay[$i] = $i; } |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | |
215 | 215 | $aYear = array(); |
216 | 216 | |
217 | - for ($i = 1900 ; $i <= 2013 ; $i++) { |
|
217 | + for ($i = 1900; $i <= 2013; $i++) { |
|
218 | 218 | |
219 | 219 | $aYear[$i] = $i; |
220 | 220 | } |
@@ -144,27 +144,22 @@ discard block |
||
144 | 144 | if ($mType instanceof Container) { |
145 | 145 | |
146 | 146 | $this->_aElement[$sName] = $mType; |
147 | - } |
|
148 | - else if ($mType === 'text' || $mType === 'submit' || $mType === 'password' || $mType === 'file' || $mType === 'tel' |
|
147 | + } else if ($mType === 'text' || $mType === 'submit' || $mType === 'password' || $mType === 'file' || $mType === 'tel' |
|
149 | 148 | || $mType === 'url' || $mType === 'email' || $mType === 'search' || $mType === 'date' || $mType === 'time' |
150 | 149 | || $mType === 'datetime' || $mType === 'month' || $mType === 'week' || $mType === 'number' || $mType === 'range' |
151 | 150 | || $mType === 'color') { |
152 | 151 | |
153 | 152 | $this->_aElement[$sName] = new Input($sName, $mType, $sLabel, $mValue); |
154 | - } |
|
155 | - elseif ($mType === 'textarea') { |
|
153 | + } elseif ($mType === 'textarea') { |
|
156 | 154 | |
157 | 155 | $this->_aElement[$sName] = new Textarea($sName, $sLabel, $mValue); |
158 | - } |
|
159 | - else if ($mType === 'select') { |
|
156 | + } else if ($mType === 'select') { |
|
160 | 157 | |
161 | 158 | $this->_aElement[$sName] = new Select($sName, $mOptions, $sLabel, $mValue); |
162 | - } |
|
163 | - else if ($mType === 'label') { |
|
159 | + } else if ($mType === 'label') { |
|
164 | 160 | |
165 | 161 | $this->_aElement[$sName] = new Label($sName); |
166 | - } |
|
167 | - else if ($mType === 'list_checkbox') { |
|
162 | + } else if ($mType === 'list_checkbox') { |
|
168 | 163 | |
169 | 164 | $i = 0; |
170 | 165 | |
@@ -174,23 +169,19 @@ discard block |
||
174 | 169 | |
175 | 170 | $this->_aElement[$sName.'_'.$i++] = new Checkbox($sName, $sValue, $mKey, $mOptions); |
176 | 171 | } |
177 | - } |
|
178 | - else if ($mType === 'checkbox') { |
|
172 | + } else if ($mType === 'checkbox') { |
|
179 | 173 | |
180 | 174 | $this->_aElement[$sName] = new Checkbox($sName, $sLabel, $mValue, $mOptions); |
181 | - } |
|
182 | - else if ($mType === 'radio') { |
|
175 | + } else if ($mType === 'radio') { |
|
183 | 176 | |
184 | 177 | $this->_aElement[$sName.rand(100000,999999)] = new Radio($sName, $sLabel, $mValue, $mOptions); |
185 | - } |
|
186 | - else if ($mType === 'date') { |
|
178 | + } else if ($mType === 'date') { |
|
187 | 179 | |
188 | 180 | $aDay = array(); |
189 | 181 | |
190 | 182 | for ($i = 1 ; $i <= 31 ; $i++) { |
191 | 183 | |
192 | - if ($i < 10) { $aDay['0'.$i] = '0'.$i; } |
|
193 | - else { $aDay[$i] = $i; } |
|
184 | + if ($i < 10) { $aDay['0'.$i] = '0'.$i; } else { $aDay[$i] = $i; } |
|
194 | 185 | } |
195 | 186 | |
196 | 187 | $this->_aElement[$sName.'_day'] = new Select($sName, $aDay); |
@@ -331,8 +322,7 @@ discard block |
||
331 | 322 | if ($sValue instanceof Form) { |
332 | 323 | |
333 | 324 | ; |
334 | - } |
|
335 | - else { |
|
325 | + } else { |
|
336 | 326 | |
337 | 327 | $sMethodNameInEntity = 'get_'.$sKey; |
338 | 328 | $mValue = $oCompleteEntity->$sMethodNameInEntity(); |
@@ -340,8 +330,7 @@ discard block |
||
340 | 330 | if ($sValue instanceof \Venus\lib\Form\Radio && method_exists($this->_aElement[$sExKey], 'setValueChecked')) { |
341 | 331 | |
342 | 332 | $this->_aElement[$sExKey]->setValueChecked($mValue); |
343 | - } |
|
344 | - else if (isset($mValue) && method_exists($this->_aElement[$sKey], 'setValue')) { |
|
333 | + } else if (isset($mValue) && method_exists($this->_aElement[$sKey], 'setValue')) { |
|
345 | 334 | |
346 | 335 | $this->_aElement[$sKey]->setValue($mValue); |
347 | 336 | } |
@@ -359,8 +348,7 @@ discard block |
||
359 | 348 | if ($sValue instanceof Container) { |
360 | 349 | |
361 | 350 | $oForm->form[$sKey] = $sValue; |
362 | - } |
|
363 | - else { |
|
351 | + } else { |
|
364 | 352 | |
365 | 353 | $oForm->form[$sKey] = $sValue->fetch(); |
366 | 354 | } |
@@ -69,7 +69,7 @@ |
||
69 | 69 | * get the Value |
70 | 70 | * |
71 | 71 | * @access public |
72 | - * @return object |
|
72 | + * @return \stdClass |
|
73 | 73 | */ |
74 | 74 | public function createView() |
75 | 75 | { |
@@ -73,24 +73,24 @@ discard block |
||
73 | 73 | */ |
74 | 74 | public function createView() |
75 | 75 | { |
76 | - $oView = new \stdClass; |
|
77 | - $oView->form = $this->_sView; |
|
78 | - $oView->form_start = $this->_oForm->getFormInObject()->start; |
|
79 | - $oView->form_end = $this->_oForm->getFormInObject()->end; |
|
80 | - $oView->form_row = array(); |
|
76 | + $oView = new \stdClass; |
|
77 | + $oView->form = $this->_sView; |
|
78 | + $oView->form_start = $this->_oForm->getFormInObject()->start; |
|
79 | + $oView->form_end = $this->_oForm->getFormInObject()->end; |
|
80 | + $oView->form_row = array(); |
|
81 | 81 | |
82 | - foreach ($this->_oForm->getFormInObject()->form as $sKey => $mValue) { |
|
82 | + foreach ($this->_oForm->getFormInObject()->form as $sKey => $mValue) { |
|
83 | 83 | |
84 | - if ($mValue instanceof Container) { |
|
84 | + if ($mValue instanceof Container) { |
|
85 | 85 | |
86 | - $oNewForm = $mValue->createView(); |
|
87 | - $oView->form_row[$sKey] = $oNewForm->form_row; |
|
88 | - } |
|
89 | - else { |
|
86 | + $oNewForm = $mValue->createView(); |
|
87 | + $oView->form_row[$sKey] = $oNewForm->form_row; |
|
88 | + } |
|
89 | + else { |
|
90 | 90 | |
91 | - $oView->form_row[$sKey] = $mValue; |
|
92 | - } |
|
93 | - } |
|
91 | + $oView->form_row[$sKey] = $mValue; |
|
92 | + } |
|
93 | + } |
|
94 | 94 | |
95 | 95 | return $oView; |
96 | 96 | } |
@@ -117,48 +117,48 @@ discard block |
||
117 | 117 | */ |
118 | 118 | public function handleRequest(array $aRequest) : bool |
119 | 119 | { |
120 | - if (!count($_POST)) { return true; } |
|
120 | + if (!count($_POST)) { return true; } |
|
121 | 121 | |
122 | - // Validation |
|
123 | - foreach ($this->_oForm->getElement() as $sKey => $sValue) { |
|
122 | + // Validation |
|
123 | + foreach ($this->_oForm->getElement() as $sKey => $sValue) { |
|
124 | 124 | |
125 | - if (!$sValue instanceof self && !$this->_validate($sValue)) { |
|
125 | + if (!$sValue instanceof self && !$this->_validate($sValue)) { |
|
126 | 126 | |
127 | - return false; |
|
128 | - } |
|
129 | - } |
|
127 | + return false; |
|
128 | + } |
|
129 | + } |
|
130 | 130 | |
131 | - // Save |
|
131 | + // Save |
|
132 | 132 | if ($this->_oForm->getIdEntity() > 0 && $this->_oForm->getSynchronizeEntity() !== null && count($aRequest) > 0) { |
133 | 133 | |
134 | - $sModelName = str_replace('Entity', 'Model', $this->_oForm->getSynchronizeEntity()); |
|
135 | - $oModel = new $sModelName; |
|
134 | + $sModelName = str_replace('Entity', 'Model', $this->_oForm->getSynchronizeEntity()); |
|
135 | + $oModel = new $sModelName; |
|
136 | 136 | |
137 | - $oEntity = new $this->_oForm->getSynchronizeEntity(); |
|
138 | - $sPrimaryKey = LibEntity::getPrimaryKeyNameWithoutMapping($oEntity); |
|
139 | - $sMethodName = 'set_'.$sPrimaryKey; |
|
137 | + $oEntity = new $this->_oForm->getSynchronizeEntity(); |
|
138 | + $sPrimaryKey = LibEntity::getPrimaryKeyNameWithoutMapping($oEntity); |
|
139 | + $sMethodName = 'set_'.$sPrimaryKey; |
|
140 | 140 | |
141 | - call_user_func_array(array(&$oEntity, $sMethodName), array($this->_oForm->getIdEntity())); |
|
141 | + call_user_func_array(array(&$oEntity, $sMethodName), array($this->_oForm->getIdEntity())); |
|
142 | 142 | |
143 | - foreach ($this->_oForm->getElement() as $sKey => $sValue) { |
|
143 | + foreach ($this->_oForm->getElement() as $sKey => $sValue) { |
|
144 | 144 | |
145 | - $sMethodName = 'set_'.$sValue->getName().''; |
|
146 | - call_user_func_array(array(&$oEntity, $sMethodName), array($aRequest[$sValue->getName()])); |
|
147 | - } |
|
145 | + $sMethodName = 'set_'.$sValue->getName().''; |
|
146 | + call_user_func_array(array(&$oEntity, $sMethodName), array($aRequest[$sValue->getName()])); |
|
147 | + } |
|
148 | 148 | |
149 | - $oEntity->save(); |
|
149 | + $oEntity->save(); |
|
150 | 150 | } |
151 | 151 | else if ($this->_oForm->getSynchronizeEntity() !== null && isset($aRequest) && count($aRequest) > 0) { |
152 | 152 | |
153 | - $oEntity = new $this->_oForm->_sSynchronizeEntity; |
|
153 | + $oEntity = new $this->_oForm->_sSynchronizeEntity; |
|
154 | 154 | |
155 | - foreach ($this->_oForm->getElement() as $sKey => $sValue) { |
|
155 | + foreach ($this->_oForm->getElement() as $sKey => $sValue) { |
|
156 | 156 | |
157 | - $sMethodName = 'set_'.$sValue->getName().''; |
|
158 | - call_user_func_array(array(&$oEntity, $sMethodName), array($aRequest[$sValue->getName()])); |
|
159 | - } |
|
157 | + $sMethodName = 'set_'.$sValue->getName().''; |
|
158 | + call_user_func_array(array(&$oEntity, $sMethodName), array($aRequest[$sValue->getName()])); |
|
159 | + } |
|
160 | 160 | |
161 | - $this->_oForm->setIdEntityCreated($oEntity->save()); |
|
161 | + $this->_oForm->setIdEntityCreated($oEntity->save()); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | $this->_bHandleRequestActivate = true; |
@@ -199,13 +199,13 @@ discard block |
||
199 | 199 | */ |
200 | 200 | public function isSubmitted() : bool |
201 | 201 | { |
202 | - if (isset($_POST['validform'.$this->_oForm->getFormNumber()]) && $_POST['validform'.$this->_oForm->getFormNumber()] == 1) { |
|
202 | + if (isset($_POST['validform'.$this->_oForm->getFormNumber()]) && $_POST['validform'.$this->_oForm->getFormNumber()] == 1) { |
|
203 | 203 | |
204 | - return true; |
|
205 | - } |
|
204 | + return true; |
|
205 | + } |
|
206 | 206 | else { |
207 | 207 | |
208 | - return false; |
|
208 | + return false; |
|
209 | 209 | } |
210 | 210 | } |
211 | 211 | |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | */ |
219 | 219 | public function isClicked(string $sElementName) : bool |
220 | 220 | { |
221 | - if (isset($_POST[$sElementName]) && $_POST[$sElementName]) { return true; } |
|
221 | + if (isset($_POST[$sElementName]) && $_POST[$sElementName]) { return true; } |
|
222 | 222 | else { return false; } |
223 | 223 | } |
224 | 224 | |
@@ -231,14 +231,14 @@ discard block |
||
231 | 231 | */ |
232 | 232 | private function _validate($oElement) : bool |
233 | 233 | { |
234 | - foreach ($oElement->getConstraint() as $oConstraint) { |
|
234 | + foreach ($oElement->getConstraint() as $oConstraint) { |
|
235 | 235 | |
236 | - if (!$oConstraint->validate($_POST[$oElement->getName()])) { |
|
236 | + if (!$oConstraint->validate($_POST[$oElement->getName()])) { |
|
237 | 237 | |
238 | - return false; |
|
239 | - } |
|
240 | - } |
|
238 | + return false; |
|
239 | + } |
|
240 | + } |
|
241 | 241 | |
242 | - return true; |
|
242 | + return true; |
|
243 | 243 | } |
244 | 244 | } |
@@ -85,8 +85,7 @@ discard block |
||
85 | 85 | |
86 | 86 | $oNewForm = $mValue->createView(); |
87 | 87 | $oView->form_row[$sKey] = $oNewForm->form_row; |
88 | - } |
|
89 | - else { |
|
88 | + } else { |
|
90 | 89 | |
91 | 90 | $oView->form_row[$sKey] = $mValue; |
92 | 91 | } |
@@ -147,8 +146,7 @@ discard block |
||
147 | 146 | } |
148 | 147 | |
149 | 148 | $oEntity->save(); |
150 | - } |
|
151 | - else if ($this->_oForm->getSynchronizeEntity() !== null && isset($aRequest) && count($aRequest) > 0) { |
|
149 | + } else if ($this->_oForm->getSynchronizeEntity() !== null && isset($aRequest) && count($aRequest) > 0) { |
|
152 | 150 | |
153 | 151 | $oEntity = new $this->_oForm->_sSynchronizeEntity; |
154 | 152 | |
@@ -187,8 +185,7 @@ discard block |
||
187 | 185 | */ |
188 | 186 | public function isValid() : bool |
189 | 187 | { |
190 | - if ($this->_bHandleRequestActivate === true) { return true; } |
|
191 | - else { return false; } |
|
188 | + if ($this->_bHandleRequestActivate === true) { return true; } else { return false; } |
|
192 | 189 | } |
193 | 190 | |
194 | 191 | /** |
@@ -202,8 +199,7 @@ discard block |
||
202 | 199 | if (isset($_POST['validform'.$this->_oForm->getFormNumber()]) && $_POST['validform'.$this->_oForm->getFormNumber()] == 1) { |
203 | 200 | |
204 | 201 | return true; |
205 | - } |
|
206 | - else { |
|
202 | + } else { |
|
207 | 203 | |
208 | 204 | return false; |
209 | 205 | } |
@@ -218,8 +214,7 @@ discard block |
||
218 | 214 | */ |
219 | 215 | public function isClicked(string $sElementName) : bool |
220 | 216 | { |
221 | - if (isset($_POST[$sElementName]) && $_POST[$sElementName]) { return true; } |
|
222 | - else { return false; } |
|
217 | + if (isset($_POST[$sElementName]) && $_POST[$sElementName]) { return true; } else { return false; } |
|
223 | 218 | } |
224 | 219 | |
225 | 220 | /** |
@@ -151,7 +151,7 @@ |
||
151 | 151 | * |
152 | 152 | * @access public |
153 | 153 | * @param string $sType type of input; |
154 | - * @return bool |
|
154 | + * @return string |
|
155 | 155 | */ |
156 | 156 | public function isClicked(string $sType) : string |
157 | 157 | { |
@@ -174,10 +174,10 @@ |
||
174 | 174 | $sContent = ''; |
175 | 175 | |
176 | 176 | if ($this->getType() === 'text' || $this->getType() === 'password' || $this->getType() === 'file' |
177 | - || $this->getType() === 'tel' || $this->getType() === 'url' || $this->getType() === 'email' |
|
178 | - || $this->getType() === 'search' || $this->getType() === 'date' || $this->getType() === 'time' |
|
179 | - || $this->getType() === 'datetime' || $this->getType() === 'month' || $this->getType() === 'week' |
|
180 | - || $this->getType() === 'number' || $this->getType() === 'range' || $this->getType() === 'color') { |
|
177 | + || $this->getType() === 'tel' || $this->getType() === 'url' || $this->getType() === 'email' |
|
178 | + || $this->getType() === 'search' || $this->getType() === 'date' || $this->getType() === 'time' |
|
179 | + || $this->getType() === 'datetime' || $this->getType() === 'month' || $this->getType() === 'week' |
|
180 | + || $this->getType() === 'number' || $this->getType() === 'range' || $this->getType() === 'color') { |
|
181 | 181 | |
182 | 182 | $sContent .= '<label>'.$this->getLabel().'</label> '; |
183 | 183 | } |
@@ -60,8 +60,7 @@ |
||
60 | 60 | $this->setName($sName); |
61 | 61 | $this->setValue($sValue); |
62 | 62 | |
63 | - if ($sLabel !== null) { $this->setLabel($sLabel); } |
|
64 | - else { $this->setLabel($sName); } |
|
63 | + if ($sLabel !== null) { $this->setLabel($sLabel); } else { $this->setLabel($sName); } |
|
65 | 64 | } |
66 | 65 | |
67 | 66 | /** |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * |
97 | 97 | * @access public |
98 | 98 | * @param string $sValue Value of input; |
99 | - * @return \Venus\lib\Form\Input |
|
99 | + * @return Radio |
|
100 | 100 | */ |
101 | 101 | public function setValue(string $sValue) : Input |
102 | 102 | { |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | * |
121 | 121 | * @access public |
122 | 122 | * @param string $sValueChecked Value of input; |
123 | - * @return \Venus\lib\Form\Input |
|
123 | + * @return Radio |
|
124 | 124 | */ |
125 | 125 | public function setValueChecked(string $sValueChecked) : Input |
126 | 126 | { |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * |
145 | 145 | * @access public |
146 | 146 | * @param string $sLabel Label of input; |
147 | - * @return \Venus\lib\Form\Input |
|
147 | + * @return Radio |
|
148 | 148 | */ |
149 | 149 | public function setLabel(string $sLabel) : Input |
150 | 150 | { |