@@ -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 current directory is still valid or not. |
@@ -28,22 +29,24 @@ discard block |
||
28 | 29 | global $smcFunc, $boarddir, $modSettings, $context; |
29 | 30 | |
30 | 31 | // Not pretty, but since we don't want folders created for every post. It'll do unless a better solution can be found. |
31 | - if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin') |
|
32 | - $doit = true; |
|
33 | - elseif (empty($modSettings['automanage_attachments'])) |
|
34 | - return; |
|
35 | - elseif (!isset($_FILES)) |
|
36 | - return; |
|
37 | - elseif (isset($_FILES['attachment'])) |
|
38 | - foreach ($_FILES['attachment']['tmp_name'] as $dummy) |
|
32 | + if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin') { |
|
33 | + $doit = true; |
|
34 | + } elseif (empty($modSettings['automanage_attachments'])) { |
|
35 | + return; |
|
36 | + } elseif (!isset($_FILES)) { |
|
37 | + return; |
|
38 | + } elseif (isset($_FILES['attachment'])) { |
|
39 | + foreach ($_FILES['attachment']['tmp_name'] as $dummy) |
|
39 | 40 | if (!empty($dummy)) |
40 | 41 | { |
41 | 42 | $doit = true; |
43 | + } |
|
42 | 44 | break; |
43 | 45 | } |
44 | 46 | |
45 | - if (!isset($doit)) |
|
46 | - return; |
|
47 | + if (!isset($doit)) { |
|
48 | + return; |
|
49 | + } |
|
47 | 50 | |
48 | 51 | $year = date('Y'); |
49 | 52 | $month = date('m'); |
@@ -54,21 +57,25 @@ discard block |
||
54 | 57 | |
55 | 58 | if (!empty($modSettings['attachment_basedirectories']) && !empty($modSettings['use_subdirectories_for_attachments'])) |
56 | 59 | { |
57 | - if (!is_array($modSettings['attachment_basedirectories'])) |
|
58 | - $modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true); |
|
60 | + if (!is_array($modSettings['attachment_basedirectories'])) { |
|
61 | + $modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true); |
|
62 | + } |
|
59 | 63 | $base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']); |
64 | + } else { |
|
65 | + $base_dir = 0; |
|
60 | 66 | } |
61 | - else |
|
62 | - $base_dir = 0; |
|
63 | 67 | |
64 | 68 | if ($modSettings['automanage_attachments'] == 1) |
65 | 69 | { |
66 | - if (!isset($modSettings['last_attachments_directory'])) |
|
67 | - $modSettings['last_attachments_directory'] = array(); |
|
68 | - if (!is_array($modSettings['last_attachments_directory'])) |
|
69 | - $modSettings['last_attachments_directory'] = $smcFunc['json_decode']($modSettings['last_attachments_directory'], true); |
|
70 | - if (!isset($modSettings['last_attachments_directory'][$base_dir])) |
|
71 | - $modSettings['last_attachments_directory'][$base_dir] = 0; |
|
70 | + if (!isset($modSettings['last_attachments_directory'])) { |
|
71 | + $modSettings['last_attachments_directory'] = array(); |
|
72 | + } |
|
73 | + if (!is_array($modSettings['last_attachments_directory'])) { |
|
74 | + $modSettings['last_attachments_directory'] = $smcFunc['json_decode']($modSettings['last_attachments_directory'], true); |
|
75 | + } |
|
76 | + if (!isset($modSettings['last_attachments_directory'][$base_dir])) { |
|
77 | + $modSettings['last_attachments_directory'][$base_dir] = 0; |
|
78 | + } |
|
72 | 79 | } |
73 | 80 | |
74 | 81 | $basedirectory = (!empty($modSettings['use_subdirectories_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir); |
@@ -97,12 +104,14 @@ discard block |
||
97 | 104 | $updir = ''; |
98 | 105 | } |
99 | 106 | |
100 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
101 | - $modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true); |
|
102 | - if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir)) |
|
103 | - $outputCreation = automanage_attachments_create_directory($updir); |
|
104 | - elseif (in_array($updir, $modSettings['attachmentUploadDir'])) |
|
105 | - $outputCreation = true; |
|
107 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
108 | + $modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true); |
|
109 | + } |
|
110 | + if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir)) { |
|
111 | + $outputCreation = automanage_attachments_create_directory($updir); |
|
112 | + } elseif (in_array($updir, $modSettings['attachmentUploadDir'])) { |
|
113 | + $outputCreation = true; |
|
114 | + } |
|
106 | 115 | |
107 | 116 | if ($outputCreation) |
108 | 117 | { |
@@ -139,8 +148,9 @@ discard block |
||
139 | 148 | $count = count($tree); |
140 | 149 | |
141 | 150 | $directory = attachments_init_dir($tree, $count); |
142 | - if ($directory === false) |
|
143 | - return false; |
|
151 | + if ($directory === false) { |
|
152 | + return false; |
|
153 | + } |
|
144 | 154 | } |
145 | 155 | |
146 | 156 | $directory .= DIRECTORY_SEPARATOR . array_shift($tree); |
@@ -168,8 +178,9 @@ discard block |
||
168 | 178 | } |
169 | 179 | |
170 | 180 | // Everything seems fine...let's create the .htaccess |
171 | - if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess')) |
|
172 | - secureDirectory($updir, true); |
|
181 | + if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess')) { |
|
182 | + secureDirectory($updir, true); |
|
183 | + } |
|
173 | 184 | |
174 | 185 | $sep = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? '\/' : DIRECTORY_SEPARATOR; |
175 | 186 | $updir = rtrim($updir, $sep); |
@@ -201,8 +212,9 @@ discard block |
||
201 | 212 | { |
202 | 213 | global $smcFunc, $modSettings, $boarddir; |
203 | 214 | |
204 | - if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1)) |
|
205 | - return; |
|
215 | + if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1)) { |
|
216 | + return; |
|
217 | + } |
|
206 | 218 | |
207 | 219 | $basedirectory = !empty($modSettings['use_subdirectories_for_attachments']) ? $modSettings['basedirectory_for_attachments'] : $boarddir; |
208 | 220 | // Just to be sure: I don't want directory separators at the end |
@@ -214,13 +226,14 @@ discard block |
||
214 | 226 | { |
215 | 227 | $base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']); |
216 | 228 | $base_dir = !empty($modSettings['automanage_attachments']) ? $base_dir : 0; |
229 | + } else { |
|
230 | + $base_dir = 0; |
|
217 | 231 | } |
218 | - else |
|
219 | - $base_dir = 0; |
|
220 | 232 | |
221 | 233 | // Get the last attachment directory for that base directory |
222 | - if (empty($modSettings['last_attachments_directory'][$base_dir])) |
|
223 | - $modSettings['last_attachments_directory'][$base_dir] = 0; |
|
234 | + if (empty($modSettings['last_attachments_directory'][$base_dir])) { |
|
235 | + $modSettings['last_attachments_directory'][$base_dir] = 0; |
|
236 | + } |
|
224 | 237 | // And increment it. |
225 | 238 | $modSettings['last_attachments_directory'][$base_dir]++; |
226 | 239 | |
@@ -235,10 +248,10 @@ discard block |
||
235 | 248 | $modSettings['last_attachments_directory'] = $smcFunc['json_decode']($modSettings['last_attachments_directory'], true); |
236 | 249 | |
237 | 250 | return true; |
251 | + } else { |
|
252 | + return false; |
|
253 | + } |
|
238 | 254 | } |
239 | - else |
|
240 | - return false; |
|
241 | -} |
|
242 | 255 | |
243 | 256 | /** |
244 | 257 | * Split a path into a list of all directories and subdirectories |
@@ -256,12 +269,13 @@ discard block |
||
256 | 269 | * in Windows we need to explode for both \ and / |
257 | 270 | * while in linux should be safe to explode only for / (aka DIRECTORY_SEPARATOR) |
258 | 271 | */ |
259 | - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') |
|
260 | - $tree = preg_split('#[\\\/]#', $directory); |
|
261 | - else |
|
272 | + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { |
|
273 | + $tree = preg_split('#[\\\/]#', $directory); |
|
274 | + } else |
|
262 | 275 | { |
263 | - if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) |
|
264 | - return false; |
|
276 | + if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) { |
|
277 | + return false; |
|
278 | + } |
|
265 | 279 | |
266 | 280 | $tree = explode(DIRECTORY_SEPARATOR, trim($directory, DIRECTORY_SEPARATOR)); |
267 | 281 | } |
@@ -285,10 +299,11 @@ discard block |
||
285 | 299 | //Better be sure that the first part of the path is actually a drive letter... |
286 | 300 | //...even if, I should check this in the admin page...isn't it? |
287 | 301 | //...NHAAA Let's leave space for users' complains! :P |
288 | - if (preg_match('/^[a-z]:$/i', $tree[0])) |
|
289 | - $directory = array_shift($tree); |
|
290 | - else |
|
291 | - return false; |
|
302 | + if (preg_match('/^[a-z]:$/i', $tree[0])) { |
|
303 | + $directory = array_shift($tree); |
|
304 | + } else { |
|
305 | + return false; |
|
306 | + } |
|
292 | 307 | |
293 | 308 | $count--; |
294 | 309 | } |
@@ -303,18 +318,20 @@ discard block |
||
303 | 318 | global $context, $modSettings, $smcFunc, $txt, $user_info; |
304 | 319 | |
305 | 320 | // Make sure we're uploading to the right place. |
306 | - if (!empty($modSettings['automanage_attachments'])) |
|
307 | - automanage_attachments_check_directory(); |
|
321 | + if (!empty($modSettings['automanage_attachments'])) { |
|
322 | + automanage_attachments_check_directory(); |
|
323 | + } |
|
308 | 324 | |
309 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
310 | - $modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true); |
|
325 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
326 | + $modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true); |
|
327 | + } |
|
311 | 328 | |
312 | 329 | $context['attach_dir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
313 | 330 | |
314 | 331 | // Is the attachments folder actualy there? |
315 | - if (!empty($context['dir_creation_error'])) |
|
316 | - $initial_error = $context['dir_creation_error']; |
|
317 | - elseif (!is_dir($context['attach_dir'])) |
|
332 | + if (!empty($context['dir_creation_error'])) { |
|
333 | + $initial_error = $context['dir_creation_error']; |
|
334 | + } elseif (!is_dir($context['attach_dir'])) |
|
318 | 335 | { |
319 | 336 | $initial_error = 'attach_folder_warning'; |
320 | 337 | log_error(sprintf($txt['attach_folder_admin_warning'], $context['attach_dir']), 'critical'); |
@@ -337,12 +354,12 @@ discard block |
||
337 | 354 | ); |
338 | 355 | list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request); |
339 | 356 | $smcFunc['db_free_result']($request); |
340 | - } |
|
341 | - else |
|
342 | - $context['attachments'] = array( |
|
357 | + } else { |
|
358 | + $context['attachments'] = array( |
|
343 | 359 | 'quantity' => 0, |
344 | 360 | 'total_size' => 0, |
345 | 361 | ); |
362 | + } |
|
346 | 363 | } |
347 | 364 | |
348 | 365 | // Hmm. There are still files in session. |
@@ -352,39 +369,44 @@ discard block |
||
352 | 369 | // Let's try to keep them. But... |
353 | 370 | $ignore_temp = true; |
354 | 371 | // If new files are being added. We can't ignore those |
355 | - foreach ($_FILES['attachment']['tmp_name'] as $dummy) |
|
356 | - if (!empty($dummy)) |
|
372 | + foreach ($_FILES['attachment']['tmp_name'] as $dummy) { |
|
373 | + if (!empty($dummy)) |
|
357 | 374 | { |
358 | 375 | $ignore_temp = false; |
376 | + } |
|
359 | 377 | break; |
360 | 378 | } |
361 | 379 | |
362 | 380 | // Need to make space for the new files. So, bye bye. |
363 | 381 | if (!$ignore_temp) |
364 | 382 | { |
365 | - foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
|
366 | - if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
383 | + foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) { |
|
384 | + if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
367 | 385 | unlink($attachment['tmp_name']); |
386 | + } |
|
368 | 387 | |
369 | 388 | $context['we_are_history'] = $txt['error_temp_attachments_flushed']; |
370 | 389 | $_SESSION['temp_attachments'] = array(); |
371 | 390 | } |
372 | 391 | } |
373 | 392 | |
374 | - if (!isset($_FILES['attachment']['name'])) |
|
375 | - $_FILES['attachment']['tmp_name'] = array(); |
|
393 | + if (!isset($_FILES['attachment']['name'])) { |
|
394 | + $_FILES['attachment']['tmp_name'] = array(); |
|
395 | + } |
|
376 | 396 | |
377 | - if (!isset($_SESSION['temp_attachments'])) |
|
378 | - $_SESSION['temp_attachments'] = array(); |
|
397 | + if (!isset($_SESSION['temp_attachments'])) { |
|
398 | + $_SESSION['temp_attachments'] = array(); |
|
399 | + } |
|
379 | 400 | |
380 | 401 | // Remember where we are at. If it's anywhere at all. |
381 | - if (!$ignore_temp) |
|
382 | - $_SESSION['temp_attachments']['post'] = array( |
|
402 | + if (!$ignore_temp) { |
|
403 | + $_SESSION['temp_attachments']['post'] = array( |
|
383 | 404 | 'msg' => !empty($_REQUEST['msg']) ? $_REQUEST['msg'] : 0, |
384 | 405 | 'last_msg' => !empty($_REQUEST['last_msg']) ? $_REQUEST['last_msg'] : 0, |
385 | 406 | 'topic' => !empty($topic) ? $topic : 0, |
386 | 407 | 'board' => !empty($board) ? $board : 0, |
387 | 408 | ); |
409 | + } |
|
388 | 410 | |
389 | 411 | // If we have an initial error, lets just display it. |
390 | 412 | if (!empty($initial_error)) |
@@ -392,9 +414,10 @@ discard block |
||
392 | 414 | $_SESSION['temp_attachments']['initial_error'] = $initial_error; |
393 | 415 | |
394 | 416 | // And delete the files 'cos they ain't going nowhere. |
395 | - foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) |
|
396 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
417 | + foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) { |
|
418 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
397 | 419 | unlink($_FILES['attachment']['tmp_name'][$n]); |
420 | + } |
|
398 | 421 | |
399 | 422 | $_FILES['attachment']['tmp_name'] = array(); |
400 | 423 | } |
@@ -402,21 +425,24 @@ discard block |
||
402 | 425 | // Loop through $_FILES['attachment'] array and move each file to the current attachments folder. |
403 | 426 | foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) |
404 | 427 | { |
405 | - if ($_FILES['attachment']['name'][$n] == '') |
|
406 | - continue; |
|
428 | + if ($_FILES['attachment']['name'][$n] == '') { |
|
429 | + continue; |
|
430 | + } |
|
407 | 431 | |
408 | 432 | // First, let's first check for PHP upload errors. |
409 | 433 | $errors = array(); |
410 | 434 | if (!empty($_FILES['attachment']['error'][$n])) |
411 | 435 | { |
412 | - if ($_FILES['attachment']['error'][$n] == 2) |
|
413 | - $errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit'])); |
|
414 | - elseif ($_FILES['attachment']['error'][$n] == 6) |
|
415 | - log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical'); |
|
416 | - else |
|
417 | - log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]); |
|
418 | - if (empty($errors)) |
|
419 | - $errors[] = 'attach_php_error'; |
|
436 | + if ($_FILES['attachment']['error'][$n] == 2) { |
|
437 | + $errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit'])); |
|
438 | + } elseif ($_FILES['attachment']['error'][$n] == 6) { |
|
439 | + log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical'); |
|
440 | + } else { |
|
441 | + log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]); |
|
442 | + } |
|
443 | + if (empty($errors)) { |
|
444 | + $errors[] = 'attach_php_error'; |
|
445 | + } |
|
420 | 446 | } |
421 | 447 | |
422 | 448 | // Try to move and rename the file before doing any more checks on it. |
@@ -426,8 +452,9 @@ discard block |
||
426 | 452 | { |
427 | 453 | // The reported MIME type of the attachment might not be reliable. |
428 | 454 | // Fortunately, PHP 5.3+ lets us easily verify the real MIME type. |
429 | - if (function_exists('mime_content_type')) |
|
430 | - $_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]); |
|
455 | + if (function_exists('mime_content_type')) { |
|
456 | + $_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]); |
|
457 | + } |
|
431 | 458 | |
432 | 459 | $_SESSION['temp_attachments'][$attachID] = array( |
433 | 460 | 'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])), |
@@ -439,16 +466,16 @@ discard block |
||
439 | 466 | ); |
440 | 467 | |
441 | 468 | // Move the file to the attachments folder with a temp name for now. |
442 | - if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) |
|
443 | - smf_chmod($destName, 0644); |
|
444 | - else |
|
469 | + if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) { |
|
470 | + smf_chmod($destName, 0644); |
|
471 | + } else |
|
445 | 472 | { |
446 | 473 | $_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout'; |
447 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
448 | - unlink($_FILES['attachment']['tmp_name'][$n]); |
|
474 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) { |
|
475 | + unlink($_FILES['attachment']['tmp_name'][$n]); |
|
476 | + } |
|
449 | 477 | } |
450 | - } |
|
451 | - else |
|
478 | + } else |
|
452 | 479 | { |
453 | 480 | $_SESSION['temp_attachments'][$attachID] = array( |
454 | 481 | 'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])), |
@@ -456,12 +483,14 @@ discard block |
||
456 | 483 | 'errors' => $errors, |
457 | 484 | ); |
458 | 485 | |
459 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
460 | - unlink($_FILES['attachment']['tmp_name'][$n]); |
|
486 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) { |
|
487 | + unlink($_FILES['attachment']['tmp_name'][$n]); |
|
488 | + } |
|
461 | 489 | } |
462 | 490 | // If there's no errors to this point. We still do need to apply some additional checks before we are finished. |
463 | - if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) |
|
464 | - attachmentChecks($attachID); |
|
491 | + if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) { |
|
492 | + attachmentChecks($attachID); |
|
493 | + } |
|
465 | 494 | } |
466 | 495 | // Mod authors, finally a hook to hang an alternate attachment upload system upon |
467 | 496 | // Upload to the current attachment folder with the file name $attachID or 'post_tmp_' . $user_info['id'] . '_' . md5(mt_rand()) |
@@ -488,21 +517,20 @@ discard block |
||
488 | 517 | global $modSettings, $context, $sourcedir, $smcFunc; |
489 | 518 | |
490 | 519 | // No data or missing data .... Not necessarily needed, but in case a mod author missed something. |
491 | - if (empty($_SESSION['temp_attachments'][$attachID])) |
|
492 | - $error = '$_SESSION[\'temp_attachments\'][$attachID]'; |
|
493 | - |
|
494 | - elseif (empty($attachID)) |
|
495 | - $error = '$attachID'; |
|
496 | - |
|
497 | - elseif (empty($context['attachments'])) |
|
498 | - $error = '$context[\'attachments\']'; |
|
499 | - |
|
500 | - elseif (empty($context['attach_dir'])) |
|
501 | - $error = '$context[\'attach_dir\']'; |
|
520 | + if (empty($_SESSION['temp_attachments'][$attachID])) { |
|
521 | + $error = '$_SESSION[\'temp_attachments\'][$attachID]'; |
|
522 | + } elseif (empty($attachID)) { |
|
523 | + $error = '$attachID'; |
|
524 | + } elseif (empty($context['attachments'])) { |
|
525 | + $error = '$context[\'attachments\']'; |
|
526 | + } elseif (empty($context['attach_dir'])) { |
|
527 | + $error = '$context[\'attach_dir\']'; |
|
528 | + } |
|
502 | 529 | |
503 | 530 | // Let's get their attention. |
504 | - if (!empty($error)) |
|
505 | - fatal_lang_error('attach_check_nag', 'debug', array($error)); |
|
531 | + if (!empty($error)) { |
|
532 | + fatal_lang_error('attach_check_nag', 'debug', array($error)); |
|
533 | + } |
|
506 | 534 | |
507 | 535 | // Just in case this slipped by the first checks, we stop it here and now |
508 | 536 | if ($_SESSION['temp_attachments'][$attachID]['size'] == 0) |
@@ -531,8 +559,9 @@ discard block |
||
531 | 559 | $size = @getimagesize($_SESSION['temp_attachments'][$attachID]['tmp_name']); |
532 | 560 | if (!(empty($size)) && ($size[2] != $old_format)) |
533 | 561 | { |
534 | - if (isset($context['validImageTypes'][$size[2]])) |
|
535 | - $_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]]; |
|
562 | + if (isset($context['validImageTypes'][$size[2]])) { |
|
563 | + $_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]]; |
|
564 | + } |
|
536 | 565 | } |
537 | 566 | } |
538 | 567 | } |
@@ -586,42 +615,48 @@ discard block |
||
586 | 615 | // Or, let the user know that it ain't gonna happen. |
587 | 616 | else |
588 | 617 | { |
589 | - if (isset($context['dir_creation_error'])) |
|
590 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error']; |
|
591 | - else |
|
592 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space'; |
|
618 | + if (isset($context['dir_creation_error'])) { |
|
619 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error']; |
|
620 | + } else { |
|
621 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space'; |
|
622 | + } |
|
593 | 623 | } |
624 | + } else { |
|
625 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space'; |
|
594 | 626 | } |
595 | - else |
|
596 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space'; |
|
597 | 627 | } |
598 | 628 | } |
599 | 629 | |
600 | 630 | // Is the file too big? |
601 | 631 | $context['attachments']['total_size'] += $_SESSION['temp_attachments'][$attachID]['size']; |
602 | - if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024) |
|
603 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0))); |
|
632 | + if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024) { |
|
633 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0))); |
|
634 | + } |
|
604 | 635 | |
605 | 636 | // Check the total upload size for this post... |
606 | - if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024) |
|
607 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0))); |
|
637 | + if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024) { |
|
638 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0))); |
|
639 | + } |
|
608 | 640 | |
609 | 641 | // Have we reached the maximum number of files we are allowed? |
610 | 642 | $context['attachments']['quantity']++; |
611 | 643 | |
612 | 644 | // Set a max limit if none exists |
613 | - if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50) |
|
614 | - $modSettings['attachmentNumPerPostLimit'] = 50; |
|
645 | + if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50) { |
|
646 | + $modSettings['attachmentNumPerPostLimit'] = 50; |
|
647 | + } |
|
615 | 648 | |
616 | - if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit']) |
|
617 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit'])); |
|
649 | + if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit']) { |
|
650 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit'])); |
|
651 | + } |
|
618 | 652 | |
619 | 653 | // File extension check |
620 | 654 | if (!empty($modSettings['attachmentCheckExtensions'])) |
621 | 655 | { |
622 | 656 | $allowed = explode(',', strtolower($modSettings['attachmentExtensions'])); |
623 | - foreach ($allowed as $k => $dummy) |
|
624 | - $allowed[$k] = trim($dummy); |
|
657 | + foreach ($allowed as $k => $dummy) { |
|
658 | + $allowed[$k] = trim($dummy); |
|
659 | + } |
|
625 | 660 | |
626 | 661 | if (!in_array(strtolower(substr(strrchr($_SESSION['temp_attachments'][$attachID]['name'], '.'), 1)), $allowed)) |
627 | 662 | { |
@@ -633,10 +668,12 @@ discard block |
||
633 | 668 | // Undo the math if there's an error |
634 | 669 | if (!empty($_SESSION['temp_attachments'][$attachID]['errors'])) |
635 | 670 | { |
636 | - if (isset($context['dir_size'])) |
|
637 | - $context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size']; |
|
638 | - if (isset($context['dir_files'])) |
|
639 | - $context['dir_files']--; |
|
671 | + if (isset($context['dir_size'])) { |
|
672 | + $context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size']; |
|
673 | + } |
|
674 | + if (isset($context['dir_files'])) { |
|
675 | + $context['dir_files']--; |
|
676 | + } |
|
640 | 677 | $context['attachments']['total_size'] -= $_SESSION['temp_attachments'][$attachID]['size']; |
641 | 678 | $context['attachments']['quantity']--; |
642 | 679 | return false; |
@@ -668,12 +705,14 @@ discard block |
||
668 | 705 | if (empty($attachmentOptions['mime_type']) && $attachmentOptions['width']) |
669 | 706 | { |
670 | 707 | // Got a proper mime type? |
671 | - if (!empty($size['mime'])) |
|
672 | - $attachmentOptions['mime_type'] = $size['mime']; |
|
708 | + if (!empty($size['mime'])) { |
|
709 | + $attachmentOptions['mime_type'] = $size['mime']; |
|
710 | + } |
|
673 | 711 | |
674 | 712 | // Otherwise a valid one? |
675 | - elseif (isset($context['validImageTypes'][$size[2]])) |
|
676 | - $attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]]; |
|
713 | + elseif (isset($context['validImageTypes'][$size[2]])) { |
|
714 | + $attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]]; |
|
715 | + } |
|
677 | 716 | } |
678 | 717 | |
679 | 718 | // It is possible we might have a MIME type that isn't actually an image but still have a size. |
@@ -685,15 +724,17 @@ discard block |
||
685 | 724 | } |
686 | 725 | |
687 | 726 | // Get the hash if no hash has been given yet. |
688 | - if (empty($attachmentOptions['file_hash'])) |
|
689 | - $attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true); |
|
727 | + if (empty($attachmentOptions['file_hash'])) { |
|
728 | + $attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true); |
|
729 | + } |
|
690 | 730 | |
691 | 731 | // Assuming no-one set the extension let's take a look at it. |
692 | 732 | if (empty($attachmentOptions['fileext'])) |
693 | 733 | { |
694 | 734 | $attachmentOptions['fileext'] = strtolower(strrpos($attachmentOptions['name'], '.') !== false ? substr($attachmentOptions['name'], strrpos($attachmentOptions['name'], '.') + 1) : ''); |
695 | - if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name']) |
|
696 | - $attachmentOptions['fileext'] = ''; |
|
735 | + if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name']) { |
|
736 | + $attachmentOptions['fileext'] = ''; |
|
737 | + } |
|
697 | 738 | } |
698 | 739 | |
699 | 740 | // Last chance to change stuff! |
@@ -702,8 +743,9 @@ discard block |
||
702 | 743 | // Make sure the folder is valid... |
703 | 744 | $tmp = is_array($modSettings['attachmentUploadDir']) ? $modSettings['attachmentUploadDir'] : $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true); |
704 | 745 | $folders = array_keys($tmp); |
705 | - if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders)) |
|
706 | - $attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir']; |
|
746 | + if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders)) { |
|
747 | + $attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir']; |
|
748 | + } |
|
707 | 749 | |
708 | 750 | $attachmentOptions['id'] = $smcFunc['db_insert']('', |
709 | 751 | '{db_prefix}attachments', |
@@ -734,8 +776,8 @@ discard block |
||
734 | 776 | rename($attachmentOptions['tmp_name'], $attachmentOptions['destination']); |
735 | 777 | |
736 | 778 | // If it's not approved then add to the approval queue. |
737 | - if (!$attachmentOptions['approved']) |
|
738 | - $smcFunc['db_insert']('', |
|
779 | + if (!$attachmentOptions['approved']) { |
|
780 | + $smcFunc['db_insert']('', |
|
739 | 781 | '{db_prefix}approval_queue', |
740 | 782 | array( |
741 | 783 | 'id_attach' => 'int', 'id_msg' => 'int', |
@@ -745,9 +787,11 @@ discard block |
||
745 | 787 | ), |
746 | 788 | array() |
747 | 789 | ); |
790 | + } |
|
748 | 791 | |
749 | - if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height']))) |
|
750 | - return true; |
|
792 | + if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height']))) { |
|
793 | + return true; |
|
794 | + } |
|
751 | 795 | |
752 | 796 | // Like thumbnails, do we? |
753 | 797 | if (!empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && ($attachmentOptions['width'] > $modSettings['attachmentThumbWidth'] || $attachmentOptions['height'] > $modSettings['attachmentThumbHeight'])) |
@@ -758,13 +802,15 @@ discard block |
||
758 | 802 | $size = @getimagesize($attachmentOptions['destination'] . '_thumb'); |
759 | 803 | list ($thumb_width, $thumb_height) = $size; |
760 | 804 | |
761 | - if (!empty($size['mime'])) |
|
762 | - $thumb_mime = $size['mime']; |
|
763 | - elseif (isset($context['validImageTypes'][$size[2]])) |
|
764 | - $thumb_mime = 'image/' . $context['validImageTypes'][$size[2]]; |
|
805 | + if (!empty($size['mime'])) { |
|
806 | + $thumb_mime = $size['mime']; |
|
807 | + } elseif (isset($context['validImageTypes'][$size[2]])) { |
|
808 | + $thumb_mime = 'image/' . $context['validImageTypes'][$size[2]]; |
|
809 | + } |
|
765 | 810 | // Lord only knows how this happened... |
766 | - else |
|
767 | - $thumb_mime = ''; |
|
811 | + else { |
|
812 | + $thumb_mime = ''; |
|
813 | + } |
|
768 | 814 | |
769 | 815 | $thumb_filename = $attachmentOptions['name'] . '_thumb'; |
770 | 816 | $thumb_size = filesize($attachmentOptions['destination'] . '_thumb'); |
@@ -844,15 +890,17 @@ discard block |
||
844 | 890 | global $smcFunc; |
845 | 891 | |
846 | 892 | // Oh, come on! |
847 | - if (empty($attachIDs) || empty($msgID)) |
|
848 | - return false; |
|
893 | + if (empty($attachIDs) || empty($msgID)) { |
|
894 | + return false; |
|
895 | + } |
|
849 | 896 | |
850 | 897 | // "I see what is right and approve, but I do what is wrong." |
851 | 898 | call_integration_hook('integrate_assign_attachments', array(&$attachIDs, &$msgID)); |
852 | 899 | |
853 | 900 | // One last check |
854 | - if (empty($attachIDs)) |
|
855 | - return false; |
|
901 | + if (empty($attachIDs)) { |
|
902 | + return false; |
|
903 | + } |
|
856 | 904 | |
857 | 905 | // Perform. |
858 | 906 | $smcFunc['db_query']('', ' |
@@ -880,8 +928,9 @@ discard block |
||
880 | 928 | global $board, $modSettings, $context, $scripturl, $smcFunc; |
881 | 929 | |
882 | 930 | // Meh... |
883 | - if (empty($attachID)) |
|
884 | - return 'attachments_no_data_loaded'; |
|
931 | + if (empty($attachID)) { |
|
932 | + return 'attachments_no_data_loaded'; |
|
933 | + } |
|
885 | 934 | |
886 | 935 | // Make it easy. |
887 | 936 | $msgID = !empty($_REQUEST['msg']) ? (int) $_REQUEST['msg'] : 0; |
@@ -890,20 +939,23 @@ discard block |
||
890 | 939 | $externalParse = call_integration_hook('integrate_pre_parseAttachBBC', array($attachID, $msgID)); |
891 | 940 | |
892 | 941 | // "I am innocent of the blood of this just person: see ye to it." |
893 | - if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse))) |
|
894 | - return $externalParse; |
|
942 | + if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse))) { |
|
943 | + return $externalParse; |
|
944 | + } |
|
895 | 945 | |
896 | 946 | //Are attachments enable? |
897 | - if (empty($modSettings['attachmentEnable'])) |
|
898 | - return 'attachments_not_enable'; |
|
947 | + if (empty($modSettings['attachmentEnable'])) { |
|
948 | + return 'attachments_not_enable'; |
|
949 | + } |
|
899 | 950 | |
900 | 951 | // Previewing much? no msg ID has been set yet. |
901 | 952 | if (!empty($context['preview_message'])) |
902 | 953 | { |
903 | 954 | $allAttachments = getAttachsByMsg(0); |
904 | 955 | |
905 | - if (empty($allAttachments[0][$attachID])) |
|
906 | - return 'attachments_no_data_loaded'; |
|
956 | + if (empty($allAttachments[0][$attachID])) { |
|
957 | + return 'attachments_no_data_loaded'; |
|
958 | + } |
|
907 | 959 | |
908 | 960 | $attachLoaded = loadAttachmentContext(0, $allAttachments); |
909 | 961 | |
@@ -915,57 +967,66 @@ discard block |
||
915 | 967 | $attachContext['link'] = '<a href="' . $scripturl . '?action=dlattach;attach=' . $attachID . ';type=preview' . (empty($attachContext['is_image']) ? ';file' : '') . '">' . $smcFunc['htmlspecialchars']($attachContext['name']) . '</a>'; |
916 | 968 | |
917 | 969 | // Fix the thumbnail too, if the image has one. |
918 | - if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb'])) |
|
919 | - $attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview'; |
|
970 | + if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb'])) { |
|
971 | + $attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview'; |
|
972 | + } |
|
920 | 973 | |
921 | 974 | return $attachContext; |
922 | 975 | } |
923 | 976 | |
924 | 977 | // There is always the chance someone else has already done our dirty work... |
925 | 978 | // If so, all pertinent checks were already done. Hopefully... |
926 | - if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID])) |
|
927 | - return $context['current_attachments'][$attachID]; |
|
979 | + if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID])) { |
|
980 | + return $context['current_attachments'][$attachID]; |
|
981 | + } |
|
928 | 982 | |
929 | 983 | // If we are lucky enough to be in $board's scope then check it! |
930 | - if (!empty($board) && !allowedTo('view_attachments', $board)) |
|
931 | - return 'attachments_not_allowed_to_see'; |
|
984 | + if (!empty($board) && !allowedTo('view_attachments', $board)) { |
|
985 | + return 'attachments_not_allowed_to_see'; |
|
986 | + } |
|
932 | 987 | |
933 | 988 | // Get the message info associated with this particular attach ID. |
934 | 989 | $attachInfo = getAttachMsgInfo($attachID); |
935 | 990 | |
936 | 991 | // There is always the chance this attachment no longer exists or isn't associated to a message anymore... |
937 | - if (empty($attachInfo) || empty($attachInfo['msg'])) |
|
938 | - return 'attachments_no_msg_associated'; |
|
992 | + if (empty($attachInfo) || empty($attachInfo['msg'])) { |
|
993 | + return 'attachments_no_msg_associated'; |
|
994 | + } |
|
939 | 995 | |
940 | 996 | // Hold it! got the info now check if you can see this attachment. |
941 | - if (!allowedTo('view_attachments', $attachInfo['board'])) |
|
942 | - return 'attachments_not_allowed_to_see'; |
|
997 | + if (!allowedTo('view_attachments', $attachInfo['board'])) { |
|
998 | + return 'attachments_not_allowed_to_see'; |
|
999 | + } |
|
943 | 1000 | |
944 | 1001 | $allAttachments = getAttachsByMsg($attachInfo['msg']); |
945 | 1002 | $attachContext = $allAttachments[$attachInfo['msg']][$attachID]; |
946 | 1003 | |
947 | 1004 | // No point in keep going further. |
948 | - if (!allowedTo('view_attachments', $attachContext['board'])) |
|
949 | - return 'attachments_not_allowed_to_see'; |
|
1005 | + if (!allowedTo('view_attachments', $attachContext['board'])) { |
|
1006 | + return 'attachments_not_allowed_to_see'; |
|
1007 | + } |
|
950 | 1008 | |
951 | 1009 | // Load this particular attach's context. |
952 | - if (!empty($attachContext)) |
|
953 | - $attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments); |
|
1010 | + if (!empty($attachContext)) { |
|
1011 | + $attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments); |
|
1012 | + } |
|
954 | 1013 | |
955 | 1014 | // One last check, you know, gotta be paranoid... |
956 | - else |
|
957 | - return 'attachments_no_data_loaded'; |
|
1015 | + else { |
|
1016 | + return 'attachments_no_data_loaded'; |
|
1017 | + } |
|
958 | 1018 | |
959 | 1019 | // This is the last "if" I promise! |
960 | - if (empty($attachLoaded)) |
|
961 | - return 'attachments_no_data_loaded'; |
|
962 | - |
|
963 | - else |
|
964 | - $attachContext = $attachLoaded[$attachID]; |
|
1020 | + if (empty($attachLoaded)) { |
|
1021 | + return 'attachments_no_data_loaded'; |
|
1022 | + } else { |
|
1023 | + $attachContext = $attachLoaded[$attachID]; |
|
1024 | + } |
|
965 | 1025 | |
966 | 1026 | // You may or may not want to show this under the post. |
967 | - if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID])) |
|
968 | - $context['show_attach_under_post'][$attachID] = $attachID; |
|
1027 | + if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID])) { |
|
1028 | + $context['show_attach_under_post'][$attachID] = $attachID; |
|
1029 | + } |
|
969 | 1030 | |
970 | 1031 | // Last minute changes? |
971 | 1032 | call_integration_hook('integrate_post_parseAttachBBC', array(&$attachContext)); |
@@ -985,8 +1046,9 @@ discard block |
||
985 | 1046 | { |
986 | 1047 | global $smcFunc, $modSettings; |
987 | 1048 | |
988 | - if (empty($attachIDs)) |
|
989 | - return array(); |
|
1049 | + if (empty($attachIDs)) { |
|
1050 | + return array(); |
|
1051 | + } |
|
990 | 1052 | |
991 | 1053 | $return = array(); |
992 | 1054 | |
@@ -1002,11 +1064,12 @@ discard block |
||
1002 | 1064 | ) |
1003 | 1065 | ); |
1004 | 1066 | |
1005 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
1006 | - return array(); |
|
1067 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
1068 | + return array(); |
|
1069 | + } |
|
1007 | 1070 | |
1008 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1009 | - $return[$row['id_attach']] = array( |
|
1071 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1072 | + $return[$row['id_attach']] = array( |
|
1010 | 1073 | 'name' => $smcFunc['htmlspecialchars']($row['filename']), |
1011 | 1074 | 'size' => $row['size'], |
1012 | 1075 | 'attachID' => $row['id_attach'], |
@@ -1015,6 +1078,7 @@ discard block |
||
1015 | 1078 | 'mime_type' => $row['mime_type'], |
1016 | 1079 | 'thumb' => $row['id_thumb'], |
1017 | 1080 | ); |
1081 | + } |
|
1018 | 1082 | $smcFunc['db_free_result']($request); |
1019 | 1083 | |
1020 | 1084 | return $return; |
@@ -1031,8 +1095,9 @@ discard block |
||
1031 | 1095 | { |
1032 | 1096 | global $smcFunc; |
1033 | 1097 | |
1034 | - if (empty($attachID)) |
|
1035 | - return array(); |
|
1098 | + if (empty($attachID)) { |
|
1099 | + return array(); |
|
1100 | + } |
|
1036 | 1101 | |
1037 | 1102 | $request = $smcFunc['db_query']('', ' |
1038 | 1103 | SELECT a.id_msg AS msg, m.id_topic AS topic, m.id_board AS board |
@@ -1045,8 +1110,9 @@ discard block |
||
1045 | 1110 | ) |
1046 | 1111 | ); |
1047 | 1112 | |
1048 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
1049 | - return array(); |
|
1113 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
1114 | + return array(); |
|
1115 | + } |
|
1050 | 1116 | |
1051 | 1117 | $row = $smcFunc['db_fetch_assoc']($request); |
1052 | 1118 | $smcFunc['db_free_result']($request); |
@@ -1087,8 +1153,9 @@ discard block |
||
1087 | 1153 | $temp = array(); |
1088 | 1154 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1089 | 1155 | { |
1090 | - if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) |
|
1091 | - continue; |
|
1156 | + if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) { |
|
1157 | + continue; |
|
1158 | + } |
|
1092 | 1159 | |
1093 | 1160 | $temp[$row['id_attach']] = $row; |
1094 | 1161 | } |
@@ -1117,8 +1184,9 @@ discard block |
||
1117 | 1184 | { |
1118 | 1185 | global $modSettings, $txt, $scripturl, $sourcedir, $smcFunc; |
1119 | 1186 | |
1120 | - if (empty($attachments) || empty($attachments[$id_msg])) |
|
1121 | - return array(); |
|
1187 | + if (empty($attachments) || empty($attachments[$id_msg])) { |
|
1188 | + return array(); |
|
1189 | + } |
|
1122 | 1190 | |
1123 | 1191 | // Set up the attachment info - based on code by Meriadoc. |
1124 | 1192 | $attachmentData = array(); |
@@ -1142,11 +1210,13 @@ discard block |
||
1142 | 1210 | ); |
1143 | 1211 | |
1144 | 1212 | // If something is unapproved we'll note it so we can sort them. |
1145 | - if (!$attachment['approved']) |
|
1146 | - $have_unapproved = true; |
|
1213 | + if (!$attachment['approved']) { |
|
1214 | + $have_unapproved = true; |
|
1215 | + } |
|
1147 | 1216 | |
1148 | - if (!$attachmentData[$i]['is_image']) |
|
1149 | - continue; |
|
1217 | + if (!$attachmentData[$i]['is_image']) { |
|
1218 | + continue; |
|
1219 | + } |
|
1150 | 1220 | |
1151 | 1221 | $attachmentData[$i]['real_width'] = $attachment['width']; |
1152 | 1222 | $attachmentData[$i]['width'] = $attachment['width']; |
@@ -1167,11 +1237,11 @@ discard block |
||
1167 | 1237 | // So what folder are we putting this image in? |
1168 | 1238 | if (!empty($modSettings['currentAttachmentUploadDir'])) |
1169 | 1239 | { |
1170 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
1171 | - $modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true); |
|
1240 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
1241 | + $modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true); |
|
1242 | + } |
|
1172 | 1243 | $id_folder_thumb = $modSettings['currentAttachmentUploadDir']; |
1173 | - } |
|
1174 | - else |
|
1244 | + } else |
|
1175 | 1245 | { |
1176 | 1246 | $id_folder_thumb = 1; |
1177 | 1247 | } |
@@ -1185,10 +1255,11 @@ discard block |
||
1185 | 1255 | $thumb_ext = isset($context['validImageTypes'][$size[2]]) ? $context['validImageTypes'][$size[2]] : ''; |
1186 | 1256 | |
1187 | 1257 | // Figure out the mime type. |
1188 | - if (!empty($size['mime'])) |
|
1189 | - $thumb_mime = $size['mime']; |
|
1190 | - else |
|
1191 | - $thumb_mime = 'image/' . $thumb_ext; |
|
1258 | + if (!empty($size['mime'])) { |
|
1259 | + $thumb_mime = $size['mime']; |
|
1260 | + } else { |
|
1261 | + $thumb_mime = 'image/' . $thumb_ext; |
|
1262 | + } |
|
1192 | 1263 | |
1193 | 1264 | $thumb_filename = $attachment['filename'] . '_thumb'; |
1194 | 1265 | $thumb_hash = getAttachmentFilename($thumb_filename, false, null, true); |
@@ -1235,11 +1306,12 @@ discard block |
||
1235 | 1306 | } |
1236 | 1307 | } |
1237 | 1308 | |
1238 | - if (!empty($attachment['id_thumb'])) |
|
1239 | - $attachmentData[$i]['thumbnail'] = array( |
|
1309 | + if (!empty($attachment['id_thumb'])) { |
|
1310 | + $attachmentData[$i]['thumbnail'] = array( |
|
1240 | 1311 | 'id' => $attachment['id_thumb'], |
1241 | 1312 | 'href' => $scripturl . '?action=dlattach;topic=' . $attachment['topic'] . '.0;attach=' . $attachment['id_thumb'] . ';image', |
1242 | 1313 | ); |
1314 | + } |
|
1243 | 1315 | $attachmentData[$i]['thumbnail']['has_thumb'] = !empty($attachment['id_thumb']); |
1244 | 1316 | |
1245 | 1317 | // If thumbnails are disabled, check the maximum size of the image. |
@@ -1249,30 +1321,31 @@ discard block |
||
1249 | 1321 | { |
1250 | 1322 | $attachmentData[$i]['width'] = $modSettings['max_image_width']; |
1251 | 1323 | $attachmentData[$i]['height'] = floor($attachment['height'] * $modSettings['max_image_width'] / $attachment['width']); |
1252 | - } |
|
1253 | - elseif (!empty($modSettings['max_image_width'])) |
|
1324 | + } elseif (!empty($modSettings['max_image_width'])) |
|
1254 | 1325 | { |
1255 | 1326 | $attachmentData[$i]['width'] = floor($attachment['width'] * $modSettings['max_image_height'] / $attachment['height']); |
1256 | 1327 | $attachmentData[$i]['height'] = $modSettings['max_image_height']; |
1257 | 1328 | } |
1258 | - } |
|
1259 | - elseif ($attachmentData[$i]['thumbnail']['has_thumb']) |
|
1329 | + } elseif ($attachmentData[$i]['thumbnail']['has_thumb']) |
|
1260 | 1330 | { |
1261 | 1331 | // If the image is too large to show inline, make it a popup. |
1262 | - if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height']))) |
|
1263 | - $attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);'; |
|
1264 | - else |
|
1265 | - $attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');'; |
|
1332 | + if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height']))) { |
|
1333 | + $attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);'; |
|
1334 | + } else { |
|
1335 | + $attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');'; |
|
1336 | + } |
|
1266 | 1337 | } |
1267 | 1338 | |
1268 | - if (!$attachmentData[$i]['thumbnail']['has_thumb']) |
|
1269 | - $attachmentData[$i]['downloads']++; |
|
1339 | + if (!$attachmentData[$i]['thumbnail']['has_thumb']) { |
|
1340 | + $attachmentData[$i]['downloads']++; |
|
1341 | + } |
|
1270 | 1342 | } |
1271 | 1343 | } |
1272 | 1344 | |
1273 | 1345 | // Do we need to instigate a sort? |
1274 | - if ($have_unapproved) |
|
1275 | - usort($attachmentData, 'approved_attach_sort'); |
|
1346 | + if ($have_unapproved) { |
|
1347 | + usort($attachmentData, 'approved_attach_sort'); |
|
1348 | + } |
|
1276 | 1349 | |
1277 | 1350 | return $attachmentData; |
1278 | 1351 | } |
@@ -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 | * This is the notoriously defunct package manager..... :/. |
@@ -57,10 +58,11 @@ discard block |
||
57 | 58 | ); |
58 | 59 | |
59 | 60 | // Work out exactly who it is we are calling. |
60 | - if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) |
|
61 | - $context['sub_action'] = $_REQUEST['sa']; |
|
62 | - else |
|
63 | - $context['sub_action'] = 'browse'; |
|
61 | + if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) { |
|
62 | + $context['sub_action'] = $_REQUEST['sa']; |
|
63 | + } else { |
|
64 | + $context['sub_action'] = 'browse'; |
|
65 | + } |
|
64 | 66 | |
65 | 67 | // Set up some tabs... |
66 | 68 | $context[$context['admin_menu_name']]['tab_data'] = array( |
@@ -82,8 +84,9 @@ discard block |
||
82 | 84 | ), |
83 | 85 | ); |
84 | 86 | |
85 | - if ($context['sub_action'] == 'browse') |
|
86 | - loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest'); |
|
87 | + if ($context['sub_action'] == 'browse') { |
|
88 | + loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest'); |
|
89 | + } |
|
87 | 90 | |
88 | 91 | call_integration_hook('integrate_manage_packages', array(&$subActions)); |
89 | 92 | |
@@ -99,8 +102,9 @@ discard block |
||
99 | 102 | global $boarddir, $txt, $context, $scripturl, $sourcedir, $packagesdir, $modSettings, $smcFunc, $settings; |
100 | 103 | |
101 | 104 | // You have to specify a file!! |
102 | - if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') |
|
103 | - redirectexit('action=admin;area=packages'); |
|
105 | + if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') { |
|
106 | + redirectexit('action=admin;area=packages'); |
|
107 | + } |
|
104 | 108 | $context['filename'] = preg_replace('~[\.]+~', '.', $_REQUEST['package']); |
105 | 109 | |
106 | 110 | // Do we have an existing id, for uninstalls and the like. |
@@ -112,8 +116,9 @@ discard block |
||
112 | 116 | create_chmod_control(); |
113 | 117 | |
114 | 118 | // Make sure temp directory exists and is empty. |
115 | - if (file_exists($packagesdir . '/temp')) |
|
116 | - deltree($packagesdir . '/temp', false); |
|
119 | + if (file_exists($packagesdir . '/temp')) { |
|
120 | + deltree($packagesdir . '/temp', false); |
|
121 | + } |
|
117 | 122 | |
118 | 123 | if (!mktree($packagesdir . '/temp', 0755)) |
119 | 124 | { |
@@ -124,8 +129,9 @@ discard block |
||
124 | 129 | create_chmod_control(array($packagesdir . '/temp/delme.tmp'), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=' . $_REQUEST['sa'] . ';package=' . $_REQUEST['package'], 'crash_on_error' => true)); |
125 | 130 | |
126 | 131 | deltree($packagesdir . '/temp', false); |
127 | - if (!mktree($packagesdir . '/temp', 0777)) |
|
128 | - fatal_lang_error('package_cant_download', false); |
|
132 | + if (!mktree($packagesdir . '/temp', 0777)) { |
|
133 | + fatal_lang_error('package_cant_download', false); |
|
134 | + } |
|
129 | 135 | } |
130 | 136 | } |
131 | 137 | |
@@ -151,25 +157,26 @@ discard block |
||
151 | 157 | { |
152 | 158 | $context['extracted_files'] = read_tgz_file($packagesdir . '/' . $context['filename'], $packagesdir . '/temp'); |
153 | 159 | |
154 | - if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml')) |
|
155 | - foreach ($context['extracted_files'] as $file) |
|
160 | + if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml')) { |
|
161 | + foreach ($context['extracted_files'] as $file) |
|
156 | 162 | if (basename($file['filename']) == 'package-info.xml') |
157 | 163 | { |
158 | 164 | $context['base_path'] = dirname($file['filename']) . '/'; |
165 | + } |
|
159 | 166 | break; |
160 | 167 | } |
161 | 168 | |
162 | - if (!isset($context['base_path'])) |
|
163 | - $context['base_path'] = ''; |
|
164 | - } |
|
165 | - elseif (is_dir($packagesdir . '/' . $context['filename'])) |
|
169 | + if (!isset($context['base_path'])) { |
|
170 | + $context['base_path'] = ''; |
|
171 | + } |
|
172 | + } elseif (is_dir($packagesdir . '/' . $context['filename'])) |
|
166 | 173 | { |
167 | 174 | copytree($packagesdir . '/' . $context['filename'], $packagesdir . '/temp'); |
168 | 175 | $context['extracted_files'] = listtree($packagesdir . '/temp'); |
169 | 176 | $context['base_path'] = ''; |
177 | + } else { |
|
178 | + fatal_lang_error('no_access', false); |
|
170 | 179 | } |
171 | - else |
|
172 | - fatal_lang_error('no_access', false); |
|
173 | 180 | |
174 | 181 | // Load up any custom themes we may want to install into... |
175 | 182 | $request = $smcFunc['db_query']('', ' |
@@ -185,15 +192,17 @@ discard block |
||
185 | 192 | ) |
186 | 193 | ); |
187 | 194 | $theme_paths = array(); |
188 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
189 | - $theme_paths[$row['id_theme']][$row['variable']] = $row['value']; |
|
195 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
196 | + $theme_paths[$row['id_theme']][$row['variable']] = $row['value']; |
|
197 | + } |
|
190 | 198 | $smcFunc['db_free_result']($request); |
191 | 199 | |
192 | 200 | // Get the package info... |
193 | 201 | $packageInfo = getPackageInfo($context['filename']); |
194 | 202 | |
195 | - if (!is_array($packageInfo)) |
|
196 | - fatal_lang_error($packageInfo); |
|
203 | + if (!is_array($packageInfo)) { |
|
204 | + fatal_lang_error($packageInfo); |
|
205 | + } |
|
197 | 206 | |
198 | 207 | $packageInfo['filename'] = $context['filename']; |
199 | 208 | $context['package_name'] = isset($packageInfo['name']) ? $packageInfo['name'] : $context['filename']; |
@@ -227,18 +236,19 @@ discard block |
||
227 | 236 | $smcFunc['db_free_result']($request); |
228 | 237 | |
229 | 238 | $context['database_changes'] = array(); |
230 | - if (isset($packageInfo['uninstall']['database'])) |
|
231 | - $context['database_changes'][] = $txt['execute_database_changes'] . ' - ' . $packageInfo['uninstall']['database']; |
|
232 | - elseif (!empty($db_changes)) |
|
239 | + if (isset($packageInfo['uninstall']['database'])) { |
|
240 | + $context['database_changes'][] = $txt['execute_database_changes'] . ' - ' . $packageInfo['uninstall']['database']; |
|
241 | + } elseif (!empty($db_changes)) |
|
233 | 242 | { |
234 | 243 | foreach ($db_changes as $change) |
235 | 244 | { |
236 | - if (isset($change[2]) && isset($txt['package_db_' . $change[0]])) |
|
237 | - $context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1], $change[2]); |
|
238 | - elseif (isset($txt['package_db_' . $change[0]])) |
|
239 | - $context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1]); |
|
240 | - else |
|
241 | - $context['database_changes'][] = $change[0] . '-' . $change[1] . (isset($change[2]) ? '-' . $change[2] : ''); |
|
245 | + if (isset($change[2]) && isset($txt['package_db_' . $change[0]])) { |
|
246 | + $context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1], $change[2]); |
|
247 | + } elseif (isset($txt['package_db_' . $change[0]])) { |
|
248 | + $context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1]); |
|
249 | + } else { |
|
250 | + $context['database_changes'][] = $change[0] . '-' . $change[1] . (isset($change[2]) ? '-' . $change[2] : ''); |
|
251 | + } |
|
242 | 252 | } |
243 | 253 | } |
244 | 254 | |
@@ -265,31 +275,33 @@ discard block |
||
265 | 275 | $context['themes_locked'] = true; |
266 | 276 | |
267 | 277 | // Only let them uninstall themes it was installed into. |
268 | - foreach ($theme_paths as $id => $data) |
|
269 | - if ($id != 1 && !in_array($id, $old_themes)) |
|
278 | + foreach ($theme_paths as $id => $data) { |
|
279 | + if ($id != 1 && !in_array($id, $old_themes)) |
|
270 | 280 | unset($theme_paths[$id]); |
271 | - } |
|
272 | - elseif (isset($old_version) && $old_version != $packageInfo['version']) |
|
281 | + } |
|
282 | + } elseif (isset($old_version) && $old_version != $packageInfo['version']) |
|
273 | 283 | { |
274 | 284 | // Look for an upgrade... |
275 | 285 | $actions = parsePackageInfo($packageInfo['xml'], true, 'upgrade', $old_version); |
276 | 286 | |
277 | 287 | // There was no upgrade.... |
278 | - if (empty($actions)) |
|
279 | - $context['is_installed'] = true; |
|
280 | - else |
|
288 | + if (empty($actions)) { |
|
289 | + $context['is_installed'] = true; |
|
290 | + } else |
|
281 | 291 | { |
282 | 292 | // Otherwise they can only upgrade themes from the first time around. |
283 | - foreach ($theme_paths as $id => $data) |
|
284 | - if ($id != 1 && !in_array($id, $old_themes)) |
|
293 | + foreach ($theme_paths as $id => $data) { |
|
294 | + if ($id != 1 && !in_array($id, $old_themes)) |
|
285 | 295 | unset($theme_paths[$id]); |
296 | + } |
|
286 | 297 | } |
298 | + } elseif (isset($old_version) && $old_version == $packageInfo['version']) { |
|
299 | + $context['is_installed'] = true; |
|
287 | 300 | } |
288 | - elseif (isset($old_version) && $old_version == $packageInfo['version']) |
|
289 | - $context['is_installed'] = true; |
|
290 | 301 | |
291 | - if (!isset($old_version) || $context['is_installed']) |
|
292 | - $actions = parsePackageInfo($packageInfo['xml'], true, 'install'); |
|
302 | + if (!isset($old_version) || $context['is_installed']) { |
|
303 | + $actions = parsePackageInfo($packageInfo['xml'], true, 'install'); |
|
304 | + } |
|
293 | 305 | |
294 | 306 | $context['actions'] = array(); |
295 | 307 | $context['ftp_needed'] = false; |
@@ -297,8 +309,9 @@ discard block |
||
297 | 309 | $chmod_files = array(); |
298 | 310 | |
299 | 311 | // no actions found, return so we can display an error |
300 | - if (empty($actions)) |
|
301 | - return; |
|
312 | + if (empty($actions)) { |
|
313 | + return; |
|
314 | + } |
|
302 | 315 | |
303 | 316 | // This will hold data about anything that can be installed in other themes. |
304 | 317 | $themeFinds = array( |
@@ -317,14 +330,14 @@ discard block |
||
317 | 330 | { |
318 | 331 | $chmod_files[] = $action['filename']; |
319 | 332 | continue; |
320 | - } |
|
321 | - elseif ($action['type'] == 'readme' || $action['type'] == 'license') |
|
333 | + } elseif ($action['type'] == 'readme' || $action['type'] == 'license') |
|
322 | 334 | { |
323 | 335 | $type = 'package_' . $action['type']; |
324 | - if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) |
|
325 | - $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), "\n\r")); |
|
326 | - elseif (file_exists($action['filename'])) |
|
327 | - $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r")); |
|
336 | + if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) { |
|
337 | + $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), "\n\r")); |
|
338 | + } elseif (file_exists($action['filename'])) { |
|
339 | + $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r")); |
|
340 | + } |
|
328 | 341 | |
329 | 342 | if (!empty($action['parse_bbc'])) |
330 | 343 | { |
@@ -332,24 +345,24 @@ discard block |
||
332 | 345 | $context[$type] = preg_replace('~\[[/]?html\]~i', '', $context[$type]); |
333 | 346 | preparsecode($context[$type]); |
334 | 347 | $context[$type] = parse_bbc($context[$type]); |
348 | + } else { |
|
349 | + $context[$type] = nl2br($context[$type]); |
|
335 | 350 | } |
336 | - else |
|
337 | - $context[$type] = nl2br($context[$type]); |
|
338 | 351 | |
339 | 352 | continue; |
340 | 353 | } |
341 | 354 | // Don't show redirects. |
342 | - elseif ($action['type'] == 'redirect') |
|
343 | - continue; |
|
344 | - elseif ($action['type'] == 'error') |
|
355 | + elseif ($action['type'] == 'redirect') { |
|
356 | + continue; |
|
357 | + } elseif ($action['type'] == 'error') |
|
345 | 358 | { |
346 | 359 | $context['has_failure'] = true; |
347 | - if (isset($action['error_msg']) && isset($action['error_var'])) |
|
348 | - $context['failure_details'] = sprintf($txt['package_will_fail_' . $action['error_msg']], $action['error_var']); |
|
349 | - elseif (isset($action['error_msg'])) |
|
350 | - $context['failure_details'] = isset($txt['package_will_fail_' . $action['error_msg']]) ? $txt['package_will_fail_' . $action['error_msg']] : $action['error_msg']; |
|
351 | - } |
|
352 | - elseif ($action['type'] == 'modification') |
|
360 | + if (isset($action['error_msg']) && isset($action['error_var'])) { |
|
361 | + $context['failure_details'] = sprintf($txt['package_will_fail_' . $action['error_msg']], $action['error_var']); |
|
362 | + } elseif (isset($action['error_msg'])) { |
|
363 | + $context['failure_details'] = isset($txt['package_will_fail_' . $action['error_msg']]) ? $txt['package_will_fail_' . $action['error_msg']] : $action['error_msg']; |
|
364 | + } |
|
365 | + } elseif ($action['type'] == 'modification') |
|
353 | 366 | { |
354 | 367 | if (!file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) |
355 | 368 | { |
@@ -361,52 +374,54 @@ discard block |
||
361 | 374 | 'description' => $txt['package_action_missing'], |
362 | 375 | 'failed' => true, |
363 | 376 | ); |
364 | - } |
|
365 | - else |
|
377 | + } else |
|
366 | 378 | { |
367 | 379 | |
368 | - if ($action['boardmod']) |
|
369 | - $mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths); |
|
370 | - else |
|
371 | - $mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths); |
|
380 | + if ($action['boardmod']) { |
|
381 | + $mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths); |
|
382 | + } else { |
|
383 | + $mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths); |
|
384 | + } |
|
372 | 385 | |
373 | - if (count($mod_actions) == 1 && isset($mod_actions[0]) && $mod_actions[0]['type'] == 'error' && $mod_actions[0]['filename'] == '-') |
|
374 | - $mod_actions[0]['filename'] = $action['filename']; |
|
386 | + if (count($mod_actions) == 1 && isset($mod_actions[0]) && $mod_actions[0]['type'] == 'error' && $mod_actions[0]['filename'] == '-') { |
|
387 | + $mod_actions[0]['filename'] = $action['filename']; |
|
388 | + } |
|
375 | 389 | |
376 | 390 | foreach ($mod_actions as $key => $mod_action) |
377 | 391 | { |
378 | 392 | // Lets get the last section of the file name. |
379 | - if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php') |
|
380 | - $actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']); |
|
381 | - elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches)) |
|
382 | - $actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']); |
|
383 | - else |
|
384 | - $actual_filename = $key; |
|
385 | - |
|
386 | - if ($mod_action['type'] == 'opened') |
|
387 | - $failed = false; |
|
388 | - elseif ($mod_action['type'] == 'failure') |
|
393 | + if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php') { |
|
394 | + $actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']); |
|
395 | + } elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches)) { |
|
396 | + $actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']); |
|
397 | + } else { |
|
398 | + $actual_filename = $key; |
|
399 | + } |
|
400 | + |
|
401 | + if ($mod_action['type'] == 'opened') { |
|
402 | + $failed = false; |
|
403 | + } elseif ($mod_action['type'] == 'failure') |
|
389 | 404 | { |
390 | - if (empty($mod_action['is_custom'])) |
|
391 | - $context['has_failure'] = true; |
|
405 | + if (empty($mod_action['is_custom'])) { |
|
406 | + $context['has_failure'] = true; |
|
407 | + } |
|
392 | 408 | $failed = true; |
393 | - } |
|
394 | - elseif ($mod_action['type'] == 'chmod') |
|
409 | + } elseif ($mod_action['type'] == 'chmod') |
|
395 | 410 | { |
396 | 411 | $chmod_files[] = $mod_action['filename']; |
397 | - } |
|
398 | - elseif ($mod_action['type'] == 'saved') |
|
412 | + } elseif ($mod_action['type'] == 'saved') |
|
399 | 413 | { |
400 | 414 | if (!empty($mod_action['is_custom'])) |
401 | 415 | { |
402 | - if (!isset($context['theme_actions'][$mod_action['is_custom']])) |
|
403 | - $context['theme_actions'][$mod_action['is_custom']] = array( |
|
416 | + if (!isset($context['theme_actions'][$mod_action['is_custom']])) { |
|
417 | + $context['theme_actions'][$mod_action['is_custom']] = array( |
|
404 | 418 | 'name' => $theme_paths[$mod_action['is_custom']]['name'], |
405 | 419 | 'actions' => array(), |
406 | 420 | 'has_failure' => $failed, |
407 | 421 | ); |
408 | - else |
|
409 | - $context['theme_actions'][$mod_action['is_custom']]['has_failure'] |= $failed; |
|
422 | + } else { |
|
423 | + $context['theme_actions'][$mod_action['is_custom']]['has_failure'] |= $failed; |
|
424 | + } |
|
410 | 425 | |
411 | 426 | $context['theme_actions'][$mod_action['is_custom']]['actions'][$actual_filename] = array( |
412 | 427 | 'type' => $txt['execute_modification'], |
@@ -414,8 +429,7 @@ discard block |
||
414 | 429 | 'description' => $failed ? $txt['package_action_failure'] : $txt['package_action_success'], |
415 | 430 | 'failed' => $failed, |
416 | 431 | ); |
417 | - } |
|
418 | - elseif (!isset($context['actions'][$actual_filename])) |
|
432 | + } elseif (!isset($context['actions'][$actual_filename])) |
|
419 | 433 | { |
420 | 434 | $context['actions'][$actual_filename] = array( |
421 | 435 | 'type' => $txt['execute_modification'], |
@@ -423,22 +437,19 @@ discard block |
||
423 | 437 | 'description' => $failed ? $txt['package_action_failure'] : $txt['package_action_success'], |
424 | 438 | 'failed' => $failed, |
425 | 439 | ); |
426 | - } |
|
427 | - else |
|
440 | + } else |
|
428 | 441 | { |
429 | 442 | $context['actions'][$actual_filename]['failed'] |= $failed; |
430 | 443 | $context['actions'][$actual_filename]['description'] = $context['actions'][$actual_filename]['failed'] ? $txt['package_action_failure'] : $txt['package_action_success']; |
431 | 444 | } |
432 | - } |
|
433 | - elseif ($mod_action['type'] == 'skipping') |
|
445 | + } elseif ($mod_action['type'] == 'skipping') |
|
434 | 446 | { |
435 | 447 | $context['actions'][$actual_filename] = array( |
436 | 448 | 'type' => $txt['execute_modification'], |
437 | 449 | 'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))), |
438 | 450 | 'description' => $txt['package_action_skipping'] |
439 | 451 | ); |
440 | - } |
|
441 | - elseif ($mod_action['type'] == 'missing' && empty($mod_action['is_custom'])) |
|
452 | + } elseif ($mod_action['type'] == 'missing' && empty($mod_action['is_custom'])) |
|
442 | 453 | { |
443 | 454 | $context['has_failure'] = true; |
444 | 455 | $context['actions'][$actual_filename] = array( |
@@ -447,32 +458,33 @@ discard block |
||
447 | 458 | 'description' => $txt['package_action_missing'], |
448 | 459 | 'failed' => true, |
449 | 460 | ); |
450 | - } |
|
451 | - elseif ($mod_action['type'] == 'error') |
|
452 | - $context['actions'][$actual_filename] = array( |
|
461 | + } elseif ($mod_action['type'] == 'error') { |
|
462 | + $context['actions'][$actual_filename] = array( |
|
453 | 463 | 'type' => $txt['execute_modification'], |
454 | 464 | 'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))), |
455 | 465 | 'description' => $txt['package_action_error'], |
456 | 466 | 'failed' => true, |
457 | 467 | ); |
468 | + } |
|
458 | 469 | } |
459 | 470 | |
460 | 471 | // We need to loop again just to get the operations down correctly. |
461 | 472 | foreach ($mod_actions as $operation_key => $mod_action) |
462 | 473 | { |
463 | 474 | // Lets get the last section of the file name. |
464 | - if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php') |
|
465 | - $actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']); |
|
466 | - elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches)) |
|
467 | - $actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']); |
|
468 | - else |
|
469 | - $actual_filename = $key; |
|
475 | + if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php') { |
|
476 | + $actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']); |
|
477 | + } elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches)) { |
|
478 | + $actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']); |
|
479 | + } else { |
|
480 | + $actual_filename = $key; |
|
481 | + } |
|
470 | 482 | |
471 | 483 | // We just need it for actual parse changes. |
472 | 484 | if (!in_array($mod_action['type'], array('error', 'result', 'opened', 'saved', 'end', 'missing', 'skipping', 'chmod'))) |
473 | 485 | { |
474 | - if (empty($mod_action['is_custom'])) |
|
475 | - $context['actions'][$actual_filename]['operations'][] = array( |
|
486 | + if (empty($mod_action['is_custom'])) { |
|
487 | + $context['actions'][$actual_filename]['operations'][] = array( |
|
476 | 488 | 'type' => $txt['execute_modification'], |
477 | 489 | 'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))), |
478 | 490 | 'description' => $mod_action['failed'] ? $txt['package_action_failure'] : $txt['package_action_success'], |
@@ -483,10 +495,11 @@ discard block |
||
483 | 495 | 'failed' => $mod_action['failed'], |
484 | 496 | 'ignore_failure' => !empty($mod_action['ignore_failure']), |
485 | 497 | ); |
498 | + } |
|
486 | 499 | |
487 | 500 | // Themes are under the saved type. |
488 | - if (isset($mod_action['is_custom']) && isset($context['theme_actions'][$mod_action['is_custom']])) |
|
489 | - $context['theme_actions'][$mod_action['is_custom']]['actions'][$actual_filename]['operations'][] = array( |
|
501 | + if (isset($mod_action['is_custom']) && isset($context['theme_actions'][$mod_action['is_custom']])) { |
|
502 | + $context['theme_actions'][$mod_action['is_custom']]['actions'][$actual_filename]['operations'][] = array( |
|
490 | 503 | 'type' => $txt['execute_modification'], |
491 | 504 | 'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))), |
492 | 505 | 'description' => $mod_action['failed'] ? $txt['package_action_failure'] : $txt['package_action_success'], |
@@ -497,59 +510,55 @@ discard block |
||
497 | 510 | 'failed' => $mod_action['failed'], |
498 | 511 | 'ignore_failure' => !empty($mod_action['ignore_failure']), |
499 | 512 | ); |
513 | + } |
|
500 | 514 | } |
501 | 515 | } |
502 | 516 | } |
503 | - } |
|
504 | - elseif ($action['type'] == 'code') |
|
517 | + } elseif ($action['type'] == 'code') |
|
505 | 518 | { |
506 | 519 | $thisAction = array( |
507 | 520 | 'type' => $txt['execute_code'], |
508 | 521 | 'action' => $smcFunc['htmlspecialchars']($action['filename']), |
509 | 522 | ); |
510 | - } |
|
511 | - elseif ($action['type'] == 'database') |
|
523 | + } elseif ($action['type'] == 'database') |
|
512 | 524 | { |
513 | 525 | $thisAction = array( |
514 | 526 | 'type' => $txt['execute_database_changes'], |
515 | 527 | 'action' => $smcFunc['htmlspecialchars']($action['filename']), |
516 | 528 | ); |
517 | - } |
|
518 | - elseif (in_array($action['type'], array('create-dir', 'create-file'))) |
|
529 | + } elseif (in_array($action['type'], array('create-dir', 'create-file'))) |
|
519 | 530 | { |
520 | 531 | $thisAction = array( |
521 | 532 | 'type' => $txt['package_create'] . ' ' . ($action['type'] == 'create-dir' ? $txt['package_tree'] : $txt['package_file']), |
522 | 533 | 'action' => $smcFunc['htmlspecialchars'](strtr($action['destination'], array($boarddir => '.'))) |
523 | 534 | ); |
524 | - } |
|
525 | - elseif ($action['type'] == 'hook') |
|
535 | + } elseif ($action['type'] == 'hook') |
|
526 | 536 | { |
527 | 537 | $action['description'] = !isset($action['hook'], $action['function']) ? $txt['package_action_failure'] : $txt['package_action_success']; |
528 | 538 | |
529 | - if (!isset($action['hook'], $action['function'])) |
|
530 | - $context['has_failure'] = true; |
|
539 | + if (!isset($action['hook'], $action['function'])) { |
|
540 | + $context['has_failure'] = true; |
|
541 | + } |
|
531 | 542 | |
532 | 543 | $thisAction = array( |
533 | 544 | 'type' => $action['reverse'] ? $txt['execute_hook_remove'] : $txt['execute_hook_add'], |
534 | 545 | 'action' => sprintf($txt['execute_hook_action' . ($action['reverse'] ? '_inverse' : '')], $smcFunc['htmlspecialchars']($action['hook'])), |
535 | 546 | ); |
536 | - } |
|
537 | - elseif ($action['type'] == 'credits') |
|
547 | + } elseif ($action['type'] == 'credits') |
|
538 | 548 | { |
539 | 549 | $thisAction = array( |
540 | 550 | 'type' => $txt['execute_credits_add'], |
541 | 551 | 'action' => sprintf($txt['execute_credits_action'], $smcFunc['htmlspecialchars']($action['title'])), |
542 | 552 | ); |
543 | - } |
|
544 | - elseif ($action['type'] == 'requires') |
|
553 | + } elseif ($action['type'] == 'requires') |
|
545 | 554 | { |
546 | 555 | $installed = false; |
547 | 556 | $version = true; |
548 | 557 | |
549 | 558 | // package missing required values? |
550 | - if (!isset($action['id'])) |
|
551 | - $context['has_failure'] = true; |
|
552 | - else |
|
559 | + if (!isset($action['id'])) { |
|
560 | + $context['has_failure'] = true; |
|
561 | + } else |
|
553 | 562 | { |
554 | 563 | // See if this dependancy is installed |
555 | 564 | $request = $smcFunc['db_query']('', ' |
@@ -565,8 +574,9 @@ discard block |
||
565 | 574 | ) |
566 | 575 | ); |
567 | 576 | $installed = ($smcFunc['db_num_rows']($request) !== 0); |
568 | - if ($installed) |
|
569 | - list ($version) = $smcFunc['db_fetch_row']($request); |
|
577 | + if ($installed) { |
|
578 | + list ($version) = $smcFunc['db_fetch_row']($request); |
|
579 | + } |
|
570 | 580 | $smcFunc['db_free_result']($request); |
571 | 581 | |
572 | 582 | // do a version level check (if requested) in the most basic way |
@@ -581,8 +591,7 @@ discard block |
||
581 | 591 | 'type' => $txt['package_requires'], |
582 | 592 | 'action' => $txt['package_check_for'] . ' ' . $action['id'] . (isset($action['version']) ? (' / ' . ($version ? $action['version'] : '<span class="error">' . $action['version'] . '</span>')) : ''), |
583 | 593 | ); |
584 | - } |
|
585 | - elseif (in_array($action['type'], array('require-dir', 'require-file'))) |
|
594 | + } elseif (in_array($action['type'], array('require-dir', 'require-file'))) |
|
586 | 595 | { |
587 | 596 | // Do this one... |
588 | 597 | $thisAction = array( |
@@ -596,26 +605,29 @@ discard block |
||
596 | 605 | // Is the action already stated? |
597 | 606 | $theme_action = !empty($action['theme_action']) && in_array($action['theme_action'], array('no', 'yes', 'auto')) ? $action['theme_action'] : 'auto'; |
598 | 607 | // If it's not auto do we think we have something we can act upon? |
599 | - if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir'))) |
|
600 | - $theme_action = ''; |
|
608 | + if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir'))) { |
|
609 | + $theme_action = ''; |
|
610 | + } |
|
601 | 611 | // ... or if it's auto do we even want to do anything? |
602 | - elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir') |
|
603 | - $theme_action = ''; |
|
612 | + elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir') { |
|
613 | + $theme_action = ''; |
|
614 | + } |
|
604 | 615 | |
605 | 616 | // So, we still want to do something? |
606 | - if ($theme_action != '') |
|
607 | - $themeFinds['candidates'][] = $action; |
|
617 | + if ($theme_action != '') { |
|
618 | + $themeFinds['candidates'][] = $action; |
|
619 | + } |
|
608 | 620 | // Otherwise is this is going into another theme record it. |
609 | - elseif ($matches[1] == 'themes_dir') |
|
610 | - $themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_destination']), array('\\' => '/')) . '/' . basename($action['filename'])); |
|
621 | + elseif ($matches[1] == 'themes_dir') { |
|
622 | + $themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_destination']), array('\\' => '/')) . '/' . basename($action['filename'])); |
|
623 | + } |
|
611 | 624 | } |
612 | - } |
|
613 | - elseif (in_array($action['type'], array('move-dir', 'move-file'))) |
|
614 | - $thisAction = array( |
|
625 | + } elseif (in_array($action['type'], array('move-dir', 'move-file'))) { |
|
626 | + $thisAction = array( |
|
615 | 627 | 'type' => $txt['package_move'] . ' ' . ($action['type'] == 'move-dir' ? $txt['package_tree'] : $txt['package_file']), |
616 | 628 | 'action' => $smcFunc['htmlspecialchars'](strtr($action['source'], array($boarddir => '.'))) . ' => ' . $smcFunc['htmlspecialchars'](strtr($action['destination'], array($boarddir => '.'))) |
617 | 629 | ); |
618 | - elseif (in_array($action['type'], array('remove-dir', 'remove-file'))) |
|
630 | + } elseif (in_array($action['type'], array('remove-dir', 'remove-file'))) |
|
619 | 631 | { |
620 | 632 | $thisAction = array( |
621 | 633 | 'type' => $txt['package_delete'] . ' ' . ($action['type'] == 'remove-dir' ? $txt['package_tree'] : $txt['package_file']), |
@@ -631,30 +643,36 @@ discard block |
||
631 | 643 | $action['unparsed_destination'] = $action['unparsed_filename']; |
632 | 644 | |
633 | 645 | // If it's not auto do we think we have something we can act upon? |
634 | - if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir'))) |
|
635 | - $theme_action = ''; |
|
646 | + if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir'))) { |
|
647 | + $theme_action = ''; |
|
648 | + } |
|
636 | 649 | // ... or if it's auto do we even want to do anything? |
637 | - elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir') |
|
638 | - $theme_action = ''; |
|
650 | + elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir') { |
|
651 | + $theme_action = ''; |
|
652 | + } |
|
639 | 653 | |
640 | 654 | // So, we still want to do something? |
641 | - if ($theme_action != '') |
|
642 | - $themeFinds['candidates'][] = $action; |
|
655 | + if ($theme_action != '') { |
|
656 | + $themeFinds['candidates'][] = $action; |
|
657 | + } |
|
643 | 658 | // Otherwise is this is going into another theme record it. |
644 | - elseif ($matches[1] == 'themes_dir') |
|
645 | - $themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_filename']), array('\\' => '/')) . '/' . basename($action['filename'])); |
|
659 | + elseif ($matches[1] == 'themes_dir') { |
|
660 | + $themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_filename']), array('\\' => '/')) . '/' . basename($action['filename'])); |
|
661 | + } |
|
646 | 662 | } |
647 | 663 | } |
648 | 664 | |
649 | - if (empty($thisAction)) |
|
650 | - continue; |
|
665 | + if (empty($thisAction)) { |
|
666 | + continue; |
|
667 | + } |
|
651 | 668 | |
652 | 669 | if (!in_array($action['type'], array('hook', 'credits'))) |
653 | 670 | { |
654 | - if ($context['uninstalling']) |
|
655 | - $file = in_array($action['type'], array('remove-dir', 'remove-file')) ? $action['filename'] : $packagesdir . '/temp/' . $context['base_path'] . $action['filename']; |
|
656 | - else |
|
657 | - $file = $packagesdir . '/temp/' . $context['base_path'] . $action['filename']; |
|
671 | + if ($context['uninstalling']) { |
|
672 | + $file = in_array($action['type'], array('remove-dir', 'remove-file')) ? $action['filename'] : $packagesdir . '/temp/' . $context['base_path'] . $action['filename']; |
|
673 | + } else { |
|
674 | + $file = $packagesdir . '/temp/' . $context['base_path'] . $action['filename']; |
|
675 | + } |
|
658 | 676 | } |
659 | 677 | |
660 | 678 | // Don't fail if a file/directory we're trying to create doesn't exist... |
@@ -669,8 +687,9 @@ discard block |
||
669 | 687 | } |
670 | 688 | |
671 | 689 | // @todo None given? |
672 | - if (empty($thisAction['description'])) |
|
673 | - $thisAction['description'] = isset($action['description']) ? $action['description'] : ''; |
|
690 | + if (empty($thisAction['description'])) { |
|
691 | + $thisAction['description'] = isset($action['description']) ? $action['description'] : ''; |
|
692 | + } |
|
674 | 693 | |
675 | 694 | $context['actions'][] = $thisAction; |
676 | 695 | } |
@@ -683,18 +702,21 @@ discard block |
||
683 | 702 | // Get the part of the file we'll be dealing with. |
684 | 703 | preg_match('~^\$(languagedir|languages_dir|imagesdir|themedir)(\\|/)*(.+)*~i', $action_data['unparsed_destination'], $matches); |
685 | 704 | |
686 | - if ($matches[1] == 'imagesdir') |
|
687 | - $path = '/' . basename($settings['default_images_url']); |
|
688 | - elseif ($matches[1] == 'languagedir' || $matches[1] == 'languages_dir') |
|
689 | - $path = '/languages'; |
|
690 | - else |
|
691 | - $path = ''; |
|
705 | + if ($matches[1] == 'imagesdir') { |
|
706 | + $path = '/' . basename($settings['default_images_url']); |
|
707 | + } elseif ($matches[1] == 'languagedir' || $matches[1] == 'languages_dir') { |
|
708 | + $path = '/languages'; |
|
709 | + } else { |
|
710 | + $path = ''; |
|
711 | + } |
|
692 | 712 | |
693 | - if (!empty($matches[3])) |
|
694 | - $path .= $matches[3]; |
|
713 | + if (!empty($matches[3])) { |
|
714 | + $path .= $matches[3]; |
|
715 | + } |
|
695 | 716 | |
696 | - if (!$context['uninstalling']) |
|
697 | - $path .= '/' . basename($action_data['filename']); |
|
717 | + if (!$context['uninstalling']) { |
|
718 | + $path .= '/' . basename($action_data['filename']); |
|
719 | + } |
|
698 | 720 | |
699 | 721 | // Loop through each custom theme to note it's candidacy! |
700 | 722 | foreach ($theme_paths as $id => $theme_data) |
@@ -710,36 +732,40 @@ discard block |
||
710 | 732 | if (!mktree(dirname($real_path), false)) |
711 | 733 | { |
712 | 734 | $temp = dirname($real_path); |
713 | - while (!file_exists($temp) && strlen($temp) > 1) |
|
714 | - $temp = dirname($temp); |
|
735 | + while (!file_exists($temp) && strlen($temp) > 1) { |
|
736 | + $temp = dirname($temp); |
|
737 | + } |
|
715 | 738 | $chmod_files[] = $temp; |
716 | 739 | } |
717 | 740 | |
718 | - if ($action_data['type'] == 'require-dir' && !is_writable($real_path) && (file_exists($real_path) || !is_writable(dirname($real_path)))) |
|
719 | - $chmod_files[] = $real_path; |
|
741 | + if ($action_data['type'] == 'require-dir' && !is_writable($real_path) && (file_exists($real_path) || !is_writable(dirname($real_path)))) { |
|
742 | + $chmod_files[] = $real_path; |
|
743 | + } |
|
720 | 744 | |
721 | - if (!isset($context['theme_actions'][$id])) |
|
722 | - $context['theme_actions'][$id] = array( |
|
745 | + if (!isset($context['theme_actions'][$id])) { |
|
746 | + $context['theme_actions'][$id] = array( |
|
723 | 747 | 'name' => $theme_data['name'], |
724 | 748 | 'actions' => array(), |
725 | 749 | ); |
750 | + } |
|
726 | 751 | |
727 | - if ($context['uninstalling']) |
|
728 | - $context['theme_actions'][$id]['actions'][] = array( |
|
752 | + if ($context['uninstalling']) { |
|
753 | + $context['theme_actions'][$id]['actions'][] = array( |
|
729 | 754 | 'type' => $txt['package_delete'] . ' ' . ($action_data['type'] == 'require-dir' ? $txt['package_tree'] : $txt['package_file']), |
730 | 755 | 'action' => strtr($real_path, array('\\' => '/', $boarddir => '.')), |
731 | 756 | 'description' => '', |
732 | 757 | 'value' => base64_encode($smcFunc['json_encode'](array('type' => $action_data['type'], 'orig' => $action_data['filename'], 'future' => $real_path, 'id' => $id))), |
733 | 758 | 'not_mod' => true, |
734 | 759 | ); |
735 | - else |
|
736 | - $context['theme_actions'][$id]['actions'][] = array( |
|
760 | + } else { |
|
761 | + $context['theme_actions'][$id]['actions'][] = array( |
|
737 | 762 | 'type' => $txt['package_extract'] . ' ' . ($action_data['type'] == 'require-dir' ? $txt['package_tree'] : $txt['package_file']), |
738 | 763 | 'action' => strtr($real_path, array('\\' => '/', $boarddir => '.')), |
739 | 764 | 'description' => '', |
740 | 765 | 'value' => base64_encode($smcFunc['json_encode'](array('type' => $action_data['type'], 'orig' => $action_data['destination'], 'future' => $real_path, 'id' => $id))), |
741 | 766 | 'not_mod' => true, |
742 | 767 | ); |
768 | + } |
|
743 | 769 | } |
744 | 770 | } |
745 | 771 | } |
@@ -749,8 +775,9 @@ discard block |
||
749 | 775 | // Trash the cache... which will also check permissions for us! |
750 | 776 | package_flush_cache(true); |
751 | 777 | |
752 | - if (file_exists($packagesdir . '/temp')) |
|
753 | - deltree($packagesdir . '/temp'); |
|
778 | + if (file_exists($packagesdir . '/temp')) { |
|
779 | + deltree($packagesdir . '/temp'); |
|
780 | + } |
|
754 | 781 | |
755 | 782 | if (!empty($chmod_files)) |
756 | 783 | { |
@@ -775,8 +802,9 @@ discard block |
||
775 | 802 | checkSession(); |
776 | 803 | |
777 | 804 | // If there's no file, what are we installing? |
778 | - if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') |
|
779 | - redirectexit('action=admin;area=packages'); |
|
805 | + if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') { |
|
806 | + redirectexit('action=admin;area=packages'); |
|
807 | + } |
|
780 | 808 | $context['filename'] = $_REQUEST['package']; |
781 | 809 | |
782 | 810 | // If this is an uninstall, we'll have an id. |
@@ -797,51 +825,55 @@ discard block |
||
797 | 825 | |
798 | 826 | $context['sub_template'] = 'extract_package'; |
799 | 827 | |
800 | - if (!file_exists($packagesdir . '/' . $context['filename'])) |
|
801 | - fatal_lang_error('package_no_file', false); |
|
828 | + if (!file_exists($packagesdir . '/' . $context['filename'])) { |
|
829 | + fatal_lang_error('package_no_file', false); |
|
830 | + } |
|
802 | 831 | |
803 | 832 | // Load up the package FTP information? |
804 | 833 | create_chmod_control(array(), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=' . $_REQUEST['sa'] . ';package=' . $_REQUEST['package'])); |
805 | 834 | |
806 | 835 | // Make sure temp directory exists and is empty! |
807 | - if (file_exists($packagesdir . '/temp')) |
|
808 | - deltree($packagesdir . '/temp', false); |
|
809 | - else |
|
810 | - mktree($packagesdir . '/temp', 0777); |
|
836 | + if (file_exists($packagesdir . '/temp')) { |
|
837 | + deltree($packagesdir . '/temp', false); |
|
838 | + } else { |
|
839 | + mktree($packagesdir . '/temp', 0777); |
|
840 | + } |
|
811 | 841 | |
812 | 842 | // Let the unpacker do the work. |
813 | 843 | if (is_file($packagesdir . '/' . $context['filename'])) |
814 | 844 | { |
815 | 845 | $context['extracted_files'] = read_tgz_file($packagesdir . '/' . $context['filename'], $packagesdir . '/temp'); |
816 | 846 | |
817 | - if (!file_exists($packagesdir . '/temp/package-info.xml')) |
|
818 | - foreach ($context['extracted_files'] as $file) |
|
847 | + if (!file_exists($packagesdir . '/temp/package-info.xml')) { |
|
848 | + foreach ($context['extracted_files'] as $file) |
|
819 | 849 | if (basename($file['filename']) == 'package-info.xml') |
820 | 850 | { |
821 | 851 | $context['base_path'] = dirname($file['filename']) . '/'; |
852 | + } |
|
822 | 853 | break; |
823 | 854 | } |
824 | 855 | |
825 | - if (!isset($context['base_path'])) |
|
826 | - $context['base_path'] = ''; |
|
827 | - } |
|
828 | - elseif (is_dir($packagesdir . '/' . $context['filename'])) |
|
856 | + if (!isset($context['base_path'])) { |
|
857 | + $context['base_path'] = ''; |
|
858 | + } |
|
859 | + } elseif (is_dir($packagesdir . '/' . $context['filename'])) |
|
829 | 860 | { |
830 | 861 | copytree($packagesdir . '/' . $context['filename'], $packagesdir . '/temp'); |
831 | 862 | $context['extracted_files'] = listtree($packagesdir . '/temp'); |
832 | 863 | $context['base_path'] = ''; |
864 | + } else { |
|
865 | + fatal_lang_error('no_access', false); |
|
833 | 866 | } |
834 | - else |
|
835 | - fatal_lang_error('no_access', false); |
|
836 | 867 | |
837 | 868 | // Are we installing this into any custom themes? |
838 | 869 | $custom_themes = array(1); |
839 | 870 | $known_themes = explode(',', $modSettings['knownThemes']); |
840 | 871 | if (!empty($_POST['custom_theme'])) |
841 | 872 | { |
842 | - foreach ($_POST['custom_theme'] as $tid) |
|
843 | - if (in_array($tid, $known_themes)) |
|
873 | + foreach ($_POST['custom_theme'] as $tid) { |
|
874 | + if (in_array($tid, $known_themes)) |
|
844 | 875 | $custom_themes[] = (int) $tid; |
876 | + } |
|
845 | 877 | } |
846 | 878 | |
847 | 879 | // Now load up the paths of the themes that we need to know about. |
@@ -858,8 +890,9 @@ discard block |
||
858 | 890 | ); |
859 | 891 | $theme_paths = array(); |
860 | 892 | $themes_installed = array(1); |
861 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
862 | - $theme_paths[$row['id_theme']][$row['variable']] = $row['value']; |
|
893 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
894 | + $theme_paths[$row['id_theme']][$row['variable']] = $row['value']; |
|
895 | + } |
|
863 | 896 | $smcFunc['db_free_result']($request); |
864 | 897 | |
865 | 898 | // Are there any theme copying that we want to take place? |
@@ -871,11 +904,13 @@ discard block |
||
871 | 904 | { |
872 | 905 | foreach ($_POST['theme_changes'] as $change) |
873 | 906 | { |
874 | - if (empty($change)) |
|
875 | - continue; |
|
907 | + if (empty($change)) { |
|
908 | + continue; |
|
909 | + } |
|
876 | 910 | $theme_data = $smcFunc['json_decode'](base64_decode($change), true); |
877 | - if (empty($theme_data['type'])) |
|
878 | - continue; |
|
911 | + if (empty($theme_data['type'])) { |
|
912 | + continue; |
|
913 | + } |
|
879 | 914 | |
880 | 915 | $themes_installed[] = $theme_data['id']; |
881 | 916 | $context['theme_copies'][$theme_data['type']][$theme_data['orig']][] = $theme_data['future']; |
@@ -884,8 +919,9 @@ discard block |
||
884 | 919 | |
885 | 920 | // Get the package info... |
886 | 921 | $packageInfo = getPackageInfo($context['filename']); |
887 | - if (!is_array($packageInfo)) |
|
888 | - fatal_lang_error($packageInfo); |
|
922 | + if (!is_array($packageInfo)) { |
|
923 | + fatal_lang_error($packageInfo); |
|
924 | + } |
|
889 | 925 | |
890 | 926 | $packageInfo['filename'] = $context['filename']; |
891 | 927 | |
@@ -897,8 +933,9 @@ discard block |
||
897 | 933 | { |
898 | 934 | $_SESSION['last_backup_for'] = $context['filename'] . ($context['uninstalling'] ? '$$' : '$'); |
899 | 935 | $result = package_create_backup(($context['uninstalling'] ? 'backup_' : 'before_') . strtok($context['filename'], '.')); |
900 | - if (!$result) |
|
901 | - fatal_lang_error('could_not_package_backup', false); |
|
936 | + if (!$result) { |
|
937 | + fatal_lang_error('could_not_package_backup', false); |
|
938 | + } |
|
902 | 939 | } |
903 | 940 | |
904 | 941 | // The mod isn't installed.... unless proven otherwise. |
@@ -938,35 +975,38 @@ discard block |
||
938 | 975 | $install_log = parsePackageInfo($packageInfo['xml'], false, 'uninstall'); |
939 | 976 | |
940 | 977 | // Gadzooks! There's no uninstaller at all!? |
941 | - if (empty($install_log)) |
|
942 | - fatal_lang_error('package_uninstall_cannot', false); |
|
978 | + if (empty($install_log)) { |
|
979 | + fatal_lang_error('package_uninstall_cannot', false); |
|
980 | + } |
|
943 | 981 | |
944 | 982 | // They can only uninstall from what it was originally installed into. |
945 | - foreach ($theme_paths as $id => $data) |
|
946 | - if ($id != 1 && !in_array($id, $old_themes)) |
|
983 | + foreach ($theme_paths as $id => $data) { |
|
984 | + if ($id != 1 && !in_array($id, $old_themes)) |
|
947 | 985 | unset($theme_paths[$id]); |
948 | - } |
|
949 | - elseif (isset($old_version) && $old_version != $packageInfo['version']) |
|
986 | + } |
|
987 | + } elseif (isset($old_version) && $old_version != $packageInfo['version']) |
|
950 | 988 | { |
951 | 989 | // Look for an upgrade... |
952 | 990 | $install_log = parsePackageInfo($packageInfo['xml'], false, 'upgrade', $old_version); |
953 | 991 | |
954 | 992 | // There was no upgrade.... |
955 | - if (empty($install_log)) |
|
956 | - $context['is_installed'] = true; |
|
957 | - else |
|
993 | + if (empty($install_log)) { |
|
994 | + $context['is_installed'] = true; |
|
995 | + } else |
|
958 | 996 | { |
959 | 997 | // Upgrade previous themes only! |
960 | - foreach ($theme_paths as $id => $data) |
|
961 | - if ($id != 1 && !in_array($id, $old_themes)) |
|
998 | + foreach ($theme_paths as $id => $data) { |
|
999 | + if ($id != 1 && !in_array($id, $old_themes)) |
|
962 | 1000 | unset($theme_paths[$id]); |
1001 | + } |
|
963 | 1002 | } |
1003 | + } elseif (isset($old_version) && $old_version == $packageInfo['version']) { |
|
1004 | + $context['is_installed'] = true; |
|
964 | 1005 | } |
965 | - elseif (isset($old_version) && $old_version == $packageInfo['version']) |
|
966 | - $context['is_installed'] = true; |
|
967 | 1006 | |
968 | - if (!isset($old_version) || $context['is_installed']) |
|
969 | - $install_log = parsePackageInfo($packageInfo['xml'], false, 'install'); |
|
1007 | + if (!isset($old_version) || $context['is_installed']) { |
|
1008 | + $install_log = parsePackageInfo($packageInfo['xml'], false, 'install'); |
|
1009 | + } |
|
970 | 1010 | |
971 | 1011 | $context['install_finished'] = false; |
972 | 1012 | |
@@ -983,37 +1023,39 @@ discard block |
||
983 | 1023 | |
984 | 1024 | if ($action['type'] == 'modification' && !empty($action['filename'])) |
985 | 1025 | { |
986 | - if ($action['boardmod']) |
|
987 | - $mod_actions = parseBoardMod(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths); |
|
988 | - else |
|
989 | - $mod_actions = parseModification(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths); |
|
1026 | + if ($action['boardmod']) { |
|
1027 | + $mod_actions = parseBoardMod(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths); |
|
1028 | + } else { |
|
1029 | + $mod_actions = parseModification(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths); |
|
1030 | + } |
|
990 | 1031 | |
991 | 1032 | // Any errors worth noting? |
992 | 1033 | foreach ($mod_actions as $key => $modAction) |
993 | 1034 | { |
994 | - if ($modAction['type'] == 'failure') |
|
995 | - $failed_steps[] = array( |
|
1035 | + if ($modAction['type'] == 'failure') { |
|
1036 | + $failed_steps[] = array( |
|
996 | 1037 | 'file' => $modAction['filename'], |
997 | 1038 | 'large_step' => $failed_count, |
998 | 1039 | 'sub_step' => $key, |
999 | 1040 | 'theme' => 1, |
1000 | 1041 | ); |
1042 | + } |
|
1001 | 1043 | |
1002 | 1044 | // Gather the themes we installed into. |
1003 | - if (!empty($modAction['is_custom'])) |
|
1004 | - $themes_installed[] = $modAction['is_custom']; |
|
1045 | + if (!empty($modAction['is_custom'])) { |
|
1046 | + $themes_installed[] = $modAction['is_custom']; |
|
1047 | + } |
|
1005 | 1048 | } |
1006 | - } |
|
1007 | - elseif ($action['type'] == 'code' && !empty($action['filename'])) |
|
1049 | + } elseif ($action['type'] == 'code' && !empty($action['filename'])) |
|
1008 | 1050 | { |
1009 | 1051 | // This is just here as reference for what is available. |
1010 | 1052 | global $txt, $boarddir, $sourcedir, $modSettings, $context, $settings, $forum_version, $smcFunc; |
1011 | 1053 | |
1012 | 1054 | // Now include the file and be done with it ;). |
1013 | - if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) |
|
1014 | - require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']); |
|
1015 | - } |
|
1016 | - elseif ($action['type'] == 'credits') |
|
1055 | + if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) { |
|
1056 | + require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']); |
|
1057 | + } |
|
1058 | + } elseif ($action['type'] == 'credits') |
|
1017 | 1059 | { |
1018 | 1060 | // Time to build the billboard |
1019 | 1061 | $credits_tag = array( |
@@ -1023,13 +1065,13 @@ discard block |
||
1023 | 1065 | 'copyright' => $action['copyright'], |
1024 | 1066 | 'title' => $action['title'], |
1025 | 1067 | ); |
1026 | - } |
|
1027 | - elseif ($action['type'] == 'hook' && isset($action['hook'], $action['function'])) |
|
1068 | + } elseif ($action['type'] == 'hook' && isset($action['hook'], $action['function'])) |
|
1028 | 1069 | { |
1029 | - if ($action['reverse']) |
|
1030 | - remove_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']); |
|
1031 | - else |
|
1032 | - add_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']); |
|
1070 | + if ($action['reverse']) { |
|
1071 | + remove_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']); |
|
1072 | + } else { |
|
1073 | + add_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']); |
|
1074 | + } |
|
1033 | 1075 | } |
1034 | 1076 | // Only do the database changes on uninstall if requested. |
1035 | 1077 | elseif ($action['type'] == 'database' && !empty($action['filename']) && (!$context['uninstalling'] || !empty($_POST['do_db_changes']))) |
@@ -1042,8 +1084,9 @@ discard block |
||
1042 | 1084 | db_extend('packages'); |
1043 | 1085 | |
1044 | 1086 | // Let the file work its magic ;) |
1045 | - if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) |
|
1046 | - require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']); |
|
1087 | + if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) { |
|
1088 | + require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']); |
|
1089 | + } |
|
1047 | 1090 | } |
1048 | 1091 | // Handle a redirect... |
1049 | 1092 | elseif ($action['type'] == 'redirect' && !empty($action['redirect_url'])) |
@@ -1125,8 +1168,9 @@ discard block |
||
1125 | 1168 | reloadSettings(); |
1126 | 1169 | |
1127 | 1170 | // Any db changes from older version? |
1128 | - if (!empty($old_db_changes)) |
|
1129 | - $db_package_log = empty($db_package_log) ? $old_db_changes : array_merge($old_db_changes, $db_package_log); |
|
1171 | + if (!empty($old_db_changes)) { |
|
1172 | + $db_package_log = empty($db_package_log) ? $old_db_changes : array_merge($old_db_changes, $db_package_log); |
|
1173 | + } |
|
1130 | 1174 | |
1131 | 1175 | // If there are some database changes we might want to remove then filter them out. |
1132 | 1176 | if (!empty($db_package_log)) |
@@ -1142,22 +1186,24 @@ discard block |
||
1142 | 1186 | */ |
1143 | 1187 | function sort_table_first($a, $b) |
1144 | 1188 | { |
1145 | - if ($a[0] == $b[0]) |
|
1146 | - return 0; |
|
1189 | + if ($a[0] == $b[0]) { |
|
1190 | + return 0; |
|
1191 | + } |
|
1147 | 1192 | return $a[0] == 'remove_table' ? -1 : 1; |
1148 | 1193 | } |
1149 | 1194 | usort($db_package_log, 'sort_table_first'); |
1150 | 1195 | foreach ($db_package_log as $k => $log) |
1151 | 1196 | { |
1152 | - if ($log[0] == 'remove_table') |
|
1153 | - $tables[] = $log[1]; |
|
1154 | - elseif (in_array($log[1], $tables)) |
|
1155 | - unset($db_package_log[$k]); |
|
1197 | + if ($log[0] == 'remove_table') { |
|
1198 | + $tables[] = $log[1]; |
|
1199 | + } elseif (in_array($log[1], $tables)) { |
|
1200 | + unset($db_package_log[$k]); |
|
1201 | + } |
|
1156 | 1202 | } |
1157 | 1203 | $db_changes = $smcFunc['json_encode']($db_package_log); |
1204 | + } else { |
|
1205 | + $db_changes = ''; |
|
1158 | 1206 | } |
1159 | - else |
|
1160 | - $db_changes = ''; |
|
1161 | 1207 | |
1162 | 1208 | // What themes did we actually install? |
1163 | 1209 | $themes_installed = array_unique($themes_installed); |
@@ -1206,18 +1252,20 @@ discard block |
||
1206 | 1252 | |
1207 | 1253 | foreach ($db_changes as $change) |
1208 | 1254 | { |
1209 | - if ($change[0] == 'remove_table' && isset($change[1])) |
|
1210 | - $smcFunc['db_drop_table']($change[1]); |
|
1211 | - elseif ($change[0] == 'remove_column' && isset($change[2])) |
|
1212 | - $smcFunc['db_remove_column']($change[1], $change[2]); |
|
1213 | - elseif ($change[0] == 'remove_index' && isset($change[2])) |
|
1214 | - $smcFunc['db_remove_index']($change[1], $change[2]); |
|
1255 | + if ($change[0] == 'remove_table' && isset($change[1])) { |
|
1256 | + $smcFunc['db_drop_table']($change[1]); |
|
1257 | + } elseif ($change[0] == 'remove_column' && isset($change[2])) { |
|
1258 | + $smcFunc['db_remove_column']($change[1], $change[2]); |
|
1259 | + } elseif ($change[0] == 'remove_index' && isset($change[2])) { |
|
1260 | + $smcFunc['db_remove_index']($change[1], $change[2]); |
|
1261 | + } |
|
1215 | 1262 | } |
1216 | 1263 | } |
1217 | 1264 | |
1218 | 1265 | // Clean house... get rid of the evidence ;). |
1219 | - if (file_exists($packagesdir . '/temp')) |
|
1220 | - deltree($packagesdir . '/temp'); |
|
1266 | + if (file_exists($packagesdir . '/temp')) { |
|
1267 | + deltree($packagesdir . '/temp'); |
|
1268 | + } |
|
1221 | 1269 | |
1222 | 1270 | // Log what we just did. |
1223 | 1271 | logAction($context['uninstalling'] ? 'uninstall_package' : (!empty($is_upgrade) ? 'upgrade_package' : 'install_package'), array('package' => $smcFunc['htmlspecialchars']($packageInfo['name']), 'version' => $smcFunc['htmlspecialchars']($packageInfo['version'])), 'admin'); |
@@ -1239,8 +1287,9 @@ discard block |
||
1239 | 1287 | require_once($sourcedir . '/Subs-Package.php'); |
1240 | 1288 | |
1241 | 1289 | // No package? Show him or her the door. |
1242 | - if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') |
|
1243 | - redirectexit('action=admin;area=packages'); |
|
1290 | + if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') { |
|
1291 | + redirectexit('action=admin;area=packages'); |
|
1292 | + } |
|
1244 | 1293 | |
1245 | 1294 | $context['linktree'][] = array( |
1246 | 1295 | 'url' => $scripturl . '?action=admin;area=packages;sa=list;package=' . $_REQUEST['package'], |
@@ -1253,11 +1302,12 @@ discard block |
||
1253 | 1302 | $context['filename'] = $_REQUEST['package']; |
1254 | 1303 | |
1255 | 1304 | // Let the unpacker do the work. |
1256 | - if (is_file($packagesdir . '/' . $context['filename'])) |
|
1257 | - $context['files'] = read_tgz_file($packagesdir . '/' . $context['filename'], null); |
|
1258 | - elseif (is_dir($packagesdir . '/' . $context['filename'])) |
|
1259 | - $context['files'] = listtree($packagesdir . '/' . $context['filename']); |
|
1260 | -} |
|
1305 | + if (is_file($packagesdir . '/' . $context['filename'])) { |
|
1306 | + $context['files'] = read_tgz_file($packagesdir . '/' . $context['filename'], null); |
|
1307 | + } elseif (is_dir($packagesdir . '/' . $context['filename'])) { |
|
1308 | + $context['files'] = listtree($packagesdir . '/' . $context['filename']); |
|
1309 | + } |
|
1310 | + } |
|
1261 | 1311 | |
1262 | 1312 | /** |
1263 | 1313 | * Display one of the files in a package. |
@@ -1269,22 +1319,25 @@ discard block |
||
1269 | 1319 | require_once($sourcedir . '/Subs-Package.php'); |
1270 | 1320 | |
1271 | 1321 | // No package? Show him or her the door. |
1272 | - if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') |
|
1273 | - redirectexit('action=admin;area=packages'); |
|
1322 | + if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') { |
|
1323 | + redirectexit('action=admin;area=packages'); |
|
1324 | + } |
|
1274 | 1325 | |
1275 | 1326 | // No file? Show him or her the door. |
1276 | - if (!isset($_REQUEST['file']) || $_REQUEST['file'] == '') |
|
1277 | - redirectexit('action=admin;area=packages'); |
|
1327 | + if (!isset($_REQUEST['file']) || $_REQUEST['file'] == '') { |
|
1328 | + redirectexit('action=admin;area=packages'); |
|
1329 | + } |
|
1278 | 1330 | |
1279 | 1331 | $_REQUEST['package'] = preg_replace('~[\.]+~', '.', strtr($_REQUEST['package'], array('/' => '_', '\\' => '_'))); |
1280 | 1332 | $_REQUEST['file'] = preg_replace('~[\.]+~', '.', $_REQUEST['file']); |
1281 | 1333 | |
1282 | 1334 | if (isset($_REQUEST['raw'])) |
1283 | 1335 | { |
1284 | - if (is_file($packagesdir . '/' . $_REQUEST['package'])) |
|
1285 | - echo read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true); |
|
1286 | - elseif (is_dir($packagesdir . '/' . $_REQUEST['package'])) |
|
1287 | - echo file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file']); |
|
1336 | + if (is_file($packagesdir . '/' . $_REQUEST['package'])) { |
|
1337 | + echo read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true); |
|
1338 | + } elseif (is_dir($packagesdir . '/' . $_REQUEST['package'])) { |
|
1339 | + echo file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file']); |
|
1340 | + } |
|
1288 | 1341 | |
1289 | 1342 | obExit(false); |
1290 | 1343 | } |
@@ -1301,17 +1354,19 @@ discard block |
||
1301 | 1354 | $context['filename'] = $_REQUEST['file']; |
1302 | 1355 | |
1303 | 1356 | // Let the unpacker do the work.... but make sure we handle images properly. |
1304 | - if (in_array(strtolower(strrchr($_REQUEST['file'], '.')), array('.bmp', '.gif', '.jpeg', '.jpg', '.png'))) |
|
1305 | - $context['filedata'] = '<img src="' . $scripturl . '?action=admin;area=packages;sa=examine;package=' . $_REQUEST['package'] . ';file=' . $_REQUEST['file'] . ';raw" alt="' . $_REQUEST['file'] . '">'; |
|
1306 | - else |
|
1357 | + if (in_array(strtolower(strrchr($_REQUEST['file'], '.')), array('.bmp', '.gif', '.jpeg', '.jpg', '.png'))) { |
|
1358 | + $context['filedata'] = '<img src="' . $scripturl . '?action=admin;area=packages;sa=examine;package=' . $_REQUEST['package'] . ';file=' . $_REQUEST['file'] . ';raw" alt="' . $_REQUEST['file'] . '">'; |
|
1359 | + } else |
|
1307 | 1360 | { |
1308 | - if (is_file($packagesdir . '/' . $_REQUEST['package'])) |
|
1309 | - $context['filedata'] = $smcFunc['htmlspecialchars'](read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true)); |
|
1310 | - elseif (is_dir($packagesdir . '/' . $_REQUEST['package'])) |
|
1311 | - $context['filedata'] = $smcFunc['htmlspecialchars'](file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file'])); |
|
1361 | + if (is_file($packagesdir . '/' . $_REQUEST['package'])) { |
|
1362 | + $context['filedata'] = $smcFunc['htmlspecialchars'](read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true)); |
|
1363 | + } elseif (is_dir($packagesdir . '/' . $_REQUEST['package'])) { |
|
1364 | + $context['filedata'] = $smcFunc['htmlspecialchars'](file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file'])); |
|
1365 | + } |
|
1312 | 1366 | |
1313 | - if (strtolower(strrchr($_REQUEST['file'], '.')) == '.php') |
|
1314 | - $context['filedata'] = highlight_php_code($context['filedata']); |
|
1367 | + if (strtolower(strrchr($_REQUEST['file'], '.')) == '.php') { |
|
1368 | + $context['filedata'] = highlight_php_code($context['filedata']); |
|
1369 | + } |
|
1315 | 1370 | } |
1316 | 1371 | } |
1317 | 1372 | |
@@ -1326,8 +1381,9 @@ discard block |
||
1326 | 1381 | checkSession('get'); |
1327 | 1382 | |
1328 | 1383 | // Ack, don't allow deletion of arbitrary files here, could become a security hole somehow! |
1329 | - if (!isset($_GET['package']) || $_GET['package'] == 'index.php' || $_GET['package'] == 'backups') |
|
1330 | - redirectexit('action=admin;area=packages;sa=browse'); |
|
1384 | + if (!isset($_GET['package']) || $_GET['package'] == 'index.php' || $_GET['package'] == 'backups') { |
|
1385 | + redirectexit('action=admin;area=packages;sa=browse'); |
|
1386 | + } |
|
1331 | 1387 | $_GET['package'] = preg_replace('~[\.]+~', '.', strtr($_GET['package'], array('/' => '_', '\\' => '_'))); |
1332 | 1388 | |
1333 | 1389 | // Can't delete what's not there. |
@@ -1335,9 +1391,9 @@ discard block |
||
1335 | 1391 | { |
1336 | 1392 | create_chmod_control(array($packagesdir . '/' . $_GET['package']), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=remove;package=' . $_GET['package'], 'crash_on_error' => true)); |
1337 | 1393 | |
1338 | - if (is_dir($packagesdir . '/' . $_GET['package'])) |
|
1339 | - deltree($packagesdir . '/' . $_GET['package']); |
|
1340 | - else |
|
1394 | + if (is_dir($packagesdir . '/' . $_GET['package'])) { |
|
1395 | + deltree($packagesdir . '/' . $_GET['package']); |
|
1396 | + } else |
|
1341 | 1397 | { |
1342 | 1398 | smf_chmod($packagesdir . '/' . $_GET['package'], 0777); |
1343 | 1399 | unlink($packagesdir . '/' . $_GET['package']); |
@@ -1385,8 +1441,9 @@ discard block |
||
1385 | 1441 | 'data' => array( |
1386 | 1442 | 'function' => function($package_md5) use ($type, &$context) |
1387 | 1443 | { |
1388 | - if (isset($context['available_' . $type . ''][$package_md5])) |
|
1389 | - return $context['available_' . $type . ''][$package_md5]['sort_id']; |
|
1444 | + if (isset($context['available_' . $type . ''][$package_md5])) { |
|
1445 | + return $context['available_' . $type . ''][$package_md5]['sort_id']; |
|
1446 | + } |
|
1390 | 1447 | }, |
1391 | 1448 | ), |
1392 | 1449 | 'sort' => array( |
@@ -1402,8 +1459,9 @@ discard block |
||
1402 | 1459 | 'data' => array( |
1403 | 1460 | 'function' => function($package_md5) use ($type, &$context) |
1404 | 1461 | { |
1405 | - if (isset($context['available_' . $type . ''][$package_md5])) |
|
1406 | - return $context['available_' . $type . ''][$package_md5]['name']; |
|
1462 | + if (isset($context['available_' . $type . ''][$package_md5])) { |
|
1463 | + return $context['available_' . $type . ''][$package_md5]['name']; |
|
1464 | + } |
|
1407 | 1465 | }, |
1408 | 1466 | ), |
1409 | 1467 | 'sort' => array( |
@@ -1418,8 +1476,9 @@ discard block |
||
1418 | 1476 | 'data' => array( |
1419 | 1477 | 'function' => function($package_md5) use ($type, &$context) |
1420 | 1478 | { |
1421 | - if (isset($context['available_' . $type . ''][$package_md5])) |
|
1422 | - return $context['available_' . $type . ''][$package_md5]['version']; |
|
1479 | + if (isset($context['available_' . $type . ''][$package_md5])) { |
|
1480 | + return $context['available_' . $type . ''][$package_md5]['version']; |
|
1481 | + } |
|
1423 | 1482 | }, |
1424 | 1483 | ), |
1425 | 1484 | 'sort' => array( |
@@ -1434,8 +1493,9 @@ discard block |
||
1434 | 1493 | 'data' => array( |
1435 | 1494 | 'function' => function($package_md5) use ($type, $txt, &$context) |
1436 | 1495 | { |
1437 | - if (isset($context['available_' . $type . ''][$package_md5])) |
|
1438 | - return !empty($context['available_' . $type . ''][$package_md5]['time_installed']) ? timeformat($context['available_' . $type . ''][$package_md5]['time_installed']) : $txt['not_applicable']; |
|
1496 | + if (isset($context['available_' . $type . ''][$package_md5])) { |
|
1497 | + return !empty($context['available_' . $type . ''][$package_md5]['time_installed']) ? timeformat($context['available_' . $type . ''][$package_md5]['time_installed']) : $txt['not_applicable']; |
|
1498 | + } |
|
1439 | 1499 | }, |
1440 | 1500 | 'class' => 'smalltext', |
1441 | 1501 | ), |
@@ -1451,28 +1511,30 @@ discard block |
||
1451 | 1511 | 'data' => array( |
1452 | 1512 | 'function' => function($package_md5) use ($type, &$context, $scripturl, $txt) |
1453 | 1513 | { |
1454 | - if (!isset($context['available_' . $type . ''][$package_md5])) |
|
1455 | - return ''; |
|
1514 | + if (!isset($context['available_' . $type . ''][$package_md5])) { |
|
1515 | + return ''; |
|
1516 | + } |
|
1456 | 1517 | |
1457 | 1518 | // Rewrite shortcut |
1458 | 1519 | $package = $context['available_' . $type . ''][$package_md5]; |
1459 | 1520 | $return = ''; |
1460 | 1521 | |
1461 | - if ($package['can_uninstall']) |
|
1462 | - $return = ' |
|
1522 | + if ($package['can_uninstall']) { |
|
1523 | + $return = ' |
|
1463 | 1524 | <a href="' . $scripturl . '?action=admin;area=packages;sa=uninstall;package=' . $package['filename'] . ';pid=' . $package['installed_id'] . '" class="button">' . $txt['uninstall'] . '</a>'; |
1464 | - elseif ($package['can_emulate_uninstall']) |
|
1465 | - $return = ' |
|
1525 | + } elseif ($package['can_emulate_uninstall']) { |
|
1526 | + $return = ' |
|
1466 | 1527 | <a href="' . $scripturl . '?action=admin;area=packages;sa=uninstall;ve=' . $package['can_emulate_uninstall'] . ';package=' . $package['filename'] . ';pid=' . $package['installed_id'] . '" class="button">' . $txt['package_emulate_uninstall'] . ' ' . $package['can_emulate_uninstall'] . '</a>'; |
1467 | - elseif ($package['can_upgrade']) |
|
1468 | - $return = ' |
|
1528 | + } elseif ($package['can_upgrade']) { |
|
1529 | + $return = ' |
|
1469 | 1530 | <a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $package['filename'] . '" class="button">' . $txt['package_upgrade'] . '</a>'; |
1470 | - elseif ($package['can_install']) |
|
1471 | - $return = ' |
|
1531 | + } elseif ($package['can_install']) { |
|
1532 | + $return = ' |
|
1472 | 1533 | <a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $package['filename'] . '" class="button">' . $txt['install_mod'] . '</a>'; |
1473 | - elseif ($package['can_emulate_install']) |
|
1474 | - $return = ' |
|
1534 | + } elseif ($package['can_emulate_install']) { |
|
1535 | + $return = ' |
|
1475 | 1536 | <a href="' . $scripturl . '?action=admin;area=packages;sa=install;ve=' . $package['can_emulate_install'] . ';package=' . $package['filename'] . '" class="button">' . $txt['package_emulate_install'] . ' ' . $package['can_emulate_install'] . '</a>'; |
1537 | + } |
|
1476 | 1538 | |
1477 | 1539 | return $return . ' |
1478 | 1540 | <a href="' . $scripturl . '?action=admin;area=packages;sa=list;package=' . $package['filename'] . '" class="button">' . $txt['list_files'] . '</a> |
@@ -1537,12 +1599,14 @@ discard block |
||
1537 | 1599 | static $packages, $installed_mods; |
1538 | 1600 | |
1539 | 1601 | // Start things up |
1540 | - if (!isset($packages[$params])) |
|
1541 | - $packages[$params] = array(); |
|
1602 | + if (!isset($packages[$params])) { |
|
1603 | + $packages[$params] = array(); |
|
1604 | + } |
|
1542 | 1605 | |
1543 | 1606 | // We need the packages directory to be writable for this. |
1544 | - if (!@is_writable($packagesdir)) |
|
1545 | - create_chmod_control(array($packagesdir), array('destination_url' => $scripturl . '?action=admin;area=packages', 'crash_on_error' => true)); |
|
1607 | + if (!@is_writable($packagesdir)) { |
|
1608 | + create_chmod_control(array($packagesdir), array('destination_url' => $scripturl . '?action=admin;area=packages', 'crash_on_error' => true)); |
|
1609 | + } |
|
1546 | 1610 | |
1547 | 1611 | $the_version = strtr($forum_version, array('SMF ' => '')); |
1548 | 1612 | |
@@ -1550,41 +1614,44 @@ discard block |
||
1550 | 1614 | if (isset($_GET['version_emulate']) && strtr($_GET['version_emulate'], array('SMF ' => '')) == $the_version) |
1551 | 1615 | { |
1552 | 1616 | unset($_SESSION['version_emulate']); |
1553 | - } |
|
1554 | - elseif (isset($_GET['version_emulate'])) |
|
1617 | + } elseif (isset($_GET['version_emulate'])) |
|
1555 | 1618 | { |
1556 | - if (($_GET['version_emulate'] === 0 || $_GET['version_emulate'] === $forum_version) && isset($_SESSION['version_emulate'])) |
|
1557 | - unset($_SESSION['version_emulate']); |
|
1558 | - elseif ($_GET['version_emulate'] !== 0) |
|
1559 | - $_SESSION['version_emulate'] = strtr($_GET['version_emulate'], array('-' => ' ', '+' => ' ', 'SMF ' => '')); |
|
1619 | + if (($_GET['version_emulate'] === 0 || $_GET['version_emulate'] === $forum_version) && isset($_SESSION['version_emulate'])) { |
|
1620 | + unset($_SESSION['version_emulate']); |
|
1621 | + } elseif ($_GET['version_emulate'] !== 0) { |
|
1622 | + $_SESSION['version_emulate'] = strtr($_GET['version_emulate'], array('-' => ' ', '+' => ' ', 'SMF ' => '')); |
|
1623 | + } |
|
1560 | 1624 | } |
1561 | 1625 | if (!empty($_SESSION['version_emulate'])) |
1562 | 1626 | { |
1563 | 1627 | $context['forum_version'] = 'SMF ' . $_SESSION['version_emulate']; |
1564 | 1628 | $the_version = $_SESSION['version_emulate']; |
1565 | 1629 | } |
1566 | - if (isset($_SESSION['single_version_emulate'])) |
|
1567 | - unset($_SESSION['single_version_emulate']); |
|
1630 | + if (isset($_SESSION['single_version_emulate'])) { |
|
1631 | + unset($_SESSION['single_version_emulate']); |
|
1632 | + } |
|
1568 | 1633 | |
1569 | 1634 | if (empty($installed_mods)) |
1570 | 1635 | { |
1571 | 1636 | $instmods = loadInstalledPackages(); |
1572 | 1637 | $installed_mods = array(); |
1573 | 1638 | // Look through the list of installed mods... |
1574 | - foreach ($instmods as $installed_mod) |
|
1575 | - $installed_mods[$installed_mod['package_id']] = array( |
|
1639 | + foreach ($instmods as $installed_mod) { |
|
1640 | + $installed_mods[$installed_mod['package_id']] = array( |
|
1576 | 1641 | 'id' => $installed_mod['id'], |
1577 | 1642 | 'version' => $installed_mod['version'], |
1578 | 1643 | 'time_installed' => $installed_mod['time_installed'], |
1579 | 1644 | ); |
1645 | + } |
|
1580 | 1646 | |
1581 | 1647 | // Get a list of all the ids installed, so the latest packages won't include already installed ones. |
1582 | 1648 | $context['installed_mods'] = array_keys($installed_mods); |
1583 | 1649 | } |
1584 | 1650 | |
1585 | - if (empty($packages)) |
|
1586 | - foreach ($context['modification_types'] as $type) |
|
1651 | + if (empty($packages)) { |
|
1652 | + foreach ($context['modification_types'] as $type) |
|
1587 | 1653 | $packages[$type] = array(); |
1654 | + } |
|
1588 | 1655 | |
1589 | 1656 | if ($dir = @opendir($packagesdir)) |
1590 | 1657 | { |
@@ -1600,50 +1667,56 @@ discard block |
||
1600 | 1667 | |
1601 | 1668 | while ($package = readdir($dir)) |
1602 | 1669 | { |
1603 | - if ($package == '.' || $package == '..' || $package == 'temp' || (!(is_dir($packagesdir . '/' . $package) && file_exists($packagesdir . '/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip')) |
|
1604 | - continue; |
|
1670 | + if ($package == '.' || $package == '..' || $package == 'temp' || (!(is_dir($packagesdir . '/' . $package) && file_exists($packagesdir . '/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip')) { |
|
1671 | + continue; |
|
1672 | + } |
|
1605 | 1673 | |
1606 | 1674 | $skip = false; |
1607 | - foreach ($context['modification_types'] as $type) |
|
1608 | - if (isset($context['available_' . $type][md5($package)])) |
|
1675 | + foreach ($context['modification_types'] as $type) { |
|
1676 | + if (isset($context['available_' . $type][md5($package)])) |
|
1609 | 1677 | $skip = true; |
1678 | + } |
|
1610 | 1679 | |
1611 | - if ($skip) |
|
1612 | - continue; |
|
1680 | + if ($skip) { |
|
1681 | + continue; |
|
1682 | + } |
|
1613 | 1683 | |
1614 | 1684 | // Skip directories or files that are named the same. |
1615 | 1685 | if (is_dir($packagesdir . '/' . $package)) |
1616 | 1686 | { |
1617 | - if (in_array($package, $dirs)) |
|
1618 | - continue; |
|
1687 | + if (in_array($package, $dirs)) { |
|
1688 | + continue; |
|
1689 | + } |
|
1619 | 1690 | $dirs[] = $package; |
1620 | - } |
|
1621 | - elseif (substr(strtolower($package), -7) == '.tar.gz') |
|
1691 | + } elseif (substr(strtolower($package), -7) == '.tar.gz') |
|
1622 | 1692 | { |
1623 | - if (in_array(substr($package, 0, -7), $dirs)) |
|
1624 | - continue; |
|
1693 | + if (in_array(substr($package, 0, -7), $dirs)) { |
|
1694 | + continue; |
|
1695 | + } |
|
1625 | 1696 | $dirs[] = substr($package, 0, -7); |
1626 | - } |
|
1627 | - elseif (substr(strtolower($package), -4) == '.zip' || substr(strtolower($package), -4) == '.tgz') |
|
1697 | + } elseif (substr(strtolower($package), -4) == '.zip' || substr(strtolower($package), -4) == '.tgz') |
|
1628 | 1698 | { |
1629 | - if (in_array(substr($package, 0, -4), $dirs)) |
|
1630 | - continue; |
|
1699 | + if (in_array(substr($package, 0, -4), $dirs)) { |
|
1700 | + continue; |
|
1701 | + } |
|
1631 | 1702 | $dirs[] = substr($package, 0, -4); |
1632 | 1703 | } |
1633 | 1704 | |
1634 | 1705 | $packageInfo = getPackageInfo($package); |
1635 | - if (!is_array($packageInfo)) |
|
1636 | - continue; |
|
1706 | + if (!is_array($packageInfo)) { |
|
1707 | + continue; |
|
1708 | + } |
|
1637 | 1709 | |
1638 | 1710 | if (!empty($packageInfo)) |
1639 | 1711 | { |
1640 | 1712 | $packageInfo['installed_id'] = isset($installed_mods[$packageInfo['id']]) ? $installed_mods[$packageInfo['id']]['id'] : 0; |
1641 | 1713 | $packageInfo['time_installed'] = isset($installed_mods[$packageInfo['id']]) ? $installed_mods[$packageInfo['id']]['time_installed'] : 0; |
1642 | 1714 | |
1643 | - if (!isset($sort_id[$packageInfo['type']])) |
|
1644 | - $packageInfo['sort_id'] = $sort_id['unknown']; |
|
1645 | - else |
|
1646 | - $packageInfo['sort_id'] = $sort_id[$packageInfo['type']]; |
|
1715 | + if (!isset($sort_id[$packageInfo['type']])) { |
|
1716 | + $packageInfo['sort_id'] = $sort_id['unknown']; |
|
1717 | + } else { |
|
1718 | + $packageInfo['sort_id'] = $sort_id[$packageInfo['type']]; |
|
1719 | + } |
|
1647 | 1720 | |
1648 | 1721 | $packageInfo['is_installed'] = isset($installed_mods[$packageInfo['id']]); |
1649 | 1722 | $packageInfo['is_current'] = $packageInfo['is_installed'] && ($installed_mods[$packageInfo['id']]['version'] == $packageInfo['version']); |
@@ -1692,10 +1765,11 @@ discard block |
||
1692 | 1765 | foreach ($upgrades as $upgrade) |
1693 | 1766 | { |
1694 | 1767 | // Even if it is for this SMF, is it for the installed version of the mod? |
1695 | - if (!$upgrade->exists('@for') || matchPackageVersion($the_version, $upgrade->fetch('@for'))) |
|
1696 | - if (!$upgrade->exists('@from') || matchPackageVersion($installed_mods[$packageInfo['id']]['version'], $upgrade->fetch('@from'))) |
|
1768 | + if (!$upgrade->exists('@for') || matchPackageVersion($the_version, $upgrade->fetch('@for'))) { |
|
1769 | + if (!$upgrade->exists('@from') || matchPackageVersion($installed_mods[$packageInfo['id']]['version'], $upgrade->fetch('@from'))) |
|
1697 | 1770 | { |
1698 | 1771 | $packageInfo['can_upgrade'] = true; |
1772 | + } |
|
1699 | 1773 | break; |
1700 | 1774 | } |
1701 | 1775 | } |
@@ -1772,10 +1846,11 @@ discard block |
||
1772 | 1846 | |
1773 | 1847 | if (isset($_GET['type']) && $_GET['type'] == $params) |
1774 | 1848 | { |
1775 | - if (isset($_GET['desc'])) |
|
1776 | - krsort($packages[$params]); |
|
1777 | - else |
|
1778 | - ksort($packages[$params]); |
|
1849 | + if (isset($_GET['desc'])) { |
|
1850 | + krsort($packages[$params]); |
|
1851 | + } else { |
|
1852 | + ksort($packages[$params]); |
|
1853 | + } |
|
1779 | 1854 | } |
1780 | 1855 | |
1781 | 1856 | return $packages[$params]; |
@@ -1804,10 +1879,11 @@ discard block |
||
1804 | 1879 | redirectexit('action=admin;area=packages;sa=options'); |
1805 | 1880 | } |
1806 | 1881 | |
1807 | - if (preg_match('~^/home\d*/([^/]+?)/public_html~', $_SERVER['DOCUMENT_ROOT'], $match)) |
|
1808 | - $default_username = $match[1]; |
|
1809 | - else |
|
1810 | - $default_username = ''; |
|
1882 | + if (preg_match('~^/home\d*/([^/]+?)/public_html~', $_SERVER['DOCUMENT_ROOT'], $match)) { |
|
1883 | + $default_username = $match[1]; |
|
1884 | + } else { |
|
1885 | + $default_username = ''; |
|
1886 | + } |
|
1811 | 1887 | |
1812 | 1888 | $context['page_title'] = $txt['package_settings']; |
1813 | 1889 | $context['sub_template'] = 'install_options'; |
@@ -1836,8 +1912,9 @@ discard block |
||
1836 | 1912 | isAllowedTo('admin_forum'); |
1837 | 1913 | |
1838 | 1914 | // We need to know the operation key for the search and replace, mod file looking at, is it a board mod? |
1839 | - if (!isset($_REQUEST['operation_key'], $_REQUEST['filename']) && !is_numeric($_REQUEST['operation_key'])) |
|
1840 | - fatal_lang_error('operation_invalid', 'general'); |
|
1915 | + if (!isset($_REQUEST['operation_key'], $_REQUEST['filename']) && !is_numeric($_REQUEST['operation_key'])) { |
|
1916 | + fatal_lang_error('operation_invalid', 'general'); |
|
1917 | + } |
|
1841 | 1918 | |
1842 | 1919 | // Load the required file. |
1843 | 1920 | require_once($sourcedir . '/Subs-Package.php'); |
@@ -1853,18 +1930,19 @@ discard block |
||
1853 | 1930 | { |
1854 | 1931 | $context['extracted_files'] = read_tgz_file($packagesdir . '/' . $context['filename'], $packagesdir . '/temp'); |
1855 | 1932 | |
1856 | - if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml')) |
|
1857 | - foreach ($context['extracted_files'] as $file) |
|
1933 | + if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml')) { |
|
1934 | + foreach ($context['extracted_files'] as $file) |
|
1858 | 1935 | if (basename($file['filename']) == 'package-info.xml') |
1859 | 1936 | { |
1860 | 1937 | $context['base_path'] = dirname($file['filename']) . '/'; |
1938 | + } |
|
1861 | 1939 | break; |
1862 | 1940 | } |
1863 | 1941 | |
1864 | - if (!isset($context['base_path'])) |
|
1865 | - $context['base_path'] = ''; |
|
1866 | - } |
|
1867 | - elseif (is_dir($packagesdir . '/' . $context['filename'])) |
|
1942 | + if (!isset($context['base_path'])) { |
|
1943 | + $context['base_path'] = ''; |
|
1944 | + } |
|
1945 | + } elseif (is_dir($packagesdir . '/' . $context['filename'])) |
|
1868 | 1946 | { |
1869 | 1947 | copytree($packagesdir . '/' . $context['filename'], $packagesdir . '/temp'); |
1870 | 1948 | $context['extracted_files'] = listtree($packagesdir . '/temp'); |
@@ -1885,8 +1963,9 @@ discard block |
||
1885 | 1963 | ) |
1886 | 1964 | ); |
1887 | 1965 | $theme_paths = array(); |
1888 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1889 | - $theme_paths[$row['id_theme']][$row['variable']] = $row['value']; |
|
1966 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1967 | + $theme_paths[$row['id_theme']][$row['variable']] = $row['value']; |
|
1968 | + } |
|
1890 | 1969 | $smcFunc['db_free_result']($request); |
1891 | 1970 | |
1892 | 1971 | // If we're viewing uninstall operations, only consider themes that |
@@ -1911,19 +1990,21 @@ discard block |
||
1911 | 1990 | list ($old_themes) = $smcFunc['db_fetch_row']($request); |
1912 | 1991 | $old_themes = explode(',', $old_themes); |
1913 | 1992 | |
1914 | - foreach ($theme_paths as $id => $data) |
|
1915 | - if ($id != 1 && !in_array($id, $old_themes)) |
|
1993 | + foreach ($theme_paths as $id => $data) { |
|
1994 | + if ($id != 1 && !in_array($id, $old_themes)) |
|
1916 | 1995 | unset($theme_paths[$id]); |
1996 | + } |
|
1917 | 1997 | } |
1918 | 1998 | $smcFunc['db_free_result']($request); |
1919 | 1999 | } |
1920 | 2000 | } |
1921 | 2001 | |
1922 | 2002 | // Boardmod? |
1923 | - if (isset($_REQUEST['boardmod'])) |
|
1924 | - $mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths); |
|
1925 | - else |
|
1926 | - $mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths); |
|
2003 | + if (isset($_REQUEST['boardmod'])) { |
|
2004 | + $mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths); |
|
2005 | + } else { |
|
2006 | + $mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths); |
|
2007 | + } |
|
1927 | 2008 | |
1928 | 2009 | // Ok lets get the content of the file. |
1929 | 2010 | $context['operations'] = array( |
@@ -1979,9 +2060,9 @@ discard block |
||
1979 | 2060 | 'path' => $detect_path, |
1980 | 2061 | 'form_elements_only' => true, |
1981 | 2062 | ); |
2063 | + } else { |
|
2064 | + $context['ftp_connected'] = true; |
|
1982 | 2065 | } |
1983 | - else |
|
1984 | - $context['ftp_connected'] = true; |
|
1985 | 2066 | |
1986 | 2067 | // Define the template. |
1987 | 2068 | $context['page_title'] = $txt['package_file_perms']; |
@@ -2094,18 +2175,19 @@ discard block |
||
2094 | 2175 | { |
2095 | 2176 | unset($context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['attachments']); |
2096 | 2177 | |
2097 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
2098 | - $modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true); |
|
2178 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
2179 | + $modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true); |
|
2180 | + } |
|
2099 | 2181 | |
2100 | 2182 | // @todo Should we suggest non-current directories be read only? |
2101 | - foreach ($modSettings['attachmentUploadDir'] as $dir) |
|
2102 | - $context['file_tree'][strtr($dir, array('\\' => '/'))] = array( |
|
2183 | + foreach ($modSettings['attachmentUploadDir'] as $dir) { |
|
2184 | + $context['file_tree'][strtr($dir, array('\\' => '/'))] = array( |
|
2103 | 2185 | 'type' => 'dir', |
2104 | 2186 | 'writable_on' => 'restrictive', |
2105 | 2187 | ); |
2188 | + } |
|
2106 | 2189 | |
2107 | - } |
|
2108 | - elseif (substr($modSettings['attachmentUploadDir'], 0, strlen($boarddir)) != $boarddir) |
|
2190 | + } elseif (substr($modSettings['attachmentUploadDir'], 0, strlen($boarddir)) != $boarddir) |
|
2109 | 2191 | { |
2110 | 2192 | unset($context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['attachments']); |
2111 | 2193 | $context['file_tree'][strtr($modSettings['attachmentUploadDir'], array('\\' => '/'))] = array( |
@@ -2155,8 +2237,8 @@ discard block |
||
2155 | 2237 | ); |
2156 | 2238 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
2157 | 2239 | { |
2158 | - if (substr(strtolower(strtr($row['value'], array('\\' => '/'))), 0, strlen($boarddir) + 7) == strtolower(strtr($boarddir, array('\\' => '/')) . '/Themes')) |
|
2159 | - $context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['Themes']['contents'][substr($row['value'], strlen($boarddir) + 8)] = array( |
|
2240 | + if (substr(strtolower(strtr($row['value'], array('\\' => '/'))), 0, strlen($boarddir) + 7) == strtolower(strtr($boarddir, array('\\' => '/')) . '/Themes')) { |
|
2241 | + $context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['Themes']['contents'][substr($row['value'], strlen($boarddir) + 8)] = array( |
|
2160 | 2242 | 'type' => 'dir_recursive', |
2161 | 2243 | 'list_contents' => true, |
2162 | 2244 | 'contents' => array( |
@@ -2166,7 +2248,7 @@ discard block |
||
2166 | 2248 | ), |
2167 | 2249 | ), |
2168 | 2250 | ); |
2169 | - else |
|
2251 | + } else |
|
2170 | 2252 | { |
2171 | 2253 | $context['file_tree'][strtr($row['value'], array('\\' => '/'))] = array( |
2172 | 2254 | 'type' => 'dir_recursive', |
@@ -2183,28 +2265,33 @@ discard block |
||
2183 | 2265 | $smcFunc['db_free_result']($request); |
2184 | 2266 | |
2185 | 2267 | // If we're submitting then let's move on to another function to keep things cleaner.. |
2186 | - if (isset($_POST['action_changes'])) |
|
2187 | - return PackagePermissionsAction(); |
|
2268 | + if (isset($_POST['action_changes'])) { |
|
2269 | + return PackagePermissionsAction(); |
|
2270 | + } |
|
2188 | 2271 | |
2189 | 2272 | $context['look_for'] = array(); |
2190 | 2273 | // Are we looking for a particular tree - normally an expansion? |
2191 | - if (!empty($_REQUEST['find'])) |
|
2192 | - $context['look_for'][] = base64_decode($_REQUEST['find']); |
|
2274 | + if (!empty($_REQUEST['find'])) { |
|
2275 | + $context['look_for'][] = base64_decode($_REQUEST['find']); |
|
2276 | + } |
|
2193 | 2277 | // Only that tree? |
2194 | 2278 | $context['only_find'] = isset($_GET['xml']) && !empty($_REQUEST['onlyfind']) ? $_REQUEST['onlyfind'] : ''; |
2195 | - if ($context['only_find']) |
|
2196 | - $context['look_for'][] = $context['only_find']; |
|
2279 | + if ($context['only_find']) { |
|
2280 | + $context['look_for'][] = $context['only_find']; |
|
2281 | + } |
|
2197 | 2282 | |
2198 | 2283 | // Have we got a load of back-catalogue trees to expand from a submit etc? |
2199 | 2284 | if (!empty($_GET['back_look'])) |
2200 | 2285 | { |
2201 | 2286 | $potententialTrees = $smcFunc['json_decode'](base64_decode($_GET['back_look']), true); |
2202 | - foreach ($potententialTrees as $tree) |
|
2203 | - $context['look_for'][] = $tree; |
|
2287 | + foreach ($potententialTrees as $tree) { |
|
2288 | + $context['look_for'][] = $tree; |
|
2289 | + } |
|
2204 | 2290 | } |
2205 | 2291 | // ... maybe posted? |
2206 | - if (!empty($_POST['back_look'])) |
|
2207 | - $context['only_find'] = array_merge($context['only_find'], $_POST['back_look']); |
|
2292 | + if (!empty($_POST['back_look'])) { |
|
2293 | + $context['only_find'] = array_merge($context['only_find'], $_POST['back_look']); |
|
2294 | + } |
|
2208 | 2295 | |
2209 | 2296 | $context['back_look_data'] = base64_encode($smcFunc['json_encode'](array_slice($context['look_for'], 0, 15))); |
2210 | 2297 | |
@@ -2243,9 +2330,9 @@ discard block |
||
2243 | 2330 | 'chmod' => @is_writable($path), |
2244 | 2331 | 'perms' => @fileperms($path), |
2245 | 2332 | ); |
2333 | + } else { |
|
2334 | + unset($context['file_tree'][$path]); |
|
2246 | 2335 | } |
2247 | - else |
|
2248 | - unset($context['file_tree'][$path]); |
|
2249 | 2336 | } |
2250 | 2337 | |
2251 | 2338 | // Is this actually xml? |
@@ -2269,22 +2356,25 @@ discard block |
||
2269 | 2356 | global $context; |
2270 | 2357 | |
2271 | 2358 | $isLikelyPath = false; |
2272 | - foreach ($context['look_for'] as $possiblePath) |
|
2273 | - if (substr($possiblePath, 0, strlen($path)) == $path) |
|
2359 | + foreach ($context['look_for'] as $possiblePath) { |
|
2360 | + if (substr($possiblePath, 0, strlen($path)) == $path) |
|
2274 | 2361 | $isLikelyPath = true; |
2362 | + } |
|
2275 | 2363 | |
2276 | 2364 | // Is this where we stop? |
2277 | - if (isset($_GET['xml']) && !empty($context['look_for']) && !$isLikelyPath) |
|
2278 | - return; |
|
2279 | - elseif ($level > $context['default_level'] && !$isLikelyPath) |
|
2280 | - return; |
|
2365 | + if (isset($_GET['xml']) && !empty($context['look_for']) && !$isLikelyPath) { |
|
2366 | + return; |
|
2367 | + } elseif ($level > $context['default_level'] && !$isLikelyPath) { |
|
2368 | + return; |
|
2369 | + } |
|
2281 | 2370 | |
2282 | 2371 | // Are we actually interested in saving this data? |
2283 | 2372 | $save_data = empty($context['only_find']) || $context['only_find'] == $path; |
2284 | 2373 | |
2285 | 2374 | // @todo Shouldn't happen - but better error message? |
2286 | - if (!is_dir($path)) |
|
2287 | - fatal_lang_error('no_access', false); |
|
2375 | + if (!is_dir($path)) { |
|
2376 | + fatal_lang_error('no_access', false); |
|
2377 | + } |
|
2288 | 2378 | |
2289 | 2379 | // This is where we put stuff we've found for sorting. |
2290 | 2380 | $foundData = array( |
@@ -2299,11 +2389,13 @@ discard block |
||
2299 | 2389 | if (is_file($path . '/' . $entry)) |
2300 | 2390 | { |
2301 | 2391 | // Are we listing PHP files in this directory? |
2302 | - if ($save_data && !empty($data['list_contents']) && substr($entry, -4) == '.php') |
|
2303 | - $foundData['files'][$entry] = true; |
|
2392 | + if ($save_data && !empty($data['list_contents']) && substr($entry, -4) == '.php') { |
|
2393 | + $foundData['files'][$entry] = true; |
|
2394 | + } |
|
2304 | 2395 | // A file we were looking for. |
2305 | - elseif ($save_data && isset($data['contents'][$entry])) |
|
2306 | - $foundData['files'][$entry] = true; |
|
2396 | + elseif ($save_data && isset($data['contents'][$entry])) { |
|
2397 | + $foundData['files'][$entry] = true; |
|
2398 | + } |
|
2307 | 2399 | } |
2308 | 2400 | // It's a directory - we're interested one way or another, probably... |
2309 | 2401 | elseif ($entry != '.' && $entry != '..') |
@@ -2311,32 +2403,36 @@ discard block |
||
2311 | 2403 | // Going further? |
2312 | 2404 | if ((!empty($data['type']) && $data['type'] == 'dir_recursive') || (isset($data['contents'][$entry]) && (!empty($data['contents'][$entry]['list_contents']) || (!empty($data['contents'][$entry]['type']) && $data['contents'][$entry]['type'] == 'dir_recursive')))) |
2313 | 2405 | { |
2314 | - if (!isset($data['contents'][$entry])) |
|
2315 | - $foundData['folders'][$entry] = 'dir_recursive'; |
|
2316 | - else |
|
2317 | - $foundData['folders'][$entry] = true; |
|
2406 | + if (!isset($data['contents'][$entry])) { |
|
2407 | + $foundData['folders'][$entry] = 'dir_recursive'; |
|
2408 | + } else { |
|
2409 | + $foundData['folders'][$entry] = true; |
|
2410 | + } |
|
2318 | 2411 | |
2319 | 2412 | // If this wasn't expected inherit the recusiveness... |
2320 | - if (!isset($data['contents'][$entry])) |
|
2321 | - // We need to do this as we will be going all recursive. |
|
2413 | + if (!isset($data['contents'][$entry])) { |
|
2414 | + // We need to do this as we will be going all recursive. |
|
2322 | 2415 | $data['contents'][$entry] = array( |
2323 | 2416 | 'type' => 'dir_recursive', |
2324 | 2417 | ); |
2418 | + } |
|
2325 | 2419 | |
2326 | 2420 | // Actually do the recursive stuff... |
2327 | 2421 | fetchPerms__recursive($path . '/' . $entry, $data['contents'][$entry], $level + 1); |
2328 | 2422 | } |
2329 | 2423 | // Maybe it is a folder we are not descending into. |
2330 | - elseif (isset($data['contents'][$entry])) |
|
2331 | - $foundData['folders'][$entry] = true; |
|
2424 | + elseif (isset($data['contents'][$entry])) { |
|
2425 | + $foundData['folders'][$entry] = true; |
|
2426 | + } |
|
2332 | 2427 | // Otherwise we stop here. |
2333 | 2428 | } |
2334 | 2429 | } |
2335 | 2430 | closedir($dh); |
2336 | 2431 | |
2337 | 2432 | // Nothing to see here? |
2338 | - if (!$save_data) |
|
2339 | - return; |
|
2433 | + if (!$save_data) { |
|
2434 | + return; |
|
2435 | + } |
|
2340 | 2436 | |
2341 | 2437 | // Now actually add the data, starting with the folders. |
2342 | 2438 | ksort($foundData['folders']); |
@@ -2348,8 +2444,9 @@ discard block |
||
2348 | 2444 | 'perms' => @fileperms($path . '/' . $folder), |
2349 | 2445 | ), |
2350 | 2446 | ); |
2351 | - if ($type !== true) |
|
2352 | - $additional_data['type'] = $type; |
|
2447 | + if ($type !== true) { |
|
2448 | + $additional_data['type'] = $type; |
|
2449 | + } |
|
2353 | 2450 | |
2354 | 2451 | // If there's an offset ignore any folders in XML mode. |
2355 | 2452 | if (isset($_GET['xml']) && $context['file_offset'] == 0) |
@@ -2368,13 +2465,13 @@ discard block |
||
2368 | 2465 | ), |
2369 | 2466 | 'value' => $folder, |
2370 | 2467 | ); |
2371 | - } |
|
2372 | - elseif (!isset($_GET['xml'])) |
|
2468 | + } elseif (!isset($_GET['xml'])) |
|
2373 | 2469 | { |
2374 | - if (isset($data['contents'][$folder])) |
|
2375 | - $data['contents'][$folder] = array_merge($data['contents'][$folder], $additional_data); |
|
2376 | - else |
|
2377 | - $data['contents'][$folder] = $additional_data; |
|
2470 | + if (isset($data['contents'][$folder])) { |
|
2471 | + $data['contents'][$folder] = array_merge($data['contents'][$folder], $additional_data); |
|
2472 | + } else { |
|
2473 | + $data['contents'][$folder] = $additional_data; |
|
2474 | + } |
|
2378 | 2475 | } |
2379 | 2476 | } |
2380 | 2477 | |
@@ -2386,11 +2483,13 @@ discard block |
||
2386 | 2483 | $counter++; |
2387 | 2484 | |
2388 | 2485 | // Have we reached our offset? |
2389 | - if ($context['file_offset'] > $counter) |
|
2390 | - continue; |
|
2486 | + if ($context['file_offset'] > $counter) { |
|
2487 | + continue; |
|
2488 | + } |
|
2391 | 2489 | // Gone too far? |
2392 | - if ($counter > ($context['file_offset'] + $context['file_limit'])) |
|
2393 | - continue; |
|
2490 | + if ($counter > ($context['file_offset'] + $context['file_limit'])) { |
|
2491 | + continue; |
|
2492 | + } |
|
2394 | 2493 | |
2395 | 2494 | $additional_data = array( |
2396 | 2495 | 'perms' => array( |
@@ -2416,13 +2515,13 @@ discard block |
||
2416 | 2515 | ), |
2417 | 2516 | 'value' => $file, |
2418 | 2517 | ); |
2419 | - } |
|
2420 | - elseif ($counter != ($context['file_offset'] + $context['file_limit'])) |
|
2518 | + } elseif ($counter != ($context['file_offset'] + $context['file_limit'])) |
|
2421 | 2519 | { |
2422 | - if (isset($data['contents'][$file])) |
|
2423 | - $data['contents'][$file] = array_merge($data['contents'][$file], $additional_data); |
|
2424 | - else |
|
2425 | - $data['contents'][$file] = $additional_data; |
|
2520 | + if (isset($data['contents'][$file])) { |
|
2521 | + $data['contents'][$file] = array_merge($data['contents'][$file], $additional_data); |
|
2522 | + } else { |
|
2523 | + $data['contents'][$file] = $additional_data; |
|
2524 | + } |
|
2426 | 2525 | } |
2427 | 2526 | } |
2428 | 2527 | } |
@@ -2444,8 +2543,9 @@ discard block |
||
2444 | 2543 | $context['back_look_data'] = isset($_POST['back_look']) ? $_POST['back_look'] : array(); |
2445 | 2544 | |
2446 | 2545 | // Skipping use of FTP? |
2447 | - if (empty($package_ftp)) |
|
2448 | - $context['skip_ftp'] = true; |
|
2546 | + if (empty($package_ftp)) { |
|
2547 | + $context['skip_ftp'] = true; |
|
2548 | + } |
|
2449 | 2549 | |
2450 | 2550 | // We'll start off in a good place, security. Make sure that if we're dealing with individual files that they seem in the right place. |
2451 | 2551 | if ($context['method'] == 'individual') |
@@ -2455,8 +2555,9 @@ discard block |
||
2455 | 2555 | $context['custom_value'] = (int) $_POST['custom_value']; |
2456 | 2556 | |
2457 | 2557 | // Continuing? |
2458 | - if (isset($_POST['toProcess'])) |
|
2459 | - $_POST['permStatus'] = $smcFunc['json_decode'](base64_decode($_POST['toProcess']), true); |
|
2558 | + if (isset($_POST['toProcess'])) { |
|
2559 | + $_POST['permStatus'] = $smcFunc['json_decode'](base64_decode($_POST['toProcess']), true); |
|
2560 | + } |
|
2460 | 2561 | |
2461 | 2562 | if (isset($_POST['permStatus'])) |
2462 | 2563 | { |
@@ -2465,22 +2566,27 @@ discard block |
||
2465 | 2566 | foreach ($_POST['permStatus'] as $path => $status) |
2466 | 2567 | { |
2467 | 2568 | // Nothing to see here? |
2468 | - if ($status == 'no_change') |
|
2469 | - continue; |
|
2569 | + if ($status == 'no_change') { |
|
2570 | + continue; |
|
2571 | + } |
|
2470 | 2572 | $legal = false; |
2471 | - foreach ($legal_roots as $root) |
|
2472 | - if (substr($path, 0, strlen($root)) == $root) |
|
2573 | + foreach ($legal_roots as $root) { |
|
2574 | + if (substr($path, 0, strlen($root)) == $root) |
|
2473 | 2575 | $legal = true; |
2576 | + } |
|
2474 | 2577 | |
2475 | - if (!$legal) |
|
2476 | - continue; |
|
2578 | + if (!$legal) { |
|
2579 | + continue; |
|
2580 | + } |
|
2477 | 2581 | |
2478 | 2582 | // Check it exists. |
2479 | - if (!file_exists($path)) |
|
2480 | - continue; |
|
2583 | + if (!file_exists($path)) { |
|
2584 | + continue; |
|
2585 | + } |
|
2481 | 2586 | |
2482 | - if ($status == 'custom') |
|
2483 | - $validate_custom = true; |
|
2587 | + if ($status == 'custom') { |
|
2588 | + $validate_custom = true; |
|
2589 | + } |
|
2484 | 2590 | |
2485 | 2591 | // Now add it. |
2486 | 2592 | $context['to_process'][$path] = $status; |
@@ -2490,17 +2596,20 @@ discard block |
||
2490 | 2596 | // Make sure the chmod status is valid? |
2491 | 2597 | if ($validate_custom) |
2492 | 2598 | { |
2493 | - if (preg_match('~^[4567][4567][4567]$~', $context['custom_value']) == false) |
|
2494 | - fatal_error($txt['chmod_value_invalid']); |
|
2599 | + if (preg_match('~^[4567][4567][4567]$~', $context['custom_value']) == false) { |
|
2600 | + fatal_error($txt['chmod_value_invalid']); |
|
2601 | + } |
|
2495 | 2602 | } |
2496 | 2603 | |
2497 | 2604 | // Nothing to do? |
2498 | - if (empty($context['to_process'])) |
|
2499 | - redirectexit('action=admin;area=packages;sa=perms' . (!empty($context['back_look_data']) ? ';back_look=' . base64_encode($smcFunc['json_encode']($context['back_look_data'])) : '') . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
2605 | + if (empty($context['to_process'])) { |
|
2606 | + redirectexit('action=admin;area=packages;sa=perms' . (!empty($context['back_look_data']) ? ';back_look=' . base64_encode($smcFunc['json_encode']($context['back_look_data'])) : '') . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
2607 | + } |
|
2500 | 2608 | } |
2501 | 2609 | // Should never get here, |
2502 | - else |
|
2503 | - fatal_lang_error('no_access', false); |
|
2610 | + else { |
|
2611 | + fatal_lang_error('no_access', false); |
|
2612 | + } |
|
2504 | 2613 | |
2505 | 2614 | // Setup the custom value. |
2506 | 2615 | $custom_value = octdec('0' . $context['custom_value']); |
@@ -2508,18 +2617,18 @@ discard block |
||
2508 | 2617 | // Start processing items. |
2509 | 2618 | foreach ($context['to_process'] as $path => $status) |
2510 | 2619 | { |
2511 | - if (in_array($status, array('execute', 'writable', 'read'))) |
|
2512 | - package_chmod($path, $status); |
|
2513 | - elseif ($status == 'custom' && !empty($custom_value)) |
|
2620 | + if (in_array($status, array('execute', 'writable', 'read'))) { |
|
2621 | + package_chmod($path, $status); |
|
2622 | + } elseif ($status == 'custom' && !empty($custom_value)) |
|
2514 | 2623 | { |
2515 | 2624 | // Use FTP if we have it. |
2516 | 2625 | if (!empty($package_ftp) && !empty($_SESSION['pack_ftp'])) |
2517 | 2626 | { |
2518 | 2627 | $ftp_file = strtr($path, array($_SESSION['pack_ftp']['root'] => '')); |
2519 | 2628 | $package_ftp->chmod($ftp_file, $custom_value); |
2629 | + } else { |
|
2630 | + smf_chmod($path, $custom_value); |
|
2520 | 2631 | } |
2521 | - else |
|
2522 | - smf_chmod($path, $custom_value); |
|
2523 | 2632 | } |
2524 | 2633 | |
2525 | 2634 | // This fish is fried... |
@@ -2603,23 +2712,27 @@ discard block |
||
2603 | 2712 | { |
2604 | 2713 | global $context; |
2605 | 2714 | |
2606 | - if (!empty($data['writable_on'])) |
|
2607 | - if ($context['predefined_type'] == 'standard' || $data['writable_on'] == 'restrictive') |
|
2715 | + if (!empty($data['writable_on'])) { |
|
2716 | + if ($context['predefined_type'] == 'standard' || $data['writable_on'] == 'restrictive') |
|
2608 | 2717 | $context['special_files'][$path] = 1; |
2718 | + } |
|
2609 | 2719 | |
2610 | - if (!empty($data['contents'])) |
|
2611 | - foreach ($data['contents'] as $name => $contents) |
|
2720 | + if (!empty($data['contents'])) { |
|
2721 | + foreach ($data['contents'] as $name => $contents) |
|
2612 | 2722 | build_special_files__recursive($path . '/' . $name, $contents); |
2723 | + } |
|
2613 | 2724 | } |
2614 | 2725 | |
2615 | - foreach ($context['file_tree'] as $path => $data) |
|
2616 | - build_special_files__recursive($path, $data); |
|
2726 | + foreach ($context['file_tree'] as $path => $data) { |
|
2727 | + build_special_files__recursive($path, $data); |
|
2728 | + } |
|
2617 | 2729 | } |
2618 | 2730 | // Free doesn't need special files. |
2619 | - elseif ($context['predefined_type'] == 'free') |
|
2620 | - $context['special_files'] = array(); |
|
2621 | - else |
|
2622 | - $context['special_files'] = $smcFunc['json_decode'](base64_decode($_POST['specialFiles']), true); |
|
2731 | + elseif ($context['predefined_type'] == 'free') { |
|
2732 | + $context['special_files'] = array(); |
|
2733 | + } else { |
|
2734 | + $context['special_files'] = $smcFunc['json_decode'](base64_decode($_POST['specialFiles']), true); |
|
2735 | + } |
|
2623 | 2736 | |
2624 | 2737 | // Now we definitely know where we are, we need to go through again doing the chmod! |
2625 | 2738 | foreach ($context['directory_list'] as $path => $dummy) |
@@ -11,8 +11,9 @@ discard block |
||
11 | 11 | * @version 2.1 Beta 4 |
12 | 12 | */ |
13 | 13 | |
14 | -if (!defined('SMF')) |
|
14 | +if (!defined('SMF')) { |
|
15 | 15 | die('No direct access...'); |
16 | +} |
|
16 | 17 | |
17 | 18 | /** |
18 | 19 | * Used for the "custom search index" option |
@@ -54,8 +55,9 @@ discard block |
||
54 | 55 | return; |
55 | 56 | } |
56 | 57 | |
57 | - if (empty($modSettings['search_custom_index_config'])) |
|
58 | - return; |
|
58 | + if (empty($modSettings['search_custom_index_config'])) { |
|
59 | + return; |
|
60 | + } |
|
59 | 61 | |
60 | 62 | $this->indexSettings = $smcFunc['json_decode']($modSettings['search_custom_index_config'], true); |
61 | 63 | |
@@ -117,21 +119,23 @@ discard block |
||
117 | 119 | |
118 | 120 | $subwords = text2words($word, $this->min_word_length, true); |
119 | 121 | |
120 | - if (empty($modSettings['search_force_index'])) |
|
121 | - $wordsSearch['words'][] = $word; |
|
122 | + if (empty($modSettings['search_force_index'])) { |
|
123 | + $wordsSearch['words'][] = $word; |
|
124 | + } |
|
122 | 125 | |
123 | 126 | // Excluded phrases don't benefit from being split into subwords. |
124 | - if (count($subwords) > 1 && $isExcluded) |
|
125 | - return; |
|
126 | - else |
|
127 | + if (count($subwords) > 1 && $isExcluded) { |
|
128 | + return; |
|
129 | + } else |
|
127 | 130 | { |
128 | 131 | foreach ($subwords as $subword) |
129 | 132 | { |
130 | 133 | if ($smcFunc['strlen']($subword) >= $this->min_word_length && !in_array($subword, $this->bannedWords)) |
131 | 134 | { |
132 | 135 | $wordsSearch['indexed_words'][] = $subword; |
133 | - if ($isExcluded) |
|
134 | - $wordsExclude[] = $subword; |
|
136 | + if ($isExcluded) { |
|
137 | + $wordsExclude[] = $subword; |
|
138 | + } |
|
135 | 139 | } |
136 | 140 | } |
137 | 141 | } |
@@ -152,8 +156,9 @@ discard block |
||
152 | 156 | $query_where = array(); |
153 | 157 | $query_params = $search_data['params']; |
154 | 158 | |
155 | - if ($query_params['id_search']) |
|
156 | - $query_select['id_search'] = '{int:id_search}'; |
|
159 | + if ($query_params['id_search']) { |
|
160 | + $query_select['id_search'] = '{int:id_search}'; |
|
161 | + } |
|
157 | 162 | |
158 | 163 | $count = 0; |
159 | 164 | foreach ($words['words'] as $regularWord) |
@@ -162,30 +167,37 @@ discard block |
||
162 | 167 | $query_params['complex_body_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]'; |
163 | 168 | } |
164 | 169 | |
165 | - if ($query_params['user_query']) |
|
166 | - $query_where[] = '{raw:user_query}'; |
|
167 | - if ($query_params['board_query']) |
|
168 | - $query_where[] = 'm.id_board {raw:board_query}'; |
|
170 | + if ($query_params['user_query']) { |
|
171 | + $query_where[] = '{raw:user_query}'; |
|
172 | + } |
|
173 | + if ($query_params['board_query']) { |
|
174 | + $query_where[] = 'm.id_board {raw:board_query}'; |
|
175 | + } |
|
169 | 176 | |
170 | - if ($query_params['topic']) |
|
171 | - $query_where[] = 'm.id_topic = {int:topic}'; |
|
172 | - if ($query_params['min_msg_id']) |
|
173 | - $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
174 | - if ($query_params['max_msg_id']) |
|
175 | - $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
177 | + if ($query_params['topic']) { |
|
178 | + $query_where[] = 'm.id_topic = {int:topic}'; |
|
179 | + } |
|
180 | + if ($query_params['min_msg_id']) { |
|
181 | + $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
182 | + } |
|
183 | + if ($query_params['max_msg_id']) { |
|
184 | + $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
185 | + } |
|
176 | 186 | |
177 | 187 | $count = 0; |
178 | - if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) |
|
179 | - foreach ($query_params['excluded_phrases'] as $phrase) |
|
188 | + if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) { |
|
189 | + foreach ($query_params['excluded_phrases'] as $phrase) |
|
180 | 190 | { |
181 | 191 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : ' RLIKE ') . '{string:exclude_subject_phrase_' . $count . '}'; |
192 | + } |
|
182 | 193 | $query_params['exclude_subject_phrase_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($phrase, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $phrase), '\\\'') . '[[:>:]]'; |
183 | 194 | } |
184 | 195 | $count = 0; |
185 | - if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) |
|
186 | - foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
196 | + if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) { |
|
197 | + foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
187 | 198 | { |
188 | 199 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : ' RLIKE ') . '{string:exclude_subject_words_' . $count . '}'; |
200 | + } |
|
189 | 201 | $query_params['exclude_subject_words_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($excludedWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $excludedWord), '\\\'') . '[[:>:]]'; |
190 | 202 | } |
191 | 203 | |
@@ -198,8 +210,7 @@ discard block |
||
198 | 210 | { |
199 | 211 | $query_left_join[] = '{db_prefix}log_search_words AS lsw' . $numTables . ' ON (lsw' . $numTables . '.id_word = ' . $indexedWord . ' AND lsw' . $numTables . '.id_msg = m.id_msg)'; |
200 | 212 | $query_where[] = '(lsw' . $numTables . '.id_word IS NULL)'; |
201 | - } |
|
202 | - else |
|
213 | + } else |
|
203 | 214 | { |
204 | 215 | $query_inner_join[] = '{db_prefix}log_search_words AS lsw' . $numTables . ' ON (lsw' . $numTables . '.id_msg = ' . ($prev_join === 0 ? 'm' : 'lsw' . $prev_join) . '.id_msg)'; |
205 | 216 | $query_where[] = 'lsw' . $numTables . '.id_word = ' . $indexedWord; |
@@ -235,16 +246,18 @@ discard block |
||
235 | 246 | $customIndexSettings = $smcFunc['json_decode']($modSettings['search_custom_index_config'], true); |
236 | 247 | |
237 | 248 | $inserts = array(); |
238 | - foreach (text2words($msgOptions['body'], $customIndexSettings['bytes_per_word'], true) as $word) |
|
239 | - $inserts[] = array($word, $msgOptions['id']); |
|
249 | + foreach (text2words($msgOptions['body'], $customIndexSettings['bytes_per_word'], true) as $word) { |
|
250 | + $inserts[] = array($word, $msgOptions['id']); |
|
251 | + } |
|
240 | 252 | |
241 | - if (!empty($inserts)) |
|
242 | - $smcFunc['db_insert']('ignore', |
|
253 | + if (!empty($inserts)) { |
|
254 | + $smcFunc['db_insert']('ignore', |
|
243 | 255 | '{db_prefix}log_search_words', |
244 | 256 | array('id_word' => 'int', 'id_msg' => 'int'), |
245 | 257 | $inserts, |
246 | 258 | array('id_word', 'id_msg') |
247 | 259 | ); |
260 | + } |
|
248 | 261 | } |
249 | 262 | |
250 | 263 | /** |
@@ -287,8 +300,9 @@ discard block |
||
287 | 300 | if (!empty($inserted_words)) |
288 | 301 | { |
289 | 302 | $inserts = array(); |
290 | - foreach ($inserted_words as $word) |
|
291 | - $inserts[] = array($word, $msgOptions['id']); |
|
303 | + foreach ($inserted_words as $word) { |
|
304 | + $inserts[] = array($word, $msgOptions['id']); |
|
305 | + } |
|
292 | 306 | $smcFunc['db_insert']('insert', |
293 | 307 | '{db_prefix}log_search_words', |
294 | 308 | array('id_word' => 'string', 'id_msg' => 'int'), |
@@ -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 | loadLanguage('Drafts'); |
21 | 22 | |
@@ -33,8 +34,9 @@ discard block |
||
33 | 34 | global $context, $user_info, $smcFunc, $modSettings, $board; |
34 | 35 | |
35 | 36 | // can you be, should you be ... here? |
36 | - if (empty($modSettings['drafts_post_enabled']) || !allowedTo('post_draft') || !isset($_POST['save_draft']) || !isset($_POST['id_draft'])) |
|
37 | - return false; |
|
37 | + if (empty($modSettings['drafts_post_enabled']) || !allowedTo('post_draft') || !isset($_POST['save_draft']) || !isset($_POST['id_draft'])) { |
|
38 | + return false; |
|
39 | + } |
|
38 | 40 | |
39 | 41 | // read in what they sent us, if anything |
40 | 42 | $id_draft = (int) $_POST['id_draft']; |
@@ -46,14 +48,16 @@ discard block |
||
46 | 48 | $context['draft_saved_on'] = $draft_info['poster_time']; |
47 | 49 | |
48 | 50 | // since we were called from the autosave function, send something back |
49 | - if (!empty($id_draft)) |
|
50 | - XmlDraft($id_draft); |
|
51 | + if (!empty($id_draft)) { |
|
52 | + XmlDraft($id_draft); |
|
53 | + } |
|
51 | 54 | |
52 | 55 | return true; |
53 | 56 | } |
54 | 57 | |
55 | - if (!isset($_POST['message'])) |
|
56 | - $_POST['message'] = isset($_POST['quickReply']) ? $_POST['quickReply'] : ''; |
|
58 | + if (!isset($_POST['message'])) { |
|
59 | + $_POST['message'] = isset($_POST['quickReply']) ? $_POST['quickReply'] : ''; |
|
60 | + } |
|
57 | 61 | |
58 | 62 | // prepare any data from the form |
59 | 63 | $topic_id = empty($_REQUEST['topic']) ? 0 : (int) $_REQUEST['topic']; |
@@ -66,8 +70,9 @@ discard block |
||
66 | 70 | |
67 | 71 | // message and subject still need a bit more work |
68 | 72 | preparsecode($draft['body']); |
69 | - if ($smcFunc['strlen']($draft['subject']) > 100) |
|
70 | - $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); |
|
73 | + if ($smcFunc['strlen']($draft['subject']) > 100) { |
|
74 | + $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); |
|
75 | + } |
|
71 | 76 | |
72 | 77 | // Modifying an existing draft, like hitting the save draft button or autosave enabled? |
73 | 78 | if (!empty($id_draft) && !empty($draft_info)) |
@@ -148,9 +153,9 @@ discard block |
||
148 | 153 | { |
149 | 154 | $context['draft_saved'] = true; |
150 | 155 | $context['id_draft'] = $id_draft; |
156 | + } else { |
|
157 | + $post_errors[] = 'draft_not_saved'; |
|
151 | 158 | } |
152 | - else |
|
153 | - $post_errors[] = 'draft_not_saved'; |
|
154 | 159 | |
155 | 160 | // cleanup |
156 | 161 | unset($_POST['save_draft']); |
@@ -180,8 +185,9 @@ discard block |
||
180 | 185 | global $context, $user_info, $smcFunc, $modSettings; |
181 | 186 | |
182 | 187 | // PM survey says ... can you stay or must you go |
183 | - if (empty($modSettings['drafts_pm_enabled']) || !allowedTo('pm_draft') || !isset($_POST['save_draft'])) |
|
184 | - return false; |
|
188 | + if (empty($modSettings['drafts_pm_enabled']) || !allowedTo('pm_draft') || !isset($_POST['save_draft'])) { |
|
189 | + return false; |
|
190 | + } |
|
185 | 191 | |
186 | 192 | // read in what you sent us |
187 | 193 | $id_pm_draft = (int) $_POST['id_pm_draft']; |
@@ -193,8 +199,9 @@ discard block |
||
193 | 199 | $context['draft_saved_on'] = $draft_info['poster_time']; |
194 | 200 | |
195 | 201 | // Send something back to the javascript caller |
196 | - if (!empty($id_draft)) |
|
197 | - XmlDraft($id_draft); |
|
202 | + if (!empty($id_draft)) { |
|
203 | + XmlDraft($id_draft); |
|
204 | + } |
|
198 | 205 | |
199 | 206 | return true; |
200 | 207 | } |
@@ -204,9 +211,9 @@ discard block |
||
204 | 211 | { |
205 | 212 | $recipientList['to'] = isset($_POST['recipient_to']) ? explode(',', $_POST['recipient_to']) : array(); |
206 | 213 | $recipientList['bcc'] = isset($_POST['recipient_bcc']) ? explode(',', $_POST['recipient_bcc']) : array(); |
214 | + } elseif (!empty($draft_info['to_list']) && empty($recipientList)) { |
|
215 | + $recipientList = $smcFunc['json_decode']($draft_info['to_list'], true); |
|
207 | 216 | } |
208 | - elseif (!empty($draft_info['to_list']) && empty($recipientList)) |
|
209 | - $recipientList = $smcFunc['json_decode']($draft_info['to_list'], true); |
|
210 | 217 | |
211 | 218 | // prepare the data we got from the form |
212 | 219 | $reply_id = empty($_POST['replied_to']) ? 0 : (int) $_POST['replied_to']; |
@@ -215,8 +222,9 @@ discard block |
||
215 | 222 | |
216 | 223 | // message and subject always need a bit more work |
217 | 224 | preparsecode($draft['body']); |
218 | - if ($smcFunc['strlen']($draft['subject']) > 100) |
|
219 | - $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); |
|
225 | + if ($smcFunc['strlen']($draft['subject']) > 100) { |
|
226 | + $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); |
|
227 | + } |
|
220 | 228 | |
221 | 229 | // Modifying an existing PM draft? |
222 | 230 | if (!empty($id_pm_draft) && !empty($draft_info)) |
@@ -280,9 +288,9 @@ discard block |
||
280 | 288 | { |
281 | 289 | $context['draft_saved'] = true; |
282 | 290 | $context['id_pm_draft'] = $id_pm_draft; |
291 | + } else { |
|
292 | + $post_errors[] = 'draft_not_saved'; |
|
283 | 293 | } |
284 | - else |
|
285 | - $post_errors[] = 'draft_not_saved'; |
|
286 | 294 | } |
287 | 295 | |
288 | 296 | // if we were called from the autosave function, send something back |
@@ -315,8 +323,9 @@ discard block |
||
315 | 323 | $type = (int) $type; |
316 | 324 | |
317 | 325 | // nothing to read, nothing to do |
318 | - if (empty($id_draft)) |
|
319 | - return false; |
|
326 | + if (empty($id_draft)) { |
|
327 | + return false; |
|
328 | + } |
|
320 | 329 | |
321 | 330 | // load in this draft from the DB |
322 | 331 | $request = $smcFunc['db_query']('', ' |
@@ -337,8 +346,9 @@ discard block |
||
337 | 346 | ); |
338 | 347 | |
339 | 348 | // no results? |
340 | - if (!$smcFunc['db_num_rows']($request)) |
|
341 | - return false; |
|
349 | + if (!$smcFunc['db_num_rows']($request)) { |
|
350 | + return false; |
|
351 | + } |
|
342 | 352 | |
343 | 353 | // load up the data |
344 | 354 | $draft_info = $smcFunc['db_fetch_assoc']($request); |
@@ -358,8 +368,7 @@ discard block |
||
358 | 368 | $context['subject'] = !empty($draft_info['subject']) ? stripslashes($draft_info['subject']) : ''; |
359 | 369 | $context['board'] = !empty($draft_info['id_board']) ? $draft_info['id_board'] : ''; |
360 | 370 | $context['id_draft'] = !empty($draft_info['id_draft']) ? $draft_info['id_draft'] : 0; |
361 | - } |
|
362 | - elseif ($type === 1) |
|
371 | + } elseif ($type === 1) |
|
363 | 372 | { |
364 | 373 | // one of those pm drafts? then set it up like we have an error |
365 | 374 | $_REQUEST['subject'] = !empty($draft_info['subject']) ? stripslashes($draft_info['subject']) : ''; |
@@ -395,12 +404,14 @@ discard block |
||
395 | 404 | global $user_info, $smcFunc; |
396 | 405 | |
397 | 406 | // Only a single draft. |
398 | - if (is_numeric($id_draft)) |
|
399 | - $id_draft = array($id_draft); |
|
407 | + if (is_numeric($id_draft)) { |
|
408 | + $id_draft = array($id_draft); |
|
409 | + } |
|
400 | 410 | |
401 | 411 | // can't delete nothing |
402 | - if (empty($id_draft) || ($check && empty($user_info['id']))) |
|
403 | - return false; |
|
412 | + if (empty($id_draft) || ($check && empty($user_info['id']))) { |
|
413 | + return false; |
|
414 | + } |
|
404 | 415 | |
405 | 416 | $smcFunc['db_query']('', ' |
406 | 417 | DELETE FROM {db_prefix}user_drafts |
@@ -429,14 +440,16 @@ discard block |
||
429 | 440 | global $smcFunc, $scripturl, $context, $txt, $modSettings; |
430 | 441 | |
431 | 442 | // Permissions |
432 | - if (($draft_type === 0 && empty($context['drafts_save'])) || ($draft_type === 1 && empty($context['drafts_pm_save'])) || empty($member_id)) |
|
433 | - return false; |
|
443 | + if (($draft_type === 0 && empty($context['drafts_save'])) || ($draft_type === 1 && empty($context['drafts_pm_save'])) || empty($member_id)) { |
|
444 | + return false; |
|
445 | + } |
|
434 | 446 | |
435 | 447 | $context['drafts'] = array(); |
436 | 448 | |
437 | 449 | // has a specific draft has been selected? Load it up if there is not a message already in the editor |
438 | - if (isset($_REQUEST['id_draft']) && empty($_POST['subject']) && empty($_POST['message'])) |
|
439 | - ReadDraft((int) $_REQUEST['id_draft'], $draft_type, true, true); |
|
450 | + if (isset($_REQUEST['id_draft']) && empty($_POST['subject']) && empty($_POST['message'])) { |
|
451 | + ReadDraft((int) $_REQUEST['id_draft'], $draft_type, true, true); |
|
452 | + } |
|
440 | 453 | |
441 | 454 | // load the drafts this user has available |
442 | 455 | $request = $smcFunc['db_query']('', ' |
@@ -459,8 +472,9 @@ discard block |
||
459 | 472 | // add them to the draft array for display |
460 | 473 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
461 | 474 | { |
462 | - if (empty($row['subject'])) |
|
463 | - $row['subject'] = $txt['no_subject']; |
|
475 | + if (empty($row['subject'])) { |
|
476 | + $row['subject'] = $txt['no_subject']; |
|
477 | + } |
|
464 | 478 | |
465 | 479 | // Post drafts |
466 | 480 | if ($draft_type === 0) |
@@ -545,8 +559,9 @@ discard block |
||
545 | 559 | } |
546 | 560 | |
547 | 561 | // Default to 10. |
548 | - if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) |
|
549 | - $_REQUEST['viewscount'] = 10; |
|
562 | + if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) { |
|
563 | + $_REQUEST['viewscount'] = 10; |
|
564 | + } |
|
550 | 565 | |
551 | 566 | // Get the count of applicable drafts on the boards they can (still) see ... |
552 | 567 | // @todo .. should we just let them see their drafts even if they have lost board access ? |
@@ -611,12 +626,14 @@ discard block |
||
611 | 626 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
612 | 627 | { |
613 | 628 | // Censor.... |
614 | - if (empty($row['body'])) |
|
615 | - $row['body'] = ''; |
|
629 | + if (empty($row['body'])) { |
|
630 | + $row['body'] = ''; |
|
631 | + } |
|
616 | 632 | |
617 | 633 | $row['subject'] = $smcFunc['htmltrim']($row['subject']); |
618 | - if (empty($row['subject'])) |
|
619 | - $row['subject'] = $txt['no_subject']; |
|
634 | + if (empty($row['subject'])) { |
|
635 | + $row['subject'] = $txt['no_subject']; |
|
636 | + } |
|
620 | 637 | |
621 | 638 | censorText($row['body']); |
622 | 639 | censorText($row['subject']); |
@@ -648,8 +665,9 @@ discard block |
||
648 | 665 | $smcFunc['db_free_result']($request); |
649 | 666 | |
650 | 667 | // If the drafts were retrieved in reverse order, get them right again. |
651 | - if ($reverse) |
|
652 | - $context['drafts'] = array_reverse($context['drafts'], true); |
|
668 | + if ($reverse) { |
|
669 | + $context['drafts'] = array_reverse($context['drafts'], true); |
|
670 | + } |
|
653 | 671 | |
654 | 672 | // Menu tab |
655 | 673 | $context[$context['profile_menu_name']]['tab_data'] = array( |
@@ -707,8 +725,9 @@ discard block |
||
707 | 725 | } |
708 | 726 | |
709 | 727 | // Default to 10. |
710 | - if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) |
|
711 | - $_REQUEST['viewscount'] = 10; |
|
728 | + if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) { |
|
729 | + $_REQUEST['viewscount'] = 10; |
|
730 | + } |
|
712 | 731 | |
713 | 732 | // Get the count of applicable drafts |
714 | 733 | $request = $smcFunc['db_query']('', ' |
@@ -767,12 +786,14 @@ discard block |
||
767 | 786 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
768 | 787 | { |
769 | 788 | // Censor.... |
770 | - if (empty($row['body'])) |
|
771 | - $row['body'] = ''; |
|
789 | + if (empty($row['body'])) { |
|
790 | + $row['body'] = ''; |
|
791 | + } |
|
772 | 792 | |
773 | 793 | $row['subject'] = $smcFunc['htmltrim']($row['subject']); |
774 | - if (empty($row['subject'])) |
|
775 | - $row['subject'] = $txt['no_subject']; |
|
794 | + if (empty($row['subject'])) { |
|
795 | + $row['subject'] = $txt['no_subject']; |
|
796 | + } |
|
776 | 797 | |
777 | 798 | censorText($row['body']); |
778 | 799 | censorText($row['subject']); |
@@ -827,8 +848,9 @@ discard block |
||
827 | 848 | $smcFunc['db_free_result']($request); |
828 | 849 | |
829 | 850 | // if the drafts were retrieved in reverse order, then put them in the right order again. |
830 | - if ($reverse) |
|
831 | - $context['drafts'] = array_reverse($context['drafts'], true); |
|
851 | + if ($reverse) { |
|
852 | + $context['drafts'] = array_reverse($context['drafts'], true); |
|
853 | + } |
|
832 | 854 | |
833 | 855 | // off to the template we go |
834 | 856 | $context['page_title'] = $txt['drafts']; |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | * |
174 | 174 | * @param string $post_errors A string of info about errors encountered trying to save this draft |
175 | 175 | * @param array $recipientList An array of data about who this PM is being sent to |
176 | - * @return boolean false if you can't save the draft, true if we're doing this via XML more than 5 seconds after the last save, nothing otherwise |
|
176 | + * @return boolean|null false if you can't save the draft, true if we're doing this via XML more than 5 seconds after the last save, nothing otherwise |
|
177 | 177 | */ |
178 | 178 | function SavePMDraft(&$post_errors, $recipientList) |
179 | 179 | { |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | * |
389 | 389 | * @param int $id_draft The ID of the draft to delete |
390 | 390 | * @param boolean $check Whether or not to check that the draft belongs to the current user |
391 | - * @return boolean False if it couldn't be deleted (doesn't return anything otherwise) |
|
391 | + * @return false|null False if it couldn't be deleted (doesn't return anything otherwise) |
|
392 | 392 | */ |
393 | 393 | function DeleteDraft($id_draft, $check = true) |
394 | 394 | { |
@@ -422,7 +422,7 @@ discard block |
||
422 | 422 | * @param int $member_id ID of the member to show drafts for |
423 | 423 | * @param boolean|integer $topic If $type is 1, this can be set to only load drafts for posts in the specific topic |
424 | 424 | * @param int $draft_type The type of drafts to show - 0 for post drafts, 1 for PM drafts |
425 | - * @return boolean False if the drafts couldn't be loaded, nothing otherwise |
|
425 | + * @return false|null False if the drafts couldn't be loaded, nothing otherwise |
|
426 | 426 | */ |
427 | 427 | function ShowDrafts($member_id, $topic = false, $draft_type = 0) |
428 | 428 | { |
@@ -16,8 +16,9 @@ discard block |
||
16 | 16 | |
17 | 17 | // Start things rolling by getting SMF alive... |
18 | 18 | $ssi_guest_access = true; |
19 | -if (!file_exists(dirname(__FILE__) . '/SSI.php')) |
|
19 | +if (!file_exists(dirname(__FILE__) . '/SSI.php')) { |
|
20 | 20 | die('Cannot find SSI.php'); |
21 | +} |
|
21 | 22 | |
22 | 23 | require_once(dirname(__FILE__) . '/SSI.php'); |
23 | 24 | require_once($sourcedir . '/ManagePaid.php'); |
@@ -35,20 +36,22 @@ discard block |
||
35 | 36 | } |
36 | 37 | |
37 | 38 | // I assume we're even active? |
38 | -if (empty($modSettings['paid_enabled'])) |
|
39 | +if (empty($modSettings['paid_enabled'])) { |
|
39 | 40 | exit; |
41 | +} |
|
40 | 42 | |
41 | 43 | // If we have some custom people who find out about problems load them here. |
42 | 44 | $notify_users = array(); |
43 | 45 | if (!empty($modSettings['paid_email_to'])) |
44 | 46 | { |
45 | - foreach (explode(',', $modSettings['paid_email_to']) as $email) |
|
46 | - $notify_users[] = array( |
|
47 | + foreach (explode(',', $modSettings['paid_email_to']) as $email) { |
|
48 | + $notify_users[] = array( |
|
47 | 49 | 'email' => $email, |
48 | 50 | 'name' => $txt['who_member'], |
49 | 51 | 'id' => 0, |
50 | 52 | ); |
51 | -} |
|
53 | + } |
|
54 | + } |
|
52 | 55 | |
53 | 56 | // We need to see whether we can find the correct payment gateway, |
54 | 57 | // we'll going to go through all our gateway scripts and find out |
@@ -65,8 +68,9 @@ discard block |
||
65 | 68 | } |
66 | 69 | } |
67 | 70 | |
68 | -if (empty($txnType)) |
|
71 | +if (empty($txnType)) { |
|
69 | 72 | generateSubscriptionError($txt['paid_unknown_transaction_type']); |
73 | +} |
|
70 | 74 | |
71 | 75 | // Get the subscription and member ID amoungst others... |
72 | 76 | @list($subscription_id, $member_id) = $gatewayClass->precheck(); |
@@ -76,8 +80,9 @@ discard block |
||
76 | 80 | $member_id = (int) $member_id; |
77 | 81 | |
78 | 82 | // This would be bad... |
79 | -if (empty($member_id)) |
|
83 | +if (empty($member_id)) { |
|
80 | 84 | generateSubscriptionError($txt['paid_empty_member']); |
85 | +} |
|
81 | 86 | |
82 | 87 | // Verify the member. |
83 | 88 | $request = $smcFunc['db_query']('', ' |
@@ -89,8 +94,9 @@ discard block |
||
89 | 94 | ) |
90 | 95 | ); |
91 | 96 | // Didn't find them? |
92 | -if ($smcFunc['db_num_rows']($request) === 0) |
|
97 | +if ($smcFunc['db_num_rows']($request) === 0) { |
|
93 | 98 | generateSubscriptionError(sprintf($txt['paid_could_not_find_member'], $member_id)); |
99 | +} |
|
94 | 100 | $member_info = $smcFunc['db_fetch_assoc']($request); |
95 | 101 | $smcFunc['db_free_result']($request); |
96 | 102 | |
@@ -105,8 +111,9 @@ discard block |
||
105 | 111 | ); |
106 | 112 | |
107 | 113 | // Didn't find it? |
108 | -if ($smcFunc['db_num_rows']($request) === 0) |
|
114 | +if ($smcFunc['db_num_rows']($request) === 0) { |
|
109 | 115 | generateSubscriptionError(sprintf($txt['paid_count_not_find_subscription'], $member_id, $subscription_id)); |
116 | +} |
|
110 | 117 | |
111 | 118 | $subscription_info = $smcFunc['db_fetch_assoc']($request); |
112 | 119 | $smcFunc['db_free_result']($request); |
@@ -123,8 +130,9 @@ discard block |
||
123 | 130 | 'current_member' => $member_id, |
124 | 131 | ) |
125 | 132 | ); |
126 | -if ($smcFunc['db_num_rows']($request) === 0) |
|
133 | +if ($smcFunc['db_num_rows']($request) === 0) { |
|
127 | 134 | generateSubscriptionError(sprintf($txt['paid_count_not_find_subscription_log'], $member_id, $subscription_id)); |
135 | +} |
|
128 | 136 | $subscription_info += $smcFunc['db_fetch_assoc']($request); |
129 | 137 | $smcFunc['db_free_result']($request); |
130 | 138 | |
@@ -139,8 +147,7 @@ discard block |
||
139 | 147 | removeSubscription($subscription_id, $member_id); |
140 | 148 | $subscription_act = time(); |
141 | 149 | $status = 0; |
142 | - } |
|
143 | - else |
|
150 | + } else |
|
144 | 151 | { |
145 | 152 | loadSubscriptions(); |
146 | 153 | $subscription_act = $subscription_info['end_time'] - $context['subscriptions'][$subscription_id]['num_length']; |
@@ -188,16 +195,18 @@ discard block |
||
188 | 195 | if (!$gatewayClass->isSubscription()) |
189 | 196 | { |
190 | 197 | $real_details = $smcFunc['json_decode']($subscription_info['pending_details'], true); |
191 | - if (empty($real_details)) |
|
192 | - generateSubscriptionError(sprintf($txt['paid_count_not_find_outstanding_payment'], $member_id, $subscription_id)); |
|
198 | + if (empty($real_details)) { |
|
199 | + generateSubscriptionError(sprintf($txt['paid_count_not_find_outstanding_payment'], $member_id, $subscription_id)); |
|
200 | + } |
|
193 | 201 | |
194 | 202 | // Now we just try to find anything pending. |
195 | 203 | // We don't really care which it is as security happens later. |
196 | 204 | foreach ($real_details as $id => $detail) |
197 | 205 | { |
198 | 206 | unset($real_details[$id]); |
199 | - if ($detail[3] == 'payback' && $subscription_info['payments_pending']) |
|
200 | - $subscription_info['payments_pending']--; |
|
207 | + if ($detail[3] == 'payback' && $subscription_info['payments_pending']) { |
|
208 | + $subscription_info['payments_pending']--; |
|
209 | + } |
|
201 | 210 | break; |
202 | 211 | } |
203 | 212 | |
@@ -223,10 +232,11 @@ discard block |
||
223 | 232 | // This is a little harder, can we find the right duration? |
224 | 233 | foreach ($cost as $duration => $value) |
225 | 234 | { |
226 | - if ($duration == 'fixed') |
|
227 | - continue; |
|
228 | - elseif ((float) $value == (float) $total_cost) |
|
229 | - $found_duration = strtoupper(substr($duration, 0, 1)); |
|
235 | + if ($duration == 'fixed') { |
|
236 | + continue; |
|
237 | + } elseif ((float) $value == (float) $total_cost) { |
|
238 | + $found_duration = strtoupper(substr($duration, 0, 1)); |
|
239 | + } |
|
230 | 240 | } |
231 | 241 | |
232 | 242 | // If we have the duration then we're done. |
@@ -235,8 +245,7 @@ discard block |
||
235 | 245 | $notify = true; |
236 | 246 | addSubscription($subscription_id, $member_id, $found_duration); |
237 | 247 | } |
238 | - } |
|
239 | - else |
|
248 | + } else |
|
240 | 249 | { |
241 | 250 | $actual_cost = $cost['fixed']; |
242 | 251 | |
@@ -268,10 +277,10 @@ discard block |
||
268 | 277 | // Maybe they're cancelling. Some subscriptions may require actively doing something, but PayPal doesn't, for example. |
269 | 278 | elseif ($gatewayClass->isCancellation()) |
270 | 279 | { |
271 | - if (method_exists($gatewayClass, 'performCancel')) |
|
272 | - $gatewayClass->performCancel($subscription_id, $member_id, $subscription_info); |
|
273 | -} |
|
274 | -else |
|
280 | + if (method_exists($gatewayClass, 'performCancel')) { |
|
281 | + $gatewayClass->performCancel($subscription_id, $member_id, $subscription_info); |
|
282 | + } |
|
283 | + } else |
|
275 | 284 | { |
276 | 285 | // Some other "valid" transaction such as: |
277 | 286 | // |
@@ -308,8 +317,9 @@ discard block |
||
308 | 317 | // Maybe we can try to give them the post data? |
309 | 318 | if (!empty($_POST)) |
310 | 319 | { |
311 | - foreach ($_POST as $key => $val) |
|
312 | - $text .= '<br>' . $smcFunc['htmlspecialchars']($key) . ': ' . $smcFunc['htmlspecialchars']($val); |
|
320 | + foreach ($_POST as $key => $val) { |
|
321 | + $text .= '<br>' . $smcFunc['htmlspecialchars']($key) . ': ' . $smcFunc['htmlspecialchars']($val); |
|
322 | + } |
|
313 | 323 | } |
314 | 324 | |
315 | 325 | // Then just log and die. |
@@ -86,7 +86,7 @@ |
||
86 | 86 | foreach ($board['children'] as $child) |
87 | 87 | { |
88 | 88 | if (!$child['is_redirect']) |
89 | - $child['link'] = ''. ($child['new'] ? '<a href="' . $scripturl . '?action=unread;board=' . $child['id'] . '" title="' . $txt['new_posts'] . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')"><span class="new_posts">' . $txt['new'] . '</span></a>' : '') . '<a href="' . $child['href'] . '" ' . ($child['new'] ? 'class="board_new_posts" ' : '') . 'title="' . ($child['new'] ? $txt['new_posts'] : $txt['old_posts']) . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')">' . $child['name'] . '</a>'; |
|
89 | + $child['link'] = '' . ($child['new'] ? '<a href="' . $scripturl . '?action=unread;board=' . $child['id'] . '" title="' . $txt['new_posts'] . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')"><span class="new_posts">' . $txt['new'] . '</span></a>' : '') . '<a href="' . $child['href'] . '" ' . ($child['new'] ? 'class="board_new_posts" ' : '') . 'title="' . ($child['new'] ? $txt['new_posts'] : $txt['old_posts']) . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')">' . $child['name'] . '</a>'; |
|
90 | 90 | else |
91 | 91 | $child['link'] = '<a href="' . $child['href'] . '" title="' . comma_format($child['posts']) . ' ' . $txt['redirects'] . '">' . $child['name'] . '</a>'; |
92 | 92 |
@@ -18,11 +18,12 @@ discard block |
||
18 | 18 | global $context, $settings, $options, $scripturl, $modSettings, $txt; |
19 | 19 | |
20 | 20 | // Let them know why their message became unapproved. |
21 | - if ($context['becomesUnapproved']) |
|
22 | - echo ' |
|
21 | + if ($context['becomesUnapproved']) { |
|
22 | + echo ' |
|
23 | 23 | <div class="noticebox"> |
24 | 24 | ', $txt['post_becomesUnapproved'], ' |
25 | 25 | </div>'; |
26 | + } |
|
26 | 27 | |
27 | 28 | if (!empty($context['boards']) && (!empty($options['show_children']) || $context['start'] == 0)) |
28 | 29 | { |
@@ -46,17 +47,19 @@ discard block |
||
46 | 47 | </a>'; |
47 | 48 | |
48 | 49 | // Has it outstanding posts for approval? |
49 | - if ($board['can_approve_posts'] && ($board['unapproved_posts'] || $board['unapproved_topics'])) |
|
50 | - echo ' |
|
50 | + if ($board['can_approve_posts'] && ($board['unapproved_posts'] || $board['unapproved_topics'])) { |
|
51 | + echo ' |
|
51 | 52 | <a href="', $scripturl, '?action=moderate;area=postmod;sa=', ($board['unapproved_topics'] > 0 ? 'topics' : 'posts'), ';brd=', $board['id'], ';', $context['session_var'], '=', $context['session_id'], '" title="', sprintf($txt['unapproved_posts'], $board['unapproved_topics'], $board['unapproved_posts']), '" class="moderation_link">(!)</a>'; |
53 | + } |
|
52 | 54 | |
53 | 55 | echo ' |
54 | 56 | <p class="board_description">', $board['description'], '</p>'; |
55 | 57 | |
56 | 58 | // Show the "Moderators: ". Each has name, href, link, and id. (but we're gonna use link_moderators.) |
57 | - if (!empty($board['moderators']) || !empty($board['moderator_groups'])) |
|
58 | - echo ' |
|
59 | + if (!empty($board['moderators']) || !empty($board['moderator_groups'])) { |
|
60 | + echo ' |
|
59 | 61 | <p class="moderators">', count($board['link_moderators']) === 1 ? $txt['moderator'] : $txt['moderators'], ': ', implode(', ', $board['link_moderators']), '</p>'; |
62 | + } |
|
60 | 63 | |
61 | 64 | // Show some basic information about the number of posts, etc. |
62 | 65 | echo ' |
@@ -68,9 +71,10 @@ discard block |
||
68 | 71 | </div> |
69 | 72 | <div class="lastpost lpr_border">'; |
70 | 73 | |
71 | - if (!empty($board['last_post']['id'])) |
|
72 | - echo ' |
|
74 | + if (!empty($board['last_post']['id'])) { |
|
75 | + echo ' |
|
73 | 76 | <p>', $board['last_post']['last_post_message'], '</p>'; |
77 | + } |
|
74 | 78 | |
75 | 79 | echo ' |
76 | 80 | </div>'; |
@@ -84,14 +88,16 @@ discard block |
||
84 | 88 | id, name, description, new (is it new?), topics (#), posts (#), href, link, and last_post. */ |
85 | 89 | foreach ($board['children'] as $child) |
86 | 90 | { |
87 | - if (!$child['is_redirect']) |
|
88 | - $child['link'] = ''. ($child['new'] ? '<a href="' . $scripturl . '?action=unread;board=' . $child['id'] . '" title="' . $txt['new_posts'] . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')"><span class="new_posts">' . $txt['new'] . '</span></a>' : '') . '<a href="' . $child['href'] . '" ' . ($child['new'] ? 'class="board_new_posts" ' : '') . 'title="' . ($child['new'] ? $txt['new_posts'] : $txt['old_posts']) . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')">' . $child['name'] . '</a>'; |
|
89 | - else |
|
90 | - $child['link'] = '<a href="' . $child['href'] . '" title="' . comma_format($child['posts']) . ' ' . $txt['redirects'] . '">' . $child['name'] . '</a>'; |
|
91 | + if (!$child['is_redirect']) { |
|
92 | + $child['link'] = ''. ($child['new'] ? '<a href="' . $scripturl . '?action=unread;board=' . $child['id'] . '" title="' . $txt['new_posts'] . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')"><span class="new_posts">' . $txt['new'] . '</span></a>' : '') . '<a href="' . $child['href'] . '" ' . ($child['new'] ? 'class="board_new_posts" ' : '') . 'title="' . ($child['new'] ? $txt['new_posts'] : $txt['old_posts']) . ' (' . $txt['board_topics'] . ': ' . comma_format($child['topics']) . ', ' . $txt['posts'] . ': ' . comma_format($child['posts']) . ')">' . $child['name'] . '</a>'; |
|
93 | + } else { |
|
94 | + $child['link'] = '<a href="' . $child['href'] . '" title="' . comma_format($child['posts']) . ' ' . $txt['redirects'] . '">' . $child['name'] . '</a>'; |
|
95 | + } |
|
91 | 96 | |
92 | 97 | // Has it posts awaiting approval? |
93 | - if ($child['can_approve_posts'] && ($child['unapproved_posts'] | $child['unapproved_topics'])) |
|
94 | - $child['link'] .= ' <a href="' . $scripturl . '?action=moderate;area=postmod;sa=' . ($child['unapproved_topics'] > 0 ? 'topics' : 'posts') . ';brd=' . $child['id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '" title="' . sprintf($txt['unapproved_posts'], $child['unapproved_topics'], $child['unapproved_posts']) . '" class="moderation_link">(!)</a>'; |
|
98 | + if ($child['can_approve_posts'] && ($child['unapproved_posts'] | $child['unapproved_topics'])) { |
|
99 | + $child['link'] .= ' <a href="' . $scripturl . '?action=moderate;area=postmod;sa=' . ($child['unapproved_topics'] > 0 ? 'topics' : 'posts') . ';brd=' . $child['id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '" title="' . sprintf($txt['unapproved_posts'], $child['unapproved_topics'], $child['unapproved_posts']) . '" class="moderation_link">(!)</a>'; |
|
100 | + } |
|
95 | 101 | |
96 | 102 | $children[] = $child['new'] ? '<span class="strong">' . $child['link'] . '</span>' : '<span>' . $child['link'] . '</span>'; |
97 | 103 | } |
@@ -111,8 +117,9 @@ discard block |
||
111 | 117 | } |
112 | 118 | |
113 | 119 | // They can only mark read if they are logged in and it's enabled! |
114 | - if (!$context['user']['is_logged']) |
|
115 | - unset($context['normal_buttons']['markread']); |
|
120 | + if (!$context['user']['is_logged']) { |
|
121 | + unset($context['normal_buttons']['markread']); |
|
122 | + } |
|
116 | 123 | |
117 | 124 | if (!$context['no_topic_listing']) |
118 | 125 | { |
@@ -139,13 +146,15 @@ discard block |
||
139 | 146 | <h3>', $context['name'], '</h3> |
140 | 147 | <p>'; |
141 | 148 | |
142 | - if ($context['description'] != '') |
|
143 | - echo ' |
|
149 | + if ($context['description'] != '') { |
|
150 | + echo ' |
|
144 | 151 | ', $context['description']; |
152 | + } |
|
145 | 153 | |
146 | - if (!empty($context['moderators'])) |
|
147 | - echo ' |
|
154 | + if (!empty($context['moderators'])) { |
|
155 | + echo ' |
|
148 | 156 | ', count($context['moderators']) === 1 ? $txt['moderator'] : $txt['moderators'], ': ', implode(', ', $context['link_moderators']), '.'; |
157 | + } |
|
149 | 158 | |
150 | 159 | echo ' |
151 | 160 | </p> |
@@ -153,9 +162,10 @@ discard block |
||
153 | 162 | } |
154 | 163 | |
155 | 164 | // If Quick Moderation is enabled start the form. |
156 | - if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] > 0 && !empty($context['topics'])) |
|
157 | - echo ' |
|
165 | + if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] > 0 && !empty($context['topics'])) { |
|
166 | + echo ' |
|
158 | 167 | <form action="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], '" method="post" accept-charset="', $context['character_set'], '" class="clear" name="quickModForm" id="quickModForm">'; |
168 | + } |
|
159 | 169 | |
160 | 170 | echo ' |
161 | 171 | <div id="messageindex">'; |
@@ -165,11 +175,11 @@ discard block |
||
165 | 175 | echo ' |
166 | 176 | <div class="information">'; |
167 | 177 | |
168 | - if ($settings['display_who_viewing'] == 1) |
|
169 | - echo count($context['view_members']), ' ', count($context['view_members']) === 1 ? $txt['who_member'] : $txt['members']; |
|
170 | - |
|
171 | - else |
|
172 | - echo empty($context['view_members_list']) ? '0 ' . $txt['members'] : implode(', ', $context['view_members_list']) . (empty($context['view_num_hidden']) || $context['can_moderate_forum'] ? '' : ' (+ ' . $context['view_num_hidden'] . ' ' . $txt['hidden'] . ')'); |
|
178 | + if ($settings['display_who_viewing'] == 1) { |
|
179 | + echo count($context['view_members']), ' ', count($context['view_members']) === 1 ? $txt['who_member'] : $txt['members']; |
|
180 | + } else { |
|
181 | + echo empty($context['view_members_list']) ? '0 ' . $txt['members'] : implode(', ', $context['view_members_list']) . (empty($context['view_num_hidden']) || $context['can_moderate_forum'] ? '' : ' (+ ' . $context['view_num_hidden'] . ' ' . $txt['hidden'] . ')'); |
|
182 | + } |
|
173 | 183 | echo $txt['who_and'], $context['view_num_guests'], ' ', $context['view_num_guests'] == 1 ? $txt['guest'] : $txt['guests'], $txt['who_viewing_board']; |
174 | 184 | |
175 | 185 | echo ' |
@@ -189,32 +199,36 @@ discard block |
||
189 | 199 | <div class="lastpost">', $context['topics_headers']['last_post'], '</div>'; |
190 | 200 | |
191 | 201 | // Show a "select all" box for quick moderation? |
192 | - if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] == 1) |
|
193 | - echo ' |
|
202 | + if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] == 1) { |
|
203 | + echo ' |
|
194 | 204 | <div class="moderation"> |
195 | 205 | <input type="checkbox" onclick="invertAll(this, this.form, \'topics[]\');"> |
196 | 206 | </div>'; |
207 | + } |
|
197 | 208 | |
198 | 209 | // If it's on in "image" mode, don't show anything but the column. |
199 | - elseif (!empty($context['can_quick_mod'])) |
|
200 | - echo ' |
|
210 | + elseif (!empty($context['can_quick_mod'])) { |
|
211 | + echo ' |
|
201 | 212 | <div class="moderation"></div>'; |
213 | + } |
|
202 | 214 | } |
203 | 215 | |
204 | 216 | // No topics... just say, "sorry bub". |
205 | - else |
|
206 | - echo ' |
|
217 | + else { |
|
218 | + echo ' |
|
207 | 219 | <h3 class="titlebg">', $txt['topic_alert_none'], '</h3>'; |
220 | + } |
|
208 | 221 | |
209 | 222 | echo ' |
210 | 223 | </div><!-- #topic_header -->'; |
211 | 224 | |
212 | 225 | // If this person can approve items and we have some awaiting approval tell them. |
213 | - if (!empty($context['unapproved_posts_message'])) |
|
214 | - echo ' |
|
226 | + if (!empty($context['unapproved_posts_message'])) { |
|
227 | + echo ' |
|
215 | 228 | <div class="information"> |
216 | 229 | <span class="alert">!</span> ', $context['unapproved_posts_message'], ' |
217 | 230 | </div>'; |
231 | + } |
|
218 | 232 | |
219 | 233 | // Contain the topic list |
220 | 234 | echo ' |
@@ -235,25 +249,30 @@ discard block |
||
235 | 249 | echo ' |
236 | 250 | <div class="icons floatright">'; |
237 | 251 | |
238 | - if ($topic['is_watched']) |
|
239 | - echo ' |
|
252 | + if ($topic['is_watched']) { |
|
253 | + echo ' |
|
240 | 254 | <span class="generic_icons watch" title="', $txt['watching_this_topic'], '"></span>'; |
255 | + } |
|
241 | 256 | |
242 | - if ($topic['is_locked']) |
|
243 | - echo ' |
|
257 | + if ($topic['is_locked']) { |
|
258 | + echo ' |
|
244 | 259 | <span class="generic_icons lock"></span>'; |
260 | + } |
|
245 | 261 | |
246 | - if ($topic['is_sticky']) |
|
247 | - echo ' |
|
262 | + if ($topic['is_sticky']) { |
|
263 | + echo ' |
|
248 | 264 | <span class="generic_icons sticky"></span>'; |
265 | + } |
|
249 | 266 | |
250 | - if ($topic['is_redirect']) |
|
251 | - echo ' |
|
267 | + if ($topic['is_redirect']) { |
|
268 | + echo ' |
|
252 | 269 | <span class="generic_icons move"></span>'; |
270 | + } |
|
253 | 271 | |
254 | - if ($topic['is_poll']) |
|
255 | - echo ' |
|
272 | + if ($topic['is_poll']) { |
|
273 | + echo ' |
|
256 | 274 | <span class="generic_icons poll"></span>'; |
275 | + } |
|
257 | 276 | |
258 | 277 | echo ' |
259 | 278 | </div>'; |
@@ -285,26 +304,31 @@ discard block |
||
285 | 304 | echo ' |
286 | 305 | <div class="moderation">'; |
287 | 306 | |
288 | - if ($options['display_quick_mod'] == 1) |
|
289 | - echo ' |
|
307 | + if ($options['display_quick_mod'] == 1) { |
|
308 | + echo ' |
|
290 | 309 | <input type="checkbox" name="topics[]" value="', $topic['id'], '">'; |
291 | - else |
|
310 | + } else |
|
292 | 311 | { |
293 | 312 | // Check permissions on each and show only the ones they are allowed to use. |
294 | - if ($topic['quick_mod']['remove']) |
|
295 | - echo '<a href="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], ';actions%5B', $topic['id'], '%5D=remove;', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons delete" title="', $txt['remove_topic'], '"></span></a>'; |
|
313 | + if ($topic['quick_mod']['remove']) { |
|
314 | + echo '<a href="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], ';actions%5B', $topic['id'], '%5D=remove;', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons delete" title="', $txt['remove_topic'], '"></span></a>'; |
|
315 | + } |
|
296 | 316 | |
297 | - if ($topic['quick_mod']['lock']) |
|
298 | - echo '<a href="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], ';actions%5B', $topic['id'], '%5D=lock;', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons lock" title="', $topic['is_locked'] ? $txt['set_unlock'] : $txt['set_lock'], '"></span></a>'; |
|
317 | + if ($topic['quick_mod']['lock']) { |
|
318 | + echo '<a href="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], ';actions%5B', $topic['id'], '%5D=lock;', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons lock" title="', $topic['is_locked'] ? $txt['set_unlock'] : $txt['set_lock'], '"></span></a>'; |
|
319 | + } |
|
299 | 320 | |
300 | - if ($topic['quick_mod']['lock'] || $topic['quick_mod']['remove']) |
|
301 | - echo '<br>'; |
|
321 | + if ($topic['quick_mod']['lock'] || $topic['quick_mod']['remove']) { |
|
322 | + echo '<br>'; |
|
323 | + } |
|
302 | 324 | |
303 | - if ($topic['quick_mod']['sticky']) |
|
304 | - echo '<a href="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], ';actions%5B', $topic['id'], '%5D=sticky;', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons sticky" title="', $topic['is_sticky'] ? $txt['set_nonsticky'] : $txt['set_sticky'], '"></span></a>'; |
|
325 | + if ($topic['quick_mod']['sticky']) { |
|
326 | + echo '<a href="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], ';actions%5B', $topic['id'], '%5D=sticky;', $context['session_var'], '=', $context['session_id'], '" class="you_sure"><span class="generic_icons sticky" title="', $topic['is_sticky'] ? $txt['set_nonsticky'] : $txt['set_sticky'], '"></span></a>'; |
|
327 | + } |
|
305 | 328 | |
306 | - if ($topic['quick_mod']['move']) |
|
307 | - echo '<a href="', $scripturl, '?action=movetopic;current_board=', $context['current_board'], ';board=', $context['current_board'], '.', $context['start'], ';topic=', $topic['id'], '.0"><span class="generic_icons move" title="', $txt['move_topic'], '"></span></a>'; |
|
329 | + if ($topic['quick_mod']['move']) { |
|
330 | + echo '<a href="', $scripturl, '?action=movetopic;current_board=', $context['current_board'], ';board=', $context['current_board'], '.', $context['start'], ';topic=', $topic['id'], '.0"><span class="generic_icons move" title="', $txt['move_topic'], '"></span></a>'; |
|
331 | + } |
|
308 | 332 | } |
309 | 333 | echo ' |
310 | 334 | </div><!-- .moderation -->'; |
@@ -322,18 +346,20 @@ discard block |
||
322 | 346 | <select class="qaction" name="qaction"', $context['can_move'] ? ' onchange="this.form.move_to.disabled = (this.options[this.selectedIndex].value != \'move\');"' : '', '> |
323 | 347 | <option value="">--------</option>'; |
324 | 348 | |
325 | - foreach ($context['qmod_actions'] as $qmod_action) |
|
326 | - if ($context['can_' . $qmod_action]) |
|
349 | + foreach ($context['qmod_actions'] as $qmod_action) { |
|
350 | + if ($context['can_' . $qmod_action]) |
|
327 | 351 | echo ' |
328 | 352 | <option value="' . $qmod_action . '">' . $txt['quick_mod_' . $qmod_action] . '</option>'; |
353 | + } |
|
329 | 354 | |
330 | 355 | echo ' |
331 | 356 | </select>'; |
332 | 357 | |
333 | 358 | // Show a list of boards they can move the topic to. |
334 | - if ($context['can_move']) |
|
335 | - echo ' |
|
359 | + if ($context['can_move']) { |
|
360 | + echo ' |
|
336 | 361 | <span id="quick_mod_jump_to"></span>'; |
362 | + } |
|
337 | 363 | |
338 | 364 | echo ' |
339 | 365 | <input type="submit" value="', $txt['quick_mod_go'], '" onclick="return document.forms.quickModForm.qaction.value != \'\' && confirm(\'', $txt['quickmod_confirm'], '\');" class="button qaction"> |
@@ -344,10 +370,11 @@ discard block |
||
344 | 370 | </div><!-- #messageindex -->'; |
345 | 371 | |
346 | 372 | // Finish off the form - again. |
347 | - if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] > 0 && !empty($context['topics'])) |
|
348 | - echo ' |
|
373 | + if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] > 0 && !empty($context['topics'])) { |
|
374 | + echo ' |
|
349 | 375 | <input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '"> |
350 | 376 | </form>'; |
377 | + } |
|
351 | 378 | |
352 | 379 | // Mobile action buttons (bottom) |
353 | 380 | echo ' |
@@ -369,8 +396,8 @@ discard block |
||
369 | 396 | // Show breadcrumbs at the bottom too. |
370 | 397 | theme_linktree(); |
371 | 398 | |
372 | - if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] == 1 && !empty($context['topics']) && $context['can_move']) |
|
373 | - echo ' |
|
399 | + if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] == 1 && !empty($context['topics']) && $context['can_move']) { |
|
400 | + echo ' |
|
374 | 401 | <script> |
375 | 402 | if (typeof(window.XMLHttpRequest) != "undefined") |
376 | 403 | aJumpTo[aJumpTo.length] = new JumpTo({ |
@@ -389,6 +416,7 @@ discard block |
||
389 | 416 | sCustomName: "move_to" |
390 | 417 | }); |
391 | 418 | </script>'; |
419 | + } |
|
392 | 420 | |
393 | 421 | // Javascript for inline editing. |
394 | 422 | echo ' |
@@ -425,8 +453,8 @@ discard block |
||
425 | 453 | <div class="information"> |
426 | 454 | <p class="floatright" id="message_index_jump_to"></p>'; |
427 | 455 | |
428 | - if (empty($context['no_topic_listing'])) |
|
429 | - echo ' |
|
456 | + if (empty($context['no_topic_listing'])) { |
|
457 | + echo ' |
|
430 | 458 | <p class="floatleft">', !empty($modSettings['enableParticipation']) && $context['user']['is_logged'] ? ' |
431 | 459 | <img src="' . $settings['images_url'] . '/icons/profile_sm.png" alt="" class="centericon"> ' . $txt['participation_caption'] . '<br>' : '', ' |
432 | 460 | '. ($modSettings['pollMode'] == '1' ? '<span class="generic_icons poll centericon"></span> ' . $txt['poll'] : '') . '<br> |
@@ -436,9 +464,10 @@ discard block |
||
436 | 464 | <span class="generic_icons lock centericon"></span> ' . $txt['locked_topic'] . '<br> |
437 | 465 | <span class="generic_icons sticky centericon"></span> ' . $txt['sticky_topic'] . '<br> |
438 | 466 | </p>'; |
467 | + } |
|
439 | 468 | |
440 | - if (!empty($context['jump_to'])) |
|
441 | - echo ' |
|
469 | + if (!empty($context['jump_to'])) { |
|
470 | + echo ' |
|
442 | 471 | <script> |
443 | 472 | if (typeof(window.XMLHttpRequest) != "undefined") |
444 | 473 | aJumpTo[aJumpTo.length] = new JumpTo({ |
@@ -454,6 +483,7 @@ discard block |
||
454 | 483 | sGoButtonLabel: "', $txt['quick_mod_go'], '" |
455 | 484 | }); |
456 | 485 | </script>'; |
486 | + } |
|
457 | 487 | |
458 | 488 | echo ' |
459 | 489 | <br class="clear"> |
@@ -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 dispatcher; doesn't do anything, just delegates. |
@@ -92,18 +93,19 @@ discard block |
||
92 | 93 | checkSession('get'); |
93 | 94 | validateToken('admin-bm-' . (int) $_REQUEST['src_board'], 'request'); |
94 | 95 | |
95 | - if ($_REQUEST['move_to'] === 'top') |
|
96 | - $boardOptions = array( |
|
96 | + if ($_REQUEST['move_to'] === 'top') { |
|
97 | + $boardOptions = array( |
|
97 | 98 | 'move_to' => $_REQUEST['move_to'], |
98 | 99 | 'target_category' => (int) $_REQUEST['target_cat'], |
99 | 100 | 'move_first_child' => true, |
100 | 101 | ); |
101 | - else |
|
102 | - $boardOptions = array( |
|
102 | + } else { |
|
103 | + $boardOptions = array( |
|
103 | 104 | 'move_to' => $_REQUEST['move_to'], |
104 | 105 | 'target_board' => (int) $_REQUEST['target_board'], |
105 | 106 | 'move_first_child' => true, |
106 | 107 | ); |
108 | + } |
|
107 | 109 | modifyBoard((int) $_REQUEST['src_board'], $boardOptions); |
108 | 110 | } |
109 | 111 | |
@@ -148,15 +150,16 @@ discard block |
||
148 | 150 | $security = $context['session_var'] . '=' . $context['session_id'] . ';' . $context['admin-bm-' . $context['move_board'] . '_token_var'] . '=' . $context['admin-bm-' . $context['move_board'] . '_token']; |
149 | 151 | foreach ($boardList[$catid] as $boardid) |
150 | 152 | { |
151 | - if (!isset($context['categories'][$catid]['move_link'])) |
|
152 | - $context['categories'][$catid]['move_link'] = array( |
|
153 | + if (!isset($context['categories'][$catid]['move_link'])) { |
|
154 | + $context['categories'][$catid]['move_link'] = array( |
|
153 | 155 | 'child_level' => 0, |
154 | 156 | 'label' => $txt['mboards_order_before'] . ' \'' . $smcFunc['htmlspecialchars']($boards[$boardid]['name']) . '\'', |
155 | 157 | 'href' => $scripturl . '?action=admin;area=manageboards;sa=move;src_board=' . $context['move_board'] . ';target_board=' . $boardid . ';move_to=before;' . $security, |
156 | 158 | ); |
159 | + } |
|
157 | 160 | |
158 | - if (!$context['categories'][$catid]['boards'][$boardid]['move']) |
|
159 | - $context['categories'][$catid]['boards'][$boardid]['move_links'] = array( |
|
161 | + if (!$context['categories'][$catid]['boards'][$boardid]['move']) { |
|
162 | + $context['categories'][$catid]['boards'][$boardid]['move_links'] = array( |
|
160 | 163 | array( |
161 | 164 | 'child_level' => $boards[$boardid]['level'], |
162 | 165 | 'label' => $txt['mboards_order_after'] . '\'' . $smcFunc['htmlspecialchars']($boards[$boardid]['name']) . '\'', |
@@ -170,34 +173,39 @@ discard block |
||
170 | 173 | 'class' => 'here', |
171 | 174 | ), |
172 | 175 | ); |
176 | + } |
|
173 | 177 | |
174 | 178 | $difference = $boards[$boardid]['level'] - $prev_child_level; |
175 | - if ($difference == 1) |
|
176 | - array_push($stack, !empty($context['categories'][$catid]['boards'][$prev_board]['move_links']) ? array_shift($context['categories'][$catid]['boards'][$prev_board]['move_links']) : null); |
|
177 | - elseif ($difference < 0) |
|
179 | + if ($difference == 1) { |
|
180 | + array_push($stack, !empty($context['categories'][$catid]['boards'][$prev_board]['move_links']) ? array_shift($context['categories'][$catid]['boards'][$prev_board]['move_links']) : null); |
|
181 | + } elseif ($difference < 0) |
|
178 | 182 | { |
179 | - if (empty($context['categories'][$catid]['boards'][$prev_board]['move_links'])) |
|
180 | - $context['categories'][$catid]['boards'][$prev_board]['move_links'] = array(); |
|
181 | - for ($i = 0; $i < -$difference; $i++) |
|
182 | - if (($temp = array_pop($stack)) != null) |
|
183 | + if (empty($context['categories'][$catid]['boards'][$prev_board]['move_links'])) { |
|
184 | + $context['categories'][$catid]['boards'][$prev_board]['move_links'] = array(); |
|
185 | + } |
|
186 | + for ($i = 0; $i < -$difference; $i++) { |
|
187 | + if (($temp = array_pop($stack)) != null) |
|
183 | 188 | array_unshift($context['categories'][$catid]['boards'][$prev_board]['move_links'], $temp); |
189 | + } |
|
184 | 190 | } |
185 | 191 | |
186 | 192 | $prev_board = $boardid; |
187 | 193 | $prev_child_level = $boards[$boardid]['level']; |
188 | 194 | |
189 | 195 | } |
190 | - if (!empty($stack) && !empty($context['categories'][$catid]['boards'][$prev_board]['move_links'])) |
|
191 | - $context['categories'][$catid]['boards'][$prev_board]['move_links'] = array_merge($stack, $context['categories'][$catid]['boards'][$prev_board]['move_links']); |
|
192 | - elseif (!empty($stack)) |
|
193 | - $context['categories'][$catid]['boards'][$prev_board]['move_links'] = $stack; |
|
196 | + if (!empty($stack) && !empty($context['categories'][$catid]['boards'][$prev_board]['move_links'])) { |
|
197 | + $context['categories'][$catid]['boards'][$prev_board]['move_links'] = array_merge($stack, $context['categories'][$catid]['boards'][$prev_board]['move_links']); |
|
198 | + } elseif (!empty($stack)) { |
|
199 | + $context['categories'][$catid]['boards'][$prev_board]['move_links'] = $stack; |
|
200 | + } |
|
194 | 201 | |
195 | - if (empty($boardList[$catid])) |
|
196 | - $context['categories'][$catid]['move_link'] = array( |
|
202 | + if (empty($boardList[$catid])) { |
|
203 | + $context['categories'][$catid]['move_link'] = array( |
|
197 | 204 | 'child_level' => 0, |
198 | 205 | 'label' => $txt['mboards_order_before'] . ' \'' . $smcFunc['htmlspecialchars']($tree['node']['name']) . '\'', |
199 | 206 | 'href' => $scripturl . '?action=admin;area=manageboards;sa=move;src_board=' . $context['move_board'] . ';target_cat=' . $catid . ';move_to=top;' . $security, |
200 | 207 | ); |
208 | + } |
|
201 | 209 | } |
202 | 210 | } |
203 | 211 | |
@@ -253,9 +261,9 @@ discard block |
||
253 | 261 | ); |
254 | 262 | } |
255 | 263 | // Category doesn't exist, man... sorry. |
256 | - elseif (!isset($cat_tree[$_REQUEST['cat']])) |
|
257 | - redirectexit('action=admin;area=manageboards'); |
|
258 | - else |
|
264 | + elseif (!isset($cat_tree[$_REQUEST['cat']])) { |
|
265 | + redirectexit('action=admin;area=manageboards'); |
|
266 | + } else |
|
259 | 267 | { |
260 | 268 | $context['category'] = array( |
261 | 269 | 'id' => $_REQUEST['cat'], |
@@ -267,30 +275,31 @@ discard block |
||
267 | 275 | 'is_empty' => empty($cat_tree[$_REQUEST['cat']]['children']) |
268 | 276 | ); |
269 | 277 | |
270 | - foreach ($boardList[$_REQUEST['cat']] as $child_board) |
|
271 | - $context['category']['children'][] = str_repeat('-', $boards[$child_board]['level']) . ' ' . $boards[$child_board]['name']; |
|
278 | + foreach ($boardList[$_REQUEST['cat']] as $child_board) { |
|
279 | + $context['category']['children'][] = str_repeat('-', $boards[$child_board]['level']) . ' ' . $boards[$child_board]['name']; |
|
280 | + } |
|
272 | 281 | } |
273 | 282 | |
274 | 283 | $prevCat = 0; |
275 | 284 | foreach ($cat_tree as $catid => $tree) |
276 | 285 | { |
277 | - if ($catid == $_REQUEST['cat'] && $prevCat > 0) |
|
278 | - $context['category_order'][$prevCat]['selected'] = true; |
|
279 | - elseif ($catid != $_REQUEST['cat']) |
|
280 | - $context['category_order'][$catid] = array( |
|
286 | + if ($catid == $_REQUEST['cat'] && $prevCat > 0) { |
|
287 | + $context['category_order'][$prevCat]['selected'] = true; |
|
288 | + } elseif ($catid != $_REQUEST['cat']) { |
|
289 | + $context['category_order'][$catid] = array( |
|
281 | 290 | 'id' => $catid, |
282 | 291 | 'name' => $txt['mboards_order_after'] . $tree['node']['name'], |
283 | 292 | 'selected' => false, |
284 | 293 | 'true_name' => $tree['node']['name'] |
285 | 294 | ); |
295 | + } |
|
286 | 296 | $prevCat = $catid; |
287 | 297 | } |
288 | 298 | if (!isset($_REQUEST['delete'])) |
289 | 299 | { |
290 | 300 | $context['sub_template'] = 'modify_category'; |
291 | 301 | $context['page_title'] = $_REQUEST['sa'] == 'newcat' ? $txt['mboards_new_cat_name'] : $txt['catEdit']; |
292 | - } |
|
293 | - else |
|
302 | + } else |
|
294 | 303 | { |
295 | 304 | $context['sub_template'] = 'confirm_category_delete'; |
296 | 305 | $context['page_title'] = $txt['mboards_delete_cat']; |
@@ -327,8 +336,9 @@ discard block |
||
327 | 336 | { |
328 | 337 | $catOptions = array(); |
329 | 338 | |
330 | - if (isset($_POST['cat_order'])) |
|
331 | - $catOptions['move_after'] = (int) $_POST['cat_order']; |
|
339 | + if (isset($_POST['cat_order'])) { |
|
340 | + $catOptions['move_after'] = (int) $_POST['cat_order']; |
|
341 | + } |
|
332 | 342 | |
333 | 343 | // Change "This & That" to "This & That" but don't change "¢" to "&cent;"... |
334 | 344 | $catOptions['cat_name'] = parse_bbc($smcFunc['htmlspecialchars']($_POST['cat_name']), false, '', $context['description_allowed_tags']); |
@@ -336,10 +346,11 @@ discard block |
||
336 | 346 | |
337 | 347 | $catOptions['is_collapsible'] = isset($_POST['collapse']); |
338 | 348 | |
339 | - if (isset($_POST['add'])) |
|
340 | - createCategory($catOptions); |
|
341 | - else |
|
342 | - modifyCategory($_POST['cat'], $catOptions); |
|
349 | + if (isset($_POST['add'])) { |
|
350 | + createCategory($catOptions); |
|
351 | + } else { |
|
352 | + modifyCategory($_POST['cat'], $catOptions); |
|
353 | + } |
|
343 | 354 | } |
344 | 355 | // If they want to delete - first give them confirmation. |
345 | 356 | elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['empty'])) |
@@ -353,13 +364,14 @@ discard block |
||
353 | 364 | // First off - check if we are moving all the current boards first - before we start deleting! |
354 | 365 | if (isset($_POST['delete_action']) && $_POST['delete_action'] == 1) |
355 | 366 | { |
356 | - if (empty($_POST['cat_to'])) |
|
357 | - fatal_lang_error('mboards_delete_error'); |
|
367 | + if (empty($_POST['cat_to'])) { |
|
368 | + fatal_lang_error('mboards_delete_error'); |
|
369 | + } |
|
358 | 370 | |
359 | 371 | deleteCategories(array($_POST['cat']), (int) $_POST['cat_to']); |
372 | + } else { |
|
373 | + deleteCategories(array($_POST['cat'])); |
|
360 | 374 | } |
361 | - else |
|
362 | - deleteCategories(array($_POST['cat'])); |
|
363 | 375 | } |
364 | 376 | |
365 | 377 | redirectexit('action=admin;area=manageboards'); |
@@ -404,8 +416,9 @@ discard block |
||
404 | 416 | if ($_REQUEST['sa'] == 'newboard') |
405 | 417 | { |
406 | 418 | // Category doesn't exist, man... sorry. |
407 | - if (empty($_REQUEST['cat'])) |
|
408 | - redirectexit('action=admin;area=manageboards'); |
|
419 | + if (empty($_REQUEST['cat'])) { |
|
420 | + redirectexit('action=admin;area=manageboards'); |
|
421 | + } |
|
409 | 422 | |
410 | 423 | // Some things that need to be setup for a new board. |
411 | 424 | $curBoard = array( |
@@ -429,8 +442,7 @@ discard block |
||
429 | 442 | 'category' => (int) $_REQUEST['cat'], |
430 | 443 | 'no_children' => true, |
431 | 444 | ); |
432 | - } |
|
433 | - else |
|
445 | + } else |
|
434 | 446 | { |
435 | 447 | // Just some easy shortcuts. |
436 | 448 | $curBoard = &$boards[$_REQUEST['boardid']]; |
@@ -478,8 +490,9 @@ discard block |
||
478 | 490 | ); |
479 | 491 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
480 | 492 | { |
481 | - if ($_REQUEST['sa'] == 'newboard' && $row['min_posts'] == -1) |
|
482 | - $curBoard['member_groups'][] = $row['id_group']; |
|
493 | + if ($_REQUEST['sa'] == 'newboard' && $row['min_posts'] == -1) { |
|
494 | + $curBoard['member_groups'][] = $row['id_group']; |
|
495 | + } |
|
483 | 496 | |
484 | 497 | $context['groups'][(int) $row['id_group']] = array( |
485 | 498 | 'id' => $row['id_group'], |
@@ -492,8 +505,9 @@ discard block |
||
492 | 505 | $smcFunc['db_free_result']($request); |
493 | 506 | |
494 | 507 | // Category doesn't exist, man... sorry. |
495 | - if (!isset($boardList[$curBoard['category']])) |
|
496 | - redirectexit('action=admin;area=manageboards'); |
|
508 | + if (!isset($boardList[$curBoard['category']])) { |
|
509 | + redirectexit('action=admin;area=manageboards'); |
|
510 | + } |
|
497 | 511 | |
498 | 512 | foreach ($boardList[$curBoard['category']] as $boardid) |
499 | 513 | { |
@@ -507,8 +521,7 @@ discard block |
||
507 | 521 | 'is_child' => false, |
508 | 522 | 'selected' => true |
509 | 523 | ); |
510 | - } |
|
511 | - else |
|
524 | + } else |
|
512 | 525 | { |
513 | 526 | $context['board_order'][] = array( |
514 | 527 | 'id' => $boardid, |
@@ -525,19 +538,21 @@ discard block |
||
525 | 538 | $context['can_move_children'] = false; |
526 | 539 | $context['children'] = $boards[$_REQUEST['boardid']]['tree']['children']; |
527 | 540 | |
528 | - foreach ($context['board_order'] as $lBoard) |
|
529 | - if ($lBoard['is_child'] == false && $lBoard['selected'] == false) |
|
541 | + foreach ($context['board_order'] as $lBoard) { |
|
542 | + if ($lBoard['is_child'] == false && $lBoard['selected'] == false) |
|
530 | 543 | $context['can_move_children'] = true; |
544 | + } |
|
531 | 545 | } |
532 | 546 | |
533 | 547 | // Get other available categories. |
534 | 548 | $context['categories'] = array(); |
535 | - foreach ($cat_tree as $catID => $tree) |
|
536 | - $context['categories'][] = array( |
|
549 | + foreach ($cat_tree as $catID => $tree) { |
|
550 | + $context['categories'][] = array( |
|
537 | 551 | 'id' => $catID == $curBoard['category'] ? 0 : $catID, |
538 | 552 | 'name' => $tree['node']['name'], |
539 | 553 | 'selected' => $catID == $curBoard['category'] |
540 | 554 | ); |
555 | + } |
|
541 | 556 | |
542 | 557 | $request = $smcFunc['db_query']('', ' |
543 | 558 | SELECT mem.id_member, mem.real_name |
@@ -549,14 +564,16 @@ discard block |
||
549 | 564 | ) |
550 | 565 | ); |
551 | 566 | $context['board']['moderators'] = array(); |
552 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
553 | - $context['board']['moderators'][$row['id_member']] = $row['real_name']; |
|
567 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
568 | + $context['board']['moderators'][$row['id_member']] = $row['real_name']; |
|
569 | + } |
|
554 | 570 | $smcFunc['db_free_result']($request); |
555 | 571 | |
556 | 572 | $context['board']['moderator_list'] = empty($context['board']['moderators']) ? '' : '"' . implode('", "', $context['board']['moderators']) . '"'; |
557 | 573 | |
558 | - if (!empty($context['board']['moderators'])) |
|
559 | - list ($context['board']['last_moderator_id']) = array_slice(array_keys($context['board']['moderators']), -1); |
|
574 | + if (!empty($context['board']['moderators'])) { |
|
575 | + list ($context['board']['last_moderator_id']) = array_slice(array_keys($context['board']['moderators']), -1); |
|
576 | + } |
|
560 | 577 | |
561 | 578 | // Get all the groups assigned as moderators |
562 | 579 | $request = $smcFunc['db_query']('', ' |
@@ -568,14 +585,16 @@ discard block |
||
568 | 585 | ) |
569 | 586 | ); |
570 | 587 | $context['board']['moderator_groups'] = array(); |
571 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
572 | - $context['board']['moderator_groups'][$row['id_group']] = $context['groups'][$row['id_group']]['name']; |
|
588 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
589 | + $context['board']['moderator_groups'][$row['id_group']] = $context['groups'][$row['id_group']]['name']; |
|
590 | + } |
|
573 | 591 | $smcFunc['db_free_result']($request); |
574 | 592 | |
575 | 593 | $context['board']['moderator_groups_list'] = empty($context['board']['moderator_groups']) ? '' : '"' . implode('", &qout;', $context['board']['moderator_groups']) . '"'; |
576 | 594 | |
577 | - if (!empty($context['board']['moderator_groups'])) |
|
578 | - list ($context['board']['last_moderator_group_id']) = array_slice(array_keys($context['board']['moderator_groups']), -1); |
|
595 | + if (!empty($context['board']['moderator_groups'])) { |
|
596 | + list ($context['board']['last_moderator_group_id']) = array_slice(array_keys($context['board']['moderator_groups']), -1); |
|
597 | + } |
|
579 | 598 | |
580 | 599 | // Get all the themes... |
581 | 600 | $request = $smcFunc['db_query']('', ' |
@@ -587,8 +606,9 @@ discard block |
||
587 | 606 | ) |
588 | 607 | ); |
589 | 608 | $context['themes'] = array(); |
590 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
591 | - $context['themes'][] = $row; |
|
609 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
610 | + $context['themes'][] = $row; |
|
611 | + } |
|
592 | 612 | $smcFunc['db_free_result']($request); |
593 | 613 | |
594 | 614 | if (!isset($_REQUEST['delete'])) |
@@ -596,8 +616,7 @@ discard block |
||
596 | 616 | $context['sub_template'] = 'modify_board'; |
597 | 617 | $context['page_title'] = $txt['boardsEdit']; |
598 | 618 | loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest'); |
599 | - } |
|
600 | - else |
|
619 | + } else |
|
601 | 620 | { |
602 | 621 | $context['sub_template'] = 'confirm_board_delete'; |
603 | 622 | $context['page_title'] = $txt['mboards_delete_board']; |
@@ -641,8 +660,9 @@ discard block |
||
641 | 660 | // Change the boardorder of this board? |
642 | 661 | elseif (!empty($_POST['placement']) && !empty($_POST['board_order'])) |
643 | 662 | { |
644 | - if (!in_array($_POST['placement'], array('before', 'after', 'child'))) |
|
645 | - fatal_lang_error('mangled_post', false); |
|
663 | + if (!in_array($_POST['placement'], array('before', 'after', 'child'))) { |
|
664 | + fatal_lang_error('mangled_post', false); |
|
665 | + } |
|
646 | 666 | |
647 | 667 | $boardOptions['move_to'] = $_POST['placement']; |
648 | 668 | $boardOptions['target_board'] = (int) $_POST['board_order']; |
@@ -655,13 +675,14 @@ discard block |
||
655 | 675 | $boardOptions['access_groups'] = array(); |
656 | 676 | $boardOptions['deny_groups'] = array(); |
657 | 677 | |
658 | - if (!empty($_POST['groups'])) |
|
659 | - foreach ($_POST['groups'] as $group => $action) |
|
678 | + if (!empty($_POST['groups'])) { |
|
679 | + foreach ($_POST['groups'] as $group => $action) |
|
660 | 680 | { |
661 | 681 | if ($action == 'allow') |
662 | 682 | $boardOptions['access_groups'][] = (int) $group; |
663 | - elseif ($action == 'deny') |
|
664 | - $boardOptions['deny_groups'][] = (int) $group; |
|
683 | + } elseif ($action == 'deny') { |
|
684 | + $boardOptions['deny_groups'][] = (int) $group; |
|
685 | + } |
|
665 | 686 | } |
666 | 687 | |
667 | 688 | // People with manage-boards are special. |
@@ -673,8 +694,9 @@ discard block |
||
673 | 694 | // Secondly, make sure those with super cow powers (like apt-get, or in this case manage boards) are upgraded. |
674 | 695 | $boardOptions['access_groups'] = array_unique(array_merge($boardOptions['access_groups'], $board_managers)); |
675 | 696 | |
676 | - if (strlen(implode(',', $boardOptions['access_groups'])) > 255 || strlen(implode(',', $boardOptions['deny_groups'])) > 255) |
|
677 | - fatal_lang_error('too_many_groups', false); |
|
697 | + if (strlen(implode(',', $boardOptions['access_groups'])) > 255 || strlen(implode(',', $boardOptions['deny_groups'])) > 255) { |
|
698 | + fatal_lang_error('too_many_groups', false); |
|
699 | + } |
|
678 | 700 | |
679 | 701 | // Do not allow HTML tags. Parse the string. |
680 | 702 | $boardOptions['board_name'] = parse_bbc($smcFunc['htmlspecialchars']($_POST['board_name']), false, '', $context['description_allowed_tags']); |
@@ -685,8 +707,9 @@ discard block |
||
685 | 707 | if (isset($_POST['moderator_list']) && is_array($_POST['moderator_list'])) |
686 | 708 | { |
687 | 709 | $moderators = array(); |
688 | - foreach ($_POST['moderator_list'] as $moderator) |
|
689 | - $moderators[(int) $moderator] = (int) $moderator; |
|
710 | + foreach ($_POST['moderator_list'] as $moderator) { |
|
711 | + $moderators[(int) $moderator] = (int) $moderator; |
|
712 | + } |
|
690 | 713 | $boardOptions['moderators'] = $moderators; |
691 | 714 | } |
692 | 715 | |
@@ -695,8 +718,9 @@ discard block |
||
695 | 718 | if (isset($_POST['moderator_group_list']) && is_array($_POST['moderator_group_list'])) |
696 | 719 | { |
697 | 720 | $moderator_groups = array(); |
698 | - foreach ($_POST['moderator_group_list'] as $moderator_group) |
|
699 | - $moderator_groups[(int) $moderator_group] = (int) $moderator_group; |
|
721 | + foreach ($_POST['moderator_group_list'] as $moderator_group) { |
|
722 | + $moderator_groups[(int) $moderator_group] = (int) $moderator_group; |
|
723 | + } |
|
700 | 724 | $boardOptions['moderator_groups'] = $moderator_groups; |
701 | 725 | } |
702 | 726 | |
@@ -722,56 +746,62 @@ discard block |
||
722 | 746 | $smcFunc['db_free_result']($request); |
723 | 747 | |
724 | 748 | // If we're turning redirection on check the board doesn't have posts in it - if it does don't make it a redirection board. |
725 | - if ($boardOptions['redirect'] && empty($oldRedirect) && $numPosts) |
|
726 | - unset($boardOptions['redirect']); |
|
749 | + if ($boardOptions['redirect'] && empty($oldRedirect) && $numPosts) { |
|
750 | + unset($boardOptions['redirect']); |
|
751 | + } |
|
727 | 752 | // Reset the redirection count when switching on/off. |
728 | - elseif (empty($boardOptions['redirect']) != empty($oldRedirect)) |
|
729 | - $boardOptions['num_posts'] = 0; |
|
753 | + elseif (empty($boardOptions['redirect']) != empty($oldRedirect)) { |
|
754 | + $boardOptions['num_posts'] = 0; |
|
755 | + } |
|
730 | 756 | // Resetting the count? |
731 | - elseif ($boardOptions['redirect'] && !empty($_POST['reset_redirect'])) |
|
732 | - $boardOptions['num_posts'] = 0; |
|
757 | + elseif ($boardOptions['redirect'] && !empty($_POST['reset_redirect'])) { |
|
758 | + $boardOptions['num_posts'] = 0; |
|
759 | + } |
|
733 | 760 | } |
734 | 761 | |
735 | 762 | // Create a new board... |
736 | 763 | if (isset($_POST['add'])) |
737 | 764 | { |
738 | 765 | // New boards by default go to the bottom of the category. |
739 | - if (empty($_POST['new_cat'])) |
|
740 | - $boardOptions['target_category'] = (int) $_POST['cur_cat']; |
|
741 | - if (!isset($boardOptions['move_to'])) |
|
742 | - $boardOptions['move_to'] = 'bottom'; |
|
766 | + if (empty($_POST['new_cat'])) { |
|
767 | + $boardOptions['target_category'] = (int) $_POST['cur_cat']; |
|
768 | + } |
|
769 | + if (!isset($boardOptions['move_to'])) { |
|
770 | + $boardOptions['move_to'] = 'bottom'; |
|
771 | + } |
|
743 | 772 | |
744 | 773 | createBoard($boardOptions); |
745 | 774 | } |
746 | 775 | |
747 | 776 | // ...or update an existing board. |
748 | - else |
|
749 | - modifyBoard($_POST['boardid'], $boardOptions); |
|
750 | - } |
|
751 | - elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['no_children'])) |
|
777 | + else { |
|
778 | + modifyBoard($_POST['boardid'], $boardOptions); |
|
779 | + } |
|
780 | + } elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['no_children'])) |
|
752 | 781 | { |
753 | 782 | EditBoard(); |
754 | 783 | return; |
755 | - } |
|
756 | - elseif (isset($_POST['delete'])) |
|
784 | + } elseif (isset($_POST['delete'])) |
|
757 | 785 | { |
758 | 786 | // First off - check if we are moving all the current child boards first - before we start deleting! |
759 | 787 | if (isset($_POST['delete_action']) && $_POST['delete_action'] == 1) |
760 | 788 | { |
761 | - if (empty($_POST['board_to'])) |
|
762 | - fatal_lang_error('mboards_delete_board_error'); |
|
789 | + if (empty($_POST['board_to'])) { |
|
790 | + fatal_lang_error('mboards_delete_board_error'); |
|
791 | + } |
|
763 | 792 | |
764 | 793 | deleteBoards(array($_POST['boardid']), (int) $_POST['board_to']); |
794 | + } else { |
|
795 | + deleteBoards(array($_POST['boardid']), 0); |
|
765 | 796 | } |
766 | - else |
|
767 | - deleteBoards(array($_POST['boardid']), 0); |
|
768 | 797 | } |
769 | 798 | |
770 | - if (isset($_REQUEST['rid']) && $_REQUEST['rid'] == 'permissions') |
|
771 | - redirectexit('action=admin;area=permissions;sa=board;' . $context['session_var'] . '=' . $context['session_id']); |
|
772 | - else |
|
773 | - redirectexit('action=admin;area=manageboards'); |
|
774 | -} |
|
799 | + if (isset($_REQUEST['rid']) && $_REQUEST['rid'] == 'permissions') { |
|
800 | + redirectexit('action=admin;area=permissions;sa=board;' . $context['session_var'] . '=' . $context['session_id']); |
|
801 | + } else { |
|
802 | + redirectexit('action=admin;area=manageboards'); |
|
803 | + } |
|
804 | + } |
|
775 | 805 | |
776 | 806 | /** |
777 | 807 | * Used to retrieve data for modifying a board category |
@@ -808,8 +838,9 @@ discard block |
||
808 | 838 | $smcFunc['db_free_result']($request); |
809 | 839 | |
810 | 840 | // This would probably never happen, but just to be sure. |
811 | - if ($cat .= $allowed_sa[1]) |
|
812 | - die(str_replace(',', ' to', $cat)); |
|
841 | + if ($cat .= $allowed_sa[1]) { |
|
842 | + die(str_replace(',', ' to', $cat)); |
|
843 | + } |
|
813 | 844 | |
814 | 845 | redirectexit(); |
815 | 846 | } |
@@ -835,8 +866,9 @@ discard block |
||
835 | 866 | 'empty_string' => '', |
836 | 867 | ) |
837 | 868 | ); |
838 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
839 | - $recycle_boards[$row['id_board']] = $row['cat_name'] . ' - ' . $row['board_name']; |
|
869 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
870 | + $recycle_boards[$row['id_board']] = $row['cat_name'] . ' - ' . $row['board_name']; |
|
871 | + } |
|
840 | 872 | $smcFunc['db_free_result']($request); |
841 | 873 | |
842 | 874 | if (!empty($recycle_boards)) |
@@ -844,9 +876,9 @@ discard block |
||
844 | 876 | require_once($sourcedir . '/Subs-Boards.php'); |
845 | 877 | sortBoards($recycle_boards); |
846 | 878 | $recycle_boards = array('') + $recycle_boards; |
879 | + } else { |
|
880 | + $recycle_boards = array(''); |
|
847 | 881 | } |
848 | - else |
|
849 | - $recycle_boards = array(''); |
|
850 | 882 | |
851 | 883 | // Here and the board settings... |
852 | 884 | $config_vars = array( |
@@ -864,8 +896,9 @@ discard block |
||
864 | 896 | |
865 | 897 | call_integration_hook('integrate_modify_board_settings', array(&$config_vars)); |
866 | 898 | |
867 | - if ($return_config) |
|
868 | - return $config_vars; |
|
899 | + if ($return_config) { |
|
900 | + return $config_vars; |
|
901 | + } |
|
869 | 902 | |
870 | 903 | // Needed for the settings template. |
871 | 904 | require_once($sourcedir . '/ManageServer.php'); |
@@ -2259,9 +2259,9 @@ discard block |
||
2259 | 2259 | * |
2260 | 2260 | * @uses the template_include() function to include the file. |
2261 | 2261 | * @param string $template_name The name of the template to load |
2262 | - * @param array|string $style_sheets The name of a single stylesheet or an array of names of stylesheets to load |
|
2262 | + * @param string $style_sheets The name of a single stylesheet or an array of names of stylesheets to load |
|
2263 | 2263 | * @param bool $fatal If true, dies with an error message if the template cannot be found |
2264 | - * @return boolean Whether or not the template was loaded |
|
2264 | + * @return boolean|null Whether or not the template was loaded |
|
2265 | 2265 | */ |
2266 | 2266 | function loadTemplate($template_name, $style_sheets = array(), $fatal = true) |
2267 | 2267 | { |
@@ -2444,7 +2444,7 @@ discard block |
||
2444 | 2444 | * - all code added with this function is added to the same <style> tag so do make sure your css is valid! |
2445 | 2445 | * |
2446 | 2446 | * @param string $css Some css code |
2447 | - * @return void|bool Adds the CSS to the $context['css_header'] array or returns if no CSS is specified |
|
2447 | + * @return false|null Adds the CSS to the $context['css_header'] array or returns if no CSS is specified |
|
2448 | 2448 | */ |
2449 | 2449 | function addInlineCss($css) |
2450 | 2450 | { |
@@ -2558,7 +2558,7 @@ discard block |
||
2558 | 2558 | * |
2559 | 2559 | * @param string $javascript Some JS code |
2560 | 2560 | * @param bool $defer Whether the script should load in <head> or before the closing <html> tag |
2561 | - * @return void|bool Adds the code to one of the $context['javascript_inline'] arrays or returns if no JS was specified |
|
2561 | + * @return false|null Adds the code to one of the $context['javascript_inline'] arrays or returns if no JS was specified |
|
2562 | 2562 | */ |
2563 | 2563 | function addInlineJavaScript($javascript, $defer = false) |
2564 | 2564 | { |
@@ -2791,7 +2791,7 @@ discard block |
||
2791 | 2791 | * It will try to choose only utf8 or non-utf8 languages. |
2792 | 2792 | * |
2793 | 2793 | * @param bool $use_cache Whether or not to use the cache |
2794 | - * @return array An array of information about available languages |
|
2794 | + * @return string An array of information about available languages |
|
2795 | 2795 | */ |
2796 | 2796 | function getLanguages($use_cache = true) |
2797 | 2797 | { |
@@ -1746,7 +1746,7 @@ discard block |
||
1746 | 1746 | $id_theme = $modSettings['theme_guests']; |
1747 | 1747 | |
1748 | 1748 | // We already load the basic stuff? |
1749 | - if (empty($settings['theme_id']) || $settings['theme_id'] != $id_theme ) |
|
1749 | + if (empty($settings['theme_id']) || $settings['theme_id'] != $id_theme) |
|
1750 | 1750 | { |
1751 | 1751 | // Verify the id_theme... no foul play. |
1752 | 1752 | // Always allow the board specific theme, if they are overriding. |
@@ -2018,7 +2018,7 @@ discard block |
||
2018 | 2018 | if (!isset($context['javascript_vars'])) |
2019 | 2019 | $context['javascript_vars'] = array(); |
2020 | 2020 | |
2021 | - $context['login_url'] = $scripturl . '?action=login2'; |
|
2021 | + $context['login_url'] = $scripturl . '?action=login2'; |
|
2022 | 2022 | $context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | '; |
2023 | 2023 | $context['session_var'] = $_SESSION['session_var']; |
2024 | 2024 | $context['session_id'] = $_SESSION['session_value']; |
@@ -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 | * Load the $modSettings array. |
@@ -25,13 +26,14 @@ discard block |
||
25 | 26 | global $cache_enable, $sourcedir, $context; |
26 | 27 | |
27 | 28 | // Most database systems have not set UTF-8 as their default input charset. |
28 | - if (!empty($db_character_set)) |
|
29 | - $smcFunc['db_query']('', ' |
|
29 | + if (!empty($db_character_set)) { |
|
30 | + $smcFunc['db_query']('', ' |
|
30 | 31 | SET NAMES {string:db_character_set}', |
31 | 32 | array( |
32 | 33 | 'db_character_set' => $db_character_set, |
33 | 34 | ) |
34 | 35 | ); |
36 | + } |
|
35 | 37 | |
36 | 38 | // We need some caching support, maybe. |
37 | 39 | loadCacheAccelerator(); |
@@ -46,28 +48,36 @@ discard block |
||
46 | 48 | ) |
47 | 49 | ); |
48 | 50 | $modSettings = array(); |
49 | - if (!$request) |
|
50 | - display_db_error(); |
|
51 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
52 | - $modSettings[$row[0]] = $row[1]; |
|
51 | + if (!$request) { |
|
52 | + display_db_error(); |
|
53 | + } |
|
54 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
55 | + $modSettings[$row[0]] = $row[1]; |
|
56 | + } |
|
53 | 57 | $smcFunc['db_free_result']($request); |
54 | 58 | |
55 | 59 | // Do a few things to protect against missing settings or settings with invalid values... |
56 | - if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) |
|
57 | - $modSettings['defaultMaxTopics'] = 20; |
|
58 | - if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) |
|
59 | - $modSettings['defaultMaxMessages'] = 15; |
|
60 | - if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) |
|
61 | - $modSettings['defaultMaxMembers'] = 30; |
|
62 | - if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) |
|
63 | - $modSettings['defaultMaxListItems'] = 15; |
|
60 | + if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) { |
|
61 | + $modSettings['defaultMaxTopics'] = 20; |
|
62 | + } |
|
63 | + if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) { |
|
64 | + $modSettings['defaultMaxMessages'] = 15; |
|
65 | + } |
|
66 | + if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) { |
|
67 | + $modSettings['defaultMaxMembers'] = 30; |
|
68 | + } |
|
69 | + if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) { |
|
70 | + $modSettings['defaultMaxListItems'] = 15; |
|
71 | + } |
|
64 | 72 | |
65 | 73 | // We excpiclity do not use $smcFunc['json_decode'] here yet, as $smcFunc is not fully loaded. |
66 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
67 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
74 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
75 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
76 | + } |
|
68 | 77 | |
69 | - if (!empty($cache_enable)) |
|
70 | - cache_put_data('modSettings', $modSettings, 90); |
|
78 | + if (!empty($cache_enable)) { |
|
79 | + cache_put_data('modSettings', $modSettings, 90); |
|
80 | + } |
|
71 | 81 | } |
72 | 82 | |
73 | 83 | $modSettings['cache_enable'] = $cache_enable; |
@@ -87,8 +97,9 @@ discard block |
||
87 | 97 | }; |
88 | 98 | $fix_utf8mb4 = function($string) use ($utf8, $smcFunc) |
89 | 99 | { |
90 | - if (!$utf8 || $smcFunc['db_mb4']) |
|
91 | - return $string; |
|
100 | + if (!$utf8 || $smcFunc['db_mb4']) { |
|
101 | + return $string; |
|
102 | + } |
|
92 | 103 | |
93 | 104 | $i = 0; |
94 | 105 | $len = strlen($string); |
@@ -100,18 +111,15 @@ discard block |
||
100 | 111 | { |
101 | 112 | $new_string .= $string[$i]; |
102 | 113 | $i++; |
103 | - } |
|
104 | - elseif ($ord < 224) |
|
114 | + } elseif ($ord < 224) |
|
105 | 115 | { |
106 | 116 | $new_string .= $string[$i] . $string[$i + 1]; |
107 | 117 | $i += 2; |
108 | - } |
|
109 | - elseif ($ord < 240) |
|
118 | + } elseif ($ord < 240) |
|
110 | 119 | { |
111 | 120 | $new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2]; |
112 | 121 | $i += 3; |
113 | - } |
|
114 | - elseif ($ord < 248) |
|
122 | + } elseif ($ord < 248) |
|
115 | 123 | { |
116 | 124 | // Magic happens. |
117 | 125 | $val = (ord($string[$i]) & 0x07) << 18; |
@@ -155,8 +163,7 @@ discard block |
||
155 | 163 | { |
156 | 164 | $result = array_search($needle, array_slice($haystack_arr, $offset)); |
157 | 165 | return is_int($result) ? $result + $offset : false; |
158 | - } |
|
159 | - else |
|
166 | + } else |
|
160 | 167 | { |
161 | 168 | $needle_arr = preg_split('~(' . $ent_list . '|.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); |
162 | 169 | $needle_size = count($needle_arr); |
@@ -165,8 +172,9 @@ discard block |
||
165 | 172 | while ((int) $result === $result) |
166 | 173 | { |
167 | 174 | $offset += $result; |
168 | - if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) |
|
169 | - return $offset; |
|
175 | + if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) { |
|
176 | + return $offset; |
|
177 | + } |
|
170 | 178 | $result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset)); |
171 | 179 | } |
172 | 180 | return false; |
@@ -204,8 +212,9 @@ discard block |
||
204 | 212 | $string = $ent_check($string); |
205 | 213 | preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches); |
206 | 214 | $string = $matches[0]; |
207 | - while (strlen($string) > $length) |
|
208 | - $string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string); |
|
215 | + while (strlen($string) > $length) { |
|
216 | + $string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string); |
|
217 | + } |
|
209 | 218 | return $string; |
210 | 219 | }, |
211 | 220 | 'ucfirst' => $utf8 ? function($string) use (&$smcFunc) |
@@ -215,8 +224,9 @@ discard block |
||
215 | 224 | 'ucwords' => $utf8 ? function($string) use (&$smcFunc) |
216 | 225 | { |
217 | 226 | $words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE); |
218 | - for ($i = 0, $n = count($words); $i < $n; $i += 2) |
|
219 | - $words[$i] = $smcFunc['ucfirst']($words[$i]); |
|
227 | + for ($i = 0, $n = count($words); $i < $n; $i += 2) { |
|
228 | + $words[$i] = $smcFunc['ucfirst']($words[$i]); |
|
229 | + } |
|
220 | 230 | return implode('', $words); |
221 | 231 | } : 'ucwords', |
222 | 232 | 'json_decode' => 'smf_json_decode', |
@@ -224,16 +234,17 @@ discard block |
||
224 | 234 | ); |
225 | 235 | |
226 | 236 | // Setting the timezone is a requirement for some functions. |
227 | - if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) |
|
228 | - date_default_timezone_set($modSettings['default_timezone']); |
|
229 | - else |
|
237 | + if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) { |
|
238 | + date_default_timezone_set($modSettings['default_timezone']); |
|
239 | + } else |
|
230 | 240 | { |
231 | 241 | // Get PHP's default timezone, if set |
232 | 242 | $ini_tz = ini_get('date.timezone'); |
233 | - if (!empty($ini_tz)) |
|
234 | - $modSettings['default_timezone'] = $ini_tz; |
|
235 | - else |
|
236 | - $modSettings['default_timezone'] = ''; |
|
243 | + if (!empty($ini_tz)) { |
|
244 | + $modSettings['default_timezone'] = $ini_tz; |
|
245 | + } else { |
|
246 | + $modSettings['default_timezone'] = ''; |
|
247 | + } |
|
237 | 248 | |
238 | 249 | // If date.timezone is unset, invalid, or just plain weird, make a best guess |
239 | 250 | if (!in_array($modSettings['default_timezone'], timezone_identifiers_list())) |
@@ -251,22 +262,26 @@ discard block |
||
251 | 262 | if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null) |
252 | 263 | { |
253 | 264 | $modSettings['load_average'] = @file_get_contents('/proc/loadavg'); |
254 | - if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) |
|
255 | - $modSettings['load_average'] = (float) $matches[1]; |
|
256 | - elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) |
|
257 | - $modSettings['load_average'] = (float) $matches[1]; |
|
258 | - else |
|
259 | - unset($modSettings['load_average']); |
|
265 | + if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) { |
|
266 | + $modSettings['load_average'] = (float) $matches[1]; |
|
267 | + } elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) { |
|
268 | + $modSettings['load_average'] = (float) $matches[1]; |
|
269 | + } else { |
|
270 | + unset($modSettings['load_average']); |
|
271 | + } |
|
260 | 272 | |
261 | - if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) |
|
262 | - cache_put_data('loadavg', $modSettings['load_average'], 90); |
|
273 | + if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) { |
|
274 | + cache_put_data('loadavg', $modSettings['load_average'], 90); |
|
275 | + } |
|
263 | 276 | } |
264 | 277 | |
265 | - if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) |
|
266 | - call_integration_hook('integrate_load_average', array($modSettings['load_average'])); |
|
278 | + if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) { |
|
279 | + call_integration_hook('integrate_load_average', array($modSettings['load_average'])); |
|
280 | + } |
|
267 | 281 | |
268 | - if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) |
|
269 | - display_loadavg_error(); |
|
282 | + if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) { |
|
283 | + display_loadavg_error(); |
|
284 | + } |
|
270 | 285 | } |
271 | 286 | |
272 | 287 | // Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is. |
@@ -287,8 +302,9 @@ discard block |
||
287 | 302 | if (defined('SMF_INTEGRATION_SETTINGS')) |
288 | 303 | { |
289 | 304 | $integration_settings = $smcFunc['json_decode'](SMF_INTEGRATION_SETTINGS, true); |
290 | - foreach ($integration_settings as $hook => $function) |
|
291 | - add_integration_function($hook, $function, '', false); |
|
305 | + foreach ($integration_settings as $hook => $function) { |
|
306 | + add_integration_function($hook, $function, '', false); |
|
307 | + } |
|
292 | 308 | } |
293 | 309 | |
294 | 310 | // Any files to pre include? |
@@ -298,8 +314,9 @@ discard block |
||
298 | 314 | foreach ($pre_includes as $include) |
299 | 315 | { |
300 | 316 | $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
301 | - if (file_exists($include)) |
|
302 | - require_once($include); |
|
317 | + if (file_exists($include)) { |
|
318 | + require_once($include); |
|
319 | + } |
|
303 | 320 | } |
304 | 321 | } |
305 | 322 | |
@@ -392,9 +409,9 @@ discard block |
||
392 | 409 | break; |
393 | 410 | } |
394 | 411 | } |
412 | + } else { |
|
413 | + $id_member = 0; |
|
395 | 414 | } |
396 | - else |
|
397 | - $id_member = 0; |
|
398 | 415 | |
399 | 416 | if (empty($id_member) && isset($_COOKIE[$cookiename])) |
400 | 417 | { |
@@ -402,8 +419,9 @@ discard block |
||
402 | 419 | $cookie_data = $smcFunc['json_decode']($_COOKIE[$cookiename], true, false); |
403 | 420 | |
404 | 421 | // Legacy format (for recent 2.0 --> 2.1 upgrades) |
405 | - if (empty($cookie_data)) |
|
406 | - $cookie_data = safe_unserialize($_COOKIE[$cookiename]); |
|
422 | + if (empty($cookie_data)) { |
|
423 | + $cookie_data = safe_unserialize($_COOKIE[$cookiename]); |
|
424 | + } |
|
407 | 425 | |
408 | 426 | list($id_member, $password, $login_span, $cookie_domain, $cookie_path) = array_pad((array) $cookie_data, 5, ''); |
409 | 427 | |
@@ -411,16 +429,17 @@ discard block |
||
411 | 429 | |
412 | 430 | // Make sure the cookie is set to the correct domain and path |
413 | 431 | require_once($sourcedir . '/Subs-Auth.php'); |
414 | - if (array($cookie_domain, $cookie_path) !== url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']))) |
|
415 | - setLoginCookie((int) $login_span - time(), $id_member); |
|
416 | - } |
|
417 | - elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA']))) |
|
432 | + if (array($cookie_domain, $cookie_path) !== url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']))) { |
|
433 | + setLoginCookie((int) $login_span - time(), $id_member); |
|
434 | + } |
|
435 | + } elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA']))) |
|
418 | 436 | { |
419 | 437 | // @todo Perhaps we can do some more checking on this, such as on the first octet of the IP? |
420 | 438 | $cookie_data = $smcFunc['json_decode']($_SESSION['login_' . $cookiename], true); |
421 | 439 | |
422 | - if (empty($cookie_data)) |
|
423 | - $cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
440 | + if (empty($cookie_data)) { |
|
441 | + $cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
442 | + } |
|
424 | 443 | |
425 | 444 | list($id_member, $password, $login_span) = array_pad((array) $cookie_data, 3, ''); |
426 | 445 | $id_member = !empty($id_member) && strlen($password) == 128 && (int) $login_span > time() ? (int) $id_member : 0; |
@@ -445,30 +464,34 @@ discard block |
||
445 | 464 | $user_settings = $smcFunc['db_fetch_assoc']($request); |
446 | 465 | $smcFunc['db_free_result']($request); |
447 | 466 | |
448 | - if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) |
|
449 | - $user_settings['avatar'] = get_proxied_url($user_settings['avatar']); |
|
467 | + if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) { |
|
468 | + $user_settings['avatar'] = get_proxied_url($user_settings['avatar']); |
|
469 | + } |
|
450 | 470 | |
451 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
452 | - cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
471 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
472 | + cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
473 | + } |
|
453 | 474 | } |
454 | 475 | |
455 | 476 | // Did we find 'im? If not, junk it. |
456 | 477 | if (!empty($user_settings)) |
457 | 478 | { |
458 | 479 | // As much as the password should be right, we can assume the integration set things up. |
459 | - if (!empty($already_verified) && $already_verified === true) |
|
460 | - $check = true; |
|
480 | + if (!empty($already_verified) && $already_verified === true) { |
|
481 | + $check = true; |
|
482 | + } |
|
461 | 483 | // SHA-512 hash should be 128 characters long. |
462 | - elseif (strlen($password) == 128) |
|
463 | - $check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password; |
|
464 | - else |
|
465 | - $check = false; |
|
484 | + elseif (strlen($password) == 128) { |
|
485 | + $check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password; |
|
486 | + } else { |
|
487 | + $check = false; |
|
488 | + } |
|
466 | 489 | |
467 | 490 | // Wrong password or not activated - either way, you're going nowhere. |
468 | 491 | $id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0; |
492 | + } else { |
|
493 | + $id_member = 0; |
|
469 | 494 | } |
470 | - else |
|
471 | - $id_member = 0; |
|
472 | 495 | |
473 | 496 | // If we no longer have the member maybe they're being all hackey, stop brute force! |
474 | 497 | if (!$id_member) |
@@ -497,8 +520,9 @@ discard block |
||
497 | 520 | |
498 | 521 | list ($tfamember, $tfasecret) = array_pad((array) $tfa_data, 2, ''); |
499 | 522 | |
500 | - if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) |
|
501 | - $tfasecret = null; |
|
523 | + if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) { |
|
524 | + $tfasecret = null; |
|
525 | + } |
|
502 | 526 | } |
503 | 527 | |
504 | 528 | // They didn't finish logging in before coming here? Then they're no one to us. |
@@ -520,10 +544,12 @@ discard block |
||
520 | 544 | // Are we forcing 2FA? Need to check if the user groups actually require 2FA |
521 | 545 | elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret'])) |
522 | 546 | { |
523 | - if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups |
|
547 | + if ($modSettings['tfa_mode'] == 2) { |
|
548 | + //only do this if we are just forcing SOME membergroups |
|
524 | 549 | { |
525 | 550 | //Build an array of ALL user membergroups. |
526 | 551 | $full_groups = array($user_settings['id_group']); |
552 | + } |
|
527 | 553 | if (!empty($user_settings['additional_groups'])) |
528 | 554 | { |
529 | 555 | $full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups'])); |
@@ -543,15 +569,17 @@ discard block |
||
543 | 569 | ); |
544 | 570 | $row = $smcFunc['db_fetch_assoc']($request); |
545 | 571 | $smcFunc['db_free_result']($request); |
572 | + } else { |
|
573 | + $row['total'] = 1; |
|
546 | 574 | } |
547 | - else |
|
548 | - $row['total'] = 1; //simplifies logics in the next "if" |
|
575 | + //simplifies logics in the next "if" |
|
549 | 576 | |
550 | 577 | $area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : ''; |
551 | 578 | $action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : ''; |
552 | 579 | |
553 | - if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) |
|
554 | - redirectexit('action=profile;area=tfasetup;forced'); |
|
580 | + if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) { |
|
581 | + redirectexit('action=profile;area=tfasetup;forced'); |
|
582 | + } |
|
555 | 583 | } |
556 | 584 | } |
557 | 585 | |
@@ -588,33 +616,37 @@ discard block |
||
588 | 616 | updateMemberData($id_member, array('id_msg_last_visit' => (int) $modSettings['maxMsgID'], 'last_login' => time(), 'member_ip' => $_SERVER['REMOTE_ADDR'], 'member_ip2' => $_SERVER['BAN_CHECK_IP'])); |
589 | 617 | $user_settings['last_login'] = time(); |
590 | 618 | |
591 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
592 | - cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
619 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
620 | + cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
621 | + } |
|
593 | 622 | |
594 | - if (!empty($modSettings['cache_enable'])) |
|
595 | - cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600); |
|
623 | + if (!empty($modSettings['cache_enable'])) { |
|
624 | + cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600); |
|
625 | + } |
|
596 | 626 | } |
627 | + } elseif (empty($_SESSION['id_msg_last_visit'])) { |
|
628 | + $_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit']; |
|
597 | 629 | } |
598 | - elseif (empty($_SESSION['id_msg_last_visit'])) |
|
599 | - $_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit']; |
|
600 | 630 | |
601 | 631 | $username = $user_settings['member_name']; |
602 | 632 | |
603 | - if (empty($user_settings['additional_groups'])) |
|
604 | - $user_info = array( |
|
633 | + if (empty($user_settings['additional_groups'])) { |
|
634 | + $user_info = array( |
|
605 | 635 | 'groups' => array($user_settings['id_group'], $user_settings['id_post_group']) |
606 | 636 | ); |
607 | - else |
|
608 | - $user_info = array( |
|
637 | + } else { |
|
638 | + $user_info = array( |
|
609 | 639 | 'groups' => array_merge( |
610 | 640 | array($user_settings['id_group'], $user_settings['id_post_group']), |
611 | 641 | explode(',', $user_settings['additional_groups']) |
612 | 642 | ) |
613 | 643 | ); |
644 | + } |
|
614 | 645 | |
615 | 646 | // Because history has proven that it is possible for groups to go bad - clean up in case. |
616 | - foreach ($user_info['groups'] as $k => $v) |
|
617 | - $user_info['groups'][$k] = (int) $v; |
|
647 | + foreach ($user_info['groups'] as $k => $v) { |
|
648 | + $user_info['groups'][$k] = (int) $v; |
|
649 | + } |
|
618 | 650 | |
619 | 651 | // This is a logged in user, so definitely not a spider. |
620 | 652 | $user_info['possibly_robot'] = false; |
@@ -628,8 +660,7 @@ discard block |
||
628 | 660 | $time_system = new DateTime('now', $tz_system); |
629 | 661 | $time_user = new DateTime('now', $tz_user); |
630 | 662 | $user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600; |
631 | - } |
|
632 | - else |
|
663 | + } else |
|
633 | 664 | { |
634 | 665 | // !!! Compatibility. |
635 | 666 | $user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset']; |
@@ -643,8 +674,9 @@ discard block |
||
643 | 674 | $user_info = array('groups' => array(-1)); |
644 | 675 | $user_settings = array(); |
645 | 676 | |
646 | - if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) |
|
647 | - $_COOKIE[$cookiename] = ''; |
|
677 | + if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) { |
|
678 | + $_COOKIE[$cookiename] = ''; |
|
679 | + } |
|
648 | 680 | |
649 | 681 | // Expire the 2FA cookie |
650 | 682 | if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member'])) |
@@ -661,19 +693,20 @@ discard block |
||
661 | 693 | } |
662 | 694 | |
663 | 695 | // Create a login token if it doesn't exist yet. |
664 | - if (!isset($_SESSION['token']['post-login'])) |
|
665 | - createToken('login'); |
|
666 | - else |
|
667 | - list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login']; |
|
696 | + if (!isset($_SESSION['token']['post-login'])) { |
|
697 | + createToken('login'); |
|
698 | + } else { |
|
699 | + list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login']; |
|
700 | + } |
|
668 | 701 | |
669 | 702 | // Do we perhaps think this is a search robot? Check every five minutes just in case... |
670 | 703 | if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300)) |
671 | 704 | { |
672 | 705 | require_once($sourcedir . '/ManageSearchEngines.php'); |
673 | 706 | $user_info['possibly_robot'] = SpiderCheck(); |
707 | + } elseif (!empty($modSettings['spider_mode'])) { |
|
708 | + $user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0; |
|
674 | 709 | } |
675 | - elseif (!empty($modSettings['spider_mode'])) |
|
676 | - $user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0; |
|
677 | 710 | // If we haven't turned on proper spider hunts then have a guess! |
678 | 711 | else |
679 | 712 | { |
@@ -721,8 +754,9 @@ discard block |
||
721 | 754 | $user_info['groups'] = array_unique($user_info['groups']); |
722 | 755 | |
723 | 756 | // Make sure that the last item in the ignore boards array is valid. If the list was too long it could have an ending comma that could cause problems. |
724 | - if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) |
|
725 | - unset($user_info['ignoreboards'][$tmp]); |
|
757 | + if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) { |
|
758 | + unset($user_info['ignoreboards'][$tmp]); |
|
759 | + } |
|
726 | 760 | |
727 | 761 | // Allow the user to change their language. |
728 | 762 | if (!empty($modSettings['userLanguage'])) |
@@ -735,13 +769,14 @@ discard block |
||
735 | 769 | $user_info['language'] = strtr($_GET['language'], './\\:', '____'); |
736 | 770 | |
737 | 771 | // Make it permanent for members. |
738 | - if (!empty($user_info['id'])) |
|
739 | - updateMemberData($user_info['id'], array('lngfile' => $user_info['language'])); |
|
740 | - else |
|
741 | - $_SESSION['language'] = $user_info['language']; |
|
772 | + if (!empty($user_info['id'])) { |
|
773 | + updateMemberData($user_info['id'], array('lngfile' => $user_info['language'])); |
|
774 | + } else { |
|
775 | + $_SESSION['language'] = $user_info['language']; |
|
776 | + } |
|
777 | + } elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) { |
|
778 | + $user_info['language'] = strtr($_SESSION['language'], './\\:', '____'); |
|
742 | 779 | } |
743 | - elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) |
|
744 | - $user_info['language'] = strtr($_SESSION['language'], './\\:', '____'); |
|
745 | 780 | } |
746 | 781 | |
747 | 782 | $temp = build_query_board($user_info['id']); |
@@ -804,9 +839,9 @@ discard block |
||
804 | 839 | } |
805 | 840 | |
806 | 841 | // Remember redirection is the key to avoiding fallout from your bosses. |
807 | - if (!empty($topic)) |
|
808 | - redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']); |
|
809 | - else |
|
842 | + if (!empty($topic)) { |
|
843 | + redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']); |
|
844 | + } else |
|
810 | 845 | { |
811 | 846 | loadPermissions(); |
812 | 847 | loadTheme(); |
@@ -824,10 +859,11 @@ discard block |
||
824 | 859 | if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3)) |
825 | 860 | { |
826 | 861 | // @todo SLOW? |
827 | - if (!empty($topic)) |
|
828 | - $temp = cache_get_data('topic_board-' . $topic, 120); |
|
829 | - else |
|
830 | - $temp = cache_get_data('board-' . $board, 120); |
|
862 | + if (!empty($topic)) { |
|
863 | + $temp = cache_get_data('topic_board-' . $topic, 120); |
|
864 | + } else { |
|
865 | + $temp = cache_get_data('board-' . $board, 120); |
|
866 | + } |
|
831 | 867 | |
832 | 868 | if (!empty($temp)) |
833 | 869 | { |
@@ -865,8 +901,9 @@ discard block |
||
865 | 901 | $row = $smcFunc['db_fetch_assoc']($request); |
866 | 902 | |
867 | 903 | // Set the current board. |
868 | - if (!empty($row['id_board'])) |
|
869 | - $board = $row['id_board']; |
|
904 | + if (!empty($row['id_board'])) { |
|
905 | + $board = $row['id_board']; |
|
906 | + } |
|
870 | 907 | |
871 | 908 | // Basic operating information. (globals... :/) |
872 | 909 | $board_info = array( |
@@ -902,21 +939,23 @@ discard block |
||
902 | 939 | |
903 | 940 | do |
904 | 941 | { |
905 | - if (!empty($row['id_moderator'])) |
|
906 | - $board_info['moderators'][$row['id_moderator']] = array( |
|
942 | + if (!empty($row['id_moderator'])) { |
|
943 | + $board_info['moderators'][$row['id_moderator']] = array( |
|
907 | 944 | 'id' => $row['id_moderator'], |
908 | 945 | 'name' => $row['real_name'], |
909 | 946 | 'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'], |
910 | 947 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>' |
911 | 948 | ); |
949 | + } |
|
912 | 950 | |
913 | - if (!empty($row['id_moderator_group'])) |
|
914 | - $board_info['moderator_groups'][$row['id_moderator_group']] = array( |
|
951 | + if (!empty($row['id_moderator_group'])) { |
|
952 | + $board_info['moderator_groups'][$row['id_moderator_group']] = array( |
|
915 | 953 | 'id' => $row['id_moderator_group'], |
916 | 954 | 'name' => $row['group_name'], |
917 | 955 | 'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'], |
918 | 956 | 'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>' |
919 | 957 | ); |
958 | + } |
|
920 | 959 | } |
921 | 960 | while ($row = $smcFunc['db_fetch_assoc']($request)); |
922 | 961 | |
@@ -948,12 +987,12 @@ discard block |
||
948 | 987 | if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3)) |
949 | 988 | { |
950 | 989 | // @todo SLOW? |
951 | - if (!empty($topic)) |
|
952 | - cache_put_data('topic_board-' . $topic, $board_info, 120); |
|
990 | + if (!empty($topic)) { |
|
991 | + cache_put_data('topic_board-' . $topic, $board_info, 120); |
|
992 | + } |
|
953 | 993 | cache_put_data('board-' . $board, $board_info, 120); |
954 | 994 | } |
955 | - } |
|
956 | - else |
|
995 | + } else |
|
957 | 996 | { |
958 | 997 | // Otherwise the topic is invalid, there are no moderators, etc. |
959 | 998 | $board_info = array( |
@@ -967,8 +1006,9 @@ discard block |
||
967 | 1006 | $smcFunc['db_free_result']($request); |
968 | 1007 | } |
969 | 1008 | |
970 | - if (!empty($topic)) |
|
971 | - $_GET['board'] = (int) $board; |
|
1009 | + if (!empty($topic)) { |
|
1010 | + $_GET['board'] = (int) $board; |
|
1011 | + } |
|
972 | 1012 | |
973 | 1013 | if (!empty($board)) |
974 | 1014 | { |
@@ -978,10 +1018,12 @@ discard block |
||
978 | 1018 | // Now check if the user is a moderator. |
979 | 1019 | $user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0; |
980 | 1020 | |
981 | - if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) |
|
982 | - $board_info['error'] = 'access'; |
|
983 | - if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) |
|
984 | - $board_info['error'] = 'access'; |
|
1021 | + if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) { |
|
1022 | + $board_info['error'] = 'access'; |
|
1023 | + } |
|
1024 | + if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) { |
|
1025 | + $board_info['error'] = 'access'; |
|
1026 | + } |
|
985 | 1027 | |
986 | 1028 | // Build up the linktree. |
987 | 1029 | $context['linktree'] = array_merge( |
@@ -1004,8 +1046,9 @@ discard block |
||
1004 | 1046 | $context['current_board'] = $board; |
1005 | 1047 | |
1006 | 1048 | // No posting in redirection boards! |
1007 | - if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) |
|
1008 | - $board_info['error'] == 'post_in_redirect'; |
|
1049 | + if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) { |
|
1050 | + $board_info['error'] == 'post_in_redirect'; |
|
1051 | + } |
|
1009 | 1052 | |
1010 | 1053 | // Hacker... you can't see this topic, I'll tell you that. (but moderators can!) |
1011 | 1054 | if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod'])) |
@@ -1031,24 +1074,23 @@ discard block |
||
1031 | 1074 | ob_end_clean(); |
1032 | 1075 | header('HTTP/1.1 403 Forbidden'); |
1033 | 1076 | die; |
1034 | - } |
|
1035 | - elseif ($board_info['error'] == 'post_in_redirect') |
|
1077 | + } elseif ($board_info['error'] == 'post_in_redirect') |
|
1036 | 1078 | { |
1037 | 1079 | // Slightly different error message here... |
1038 | 1080 | fatal_lang_error('cannot_post_redirect', false); |
1039 | - } |
|
1040 | - elseif ($user_info['is_guest']) |
|
1081 | + } elseif ($user_info['is_guest']) |
|
1041 | 1082 | { |
1042 | 1083 | loadLanguage('Errors'); |
1043 | 1084 | is_not_guest($txt['topic_gone']); |
1085 | + } else { |
|
1086 | + fatal_lang_error('topic_gone', false); |
|
1044 | 1087 | } |
1045 | - else |
|
1046 | - fatal_lang_error('topic_gone', false); |
|
1047 | 1088 | } |
1048 | 1089 | |
1049 | - if ($user_info['is_mod']) |
|
1050 | - $user_info['groups'][] = 3; |
|
1051 | -} |
|
1090 | + if ($user_info['is_mod']) { |
|
1091 | + $user_info['groups'][] = 3; |
|
1092 | + } |
|
1093 | + } |
|
1052 | 1094 | |
1053 | 1095 | /** |
1054 | 1096 | * Load this user's permissions. |
@@ -1069,8 +1111,9 @@ discard block |
||
1069 | 1111 | asort($cache_groups); |
1070 | 1112 | $cache_groups = implode(',', $cache_groups); |
1071 | 1113 | // If it's a spider then cache it different. |
1072 | - if ($user_info['possibly_robot']) |
|
1073 | - $cache_groups .= '-spider'; |
|
1114 | + if ($user_info['possibly_robot']) { |
|
1115 | + $cache_groups .= '-spider'; |
|
1116 | + } |
|
1074 | 1117 | |
1075 | 1118 | if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated']) |
1076 | 1119 | { |
@@ -1078,9 +1121,9 @@ discard block |
||
1078 | 1121 | banPermissions(); |
1079 | 1122 | |
1080 | 1123 | return; |
1124 | + } elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) { |
|
1125 | + list ($user_info['permissions'], $removals) = $temp; |
|
1081 | 1126 | } |
1082 | - elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) |
|
1083 | - list ($user_info['permissions'], $removals) = $temp; |
|
1084 | 1127 | } |
1085 | 1128 | |
1086 | 1129 | // If it is detected as a robot, and we are restricting permissions as a special group - then implement this. |
@@ -1102,23 +1145,26 @@ discard block |
||
1102 | 1145 | $removals = array(); |
1103 | 1146 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1104 | 1147 | { |
1105 | - if (empty($row['add_deny'])) |
|
1106 | - $removals[] = $row['permission']; |
|
1107 | - else |
|
1108 | - $user_info['permissions'][] = $row['permission']; |
|
1148 | + if (empty($row['add_deny'])) { |
|
1149 | + $removals[] = $row['permission']; |
|
1150 | + } else { |
|
1151 | + $user_info['permissions'][] = $row['permission']; |
|
1152 | + } |
|
1109 | 1153 | } |
1110 | 1154 | $smcFunc['db_free_result']($request); |
1111 | 1155 | |
1112 | - if (isset($cache_groups)) |
|
1113 | - cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240); |
|
1156 | + if (isset($cache_groups)) { |
|
1157 | + cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240); |
|
1158 | + } |
|
1114 | 1159 | } |
1115 | 1160 | |
1116 | 1161 | // Get the board permissions. |
1117 | 1162 | if (!empty($board)) |
1118 | 1163 | { |
1119 | 1164 | // Make sure the board (if any) has been loaded by loadBoard(). |
1120 | - if (!isset($board_info['profile'])) |
|
1121 | - fatal_lang_error('no_board'); |
|
1165 | + if (!isset($board_info['profile'])) { |
|
1166 | + fatal_lang_error('no_board'); |
|
1167 | + } |
|
1122 | 1168 | |
1123 | 1169 | $request = $smcFunc['db_query']('', ' |
1124 | 1170 | SELECT permission, add_deny |
@@ -1134,20 +1180,23 @@ discard block |
||
1134 | 1180 | ); |
1135 | 1181 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1136 | 1182 | { |
1137 | - if (empty($row['add_deny'])) |
|
1138 | - $removals[] = $row['permission']; |
|
1139 | - else |
|
1140 | - $user_info['permissions'][] = $row['permission']; |
|
1183 | + if (empty($row['add_deny'])) { |
|
1184 | + $removals[] = $row['permission']; |
|
1185 | + } else { |
|
1186 | + $user_info['permissions'][] = $row['permission']; |
|
1187 | + } |
|
1141 | 1188 | } |
1142 | 1189 | $smcFunc['db_free_result']($request); |
1143 | 1190 | } |
1144 | 1191 | |
1145 | 1192 | // Remove all the permissions they shouldn't have ;). |
1146 | - if (!empty($modSettings['permission_enable_deny'])) |
|
1147 | - $user_info['permissions'] = array_diff($user_info['permissions'], $removals); |
|
1193 | + if (!empty($modSettings['permission_enable_deny'])) { |
|
1194 | + $user_info['permissions'] = array_diff($user_info['permissions'], $removals); |
|
1195 | + } |
|
1148 | 1196 | |
1149 | - if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) |
|
1150 | - cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240); |
|
1197 | + if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) { |
|
1198 | + cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240); |
|
1199 | + } |
|
1151 | 1200 | |
1152 | 1201 | // Banned? Watch, don't touch.. |
1153 | 1202 | banPermissions(); |
@@ -1159,17 +1208,18 @@ discard block |
||
1159 | 1208 | { |
1160 | 1209 | require_once($sourcedir . '/Subs-Auth.php'); |
1161 | 1210 | rebuildModCache(); |
1211 | + } else { |
|
1212 | + $user_info['mod_cache'] = $_SESSION['mc']; |
|
1162 | 1213 | } |
1163 | - else |
|
1164 | - $user_info['mod_cache'] = $_SESSION['mc']; |
|
1165 | 1214 | |
1166 | 1215 | // This is a useful phantom permission added to the current user, and only the current user while they are logged in. |
1167 | 1216 | // For example this drastically simplifies certain changes to the profile area. |
1168 | 1217 | $user_info['permissions'][] = 'is_not_guest'; |
1169 | 1218 | // And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions. |
1170 | 1219 | $user_info['permissions'][] = 'profile_view_own'; |
1171 | - if (in_array('profile_view', $user_info['permissions'])) |
|
1172 | - $user_info['permissions'][] = 'profile_view_any'; |
|
1220 | + if (in_array('profile_view', $user_info['permissions'])) { |
|
1221 | + $user_info['permissions'][] = 'profile_view_any'; |
|
1222 | + } |
|
1173 | 1223 | } |
1174 | 1224 | } |
1175 | 1225 | |
@@ -1187,8 +1237,9 @@ discard block |
||
1187 | 1237 | global $image_proxy_enabled, $boardurl, $user_info; |
1188 | 1238 | |
1189 | 1239 | // Can't just look for no users :P. |
1190 | - if (empty($users)) |
|
1191 | - return array(); |
|
1240 | + if (empty($users)) { |
|
1241 | + return array(); |
|
1242 | + } |
|
1192 | 1243 | |
1193 | 1244 | // Pass the set value |
1194 | 1245 | $context['loadMemberContext_set'] = $set; |
@@ -1203,8 +1254,9 @@ discard block |
||
1203 | 1254 | for ($i = 0, $n = count($users); $i < $n; $i++) |
1204 | 1255 | { |
1205 | 1256 | $data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240); |
1206 | - if ($data == null) |
|
1207 | - continue; |
|
1257 | + if ($data == null) { |
|
1258 | + continue; |
|
1259 | + } |
|
1208 | 1260 | |
1209 | 1261 | $loaded_ids[] = $data['id_member']; |
1210 | 1262 | $user_profile[$data['id_member']] = $data; |
@@ -1271,16 +1323,19 @@ discard block |
||
1271 | 1323 | $row['avatar_original'] = !empty($row['avatar']) ? $row['avatar'] : ''; |
1272 | 1324 | |
1273 | 1325 | // Take care of proxying avatar if required, do this here for maximum reach |
1274 | - if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) |
|
1275 | - $row['avatar'] = get_proxied_url($row['avatar']); |
|
1326 | + if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) { |
|
1327 | + $row['avatar'] = get_proxied_url($row['avatar']); |
|
1328 | + } |
|
1276 | 1329 | |
1277 | 1330 | // Keep track of the member's normal member group |
1278 | 1331 | $row['primary_group'] = $row['member_group']; |
1279 | 1332 | |
1280 | - if (isset($row['member_ip'])) |
|
1281 | - $row['member_ip'] = inet_dtop($row['member_ip']); |
|
1282 | - if (isset($row['member_ip2'])) |
|
1283 | - $row['member_ip2'] = inet_dtop($row['member_ip2']); |
|
1333 | + if (isset($row['member_ip'])) { |
|
1334 | + $row['member_ip'] = inet_dtop($row['member_ip']); |
|
1335 | + } |
|
1336 | + if (isset($row['member_ip2'])) { |
|
1337 | + $row['member_ip2'] = inet_dtop($row['member_ip2']); |
|
1338 | + } |
|
1284 | 1339 | $new_loaded_ids[] = $row['id_member']; |
1285 | 1340 | $loaded_ids[] = $row['id_member']; |
1286 | 1341 | $row['options'] = array(); |
@@ -1299,8 +1354,9 @@ discard block |
||
1299 | 1354 | 'loaded_ids' => $new_loaded_ids, |
1300 | 1355 | ) |
1301 | 1356 | ); |
1302 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1303 | - $user_profile[$row['id_member']]['options'][$row['variable']] = $row['value']; |
|
1357 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1358 | + $user_profile[$row['id_member']]['options'][$row['variable']] = $row['value']; |
|
1359 | + } |
|
1304 | 1360 | $smcFunc['db_free_result']($request); |
1305 | 1361 | } |
1306 | 1362 | |
@@ -1311,10 +1367,11 @@ discard block |
||
1311 | 1367 | { |
1312 | 1368 | foreach ($loaded_ids as $a_member) |
1313 | 1369 | { |
1314 | - if (!empty($user_profile[$a_member]['additional_groups'])) |
|
1315 | - $groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups'])); |
|
1316 | - else |
|
1317 | - $groups = array($user_profile[$a_member]['id_group']); |
|
1370 | + if (!empty($user_profile[$a_member]['additional_groups'])) { |
|
1371 | + $groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups'])); |
|
1372 | + } else { |
|
1373 | + $groups = array($user_profile[$a_member]['id_group']); |
|
1374 | + } |
|
1318 | 1375 | |
1319 | 1376 | $temp = array_intersect($groups, array_keys($board_info['moderator_groups'])); |
1320 | 1377 | |
@@ -1327,8 +1384,9 @@ discard block |
||
1327 | 1384 | |
1328 | 1385 | if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3) |
1329 | 1386 | { |
1330 | - for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) |
|
1331 | - cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240); |
|
1387 | + for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) { |
|
1388 | + cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240); |
|
1389 | + } |
|
1332 | 1390 | } |
1333 | 1391 | |
1334 | 1392 | // Are we loading any moderators? If so, fix their group data... |
@@ -1354,14 +1412,17 @@ discard block |
||
1354 | 1412 | foreach ($temp_mods as $id) |
1355 | 1413 | { |
1356 | 1414 | // By popular demand, don't show admins or global moderators as moderators. |
1357 | - if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) |
|
1358 | - $user_profile[$id]['member_group'] = $row['member_group']; |
|
1415 | + if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) { |
|
1416 | + $user_profile[$id]['member_group'] = $row['member_group']; |
|
1417 | + } |
|
1359 | 1418 | |
1360 | 1419 | // If the Moderator group has no color or icons, but their group does... don't overwrite. |
1361 | - if (!empty($row['icons'])) |
|
1362 | - $user_profile[$id]['icons'] = $row['icons']; |
|
1363 | - if (!empty($row['member_group_color'])) |
|
1364 | - $user_profile[$id]['member_group_color'] = $row['member_group_color']; |
|
1420 | + if (!empty($row['icons'])) { |
|
1421 | + $user_profile[$id]['icons'] = $row['icons']; |
|
1422 | + } |
|
1423 | + if (!empty($row['member_group_color'])) { |
|
1424 | + $user_profile[$id]['member_group_color'] = $row['member_group_color']; |
|
1425 | + } |
|
1365 | 1426 | } |
1366 | 1427 | } |
1367 | 1428 | |
@@ -1383,12 +1444,14 @@ discard block |
||
1383 | 1444 | static $loadedLanguages = array(); |
1384 | 1445 | |
1385 | 1446 | // If this person's data is already loaded, skip it. |
1386 | - if (isset($dataLoaded[$user])) |
|
1387 | - return true; |
|
1447 | + if (isset($dataLoaded[$user])) { |
|
1448 | + return true; |
|
1449 | + } |
|
1388 | 1450 | |
1389 | 1451 | // We can't load guests or members not loaded by loadMemberData()! |
1390 | - if ($user == 0) |
|
1391 | - return false; |
|
1452 | + if ($user == 0) { |
|
1453 | + return false; |
|
1454 | + } |
|
1392 | 1455 | if (!isset($user_profile[$user])) |
1393 | 1456 | { |
1394 | 1457 | trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING); |
@@ -1414,12 +1477,16 @@ discard block |
||
1414 | 1477 | $buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array(); |
1415 | 1478 | |
1416 | 1479 | //We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme |
1417 | - if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists |
|
1480 | + if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) { |
|
1481 | + //icon is set and exists |
|
1418 | 1482 | $group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1]; |
1419 | - elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default |
|
1483 | + } elseif (isset($profile['icons'][1])) { |
|
1484 | + //icon is set and doesn't exist, fallback to default |
|
1420 | 1485 | $group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1]; |
1421 | - else //not set, bye bye |
|
1486 | + } else { |
|
1487 | + //not set, bye bye |
|
1422 | 1488 | $group_icon_url = ''; |
1489 | + } |
|
1423 | 1490 | |
1424 | 1491 | // These minimal values are always loaded |
1425 | 1492 | $memberContext[$user] = array( |
@@ -1438,8 +1505,9 @@ discard block |
||
1438 | 1505 | if ($context['loadMemberContext_set'] != 'minimal') |
1439 | 1506 | { |
1440 | 1507 | // Go the extra mile and load the user's native language name. |
1441 | - if (empty($loadedLanguages)) |
|
1442 | - $loadedLanguages = getLanguages(); |
|
1508 | + if (empty($loadedLanguages)) { |
|
1509 | + $loadedLanguages = getLanguages(); |
|
1510 | + } |
|
1443 | 1511 | |
1444 | 1512 | $memberContext[$user] += array( |
1445 | 1513 | 'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>', |
@@ -1494,31 +1562,33 @@ discard block |
||
1494 | 1562 | { |
1495 | 1563 | if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://'))) |
1496 | 1564 | { |
1497 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) |
|
1498 | - $image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11)); |
|
1499 | - else |
|
1500 | - $image = get_gravatar_url($profile['email_address']); |
|
1501 | - } |
|
1502 | - else |
|
1565 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) { |
|
1566 | + $image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11)); |
|
1567 | + } else { |
|
1568 | + $image = get_gravatar_url($profile['email_address']); |
|
1569 | + } |
|
1570 | + } else |
|
1503 | 1571 | { |
1504 | 1572 | // So it's stored in the member table? |
1505 | 1573 | if (!empty($profile['avatar'])) |
1506 | 1574 | { |
1507 | 1575 | $image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar']; |
1576 | + } elseif (!empty($profile['filename'])) { |
|
1577 | + $image = $modSettings['custom_avatar_url'] . '/' . $profile['filename']; |
|
1508 | 1578 | } |
1509 | - elseif (!empty($profile['filename'])) |
|
1510 | - $image = $modSettings['custom_avatar_url'] . '/' . $profile['filename']; |
|
1511 | 1579 | // Right... no avatar...use the default one |
1512 | - else |
|
1513 | - $image = $modSettings['avatar_url'] . '/default.png'; |
|
1580 | + else { |
|
1581 | + $image = $modSettings['avatar_url'] . '/default.png'; |
|
1582 | + } |
|
1514 | 1583 | } |
1515 | - if (!empty($image)) |
|
1516 | - $memberContext[$user]['avatar'] = array( |
|
1584 | + if (!empty($image)) { |
|
1585 | + $memberContext[$user]['avatar'] = array( |
|
1517 | 1586 | 'name' => $profile['avatar'], |
1518 | 1587 | 'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">', |
1519 | 1588 | 'href' => $image, |
1520 | 1589 | 'url' => $image, |
1521 | 1590 | ); |
1591 | + } |
|
1522 | 1592 | } |
1523 | 1593 | |
1524 | 1594 | // Are we also loading the members custom fields into context? |
@@ -1526,13 +1596,15 @@ discard block |
||
1526 | 1596 | { |
1527 | 1597 | $memberContext[$user]['custom_fields'] = array(); |
1528 | 1598 | |
1529 | - if (!isset($context['display_fields'])) |
|
1530 | - $context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true); |
|
1599 | + if (!isset($context['display_fields'])) { |
|
1600 | + $context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true); |
|
1601 | + } |
|
1531 | 1602 | |
1532 | 1603 | foreach ($context['display_fields'] as $custom) |
1533 | 1604 | { |
1534 | - if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) |
|
1535 | - continue; |
|
1605 | + if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) { |
|
1606 | + continue; |
|
1607 | + } |
|
1536 | 1608 | |
1537 | 1609 | $value = $profile['options'][$custom['col_name']]; |
1538 | 1610 | |
@@ -1540,31 +1612,36 @@ discard block |
||
1540 | 1612 | $currentKey = 0; |
1541 | 1613 | |
1542 | 1614 | // Create a key => value array for multiple options fields |
1543 | - if (!empty($custom['options'])) |
|
1544 | - foreach ($custom['options'] as $k => $v) |
|
1615 | + if (!empty($custom['options'])) { |
|
1616 | + foreach ($custom['options'] as $k => $v) |
|
1545 | 1617 | { |
1546 | 1618 | $fieldOptions[] = $v; |
1547 | - if (empty($currentKey)) |
|
1548 | - $currentKey = $v == $value ? $k : 0; |
|
1619 | + } |
|
1620 | + if (empty($currentKey)) { |
|
1621 | + $currentKey = $v == $value ? $k : 0; |
|
1622 | + } |
|
1549 | 1623 | } |
1550 | 1624 | |
1551 | 1625 | // BBC? |
1552 | - if ($custom['bbc']) |
|
1553 | - $value = parse_bbc($value); |
|
1626 | + if ($custom['bbc']) { |
|
1627 | + $value = parse_bbc($value); |
|
1628 | + } |
|
1554 | 1629 | |
1555 | 1630 | // ... or checkbox? |
1556 | - elseif (isset($custom['type']) && $custom['type'] == 'check') |
|
1557 | - $value = $value ? $txt['yes'] : $txt['no']; |
|
1631 | + elseif (isset($custom['type']) && $custom['type'] == 'check') { |
|
1632 | + $value = $value ? $txt['yes'] : $txt['no']; |
|
1633 | + } |
|
1558 | 1634 | |
1559 | 1635 | // Enclosing the user input within some other text? |
1560 | - if (!empty($custom['enclose'])) |
|
1561 | - $value = strtr($custom['enclose'], array( |
|
1636 | + if (!empty($custom['enclose'])) { |
|
1637 | + $value = strtr($custom['enclose'], array( |
|
1562 | 1638 | '{SCRIPTURL}' => $scripturl, |
1563 | 1639 | '{IMAGES_URL}' => $settings['images_url'], |
1564 | 1640 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
1565 | 1641 | '{INPUT}' => $value, |
1566 | 1642 | '{KEY}' => $currentKey, |
1567 | 1643 | )); |
1644 | + } |
|
1568 | 1645 | |
1569 | 1646 | $memberContext[$user]['custom_fields'][] = array( |
1570 | 1647 | 'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'], |
@@ -1591,8 +1668,9 @@ discard block |
||
1591 | 1668 | global $smcFunc, $txt, $scripturl, $settings; |
1592 | 1669 | |
1593 | 1670 | // Do not waste my time... |
1594 | - if (empty($users) || empty($params)) |
|
1595 | - return false; |
|
1671 | + if (empty($users) || empty($params)) { |
|
1672 | + return false; |
|
1673 | + } |
|
1596 | 1674 | |
1597 | 1675 | // Make sure it's an array. |
1598 | 1676 | $users = !is_array($users) ? array($users) : array_unique($users); |
@@ -1619,41 +1697,48 @@ discard block |
||
1619 | 1697 | $currentKey = 0; |
1620 | 1698 | |
1621 | 1699 | // Create a key => value array for multiple options fields |
1622 | - if (!empty($row['field_options'])) |
|
1623 | - foreach (explode(',', $row['field_options']) as $k => $v) |
|
1700 | + if (!empty($row['field_options'])) { |
|
1701 | + foreach (explode(',', $row['field_options']) as $k => $v) |
|
1624 | 1702 | { |
1625 | 1703 | $fieldOptions[] = $v; |
1626 | - if (empty($currentKey)) |
|
1627 | - $currentKey = $v == $row['value'] ? $k : 0; |
|
1704 | + } |
|
1705 | + if (empty($currentKey)) { |
|
1706 | + $currentKey = $v == $row['value'] ? $k : 0; |
|
1707 | + } |
|
1628 | 1708 | } |
1629 | 1709 | |
1630 | 1710 | // BBC? |
1631 | - if (!empty($row['bbc'])) |
|
1632 | - $row['value'] = parse_bbc($row['value']); |
|
1711 | + if (!empty($row['bbc'])) { |
|
1712 | + $row['value'] = parse_bbc($row['value']); |
|
1713 | + } |
|
1633 | 1714 | |
1634 | 1715 | // ... or checkbox? |
1635 | - elseif (isset($row['type']) && $row['type'] == 'check') |
|
1636 | - $row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no']; |
|
1716 | + elseif (isset($row['type']) && $row['type'] == 'check') { |
|
1717 | + $row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no']; |
|
1718 | + } |
|
1637 | 1719 | |
1638 | 1720 | // Enclosing the user input within some other text? |
1639 | - if (!empty($row['enclose'])) |
|
1640 | - $row['value'] = strtr($row['enclose'], array( |
|
1721 | + if (!empty($row['enclose'])) { |
|
1722 | + $row['value'] = strtr($row['enclose'], array( |
|
1641 | 1723 | '{SCRIPTURL}' => $scripturl, |
1642 | 1724 | '{IMAGES_URL}' => $settings['images_url'], |
1643 | 1725 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
1644 | 1726 | '{INPUT}' => un_htmlspecialchars($row['value']), |
1645 | 1727 | '{KEY}' => $currentKey, |
1646 | 1728 | )); |
1729 | + } |
|
1647 | 1730 | |
1648 | 1731 | // Send a simple array if there is just 1 param |
1649 | - if (count($params) == 1) |
|
1650 | - $return[$row['id_member']] = $row; |
|
1732 | + if (count($params) == 1) { |
|
1733 | + $return[$row['id_member']] = $row; |
|
1734 | + } |
|
1651 | 1735 | |
1652 | 1736 | // More than 1? knock yourself out... |
1653 | 1737 | else |
1654 | 1738 | { |
1655 | - if (!isset($return[$row['id_member']])) |
|
1656 | - $return[$row['id_member']] = array(); |
|
1739 | + if (!isset($return[$row['id_member']])) { |
|
1740 | + $return[$row['id_member']] = array(); |
|
1741 | + } |
|
1657 | 1742 | |
1658 | 1743 | $return[$row['id_member']][$row['variable']] = $row; |
1659 | 1744 | } |
@@ -1687,8 +1772,9 @@ discard block |
||
1687 | 1772 | global $context; |
1688 | 1773 | |
1689 | 1774 | // Don't know any browser! |
1690 | - if (empty($context['browser'])) |
|
1691 | - detectBrowser(); |
|
1775 | + if (empty($context['browser'])) { |
|
1776 | + detectBrowser(); |
|
1777 | + } |
|
1692 | 1778 | |
1693 | 1779 | return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false; |
1694 | 1780 | } |
@@ -1706,8 +1792,9 @@ discard block |
||
1706 | 1792 | global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled; |
1707 | 1793 | |
1708 | 1794 | // The theme was specified by parameter. |
1709 | - if (!empty($id_theme)) |
|
1710 | - $id_theme = (int) $id_theme; |
|
1795 | + if (!empty($id_theme)) { |
|
1796 | + $id_theme = (int) $id_theme; |
|
1797 | + } |
|
1711 | 1798 | // The theme was specified by REQUEST. |
1712 | 1799 | elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) |
1713 | 1800 | { |
@@ -1715,54 +1802,61 @@ discard block |
||
1715 | 1802 | $_SESSION['id_theme'] = $id_theme; |
1716 | 1803 | } |
1717 | 1804 | // The theme was specified by REQUEST... previously. |
1718 | - elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) |
|
1719 | - $id_theme = (int) $_SESSION['id_theme']; |
|
1805 | + elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) { |
|
1806 | + $id_theme = (int) $_SESSION['id_theme']; |
|
1807 | + } |
|
1720 | 1808 | // The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.) |
1721 | - elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) |
|
1722 | - $id_theme = $user_info['theme']; |
|
1809 | + elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) { |
|
1810 | + $id_theme = $user_info['theme']; |
|
1811 | + } |
|
1723 | 1812 | // The theme was specified by the board. |
1724 | - elseif (!empty($board_info['theme'])) |
|
1725 | - $id_theme = $board_info['theme']; |
|
1813 | + elseif (!empty($board_info['theme'])) { |
|
1814 | + $id_theme = $board_info['theme']; |
|
1815 | + } |
|
1726 | 1816 | // The theme is the forum's default. |
1727 | - else |
|
1728 | - $id_theme = $modSettings['theme_guests']; |
|
1817 | + else { |
|
1818 | + $id_theme = $modSettings['theme_guests']; |
|
1819 | + } |
|
1729 | 1820 | |
1730 | 1821 | // We already load the basic stuff? |
1731 | 1822 | if (empty($settings['theme_id']) || $settings['theme_id'] != $id_theme ) |
1732 | 1823 | { |
1733 | 1824 | // Verify the id_theme... no foul play. |
1734 | 1825 | // Always allow the board specific theme, if they are overriding. |
1735 | - if (!empty($board_info['theme']) && $board_info['override_theme']) |
|
1736 | - $id_theme = $board_info['theme']; |
|
1826 | + if (!empty($board_info['theme']) && $board_info['override_theme']) { |
|
1827 | + $id_theme = $board_info['theme']; |
|
1828 | + } |
|
1737 | 1829 | // If they have specified a particular theme to use with SSI allow it to be used. |
1738 | - elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) |
|
1739 | - $id_theme = (int) $id_theme; |
|
1740 | - elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum')) |
|
1830 | + elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) { |
|
1831 | + $id_theme = (int) $id_theme; |
|
1832 | + } elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum')) |
|
1741 | 1833 | { |
1742 | 1834 | $themes = explode(',', $modSettings['enableThemes']); |
1743 | - if (!in_array($id_theme, $themes)) |
|
1744 | - $id_theme = $modSettings['theme_guests']; |
|
1745 | - else |
|
1746 | - $id_theme = (int) $id_theme; |
|
1835 | + if (!in_array($id_theme, $themes)) { |
|
1836 | + $id_theme = $modSettings['theme_guests']; |
|
1837 | + } else { |
|
1838 | + $id_theme = (int) $id_theme; |
|
1839 | + } |
|
1840 | + } else { |
|
1841 | + $id_theme = (int) $id_theme; |
|
1747 | 1842 | } |
1748 | - else |
|
1749 | - $id_theme = (int) $id_theme; |
|
1750 | 1843 | |
1751 | 1844 | $member = empty($user_info['id']) ? -1 : $user_info['id']; |
1752 | 1845 | |
1753 | 1846 | // Disable image proxy if we don't have SSL enabled |
1754 | - if (empty($modSettings['force_ssl'])) |
|
1755 | - $image_proxy_enabled = false; |
|
1847 | + if (empty($modSettings['force_ssl'])) { |
|
1848 | + $image_proxy_enabled = false; |
|
1849 | + } |
|
1756 | 1850 | |
1757 | 1851 | if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && ($temp = cache_get_data('theme_settings-' . $id_theme . ':' . $member, 60)) != null && time() - 60 > $modSettings['settings_updated']) |
1758 | 1852 | { |
1759 | 1853 | $themeData = $temp; |
1760 | 1854 | $flag = true; |
1855 | + } elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) { |
|
1856 | + $themeData = $temp + array($member => array()); |
|
1857 | + } else { |
|
1858 | + $themeData = array(-1 => array(), 0 => array(), $member => array()); |
|
1761 | 1859 | } |
1762 | - elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) |
|
1763 | - $themeData = $temp + array($member => array()); |
|
1764 | - else |
|
1765 | - $themeData = array(-1 => array(), 0 => array(), $member => array()); |
|
1766 | 1860 | |
1767 | 1861 | if (empty($flag)) |
1768 | 1862 | { |
@@ -1781,31 +1875,37 @@ discard block |
||
1781 | 1875 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
1782 | 1876 | { |
1783 | 1877 | // There are just things we shouldn't be able to change as members. |
1784 | - if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) |
|
1785 | - continue; |
|
1878 | + if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) { |
|
1879 | + continue; |
|
1880 | + } |
|
1786 | 1881 | |
1787 | 1882 | // If this is the theme_dir of the default theme, store it. |
1788 | - if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) |
|
1789 | - $themeData[0]['default_' . $row['variable']] = $row['value']; |
|
1883 | + if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) { |
|
1884 | + $themeData[0]['default_' . $row['variable']] = $row['value']; |
|
1885 | + } |
|
1790 | 1886 | |
1791 | 1887 | // If this isn't set yet, is a theme option, or is not the default theme.. |
1792 | - if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') |
|
1793 | - $themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value']; |
|
1888 | + if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') { |
|
1889 | + $themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value']; |
|
1890 | + } |
|
1794 | 1891 | } |
1795 | 1892 | $smcFunc['db_free_result']($result); |
1796 | 1893 | |
1797 | - if (!empty($themeData[-1])) |
|
1798 | - foreach ($themeData[-1] as $k => $v) |
|
1894 | + if (!empty($themeData[-1])) { |
|
1895 | + foreach ($themeData[-1] as $k => $v) |
|
1799 | 1896 | { |
1800 | 1897 | if (!isset($themeData[$member][$k])) |
1801 | 1898 | $themeData[$member][$k] = $v; |
1899 | + } |
|
1802 | 1900 | } |
1803 | 1901 | |
1804 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
1805 | - cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60); |
|
1902 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
1903 | + cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60); |
|
1904 | + } |
|
1806 | 1905 | // Only if we didn't already load that part of the cache... |
1807 | - elseif (!isset($temp)) |
|
1808 | - cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90); |
|
1906 | + elseif (!isset($temp)) { |
|
1907 | + cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90); |
|
1908 | + } |
|
1809 | 1909 | } |
1810 | 1910 | |
1811 | 1911 | $settings = $themeData[0]; |
@@ -1822,17 +1922,20 @@ discard block |
||
1822 | 1922 | $settings['template_dirs'][] = $settings['theme_dir']; |
1823 | 1923 | |
1824 | 1924 | // Based on theme (if there is one). |
1825 | - if (!empty($settings['base_theme_dir'])) |
|
1826 | - $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
1925 | + if (!empty($settings['base_theme_dir'])) { |
|
1926 | + $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
1927 | + } |
|
1827 | 1928 | |
1828 | 1929 | // Lastly the default theme. |
1829 | - if ($settings['theme_dir'] != $settings['default_theme_dir']) |
|
1830 | - $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
1930 | + if ($settings['theme_dir'] != $settings['default_theme_dir']) { |
|
1931 | + $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
1932 | + } |
|
1831 | 1933 | } |
1832 | 1934 | |
1833 | 1935 | |
1834 | - if (!$initialize) |
|
1835 | - return; |
|
1936 | + if (!$initialize) { |
|
1937 | + return; |
|
1938 | + } |
|
1836 | 1939 | |
1837 | 1940 | // Check to see if we're forcing SSL |
1838 | 1941 | if (!empty($modSettings['force_ssl']) && empty($maintenance) && |
@@ -1853,8 +1956,9 @@ discard block |
||
1853 | 1956 | $detected_url = httpsOn() ? 'https://' : 'http://'; |
1854 | 1957 | $detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST']; |
1855 | 1958 | $temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/')); |
1856 | - if ($temp != '/') |
|
1857 | - $detected_url .= $temp; |
|
1959 | + if ($temp != '/') { |
|
1960 | + $detected_url .= $temp; |
|
1961 | + } |
|
1858 | 1962 | } |
1859 | 1963 | if (isset($detected_url) && $detected_url != $boardurl) |
1860 | 1964 | { |
@@ -1866,8 +1970,9 @@ discard block |
||
1866 | 1970 | foreach ($aliases as $alias) |
1867 | 1971 | { |
1868 | 1972 | // Rip off all the boring parts, spaces, etc. |
1869 | - if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) |
|
1870 | - $do_fix = true; |
|
1973 | + if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) { |
|
1974 | + $do_fix = true; |
|
1975 | + } |
|
1871 | 1976 | } |
1872 | 1977 | } |
1873 | 1978 | |
@@ -1875,21 +1980,23 @@ discard block |
||
1875 | 1980 | if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI') |
1876 | 1981 | { |
1877 | 1982 | // Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;). |
1878 | - if (empty($_GET)) |
|
1879 | - redirectexit('wwwRedirect'); |
|
1880 | - else |
|
1983 | + if (empty($_GET)) { |
|
1984 | + redirectexit('wwwRedirect'); |
|
1985 | + } else |
|
1881 | 1986 | { |
1882 | 1987 | $k = key($_GET); |
1883 | 1988 | $v = current($_GET); |
1884 | 1989 | |
1885 | - if ($k != 'wwwRedirect') |
|
1886 | - redirectexit('wwwRedirect;' . $k . '=' . $v); |
|
1990 | + if ($k != 'wwwRedirect') { |
|
1991 | + redirectexit('wwwRedirect;' . $k . '=' . $v); |
|
1992 | + } |
|
1887 | 1993 | } |
1888 | 1994 | } |
1889 | 1995 | |
1890 | 1996 | // #3 is just a check for SSL... |
1891 | - if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) |
|
1892 | - $do_fix = true; |
|
1997 | + if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) { |
|
1998 | + $do_fix = true; |
|
1999 | + } |
|
1893 | 2000 | |
1894 | 2001 | // Okay, #4 - perhaps it's an IP address? We're gonna want to use that one, then. (assuming it's the IP or something...) |
1895 | 2002 | if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1) |
@@ -1924,8 +2031,9 @@ discard block |
||
1924 | 2031 | $board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl)); |
1925 | 2032 | } |
1926 | 2033 | } |
1927 | - foreach ($context['linktree'] as $k => $dummy) |
|
1928 | - $context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl)); |
|
2034 | + foreach ($context['linktree'] as $k => $dummy) { |
|
2035 | + $context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl)); |
|
2036 | + } |
|
1929 | 2037 | } |
1930 | 2038 | } |
1931 | 2039 | // Set up the contextual user array. |
@@ -1944,16 +2052,16 @@ discard block |
||
1944 | 2052 | 'email' => $user_info['email'], |
1945 | 2053 | 'ignoreusers' => $user_info['ignoreusers'], |
1946 | 2054 | ); |
1947 | - if (!$context['user']['is_guest']) |
|
1948 | - $context['user']['name'] = $user_info['name']; |
|
1949 | - elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) |
|
1950 | - $context['user']['name'] = $txt['guest_title']; |
|
2055 | + if (!$context['user']['is_guest']) { |
|
2056 | + $context['user']['name'] = $user_info['name']; |
|
2057 | + } elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) { |
|
2058 | + $context['user']['name'] = $txt['guest_title']; |
|
2059 | + } |
|
1951 | 2060 | |
1952 | 2061 | // Determine the current smiley set. |
1953 | 2062 | $user_info['smiley_set'] = (!in_array($user_info['smiley_set'], explode(',', $modSettings['smiley_sets_known'])) && $user_info['smiley_set'] != 'none') || empty($modSettings['smiley_sets_enable']) ? (!empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default']) : $user_info['smiley_set']; |
1954 | 2063 | $context['user']['smiley_set'] = $user_info['smiley_set']; |
1955 | - } |
|
1956 | - else |
|
2064 | + } else |
|
1957 | 2065 | { |
1958 | 2066 | // What to do when there is no $user_info (e.g., an error very early in the login process) |
1959 | 2067 | $context['user'] = array( |
@@ -1987,18 +2095,24 @@ discard block |
||
1987 | 2095 | } |
1988 | 2096 | |
1989 | 2097 | // Some basic information... |
1990 | - if (!isset($context['html_headers'])) |
|
1991 | - $context['html_headers'] = ''; |
|
1992 | - if (!isset($context['javascript_files'])) |
|
1993 | - $context['javascript_files'] = array(); |
|
1994 | - if (!isset($context['css_files'])) |
|
1995 | - $context['css_files'] = array(); |
|
1996 | - if (!isset($context['css_header'])) |
|
1997 | - $context['css_header'] = array(); |
|
1998 | - if (!isset($context['javascript_inline'])) |
|
1999 | - $context['javascript_inline'] = array('standard' => array(), 'defer' => array()); |
|
2000 | - if (!isset($context['javascript_vars'])) |
|
2001 | - $context['javascript_vars'] = array(); |
|
2098 | + if (!isset($context['html_headers'])) { |
|
2099 | + $context['html_headers'] = ''; |
|
2100 | + } |
|
2101 | + if (!isset($context['javascript_files'])) { |
|
2102 | + $context['javascript_files'] = array(); |
|
2103 | + } |
|
2104 | + if (!isset($context['css_files'])) { |
|
2105 | + $context['css_files'] = array(); |
|
2106 | + } |
|
2107 | + if (!isset($context['css_header'])) { |
|
2108 | + $context['css_header'] = array(); |
|
2109 | + } |
|
2110 | + if (!isset($context['javascript_inline'])) { |
|
2111 | + $context['javascript_inline'] = array('standard' => array(), 'defer' => array()); |
|
2112 | + } |
|
2113 | + if (!isset($context['javascript_vars'])) { |
|
2114 | + $context['javascript_vars'] = array(); |
|
2115 | + } |
|
2002 | 2116 | |
2003 | 2117 | $context['login_url'] = $scripturl . '?action=login2'; |
2004 | 2118 | $context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | '; |
@@ -2010,16 +2124,18 @@ discard block |
||
2010 | 2124 | $context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null; |
2011 | 2125 | $context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null; |
2012 | 2126 | $context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3; |
2013 | - if (isset($modSettings['load_average'])) |
|
2014 | - $context['load_average'] = $modSettings['load_average']; |
|
2127 | + if (isset($modSettings['load_average'])) { |
|
2128 | + $context['load_average'] = $modSettings['load_average']; |
|
2129 | + } |
|
2015 | 2130 | |
2016 | 2131 | // Detect the browser. This is separated out because it's also used in attachment downloads |
2017 | 2132 | detectBrowser(); |
2018 | 2133 | |
2019 | 2134 | // Set the top level linktree up. |
2020 | 2135 | // Note that if we're dealing with certain very early errors (e.g., login) the linktree might not be set yet... |
2021 | - if (empty($context['linktree'])) |
|
2022 | - $context['linktree'] = array(); |
|
2136 | + if (empty($context['linktree'])) { |
|
2137 | + $context['linktree'] = array(); |
|
2138 | + } |
|
2023 | 2139 | array_unshift($context['linktree'], array( |
2024 | 2140 | 'url' => $scripturl, |
2025 | 2141 | 'name' => $context['forum_name_html_safe'] |
@@ -2028,8 +2144,9 @@ discard block |
||
2028 | 2144 | // This allows sticking some HTML on the page output - useful for controls. |
2029 | 2145 | $context['insert_after_template'] = ''; |
2030 | 2146 | |
2031 | - if (!isset($txt)) |
|
2032 | - $txt = array(); |
|
2147 | + if (!isset($txt)) { |
|
2148 | + $txt = array(); |
|
2149 | + } |
|
2033 | 2150 | |
2034 | 2151 | $simpleActions = array( |
2035 | 2152 | 'findmember', |
@@ -2075,9 +2192,10 @@ discard block |
||
2075 | 2192 | |
2076 | 2193 | // See if theres any extra param to check. |
2077 | 2194 | $requiresXML = false; |
2078 | - foreach ($extraParams as $key => $extra) |
|
2079 | - if (isset($_REQUEST[$extra])) |
|
2195 | + foreach ($extraParams as $key => $extra) { |
|
2196 | + if (isset($_REQUEST[$extra])) |
|
2080 | 2197 | $requiresXML = true; |
2198 | + } |
|
2081 | 2199 | |
2082 | 2200 | // Output is fully XML, so no need for the index template. |
2083 | 2201 | if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML)) |
@@ -2092,37 +2210,39 @@ discard block |
||
2092 | 2210 | { |
2093 | 2211 | loadLanguage('index+Modifications'); |
2094 | 2212 | $context['template_layers'] = array(); |
2095 | - } |
|
2096 | - |
|
2097 | - else |
|
2213 | + } else |
|
2098 | 2214 | { |
2099 | 2215 | // Custom templates to load, or just default? |
2100 | - if (isset($settings['theme_templates'])) |
|
2101 | - $templates = explode(',', $settings['theme_templates']); |
|
2102 | - else |
|
2103 | - $templates = array('index'); |
|
2216 | + if (isset($settings['theme_templates'])) { |
|
2217 | + $templates = explode(',', $settings['theme_templates']); |
|
2218 | + } else { |
|
2219 | + $templates = array('index'); |
|
2220 | + } |
|
2104 | 2221 | |
2105 | 2222 | // Load each template... |
2106 | - foreach ($templates as $template) |
|
2107 | - loadTemplate($template); |
|
2223 | + foreach ($templates as $template) { |
|
2224 | + loadTemplate($template); |
|
2225 | + } |
|
2108 | 2226 | |
2109 | 2227 | // ...and attempt to load their associated language files. |
2110 | 2228 | $required_files = implode('+', array_merge($templates, array('Modifications'))); |
2111 | 2229 | loadLanguage($required_files, '', false); |
2112 | 2230 | |
2113 | 2231 | // Custom template layers? |
2114 | - if (isset($settings['theme_layers'])) |
|
2115 | - $context['template_layers'] = explode(',', $settings['theme_layers']); |
|
2116 | - else |
|
2117 | - $context['template_layers'] = array('html', 'body'); |
|
2232 | + if (isset($settings['theme_layers'])) { |
|
2233 | + $context['template_layers'] = explode(',', $settings['theme_layers']); |
|
2234 | + } else { |
|
2235 | + $context['template_layers'] = array('html', 'body'); |
|
2236 | + } |
|
2118 | 2237 | } |
2119 | 2238 | |
2120 | 2239 | // Initialize the theme. |
2121 | 2240 | loadSubTemplate('init', 'ignore'); |
2122 | 2241 | |
2123 | 2242 | // Allow overriding the board wide time/number formats. |
2124 | - if (empty($user_settings['time_format']) && !empty($txt['time_format'])) |
|
2125 | - $user_info['time_format'] = $txt['time_format']; |
|
2243 | + if (empty($user_settings['time_format']) && !empty($txt['time_format'])) { |
|
2244 | + $user_info['time_format'] = $txt['time_format']; |
|
2245 | + } |
|
2126 | 2246 | |
2127 | 2247 | // Set the character set from the template. |
2128 | 2248 | $context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']; |
@@ -2130,12 +2250,14 @@ discard block |
||
2130 | 2250 | $context['right_to_left'] = !empty($txt['lang_rtl']); |
2131 | 2251 | |
2132 | 2252 | // Guests may still need a name. |
2133 | - if ($context['user']['is_guest'] && empty($context['user']['name'])) |
|
2134 | - $context['user']['name'] = $txt['guest_title']; |
|
2253 | + if ($context['user']['is_guest'] && empty($context['user']['name'])) { |
|
2254 | + $context['user']['name'] = $txt['guest_title']; |
|
2255 | + } |
|
2135 | 2256 | |
2136 | 2257 | // Any theme-related strings that need to be loaded? |
2137 | - if (!empty($settings['require_theme_strings'])) |
|
2138 | - loadLanguage('ThemeStrings', '', false); |
|
2258 | + if (!empty($settings['require_theme_strings'])) { |
|
2259 | + loadLanguage('ThemeStrings', '', false); |
|
2260 | + } |
|
2139 | 2261 | |
2140 | 2262 | // Make a special URL for the language. |
2141 | 2263 | $settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']); |
@@ -2146,8 +2268,9 @@ discard block |
||
2146 | 2268 | // Here is my luvly Responsive CSS |
2147 | 2269 | loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true, 'order_pos' => 9000), 'smf_responsive'); |
2148 | 2270 | |
2149 | - if ($context['right_to_left']) |
|
2150 | - loadCSSFile('rtl.css', array('order_pos' => 200), 'smf_rtl'); |
|
2271 | + if ($context['right_to_left']) { |
|
2272 | + loadCSSFile('rtl.css', array('order_pos' => 200), 'smf_rtl'); |
|
2273 | + } |
|
2151 | 2274 | |
2152 | 2275 | // We allow theme variants, because we're cool. |
2153 | 2276 | $context['theme_variant'] = ''; |
@@ -2155,14 +2278,17 @@ discard block |
||
2155 | 2278 | if (!empty($settings['theme_variants'])) |
2156 | 2279 | { |
2157 | 2280 | // Overriding - for previews and that ilk. |
2158 | - if (!empty($_REQUEST['variant'])) |
|
2159 | - $_SESSION['id_variant'] = $_REQUEST['variant']; |
|
2281 | + if (!empty($_REQUEST['variant'])) { |
|
2282 | + $_SESSION['id_variant'] = $_REQUEST['variant']; |
|
2283 | + } |
|
2160 | 2284 | // User selection? |
2161 | - if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) |
|
2162 | - $context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : ''); |
|
2285 | + if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) { |
|
2286 | + $context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : ''); |
|
2287 | + } |
|
2163 | 2288 | // If not a user variant, select the default. |
2164 | - if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) |
|
2165 | - $context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0]; |
|
2289 | + if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) { |
|
2290 | + $context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0]; |
|
2291 | + } |
|
2166 | 2292 | |
2167 | 2293 | // Do this to keep things easier in the templates. |
2168 | 2294 | $context['theme_variant'] = '_' . $context['theme_variant']; |
@@ -2171,20 +2297,23 @@ discard block |
||
2171 | 2297 | if (!empty($context['theme_variant'])) |
2172 | 2298 | { |
2173 | 2299 | loadCSSFile('index' . $context['theme_variant'] . '.css', array('order_pos' => 300), 'smf_index' . $context['theme_variant']); |
2174 | - if ($context['right_to_left']) |
|
2175 | - loadCSSFile('rtl' . $context['theme_variant'] . '.css', array('order_pos' => 400), 'smf_rtl' . $context['theme_variant']); |
|
2300 | + if ($context['right_to_left']) { |
|
2301 | + loadCSSFile('rtl' . $context['theme_variant'] . '.css', array('order_pos' => 400), 'smf_rtl' . $context['theme_variant']); |
|
2302 | + } |
|
2176 | 2303 | } |
2177 | 2304 | } |
2178 | 2305 | |
2179 | 2306 | // Let's be compatible with old themes! |
2180 | - if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) |
|
2181 | - $context['template_layers'] = array('main'); |
|
2307 | + if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) { |
|
2308 | + $context['template_layers'] = array('main'); |
|
2309 | + } |
|
2182 | 2310 | |
2183 | 2311 | $context['tabindex'] = 1; |
2184 | 2312 | |
2185 | 2313 | // Compatibility. |
2186 | - if (!isset($settings['theme_version'])) |
|
2187 | - $modSettings['memberCount'] = $modSettings['totalMembers']; |
|
2314 | + if (!isset($settings['theme_version'])) { |
|
2315 | + $modSettings['memberCount'] = $modSettings['totalMembers']; |
|
2316 | + } |
|
2188 | 2317 | |
2189 | 2318 | // Default JS variables for use in every theme |
2190 | 2319 | $context['javascript_vars'] = array( |
@@ -2203,18 +2332,18 @@ discard block |
||
2203 | 2332 | ); |
2204 | 2333 | |
2205 | 2334 | // Add the JQuery library to the list of files to load. |
2206 | - if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') |
|
2207 | - loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
2208 | - |
|
2209 | - elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') |
|
2210 | - loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery'); |
|
2211 | - |
|
2212 | - elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') |
|
2213 | - loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery'); |
|
2335 | + if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') { |
|
2336 | + loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
2337 | + } elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') { |
|
2338 | + loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery'); |
|
2339 | + } elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') { |
|
2340 | + loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery'); |
|
2341 | + } |
|
2214 | 2342 | |
2215 | 2343 | // Auto loading? template_javascript() will take care of the local half of this. |
2216 | - else |
|
2217 | - loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
2344 | + else { |
|
2345 | + loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
2346 | + } |
|
2218 | 2347 | |
2219 | 2348 | // Queue our JQuery plugins! |
2220 | 2349 | loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins'); |
@@ -2237,12 +2366,12 @@ discard block |
||
2237 | 2366 | require_once($sourcedir . '/ScheduledTasks.php'); |
2238 | 2367 | |
2239 | 2368 | // What to do, what to do?! |
2240 | - if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) |
|
2241 | - AutoTask(); |
|
2242 | - else |
|
2243 | - ReduceMailQueue(); |
|
2244 | - } |
|
2245 | - else |
|
2369 | + if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) { |
|
2370 | + AutoTask(); |
|
2371 | + } else { |
|
2372 | + ReduceMailQueue(); |
|
2373 | + } |
|
2374 | + } else |
|
2246 | 2375 | { |
2247 | 2376 | $type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq'; |
2248 | 2377 | $ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time']; |
@@ -2293,8 +2422,9 @@ discard block |
||
2293 | 2422 | foreach ($theme_includes as $include) |
2294 | 2423 | { |
2295 | 2424 | $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
2296 | - if (file_exists($include)) |
|
2297 | - require_once($include); |
|
2425 | + if (file_exists($include)) { |
|
2426 | + require_once($include); |
|
2427 | + } |
|
2298 | 2428 | } |
2299 | 2429 | } |
2300 | 2430 | |
@@ -2324,16 +2454,19 @@ discard block |
||
2324 | 2454 | // Do any style sheets first, cause we're easy with those. |
2325 | 2455 | if (!empty($style_sheets)) |
2326 | 2456 | { |
2327 | - if (!is_array($style_sheets)) |
|
2328 | - $style_sheets = array($style_sheets); |
|
2457 | + if (!is_array($style_sheets)) { |
|
2458 | + $style_sheets = array($style_sheets); |
|
2459 | + } |
|
2329 | 2460 | |
2330 | - foreach ($style_sheets as $sheet) |
|
2331 | - loadCSSFile($sheet . '.css', array(), $sheet); |
|
2461 | + foreach ($style_sheets as $sheet) { |
|
2462 | + loadCSSFile($sheet . '.css', array(), $sheet); |
|
2463 | + } |
|
2332 | 2464 | } |
2333 | 2465 | |
2334 | 2466 | // No template to load? |
2335 | - if ($template_name === false) |
|
2336 | - return true; |
|
2467 | + if ($template_name === false) { |
|
2468 | + return true; |
|
2469 | + } |
|
2337 | 2470 | |
2338 | 2471 | $loaded = false; |
2339 | 2472 | foreach ($settings['template_dirs'] as $template_dir) |
@@ -2348,12 +2481,14 @@ discard block |
||
2348 | 2481 | |
2349 | 2482 | if ($loaded) |
2350 | 2483 | { |
2351 | - if ($db_show_debug === true) |
|
2352 | - $context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')'; |
|
2484 | + if ($db_show_debug === true) { |
|
2485 | + $context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')'; |
|
2486 | + } |
|
2353 | 2487 | |
2354 | 2488 | // If they have specified an initialization function for this template, go ahead and call it now. |
2355 | - if (function_exists('template_' . $template_name . '_init')) |
|
2356 | - call_user_func('template_' . $template_name . '_init'); |
|
2489 | + if (function_exists('template_' . $template_name . '_init')) { |
|
2490 | + call_user_func('template_' . $template_name . '_init'); |
|
2491 | + } |
|
2357 | 2492 | } |
2358 | 2493 | // Hmmm... doesn't exist?! I don't suppose the directory is wrong, is it? |
2359 | 2494 | elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default')) |
@@ -2373,13 +2508,14 @@ discard block |
||
2373 | 2508 | loadTemplate($template_name); |
2374 | 2509 | } |
2375 | 2510 | // Cause an error otherwise. |
2376 | - elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) |
|
2377 | - fatal_lang_error('theme_template_error', 'template', array((string) $template_name)); |
|
2378 | - elseif ($fatal) |
|
2379 | - die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template')); |
|
2380 | - else |
|
2381 | - return false; |
|
2382 | -} |
|
2511 | + elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) { |
|
2512 | + fatal_lang_error('theme_template_error', 'template', array((string) $template_name)); |
|
2513 | + } elseif ($fatal) { |
|
2514 | + die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template')); |
|
2515 | + } else { |
|
2516 | + return false; |
|
2517 | + } |
|
2518 | + } |
|
2383 | 2519 | |
2384 | 2520 | /** |
2385 | 2521 | * Load a sub-template. |
@@ -2397,17 +2533,19 @@ discard block |
||
2397 | 2533 | { |
2398 | 2534 | global $context, $txt, $db_show_debug; |
2399 | 2535 | |
2400 | - if ($db_show_debug === true) |
|
2401 | - $context['debug']['sub_templates'][] = $sub_template_name; |
|
2536 | + if ($db_show_debug === true) { |
|
2537 | + $context['debug']['sub_templates'][] = $sub_template_name; |
|
2538 | + } |
|
2402 | 2539 | |
2403 | 2540 | // Figure out what the template function is named. |
2404 | 2541 | $theme_function = 'template_' . $sub_template_name; |
2405 | - if (function_exists($theme_function)) |
|
2406 | - $theme_function(); |
|
2407 | - elseif ($fatal === false) |
|
2408 | - fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name)); |
|
2409 | - elseif ($fatal !== 'ignore') |
|
2410 | - die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template')); |
|
2542 | + if (function_exists($theme_function)) { |
|
2543 | + $theme_function(); |
|
2544 | + } elseif ($fatal === false) { |
|
2545 | + fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name)); |
|
2546 | + } elseif ($fatal !== 'ignore') { |
|
2547 | + die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template')); |
|
2548 | + } |
|
2411 | 2549 | |
2412 | 2550 | // Are we showing debugging for templates? Just make sure not to do it before the doctype... |
2413 | 2551 | if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml'])) |
@@ -2437,8 +2575,9 @@ discard block |
||
2437 | 2575 | { |
2438 | 2576 | global $settings, $context, $modSettings; |
2439 | 2577 | |
2440 | - if (empty($context['css_files_order'])) |
|
2441 | - $context['css_files_order'] = array(); |
|
2578 | + if (empty($context['css_files_order'])) { |
|
2579 | + $context['css_files_order'] = array(); |
|
2580 | + } |
|
2442 | 2581 | |
2443 | 2582 | $params['seed'] = (!array_key_exists('seed', $params) || (array_key_exists('seed', $params) && $params['seed'] === true)) ? (array_key_exists('browser_cache', $modSettings) ? $modSettings['browser_cache'] : '') : (is_string($params['seed']) ? ($params['seed'] = $params['seed'][0] === '?' ? $params['seed'] : '?' . $params['seed']) : ''); |
2444 | 2583 | $params['force_current'] = isset($params['force_current']) ? $params['force_current'] : false; |
@@ -2449,8 +2588,9 @@ discard block |
||
2449 | 2588 | $params['order_pos'] = isset($params['order_pos']) ? (int) $params['order_pos'] : 3000; |
2450 | 2589 | |
2451 | 2590 | // If this is an external file, automatically set this to false. |
2452 | - if (!empty($params['external'])) |
|
2453 | - $params['minimize'] = false; |
|
2591 | + if (!empty($params['external'])) { |
|
2592 | + $params['minimize'] = false; |
|
2593 | + } |
|
2454 | 2594 | |
2455 | 2595 | // Account for shorthand like admin.css?alp21 filenames |
2456 | 2596 | $has_seed = strpos($fileName, '.css?'); |
@@ -2467,16 +2607,12 @@ discard block |
||
2467 | 2607 | { |
2468 | 2608 | $fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
2469 | 2609 | $filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
2470 | - } |
|
2471 | - |
|
2472 | - else |
|
2610 | + } else |
|
2473 | 2611 | { |
2474 | 2612 | $fileUrl = false; |
2475 | 2613 | $filePath = false; |
2476 | 2614 | } |
2477 | - } |
|
2478 | - |
|
2479 | - else |
|
2615 | + } else |
|
2480 | 2616 | { |
2481 | 2617 | $fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
2482 | 2618 | $filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
@@ -2494,16 +2630,18 @@ discard block |
||
2494 | 2630 | if (!empty($fileName)) |
2495 | 2631 | { |
2496 | 2632 | // find a free number/position |
2497 | - while (isset($context['css_files_order'][$params['order_pos']])) |
|
2498 | - $params['order_pos']++; |
|
2633 | + while (isset($context['css_files_order'][$params['order_pos']])) { |
|
2634 | + $params['order_pos']++; |
|
2635 | + } |
|
2499 | 2636 | $context['css_files_order'][$params['order_pos']] = $id; |
2500 | 2637 | |
2501 | 2638 | $context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
2502 | 2639 | } |
2503 | 2640 | |
2504 | - if (!empty($context['right_to_left']) && !empty($params['rtl'])) |
|
2505 | - loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0))); |
|
2506 | -} |
|
2641 | + if (!empty($context['right_to_left']) && !empty($params['rtl'])) { |
|
2642 | + loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0))); |
|
2643 | + } |
|
2644 | + } |
|
2507 | 2645 | |
2508 | 2646 | /** |
2509 | 2647 | * Add a block of inline css code to be executed later |
@@ -2520,8 +2658,9 @@ discard block |
||
2520 | 2658 | global $context; |
2521 | 2659 | |
2522 | 2660 | // Gotta add something... |
2523 | - if (empty($css)) |
|
2524 | - return false; |
|
2661 | + if (empty($css)) { |
|
2662 | + return false; |
|
2663 | + } |
|
2525 | 2664 | |
2526 | 2665 | $context['css_header'][] = $css; |
2527 | 2666 | } |
@@ -2556,8 +2695,9 @@ discard block |
||
2556 | 2695 | $params['validate'] = isset($params['validate']) ? $params['validate'] : true; |
2557 | 2696 | |
2558 | 2697 | // If this is an external file, automatically set this to false. |
2559 | - if (!empty($params['external'])) |
|
2560 | - $params['minimize'] = false; |
|
2698 | + if (!empty($params['external'])) { |
|
2699 | + $params['minimize'] = false; |
|
2700 | + } |
|
2561 | 2701 | |
2562 | 2702 | // Account for shorthand like admin.js?alp21 filenames |
2563 | 2703 | $has_seed = strpos($fileName, '.js?'); |
@@ -2574,16 +2714,12 @@ discard block |
||
2574 | 2714 | { |
2575 | 2715 | $fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
2576 | 2716 | $filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
2577 | - } |
|
2578 | - |
|
2579 | - else |
|
2717 | + } else |
|
2580 | 2718 | { |
2581 | 2719 | $fileUrl = false; |
2582 | 2720 | $filePath = false; |
2583 | 2721 | } |
2584 | - } |
|
2585 | - |
|
2586 | - else |
|
2722 | + } else |
|
2587 | 2723 | { |
2588 | 2724 | $fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
2589 | 2725 | $filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
@@ -2598,9 +2734,10 @@ discard block |
||
2598 | 2734 | } |
2599 | 2735 | |
2600 | 2736 | // Add it to the array for use in the template |
2601 | - if (!empty($fileName)) |
|
2602 | - $context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
2603 | -} |
|
2737 | + if (!empty($fileName)) { |
|
2738 | + $context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
2739 | + } |
|
2740 | + } |
|
2604 | 2741 | |
2605 | 2742 | /** |
2606 | 2743 | * Add a Javascript variable for output later (for feeding text strings and similar to JS) |
@@ -2614,9 +2751,10 @@ discard block |
||
2614 | 2751 | { |
2615 | 2752 | global $context; |
2616 | 2753 | |
2617 | - if (!empty($key) && (!empty($value) || $value === '0')) |
|
2618 | - $context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value; |
|
2619 | -} |
|
2754 | + if (!empty($key) && (!empty($value) || $value === '0')) { |
|
2755 | + $context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value; |
|
2756 | + } |
|
2757 | + } |
|
2620 | 2758 | |
2621 | 2759 | /** |
2622 | 2760 | * Add a block of inline Javascript code to be executed later |
@@ -2633,8 +2771,9 @@ discard block |
||
2633 | 2771 | { |
2634 | 2772 | global $context; |
2635 | 2773 | |
2636 | - if (empty($javascript)) |
|
2637 | - return false; |
|
2774 | + if (empty($javascript)) { |
|
2775 | + return false; |
|
2776 | + } |
|
2638 | 2777 | |
2639 | 2778 | $context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript; |
2640 | 2779 | } |
@@ -2655,15 +2794,18 @@ discard block |
||
2655 | 2794 | static $already_loaded = array(); |
2656 | 2795 | |
2657 | 2796 | // Default to the user's language. |
2658 | - if ($lang == '') |
|
2659 | - $lang = isset($user_info['language']) ? $user_info['language'] : $language; |
|
2797 | + if ($lang == '') { |
|
2798 | + $lang = isset($user_info['language']) ? $user_info['language'] : $language; |
|
2799 | + } |
|
2660 | 2800 | |
2661 | 2801 | // Do we want the English version of language file as fallback? |
2662 | - if (empty($modSettings['disable_language_fallback']) && $lang != 'english') |
|
2663 | - loadLanguage($template_name, 'english', false); |
|
2802 | + if (empty($modSettings['disable_language_fallback']) && $lang != 'english') { |
|
2803 | + loadLanguage($template_name, 'english', false); |
|
2804 | + } |
|
2664 | 2805 | |
2665 | - if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) |
|
2666 | - return $lang; |
|
2806 | + if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) { |
|
2807 | + return $lang; |
|
2808 | + } |
|
2667 | 2809 | |
2668 | 2810 | // Make sure we have $settings - if not we're in trouble and need to find it! |
2669 | 2811 | if (empty($settings['default_theme_dir'])) |
@@ -2674,8 +2816,9 @@ discard block |
||
2674 | 2816 | |
2675 | 2817 | // What theme are we in? |
2676 | 2818 | $theme_name = basename($settings['theme_url']); |
2677 | - if (empty($theme_name)) |
|
2678 | - $theme_name = 'unknown'; |
|
2819 | + if (empty($theme_name)) { |
|
2820 | + $theme_name = 'unknown'; |
|
2821 | + } |
|
2679 | 2822 | |
2680 | 2823 | // For each file open it up and write it out! |
2681 | 2824 | foreach (explode('+', $template_name) as $template) |
@@ -2717,8 +2860,9 @@ discard block |
||
2717 | 2860 | $found = true; |
2718 | 2861 | |
2719 | 2862 | // setlocale is required for basename() & pathinfo() to work properly on the selected language |
2720 | - if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) |
|
2721 | - setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']); |
|
2863 | + if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) { |
|
2864 | + setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']); |
|
2865 | + } |
|
2722 | 2866 | |
2723 | 2867 | break; |
2724 | 2868 | } |
@@ -2758,8 +2902,9 @@ discard block |
||
2758 | 2902 | } |
2759 | 2903 | |
2760 | 2904 | // Keep track of what we're up to soldier. |
2761 | - if ($db_show_debug === true) |
|
2762 | - $context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')'; |
|
2905 | + if ($db_show_debug === true) { |
|
2906 | + $context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')'; |
|
2907 | + } |
|
2763 | 2908 | |
2764 | 2909 | // Remember what we have loaded, and in which language. |
2765 | 2910 | $already_loaded[$template_name] = $lang; |
@@ -2805,8 +2950,9 @@ discard block |
||
2805 | 2950 | ) |
2806 | 2951 | ); |
2807 | 2952 | // In the EXTREMELY unlikely event this happens, give an error message. |
2808 | - if ($smcFunc['db_num_rows']($result) == 0) |
|
2809 | - fatal_lang_error('parent_not_found', 'critical'); |
|
2953 | + if ($smcFunc['db_num_rows']($result) == 0) { |
|
2954 | + fatal_lang_error('parent_not_found', 'critical'); |
|
2955 | + } |
|
2810 | 2956 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
2811 | 2957 | { |
2812 | 2958 | if (!isset($boards[$row['id_board']])) |
@@ -2823,8 +2969,8 @@ discard block |
||
2823 | 2969 | ); |
2824 | 2970 | } |
2825 | 2971 | // If a moderator exists for this board, add that moderator for all children too. |
2826 | - if (!empty($row['id_moderator'])) |
|
2827 | - foreach ($boards as $id => $dummy) |
|
2972 | + if (!empty($row['id_moderator'])) { |
|
2973 | + foreach ($boards as $id => $dummy) |
|
2828 | 2974 | { |
2829 | 2975 | $boards[$id]['moderators'][$row['id_moderator']] = array( |
2830 | 2976 | 'id' => $row['id_moderator'], |
@@ -2832,11 +2978,12 @@ discard block |
||
2832 | 2978 | 'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'], |
2833 | 2979 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>' |
2834 | 2980 | ); |
2981 | + } |
|
2835 | 2982 | } |
2836 | 2983 | |
2837 | 2984 | // If a moderator group exists for this board, add that moderator group for all children too |
2838 | - if (!empty($row['id_moderator_group'])) |
|
2839 | - foreach ($boards as $id => $dummy) |
|
2985 | + if (!empty($row['id_moderator_group'])) { |
|
2986 | + foreach ($boards as $id => $dummy) |
|
2840 | 2987 | { |
2841 | 2988 | $boards[$id]['moderator_groups'][$row['id_moderator_group']] = array( |
2842 | 2989 | 'id' => $row['id_moderator_group'], |
@@ -2844,6 +2991,7 @@ discard block |
||
2844 | 2991 | 'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'], |
2845 | 2992 | 'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>' |
2846 | 2993 | ); |
2994 | + } |
|
2847 | 2995 | } |
2848 | 2996 | } |
2849 | 2997 | $smcFunc['db_free_result']($result); |
@@ -2870,23 +3018,27 @@ discard block |
||
2870 | 3018 | if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null) |
2871 | 3019 | { |
2872 | 3020 | // If we don't have our ucwords function defined yet, let's load the settings data. |
2873 | - if (empty($smcFunc['ucwords'])) |
|
2874 | - reloadSettings(); |
|
3021 | + if (empty($smcFunc['ucwords'])) { |
|
3022 | + reloadSettings(); |
|
3023 | + } |
|
2875 | 3024 | |
2876 | 3025 | // If we don't have our theme information yet, let's get it. |
2877 | - if (empty($settings['default_theme_dir'])) |
|
2878 | - loadTheme(0, false); |
|
3026 | + if (empty($settings['default_theme_dir'])) { |
|
3027 | + loadTheme(0, false); |
|
3028 | + } |
|
2879 | 3029 | |
2880 | 3030 | // Default language directories to try. |
2881 | 3031 | $language_directories = array( |
2882 | 3032 | $settings['default_theme_dir'] . '/languages', |
2883 | 3033 | ); |
2884 | - if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) |
|
2885 | - $language_directories[] = $settings['actual_theme_dir'] . '/languages'; |
|
3034 | + if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) { |
|
3035 | + $language_directories[] = $settings['actual_theme_dir'] . '/languages'; |
|
3036 | + } |
|
2886 | 3037 | |
2887 | 3038 | // We possibly have a base theme directory. |
2888 | - if (!empty($settings['base_theme_dir'])) |
|
2889 | - $language_directories[] = $settings['base_theme_dir'] . '/languages'; |
|
3039 | + if (!empty($settings['base_theme_dir'])) { |
|
3040 | + $language_directories[] = $settings['base_theme_dir'] . '/languages'; |
|
3041 | + } |
|
2890 | 3042 | |
2891 | 3043 | // Remove any duplicates. |
2892 | 3044 | $language_directories = array_unique($language_directories); |
@@ -2900,20 +3052,21 @@ discard block |
||
2900 | 3052 | foreach ($language_directories as $language_dir) |
2901 | 3053 | { |
2902 | 3054 | // Can't look in here... doesn't exist! |
2903 | - if (!file_exists($language_dir)) |
|
2904 | - continue; |
|
3055 | + if (!file_exists($language_dir)) { |
|
3056 | + continue; |
|
3057 | + } |
|
2905 | 3058 | |
2906 | 3059 | $dir = dir($language_dir); |
2907 | 3060 | while ($entry = $dir->read()) |
2908 | 3061 | { |
2909 | 3062 | // Look for the index language file... For good measure skip any "index.language-utf8.php" files |
2910 | - if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) |
|
2911 | - continue; |
|
2912 | - |
|
2913 | - if (!empty($langList) && !empty($langList[$matches[1]])) |
|
2914 | - $langName = $langList[$matches[1]]; |
|
3063 | + if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) { |
|
3064 | + continue; |
|
3065 | + } |
|
2915 | 3066 | |
2916 | - else |
|
3067 | + if (!empty($langList) && !empty($langList[$matches[1]])) { |
|
3068 | + $langName = $langList[$matches[1]]; |
|
3069 | + } else |
|
2917 | 3070 | { |
2918 | 3071 | $langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' '))); |
2919 | 3072 | |
@@ -2954,12 +3107,14 @@ discard block |
||
2954 | 3107 | } |
2955 | 3108 | |
2956 | 3109 | // Do we need to store the lang list? |
2957 | - if (empty($langList)) |
|
2958 | - updateSettings(array('langList' => $smcFunc['json_encode']($catchLang))); |
|
3110 | + if (empty($langList)) { |
|
3111 | + updateSettings(array('langList' => $smcFunc['json_encode']($catchLang))); |
|
3112 | + } |
|
2959 | 3113 | |
2960 | 3114 | // Let's cash in on this deal. |
2961 | - if (!empty($modSettings['cache_enable'])) |
|
2962 | - cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600); |
|
3115 | + if (!empty($modSettings['cache_enable'])) { |
|
3116 | + cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600); |
|
3117 | + } |
|
2963 | 3118 | } |
2964 | 3119 | |
2965 | 3120 | return $context['languages']; |
@@ -2982,8 +3137,9 @@ discard block |
||
2982 | 3137 | global $modSettings, $options, $txt; |
2983 | 3138 | static $censor_vulgar = null, $censor_proper; |
2984 | 3139 | |
2985 | - if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') |
|
2986 | - return $text; |
|
3140 | + if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') { |
|
3141 | + return $text; |
|
3142 | + } |
|
2987 | 3143 | |
2988 | 3144 | // If they haven't yet been loaded, load them. |
2989 | 3145 | if ($censor_vulgar == null) |
@@ -3014,9 +3170,9 @@ discard block |
||
3014 | 3170 | { |
3015 | 3171 | $func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace'; |
3016 | 3172 | $text = $func($censor_vulgar, $censor_proper, $text); |
3173 | + } else { |
|
3174 | + $text = preg_replace($censor_vulgar, $censor_proper, $text); |
|
3017 | 3175 | } |
3018 | - else |
|
3019 | - $text = preg_replace($censor_vulgar, $censor_proper, $text); |
|
3020 | 3176 | |
3021 | 3177 | return $text; |
3022 | 3178 | } |
@@ -3042,38 +3198,42 @@ discard block |
||
3042 | 3198 | @ini_set('track_errors', '1'); |
3043 | 3199 | |
3044 | 3200 | // Don't include the file more than once, if $once is true. |
3045 | - if ($once && in_array($filename, $templates)) |
|
3046 | - return; |
|
3201 | + if ($once && in_array($filename, $templates)) { |
|
3202 | + return; |
|
3203 | + } |
|
3047 | 3204 | // Add this file to the include list, whether $once is true or not. |
3048 | - else |
|
3049 | - $templates[] = $filename; |
|
3205 | + else { |
|
3206 | + $templates[] = $filename; |
|
3207 | + } |
|
3050 | 3208 | |
3051 | 3209 | // Are we going to use eval? |
3052 | 3210 | if (empty($modSettings['disableTemplateEval'])) |
3053 | 3211 | { |
3054 | 3212 | $file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false; |
3055 | 3213 | $settings['current_include_filename'] = $filename; |
3056 | - } |
|
3057 | - else |
|
3214 | + } else |
|
3058 | 3215 | { |
3059 | 3216 | $file_found = file_exists($filename); |
3060 | 3217 | |
3061 | - if ($once && $file_found) |
|
3062 | - require_once($filename); |
|
3063 | - elseif ($file_found) |
|
3064 | - require($filename); |
|
3218 | + if ($once && $file_found) { |
|
3219 | + require_once($filename); |
|
3220 | + } elseif ($file_found) { |
|
3221 | + require($filename); |
|
3222 | + } |
|
3065 | 3223 | } |
3066 | 3224 | |
3067 | 3225 | if ($file_found !== true) |
3068 | 3226 | { |
3069 | 3227 | ob_end_clean(); |
3070 | - if (!empty($modSettings['enableCompressedOutput'])) |
|
3071 | - @ob_start('ob_gzhandler'); |
|
3072 | - else |
|
3073 | - ob_start(); |
|
3228 | + if (!empty($modSettings['enableCompressedOutput'])) { |
|
3229 | + @ob_start('ob_gzhandler'); |
|
3230 | + } else { |
|
3231 | + ob_start(); |
|
3232 | + } |
|
3074 | 3233 | |
3075 | - if (isset($_GET['debug'])) |
|
3076 | - header('content-type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3234 | + if (isset($_GET['debug'])) { |
|
3235 | + header('content-type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3236 | + } |
|
3077 | 3237 | |
3078 | 3238 | // Don't cache error pages!! |
3079 | 3239 | header('expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
@@ -3092,12 +3252,13 @@ discard block |
||
3092 | 3252 | echo '<!DOCTYPE html> |
3093 | 3253 | <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '> |
3094 | 3254 | <head>'; |
3095 | - if (isset($context['character_set'])) |
|
3096 | - echo ' |
|
3255 | + if (isset($context['character_set'])) { |
|
3256 | + echo ' |
|
3097 | 3257 | <meta charset="', $context['character_set'], '">'; |
3258 | + } |
|
3098 | 3259 | |
3099 | - if (!empty($maintenance) && !allowedTo('admin_forum')) |
|
3100 | - echo ' |
|
3260 | + if (!empty($maintenance) && !allowedTo('admin_forum')) { |
|
3261 | + echo ' |
|
3101 | 3262 | <title>', $mtitle, '</title> |
3102 | 3263 | </head> |
3103 | 3264 | <body> |
@@ -3105,8 +3266,8 @@ discard block |
||
3105 | 3266 | ', $mmessage, ' |
3106 | 3267 | </body> |
3107 | 3268 | </html>'; |
3108 | - elseif (!allowedTo('admin_forum')) |
|
3109 | - echo ' |
|
3269 | + } elseif (!allowedTo('admin_forum')) { |
|
3270 | + echo ' |
|
3110 | 3271 | <title>', $txt['template_parse_error'], '</title> |
3111 | 3272 | </head> |
3112 | 3273 | <body> |
@@ -3114,14 +3275,16 @@ discard block |
||
3114 | 3275 | ', $txt['template_parse_error_message'], ' |
3115 | 3276 | </body> |
3116 | 3277 | </html>'; |
3117 | - else |
|
3278 | + } else |
|
3118 | 3279 | { |
3119 | 3280 | $error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => ''))); |
3120 | 3281 | $error_array = error_get_last(); |
3121 | - if (empty($error) && ini_get('track_errors') && !empty($error_array)) |
|
3122 | - $error = $error_array['message']; |
|
3123 | - if (empty($error)) |
|
3124 | - $error = $txt['template_parse_errmsg']; |
|
3282 | + if (empty($error) && ini_get('track_errors') && !empty($error_array)) { |
|
3283 | + $error = $error_array['message']; |
|
3284 | + } |
|
3285 | + if (empty($error)) { |
|
3286 | + $error = $txt['template_parse_errmsg']; |
|
3287 | + } |
|
3125 | 3288 | |
3126 | 3289 | $error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>')); |
3127 | 3290 | |
@@ -3132,11 +3295,12 @@ discard block |
||
3132 | 3295 | <h3>', $txt['template_parse_error'], '</h3> |
3133 | 3296 | ', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => ''))); |
3134 | 3297 | |
3135 | - if (!empty($error)) |
|
3136 | - echo ' |
|
3298 | + if (!empty($error)) { |
|
3299 | + echo ' |
|
3137 | 3300 | <hr> |
3138 | 3301 | |
3139 | 3302 | <div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>'; |
3303 | + } |
|
3140 | 3304 | |
3141 | 3305 | // I know, I know... this is VERY COMPLICATED. Still, it's good. |
3142 | 3306 | if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0) |
@@ -3146,10 +3310,11 @@ discard block |
||
3146 | 3310 | $data2 = preg_split('~\<br( /)?\>~', $data2); |
3147 | 3311 | |
3148 | 3312 | // Fix the PHP code stuff... |
3149 | - if (!isBrowser('gecko')) |
|
3150 | - $data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2); |
|
3151 | - else |
|
3152 | - $data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2); |
|
3313 | + if (!isBrowser('gecko')) { |
|
3314 | + $data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2); |
|
3315 | + } else { |
|
3316 | + $data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2); |
|
3317 | + } |
|
3153 | 3318 | |
3154 | 3319 | // Now we get to work around a bug in PHP where it doesn't escape <br>s! |
3155 | 3320 | $j = -1; |
@@ -3157,8 +3322,9 @@ discard block |
||
3157 | 3322 | { |
3158 | 3323 | $j++; |
3159 | 3324 | |
3160 | - if (substr_count($line, '<br>') == 0) |
|
3161 | - continue; |
|
3325 | + if (substr_count($line, '<br>') == 0) { |
|
3326 | + continue; |
|
3327 | + } |
|
3162 | 3328 | |
3163 | 3329 | $n = substr_count($line, '<br>'); |
3164 | 3330 | for ($i = 0; $i < $n; $i++) |
@@ -3177,38 +3343,42 @@ discard block |
||
3177 | 3343 | // Figure out what the color coding was before... |
3178 | 3344 | $line = max($match[1] - 9, 1); |
3179 | 3345 | $last_line = ''; |
3180 | - for ($line2 = $line - 1; $line2 > 1; $line2--) |
|
3181 | - if (strpos($data2[$line2], '<') !== false) |
|
3346 | + for ($line2 = $line - 1; $line2 > 1; $line2--) { |
|
3347 | + if (strpos($data2[$line2], '<') !== false) |
|
3182 | 3348 | { |
3183 | 3349 | if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0) |
3184 | 3350 | $last_line = $color_match[1]; |
3351 | + } |
|
3185 | 3352 | break; |
3186 | 3353 | } |
3187 | 3354 | |
3188 | 3355 | // Show the relevant lines... |
3189 | 3356 | for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++) |
3190 | 3357 | { |
3191 | - if ($line == $match[1]) |
|
3192 | - echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">'; |
|
3358 | + if ($line == $match[1]) { |
|
3359 | + echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">'; |
|
3360 | + } |
|
3193 | 3361 | |
3194 | 3362 | echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> '; |
3195 | - if (isset($data2[$line]) && $data2[$line] != '') |
|
3196 | - echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line]; |
|
3363 | + if (isset($data2[$line]) && $data2[$line] != '') { |
|
3364 | + echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line]; |
|
3365 | + } |
|
3197 | 3366 | |
3198 | 3367 | if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0) |
3199 | 3368 | { |
3200 | 3369 | $last_line = $color_match[1]; |
3201 | 3370 | echo '</', substr($last_line, 1, 4), '>'; |
3371 | + } elseif ($last_line != '' && strpos($data2[$line], '<') !== false) { |
|
3372 | + $last_line = ''; |
|
3373 | + } elseif ($last_line != '' && $data2[$line] != '') { |
|
3374 | + echo '</', substr($last_line, 1, 4), '>'; |
|
3202 | 3375 | } |
3203 | - elseif ($last_line != '' && strpos($data2[$line], '<') !== false) |
|
3204 | - $last_line = ''; |
|
3205 | - elseif ($last_line != '' && $data2[$line] != '') |
|
3206 | - echo '</', substr($last_line, 1, 4), '>'; |
|
3207 | 3376 | |
3208 | - if ($line == $match[1]) |
|
3209 | - echo '</pre></div><pre style="margin: 0;">'; |
|
3210 | - else |
|
3211 | - echo "\n"; |
|
3377 | + if ($line == $match[1]) { |
|
3378 | + echo '</pre></div><pre style="margin: 0;">'; |
|
3379 | + } else { |
|
3380 | + echo "\n"; |
|
3381 | + } |
|
3212 | 3382 | } |
3213 | 3383 | |
3214 | 3384 | echo '</pre></div>'; |
@@ -3232,8 +3402,9 @@ discard block |
||
3232 | 3402 | global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port; |
3233 | 3403 | |
3234 | 3404 | // Figure out what type of database we are using. |
3235 | - if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) |
|
3236 | - $db_type = 'mysql'; |
|
3405 | + if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) { |
|
3406 | + $db_type = 'mysql'; |
|
3407 | + } |
|
3237 | 3408 | |
3238 | 3409 | // Load the file for the database. |
3239 | 3410 | require_once($sourcedir . '/Subs-Db-' . $db_type . '.php'); |
@@ -3241,8 +3412,9 @@ discard block |
||
3241 | 3412 | $db_options = array(); |
3242 | 3413 | |
3243 | 3414 | // Add in the port if needed |
3244 | - if (!empty($db_port)) |
|
3245 | - $db_options['port'] = $db_port; |
|
3415 | + if (!empty($db_port)) { |
|
3416 | + $db_options['port'] = $db_port; |
|
3417 | + } |
|
3246 | 3418 | |
3247 | 3419 | // If we are in SSI try them first, but don't worry if it doesn't work, we have the normal username and password we can use. |
3248 | 3420 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
@@ -3261,13 +3433,15 @@ discard block |
||
3261 | 3433 | } |
3262 | 3434 | |
3263 | 3435 | // Safe guard here, if there isn't a valid connection lets put a stop to it. |
3264 | - if (!$db_connection) |
|
3265 | - display_db_error(); |
|
3436 | + if (!$db_connection) { |
|
3437 | + display_db_error(); |
|
3438 | + } |
|
3266 | 3439 | |
3267 | 3440 | // If in SSI mode fix up the prefix. |
3268 | - if (SMF == 'SSI') |
|
3269 | - db_fix_prefix($db_prefix, $db_name); |
|
3270 | -} |
|
3441 | + if (SMF == 'SSI') { |
|
3442 | + db_fix_prefix($db_prefix, $db_name); |
|
3443 | + } |
|
3444 | + } |
|
3271 | 3445 | |
3272 | 3446 | /** |
3273 | 3447 | * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it. |
@@ -3281,10 +3455,11 @@ discard block |
||
3281 | 3455 | global $sourcedir, $cacheAPI, $cache_accelerator; |
3282 | 3456 | |
3283 | 3457 | // Not overriding this and we have a cacheAPI, send it back. |
3284 | - if (empty($overrideCache) && is_object($cacheAPI)) |
|
3285 | - return $cacheAPI; |
|
3286 | - elseif (is_null($cacheAPI)) |
|
3287 | - $cacheAPI = false; |
|
3458 | + if (empty($overrideCache) && is_object($cacheAPI)) { |
|
3459 | + return $cacheAPI; |
|
3460 | + } elseif (is_null($cacheAPI)) { |
|
3461 | + $cacheAPI = false; |
|
3462 | + } |
|
3288 | 3463 | |
3289 | 3464 | // Make sure our class is in session. |
3290 | 3465 | require_once($sourcedir . '/Class-CacheAPI.php'); |
@@ -3305,8 +3480,9 @@ discard block |
||
3305 | 3480 | if (!$testAPI->isSupported()) |
3306 | 3481 | { |
3307 | 3482 | // Can we save ourselves? |
3308 | - if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') |
|
3309 | - return loadCacheAccelerator(null, false); |
|
3483 | + if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') { |
|
3484 | + return loadCacheAccelerator(null, false); |
|
3485 | + } |
|
3310 | 3486 | return false; |
3311 | 3487 | } |
3312 | 3488 | |
@@ -3318,9 +3494,9 @@ discard block |
||
3318 | 3494 | { |
3319 | 3495 | $cacheAPI = $testAPI; |
3320 | 3496 | return $cacheAPI; |
3497 | + } else { |
|
3498 | + return $testAPI; |
|
3321 | 3499 | } |
3322 | - else |
|
3323 | - return $testAPI; |
|
3324 | 3500 | } |
3325 | 3501 | } |
3326 | 3502 | |
@@ -3340,8 +3516,9 @@ discard block |
||
3340 | 3516 | |
3341 | 3517 | // @todo Why are we doing this if caching is disabled? |
3342 | 3518 | |
3343 | - if (function_exists('call_integration_hook')) |
|
3344 | - call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level)); |
|
3519 | + if (function_exists('call_integration_hook')) { |
|
3520 | + call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level)); |
|
3521 | + } |
|
3345 | 3522 | |
3346 | 3523 | /* Refresh the cache if either: |
3347 | 3524 | 1. Caching is disabled. |
@@ -3355,16 +3532,19 @@ discard block |
||
3355 | 3532 | require_once($sourcedir . '/' . $file); |
3356 | 3533 | $cache_block = call_user_func_array($function, $params); |
3357 | 3534 | |
3358 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) |
|
3359 | - cache_put_data($key, $cache_block, $cache_block['expires'] - time()); |
|
3535 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) { |
|
3536 | + cache_put_data($key, $cache_block, $cache_block['expires'] - time()); |
|
3537 | + } |
|
3360 | 3538 | } |
3361 | 3539 | |
3362 | 3540 | // Some cached data may need a freshening up after retrieval. |
3363 | - if (!empty($cache_block['post_retri_eval'])) |
|
3364 | - eval($cache_block['post_retri_eval']); |
|
3541 | + if (!empty($cache_block['post_retri_eval'])) { |
|
3542 | + eval($cache_block['post_retri_eval']); |
|
3543 | + } |
|
3365 | 3544 | |
3366 | - if (function_exists('call_integration_hook')) |
|
3367 | - call_integration_hook('post_cache_quick_get', array(&$cache_block)); |
|
3545 | + if (function_exists('call_integration_hook')) { |
|
3546 | + call_integration_hook('post_cache_quick_get', array(&$cache_block)); |
|
3547 | + } |
|
3368 | 3548 | |
3369 | 3549 | return $cache_block['data']; |
3370 | 3550 | } |
@@ -3391,8 +3571,9 @@ discard block |
||
3391 | 3571 | global $smcFunc, $cache_enable, $cacheAPI; |
3392 | 3572 | global $cache_hits, $cache_count, $db_show_debug; |
3393 | 3573 | |
3394 | - if (empty($cache_enable) || empty($cacheAPI)) |
|
3395 | - return; |
|
3574 | + if (empty($cache_enable) || empty($cacheAPI)) { |
|
3575 | + return; |
|
3576 | + } |
|
3396 | 3577 | |
3397 | 3578 | $cache_count = isset($cache_count) ? $cache_count + 1 : 1; |
3398 | 3579 | if (isset($db_show_debug) && $db_show_debug === true) |
@@ -3405,12 +3586,14 @@ discard block |
||
3405 | 3586 | $value = $value === null ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_encode']($value) : json_encode($value)); |
3406 | 3587 | $cacheAPI->putData($key, $value, $ttl); |
3407 | 3588 | |
3408 | - if (function_exists('call_integration_hook')) |
|
3409 | - call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl)); |
|
3589 | + if (function_exists('call_integration_hook')) { |
|
3590 | + call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl)); |
|
3591 | + } |
|
3410 | 3592 | |
3411 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
3412 | - $cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
3413 | -} |
|
3593 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
3594 | + $cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
3595 | + } |
|
3596 | + } |
|
3414 | 3597 | |
3415 | 3598 | /** |
3416 | 3599 | * Gets the value from the cache specified by key, so long as it is not older than ttl seconds. |
@@ -3426,8 +3609,9 @@ discard block |
||
3426 | 3609 | global $smcFunc, $cache_enable, $cacheAPI; |
3427 | 3610 | global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug; |
3428 | 3611 | |
3429 | - if (empty($cache_enable) || empty($cacheAPI)) |
|
3430 | - return; |
|
3612 | + if (empty($cache_enable) || empty($cacheAPI)) { |
|
3613 | + return; |
|
3614 | + } |
|
3431 | 3615 | |
3432 | 3616 | $cache_count = isset($cache_count) ? $cache_count + 1 : 1; |
3433 | 3617 | if (isset($db_show_debug) && $db_show_debug === true) |
@@ -3447,16 +3631,18 @@ discard block |
||
3447 | 3631 | |
3448 | 3632 | if (empty($value)) |
3449 | 3633 | { |
3450 | - if (!is_array($cache_misses)) |
|
3451 | - $cache_misses = array(); |
|
3634 | + if (!is_array($cache_misses)) { |
|
3635 | + $cache_misses = array(); |
|
3636 | + } |
|
3452 | 3637 | |
3453 | 3638 | $cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1; |
3454 | 3639 | $cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get'); |
3455 | 3640 | } |
3456 | 3641 | } |
3457 | 3642 | |
3458 | - if (function_exists('call_integration_hook') && isset($value)) |
|
3459 | - call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value)); |
|
3643 | + if (function_exists('call_integration_hook') && isset($value)) { |
|
3644 | + call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value)); |
|
3645 | + } |
|
3460 | 3646 | |
3461 | 3647 | return empty($value) ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_decode']($value, true) : smf_json_decode($value, true)); |
3462 | 3648 | } |
@@ -3478,8 +3664,9 @@ discard block |
||
3478 | 3664 | global $cacheAPI; |
3479 | 3665 | |
3480 | 3666 | // If we can't get to the API, can't do this. |
3481 | - if (empty($cacheAPI)) |
|
3482 | - return; |
|
3667 | + if (empty($cacheAPI)) { |
|
3668 | + return; |
|
3669 | + } |
|
3483 | 3670 | |
3484 | 3671 | // Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure. |
3485 | 3672 | $cacheAPI->cleanCache($type); |
@@ -3504,8 +3691,9 @@ discard block |
||
3504 | 3691 | global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $user_info; |
3505 | 3692 | |
3506 | 3693 | // Come on! |
3507 | - if (empty($data)) |
|
3508 | - return array(); |
|
3694 | + if (empty($data)) { |
|
3695 | + return array(); |
|
3696 | + } |
|
3509 | 3697 | |
3510 | 3698 | // Set a nice default var. |
3511 | 3699 | $image = ''; |
@@ -3513,11 +3701,11 @@ discard block |
||
3513 | 3701 | // Gravatar has been set as mandatory! |
3514 | 3702 | if (!empty($modSettings['gravatarOverride'])) |
3515 | 3703 | { |
3516 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) |
|
3517 | - $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
3518 | - |
|
3519 | - else if (!empty($data['email'])) |
|
3520 | - $image = get_gravatar_url($data['email']); |
|
3704 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) { |
|
3705 | + $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
3706 | + } else if (!empty($data['email'])) { |
|
3707 | + $image = get_gravatar_url($data['email']); |
|
3708 | + } |
|
3521 | 3709 | } |
3522 | 3710 | |
3523 | 3711 | // Look if the user has a gravatar field or has set an external url as avatar. |
@@ -3529,54 +3717,60 @@ discard block |
||
3529 | 3717 | // Gravatar. |
3530 | 3718 | if (stristr($data['avatar'], 'gravatar://')) |
3531 | 3719 | { |
3532 | - if ($data['avatar'] == 'gravatar://') |
|
3533 | - $image = get_gravatar_url($data['email']); |
|
3534 | - |
|
3535 | - elseif (!empty($modSettings['gravatarAllowExtraEmail'])) |
|
3536 | - $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
3720 | + if ($data['avatar'] == 'gravatar://') { |
|
3721 | + $image = get_gravatar_url($data['email']); |
|
3722 | + } elseif (!empty($modSettings['gravatarAllowExtraEmail'])) { |
|
3723 | + $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
3724 | + } |
|
3537 | 3725 | } |
3538 | 3726 | |
3539 | 3727 | // External url. |
3540 | 3728 | else |
3541 | 3729 | { |
3542 | 3730 | // Using ssl? |
3543 | - if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) |
|
3544 | - $image = get_proxied_url($data['avatar']); |
|
3731 | + if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) { |
|
3732 | + $image = get_proxied_url($data['avatar']); |
|
3733 | + } |
|
3545 | 3734 | |
3546 | 3735 | // Just a plain external url. |
3547 | - else |
|
3548 | - $image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar']; |
|
3736 | + else { |
|
3737 | + $image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar']; |
|
3738 | + } |
|
3549 | 3739 | } |
3550 | 3740 | } |
3551 | 3741 | |
3552 | 3742 | // Perhaps this user has an attachment as avatar... |
3553 | - else if (!empty($data['filename'])) |
|
3554 | - $image = $modSettings['custom_avatar_url'] . '/' . $data['filename']; |
|
3743 | + else if (!empty($data['filename'])) { |
|
3744 | + $image = $modSettings['custom_avatar_url'] . '/' . $data['filename']; |
|
3745 | + } |
|
3555 | 3746 | |
3556 | 3747 | // Right... no avatar... use our default image. |
3557 | - else |
|
3558 | - $image = $modSettings['avatar_url'] . '/default.png'; |
|
3748 | + else { |
|
3749 | + $image = $modSettings['avatar_url'] . '/default.png'; |
|
3750 | + } |
|
3559 | 3751 | } |
3560 | 3752 | |
3561 | 3753 | call_integration_hook('integrate_set_avatar_data', array(&$image, &$data)); |
3562 | 3754 | |
3563 | 3755 | // At this point in time $image has to be filled unless you chose to force gravatar and the user doesn't have the needed data to retrieve it... thus a check for !empty() is still needed. |
3564 | - if (!empty($image)) |
|
3565 | - return array( |
|
3756 | + if (!empty($image)) { |
|
3757 | + return array( |
|
3566 | 3758 | 'name' => !empty($data['avatar']) ? $data['avatar'] : '', |
3567 | 3759 | 'image' => '<img class="avatar" src="' . $image . '" />', |
3568 | 3760 | 'href' => $image, |
3569 | 3761 | 'url' => $image, |
3570 | 3762 | ); |
3763 | + } |
|
3571 | 3764 | |
3572 | 3765 | // Fallback to make life easier for everyone... |
3573 | - else |
|
3574 | - return array( |
|
3766 | + else { |
|
3767 | + return array( |
|
3575 | 3768 | 'name' => '', |
3576 | 3769 | 'image' => '', |
3577 | 3770 | 'href' => '', |
3578 | 3771 | 'url' => '', |
3579 | 3772 | ); |
3580 | -} |
|
3773 | + } |
|
3774 | + } |
|
3581 | 3775 | |
3582 | 3776 | ?> |
3583 | 3777 | \ No newline at end of file |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | /** |
501 | 501 | * Returns the amount of affected rows for a query. |
502 | 502 | * |
503 | - * @param mixed $result |
|
503 | + * @param resource|null $result |
|
504 | 504 | * |
505 | 505 | * @return int |
506 | 506 | * |
@@ -869,7 +869,7 @@ discard block |
||
869 | 869 | * |
870 | 870 | * @param string $db_name The database name |
871 | 871 | * @param resource $db_connection The database connection |
872 | - * @return true Always returns true |
|
872 | + * @return boolean Always returns true |
|
873 | 873 | */ |
874 | 874 | function smf_db_select_db($db_name, $db_connection) |
875 | 875 | { |
@@ -199,22 +199,22 @@ discard block |
||
199 | 199 | |
200 | 200 | case 'date': |
201 | 201 | if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
202 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date'; |
|
202 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]) . '::date'; |
|
203 | 203 | else |
204 | 204 | smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
205 | 205 | break; |
206 | 206 | |
207 | 207 | case 'time': |
208 | 208 | if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
209 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time'; |
|
209 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]) . '::time'; |
|
210 | 210 | else |
211 | 211 | smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
212 | 212 | break; |
213 | 213 | |
214 | 214 | case 'datetime': |
215 | 215 | if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) |
216 | - return 'to_timestamp('. |
|
217 | - sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]). |
|
216 | + return 'to_timestamp(' . |
|
217 | + sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5], $datetime_matches[6]) . |
|
218 | 218 | ',\'YYYY-MM-DD HH24:MI:SS\')'; |
219 | 219 | else |
220 | 220 | smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | $old_pos = 0; |
425 | 425 | $pos = -1; |
426 | 426 | // Remove the string escape for better runtime |
427 | - $db_string_1 = str_replace('\'\'','',$db_string); |
|
427 | + $db_string_1 = str_replace('\'\'', '', $db_string); |
|
428 | 428 | while (true) |
429 | 429 | { |
430 | 430 | $pos = strpos($db_string_1, '\'', $pos + 1); |
@@ -802,7 +802,7 @@ discard block |
||
802 | 802 | if (!empty($keys) && (count($keys) > 0) && $returnmode > 0) |
803 | 803 | { |
804 | 804 | // we only take the first key |
805 | - $returning = ' RETURNING '.$keys[0]; |
|
805 | + $returning = ' RETURNING ' . $keys[0]; |
|
806 | 806 | $with_returning = true; |
807 | 807 | } |
808 | 808 | |
@@ -833,7 +833,7 @@ discard block |
||
833 | 833 | INSERT INTO ' . $table . '("' . implode('", "', $indexed_columns) . '") |
834 | 834 | VALUES |
835 | 835 | ' . implode(', |
836 | - ', $insertRows).$replace.$returning, |
|
836 | + ', $insertRows) . $replace . $returning, |
|
837 | 837 | array( |
838 | 838 | 'security_override' => true, |
839 | 839 | 'db_error_skip' => $method == 'ignore' || $table === $db_prefix . 'log_errors', |
@@ -846,7 +846,7 @@ discard block |
||
846 | 846 | if ($returnmode === 2) |
847 | 847 | $return_var = array(); |
848 | 848 | |
849 | - while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning) |
|
849 | + while (($row = $smcFunc['db_fetch_row']($request)) && $with_returning) |
|
850 | 850 | { |
851 | 851 | if (is_numeric($row[0])) // try to emulate mysql limitation |
852 | 852 | { |
@@ -1009,7 +1009,7 @@ discard block |
||
1009 | 1009 | */ |
1010 | 1010 | function smf_db_custom_order($field, $array_values, $desc = false) |
1011 | 1011 | { |
1012 | - $return = 'CASE '. $field . ' '; |
|
1012 | + $return = 'CASE ' . $field . ' '; |
|
1013 | 1013 | $count = count($array_values); |
1014 | 1014 | $then = ($desc ? ' THEN -' : ' THEN '); |
1015 | 1015 |
@@ -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 | * Maps the implementations in this file (smf_db_function_name) |
@@ -34,8 +35,8 @@ discard block |
||
34 | 35 | global $smcFunc; |
35 | 36 | |
36 | 37 | // Map some database specific functions, only do this once. |
37 | - if (!isset($smcFunc['db_fetch_assoc'])) |
|
38 | - $smcFunc += array( |
|
38 | + if (!isset($smcFunc['db_fetch_assoc'])) { |
|
39 | + $smcFunc += array( |
|
39 | 40 | 'db_query' => 'smf_db_query', |
40 | 41 | 'db_quote' => 'smf_db_quote', |
41 | 42 | 'db_insert' => 'smf_db_insert', |
@@ -64,11 +65,13 @@ discard block |
||
64 | 65 | 'db_error_insert' => 'smf_db_error_insert', |
65 | 66 | 'db_custom_order' => 'smf_db_custom_order', |
66 | 67 | ); |
68 | + } |
|
67 | 69 | |
68 | - if (!empty($db_options['persist'])) |
|
69 | - $connection = @pg_pconnect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
70 | - else |
|
71 | - $connection = @pg_connect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
70 | + if (!empty($db_options['persist'])) { |
|
71 | + $connection = @pg_pconnect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
72 | + } else { |
|
73 | + $connection = @pg_connect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
74 | + } |
|
72 | 75 | |
73 | 76 | // Something's wrong, show an error if its fatal (which we assume it is) |
74 | 77 | if (!$connection) |
@@ -76,8 +79,7 @@ discard block |
||
76 | 79 | if (!empty($db_options['non_fatal'])) |
77 | 80 | { |
78 | 81 | return null; |
79 | - } |
|
80 | - else |
|
82 | + } else |
|
81 | 83 | { |
82 | 84 | display_db_error(); |
83 | 85 | } |
@@ -128,31 +130,38 @@ discard block |
||
128 | 130 | |
129 | 131 | list ($values, $connection) = $db_callback; |
130 | 132 | |
131 | - if ($matches[1] === 'db_prefix') |
|
132 | - return $db_prefix; |
|
133 | + if ($matches[1] === 'db_prefix') { |
|
134 | + return $db_prefix; |
|
135 | + } |
|
133 | 136 | |
134 | - if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) |
|
135 | - return $user_info[$matches[1]]; |
|
137 | + if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) { |
|
138 | + return $user_info[$matches[1]]; |
|
139 | + } |
|
136 | 140 | |
137 | - if ($matches[1] === 'empty') |
|
138 | - return '\'\''; |
|
141 | + if ($matches[1] === 'empty') { |
|
142 | + return '\'\''; |
|
143 | + } |
|
139 | 144 | |
140 | - if (!isset($matches[2])) |
|
141 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
145 | + if (!isset($matches[2])) { |
|
146 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
147 | + } |
|
142 | 148 | |
143 | - if ($matches[1] === 'literal') |
|
144 | - return '\'' . pg_escape_string($matches[2]) . '\''; |
|
149 | + if ($matches[1] === 'literal') { |
|
150 | + return '\'' . pg_escape_string($matches[2]) . '\''; |
|
151 | + } |
|
145 | 152 | |
146 | - if (!isset($values[$matches[2]])) |
|
147 | - smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
153 | + if (!isset($values[$matches[2]])) { |
|
154 | + smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
155 | + } |
|
148 | 156 | |
149 | 157 | $replacement = $values[$matches[2]]; |
150 | 158 | |
151 | 159 | switch ($matches[1]) |
152 | 160 | { |
153 | 161 | case 'int': |
154 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
155 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
162 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
163 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
164 | + } |
|
156 | 165 | return (string) (int) $replacement; |
157 | 166 | break; |
158 | 167 | |
@@ -164,65 +173,73 @@ discard block |
||
164 | 173 | case 'array_int': |
165 | 174 | if (is_array($replacement)) |
166 | 175 | { |
167 | - if (empty($replacement)) |
|
168 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
176 | + if (empty($replacement)) { |
|
177 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
178 | + } |
|
169 | 179 | |
170 | 180 | foreach ($replacement as $key => $value) |
171 | 181 | { |
172 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
173 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
182 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
183 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
184 | + } |
|
174 | 185 | |
175 | 186 | $replacement[$key] = (string) (int) $value; |
176 | 187 | } |
177 | 188 | |
178 | 189 | return implode(', ', $replacement); |
190 | + } else { |
|
191 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
179 | 192 | } |
180 | - else |
|
181 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
182 | 193 | |
183 | 194 | break; |
184 | 195 | |
185 | 196 | case 'array_string': |
186 | 197 | if (is_array($replacement)) |
187 | 198 | { |
188 | - if (empty($replacement)) |
|
189 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
199 | + if (empty($replacement)) { |
|
200 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
201 | + } |
|
190 | 202 | |
191 | - foreach ($replacement as $key => $value) |
|
192 | - $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
203 | + foreach ($replacement as $key => $value) { |
|
204 | + $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
205 | + } |
|
193 | 206 | |
194 | 207 | return implode(', ', $replacement); |
208 | + } else { |
|
209 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
195 | 210 | } |
196 | - else |
|
197 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
198 | 211 | break; |
199 | 212 | |
200 | 213 | case 'date': |
201 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
202 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date'; |
|
203 | - else |
|
204 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
214 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
215 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date'; |
|
216 | + } else { |
|
217 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
218 | + } |
|
205 | 219 | break; |
206 | 220 | |
207 | 221 | case 'time': |
208 | - if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
|
209 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time'; |
|
210 | - else |
|
211 | - smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
222 | + if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) { |
|
223 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time'; |
|
224 | + } else { |
|
225 | + smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
226 | + } |
|
212 | 227 | break; |
213 | 228 | |
214 | 229 | case 'datetime': |
215 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) |
|
216 | - return 'to_timestamp('. |
|
230 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) { |
|
231 | + return 'to_timestamp('. |
|
217 | 232 | sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]). |
218 | 233 | ',\'YYYY-MM-DD HH24:MI:SS\')'; |
219 | - else |
|
220 | - smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
234 | + } else { |
|
235 | + smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
236 | + } |
|
221 | 237 | break; |
222 | 238 | |
223 | 239 | case 'float': |
224 | - if (!is_numeric($replacement)) |
|
225 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
240 | + if (!is_numeric($replacement)) { |
|
241 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
242 | + } |
|
226 | 243 | return (string) (float) $replacement; |
227 | 244 | break; |
228 | 245 | |
@@ -235,31 +252,36 @@ discard block |
||
235 | 252 | break; |
236 | 253 | |
237 | 254 | case 'inet': |
238 | - if ($replacement == 'null' || $replacement == '') |
|
239 | - return 'null'; |
|
240 | - if (inet_pton($replacement) === false) |
|
241 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
255 | + if ($replacement == 'null' || $replacement == '') { |
|
256 | + return 'null'; |
|
257 | + } |
|
258 | + if (inet_pton($replacement) === false) { |
|
259 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
260 | + } |
|
242 | 261 | return sprintf('\'%1$s\'::inet', pg_escape_string($replacement)); |
243 | 262 | |
244 | 263 | case 'array_inet': |
245 | 264 | if (is_array($replacement)) |
246 | 265 | { |
247 | - if (empty($replacement)) |
|
248 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
266 | + if (empty($replacement)) { |
|
267 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
268 | + } |
|
249 | 269 | |
250 | 270 | foreach ($replacement as $key => $value) |
251 | 271 | { |
252 | - if ($replacement == 'null' || $replacement == '') |
|
253 | - $replacement[$key] = 'null'; |
|
254 | - if (!isValidIP($value)) |
|
255 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
272 | + if ($replacement == 'null' || $replacement == '') { |
|
273 | + $replacement[$key] = 'null'; |
|
274 | + } |
|
275 | + if (!isValidIP($value)) { |
|
276 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
277 | + } |
|
256 | 278 | $replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value)); |
257 | 279 | } |
258 | 280 | |
259 | 281 | return implode(', ', $replacement); |
282 | + } else { |
|
283 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
260 | 284 | } |
261 | - else |
|
262 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
263 | 285 | break; |
264 | 286 | |
265 | 287 | default: |
@@ -350,14 +372,16 @@ discard block |
||
350 | 372 | ), |
351 | 373 | ); |
352 | 374 | |
353 | - if (isset($replacements[$identifier])) |
|
354 | - $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
375 | + if (isset($replacements[$identifier])) { |
|
376 | + $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
377 | + } |
|
355 | 378 | |
356 | 379 | // Limits need to be a little different. |
357 | 380 | $db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string); |
358 | 381 | |
359 | - if (trim($db_string) == '') |
|
360 | - return false; |
|
382 | + if (trim($db_string) == '') { |
|
383 | + return false; |
|
384 | + } |
|
361 | 385 | |
362 | 386 | // Comments that are allowed in a query are preg_removed. |
363 | 387 | static $allowed_comments_from = array( |
@@ -377,8 +401,9 @@ discard block |
||
377 | 401 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
378 | 402 | $db_replace_result = 0; |
379 | 403 | |
380 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
381 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
404 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
405 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
406 | + } |
|
382 | 407 | |
383 | 408 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
384 | 409 | { |
@@ -403,17 +428,18 @@ discard block |
||
403 | 428 | while (true) |
404 | 429 | { |
405 | 430 | $pos = strpos($db_string_1, '\'', $pos + 1); |
406 | - if ($pos === false) |
|
407 | - break; |
|
431 | + if ($pos === false) { |
|
432 | + break; |
|
433 | + } |
|
408 | 434 | $clean .= substr($db_string_1, $old_pos, $pos - $old_pos); |
409 | 435 | |
410 | 436 | while (true) |
411 | 437 | { |
412 | 438 | $pos1 = strpos($db_string_1, '\'', $pos + 1); |
413 | 439 | $pos2 = strpos($db_string_1, '\\', $pos + 1); |
414 | - if ($pos1 === false) |
|
415 | - break; |
|
416 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
440 | + if ($pos1 === false) { |
|
441 | + break; |
|
442 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
417 | 443 | { |
418 | 444 | $pos = $pos1; |
419 | 445 | break; |
@@ -429,16 +455,19 @@ discard block |
||
429 | 455 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
430 | 456 | |
431 | 457 | // Comments? We don't use comments in our queries, we leave 'em outside! |
432 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
433 | - $fail = true; |
|
458 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
459 | + $fail = true; |
|
460 | + } |
|
434 | 461 | // Trying to change passwords, slow us down, or something? |
435 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
436 | - $fail = true; |
|
437 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
438 | - $fail = true; |
|
462 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
463 | + $fail = true; |
|
464 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
465 | + $fail = true; |
|
466 | + } |
|
439 | 467 | |
440 | - if (!empty($fail) && function_exists('log_error')) |
|
441 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
468 | + if (!empty($fail) && function_exists('log_error')) { |
|
469 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
470 | + } |
|
442 | 471 | } |
443 | 472 | |
444 | 473 | // Set optimize stuff |
@@ -465,8 +494,9 @@ discard block |
||
465 | 494 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
466 | 495 | |
467 | 496 | // Initialize $db_cache if not already initialized. |
468 | - if (!isset($db_cache)) |
|
469 | - $db_cache = array(); |
|
497 | + if (!isset($db_cache)) { |
|
498 | + $db_cache = array(); |
|
499 | + } |
|
470 | 500 | |
471 | 501 | if (!empty($_SESSION['debug_redirect'])) |
472 | 502 | { |
@@ -484,12 +514,14 @@ discard block |
||
484 | 514 | |
485 | 515 | $db_last_result = @pg_query($connection, $db_string); |
486 | 516 | |
487 | - if ($db_last_result === false && empty($db_values['db_error_skip'])) |
|
488 | - $db_last_result = smf_db_error($db_string, $connection); |
|
517 | + if ($db_last_result === false && empty($db_values['db_error_skip'])) { |
|
518 | + $db_last_result = smf_db_error($db_string, $connection); |
|
519 | + } |
|
489 | 520 | |
490 | 521 | // Debugging. |
491 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
492 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
522 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
523 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
524 | + } |
|
493 | 525 | |
494 | 526 | return $db_last_result; |
495 | 527 | } |
@@ -506,10 +538,11 @@ discard block |
||
506 | 538 | { |
507 | 539 | global $db_last_result, $db_replace_result; |
508 | 540 | |
509 | - if ($db_replace_result) |
|
510 | - return $db_replace_result; |
|
511 | - elseif ($result === null && !$db_last_result) |
|
512 | - return 0; |
|
541 | + if ($db_replace_result) { |
|
542 | + return $db_replace_result; |
|
543 | + } elseif ($result === null && !$db_last_result) { |
|
544 | + return 0; |
|
545 | + } |
|
513 | 546 | |
514 | 547 | return pg_affected_rows($result === null ? $db_last_result : $result); |
515 | 548 | } |
@@ -533,8 +566,9 @@ discard block |
||
533 | 566 | array( |
534 | 567 | ) |
535 | 568 | ); |
536 | - if (!$request) |
|
537 | - return false; |
|
569 | + if (!$request) { |
|
570 | + return false; |
|
571 | + } |
|
538 | 572 | list ($lastID) = $smcFunc['db_fetch_row']($request); |
539 | 573 | $smcFunc['db_free_result']($request); |
540 | 574 | |
@@ -555,12 +589,13 @@ discard block |
||
555 | 589 | // Decide which connection to use |
556 | 590 | $connection = $connection === null ? $db_connection : $connection; |
557 | 591 | |
558 | - if ($type == 'begin') |
|
559 | - return @pg_query($connection, 'BEGIN'); |
|
560 | - elseif ($type == 'rollback') |
|
561 | - return @pg_query($connection, 'ROLLBACK'); |
|
562 | - elseif ($type == 'commit') |
|
563 | - return @pg_query($connection, 'COMMIT'); |
|
592 | + if ($type == 'begin') { |
|
593 | + return @pg_query($connection, 'BEGIN'); |
|
594 | + } elseif ($type == 'rollback') { |
|
595 | + return @pg_query($connection, 'ROLLBACK'); |
|
596 | + } elseif ($type == 'commit') { |
|
597 | + return @pg_query($connection, 'COMMIT'); |
|
598 | + } |
|
564 | 599 | |
565 | 600 | return false; |
566 | 601 | } |
@@ -588,19 +623,22 @@ discard block |
||
588 | 623 | $query_error = @pg_last_error($connection); |
589 | 624 | |
590 | 625 | // Log the error. |
591 | - if (function_exists('log_error')) |
|
592 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
626 | + if (function_exists('log_error')) { |
|
627 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
628 | + } |
|
593 | 629 | |
594 | 630 | // Nothing's defined yet... just die with it. |
595 | - if (empty($context) || empty($txt)) |
|
596 | - die($query_error); |
|
631 | + if (empty($context) || empty($txt)) { |
|
632 | + die($query_error); |
|
633 | + } |
|
597 | 634 | |
598 | 635 | // Show an error message, if possible. |
599 | 636 | $context['error_title'] = $txt['database_error']; |
600 | - if (allowedTo('admin_forum')) |
|
601 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
602 | - else |
|
603 | - $context['error_message'] = $txt['try_again']; |
|
637 | + if (allowedTo('admin_forum')) { |
|
638 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
639 | + } else { |
|
640 | + $context['error_message'] = $txt['try_again']; |
|
641 | + } |
|
604 | 642 | |
605 | 643 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
606 | 644 | { |
@@ -622,12 +660,14 @@ discard block |
||
622 | 660 | { |
623 | 661 | global $db_row_count; |
624 | 662 | |
625 | - if ($counter !== false) |
|
626 | - return pg_fetch_row($request, $counter); |
|
663 | + if ($counter !== false) { |
|
664 | + return pg_fetch_row($request, $counter); |
|
665 | + } |
|
627 | 666 | |
628 | 667 | // Reset the row counter... |
629 | - if (!isset($db_row_count[(int) $request])) |
|
630 | - $db_row_count[(int) $request] = 0; |
|
668 | + if (!isset($db_row_count[(int) $request])) { |
|
669 | + $db_row_count[(int) $request] = 0; |
|
670 | + } |
|
631 | 671 | |
632 | 672 | // Return the right row. |
633 | 673 | return @pg_fetch_row($request, $db_row_count[(int) $request]++); |
@@ -644,12 +684,14 @@ discard block |
||
644 | 684 | { |
645 | 685 | global $db_row_count; |
646 | 686 | |
647 | - if ($counter !== false) |
|
648 | - return pg_fetch_assoc($request, $counter); |
|
687 | + if ($counter !== false) { |
|
688 | + return pg_fetch_assoc($request, $counter); |
|
689 | + } |
|
649 | 690 | |
650 | 691 | // Reset the row counter... |
651 | - if (!isset($db_row_count[(int) $request])) |
|
652 | - $db_row_count[(int) $request] = 0; |
|
692 | + if (!isset($db_row_count[(int) $request])) { |
|
693 | + $db_row_count[(int) $request] = 0; |
|
694 | + } |
|
653 | 695 | |
654 | 696 | // Return the right row. |
655 | 697 | return @pg_fetch_assoc($request, $db_row_count[(int) $request]++); |
@@ -702,11 +744,13 @@ discard block |
||
702 | 744 | |
703 | 745 | $replace = ''; |
704 | 746 | |
705 | - if (empty($data)) |
|
706 | - return; |
|
747 | + if (empty($data)) { |
|
748 | + return; |
|
749 | + } |
|
707 | 750 | |
708 | - if (!is_array($data[array_rand($data)])) |
|
709 | - $data = array($data); |
|
751 | + if (!is_array($data[array_rand($data)])) { |
|
752 | + $data = array($data); |
|
753 | + } |
|
710 | 754 | |
711 | 755 | // Replace the prefix holder with the actual prefix. |
712 | 756 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
@@ -725,11 +769,13 @@ discard block |
||
725 | 769 | //pg 9.5 got replace support |
726 | 770 | $pg_version = $smcFunc['db_get_version'](); |
727 | 771 | // if we got a Beta Version |
728 | - if (stripos($pg_version, 'beta') !== false) |
|
729 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
772 | + if (stripos($pg_version, 'beta') !== false) { |
|
773 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
774 | + } |
|
730 | 775 | // or RC |
731 | - if (stripos($pg_version, 'rc') !== false) |
|
732 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
776 | + if (stripos($pg_version, 'rc') !== false) { |
|
777 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
778 | + } |
|
733 | 779 | |
734 | 780 | $replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false); |
735 | 781 | } |
@@ -748,32 +794,35 @@ discard block |
||
748 | 794 | $key_str .= ($count_pk > 0 ? ',' : ''); |
749 | 795 | $key_str .= $columnName; |
750 | 796 | $count_pk++; |
751 | - } |
|
752 | - else if ($method == 'replace') //normal field |
|
797 | + } else if ($method == 'replace') { |
|
798 | + //normal field |
|
753 | 799 | { |
754 | 800 | $col_str .= ($count > 0 ? ',' : ''); |
801 | + } |
|
755 | 802 | $col_str .= $columnName . ' = EXCLUDED.' . $columnName; |
756 | 803 | $count++; |
757 | 804 | } |
758 | 805 | } |
759 | - if ($method == 'replace') |
|
760 | - $replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str; |
|
761 | - else |
|
762 | - $replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING'; |
|
763 | - } |
|
764 | - else if ($method == 'replace') |
|
806 | + if ($method == 'replace') { |
|
807 | + $replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str; |
|
808 | + } else { |
|
809 | + $replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING'; |
|
810 | + } |
|
811 | + } else if ($method == 'replace') |
|
765 | 812 | { |
766 | 813 | foreach ($columns as $columnName => $type) |
767 | 814 | { |
768 | 815 | // Are we restricting the length? |
769 | - if (strpos($type, 'string-') !== false) |
|
770 | - $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
771 | - else |
|
772 | - $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
816 | + if (strpos($type, 'string-') !== false) { |
|
817 | + $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
818 | + } else { |
|
819 | + $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
820 | + } |
|
773 | 821 | |
774 | 822 | // A key? That's what we were looking for. |
775 | - if (in_array($columnName, $keys)) |
|
776 | - $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
823 | + if (in_array($columnName, $keys)) { |
|
824 | + $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
825 | + } |
|
777 | 826 | $count++; |
778 | 827 | } |
779 | 828 | |
@@ -809,10 +858,11 @@ discard block |
||
809 | 858 | foreach ($columns as $columnName => $type) |
810 | 859 | { |
811 | 860 | // Are we restricting the length? |
812 | - if (strpos($type, 'string-') !== false) |
|
813 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
814 | - else |
|
815 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
861 | + if (strpos($type, 'string-') !== false) { |
|
862 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
863 | + } else { |
|
864 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
865 | + } |
|
816 | 866 | } |
817 | 867 | $insertData = substr($insertData, 0, -2) . ')'; |
818 | 868 | |
@@ -821,8 +871,9 @@ discard block |
||
821 | 871 | |
822 | 872 | // Here's where the variables are injected to the query. |
823 | 873 | $insertRows = array(); |
824 | - foreach ($data as $dataRow) |
|
825 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
874 | + foreach ($data as $dataRow) { |
|
875 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
876 | + } |
|
826 | 877 | |
827 | 878 | // Do the insert. |
828 | 879 | $request = $smcFunc['db_query']('', ' |
@@ -839,19 +890,21 @@ discard block |
||
839 | 890 | |
840 | 891 | if ($with_returning && $request !== false) |
841 | 892 | { |
842 | - if ($returnmode === 2) |
|
843 | - $return_var = array(); |
|
893 | + if ($returnmode === 2) { |
|
894 | + $return_var = array(); |
|
895 | + } |
|
844 | 896 | |
845 | 897 | while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning) |
846 | 898 | { |
847 | - if (is_numeric($row[0])) // try to emulate mysql limitation |
|
899 | + if (is_numeric($row[0])) { |
|
900 | + // try to emulate mysql limitation |
|
848 | 901 | { |
849 | 902 | if ($returnmode === 1) |
850 | 903 | $return_var = $row[0]; |
851 | - elseif ($returnmode === 2) |
|
852 | - $return_var[] = $row[0]; |
|
853 | - } |
|
854 | - else |
|
904 | + } elseif ($returnmode === 2) { |
|
905 | + $return_var[] = $row[0]; |
|
906 | + } |
|
907 | + } else |
|
855 | 908 | { |
856 | 909 | $with_returning = false; |
857 | 910 | trigger_error('trying to returning ID Field which is not a Int field', E_USER_ERROR); |
@@ -860,9 +913,10 @@ discard block |
||
860 | 913 | } |
861 | 914 | } |
862 | 915 | |
863 | - if ($with_returning && !empty($return_var)) |
|
864 | - return $return_var; |
|
865 | -} |
|
916 | + if ($with_returning && !empty($return_var)) { |
|
917 | + return $return_var; |
|
918 | + } |
|
919 | + } |
|
866 | 920 | |
867 | 921 | /** |
868 | 922 | * Dummy function really. Doesn't do anything on PostgreSQL. |
@@ -899,8 +953,9 @@ discard block |
||
899 | 953 | */ |
900 | 954 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
901 | 955 | { |
902 | - if (empty($log_message)) |
|
903 | - $log_message = $error_message; |
|
956 | + if (empty($log_message)) { |
|
957 | + $log_message = $error_message; |
|
958 | + } |
|
904 | 959 | |
905 | 960 | foreach (debug_backtrace() as $step) |
906 | 961 | { |
@@ -919,12 +974,14 @@ discard block |
||
919 | 974 | } |
920 | 975 | |
921 | 976 | // A special case - we want the file and line numbers for debugging. |
922 | - if ($error_type == 'return') |
|
923 | - return array($file, $line); |
|
977 | + if ($error_type == 'return') { |
|
978 | + return array($file, $line); |
|
979 | + } |
|
924 | 980 | |
925 | 981 | // Is always a critical error. |
926 | - if (function_exists('log_error')) |
|
927 | - log_error($log_message, 'critical', $file, $line); |
|
982 | + if (function_exists('log_error')) { |
|
983 | + log_error($log_message, 'critical', $file, $line); |
|
984 | + } |
|
928 | 985 | |
929 | 986 | if (function_exists('fatal_error')) |
930 | 987 | { |
@@ -932,12 +989,12 @@ discard block |
||
932 | 989 | |
933 | 990 | // Cannot continue... |
934 | 991 | exit; |
992 | + } elseif ($error_type) { |
|
993 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
994 | + } else { |
|
995 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
996 | + } |
|
935 | 997 | } |
936 | - elseif ($error_type) |
|
937 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
938 | - else |
|
939 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
940 | -} |
|
941 | 998 | |
942 | 999 | /** |
943 | 1000 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -954,10 +1011,11 @@ discard block |
||
954 | 1011 | '\\' => '\\\\', |
955 | 1012 | ); |
956 | 1013 | |
957 | - if ($translate_human_wildcards) |
|
958 | - $replacements += array( |
|
1014 | + if ($translate_human_wildcards) { |
|
1015 | + $replacements += array( |
|
959 | 1016 | '*' => '%', |
960 | 1017 | ); |
1018 | + } |
|
961 | 1019 | |
962 | 1020 | return strtr($string, $replacements); |
963 | 1021 | } |
@@ -986,14 +1044,16 @@ discard block |
||
986 | 1044 | static $pg_error_data_prep; |
987 | 1045 | |
988 | 1046 | // without database we can't do anything |
989 | - if (empty($db_connection)) |
|
990 | - return; |
|
1047 | + if (empty($db_connection)) { |
|
1048 | + return; |
|
1049 | + } |
|
991 | 1050 | |
992 | - if (empty($pg_error_data_prep)) |
|
993 | - $pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors', |
|
1051 | + if (empty($pg_error_data_prep)) { |
|
1052 | + $pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors', |
|
994 | 1053 | 'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line) |
995 | 1054 | VALUES( $1, $2, $3, $4, $5, $6, $7, $8, $9)' |
996 | 1055 | ); |
1056 | + } |
|
997 | 1057 | |
998 | 1058 | pg_execute($db_connection, 'smf_log_errors', $error_array); |
999 | 1059 | } |
@@ -1013,8 +1073,9 @@ discard block |
||
1013 | 1073 | $count = count($array_values); |
1014 | 1074 | $then = ($desc ? ' THEN -' : ' THEN '); |
1015 | 1075 | |
1016 | - for ($i = 0; $i < $count; $i++) |
|
1017 | - $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
1076 | + for ($i = 0; $i < $count; $i++) { |
|
1077 | + $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
1078 | + } |
|
1018 | 1079 | |
1019 | 1080 | $return .= 'END'; |
1020 | 1081 | return $return; |