@@ -196,8 +196,8 @@ discard block |
||
196 | 196 | * |
197 | 197 | * @access private |
198 | 198 | * @param string $sFileToMerge file to get |
199 | - * @param object $base base |
|
200 | - * @return object |
|
199 | + * @param stdClass $base base |
|
200 | + * @return stdClass |
|
201 | 201 | */ |
202 | 202 | private static function _mergeAndGetConf(string $sFileToMerge, \StdClass $base) : \StdClass |
203 | 203 | { |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | * |
223 | 223 | * @access private |
224 | 224 | * @param $oConfFiles |
225 | - * @param StdClass $base |
|
225 | + * @param stdClass $base |
|
226 | 226 | * @return multitype:array multitype:array |
227 | 227 | */ |
228 | 228 | private static function _recursiveGet($oConfFiles, StdClass $base) : array |
@@ -14,7 +14,6 @@ |
||
14 | 14 | */ |
15 | 15 | namespace Venus\core; |
16 | 16 | |
17 | -use stdClass; |
|
18 | 17 | use \Venus\lib\Debug as Debug; |
19 | 18 | |
20 | 19 | /** |
@@ -50,17 +50,17 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public static function get(string $sName, string $sPortal = null, bool $bNoDoRedirect = false) |
52 | 52 | { |
53 | - if ($bNoDoRedirect === true) { $sNameCache = $sName.'_true'; } |
|
54 | - else { $sNameCache = $sName; } |
|
53 | + if ($bNoDoRedirect === true) { $sNameCache = $sName.'_true'; } |
|
54 | + else { $sNameCache = $sName; } |
|
55 | 55 | |
56 | 56 | if ($sPortal === null || !is_string($sPortal)) { |
57 | 57 | |
58 | - if (defined('PORTAL')) { |
|
58 | + if (defined('PORTAL')) { |
|
59 | 59 | |
60 | 60 | $sPortal = PORTAL; |
61 | 61 | $aDirectories = array($sPortal); |
62 | 62 | } |
63 | - else { |
|
63 | + else { |
|
64 | 64 | |
65 | 65 | $sPortal = ''; |
66 | 66 | $aDirectories = scandir(str_replace('core', 'src', __DIR__)); |
@@ -73,84 +73,84 @@ discard block |
||
73 | 73 | |
74 | 74 | foreach ($aDirectories as $sPortal) { |
75 | 75 | |
76 | - if ($sPortal != '..' && $sPortal != '.') { |
|
76 | + if ($sPortal != '..' && $sPortal != '.') { |
|
77 | 77 | |
78 | - if (file_exists(str_replace('core', 'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-local')) { |
|
78 | + if (file_exists(str_replace('core', 'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-local')) { |
|
79 | 79 | |
80 | - $sJsonFile = str_replace('core', 'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-local'; |
|
81 | - $base = self::_mergeAndGetConf($sJsonFile, $base); |
|
82 | - } |
|
80 | + $sJsonFile = str_replace('core', 'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-local'; |
|
81 | + $base = self::_mergeAndGetConf($sJsonFile, $base); |
|
82 | + } |
|
83 | 83 | |
84 | - if (file_exists(str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-local')) { |
|
84 | + if (file_exists(str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-local')) { |
|
85 | 85 | |
86 | - $sJsonFile = str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-local'; |
|
87 | - $base = self::_mergeAndGetConf($sJsonFile, $base); |
|
88 | - } |
|
86 | + $sJsonFile = str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-local'; |
|
87 | + $base = self::_mergeAndGetConf($sJsonFile, $base); |
|
88 | + } |
|
89 | 89 | |
90 | - if (file_exists(str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-dev') && getenv('DEV') == 1) { |
|
90 | + if (file_exists(str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-dev') && getenv('DEV') == 1) { |
|
91 | 91 | |
92 | - $sJsonFile = str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-dev'; |
|
93 | - $base = self::_mergeAndGetConf($sJsonFile, $base); |
|
94 | - } |
|
92 | + $sJsonFile = str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-dev'; |
|
93 | + $base = self::_mergeAndGetConf($sJsonFile, $base); |
|
94 | + } |
|
95 | 95 | |
96 | - if (file_exists(str_replace('core', 'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-dev') && getenv('DEV') == 1) { |
|
96 | + if (file_exists(str_replace('core', 'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-dev') && getenv('DEV') == 1) { |
|
97 | 97 | |
98 | - $sJsonFile = str_replace('core', 'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-dev'; |
|
99 | - $base = self::_mergeAndGetConf($sJsonFile, $base); |
|
100 | - } |
|
98 | + $sJsonFile = str_replace('core', 'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-dev'; |
|
99 | + $base = self::_mergeAndGetConf($sJsonFile, $base); |
|
100 | + } |
|
101 | 101 | |
102 | - if (file_exists(str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-dev') && getenv('PROD') == 1) { |
|
102 | + if (file_exists(str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-dev') && getenv('PROD') == 1) { |
|
103 | 103 | |
104 | - $sJsonFile = str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-prod'; |
|
105 | - $base = self::_mergeAndGetConf($sJsonFile, $base); |
|
106 | - } |
|
104 | + $sJsonFile = str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-prod'; |
|
105 | + $base = self::_mergeAndGetConf($sJsonFile, $base); |
|
106 | + } |
|
107 | 107 | |
108 | - if (file_exists(str_replace('core', 'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-dev') && getenv('PROD') == 1) { |
|
108 | + if (file_exists(str_replace('core', 'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-dev') && getenv('PROD') == 1) { |
|
109 | 109 | |
110 | - $sJsonFile = str_replace('core', 'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-prod'; |
|
111 | - $base = self::_mergeAndGetConf($sJsonFile, $base); |
|
112 | - } |
|
110 | + $sJsonFile = str_replace('core', 'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-prod'; |
|
111 | + $base = self::_mergeAndGetConf($sJsonFile, $base); |
|
112 | + } |
|
113 | 113 | |
114 | - if (file_exists(str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-dev') && getenv('PREPROD') == 1) { |
|
114 | + if (file_exists(str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-dev') && getenv('PREPROD') == 1) { |
|
115 | 115 | |
116 | - $sJsonFile = str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-pprod'; |
|
117 | - $base = self::_mergeAndGetConf($sJsonFile, $base); |
|
118 | - } |
|
116 | + $sJsonFile = str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-pprod'; |
|
117 | + $base = self::_mergeAndGetConf($sJsonFile, $base); |
|
118 | + } |
|
119 | 119 | |
120 | - if (file_exists(str_replace('core', 'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-dev') && getenv('PREPROD') == 1) { |
|
120 | + if (file_exists(str_replace('core', 'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-dev') && getenv('PREPROD') == 1) { |
|
121 | 121 | |
122 | - $sJsonFile = str_replace('core', 'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-pprod'; |
|
123 | - $base = self::_mergeAndGetConf($sJsonFile, $base); |
|
124 | - } |
|
122 | + $sJsonFile = str_replace('core', 'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-pprod'; |
|
123 | + $base = self::_mergeAndGetConf($sJsonFile, $base); |
|
124 | + } |
|
125 | 125 | |
126 | - if (file_exists(str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-dev') && getenv('RECETTE') == 1) { |
|
126 | + if (file_exists(str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-dev') && getenv('RECETTE') == 1) { |
|
127 | 127 | |
128 | - $sJsonFile = str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-rec'; |
|
129 | - $base = self::_mergeAndGetConf($sJsonFile, $base); |
|
130 | - } |
|
128 | + $sJsonFile = str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-rec'; |
|
129 | + $base = self::_mergeAndGetConf($sJsonFile, $base); |
|
130 | + } |
|
131 | 131 | |
132 | - if (file_exists(str_replace('core', 'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-dev') && getenv('RECETTE') == 1) { |
|
132 | + if (file_exists(str_replace('core', 'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-dev') && getenv('RECETTE') == 1) { |
|
133 | 133 | |
134 | - $sJsonFile = str_replace('core', 'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-rec'; |
|
135 | - $base = self::_mergeAndGetConf($sJsonFile, $base); |
|
136 | - } |
|
134 | + $sJsonFile = str_replace('core', 'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-rec'; |
|
135 | + $base = self::_mergeAndGetConf($sJsonFile, $base); |
|
136 | + } |
|
137 | 137 | |
138 | - if (file_exists(str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-local')) { |
|
138 | + if (file_exists(str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-local')) { |
|
139 | 139 | |
140 | - $sJsonFile = str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-local'; |
|
141 | - $base = self::_mergeAndGetConf($sJsonFile, $base); |
|
142 | - } |
|
140 | + $sJsonFile = str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-local'; |
|
141 | + $base = self::_mergeAndGetConf($sJsonFile, $base); |
|
142 | + } |
|
143 | 143 | |
144 | - if (file_exists(str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf')) { |
|
144 | + if (file_exists(str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf')) { |
|
145 | 145 | |
146 | - $sJsonFile = str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf'; |
|
147 | - $base = self::_mergeAndGetConf($sJsonFile, $base); |
|
148 | - } |
|
146 | + $sJsonFile = str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf'; |
|
147 | + $base = self::_mergeAndGetConf($sJsonFile, $base); |
|
148 | + } |
|
149 | 149 | |
150 | - $sJsonFile = str_replace('core', 'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf'; |
|
151 | - $base = self::_mergeAndGetConf($sJsonFile, $base); |
|
152 | - } |
|
153 | - } |
|
150 | + $sJsonFile = str_replace('core', 'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf'; |
|
151 | + $base = self::_mergeAndGetConf($sJsonFile, $base); |
|
152 | + } |
|
153 | + } |
|
154 | 154 | |
155 | 155 | if ($base === '') { |
156 | 156 | |
@@ -185,10 +185,10 @@ discard block |
||
185 | 185 | */ |
186 | 186 | public static function getBundleLocationName(string $sName): string |
187 | 187 | { |
188 | - $oConfig = self::get($sName, null, true); |
|
188 | + $oConfig = self::get($sName, null, true); |
|
189 | 189 | |
190 | - if (isset($oConfig->redirect)) { return $oConfig->redirect; } |
|
191 | - else { return PORTAL; } |
|
190 | + if (isset($oConfig->redirect)) { return $oConfig->redirect; } |
|
191 | + else { return PORTAL; } |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -50,8 +50,7 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public static function get(string $sName, string $sPortal = null, bool $bNoDoRedirect = false) |
52 | 52 | { |
53 | - if ($bNoDoRedirect === true) { $sNameCache = $sName.'_true'; } |
|
54 | - else { $sNameCache = $sName; } |
|
53 | + if ($bNoDoRedirect === true) { $sNameCache = $sName.'_true'; } else { $sNameCache = $sName; } |
|
55 | 54 | |
56 | 55 | if ($sPortal === null || !is_string($sPortal)) { |
57 | 56 | |
@@ -59,8 +58,7 @@ discard block |
||
59 | 58 | |
60 | 59 | $sPortal = PORTAL; |
61 | 60 | $aDirectories = array($sPortal); |
62 | - } |
|
63 | - else { |
|
61 | + } else { |
|
64 | 62 | |
65 | 63 | $sPortal = ''; |
66 | 64 | $aDirectories = scandir(str_replace('core', 'src', __DIR__)); |
@@ -187,8 +185,7 @@ discard block |
||
187 | 185 | { |
188 | 186 | $oConfig = self::get($sName, null, true); |
189 | 187 | |
190 | - if (isset($oConfig->redirect)) { return $oConfig->redirect; } |
|
191 | - else { return PORTAL; } |
|
188 | + if (isset($oConfig->redirect)) { return $oConfig->redirect; } else { return PORTAL; } |
|
192 | 189 | } |
193 | 190 | |
194 | 191 | /** |
@@ -207,8 +204,7 @@ discard block |
||
207 | 204 | |
208 | 205 | list($oConfFiles, $base) = self::_recursiveGet($oConfFiles, $base); |
209 | 206 | return $base; |
210 | - } |
|
211 | - else { |
|
207 | + } else { |
|
212 | 208 | |
213 | 209 | echo "The Json ".$sFileToMerge." has an error! Please verify!\n"; |
214 | 210 | $oDebug = Debug::getInstance(); |
@@ -232,12 +228,10 @@ discard block |
||
232 | 228 | if (is_object($oConfFiles) && is_object($base) && !isset($base->$sKey)) { |
233 | 229 | |
234 | 230 | $base->$sKey = $oConfFiles->$sKey; |
235 | - } |
|
236 | - else if (is_array($oConfFiles) && is_array($base) && !isset($base[$sKey])) { |
|
231 | + } else if (is_array($oConfFiles) && is_array($base) && !isset($base[$sKey])) { |
|
237 | 232 | |
238 | 233 | $base[$sKey] = $oConfFiles[$sKey]; |
239 | - } |
|
240 | - else if (!isset($base->$sKey) && is_array($mOne)) { |
|
234 | + } else if (!isset($base->$sKey) && is_array($mOne)) { |
|
241 | 235 | |
242 | 236 | $base->$sKey = new \StdClass; |
243 | 237 | list($oConfFiles, $base) = self::_recursiveGet($mOne, $base->$sKey); |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | * |
119 | 119 | * @access public |
120 | 120 | * @param mixed $mKey |
121 | - * @return void |
|
121 | + * @return boolean |
|
122 | 122 | */ |
123 | 123 | public function __isset($mKey) |
124 | 124 | { |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | * |
131 | 131 | * @access public |
132 | 132 | * @param mixed $mOffset |
133 | - * @return mixed |
|
133 | + * @return boolean |
|
134 | 134 | */ |
135 | 135 | function offsetExists($mOffset) |
136 | 136 | { |
@@ -62,15 +62,13 @@ discard block |
||
62 | 62 | if (!is_callable($data = $this->_aDataType[$mKey][$mKey]) || (is_string($data) && function_exists($data))) { |
63 | 63 | |
64 | 64 | return $data; |
65 | - } |
|
66 | - else { |
|
65 | + } else { |
|
67 | 66 | |
68 | 67 | $dataStore = &$this->_aDataType[$mKey]; |
69 | 68 | $dataStore[$mKey] = call_user_func($data, null); |
70 | 69 | return $dataStore[$mKey]; |
71 | 70 | } |
72 | - } |
|
73 | - else { |
|
71 | + } else { |
|
74 | 72 | |
75 | 73 | return null; |
76 | 74 | } |
@@ -89,8 +87,7 @@ discard block |
||
89 | 87 | |
90 | 88 | $this->_aClosures[$mKey] = $mValue; |
91 | 89 | $this->_aDataType[$mKey] = &$this->_aClosures; |
92 | - } |
|
93 | - else { |
|
90 | + } else { |
|
94 | 91 | |
95 | 92 | $this->_aData[$mKey] = $mValue; |
96 | 93 | $this->_aDataType[$mKey] = &$this->_aData; |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * run the routeur |
91 | 91 | * |
92 | 92 | * @access public |
93 | - * @return void |
|
93 | + * @return null|boolean |
|
94 | 94 | */ |
95 | 95 | public function run() |
96 | 96 | { |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | * load a route |
379 | 379 | * |
380 | 380 | * @access private |
381 | - * @param stdClass $oRoute one route |
|
381 | + * @param \stdClass $oRoute one route |
|
382 | 382 | * @param string $RequestUri URI |
383 | 383 | * @return void |
384 | 384 | */ |
@@ -82,8 +82,8 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function __construct() |
84 | 84 | { |
85 | - $oLogger = Debug::getInstance(); |
|
86 | - $this->setLogger($oLogger); |
|
85 | + $oLogger = Debug::getInstance(); |
|
86 | + $this->setLogger($oLogger); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -100,120 +100,120 @@ discard block |
||
100 | 100 | |
101 | 101 | if (Request::isHttpRequest()) { |
102 | 102 | |
103 | - // Search if a Less file exists |
|
104 | - if (defined('LESS_ACTIVE') && LESS_ACTIVE === true) { |
|
103 | + // Search if a Less file exists |
|
104 | + if (defined('LESS_ACTIVE') && LESS_ACTIVE === true) { |
|
105 | 105 | |
106 | - if (strstr($_SERVER['REQUEST_URI'], '.css') |
|
107 | - && file_exists(preg_replace('/\.css/', '.less', $_SERVER['REQUEST_URI']))) { |
|
106 | + if (strstr($_SERVER['REQUEST_URI'], '.css') |
|
107 | + && file_exists(preg_replace('/\.css/', '.less', $_SERVER['REQUEST_URI']))) { |
|
108 | 108 | |
109 | - Less::toCss($_SERVER['REQUEST_URI']); |
|
110 | - exit; |
|
111 | - } |
|
112 | - } |
|
109 | + Less::toCss($_SERVER['REQUEST_URI']); |
|
110 | + exit; |
|
111 | + } |
|
112 | + } |
|
113 | 113 | |
114 | - // Search if a typescript file exists |
|
115 | - if (defined('TYPESCRIPT_ACTIVE') && TYPESCRIPT_ACTIVE === true) { |
|
114 | + // Search if a typescript file exists |
|
115 | + if (defined('TYPESCRIPT_ACTIVE') && TYPESCRIPT_ACTIVE === true) { |
|
116 | 116 | |
117 | - if (strstr($_SERVER['REQUEST_URI'], '.js') |
|
118 | - && file_exists(preg_replace('/\.js/', '.ts', $_SERVER['REQUEST_URI']))) { |
|
117 | + if (strstr($_SERVER['REQUEST_URI'], '.js') |
|
118 | + && file_exists(preg_replace('/\.js/', '.ts', $_SERVER['REQUEST_URI']))) { |
|
119 | 119 | |
120 | - Typescript::toJs($_SERVER['REQUEST_URI']); |
|
121 | - exit; |
|
122 | - } |
|
123 | - } |
|
120 | + Typescript::toJs($_SERVER['REQUEST_URI']); |
|
121 | + exit; |
|
122 | + } |
|
123 | + } |
|
124 | 124 | |
125 | - // Search public files in all plugins |
|
126 | - if ($_SERVER['REQUEST_URI'] !== '/') { |
|
125 | + // Search public files in all plugins |
|
126 | + if ($_SERVER['REQUEST_URI'] !== '/') { |
|
127 | 127 | |
128 | - foreach (Config::get('Plugins')->list as $iKey => $sPlugin) { |
|
128 | + foreach (Config::get('Plugins')->list as $iKey => $sPlugin) { |
|
129 | 129 | |
130 | - if (file_exists(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.$_SERVER['REQUEST_URI'])) { |
|
130 | + if (file_exists(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.$_SERVER['REQUEST_URI'])) { |
|
131 | 131 | |
132 | - echo file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.$_SERVER['REQUEST_URI']); |
|
133 | - exit; |
|
134 | - } |
|
135 | - else if (strstr($_SERVER['REQUEST_URI'], '.css') |
|
136 | - && file_exists(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.preg_replace('/\.css/', '.less', $_SERVER['REQUEST_URI']))) { |
|
137 | - |
|
138 | - Less::toCss(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.preg_replace('/\.css/', '.less', $_SERVER['REQUEST_URI'])); |
|
139 | - exit; |
|
140 | - } |
|
141 | - else if (strstr($_SERVER['REQUEST_URI'], '.js') |
|
142 | - && file_exists(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.preg_replace('/\.js/', '.ts', $_SERVER['REQUEST_URI']))) { |
|
143 | - |
|
144 | - Typescript::toJs(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.preg_replace('/\.js/', '.ts', $_SERVER['REQUEST_URI'])); |
|
145 | - exit; |
|
146 | - } |
|
147 | - } |
|
148 | - } |
|
132 | + echo file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.$_SERVER['REQUEST_URI']); |
|
133 | + exit; |
|
134 | + } |
|
135 | + else if (strstr($_SERVER['REQUEST_URI'], '.css') |
|
136 | + && file_exists(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.preg_replace('/\.css/', '.less', $_SERVER['REQUEST_URI']))) { |
|
137 | + |
|
138 | + Less::toCss(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.preg_replace('/\.css/', '.less', $_SERVER['REQUEST_URI'])); |
|
139 | + exit; |
|
140 | + } |
|
141 | + else if (strstr($_SERVER['REQUEST_URI'], '.js') |
|
142 | + && file_exists(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.preg_replace('/\.js/', '.ts', $_SERVER['REQUEST_URI']))) { |
|
143 | + |
|
144 | + Typescript::toJs(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.preg_replace('/\.js/', '.ts', $_SERVER['REQUEST_URI'])); |
|
145 | + exit; |
|
146 | + } |
|
147 | + } |
|
148 | + } |
|
149 | 149 | |
150 | 150 | foreach (Config::get('Route') as $sMultiHost => $oHost) { |
151 | 151 | |
152 | - foreach (explode(',', $sMultiHost) as $sHost) { |
|
152 | + foreach (explode(',', $sMultiHost) as $sHost) { |
|
153 | 153 | |
154 | - if ((!strstr($sHost, '/') && $sHost == $_SERVER['HTTP_HOST']) || (strstr($sHost, '/') |
|
155 | - && strstr($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $sHost))) { |
|
154 | + if ((!strstr($sHost, '/') && $sHost == $_SERVER['HTTP_HOST']) || (strstr($sHost, '/') |
|
155 | + && strstr($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $sHost))) { |
|
156 | 156 | |
157 | - $this->_oRoutes = $oHost; |
|
157 | + $this->_oRoutes = $oHost; |
|
158 | 158 | |
159 | - if (strstr($sHost, '/') |
|
160 | - && strstr($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $sHost)) { |
|
159 | + if (strstr($sHost, '/') |
|
160 | + && strstr($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $sHost)) { |
|
161 | 161 | |
162 | - $this->_sBaseUri = preg_replace('#^[^/]+#', '', $sHost); |
|
163 | - } |
|
162 | + $this->_sBaseUri = preg_replace('#^[^/]+#', '', $sHost); |
|
163 | + } |
|
164 | 164 | |
165 | - if (isset($oHost->location)) { |
|
165 | + if (isset($oHost->location)) { |
|
166 | 166 | |
167 | - header('Status: 301 Moved Permanently', false, 301); |
|
168 | - header('Location: '.$oHost->location); |
|
169 | - exit; |
|
170 | - } |
|
171 | - else if (preg_match('#getCss\?#', $_SERVER['REQUEST_URI'])) { |
|
167 | + header('Status: 301 Moved Permanently', false, 301); |
|
168 | + header('Location: '.$oHost->location); |
|
169 | + exit; |
|
170 | + } |
|
171 | + else if (preg_match('#getCss\?#', $_SERVER['REQUEST_URI'])) { |
|
172 | 172 | |
173 | - foreach ($_GET as $sKey => $sValue) { |
|
173 | + foreach ($_GET as $sKey => $sValue) { |
|
174 | 174 | |
175 | - if (file_exists(str_replace(DIRECTORY_SEPARATOR.'core', DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR, __DIR__).$sKey.'.css')) { |
|
175 | + if (file_exists(str_replace(DIRECTORY_SEPARATOR.'core', DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR, __DIR__).$sKey.'.css')) { |
|
176 | 176 | |
177 | - echo file_get_contents(str_replace(DIRECTORY_SEPARATOR.'core', DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR, __DIR__).$sKey.'.css')."\n"; |
|
178 | - } |
|
179 | - } |
|
177 | + echo file_get_contents(str_replace(DIRECTORY_SEPARATOR.'core', DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR, __DIR__).$sKey.'.css')."\n"; |
|
178 | + } |
|
179 | + } |
|
180 | 180 | |
181 | - exit; |
|
182 | - } |
|
183 | - else if (preg_match('#getJs\?#', $_SERVER['REQUEST_URI'])) { |
|
181 | + exit; |
|
182 | + } |
|
183 | + else if (preg_match('#getJs\?#', $_SERVER['REQUEST_URI'])) { |
|
184 | 184 | |
185 | - foreach ($_GET as $sKey => $sValue) { |
|
185 | + foreach ($_GET as $sKey => $sValue) { |
|
186 | 186 | |
187 | - if (file_exists(str_replace(DIRECTORY_SEPARATOR.'core', DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR, __DIR__).$sKey.'.js')) { |
|
187 | + if (file_exists(str_replace(DIRECTORY_SEPARATOR.'core', DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR, __DIR__).$sKey.'.js')) { |
|
188 | 188 | |
189 | - echo file_get_contents(str_replace(DIRECTORY_SEPARATOR.'core', DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR, __DIR__).$sKey.'.js')."\n"; |
|
190 | - } |
|
191 | - } |
|
189 | + echo file_get_contents(str_replace(DIRECTORY_SEPARATOR.'core', DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR, __DIR__).$sKey.'.js')."\n"; |
|
190 | + } |
|
191 | + } |
|
192 | 192 | |
193 | - exit; |
|
194 | - } |
|
195 | - else if (isset($oHost->routes)) { |
|
193 | + exit; |
|
194 | + } |
|
195 | + else if (isset($oHost->routes)) { |
|
196 | 196 | |
197 | - foreach($oHost->routes as $sKey => $oRoute) { |
|
197 | + foreach($oHost->routes as $sKey => $oRoute) { |
|
198 | 198 | |
199 | - $mReturn = $this->_route($oRoute, $_SERVER['REQUEST_URI']); |
|
199 | + $mReturn = $this->_route($oRoute, $_SERVER['REQUEST_URI']); |
|
200 | 200 | |
201 | - if ($mReturn === 403) { |
|
201 | + if ($mReturn === 403) { |
|
202 | 202 | |
203 | - $this->_getPage403(); |
|
204 | - } |
|
205 | - else if ($mReturn == true) { |
|
203 | + $this->_getPage403(); |
|
204 | + } |
|
205 | + else if ($mReturn == true) { |
|
206 | 206 | |
207 | - if (isset($oRoute->cache)) { $this->_checkCache($oRoute->cache); } |
|
207 | + if (isset($oRoute->cache)) { $this->_checkCache($oRoute->cache); } |
|
208 | 208 | |
209 | - return true; |
|
210 | - } |
|
211 | - } |
|
209 | + return true; |
|
210 | + } |
|
211 | + } |
|
212 | 212 | |
213 | - $this->_getPage404(); |
|
214 | - } |
|
215 | - } |
|
216 | - } |
|
213 | + $this->_getPage404(); |
|
214 | + } |
|
215 | + } |
|
216 | + } |
|
217 | 217 | |
218 | 218 | //@todo fait l'erreur à chaque passage |
219 | 219 | // if ($sHost !== $_SERVER['HTTP_HOST']) { |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | // } |
228 | 228 | } |
229 | 229 | } |
230 | - else if (Request::isCliRequest()) { |
|
230 | + else if (Request::isCliRequest()) { |
|
231 | 231 | |
232 | 232 | if (isset($_SERVER['argv'])) { $aArguments = $_SERVER['argv']; } |
233 | 233 | else { $aArguments = $argv; } |
@@ -235,15 +235,15 @@ discard block |
||
235 | 235 | define('PORTAL', 'Batch'); |
236 | 236 | set_include_path(get_include_path().PATH_SEPARATOR.'src'.PATH_SEPARATOR.PORTAL.PATH_SEPARATOR.'public'); |
237 | 237 | |
238 | - if (!isset($aArguments[1]) && strstr($aArguments[0], '/phpunit')) { |
|
238 | + if (!isset($aArguments[1]) && strstr($aArguments[0], '/phpunit')) { |
|
239 | 239 | |
240 | - $sBatchName = "phpunit"; |
|
241 | - $aArguments[0] = "bin/console"; |
|
242 | - $aArguments[1] = "phpunit"; |
|
243 | - } |
|
244 | - else { |
|
245 | - $sBatchName = $aArguments[1]; |
|
246 | - } |
|
240 | + $sBatchName = "phpunit"; |
|
241 | + $aArguments[0] = "bin/console"; |
|
242 | + $aArguments[1] = "phpunit"; |
|
243 | + } |
|
244 | + else { |
|
245 | + $sBatchName = $aArguments[1]; |
|
246 | + } |
|
247 | 247 | |
248 | 248 | if (isset(Config::get('Route')->batch->script->{$sBatchName})) { |
249 | 249 | |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | array_shift($aArguments); |
286 | 286 | } |
287 | 287 | } |
288 | - } |
|
288 | + } |
|
289 | 289 | |
290 | 290 | if (isset($oBatch->controller) && isset($oBatch->action)) { |
291 | 291 | |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | foreach (Config::get('Route') as $sHost => $oHost) { |
359 | 359 | |
360 | 360 | if ((!strstr($sHost, '/') && $sHost == $_SERVER['HTTP_HOST']) |
361 | - || (strstr($sHost, '/') && strstr($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $sHost))) { |
|
361 | + || (strstr($sHost, '/') && strstr($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $sHost))) { |
|
362 | 362 | |
363 | 363 | $this->_oRoutes = $oHost->routes; |
364 | 364 | |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | |
389 | 389 | if (isset($oRoute->route)) { |
390 | 390 | |
391 | - $sRoute = str_replace("*", ".*", $oRoute->route); |
|
391 | + $sRoute = str_replace("*", ".*", $oRoute->route); |
|
392 | 392 | |
393 | 393 | $sFinalRoute = preg_replace_callback( |
394 | 394 | '|\[/{0,1}:([a-zA-Z_]+)\]|', |
@@ -464,8 +464,8 @@ discard block |
||
464 | 464 | |
465 | 465 | if (isset($oRoute->controller)) { |
466 | 466 | |
467 | - define('PORTAL', preg_replace('/^\\\\Venus\\\\src\\\\([a-zA-Z0-9_]+)\\\\.+$/', '$1', $oRoute->controller)); |
|
468 | - set_include_path(get_include_path().PATH_SEPARATOR.'src'.PATH_SEPARATOR.PORTAL.PATH_SEPARATOR.'public'); |
|
467 | + define('PORTAL', preg_replace('/^\\\\Venus\\\\src\\\\([a-zA-Z0-9_]+)\\\\.+$/', '$1', $oRoute->controller)); |
|
468 | + set_include_path(get_include_path().PATH_SEPARATOR.'src'.PATH_SEPARATOR.PORTAL.PATH_SEPARATOR.'public'); |
|
469 | 469 | |
470 | 470 | if (isset($oRoute->content_type)) { |
471 | 471 | |
@@ -519,7 +519,7 @@ discard block |
||
519 | 519 | } |
520 | 520 | else { |
521 | 521 | |
522 | - $this->_oLogger->warning('Error: Parameter '.$sName.' not exists!'); |
|
522 | + $this->_oLogger->warning('Error: Parameter '.$sName.' not exists!'); |
|
523 | 523 | break; |
524 | 524 | } |
525 | 525 | } |
@@ -545,10 +545,10 @@ discard block |
||
545 | 545 | } |
546 | 546 | else if (isset($oRoute->template) && isset($oRoute->layout) && $oRoute->layout === true) { |
547 | 547 | |
548 | - define('PORTAL', preg_replace('/^\\\\Venus\\\\src\\\\([a-zA-Z0-9_]+)\\\\.+$/', '$1', $oRoute->template)); |
|
549 | - set_include_path(get_include_path().PATH_SEPARATOR.'src'.PATH_SEPARATOR.PORTAL.PATH_SEPARATOR.'public'); |
|
548 | + define('PORTAL', preg_replace('/^\\\\Venus\\\\src\\\\([a-zA-Z0-9_]+)\\\\.+$/', '$1', $oRoute->template)); |
|
549 | + set_include_path(get_include_path().PATH_SEPARATOR.'src'.PATH_SEPARATOR.PORTAL.PATH_SEPARATOR.'public'); |
|
550 | 550 | |
551 | - $oLayout = Vendor::getVendor('Apollina\Template', DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.PORTAL.DIRECTORY_SEPARATOR.'View'.DIRECTORY_SEPARATOR.'Layout.tpl'); |
|
551 | + $oLayout = Vendor::getVendor('Apollina\Template', DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.PORTAL.DIRECTORY_SEPARATOR.'View'.DIRECTORY_SEPARATOR.'Layout.tpl'); |
|
552 | 552 | |
553 | 553 | if (isset($oRoute->vars)) { |
554 | 554 | |
@@ -563,8 +563,8 @@ discard block |
||
563 | 563 | } |
564 | 564 | else if (isset($oRoute->template)) { |
565 | 565 | |
566 | - define('PORTAL', preg_replace('/^\\\\Venus\\\\src\\\\([a-zA-Z0-9_]+)\\\\.+$/', '$1', $oRoute->template)); |
|
567 | - set_include_path(get_include_path().PATH_SEPARATOR.'src'.PATH_SEPARATOR.PORTAL.PATH_SEPARATOR.'public'); |
|
566 | + define('PORTAL', preg_replace('/^\\\\Venus\\\\src\\\\([a-zA-Z0-9_]+)\\\\.+$/', '$1', $oRoute->template)); |
|
567 | + set_include_path(get_include_path().PATH_SEPARATOR.'src'.PATH_SEPARATOR.PORTAL.PATH_SEPARATOR.'public'); |
|
568 | 568 | |
569 | 569 | $oTemplate = Vendor::getVendor('Apollina\Template', DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.PORTAL.DIRECTORY_SEPARATOR.'View'.DIRECTORY_SEPARATOR.$oRoute->template.'.tpl'); |
570 | 570 | |
@@ -664,14 +664,14 @@ discard block |
||
664 | 664 | |
665 | 665 | if (method_exists($oController, 'beforeExecuteRoute')) { |
666 | 666 | |
667 | - call_user_func_array(array($oController, 'beforeExecuteRoute'), array()); |
|
667 | + call_user_func_array(array($oController, 'beforeExecuteRoute'), array()); |
|
668 | 668 | } |
669 | 669 | |
670 | 670 | $mReturnController = call_user_func_array(array($oController, $sActionName), $aParams); |
671 | 671 | |
672 | 672 | if (method_exists($oController, 'afterExecuteRoute')) { |
673 | 673 | |
674 | - call_user_func_array(array($oController, 'afterExecuteRoute'), array()); |
|
674 | + call_user_func_array(array($oController, 'afterExecuteRoute'), array()); |
|
675 | 675 | } |
676 | 676 | |
677 | 677 | $mReturn = ob_get_clean(); |
@@ -811,6 +811,6 @@ discard block |
||
811 | 811 | */ |
812 | 812 | public function setLogger(LoggerInterface $logger) { |
813 | 813 | |
814 | - $this->_oLogger = $logger; |
|
814 | + $this->_oLogger = $logger; |
|
815 | 815 | } |
816 | 816 | } |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | } |
195 | 195 | else if (isset($oHost->routes)) { |
196 | 196 | |
197 | - foreach($oHost->routes as $sKey => $oRoute) { |
|
197 | + foreach ($oHost->routes as $sKey => $oRoute) { |
|
198 | 198 | |
199 | 199 | $mReturn = $this->_route($oRoute, $_SERVER['REQUEST_URI']); |
200 | 200 | |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | $this->_sBaseUri = preg_replace('#^[^/]+#', '', $sHost); |
329 | 329 | } |
330 | 330 | |
331 | - foreach($oHost->routes as $sKey => $oRoute) { |
|
331 | + foreach ($oHost->routes as $sKey => $oRoute) { |
|
332 | 332 | |
333 | 333 | $this->_route($oRoute, $sRoute); |
334 | 334 | } |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | |
393 | 393 | $sFinalRoute = preg_replace_callback( |
394 | 394 | '|\[/{0,1}:([a-zA-Z_]+)\]|', |
395 | - function ($aMatches) use ($oRoute) { |
|
395 | + function($aMatches) use ($oRoute) { |
|
396 | 396 | return "/{0,1}(?P<".$aMatches[1].">".$oRoute->constraints->{$aMatches[1]}.")"; |
397 | 397 | }, |
398 | 398 | $sRoute |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | |
433 | 433 | // create the $_GET by the URL |
434 | 434 | |
435 | - foreach($aMatch as $mKey => $sResults) { |
|
435 | + foreach ($aMatch as $mKey => $sResults) { |
|
436 | 436 | |
437 | 437 | if (is_string($mKey)) { |
438 | 438 |
@@ -131,14 +131,12 @@ discard block |
||
131 | 131 | |
132 | 132 | echo file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.$_SERVER['REQUEST_URI']); |
133 | 133 | exit; |
134 | - } |
|
135 | - else if (strstr($_SERVER['REQUEST_URI'], '.css') |
|
134 | + } else if (strstr($_SERVER['REQUEST_URI'], '.css') |
|
136 | 135 | && file_exists(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.preg_replace('/\.css/', '.less', $_SERVER['REQUEST_URI']))) { |
137 | 136 | |
138 | 137 | Less::toCss(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.preg_replace('/\.css/', '.less', $_SERVER['REQUEST_URI'])); |
139 | 138 | exit; |
140 | - } |
|
141 | - else if (strstr($_SERVER['REQUEST_URI'], '.js') |
|
139 | + } else if (strstr($_SERVER['REQUEST_URI'], '.js') |
|
142 | 140 | && file_exists(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.preg_replace('/\.js/', '.ts', $_SERVER['REQUEST_URI']))) { |
143 | 141 | |
144 | 142 | Typescript::toJs(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.preg_replace('/\.js/', '.ts', $_SERVER['REQUEST_URI'])); |
@@ -167,8 +165,7 @@ discard block |
||
167 | 165 | header('Status: 301 Moved Permanently', false, 301); |
168 | 166 | header('Location: '.$oHost->location); |
169 | 167 | exit; |
170 | - } |
|
171 | - else if (preg_match('#getCss\?#', $_SERVER['REQUEST_URI'])) { |
|
168 | + } else if (preg_match('#getCss\?#', $_SERVER['REQUEST_URI'])) { |
|
172 | 169 | |
173 | 170 | foreach ($_GET as $sKey => $sValue) { |
174 | 171 | |
@@ -179,8 +176,7 @@ discard block |
||
179 | 176 | } |
180 | 177 | |
181 | 178 | exit; |
182 | - } |
|
183 | - else if (preg_match('#getJs\?#', $_SERVER['REQUEST_URI'])) { |
|
179 | + } else if (preg_match('#getJs\?#', $_SERVER['REQUEST_URI'])) { |
|
184 | 180 | |
185 | 181 | foreach ($_GET as $sKey => $sValue) { |
186 | 182 | |
@@ -191,8 +187,7 @@ discard block |
||
191 | 187 | } |
192 | 188 | |
193 | 189 | exit; |
194 | - } |
|
195 | - else if (isset($oHost->routes)) { |
|
190 | + } else if (isset($oHost->routes)) { |
|
196 | 191 | |
197 | 192 | foreach($oHost->routes as $sKey => $oRoute) { |
198 | 193 | |
@@ -201,8 +196,7 @@ discard block |
||
201 | 196 | if ($mReturn === 403) { |
202 | 197 | |
203 | 198 | $this->_getPage403(); |
204 | - } |
|
205 | - else if ($mReturn == true) { |
|
199 | + } else if ($mReturn == true) { |
|
206 | 200 | |
207 | 201 | if (isset($oRoute->cache)) { $this->_checkCache($oRoute->cache); } |
208 | 202 | |
@@ -226,11 +220,9 @@ discard block |
||
226 | 220 | // trigger_error("Votre route n'existe pas : ".$_SERVER['REQUEST_URI'], E_USER_NOTICE); |
227 | 221 | // } |
228 | 222 | } |
229 | - } |
|
230 | - else if (Request::isCliRequest()) { |
|
223 | + } else if (Request::isCliRequest()) { |
|
231 | 224 | |
232 | - if (isset($_SERVER['argv'])) { $aArguments = $_SERVER['argv']; } |
|
233 | - else { $aArguments = $argv; } |
|
225 | + if (isset($_SERVER['argv'])) { $aArguments = $_SERVER['argv']; } else { $aArguments = $argv; } |
|
234 | 226 | |
235 | 227 | define('PORTAL', 'Batch'); |
236 | 228 | set_include_path(get_include_path().PATH_SEPARATOR.'src'.PATH_SEPARATOR.PORTAL.PATH_SEPARATOR.'public'); |
@@ -240,8 +232,7 @@ discard block |
||
240 | 232 | $sBatchName = "phpunit"; |
241 | 233 | $aArguments[0] = "bin/console"; |
242 | 234 | $aArguments[1] = "phpunit"; |
243 | - } |
|
244 | - else { |
|
235 | + } else { |
|
245 | 236 | $sBatchName = $aArguments[1]; |
246 | 237 | } |
247 | 238 | |
@@ -290,8 +281,7 @@ discard block |
||
290 | 281 | if (isset($oBatch->controller) && isset($oBatch->action)) { |
291 | 282 | |
292 | 283 | echo $this->_loadController($oBatch->controller, $oBatch->action, array($aOptions)); |
293 | - } |
|
294 | - else { |
|
284 | + } else { |
|
295 | 285 | |
296 | 286 | if (Request::isCliRequest()) { |
297 | 287 | |
@@ -334,8 +324,7 @@ discard block |
||
334 | 324 | } |
335 | 325 | } |
336 | 326 | } |
337 | - } |
|
338 | - else if (defined('STDIN')) { |
|
327 | + } else if (defined('STDIN')) { |
|
339 | 328 | |
340 | 329 | $oBatch = Config::get('Route')->batch->script->{$sRoute}; |
341 | 330 | echo $this->_loadController($oBatch->controller, $oBatch->action, $aParams); |
@@ -397,8 +386,7 @@ discard block |
||
397 | 386 | }, |
398 | 387 | $sRoute |
399 | 388 | ); |
400 | - } |
|
401 | - else { |
|
389 | + } else { |
|
402 | 390 | |
403 | 391 | $sFinalRoute = '.*'; |
404 | 392 | } |
@@ -448,8 +436,7 @@ discard block |
||
448 | 436 | |
449 | 437 | $oMobileDetect = new \Mobile_Detect; |
450 | 438 | |
451 | - if ($oMobileDetect->isMobile()) { $sCacheExt = '.mobi'; } |
|
452 | - else { $sCacheExt = ''; } |
|
439 | + if ($oMobileDetect->isMobile()) { $sCacheExt = '.mobi'; } else { $sCacheExt = ''; } |
|
453 | 440 | |
454 | 441 | $mCacheReturn = Cache::get($RequestUri.$sCacheExt, $oRoute->cache->max_age); |
455 | 442 | |
@@ -472,17 +459,14 @@ discard block |
||
472 | 459 | if ($oRoute->content_type == 'json') { |
473 | 460 | |
474 | 461 | header('Content-type: application/json; charset='.$sCharset.''); |
475 | - } |
|
476 | - else if ($oRoute->content_type == 'html') { |
|
462 | + } else if ($oRoute->content_type == 'html') { |
|
477 | 463 | |
478 | 464 | header('Content-type: text/html; charset='.$sCharset.''); |
479 | - } |
|
480 | - else if ($oRoute->content_type == 'jpeg') { |
|
465 | + } else if ($oRoute->content_type == 'jpeg') { |
|
481 | 466 | |
482 | 467 | header('Content-type: image/jpeg'); |
483 | 468 | } |
484 | - } |
|
485 | - else { |
|
469 | + } else { |
|
486 | 470 | |
487 | 471 | header('Content-type: text/html; charset='.$sCharset.''); |
488 | 472 | } |
@@ -503,21 +487,17 @@ discard block |
||
503 | 487 | if (isset($_GET[$sName]) && $_GET[$sName] != '') { |
504 | 488 | |
505 | 489 | $aEntries[] = $_GET[$sName]; |
506 | - } |
|
507 | - else if (isset($oRoute->defaults_constraints) && is_object($oRoute->defaults_constraints) |
|
490 | + } else if (isset($oRoute->defaults_constraints) && is_object($oRoute->defaults_constraints) |
|
508 | 491 | && isset($oRoute->defaults_constraints->{$sName})) { |
509 | 492 | |
510 | 493 | $aEntries[] = $oRoute->defaults_constraints->{$sName}; |
511 | - } |
|
512 | - else if (isset($_GET[$sName])) { |
|
494 | + } else if (isset($_GET[$sName])) { |
|
513 | 495 | |
514 | 496 | $aEntries[] = $_GET[$sName]; |
515 | - } |
|
516 | - else if (preg_match('/'.$sType.'/', '')) { |
|
497 | + } else if (preg_match('/'.$sType.'/', '')) { |
|
517 | 498 | |
518 | 499 | $aEntries[] = ''; |
519 | - } |
|
520 | - else { |
|
500 | + } else { |
|
521 | 501 | |
522 | 502 | $this->_oLogger->warning('Error: Parameter '.$sName.' not exists!'); |
523 | 503 | break; |
@@ -529,8 +509,7 @@ discard block |
||
529 | 509 | $mReturn = $this->_loadController($oController, $sActionName, $aEntries); |
530 | 510 | |
531 | 511 | } |
532 | - } |
|
533 | - else { |
|
512 | + } else { |
|
534 | 513 | |
535 | 514 | $mReturn = $this->_loadController($oController, $sActionName, $aEntries); |
536 | 515 | } |
@@ -542,8 +521,7 @@ discard block |
||
542 | 521 | $mReturn = json_encode($mReturn, JSON_PRETTY_PRINT); |
543 | 522 | } |
544 | 523 | } |
545 | - } |
|
546 | - else if (isset($oRoute->template) && isset($oRoute->layout) && $oRoute->layout === true) { |
|
524 | + } else if (isset($oRoute->template) && isset($oRoute->layout) && $oRoute->layout === true) { |
|
547 | 525 | |
548 | 526 | define('PORTAL', preg_replace('/^\\\\Venus\\\\src\\\\([a-zA-Z0-9_]+)\\\\.+$/', '$1', $oRoute->template)); |
549 | 527 | set_include_path(get_include_path().PATH_SEPARATOR.'src'.PATH_SEPARATOR.PORTAL.PATH_SEPARATOR.'public'); |
@@ -560,8 +538,7 @@ discard block |
||
560 | 538 | |
561 | 539 | $mReturn = $oLayout->assign('model', DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.PORTAL.DIRECTORY_SEPARATOR.'View'.DIRECTORY_SEPARATOR.$oRoute->template.'.tpl') |
562 | 540 | ->fetch(); |
563 | - } |
|
564 | - else if (isset($oRoute->template)) { |
|
541 | + } else if (isset($oRoute->template)) { |
|
565 | 542 | |
566 | 543 | define('PORTAL', preg_replace('/^\\\\Venus\\\\src\\\\([a-zA-Z0-9_]+)\\\\.+$/', '$1', $oRoute->template)); |
567 | 544 | set_include_path(get_include_path().PATH_SEPARATOR.'src'.PATH_SEPARATOR.PORTAL.PATH_SEPARATOR.'public'); |
@@ -585,8 +562,7 @@ discard block |
||
585 | 562 | |
586 | 563 | $oMobileDetect = new \Mobile_Detect; |
587 | 564 | |
588 | - if ($oMobileDetect->isMobile()) { $sCacheExt = '.mobi'; } |
|
589 | - else { $sCacheExt = ''; } |
|
565 | + if ($oMobileDetect->isMobile()) { $sCacheExt = '.mobi'; } else { $sCacheExt = ''; } |
|
590 | 566 | |
591 | 567 | if (defined('COMPRESS_HTML') && COMPRESS_HTML) { |
592 | 568 | |
@@ -640,8 +616,7 @@ discard block |
||
640 | 616 | |
641 | 617 | $oMobileDetect = new \Mobile_Detect; |
642 | 618 | |
643 | - if ($oMobileDetect->isMobile()) { $sCacheExt = '.mobi'; } |
|
644 | - else { $sCacheExt = ''; } |
|
619 | + if ($oMobileDetect->isMobile()) { $sCacheExt = '.mobi'; } else { $sCacheExt = ''; } |
|
645 | 620 | |
646 | 621 | $mCacheReturn = Cache::get($sActionName.$sCacheExt, $aPhpDoc['Cache']['maxage']); |
647 | 622 | |
@@ -682,8 +657,7 @@ discard block |
||
682 | 657 | |
683 | 658 | $oMobileDetect = new \Mobile_Detect; |
684 | 659 | |
685 | - if ($oMobileDetect->isMobile()) { $sCacheExt = '.mobi'; } |
|
686 | - else { $sCacheExt = ''; } |
|
660 | + if ($oMobileDetect->isMobile()) { $sCacheExt = '.mobi'; } else { $sCacheExt = ''; } |
|
687 | 661 | |
688 | 662 | if (defined('COMPRESS_HTML') && COMPRESS_HTML) { |
689 | 663 |
@@ -63,7 +63,7 @@ |
||
63 | 63 | * check security of access |
64 | 64 | * |
65 | 65 | * @access public |
66 | - * @return void |
|
66 | + * @return null|boolean |
|
67 | 67 | */ |
68 | 68 | |
69 | 69 | public function checkSecurity() { |
@@ -95,8 +95,7 @@ discard block |
||
95 | 95 | header('HTTP/1.0 401 Unauthorized'); |
96 | 96 | echo $oSecurity->cancelled; |
97 | 97 | exit; |
98 | - } |
|
99 | - else { |
|
98 | + } else { |
|
100 | 99 | |
101 | 100 | self::$_sLogin = $_SERVER['PHP_AUTH_USER']; |
102 | 101 | self::$_sPassword = $_SERVER['PHP_AUTH_PW']; |
@@ -105,8 +104,7 @@ discard block |
||
105 | 104 | if (!$this->_checkAccess()) { return false; } |
106 | 105 | if (!$this->_checkBlackListIps()) { return false; } |
107 | 106 | } |
108 | - } |
|
109 | - else if (isset($oSecurity->authentification) && $oSecurity->authentification === 'http_basic_validate_by_controller') { |
|
107 | + } else if (isset($oSecurity->authentification) && $oSecurity->authentification === 'http_basic_validate_by_controller') { |
|
110 | 108 | |
111 | 109 | if (!isset($_SERVER['PHP_AUTH_USER'])) { |
112 | 110 | |
@@ -117,8 +115,7 @@ discard block |
||
117 | 115 | header('HTTP/1.0 401 Unauthorized'); |
118 | 116 | echo $oSecurity->cancelled; |
119 | 117 | exit; |
120 | - } |
|
121 | - else { |
|
118 | + } else { |
|
122 | 119 | |
123 | 120 | self::$_sLogin = $_SERVER['PHP_AUTH_USER']; |
124 | 121 | self::$_sPassword = $_SERVER['PHP_AUTH_PW']; |
@@ -132,8 +129,7 @@ discard block |
||
132 | 129 | if (!$this->_checkAccess()) { return false; } |
133 | 130 | if (!$this->_checkBlackListIps()) { return false; } |
134 | 131 | } |
135 | - } |
|
136 | - else if (isset($oSecurity->authentification) && $oSecurity->authentification === 'controller') { |
|
132 | + } else if (isset($oSecurity->authentification) && $oSecurity->authentification === 'controller') { |
|
137 | 133 | |
138 | 134 | // it's an action of one controller that it return true or false for the authentification |
139 | 135 | |
@@ -152,8 +148,7 @@ discard block |
||
152 | 148 | if (isset($oSecurity->requires_channel) && $oSecurity->requires_channel == 'https' && !Request::isHttpsRequest()) { |
153 | 149 | |
154 | 150 | return false; |
155 | - } |
|
156 | - else if (isset($oSecurity->requires_channel) && $oSecurity->requires_channel == 'http' && ((Request::isHttpRequest() |
|
151 | + } else if (isset($oSecurity->requires_channel) && $oSecurity->requires_channel == 'http' && ((Request::isHttpRequest() |
|
157 | 152 | && Request::isHttpsRequest()) || !Request::isHttpRequest())) { |
158 | 153 | |
159 | 154 | return false; |
@@ -180,8 +175,7 @@ discard block |
||
180 | 175 | |
181 | 176 | if (preg_match('#'.$sPathAccess.'#', str_replace($this->_sBaseUri, '', $_SERVER['REQUEST_URI']))) { |
182 | 177 | |
183 | - if (in_array($this->getUserRole(), $aParams->roles)) { return true; } |
|
184 | - else { return false; } |
|
178 | + if (in_array($this->getUserRole(), $aParams->roles)) { return true; } else { return false; } |
|
185 | 179 | } |
186 | 180 | } |
187 | 181 | } |
@@ -223,9 +217,7 @@ discard block |
||
223 | 217 | $sLogin = self::$_sLogin; |
224 | 218 | $sPassword = Config::get('Security')->users->$sLogin->password; |
225 | 219 | |
226 | - if ($sPassword == self::$_sPassword) { return true; } |
|
227 | - else if ($sPassword == md5(self::$_sPassword)) { return true; } |
|
228 | - else { return false; } |
|
220 | + if ($sPassword == self::$_sPassword) { return true; } else if ($sPassword == md5(self::$_sPassword)) { return true; } else { return false; } |
|
229 | 221 | } |
230 | 222 | |
231 | 223 | /** |
@@ -241,8 +233,7 @@ discard block |
||
241 | 233 | |
242 | 234 | $sLogin = self::$_sLogin; |
243 | 235 | return Config::get('Security')->users->$sLogin->roles; |
244 | - } |
|
245 | - else { |
|
236 | + } else { |
|
246 | 237 | |
247 | 238 | return ''; |
248 | 239 | } |
@@ -259,8 +250,7 @@ discard block |
||
259 | 250 | |
260 | 251 | public function isGranted(string $sRole) : bool { |
261 | 252 | |
262 | - if ($sRole == $this->getUserRole() || $this->getUserRole() == '') { return true; } |
|
263 | - else { return false; } |
|
253 | + if ($sRole == $this->getUserRole() || $this->getUserRole() == '') { return true; } else { return false; } |
|
264 | 254 | } |
265 | 255 | |
266 | 256 | /** |
@@ -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) { |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | * |
98 | 98 | * @access public |
99 | 99 | * @param string $sName name of the session |
100 | - * @return mixed |
|
100 | + * @return boolean |
|
101 | 101 | */ |
102 | 102 | public function delete(string $sName) |
103 | 103 | { |
@@ -108,7 +108,6 @@ discard block |
||
108 | 108 | * flush the cache |
109 | 109 | * |
110 | 110 | * @access public |
111 | - * @param string $sName name of the session |
|
112 | 111 | * @return mixed |
113 | 112 | */ |
114 | 113 | public function flush() |
@@ -121,7 +120,7 @@ discard block |
||
121 | 120 | * |
122 | 121 | * @access public |
123 | 122 | * @param string $sName name of the session |
124 | - * @return mixed |
|
123 | + * @return string |
|
125 | 124 | */ |
126 | 125 | private function _getSubDirectory($sName) |
127 | 126 | { |
@@ -85,8 +85,7 @@ discard block |
||
85 | 85 | if (file_exists($this->_sFolder.$this->_getSubDirectory($sName).md5($sName).'.fil.cac')) { |
86 | 86 | |
87 | 87 | return unserialize(file_get_contents($this->_sFolder.$this->_getSubDirectory($sName).md5($sName).'.fil.cac')); |
88 | - } |
|
89 | - else { |
|
88 | + } else { |
|
90 | 89 | |
91 | 90 | return false; |
92 | 91 | } |
@@ -146,8 +145,7 @@ discard block |
||
146 | 145 | |
147 | 146 | while (($sFile = readdir($rDirectory)) !== false) { |
148 | 147 | |
149 | - if ($sFile > '0' and filetype($sName.$sFile) == "file") { unlink($sName.$sFile); } |
|
150 | - elseif ($sFile > '0' and filetype($sName.$sFile) == "dir") { remove_dir($sName.$sFile."\\"); } |
|
148 | + if ($sFile > '0' and filetype($sName.$sFile) == "file") { unlink($sName.$sFile); } elseif ($sFile > '0' and filetype($sName.$sFile) == "dir") { remove_dir($sName.$sFile."\\"); } |
|
151 | 149 | } |
152 | 150 | |
153 | 151 | closedir($rDirectory); |
@@ -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 | } |
@@ -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 | } |