@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Downloads an avatar or attachment based on $_GET['attach'], and increments the download count. |
@@ -40,11 +41,11 @@ discard block |
||
40 | 41 | |
41 | 42 | if (!empty($modSettings['enableCompressedOutput']) && !headers_sent() && ob_get_length() == 0) |
42 | 43 | { |
43 | - if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') == 'ob_gzhandler') |
|
44 | - $modSettings['enableCompressedOutput'] = 0; |
|
45 | - |
|
46 | - else |
|
47 | - ob_start('ob_gzhandler'); |
|
44 | + if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') == 'ob_gzhandler') { |
|
45 | + $modSettings['enableCompressedOutput'] = 0; |
|
46 | + } else { |
|
47 | + ob_start('ob_gzhandler'); |
|
48 | + } |
|
48 | 49 | } |
49 | 50 | |
50 | 51 | if (empty($modSettings['enableCompressedOutput'])) |
@@ -76,8 +77,9 @@ discard block |
||
76 | 77 | } |
77 | 78 | |
78 | 79 | // Use cache when possible. |
79 | - if (($cache = cache_get_data('attachment_lookup_id-' . $attachId)) != null) |
|
80 | - list($file, $thumbFile) = $cache; |
|
80 | + if (($cache = cache_get_data('attachment_lookup_id-' . $attachId)) != null) { |
|
81 | + list($file, $thumbFile) = $cache; |
|
82 | + } |
|
81 | 83 | |
82 | 84 | // Get the info from the DB. |
83 | 85 | if (empty($file) || empty($thumbFile) && !empty($file['id_thumb'])) |
@@ -85,10 +87,9 @@ discard block |
||
85 | 87 | // Do we have a hook wanting to use our attachment system? We use $attachRequest to prevent accidental usage of $request. |
86 | 88 | $attachRequest = null; |
87 | 89 | call_integration_hook('integrate_download_request', array(&$attachRequest)); |
88 | - if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) |
|
89 | - $request = $attachRequest; |
|
90 | - |
|
91 | - else |
|
90 | + if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) { |
|
91 | + $request = $attachRequest; |
|
92 | + } else |
|
92 | 93 | { |
93 | 94 | // Make sure this attachment is on this board and load its info while we are at it. |
94 | 95 | $request = $smcFunc['db_query']('', ' |
@@ -181,13 +182,15 @@ discard block |
||
181 | 182 | } |
182 | 183 | |
183 | 184 | // Cache it. |
184 | - if (!empty($file) || !empty($thumbFile)) |
|
185 | - cache_put_data('attachment_lookup_id-' . $file['id_attach'], array($file, $thumbFile), mt_rand(850, 900)); |
|
185 | + if (!empty($file) || !empty($thumbFile)) { |
|
186 | + cache_put_data('attachment_lookup_id-' . $file['id_attach'], array($file, $thumbFile), mt_rand(850, 900)); |
|
187 | + } |
|
186 | 188 | } |
187 | 189 | |
188 | 190 | // Replace the normal file with its thumbnail if it has one! |
189 | - if (!empty($showThumb) && !empty($thumbFile)) |
|
190 | - $file = $thumbFile; |
|
191 | + if (!empty($showThumb) && !empty($thumbFile)) { |
|
192 | + $file = $thumbFile; |
|
193 | + } |
|
191 | 194 | |
192 | 195 | // No point in a nicer message, because this is supposed to be an attachment anyway... |
193 | 196 | if (!file_exists($file['filePath'])) |
@@ -237,8 +240,8 @@ discard block |
||
237 | 240 | } |
238 | 241 | |
239 | 242 | // Update the download counter (unless it's a thumbnail or resuming an incomplete download). |
240 | - if ($file['attachment_type'] != 3 && empty($showThumb) && $range === 0) |
|
241 | - $smcFunc['db_query']('', ' |
|
243 | + if ($file['attachment_type'] != 3 && empty($showThumb) && $range === 0) { |
|
244 | + $smcFunc['db_query']('', ' |
|
242 | 245 | UPDATE {db_prefix}attachments |
243 | 246 | SET downloads = downloads + 1 |
244 | 247 | WHERE id_attach = {int:id_attach}', |
@@ -246,12 +249,14 @@ discard block |
||
246 | 249 | 'id_attach' => $attachId, |
247 | 250 | ) |
248 | 251 | ); |
252 | + } |
|
249 | 253 | |
250 | 254 | // Send the attachment headers. |
251 | 255 | header('pragma: '); |
252 | 256 | |
253 | - if (!isBrowser('gecko')) |
|
254 | - header('content-transfer-encoding: binary'); |
|
257 | + if (!isBrowser('gecko')) { |
|
258 | + header('content-transfer-encoding: binary'); |
|
259 | + } |
|
255 | 260 | |
256 | 261 | header('expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT'); |
257 | 262 | header('last-modified: ' . gmdate('D, d M Y H:i:s', filemtime($file['filePath'])) . ' GMT'); |
@@ -260,18 +265,19 @@ discard block |
||
260 | 265 | header('etag: ' . $eTag); |
261 | 266 | |
262 | 267 | // Make sure the mime type warrants an inline display. |
263 | - if (isset($_REQUEST['image']) && !empty($file['mime_type']) && strpos($file['mime_type'], 'image/') !== 0) |
|
264 | - unset($_REQUEST['image']); |
|
268 | + if (isset($_REQUEST['image']) && !empty($file['mime_type']) && strpos($file['mime_type'], 'image/') !== 0) { |
|
269 | + unset($_REQUEST['image']); |
|
270 | + } |
|
265 | 271 | |
266 | 272 | // Does this have a mime type? |
267 | - elseif (!empty($file['mime_type']) && (isset($_REQUEST['image']) || !in_array($file['fileext'], array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) |
|
268 | - header('content-type: ' . strtr($file['mime_type'], array('image/bmp' => 'image/x-ms-bmp'))); |
|
269 | - |
|
270 | - else |
|
273 | + elseif (!empty($file['mime_type']) && (isset($_REQUEST['image']) || !in_array($file['fileext'], array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) { |
|
274 | + header('content-type: ' . strtr($file['mime_type'], array('image/bmp' => 'image/x-ms-bmp'))); |
|
275 | + } else |
|
271 | 276 | { |
272 | 277 | header('content-type: ' . (isBrowser('ie') || isBrowser('opera') ? 'application/octetstream' : 'application/octet-stream')); |
273 | - if (isset($_REQUEST['image'])) |
|
274 | - unset($_REQUEST['image']); |
|
278 | + if (isset($_REQUEST['image'])) { |
|
279 | + unset($_REQUEST['image']); |
|
280 | + } |
|
275 | 281 | } |
276 | 282 | |
277 | 283 | // Convert the file to UTF-8, cuz most browsers dig that. |
@@ -279,24 +285,22 @@ discard block |
||
279 | 285 | $disposition = !isset($_REQUEST['image']) ? 'attachment' : 'inline'; |
280 | 286 | |
281 | 287 | // Different browsers like different standards... |
282 | - if (isBrowser('firefox')) |
|
283 | - header('content-disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name))); |
|
284 | - |
|
285 | - elseif (isBrowser('opera')) |
|
286 | - header('content-disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"'); |
|
287 | - |
|
288 | - elseif (isBrowser('ie')) |
|
289 | - header('content-disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"'); |
|
290 | - |
|
291 | - else |
|
292 | - header('content-disposition: ' . $disposition . '; filename="' . $utf8name . '"'); |
|
288 | + if (isBrowser('firefox')) { |
|
289 | + header('content-disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name))); |
|
290 | + } elseif (isBrowser('opera')) { |
|
291 | + header('content-disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"'); |
|
292 | + } elseif (isBrowser('ie')) { |
|
293 | + header('content-disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"'); |
|
294 | + } else { |
|
295 | + header('content-disposition: ' . $disposition . '; filename="' . $utf8name . '"'); |
|
296 | + } |
|
293 | 297 | |
294 | 298 | // If this has an "image extension" - but isn't actually an image - then ensure it isn't cached cause of silly IE. |
295 | - if (!isset($_REQUEST['image']) && in_array($file['fileext'], array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) |
|
296 | - header('cache-control: no-cache'); |
|
297 | - |
|
298 | - else |
|
299 | - header('cache-control: max-age=' . (525600 * 60) . ', private'); |
|
299 | + if (!isset($_REQUEST['image']) && in_array($file['fileext'], array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) { |
|
300 | + header('cache-control: no-cache'); |
|
301 | + } else { |
|
302 | + header('cache-control: max-age=' . (525600 * 60) . ', private'); |
|
303 | + } |
|
300 | 304 | |
301 | 305 | // Multipart and resuming support |
302 | 306 | if (isset($_SERVER['HTTP_RANGE'])) |
@@ -304,9 +308,9 @@ discard block |
||
304 | 308 | header("HTTP/1.1 206 Partial Content"); |
305 | 309 | header("content-length: $new_length"); |
306 | 310 | header("content-range: bytes $range-$range_end/$size"); |
311 | + } else { |
|
312 | + header("content-length: " . $size); |
|
307 | 313 | } |
308 | - else |
|
309 | - header("content-length: " . $size); |
|
310 | 314 | |
311 | 315 | |
312 | 316 | // Try to buy some time... |
@@ -315,8 +319,9 @@ discard block |
||
315 | 319 | // For multipart/resumable downloads, send the requested chunk(s) of the file |
316 | 320 | if (isset($_SERVER['HTTP_RANGE'])) |
317 | 321 | { |
318 | - while (@ob_get_level() > 0) |
|
319 | - @ob_end_clean(); |
|
322 | + while (@ob_get_level() > 0) { |
|
323 | + @ob_end_clean(); |
|
324 | + } |
|
320 | 325 | |
321 | 326 | // 40 kilobytes is a good-ish amount |
322 | 327 | $chunksize = 40 * 1024; |
@@ -340,8 +345,9 @@ discard block |
||
340 | 345 | elseif ($size > 4194304) |
341 | 346 | { |
342 | 347 | // Forcibly end any output buffering going on. |
343 | - while (@ob_get_level() > 0) |
|
344 | - @ob_end_clean(); |
|
348 | + while (@ob_get_level() > 0) { |
|
349 | + @ob_end_clean(); |
|
350 | + } |
|
345 | 351 | |
346 | 352 | $fp = fopen($file['filePath'], 'rb'); |
347 | 353 | while (!feof($fp)) |
@@ -353,8 +359,9 @@ discard block |
||
353 | 359 | } |
354 | 360 | |
355 | 361 | // On some of the less-bright hosts, readfile() is disabled. It's just a faster, more byte safe, version of what's in the if. |
356 | - elseif (@readfile($file['filePath']) === null) |
|
357 | - echo file_get_contents($file['filePath']); |
|
362 | + elseif (@readfile($file['filePath']) === null) { |
|
363 | + echo file_get_contents($file['filePath']); |
|
364 | + } |
|
358 | 365 | |
359 | 366 | die(); |
360 | 367 | } |
@@ -17,8 +17,9 @@ discard block |
||
17 | 17 | * @version 2.1 Beta 4 |
18 | 18 | */ |
19 | 19 | |
20 | -if (!defined('SMF')) |
|
20 | +if (!defined('SMF')) { |
|
21 | 21 | die('No direct access...'); |
22 | +} |
|
22 | 23 | |
23 | 24 | /** |
24 | 25 | * Attempt to start the session, unless it already has been. |
@@ -38,8 +39,9 @@ discard block |
||
38 | 39 | { |
39 | 40 | $parsed_url = parse_url($boardurl); |
40 | 41 | |
41 | - if (preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) |
|
42 | - @ini_set('session.cookie_domain', '.' . $parts[1]); |
|
42 | + if (preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) { |
|
43 | + @ini_set('session.cookie_domain', '.' . $parts[1]); |
|
44 | + } |
|
43 | 45 | } |
44 | 46 | // @todo Set the session cookie path? |
45 | 47 | |
@@ -47,8 +49,9 @@ discard block |
||
47 | 49 | if ((ini_get('session.auto_start') == 1 && !empty($modSettings['databaseSession_enable'])) || session_id() == '') |
48 | 50 | { |
49 | 51 | // Attempt to end the already-started session. |
50 | - if (ini_get('session.auto_start') == 1) |
|
51 | - session_write_close(); |
|
52 | + if (ini_get('session.auto_start') == 1) { |
|
53 | + session_write_close(); |
|
54 | + } |
|
52 | 55 | |
53 | 56 | // This is here to stop people from using bad junky PHPSESSIDs. |
54 | 57 | if (isset($_REQUEST[session_name()]) && preg_match('~^[A-Za-z0-9,-]{16,64}$~', $_REQUEST[session_name()]) == 0 && !isset($_COOKIE[session_name()])) |
@@ -63,23 +66,26 @@ discard block |
||
63 | 66 | if (!empty($modSettings['databaseSession_enable'])) |
64 | 67 | { |
65 | 68 | @ini_set('session.serialize_handler', 'php_serialize'); |
66 | - if (ini_get('session.serialize_handler') != 'php_serialize') |
|
67 | - @ini_set('session.serialize_handler', 'php'); |
|
69 | + if (ini_get('session.serialize_handler') != 'php_serialize') { |
|
70 | + @ini_set('session.serialize_handler', 'php'); |
|
71 | + } |
|
68 | 72 | session_set_save_handler('sessionOpen', 'sessionClose', 'sessionRead', 'sessionWrite', 'sessionDestroy', 'sessionGC'); |
69 | 73 | @ini_set('session.gc_probability', '1'); |
74 | + } elseif (ini_get('session.gc_maxlifetime') <= 1440 && !empty($modSettings['databaseSession_lifetime'])) { |
|
75 | + @ini_set('session.gc_maxlifetime', max($modSettings['databaseSession_lifetime'], 60)); |
|
70 | 76 | } |
71 | - elseif (ini_get('session.gc_maxlifetime') <= 1440 && !empty($modSettings['databaseSession_lifetime'])) |
|
72 | - @ini_set('session.gc_maxlifetime', max($modSettings['databaseSession_lifetime'], 60)); |
|
73 | 77 | |
74 | 78 | // Use cache setting sessions? |
75 | - if (empty($modSettings['databaseSession_enable']) && !empty($modSettings['cache_enable']) && php_sapi_name() != 'cli') |
|
76 | - call_integration_hook('integrate_session_handlers'); |
|
79 | + if (empty($modSettings['databaseSession_enable']) && !empty($modSettings['cache_enable']) && php_sapi_name() != 'cli') { |
|
80 | + call_integration_hook('integrate_session_handlers'); |
|
81 | + } |
|
77 | 82 | |
78 | 83 | session_start(); |
79 | 84 | |
80 | 85 | // Change it so the cache settings are a little looser than default. |
81 | - if (!empty($modSettings['databaseSession_loose'])) |
|
82 | - header('cache-control: private'); |
|
86 | + if (!empty($modSettings['databaseSession_loose'])) { |
|
87 | + header('cache-control: private'); |
|
88 | + } |
|
83 | 89 | } |
84 | 90 | |
85 | 91 | // Set the randomly generated code. |
@@ -125,8 +131,9 @@ discard block |
||
125 | 131 | { |
126 | 132 | global $smcFunc; |
127 | 133 | |
128 | - if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) |
|
129 | - return ''; |
|
134 | + if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) { |
|
135 | + return ''; |
|
136 | + } |
|
130 | 137 | |
131 | 138 | // Look for it in the database. |
132 | 139 | $result = $smcFunc['db_query']('', ' |
@@ -155,8 +162,9 @@ discard block |
||
155 | 162 | { |
156 | 163 | global $smcFunc; |
157 | 164 | |
158 | - if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) |
|
159 | - return false; |
|
165 | + if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) { |
|
166 | + return false; |
|
167 | + } |
|
160 | 168 | |
161 | 169 | // First try to update an existing row... |
162 | 170 | $smcFunc['db_query']('', ' |
@@ -171,13 +179,14 @@ discard block |
||
171 | 179 | ); |
172 | 180 | |
173 | 181 | // If that didn't work, try inserting a new one. |
174 | - if ($smcFunc['db_affected_rows']() == 0) |
|
175 | - $smcFunc['db_insert']('ignore', |
|
182 | + if ($smcFunc['db_affected_rows']() == 0) { |
|
183 | + $smcFunc['db_insert']('ignore', |
|
176 | 184 | '{db_prefix}sessions', |
177 | 185 | array('session_id' => 'string', 'data' => 'string', 'last_update' => 'int'), |
178 | 186 | array($session_id, $data, time()), |
179 | 187 | array('session_id') |
180 | 188 | ); |
189 | + } |
|
181 | 190 | |
182 | 191 | return ($smcFunc['db_affected_rows']() == 0 ? false : true); |
183 | 192 | } |
@@ -192,8 +201,9 @@ discard block |
||
192 | 201 | { |
193 | 202 | global $smcFunc; |
194 | 203 | |
195 | - if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) |
|
196 | - return false; |
|
204 | + if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) { |
|
205 | + return false; |
|
206 | + } |
|
197 | 207 | |
198 | 208 | // Just delete the row... |
199 | 209 | $smcFunc['db_query']('', ' |
@@ -219,8 +229,9 @@ discard block |
||
219 | 229 | global $modSettings, $smcFunc; |
220 | 230 | |
221 | 231 | // Just set to the default or lower? Ignore it for a higher value. (hopefully) |
222 | - if (!empty($modSettings['databaseSession_lifetime']) && ($max_lifetime <= 1440 || $modSettings['databaseSession_lifetime'] > $max_lifetime)) |
|
223 | - $max_lifetime = max($modSettings['databaseSession_lifetime'], 60); |
|
232 | + if (!empty($modSettings['databaseSession_lifetime']) && ($max_lifetime <= 1440 || $modSettings['databaseSession_lifetime'] > $max_lifetime)) { |
|
233 | + $max_lifetime = max($modSettings['databaseSession_lifetime'], 60); |
|
234 | + } |
|
224 | 235 | |
225 | 236 | // Clean up after yerself ;). |
226 | 237 | $smcFunc['db_query']('', ' |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | // Just send a generic message. |
77 | 77 | else |
78 | 78 | $this->setResponse(array( |
79 | - 'text' => $this->_sa == 'add' ? 'attach_error_title' : 'attached_file_deleted_error', |
|
79 | + 'text' => $this->_sa == 'add' ? 'attach_error_title' : 'attached_file_deleted_error', |
|
80 | 80 | 'type' => 'error', |
81 | 81 | 'data' => false, |
82 | 82 | )); |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | // Gotta urlencode the filename. |
411 | 411 | if ($this->_attachResults) |
412 | 412 | foreach ($this->_attachResults as $k => $v) |
413 | - $this->_attachResults[$k]['name'] = urlencode($this->_attachResults[$k]['name']); |
|
413 | + $this->_attachResults[$k]['name'] = urlencode($this->_attachResults[$k]['name']); |
|
414 | 414 | |
415 | 415 | $this->_response = array( |
416 | 416 | 'files' => $this->_attachResults ? $this->_attachResults : false, |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | ob_start(); |
438 | 438 | |
439 | 439 | // Set the header. |
440 | - header('content-type: application/json; charset='. $context['character_set'] .''); |
|
440 | + header('content-type: application/json; charset=' . $context['character_set'] . ''); |
|
441 | 441 | |
442 | 442 | echo $smcFunc['json_encode']($this->_response ? $this->_response : array()); |
443 | 443 |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | class Attachments |
20 | 21 | { |
@@ -70,16 +71,18 @@ discard block |
||
70 | 71 | |
71 | 72 | $this->_sa = !empty($_REQUEST['sa']) ? $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($_REQUEST['sa'])) : false; |
72 | 73 | |
73 | - if ($this->_canPostAttachment && $this->_sa && in_array($this->_sa, $this->_subActions)) |
|
74 | - $this->{$this->_sa}(); |
|
74 | + if ($this->_canPostAttachment && $this->_sa && in_array($this->_sa, $this->_subActions)) { |
|
75 | + $this->{$this->_sa}(); |
|
76 | + } |
|
75 | 77 | |
76 | 78 | // Just send a generic message. |
77 | - else |
|
78 | - $this->setResponse(array( |
|
79 | + else { |
|
80 | + $this->setResponse(array( |
|
79 | 81 | 'text' => $this->_sa == 'add' ? 'attach_error_title' : 'attached_file_deleted_error', |
80 | 82 | 'type' => 'error', |
81 | 83 | 'data' => false, |
82 | 84 | )); |
85 | + } |
|
83 | 86 | |
84 | 87 | // Back to the future, oh, to the browser! |
85 | 88 | $this->sendResponse(); |
@@ -95,12 +98,13 @@ discard block |
||
95 | 98 | $attachID = !empty($_REQUEST['attach']) && is_numeric($_REQUEST['attach']) ? (int) $_REQUEST['attach'] : 0; |
96 | 99 | |
97 | 100 | // Need something to work with. |
98 | - if (!$attachID || (!empty($_SESSION['already_attached']) && !isset($_SESSION['already_attached'][$attachID]))) |
|
99 | - return $this->setResponse(array( |
|
101 | + if (!$attachID || (!empty($_SESSION['already_attached']) && !isset($_SESSION['already_attached'][$attachID]))) { |
|
102 | + return $this->setResponse(array( |
|
100 | 103 | 'text' => 'attached_file_deleted_error', |
101 | 104 | 'type' => 'error', |
102 | 105 | 'data' => false, |
103 | 106 | )); |
107 | + } |
|
104 | 108 | |
105 | 109 | // Lets pass some params and see what happens :P |
106 | 110 | $affectedMessage = removeAttachments(array('id_attach' => $attachID), '', true, true); |
@@ -119,19 +123,21 @@ discard block |
||
119 | 123 | public function add() |
120 | 124 | { |
121 | 125 | // You gotta be able to post attachments. |
122 | - if (!$this->_canPostAttachment) |
|
123 | - return $this->setResponse(array( |
|
126 | + if (!$this->_canPostAttachment) { |
|
127 | + return $this->setResponse(array( |
|
124 | 128 | 'text' => 'attached_file_cannot', |
125 | 129 | 'type' => 'error', |
126 | 130 | 'data' => false, |
127 | 131 | )); |
132 | + } |
|
128 | 133 | |
129 | 134 | // Process them at once! |
130 | 135 | $this->processAttachments(); |
131 | 136 | |
132 | 137 | // The attachments was created and moved the the right folder, time to update the DB. |
133 | - if (!empty($_SESSION['temp_attachments'])) |
|
134 | - $this->createAtttach(); |
|
138 | + if (!empty($_SESSION['temp_attachments'])) { |
|
139 | + $this->createAtttach(); |
|
140 | + } |
|
135 | 141 | |
136 | 142 | // Set the response. |
137 | 143 | $this->setResponse(); |
@@ -144,8 +150,9 @@ discard block |
||
144 | 150 | { |
145 | 151 | global $context, $modSettings, $smcFunc, $user_info, $txt; |
146 | 152 | |
147 | - if (!isset($_FILES['attachment']['name'])) |
|
148 | - $_FILES['attachment']['tmp_name'] = array(); |
|
153 | + if (!isset($_FILES['attachment']['name'])) { |
|
154 | + $_FILES['attachment']['tmp_name'] = array(); |
|
155 | + } |
|
149 | 156 | |
150 | 157 | // If there are attachments, calculate the total size and how many. |
151 | 158 | $context['attachments']['total_size'] = 0; |
@@ -155,25 +162,30 @@ discard block |
||
155 | 162 | if (isset($_REQUEST['msg'])) |
156 | 163 | { |
157 | 164 | $context['attachments']['quantity'] = count($context['current_attachments']); |
158 | - foreach ($context['current_attachments'] as $attachment) |
|
159 | - $context['attachments']['total_size'] += $attachment['size']; |
|
165 | + foreach ($context['current_attachments'] as $attachment) { |
|
166 | + $context['attachments']['total_size'] += $attachment['size']; |
|
167 | + } |
|
160 | 168 | } |
161 | 169 | |
162 | 170 | // A bit of house keeping first. |
163 | - if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) |
|
164 | - unset($_SESSION['temp_attachments']); |
|
171 | + if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) { |
|
172 | + unset($_SESSION['temp_attachments']); |
|
173 | + } |
|
165 | 174 | |
166 | 175 | // Our infamous SESSION var, we are gonna have soo much fun with it! |
167 | - if (!isset($_SESSION['temp_attachments'])) |
|
168 | - $_SESSION['temp_attachments'] = array(); |
|
176 | + if (!isset($_SESSION['temp_attachments'])) { |
|
177 | + $_SESSION['temp_attachments'] = array(); |
|
178 | + } |
|
169 | 179 | |
170 | 180 | // Make sure we're uploading to the right place. |
171 | - if (!empty($modSettings['automanage_attachments'])) |
|
172 | - automanage_attachments_check_directory(); |
|
181 | + if (!empty($modSettings['automanage_attachments'])) { |
|
182 | + automanage_attachments_check_directory(); |
|
183 | + } |
|
173 | 184 | |
174 | 185 | // Is the attachments folder actually there? |
175 | - if (!empty($context['dir_creation_error'])) |
|
176 | - $this->_generalErrors[] = $context['dir_creation_error']; |
|
186 | + if (!empty($context['dir_creation_error'])) { |
|
187 | + $this->_generalErrors[] = $context['dir_creation_error']; |
|
188 | + } |
|
177 | 189 | |
178 | 190 | // The current attach folder ha some issues... |
179 | 191 | elseif (!is_dir($this->_attchDir)) |
@@ -198,13 +210,12 @@ discard block |
||
198 | 210 | ); |
199 | 211 | list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request); |
200 | 212 | $smcFunc['db_free_result']($request); |
201 | - } |
|
202 | - |
|
203 | - else |
|
204 | - $context['attachments'] = array( |
|
213 | + } else { |
|
214 | + $context['attachments'] = array( |
|
205 | 215 | 'quantity' => 0, |
206 | 216 | 'total_size' => 0, |
207 | 217 | ); |
218 | + } |
|
208 | 219 | |
209 | 220 | // Check for other general errors here. |
210 | 221 | |
@@ -212,9 +223,10 @@ discard block |
||
212 | 223 | if (!empty($this->_generalErrors)) |
213 | 224 | { |
214 | 225 | // And delete the files 'cos they ain't going nowhere. |
215 | - foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) |
|
216 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
226 | + foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) { |
|
227 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
217 | 228 | unlink($_FILES['attachment']['tmp_name'][$n]); |
229 | + } |
|
218 | 230 | |
219 | 231 | $_FILES['attachment']['tmp_name'] = array(); |
220 | 232 | |
@@ -225,26 +237,29 @@ discard block |
||
225 | 237 | // Loop through $_FILES['attachment'] array and move each file to the current attachments folder. |
226 | 238 | foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) |
227 | 239 | { |
228 | - if ($_FILES['attachment']['name'][$n] == '') |
|
229 | - continue; |
|
240 | + if ($_FILES['attachment']['name'][$n] == '') { |
|
241 | + continue; |
|
242 | + } |
|
230 | 243 | |
231 | 244 | // First, let's first check for PHP upload errors. |
232 | 245 | $errors = array(); |
233 | 246 | if (!empty($_FILES['attachment']['error'][$n])) |
234 | 247 | { |
235 | - if ($_FILES['attachment']['error'][$n] == 2) |
|
236 | - $errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit'])); |
|
237 | - |
|
238 | - else |
|
239 | - log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]); |
|
248 | + if ($_FILES['attachment']['error'][$n] == 2) { |
|
249 | + $errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit'])); |
|
250 | + } else { |
|
251 | + log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]); |
|
252 | + } |
|
240 | 253 | |
241 | 254 | // Log this one, because... |
242 | - if ($_FILES['attachment']['error'][$n] == 6) |
|
243 | - log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical'); |
|
255 | + if ($_FILES['attachment']['error'][$n] == 6) { |
|
256 | + log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical'); |
|
257 | + } |
|
244 | 258 | |
245 | 259 | // Weird, no errors were cached, still fill out a generic one. |
246 | - if (empty($errors)) |
|
247 | - $errors[] = 'attach_php_error'; |
|
260 | + if (empty($errors)) { |
|
261 | + $errors[] = 'attach_php_error'; |
|
262 | + } |
|
248 | 263 | } |
249 | 264 | |
250 | 265 | // Try to move and rename the file before doing any more checks on it. |
@@ -256,8 +271,9 @@ discard block |
||
256 | 271 | { |
257 | 272 | // The reported MIME type of the attachment might not be reliable. |
258 | 273 | // Fortunately, PHP 5.3+ lets us easily verify the real MIME type. |
259 | - if (function_exists('mime_content_type')) |
|
260 | - $_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]); |
|
274 | + if (function_exists('mime_content_type')) { |
|
275 | + $_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]); |
|
276 | + } |
|
261 | 277 | |
262 | 278 | $_SESSION['temp_attachments'][$attachID] = array( |
263 | 279 | 'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])), |
@@ -269,16 +285,18 @@ discard block |
||
269 | 285 | ); |
270 | 286 | |
271 | 287 | // Move the file to the attachments folder with a temp name for now. |
272 | - if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) |
|
273 | - smf_chmod($destName, 0644); |
|
288 | + if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) { |
|
289 | + smf_chmod($destName, 0644); |
|
290 | + } |
|
274 | 291 | |
275 | 292 | // This is madness!! |
276 | 293 | else |
277 | 294 | { |
278 | 295 | // File couldn't be moved. |
279 | 296 | $_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout'; |
280 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
281 | - unlink($_FILES['attachment']['tmp_name'][$n]); |
|
297 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) { |
|
298 | + unlink($_FILES['attachment']['tmp_name'][$n]); |
|
299 | + } |
|
282 | 300 | } |
283 | 301 | } |
284 | 302 | |
@@ -291,13 +309,15 @@ discard block |
||
291 | 309 | 'errors' => $errors, |
292 | 310 | ); |
293 | 311 | |
294 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
295 | - unlink($_FILES['attachment']['tmp_name'][$n]); |
|
312 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) { |
|
313 | + unlink($_FILES['attachment']['tmp_name'][$n]); |
|
314 | + } |
|
296 | 315 | } |
297 | 316 | |
298 | 317 | // If there's no errors to this point. We still do need to apply some additional checks before we are finished. |
299 | - if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) |
|
300 | - attachmentChecks($attachID); |
|
318 | + if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) { |
|
319 | + attachmentChecks($attachID); |
|
320 | + } |
|
301 | 321 | } |
302 | 322 | |
303 | 323 | // Mod authors, finally a hook to hang an alternate attachment upload system upon |
@@ -344,14 +364,15 @@ discard block |
||
344 | 364 | |
345 | 365 | $_SESSION['already_attached'][$attachmentOptions['attachID']] = $attachmentOptions['attachID']; |
346 | 366 | |
347 | - if (!empty($attachmentOptions['thumb'])) |
|
348 | - $_SESSION['already_attached'][$attachmentOptions['thumb']] = $attachmentOptions['thumb']; |
|
367 | + if (!empty($attachmentOptions['thumb'])) { |
|
368 | + $_SESSION['already_attached'][$attachmentOptions['thumb']] = $attachmentOptions['thumb']; |
|
369 | + } |
|
349 | 370 | |
350 | - if ($this->_msg) |
|
351 | - assignAttachments($_SESSION['already_attached'], $this->_msg); |
|
371 | + if ($this->_msg) { |
|
372 | + assignAttachments($_SESSION['already_attached'], $this->_msg); |
|
373 | + } |
|
352 | 374 | } |
353 | - } |
|
354 | - else |
|
375 | + } else |
|
355 | 376 | { |
356 | 377 | // Sort out the errors for display and delete any associated files. |
357 | 378 | $log_these = array('attachments_no_create', 'attachments_no_write', 'attach_timeout', 'ran_out_of_space', 'cant_access_upload_path', 'attach_0_byte_file'); |
@@ -363,14 +384,16 @@ discard block |
||
363 | 384 | if (!is_array($error)) |
364 | 385 | { |
365 | 386 | $attachmentOptions['errors'][] = $txt[$error]; |
366 | - if (in_array($error, $log_these)) |
|
367 | - log_error($attachment['name'] . ': ' . $txt[$error], 'critical'); |
|
387 | + if (in_array($error, $log_these)) { |
|
388 | + log_error($attachment['name'] . ': ' . $txt[$error], 'critical'); |
|
389 | + } |
|
390 | + } else { |
|
391 | + $attachmentOptions['errors'][] = vsprintf($txt[$error[0]], $error[1]); |
|
368 | 392 | } |
369 | - else |
|
370 | - $attachmentOptions['errors'][] = vsprintf($txt[$error[0]], $error[1]); |
|
371 | 393 | } |
372 | - if (file_exists($attachment['tmp_name'])) |
|
373 | - unlink($attachment['tmp_name']); |
|
394 | + if (file_exists($attachment['tmp_name'])) { |
|
395 | + unlink($attachment['tmp_name']); |
|
396 | + } |
|
374 | 397 | } |
375 | 398 | |
376 | 399 | // You don't need to know. |
@@ -382,8 +405,9 @@ discard block |
||
382 | 405 | } |
383 | 406 | |
384 | 407 | // Temp save this on the db. |
385 | - if (!empty($_SESSION['already_attached'])) |
|
386 | - $this->_attachSuccess = $_SESSION['already_attached']; |
|
408 | + if (!empty($_SESSION['already_attached'])) { |
|
409 | + $this->_attachSuccess = $_SESSION['already_attached']; |
|
410 | + } |
|
387 | 411 | |
388 | 412 | unset($_SESSION['temp_attachments']); |
389 | 413 | } |
@@ -403,14 +427,16 @@ discard block |
||
403 | 427 | if ($this->_sa == 'add') |
404 | 428 | { |
405 | 429 | // Is there any generic errors? made some sense out of them! |
406 | - if ($this->_generalErrors) |
|
407 | - foreach ($this->_generalErrors as $k => $v) |
|
430 | + if ($this->_generalErrors) { |
|
431 | + foreach ($this->_generalErrors as $k => $v) |
|
408 | 432 | $this->_generalErrors[$k] = (is_array($v) ? vsprintf($txt[$v[0]], $v[1]) : $txt[$v]); |
433 | + } |
|
409 | 434 | |
410 | 435 | // Gotta urlencode the filename. |
411 | - if ($this->_attachResults) |
|
412 | - foreach ($this->_attachResults as $k => $v) |
|
436 | + if ($this->_attachResults) { |
|
437 | + foreach ($this->_attachResults as $k => $v) |
|
413 | 438 | $this->_attachResults[$k]['name'] = urlencode($this->_attachResults[$k]['name']); |
439 | + } |
|
414 | 440 | |
415 | 441 | $this->_response = array( |
416 | 442 | 'files' => $this->_attachResults ? $this->_attachResults : false, |
@@ -419,9 +445,10 @@ discard block |
||
419 | 445 | } |
420 | 446 | |
421 | 447 | // Rest of us mere mortals gets no special treatment... |
422 | - elseif (!empty($data)) |
|
423 | - if (!empty($data['text']) && !empty($txt[$data['text']])) |
|
448 | + elseif (!empty($data)) { |
|
449 | + if (!empty($data['text']) && !empty($txt[$data['text']])) |
|
424 | 450 | $this->_response['text'] = $txt[$data['text']]; |
451 | + } |
|
425 | 452 | } |
426 | 453 | |
427 | 454 | protected function sendResponse() |
@@ -430,11 +457,11 @@ discard block |
||
430 | 457 | |
431 | 458 | ob_end_clean(); |
432 | 459 | |
433 | - if (!empty($modSettings['CompressedOutput'])) |
|
434 | - @ob_start('ob_gzhandler'); |
|
435 | - |
|
436 | - else |
|
437 | - ob_start(); |
|
460 | + if (!empty($modSettings['CompressedOutput'])) { |
|
461 | + @ob_start('ob_gzhandler'); |
|
462 | + } else { |
|
463 | + ob_start(); |
|
464 | + } |
|
438 | 465 | |
439 | 466 | // Set the header. |
440 | 467 | header('content-type: application/json; charset='. $context['character_set'] .''); |
@@ -15,8 +15,9 @@ discard block |
||
15 | 15 | * @version 2.1 Beta 4 |
16 | 16 | */ |
17 | 17 | |
18 | -if (!defined('SMF')) |
|
18 | +if (!defined('SMF')) { |
|
19 | 19 | die('No direct access...'); |
20 | +} |
|
20 | 21 | |
21 | 22 | /** |
22 | 23 | * Begin the registration process. |
@@ -29,19 +30,23 @@ discard block |
||
29 | 30 | global $language, $scripturl, $smcFunc, $sourcedir, $cur_profile; |
30 | 31 | |
31 | 32 | // Is this an incoming AJAX check? |
32 | - if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck') |
|
33 | - return RegisterCheckUsername(); |
|
33 | + if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck') { |
|
34 | + return RegisterCheckUsername(); |
|
35 | + } |
|
34 | 36 | |
35 | 37 | // Check if the administrator has it disabled. |
36 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3') |
|
37 | - fatal_lang_error('registration_disabled', false); |
|
38 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3') { |
|
39 | + fatal_lang_error('registration_disabled', false); |
|
40 | + } |
|
38 | 41 | |
39 | 42 | // If this user is an admin - redirect them to the admin registration page. |
40 | - if (allowedTo('moderate_forum') && !$user_info['is_guest']) |
|
41 | - redirectexit('action=admin;area=regcenter;sa=register'); |
|
43 | + if (allowedTo('moderate_forum') && !$user_info['is_guest']) { |
|
44 | + redirectexit('action=admin;area=regcenter;sa=register'); |
|
45 | + } |
|
42 | 46 | // You are not a guest, so you are a member - and members don't get to register twice! |
43 | - elseif (empty($user_info['is_guest'])) |
|
44 | - redirectexit(); |
|
47 | + elseif (empty($user_info['is_guest'])) { |
|
48 | + redirectexit(); |
|
49 | + } |
|
45 | 50 | |
46 | 51 | loadLanguage('Login'); |
47 | 52 | loadTemplate('Register'); |
@@ -82,16 +87,18 @@ discard block |
||
82 | 87 | } |
83 | 88 | } |
84 | 89 | // Make sure they don't squeeze through without agreeing. |
85 | - elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement']) |
|
86 | - $current_step = 1; |
|
90 | + elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement']) { |
|
91 | + $current_step = 1; |
|
92 | + } |
|
87 | 93 | |
88 | 94 | // Show the user the right form. |
89 | 95 | $context['sub_template'] = $current_step == 1 ? 'registration_agreement' : 'registration_form'; |
90 | 96 | $context['page_title'] = $current_step == 1 ? $txt['registration_agreement'] : $txt['registration_form']; |
91 | 97 | |
92 | 98 | // Kinda need this. |
93 | - if ($context['sub_template'] == 'registration_form') |
|
94 | - loadJavaScriptFile('register.js', array('defer' => false), 'smf_register'); |
|
99 | + if ($context['sub_template'] == 'registration_form') { |
|
100 | + loadJavaScriptFile('register.js', array('defer' => false), 'smf_register'); |
|
101 | + } |
|
95 | 102 | |
96 | 103 | // Add the register chain to the link tree. |
97 | 104 | $context['linktree'][] = array( |
@@ -100,24 +107,26 @@ discard block |
||
100 | 107 | ); |
101 | 108 | |
102 | 109 | // Prepare the time gate! Do it like so, in case later steps want to reset the limit for any reason, but make sure the time is the current one. |
103 | - if (!isset($_SESSION['register'])) |
|
104 | - $_SESSION['register'] = array( |
|
110 | + if (!isset($_SESSION['register'])) { |
|
111 | + $_SESSION['register'] = array( |
|
105 | 112 | 'timenow' => time(), |
106 | 113 | 'limit' => 10, // minimum number of seconds required on this page for registration |
107 | 114 | ); |
108 | - else |
|
109 | - $_SESSION['register']['timenow'] = time(); |
|
115 | + } else { |
|
116 | + $_SESSION['register']['timenow'] = time(); |
|
117 | + } |
|
110 | 118 | |
111 | 119 | // If you have to agree to the agreement, it needs to be fetched from the file. |
112 | 120 | if ($context['require_agreement']) |
113 | 121 | { |
114 | 122 | // Have we got a localized one? |
115 | - if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt')) |
|
116 | - $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']); |
|
117 | - elseif (file_exists($boarddir . '/agreement.txt')) |
|
118 | - $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement'); |
|
119 | - else |
|
120 | - $context['agreement'] = ''; |
|
123 | + if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt')) { |
|
124 | + $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']); |
|
125 | + } elseif (file_exists($boarddir . '/agreement.txt')) { |
|
126 | + $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement'); |
|
127 | + } else { |
|
128 | + $context['agreement'] = ''; |
|
129 | + } |
|
121 | 130 | |
122 | 131 | // Nothing to show, lets disable registration and inform the admin of this error |
123 | 132 | if (empty($context['agreement'])) |
@@ -133,8 +142,9 @@ discard block |
||
133 | 142 | $selectedLanguage = empty($_SESSION['language']) ? $language : $_SESSION['language']; |
134 | 143 | |
135 | 144 | // Do we have any languages? |
136 | - if (empty($context['languages'])) |
|
137 | - getLanguages(); |
|
145 | + if (empty($context['languages'])) { |
|
146 | + getLanguages(); |
|
147 | + } |
|
138 | 148 | |
139 | 149 | // Try to find our selected language. |
140 | 150 | foreach ($context['languages'] as $key => $lang) |
@@ -142,8 +152,9 @@ discard block |
||
142 | 152 | $context['languages'][$key]['name'] = strtr($lang['name'], array('-utf8' => '')); |
143 | 153 | |
144 | 154 | // Found it! |
145 | - if ($selectedLanguage == $lang['filename']) |
|
146 | - $context['languages'][$key]['selected'] = true; |
|
155 | + if ($selectedLanguage == $lang['filename']) { |
|
156 | + $context['languages'][$key]['selected'] = true; |
|
157 | + } |
|
147 | 158 | } |
148 | 159 | } |
149 | 160 | |
@@ -170,16 +181,19 @@ discard block |
||
170 | 181 | if (in_array('website', $reg_fields)) |
171 | 182 | { |
172 | 183 | unset($reg_fields['website']); |
173 | - if (isset($_POST['website_title'])) |
|
174 | - $cur_profile['website_title'] = $smcFunc['htmlspecialchars']($_POST['website_title']); |
|
175 | - if (isset($_POST['website_url'])) |
|
176 | - $cur_profile['website_url'] = $smcFunc['htmlspecialchars']($_POST['website_url']); |
|
184 | + if (isset($_POST['website_title'])) { |
|
185 | + $cur_profile['website_title'] = $smcFunc['htmlspecialchars']($_POST['website_title']); |
|
186 | + } |
|
187 | + if (isset($_POST['website_url'])) { |
|
188 | + $cur_profile['website_url'] = $smcFunc['htmlspecialchars']($_POST['website_url']); |
|
189 | + } |
|
177 | 190 | } |
178 | 191 | |
179 | 192 | // We might have had some submissions on this front - go check. |
180 | - foreach ($reg_fields as $field) |
|
181 | - if (isset($_POST[$field])) |
|
193 | + foreach ($reg_fields as $field) { |
|
194 | + if (isset($_POST[$field])) |
|
182 | 195 | $cur_profile[$field] = $smcFunc['htmlspecialchars']($_POST[$field]); |
196 | + } |
|
183 | 197 | |
184 | 198 | // Load all the fields in question. |
185 | 199 | setupProfileContext($reg_fields); |
@@ -196,8 +210,9 @@ discard block |
||
196 | 210 | $context['visual_verification_id'] = $verificationOptions['id']; |
197 | 211 | } |
198 | 212 | // Otherwise we have nothing to show. |
199 | - else |
|
200 | - $context['visual_verification'] = false; |
|
213 | + else { |
|
214 | + $context['visual_verification'] = false; |
|
215 | + } |
|
201 | 216 | |
202 | 217 | |
203 | 218 | $context += array( |
@@ -208,8 +223,9 @@ discard block |
||
208 | 223 | |
209 | 224 | // Were there any errors? |
210 | 225 | $context['registration_errors'] = array(); |
211 | - if (!empty($reg_errors)) |
|
212 | - $context['registration_errors'] = $reg_errors; |
|
226 | + if (!empty($reg_errors)) { |
|
227 | + $context['registration_errors'] = $reg_errors; |
|
228 | + } |
|
213 | 229 | |
214 | 230 | createToken('register'); |
215 | 231 | } |
@@ -226,27 +242,32 @@ discard block |
||
226 | 242 | validateToken('register'); |
227 | 243 | |
228 | 244 | // Check to ensure we're forcing SSL for authentication |
229 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) |
|
230 | - fatal_lang_error('register_ssl_required'); |
|
245 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) { |
|
246 | + fatal_lang_error('register_ssl_required'); |
|
247 | + } |
|
231 | 248 | |
232 | 249 | // Start collecting together any errors. |
233 | 250 | $reg_errors = array(); |
234 | 251 | |
235 | 252 | // You can't register if it's disabled. |
236 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3) |
|
237 | - fatal_lang_error('registration_disabled', false); |
|
253 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3) { |
|
254 | + fatal_lang_error('registration_disabled', false); |
|
255 | + } |
|
238 | 256 | |
239 | 257 | // Well, if you don't agree, you can't register. |
240 | - if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed'])) |
|
241 | - redirectexit(); |
|
258 | + if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed'])) { |
|
259 | + redirectexit(); |
|
260 | + } |
|
242 | 261 | |
243 | 262 | // Make sure they came from *somewhere*, have a session. |
244 | - if (!isset($_SESSION['old_url'])) |
|
245 | - redirectexit('action=signup'); |
|
263 | + if (!isset($_SESSION['old_url'])) { |
|
264 | + redirectexit('action=signup'); |
|
265 | + } |
|
246 | 266 | |
247 | 267 | // If we don't require an agreement, we need a extra check for coppa. |
248 | - if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge'])) |
|
249 | - $_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']); |
|
268 | + if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge'])) { |
|
269 | + $_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']); |
|
270 | + } |
|
250 | 271 | // Are they under age, and under age users are banned? |
251 | 272 | if (!empty($modSettings['coppaAge']) && empty($modSettings['coppaType']) && empty($_SESSION['skip_coppa'])) |
252 | 273 | { |
@@ -255,8 +276,9 @@ discard block |
||
255 | 276 | } |
256 | 277 | |
257 | 278 | // Check the time gate for miscreants. First make sure they came from somewhere that actually set it up. |
258 | - if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit'])) |
|
259 | - redirectexit('action=signup'); |
|
279 | + if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit'])) { |
|
280 | + redirectexit('action=signup'); |
|
281 | + } |
|
260 | 282 | // Failing that, check the time on it. |
261 | 283 | if (time() - $_SESSION['register']['timenow'] < $_SESSION['register']['limit']) |
262 | 284 | { |
@@ -276,15 +298,17 @@ discard block |
||
276 | 298 | if (is_array($context['visual_verification'])) |
277 | 299 | { |
278 | 300 | loadLanguage('Errors'); |
279 | - foreach ($context['visual_verification'] as $error) |
|
280 | - $reg_errors[] = $txt['error_' . $error]; |
|
301 | + foreach ($context['visual_verification'] as $error) { |
|
302 | + $reg_errors[] = $txt['error_' . $error]; |
|
303 | + } |
|
281 | 304 | } |
282 | 305 | } |
283 | 306 | |
284 | 307 | foreach ($_POST as $key => $value) |
285 | 308 | { |
286 | - if (!is_array($_POST[$key])) |
|
287 | - $_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key])); |
|
309 | + if (!is_array($_POST[$key])) { |
|
310 | + $_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key])); |
|
311 | + } |
|
288 | 312 | } |
289 | 313 | |
290 | 314 | // Collect all extra registration fields someone might have filled in. |
@@ -314,12 +338,14 @@ discard block |
||
314 | 338 | $reg_fields = explode(',', $modSettings['registration_fields']); |
315 | 339 | |
316 | 340 | // Website is a little different |
317 | - if (in_array('website', $reg_fields)) |
|
318 | - $possible_strings = array_merge(array('website_url', 'website_title'), $possible_strings); |
|
341 | + if (in_array('website', $reg_fields)) { |
|
342 | + $possible_strings = array_merge(array('website_url', 'website_title'), $possible_strings); |
|
343 | + } |
|
319 | 344 | } |
320 | 345 | |
321 | - if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '') |
|
322 | - $_POST['secret_answer'] = md5($_POST['secret_answer']); |
|
346 | + if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '') { |
|
347 | + $_POST['secret_answer'] = md5($_POST['secret_answer']); |
|
348 | + } |
|
323 | 349 | |
324 | 350 | // Needed for isReservedName() and registerMember(). |
325 | 351 | require_once($sourcedir . '/Subs-Members.php'); |
@@ -328,8 +354,9 @@ discard block |
||
328 | 354 | if (isset($_POST['real_name'])) |
329 | 355 | { |
330 | 356 | // Are you already allowed to edit the displayed name? |
331 | - if (allowedTo('profile_displayed_name') || allowedTo('moderate_forum')) |
|
332 | - $canEditDisplayName = true; |
|
357 | + if (allowedTo('profile_displayed_name') || allowedTo('moderate_forum')) { |
|
358 | + $canEditDisplayName = true; |
|
359 | + } |
|
333 | 360 | |
334 | 361 | // If you are a guest, will you be allowed to once you register? |
335 | 362 | else |
@@ -353,33 +380,38 @@ discard block |
||
353 | 380 | $_POST['real_name'] = trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $_POST['real_name'])); |
354 | 381 | |
355 | 382 | // Only set it if we are sure it is good |
356 | - if (trim($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60) |
|
357 | - $possible_strings[] = 'real_name'; |
|
383 | + if (trim($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60) { |
|
384 | + $possible_strings[] = 'real_name'; |
|
385 | + } |
|
358 | 386 | } |
359 | 387 | } |
360 | 388 | |
361 | 389 | // Handle a string as a birthdate... |
362 | - if (isset($_POST['birthdate']) && $_POST['birthdate'] != '') |
|
363 | - $_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate'])); |
|
390 | + if (isset($_POST['birthdate']) && $_POST['birthdate'] != '') { |
|
391 | + $_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate'])); |
|
392 | + } |
|
364 | 393 | // Or birthdate parts... |
365 | - elseif (!empty($_POST['bday1']) && !empty($_POST['bday2'])) |
|
366 | - $_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']); |
|
394 | + elseif (!empty($_POST['bday1']) && !empty($_POST['bday2'])) { |
|
395 | + $_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']); |
|
396 | + } |
|
367 | 397 | |
368 | 398 | // Validate the passed language file. |
369 | 399 | if (isset($_POST['lngfile']) && !empty($modSettings['userLanguage'])) |
370 | 400 | { |
371 | 401 | // Do we have any languages? |
372 | - if (empty($context['languages'])) |
|
373 | - getLanguages(); |
|
402 | + if (empty($context['languages'])) { |
|
403 | + getLanguages(); |
|
404 | + } |
|
374 | 405 | |
375 | 406 | // Did we find it? |
376 | - if (isset($context['languages'][$_POST['lngfile']])) |
|
377 | - $_SESSION['language'] = $_POST['lngfile']; |
|
378 | - else |
|
407 | + if (isset($context['languages'][$_POST['lngfile']])) { |
|
408 | + $_SESSION['language'] = $_POST['lngfile']; |
|
409 | + } else { |
|
410 | + unset($_POST['lngfile']); |
|
411 | + } |
|
412 | + } else { |
|
379 | 413 | unset($_POST['lngfile']); |
380 | 414 | } |
381 | - else |
|
382 | - unset($_POST['lngfile']); |
|
383 | 415 | |
384 | 416 | // Set the options needed for registration. |
385 | 417 | $regOptions = array( |
@@ -399,22 +431,27 @@ discard block |
||
399 | 431 | ); |
400 | 432 | |
401 | 433 | // Include the additional options that might have been filled in. |
402 | - foreach ($possible_strings as $var) |
|
403 | - if (isset($_POST[$var])) |
|
434 | + foreach ($possible_strings as $var) { |
|
435 | + if (isset($_POST[$var])) |
|
404 | 436 | $regOptions['extra_register_vars'][$var] = $smcFunc['htmlspecialchars']($_POST[$var], ENT_QUOTES); |
405 | - foreach ($possible_ints as $var) |
|
406 | - if (isset($_POST[$var])) |
|
437 | + } |
|
438 | + foreach ($possible_ints as $var) { |
|
439 | + if (isset($_POST[$var])) |
|
407 | 440 | $regOptions['extra_register_vars'][$var] = (int) $_POST[$var]; |
408 | - foreach ($possible_floats as $var) |
|
409 | - if (isset($_POST[$var])) |
|
441 | + } |
|
442 | + foreach ($possible_floats as $var) { |
|
443 | + if (isset($_POST[$var])) |
|
410 | 444 | $regOptions['extra_register_vars'][$var] = (float) $_POST[$var]; |
411 | - foreach ($possible_bools as $var) |
|
412 | - if (isset($_POST[$var])) |
|
445 | + } |
|
446 | + foreach ($possible_bools as $var) { |
|
447 | + if (isset($_POST[$var])) |
|
413 | 448 | $regOptions['extra_register_vars'][$var] = empty($_POST[$var]) ? 0 : 1; |
449 | + } |
|
414 | 450 | |
415 | 451 | // Registration options are always default options... |
416 | - if (isset($_POST['default_options'])) |
|
417 | - $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; |
|
452 | + if (isset($_POST['default_options'])) { |
|
453 | + $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; |
|
454 | + } |
|
418 | 455 | $regOptions['theme_vars'] = isset($_POST['options']) && is_array($_POST['options']) ? $_POST['options'] : array(); |
419 | 456 | |
420 | 457 | // Make sure they are clean, dammit! |
@@ -434,12 +471,14 @@ discard block |
||
434 | 471 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
435 | 472 | { |
436 | 473 | // Don't allow overriding of the theme variables. |
437 | - if (isset($regOptions['theme_vars'][$row['col_name']])) |
|
438 | - unset($regOptions['theme_vars'][$row['col_name']]); |
|
474 | + if (isset($regOptions['theme_vars'][$row['col_name']])) { |
|
475 | + unset($regOptions['theme_vars'][$row['col_name']]); |
|
476 | + } |
|
439 | 477 | |
440 | 478 | // Not actually showing it then? |
441 | - if (!$row['show_reg']) |
|
442 | - continue; |
|
479 | + if (!$row['show_reg']) { |
|
480 | + continue; |
|
481 | + } |
|
443 | 482 | |
444 | 483 | // Prepare the value! |
445 | 484 | $value = isset($_POST['customfield'][$row['col_name']]) ? trim($_POST['customfield'][$row['col_name']]) : ''; |
@@ -448,24 +487,27 @@ discard block |
||
448 | 487 | if (!in_array($row['field_type'], array('check', 'select', 'radio'))) |
449 | 488 | { |
450 | 489 | // Is it too long? |
451 | - if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value)) |
|
452 | - $custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length'])); |
|
490 | + if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value)) { |
|
491 | + $custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length'])); |
|
492 | + } |
|
453 | 493 | |
454 | 494 | // Any masks to apply? |
455 | 495 | if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none') |
456 | 496 | { |
457 | - if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255)) |
|
458 | - $custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name'])); |
|
459 | - elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value)) |
|
460 | - $custom_field_errors[] = array('custom_field_not_number', array($row['field_name'])); |
|
461 | - elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0) |
|
462 | - $custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name'])); |
|
497 | + if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255)) { |
|
498 | + $custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name'])); |
|
499 | + } elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value)) { |
|
500 | + $custom_field_errors[] = array('custom_field_not_number', array($row['field_name'])); |
|
501 | + } elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0) { |
|
502 | + $custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name'])); |
|
503 | + } |
|
463 | 504 | } |
464 | 505 | } |
465 | 506 | |
466 | 507 | // Is this required but not there? |
467 | - if (trim($value) == '' && $row['show_reg'] > 1) |
|
468 | - $custom_field_errors[] = array('custom_field_empty', array($row['field_name'])); |
|
508 | + if (trim($value) == '' && $row['show_reg'] > 1) { |
|
509 | + $custom_field_errors[] = array('custom_field_empty', array($row['field_name'])); |
|
510 | + } |
|
469 | 511 | } |
470 | 512 | $smcFunc['db_free_result']($request); |
471 | 513 | |
@@ -473,8 +515,9 @@ discard block |
||
473 | 515 | if (!empty($custom_field_errors)) |
474 | 516 | { |
475 | 517 | loadLanguage('Errors'); |
476 | - foreach ($custom_field_errors as $error) |
|
477 | - $reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]); |
|
518 | + foreach ($custom_field_errors as $error) { |
|
519 | + $reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]); |
|
520 | + } |
|
478 | 521 | } |
479 | 522 | |
480 | 523 | // Lets check for other errors before trying to register the member. |
@@ -519,8 +562,9 @@ discard block |
||
519 | 562 | } |
520 | 563 | |
521 | 564 | // If COPPA has been selected then things get complicated, setup the template. |
522 | - if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa'])) |
|
523 | - redirectexit('action=coppa;member=' . $memberID); |
|
565 | + if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa'])) { |
|
566 | + redirectexit('action=coppa;member=' . $memberID); |
|
567 | + } |
|
524 | 568 | // Basic template variable setup. |
525 | 569 | elseif (!empty($modSettings['registration_method'])) |
526 | 570 | { |
@@ -532,8 +576,7 @@ discard block |
||
532 | 576 | 'sub_template' => 'after', |
533 | 577 | 'description' => $modSettings['registration_method'] == 2 ? $txt['approval_after_registration'] : $txt['activate_after_registration'] |
534 | 578 | ); |
535 | - } |
|
536 | - else |
|
579 | + } else |
|
537 | 580 | { |
538 | 581 | call_integration_hook('integrate_activate', array($regOptions['username'])); |
539 | 582 | |
@@ -553,16 +596,18 @@ discard block |
||
553 | 596 | global $context, $txt, $modSettings, $scripturl, $sourcedir, $smcFunc, $language, $user_info; |
554 | 597 | |
555 | 598 | // Logged in users should not bother to activate their accounts |
556 | - if (!empty($user_info['id'])) |
|
557 | - redirectexit(); |
|
599 | + if (!empty($user_info['id'])) { |
|
600 | + redirectexit(); |
|
601 | + } |
|
558 | 602 | |
559 | 603 | loadLanguage('Login'); |
560 | 604 | loadTemplate('Login'); |
561 | 605 | |
562 | 606 | if (empty($_REQUEST['u']) && empty($_POST['user'])) |
563 | 607 | { |
564 | - if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3') |
|
565 | - fatal_lang_error('no_access', false); |
|
608 | + if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3') { |
|
609 | + fatal_lang_error('no_access', false); |
|
610 | + } |
|
566 | 611 | |
567 | 612 | $context['member_id'] = 0; |
568 | 613 | $context['sub_template'] = 'resend'; |
@@ -602,11 +647,13 @@ discard block |
||
602 | 647 | // Change their email address? (they probably tried a fake one first :P.) |
603 | 648 | if (isset($_POST['new_email'], $_REQUEST['passwd']) && hash_password($row['member_name'], $_REQUEST['passwd']) == $row['passwd'] && ($row['is_activated'] == 0 || $row['is_activated'] == 2)) |
604 | 649 | { |
605 | - if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3) |
|
606 | - fatal_lang_error('no_access', false); |
|
650 | + if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3) { |
|
651 | + fatal_lang_error('no_access', false); |
|
652 | + } |
|
607 | 653 | |
608 | - if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL)) |
|
609 | - fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false); |
|
654 | + if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL)) { |
|
655 | + fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false); |
|
656 | + } |
|
610 | 657 | |
611 | 658 | // Make sure their email isn't banned. |
612 | 659 | isBannedEmail($_POST['new_email'], 'cannot_register', $txt['ban_register_prohibited']); |
@@ -622,8 +669,9 @@ discard block |
||
622 | 669 | ) |
623 | 670 | ); |
624 | 671 | |
625 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
626 | - fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email']))); |
|
672 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
673 | + fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email']))); |
|
674 | + } |
|
627 | 675 | $smcFunc['db_free_result']($request); |
628 | 676 | |
629 | 677 | updateMemberData($row['id_member'], array('email_address' => $_POST['new_email'])); |
@@ -661,9 +709,9 @@ discard block |
||
661 | 709 | // Quit if this code is not right. |
662 | 710 | if (empty($_REQUEST['code']) || $row['validation_code'] != $_REQUEST['code']) |
663 | 711 | { |
664 | - if (!empty($row['is_activated'])) |
|
665 | - fatal_lang_error('already_activated', false); |
|
666 | - elseif ($row['validation_code'] == '') |
|
712 | + if (!empty($row['is_activated'])) { |
|
713 | + fatal_lang_error('already_activated', false); |
|
714 | + } elseif ($row['validation_code'] == '') |
|
667 | 715 | { |
668 | 716 | loadLanguage('Profile'); |
669 | 717 | fatal_error(sprintf($txt['registration_not_approved'], $scripturl . '?action=activate;user=' . $row['member_name']), false); |
@@ -713,8 +761,9 @@ discard block |
||
713 | 761 | loadTemplate('Register'); |
714 | 762 | |
715 | 763 | // No User ID?? |
716 | - if (!isset($_GET['member'])) |
|
717 | - fatal_lang_error('no_access', false); |
|
764 | + if (!isset($_GET['member'])) { |
|
765 | + fatal_lang_error('no_access', false); |
|
766 | + } |
|
718 | 767 | |
719 | 768 | // Get the user details... |
720 | 769 | $request = $smcFunc['db_query']('', ' |
@@ -727,8 +776,9 @@ discard block |
||
727 | 776 | 'is_coppa' => 5, |
728 | 777 | ) |
729 | 778 | ); |
730 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
731 | - fatal_lang_error('no_access', false); |
|
779 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
780 | + fatal_lang_error('no_access', false); |
|
781 | + } |
|
732 | 782 | list ($username) = $smcFunc['db_fetch_row']($request); |
733 | 783 | $smcFunc['db_free_result']($request); |
734 | 784 | |
@@ -766,8 +816,7 @@ discard block |
||
766 | 816 | echo $data; |
767 | 817 | obExit(false); |
768 | 818 | } |
769 | - } |
|
770 | - else |
|
819 | + } else |
|
771 | 820 | { |
772 | 821 | $context += array( |
773 | 822 | 'page_title' => $txt['coppa_title'], |
@@ -820,8 +869,9 @@ discard block |
||
820 | 869 | { |
821 | 870 | require_once($sourcedir . '/Subs-Graphics.php'); |
822 | 871 | |
823 | - if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code)) |
|
824 | - header('HTTP/1.1 400 Bad Request'); |
|
872 | + if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code)) { |
|
873 | + header('HTTP/1.1 400 Bad Request'); |
|
874 | + } |
|
825 | 875 | |
826 | 876 | // Otherwise just show a pre-defined letter. |
827 | 877 | elseif (isset($_REQUEST['letter'])) |
@@ -839,14 +889,13 @@ discard block |
||
839 | 889 | header('content-type: image/gif'); |
840 | 890 | die("\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B"); |
841 | 891 | } |
842 | - } |
|
843 | - |
|
844 | - elseif ($_REQUEST['format'] === '.wav') |
|
892 | + } elseif ($_REQUEST['format'] === '.wav') |
|
845 | 893 | { |
846 | 894 | require_once($sourcedir . '/Subs-Sound.php'); |
847 | 895 | |
848 | - if (!createWaveFile($code)) |
|
849 | - header('HTTP/1.1 400 Bad Request'); |
|
896 | + if (!createWaveFile($code)) { |
|
897 | + header('HTTP/1.1 400 Bad Request'); |
|
898 | + } |
|
850 | 899 | } |
851 | 900 | |
852 | 901 | // We all die one day... |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 4 |
15 | 15 | */ |
16 | 16 | |
17 | -if (!defined('SMF')) |
|
17 | +if (!defined('SMF')) { |
|
18 | 18 | die('No direct access...'); |
19 | +} |
|
19 | 20 | |
20 | 21 | /** |
21 | 22 | * Check if the user is who he/she says he is |
@@ -42,12 +43,14 @@ discard block |
||
42 | 43 | $refreshTime = isset($_GET['xml']) ? 4200 : 3600; |
43 | 44 | |
44 | 45 | // Is the security option off? |
45 | - if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')])) |
|
46 | - return; |
|
46 | + if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')])) { |
|
47 | + return; |
|
48 | + } |
|
47 | 49 | |
48 | 50 | // Or are they already logged in?, Moderator or admin session is need for this area |
49 | - if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time())) |
|
50 | - return; |
|
51 | + if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time())) { |
|
52 | + return; |
|
53 | + } |
|
51 | 54 | |
52 | 55 | require_once($sourcedir . '/Subs-Auth.php'); |
53 | 56 | |
@@ -55,8 +58,9 @@ discard block |
||
55 | 58 | if (isset($_POST[$type . '_pass'])) |
56 | 59 | { |
57 | 60 | // Check to ensure we're forcing SSL for authentication |
58 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) |
|
59 | - fatal_lang_error('login_ssl_required'); |
|
61 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) { |
|
62 | + fatal_lang_error('login_ssl_required'); |
|
63 | + } |
|
60 | 64 | |
61 | 65 | checkSession(); |
62 | 66 | |
@@ -72,17 +76,19 @@ discard block |
||
72 | 76 | } |
73 | 77 | |
74 | 78 | // Better be sure to remember the real referer |
75 | - if (empty($_SESSION['request_referer'])) |
|
76 | - $_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array(); |
|
77 | - elseif (empty($_POST)) |
|
78 | - unset($_SESSION['request_referer']); |
|
79 | + if (empty($_SESSION['request_referer'])) { |
|
80 | + $_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array(); |
|
81 | + } elseif (empty($_POST)) { |
|
82 | + unset($_SESSION['request_referer']); |
|
83 | + } |
|
79 | 84 | |
80 | 85 | // Need to type in a password for that, man. |
81 | - if (!isset($_GET['xml'])) |
|
82 | - adminLogin($type); |
|
83 | - else |
|
84 | - return 'session_verify_fail'; |
|
85 | -} |
|
86 | + if (!isset($_GET['xml'])) { |
|
87 | + adminLogin($type); |
|
88 | + } else { |
|
89 | + return 'session_verify_fail'; |
|
90 | + } |
|
91 | + } |
|
86 | 92 | |
87 | 93 | /** |
88 | 94 | * Require a user who is logged in. (not a guest.) |
@@ -96,25 +102,30 @@ discard block |
||
96 | 102 | global $user_info, $txt, $context, $scripturl, $modSettings; |
97 | 103 | |
98 | 104 | // Luckily, this person isn't a guest. |
99 | - if (!$user_info['is_guest']) |
|
100 | - return; |
|
105 | + if (!$user_info['is_guest']) { |
|
106 | + return; |
|
107 | + } |
|
101 | 108 | |
102 | 109 | // Log what they were trying to do didn't work) |
103 | - if (!empty($modSettings['who_enabled'])) |
|
104 | - $_GET['error'] = 'guest_login'; |
|
110 | + if (!empty($modSettings['who_enabled'])) { |
|
111 | + $_GET['error'] = 'guest_login'; |
|
112 | + } |
|
105 | 113 | writeLog(true); |
106 | 114 | |
107 | 115 | // Just die. |
108 | - if (isset($_REQUEST['xml'])) |
|
109 | - obExit(false); |
|
116 | + if (isset($_REQUEST['xml'])) { |
|
117 | + obExit(false); |
|
118 | + } |
|
110 | 119 | |
111 | 120 | // Attempt to detect if they came from dlattach. |
112 | - if (SMF != 'SSI' && empty($context['theme_loaded'])) |
|
113 | - loadTheme(); |
|
121 | + if (SMF != 'SSI' && empty($context['theme_loaded'])) { |
|
122 | + loadTheme(); |
|
123 | + } |
|
114 | 124 | |
115 | 125 | // Never redirect to an attachment |
116 | - if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) |
|
117 | - $_SESSION['login_url'] = $_SERVER['REQUEST_URL']; |
|
126 | + if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) { |
|
127 | + $_SESSION['login_url'] = $_SERVER['REQUEST_URL']; |
|
128 | + } |
|
118 | 129 | |
119 | 130 | // Load the Login template and language file. |
120 | 131 | loadLanguage('Login'); |
@@ -124,8 +135,7 @@ discard block |
||
124 | 135 | { |
125 | 136 | $_SESSION['login_url'] = $scripturl . '?' . $_SERVER['QUERY_STRING']; |
126 | 137 | redirectexit('action=login'); |
127 | - } |
|
128 | - else |
|
138 | + } else |
|
129 | 139 | { |
130 | 140 | loadTemplate('Login'); |
131 | 141 | $context['sub_template'] = 'kick_guest'; |
@@ -155,8 +165,9 @@ discard block |
||
155 | 165 | global $sourcedir, $cookiename, $user_settings, $smcFunc; |
156 | 166 | |
157 | 167 | // You cannot be banned if you are an admin - doesn't help if you log out. |
158 | - if ($user_info['is_admin']) |
|
159 | - return; |
|
168 | + if ($user_info['is_admin']) { |
|
169 | + return; |
|
170 | + } |
|
160 | 171 | |
161 | 172 | // Only check the ban every so often. (to reduce load.) |
162 | 173 | if ($forceCheck || !isset($_SESSION['ban']) || empty($modSettings['banLastUpdated']) || ($_SESSION['ban']['last_checked'] < $modSettings['banLastUpdated']) || $_SESSION['ban']['id_member'] != $user_info['id'] || $_SESSION['ban']['ip'] != $user_info['ip'] || $_SESSION['ban']['ip2'] != $user_info['ip2'] || (isset($user_info['email'], $_SESSION['ban']['email']) && $_SESSION['ban']['email'] != $user_info['email'])) |
@@ -177,8 +188,9 @@ discard block |
||
177 | 188 | // Check both IP addresses. |
178 | 189 | foreach (array('ip', 'ip2') as $ip_number) |
179 | 190 | { |
180 | - if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip']) |
|
181 | - continue; |
|
191 | + if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip']) { |
|
192 | + continue; |
|
193 | + } |
|
182 | 194 | $ban_query[] = ' {inet:' . $ip_number . '} BETWEEN bi.ip_low and bi.ip_high'; |
183 | 195 | $ban_query_vars[$ip_number] = $user_info[$ip_number]; |
184 | 196 | // IP was valid, maybe there's also a hostname... |
@@ -228,24 +240,28 @@ discard block |
||
228 | 240 | // Store every type of ban that applies to you in your session. |
229 | 241 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
230 | 242 | { |
231 | - foreach ($restrictions as $restriction) |
|
232 | - if (!empty($row[$restriction])) |
|
243 | + foreach ($restrictions as $restriction) { |
|
244 | + if (!empty($row[$restriction])) |
|
233 | 245 | { |
234 | 246 | $_SESSION['ban'][$restriction]['reason'] = $row['reason']; |
247 | + } |
|
235 | 248 | $_SESSION['ban'][$restriction]['ids'][] = $row['id_ban']; |
236 | - if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time']))) |
|
237 | - $_SESSION['ban']['expire_time'] = $row['expire_time']; |
|
249 | + if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time']))) { |
|
250 | + $_SESSION['ban']['expire_time'] = $row['expire_time']; |
|
251 | + } |
|
238 | 252 | |
239 | - if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email'])) |
|
240 | - $flag_is_activated = true; |
|
253 | + if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email'])) { |
|
254 | + $flag_is_activated = true; |
|
255 | + } |
|
241 | 256 | } |
242 | 257 | } |
243 | 258 | $smcFunc['db_free_result']($request); |
244 | 259 | } |
245 | 260 | |
246 | 261 | // Mark the cannot_access and cannot_post bans as being 'hit'. |
247 | - if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login'])) |
|
248 | - log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array())); |
|
262 | + if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login'])) { |
|
263 | + log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array())); |
|
264 | + } |
|
249 | 265 | |
250 | 266 | // If for whatever reason the is_activated flag seems wrong, do a little work to clear it up. |
251 | 267 | if ($user_info['id'] && (($user_settings['is_activated'] >= 10 && !$flag_is_activated) |
@@ -260,8 +276,9 @@ discard block |
||
260 | 276 | if (!isset($_SESSION['ban']['cannot_access']) && !empty($_COOKIE[$cookiename . '_'])) |
261 | 277 | { |
262 | 278 | $bans = explode(',', $_COOKIE[$cookiename . '_']); |
263 | - foreach ($bans as $key => $value) |
|
264 | - $bans[$key] = (int) $value; |
|
279 | + foreach ($bans as $key => $value) { |
|
280 | + $bans[$key] = (int) $value; |
|
281 | + } |
|
265 | 282 | $request = $smcFunc['db_query']('', ' |
266 | 283 | SELECT bi.id_ban, bg.reason |
267 | 284 | FROM {db_prefix}ban_items AS bi |
@@ -297,14 +314,15 @@ discard block |
||
297 | 314 | if (isset($_SESSION['ban']['cannot_access'])) |
298 | 315 | { |
299 | 316 | // We don't wanna see you! |
300 | - if (!$user_info['is_guest']) |
|
301 | - $smcFunc['db_query']('', ' |
|
317 | + if (!$user_info['is_guest']) { |
|
318 | + $smcFunc['db_query']('', ' |
|
302 | 319 | DELETE FROM {db_prefix}log_online |
303 | 320 | WHERE id_member = {int:current_member}', |
304 | 321 | array( |
305 | 322 | 'current_member' => $user_info['id'], |
306 | 323 | ) |
307 | 324 | ); |
325 | + } |
|
308 | 326 | |
309 | 327 | // 'Log' the user out. Can't have any funny business... (save the name!) |
310 | 328 | $old_name = isset($user_info['name']) && $user_info['name'] != '' ? $user_info['name'] : $txt['guest_title']; |
@@ -390,9 +408,10 @@ discard block |
||
390 | 408 | } |
391 | 409 | |
392 | 410 | // Fix up the banning permissions. |
393 | - if (isset($user_info['permissions'])) |
|
394 | - banPermissions(); |
|
395 | -} |
|
411 | + if (isset($user_info['permissions'])) { |
|
412 | + banPermissions(); |
|
413 | + } |
|
414 | + } |
|
396 | 415 | |
397 | 416 | /** |
398 | 417 | * Fix permissions according to ban status. |
@@ -403,8 +422,9 @@ discard block |
||
403 | 422 | global $user_info, $sourcedir, $modSettings, $context; |
404 | 423 | |
405 | 424 | // Somehow they got here, at least take away all permissions... |
406 | - if (isset($_SESSION['ban']['cannot_access'])) |
|
407 | - $user_info['permissions'] = array(); |
|
425 | + if (isset($_SESSION['ban']['cannot_access'])) { |
|
426 | + $user_info['permissions'] = array(); |
|
427 | + } |
|
408 | 428 | // Okay, well, you can watch, but don't touch a thing. |
409 | 429 | elseif (isset($_SESSION['ban']['cannot_post']) || (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $user_info['warning'])) |
410 | 430 | { |
@@ -446,19 +466,20 @@ discard block |
||
446 | 466 | call_integration_hook('integrate_warn_permissions', array(&$permission_change)); |
447 | 467 | foreach ($permission_change as $old => $new) |
448 | 468 | { |
449 | - if (!in_array($old, $user_info['permissions'])) |
|
450 | - unset($permission_change[$old]); |
|
451 | - else |
|
452 | - $user_info['permissions'][] = $new; |
|
469 | + if (!in_array($old, $user_info['permissions'])) { |
|
470 | + unset($permission_change[$old]); |
|
471 | + } else { |
|
472 | + $user_info['permissions'][] = $new; |
|
473 | + } |
|
453 | 474 | } |
454 | 475 | $user_info['permissions'] = array_diff($user_info['permissions'], array_keys($permission_change)); |
455 | 476 | } |
456 | 477 | |
457 | 478 | // @todo Find a better place to call this? Needs to be after permissions loaded! |
458 | 479 | // Finally, some bits we cache in the session because it saves queries. |
459 | - if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id']) |
|
460 | - $user_info['mod_cache'] = $_SESSION['mc']; |
|
461 | - else |
|
480 | + if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id']) { |
|
481 | + $user_info['mod_cache'] = $_SESSION['mc']; |
|
482 | + } else |
|
462 | 483 | { |
463 | 484 | require_once($sourcedir . '/Subs-Auth.php'); |
464 | 485 | rebuildModCache(); |
@@ -469,14 +490,12 @@ discard block |
||
469 | 490 | { |
470 | 491 | $context['open_mod_reports'] = $_SESSION['rc']['reports']; |
471 | 492 | $context['open_member_reports'] = $_SESSION['rc']['member_reports']; |
472 | - } |
|
473 | - elseif ($_SESSION['mc']['bq'] != '0=1') |
|
493 | + } elseif ($_SESSION['mc']['bq'] != '0=1') |
|
474 | 494 | { |
475 | 495 | require_once($sourcedir . '/Subs-ReportedContent.php'); |
476 | 496 | $context['open_mod_reports'] = recountOpenReports('posts'); |
477 | 497 | $context['open_member_reports'] = recountOpenReports('members'); |
478 | - } |
|
479 | - else |
|
498 | + } else |
|
480 | 499 | { |
481 | 500 | $context['open_mod_reports'] = 0; |
482 | 501 | $context['open_member_reports'] = 0; |
@@ -496,8 +515,9 @@ discard block |
||
496 | 515 | global $user_info, $smcFunc; |
497 | 516 | |
498 | 517 | // Don't log web accelerators, it's very confusing... |
499 | - if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') |
|
500 | - return; |
|
518 | + if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') { |
|
519 | + return; |
|
520 | + } |
|
501 | 521 | |
502 | 522 | $smcFunc['db_insert']('', |
503 | 523 | '{db_prefix}log_banned', |
@@ -507,8 +527,8 @@ discard block |
||
507 | 527 | ); |
508 | 528 | |
509 | 529 | // One extra point for these bans. |
510 | - if (!empty($ban_ids)) |
|
511 | - $smcFunc['db_query']('', ' |
|
530 | + if (!empty($ban_ids)) { |
|
531 | + $smcFunc['db_query']('', ' |
|
512 | 532 | UPDATE {db_prefix}ban_items |
513 | 533 | SET hits = hits + 1 |
514 | 534 | WHERE id_ban IN ({array_int:ban_ids})', |
@@ -516,7 +536,8 @@ discard block |
||
516 | 536 | 'ban_ids' => $ban_ids, |
517 | 537 | ) |
518 | 538 | ); |
519 | -} |
|
539 | + } |
|
540 | + } |
|
520 | 541 | |
521 | 542 | /** |
522 | 543 | * Checks if a given email address might be banned. |
@@ -532,8 +553,9 @@ discard block |
||
532 | 553 | global $txt, $smcFunc; |
533 | 554 | |
534 | 555 | // Can't ban an empty email |
535 | - if (empty($email) || trim($email) == '') |
|
536 | - return; |
|
556 | + if (empty($email) || trim($email) == '') { |
|
557 | + return; |
|
558 | + } |
|
537 | 559 | |
538 | 560 | // Let's start with the bans based on your IP/hostname/memberID... |
539 | 561 | $ban_ids = isset($_SESSION['ban'][$restriction]) ? $_SESSION['ban'][$restriction]['ids'] : array(); |
@@ -606,16 +628,18 @@ discard block |
||
606 | 628 | if ($type == 'post') |
607 | 629 | { |
608 | 630 | $check = isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null); |
609 | - if ($check !== $sc) |
|
610 | - $error = 'session_timeout'; |
|
631 | + if ($check !== $sc) { |
|
632 | + $error = 'session_timeout'; |
|
633 | + } |
|
611 | 634 | } |
612 | 635 | |
613 | 636 | // How about $_GET['sesc']? |
614 | 637 | elseif ($type == 'get') |
615 | 638 | { |
616 | 639 | $check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : null); |
617 | - if ($check !== $sc) |
|
618 | - $error = 'session_verify_fail'; |
|
640 | + if ($check !== $sc) { |
|
641 | + $error = 'session_verify_fail'; |
|
642 | + } |
|
619 | 643 | } |
620 | 644 | |
621 | 645 | // Or can it be in either? |
@@ -623,13 +647,15 @@ discard block |
||
623 | 647 | { |
624 | 648 | $check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : (isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null))); |
625 | 649 | |
626 | - if ($check !== $sc) |
|
627 | - $error = 'session_verify_fail'; |
|
650 | + if ($check !== $sc) { |
|
651 | + $error = 'session_verify_fail'; |
|
652 | + } |
|
628 | 653 | } |
629 | 654 | |
630 | 655 | // Verify that they aren't changing user agents on us - that could be bad. |
631 | - if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA'])) |
|
632 | - $error = 'session_verify_fail'; |
|
656 | + if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA'])) { |
|
657 | + $error = 'session_verify_fail'; |
|
658 | + } |
|
633 | 659 | |
634 | 660 | // Make sure a page with session check requirement is not being prefetched. |
635 | 661 | if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') |
@@ -640,30 +666,35 @@ discard block |
||
640 | 666 | } |
641 | 667 | |
642 | 668 | // Check the referring site - it should be the same server at least! |
643 | - if (isset($_SESSION['request_referer'])) |
|
644 | - $referrer = $_SESSION['request_referer']; |
|
645 | - else |
|
646 | - $referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array(); |
|
669 | + if (isset($_SESSION['request_referer'])) { |
|
670 | + $referrer = $_SESSION['request_referer']; |
|
671 | + } else { |
|
672 | + $referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array(); |
|
673 | + } |
|
647 | 674 | if (!empty($referrer['host'])) |
648 | 675 | { |
649 | - if (strpos($_SERVER['HTTP_HOST'], ':') !== false) |
|
650 | - $real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':')); |
|
651 | - else |
|
652 | - $real_host = $_SERVER['HTTP_HOST']; |
|
676 | + if (strpos($_SERVER['HTTP_HOST'], ':') !== false) { |
|
677 | + $real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':')); |
|
678 | + } else { |
|
679 | + $real_host = $_SERVER['HTTP_HOST']; |
|
680 | + } |
|
653 | 681 | |
654 | 682 | $parsed_url = parse_url($boardurl); |
655 | 683 | |
656 | 684 | // Are global cookies on? If so, let's check them ;). |
657 | 685 | if (!empty($modSettings['globalCookies'])) |
658 | 686 | { |
659 | - if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1) |
|
660 | - $parsed_url['host'] = $parts[1]; |
|
687 | + if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1) { |
|
688 | + $parsed_url['host'] = $parts[1]; |
|
689 | + } |
|
661 | 690 | |
662 | - if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1) |
|
663 | - $referrer['host'] = $parts[1]; |
|
691 | + if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1) { |
|
692 | + $referrer['host'] = $parts[1]; |
|
693 | + } |
|
664 | 694 | |
665 | - if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1) |
|
666 | - $real_host = $parts[1]; |
|
695 | + if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1) { |
|
696 | + $real_host = $parts[1]; |
|
697 | + } |
|
667 | 698 | } |
668 | 699 | |
669 | 700 | // Okay: referrer must either match parsed_url or real_host. |
@@ -681,12 +712,14 @@ discard block |
||
681 | 712 | $log_error = true; |
682 | 713 | } |
683 | 714 | |
684 | - if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker') |
|
685 | - fatal_error('Sound the alarm! It\'s a hacker! Close the castle gates!!', false); |
|
715 | + if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker') { |
|
716 | + fatal_error('Sound the alarm! It\'s a hacker! Close the castle gates!!', false); |
|
717 | + } |
|
686 | 718 | |
687 | 719 | // Everything is ok, return an empty string. |
688 | - if (!isset($error)) |
|
689 | - return ''; |
|
720 | + if (!isset($error)) { |
|
721 | + return ''; |
|
722 | + } |
|
690 | 723 | // A session error occurred, show the error. |
691 | 724 | elseif ($is_fatal) |
692 | 725 | { |
@@ -695,13 +728,14 @@ discard block |
||
695 | 728 | ob_end_clean(); |
696 | 729 | header('HTTP/1.1 403 Forbidden - Session timeout'); |
697 | 730 | die; |
731 | + } else { |
|
732 | + fatal_lang_error($error, isset($log_error) ? 'user' : false); |
|
698 | 733 | } |
699 | - else |
|
700 | - fatal_lang_error($error, isset($log_error) ? 'user' : false); |
|
701 | 734 | } |
702 | 735 | // A session error occurred, return the error to the calling function. |
703 | - else |
|
704 | - return $error; |
|
736 | + else { |
|
737 | + return $error; |
|
738 | + } |
|
705 | 739 | |
706 | 740 | // We really should never fall through here, for very important reasons. Let's make sure. |
707 | 741 | trigger_error('Hacking attempt...', E_USER_ERROR); |
@@ -717,10 +751,9 @@ discard block |
||
717 | 751 | { |
718 | 752 | global $modSettings; |
719 | 753 | |
720 | - if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action]) |
|
721 | - return true; |
|
722 | - |
|
723 | - else |
|
754 | + if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action]) { |
|
755 | + return true; |
|
756 | + } else |
|
724 | 757 | { |
725 | 758 | $token = md5(mt_rand() . session_id() . (string) microtime() . $modSettings['rand_seed']); |
726 | 759 | $_SESSION['confirm_' . $action] = md5($token . $_SERVER['HTTP_USER_AGENT']); |
@@ -771,9 +804,9 @@ discard block |
||
771 | 804 | $return = $_SESSION['token'][$type . '-' . $action][3]; |
772 | 805 | unset($_SESSION['token'][$type . '-' . $action]); |
773 | 806 | return $return; |
807 | + } else { |
|
808 | + return ''; |
|
774 | 809 | } |
775 | - else |
|
776 | - return ''; |
|
777 | 810 | } |
778 | 811 | |
779 | 812 | // This nasty piece of code validates a token. |
@@ -804,12 +837,14 @@ discard block |
||
804 | 837 | fatal_lang_error('token_verify_fail', false); |
805 | 838 | } |
806 | 839 | // Remove this token as its useless |
807 | - else |
|
808 | - unset($_SESSION['token'][$type . '-' . $action]); |
|
840 | + else { |
|
841 | + unset($_SESSION['token'][$type . '-' . $action]); |
|
842 | + } |
|
809 | 843 | |
810 | 844 | // Randomly check if we should remove some older tokens. |
811 | - if (mt_rand(0, 138) == 23) |
|
812 | - cleanTokens(); |
|
845 | + if (mt_rand(0, 138) == 23) { |
|
846 | + cleanTokens(); |
|
847 | + } |
|
813 | 848 | |
814 | 849 | return false; |
815 | 850 | } |
@@ -824,14 +859,16 @@ discard block |
||
824 | 859 | function cleanTokens($complete = false) |
825 | 860 | { |
826 | 861 | // We appreciate cleaning up after yourselves. |
827 | - if (!isset($_SESSION['token'])) |
|
828 | - return; |
|
862 | + if (!isset($_SESSION['token'])) { |
|
863 | + return; |
|
864 | + } |
|
829 | 865 | |
830 | 866 | // Clean up tokens, trying to give enough time still. |
831 | - foreach ($_SESSION['token'] as $key => $data) |
|
832 | - if ($data[2] + 10800 < time() || $complete) |
|
867 | + foreach ($_SESSION['token'] as $key => $data) { |
|
868 | + if ($data[2] + 10800 < time() || $complete) |
|
833 | 869 | unset($_SESSION['token'][$key]); |
834 | -} |
|
870 | + } |
|
871 | + } |
|
835 | 872 | |
836 | 873 | /** |
837 | 874 | * Check whether a form has been submitted twice. |
@@ -849,37 +886,40 @@ discard block |
||
849 | 886 | { |
850 | 887 | global $context; |
851 | 888 | |
852 | - if (!isset($_SESSION['forms'])) |
|
853 | - $_SESSION['forms'] = array(); |
|
889 | + if (!isset($_SESSION['forms'])) { |
|
890 | + $_SESSION['forms'] = array(); |
|
891 | + } |
|
854 | 892 | |
855 | 893 | // Register a form number and store it in the session stack. (use this on the page that has the form.) |
856 | 894 | if ($action == 'register') |
857 | 895 | { |
858 | 896 | $context['form_sequence_number'] = 0; |
859 | - while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms'])) |
|
860 | - $context['form_sequence_number'] = mt_rand(1, 16000000); |
|
897 | + while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms'])) { |
|
898 | + $context['form_sequence_number'] = mt_rand(1, 16000000); |
|
899 | + } |
|
861 | 900 | } |
862 | 901 | // Check whether the submitted number can be found in the session. |
863 | 902 | elseif ($action == 'check') |
864 | 903 | { |
865 | - if (!isset($_REQUEST['seqnum'])) |
|
866 | - return true; |
|
867 | - elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms'])) |
|
904 | + if (!isset($_REQUEST['seqnum'])) { |
|
905 | + return true; |
|
906 | + } elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms'])) |
|
868 | 907 | { |
869 | 908 | $_SESSION['forms'][] = (int) $_REQUEST['seqnum']; |
870 | 909 | return true; |
910 | + } elseif ($is_fatal) { |
|
911 | + fatal_lang_error('error_form_already_submitted', false); |
|
912 | + } else { |
|
913 | + return false; |
|
871 | 914 | } |
872 | - elseif ($is_fatal) |
|
873 | - fatal_lang_error('error_form_already_submitted', false); |
|
874 | - else |
|
875 | - return false; |
|
876 | 915 | } |
877 | 916 | // Don't check, just free the stack number. |
878 | - elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms'])) |
|
879 | - $_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum'])); |
|
880 | - elseif ($action != 'free') |
|
881 | - trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING); |
|
882 | -} |
|
917 | + elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms'])) { |
|
918 | + $_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum'])); |
|
919 | + } elseif ($action != 'free') { |
|
920 | + trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING); |
|
921 | + } |
|
922 | + } |
|
883 | 923 | |
884 | 924 | /** |
885 | 925 | * Check the user's permissions. |
@@ -898,16 +938,19 @@ discard block |
||
898 | 938 | global $user_info, $smcFunc; |
899 | 939 | |
900 | 940 | // You're always allowed to do nothing. (unless you're a working man, MR. LAZY :P!) |
901 | - if (empty($permission)) |
|
902 | - return true; |
|
941 | + if (empty($permission)) { |
|
942 | + return true; |
|
943 | + } |
|
903 | 944 | |
904 | 945 | // You're never allowed to do something if your data hasn't been loaded yet! |
905 | - if (empty($user_info)) |
|
906 | - return false; |
|
946 | + if (empty($user_info)) { |
|
947 | + return false; |
|
948 | + } |
|
907 | 949 | |
908 | 950 | // Administrators are supermen :P. |
909 | - if ($user_info['is_admin']) |
|
910 | - return true; |
|
951 | + if ($user_info['is_admin']) { |
|
952 | + return true; |
|
953 | + } |
|
911 | 954 | |
912 | 955 | // Let's ensure this is an array. |
913 | 956 | $permission = (array) $permission; |
@@ -915,14 +958,16 @@ discard block |
||
915 | 958 | // Are we checking the _current_ board, or some other boards? |
916 | 959 | if ($boards === null) |
917 | 960 | { |
918 | - if (count(array_intersect($permission, $user_info['permissions'])) != 0) |
|
919 | - return true; |
|
961 | + if (count(array_intersect($permission, $user_info['permissions'])) != 0) { |
|
962 | + return true; |
|
963 | + } |
|
920 | 964 | // You aren't allowed, by default. |
921 | - else |
|
922 | - return false; |
|
965 | + else { |
|
966 | + return false; |
|
967 | + } |
|
968 | + } elseif (!is_array($boards)) { |
|
969 | + $boards = array($boards); |
|
923 | 970 | } |
924 | - elseif (!is_array($boards)) |
|
925 | - $boards = array($boards); |
|
926 | 971 | |
927 | 972 | $request = $smcFunc['db_query']('', ' |
928 | 973 | SELECT MIN(bp.add_deny) AS add_deny |
@@ -950,20 +995,23 @@ discard block |
||
950 | 995 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
951 | 996 | { |
952 | 997 | $result = !empty($row['add_deny']); |
953 | - if ($result == true) |
|
954 | - break; |
|
998 | + if ($result == true) { |
|
999 | + break; |
|
1000 | + } |
|
955 | 1001 | } |
956 | 1002 | $smcFunc['db_free_result']($request); |
957 | 1003 | return $result; |
958 | 1004 | } |
959 | 1005 | |
960 | 1006 | // Make sure they can do it on all of the boards. |
961 | - if ($smcFunc['db_num_rows']($request) != count($boards)) |
|
962 | - return false; |
|
1007 | + if ($smcFunc['db_num_rows']($request) != count($boards)) { |
|
1008 | + return false; |
|
1009 | + } |
|
963 | 1010 | |
964 | 1011 | $result = true; |
965 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
966 | - $result &= !empty($row['add_deny']); |
|
1012 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1013 | + $result &= !empty($row['add_deny']); |
|
1014 | + } |
|
967 | 1015 | $smcFunc['db_free_result']($request); |
968 | 1016 | |
969 | 1017 | // If the query returned 1, they can do it... otherwise, they can't. |
@@ -1030,9 +1078,10 @@ discard block |
||
1030 | 1078 | |
1031 | 1079 | // If you're doing something on behalf of some "heavy" permissions, validate your session. |
1032 | 1080 | // (take out the heavy permissions, and if you can't do anything but those, you need a validated session.) |
1033 | - if (!allowedTo(array_diff($permission, $heavy_permissions), $boards)) |
|
1034 | - validateSession(); |
|
1035 | -} |
|
1081 | + if (!allowedTo(array_diff($permission, $heavy_permissions), $boards)) { |
|
1082 | + validateSession(); |
|
1083 | + } |
|
1084 | + } |
|
1036 | 1085 | |
1037 | 1086 | /** |
1038 | 1087 | * Return the boards a user has a certain (board) permission on. (array(0) if all.) |
@@ -1051,8 +1100,9 @@ discard block |
||
1051 | 1100 | global $user_info, $smcFunc; |
1052 | 1101 | |
1053 | 1102 | // Arrays are nice, most of the time. |
1054 | - if (!is_array($permissions)) |
|
1055 | - $permissions = array($permissions); |
|
1103 | + if (!is_array($permissions)) { |
|
1104 | + $permissions = array($permissions); |
|
1105 | + } |
|
1056 | 1106 | |
1057 | 1107 | /* |
1058 | 1108 | * Set $simple to true to use this function as it were in SMF 2.0.x. |
@@ -1064,13 +1114,14 @@ discard block |
||
1064 | 1114 | // Administrators are all powerful, sorry. |
1065 | 1115 | if ($user_info['is_admin']) |
1066 | 1116 | { |
1067 | - if ($simple) |
|
1068 | - return array(0); |
|
1069 | - else |
|
1117 | + if ($simple) { |
|
1118 | + return array(0); |
|
1119 | + } else |
|
1070 | 1120 | { |
1071 | 1121 | $boards = array(); |
1072 | - foreach ($permissions as $permission) |
|
1073 | - $boards[$permission] = array(0); |
|
1122 | + foreach ($permissions as $permission) { |
|
1123 | + $boards[$permission] = array(0); |
|
1124 | + } |
|
1074 | 1125 | |
1075 | 1126 | return $boards; |
1076 | 1127 | } |
@@ -1102,31 +1153,32 @@ discard block |
||
1102 | 1153 | { |
1103 | 1154 | if ($simple) |
1104 | 1155 | { |
1105 | - if (empty($row['add_deny'])) |
|
1106 | - $deny_boards[] = $row['id_board']; |
|
1107 | - else |
|
1108 | - $boards[] = $row['id_board']; |
|
1109 | - } |
|
1110 | - else |
|
1156 | + if (empty($row['add_deny'])) { |
|
1157 | + $deny_boards[] = $row['id_board']; |
|
1158 | + } else { |
|
1159 | + $boards[] = $row['id_board']; |
|
1160 | + } |
|
1161 | + } else |
|
1111 | 1162 | { |
1112 | - if (empty($row['add_deny'])) |
|
1113 | - $deny_boards[$row['permission']][] = $row['id_board']; |
|
1114 | - else |
|
1115 | - $boards[$row['permission']][] = $row['id_board']; |
|
1163 | + if (empty($row['add_deny'])) { |
|
1164 | + $deny_boards[$row['permission']][] = $row['id_board']; |
|
1165 | + } else { |
|
1166 | + $boards[$row['permission']][] = $row['id_board']; |
|
1167 | + } |
|
1116 | 1168 | } |
1117 | 1169 | } |
1118 | 1170 | $smcFunc['db_free_result']($request); |
1119 | 1171 | |
1120 | - if ($simple) |
|
1121 | - $boards = array_unique(array_values(array_diff($boards, $deny_boards))); |
|
1122 | - else |
|
1172 | + if ($simple) { |
|
1173 | + $boards = array_unique(array_values(array_diff($boards, $deny_boards))); |
|
1174 | + } else |
|
1123 | 1175 | { |
1124 | 1176 | foreach ($permissions as $permission) |
1125 | 1177 | { |
1126 | 1178 | // never had it to start with |
1127 | - if (empty($boards[$permission])) |
|
1128 | - $boards[$permission] = array(); |
|
1129 | - else |
|
1179 | + if (empty($boards[$permission])) { |
|
1180 | + $boards[$permission] = array(); |
|
1181 | + } else |
|
1130 | 1182 | { |
1131 | 1183 | // Or it may have been removed |
1132 | 1184 | $deny_boards[$permission] = isset($deny_boards[$permission]) ? $deny_boards[$permission] : array(); |
@@ -1162,10 +1214,11 @@ discard block |
||
1162 | 1214 | |
1163 | 1215 | |
1164 | 1216 | // Moderators are free... |
1165 | - if (!allowedTo('moderate_board')) |
|
1166 | - $timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime']; |
|
1167 | - else |
|
1168 | - $timeLimit = 2; |
|
1217 | + if (!allowedTo('moderate_board')) { |
|
1218 | + $timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime']; |
|
1219 | + } else { |
|
1220 | + $timeLimit = 2; |
|
1221 | + } |
|
1169 | 1222 | |
1170 | 1223 | call_integration_hook('integrate_spam_protection', array(&$timeOverrides, &$timeLimit)); |
1171 | 1224 | |
@@ -1192,8 +1245,9 @@ discard block |
||
1192 | 1245 | if ($smcFunc['db_affected_rows']() != 1) |
1193 | 1246 | { |
1194 | 1247 | // Spammer! You only have to wait a *few* seconds! |
1195 | - if (!$only_return_result) |
|
1196 | - fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit)); |
|
1248 | + if (!$only_return_result) { |
|
1249 | + fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit)); |
|
1250 | + } |
|
1197 | 1251 | |
1198 | 1252 | return true; |
1199 | 1253 | } |
@@ -1211,11 +1265,13 @@ discard block |
||
1211 | 1265 | */ |
1212 | 1266 | function secureDirectory($path, $attachments = false) |
1213 | 1267 | { |
1214 | - if (empty($path)) |
|
1215 | - return 'empty_path'; |
|
1268 | + if (empty($path)) { |
|
1269 | + return 'empty_path'; |
|
1270 | + } |
|
1216 | 1271 | |
1217 | - if (!is_writable($path)) |
|
1218 | - return 'path_not_writable'; |
|
1272 | + if (!is_writable($path)) { |
|
1273 | + return 'path_not_writable'; |
|
1274 | + } |
|
1219 | 1275 | |
1220 | 1276 | $directoryname = basename($path); |
1221 | 1277 | |
@@ -1227,9 +1283,9 @@ discard block |
||
1227 | 1283 | |
1228 | 1284 | RemoveHandler .php .php3 .phtml .cgi .fcgi .pl .fpl .shtml'; |
1229 | 1285 | |
1230 | - if (file_exists($path . '/.htaccess')) |
|
1231 | - $errors[] = 'htaccess_exists'; |
|
1232 | - else |
|
1286 | + if (file_exists($path . '/.htaccess')) { |
|
1287 | + $errors[] = 'htaccess_exists'; |
|
1288 | + } else |
|
1233 | 1289 | { |
1234 | 1290 | $fh = @fopen($path . '/.htaccess', 'w'); |
1235 | 1291 | if ($fh) { |
@@ -1241,9 +1297,9 @@ discard block |
||
1241 | 1297 | $errors[] = 'htaccess_cannot_create_file'; |
1242 | 1298 | } |
1243 | 1299 | |
1244 | - if (file_exists($path . '/index.php')) |
|
1245 | - $errors[] = 'index-php_exists'; |
|
1246 | - else |
|
1300 | + if (file_exists($path . '/index.php')) { |
|
1301 | + $errors[] = 'index-php_exists'; |
|
1302 | + } else |
|
1247 | 1303 | { |
1248 | 1304 | $fh = @fopen($path . '/index.php', 'w'); |
1249 | 1305 | if ($fh) { |
@@ -1270,11 +1326,12 @@ discard block |
||
1270 | 1326 | $errors[] = 'index-php_cannot_create_file'; |
1271 | 1327 | } |
1272 | 1328 | |
1273 | - if (!empty($errors)) |
|
1274 | - return $errors; |
|
1275 | - else |
|
1276 | - return true; |
|
1277 | -} |
|
1329 | + if (!empty($errors)) { |
|
1330 | + return $errors; |
|
1331 | + } else { |
|
1332 | + return true; |
|
1333 | + } |
|
1334 | + } |
|
1278 | 1335 | |
1279 | 1336 | /** |
1280 | 1337 | * This sets the X-Frame-Options header. |
@@ -1287,14 +1344,16 @@ discard block |
||
1287 | 1344 | global $modSettings; |
1288 | 1345 | |
1289 | 1346 | $option = 'SAMEORIGIN'; |
1290 | - if (is_null($override) && !empty($modSettings['frame_security'])) |
|
1291 | - $option = $modSettings['frame_security']; |
|
1292 | - elseif (in_array($override, array('SAMEORIGIN', 'DENY'))) |
|
1293 | - $option = $override; |
|
1347 | + if (is_null($override) && !empty($modSettings['frame_security'])) { |
|
1348 | + $option = $modSettings['frame_security']; |
|
1349 | + } elseif (in_array($override, array('SAMEORIGIN', 'DENY'))) { |
|
1350 | + $option = $override; |
|
1351 | + } |
|
1294 | 1352 | |
1295 | 1353 | // Don't bother setting the header if we have disabled it. |
1296 | - if ($option == 'DISABLE') |
|
1297 | - return; |
|
1354 | + if ($option == 'DISABLE') { |
|
1355 | + return; |
|
1356 | + } |
|
1298 | 1357 | |
1299 | 1358 | // Finally set it. |
1300 | 1359 | header('x-frame-options: ' . $option); |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * The main admin handling function.<br> |
@@ -444,8 +445,9 @@ discard block |
||
444 | 445 | foreach ($admin_includes as $include) |
445 | 446 | { |
446 | 447 | $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
447 | - if (file_exists($include)) |
|
448 | - require_once($include); |
|
448 | + if (file_exists($include)) { |
|
449 | + require_once($include); |
|
450 | + } |
|
449 | 451 | } |
450 | 452 | } |
451 | 453 | |
@@ -457,24 +459,27 @@ discard block |
||
457 | 459 | unset($admin_areas); |
458 | 460 | |
459 | 461 | // Nothing valid? |
460 | - if ($admin_include_data == false) |
|
461 | - fatal_lang_error('no_access', false); |
|
462 | + if ($admin_include_data == false) { |
|
463 | + fatal_lang_error('no_access', false); |
|
464 | + } |
|
462 | 465 | |
463 | 466 | // Build the link tree. |
464 | 467 | $context['linktree'][] = array( |
465 | 468 | 'url' => $scripturl . '?action=admin', |
466 | 469 | 'name' => $txt['admin_center'], |
467 | 470 | ); |
468 | - if (isset($admin_include_data['current_area']) && $admin_include_data['current_area'] != 'index') |
|
469 | - $context['linktree'][] = array( |
|
471 | + if (isset($admin_include_data['current_area']) && $admin_include_data['current_area'] != 'index') { |
|
472 | + $context['linktree'][] = array( |
|
470 | 473 | 'url' => $scripturl . '?action=admin;area=' . $admin_include_data['current_area'] . ';' . $context['session_var'] . '=' . $context['session_id'], |
471 | 474 | 'name' => $admin_include_data['label'], |
472 | 475 | ); |
473 | - if (!empty($admin_include_data['current_subsection']) && $admin_include_data['subsections'][$admin_include_data['current_subsection']][0] != $admin_include_data['label']) |
|
474 | - $context['linktree'][] = array( |
|
476 | + } |
|
477 | + if (!empty($admin_include_data['current_subsection']) && $admin_include_data['subsections'][$admin_include_data['current_subsection']][0] != $admin_include_data['label']) { |
|
478 | + $context['linktree'][] = array( |
|
475 | 479 | 'url' => $scripturl . '?action=admin;area=' . $admin_include_data['current_area'] . ';sa=' . $admin_include_data['current_subsection'] . ';' . $context['session_var'] . '=' . $context['session_id'], |
476 | 480 | 'name' => $admin_include_data['subsections'][$admin_include_data['current_subsection']][0], |
477 | 481 | ); |
482 | + } |
|
478 | 483 | |
479 | 484 | // Make a note of the Unique ID for this menu. |
480 | 485 | $context['admin_menu_id'] = $context['max_menu_id']; |
@@ -484,16 +489,18 @@ discard block |
||
484 | 489 | $context['admin_area'] = $admin_include_data['current_area']; |
485 | 490 | |
486 | 491 | // Now - finally - call the right place! |
487 | - if (isset($admin_include_data['file'])) |
|
488 | - require_once($sourcedir . '/' . $admin_include_data['file']); |
|
492 | + if (isset($admin_include_data['file'])) { |
|
493 | + require_once($sourcedir . '/' . $admin_include_data['file']); |
|
494 | + } |
|
489 | 495 | |
490 | 496 | // Get the right callable. |
491 | 497 | $call = call_helper($admin_include_data['function'], true); |
492 | 498 | |
493 | 499 | // Is it valid? |
494 | - if (!empty($call)) |
|
495 | - call_user_func($call); |
|
496 | -} |
|
500 | + if (!empty($call)) { |
|
501 | + call_user_func($call); |
|
502 | + } |
|
503 | + } |
|
497 | 504 | |
498 | 505 | /** |
499 | 506 | * The main administration section. |
@@ -547,13 +554,14 @@ discard block |
||
547 | 554 | |
548 | 555 | $context['sub_template'] = $context['admin_area'] == 'credits' ? 'credits' : 'admin'; |
549 | 556 | $context['page_title'] = $context['admin_area'] == 'credits' ? $txt['support_credits_title'] : $txt['admin_center']; |
550 | - if ($context['admin_area'] != 'credits') |
|
551 | - $context[$context['admin_menu_name']]['tab_data'] = array( |
|
557 | + if ($context['admin_area'] != 'credits') { |
|
558 | + $context[$context['admin_menu_name']]['tab_data'] = array( |
|
552 | 559 | 'title' => $txt['admin_center'], |
553 | 560 | 'help' => '', |
554 | 561 | 'description' => '<strong>' . $txt['hello_guest'] . ' ' . $context['user']['name'] . '!</strong> |
555 | 562 | ' . sprintf($txt['admin_main_welcome'], $txt['admin_center'], $txt['help'], $txt['help']), |
556 | 563 | ); |
564 | + } |
|
557 | 565 | |
558 | 566 | // Lastly, fill in the blanks in the support resources paragraphs. |
559 | 567 | $txt['support_resources_p1'] = sprintf($txt['support_resources_p1'], |
@@ -571,9 +579,10 @@ discard block |
||
571 | 579 | 'https://www.simplemachines.org/redirect/customize_support' |
572 | 580 | ); |
573 | 581 | |
574 | - if ($context['admin_area'] == 'admin') |
|
575 | - loadJavaScriptFile('admin.js', array('defer' => false), 'smf_admin'); |
|
576 | -} |
|
582 | + if ($context['admin_area'] == 'admin') { |
|
583 | + loadJavaScriptFile('admin.js', array('defer' => false), 'smf_admin'); |
|
584 | + } |
|
585 | + } |
|
577 | 586 | |
578 | 587 | /** |
579 | 588 | * Get one of the admin information files from Simple Machines. |
@@ -584,8 +593,9 @@ discard block |
||
584 | 593 | |
585 | 594 | setMemoryLimit('32M'); |
586 | 595 | |
587 | - if (empty($_REQUEST['filename']) || !is_string($_REQUEST['filename'])) |
|
588 | - fatal_lang_error('no_access', false); |
|
596 | + if (empty($_REQUEST['filename']) || !is_string($_REQUEST['filename'])) { |
|
597 | + fatal_lang_error('no_access', false); |
|
598 | + } |
|
589 | 599 | |
590 | 600 | // Strip off the forum cache part or we won't find it... |
591 | 601 | $_REQUEST['filename'] = str_replace($modSettings['browser_cache'], '', $_REQUEST['filename']); |
@@ -600,27 +610,30 @@ discard block |
||
600 | 610 | ) |
601 | 611 | ); |
602 | 612 | |
603 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
604 | - fatal_lang_error('admin_file_not_found', true, array($_REQUEST['filename']), 404); |
|
613 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
614 | + fatal_lang_error('admin_file_not_found', true, array($_REQUEST['filename']), 404); |
|
615 | + } |
|
605 | 616 | |
606 | 617 | list ($file_data, $filetype) = $smcFunc['db_fetch_row']($request); |
607 | 618 | $smcFunc['db_free_result']($request); |
608 | 619 | |
609 | 620 | // @todo Temp |
610 | 621 | // Figure out if sesc is still being used. |
611 | - if (strpos($file_data, ';sesc=') !== false && $filetype == 'text/javascript') |
|
612 | - $file_data = ' |
|
622 | + if (strpos($file_data, ';sesc=') !== false && $filetype == 'text/javascript') { |
|
623 | + $file_data = ' |
|
613 | 624 | if (!(\'smfForum_sessionvar\' in window)) |
614 | 625 | window.smfForum_sessionvar = \'sesc\'; |
615 | 626 | ' . strtr($file_data, array(';sesc=' => ';\' + window.smfForum_sessionvar + \'=')); |
627 | + } |
|
616 | 628 | |
617 | 629 | $context['template_layers'] = array(); |
618 | 630 | // Lets make sure we aren't going to output anything nasty. |
619 | 631 | @ob_end_clean(); |
620 | - if (!empty($modSettings['enableCompressedOutput'])) |
|
621 | - @ob_start('ob_gzhandler'); |
|
622 | - else |
|
623 | - @ob_start(); |
|
632 | + if (!empty($modSettings['enableCompressedOutput'])) { |
|
633 | + @ob_start('ob_gzhandler'); |
|
634 | + } else { |
|
635 | + @ob_start(); |
|
636 | + } |
|
624 | 637 | |
625 | 638 | // Make sure they know what type of file we are. |
626 | 639 | header('content-type: ' . $filetype); |
@@ -660,11 +673,12 @@ discard block |
||
660 | 673 | updateAdminPreferences(); |
661 | 674 | } |
662 | 675 | |
663 | - if (trim($context['search_term']) == '') |
|
664 | - $context['search_results'] = array(); |
|
665 | - else |
|
666 | - call_helper($subActions[$context['search_type']]); |
|
667 | -} |
|
676 | + if (trim($context['search_term']) == '') { |
|
677 | + $context['search_results'] = array(); |
|
678 | + } else { |
|
679 | + call_helper($subActions[$context['search_type']]); |
|
680 | + } |
|
681 | + } |
|
668 | 682 | |
669 | 683 | /** |
670 | 684 | * A complicated but relatively quick internal search. |
@@ -728,8 +742,9 @@ discard block |
||
728 | 742 | |
729 | 743 | loadLanguage(implode('+', $language_files)); |
730 | 744 | |
731 | - foreach ($include_files as $file) |
|
732 | - require_once($sourcedir . '/' . $file . '.php'); |
|
745 | + foreach ($include_files as $file) { |
|
746 | + require_once($sourcedir . '/' . $file . '.php'); |
|
747 | + } |
|
733 | 748 | |
734 | 749 | /* This is the huge array that defines everything... it's a huge array of items formatted as follows: |
735 | 750 | 0 = Language index (Can be array of indexes) to search through for this setting. |
@@ -753,11 +768,12 @@ discard block |
||
753 | 768 | foreach ($section['areas'] as $menu_key => $menu_item) |
754 | 769 | { |
755 | 770 | $search_data['sections'][] = array($menu_item['label'], 'area=' . $menu_key); |
756 | - if (!empty($menu_item['subsections'])) |
|
757 | - foreach ($menu_item['subsections'] as $key => $sublabel) |
|
771 | + if (!empty($menu_item['subsections'])) { |
|
772 | + foreach ($menu_item['subsections'] as $key => $sublabel) |
|
758 | 773 | { |
759 | 774 | if (isset($sublabel['label'])) |
760 | 775 | $search_data['sections'][] = array($sublabel['label'], 'area=' . $menu_key . ';sa=' . $key); |
776 | + } |
|
761 | 777 | } |
762 | 778 | } |
763 | 779 | } |
@@ -767,9 +783,10 @@ discard block |
||
767 | 783 | // Get a list of their variables. |
768 | 784 | $config_vars = $setting_area[0](true); |
769 | 785 | |
770 | - foreach ($config_vars as $var) |
|
771 | - if (!empty($var[1]) && !in_array($var[0], array('permissions', 'switch', 'desc'))) |
|
786 | + foreach ($config_vars as $var) { |
|
787 | + if (!empty($var[1]) && !in_array($var[0], array('permissions', 'switch', 'desc'))) |
|
772 | 788 | $search_data['settings'][] = array($var[(isset($var[2]) && in_array($var[2], array('file', 'db'))) ? 0 : 1], $setting_area[1], 'alttxt' => (isset($var[2]) && in_array($var[2], array('file', 'db'))) || isset($var[3]) ? (in_array($var[2], array('file', 'db')) ? $var[1] : $var[3]) : ''); |
789 | + } |
|
773 | 790 | } |
774 | 791 | |
775 | 792 | $context['page_title'] = $txt['admin_search_results']; |
@@ -782,8 +799,9 @@ discard block |
||
782 | 799 | foreach ($data as $item) |
783 | 800 | { |
784 | 801 | $found = false; |
785 | - if (!is_array($item[0])) |
|
786 | - $item[0] = array($item[0]); |
|
802 | + if (!is_array($item[0])) { |
|
803 | + $item[0] = array($item[0]); |
|
804 | + } |
|
787 | 805 | foreach ($item[0] as $term) |
788 | 806 | { |
789 | 807 | if (stripos($term, $search_term) !== false || (isset($txt[$term]) && stripos($txt[$term], $search_term) !== false) || (isset($txt['setting_' . $term]) && stripos($txt['setting_' . $term], $search_term) !== false)) |
@@ -841,8 +859,9 @@ discard block |
||
841 | 859 | $postVars = explode(' ', $context['search_term']); |
842 | 860 | |
843 | 861 | // Encode the search data. |
844 | - foreach ($postVars as $k => $v) |
|
845 | - $postVars[$k] = urlencode($v); |
|
862 | + foreach ($postVars as $k => $v) { |
|
863 | + $postVars[$k] = urlencode($v); |
|
864 | + } |
|
846 | 865 | |
847 | 866 | // This is what we will send. |
848 | 867 | $postVars = implode('+', $postVars); |
@@ -854,8 +873,9 @@ discard block |
||
854 | 873 | $search_results = fetch_web_data($context['doc_apiurl'] . '?action=query&list=search&srprop=timestamp|snippet&format=xml&srwhat=text&srsearch=' . $postVars); |
855 | 874 | |
856 | 875 | // If we didn't get any xml back we are in trouble - perhaps the doc site is overloaded? |
857 | - if (!$search_results || preg_match('~<' . '\?xml\sversion="\d+\.\d+"\?' . '>\s*(<api>.+?</api>)~is', $search_results, $matches) != true) |
|
858 | - fatal_lang_error('cannot_connect_doc_site'); |
|
876 | + if (!$search_results || preg_match('~<' . '\?xml\sversion="\d+\.\d+"\?' . '>\s*(<api>.+?</api>)~is', $search_results, $matches) != true) { |
|
877 | + fatal_lang_error('cannot_connect_doc_site'); |
|
878 | + } |
|
859 | 879 | |
860 | 880 | $search_results = $matches[1]; |
861 | 881 | |
@@ -867,8 +887,9 @@ discard block |
||
867 | 887 | $results = new xmlArray($search_results, false); |
868 | 888 | |
869 | 889 | // Move through the api layer. |
870 | - if (!$results->exists('api')) |
|
871 | - fatal_lang_error('cannot_connect_doc_site'); |
|
890 | + if (!$results->exists('api')) { |
|
891 | + fatal_lang_error('cannot_connect_doc_site'); |
|
892 | + } |
|
872 | 893 | |
873 | 894 | // Are there actually some results? |
874 | 895 | if ($results->exists('api/query/search/p')) |
@@ -904,8 +925,9 @@ discard block |
||
904 | 925 | ); |
905 | 926 | |
906 | 927 | // If it's not got a sa set it must have come here for first time, pretend error log should be reversed. |
907 | - if (!isset($_REQUEST['sa'])) |
|
908 | - $_REQUEST['desc'] = true; |
|
928 | + if (!isset($_REQUEST['sa'])) { |
|
929 | + $_REQUEST['desc'] = true; |
|
930 | + } |
|
909 | 931 | |
910 | 932 | // Setup some tab stuff. |
911 | 933 | $context[$context['admin_menu_name']]['tab_data'] = array( |
@@ -955,9 +977,10 @@ discard block |
||
955 | 977 | unset($_SESSION['admin_time']); |
956 | 978 | |
957 | 979 | // Clean any admin tokens as well. |
958 | - foreach ($_SESSION['token'] as $key => $token) |
|
959 | - if (strpos($key, '-admin') !== false) |
|
980 | + foreach ($_SESSION['token'] as $key => $token) { |
|
981 | + if (strpos($key, '-admin') !== false) |
|
960 | 982 | unset($_SESSION['token'][$key]); |
983 | + } |
|
961 | 984 | |
962 | 985 | redirectexit(); |
963 | 986 | } |
@@ -185,17 +185,21 @@ discard block |
||
185 | 185 | $tasksdir = $sourcedir . '/tasks'; |
186 | 186 | |
187 | 187 | # Make sure the paths are correct... at least try to fix them. |
188 | -if (!file_exists($boarddir) && file_exists(dirname(__FILE__) . '/agreement.txt')) |
|
188 | +if (!file_exists($boarddir) && file_exists(dirname(__FILE__) . '/agreement.txt')) { |
|
189 | 189 | $boarddir = dirname(__FILE__); |
190 | -if (!file_exists($sourcedir) && file_exists($boarddir . '/Sources')) |
|
190 | +} |
|
191 | +if (!file_exists($sourcedir) && file_exists($boarddir . '/Sources')) { |
|
191 | 192 | $sourcedir = $boarddir . '/Sources'; |
192 | -if (!file_exists($cachedir) && file_exists($boarddir . '/cache')) |
|
193 | +} |
|
194 | +if (!file_exists($cachedir) && file_exists($boarddir . '/cache')) { |
|
193 | 195 | $cachedir = $boarddir . '/cache'; |
196 | +} |
|
194 | 197 | |
195 | 198 | ########## Error-Catching ########## |
196 | 199 | # Note: You shouldn't touch these settings. |
197 | -if (file_exists((isset($cachedir) ? $cachedir : dirname(__FILE__)) . '/db_last_error.php')) |
|
200 | +if (file_exists((isset($cachedir) ? $cachedir : dirname(__FILE__)) . '/db_last_error.php')) { |
|
198 | 201 | include((isset($cachedir) ? $cachedir : dirname(__FILE__)) . '/db_last_error.php'); |
202 | +} |
|
199 | 203 | |
200 | 204 | if (!isset($db_last_error)) |
201 | 205 | { |
@@ -207,10 +211,11 @@ discard block |
||
207 | 211 | if (file_exists(dirname(__FILE__) . '/install.php')) |
208 | 212 | { |
209 | 213 | $secure = false; |
210 | - if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') |
|
211 | - $secure = true; |
|
212 | - elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') |
|
213 | - $secure = true; |
|
214 | + if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { |
|
215 | + $secure = true; |
|
216 | + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') { |
|
217 | + $secure = true; |
|
218 | + } |
|
214 | 219 | |
215 | 220 | header('location: http' . ($secure ? 's' : '') . '://' . (empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST']) . (strtr(dirname($_SERVER['PHP_SELF']), '\\', '/') == '/' ? '' : strtr(dirname($_SERVER['PHP_SELF']), '\\', '/')) . '/install.php'); exit; |
216 | 221 | } |
@@ -12,7 +12,8 @@ |
||
12 | 12 | header('location: ' . $boardurl); |
13 | 13 | } |
14 | 14 | // Can't find it... just forget it. |
15 | -else |
|
15 | +else { |
|
16 | 16 | exit; |
17 | +} |
|
17 | 18 | |
18 | 19 | ?> |
19 | 20 | \ No newline at end of file |
@@ -12,7 +12,8 @@ |
||
12 | 12 | header('location: ' . $boardurl); |
13 | 13 | } |
14 | 14 | // Can't find it... just forget it. |
15 | -else |
|
15 | +else { |
|
16 | 16 | exit; |
17 | +} |
|
17 | 18 | |
18 | 19 | ?> |
19 | 20 | \ No newline at end of file |