@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
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 | * Class Likes |
@@ -108,8 +109,9 @@ discard block |
||
108 | 109 | $this->_extra = isset($_GET['extra']) ? $_GET['extra'] : false; |
109 | 110 | |
110 | 111 | // We do not want to output debug information here. |
111 | - if ($this->_js) |
|
112 | - $db_show_debug = false; |
|
112 | + if ($this->_js) { |
|
113 | + $db_show_debug = false; |
|
114 | + } |
|
113 | 115 | } |
114 | 116 | |
115 | 117 | /** |
@@ -143,8 +145,9 @@ discard block |
||
143 | 145 | $call = $this->_sa; |
144 | 146 | |
145 | 147 | // Guest can only view likes. |
146 | - if ($call != 'view') |
|
147 | - is_not_guest(); |
|
148 | + if ($call != 'view') { |
|
149 | + is_not_guest(); |
|
150 | + } |
|
148 | 151 | |
149 | 152 | checkSession('get'); |
150 | 153 | |
@@ -182,15 +185,17 @@ discard block |
||
182 | 185 | global $smcFunc, $modSettings; |
183 | 186 | |
184 | 187 | // This feature is currently disable. |
185 | - if (empty($modSettings['enable_likes'])) |
|
186 | - return $this->_error = 'like_disable'; |
|
188 | + if (empty($modSettings['enable_likes'])) { |
|
189 | + return $this->_error = 'like_disable'; |
|
190 | + } |
|
187 | 191 | |
188 | 192 | // Zerothly, they did indicate some kind of content to like, right? |
189 | 193 | preg_match('~^([a-z0-9\-\_]{1,6})~i', $this->_type, $matches); |
190 | 194 | $this->_type = isset($matches[1]) ? $matches[1] : ''; |
191 | 195 | |
192 | - if ($this->_type == '' || $this->_content <= 0) |
|
193 | - return $this->_error = 'cannot_'; |
|
196 | + if ($this->_type == '' || $this->_content <= 0) { |
|
197 | + return $this->_error = 'cannot_'; |
|
198 | + } |
|
194 | 199 | |
195 | 200 | // First we need to verify if the user can see the type of content or not. This is set up to be extensible, |
196 | 201 | // so we'll check for the one type we do know about, and if it's not that, we'll defer to any hooks. |
@@ -209,12 +214,14 @@ discard block |
||
209 | 214 | 'msg' => $this->_content, |
210 | 215 | ) |
211 | 216 | ); |
212 | - if ($smcFunc['db_num_rows']($request) == 1) |
|
213 | - list ($this->_idTopic, $topicOwner) = $smcFunc['db_fetch_row']($request); |
|
217 | + if ($smcFunc['db_num_rows']($request) == 1) { |
|
218 | + list ($this->_idTopic, $topicOwner) = $smcFunc['db_fetch_row']($request); |
|
219 | + } |
|
214 | 220 | |
215 | 221 | $smcFunc['db_free_result']($request); |
216 | - if (empty($this->_idTopic)) |
|
217 | - return $this->_error = 'cannot_'; |
|
222 | + if (empty($this->_idTopic)) { |
|
223 | + return $this->_error = 'cannot_'; |
|
224 | + } |
|
218 | 225 | |
219 | 226 | // So we know what topic it's in and more importantly we know the user can see it. |
220 | 227 | // If we're not viewing, we need some info set up. |
@@ -224,9 +231,7 @@ discard block |
||
224 | 231 | $this->_validLikes['can_see'] = allowedTo('likes_view') ? true : 'cannot_view_likes'; |
225 | 232 | |
226 | 233 | $this->_validLikes['can_like'] = ($this->_user['id'] == $topicOwner ? 'cannot_like_content' : (allowedTo('likes_like') ? true : 'cannot_like_content')); |
227 | - } |
|
228 | - |
|
229 | - else |
|
234 | + } else |
|
230 | 235 | { |
231 | 236 | // Modders: This will give you whatever the user offers up in terms of liking, e.g. $this->_type=msg, $this->_content=1 |
232 | 237 | // When you hook this, check $this->_type first. If it is not something your mod worries about, return false. |
@@ -244,8 +249,9 @@ discard block |
||
244 | 249 | if ($result !== false) |
245 | 250 | { |
246 | 251 | // Match the type with what we already have. |
247 | - if (!isset($result['type']) || $result['type'] != $this->_type) |
|
248 | - return $this->_error = 'not_valid_like_type'; |
|
252 | + if (!isset($result['type']) || $result['type'] != $this->_type) { |
|
253 | + return $this->_error = 'not_valid_like_type'; |
|
254 | + } |
|
249 | 255 | |
250 | 256 | // Fill out the rest. |
251 | 257 | $this->_type = $result['type']; |
@@ -256,17 +262,20 @@ discard block |
||
256 | 262 | } |
257 | 263 | } |
258 | 264 | |
259 | - if (!$found) |
|
260 | - return $this->_error = 'cannot_'; |
|
265 | + if (!$found) { |
|
266 | + return $this->_error = 'cannot_'; |
|
267 | + } |
|
261 | 268 | } |
262 | 269 | |
263 | 270 | // Does the user can see this? |
264 | - if (isset($this->_validLikes['can_see']) && is_string($this->_validLikes['can_see'])) |
|
265 | - return $this->_error = $this->_validLikes['can_see']; |
|
271 | + if (isset($this->_validLikes['can_see']) && is_string($this->_validLikes['can_see'])) { |
|
272 | + return $this->_error = $this->_validLikes['can_see']; |
|
273 | + } |
|
266 | 274 | |
267 | 275 | // Does the user can like this? Viewing a list of likes doesn't require this permission. |
268 | - if ($this->_sa != 'view' && isset($this->_validLikes['can_like']) && is_string($this->_validLikes['can_like'])) |
|
269 | - return $this->_error = $this->_validLikes['can_like']; |
|
276 | + if ($this->_sa != 'view' && isset($this->_validLikes['can_like']) && is_string($this->_validLikes['can_like'])) { |
|
277 | + return $this->_error = $this->_validLikes['can_like']; |
|
278 | + } |
|
270 | 279 | } |
271 | 280 | |
272 | 281 | /** |
@@ -291,8 +300,9 @@ discard block |
||
291 | 300 | ); |
292 | 301 | |
293 | 302 | // Are we calling this directly? if so, set a proper data for the response. Do note that __METHOD__ returns both the class name and the function name. |
294 | - if ($this->_sa == __FUNCTION__) |
|
295 | - $this->_data = __FUNCTION__; |
|
303 | + if ($this->_sa == __FUNCTION__) { |
|
304 | + $this->_data = __FUNCTION__; |
|
305 | + } |
|
296 | 306 | } |
297 | 307 | |
298 | 308 | /** |
@@ -322,8 +332,8 @@ discard block |
||
322 | 332 | |
323 | 333 | // Add a background task to process sending alerts. |
324 | 334 | // Mod author, you can add your own background task for your own custom like event using the "integrate_issue_like" hook or your callback, both are immediately called after this. |
325 | - if ($this->_type == 'msg') |
|
326 | - $smcFunc['db_insert']('insert', |
|
335 | + if ($this->_type == 'msg') { |
|
336 | + $smcFunc['db_insert']('insert', |
|
327 | 337 | '{db_prefix}background_tasks', |
328 | 338 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
329 | 339 | array('$sourcedir/tasks/Likes-Notify.php', 'Likes_Notify_Background', json_encode(array( |
@@ -335,10 +345,12 @@ discard block |
||
335 | 345 | )), 0), |
336 | 346 | array('id_task') |
337 | 347 | ); |
348 | + } |
|
338 | 349 | |
339 | 350 | // Are we calling this directly? if so, set a proper data for the response. Do note that __METHOD__ returns both the class name and the function name. |
340 | - if ($this->_sa == __FUNCTION__) |
|
341 | - $this->_data = __FUNCTION__; |
|
351 | + if ($this->_sa == __FUNCTION__) { |
|
352 | + $this->_data = __FUNCTION__; |
|
353 | + } |
|
342 | 354 | } |
343 | 355 | |
344 | 356 | /** |
@@ -364,8 +376,9 @@ discard block |
||
364 | 376 | $smcFunc['db_free_result']($request); |
365 | 377 | |
366 | 378 | // If you want to call this directly, fill out _data property too. |
367 | - if ($this->_sa == __FUNCTION__) |
|
368 | - $this->_data = $this->_numLikes; |
|
379 | + if ($this->_sa == __FUNCTION__) { |
|
380 | + $this->_data = $this->_numLikes; |
|
381 | + } |
|
369 | 382 | } |
370 | 383 | |
371 | 384 | /** |
@@ -378,8 +391,9 @@ discard block |
||
378 | 391 | global $smcFunc; |
379 | 392 | |
380 | 393 | // Safety first! |
381 | - if (empty($this->_type) || empty($this->_content)) |
|
382 | - return $this->_error = 'cannot_'; |
|
394 | + if (empty($this->_type) || empty($this->_content)) { |
|
395 | + return $this->_error = 'cannot_'; |
|
396 | + } |
|
383 | 397 | |
384 | 398 | // Do we already like this? |
385 | 399 | $request = $smcFunc['db_query']('', ' |
@@ -397,26 +411,28 @@ discard block |
||
397 | 411 | $this->_alreadyLiked = (bool) $smcFunc['db_num_rows']($request) != 0; |
398 | 412 | $smcFunc['db_free_result']($request); |
399 | 413 | |
400 | - if ($this->_alreadyLiked) |
|
401 | - $this->delete(); |
|
402 | - |
|
403 | - else |
|
404 | - $this->insert(); |
|
414 | + if ($this->_alreadyLiked) { |
|
415 | + $this->delete(); |
|
416 | + } else { |
|
417 | + $this->insert(); |
|
418 | + } |
|
405 | 419 | |
406 | 420 | // Now, how many people like this content now? We *could* just +1 / -1 the relevant container but that has proven to become unstable. |
407 | 421 | $this->_count(); |
408 | 422 | |
409 | 423 | // Update the likes count for messages. |
410 | - if ($this->_type == 'msg') |
|
411 | - $this->msgIssueLike(); |
|
424 | + if ($this->_type == 'msg') { |
|
425 | + $this->msgIssueLike(); |
|
426 | + } |
|
412 | 427 | |
413 | 428 | // Any callbacks? |
414 | 429 | elseif (!empty($this->_validLikes['callback'])) |
415 | 430 | { |
416 | 431 | $call = call_helper($this->_validLikes['callback'], true); |
417 | 432 | |
418 | - if (!empty($call)) |
|
419 | - call_user_func_array($call, array($this)); |
|
433 | + if (!empty($call)) { |
|
434 | + call_user_func_array($call, array($this)); |
|
435 | + } |
|
420 | 436 | } |
421 | 437 | |
422 | 438 | // Sometimes there might be other things that need updating after we do this like. |
@@ -425,8 +441,9 @@ discard block |
||
425 | 441 | // Now some clean up. This is provided here for any like handlers that want to do any cache flushing. |
426 | 442 | // This way a like handler doesn't need to explicitly declare anything in integrate_issue_like, but do so |
427 | 443 | // in integrate_valid_likes where it absolutely has to exist. |
428 | - if (!empty($this->_validLikes['flush_cache'])) |
|
429 | - cache_put_data($this->_validLikes['flush_cache'], null); |
|
444 | + if (!empty($this->_validLikes['flush_cache'])) { |
|
445 | + cache_put_data($this->_validLikes['flush_cache'], null); |
|
446 | + } |
|
430 | 447 | |
431 | 448 | // All done, start building the data to pass as response. |
432 | 449 | $this->_data = array( |
@@ -450,8 +467,9 @@ discard block |
||
450 | 467 | { |
451 | 468 | global $smcFunc; |
452 | 469 | |
453 | - if ($this->_type !== 'msg') |
|
454 | - return; |
|
470 | + if ($this->_type !== 'msg') { |
|
471 | + return; |
|
472 | + } |
|
455 | 473 | |
456 | 474 | $smcFunc['db_query']('', ' |
457 | 475 | UPDATE {db_prefix}messages |
@@ -492,8 +510,9 @@ discard block |
||
492 | 510 | 'like_type' => $this->_type, |
493 | 511 | ) |
494 | 512 | ); |
495 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
496 | - $context['likers'][$row['id_member']] = array('timestamp' => $row['like_time']); |
|
513 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
514 | + $context['likers'][$row['id_member']] = array('timestamp' => $row['like_time']); |
|
515 | + } |
|
497 | 516 | |
498 | 517 | // Now to get member data, including avatars and so on. |
499 | 518 | $members = array_keys($context['likers']); |
@@ -501,8 +520,9 @@ discard block |
||
501 | 520 | if (count($loaded) != count($members)) |
502 | 521 | { |
503 | 522 | $members = array_diff($members, $loaded); |
504 | - foreach ($members as $not_loaded) |
|
505 | - unset ($context['likers'][$not_loaded]); |
|
523 | + foreach ($members as $not_loaded) { |
|
524 | + unset ($context['likers'][$not_loaded]); |
|
525 | + } |
|
506 | 526 | } |
507 | 527 | |
508 | 528 | foreach ($context['likers'] as $liker => $dummy) |
@@ -544,12 +564,14 @@ discard block |
||
544 | 564 | global $context, $txt; |
545 | 565 | |
546 | 566 | // Don't do anything if someone else has already take care of the response. |
547 | - if (!$this->_setResponse) |
|
548 | - return; |
|
567 | + if (!$this->_setResponse) { |
|
568 | + return; |
|
569 | + } |
|
549 | 570 | |
550 | 571 | // Want a json response huh? |
551 | - if ($this->_validLikes['json']) |
|
552 | - return $this->jsonResponse(); |
|
572 | + if ($this->_validLikes['json']) { |
|
573 | + return $this->jsonResponse(); |
|
574 | + } |
|
553 | 575 | |
554 | 576 | // Set everything up for display. |
555 | 577 | loadTemplate('Likes'); |
@@ -559,8 +581,9 @@ discard block |
||
559 | 581 | if ($this->_error) |
560 | 582 | { |
561 | 583 | // If this is a generic error, set it up good. |
562 | - if ($this->_error == 'cannot_') |
|
563 | - $this->_error = $this->_sa == 'view' ? 'cannot_view_likes' : 'cannot_like_content'; |
|
584 | + if ($this->_error == 'cannot_') { |
|
585 | + $this->_error = $this->_sa == 'view' ? 'cannot_view_likes' : 'cannot_like_content'; |
|
586 | + } |
|
564 | 587 | |
565 | 588 | // Is this request coming from an ajax call? |
566 | 589 | if ($this->_js) |
@@ -570,8 +593,9 @@ discard block |
||
570 | 593 | } |
571 | 594 | |
572 | 595 | // Nope? then just do a redirect to whatever URL was provided. |
573 | - else |
|
574 | - redirectexit(!empty($this->_validLikes['redirect']) ? $this->_validLikes['redirect'] . ';error=' . $this->_error : ''); |
|
596 | + else { |
|
597 | + redirectexit(!empty($this->_validLikes['redirect']) ? $this->_validLikes['redirect'] . ';error=' . $this->_error : ''); |
|
598 | + } |
|
575 | 599 | |
576 | 600 | return; |
577 | 601 | } |
@@ -580,8 +604,9 @@ discard block |
||
580 | 604 | else |
581 | 605 | { |
582 | 606 | // Not an ajax request so send the user back to the previous location or the main page. |
583 | - if (!$this->_js) |
|
584 | - redirectexit(!empty($this->_validLikes['redirect']) ? $this->_validLikes['redirect'] : ''); |
|
607 | + if (!$this->_js) { |
|
608 | + redirectexit(!empty($this->_validLikes['redirect']) ? $this->_validLikes['redirect'] : ''); |
|
609 | + } |
|
585 | 610 | |
586 | 611 | // These fine gentlemen all share the same template. |
587 | 612 | $generic = array('delete', 'insert', '_count'); |
@@ -612,8 +637,9 @@ discard block |
||
612 | 637 | // If there is an error, send it. |
613 | 638 | if ($this->_error) |
614 | 639 | { |
615 | - if ($this->_error == 'cannot_') |
|
616 | - $this->_error = $this->_sa == 'view' ? 'cannot_view_likes' : 'cannot_like_content'; |
|
640 | + if ($this->_error == 'cannot_') { |
|
641 | + $this->_error = $this->_sa == 'view' ? 'cannot_view_likes' : 'cannot_like_content'; |
|
642 | + } |
|
617 | 643 | |
618 | 644 | $print['error'] = $this->_error; |
619 | 645 | } |
@@ -649,33 +675,36 @@ discard block |
||
649 | 675 | <body style="background-color: #444455; color: white; font-style: italic; font-family: serif;"> |
650 | 676 | <div style="margin-top: 12%; font-size: 1.1em; line-height: 1.4; text-align: center;">'; |
651 | 677 | |
652 | - if (!isset($_GET['verse']) || ($_GET['verse'] != '2:18' && $_GET['verse'] != '22:1-2')) |
|
653 | - $_GET['verse'] = '4:16'; |
|
678 | + if (!isset($_GET['verse']) || ($_GET['verse'] != '2:18' && $_GET['verse'] != '22:1-2')) { |
|
679 | + $_GET['verse'] = '4:16'; |
|
680 | + } |
|
654 | 681 | |
655 | - if ($_GET['verse'] == '2:18') |
|
656 | - echo ' |
|
682 | + if ($_GET['verse'] == '2:18') { |
|
683 | + echo ' |
|
657 | 684 | Woe, it was that his name wasn\'t <em>known</em>, that he came in mystery, and was recognized by none. And it became to be in those days <em>something</em>. Something not yet <em id="unknown" name="[Unknown]">unknown</em> to mankind. And thus what was to be known the <em>secret project</em> began into its existence. Henceforth the opposition was only <em>weary</em> and <em>fearful</em>, for now their match was at arms against them.'; |
658 | - elseif ($_GET['verse'] == '4:16') |
|
659 | - echo ' |
|
685 | + } elseif ($_GET['verse'] == '4:16') { |
|
686 | + echo ' |
|
660 | 687 | And it came to pass that the <em>unbelievers</em> dwindled in number and saw rise of many <em>proselytizers</em>, and the opposition found fear in the face of the <em>x</em> and the <em>j</em> while those who stood with the <em>something</em> grew stronger and came together. Still, this was only the <em>beginning</em>, and what lay in the future was <em id="unknown" name="[Unknown]">unknown</em> to all, even those on the right side.'; |
661 | - elseif ($_GET['verse'] == '22:1-2') |
|
662 | - echo ' |
|
688 | + } elseif ($_GET['verse'] == '22:1-2') { |
|
689 | + echo ' |
|
663 | 690 | <p>Now <em>behold</em>, that which was once the secret project was <em id="unknown" name="[Unknown]">unknown</em> no longer. Alas, it needed more than <em>only one</em>, but yet even thought otherwise. It became that the opposition <em>rumored</em> and lied, but still to no avail. Their match, though not <em>perfect</em>, had them outdone.</p> |
664 | 691 | <p style="margin: 2ex 1ex 0 1ex; font-size: 1.05em; line-height: 1.5; text-align: center;">Let it continue. <em>The end</em>.</p>'; |
692 | + } |
|
665 | 693 | |
666 | 694 | echo ' |
667 | 695 | </div> |
668 | 696 | <div style="margin-top: 2ex; font-size: 2em; text-align: right;">'; |
669 | 697 | |
670 | - if ($_GET['verse'] == '2:18') |
|
671 | - echo ' |
|
698 | + if ($_GET['verse'] == '2:18') { |
|
699 | + echo ' |
|
672 | 700 | from <span style="font-family: Georgia, serif;"><strong><a href="', $scripturl, '?action=about:unknown;verse=4:16" style="color: white; text-decoration: none; cursor: text;">The Book of Unknown</a></strong>, 2:18</span>'; |
673 | - elseif ($_GET['verse'] == '4:16') |
|
674 | - echo ' |
|
701 | + } elseif ($_GET['verse'] == '4:16') { |
|
702 | + echo ' |
|
675 | 703 | from <span style="font-family: Georgia, serif;"><strong><a href="', $scripturl, '?action=about:unknown;verse=22:1-2" style="color: white; text-decoration: none; cursor: text;">The Book of Unknown</a></strong>, 4:16</span>'; |
676 | - elseif ($_GET['verse'] == '22:1-2') |
|
677 | - echo ' |
|
704 | + } elseif ($_GET['verse'] == '22:1-2') { |
|
705 | + echo ' |
|
678 | 706 | from <span style="font-family: Georgia, serif;"><strong>The Book of Unknown</strong>, 22:1-2</span>'; |
707 | + } |
|
679 | 708 | |
680 | 709 | echo ' |
681 | 710 | </div> |
@@ -30,8 +30,9 @@ discard block |
||
30 | 30 | * @version 2.1 Beta 3 |
31 | 31 | */ |
32 | 32 | |
33 | -if (!defined('SMF')) |
|
33 | +if (!defined('SMF')) { |
|
34 | 34 | die('No direct access...'); |
35 | +} |
|
35 | 36 | |
36 | 37 | /** |
37 | 38 | * Subaction handler - manages the action and delegates control to the proper |
@@ -103,12 +104,12 @@ discard block |
||
103 | 104 | cache_put_data('minimized_css', null); |
104 | 105 | |
105 | 106 | // Follow the sa or just go to administration. |
106 | - if (isset($_GET['sa']) && !empty($subActions[$_GET['sa']])) |
|
107 | - call_helper($subActions[$_GET['sa']]); |
|
108 | - |
|
109 | - else |
|
110 | - call_helper($subActions['admin']); |
|
111 | -} |
|
107 | + if (isset($_GET['sa']) && !empty($subActions[$_GET['sa']])) { |
|
108 | + call_helper($subActions[$_GET['sa']]); |
|
109 | + } else { |
|
110 | + call_helper($subActions['admin']); |
|
111 | + } |
|
112 | + } |
|
112 | 113 | |
113 | 114 | /** |
114 | 115 | * This function allows administration of themes and their settings, |
@@ -130,15 +131,16 @@ discard block |
||
130 | 131 | checkSession(); |
131 | 132 | validateToken('admin-tm'); |
132 | 133 | |
133 | - if (isset($_POST['options']['known_themes'])) |
|
134 | - foreach ($_POST['options']['known_themes'] as $key => $id) |
|
134 | + if (isset($_POST['options']['known_themes'])) { |
|
135 | + foreach ($_POST['options']['known_themes'] as $key => $id) |
|
135 | 136 | $_POST['options']['known_themes'][$key] = (int) $id; |
137 | + } else { |
|
138 | + fatal_lang_error('themes_none_selectable', false); |
|
139 | + } |
|
136 | 140 | |
137 | - else |
|
138 | - fatal_lang_error('themes_none_selectable', false); |
|
139 | - |
|
140 | - if (!in_array($_POST['options']['theme_guests'], $_POST['options']['known_themes'])) |
|
141 | - fatal_lang_error('themes_default_selectable', false); |
|
141 | + if (!in_array($_POST['options']['theme_guests'], $_POST['options']['known_themes'])) { |
|
142 | + fatal_lang_error('themes_default_selectable', false); |
|
143 | + } |
|
142 | 144 | |
143 | 145 | // Commit the new settings. |
144 | 146 | updateSettings(array( |
@@ -146,8 +148,9 @@ discard block |
||
146 | 148 | 'theme_guests' => $_POST['options']['theme_guests'], |
147 | 149 | 'knownThemes' => implode(',', $_POST['options']['known_themes']), |
148 | 150 | )); |
149 | - if ((int) $_POST['theme_reset'] == 0 || in_array($_POST['theme_reset'], $_POST['options']['known_themes'])) |
|
150 | - updateMemberData(null, array('id_theme' => (int) $_POST['theme_reset'])); |
|
151 | + if ((int) $_POST['theme_reset'] == 0 || in_array($_POST['theme_reset'], $_POST['options']['known_themes'])) { |
|
152 | + updateMemberData(null, array('id_theme' => (int) $_POST['theme_reset'])); |
|
153 | + } |
|
151 | 154 | |
152 | 155 | redirectexit('action=admin;area=theme;' . $context['session_var'] . '=' . $context['session_id'] . ';sa=admin'); |
153 | 156 | } |
@@ -166,8 +169,9 @@ discard block |
||
166 | 169 | // Look for a non existent theme directory. (ie theme87.) |
167 | 170 | $theme_dir = $boarddir . '/Themes/theme'; |
168 | 171 | $i = 1; |
169 | - while (file_exists($theme_dir . $i)) |
|
170 | - $i++; |
|
172 | + while (file_exists($theme_dir . $i)) { |
|
173 | + $i++; |
|
174 | + } |
|
171 | 175 | |
172 | 176 | $context['new_theme_name'] = 'theme' . $i; |
173 | 177 | |
@@ -189,8 +193,9 @@ discard block |
||
189 | 193 | loadLanguage('Admin'); |
190 | 194 | isAllowedTo('admin_forum'); |
191 | 195 | |
192 | - if (isset($_REQUEST['th'])) |
|
193 | - return SetThemeSettings(); |
|
196 | + if (isset($_REQUEST['th'])) { |
|
197 | + return SetThemeSettings(); |
|
198 | + } |
|
194 | 199 | |
195 | 200 | if (isset($_POST['save'])) |
196 | 201 | { |
@@ -274,12 +279,13 @@ discard block |
||
274 | 279 | $context['themes'] = array(); |
275 | 280 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
276 | 281 | { |
277 | - if (!isset($context['themes'][$row['id_theme']])) |
|
278 | - $context['themes'][$row['id_theme']] = array( |
|
282 | + if (!isset($context['themes'][$row['id_theme']])) { |
|
283 | + $context['themes'][$row['id_theme']] = array( |
|
279 | 284 | 'id' => $row['id_theme'], |
280 | 285 | 'num_default_options' => 0, |
281 | 286 | 'num_members' => 0, |
282 | 287 | ); |
288 | + } |
|
283 | 289 | $context['themes'][$row['id_theme']][$row['variable']] = $row['value']; |
284 | 290 | } |
285 | 291 | $smcFunc['db_free_result']($request); |
@@ -293,8 +299,9 @@ discard block |
||
293 | 299 | 'guest_member' => -1, |
294 | 300 | ) |
295 | 301 | ); |
296 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
297 | - $context['themes'][$row['id_theme']]['num_default_options'] = $row['value']; |
|
302 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
303 | + $context['themes'][$row['id_theme']]['num_default_options'] = $row['value']; |
|
304 | + } |
|
298 | 305 | $smcFunc['db_free_result']($request); |
299 | 306 | |
300 | 307 | // Need to make sure we don't do custom fields. |
@@ -305,8 +312,9 @@ discard block |
||
305 | 312 | ) |
306 | 313 | ); |
307 | 314 | $customFields = array(); |
308 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
309 | - $customFields[] = $row['col_name']; |
|
315 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
316 | + $customFields[] = $row['col_name']; |
|
317 | + } |
|
310 | 318 | $smcFunc['db_free_result']($request); |
311 | 319 | $customFieldsQuery = empty($customFields) ? '' : ('AND variable NOT IN ({array_string:custom_fields})'); |
312 | 320 | |
@@ -321,14 +329,16 @@ discard block |
||
321 | 329 | 'custom_fields' => empty($customFields) ? array() : $customFields, |
322 | 330 | ) |
323 | 331 | ); |
324 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
325 | - $context['themes'][$row['id_theme']]['num_members'] = $row['value']; |
|
332 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
333 | + $context['themes'][$row['id_theme']]['num_members'] = $row['value']; |
|
334 | + } |
|
326 | 335 | $smcFunc['db_free_result']($request); |
327 | 336 | |
328 | 337 | // There has to be a Settings template! |
329 | - foreach ($context['themes'] as $k => $v) |
|
330 | - if (empty($v['theme_dir']) || (!file_exists($v['theme_dir'] . '/Settings.template.php') && empty($v['num_members']))) |
|
338 | + foreach ($context['themes'] as $k => $v) { |
|
339 | + if (empty($v['theme_dir']) || (!file_exists($v['theme_dir'] . '/Settings.template.php') && empty($v['num_members']))) |
|
331 | 340 | unset($context['themes'][$k]); |
341 | + } |
|
332 | 342 | |
333 | 343 | loadTemplate('Themes'); |
334 | 344 | $context['sub_template'] = 'reset_list'; |
@@ -343,16 +353,19 @@ discard block |
||
343 | 353 | checkSession(); |
344 | 354 | validateToken('admin-sto'); |
345 | 355 | |
346 | - if (empty($_POST['options'])) |
|
347 | - $_POST['options'] = array(); |
|
348 | - if (empty($_POST['default_options'])) |
|
349 | - $_POST['default_options'] = array(); |
|
356 | + if (empty($_POST['options'])) { |
|
357 | + $_POST['options'] = array(); |
|
358 | + } |
|
359 | + if (empty($_POST['default_options'])) { |
|
360 | + $_POST['default_options'] = array(); |
|
361 | + } |
|
350 | 362 | |
351 | 363 | // Set up the sql query. |
352 | 364 | $setValues = array(); |
353 | 365 | |
354 | - foreach ($_POST['options'] as $opt => $val) |
|
355 | - $setValues[] = array(-1, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val); |
|
366 | + foreach ($_POST['options'] as $opt => $val) { |
|
367 | + $setValues[] = array(-1, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val); |
|
368 | + } |
|
356 | 369 | |
357 | 370 | $old_settings = array(); |
358 | 371 | foreach ($_POST['default_options'] as $opt => $val) |
@@ -366,8 +379,8 @@ discard block |
||
366 | 379 | if (!empty($setValues)) |
367 | 380 | { |
368 | 381 | // Are there options in non-default themes set that should be cleared? |
369 | - if (!empty($old_settings)) |
|
370 | - $smcFunc['db_query']('', ' |
|
382 | + if (!empty($old_settings)) { |
|
383 | + $smcFunc['db_query']('', ' |
|
371 | 384 | DELETE FROM {db_prefix}themes |
372 | 385 | WHERE id_theme != {int:default_theme} |
373 | 386 | AND id_member = {int:guest_member} |
@@ -378,6 +391,7 @@ discard block |
||
378 | 391 | 'old_settings' => $old_settings, |
379 | 392 | ) |
380 | 393 | ); |
394 | + } |
|
381 | 395 | |
382 | 396 | $smcFunc['db_insert']('replace', |
383 | 397 | '{db_prefix}themes', |
@@ -391,8 +405,7 @@ discard block |
||
391 | 405 | cache_put_data('theme_settings-1', null, 90); |
392 | 406 | |
393 | 407 | redirectexit('action=admin;area=theme;' . $context['session_var'] . '=' . $context['session_id'] . ';sa=reset'); |
394 | - } |
|
395 | - elseif (isset($_POST['submit']) && $_POST['who'] == 1) |
|
408 | + } elseif (isset($_POST['submit']) && $_POST['who'] == 1) |
|
396 | 409 | { |
397 | 410 | checkSession(); |
398 | 411 | validateToken('admin-sto'); |
@@ -405,9 +418,9 @@ discard block |
||
405 | 418 | $old_settings = array(); |
406 | 419 | foreach ($_POST['default_options'] as $opt => $val) |
407 | 420 | { |
408 | - if ($_POST['default_options_master'][$opt] == 0) |
|
409 | - continue; |
|
410 | - elseif ($_POST['default_options_master'][$opt] == 1) |
|
421 | + if ($_POST['default_options_master'][$opt] == 0) { |
|
422 | + continue; |
|
423 | + } elseif ($_POST['default_options_master'][$opt] == 1) |
|
411 | 424 | { |
412 | 425 | // Delete then insert for ease of database compatibility! |
413 | 426 | $smcFunc['db_query']('substring', ' |
@@ -433,8 +446,7 @@ discard block |
||
433 | 446 | ); |
434 | 447 | |
435 | 448 | $old_settings[] = $opt; |
436 | - } |
|
437 | - elseif ($_POST['default_options_master'][$opt] == 2) |
|
449 | + } elseif ($_POST['default_options_master'][$opt] == 2) |
|
438 | 450 | { |
439 | 451 | $smcFunc['db_query']('', ' |
440 | 452 | DELETE FROM {db_prefix}themes |
@@ -449,8 +461,8 @@ discard block |
||
449 | 461 | } |
450 | 462 | |
451 | 463 | // Delete options from other themes. |
452 | - if (!empty($old_settings)) |
|
453 | - $smcFunc['db_query']('', ' |
|
464 | + if (!empty($old_settings)) { |
|
465 | + $smcFunc['db_query']('', ' |
|
454 | 466 | DELETE FROM {db_prefix}themes |
455 | 467 | WHERE id_theme != {int:default_theme} |
456 | 468 | AND id_member > {int:no_member} |
@@ -461,12 +473,13 @@ discard block |
||
461 | 473 | 'old_settings' => $old_settings, |
462 | 474 | ) |
463 | 475 | ); |
476 | + } |
|
464 | 477 | |
465 | 478 | foreach ($_POST['options'] as $opt => $val) |
466 | 479 | { |
467 | - if ($_POST['options_master'][$opt] == 0) |
|
468 | - continue; |
|
469 | - elseif ($_POST['options_master'][$opt] == 1) |
|
480 | + if ($_POST['options_master'][$opt] == 0) { |
|
481 | + continue; |
|
482 | + } elseif ($_POST['options_master'][$opt] == 1) |
|
470 | 483 | { |
471 | 484 | // Delete then insert for ease of database compatibility - again! |
472 | 485 | $smcFunc['db_query']('substring', ' |
@@ -491,8 +504,7 @@ discard block |
||
491 | 504 | 'value' => (is_array($val) ? implode(',', $val) : $val), |
492 | 505 | ) |
493 | 506 | ); |
494 | - } |
|
495 | - elseif ($_POST['options_master'][$opt] == 2) |
|
507 | + } elseif ($_POST['options_master'][$opt] == 2) |
|
496 | 508 | { |
497 | 509 | $smcFunc['db_query']('', ' |
498 | 510 | DELETE FROM {db_prefix}themes |
@@ -509,8 +521,7 @@ discard block |
||
509 | 521 | } |
510 | 522 | |
511 | 523 | redirectexit('action=admin;area=theme;' . $context['session_var'] . '=' . $context['session_id'] . ';sa=reset'); |
512 | - } |
|
513 | - elseif (!empty($_GET['who']) && $_GET['who'] == 2) |
|
524 | + } elseif (!empty($_GET['who']) && $_GET['who'] == 2) |
|
514 | 525 | { |
515 | 526 | checkSession('get'); |
516 | 527 | validateToken('admin-stor', 'request'); |
@@ -525,8 +536,9 @@ discard block |
||
525 | 536 | ) |
526 | 537 | ); |
527 | 538 | $customFields = array(); |
528 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
529 | - $customFields[] = $row['col_name']; |
|
539 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
540 | + $customFields[] = $row['col_name']; |
|
541 | + } |
|
530 | 542 | $smcFunc['db_free_result']($request); |
531 | 543 | } |
532 | 544 | $customFieldsQuery = empty($customFields) ? '' : ('AND variable NOT IN ({array_string:custom_fields})'); |
@@ -578,13 +590,13 @@ discard block |
||
578 | 590 | ) |
579 | 591 | ); |
580 | 592 | $context['theme_options'] = array(); |
581 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
582 | - $context['theme_options'][$row['variable']] = $row['value']; |
|
593 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
594 | + $context['theme_options'][$row['variable']] = $row['value']; |
|
595 | + } |
|
583 | 596 | $smcFunc['db_free_result']($request); |
584 | 597 | |
585 | 598 | $context['theme_options_reset'] = false; |
586 | - } |
|
587 | - else |
|
599 | + } else |
|
588 | 600 | { |
589 | 601 | $context['theme_options'] = array(); |
590 | 602 | $context['theme_options_reset'] = true; |
@@ -597,22 +609,23 @@ discard block |
||
597 | 609 | { |
598 | 610 | unset($context['options'][$i]); |
599 | 611 | continue; |
600 | - } |
|
601 | - elseif (($setting['id'] == 'topics_per_page' || $setting['id'] == 'messages_per_page') && !empty($modSettings['disableCustomPerPage'])) |
|
612 | + } elseif (($setting['id'] == 'topics_per_page' || $setting['id'] == 'messages_per_page') && !empty($modSettings['disableCustomPerPage'])) |
|
602 | 613 | { |
603 | 614 | unset($context['options'][$i]); |
604 | 615 | continue; |
605 | 616 | } |
606 | 617 | |
607 | - if (!isset($setting['type']) || $setting['type'] == 'bool') |
|
608 | - $context['options'][$i]['type'] = 'checkbox'; |
|
609 | - elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') |
|
610 | - $context['options'][$i]['type'] = 'number'; |
|
611 | - elseif ($setting['type'] == 'string') |
|
612 | - $context['options'][$i]['type'] = 'text'; |
|
618 | + if (!isset($setting['type']) || $setting['type'] == 'bool') { |
|
619 | + $context['options'][$i]['type'] = 'checkbox'; |
|
620 | + } elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') { |
|
621 | + $context['options'][$i]['type'] = 'number'; |
|
622 | + } elseif ($setting['type'] == 'string') { |
|
623 | + $context['options'][$i]['type'] = 'text'; |
|
624 | + } |
|
613 | 625 | |
614 | - if (isset($setting['options'])) |
|
615 | - $context['options'][$i]['type'] = 'list'; |
|
626 | + if (isset($setting['options'])) { |
|
627 | + $context['options'][$i]['type'] = 'list'; |
|
628 | + } |
|
616 | 629 | |
617 | 630 | $context['options'][$i]['value'] = !isset($context['theme_options'][$setting['id']]) ? '' : $context['theme_options'][$setting['id']]; |
618 | 631 | } |
@@ -637,8 +650,9 @@ discard block |
||
637 | 650 | { |
638 | 651 | global $txt, $context, $settings, $modSettings, $smcFunc; |
639 | 652 | |
640 | - if (empty($_GET['th']) && empty($_GET['id'])) |
|
641 | - return ThemeAdmin(); |
|
653 | + if (empty($_GET['th']) && empty($_GET['id'])) { |
|
654 | + return ThemeAdmin(); |
|
655 | + } |
|
642 | 656 | |
643 | 657 | $_GET['th'] = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id']; |
644 | 658 | |
@@ -649,8 +663,9 @@ discard block |
||
649 | 663 | isAllowedTo('admin_forum'); |
650 | 664 | |
651 | 665 | // Validate inputs/user. |
652 | - if (empty($_GET['th'])) |
|
653 | - fatal_lang_error('no_theme', false); |
|
666 | + if (empty($_GET['th'])) { |
|
667 | + fatal_lang_error('no_theme', false); |
|
668 | + } |
|
654 | 669 | |
655 | 670 | // Fetch the smiley sets... |
656 | 671 | $sets = explode(',', 'none,' . $modSettings['smiley_sets_known']); |
@@ -658,8 +673,9 @@ discard block |
||
658 | 673 | $context['smiley_sets'] = array( |
659 | 674 | '' => $txt['smileys_no_default'] |
660 | 675 | ); |
661 | - foreach ($sets as $i => $set) |
|
662 | - $context['smiley_sets'][$set] = $smcFunc['htmlspecialchars']($set_names[$i]); |
|
676 | + foreach ($sets as $i => $set) { |
|
677 | + $context['smiley_sets'][$set] = $smcFunc['htmlspecialchars']($set_names[$i]); |
|
678 | + } |
|
663 | 679 | |
664 | 680 | $old_id = $settings['theme_id']; |
665 | 681 | $old_settings = $settings; |
@@ -684,8 +700,9 @@ discard block |
||
684 | 700 | if (file_exists($settings['theme_dir'] . '/index.template.php')) |
685 | 701 | { |
686 | 702 | $file_contents = implode('', file($settings['theme_dir'] . '/index.template.php')); |
687 | - if (preg_match('~\$settings\[\'theme_variants\'\]\s*=(.+?);~', $file_contents, $matches)) |
|
688 | - eval('global $settings;' . $matches[0]); |
|
703 | + if (preg_match('~\$settings\[\'theme_variants\'\]\s*=(.+?);~', $file_contents, $matches)) { |
|
704 | + eval('global $settings;' . $matches[0]); |
|
705 | + } |
|
689 | 706 | } |
690 | 707 | |
691 | 708 | // Submitting! |
@@ -694,37 +711,45 @@ discard block |
||
694 | 711 | checkSession(); |
695 | 712 | validateToken('admin-sts'); |
696 | 713 | |
697 | - if (empty($_POST['options'])) |
|
698 | - $_POST['options'] = array(); |
|
699 | - if (empty($_POST['default_options'])) |
|
700 | - $_POST['default_options'] = array(); |
|
714 | + if (empty($_POST['options'])) { |
|
715 | + $_POST['options'] = array(); |
|
716 | + } |
|
717 | + if (empty($_POST['default_options'])) { |
|
718 | + $_POST['default_options'] = array(); |
|
719 | + } |
|
701 | 720 | |
702 | 721 | // Make sure items are cast correctly. |
703 | 722 | foreach ($context['theme_settings'] as $item) |
704 | 723 | { |
705 | 724 | // Disregard this item if this is just a separator. |
706 | - if (!is_array($item)) |
|
707 | - continue; |
|
725 | + if (!is_array($item)) { |
|
726 | + continue; |
|
727 | + } |
|
708 | 728 | |
709 | 729 | foreach (array('options', 'default_options') as $option) |
710 | 730 | { |
711 | - if (!isset($_POST[$option][$item['id']])) |
|
712 | - continue; |
|
731 | + if (!isset($_POST[$option][$item['id']])) { |
|
732 | + continue; |
|
733 | + } |
|
713 | 734 | // Checkbox. |
714 | - elseif (empty($item['type'])) |
|
715 | - $_POST[$option][$item['id']] = $_POST[$option][$item['id']] ? 1 : 0; |
|
735 | + elseif (empty($item['type'])) { |
|
736 | + $_POST[$option][$item['id']] = $_POST[$option][$item['id']] ? 1 : 0; |
|
737 | + } |
|
716 | 738 | // Number |
717 | - elseif ($item['type'] == 'number') |
|
718 | - $_POST[$option][$item['id']] = (int) $_POST[$option][$item['id']]; |
|
739 | + elseif ($item['type'] == 'number') { |
|
740 | + $_POST[$option][$item['id']] = (int) $_POST[$option][$item['id']]; |
|
741 | + } |
|
719 | 742 | } |
720 | 743 | } |
721 | 744 | |
722 | 745 | // Set up the sql query. |
723 | 746 | $inserts = array(); |
724 | - foreach ($_POST['options'] as $opt => $val) |
|
725 | - $inserts[] = array(0, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val); |
|
726 | - foreach ($_POST['default_options'] as $opt => $val) |
|
727 | - $inserts[] = array(0, 1, $opt, is_array($val) ? implode(',', $val) : $val); |
|
747 | + foreach ($_POST['options'] as $opt => $val) { |
|
748 | + $inserts[] = array(0, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val); |
|
749 | + } |
|
750 | + foreach ($_POST['default_options'] as $opt => $val) { |
|
751 | + $inserts[] = array(0, 1, $opt, is_array($val) ? implode(',', $val) : $val); |
|
752 | + } |
|
728 | 753 | // If we're actually inserting something.. |
729 | 754 | if (!empty($inserts)) |
730 | 755 | { |
@@ -750,8 +775,9 @@ discard block |
||
750 | 775 | |
751 | 776 | foreach ($settings as $setting => $dummy) |
752 | 777 | { |
753 | - if (!in_array($setting, array('theme_url', 'theme_dir', 'images_url', 'template_dirs'))) |
|
754 | - $settings[$setting] = htmlspecialchars__recursive($settings[$setting]); |
|
778 | + if (!in_array($setting, array('theme_url', 'theme_dir', 'images_url', 'template_dirs'))) { |
|
779 | + $settings[$setting] = htmlspecialchars__recursive($settings[$setting]); |
|
780 | + } |
|
755 | 781 | } |
756 | 782 | |
757 | 783 | $context['settings'] = $context['theme_settings']; |
@@ -760,18 +786,21 @@ discard block |
||
760 | 786 | foreach ($context['settings'] as $i => $setting) |
761 | 787 | { |
762 | 788 | // Separators are dummies, so leave them alone. |
763 | - if (!is_array($setting)) |
|
764 | - continue; |
|
789 | + if (!is_array($setting)) { |
|
790 | + continue; |
|
791 | + } |
|
765 | 792 | |
766 | - if (!isset($setting['type']) || $setting['type'] == 'bool') |
|
767 | - $context['settings'][$i]['type'] = 'checkbox'; |
|
768 | - elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') |
|
769 | - $context['settings'][$i]['type'] = 'number'; |
|
770 | - elseif ($setting['type'] == 'string') |
|
771 | - $context['settings'][$i]['type'] = 'text'; |
|
793 | + if (!isset($setting['type']) || $setting['type'] == 'bool') { |
|
794 | + $context['settings'][$i]['type'] = 'checkbox'; |
|
795 | + } elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') { |
|
796 | + $context['settings'][$i]['type'] = 'number'; |
|
797 | + } elseif ($setting['type'] == 'string') { |
|
798 | + $context['settings'][$i]['type'] = 'text'; |
|
799 | + } |
|
772 | 800 | |
773 | - if (isset($setting['options'])) |
|
774 | - $context['settings'][$i]['type'] = 'list'; |
|
801 | + if (isset($setting['options'])) { |
|
802 | + $context['settings'][$i]['type'] = 'list'; |
|
803 | + } |
|
775 | 804 | |
776 | 805 | $context['settings'][$i]['value'] = !isset($settings[$setting['id']]) ? '' : $settings[$setting['id']]; |
777 | 806 | } |
@@ -824,8 +853,9 @@ discard block |
||
824 | 853 | $themeID = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id']; |
825 | 854 | |
826 | 855 | // You can't delete the default theme! |
827 | - if ($themeID == 1) |
|
828 | - fatal_lang_error('no_access', false); |
|
856 | + if ($themeID == 1) { |
|
857 | + fatal_lang_error('no_access', false); |
|
858 | + } |
|
829 | 859 | |
830 | 860 | $theme_info = get_single_theme($themeID); |
831 | 861 | |
@@ -833,8 +863,9 @@ discard block |
||
833 | 863 | remove_theme($themeID); |
834 | 864 | |
835 | 865 | // And remove all its files and folders too. |
836 | - if (!empty($theme_info) && !empty($theme_info['theme_dir'])) |
|
837 | - remove_dir($theme_info['theme_dir']); |
|
866 | + if (!empty($theme_info) && !empty($theme_info['theme_dir'])) { |
|
867 | + remove_dir($theme_info['theme_dir']); |
|
868 | + } |
|
838 | 869 | |
839 | 870 | // Go back to the list page. |
840 | 871 | redirectexit('action=admin;area=theme;sa=list;' . $context['session_var'] . '=' . $context['session_id'] . ';done=removing'); |
@@ -859,12 +890,14 @@ discard block |
||
859 | 890 | $enableThemes = explode(',', $modSettings['enableThemes']); |
860 | 891 | |
861 | 892 | // Are we disabling it? |
862 | - if (isset($_GET['disabled'])) |
|
863 | - $enableThemes = array_diff($enableThemes, array($themeID)); |
|
893 | + if (isset($_GET['disabled'])) { |
|
894 | + $enableThemes = array_diff($enableThemes, array($themeID)); |
|
895 | + } |
|
864 | 896 | |
865 | 897 | // Nope? then enable it! |
866 | - else |
|
867 | - $enableThemes[] = (string) $themeID; |
|
898 | + else { |
|
899 | + $enableThemes[] = (string) $themeID; |
|
900 | + } |
|
868 | 901 | |
869 | 902 | // Update the setting. |
870 | 903 | $enableThemes = strtr(implode(',', $enableThemes), array(',,' => ',')); |
@@ -899,18 +932,21 @@ discard block |
||
899 | 932 | |
900 | 933 | $_SESSION['id_theme'] = 0; |
901 | 934 | |
902 | - if (isset($_GET['id'])) |
|
903 | - $_GET['th'] = $_GET['id']; |
|
935 | + if (isset($_GET['id'])) { |
|
936 | + $_GET['th'] = $_GET['id']; |
|
937 | + } |
|
904 | 938 | |
905 | 939 | // Saving a variant cause JS doesn't work - pretend it did ;) |
906 | 940 | if (isset($_POST['save'])) |
907 | 941 | { |
908 | 942 | // Which theme? |
909 | - foreach ($_POST['save'] as $k => $v) |
|
910 | - $_GET['th'] = (int) $k; |
|
943 | + foreach ($_POST['save'] as $k => $v) { |
|
944 | + $_GET['th'] = (int) $k; |
|
945 | + } |
|
911 | 946 | |
912 | - if (isset($_POST['vrt'][$k])) |
|
913 | - $_GET['vrt'] = $_POST['vrt'][$k]; |
|
947 | + if (isset($_POST['vrt'][$k])) { |
|
948 | + $_GET['vrt'] = $_POST['vrt'][$k]; |
|
949 | + } |
|
914 | 950 | } |
915 | 951 | |
916 | 952 | // Have we made a decision, or are we just browsing? |
@@ -988,8 +1024,9 @@ discard block |
||
988 | 1024 | else |
989 | 1025 | { |
990 | 1026 | // The forum's default theme is always 0 and we |
991 | - if (isset($_GET['th']) && $_GET['th'] == 0) |
|
992 | - $_GET['th'] = $modSettings['theme_guests']; |
|
1027 | + if (isset($_GET['th']) && $_GET['th'] == 0) { |
|
1028 | + $_GET['th'] = $modSettings['theme_guests']; |
|
1029 | + } |
|
993 | 1030 | |
994 | 1031 | updateMemberData((int) $_REQUEST['u'], array('id_theme' => (int) $_GET['th'])); |
995 | 1032 | |
@@ -1003,8 +1040,9 @@ discard block |
||
1003 | 1040 | ); |
1004 | 1041 | cache_put_data('theme_settings-' . $_GET['th'] . ':' . (int) $_REQUEST['u'], null, 90); |
1005 | 1042 | |
1006 | - if ($user_info['id'] == $_REQUEST['u']) |
|
1007 | - $_SESSION['id_variant'] = 0; |
|
1043 | + if ($user_info['id'] == $_REQUEST['u']) { |
|
1044 | + $_SESSION['id_variant'] = 0; |
|
1045 | + } |
|
1008 | 1046 | } |
1009 | 1047 | |
1010 | 1048 | redirectexit('action=profile;u=' . (int) $_REQUEST['u'] . ';area=theme'); |
@@ -1073,12 +1111,13 @@ discard block |
||
1073 | 1111 | ); |
1074 | 1112 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1075 | 1113 | { |
1076 | - if (!isset($context['available_themes'][$row['id_theme']])) |
|
1077 | - $context['available_themes'][$row['id_theme']] = array( |
|
1114 | + if (!isset($context['available_themes'][$row['id_theme']])) { |
|
1115 | + $context['available_themes'][$row['id_theme']] = array( |
|
1078 | 1116 | 'id' => $row['id_theme'], |
1079 | 1117 | 'selected' => $context['current_theme'] == $row['id_theme'], |
1080 | 1118 | 'num_users' => 0 |
1081 | 1119 | ); |
1120 | + } |
|
1082 | 1121 | $context['available_themes'][$row['id_theme']][$row['variable']] = $row['value']; |
1083 | 1122 | } |
1084 | 1123 | $smcFunc['db_free_result']($request); |
@@ -1091,9 +1130,9 @@ discard block |
||
1091 | 1130 | 'num_users' => 0 |
1092 | 1131 | ); |
1093 | 1132 | $guest_theme = 0; |
1133 | + } else { |
|
1134 | + $guest_theme = $modSettings['theme_guests']; |
|
1094 | 1135 | } |
1095 | - else |
|
1096 | - $guest_theme = $modSettings['theme_guests']; |
|
1097 | 1136 | |
1098 | 1137 | $request = $smcFunc['db_query']('', ' |
1099 | 1138 | SELECT id_theme, COUNT(*) AS the_count |
@@ -1106,15 +1145,17 @@ discard block |
||
1106 | 1145 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1107 | 1146 | { |
1108 | 1147 | // Figure out which theme it is they are REALLY using. |
1109 | - if (!empty($modSettings['knownThemes']) && !in_array($row['id_theme'], explode(',', $modSettings['knownThemes']))) |
|
1110 | - $row['id_theme'] = $guest_theme; |
|
1111 | - elseif (empty($modSettings['theme_allow'])) |
|
1112 | - $row['id_theme'] = $guest_theme; |
|
1148 | + if (!empty($modSettings['knownThemes']) && !in_array($row['id_theme'], explode(',', $modSettings['knownThemes']))) { |
|
1149 | + $row['id_theme'] = $guest_theme; |
|
1150 | + } elseif (empty($modSettings['theme_allow'])) { |
|
1151 | + $row['id_theme'] = $guest_theme; |
|
1152 | + } |
|
1113 | 1153 | |
1114 | - if (isset($context['available_themes'][$row['id_theme']])) |
|
1115 | - $context['available_themes'][$row['id_theme']]['num_users'] += $row['the_count']; |
|
1116 | - else |
|
1117 | - $context['available_themes'][$guest_theme]['num_users'] += $row['the_count']; |
|
1154 | + if (isset($context['available_themes'][$row['id_theme']])) { |
|
1155 | + $context['available_themes'][$row['id_theme']]['num_users'] += $row['the_count']; |
|
1156 | + } else { |
|
1157 | + $context['available_themes'][$guest_theme]['num_users'] += $row['the_count']; |
|
1158 | + } |
|
1118 | 1159 | } |
1119 | 1160 | $smcFunc['db_free_result']($request); |
1120 | 1161 | |
@@ -1133,8 +1174,9 @@ discard block |
||
1133 | 1174 | 'id_member' => isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? array(-1, $context['current_member']) : array(-1), |
1134 | 1175 | ) |
1135 | 1176 | ); |
1136 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1137 | - $variant_preferences[$row['id_theme']] = $row['value']; |
|
1177 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1178 | + $variant_preferences[$row['id_theme']] = $row['value']; |
|
1179 | + } |
|
1138 | 1180 | $smcFunc['db_free_result']($request); |
1139 | 1181 | } |
1140 | 1182 | |
@@ -1145,17 +1187,18 @@ discard block |
||
1145 | 1187 | foreach ($context['available_themes'] as $id_theme => $theme_data) |
1146 | 1188 | { |
1147 | 1189 | // Don't try to load the forum or board default theme's data... it doesn't have any! |
1148 | - if ($id_theme == 0) |
|
1149 | - continue; |
|
1190 | + if ($id_theme == 0) { |
|
1191 | + continue; |
|
1192 | + } |
|
1150 | 1193 | |
1151 | 1194 | // The thumbnail needs the correct path. |
1152 | 1195 | $settings['images_url'] = &$theme_data['images_url']; |
1153 | 1196 | |
1154 | - if (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php')) |
|
1155 | - include($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php'); |
|
1156 | - elseif (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php')) |
|
1157 | - include($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php'); |
|
1158 | - else |
|
1197 | + if (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php')) { |
|
1198 | + include($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php'); |
|
1199 | + } elseif (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php')) { |
|
1200 | + include($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php'); |
|
1201 | + } else |
|
1159 | 1202 | { |
1160 | 1203 | $txt['theme_thumbnail_href'] = $theme_data['images_url'] . '/thumbnail.png'; |
1161 | 1204 | $txt['theme_description'] = ''; |
@@ -1180,15 +1223,17 @@ discard block |
||
1180 | 1223 | loadLanguage('Settings'); |
1181 | 1224 | |
1182 | 1225 | $context['available_themes'][$id_theme]['variants'] = array(); |
1183 | - foreach ($settings['theme_variants'] as $variant) |
|
1184 | - $context['available_themes'][$id_theme]['variants'][$variant] = array( |
|
1226 | + foreach ($settings['theme_variants'] as $variant) { |
|
1227 | + $context['available_themes'][$id_theme]['variants'][$variant] = array( |
|
1185 | 1228 | 'label' => isset($txt['variant_' . $variant]) ? $txt['variant_' . $variant] : $variant, |
1186 | 1229 | 'thumbnail' => !file_exists($theme_data['theme_dir'] . '/images/thumbnail.png') || file_exists($theme_data['theme_dir'] . '/images/thumbnail_' . $variant . '.png') ? $theme_data['images_url'] . '/thumbnail_' . $variant . '.png' : ($theme_data['images_url'] . '/thumbnail.png'), |
1187 | 1230 | ); |
1231 | + } |
|
1188 | 1232 | |
1189 | 1233 | $context['available_themes'][$id_theme]['selected_variant'] = isset($_GET['vrt']) ? $_GET['vrt'] : (!empty($variant_preferences[$id_theme]) ? $variant_preferences[$id_theme] : (!empty($settings['default_variant']) ? $settings['default_variant'] : $settings['theme_variants'][0])); |
1190 | - if (!isset($context['available_themes'][$id_theme]['variants'][$context['available_themes'][$id_theme]['selected_variant']]['thumbnail'])) |
|
1191 | - $context['available_themes'][$id_theme]['selected_variant'] = $settings['theme_variants'][0]; |
|
1234 | + if (!isset($context['available_themes'][$id_theme]['variants'][$context['available_themes'][$id_theme]['selected_variant']]['thumbnail'])) { |
|
1235 | + $context['available_themes'][$id_theme]['selected_variant'] = $settings['theme_variants'][0]; |
|
1236 | + } |
|
1192 | 1237 | |
1193 | 1238 | $context['available_themes'][$id_theme]['thumbnail_href'] = $context['available_themes'][$id_theme]['variants'][$context['available_themes'][$id_theme]['selected_variant']]['thumbnail']; |
1194 | 1239 | // Allow themes to override the text. |
@@ -1204,8 +1249,9 @@ discard block |
||
1204 | 1249 | // As long as we're not doing the default theme... |
1205 | 1250 | if (!isset($_REQUEST['u']) || $_REQUEST['u'] >= 0) |
1206 | 1251 | { |
1207 | - if ($guest_theme != 0) |
|
1208 | - $context['available_themes'][0] = $context['available_themes'][$guest_theme]; |
|
1252 | + if ($guest_theme != 0) { |
|
1253 | + $context['available_themes'][0] = $context['available_themes'][$guest_theme]; |
|
1254 | + } |
|
1209 | 1255 | |
1210 | 1256 | $context['available_themes'][0]['id'] = 0; |
1211 | 1257 | $context['available_themes'][0]['name'] = $txt['theme_forum_default']; |
@@ -1254,14 +1300,16 @@ discard block |
||
1254 | 1300 | $action = $smcFunc['htmlspecialchars'](trim($_GET['do'])); |
1255 | 1301 | |
1256 | 1302 | // Got any info from the specific form? |
1257 | - if (!isset($_POST['save_' . $action])) |
|
1258 | - fatal_lang_error('theme_install_no_action', false); |
|
1303 | + if (!isset($_POST['save_' . $action])) { |
|
1304 | + fatal_lang_error('theme_install_no_action', false); |
|
1305 | + } |
|
1259 | 1306 | |
1260 | 1307 | validateToken('admin-t-' . $action); |
1261 | 1308 | |
1262 | 1309 | // Hopefully the themes directory is writable, or we might have a problem. |
1263 | - if (!is_writable($themedir)) |
|
1264 | - fatal_lang_error('theme_install_write_error', 'critical'); |
|
1310 | + if (!is_writable($themedir)) { |
|
1311 | + fatal_lang_error('theme_install_write_error', 'critical'); |
|
1312 | + } |
|
1265 | 1313 | |
1266 | 1314 | // Call the function and handle the result. |
1267 | 1315 | $result = $subActions[$action](); |
@@ -1276,9 +1324,10 @@ discard block |
||
1276 | 1324 | } |
1277 | 1325 | |
1278 | 1326 | // Nope, show a nice error. |
1279 | - else |
|
1280 | - fatal_lang_error('theme_install_no_action', false); |
|
1281 | -} |
|
1327 | + else { |
|
1328 | + fatal_lang_error('theme_install_no_action', false); |
|
1329 | + } |
|
1330 | + } |
|
1282 | 1331 | |
1283 | 1332 | /** |
1284 | 1333 | * Installs a theme from a theme package. |
@@ -1294,8 +1343,9 @@ discard block |
||
1294 | 1343 | $dirtemp = $themedir . '/temp'; |
1295 | 1344 | |
1296 | 1345 | // Make sure the temp dir doesn't already exist |
1297 | - if (file_exists($dirtemp)) |
|
1298 | - remove_dir($dirtemp); |
|
1346 | + if (file_exists($dirtemp)) { |
|
1347 | + remove_dir($dirtemp); |
|
1348 | + } |
|
1299 | 1349 | |
1300 | 1350 | // Create the temp dir. |
1301 | 1351 | mkdir($dirtemp, 0777); |
@@ -1307,17 +1357,20 @@ discard block |
||
1307 | 1357 | smf_chmod($dirtemp, '0755'); |
1308 | 1358 | |
1309 | 1359 | // How about now? |
1310 | - if (!is_writable($dirtemp)) |
|
1311 | - fatal_lang_error('theme_install_write_error', 'critical'); |
|
1360 | + if (!is_writable($dirtemp)) { |
|
1361 | + fatal_lang_error('theme_install_write_error', 'critical'); |
|
1362 | + } |
|
1312 | 1363 | } |
1313 | 1364 | |
1314 | 1365 | // This happens when the admin session is gone and the user has to login again. |
1315 | - if (!isset($_FILES) || !isset($_FILES['theme_gz']) || empty($_FILES['theme_gz'])) |
|
1316 | - redirectexit('action=admin;area=theme;sa=admin;' . $context['session_var'] . '=' . $context['session_id']); |
|
1366 | + if (!isset($_FILES) || !isset($_FILES['theme_gz']) || empty($_FILES['theme_gz'])) { |
|
1367 | + redirectexit('action=admin;area=theme;sa=admin;' . $context['session_var'] . '=' . $context['session_id']); |
|
1368 | + } |
|
1317 | 1369 | |
1318 | 1370 | // Another error check layer, something went wrong with the upload. |
1319 | - if (isset($_FILES['theme_gz']['error']) && $_FILES['theme_gz']['error'] != 0) |
|
1320 | - fatal_lang_error('theme_install_error_file_' . $_FILES['theme_gz']['error'], false); |
|
1371 | + if (isset($_FILES['theme_gz']['error']) && $_FILES['theme_gz']['error'] != 0) { |
|
1372 | + fatal_lang_error('theme_install_error_file_' . $_FILES['theme_gz']['error'], false); |
|
1373 | + } |
|
1321 | 1374 | |
1322 | 1375 | // Get the theme's name. |
1323 | 1376 | $name = pathinfo($_FILES['theme_gz']['name'], PATHINFO_FILENAME); |
@@ -1348,11 +1401,10 @@ discard block |
||
1348 | 1401 | |
1349 | 1402 | // return all the info. |
1350 | 1403 | return $context['to_install']; |
1404 | + } else { |
|
1405 | + fatal_lang_error('theme_install_error_title', false); |
|
1406 | + } |
|
1351 | 1407 | } |
1352 | - |
|
1353 | - else |
|
1354 | - fatal_lang_error('theme_install_error_title', false); |
|
1355 | -} |
|
1356 | 1408 | |
1357 | 1409 | /** |
1358 | 1410 | * Makes a copy from the default theme, assigns a name for it and installs it. |
@@ -1366,15 +1418,17 @@ discard block |
||
1366 | 1418 | global $forum_version; |
1367 | 1419 | |
1368 | 1420 | // There's gotta be something to work with. |
1369 | - if (!isset($_REQUEST['copy']) || empty($_REQUEST['copy'])) |
|
1370 | - fatal_lang_error('theme_install_error_title', false); |
|
1421 | + if (!isset($_REQUEST['copy']) || empty($_REQUEST['copy'])) { |
|
1422 | + fatal_lang_error('theme_install_error_title', false); |
|
1423 | + } |
|
1371 | 1424 | |
1372 | 1425 | // Get a cleaner version. |
1373 | 1426 | $name = preg_replace('~[^A-Za-z0-9_\- ]~', '', $_REQUEST['copy']); |
1374 | 1427 | |
1375 | 1428 | // Is there a theme already named like this? |
1376 | - if (file_exists($themedir . '/' . $name)) |
|
1377 | - fatal_lang_error('theme_install_already_dir', false); |
|
1429 | + if (file_exists($themedir . '/' . $name)) { |
|
1430 | + fatal_lang_error('theme_install_already_dir', false); |
|
1431 | + } |
|
1378 | 1432 | |
1379 | 1433 | // This is a brand new theme so set all possible values. |
1380 | 1434 | $context['to_install'] = array( |
@@ -1394,8 +1448,9 @@ discard block |
||
1394 | 1448 | |
1395 | 1449 | // Buy some time. |
1396 | 1450 | @set_time_limit(600); |
1397 | - if (function_exists('apache_reset_timeout')) |
|
1398 | - @apache_reset_timeout(); |
|
1451 | + if (function_exists('apache_reset_timeout')) { |
|
1452 | + @apache_reset_timeout(); |
|
1453 | + } |
|
1399 | 1454 | |
1400 | 1455 | // Create subdirectories for css and javascript files. |
1401 | 1456 | mkdir($context['to_install']['theme_dir'] . '/css', 0777); |
@@ -1431,12 +1486,13 @@ discard block |
||
1431 | 1486 | |
1432 | 1487 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1433 | 1488 | { |
1434 | - if ($row['variable'] == 'theme_templates') |
|
1435 | - $theme_templates = $row['value']; |
|
1436 | - elseif ($row['variable'] == 'theme_layers') |
|
1437 | - $theme_layers = $row['value']; |
|
1438 | - else |
|
1439 | - continue; |
|
1489 | + if ($row['variable'] == 'theme_templates') { |
|
1490 | + $theme_templates = $row['value']; |
|
1491 | + } elseif ($row['variable'] == 'theme_layers') { |
|
1492 | + $theme_layers = $row['value']; |
|
1493 | + } else { |
|
1494 | + continue; |
|
1495 | + } |
|
1440 | 1496 | } |
1441 | 1497 | |
1442 | 1498 | $smcFunc['db_free_result']($request); |
@@ -1495,12 +1551,14 @@ discard block |
||
1495 | 1551 | global $themedir, $themeurl, $context; |
1496 | 1552 | |
1497 | 1553 | // Cannot use the theme dir as a theme dir. |
1498 | - if (!isset($_REQUEST['theme_dir']) || empty($_REQUEST['theme_dir']) || rtrim(realpath($_REQUEST['theme_dir']), '/\\') == realpath($themedir)) |
|
1499 | - fatal_lang_error('theme_install_invalid_dir', false); |
|
1554 | + if (!isset($_REQUEST['theme_dir']) || empty($_REQUEST['theme_dir']) || rtrim(realpath($_REQUEST['theme_dir']), '/\\') == realpath($themedir)) { |
|
1555 | + fatal_lang_error('theme_install_invalid_dir', false); |
|
1556 | + } |
|
1500 | 1557 | |
1501 | 1558 | // Check is there is "something" on the dir. |
1502 | - elseif (!is_dir($_REQUEST['theme_dir']) || !file_exists($_REQUEST['theme_dir'] . '/theme_info.xml')) |
|
1503 | - fatal_lang_error('theme_install_error', false); |
|
1559 | + elseif (!is_dir($_REQUEST['theme_dir']) || !file_exists($_REQUEST['theme_dir'] . '/theme_info.xml')) { |
|
1560 | + fatal_lang_error('theme_install_error', false); |
|
1561 | + } |
|
1504 | 1562 | |
1505 | 1563 | $name = basename($_REQUEST['theme_dir']); |
1506 | 1564 | $name = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $name); |
@@ -1544,24 +1602,27 @@ discard block |
||
1544 | 1602 | } |
1545 | 1603 | |
1546 | 1604 | // Any special layers? |
1547 | - if (isset($settings['catch_action']['layers'])) |
|
1548 | - $context['template_layers'] = $settings['catch_action']['layers']; |
|
1605 | + if (isset($settings['catch_action']['layers'])) { |
|
1606 | + $context['template_layers'] = $settings['catch_action']['layers']; |
|
1607 | + } |
|
1549 | 1608 | |
1550 | 1609 | // Any function to call? |
1551 | 1610 | if (isset($settings['catch_action']['function'])) |
1552 | 1611 | { |
1553 | 1612 | $hook = $settings['catch_action']['function']; |
1554 | 1613 | |
1555 | - if (!isset($settings['catch_action']['filename'])) |
|
1556 | - $settings['catch_action']['filename'] = ''; |
|
1614 | + if (!isset($settings['catch_action']['filename'])) { |
|
1615 | + $settings['catch_action']['filename'] = ''; |
|
1616 | + } |
|
1557 | 1617 | |
1558 | 1618 | add_integration_function('integrate_wrap_action', $hook, false, $settings['catch_action']['filename'], false); |
1559 | 1619 | call_integration_hook('integrate_wrap_action'); |
1560 | 1620 | } |
1561 | 1621 | // And finally, the main sub template ;). |
1562 | - if (isset($settings['catch_action']['sub_template'])) |
|
1563 | - $context['sub_template'] = $settings['catch_action']['sub_template']; |
|
1564 | -} |
|
1622 | + if (isset($settings['catch_action']['sub_template'])) { |
|
1623 | + $context['sub_template'] = $settings['catch_action']['sub_template']; |
|
1624 | + } |
|
1625 | + } |
|
1565 | 1626 | |
1566 | 1627 | /** |
1567 | 1628 | * Set an option via javascript. |
@@ -1580,12 +1641,14 @@ discard block |
||
1580 | 1641 | checkSession('get'); |
1581 | 1642 | |
1582 | 1643 | // This good-for-nothing pixel is being used to keep the session alive. |
1583 | - if (empty($_GET['var']) || !isset($_GET['val'])) |
|
1584 | - redirectexit($settings['images_url'] . '/blank.png'); |
|
1644 | + if (empty($_GET['var']) || !isset($_GET['val'])) { |
|
1645 | + redirectexit($settings['images_url'] . '/blank.png'); |
|
1646 | + } |
|
1585 | 1647 | |
1586 | 1648 | // Sorry, guests can't go any further than this. |
1587 | - if ($user_info['is_guest'] || $user_info['id'] == 0) |
|
1588 | - obExit(false); |
|
1649 | + if ($user_info['is_guest'] || $user_info['id'] == 0) { |
|
1650 | + obExit(false); |
|
1651 | + } |
|
1589 | 1652 | |
1590 | 1653 | $reservedVars = array( |
1591 | 1654 | 'actual_theme_url', |
@@ -1608,8 +1671,9 @@ discard block |
||
1608 | 1671 | ); |
1609 | 1672 | |
1610 | 1673 | // Can't change reserved vars. |
1611 | - if (in_array(strtolower($_GET['var']), $reservedVars)) |
|
1612 | - redirectexit($settings['images_url'] . '/blank.png'); |
|
1674 | + if (in_array(strtolower($_GET['var']), $reservedVars)) { |
|
1675 | + redirectexit($settings['images_url'] . '/blank.png'); |
|
1676 | + } |
|
1613 | 1677 | |
1614 | 1678 | // Use a specific theme? |
1615 | 1679 | if (isset($_GET['th']) || isset($_GET['id'])) |
@@ -1625,8 +1689,9 @@ discard block |
||
1625 | 1689 | { |
1626 | 1690 | $options['admin_preferences'] = !empty($options['admin_preferences']) ? smf_json_decode($options['admin_preferences'], true) : array(); |
1627 | 1691 | // New thingy... |
1628 | - if (isset($_GET['admin_key']) && strlen($_GET['admin_key']) < 5) |
|
1629 | - $options['admin_preferences'][$_GET['admin_key']] = $_GET['val']; |
|
1692 | + if (isset($_GET['admin_key']) && strlen($_GET['admin_key']) < 5) { |
|
1693 | + $options['admin_preferences'][$_GET['admin_key']] = $_GET['val']; |
|
1694 | + } |
|
1630 | 1695 | |
1631 | 1696 | // Change the value to be something nice, |
1632 | 1697 | $_GET['val'] = json_encode($options['admin_preferences']); |
@@ -1656,8 +1721,9 @@ discard block |
||
1656 | 1721 | global $context, $scripturl, $boarddir, $smcFunc, $txt; |
1657 | 1722 | |
1658 | 1723 | // @todo Should this be removed? |
1659 | - if (isset($_REQUEST['preview'])) |
|
1660 | - die('die() with fire'); |
|
1724 | + if (isset($_REQUEST['preview'])) { |
|
1725 | + die('die() with fire'); |
|
1726 | + } |
|
1661 | 1727 | |
1662 | 1728 | isAllowedTo('admin_forum'); |
1663 | 1729 | loadTemplate('Themes'); |
@@ -1671,11 +1737,11 @@ discard block |
||
1671 | 1737 | foreach ($context['themes'] as $key => $theme) |
1672 | 1738 | { |
1673 | 1739 | // There has to be a Settings template! |
1674 | - if (!file_exists($theme['theme_dir'] . '/index.template.php') && !file_exists($theme['theme_dir'] . '/css/index.css')) |
|
1675 | - unset($context['themes'][$key]); |
|
1676 | - |
|
1677 | - else |
|
1678 | - $context['themes'][$key]['can_edit_style'] = file_exists($theme['theme_dir'] . '/css/index.css'); |
|
1740 | + if (!file_exists($theme['theme_dir'] . '/index.template.php') && !file_exists($theme['theme_dir'] . '/css/index.css')) { |
|
1741 | + unset($context['themes'][$key]); |
|
1742 | + } else { |
|
1743 | + $context['themes'][$key]['can_edit_style'] = file_exists($theme['theme_dir'] . '/css/index.css'); |
|
1744 | + } |
|
1679 | 1745 | } |
1680 | 1746 | |
1681 | 1747 | $context['sub_template'] = 'edit_list'; |
@@ -1690,22 +1756,24 @@ discard block |
||
1690 | 1756 | $context['theme_id'] = $currentTheme['id']; |
1691 | 1757 | $context['browse_title'] = sprintf($txt['themeadmin_browsing_theme'], $currentTheme['name']); |
1692 | 1758 | |
1693 | - if (!file_exists($currentTheme['theme_dir'] . '/index.template.php') && !file_exists($currentTheme['theme_dir'] . '/css/index.css')) |
|
1694 | - fatal_lang_error('theme_edit_missing', false); |
|
1759 | + if (!file_exists($currentTheme['theme_dir'] . '/index.template.php') && !file_exists($currentTheme['theme_dir'] . '/css/index.css')) { |
|
1760 | + fatal_lang_error('theme_edit_missing', false); |
|
1761 | + } |
|
1695 | 1762 | |
1696 | 1763 | if (!isset($_REQUEST['filename'])) |
1697 | 1764 | { |
1698 | 1765 | if (isset($_GET['directory'])) |
1699 | 1766 | { |
1700 | - if (substr($_GET['directory'], 0, 1) == '.') |
|
1701 | - $_GET['directory'] = ''; |
|
1702 | - else |
|
1767 | + if (substr($_GET['directory'], 0, 1) == '.') { |
|
1768 | + $_GET['directory'] = ''; |
|
1769 | + } else |
|
1703 | 1770 | { |
1704 | 1771 | $_GET['directory'] = preg_replace(array('~^[\./\\:\0\n\r]+~', '~[\\\\]~', '~/[\./]+~'), array('', '/', '/'), $_GET['directory']); |
1705 | 1772 | |
1706 | 1773 | $temp = realpath($currentTheme['theme_dir'] . '/' . $_GET['directory']); |
1707 | - if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir'])) |
|
1708 | - $_GET['directory'] = ''; |
|
1774 | + if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir'])) { |
|
1775 | + $_GET['directory'] = ''; |
|
1776 | + } |
|
1709 | 1777 | } |
1710 | 1778 | } |
1711 | 1779 | |
@@ -1724,37 +1792,39 @@ discard block |
||
1724 | 1792 | 'href' => $scripturl . '?action=admin;area=theme;th=' . $_GET['th'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';sa=edit;directory=' . $temp, |
1725 | 1793 | 'size' => '', |
1726 | 1794 | )); |
1795 | + } else { |
|
1796 | + $context['theme_files'] = get_file_listing($currentTheme['theme_dir'], ''); |
|
1727 | 1797 | } |
1728 | - else |
|
1729 | - $context['theme_files'] = get_file_listing($currentTheme['theme_dir'], ''); |
|
1730 | 1798 | |
1731 | 1799 | $context['sub_template'] = 'edit_browse'; |
1732 | 1800 | |
1733 | 1801 | return; |
1734 | - } |
|
1735 | - else |
|
1802 | + } else |
|
1736 | 1803 | { |
1737 | - if (substr($_REQUEST['filename'], 0, 1) == '.') |
|
1738 | - $_REQUEST['filename'] = ''; |
|
1739 | - else |
|
1804 | + if (substr($_REQUEST['filename'], 0, 1) == '.') { |
|
1805 | + $_REQUEST['filename'] = ''; |
|
1806 | + } else |
|
1740 | 1807 | { |
1741 | 1808 | $_REQUEST['filename'] = preg_replace(array('~^[\./\\:\0\n\r]+~', '~[\\\\]~', '~/[\./]+~'), array('', '/', '/'), $_REQUEST['filename']); |
1742 | 1809 | |
1743 | 1810 | $temp = realpath($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']); |
1744 | - if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir'])) |
|
1745 | - $_REQUEST['filename'] = ''; |
|
1811 | + if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir'])) { |
|
1812 | + $_REQUEST['filename'] = ''; |
|
1813 | + } |
|
1746 | 1814 | } |
1747 | 1815 | |
1748 | - if (empty($_REQUEST['filename'])) |
|
1749 | - fatal_lang_error('theme_edit_missing', false); |
|
1816 | + if (empty($_REQUEST['filename'])) { |
|
1817 | + fatal_lang_error('theme_edit_missing', false); |
|
1818 | + } |
|
1750 | 1819 | } |
1751 | 1820 | |
1752 | 1821 | if (isset($_POST['save'])) |
1753 | 1822 | { |
1754 | 1823 | if (checkSession('post', '', false) == '' && validateToken('admin-te-' . md5($_GET['th'] . '-' . $_REQUEST['filename']), 'post', false) == true) |
1755 | 1824 | { |
1756 | - if (is_array($_POST['entire_file'])) |
|
1757 | - $_POST['entire_file'] = implode("\n", $_POST['entire_file']); |
|
1825 | + if (is_array($_POST['entire_file'])) { |
|
1826 | + $_POST['entire_file'] = implode("\n", $_POST['entire_file']); |
|
1827 | + } |
|
1758 | 1828 | |
1759 | 1829 | $_POST['entire_file'] = rtrim(strtr($_POST['entire_file'], array("\r" => '', ' ' => "\t"))); |
1760 | 1830 | |
@@ -1766,10 +1836,11 @@ discard block |
||
1766 | 1836 | fclose($fp); |
1767 | 1837 | |
1768 | 1838 | $error = @file_get_contents($currentTheme['theme_url'] . '/tmp_' . session_id() . '.php'); |
1769 | - if (preg_match('~ <b>(\d+)</b><br( /)?' . '>$~i', $error) != 0) |
|
1770 | - $error_file = $currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php'; |
|
1771 | - else |
|
1772 | - unlink($currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php'); |
|
1839 | + if (preg_match('~ <b>(\d+)</b><br( /)?' . '>$~i', $error) != 0) { |
|
1840 | + $error_file = $currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php'; |
|
1841 | + } else { |
|
1842 | + unlink($currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php'); |
|
1843 | + } |
|
1773 | 1844 | } |
1774 | 1845 | |
1775 | 1846 | if (!isset($error_file)) |
@@ -1790,10 +1861,11 @@ discard block |
||
1790 | 1861 | $context['sub_template'] = 'edit_file'; |
1791 | 1862 | |
1792 | 1863 | // Recycle the submitted data. |
1793 | - if (is_array($_POST['entire_file'])) |
|
1794 | - $context['entire_file'] = $smcFunc['htmlspecialchars'](implode("\n", $_POST['entire_file'])); |
|
1795 | - else |
|
1796 | - $context['entire_file'] = $smcFunc['htmlspecialchars']($_POST['entire_file']); |
|
1864 | + if (is_array($_POST['entire_file'])) { |
|
1865 | + $context['entire_file'] = $smcFunc['htmlspecialchars'](implode("\n", $_POST['entire_file'])); |
|
1866 | + } else { |
|
1867 | + $context['entire_file'] = $smcFunc['htmlspecialchars']($_POST['entire_file']); |
|
1868 | + } |
|
1797 | 1869 | |
1798 | 1870 | $context['edit_filename'] = $smcFunc['htmlspecialchars']($_POST['filename']); |
1799 | 1871 | |
@@ -1816,17 +1888,17 @@ discard block |
||
1816 | 1888 | $context['sub_template'] = 'edit_style'; |
1817 | 1889 | |
1818 | 1890 | $context['entire_file'] = $smcFunc['htmlspecialchars'](strtr(file_get_contents($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']), array("\t" => ' '))); |
1819 | - } |
|
1820 | - elseif (substr($_REQUEST['filename'], -13) == '.template.php') |
|
1891 | + } elseif (substr($_REQUEST['filename'], -13) == '.template.php') |
|
1821 | 1892 | { |
1822 | 1893 | $context['sub_template'] = 'edit_template'; |
1823 | 1894 | |
1824 | - if (!isset($error_file)) |
|
1825 | - $file_data = file($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']); |
|
1826 | - else |
|
1895 | + if (!isset($error_file)) { |
|
1896 | + $file_data = file($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']); |
|
1897 | + } else |
|
1827 | 1898 | { |
1828 | - if (preg_match('~(<b>.+?</b>:.+?<b>).+?(</b>.+?<b>\d+</b>)<br( /)?' . '>$~i', $error, $match) != 0) |
|
1829 | - $context['parse_error'] = $match[1] . $_REQUEST['filename'] . $match[2]; |
|
1899 | + if (preg_match('~(<b>.+?</b>:.+?<b>).+?(</b>.+?<b>\d+</b>)<br( /)?' . '>$~i', $error, $match) != 0) { |
|
1900 | + $context['parse_error'] = $match[1] . $_REQUEST['filename'] . $match[2]; |
|
1901 | + } |
|
1830 | 1902 | $file_data = file($error_file); |
1831 | 1903 | unlink($error_file); |
1832 | 1904 | } |
@@ -1840,8 +1912,9 @@ discard block |
||
1840 | 1912 | // Try to format the functions a little nicer... |
1841 | 1913 | $context['file_parts'][$j]['data'] = trim($context['file_parts'][$j]['data']) . "\n"; |
1842 | 1914 | |
1843 | - if (empty($context['file_parts'][$j]['lines'])) |
|
1844 | - unset($context['file_parts'][$j]); |
|
1915 | + if (empty($context['file_parts'][$j]['lines'])) { |
|
1916 | + unset($context['file_parts'][$j]); |
|
1917 | + } |
|
1845 | 1918 | $context['file_parts'][++$j] = array('lines' => 0, 'line' => $i + 1, 'data' => ''); |
1846 | 1919 | } |
1847 | 1920 | |
@@ -1850,8 +1923,7 @@ discard block |
||
1850 | 1923 | } |
1851 | 1924 | |
1852 | 1925 | $context['entire_file'] = $smcFunc['htmlspecialchars'](strtr(implode('', $file_data), array("\t" => ' '))); |
1853 | - } |
|
1854 | - else |
|
1926 | + } else |
|
1855 | 1927 | { |
1856 | 1928 | $context['sub_template'] = 'edit_file'; |
1857 | 1929 | |
@@ -1877,8 +1949,9 @@ discard block |
||
1877 | 1949 | |
1878 | 1950 | $_GET['th'] = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id']; |
1879 | 1951 | |
1880 | - if (empty($_GET['th'])) |
|
1881 | - fatal_lang_error('theme_install_invalid_id'); |
|
1952 | + if (empty($_GET['th'])) { |
|
1953 | + fatal_lang_error('theme_install_invalid_id'); |
|
1954 | + } |
|
1882 | 1955 | |
1883 | 1956 | // Get the theme info. |
1884 | 1957 | $theme = get_single_theme($_GET['th']); |
@@ -1886,25 +1959,24 @@ discard block |
||
1886 | 1959 | |
1887 | 1960 | if (isset($_REQUEST['template']) && preg_match('~[\./\\\\:\0]~', $_REQUEST['template']) == 0) |
1888 | 1961 | { |
1889 | - if (file_exists($settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php')) |
|
1890 | - $filename = $settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php'; |
|
1891 | - |
|
1892 | - else |
|
1893 | - fatal_lang_error('no_access', false); |
|
1962 | + if (file_exists($settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php')) { |
|
1963 | + $filename = $settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php'; |
|
1964 | + } else { |
|
1965 | + fatal_lang_error('no_access', false); |
|
1966 | + } |
|
1894 | 1967 | |
1895 | 1968 | $fp = fopen($theme['theme_dir'] . '/' . $_REQUEST['template'] . '.template.php', 'w'); |
1896 | 1969 | fwrite($fp, file_get_contents($filename)); |
1897 | 1970 | fclose($fp); |
1898 | 1971 | |
1899 | 1972 | redirectexit('action=admin;area=theme;th=' . $context['theme_id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';sa=copy'); |
1900 | - } |
|
1901 | - elseif (isset($_REQUEST['lang_file']) && preg_match('~^[^\./\\\\:\0]\.[^\./\\\\:\0]$~', $_REQUEST['lang_file']) != 0) |
|
1973 | + } elseif (isset($_REQUEST['lang_file']) && preg_match('~^[^\./\\\\:\0]\.[^\./\\\\:\0]$~', $_REQUEST['lang_file']) != 0) |
|
1902 | 1974 | { |
1903 | - if (file_exists($settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php')) |
|
1904 | - $filename = $settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php'; |
|
1905 | - |
|
1906 | - else |
|
1907 | - fatal_lang_error('no_access', false); |
|
1975 | + if (file_exists($settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php')) { |
|
1976 | + $filename = $settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php'; |
|
1977 | + } else { |
|
1978 | + fatal_lang_error('no_access', false); |
|
1979 | + } |
|
1908 | 1980 | |
1909 | 1981 | $fp = fopen($theme['theme_dir'] . '/languages/' . $_REQUEST['lang_file'] . '.php', 'w'); |
1910 | 1982 | fwrite($fp, file_get_contents($filename)); |
@@ -1919,16 +1991,18 @@ discard block |
||
1919 | 1991 | $dir = dir($settings['default_theme_dir']); |
1920 | 1992 | while ($entry = $dir->read()) |
1921 | 1993 | { |
1922 | - if (substr($entry, -13) == '.template.php') |
|
1923 | - $templates[] = substr($entry, 0, -13); |
|
1994 | + if (substr($entry, -13) == '.template.php') { |
|
1995 | + $templates[] = substr($entry, 0, -13); |
|
1996 | + } |
|
1924 | 1997 | } |
1925 | 1998 | $dir->close(); |
1926 | 1999 | |
1927 | 2000 | $dir = dir($settings['default_theme_dir'] . '/languages'); |
1928 | 2001 | while ($entry = $dir->read()) |
1929 | 2002 | { |
1930 | - if (preg_match('~^([^\.]+\.[^\.]+)\.php$~', $entry, $matches)) |
|
1931 | - $lang_files[] = $matches[1]; |
|
2003 | + if (preg_match('~^([^\.]+\.[^\.]+)\.php$~', $entry, $matches)) { |
|
2004 | + $lang_files[] = $matches[1]; |
|
2005 | + } |
|
1932 | 2006 | } |
1933 | 2007 | $dir->close(); |
1934 | 2008 | |
@@ -1936,21 +2010,23 @@ discard block |
||
1936 | 2010 | natcasesort($lang_files); |
1937 | 2011 | |
1938 | 2012 | $context['available_templates'] = array(); |
1939 | - foreach ($templates as $template) |
|
1940 | - $context['available_templates'][$template] = array( |
|
2013 | + foreach ($templates as $template) { |
|
2014 | + $context['available_templates'][$template] = array( |
|
1941 | 2015 | 'filename' => $template . '.template.php', |
1942 | 2016 | 'value' => $template, |
1943 | 2017 | 'already_exists' => false, |
1944 | 2018 | 'can_copy' => is_writable($theme['theme_dir']), |
1945 | 2019 | ); |
2020 | + } |
|
1946 | 2021 | $context['available_language_files'] = array(); |
1947 | - foreach ($lang_files as $file) |
|
1948 | - $context['available_language_files'][$file] = array( |
|
2022 | + foreach ($lang_files as $file) { |
|
2023 | + $context['available_language_files'][$file] = array( |
|
1949 | 2024 | 'filename' => $file . '.php', |
1950 | 2025 | 'value' => $file, |
1951 | 2026 | 'already_exists' => false, |
1952 | 2027 | 'can_copy' => file_exists($theme['theme_dir'] . '/languages') ? is_writable($theme['theme_dir'] . '/languages') : is_writable($theme['theme_dir']), |
1953 | 2028 | ); |
2029 | + } |
|
1954 | 2030 | |
1955 | 2031 | $dir = dir($theme['theme_dir']); |
1956 | 2032 | while ($entry = $dir->read()) |
@@ -19,8 +19,9 @@ discard block |
||
19 | 19 | * @version 2.1 Beta 3 |
20 | 20 | */ |
21 | 21 | |
22 | -if (!defined('SMF')) |
|
22 | +if (!defined('SMF')) { |
|
23 | 23 | die('No direct access...'); |
24 | +} |
|
24 | 25 | |
25 | 26 | /** |
26 | 27 | * Class gif_lzw_compression |
@@ -52,13 +53,15 @@ discard block |
||
52 | 53 | |
53 | 54 | $this->LZWCommand($data, true); |
54 | 55 | |
55 | - while (($iIndex = $this->LZWCommand($data, false)) >= 0) |
|
56 | - $ret .= chr($iIndex); |
|
56 | + while (($iIndex = $this->LZWCommand($data, false)) >= 0) { |
|
57 | + $ret .= chr($iIndex); |
|
58 | + } |
|
57 | 59 | |
58 | 60 | $datLen = $stLen - strlen($data); |
59 | 61 | |
60 | - if ($iIndex != -2) |
|
61 | - return false; |
|
62 | + if ($iIndex != -2) { |
|
63 | + return false; |
|
64 | + } |
|
62 | 65 | |
63 | 66 | return $ret; |
64 | 67 | } |
@@ -140,8 +143,9 @@ discard block |
||
140 | 143 | return $this->FirstCode; |
141 | 144 | } |
142 | 145 | |
143 | - if ($Code == $this->EndCode) |
|
144 | - return -2; |
|
146 | + if ($Code == $this->EndCode) { |
|
147 | + return -2; |
|
148 | + } |
|
145 | 149 | |
146 | 150 | $InCode = $Code; |
147 | 151 | if ($Code >= $this->MaxCode) |
@@ -156,8 +160,10 @@ discard block |
||
156 | 160 | $this->Stack[$this->sp] = $this->Vals[$Code]; |
157 | 161 | $this->sp++; |
158 | 162 | |
159 | - if ($Code == $this->Next[$Code]) // Circular table entry, big GIF Error! |
|
163 | + if ($Code == $this->Next[$Code]) { |
|
164 | + // Circular table entry, big GIF Error! |
|
160 | 165 | return -1; |
166 | + } |
|
161 | 167 | |
162 | 168 | $Code = $this->Next[$Code]; |
163 | 169 | } |
@@ -207,8 +213,9 @@ discard block |
||
207 | 213 | if ($this->Done) |
208 | 214 | { |
209 | 215 | // Ran off the end of my bits... |
210 | - if ($this->CurBit >= $this->LastBit) |
|
211 | - return 0; |
|
216 | + if ($this->CurBit >= $this->LastBit) { |
|
217 | + return 0; |
|
218 | + } |
|
212 | 219 | |
213 | 220 | return -1; |
214 | 221 | } |
@@ -221,13 +228,14 @@ discard block |
||
221 | 228 | |
222 | 229 | if ($count) |
223 | 230 | { |
224 | - for ($i = 0; $i < $count; $i++) |
|
225 | - $this->Buf[2 + $i] = ord($data{$i}); |
|
231 | + for ($i = 0; $i < $count; $i++) { |
|
232 | + $this->Buf[2 + $i] = ord($data{$i}); |
|
233 | + } |
|
226 | 234 | |
227 | 235 | $data = substr($data, $count); |
236 | + } else { |
|
237 | + $this->Done = 1; |
|
228 | 238 | } |
229 | - else |
|
230 | - $this->Done = 1; |
|
231 | 239 | |
232 | 240 | $this->LastByte = 2 + $count; |
233 | 241 | $this->CurBit = ($this->CurBit - $this->LastBit) + 16; |
@@ -235,8 +243,9 @@ discard block |
||
235 | 243 | } |
236 | 244 | |
237 | 245 | $iRet = 0; |
238 | - for ($i = $this->CurBit, $j = 0; $j < $this->CodeSize; $i++, $j++) |
|
239 | - $iRet |= (($this->Buf[intval($i / 8)] & (1 << ($i % 8))) != 0) << $j; |
|
246 | + for ($i = $this->CurBit, $j = 0; $j < $this->CodeSize; $i++, $j++) { |
|
247 | + $iRet |= (($this->Buf[intval($i / 8)] & (1 << ($i % 8))) != 0) << $j; |
|
248 | + } |
|
240 | 249 | |
241 | 250 | $this->CurBit += $this->CodeSize; |
242 | 251 | return $iRet; |
@@ -261,8 +270,9 @@ discard block |
||
261 | 270 | for ($i = 0; $i < $num; $i++) |
262 | 271 | { |
263 | 272 | $rgb = substr($lpData, $i * 3, 3); |
264 | - if (strlen($rgb) < 3) |
|
265 | - return false; |
|
273 | + if (strlen($rgb) < 3) { |
|
274 | + return false; |
|
275 | + } |
|
266 | 276 | |
267 | 277 | $this->m_arColors[] = (ord($rgb[2]) << 16) + (ord($rgb[1]) << 8) + ord($rgb[0]); |
268 | 278 | $this->m_nColors++; |
@@ -329,13 +339,15 @@ discard block |
||
329 | 339 | $hdrLen = 0; |
330 | 340 | |
331 | 341 | $this->m_lpVer = substr($lpData, 0, 6); |
332 | - if (($this->m_lpVer != 'GIF87a') && ($this->m_lpVer != 'GIF89a')) |
|
333 | - return false; |
|
342 | + if (($this->m_lpVer != 'GIF87a') && ($this->m_lpVer != 'GIF89a')) { |
|
343 | + return false; |
|
344 | + } |
|
334 | 345 | |
335 | 346 | list ($this->m_nWidth, $this->m_nHeight) = array_values(unpack('v2', substr($lpData, 6, 4))); |
336 | 347 | |
337 | - if (!$this->m_nWidth || !$this->m_nHeight) |
|
338 | - return false; |
|
348 | + if (!$this->m_nWidth || !$this->m_nHeight) { |
|
349 | + return false; |
|
350 | + } |
|
339 | 351 | |
340 | 352 | $b = ord(substr($lpData, 10, 1)); |
341 | 353 | $this->m_bGlobalClr = ($b & 0x80) ? true : false; |
@@ -349,8 +361,9 @@ discard block |
||
349 | 361 | if ($this->m_bGlobalClr) |
350 | 362 | { |
351 | 363 | $this->m_colorTable = new gif_color_table(); |
352 | - if (!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize)) |
|
353 | - return false; |
|
364 | + if (!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize)) { |
|
365 | + return false; |
|
366 | + } |
|
354 | 367 | |
355 | 368 | $hdrLen += 3 * $this->m_nTableSize; |
356 | 369 | } |
@@ -377,8 +390,9 @@ discard block |
||
377 | 390 | // Get the width/height/etc. from the header. |
378 | 391 | list ($this->m_nLeft, $this->m_nTop, $this->m_nWidth, $this->m_nHeight) = array_values(unpack('v4', substr($lpData, 0, 8))); |
379 | 392 | |
380 | - if (!$this->m_nWidth || !$this->m_nHeight) |
|
381 | - return false; |
|
393 | + if (!$this->m_nWidth || !$this->m_nHeight) { |
|
394 | + return false; |
|
395 | + } |
|
382 | 396 | |
383 | 397 | $b = ord($lpData[8]); |
384 | 398 | $this->m_bLocalClr = ($b & 0x80) ? true : false; |
@@ -390,8 +404,9 @@ discard block |
||
390 | 404 | if ($this->m_bLocalClr) |
391 | 405 | { |
392 | 406 | $this->m_colorTable = new gif_color_table(); |
393 | - if (!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize)) |
|
394 | - return false; |
|
407 | + if (!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize)) { |
|
408 | + return false; |
|
409 | + } |
|
395 | 410 | |
396 | 411 | $hdrLen += 3 * $this->m_nTableSize; |
397 | 412 | } |
@@ -427,8 +442,9 @@ discard block |
||
427 | 442 | // Extension... |
428 | 443 | case 0x21: |
429 | 444 | $len = 0; |
430 | - if (!$this->skipExt($data, $len)) |
|
431 | - return false; |
|
445 | + if (!$this->skipExt($data, $len)) { |
|
446 | + return false; |
|
447 | + } |
|
432 | 448 | |
433 | 449 | $datLen += $len; |
434 | 450 | break; |
@@ -437,22 +453,25 @@ discard block |
||
437 | 453 | case 0x2C: |
438 | 454 | // Load the header and color table. |
439 | 455 | $len = 0; |
440 | - if (!$this->m_gih->load($data, $len)) |
|
441 | - return false; |
|
456 | + if (!$this->m_gih->load($data, $len)) { |
|
457 | + return false; |
|
458 | + } |
|
442 | 459 | |
443 | 460 | $data = substr($data, $len); |
444 | 461 | $datLen += $len; |
445 | 462 | |
446 | 463 | // Decompress the data, and ride on home ;). |
447 | 464 | $len = 0; |
448 | - if (!($this->m_data = $this->m_lzw->decompress($data, $len))) |
|
449 | - return false; |
|
465 | + if (!($this->m_data = $this->m_lzw->decompress($data, $len))) { |
|
466 | + return false; |
|
467 | + } |
|
450 | 468 | |
451 | 469 | $data = substr($data, $len); |
452 | 470 | $datLen += $len; |
453 | 471 | |
454 | - if ($this->m_gih->m_bInterlace) |
|
455 | - $this->deInterlace(); |
|
472 | + if ($this->m_gih->m_bInterlace) { |
|
473 | + $this->deInterlace(); |
|
474 | + } |
|
456 | 475 | |
457 | 476 | return true; |
458 | 477 | |
@@ -572,17 +591,20 @@ discard block |
||
572 | 591 | |
573 | 592 | public function loadFile($filename, $iIndex) |
574 | 593 | { |
575 | - if ($iIndex < 0) |
|
576 | - return false; |
|
594 | + if ($iIndex < 0) { |
|
595 | + return false; |
|
596 | + } |
|
577 | 597 | |
578 | 598 | $this->data = @file_get_contents($filename); |
579 | - if ($this->data === false) |
|
580 | - return false; |
|
599 | + if ($this->data === false) { |
|
600 | + return false; |
|
601 | + } |
|
581 | 602 | |
582 | 603 | // Tell the header to load up.... |
583 | 604 | $len = 0; |
584 | - if (!$this->header->load($this->data, $len)) |
|
585 | - return false; |
|
605 | + if (!$this->header->load($this->data, $len)) { |
|
606 | + return false; |
|
607 | + } |
|
586 | 608 | |
587 | 609 | $this->data = substr($this->data, $len); |
588 | 610 | |
@@ -590,8 +612,9 @@ discard block |
||
590 | 612 | for ($j = 0; $j <= $iIndex; $j++) |
591 | 613 | { |
592 | 614 | $imgLen = 0; |
593 | - if (!$this->image->load($this->data, $imgLen)) |
|
594 | - return false; |
|
615 | + if (!$this->image->load($this->data, $imgLen)) { |
|
616 | + return false; |
|
617 | + } |
|
595 | 618 | |
596 | 619 | $this->data = substr($this->data, $imgLen); |
597 | 620 | } |
@@ -602,8 +625,9 @@ discard block |
||
602 | 625 | |
603 | 626 | public function get_png_data($background_color) |
604 | 627 | { |
605 | - if (!$this->loaded) |
|
606 | - return false; |
|
628 | + if (!$this->loaded) { |
|
629 | + return false; |
|
630 | + } |
|
607 | 631 | |
608 | 632 | // Prepare the color table. |
609 | 633 | if ($this->image->m_gih->m_bLocalClr) |
@@ -611,25 +635,26 @@ discard block |
||
611 | 635 | $colors = $this->image->m_gih->m_nTableSize; |
612 | 636 | $pal = $this->image->m_gih->m_colorTable->toString(); |
613 | 637 | |
614 | - if ($background_color != -1) |
|
615 | - $background_color = $this->image->m_gih->m_colorTable->colorIndex($background_color); |
|
616 | - } |
|
617 | - elseif ($this->header->m_bGlobalClr) |
|
638 | + if ($background_color != -1) { |
|
639 | + $background_color = $this->image->m_gih->m_colorTable->colorIndex($background_color); |
|
640 | + } |
|
641 | + } elseif ($this->header->m_bGlobalClr) |
|
618 | 642 | { |
619 | 643 | $colors = $this->header->m_nTableSize; |
620 | 644 | $pal = $this->header->m_colorTable->toString(); |
621 | 645 | |
622 | - if ($background_color != -1) |
|
623 | - $background_color = $this->header->m_colorTable->colorIndex($background_color); |
|
624 | - } |
|
625 | - else |
|
646 | + if ($background_color != -1) { |
|
647 | + $background_color = $this->header->m_colorTable->colorIndex($background_color); |
|
648 | + } |
|
649 | + } else |
|
626 | 650 | { |
627 | 651 | $colors = 0; |
628 | 652 | $background_color = -1; |
629 | 653 | } |
630 | 654 | |
631 | - if ($background_color == -1) |
|
632 | - $background_color = $this->header->m_nBgColor; |
|
655 | + if ($background_color == -1) { |
|
656 | + $background_color = $this->header->m_nBgColor; |
|
657 | + } |
|
633 | 658 | |
634 | 659 | $data = &$this->image->m_data; |
635 | 660 | $header = &$this->image->m_gih; |
@@ -645,11 +670,13 @@ discard block |
||
645 | 670 | for ($x = 0; $x < $this->header->m_nWidth; $x++, $i++) |
646 | 671 | { |
647 | 672 | // Is this in the proper range? If so, get the specific pixel data... |
648 | - if ($x >= $header->m_nLeft && $y >= $header->m_nTop && $x < ($header->m_nLeft + $header->m_nWidth) && $y < ($header->m_nTop + $header->m_nHeight)) |
|
649 | - $bmp .= $data{$i}; |
|
673 | + if ($x >= $header->m_nLeft && $y >= $header->m_nTop && $x < ($header->m_nLeft + $header->m_nWidth) && $y < ($header->m_nTop + $header->m_nHeight)) { |
|
674 | + $bmp .= $data{$i}; |
|
675 | + } |
|
650 | 676 | // Otherwise, this is background... |
651 | - else |
|
652 | - $bmp .= chr($background_color); |
|
677 | + else { |
|
678 | + $bmp .= chr($background_color); |
|
679 | + } |
|
653 | 680 | } |
654 | 681 | } |
655 | 682 | |
@@ -678,8 +705,9 @@ discard block |
||
678 | 705 | $tmp = 'tRNS'; |
679 | 706 | |
680 | 707 | // Stick each color on - full transparency or none. |
681 | - for ($i = 0; $i < $colors; $i++) |
|
682 | - $tmp .= $i == $this->image->m_nTrans ? "\x00" : "\xFF"; |
|
708 | + for ($i = 0; $i < $colors; $i++) { |
|
709 | + $tmp .= $i == $this->image->m_nTrans ? "\x00" : "\xFF"; |
|
710 | + } |
|
683 | 711 | |
684 | 712 | $out .= $tmp . pack('N', smf_crc32($tmp)); |
685 | 713 | } |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
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 | * Entry point for the moderation center. |
@@ -26,8 +27,9 @@ discard block |
||
26 | 27 | global $txt, $context, $scripturl, $modSettings, $user_info, $sourcedir, $options; |
27 | 28 | |
28 | 29 | // Don't run this twice... and don't conflict with the admin bar. |
29 | - if (isset($context['admin_area'])) |
|
30 | - return; |
|
30 | + if (isset($context['admin_area'])) { |
|
31 | + return; |
|
32 | + } |
|
31 | 33 | |
32 | 34 | $context['can_moderate_boards'] = $user_info['mod_cache']['bq'] != '0=1'; |
33 | 35 | $context['can_moderate_groups'] = $user_info['mod_cache']['gq'] != '0=1'; |
@@ -35,8 +37,9 @@ discard block |
||
35 | 37 | $context['can_moderate_users'] = allowedTo('moderate_forum'); |
36 | 38 | |
37 | 39 | // Everyone using this area must be allowed here! |
38 | - if (!$context['can_moderate_boards'] && !$context['can_moderate_groups'] && !$context['can_moderate_approvals'] && !$context['can_moderate_users']) |
|
39 | - isAllowedTo('access_mod_center'); |
|
40 | + if (!$context['can_moderate_boards'] && !$context['can_moderate_groups'] && !$context['can_moderate_approvals'] && !$context['can_moderate_users']) { |
|
41 | + isAllowedTo('access_mod_center'); |
|
42 | + } |
|
40 | 43 | |
41 | 44 | // We're gonna want a menu of some kind. |
42 | 45 | require_once($sourcedir . '/Subs-Menu.php'); |
@@ -195,8 +198,9 @@ discard block |
||
195 | 198 | unset($moderation_areas); |
196 | 199 | |
197 | 200 | // We got something - didn't we? DIDN'T WE! |
198 | - if ($mod_include_data == false) |
|
199 | - fatal_lang_error('no_access', false); |
|
201 | + if ($mod_include_data == false) { |
|
202 | + fatal_lang_error('no_access', false); |
|
203 | + } |
|
200 | 204 | |
201 | 205 | // Retain the ID information in case required by a subaction. |
202 | 206 | $context['moderation_menu_id'] = $context['max_menu_id']; |
@@ -219,22 +223,25 @@ discard block |
||
219 | 223 | 'url' => $scripturl . '?action=moderate', |
220 | 224 | 'name' => $txt['moderation_center'], |
221 | 225 | ); |
222 | - if (isset($mod_include_data['current_area']) && $mod_include_data['current_area'] != 'index') |
|
223 | - $context['linktree'][] = array( |
|
226 | + if (isset($mod_include_data['current_area']) && $mod_include_data['current_area'] != 'index') { |
|
227 | + $context['linktree'][] = array( |
|
224 | 228 | 'url' => $scripturl . '?action=moderate;area=' . $mod_include_data['current_area'], |
225 | 229 | 'name' => $mod_include_data['label'], |
226 | 230 | ); |
227 | - if (!empty($mod_include_data['current_subsection']) && $mod_include_data['subsections'][$mod_include_data['current_subsection']][0] != $mod_include_data['label']) |
|
228 | - $context['linktree'][] = array( |
|
231 | + } |
|
232 | + if (!empty($mod_include_data['current_subsection']) && $mod_include_data['subsections'][$mod_include_data['current_subsection']][0] != $mod_include_data['label']) { |
|
233 | + $context['linktree'][] = array( |
|
229 | 234 | 'url' => $scripturl . '?action=moderate;area=' . $mod_include_data['current_area'] . ';sa=' . $mod_include_data['current_subsection'], |
230 | 235 | 'name' => $mod_include_data['subsections'][$mod_include_data['current_subsection']][0], |
231 | 236 | ); |
237 | + } |
|
232 | 238 | |
233 | 239 | // Now - finally - the bit before the encore - the main performance of course! |
234 | 240 | if (!$dont_call) |
235 | 241 | { |
236 | - if (isset($mod_include_data['file'])) |
|
237 | - require_once($sourcedir . '/' . $mod_include_data['file']); |
|
242 | + if (isset($mod_include_data['file'])) { |
|
243 | + require_once($sourcedir . '/' . $mod_include_data['file']); |
|
244 | + } |
|
238 | 245 | |
239 | 246 | call_helper($mod_include_data['function']); |
240 | 247 | } |
@@ -259,8 +266,9 @@ discard block |
||
259 | 266 | // Load what blocks the user actually can see... |
260 | 267 | $valid_blocks = array(); |
261 | 268 | |
262 | - if ($context['can_moderate_groups']) |
|
263 | - $valid_blocks['g'] = 'GroupRequests'; |
|
269 | + if ($context['can_moderate_groups']) { |
|
270 | + $valid_blocks['g'] = 'GroupRequests'; |
|
271 | + } |
|
264 | 272 | if ($context['can_moderate_boards']) |
265 | 273 | { |
266 | 274 | $valid_blocks['r'] = 'ReportedPosts'; |
@@ -269,8 +277,9 @@ discard block |
||
269 | 277 | if ($context['can_moderate_users']) |
270 | 278 | { |
271 | 279 | // This falls under the category of moderating users as well... |
272 | - if (!$context['can_moderate_boards']) |
|
273 | - $valid_blocks['w'] = 'WatchedUsers'; |
|
280 | + if (!$context['can_moderate_boards']) { |
|
281 | + $valid_blocks['w'] = 'WatchedUsers'; |
|
282 | + } |
|
274 | 283 | |
275 | 284 | $valid_blocks['rm'] = 'ReportedMembers'; |
276 | 285 | } |
@@ -281,8 +290,9 @@ discard block |
||
281 | 290 | foreach ($valid_blocks as $k => $block) |
282 | 291 | { |
283 | 292 | $block = 'ModBlock' . $block; |
284 | - if (function_exists($block)) |
|
285 | - $context['mod_blocks'][] = $block(); |
|
293 | + if (function_exists($block)) { |
|
294 | + $context['mod_blocks'][] = $block(); |
|
295 | + } |
|
286 | 296 | } |
287 | 297 | |
288 | 298 | $context['admin_prefs'] = !empty($options['admin_preferences']) ? smf_json_decode($options['admin_preferences'], true) : array(); |
@@ -309,8 +319,9 @@ discard block |
||
309 | 319 | ) |
310 | 320 | ); |
311 | 321 | $watched_users = array(); |
312 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
313 | - $watched_users[] = $row; |
|
322 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
323 | + $watched_users[] = $row; |
|
324 | + } |
|
314 | 325 | $smcFunc['db_free_result']($request); |
315 | 326 | |
316 | 327 | cache_put_data('recent_user_watches', $watched_users, 240); |
@@ -402,8 +413,9 @@ discard block |
||
402 | 413 | $note_owner = $smcFunc['db_num_rows']($get_owner); |
403 | 414 | $smcFunc['db_free_result']($get_owner); |
404 | 415 | |
405 | - if (empty($note_owner)) |
|
406 | - fatal_lang_error('mc_notes_delete_own', false); |
|
416 | + if (empty($note_owner)) { |
|
417 | + fatal_lang_error('mc_notes_delete_own', false); |
|
418 | + } |
|
407 | 419 | } |
408 | 420 | |
409 | 421 | // Lets delete it. |
@@ -460,12 +472,14 @@ discard block |
||
460 | 472 | ) |
461 | 473 | ); |
462 | 474 | $moderator_notes = array(); |
463 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
464 | - $moderator_notes[] = $row; |
|
475 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
476 | + $moderator_notes[] = $row; |
|
477 | + } |
|
465 | 478 | $smcFunc['db_free_result']($request); |
466 | 479 | |
467 | - if ($offset == 0) |
|
468 | - cache_put_data('moderator_notes', $moderator_notes, 240); |
|
480 | + if ($offset == 0) { |
|
481 | + cache_put_data('moderator_notes', $moderator_notes, 240); |
|
482 | + } |
|
469 | 483 | } |
470 | 484 | |
471 | 485 | // Lets construct a page index. |
@@ -504,8 +518,9 @@ discard block |
||
504 | 518 | // Got the info already? |
505 | 519 | $cachekey = md5(json_encode($user_info['mod_cache']['bq'])); |
506 | 520 | $context['reported_posts'] = array(); |
507 | - if ($user_info['mod_cache']['bq'] == '0=1') |
|
508 | - return 'reported_posts_block'; |
|
521 | + if ($user_info['mod_cache']['bq'] == '0=1') { |
|
522 | + return 'reported_posts_block'; |
|
523 | + } |
|
509 | 524 | |
510 | 525 | if (($reported_posts = cache_get_data('reported_posts_' . $cachekey, 90)) === null) |
511 | 526 | { |
@@ -529,8 +544,9 @@ discard block |
||
529 | 544 | ) |
530 | 545 | ); |
531 | 546 | $reported_posts = array(); |
532 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
533 | - $reported_posts[] = $row; |
|
547 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
548 | + $reported_posts[] = $row; |
|
549 | + } |
|
534 | 550 | $smcFunc['db_free_result']($request); |
535 | 551 | |
536 | 552 | // Cache it. |
@@ -568,8 +584,9 @@ discard block |
||
568 | 584 | |
569 | 585 | $context['group_requests'] = array(); |
570 | 586 | // Make sure they can even moderate someone! |
571 | - if ($user_info['mod_cache']['gq'] == '0=1') |
|
572 | - return 'group_requests_block'; |
|
587 | + if ($user_info['mod_cache']['gq'] == '0=1') { |
|
588 | + return 'group_requests_block'; |
|
589 | + } |
|
573 | 590 | |
574 | 591 | // What requests are outstanding? |
575 | 592 | $request = $smcFunc['db_query']('', ' |
@@ -618,8 +635,9 @@ discard block |
||
618 | 635 | // Got the info already? |
619 | 636 | $cachekey = md5(json_encode((int) allowedTo('moderate_forum'))); |
620 | 637 | $context['reported_users'] = array(); |
621 | - if (!allowedTo('moderate_forum')) |
|
622 | - return 'reported_users_block'; |
|
638 | + if (!allowedTo('moderate_forum')) { |
|
639 | + return 'reported_users_block'; |
|
640 | + } |
|
623 | 641 | |
624 | 642 | if (($reported_users = cache_get_data('reported_users_' . $cachekey, 90)) === null) |
625 | 643 | { |
@@ -642,8 +660,9 @@ discard block |
||
642 | 660 | ) |
643 | 661 | ); |
644 | 662 | $reported_users = array(); |
645 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
646 | - $reported_users[] = $row; |
|
663 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
664 | + $reported_users[] = $row; |
|
665 | + } |
|
647 | 666 | $smcFunc['db_free_result']($request); |
648 | 667 | |
649 | 668 | // Cache it. |
@@ -691,8 +710,9 @@ discard block |
||
691 | 710 | isAllowedTo('moderate_forum'); |
692 | 711 | |
693 | 712 | // Are they wanting to view a particular report? |
694 | - if (!empty($_REQUEST['report'])) |
|
695 | - return MemberReport(); |
|
713 | + if (!empty($_REQUEST['report'])) { |
|
714 | + return MemberReport(); |
|
715 | + } |
|
696 | 716 | |
697 | 717 | // Set up the comforting bits... |
698 | 718 | $context['page_title'] = $txt['mc_reported_members']; |
@@ -746,15 +766,15 @@ discard block |
||
746 | 766 | // Time to update. |
747 | 767 | updateSettings(array('last_mod_report_action' => time())); |
748 | 768 | recountOpenReports('members'); |
749 | - } |
|
750 | - elseif (isset($_POST['close']) && isset($_POST['close_selected'])) |
|
769 | + } elseif (isset($_POST['close']) && isset($_POST['close_selected'])) |
|
751 | 770 | { |
752 | 771 | checkSession(); |
753 | 772 | |
754 | 773 | // All the ones to update... |
755 | 774 | $toClose = array(); |
756 | - foreach ($_POST['close'] as $rid) |
|
757 | - $toClose[] = (int) $rid; |
|
775 | + foreach ($_POST['close'] as $rid) { |
|
776 | + $toClose[] = (int) $rid; |
|
777 | + } |
|
758 | 778 | |
759 | 779 | if (!empty($toClose)) |
760 | 780 | { |
@@ -907,8 +927,9 @@ discard block |
||
907 | 927 | global $context, $user_info; |
908 | 928 | |
909 | 929 | // You need to be allowed to moderate groups... |
910 | - if ($user_info['mod_cache']['gq'] == '0=1') |
|
911 | - isAllowedTo('manage_membergroups'); |
|
930 | + if ($user_info['mod_cache']['gq'] == '0=1') { |
|
931 | + isAllowedTo('manage_membergroups'); |
|
932 | + } |
|
912 | 933 | |
913 | 934 | // Load the group templates. |
914 | 935 | loadTemplate('ModerationCenter'); |
@@ -919,8 +940,9 @@ discard block |
||
919 | 940 | 'view' => 'ViewGroups', |
920 | 941 | ); |
921 | 942 | |
922 | - if (!isset($_GET['sa']) || !isset($subActions[$_GET['sa']])) |
|
923 | - $_GET['sa'] = 'view'; |
|
943 | + if (!isset($_GET['sa']) || !isset($subActions[$_GET['sa']])) { |
|
944 | + $_GET['sa'] = 'view'; |
|
945 | + } |
|
924 | 946 | $context['sub_action'] = $_GET['sa']; |
925 | 947 | |
926 | 948 | // Call the relevant function. |
@@ -950,8 +972,9 @@ discard block |
||
950 | 972 | 'id_notice' => $id_notice, |
951 | 973 | ) |
952 | 974 | ); |
953 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
954 | - fatal_lang_error('no_access', false); |
|
975 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
976 | + fatal_lang_error('no_access', false); |
|
977 | + } |
|
955 | 978 | list ($context['notice_body'], $context['notice_subject']) = $smcFunc['db_fetch_row']($request); |
956 | 979 | $smcFunc['db_free_result']($request); |
957 | 980 | |
@@ -988,18 +1011,20 @@ discard block |
||
988 | 1011 | checkSession(!is_array($_REQUEST['delete']) ? 'get' : 'post'); |
989 | 1012 | |
990 | 1013 | $toDelete = array(); |
991 | - if (!is_array($_REQUEST['delete'])) |
|
992 | - $toDelete[] = (int) $_REQUEST['delete']; |
|
993 | - else |
|
994 | - foreach ($_REQUEST['delete'] as $did) |
|
1014 | + if (!is_array($_REQUEST['delete'])) { |
|
1015 | + $toDelete[] = (int) $_REQUEST['delete']; |
|
1016 | + } else { |
|
1017 | + foreach ($_REQUEST['delete'] as $did) |
|
995 | 1018 | $toDelete[] = (int) $did; |
1019 | + } |
|
996 | 1020 | |
997 | 1021 | if (!empty($toDelete)) |
998 | 1022 | { |
999 | 1023 | require_once($sourcedir . '/RemoveTopic.php'); |
1000 | 1024 | // If they don't have permission we'll let it error - either way no chance of a security slip here! |
1001 | - foreach ($toDelete as $did) |
|
1002 | - removeMessage($did); |
|
1025 | + foreach ($toDelete as $did) { |
|
1026 | + removeMessage($did); |
|
1027 | + } |
|
1003 | 1028 | } |
1004 | 1029 | } |
1005 | 1030 | |
@@ -1008,20 +1033,21 @@ discard block |
||
1008 | 1033 | { |
1009 | 1034 | $approve_query = ''; |
1010 | 1035 | $delete_boards = array(); |
1011 | - } |
|
1012 | - else |
|
1036 | + } else |
|
1013 | 1037 | { |
1014 | 1038 | // Still obey permissions! |
1015 | 1039 | $approve_boards = boardsAllowedTo('approve_posts'); |
1016 | 1040 | $delete_boards = boardsAllowedTo('delete_any'); |
1017 | 1041 | |
1018 | - if ($approve_boards == array(0)) |
|
1019 | - $approve_query = ''; |
|
1020 | - elseif (!empty($approve_boards)) |
|
1021 | - $approve_query = ' AND m.id_board IN (' . implode(',', $approve_boards) . ')'; |
|
1042 | + if ($approve_boards == array(0)) { |
|
1043 | + $approve_query = ''; |
|
1044 | + } elseif (!empty($approve_boards)) { |
|
1045 | + $approve_query = ' AND m.id_board IN (' . implode(',', $approve_boards) . ')'; |
|
1046 | + } |
|
1022 | 1047 | // Nada, zip, etc... |
1023 | - else |
|
1024 | - $approve_query = ' AND 1=0'; |
|
1048 | + else { |
|
1049 | + $approve_query = ' AND 1=0'; |
|
1050 | + } |
|
1025 | 1051 | } |
1026 | 1052 | |
1027 | 1053 | require_once($sourcedir . '/Subs-List.php'); |
@@ -1120,10 +1146,11 @@ discard block |
||
1120 | 1146 | 'data' => array( |
1121 | 1147 | 'function' => function($member) use ($scripturl) |
1122 | 1148 | { |
1123 | - if ($member['last_post_id']) |
|
1124 | - return '<a href="' . $scripturl . '?msg=' . $member['last_post_id'] . '">' . $member['last_post'] . '</a>'; |
|
1125 | - else |
|
1126 | - return $member['last_post']; |
|
1149 | + if ($member['last_post_id']) { |
|
1150 | + return '<a href="' . $scripturl . '?msg=' . $member['last_post_id'] . '">' . $member['last_post'] . '</a>'; |
|
1151 | + } else { |
|
1152 | + return $member['last_post']; |
|
1153 | + } |
|
1127 | 1154 | }, |
1128 | 1155 | ), |
1129 | 1156 | ), |
@@ -1251,8 +1278,9 @@ discard block |
||
1251 | 1278 | ) |
1252 | 1279 | ); |
1253 | 1280 | $latest_posts = array(); |
1254 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1255 | - $latest_posts[$row['id_member']] = $row['last_post_id']; |
|
1281 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1282 | + $latest_posts[$row['id_member']] = $row['last_post_id']; |
|
1283 | + } |
|
1256 | 1284 | |
1257 | 1285 | if (!empty($latest_posts)) |
1258 | 1286 | { |
@@ -1443,15 +1471,17 @@ discard block |
||
1443 | 1471 | // Setup the direction stuff... |
1444 | 1472 | $context['order'] = isset($_REQUEST['sort']) && isset($sort_types[$_REQUEST['sort']]) ? $_REQUEST['sort'] : 'member'; |
1445 | 1473 | |
1446 | - if (!isset($search_params['string']) || (!empty($_REQUEST['search']) && $search_params['string'] != $_REQUEST['search'])) |
|
1447 | - $search_params_string = empty($_REQUEST['search']) ? '' : $_REQUEST['search']; |
|
1448 | - else |
|
1449 | - $search_params_string = $search_params['string']; |
|
1474 | + if (!isset($search_params['string']) || (!empty($_REQUEST['search']) && $search_params['string'] != $_REQUEST['search'])) { |
|
1475 | + $search_params_string = empty($_REQUEST['search']) ? '' : $_REQUEST['search']; |
|
1476 | + } else { |
|
1477 | + $search_params_string = $search_params['string']; |
|
1478 | + } |
|
1450 | 1479 | |
1451 | - if (isset($_REQUEST['search_type']) || empty($search_params['type']) || !isset($searchTypes[$search_params['type']])) |
|
1452 | - $search_params_type = isset($_REQUEST['search_type']) && isset($searchTypes[$_REQUEST['search_type']]) ? $_REQUEST['search_type'] : (isset($searchTypes[$context['order']]) ? $context['order'] : 'member'); |
|
1453 | - else |
|
1454 | - $search_params_type = $search_params['type']; |
|
1480 | + if (isset($_REQUEST['search_type']) || empty($search_params['type']) || !isset($searchTypes[$search_params['type']])) { |
|
1481 | + $search_params_type = isset($_REQUEST['search_type']) && isset($searchTypes[$_REQUEST['search_type']]) ? $_REQUEST['search_type'] : (isset($searchTypes[$context['order']]) ? $context['order'] : 'member'); |
|
1482 | + } else { |
|
1483 | + $search_params_type = $search_params['type']; |
|
1484 | + } |
|
1455 | 1485 | |
1456 | 1486 | $search_params_column = $searchTypes[$search_params_type]['sql']; |
1457 | 1487 | $search_params = array( |
@@ -1535,9 +1565,10 @@ discard block |
||
1535 | 1565 | ' . $rowData['reason'] . ' |
1536 | 1566 | </div>'; |
1537 | 1567 | |
1538 | - if (!empty($rowData['id_notice'])) |
|
1539 | - $output .= ' |
|
1568 | + if (!empty($rowData['id_notice'])) { |
|
1569 | + $output .= ' |
|
1540 | 1570 | <a href="' . $scripturl . '?action=moderate;area=notice;nid=' . $rowData['id_notice'] . '" onclick="window.open(this.href, \'\', \'scrollbars=yes,resizable=yes,width=400,height=250\');return false;" target="_blank" class="new_win" title="' . $txt['profile_warning_previous_notice'] . '"><span class="generic_icons filter centericon"></span></a>'; |
1571 | + } |
|
1541 | 1572 | return $output; |
1542 | 1573 | }, |
1543 | 1574 | ), |
@@ -1655,9 +1686,9 @@ discard block |
||
1655 | 1686 | global $smcFunc, $modSettings, $context, $txt, $scripturl, $sourcedir, $user_info; |
1656 | 1687 | |
1657 | 1688 | // Submitting a new one? |
1658 | - if (isset($_POST['add'])) |
|
1659 | - return ModifyWarningTemplate(); |
|
1660 | - elseif (isset($_POST['delete']) && !empty($_POST['deltpl'])) |
|
1689 | + if (isset($_POST['add'])) { |
|
1690 | + return ModifyWarningTemplate(); |
|
1691 | + } elseif (isset($_POST['delete']) && !empty($_POST['deltpl'])) |
|
1661 | 1692 | { |
1662 | 1693 | checkSession(); |
1663 | 1694 | validateToken('mod-wt'); |
@@ -1676,8 +1707,9 @@ discard block |
||
1676 | 1707 | 'current_member' => $user_info['id'], |
1677 | 1708 | ) |
1678 | 1709 | ); |
1679 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1680 | - logAction('delete_warn_template', array('template' => $row['recipient_name'])); |
|
1710 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1711 | + logAction('delete_warn_template', array('template' => $row['recipient_name'])); |
|
1712 | + } |
|
1681 | 1713 | $smcFunc['db_free_result']($request); |
1682 | 1714 | |
1683 | 1715 | // Do the deletes. |
@@ -1968,16 +2000,18 @@ discard block |
||
1968 | 2000 | ); |
1969 | 2001 | |
1970 | 2002 | // If it wasn't visible and now is they've effectively added it. |
1971 | - if ($context['template_data']['personal'] && !$recipient_id) |
|
1972 | - logAction('add_warn_template', array('template' => $_POST['template_title'])); |
|
2003 | + if ($context['template_data']['personal'] && !$recipient_id) { |
|
2004 | + logAction('add_warn_template', array('template' => $_POST['template_title'])); |
|
2005 | + } |
|
1973 | 2006 | // Conversely if they made it personal it's a delete. |
1974 | - elseif (!$context['template_data']['personal'] && $recipient_id) |
|
1975 | - logAction('delete_warn_template', array('template' => $_POST['template_title'])); |
|
2007 | + elseif (!$context['template_data']['personal'] && $recipient_id) { |
|
2008 | + logAction('delete_warn_template', array('template' => $_POST['template_title'])); |
|
2009 | + } |
|
1976 | 2010 | // Otherwise just an edit. |
1977 | - else |
|
1978 | - logAction('modify_warn_template', array('template' => $_POST['template_title'])); |
|
1979 | - } |
|
1980 | - else |
|
2011 | + else { |
|
2012 | + logAction('modify_warn_template', array('template' => $_POST['template_title'])); |
|
2013 | + } |
|
2014 | + } else |
|
1981 | 2015 | { |
1982 | 2016 | $smcFunc['db_insert']('', |
1983 | 2017 | '{db_prefix}log_comments', |
@@ -1997,17 +2031,18 @@ discard block |
||
1997 | 2031 | |
1998 | 2032 | // Get out of town... |
1999 | 2033 | redirectexit('action=moderate;area=warnings;sa=templates'); |
2000 | - } |
|
2001 | - else |
|
2034 | + } else |
|
2002 | 2035 | { |
2003 | 2036 | $context['warning_errors'] = array(); |
2004 | 2037 | $context['template_data']['title'] = !empty($_POST['template_title']) ? $_POST['template_title'] : ''; |
2005 | 2038 | $context['template_data']['body'] = !empty($_POST['template_body']) ? $_POST['template_body'] : $txt['mc_warning_template_body_default']; |
2006 | 2039 | $context['template_data']['personal'] = !empty($_POST['make_personal']); |
2007 | - if (empty($_POST['template_title'])) |
|
2008 | - $context['warning_errors'][] = $txt['mc_warning_template_error_no_title']; |
|
2009 | - if (empty($_POST['template_body'])) |
|
2010 | - $context['warning_errors'][] = $txt['mc_warning_template_error_no_body']; |
|
2040 | + if (empty($_POST['template_title'])) { |
|
2041 | + $context['warning_errors'][] = $txt['mc_warning_template_error_no_title']; |
|
2042 | + } |
|
2043 | + if (empty($_POST['template_body'])) { |
|
2044 | + $context['warning_errors'][] = $txt['mc_warning_template_error_no_body']; |
|
2045 | + } |
|
2011 | 2046 | } |
2012 | 2047 | } |
2013 | 2048 | |
@@ -2054,8 +2089,9 @@ discard block |
||
2054 | 2089 | // Now check other options! |
2055 | 2090 | $pref_binary = 0; |
2056 | 2091 | |
2057 | - if ($context['can_moderate_approvals'] && !empty($_POST['mod_notify_approval'])) |
|
2058 | - $pref_binary |= 4; |
|
2092 | + if ($context['can_moderate_approvals'] && !empty($_POST['mod_notify_approval'])) { |
|
2093 | + $pref_binary |= 4; |
|
2094 | + } |
|
2059 | 2095 | |
2060 | 2096 | // Put it all together. |
2061 | 2097 | $mod_prefs = '0||' . $pref_binary; |
@@ -2079,9 +2115,10 @@ discard block |
||
2079 | 2115 | unset($_SESSION['moderate_time']); |
2080 | 2116 | |
2081 | 2117 | // Clean any moderator tokens as well. |
2082 | - foreach ($_SESSION['token'] as $key => $token) |
|
2083 | - if (strpos($key, '-mod') !== false) |
|
2118 | + foreach ($_SESSION['token'] as $key => $token) { |
|
2119 | + if (strpos($key, '-mod') !== false) |
|
2084 | 2120 | unset($_SESSION['token'][$key]); |
2121 | + } |
|
2085 | 2122 | |
2086 | 2123 | redirectexit(); |
2087 | 2124 | } |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 3 |
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 | * Ban center. The main entrance point for all ban center functions. |
@@ -120,10 +121,11 @@ discard block |
||
120 | 121 | } |
121 | 122 | |
122 | 123 | // Create a date string so we don't overload them with date info. |
123 | - if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) |
|
124 | - $context['ban_time_format'] = $user_info['time_format']; |
|
125 | - else |
|
126 | - $context['ban_time_format'] = $matches[0]; |
|
124 | + if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) { |
|
125 | + $context['ban_time_format'] = $user_info['time_format']; |
|
126 | + } else { |
|
127 | + $context['ban_time_format'] = $matches[0]; |
|
128 | + } |
|
127 | 129 | |
128 | 130 | $listOptions = array( |
129 | 131 | 'id' => 'ban_list', |
@@ -201,16 +203,19 @@ discard block |
||
201 | 203 | 'function' => function($rowData) use ($txt) |
202 | 204 | { |
203 | 205 | // This ban never expires...whahaha. |
204 | - if ($rowData['expire_time'] === null) |
|
205 | - return $txt['never']; |
|
206 | + if ($rowData['expire_time'] === null) { |
|
207 | + return $txt['never']; |
|
208 | + } |
|
206 | 209 | |
207 | 210 | // This ban has already expired. |
208 | - elseif ($rowData['expire_time'] < time()) |
|
209 | - return sprintf('<span class="red">%1$s</span>', $txt['ban_expired']); |
|
211 | + elseif ($rowData['expire_time'] < time()) { |
|
212 | + return sprintf('<span class="red">%1$s</span>', $txt['ban_expired']); |
|
213 | + } |
|
210 | 214 | |
211 | 215 | // Still need to wait a few days for this ban to expire. |
212 | - else |
|
213 | - return sprintf('%1$d %2$s', ceil(($rowData['expire_time'] - time()) / (60 * 60 * 24)), $txt['ban_days']); |
|
216 | + else { |
|
217 | + return sprintf('%1$d %2$s', ceil(($rowData['expire_time'] - time()) / (60 * 60 * 24)), $txt['ban_days']); |
|
218 | + } |
|
214 | 219 | }, |
215 | 220 | ), |
216 | 221 | 'sort' => array( |
@@ -309,8 +314,9 @@ discard block |
||
309 | 314 | ) |
310 | 315 | ); |
311 | 316 | $bans = array(); |
312 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
313 | - $bans[] = $row; |
|
317 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
318 | + $bans[] = $row; |
|
319 | + } |
|
314 | 320 | |
315 | 321 | $smcFunc['db_free_result']($request); |
316 | 322 | |
@@ -352,8 +358,9 @@ discard block |
||
352 | 358 | { |
353 | 359 | global $txt, $modSettings, $context, $scripturl, $smcFunc, $sourcedir; |
354 | 360 | |
355 | - if ((isset($_POST['add_ban']) || isset($_POST['modify_ban']) || isset($_POST['remove_selection'])) && empty($context['ban_errors'])) |
|
356 | - BanEdit2(); |
|
361 | + if ((isset($_POST['add_ban']) || isset($_POST['modify_ban']) || isset($_POST['remove_selection'])) && empty($context['ban_errors'])) { |
|
362 | + BanEdit2(); |
|
363 | + } |
|
357 | 364 | |
358 | 365 | $ban_group_id = isset($context['ban']['id']) ? $context['ban']['id'] : (isset($_REQUEST['bg']) ? (int) $_REQUEST['bg'] : 0); |
359 | 366 | |
@@ -364,10 +371,10 @@ discard block |
||
364 | 371 | |
365 | 372 | if (!empty($context['ban_errors'])) |
366 | 373 | { |
367 | - foreach ($context['ban_errors'] as $error) |
|
368 | - $context['error_messages'][$error] = $txt[$error]; |
|
369 | - } |
|
370 | - else |
|
374 | + foreach ($context['ban_errors'] as $error) { |
|
375 | + $context['error_messages'][$error] = $txt[$error]; |
|
376 | + } |
|
377 | + } else |
|
371 | 378 | { |
372 | 379 | // If we're editing an existing ban, get it from the database. |
373 | 380 | if (!empty($ban_group_id)) |
@@ -403,12 +410,13 @@ discard block |
||
403 | 410 | 'data' => array( |
404 | 411 | 'function' => function($ban_item) use ($txt) |
405 | 412 | { |
406 | - if (in_array($ban_item['type'], array('ip', 'hostname', 'email'))) |
|
407 | - return '<strong>' . $txt[$ban_item['type']] . ':</strong> ' . $ban_item[$ban_item['type']]; |
|
408 | - elseif ($ban_item['type'] == 'user') |
|
409 | - return '<strong>' . $txt['username'] . ':</strong> ' . $ban_item['user']['link']; |
|
410 | - else |
|
411 | - return '<strong>' . $txt['unknown'] . ':</strong> ' . $ban_item['no_bantype_selected']; |
|
413 | + if (in_array($ban_item['type'], array('ip', 'hostname', 'email'))) { |
|
414 | + return '<strong>' . $txt[$ban_item['type']] . ':</strong> ' . $ban_item[$ban_item['type']]; |
|
415 | + } elseif ($ban_item['type'] == 'user') { |
|
416 | + return '<strong>' . $txt['username'] . ':</strong> ' . $ban_item['user']['link']; |
|
417 | + } else { |
|
418 | + return '<strong>' . $txt['unknown'] . ':</strong> ' . $ban_item['no_bantype_selected']; |
|
419 | + } |
|
412 | 420 | }, |
413 | 421 | 'style' => 'text-align: left;', |
414 | 422 | ), |
@@ -546,8 +554,9 @@ discard block |
||
546 | 554 | $context['ban']['from_user'] = true; |
547 | 555 | |
548 | 556 | // Would be nice if we could also ban the hostname. |
549 | - if ((preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $context['ban_suggestions']['main_ip']) == 1 || isValidIPv6($context['ban_suggestions']['main_ip'])) && empty($modSettings['disableHostnameLookup'])) |
|
550 | - $context['ban_suggestions']['hostname'] = host_from_ip($context['ban_suggestions']['main_ip']); |
|
557 | + if ((preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $context['ban_suggestions']['main_ip']) == 1 || isValidIPv6($context['ban_suggestions']['main_ip'])) && empty($modSettings['disableHostnameLookup'])) { |
|
558 | + $context['ban_suggestions']['hostname'] = host_from_ip($context['ban_suggestions']['main_ip']); |
|
559 | + } |
|
551 | 560 | |
552 | 561 | $context['ban_suggestions']['other_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id']); |
553 | 562 | } |
@@ -615,8 +624,9 @@ discard block |
||
615 | 624 | 'items_per_page' => $items_per_page, |
616 | 625 | ) |
617 | 626 | ); |
618 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
619 | - fatal_lang_error('ban_not_found', false); |
|
627 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
628 | + fatal_lang_error('ban_not_found', false); |
|
629 | + } |
|
620 | 630 | |
621 | 631 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
622 | 632 | { |
@@ -653,18 +663,15 @@ discard block |
||
653 | 663 | { |
654 | 664 | $ban_items[$row['id_ban']]['type'] = 'ip'; |
655 | 665 | $ban_items[$row['id_ban']]['ip'] = range2ip($row['ip_low'], $row['ip_high']); |
656 | - } |
|
657 | - elseif (!empty($row['hostname'])) |
|
666 | + } elseif (!empty($row['hostname'])) |
|
658 | 667 | { |
659 | 668 | $ban_items[$row['id_ban']]['type'] = 'hostname'; |
660 | 669 | $ban_items[$row['id_ban']]['hostname'] = str_replace('%', '*', $row['hostname']); |
661 | - } |
|
662 | - elseif (!empty($row['email_address'])) |
|
670 | + } elseif (!empty($row['email_address'])) |
|
663 | 671 | { |
664 | 672 | $ban_items[$row['id_ban']]['type'] = 'email'; |
665 | 673 | $ban_items[$row['id_ban']]['email'] = str_replace('%', '*', $row['email_address']); |
666 | - } |
|
667 | - elseif (!empty($row['id_member'])) |
|
674 | + } elseif (!empty($row['id_member'])) |
|
668 | 675 | { |
669 | 676 | $ban_items[$row['id_ban']]['type'] = 'user'; |
670 | 677 | $ban_items[$row['id_ban']]['user'] = array( |
@@ -730,9 +737,10 @@ discard block |
||
730 | 737 | $search_list += array('ips_in_messages' => 'banLoadAdditionalIPsMember', 'ips_in_errors' => 'banLoadAdditionalIPsError'); |
731 | 738 | |
732 | 739 | $return = array(); |
733 | - foreach ($search_list as $key => $callable) |
|
734 | - if (is_callable($callable)) |
|
740 | + foreach ($search_list as $key => $callable) { |
|
741 | + if (is_callable($callable)) |
|
735 | 742 | $return[$key] = call_user_func($callable, $member_id); |
743 | + } |
|
736 | 744 | |
737 | 745 | return $return; |
738 | 746 | } |
@@ -757,8 +765,9 @@ discard block |
||
757 | 765 | 'current_user' => $member_id, |
758 | 766 | ) |
759 | 767 | ); |
760 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
761 | - $message_ips[] = inet_dtop($row['poster_ip']); |
|
768 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
769 | + $message_ips[] = inet_dtop($row['poster_ip']); |
|
770 | + } |
|
762 | 771 | $smcFunc['db_free_result']($request); |
763 | 772 | |
764 | 773 | return $message_ips; |
@@ -783,8 +792,9 @@ discard block |
||
783 | 792 | 'current_user' => $member_id, |
784 | 793 | ) |
785 | 794 | ); |
786 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
787 | - $error_ips[] = inet_dtop($row['ip']); |
|
795 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
796 | + $error_ips[] = inet_dtop($row['ip']); |
|
797 | + } |
|
788 | 798 | $smcFunc['db_free_result']($request); |
789 | 799 | |
790 | 800 | return $error_ips; |
@@ -825,11 +835,13 @@ discard block |
||
825 | 835 | $ban_info['cannot']['login'] = !empty($ban_info['full_ban']) || empty($_POST['cannot_login']) ? 0 : 1; |
826 | 836 | |
827 | 837 | // Adding a new ban group |
828 | - if (empty($_REQUEST['bg'])) |
|
829 | - $ban_group_id = insertBanGroup($ban_info); |
|
838 | + if (empty($_REQUEST['bg'])) { |
|
839 | + $ban_group_id = insertBanGroup($ban_info); |
|
840 | + } |
|
830 | 841 | // Editing an existing ban group |
831 | - else |
|
832 | - $ban_group_id = updateBanGroup($ban_info); |
|
842 | + else { |
|
843 | + $ban_group_id = updateBanGroup($ban_info); |
|
844 | + } |
|
833 | 845 | |
834 | 846 | if (is_numeric($ban_group_id)) |
835 | 847 | { |
@@ -840,9 +852,10 @@ discard block |
||
840 | 852 | $context['ban'] = $ban_info; |
841 | 853 | } |
842 | 854 | |
843 | - if (isset($_POST['ban_suggestions'])) |
|
844 | - // @TODO: is $_REQUEST['bi'] ever set? |
|
855 | + if (isset($_POST['ban_suggestions'])) { |
|
856 | + // @TODO: is $_REQUEST['bi'] ever set? |
|
845 | 857 | $saved_triggers = saveTriggers($_POST['ban_suggestions'], $ban_info['id'], isset($_REQUEST['u']) ? (int) $_REQUEST['u'] : 0, isset($_REQUEST['bi']) ? (int) $_REQUEST['bi'] : 0); |
858 | + } |
|
846 | 859 | |
847 | 860 | // Something went wrong somewhere... Oh well, let's go back. |
848 | 861 | if (!empty($context['ban_errors'])) |
@@ -852,8 +865,9 @@ discard block |
||
852 | 865 | $context['ban_suggestions'] = array_merge($context['ban_suggestions'], getMemberData((int) $_REQUEST['u'])); |
853 | 866 | |
854 | 867 | // Not strictly necessary, but it's nice |
855 | - if (!empty($context['ban_suggestions']['member']['id'])) |
|
856 | - $context['ban_suggestions']['other_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id']); |
|
868 | + if (!empty($context['ban_suggestions']['member']['id'])) { |
|
869 | + $context['ban_suggestions']['other_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id']); |
|
870 | + } |
|
857 | 871 | return BanEdit(); |
858 | 872 | } |
859 | 873 | $context['ban_suggestions']['saved_triggers'] = !empty($saved_triggers) ? $saved_triggers : array(); |
@@ -902,10 +916,11 @@ discard block |
||
902 | 916 | |
903 | 917 | foreach ($suggestions as $key => $value) |
904 | 918 | { |
905 | - if (is_array($value)) |
|
906 | - $triggers[$key] = $value; |
|
907 | - else |
|
908 | - $triggers[$value] = !empty($_POST[$value]) ? $_POST[$value] : ''; |
|
919 | + if (is_array($value)) { |
|
920 | + $triggers[$key] = $value; |
|
921 | + } else { |
|
922 | + $triggers[$value] = !empty($_POST[$value]) ? $_POST[$value] : ''; |
|
923 | + } |
|
909 | 924 | } |
910 | 925 | |
911 | 926 | $ban_triggers = validateTriggers($triggers); |
@@ -913,16 +928,18 @@ discard block |
||
913 | 928 | // Time to save! |
914 | 929 | if (!empty($ban_triggers['ban_triggers']) && empty($context['ban_errors'])) |
915 | 930 | { |
916 | - if (empty($ban_id)) |
|
917 | - addTriggers($ban_group, $ban_triggers['ban_triggers'], $ban_triggers['log_info']); |
|
918 | - else |
|
919 | - updateTriggers($ban_id, $ban_group, array_shift($ban_triggers['ban_triggers']), $ban_triggers['log_info']); |
|
931 | + if (empty($ban_id)) { |
|
932 | + addTriggers($ban_group, $ban_triggers['ban_triggers'], $ban_triggers['log_info']); |
|
933 | + } else { |
|
934 | + updateTriggers($ban_id, $ban_group, array_shift($ban_triggers['ban_triggers']), $ban_triggers['log_info']); |
|
935 | + } |
|
936 | + } |
|
937 | + if (!empty($context['ban_errors'])) { |
|
938 | + return $triggers; |
|
939 | + } else { |
|
940 | + return false; |
|
941 | + } |
|
920 | 942 | } |
921 | - if (!empty($context['ban_errors'])) |
|
922 | - return $triggers; |
|
923 | - else |
|
924 | - return false; |
|
925 | -} |
|
926 | 943 | |
927 | 944 | /** |
928 | 945 | * This function removes a bunch of triggers based on ids |
@@ -936,14 +953,17 @@ discard block |
||
936 | 953 | { |
937 | 954 | global $smcFunc, $scripturl; |
938 | 955 | |
939 | - if ($group_id !== false) |
|
940 | - $group_id = (int) $group_id; |
|
956 | + if ($group_id !== false) { |
|
957 | + $group_id = (int) $group_id; |
|
958 | + } |
|
941 | 959 | |
942 | - if (empty($group_id) && empty($items_ids)) |
|
943 | - return false; |
|
960 | + if (empty($group_id) && empty($items_ids)) { |
|
961 | + return false; |
|
962 | + } |
|
944 | 963 | |
945 | - if (!is_array($items_ids)) |
|
946 | - $items_ids = array($items_ids); |
|
964 | + if (!is_array($items_ids)) { |
|
965 | + $items_ids = array($items_ids); |
|
966 | + } |
|
947 | 967 | |
948 | 968 | $log_info = array(); |
949 | 969 | $ban_items = array(); |
@@ -981,8 +1001,7 @@ discard block |
||
981 | 1001 | 'bantype' => ($is_range ? 'ip_range' : 'main_ip'), |
982 | 1002 | 'value' => $ban_items[$row['id_ban']]['ip'], |
983 | 1003 | ); |
984 | - } |
|
985 | - elseif (!empty($row['hostname'])) |
|
1004 | + } elseif (!empty($row['hostname'])) |
|
986 | 1005 | { |
987 | 1006 | $ban_items[$row['id_ban']]['type'] = 'hostname'; |
988 | 1007 | $ban_items[$row['id_ban']]['hostname'] = str_replace('%', '*', $row['hostname']); |
@@ -990,8 +1009,7 @@ discard block |
||
990 | 1009 | 'bantype' => 'hostname', |
991 | 1010 | 'value' => $row['hostname'], |
992 | 1011 | ); |
993 | - } |
|
994 | - elseif (!empty($row['email_address'])) |
|
1012 | + } elseif (!empty($row['email_address'])) |
|
995 | 1013 | { |
996 | 1014 | $ban_items[$row['id_ban']]['type'] = 'email'; |
997 | 1015 | $ban_items[$row['id_ban']]['email'] = str_replace('%', '*', $row['email_address']); |
@@ -999,8 +1017,7 @@ discard block |
||
999 | 1017 | 'bantype' => 'email', |
1000 | 1018 | 'value' => $ban_items[$row['id_ban']]['email'], |
1001 | 1019 | ); |
1002 | - } |
|
1003 | - elseif (!empty($row['id_member'])) |
|
1020 | + } elseif (!empty($row['id_member'])) |
|
1004 | 1021 | { |
1005 | 1022 | $ban_items[$row['id_ban']]['type'] = 'user'; |
1006 | 1023 | $ban_items[$row['id_ban']]['user'] = array( |
@@ -1033,8 +1050,7 @@ discard block |
||
1033 | 1050 | 'ban_group' => $group_id, |
1034 | 1051 | ) |
1035 | 1052 | ); |
1036 | - } |
|
1037 | - elseif (!empty($items_ids)) |
|
1053 | + } elseif (!empty($items_ids)) |
|
1038 | 1054 | { |
1039 | 1055 | $smcFunc['db_query']('', ' |
1040 | 1056 | DELETE FROM {db_prefix}ban_items |
@@ -1059,13 +1075,15 @@ discard block |
||
1059 | 1075 | { |
1060 | 1076 | global $smcFunc; |
1061 | 1077 | |
1062 | - if (!is_array($group_ids)) |
|
1063 | - $group_ids = array($group_ids); |
|
1078 | + if (!is_array($group_ids)) { |
|
1079 | + $group_ids = array($group_ids); |
|
1080 | + } |
|
1064 | 1081 | |
1065 | 1082 | $group_ids = array_unique($group_ids); |
1066 | 1083 | |
1067 | - if (empty($group_ids)) |
|
1068 | - return false; |
|
1084 | + if (empty($group_ids)) { |
|
1085 | + return false; |
|
1086 | + } |
|
1069 | 1087 | |
1070 | 1088 | $smcFunc['db_query']('', ' |
1071 | 1089 | DELETE FROM {db_prefix}ban_groups |
@@ -1089,21 +1107,23 @@ discard block |
||
1089 | 1107 | { |
1090 | 1108 | global $smcFunc; |
1091 | 1109 | |
1092 | - if (empty($ids)) |
|
1093 | - $smcFunc['db_query']('truncate_table', ' |
|
1110 | + if (empty($ids)) { |
|
1111 | + $smcFunc['db_query']('truncate_table', ' |
|
1094 | 1112 | TRUNCATE {db_prefix}log_banned', |
1095 | 1113 | array( |
1096 | 1114 | ) |
1097 | 1115 | ); |
1098 | - else |
|
1116 | + } else |
|
1099 | 1117 | { |
1100 | - if (!is_array($ids)) |
|
1101 | - $ids = array($ids); |
|
1118 | + if (!is_array($ids)) { |
|
1119 | + $ids = array($ids); |
|
1120 | + } |
|
1102 | 1121 | |
1103 | 1122 | $ids = array_unique($ids); |
1104 | 1123 | |
1105 | - if (empty($ids)) |
|
1106 | - return false; |
|
1124 | + if (empty($ids)) { |
|
1125 | + return false; |
|
1126 | + } |
|
1107 | 1127 | |
1108 | 1128 | $smcFunc['db_query']('', ' |
1109 | 1129 | DELETE FROM {db_prefix}log_banned |
@@ -1129,8 +1149,9 @@ discard block |
||
1129 | 1149 | { |
1130 | 1150 | global $context, $smcFunc; |
1131 | 1151 | |
1132 | - if (empty($triggers)) |
|
1133 | - $context['ban_erros'][] = 'ban_empty_triggers'; |
|
1152 | + if (empty($triggers)) { |
|
1153 | + $context['ban_erros'][] = 'ban_empty_triggers'; |
|
1154 | + } |
|
1134 | 1155 | |
1135 | 1156 | $ban_triggers = array(); |
1136 | 1157 | $log_info = array(); |
@@ -1139,39 +1160,39 @@ discard block |
||
1139 | 1160 | { |
1140 | 1161 | if (!empty($value)) |
1141 | 1162 | { |
1142 | - if ($key == 'member') |
|
1143 | - continue; |
|
1163 | + if ($key == 'member') { |
|
1164 | + continue; |
|
1165 | + } |
|
1144 | 1166 | |
1145 | 1167 | if ($key == 'main_ip') |
1146 | 1168 | { |
1147 | 1169 | $value = trim($value); |
1148 | 1170 | $ip_parts = ip2range($value); |
1149 | - if (!checkExistingTriggerIP($ip_parts, $value)) |
|
1150 | - $context['ban_erros'][] = 'invalid_ip'; |
|
1151 | - else |
|
1171 | + if (!checkExistingTriggerIP($ip_parts, $value)) { |
|
1172 | + $context['ban_erros'][] = 'invalid_ip'; |
|
1173 | + } else |
|
1152 | 1174 | { |
1153 | 1175 | $ban_triggers['main_ip'] = array( |
1154 | 1176 | 'ip_low' => $ip_parts['low'], |
1155 | 1177 | 'ip_high' => $ip_parts['high'] |
1156 | 1178 | ); |
1157 | 1179 | } |
1158 | - } |
|
1159 | - elseif ($key == 'hostname') |
|
1180 | + } elseif ($key == 'hostname') |
|
1160 | 1181 | { |
1161 | - if (preg_match('/[^\w.\-*]/', $value) == 1) |
|
1162 | - $context['ban_erros'][] = 'invalid_hostname'; |
|
1163 | - else |
|
1182 | + if (preg_match('/[^\w.\-*]/', $value) == 1) { |
|
1183 | + $context['ban_erros'][] = 'invalid_hostname'; |
|
1184 | + } else |
|
1164 | 1185 | { |
1165 | 1186 | // Replace the * wildcard by a MySQL wildcard %. |
1166 | 1187 | $value = substr(str_replace('*', '%', $value), 0, 255); |
1167 | 1188 | |
1168 | 1189 | $ban_triggers['hostname']['hostname'] = $value; |
1169 | 1190 | } |
1170 | - } |
|
1171 | - elseif ($key == 'email') |
|
1191 | + } elseif ($key == 'email') |
|
1172 | 1192 | { |
1173 | - if (preg_match('/[^\w.\-\+*@]/', $value) == 1) |
|
1174 | - $context['ban_erros'][] = 'invalid_email'; |
|
1193 | + if (preg_match('/[^\w.\-\+*@]/', $value) == 1) { |
|
1194 | + $context['ban_erros'][] = 'invalid_email'; |
|
1195 | + } |
|
1175 | 1196 | |
1176 | 1197 | // Check the user is not banning an admin. |
1177 | 1198 | $request = $smcFunc['db_query']('', ' |
@@ -1185,15 +1206,15 @@ discard block |
||
1185 | 1206 | 'email' => $value, |
1186 | 1207 | ) |
1187 | 1208 | ); |
1188 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
1189 | - $context['ban_erros'][] = 'no_ban_admin'; |
|
1209 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
1210 | + $context['ban_erros'][] = 'no_ban_admin'; |
|
1211 | + } |
|
1190 | 1212 | $smcFunc['db_free_result']($request); |
1191 | 1213 | |
1192 | 1214 | $value = substr(strtolower(str_replace('*', '%', $value)), 0, 255); |
1193 | 1215 | |
1194 | 1216 | $ban_triggers['email']['email_address'] = $value; |
1195 | - } |
|
1196 | - elseif ($key == 'user') |
|
1217 | + } elseif ($key == 'user') |
|
1197 | 1218 | { |
1198 | 1219 | $user = preg_replace('~&#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $smcFunc['htmlspecialchars']($value, ENT_QUOTES)); |
1199 | 1220 | |
@@ -1207,8 +1228,9 @@ discard block |
||
1207 | 1228 | 'username' => $user, |
1208 | 1229 | ) |
1209 | 1230 | ); |
1210 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
1211 | - $context['ban_erros'][] = 'invalid_username'; |
|
1231 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
1232 | + $context['ban_erros'][] = 'invalid_username'; |
|
1233 | + } |
|
1212 | 1234 | list ($value, $isAdmin) = $smcFunc['db_fetch_row']($request); |
1213 | 1235 | $smcFunc['db_free_result']($request); |
1214 | 1236 | |
@@ -1216,25 +1238,25 @@ discard block |
||
1216 | 1238 | { |
1217 | 1239 | unset($value); |
1218 | 1240 | $context['ban_erros'][] = 'no_ban_admin'; |
1241 | + } else { |
|
1242 | + $ban_triggers['user']['id_member'] = $value; |
|
1219 | 1243 | } |
1220 | - else |
|
1221 | - $ban_triggers['user']['id_member'] = $value; |
|
1222 | - } |
|
1223 | - elseif (in_array($key, array('ips_in_messages', 'ips_in_errors'))) |
|
1244 | + } elseif (in_array($key, array('ips_in_messages', 'ips_in_errors'))) |
|
1224 | 1245 | { |
1225 | 1246 | // Special case, those two are arrays themselves |
1226 | 1247 | $values = array_unique($value); |
1227 | 1248 | // Don't add the main IP again. |
1228 | - if (isset($triggers['main_ip'])) |
|
1229 | - $values = array_diff($values, array($triggers['main_ip'])); |
|
1249 | + if (isset($triggers['main_ip'])) { |
|
1250 | + $values = array_diff($values, array($triggers['main_ip'])); |
|
1251 | + } |
|
1230 | 1252 | unset($value); |
1231 | 1253 | foreach ($values as $val) |
1232 | 1254 | { |
1233 | 1255 | $val = trim($val); |
1234 | 1256 | $ip_parts = ip2range($val); |
1235 | - if (!checkExistingTriggerIP($ip_parts, $val)) |
|
1236 | - $context['ban_erros'][] = 'invalid_ip'; |
|
1237 | - else |
|
1257 | + if (!checkExistingTriggerIP($ip_parts, $val)) { |
|
1258 | + $context['ban_erros'][] = 'invalid_ip'; |
|
1259 | + } else |
|
1238 | 1260 | { |
1239 | 1261 | $ban_triggers[$key][] = array( |
1240 | 1262 | 'ip_low' => $ip_parts['low'], |
@@ -1247,15 +1269,16 @@ discard block |
||
1247 | 1269 | ); |
1248 | 1270 | } |
1249 | 1271 | } |
1272 | + } else { |
|
1273 | + $context['ban_erros'][] = 'no_bantype_selected'; |
|
1250 | 1274 | } |
1251 | - else |
|
1252 | - $context['ban_erros'][] = 'no_bantype_selected'; |
|
1253 | 1275 | |
1254 | - if (isset($value) && !is_array($value)) |
|
1255 | - $log_info[] = array( |
|
1276 | + if (isset($value) && !is_array($value)) { |
|
1277 | + $log_info[] = array( |
|
1256 | 1278 | 'value' => $value, |
1257 | 1279 | 'bantype' => $key, |
1258 | 1280 | ); |
1281 | + } |
|
1259 | 1282 | } |
1260 | 1283 | } |
1261 | 1284 | return array('ban_triggers' => $ban_triggers, 'log_info' => $log_info); |
@@ -1275,8 +1298,9 @@ discard block |
||
1275 | 1298 | { |
1276 | 1299 | global $smcFunc, $context; |
1277 | 1300 | |
1278 | - if (empty($group_id)) |
|
1279 | - $context['ban_errors'][] = 'ban_id_empty'; |
|
1301 | + if (empty($group_id)) { |
|
1302 | + $context['ban_errors'][] = 'ban_id_empty'; |
|
1303 | + } |
|
1280 | 1304 | |
1281 | 1305 | // Preset all values that are required. |
1282 | 1306 | $values = array( |
@@ -1301,18 +1325,21 @@ discard block |
||
1301 | 1325 | foreach ($triggers as $key => $trigger) |
1302 | 1326 | { |
1303 | 1327 | // Exceptions, exceptions, exceptions...always exceptions... :P |
1304 | - if (in_array($key, array('ips_in_messages', 'ips_in_errors'))) |
|
1305 | - foreach ($trigger as $real_trigger) |
|
1328 | + if (in_array($key, array('ips_in_messages', 'ips_in_errors'))) { |
|
1329 | + foreach ($trigger as $real_trigger) |
|
1306 | 1330 | $insertTriggers[] = array_merge($values, $real_trigger); |
1307 | - else |
|
1308 | - $insertTriggers[] = array_merge($values, $trigger); |
|
1331 | + } else { |
|
1332 | + $insertTriggers[] = array_merge($values, $trigger); |
|
1333 | + } |
|
1309 | 1334 | } |
1310 | 1335 | |
1311 | - if (empty($insertTriggers)) |
|
1312 | - $context['ban_errors'][] = 'ban_no_triggers'; |
|
1336 | + if (empty($insertTriggers)) { |
|
1337 | + $context['ban_errors'][] = 'ban_no_triggers'; |
|
1338 | + } |
|
1313 | 1339 | |
1314 | - if (!empty($context['ban_errors'])) |
|
1315 | - return false; |
|
1340 | + if (!empty($context['ban_errors'])) { |
|
1341 | + return false; |
|
1342 | + } |
|
1316 | 1343 | |
1317 | 1344 | $smcFunc['db_insert']('', |
1318 | 1345 | '{db_prefix}ban_items', |
@@ -1340,15 +1367,19 @@ discard block |
||
1340 | 1367 | { |
1341 | 1368 | global $smcFunc, $context; |
1342 | 1369 | |
1343 | - if (empty($ban_item)) |
|
1344 | - $context['ban_errors'][] = 'ban_ban_item_empty'; |
|
1345 | - if (empty($group_id)) |
|
1346 | - $context['ban_errors'][] = 'ban_id_empty'; |
|
1347 | - if (empty($trigger)) |
|
1348 | - $context['ban_errors'][] = 'ban_no_triggers'; |
|
1370 | + if (empty($ban_item)) { |
|
1371 | + $context['ban_errors'][] = 'ban_ban_item_empty'; |
|
1372 | + } |
|
1373 | + if (empty($group_id)) { |
|
1374 | + $context['ban_errors'][] = 'ban_id_empty'; |
|
1375 | + } |
|
1376 | + if (empty($trigger)) { |
|
1377 | + $context['ban_errors'][] = 'ban_no_triggers'; |
|
1378 | + } |
|
1349 | 1379 | |
1350 | - if (!empty($context['ban_errors'])) |
|
1351 | - return; |
|
1380 | + if (!empty($context['ban_errors'])) { |
|
1381 | + return; |
|
1382 | + } |
|
1352 | 1383 | |
1353 | 1384 | // Preset all values that are required. |
1354 | 1385 | $values = array( |
@@ -1389,8 +1420,9 @@ discard block |
||
1389 | 1420 | */ |
1390 | 1421 | function logTriggersUpdates($logs, $new = true, $removal = false) |
1391 | 1422 | { |
1392 | - if (empty($logs)) |
|
1393 | - return; |
|
1423 | + if (empty($logs)) { |
|
1424 | + return; |
|
1425 | + } |
|
1394 | 1426 | |
1395 | 1427 | $log_name_map = array( |
1396 | 1428 | 'main_ip' => 'ip_range', |
@@ -1401,14 +1433,15 @@ discard block |
||
1401 | 1433 | ); |
1402 | 1434 | |
1403 | 1435 | // Log the addion of the ban entries into the moderation log. |
1404 | - foreach ($logs as $log) |
|
1405 | - logAction('ban' . ($removal == true ? 'remove' : ''), array( |
|
1436 | + foreach ($logs as $log) { |
|
1437 | + logAction('ban' . ($removal == true ? 'remove' : ''), array( |
|
1406 | 1438 | $log_name_map[$log['bantype']] => $log['value'], |
1407 | 1439 | 'new' => empty($new) ? 0 : 1, |
1408 | 1440 | 'remove' => empty($removal) ? 0 : 1, |
1409 | 1441 | 'type' => $log['bantype'], |
1410 | 1442 | )); |
1411 | -} |
|
1443 | + } |
|
1444 | + } |
|
1412 | 1445 | |
1413 | 1446 | /** |
1414 | 1447 | * Updates an existing ban group |
@@ -1422,12 +1455,15 @@ discard block |
||
1422 | 1455 | { |
1423 | 1456 | global $smcFunc, $context; |
1424 | 1457 | |
1425 | - if (empty($ban_info['name'])) |
|
1426 | - $context['ban_errors'][] = 'ban_name_empty'; |
|
1427 | - if (empty($ban_info['id'])) |
|
1428 | - $context['ban_errors'][] = 'ban_id_empty'; |
|
1429 | - if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login'])) |
|
1430 | - $context['ban_errors'][] = 'ban_unknown_restriction_type'; |
|
1458 | + if (empty($ban_info['name'])) { |
|
1459 | + $context['ban_errors'][] = 'ban_name_empty'; |
|
1460 | + } |
|
1461 | + if (empty($ban_info['id'])) { |
|
1462 | + $context['ban_errors'][] = 'ban_id_empty'; |
|
1463 | + } |
|
1464 | + if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login'])) { |
|
1465 | + $context['ban_errors'][] = 'ban_unknown_restriction_type'; |
|
1466 | + } |
|
1431 | 1467 | |
1432 | 1468 | if (!empty($ban_info['id'])) |
1433 | 1469 | { |
@@ -1442,8 +1478,9 @@ discard block |
||
1442 | 1478 | ) |
1443 | 1479 | ); |
1444 | 1480 | |
1445 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
1446 | - $context['ban_errors'][] = 'ban_not_found'; |
|
1481 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
1482 | + $context['ban_errors'][] = 'ban_not_found'; |
|
1483 | + } |
|
1447 | 1484 | $smcFunc['db_free_result']($request); |
1448 | 1485 | } |
1449 | 1486 | |
@@ -1461,13 +1498,15 @@ discard block |
||
1461 | 1498 | 'new_ban_name' => $ban_info['name'], |
1462 | 1499 | ) |
1463 | 1500 | ); |
1464 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
1465 | - $context['ban_errors'][] = 'ban_name_exists'; |
|
1501 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
1502 | + $context['ban_errors'][] = 'ban_name_exists'; |
|
1503 | + } |
|
1466 | 1504 | $smcFunc['db_free_result']($request); |
1467 | 1505 | } |
1468 | 1506 | |
1469 | - if (!empty($context['ban_errors'])) |
|
1470 | - return $ban_info['id']; |
|
1507 | + if (!empty($context['ban_errors'])) { |
|
1508 | + return $ban_info['id']; |
|
1509 | + } |
|
1471 | 1510 | |
1472 | 1511 | $smcFunc['db_query']('', ' |
1473 | 1512 | UPDATE {db_prefix}ban_groups |
@@ -1511,10 +1550,12 @@ discard block |
||
1511 | 1550 | { |
1512 | 1551 | global $smcFunc, $context; |
1513 | 1552 | |
1514 | - if (empty($ban_info['name'])) |
|
1515 | - $context['ban_errors'][] = 'ban_name_empty'; |
|
1516 | - if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login'])) |
|
1517 | - $context['ban_errors'][] = 'ban_unknown_restriction_type'; |
|
1553 | + if (empty($ban_info['name'])) { |
|
1554 | + $context['ban_errors'][] = 'ban_name_empty'; |
|
1555 | + } |
|
1556 | + if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login'])) { |
|
1557 | + $context['ban_errors'][] = 'ban_unknown_restriction_type'; |
|
1558 | + } |
|
1518 | 1559 | |
1519 | 1560 | if (!empty($ban_info['name'])) |
1520 | 1561 | { |
@@ -1529,13 +1570,15 @@ discard block |
||
1529 | 1570 | ) |
1530 | 1571 | ); |
1531 | 1572 | |
1532 | - if ($smcFunc['db_num_rows']($request) == 1) |
|
1533 | - $context['ban_errors'][] = 'ban_name_exists'; |
|
1573 | + if ($smcFunc['db_num_rows']($request) == 1) { |
|
1574 | + $context['ban_errors'][] = 'ban_name_exists'; |
|
1575 | + } |
|
1534 | 1576 | $smcFunc['db_free_result']($request); |
1535 | 1577 | } |
1536 | 1578 | |
1537 | - if (!empty($context['ban_errors'])) |
|
1538 | - return; |
|
1579 | + if (!empty($context['ban_errors'])) { |
|
1580 | + return; |
|
1581 | + } |
|
1539 | 1582 | |
1540 | 1583 | // Yes yes, we're ready to add now. |
1541 | 1584 | $smcFunc['db_insert']('', |
@@ -1552,8 +1595,9 @@ discard block |
||
1552 | 1595 | ); |
1553 | 1596 | $ban_info['id'] = $smcFunc['db_insert_id']('{db_prefix}ban_groups', 'id_ban_group'); |
1554 | 1597 | |
1555 | - if (empty($ban_info['id'])) |
|
1556 | - $context['ban_errors'][] = 'impossible_insert_new_bangroup'; |
|
1598 | + if (empty($ban_info['id'])) { |
|
1599 | + $context['ban_errors'][] = 'impossible_insert_new_bangroup'; |
|
1600 | + } |
|
1557 | 1601 | |
1558 | 1602 | return $ban_info['id']; |
1559 | 1603 | } |
@@ -1578,24 +1622,24 @@ discard block |
||
1578 | 1622 | $ban_group = isset($_REQUEST['bg']) ? (int) $_REQUEST['bg'] : 0; |
1579 | 1623 | $ban_id = isset($_REQUEST['bi']) ? (int) $_REQUEST['bi'] : 0; |
1580 | 1624 | |
1581 | - if (empty($ban_group)) |
|
1582 | - fatal_lang_error('ban_not_found', false); |
|
1625 | + if (empty($ban_group)) { |
|
1626 | + fatal_lang_error('ban_not_found', false); |
|
1627 | + } |
|
1583 | 1628 | |
1584 | 1629 | if (isset($_POST['add_new_trigger']) && !empty($_POST['ban_suggestions'])) |
1585 | 1630 | { |
1586 | 1631 | saveTriggers($_POST['ban_suggestions'], $ban_group, 0, $ban_id); |
1587 | 1632 | redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : '')); |
1588 | - } |
|
1589 | - elseif (isset($_POST['edit_trigger']) && !empty($_POST['ban_suggestions'])) |
|
1633 | + } elseif (isset($_POST['edit_trigger']) && !empty($_POST['ban_suggestions'])) |
|
1590 | 1634 | { |
1591 | 1635 | // The first replaces the old one, the others are added new (simplification, otherwise it would require another query and some work...) |
1592 | 1636 | saveTriggers(array_shift($_POST['ban_suggestions']), $ban_group, 0, $ban_id); |
1593 | - if (!empty($_POST['ban_suggestions'])) |
|
1594 | - saveTriggers($_POST['ban_suggestions'], $ban_group); |
|
1637 | + if (!empty($_POST['ban_suggestions'])) { |
|
1638 | + saveTriggers($_POST['ban_suggestions'], $ban_group); |
|
1639 | + } |
|
1595 | 1640 | |
1596 | 1641 | redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : '')); |
1597 | - } |
|
1598 | - elseif (isset($_POST['edit_trigger'])) |
|
1642 | + } elseif (isset($_POST['edit_trigger'])) |
|
1599 | 1643 | { |
1600 | 1644 | removeBanTriggers($ban_id); |
1601 | 1645 | redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : '')); |
@@ -1626,8 +1670,7 @@ discard block |
||
1626 | 1670 | ), |
1627 | 1671 | 'is_new' => true, |
1628 | 1672 | ); |
1629 | - } |
|
1630 | - else |
|
1673 | + } else |
|
1631 | 1674 | { |
1632 | 1675 | $request = $smcFunc['db_query']('', ' |
1633 | 1676 | SELECT |
@@ -1644,8 +1687,9 @@ discard block |
||
1644 | 1687 | 'ban_group' => $ban_group, |
1645 | 1688 | ) |
1646 | 1689 | ); |
1647 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
1648 | - fatal_lang_error('ban_not_found', false); |
|
1690 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
1691 | + fatal_lang_error('ban_not_found', false); |
|
1692 | + } |
|
1649 | 1693 | $row = $smcFunc['db_fetch_assoc']($request); |
1650 | 1694 | $smcFunc['db_free_result']($request); |
1651 | 1695 | |
@@ -1694,8 +1738,9 @@ discard block |
||
1694 | 1738 | removeBanTriggers($_POST['remove']); |
1695 | 1739 | |
1696 | 1740 | // Rehabilitate some members. |
1697 | - if ($_REQUEST['entity'] == 'member') |
|
1698 | - updateBanMembers(); |
|
1741 | + if ($_REQUEST['entity'] == 'member') { |
|
1742 | + updateBanMembers(); |
|
1743 | + } |
|
1699 | 1744 | |
1700 | 1745 | // Make sure the ban cache is refreshed. |
1701 | 1746 | updateSettings(array('banLastUpdated' => time())); |
@@ -1808,8 +1853,7 @@ discard block |
||
1808 | 1853 | 'default' => 'bi.ip_low, bi.ip_high, bi.ip_low', |
1809 | 1854 | 'reverse' => 'bi.ip_low DESC, bi.ip_high DESC', |
1810 | 1855 | ); |
1811 | - } |
|
1812 | - elseif ($context['selected_entity'] === 'hostname') |
|
1856 | + } elseif ($context['selected_entity'] === 'hostname') |
|
1813 | 1857 | { |
1814 | 1858 | $listOptions['columns']['banned_entity']['data'] = array( |
1815 | 1859 | 'function' => function($rowData) use ($smcFunc) |
@@ -1821,8 +1865,7 @@ discard block |
||
1821 | 1865 | 'default' => 'bi.hostname', |
1822 | 1866 | 'reverse' => 'bi.hostname DESC', |
1823 | 1867 | ); |
1824 | - } |
|
1825 | - elseif ($context['selected_entity'] === 'email') |
|
1868 | + } elseif ($context['selected_entity'] === 'email') |
|
1826 | 1869 | { |
1827 | 1870 | $listOptions['columns']['banned_entity']['data'] = array( |
1828 | 1871 | 'function' => function($rowData) use ($smcFunc) |
@@ -1834,8 +1877,7 @@ discard block |
||
1834 | 1877 | 'default' => 'bi.email_address', |
1835 | 1878 | 'reverse' => 'bi.email_address DESC', |
1836 | 1879 | ); |
1837 | - } |
|
1838 | - elseif ($context['selected_entity'] === 'member') |
|
1880 | + } elseif ($context['selected_entity'] === 'member') |
|
1839 | 1881 | { |
1840 | 1882 | $listOptions['columns']['banned_entity']['data'] = array( |
1841 | 1883 | 'sprintf' => array( |
@@ -1899,8 +1941,9 @@ discard block |
||
1899 | 1941 | ) |
1900 | 1942 | ); |
1901 | 1943 | $ban_triggers = array(); |
1902 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1903 | - $ban_triggers[] = $row; |
|
1944 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1945 | + $ban_triggers[] = $row; |
|
1946 | + } |
|
1904 | 1947 | $smcFunc['db_free_result']($request); |
1905 | 1948 | |
1906 | 1949 | return $ban_triggers; |
@@ -1956,8 +1999,9 @@ discard block |
||
1956 | 1999 | validateToken('admin-bl'); |
1957 | 2000 | |
1958 | 2001 | // 'Delete all entries' button was pressed. |
1959 | - if (!empty($_POST['removeAll'])) |
|
1960 | - removeBanLogs(); |
|
2002 | + if (!empty($_POST['removeAll'])) { |
|
2003 | + removeBanLogs(); |
|
2004 | + } |
|
1961 | 2005 | // 'Delete selection' button was pressed. |
1962 | 2006 | else |
1963 | 2007 | { |
@@ -2166,12 +2210,15 @@ discard block |
||
2166 | 2210 | $low = inet_dtop($low); |
2167 | 2211 | $high = inet_dtop($high); |
2168 | 2212 | |
2169 | - if ($low == '255.255.255.255') return 'unknown'; |
|
2170 | - if ($low == $high) |
|
2171 | - return $low; |
|
2172 | - else |
|
2173 | - return $low . '-' . $high; |
|
2174 | -} |
|
2213 | + if ($low == '255.255.255.255') { |
|
2214 | + return 'unknown'; |
|
2215 | + } |
|
2216 | + if ($low == $high) { |
|
2217 | + return $low; |
|
2218 | + } else { |
|
2219 | + return $low . '-' . $high; |
|
2220 | + } |
|
2221 | + } |
|
2175 | 2222 | |
2176 | 2223 | /** |
2177 | 2224 | * Checks whether a given IP range already exists in the trigger list. |
@@ -2247,15 +2294,17 @@ discard block |
||
2247 | 2294 | $memberEmailWild = array(); |
2248 | 2295 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
2249 | 2296 | { |
2250 | - if ($row['id_member']) |
|
2251 | - $memberIDs[$row['id_member']] = $row['id_member']; |
|
2297 | + if ($row['id_member']) { |
|
2298 | + $memberIDs[$row['id_member']] = $row['id_member']; |
|
2299 | + } |
|
2252 | 2300 | if ($row['email_address']) |
2253 | 2301 | { |
2254 | 2302 | // Does it have a wildcard - if so we can't do a IN on it. |
2255 | - if (strpos($row['email_address'], '%') !== false) |
|
2256 | - $memberEmailWild[$row['email_address']] = $row['email_address']; |
|
2257 | - else |
|
2258 | - $memberEmails[$row['email_address']] = $row['email_address']; |
|
2303 | + if (strpos($row['email_address'], '%') !== false) { |
|
2304 | + $memberEmailWild[$row['email_address']] = $row['email_address']; |
|
2305 | + } else { |
|
2306 | + $memberEmails[$row['email_address']] = $row['email_address']; |
|
2307 | + } |
|
2259 | 2308 | } |
2260 | 2309 | } |
2261 | 2310 | $smcFunc['db_free_result']($request); |
@@ -2306,14 +2355,15 @@ discard block |
||
2306 | 2355 | } |
2307 | 2356 | |
2308 | 2357 | // We welcome our new members in the realm of the banned. |
2309 | - if (!empty($newMembers)) |
|
2310 | - $smcFunc['db_query']('', ' |
|
2358 | + if (!empty($newMembers)) { |
|
2359 | + $smcFunc['db_query']('', ' |
|
2311 | 2360 | DELETE FROM {db_prefix}log_online |
2312 | 2361 | WHERE id_member IN ({array_int:new_banned_members})', |
2313 | 2362 | array( |
2314 | 2363 | 'new_banned_members' => $newMembers, |
2315 | 2364 | ) |
2316 | 2365 | ); |
2366 | + } |
|
2317 | 2367 | |
2318 | 2368 | // Find members that are wrongfully marked as banned. |
2319 | 2369 | $request = $smcFunc['db_query']('', ' |
@@ -2340,9 +2390,10 @@ discard block |
||
2340 | 2390 | } |
2341 | 2391 | $smcFunc['db_free_result']($request); |
2342 | 2392 | |
2343 | - if (!empty($updates)) |
|
2344 | - foreach ($updates as $newStatus => $members) |
|
2393 | + if (!empty($updates)) { |
|
2394 | + foreach ($updates as $newStatus => $members) |
|
2345 | 2395 | updateMemberData($members, array('is_activated' => $newStatus)); |
2396 | + } |
|
2346 | 2397 | |
2347 | 2398 | // Update the latest member and our total members as banning may change them. |
2348 | 2399 | updateStats('member'); |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 3 |
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 | * The main 'Attachments and Avatars' management function. |
@@ -63,10 +64,11 @@ discard block |
||
63 | 64 | call_integration_hook('integrate_manage_attachments', array(&$subActions)); |
64 | 65 | |
65 | 66 | // Pick the correct sub-action. |
66 | - if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) |
|
67 | - $context['sub_action'] = $_REQUEST['sa']; |
|
68 | - else |
|
69 | - $context['sub_action'] = 'browse'; |
|
67 | + if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) { |
|
68 | + $context['sub_action'] = $_REQUEST['sa']; |
|
69 | + } else { |
|
70 | + $context['sub_action'] = 'browse'; |
|
71 | + } |
|
70 | 72 | |
71 | 73 | // Default page title is good. |
72 | 74 | $context['page_title'] = $txt['attachments_avatars']; |
@@ -94,20 +96,20 @@ discard block |
||
94 | 96 | $context['attachmentUploadDir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
95 | 97 | |
96 | 98 | // If not set, show a default path for the base directory |
97 | - if (!isset($_GET['save']) && empty($modSettings['basedirectory_for_attachments'])) |
|
98 | - if (is_dir($modSettings['attachmentUploadDir'][1])) |
|
99 | + if (!isset($_GET['save']) && empty($modSettings['basedirectory_for_attachments'])) { |
|
100 | + if (is_dir($modSettings['attachmentUploadDir'][1])) |
|
99 | 101 | $modSettings['basedirectory_for_attachments'] = $modSettings['attachmentUploadDir'][1]; |
100 | - |
|
101 | - else |
|
102 | - $modSettings['basedirectory_for_attachments'] = $context['attachmentUploadDir']; |
|
102 | + } else { |
|
103 | + $modSettings['basedirectory_for_attachments'] = $context['attachmentUploadDir']; |
|
104 | + } |
|
103 | 105 | |
104 | 106 | $context['valid_upload_dir'] = is_dir($context['attachmentUploadDir']) && is_writable($context['attachmentUploadDir']); |
105 | 107 | |
106 | - if (!empty($modSettings['automanage_attachments'])) |
|
107 | - $context['valid_basedirectory'] = !empty($modSettings['basedirectory_for_attachments']) && is_writable($modSettings['basedirectory_for_attachments']); |
|
108 | - |
|
109 | - else |
|
110 | - $context['valid_basedirectory'] = true; |
|
108 | + if (!empty($modSettings['automanage_attachments'])) { |
|
109 | + $context['valid_basedirectory'] = !empty($modSettings['basedirectory_for_attachments']) && is_writable($modSettings['basedirectory_for_attachments']); |
|
110 | + } else { |
|
111 | + $context['valid_basedirectory'] = true; |
|
112 | + } |
|
111 | 113 | |
112 | 114 | // A bit of razzle dazzle with the $txt strings. :) |
113 | 115 | $txt['attachment_path'] = $context['attachmentUploadDir']; |
@@ -185,8 +187,9 @@ discard block |
||
185 | 187 | |
186 | 188 | call_integration_hook('integrate_modify_attachment_settings', array(&$config_vars)); |
187 | 189 | |
188 | - if ($return_config) |
|
189 | - return $config_vars; |
|
190 | + if ($return_config) { |
|
191 | + return $config_vars; |
|
192 | + } |
|
190 | 193 | |
191 | 194 | // These are very likely to come in handy! (i.e. without them we're doomed!) |
192 | 195 | require_once($sourcedir . '/ManagePermissions.php'); |
@@ -197,21 +200,24 @@ discard block |
||
197 | 200 | { |
198 | 201 | checkSession(); |
199 | 202 | |
200 | - if (isset($_POST['attachmentUploadDir'])) |
|
201 | - unset($_POST['attachmentUploadDir']); |
|
203 | + if (isset($_POST['attachmentUploadDir'])) { |
|
204 | + unset($_POST['attachmentUploadDir']); |
|
205 | + } |
|
202 | 206 | |
203 | 207 | if (!empty($_POST['use_subdirectories_for_attachments'])) |
204 | 208 | { |
205 | - if (isset($_POST['use_subdirectories_for_attachments']) && empty($_POST['basedirectory_for_attachments'])) |
|
206 | - $_POST['basedirectory_for_attachments'] = (!empty($modSettings['basedirectory_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir); |
|
209 | + if (isset($_POST['use_subdirectories_for_attachments']) && empty($_POST['basedirectory_for_attachments'])) { |
|
210 | + $_POST['basedirectory_for_attachments'] = (!empty($modSettings['basedirectory_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir); |
|
211 | + } |
|
207 | 212 | |
208 | 213 | if (!empty($_POST['use_subdirectories_for_attachments']) && !empty($modSettings['attachment_basedirectories'])) |
209 | 214 | { |
210 | - if (!is_array($modSettings['attachment_basedirectories'])) |
|
211 | - $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
215 | + if (!is_array($modSettings['attachment_basedirectories'])) { |
|
216 | + $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
217 | + } |
|
218 | + } else { |
|
219 | + $modSettings['attachment_basedirectories'] = array(); |
|
212 | 220 | } |
213 | - else |
|
214 | - $modSettings['attachment_basedirectories'] = array(); |
|
215 | 221 | |
216 | 222 | if (!empty($_POST['use_subdirectories_for_attachments']) && !empty($_POST['basedirectory_for_attachments']) && !in_array($_POST['basedirectory_for_attachments'], $modSettings['attachment_basedirectories'])) |
217 | 223 | { |
@@ -219,8 +225,9 @@ discard block |
||
219 | 225 | |
220 | 226 | if (!in_array($_POST['basedirectory_for_attachments'], $modSettings['attachmentUploadDir'])) |
221 | 227 | { |
222 | - if (!automanage_attachments_create_directory($_POST['basedirectory_for_attachments'])) |
|
223 | - $_POST['basedirectory_for_attachments'] = $modSettings['basedirectory_for_attachments']; |
|
228 | + if (!automanage_attachments_create_directory($_POST['basedirectory_for_attachments'])) { |
|
229 | + $_POST['basedirectory_for_attachments'] = $modSettings['basedirectory_for_attachments']; |
|
230 | + } |
|
224 | 231 | } |
225 | 232 | |
226 | 233 | if (!in_array($_POST['basedirectory_for_attachments'], $modSettings['attachment_basedirectories'])) |
@@ -336,8 +343,9 @@ discard block |
||
336 | 343 | |
337 | 344 | call_integration_hook('integrate_modify_avatar_settings', array(&$config_vars)); |
338 | 345 | |
339 | - if ($return_config) |
|
340 | - return $config_vars; |
|
346 | + if ($return_config) { |
|
347 | + return $config_vars; |
|
348 | + } |
|
341 | 349 | |
342 | 350 | // We need this file for the settings template. |
343 | 351 | require_once($sourcedir . '/ManageServer.php'); |
@@ -348,17 +356,21 @@ discard block |
||
348 | 356 | checkSession(); |
349 | 357 | |
350 | 358 | // These settings cannot be left empty! |
351 | - if (empty($_POST['custom_avatar_dir'])) |
|
352 | - $_POST['custom_avatar_dir'] = $boarddir . '/custom_avatar'; |
|
359 | + if (empty($_POST['custom_avatar_dir'])) { |
|
360 | + $_POST['custom_avatar_dir'] = $boarddir . '/custom_avatar'; |
|
361 | + } |
|
353 | 362 | |
354 | - if (empty($_POST['custom_avatar_url'])) |
|
355 | - $_POST['custom_avatar_url'] = $boardurl . '/custom_avatar'; |
|
363 | + if (empty($_POST['custom_avatar_url'])) { |
|
364 | + $_POST['custom_avatar_url'] = $boardurl . '/custom_avatar'; |
|
365 | + } |
|
356 | 366 | |
357 | - if (empty($_POST['avatar_directory'])) |
|
358 | - $_POST['avatar_directory'] = $boarddir . '/avatars'; |
|
367 | + if (empty($_POST['avatar_directory'])) { |
|
368 | + $_POST['avatar_directory'] = $boarddir . '/avatars'; |
|
369 | + } |
|
359 | 370 | |
360 | - if (empty($_POST['avatar_url'])) |
|
361 | - $_POST['avatar_url'] = $boardurl . '/avatars'; |
|
371 | + if (empty($_POST['avatar_url'])) { |
|
372 | + $_POST['avatar_url'] = $boardurl . '/avatars'; |
|
373 | + } |
|
362 | 374 | |
363 | 375 | call_integration_hook('integrate_save_avatar_settings'); |
364 | 376 | |
@@ -406,11 +418,13 @@ discard block |
||
406 | 418 | $list_title = $txt['attachment_manager_browse_files'] . ': '; |
407 | 419 | foreach ($titles as $browse_type => $details) |
408 | 420 | { |
409 | - if ($browse_type != 'attachments') |
|
410 | - $list_title .= ' | '; |
|
421 | + if ($browse_type != 'attachments') { |
|
422 | + $list_title .= ' | '; |
|
423 | + } |
|
411 | 424 | |
412 | - if ($context['browse_type'] == $browse_type) |
|
413 | - $list_title .= '<img src="' . $settings['images_url'] . '/selected.png" alt=">"> '; |
|
425 | + if ($context['browse_type'] == $browse_type) { |
|
426 | + $list_title .= '<img src="' . $settings['images_url'] . '/selected.png" alt=">"> '; |
|
427 | + } |
|
414 | 428 | |
415 | 429 | $list_title .= '<a href="' . $scripturl . $details[0] . '">' . $details[1] . '</a>'; |
416 | 430 | } |
@@ -446,28 +460,33 @@ discard block |
||
446 | 460 | $link = '<a href="'; |
447 | 461 | |
448 | 462 | // In case of a custom avatar URL attachments have a fixed directory. |
449 | - if ($rowData['attachment_type'] == 1) |
|
450 | - $link .= sprintf('%1$s/%2$s', $modSettings['custom_avatar_url'], $rowData['filename']); |
|
463 | + if ($rowData['attachment_type'] == 1) { |
|
464 | + $link .= sprintf('%1$s/%2$s', $modSettings['custom_avatar_url'], $rowData['filename']); |
|
465 | + } |
|
451 | 466 | |
452 | 467 | // By default avatars are downloaded almost as attachments. |
453 | - elseif ($context['browse_type'] == 'avatars') |
|
454 | - $link .= sprintf('%1$s?action=dlattach;type=avatar;attach=%2$d', $scripturl, $rowData['id_attach']); |
|
468 | + elseif ($context['browse_type'] == 'avatars') { |
|
469 | + $link .= sprintf('%1$s?action=dlattach;type=avatar;attach=%2$d', $scripturl, $rowData['id_attach']); |
|
470 | + } |
|
455 | 471 | |
456 | 472 | // Normal attachments are always linked to a topic ID. |
457 | - else |
|
458 | - $link .= sprintf('%1$s?action=dlattach;topic=%2$d.0;attach=%3$d', $scripturl, $rowData['id_topic'], $rowData['id_attach']); |
|
473 | + else { |
|
474 | + $link .= sprintf('%1$s?action=dlattach;topic=%2$d.0;attach=%3$d', $scripturl, $rowData['id_topic'], $rowData['id_attach']); |
|
475 | + } |
|
459 | 476 | |
460 | 477 | $link .= '"'; |
461 | 478 | |
462 | 479 | // Show a popup on click if it's a picture and we know its dimensions. |
463 | - if (!empty($rowData['width']) && !empty($rowData['height'])) |
|
464 | - $link .= sprintf(' onclick="return reqWin(this.href' . ($rowData['attachment_type'] == 1 ? '' : ' + \';image\'') . ', %1$d, %2$d, true);"', $rowData['width'] + 20, $rowData['height'] + 20); |
|
480 | + if (!empty($rowData['width']) && !empty($rowData['height'])) { |
|
481 | + $link .= sprintf(' onclick="return reqWin(this.href' . ($rowData['attachment_type'] == 1 ? '' : ' + \';image\'') . ', %1$d, %2$d, true);"', $rowData['width'] + 20, $rowData['height'] + 20); |
|
482 | + } |
|
465 | 483 | |
466 | 484 | $link .= sprintf('>%1$s</a>', preg_replace('~&#(\\\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\\\1;', $smcFunc['htmlspecialchars']($rowData['filename']))); |
467 | 485 | |
468 | 486 | // Show the dimensions. |
469 | - if (!empty($rowData['width']) && !empty($rowData['height'])) |
|
470 | - $link .= sprintf(' <span class="smalltext">%1$dx%2$d</span>', $rowData['width'], $rowData['height']); |
|
487 | + if (!empty($rowData['width']) && !empty($rowData['height'])) { |
|
488 | + $link .= sprintf(' <span class="smalltext">%1$dx%2$d</span>', $rowData['width'], $rowData['height']); |
|
489 | + } |
|
471 | 490 | |
472 | 491 | return $link; |
473 | 492 | }, |
@@ -500,12 +519,14 @@ discard block |
||
500 | 519 | 'function' => function($rowData) use ($scripturl, $smcFunc) |
501 | 520 | { |
502 | 521 | // In case of an attachment, return the poster of the attachment. |
503 | - if (empty($rowData['id_member'])) |
|
504 | - return $smcFunc['htmlspecialchars']($rowData['poster_name']); |
|
522 | + if (empty($rowData['id_member'])) { |
|
523 | + return $smcFunc['htmlspecialchars']($rowData['poster_name']); |
|
524 | + } |
|
505 | 525 | |
506 | 526 | // Otherwise it must be an avatar, return the link to the owner of it. |
507 | - else |
|
508 | - return sprintf('<a href="%1$s?action=profile;u=%2$d">%3$s</a>', $scripturl, $rowData['id_member'], $rowData['poster_name']); |
|
527 | + else { |
|
528 | + return sprintf('<a href="%1$s?action=profile;u=%2$d">%3$s</a>', $scripturl, $rowData['id_member'], $rowData['poster_name']); |
|
529 | + } |
|
509 | 530 | }, |
510 | 531 | ), |
511 | 532 | 'sort' => array( |
@@ -524,8 +545,9 @@ discard block |
||
524 | 545 | $date = empty($rowData['poster_time']) ? $txt['never'] : timeformat($rowData['poster_time']); |
525 | 546 | |
526 | 547 | // Add a link to the topic in case of an attachment. |
527 | - if ($context['browse_type'] !== 'avatars') |
|
528 | - $date .= sprintf('<br>%1$s <a href="%2$s?topic=%3$d.msg%4$d#msg%4$d">%5$s</a>', $txt['in'], $scripturl, $rowData['id_topic'], $rowData['id_msg'], $rowData['subject']); |
|
548 | + if ($context['browse_type'] !== 'avatars') { |
|
549 | + $date .= sprintf('<br>%1$s <a href="%2$s?topic=%3$d.msg%4$d#msg%4$d">%5$s</a>', $txt['in'], $scripturl, $rowData['id_topic'], $rowData['id_msg'], $rowData['subject']); |
|
550 | + } |
|
529 | 551 | |
530 | 552 | return $date; |
531 | 553 | }, |
@@ -610,8 +632,8 @@ discard block |
||
610 | 632 | global $smcFunc, $txt; |
611 | 633 | |
612 | 634 | // Choose a query depending on what we are viewing. |
613 | - if ($browse_type === 'avatars') |
|
614 | - $request = $smcFunc['db_query']('', ' |
|
635 | + if ($browse_type === 'avatars') { |
|
636 | + $request = $smcFunc['db_query']('', ' |
|
615 | 637 | SELECT |
616 | 638 | {string:blank_text} AS id_msg, COALESCE(mem.real_name, {string:not_applicable_text}) AS poster_name, |
617 | 639 | mem.last_login AS poster_time, 0 AS id_topic, a.id_member, a.id_attach, a.filename, a.file_hash, a.attachment_type, |
@@ -630,8 +652,8 @@ discard block |
||
630 | 652 | 'per_page' => $items_per_page, |
631 | 653 | ) |
632 | 654 | ); |
633 | - else |
|
634 | - $request = $smcFunc['db_query']('', ' |
|
655 | + } else { |
|
656 | + $request = $smcFunc['db_query']('', ' |
|
635 | 657 | SELECT |
636 | 658 | m.id_msg, COALESCE(mem.real_name, m.poster_name) AS poster_name, m.poster_time, m.id_topic, m.id_member, |
637 | 659 | a.id_attach, a.filename, a.file_hash, a.attachment_type, a.size, a.width, a.height, a.downloads, mf.subject, t.id_board |
@@ -650,9 +672,11 @@ discard block |
||
650 | 672 | 'per_page' => $items_per_page, |
651 | 673 | ) |
652 | 674 | ); |
675 | + } |
|
653 | 676 | $files = array(); |
654 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
655 | - $files[] = $row; |
|
677 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
678 | + $files[] = $row; |
|
679 | + } |
|
656 | 680 | $smcFunc['db_free_result']($request); |
657 | 681 | |
658 | 682 | return $files; |
@@ -670,8 +694,8 @@ discard block |
||
670 | 694 | global $smcFunc; |
671 | 695 | |
672 | 696 | // Depending on the type of file, different queries are used. |
673 | - if ($browse_type === 'avatars') |
|
674 | - $request = $smcFunc['db_query']('', ' |
|
697 | + if ($browse_type === 'avatars') { |
|
698 | + $request = $smcFunc['db_query']('', ' |
|
675 | 699 | SELECT COUNT(*) |
676 | 700 | FROM {db_prefix}attachments |
677 | 701 | WHERE id_member != {int:guest_id_member}', |
@@ -679,8 +703,8 @@ discard block |
||
679 | 703 | 'guest_id_member' => 0, |
680 | 704 | ) |
681 | 705 | ); |
682 | - else |
|
683 | - $request = $smcFunc['db_query']('', ' |
|
706 | + } else { |
|
707 | + $request = $smcFunc['db_query']('', ' |
|
684 | 708 | SELECT COUNT(*) AS num_attach |
685 | 709 | FROM {db_prefix}attachments AS a |
686 | 710 | INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg) |
@@ -693,6 +717,7 @@ discard block |
||
693 | 717 | 'guest_id_member' => 0, |
694 | 718 | ) |
695 | 719 | ); |
720 | + } |
|
696 | 721 | |
697 | 722 | list ($num_files) = $smcFunc['db_fetch_row']($request); |
698 | 723 | $smcFunc['db_free_result']($request); |
@@ -775,12 +800,14 @@ discard block |
||
775 | 800 | $current_dir_size /= 1024; |
776 | 801 | |
777 | 802 | // If they specified a limit only.... |
778 | - if (!empty($modSettings['attachmentDirSizeLimit'])) |
|
779 | - $context['attachment_space'] = comma_format(max($modSettings['attachmentDirSizeLimit'] - $current_dir_size, 0), 2); |
|
803 | + if (!empty($modSettings['attachmentDirSizeLimit'])) { |
|
804 | + $context['attachment_space'] = comma_format(max($modSettings['attachmentDirSizeLimit'] - $current_dir_size, 0), 2); |
|
805 | + } |
|
780 | 806 | $context['attachment_current_size'] = comma_format($current_dir_size, 2); |
781 | 807 | |
782 | - if (!empty($modSettings['attachmentDirFileLimit'])) |
|
783 | - $context['attachment_files'] = comma_format(max($modSettings['attachmentDirFileLimit'] - $current_dir_files, 0), 0); |
|
808 | + if (!empty($modSettings['attachmentDirFileLimit'])) { |
|
809 | + $context['attachment_files'] = comma_format(max($modSettings['attachmentDirFileLimit'] - $current_dir_files, 0), 0); |
|
810 | + } |
|
784 | 811 | $context['attachment_current_files'] = comma_format($current_dir_files, 0); |
785 | 812 | |
786 | 813 | $context['attach_multiple_dirs'] = count($attach_dirs) > 1 ? true : false; |
@@ -817,8 +844,8 @@ discard block |
||
817 | 844 | $messages = removeAttachments(array('attachment_type' => 0, 'poster_time' => (time() - 24 * 60 * 60 * $_POST['age'])), 'messages', true); |
818 | 845 | |
819 | 846 | // Update the messages to reflect the change. |
820 | - if (!empty($messages) && !empty($_POST['notice'])) |
|
821 | - $smcFunc['db_query']('', ' |
|
847 | + if (!empty($messages) && !empty($_POST['notice'])) { |
|
848 | + $smcFunc['db_query']('', ' |
|
822 | 849 | UPDATE {db_prefix}messages |
823 | 850 | SET body = CONCAT(body, {string:notice}) |
824 | 851 | WHERE id_msg IN ({array_int:messages})', |
@@ -827,8 +854,8 @@ discard block |
||
827 | 854 | 'notice' => '<br><br>' . $_POST['notice'], |
828 | 855 | ) |
829 | 856 | ); |
830 | - } |
|
831 | - else |
|
857 | + } |
|
858 | + } else |
|
832 | 859 | { |
833 | 860 | // Remove all the old avatars. |
834 | 861 | removeAttachments(array('not_id_member' => 0, 'last_login' => (time() - 24 * 60 * 60 * $_POST['age'])), 'members'); |
@@ -853,8 +880,8 @@ discard block |
||
853 | 880 | $messages = removeAttachments(array('attachment_type' => 0, 'size' => 1024 * $_POST['size']), 'messages', true); |
854 | 881 | |
855 | 882 | // And make a note on the post. |
856 | - if (!empty($messages) && !empty($_POST['notice'])) |
|
857 | - $smcFunc['db_query']('', ' |
|
883 | + if (!empty($messages) && !empty($_POST['notice'])) { |
|
884 | + $smcFunc['db_query']('', ' |
|
858 | 885 | UPDATE {db_prefix}messages |
859 | 886 | SET body = CONCAT(body, {string:notice}) |
860 | 887 | WHERE id_msg IN ({array_int:messages})', |
@@ -863,6 +890,7 @@ discard block |
||
863 | 890 | 'notice' => '<br><br>' . $_POST['notice'], |
864 | 891 | ) |
865 | 892 | ); |
893 | + } |
|
866 | 894 | |
867 | 895 | redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
868 | 896 | } |
@@ -882,16 +910,17 @@ discard block |
||
882 | 910 | { |
883 | 911 | $attachments = array(); |
884 | 912 | // There must be a quicker way to pass this safety test?? |
885 | - foreach ($_POST['remove'] as $removeID => $dummy) |
|
886 | - $attachments[] = (int) $removeID; |
|
913 | + foreach ($_POST['remove'] as $removeID => $dummy) { |
|
914 | + $attachments[] = (int) $removeID; |
|
915 | + } |
|
887 | 916 | |
888 | 917 | // If the attachments are from a 3rd party, let them remove it. Hooks should remove their ids from the array. |
889 | 918 | $filesRemoved = false; |
890 | 919 | call_integration_hook('integrate_attachment_remove', array(&$filesRemoved, $attachments)); |
891 | 920 | |
892 | - if ($_REQUEST['type'] == 'avatars' && !empty($attachments)) |
|
893 | - removeAttachments(array('id_attach' => $attachments)); |
|
894 | - else if (!empty($attachments)) |
|
921 | + if ($_REQUEST['type'] == 'avatars' && !empty($attachments)) { |
|
922 | + removeAttachments(array('id_attach' => $attachments)); |
|
923 | + } else if (!empty($attachments)) |
|
895 | 924 | { |
896 | 925 | $messages = removeAttachments(array('id_attach' => $attachments), 'messages', true); |
897 | 926 | |
@@ -930,12 +959,13 @@ discard block |
||
930 | 959 | |
931 | 960 | $messages = removeAttachments(array('attachment_type' => 0), '', true); |
932 | 961 | |
933 | - if (!isset($_POST['notice'])) |
|
934 | - $_POST['notice'] = $txt['attachment_delete_admin']; |
|
962 | + if (!isset($_POST['notice'])) { |
|
963 | + $_POST['notice'] = $txt['attachment_delete_admin']; |
|
964 | + } |
|
935 | 965 | |
936 | 966 | // Add the notice on the end of the changed messages. |
937 | - if (!empty($messages)) |
|
938 | - $smcFunc['db_query']('', ' |
|
967 | + if (!empty($messages)) { |
|
968 | + $smcFunc['db_query']('', ' |
|
939 | 969 | UPDATE {db_prefix}messages |
940 | 970 | SET body = CONCAT(body, {string:deleted_message}) |
941 | 971 | WHERE id_msg IN ({array_int:messages})', |
@@ -944,6 +974,7 @@ discard block |
||
944 | 974 | 'deleted_message' => '<br><br>' . $_POST['notice'], |
945 | 975 | ) |
946 | 976 | ); |
977 | + } |
|
947 | 978 | |
948 | 979 | redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
949 | 980 | } |
@@ -982,24 +1013,26 @@ discard block |
||
982 | 1013 | $is_not = substr($real_type, 0, 4) == 'not_'; |
983 | 1014 | $type = $is_not ? substr($real_type, 4) : $real_type; |
984 | 1015 | |
985 | - if (in_array($type, array('id_member', 'id_attach', 'id_msg'))) |
|
986 | - $new_condition[] = 'a.' . $type . ($is_not ? ' NOT' : '') . ' IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')'; |
|
987 | - elseif ($type == 'attachment_type') |
|
988 | - $new_condition[] = 'a.attachment_type = {int:' . $real_type . '}'; |
|
989 | - elseif ($type == 'poster_time') |
|
990 | - $new_condition[] = 'm.poster_time < {int:' . $real_type . '}'; |
|
991 | - elseif ($type == 'last_login') |
|
992 | - $new_condition[] = 'mem.last_login < {int:' . $real_type . '}'; |
|
993 | - elseif ($type == 'size') |
|
994 | - $new_condition[] = 'a.size > {int:' . $real_type . '}'; |
|
995 | - elseif ($type == 'id_topic') |
|
996 | - $new_condition[] = 'm.id_topic IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')'; |
|
1016 | + if (in_array($type, array('id_member', 'id_attach', 'id_msg'))) { |
|
1017 | + $new_condition[] = 'a.' . $type . ($is_not ? ' NOT' : '') . ' IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')'; |
|
1018 | + } elseif ($type == 'attachment_type') { |
|
1019 | + $new_condition[] = 'a.attachment_type = {int:' . $real_type . '}'; |
|
1020 | + } elseif ($type == 'poster_time') { |
|
1021 | + $new_condition[] = 'm.poster_time < {int:' . $real_type . '}'; |
|
1022 | + } elseif ($type == 'last_login') { |
|
1023 | + $new_condition[] = 'mem.last_login < {int:' . $real_type . '}'; |
|
1024 | + } elseif ($type == 'size') { |
|
1025 | + $new_condition[] = 'a.size > {int:' . $real_type . '}'; |
|
1026 | + } elseif ($type == 'id_topic') { |
|
1027 | + $new_condition[] = 'm.id_topic IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')'; |
|
1028 | + } |
|
997 | 1029 | |
998 | 1030 | // Add the parameter! |
999 | 1031 | $query_parameter[$real_type] = $restriction; |
1000 | 1032 | |
1001 | - if ($type == 'do_logging') |
|
1002 | - $do_logging = $condition['id_attach']; |
|
1033 | + if ($type == 'do_logging') { |
|
1034 | + $do_logging = $condition['id_attach']; |
|
1035 | + } |
|
1003 | 1036 | } |
1004 | 1037 | $condition = implode(' AND ', $new_condition); |
1005 | 1038 | } |
@@ -1031,15 +1064,15 @@ discard block |
||
1031 | 1064 | // wasn't it obvious? :P |
1032 | 1065 | // @todo look again at this. |
1033 | 1066 | @unlink($modSettings['custom_avatar_dir'] . '/' . $row['filename']); |
1034 | - } |
|
1035 | - else |
|
1067 | + } else |
|
1036 | 1068 | { |
1037 | 1069 | $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
1038 | 1070 | @unlink($filename); |
1039 | 1071 | |
1040 | 1072 | // If this was a thumb, the parent attachment should know about it. |
1041 | - if (!empty($row['id_parent'])) |
|
1042 | - $parents[] = $row['id_parent']; |
|
1073 | + if (!empty($row['id_parent'])) { |
|
1074 | + $parents[] = $row['id_parent']; |
|
1075 | + } |
|
1043 | 1076 | |
1044 | 1077 | // If this attachments has a thumb, remove it as well. |
1045 | 1078 | if (!empty($row['id_thumb']) && $autoThumbRemoval) |
@@ -1051,8 +1084,9 @@ discard block |
||
1051 | 1084 | } |
1052 | 1085 | |
1053 | 1086 | // Make a list. |
1054 | - if ($return_affected_messages && empty($row['attachment_type'])) |
|
1055 | - $msgs[] = $row['id_msg']; |
|
1087 | + if ($return_affected_messages && empty($row['attachment_type'])) { |
|
1088 | + $msgs[] = $row['id_msg']; |
|
1089 | + } |
|
1056 | 1090 | |
1057 | 1091 | $attach[] = $row['id_attach']; |
1058 | 1092 | } |
@@ -1060,8 +1094,8 @@ discard block |
||
1060 | 1094 | |
1061 | 1095 | // Removed attachments don't have to be updated anymore. |
1062 | 1096 | $parents = array_diff($parents, $attach); |
1063 | - if (!empty($parents)) |
|
1064 | - $smcFunc['db_query']('', ' |
|
1097 | + if (!empty($parents)) { |
|
1098 | + $smcFunc['db_query']('', ' |
|
1065 | 1099 | UPDATE {db_prefix}attachments |
1066 | 1100 | SET id_thumb = {int:no_thumb} |
1067 | 1101 | WHERE id_attach IN ({array_int:parent_attachments})', |
@@ -1070,6 +1104,7 @@ discard block |
||
1070 | 1104 | 'no_thumb' => 0, |
1071 | 1105 | ) |
1072 | 1106 | ); |
1107 | + } |
|
1073 | 1108 | |
1074 | 1109 | if (!empty($do_logging)) |
1075 | 1110 | { |
@@ -1086,31 +1121,34 @@ discard block |
||
1086 | 1121 | ) |
1087 | 1122 | ); |
1088 | 1123 | |
1089 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1090 | - logAction( |
|
1124 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1125 | + logAction( |
|
1091 | 1126 | 'remove_attach', |
1092 | 1127 | array( |
1093 | 1128 | 'message' => $row['id_msg'], |
1094 | 1129 | 'filename' => preg_replace('~&#(\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\1;', $smcFunc['htmlspecialchars']($row['filename'])), |
1095 | 1130 | ) |
1096 | 1131 | ); |
1132 | + } |
|
1097 | 1133 | $smcFunc['db_free_result']($request); |
1098 | 1134 | } |
1099 | 1135 | |
1100 | - if (!empty($attach)) |
|
1101 | - $smcFunc['db_query']('', ' |
|
1136 | + if (!empty($attach)) { |
|
1137 | + $smcFunc['db_query']('', ' |
|
1102 | 1138 | DELETE FROM {db_prefix}attachments |
1103 | 1139 | WHERE id_attach IN ({array_int:attachment_list})', |
1104 | 1140 | array( |
1105 | 1141 | 'attachment_list' => $attach, |
1106 | 1142 | ) |
1107 | 1143 | ); |
1144 | + } |
|
1108 | 1145 | |
1109 | 1146 | call_integration_hook('integrate_remove_attachments', array($attach)); |
1110 | 1147 | |
1111 | - if ($return_affected_messages) |
|
1112 | - return array_unique($msgs); |
|
1113 | -} |
|
1148 | + if ($return_affected_messages) { |
|
1149 | + return array_unique($msgs); |
|
1150 | + } |
|
1151 | + } |
|
1114 | 1152 | |
1115 | 1153 | /** |
1116 | 1154 | * This function should find attachments in the database that no longer exist and clear them, and fix filesize issues. |
@@ -1122,8 +1160,9 @@ discard block |
||
1122 | 1160 | checkSession('get'); |
1123 | 1161 | |
1124 | 1162 | // If we choose cancel, redirect right back. |
1125 | - if (isset($_POST['cancel'])) |
|
1126 | - redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
|
1163 | + if (isset($_POST['cancel'])) { |
|
1164 | + redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
|
1165 | + } |
|
1127 | 1166 | |
1128 | 1167 | // Try give us a while to sort this out... |
1129 | 1168 | @set_time_limit(600); |
@@ -1140,13 +1179,15 @@ discard block |
||
1140 | 1179 | if (isset($_GET['fixErrors'])) |
1141 | 1180 | { |
1142 | 1181 | // Nothing? |
1143 | - if (empty($_POST['to_fix'])) |
|
1144 | - redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
|
1182 | + if (empty($_POST['to_fix'])) { |
|
1183 | + redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
|
1184 | + } |
|
1145 | 1185 | |
1146 | 1186 | $_SESSION['attachments_to_fix'] = array(); |
1147 | 1187 | // @todo No need to do this I think. |
1148 | - foreach ($_POST['to_fix'] as $value) |
|
1149 | - $_SESSION['attachments_to_fix'][] = $value; |
|
1188 | + foreach ($_POST['to_fix'] as $value) { |
|
1189 | + $_SESSION['attachments_to_fix'][] = $value; |
|
1190 | + } |
|
1150 | 1191 | } |
1151 | 1192 | } |
1152 | 1193 | |
@@ -1213,13 +1254,14 @@ discard block |
||
1213 | 1254 | } |
1214 | 1255 | } |
1215 | 1256 | } |
1216 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
1217 | - $to_fix[] = 'missing_thumbnail_parent'; |
|
1257 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
1258 | + $to_fix[] = 'missing_thumbnail_parent'; |
|
1259 | + } |
|
1218 | 1260 | $smcFunc['db_free_result']($result); |
1219 | 1261 | |
1220 | 1262 | // Do we need to delete what we have? |
1221 | - if ($fix_errors && !empty($to_remove) && in_array('missing_thumbnail_parent', $to_fix)) |
|
1222 | - $smcFunc['db_query']('', ' |
|
1263 | + if ($fix_errors && !empty($to_remove) && in_array('missing_thumbnail_parent', $to_fix)) { |
|
1264 | + $smcFunc['db_query']('', ' |
|
1223 | 1265 | DELETE FROM {db_prefix}attachments |
1224 | 1266 | WHERE id_attach IN ({array_int:to_remove}) |
1225 | 1267 | AND attachment_type = {int:attachment_type}', |
@@ -1228,6 +1270,7 @@ discard block |
||
1228 | 1270 | 'attachment_type' => 3, |
1229 | 1271 | ) |
1230 | 1272 | ); |
1273 | + } |
|
1231 | 1274 | |
1232 | 1275 | pauseAttachmentMaintenance($to_fix, $thumbnails); |
1233 | 1276 | } |
@@ -1272,13 +1315,14 @@ discard block |
||
1272 | 1315 | $to_update[] = $row['id_attach']; |
1273 | 1316 | $context['repair_errors']['parent_missing_thumbnail']++; |
1274 | 1317 | } |
1275 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
1276 | - $to_fix[] = 'parent_missing_thumbnail'; |
|
1318 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
1319 | + $to_fix[] = 'parent_missing_thumbnail'; |
|
1320 | + } |
|
1277 | 1321 | $smcFunc['db_free_result']($result); |
1278 | 1322 | |
1279 | 1323 | // Do we need to delete what we have? |
1280 | - if ($fix_errors && !empty($to_update) && in_array('parent_missing_thumbnail', $to_fix)) |
|
1281 | - $smcFunc['db_query']('', ' |
|
1324 | + if ($fix_errors && !empty($to_update) && in_array('parent_missing_thumbnail', $to_fix)) { |
|
1325 | + $smcFunc['db_query']('', ' |
|
1282 | 1326 | UPDATE {db_prefix}attachments |
1283 | 1327 | SET id_thumb = {int:no_thumb} |
1284 | 1328 | WHERE id_attach IN ({array_int:to_update})', |
@@ -1287,6 +1331,7 @@ discard block |
||
1287 | 1331 | 'no_thumb' => 0, |
1288 | 1332 | ) |
1289 | 1333 | ); |
1334 | + } |
|
1290 | 1335 | |
1291 | 1336 | pauseAttachmentMaintenance($to_fix, $thumbnails); |
1292 | 1337 | } |
@@ -1324,10 +1369,11 @@ discard block |
||
1324 | 1369 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
1325 | 1370 | { |
1326 | 1371 | // Get the filename. |
1327 | - if ($row['attachment_type'] == 1) |
|
1328 | - $filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename']; |
|
1329 | - else |
|
1330 | - $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
|
1372 | + if ($row['attachment_type'] == 1) { |
|
1373 | + $filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename']; |
|
1374 | + } else { |
|
1375 | + $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
|
1376 | + } |
|
1331 | 1377 | |
1332 | 1378 | // File doesn't exist? |
1333 | 1379 | if (!file_exists($filename)) |
@@ -1339,15 +1385,16 @@ discard block |
||
1339 | 1385 | $attachment_name = $row['id_attach'] . '_' . $row['file_hash'] . '.dat'; |
1340 | 1386 | |
1341 | 1387 | // Loop through the other folders. |
1342 | - foreach ($modSettings['attachmentUploadDir'] as $id => $dir) |
|
1343 | - if (file_exists($dir . '/' . $attachment_name)) |
|
1388 | + foreach ($modSettings['attachmentUploadDir'] as $id => $dir) { |
|
1389 | + if (file_exists($dir . '/' . $attachment_name)) |
|
1344 | 1390 | { |
1345 | 1391 | $context['repair_errors']['wrong_folder']++; |
1392 | + } |
|
1346 | 1393 | $errors_found[] = 'wrong_folder'; |
1347 | 1394 | |
1348 | 1395 | // Are we going to fix this now? |
1349 | - if ($fix_errors && in_array('wrong_folder', $to_fix)) |
|
1350 | - $smcFunc['db_query']('', ' |
|
1396 | + if ($fix_errors && in_array('wrong_folder', $to_fix)) { |
|
1397 | + $smcFunc['db_query']('', ' |
|
1351 | 1398 | UPDATE {db_prefix}attachments |
1352 | 1399 | SET id_folder = {int:new_folder} |
1353 | 1400 | WHERE id_attach = {int:id_attach}', |
@@ -1356,6 +1403,7 @@ discard block |
||
1356 | 1403 | 'id_attach' => $row['id_attach'], |
1357 | 1404 | ) |
1358 | 1405 | ); |
1406 | + } |
|
1359 | 1407 | |
1360 | 1408 | continue 2; |
1361 | 1409 | } |
@@ -1364,8 +1412,7 @@ discard block |
||
1364 | 1412 | $to_remove[] = $row['id_attach']; |
1365 | 1413 | $context['repair_errors']['file_missing_on_disk']++; |
1366 | 1414 | $errors_found[] = 'file_missing_on_disk'; |
1367 | - } |
|
1368 | - elseif (filesize($filename) == 0) |
|
1415 | + } elseif (filesize($filename) == 0) |
|
1369 | 1416 | { |
1370 | 1417 | $context['repair_errors']['file_size_of_zero']++; |
1371 | 1418 | $errors_found[] = 'file_size_of_zero'; |
@@ -1376,8 +1423,7 @@ discard block |
||
1376 | 1423 | $to_remove[] = $row['id_attach']; |
1377 | 1424 | @unlink($filename); |
1378 | 1425 | } |
1379 | - } |
|
1380 | - elseif (filesize($filename) != $row['size']) |
|
1426 | + } elseif (filesize($filename) != $row['size']) |
|
1381 | 1427 | { |
1382 | 1428 | $context['repair_errors']['file_wrong_size']++; |
1383 | 1429 | $errors_found[] = 'file_wrong_size'; |
@@ -1398,14 +1444,18 @@ discard block |
||
1398 | 1444 | } |
1399 | 1445 | } |
1400 | 1446 | |
1401 | - if (in_array('file_missing_on_disk', $errors_found)) |
|
1402 | - $to_fix[] = 'file_missing_on_disk'; |
|
1403 | - if (in_array('file_size_of_zero', $errors_found)) |
|
1404 | - $to_fix[] = 'file_size_of_zero'; |
|
1405 | - if (in_array('file_wrong_size', $errors_found)) |
|
1406 | - $to_fix[] = 'file_wrong_size'; |
|
1407 | - if (in_array('wrong_folder', $errors_found)) |
|
1408 | - $to_fix[] = 'wrong_folder'; |
|
1447 | + if (in_array('file_missing_on_disk', $errors_found)) { |
|
1448 | + $to_fix[] = 'file_missing_on_disk'; |
|
1449 | + } |
|
1450 | + if (in_array('file_size_of_zero', $errors_found)) { |
|
1451 | + $to_fix[] = 'file_size_of_zero'; |
|
1452 | + } |
|
1453 | + if (in_array('file_wrong_size', $errors_found)) { |
|
1454 | + $to_fix[] = 'file_wrong_size'; |
|
1455 | + } |
|
1456 | + if (in_array('wrong_folder', $errors_found)) { |
|
1457 | + $to_fix[] = 'wrong_folder'; |
|
1458 | + } |
|
1409 | 1459 | $smcFunc['db_free_result']($result); |
1410 | 1460 | |
1411 | 1461 | // Do we need to delete what we have? |
@@ -1475,20 +1525,22 @@ discard block |
||
1475 | 1525 | // If we are repairing remove the file from disk now. |
1476 | 1526 | if ($fix_errors && in_array('avatar_no_member', $to_fix)) |
1477 | 1527 | { |
1478 | - if ($row['attachment_type'] == 1) |
|
1479 | - $filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename']; |
|
1480 | - else |
|
1481 | - $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
|
1528 | + if ($row['attachment_type'] == 1) { |
|
1529 | + $filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename']; |
|
1530 | + } else { |
|
1531 | + $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
|
1532 | + } |
|
1482 | 1533 | @unlink($filename); |
1483 | 1534 | } |
1484 | 1535 | } |
1485 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
1486 | - $to_fix[] = 'avatar_no_member'; |
|
1536 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
1537 | + $to_fix[] = 'avatar_no_member'; |
|
1538 | + } |
|
1487 | 1539 | $smcFunc['db_free_result']($result); |
1488 | 1540 | |
1489 | 1541 | // Do we need to delete what we have? |
1490 | - if ($fix_errors && !empty($to_remove) && in_array('avatar_no_member', $to_fix)) |
|
1491 | - $smcFunc['db_query']('', ' |
|
1542 | + if ($fix_errors && !empty($to_remove) && in_array('avatar_no_member', $to_fix)) { |
|
1543 | + $smcFunc['db_query']('', ' |
|
1492 | 1544 | DELETE FROM {db_prefix}attachments |
1493 | 1545 | WHERE id_attach IN ({array_int:to_remove}) |
1494 | 1546 | AND id_member != {int:no_member} |
@@ -1499,6 +1551,7 @@ discard block |
||
1499 | 1551 | 'no_msg' => 0, |
1500 | 1552 | ) |
1501 | 1553 | ); |
1554 | + } |
|
1502 | 1555 | |
1503 | 1556 | pauseAttachmentMaintenance($to_fix, $thumbnails); |
1504 | 1557 | } |
@@ -1554,13 +1607,14 @@ discard block |
||
1554 | 1607 | @unlink($filename); |
1555 | 1608 | } |
1556 | 1609 | } |
1557 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
1558 | - $to_fix[] = 'attachment_no_msg'; |
|
1610 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
1611 | + $to_fix[] = 'attachment_no_msg'; |
|
1612 | + } |
|
1559 | 1613 | $smcFunc['db_free_result']($result); |
1560 | 1614 | |
1561 | 1615 | // Do we need to delete what we have? |
1562 | - if ($fix_errors && !empty($to_remove) && in_array('attachment_no_msg', $to_fix)) |
|
1563 | - $smcFunc['db_query']('', ' |
|
1616 | + if ($fix_errors && !empty($to_remove) && in_array('attachment_no_msg', $to_fix)) { |
|
1617 | + $smcFunc['db_query']('', ' |
|
1564 | 1618 | DELETE FROM {db_prefix}attachments |
1565 | 1619 | WHERE id_attach IN ({array_int:to_remove}) |
1566 | 1620 | AND id_member = {int:no_member} |
@@ -1571,6 +1625,7 @@ discard block |
||
1571 | 1625 | 'no_msg' => 0, |
1572 | 1626 | ) |
1573 | 1627 | ); |
1628 | + } |
|
1574 | 1629 | |
1575 | 1630 | pauseAttachmentMaintenance($to_fix, $thumbnails); |
1576 | 1631 | } |
@@ -1594,8 +1649,9 @@ discard block |
||
1594 | 1649 | { |
1595 | 1650 | while ($file = readdir($dir)) |
1596 | 1651 | { |
1597 | - if (in_array($file, array('.', '..', '.htaccess', 'index.php'))) |
|
1598 | - continue; |
|
1652 | + if (in_array($file, array('.', '..', '.htaccess', 'index.php'))) { |
|
1653 | + continue; |
|
1654 | + } |
|
1599 | 1655 | |
1600 | 1656 | if ($files_checked <= $current_check) |
1601 | 1657 | { |
@@ -1603,8 +1659,9 @@ discard block |
||
1603 | 1659 | if (strpos($file, 'post_tmp_') !== false) |
1604 | 1660 | { |
1605 | 1661 | // Temp file is more than 5 hours old! |
1606 | - if (filemtime($attach_dir . '/' . $file) < time() - 18000) |
|
1607 | - @unlink($attach_dir . '/' . $file); |
|
1662 | + if (filemtime($attach_dir . '/' . $file) < time() - 18000) { |
|
1663 | + @unlink($attach_dir . '/' . $file); |
|
1664 | + } |
|
1608 | 1665 | } |
1609 | 1666 | // That should be an attachment, let's check if we have it in the database |
1610 | 1667 | elseif (strpos($file, '_') !== false) |
@@ -1626,8 +1683,7 @@ discard block |
||
1626 | 1683 | if ($fix_errors && in_array('files_without_attachment', $to_fix)) |
1627 | 1684 | { |
1628 | 1685 | @unlink($attach_dir . '/' . $file); |
1629 | - } |
|
1630 | - else |
|
1686 | + } else |
|
1631 | 1687 | { |
1632 | 1688 | $context['repair_errors']['files_without_attachment']++; |
1633 | 1689 | $to_fix[] = 'files_without_attachment'; |
@@ -1635,14 +1691,12 @@ discard block |
||
1635 | 1691 | } |
1636 | 1692 | $smcFunc['db_free_result']($request); |
1637 | 1693 | } |
1638 | - } |
|
1639 | - else |
|
1694 | + } else |
|
1640 | 1695 | { |
1641 | 1696 | if ($fix_errors && in_array('files_without_attachment', $to_fix)) |
1642 | 1697 | { |
1643 | 1698 | @unlink($attach_dir . '/' . $file); |
1644 | - } |
|
1645 | - else |
|
1699 | + } else |
|
1646 | 1700 | { |
1647 | 1701 | $context['repair_errors']['files_without_attachment']++; |
1648 | 1702 | $to_fix[] = 'files_without_attachment'; |
@@ -1651,8 +1705,9 @@ discard block |
||
1651 | 1705 | } |
1652 | 1706 | $current_check++; |
1653 | 1707 | $_GET['substep'] = $current_check; |
1654 | - if ($current_check - $files_checked >= $max_checks) |
|
1655 | - pauseAttachmentMaintenance($to_fix); |
|
1708 | + if ($current_check - $files_checked >= $max_checks) { |
|
1709 | + pauseAttachmentMaintenance($to_fix); |
|
1710 | + } |
|
1656 | 1711 | } |
1657 | 1712 | closedir($dir); |
1658 | 1713 | } |
@@ -1688,12 +1743,14 @@ discard block |
||
1688 | 1743 | |
1689 | 1744 | // Try get more time... |
1690 | 1745 | @set_time_limit(600); |
1691 | - if (function_exists('apache_reset_timeout')) |
|
1692 | - @apache_reset_timeout(); |
|
1746 | + if (function_exists('apache_reset_timeout')) { |
|
1747 | + @apache_reset_timeout(); |
|
1748 | + } |
|
1693 | 1749 | |
1694 | 1750 | // Have we already used our maximum time? |
1695 | - if (time() - array_sum(explode(' ', $time_start)) < 3 || $context['starting_substep'] == $_GET['substep']) |
|
1696 | - return; |
|
1751 | + if (time() - array_sum(explode(' ', $time_start)) < 3 || $context['starting_substep'] == $_GET['substep']) { |
|
1752 | + return; |
|
1753 | + } |
|
1697 | 1754 | |
1698 | 1755 | $context['continue_get_data'] = '?action=admin;area=manageattachments;sa=repair' . (isset($_GET['fixErrors']) ? ';fixErrors' : '') . ';step=' . $_GET['step'] . ';substep=' . $_GET['substep'] . ';' . $context['session_var'] . '=' . $context['session_id']; |
1699 | 1756 | $context['page_title'] = $txt['not_done_title']; |
@@ -1705,10 +1762,11 @@ discard block |
||
1705 | 1762 | $context[$context['admin_menu_name']]['current_subsection'] = 'maintenance'; |
1706 | 1763 | |
1707 | 1764 | // Change these two if more steps are added! |
1708 | - if (empty($max_substep)) |
|
1709 | - $context['continue_percent'] = round(($_GET['step'] * 100) / 25); |
|
1710 | - else |
|
1711 | - $context['continue_percent'] = round(($_GET['step'] * 100 + ($_GET['substep'] * 100) / $max_substep) / 25); |
|
1765 | + if (empty($max_substep)) { |
|
1766 | + $context['continue_percent'] = round(($_GET['step'] * 100) / 25); |
|
1767 | + } else { |
|
1768 | + $context['continue_percent'] = round(($_GET['step'] * 100 + ($_GET['substep'] * 100) / $max_substep) / 25); |
|
1769 | + } |
|
1712 | 1770 | |
1713 | 1771 | // Never more than 100%! |
1714 | 1772 | $context['continue_percent'] = min($context['continue_percent'], 100); |
@@ -1750,15 +1808,17 @@ discard block |
||
1750 | 1808 | 'attachment_type' => 0, |
1751 | 1809 | ) |
1752 | 1810 | ); |
1753 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1754 | - $attachments[] = $row['id_attach']; |
|
1811 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1812 | + $attachments[] = $row['id_attach']; |
|
1813 | + } |
|
1755 | 1814 | $smcFunc['db_free_result']($request); |
1815 | + } elseif (!empty($_GET['aid'])) { |
|
1816 | + $attachments[] = (int) $_GET['aid']; |
|
1756 | 1817 | } |
1757 | - elseif (!empty($_GET['aid'])) |
|
1758 | - $attachments[] = (int) $_GET['aid']; |
|
1759 | 1818 | |
1760 | - if (empty($attachments)) |
|
1761 | - fatal_lang_error('no_access', false); |
|
1819 | + if (empty($attachments)) { |
|
1820 | + fatal_lang_error('no_access', false); |
|
1821 | + } |
|
1762 | 1822 | |
1763 | 1823 | // Now we have some ID's cleaned and ready to approve, but first - let's check we have permission! |
1764 | 1824 | $allowed_boards = boardsAllowedTo('approve_posts'); |
@@ -1791,17 +1851,18 @@ discard block |
||
1791 | 1851 | } |
1792 | 1852 | $smcFunc['db_free_result']($request); |
1793 | 1853 | |
1794 | - if (empty($attachments)) |
|
1795 | - fatal_lang_error('no_access', false); |
|
1854 | + if (empty($attachments)) { |
|
1855 | + fatal_lang_error('no_access', false); |
|
1856 | + } |
|
1796 | 1857 | |
1797 | 1858 | // Finally, we are there. Follow through! |
1798 | 1859 | if ($is_approve) |
1799 | 1860 | { |
1800 | 1861 | // Checked and deemed worthy. |
1801 | 1862 | ApproveAttachments($attachments); |
1863 | + } else { |
|
1864 | + removeAttachments(array('id_attach' => $attachments, 'do_logging' => true)); |
|
1802 | 1865 | } |
1803 | - else |
|
1804 | - removeAttachments(array('id_attach' => $attachments, 'do_logging' => true)); |
|
1805 | 1866 | |
1806 | 1867 | // Return to the topic.... |
1807 | 1868 | redirectexit($redirect); |
@@ -1817,8 +1878,9 @@ discard block |
||
1817 | 1878 | { |
1818 | 1879 | global $smcFunc; |
1819 | 1880 | |
1820 | - if (empty($attachments)) |
|
1821 | - return 0; |
|
1881 | + if (empty($attachments)) { |
|
1882 | + return 0; |
|
1883 | + } |
|
1822 | 1884 | |
1823 | 1885 | // For safety, check for thumbnails... |
1824 | 1886 | $request = $smcFunc['db_query']('', ' |
@@ -1837,15 +1899,17 @@ discard block |
||
1837 | 1899 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1838 | 1900 | { |
1839 | 1901 | // Update the thumbnail too... |
1840 | - if (!empty($row['id_thumb'])) |
|
1841 | - $attachments[] = $row['id_thumb']; |
|
1902 | + if (!empty($row['id_thumb'])) { |
|
1903 | + $attachments[] = $row['id_thumb']; |
|
1904 | + } |
|
1842 | 1905 | |
1843 | 1906 | $attachments[] = $row['id_attach']; |
1844 | 1907 | } |
1845 | 1908 | $smcFunc['db_free_result']($request); |
1846 | 1909 | |
1847 | - if (empty($attachments)) |
|
1848 | - return 0; |
|
1910 | + if (empty($attachments)) { |
|
1911 | + return 0; |
|
1912 | + } |
|
1849 | 1913 | |
1850 | 1914 | // Approving an attachment is not hard - it's easy. |
1851 | 1915 | $smcFunc['db_query']('', ' |
@@ -1871,14 +1935,15 @@ discard block |
||
1871 | 1935 | ) |
1872 | 1936 | ); |
1873 | 1937 | |
1874 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1875 | - logAction( |
|
1938 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1939 | + logAction( |
|
1876 | 1940 | 'approve_attach', |
1877 | 1941 | array( |
1878 | 1942 | 'message' => $row['id_msg'], |
1879 | 1943 | 'filename' => preg_replace('~&#(\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\1;', $smcFunc['htmlspecialchars']($row['filename'])), |
1880 | 1944 | ) |
1881 | 1945 | ); |
1946 | + } |
|
1882 | 1947 | $smcFunc['db_free_result']($request); |
1883 | 1948 | |
1884 | 1949 | // Remove from the approval queue. |
@@ -1901,11 +1966,11 @@ discard block |
||
1901 | 1966 | global $modSettings, $scripturl, $context, $txt, $sourcedir, $boarddir, $smcFunc, $settings; |
1902 | 1967 | |
1903 | 1968 | // Since this needs to be done eventually. |
1904 | - if (!isset($modSettings['attachment_basedirectories'])) |
|
1905 | - $modSettings['attachment_basedirectories'] = array(); |
|
1906 | - |
|
1907 | - elseif (!is_array($modSettings['attachment_basedirectories'])) |
|
1908 | - $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
1969 | + if (!isset($modSettings['attachment_basedirectories'])) { |
|
1970 | + $modSettings['attachment_basedirectories'] = array(); |
|
1971 | + } elseif (!is_array($modSettings['attachment_basedirectories'])) { |
|
1972 | + $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
1973 | + } |
|
1909 | 1974 | |
1910 | 1975 | $errors = array(); |
1911 | 1976 | |
@@ -1920,8 +1985,9 @@ discard block |
||
1920 | 1985 | { |
1921 | 1986 | $error = ''; |
1922 | 1987 | $id = (int) $id; |
1923 | - if ($id < 1) |
|
1924 | - continue; |
|
1988 | + if ($id < 1) { |
|
1989 | + continue; |
|
1990 | + } |
|
1925 | 1991 | |
1926 | 1992 | // Sorry, these dirs are NOT valid |
1927 | 1993 | $invalid_dirs = array($boarddir, $settings['default_theme_dir'], $sourcedir); |
@@ -1940,8 +2006,7 @@ discard block |
||
1940 | 2006 | { |
1941 | 2007 | $errors[] = $path . ': ' . $txt['attach_dir_duplicate_msg']; |
1942 | 2008 | continue; |
1943 | - } |
|
1944 | - elseif (empty($path)) |
|
2009 | + } elseif (empty($path)) |
|
1945 | 2010 | { |
1946 | 2011 | // Ignore this and set $id to one less |
1947 | 2012 | continue; |
@@ -1949,10 +2014,11 @@ discard block |
||
1949 | 2014 | |
1950 | 2015 | // OK, so let's try to create it then. |
1951 | 2016 | require_once($sourcedir . '/Subs-Attachments.php'); |
1952 | - if (automanage_attachments_create_directory($path)) |
|
1953 | - $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
1954 | - else |
|
1955 | - $errors[] = $path . ': ' . $txt[$context['dir_creation_error']]; |
|
2017 | + if (automanage_attachments_create_directory($path)) { |
|
2018 | + $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
2019 | + } else { |
|
2020 | + $errors[] = $path . ': ' . $txt[$context['dir_creation_error']]; |
|
2021 | + } |
|
1956 | 2022 | } |
1957 | 2023 | |
1958 | 2024 | // Changing a directory name? |
@@ -1965,8 +2031,7 @@ discard block |
||
1965 | 2031 | $errors[] = $path . ': ' . $txt['attach_dir_no_rename']; |
1966 | 2032 | $path = $modSettings['attachmentUploadDir'][$id]; |
1967 | 2033 | } |
1968 | - } |
|
1969 | - else |
|
2034 | + } else |
|
1970 | 2035 | { |
1971 | 2036 | $errors[] = $path . ': ' . $txt['attach_dir_exists_msg']; |
1972 | 2037 | $path = $modSettings['attachmentUploadDir'][$id]; |
@@ -1991,12 +2056,13 @@ discard block |
||
1991 | 2056 | $path = $modSettings['attachmentUploadDir'][$id]; |
1992 | 2057 | |
1993 | 2058 | // It's not a good idea to delete the current directory. |
1994 | - if ($id == (!empty($_POST['current_dir']) ? $_POST['current_dir'] : $modSettings['currentAttachmentUploadDir'])) |
|
1995 | - $errors[] = $path . ': ' . $txt['attach_dir_is_current']; |
|
2059 | + if ($id == (!empty($_POST['current_dir']) ? $_POST['current_dir'] : $modSettings['currentAttachmentUploadDir'])) { |
|
2060 | + $errors[] = $path . ': ' . $txt['attach_dir_is_current']; |
|
2061 | + } |
|
1996 | 2062 | // Or the current base directory |
1997 | - elseif (!empty($modSettings['basedirectory_for_attachments']) && $modSettings['basedirectory_for_attachments'] == $modSettings['attachmentUploadDir'][$id]) |
|
1998 | - $errors[] = $path . ': ' . $txt['attach_dir_is_current_bd']; |
|
1999 | - else |
|
2063 | + elseif (!empty($modSettings['basedirectory_for_attachments']) && $modSettings['basedirectory_for_attachments'] == $modSettings['attachmentUploadDir'][$id]) { |
|
2064 | + $errors[] = $path . ': ' . $txt['attach_dir_is_current_bd']; |
|
2065 | + } else |
|
2000 | 2066 | { |
2001 | 2067 | // Let's not try to delete a path with files in it. |
2002 | 2068 | $request = $smcFunc['db_query']('', ' |
@@ -2015,17 +2081,18 @@ discard block |
||
2015 | 2081 | if (!empty($modSettings['attachment_basedirectories'])) |
2016 | 2082 | { |
2017 | 2083 | // Count any sub-folders. |
2018 | - foreach ($modSettings['attachmentUploadDir'] as $sub) |
|
2019 | - if (strpos($sub, $path . DIRECTORY_SEPARATOR) !== false) |
|
2084 | + foreach ($modSettings['attachmentUploadDir'] as $sub) { |
|
2085 | + if (strpos($sub, $path . DIRECTORY_SEPARATOR) !== false) |
|
2020 | 2086 | $num_attach++; |
2087 | + } |
|
2021 | 2088 | } |
2022 | 2089 | |
2023 | 2090 | // It's safe to delete. So try to delete the folder also |
2024 | 2091 | if ($num_attach == 0) |
2025 | 2092 | { |
2026 | - if (is_dir($path)) |
|
2027 | - $doit = true; |
|
2028 | - elseif (is_dir($boarddir . DIRECTORY_SEPARATOR . $path)) |
|
2093 | + if (is_dir($path)) { |
|
2094 | + $doit = true; |
|
2095 | + } elseif (is_dir($boarddir . DIRECTORY_SEPARATOR . $path)) |
|
2029 | 2096 | { |
2030 | 2097 | $doit = true; |
2031 | 2098 | $path = $boarddir . DIRECTORY_SEPARATOR . $path; |
@@ -2035,8 +2102,9 @@ discard block |
||
2035 | 2102 | { |
2036 | 2103 | unlink($path . '/.htaccess'); |
2037 | 2104 | unlink($path . '/index.php'); |
2038 | - if (!@rmdir($path)) |
|
2039 | - $error = $path . ': ' . $txt['attach_dir_no_delete']; |
|
2105 | + if (!@rmdir($path)) { |
|
2106 | + $error = $path . ': ' . $txt['attach_dir_no_delete']; |
|
2107 | + } |
|
2040 | 2108 | } |
2041 | 2109 | |
2042 | 2110 | // Remove it from the base directory list. |
@@ -2046,14 +2114,15 @@ discard block |
||
2046 | 2114 | updateSettings(array('attachment_basedirectories' => json_encode($modSettings['attachment_basedirectories']))); |
2047 | 2115 | $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
2048 | 2116 | } |
2117 | + } else { |
|
2118 | + $error = $path . ': ' . $txt['attach_dir_no_remove']; |
|
2049 | 2119 | } |
2050 | - else |
|
2051 | - $error = $path . ': ' . $txt['attach_dir_no_remove']; |
|
2052 | 2120 | |
2053 | - if (empty($error)) |
|
2054 | - continue; |
|
2055 | - else |
|
2056 | - $errors[] = $error; |
|
2121 | + if (empty($error)) { |
|
2122 | + continue; |
|
2123 | + } else { |
|
2124 | + $errors[] = $error; |
|
2125 | + } |
|
2057 | 2126 | } |
2058 | 2127 | } |
2059 | 2128 | |
@@ -2061,23 +2130,26 @@ discard block |
||
2061 | 2130 | } |
2062 | 2131 | |
2063 | 2132 | // We need to make sure the current directory is right. |
2064 | - if (empty($_POST['current_dir']) && !empty($modSettings['currentAttachmentUploadDir'])) |
|
2065 | - $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
2133 | + if (empty($_POST['current_dir']) && !empty($modSettings['currentAttachmentUploadDir'])) { |
|
2134 | + $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
2135 | + } |
|
2066 | 2136 | |
2067 | 2137 | // Find the current directory if there's no value carried, |
2068 | 2138 | if (empty($_POST['current_dir']) || empty($new_dirs[$_POST['current_dir']])) |
2069 | 2139 | { |
2070 | - if (array_key_exists($modSettings['currentAttachmentUploadDir'], $modSettings['attachmentUploadDir'])) |
|
2071 | - $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
2072 | - else |
|
2073 | - $_POST['current_dir'] = max(array_keys($modSettings['attachmentUploadDir'])); |
|
2140 | + if (array_key_exists($modSettings['currentAttachmentUploadDir'], $modSettings['attachmentUploadDir'])) { |
|
2141 | + $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
2142 | + } else { |
|
2143 | + $_POST['current_dir'] = max(array_keys($modSettings['attachmentUploadDir'])); |
|
2144 | + } |
|
2074 | 2145 | } |
2075 | 2146 | |
2076 | 2147 | // If the user wishes to go back, update the last_dir array |
2077 | 2148 | if ($_POST['current_dir'] != $modSettings['currentAttachmentUploadDir'] && !empty($modSettings['last_attachments_directory']) && (isset($modSettings['last_attachments_directory'][$_POST['current_dir']]) || isset($modSettings['last_attachments_directory'][0]))) |
2078 | 2149 | { |
2079 | - if (!is_array($modSettings['last_attachments_directory'])) |
|
2080 | - $modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true); |
|
2150 | + if (!is_array($modSettings['last_attachments_directory'])) { |
|
2151 | + $modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true); |
|
2152 | + } |
|
2081 | 2153 | $num = substr(strrchr($modSettings['attachmentUploadDir'][$_POST['current_dir']], '_'), 1); |
2082 | 2154 | |
2083 | 2155 | if (is_numeric($num)) |
@@ -2085,16 +2157,18 @@ discard block |
||
2085 | 2157 | // Need to find the base folder. |
2086 | 2158 | $bid = -1; |
2087 | 2159 | $use_subdirectories_for_attachments = 0; |
2088 | - if (!empty($modSettings['attachment_basedirectories'])) |
|
2089 | - foreach ($modSettings['attachment_basedirectories'] as $bid => $base) |
|
2160 | + if (!empty($modSettings['attachment_basedirectories'])) { |
|
2161 | + foreach ($modSettings['attachment_basedirectories'] as $bid => $base) |
|
2090 | 2162 | if (strpos($modSettings['attachmentUploadDir'][$_POST['current_dir']], $base . DIRECTORY_SEPARATOR) !== false) |
2091 | 2163 | { |
2092 | 2164 | $use_subdirectories_for_attachments = 1; |
2165 | + } |
|
2093 | 2166 | break; |
2094 | 2167 | } |
2095 | 2168 | |
2096 | - if ($use_subdirectories_for_attachments == 0 && strpos($modSettings['attachmentUploadDir'][$_POST['current_dir']], $boarddir . DIRECTORY_SEPARATOR) !== false) |
|
2097 | - $bid = 0; |
|
2169 | + if ($use_subdirectories_for_attachments == 0 && strpos($modSettings['attachmentUploadDir'][$_POST['current_dir']], $boarddir . DIRECTORY_SEPARATOR) !== false) { |
|
2170 | + $bid = 0; |
|
2171 | + } |
|
2098 | 2172 | |
2099 | 2173 | $modSettings['last_attachments_directory'][$bid] = (int) $num; |
2100 | 2174 | $modSettings['basedirectory_for_attachments'] = !empty($modSettings['basedirectory_for_attachments']) ? $modSettings['basedirectory_for_attachments'] : ''; |
@@ -2113,8 +2187,8 @@ discard block |
||
2113 | 2187 | // We might need to reset the paths. This loop will just loop through once. |
2114 | 2188 | foreach ($new_dirs as $id => $dir) |
2115 | 2189 | { |
2116 | - if ($id != 1) |
|
2117 | - $smcFunc['db_query']('', ' |
|
2190 | + if ($id != 1) { |
|
2191 | + $smcFunc['db_query']('', ' |
|
2118 | 2192 | UPDATE {db_prefix}attachments |
2119 | 2193 | SET id_folder = {int:default_folder} |
2120 | 2194 | WHERE id_folder = {int:current_folder}', |
@@ -2123,14 +2197,14 @@ discard block |
||
2123 | 2197 | 'current_folder' => $id, |
2124 | 2198 | ) |
2125 | 2199 | ); |
2200 | + } |
|
2126 | 2201 | |
2127 | 2202 | $update = array( |
2128 | 2203 | 'currentAttachmentUploadDir' => 1, |
2129 | 2204 | 'attachmentUploadDir' => json_encode(array(1 => $dir)), |
2130 | 2205 | ); |
2131 | 2206 | } |
2132 | - } |
|
2133 | - else |
|
2207 | + } else |
|
2134 | 2208 | { |
2135 | 2209 | // Save it to the database. |
2136 | 2210 | $update = array( |
@@ -2139,11 +2213,13 @@ discard block |
||
2139 | 2213 | ); |
2140 | 2214 | } |
2141 | 2215 | |
2142 | - if (!empty($update)) |
|
2143 | - updateSettings($update); |
|
2216 | + if (!empty($update)) { |
|
2217 | + updateSettings($update); |
|
2218 | + } |
|
2144 | 2219 | |
2145 | - if (!empty($errors)) |
|
2146 | - $_SESSION['errors']['dir'] = $errors; |
|
2220 | + if (!empty($errors)) { |
|
2221 | + $_SESSION['errors']['dir'] = $errors; |
|
2222 | + } |
|
2147 | 2223 | |
2148 | 2224 | redirectexit('action=admin;area=manageattachments;sa=attachpaths;' . $context['session_var'] . '=' . $context['session_id']); |
2149 | 2225 | } |
@@ -2157,10 +2233,11 @@ discard block |
||
2157 | 2233 | $_POST['current_base_dir'] = isset($_POST['current_base_dir']) ? (int) $_POST['current_base_dir'] : 1; |
2158 | 2234 | if (empty($_POST['new_base_dir']) && !empty($_POST['current_base_dir'])) |
2159 | 2235 | { |
2160 | - if ($modSettings['basedirectory_for_attachments'] != $modSettings['attachmentUploadDir'][$_POST['current_base_dir']]) |
|
2161 | - $update = (array( |
|
2236 | + if ($modSettings['basedirectory_for_attachments'] != $modSettings['attachmentUploadDir'][$_POST['current_base_dir']]) { |
|
2237 | + $update = (array( |
|
2162 | 2238 | 'basedirectory_for_attachments' => $modSettings['attachmentUploadDir'][$_POST['current_base_dir']], |
2163 | 2239 | )); |
2240 | + } |
|
2164 | 2241 | } |
2165 | 2242 | |
2166 | 2243 | if (isset($_POST['base_dir'])) |
@@ -2208,13 +2285,15 @@ discard block |
||
2208 | 2285 | |
2209 | 2286 | if (!in_array($_POST['new_base_dir'], $modSettings['attachmentUploadDir'])) |
2210 | 2287 | { |
2211 | - if (!automanage_attachments_create_directory($_POST['new_base_dir'])) |
|
2212 | - $errors[] = $_POST['new_base_dir'] . ': ' . $txt['attach_dir_base_no_create']; |
|
2288 | + if (!automanage_attachments_create_directory($_POST['new_base_dir'])) { |
|
2289 | + $errors[] = $_POST['new_base_dir'] . ': ' . $txt['attach_dir_base_no_create']; |
|
2290 | + } |
|
2213 | 2291 | } |
2214 | 2292 | |
2215 | 2293 | $modSettings['currentAttachmentUploadDir'] = array_search($_POST['new_base_dir'], $modSettings['attachmentUploadDir']); |
2216 | - if (!in_array($_POST['new_base_dir'], $modSettings['attachment_basedirectories'])) |
|
2217 | - $modSettings['attachment_basedirectories'][$modSettings['currentAttachmentUploadDir']] = $_POST['new_base_dir']; |
|
2294 | + if (!in_array($_POST['new_base_dir'], $modSettings['attachment_basedirectories'])) { |
|
2295 | + $modSettings['attachment_basedirectories'][$modSettings['currentAttachmentUploadDir']] = $_POST['new_base_dir']; |
|
2296 | + } |
|
2218 | 2297 | ksort($modSettings['attachment_basedirectories']); |
2219 | 2298 | |
2220 | 2299 | $update = (array( |
@@ -2224,11 +2303,13 @@ discard block |
||
2224 | 2303 | )); |
2225 | 2304 | } |
2226 | 2305 | |
2227 | - if (!empty($errors)) |
|
2228 | - $_SESSION['errors']['base'] = $errors; |
|
2306 | + if (!empty($errors)) { |
|
2307 | + $_SESSION['errors']['base'] = $errors; |
|
2308 | + } |
|
2229 | 2309 | |
2230 | - if (!empty($update)) |
|
2231 | - updateSettings($update); |
|
2310 | + if (!empty($update)) { |
|
2311 | + updateSettings($update); |
|
2312 | + } |
|
2232 | 2313 | |
2233 | 2314 | redirectexit('action=admin;area=manageattachments;sa=attachpaths;' . $context['session_var'] . '=' . $context['session_id']); |
2234 | 2315 | } |
@@ -2238,13 +2319,15 @@ discard block |
||
2238 | 2319 | if (is_array($_SESSION['errors'])) |
2239 | 2320 | { |
2240 | 2321 | $errors = array(); |
2241 | - if (!empty($_SESSION['errors']['dir'])) |
|
2242 | - foreach ($_SESSION['errors']['dir'] as $error) |
|
2322 | + if (!empty($_SESSION['errors']['dir'])) { |
|
2323 | + foreach ($_SESSION['errors']['dir'] as $error) |
|
2243 | 2324 | $errors['dir'][] = $smcFunc['htmlspecialchars']($error, ENT_QUOTES); |
2325 | + } |
|
2244 | 2326 | |
2245 | - if (!empty($_SESSION['errors']['base'])) |
|
2246 | - foreach ($_SESSION['errors']['base'] as $error) |
|
2327 | + if (!empty($_SESSION['errors']['base'])) { |
|
2328 | + foreach ($_SESSION['errors']['base'] as $error) |
|
2247 | 2329 | $errors['base'][] = $smcFunc['htmlspecialchars']($error, ENT_QUOTES); |
2330 | + } |
|
2248 | 2331 | } |
2249 | 2332 | unset($_SESSION['errors']); |
2250 | 2333 | } |
@@ -2454,8 +2537,9 @@ discard block |
||
2454 | 2537 | foreach ($modSettings['attachmentUploadDir'] as $id => $dir) |
2455 | 2538 | { |
2456 | 2539 | // If there aren't any attachments in this directory this won't exist. |
2457 | - if (!isset($expected_files[$id])) |
|
2458 | - $expected_files[$id] = 0; |
|
2540 | + if (!isset($expected_files[$id])) { |
|
2541 | + $expected_files[$id] = 0; |
|
2542 | + } |
|
2459 | 2543 | |
2460 | 2544 | // Check if the directory is doing okay. |
2461 | 2545 | list ($status, $error, $files) = attachDirStatus($dir, $expected_files[$id]); |
@@ -2468,10 +2552,11 @@ discard block |
||
2468 | 2552 | $is_base_dir = in_array($dir, $modSettings['attachment_basedirectories']); |
2469 | 2553 | |
2470 | 2554 | // Count any sub-folders. |
2471 | - foreach ($modSettings['attachmentUploadDir'] as $sid => $sub) |
|
2472 | - if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false) |
|
2555 | + foreach ($modSettings['attachmentUploadDir'] as $sid => $sub) { |
|
2556 | + if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false) |
|
2473 | 2557 | { |
2474 | 2558 | $expected_files[$id]++; |
2559 | + } |
|
2475 | 2560 | $sub_dirs++; |
2476 | 2561 | } |
2477 | 2562 | } |
@@ -2489,8 +2574,8 @@ discard block |
||
2489 | 2574 | } |
2490 | 2575 | |
2491 | 2576 | // Just stick a new directory on at the bottom. |
2492 | - if (isset($_REQUEST['new_path'])) |
|
2493 | - $attachdirs[] = array( |
|
2577 | + if (isset($_REQUEST['new_path'])) { |
|
2578 | + $attachdirs[] = array( |
|
2494 | 2579 | 'id' => max(array_merge(array_keys($expected_files), array_keys($modSettings['attachmentUploadDir']))) + 1, |
2495 | 2580 | 'current' => false, |
2496 | 2581 | 'path' => '', |
@@ -2498,6 +2583,7 @@ discard block |
||
2498 | 2583 | 'num_files' => '', |
2499 | 2584 | 'status' => '', |
2500 | 2585 | ); |
2586 | + } |
|
2501 | 2587 | |
2502 | 2588 | return $attachdirs; |
2503 | 2589 | } |
@@ -2510,8 +2596,9 @@ discard block |
||
2510 | 2596 | { |
2511 | 2597 | global $modSettings, $txt; |
2512 | 2598 | |
2513 | - if (empty($modSettings['attachment_basedirectories'])) |
|
2514 | - return; |
|
2599 | + if (empty($modSettings['attachment_basedirectories'])) { |
|
2600 | + return; |
|
2601 | + } |
|
2515 | 2602 | |
2516 | 2603 | $basedirs = array(); |
2517 | 2604 | // Get a list of the base directories. |
@@ -2519,16 +2606,18 @@ discard block |
||
2519 | 2606 | { |
2520 | 2607 | // Loop through the attach directory array to count any sub-directories |
2521 | 2608 | $expected_dirs = 0; |
2522 | - foreach ($modSettings['attachmentUploadDir'] as $sid => $sub) |
|
2523 | - if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false) |
|
2609 | + foreach ($modSettings['attachmentUploadDir'] as $sid => $sub) { |
|
2610 | + if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false) |
|
2524 | 2611 | $expected_dirs++; |
2612 | + } |
|
2525 | 2613 | |
2526 | - if (!is_dir($dir)) |
|
2527 | - $status = 'does_not_exist'; |
|
2528 | - elseif (!is_writeable($dir)) |
|
2529 | - $status = 'not_writable'; |
|
2530 | - else |
|
2531 | - $status = 'ok'; |
|
2614 | + if (!is_dir($dir)) { |
|
2615 | + $status = 'does_not_exist'; |
|
2616 | + } elseif (!is_writeable($dir)) { |
|
2617 | + $status = 'not_writable'; |
|
2618 | + } else { |
|
2619 | + $status = 'ok'; |
|
2620 | + } |
|
2532 | 2621 | |
2533 | 2622 | $basedirs[] = array( |
2534 | 2623 | 'id' => $id, |
@@ -2539,14 +2628,15 @@ discard block |
||
2539 | 2628 | ); |
2540 | 2629 | } |
2541 | 2630 | |
2542 | - if (isset($_REQUEST['new_base_path'])) |
|
2543 | - $basedirs[] = array( |
|
2631 | + if (isset($_REQUEST['new_base_path'])) { |
|
2632 | + $basedirs[] = array( |
|
2544 | 2633 | 'id' => '', |
2545 | 2634 | 'current' => false, |
2546 | 2635 | 'path' => '<input type="text" name="new_base_dir" value="" size="40">', |
2547 | 2636 | 'num_dirs' => '', |
2548 | 2637 | 'status' => '', |
2549 | 2638 | ); |
2639 | + } |
|
2550 | 2640 | |
2551 | 2641 | return $basedirs; |
2552 | 2642 | } |
@@ -2562,10 +2652,11 @@ discard block |
||
2562 | 2652 | */ |
2563 | 2653 | function attachDirStatus($dir, $expected_files) |
2564 | 2654 | { |
2565 | - if (!is_dir($dir)) |
|
2566 | - return array('does_not_exist', true, ''); |
|
2567 | - elseif (!is_writable($dir)) |
|
2568 | - return array('not_writable', true, ''); |
|
2655 | + if (!is_dir($dir)) { |
|
2656 | + return array('does_not_exist', true, ''); |
|
2657 | + } elseif (!is_writable($dir)) { |
|
2658 | + return array('not_writable', true, ''); |
|
2659 | + } |
|
2569 | 2660 | |
2570 | 2661 | // Everything is okay so far, start to scan through the directory. |
2571 | 2662 | $num_files = 0; |
@@ -2573,22 +2664,26 @@ discard block |
||
2573 | 2664 | while ($file = $dir_handle->read()) |
2574 | 2665 | { |
2575 | 2666 | // Now do we have a real file here? |
2576 | - if (in_array($file, array('.', '..', '.htaccess', 'index.php'))) |
|
2577 | - continue; |
|
2667 | + if (in_array($file, array('.', '..', '.htaccess', 'index.php'))) { |
|
2668 | + continue; |
|
2669 | + } |
|
2578 | 2670 | |
2579 | 2671 | $num_files++; |
2580 | 2672 | } |
2581 | 2673 | $dir_handle->close(); |
2582 | 2674 | |
2583 | - if ($num_files < $expected_files) |
|
2584 | - return array('files_missing', true, $num_files); |
|
2675 | + if ($num_files < $expected_files) { |
|
2676 | + return array('files_missing', true, $num_files); |
|
2677 | + } |
|
2585 | 2678 | // Empty? |
2586 | - elseif ($expected_files == 0) |
|
2587 | - return array('unused', false, $num_files); |
|
2679 | + elseif ($expected_files == 0) { |
|
2680 | + return array('unused', false, $num_files); |
|
2681 | + } |
|
2588 | 2682 | // All good! |
2589 | - else |
|
2590 | - return array('ok', false, $num_files); |
|
2591 | -} |
|
2683 | + else { |
|
2684 | + return array('ok', false, $num_files); |
|
2685 | + } |
|
2686 | + } |
|
2592 | 2687 | |
2593 | 2688 | /** |
2594 | 2689 | * Maintance function to move attachments from one directory to another |
@@ -2600,10 +2695,11 @@ discard block |
||
2600 | 2695 | checkSession(); |
2601 | 2696 | |
2602 | 2697 | $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
2603 | - if (!empty($modSettings['attachment_basedirectories'])) |
|
2604 | - $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
2605 | - else |
|
2606 | - $modSettings['basedirectory_for_attachments'] = array(); |
|
2698 | + if (!empty($modSettings['attachment_basedirectories'])) { |
|
2699 | + $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
2700 | + } else { |
|
2701 | + $modSettings['basedirectory_for_attachments'] = array(); |
|
2702 | + } |
|
2607 | 2703 | |
2608 | 2704 | $_POST['from'] = (int) $_POST['from']; |
2609 | 2705 | $_POST['auto'] = !empty($_POST['auto']) ? (int) $_POST['auto'] : 0; |
@@ -2617,11 +2713,13 @@ discard block |
||
2617 | 2713 | $total_moved = 0; |
2618 | 2714 | $total_not_moved = 0; |
2619 | 2715 | |
2620 | - if (empty($_POST['from']) || (empty($_POST['auto']) && empty($_POST['to']))) |
|
2621 | - $results[] = $txt['attachment_transfer_no_dir']; |
|
2716 | + if (empty($_POST['from']) || (empty($_POST['auto']) && empty($_POST['to']))) { |
|
2717 | + $results[] = $txt['attachment_transfer_no_dir']; |
|
2718 | + } |
|
2622 | 2719 | |
2623 | - if ($_POST['from'] == $_POST['to']) |
|
2624 | - $results[] = $txt['attachment_transfer_same_dir']; |
|
2720 | + if ($_POST['from'] == $_POST['to']) { |
|
2721 | + $results[] = $txt['attachment_transfer_same_dir']; |
|
2722 | + } |
|
2625 | 2723 | |
2626 | 2724 | if (empty($results)) |
2627 | 2725 | { |
@@ -2640,8 +2738,9 @@ discard block |
||
2640 | 2738 | $smcFunc['db_free_result']($request); |
2641 | 2739 | $total_progress -= $start; |
2642 | 2740 | |
2643 | - if ($total_progress < 1) |
|
2644 | - $results[] = $txt['attachment_transfer_no_find']; |
|
2741 | + if ($total_progress < 1) { |
|
2742 | + $results[] = $txt['attachment_transfer_no_find']; |
|
2743 | + } |
|
2645 | 2744 | } |
2646 | 2745 | |
2647 | 2746 | if (empty($results)) |
@@ -2657,9 +2756,9 @@ discard block |
||
2657 | 2756 | |
2658 | 2757 | automanage_attachments_check_directory(); |
2659 | 2758 | $new_dir = $modSettings['currentAttachmentUploadDir']; |
2759 | + } else { |
|
2760 | + $new_dir = $_POST['to']; |
|
2660 | 2761 | } |
2661 | - else |
|
2662 | - $new_dir = $_POST['to']; |
|
2663 | 2762 | |
2664 | 2763 | $modSettings['currentAttachmentUploadDir'] = $new_dir; |
2665 | 2764 | |
@@ -2667,8 +2766,9 @@ discard block |
||
2667 | 2766 | while ($break == false) |
2668 | 2767 | { |
2669 | 2768 | @set_time_limit(300); |
2670 | - if (function_exists('apache_reset_timeout')) |
|
2671 | - @apache_reset_timeout(); |
|
2769 | + if (function_exists('apache_reset_timeout')) { |
|
2770 | + @apache_reset_timeout(); |
|
2771 | + } |
|
2672 | 2772 | |
2673 | 2773 | // If limits are set, get the file count and size for the destination folder |
2674 | 2774 | if ($dir_files <= 0 && (!empty($modSettings['attachmentDirSizeLimit']) || !empty($modSettings['attachmentDirFileLimit']))) |
@@ -2704,13 +2804,15 @@ discard block |
||
2704 | 2804 | |
2705 | 2805 | if ($smcFunc['db_num_rows']($request) === 0) |
2706 | 2806 | { |
2707 | - if (empty($current_progress)) |
|
2708 | - $results[] = $txt['attachment_transfer_no_find']; |
|
2807 | + if (empty($current_progress)) { |
|
2808 | + $results[] = $txt['attachment_transfer_no_find']; |
|
2809 | + } |
|
2709 | 2810 | break; |
2710 | 2811 | } |
2711 | 2812 | |
2712 | - if ($smcFunc['db_num_rows']($request) < $limit) |
|
2713 | - $break = true; |
|
2813 | + if ($smcFunc['db_num_rows']($request) < $limit) { |
|
2814 | + $break = true; |
|
2815 | + } |
|
2714 | 2816 | |
2715 | 2817 | // Move them |
2716 | 2818 | $moved = array(); |
@@ -2734,8 +2836,9 @@ discard block |
||
2734 | 2836 | automanage_attachments_by_space(); |
2735 | 2837 | |
2736 | 2838 | $results[] = sprintf($txt['attachments_transferred'], $total_moved, $modSettings['attachmentUploadDir'][$new_dir]); |
2737 | - if (!empty($total_not_moved)) |
|
2738 | - $results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved); |
|
2839 | + if (!empty($total_not_moved)) { |
|
2840 | + $results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved); |
|
2841 | + } |
|
2739 | 2842 | |
2740 | 2843 | $dir_files = 0; |
2741 | 2844 | $total_moved = 0; |
@@ -2743,8 +2846,7 @@ discard block |
||
2743 | 2846 | |
2744 | 2847 | $break = false; |
2745 | 2848 | break; |
2746 | - } |
|
2747 | - else |
|
2849 | + } else |
|
2748 | 2850 | { |
2749 | 2851 | // Hmm, not in auto. Time to bail out then... |
2750 | 2852 | $results[] = $txt['attachment_transfer_no_room']; |
@@ -2759,9 +2861,9 @@ discard block |
||
2759 | 2861 | $total_moved++; |
2760 | 2862 | $current_progress++; |
2761 | 2863 | $moved[] = $row['id_attach']; |
2864 | + } else { |
|
2865 | + $total_not_moved++; |
|
2762 | 2866 | } |
2763 | - else |
|
2764 | - $total_not_moved++; |
|
2765 | 2867 | } |
2766 | 2868 | $smcFunc['db_free_result']($request); |
2767 | 2869 | |
@@ -2800,13 +2902,15 @@ discard block |
||
2800 | 2902 | } |
2801 | 2903 | |
2802 | 2904 | $results[] = sprintf($txt['attachments_transferred'], $total_moved, $modSettings['attachmentUploadDir'][$new_dir]); |
2803 | - if (!empty($total_not_moved)) |
|
2804 | - $results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved); |
|
2905 | + if (!empty($total_not_moved)) { |
|
2906 | + $results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved); |
|
2907 | + } |
|
2805 | 2908 | } |
2806 | 2909 | |
2807 | 2910 | $_SESSION['results'] = $results; |
2808 | - if (file_exists($boarddir . '/progress.php')) |
|
2809 | - unlink($boarddir . '/progress.php'); |
|
2911 | + if (file_exists($boarddir . '/progress.php')) { |
|
2912 | + unlink($boarddir . '/progress.php'); |
|
2913 | + } |
|
2810 | 2914 | |
2811 | 2915 | redirectexit('action=admin;area=manageattachments;sa=maintenance#transfer'); |
2812 | 2916 | } |
@@ -15,8 +15,9 @@ discard block |
||
15 | 15 | * @version 2.1 Beta 3 |
16 | 16 | */ |
17 | 17 | |
18 | -if (!defined('SMF')) |
|
18 | +if (!defined('SMF')) { |
|
19 | 19 | die('No direct access...'); |
20 | +} |
|
20 | 21 | |
21 | 22 | /** |
22 | 23 | * Creates a wave file that spells the letters of $word. |
@@ -32,8 +33,9 @@ discard block |
||
32 | 33 | global $settings, $user_info; |
33 | 34 | |
34 | 35 | // Allow max 2 requests per 20 seconds. |
35 | - if (($ip = cache_get_data('wave_file/' . $user_info['ip'], 20)) > 2 || ($ip2 = cache_get_data('wave_file/' . $user_info['ip2'], 20)) > 2) |
|
36 | - die(header('HTTP/1.1 400 Bad Request')); |
|
36 | + if (($ip = cache_get_data('wave_file/' . $user_info['ip'], 20)) > 2 || ($ip2 = cache_get_data('wave_file/' . $user_info['ip2'], 20)) > 2) { |
|
37 | + die(header('HTTP/1.1 400 Bad Request')); |
|
38 | + } |
|
37 | 39 | cache_put_data('wave_file/' . $user_info['ip'], $ip ? $ip + 1 : 1, 20); |
38 | 40 | cache_put_data('wave_file/' . $user_info['ip2'], $ip2 ? $ip2 + 1 : 1, 20); |
39 | 41 | |
@@ -41,16 +43,19 @@ discard block |
||
41 | 43 | mt_srand(end(unpack('n', md5($word . session_id())))); |
42 | 44 | |
43 | 45 | // Try to see if there's a sound font in the user's language. |
44 | - if (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.' . $user_info['language'] . '.wav')) |
|
45 | - $sound_language = $user_info['language']; |
|
46 | + if (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.' . $user_info['language'] . '.wav')) { |
|
47 | + $sound_language = $user_info['language']; |
|
48 | + } |
|
46 | 49 | |
47 | 50 | // English should be there. |
48 | - elseif (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.english.wav')) |
|
49 | - $sound_language = 'english'; |
|
51 | + elseif (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.english.wav')) { |
|
52 | + $sound_language = 'english'; |
|
53 | + } |
|
50 | 54 | |
51 | 55 | // Guess not... |
52 | - else |
|
53 | - return false; |
|
56 | + else { |
|
57 | + return false; |
|
58 | + } |
|
54 | 59 | |
55 | 60 | // File names are in lower case so lets make sure that we are only using a lower case string |
56 | 61 | $word = strtolower($word); |
@@ -60,20 +65,25 @@ discard block |
||
60 | 65 | for ($i = 0; $i < strlen($word); $i++) |
61 | 66 | { |
62 | 67 | $sound_letter = implode('', file($settings['default_theme_dir'] . '/fonts/sound/' . $word{$i} . '.' . $sound_language . '.wav')); |
63 | - if (strpos($sound_letter, 'data') === false) |
|
64 | - return false; |
|
68 | + if (strpos($sound_letter, 'data') === false) { |
|
69 | + return false; |
|
70 | + } |
|
65 | 71 | |
66 | 72 | $sound_letter = substr($sound_letter, strpos($sound_letter, 'data') + 8); |
67 | 73 | switch ($word{$i} === 's' ? 0 : mt_rand(0, 2)) |
68 | 74 | { |
69 | - case 0 : for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++) |
|
70 | - for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++) |
|
71 | - $sound_word .= $word{$i} === 's' ? $sound_letter{$j} : chr(mt_rand(max(ord($sound_letter{$j}) - 1, 0x00), min(ord($sound_letter{$j}) + 1, 0xFF))); |
|
75 | + case 0 : for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++) { |
|
76 | + for ($k = 0, $m = round(mt_rand(15, 25) / 10); |
|
77 | + } |
|
78 | + $k < $m; $k++) { |
|
79 | + $sound_word .= $word{$i} === 's' ? $sound_letter{$j} : chr(mt_rand(max(ord($sound_letter{$j}) - 1, 0x00), min(ord($sound_letter{$j}) + 1, 0xFF))); |
|
80 | + } |
|
72 | 81 | break; |
73 | 82 | |
74 | 83 | case 1: |
75 | - for ($j = 0, $n = strlen($sound_letter) - 1; $j < $n; $j += 2) |
|
76 | - $sound_word .= (mt_rand(0, 3) == 0 ? '' : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j + 1} : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j} : $sound_letter{$j + 1}) . $sound_letter{$j + 1} . (mt_rand(0, 3) == 0 ? $sound_letter{$j + 1} : ''); |
|
84 | + for ($j = 0, $n = strlen($sound_letter) - 1; $j < $n; $j += 2) { |
|
85 | + $sound_word .= (mt_rand(0, 3) == 0 ? '' : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j + 1} : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j} : $sound_letter{$j + 1}) . $sound_letter{$j + 1} . (mt_rand(0, 3) == 0 ? $sound_letter{$j + 1} : ''); |
|
86 | + } |
|
77 | 87 | $sound_word .= str_repeat($sound_letter{$n}, 2); |
78 | 88 | break; |
79 | 89 | |
@@ -81,10 +91,12 @@ discard block |
||
81 | 91 | $shift = 0; |
82 | 92 | for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++) |
83 | 93 | { |
84 | - if (mt_rand(0, 10) === 0) |
|
85 | - $shift += mt_rand(-3, 3); |
|
86 | - for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++) |
|
87 | - $sound_word .= chr(min(max(ord($sound_letter{$j}) + $shift, 0x00), 0xFF)); |
|
94 | + if (mt_rand(0, 10) === 0) { |
|
95 | + $shift += mt_rand(-3, 3); |
|
96 | + } |
|
97 | + for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++) { |
|
98 | + $sound_word .= chr(min(max(ord($sound_letter{$j}) + $shift, 0x00), 0xFF)); |
|
99 | + } |
|
88 | 100 | } |
89 | 101 | break; |
90 | 102 |
@@ -15,8 +15,9 @@ discard block |
||
15 | 15 | * @version 2.1 Beta 3 |
16 | 16 | */ |
17 | 17 | |
18 | -if (!defined('SMF')) |
|
18 | +if (!defined('SMF')) { |
|
19 | 19 | die('No direct access...'); |
20 | +} |
|
20 | 21 | |
21 | 22 | /** |
22 | 23 | * Takes a message and parses it, returning nothing. |
@@ -46,17 +47,19 @@ discard block |
||
46 | 47 | $message = preg_replace('~\.{100,}~', '...', $message); |
47 | 48 | |
48 | 49 | // Trim off trailing quotes - these often happen by accident. |
49 | - while (substr($message, -7) == '[quote]') |
|
50 | - $message = substr($message, 0, -7); |
|
51 | - while (substr($message, 0, 8) == '[/quote]') |
|
52 | - $message = substr($message, 8); |
|
50 | + while (substr($message, -7) == '[quote]') { |
|
51 | + $message = substr($message, 0, -7); |
|
52 | + } |
|
53 | + while (substr($message, 0, 8) == '[/quote]') { |
|
54 | + $message = substr($message, 8); |
|
55 | + } |
|
53 | 56 | |
54 | 57 | // Find all code blocks, work out whether we'd be parsing them, then ensure they are all closed. |
55 | 58 | $in_tag = false; |
56 | 59 | $had_tag = false; |
57 | 60 | $codeopen = 0; |
58 | - if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches)) |
|
59 | - foreach ($matches[0] as $index => $dummy) |
|
61 | + if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches)) { |
|
62 | + foreach ($matches[0] as $index => $dummy) |
|
60 | 63 | { |
61 | 64 | // Closing? |
62 | 65 | if (!empty($matches[2][$index])) |
@@ -64,6 +67,7 @@ discard block |
||
64 | 67 | // If it's closing and we're not in a tag we need to open it... |
65 | 68 | if (!$in_tag) |
66 | 69 | $codeopen = true; |
70 | + } |
|
67 | 71 | // Either way we ain't in one any more. |
68 | 72 | $in_tag = false; |
69 | 73 | } |
@@ -72,17 +76,20 @@ discard block |
||
72 | 76 | { |
73 | 77 | $had_tag = true; |
74 | 78 | // If we're in a tag don't do nought! |
75 | - if (!$in_tag) |
|
76 | - $in_tag = true; |
|
79 | + if (!$in_tag) { |
|
80 | + $in_tag = true; |
|
81 | + } |
|
77 | 82 | } |
78 | 83 | } |
79 | 84 | |
80 | 85 | // If we have an open tag, close it. |
81 | - if ($in_tag) |
|
82 | - $message .= '[/code]'; |
|
86 | + if ($in_tag) { |
|
87 | + $message .= '[/code]'; |
|
88 | + } |
|
83 | 89 | // Open any ones that need to be open, only if we've never had a tag. |
84 | - if ($codeopen && !$had_tag) |
|
85 | - $message = '[code]' . $message; |
|
90 | + if ($codeopen && !$had_tag) { |
|
91 | + $message = '[code]' . $message; |
|
92 | + } |
|
86 | 93 | |
87 | 94 | // Now that we've fixed all the code tags, let's fix the img and url tags... |
88 | 95 | $parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $message, -1, PREG_SPLIT_DELIM_CAPTURE); |
@@ -108,23 +115,26 @@ discard block |
||
108 | 115 | fixTags($message); |
109 | 116 | |
110 | 117 | // Replace /me.+?\n with [me=name]dsf[/me]\n. |
111 | - if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false) |
|
112 | - $message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me="' . $user_info['name'] . '"]$2[/me]', $message); |
|
113 | - else |
|
114 | - $message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message); |
|
118 | + if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false) { |
|
119 | + $message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me="' . $user_info['name'] . '"]$2[/me]', $message); |
|
120 | + } else { |
|
121 | + $message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message); |
|
122 | + } |
|
115 | 123 | |
116 | 124 | if (!$previewing && strpos($message, '[html]') !== false) |
117 | 125 | { |
118 | - if (allowedTo('admin_forum')) |
|
119 | - $message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) { |
|
126 | + if (allowedTo('admin_forum')) { |
|
127 | + $message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) { |
|
120 | 128 | return '[html]' . strtr(un_htmlspecialchars($m), array("\n" => ' ', ' ' => '  ', '[' => '[', ']' => ']')) . '[/html]'; |
129 | + } |
|
121 | 130 | }, $message); |
122 | 131 | |
123 | 132 | // We should edit them out, or else if an admin edits the message they will get shown... |
124 | 133 | else |
125 | 134 | { |
126 | - while (strpos($message, '[html]') !== false) |
|
127 | - $message = preg_replace('~\[[/]?html\]~i', '', $message); |
|
135 | + while (strpos($message, '[html]') !== false) { |
|
136 | + $message = preg_replace('~\[[/]?html\]~i', '', $message); |
|
137 | + } |
|
128 | 138 | } |
129 | 139 | } |
130 | 140 | |
@@ -146,10 +156,12 @@ discard block |
||
146 | 156 | |
147 | 157 | $list_open = substr_count($message, '[list]') + substr_count($message, '[list '); |
148 | 158 | $list_close = substr_count($message, '[/list]'); |
149 | - if ($list_close - $list_open > 0) |
|
150 | - $message = str_repeat('[list]', $list_close - $list_open) . $message; |
|
151 | - if ($list_open - $list_close > 0) |
|
152 | - $message = $message . str_repeat('[/list]', $list_open - $list_close); |
|
159 | + if ($list_close - $list_open > 0) { |
|
160 | + $message = str_repeat('[list]', $list_close - $list_open) . $message; |
|
161 | + } |
|
162 | + if ($list_open - $list_close > 0) { |
|
163 | + $message = $message . str_repeat('[/list]', $list_open - $list_close); |
|
164 | + } |
|
153 | 165 | |
154 | 166 | $mistake_fixes = array( |
155 | 167 | // Find [table]s not followed by [tr]. |
@@ -198,8 +210,9 @@ discard block |
||
198 | 210 | ); |
199 | 211 | |
200 | 212 | // Fix up some use of tables without [tr]s, etc. (it has to be done more than once to catch it all.) |
201 | - for ($j = 0; $j < 3; $j++) |
|
202 | - $message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message); |
|
213 | + for ($j = 0; $j < 3; $j++) { |
|
214 | + $message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message); |
|
215 | + } |
|
203 | 216 | |
204 | 217 | // Remove empty bbc from the sections outside the code tags |
205 | 218 | $allowedEmpty = array( |
@@ -209,24 +222,28 @@ discard block |
||
209 | 222 | |
210 | 223 | require_once($sourcedir . '/Subs.php'); |
211 | 224 | |
212 | - foreach (($codes = parse_bbc(false)) as $code) |
|
213 | - if (!in_array($code['tag'], $allowedEmpty)) |
|
225 | + foreach (($codes = parse_bbc(false)) as $code) { |
|
226 | + if (!in_array($code['tag'], $allowedEmpty)) |
|
214 | 227 | $alltags[] = $code['tag']; |
228 | + } |
|
215 | 229 | |
216 | 230 | $alltags_regex = '\b' . implode("\b|\b", array_unique($alltags)) . '\b'; |
217 | 231 | |
218 | - while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message)) |
|
219 | - $message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message); |
|
232 | + while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message)) { |
|
233 | + $message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message); |
|
234 | + } |
|
220 | 235 | |
221 | 236 | // Restore code blocks |
222 | - if (!empty($code_tags)) |
|
223 | - $message = str_replace(array_keys($code_tags), array_values($code_tags), $message); |
|
237 | + if (!empty($code_tags)) { |
|
238 | + $message = str_replace(array_keys($code_tags), array_values($code_tags), $message); |
|
239 | + } |
|
224 | 240 | |
225 | 241 | // Restore white space entities |
226 | - if (!$previewing) |
|
227 | - $message = strtr($message, array(' ' => ' ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => ' ')); |
|
228 | - else |
|
229 | - $message = strtr($message, array(' ' => ' ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => ' ')); |
|
242 | + if (!$previewing) { |
|
243 | + $message = strtr($message, array(' ' => ' ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => ' ')); |
|
244 | + } else { |
|
245 | + $message = strtr($message, array(' ' => ' ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => ' ')); |
|
246 | + } |
|
230 | 247 | |
231 | 248 | // Now let's quickly clean up things that will slow our parser (which are common in posted code.) |
232 | 249 | $message = strtr($message, array('[]' => '[]', '['' => '['')); |
@@ -269,8 +286,9 @@ discard block |
||
269 | 286 | return "[time]" . timeformat("$m[1]", false) . "[/time]"; |
270 | 287 | }, $message); |
271 | 288 | |
272 | - if (!empty($code_tags)) |
|
273 | - $message = str_replace(array_keys($code_tags), array_values($code_tags), $message); |
|
289 | + if (!empty($code_tags)) { |
|
290 | + $message = str_replace(array_keys($code_tags), array_values($code_tags), $message); |
|
291 | + } |
|
274 | 292 | |
275 | 293 | // Change breaks back to \n's and &nsbp; back to spaces. |
276 | 294 | return preg_replace('~<br( /)?' . '>~', "\n", str_replace(' ', ' ', $message)); |
@@ -351,8 +369,9 @@ discard block |
||
351 | 369 | ); |
352 | 370 | |
353 | 371 | // Fix each type of tag. |
354 | - foreach ($fixArray as $param) |
|
355 | - fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra'])); |
|
372 | + foreach ($fixArray as $param) { |
|
373 | + fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra'])); |
|
374 | + } |
|
356 | 375 | |
357 | 376 | // Now fix possible security problems with images loading links automatically... |
358 | 377 | $message = preg_replace_callback('~(\[img.*?\])(.+?)\[/img\]~is', function($m) |
@@ -388,16 +407,19 @@ discard block |
||
388 | 407 | $desired_height = $height; |
389 | 408 | } |
390 | 409 | // Scale it to the width... |
391 | - elseif (empty($desired_width) && !empty($height)) |
|
392 | - $desired_width = (int) (($desired_height * $width) / $height); |
|
410 | + elseif (empty($desired_width) && !empty($height)) { |
|
411 | + $desired_width = (int) (($desired_height * $width) / $height); |
|
412 | + } |
|
393 | 413 | // Scale if to the height. |
394 | - elseif (!empty($width)) |
|
395 | - $desired_height = (int) (($desired_width * $height) / $width); |
|
414 | + elseif (!empty($width)) { |
|
415 | + $desired_height = (int) (($desired_width * $height) / $width); |
|
416 | + } |
|
396 | 417 | } |
397 | 418 | |
398 | 419 | // If the width and height are fine, just continue along... |
399 | - if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height']) |
|
400 | - continue; |
|
420 | + if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height']) { |
|
421 | + continue; |
|
422 | + } |
|
401 | 423 | |
402 | 424 | // Too bad, it's too wide. Make it as wide as the maximum. |
403 | 425 | if ($desired_width > $modSettings['max_image_width'] && !empty($modSettings['max_image_width'])) |
@@ -417,8 +439,9 @@ discard block |
||
417 | 439 | } |
418 | 440 | |
419 | 441 | // If any img tags were actually changed... |
420 | - if (!empty($replaces)) |
|
421 | - $message = strtr($message, $replaces); |
|
442 | + if (!empty($replaces)) { |
|
443 | + $message = strtr($message, $replaces); |
|
444 | + } |
|
422 | 445 | } |
423 | 446 | } |
424 | 447 | |
@@ -437,10 +460,11 @@ discard block |
||
437 | 460 | { |
438 | 461 | global $boardurl, $scripturl; |
439 | 462 | |
440 | - if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0) |
|
441 | - $domain_url = $match[1]; |
|
442 | - else |
|
443 | - $domain_url = $boardurl . '/'; |
|
463 | + if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0) { |
|
464 | + $domain_url = $match[1]; |
|
465 | + } else { |
|
466 | + $domain_url = $boardurl . '/'; |
|
467 | + } |
|
444 | 468 | |
445 | 469 | $replaces = array(); |
446 | 470 | |
@@ -448,11 +472,11 @@ discard block |
||
448 | 472 | { |
449 | 473 | $quoted = preg_match('~\[(' . $myTag . ')="~', $message); |
450 | 474 | preg_match_all('~\[(' . $myTag . ')=' . ($quoted ? '"(.*?)"' : '([^\]]*?)') . '\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches); |
475 | + } elseif ($hasEqualSign) { |
|
476 | + preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches); |
|
477 | + } else { |
|
478 | + preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches); |
|
451 | 479 | } |
452 | - elseif ($hasEqualSign) |
|
453 | - preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches); |
|
454 | - else |
|
455 | - preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches); |
|
456 | 480 | |
457 | 481 | foreach ($matches[0] as $k => $dummy) |
458 | 482 | { |
@@ -465,49 +489,53 @@ discard block |
||
465 | 489 | foreach ($protocols as $protocol) |
466 | 490 | { |
467 | 491 | $found = strncasecmp($replace, $protocol . '://', strlen($protocol) + 3) === 0; |
468 | - if ($found) |
|
469 | - break; |
|
492 | + if ($found) { |
|
493 | + break; |
|
494 | + } |
|
470 | 495 | } |
471 | 496 | |
472 | 497 | if (!$found && $protocols[0] == 'http') |
473 | 498 | { |
474 | - if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//') |
|
475 | - $replace = $domain_url . $replace; |
|
476 | - elseif (substr($replace, 0, 1) == '?') |
|
477 | - $replace = $scripturl . $replace; |
|
478 | - elseif (substr($replace, 0, 1) == '#' && $embeddedUrl) |
|
499 | + if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//') { |
|
500 | + $replace = $domain_url . $replace; |
|
501 | + } elseif (substr($replace, 0, 1) == '?') { |
|
502 | + $replace = $scripturl . $replace; |
|
503 | + } elseif (substr($replace, 0, 1) == '#' && $embeddedUrl) |
|
479 | 504 | { |
480 | 505 | $replace = '#' . preg_replace('~[^A-Za-z0-9_\-#]~', '', substr($replace, 1)); |
481 | 506 | $this_tag = 'iurl'; |
482 | 507 | $this_close = 'iurl'; |
508 | + } elseif (substr($replace, 0, 2) != '//') { |
|
509 | + $replace = $protocols[0] . '://' . $replace; |
|
483 | 510 | } |
484 | - elseif (substr($replace, 0, 2) != '//') |
|
485 | - $replace = $protocols[0] . '://' . $replace; |
|
486 | - } |
|
487 | - elseif (!$found && $protocols[0] == 'ftp') |
|
488 | - $replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace); |
|
489 | - elseif (!$found) |
|
490 | - $replace = $protocols[0] . '://' . $replace; |
|
491 | - |
|
492 | - if ($hasEqualSign && $embeddedUrl) |
|
493 | - $replaces[$matches[0][$k]] = '[' . $this_tag . '="' . $replace . '"]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']'); |
|
494 | - elseif ($hasEqualSign) |
|
495 | - $replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']'; |
|
496 | - elseif ($embeddedUrl) |
|
497 | - $replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']'; |
|
498 | - else |
|
499 | - $replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']'; |
|
511 | + } elseif (!$found && $protocols[0] == 'ftp') { |
|
512 | + $replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace); |
|
513 | + } elseif (!$found) { |
|
514 | + $replace = $protocols[0] . '://' . $replace; |
|
515 | + } |
|
516 | + |
|
517 | + if ($hasEqualSign && $embeddedUrl) { |
|
518 | + $replaces[$matches[0][$k]] = '[' . $this_tag . '="' . $replace . '"]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']'); |
|
519 | + } elseif ($hasEqualSign) { |
|
520 | + $replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']'; |
|
521 | + } elseif ($embeddedUrl) { |
|
522 | + $replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']'; |
|
523 | + } else { |
|
524 | + $replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']'; |
|
525 | + } |
|
500 | 526 | } |
501 | 527 | |
502 | 528 | foreach ($replaces as $k => $v) |
503 | 529 | { |
504 | - if ($k == $v) |
|
505 | - unset($replaces[$k]); |
|
530 | + if ($k == $v) { |
|
531 | + unset($replaces[$k]); |
|
532 | + } |
|
506 | 533 | } |
507 | 534 | |
508 | - if (!empty($replaces)) |
|
509 | - $message = strtr($message, $replaces); |
|
510 | -} |
|
535 | + if (!empty($replaces)) { |
|
536 | + $message = strtr($message, $replaces); |
|
537 | + } |
|
538 | + } |
|
511 | 539 | |
512 | 540 | /** |
513 | 541 | * This function sends an email to the specified recipient(s). |
@@ -551,8 +579,9 @@ discard block |
||
551 | 579 | } |
552 | 580 | |
553 | 581 | // Nothing left? Nothing else to do |
554 | - if (empty($to_array)) |
|
555 | - return true; |
|
582 | + if (empty($to_array)) { |
|
583 | + return true; |
|
584 | + } |
|
556 | 585 | |
557 | 586 | // Once upon a time, Hotmail could not interpret non-ASCII mails. |
558 | 587 | // In honour of those days, it's still called the 'hotmail fix'. |
@@ -569,15 +598,17 @@ discard block |
||
569 | 598 | } |
570 | 599 | |
571 | 600 | // Call this function recursively for the hotmail addresses. |
572 | - if (!empty($hotmail_to)) |
|
573 | - $mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private); |
|
601 | + if (!empty($hotmail_to)) { |
|
602 | + $mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private); |
|
603 | + } |
|
574 | 604 | |
575 | 605 | // The remaining addresses no longer need the fix. |
576 | 606 | $hotmail_fix = false; |
577 | 607 | |
578 | 608 | // No other addresses left? Return instantly. |
579 | - if (empty($to_array)) |
|
580 | - return $mail_result; |
|
609 | + if (empty($to_array)) { |
|
610 | + return $mail_result; |
|
611 | + } |
|
581 | 612 | } |
582 | 613 | |
583 | 614 | // Get rid of entities. |
@@ -602,13 +633,15 @@ discard block |
||
602 | 633 | $headers .= 'Return-Path: ' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . $line_break; |
603 | 634 | $headers .= 'Date: ' . gmdate('D, d M Y H:i:s') . ' -0000' . $line_break; |
604 | 635 | |
605 | - if ($message_id !== null && empty($modSettings['mail_no_message_id'])) |
|
606 | - $headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break; |
|
636 | + if ($message_id !== null && empty($modSettings['mail_no_message_id'])) { |
|
637 | + $headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break; |
|
638 | + } |
|
607 | 639 | $headers .= 'X-Mailer: SMF' . $line_break; |
608 | 640 | |
609 | 641 | // Pass this to the integration before we start modifying the output -- it'll make it easier later. |
610 | - if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true)) |
|
611 | - return false; |
|
642 | + if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true)) { |
|
643 | + return false; |
|
644 | + } |
|
612 | 645 | |
613 | 646 | // Save the original message... |
614 | 647 | $orig_message = $message; |
@@ -657,17 +690,19 @@ discard block |
||
657 | 690 | } |
658 | 691 | |
659 | 692 | // Are we using the mail queue, if so this is where we butt in... |
660 | - if ($priority != 0) |
|
661 | - return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private); |
|
693 | + if ($priority != 0) { |
|
694 | + return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private); |
|
695 | + } |
|
662 | 696 | |
663 | 697 | // If it's a priority mail, send it now - note though that this should NOT be used for sending many at once. |
664 | 698 | elseif (!empty($modSettings['mail_limit'])) |
665 | 699 | { |
666 | 700 | list ($last_mail_time, $mails_this_minute) = @explode('|', $modSettings['mail_recent']); |
667 | - if (empty($mails_this_minute) || time() > $last_mail_time + 60) |
|
668 | - $new_queue_stat = time() . '|' . 1; |
|
669 | - else |
|
670 | - $new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1); |
|
701 | + if (empty($mails_this_minute) || time() > $last_mail_time + 60) { |
|
702 | + $new_queue_stat = time() . '|' . 1; |
|
703 | + } else { |
|
704 | + $new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1); |
|
705 | + } |
|
671 | 706 | |
672 | 707 | updateSettings(array('mail_recent' => $new_queue_stat)); |
673 | 708 | } |
@@ -692,12 +727,13 @@ discard block |
||
692 | 727 | |
693 | 728 | // Wait, wait, I'm still sending here! |
694 | 729 | @set_time_limit(300); |
695 | - if (function_exists('apache_reset_timeout')) |
|
696 | - @apache_reset_timeout(); |
|
730 | + if (function_exists('apache_reset_timeout')) { |
|
731 | + @apache_reset_timeout(); |
|
732 | + } |
|
697 | 733 | } |
734 | + } else { |
|
735 | + $mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers); |
|
698 | 736 | } |
699 | - else |
|
700 | - $mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers); |
|
701 | 737 | |
702 | 738 | // Everything go smoothly? |
703 | 739 | return $mail_result; |
@@ -723,8 +759,9 @@ discard block |
||
723 | 759 | static $cur_insert = array(); |
724 | 760 | static $cur_insert_len = 0; |
725 | 761 | |
726 | - if ($cur_insert_len == 0) |
|
727 | - $cur_insert = array(); |
|
762 | + if ($cur_insert_len == 0) { |
|
763 | + $cur_insert = array(); |
|
764 | + } |
|
728 | 765 | |
729 | 766 | // If we're flushing, make the final inserts - also if we're near the MySQL length limit! |
730 | 767 | if (($flush || $cur_insert_len > 800000) && !empty($cur_insert)) |
@@ -799,8 +836,9 @@ discard block |
||
799 | 836 | } |
800 | 837 | |
801 | 838 | // If they are using SSI there is a good chance obExit will never be called. So lets be nice and flush it for them. |
802 | - if (SMF === 'SSI' || SMF === 'BACKGROUND') |
|
803 | - return AddMailQueue(true); |
|
839 | + if (SMF === 'SSI' || SMF === 'BACKGROUND') { |
|
840 | + return AddMailQueue(true); |
|
841 | + } |
|
804 | 842 | |
805 | 843 | return true; |
806 | 844 | } |
@@ -833,23 +871,26 @@ discard block |
||
833 | 871 | 'sent' => array() |
834 | 872 | ); |
835 | 873 | |
836 | - if ($from === null) |
|
837 | - $from = array( |
|
874 | + if ($from === null) { |
|
875 | + $from = array( |
|
838 | 876 | 'id' => $user_info['id'], |
839 | 877 | 'name' => $user_info['name'], |
840 | 878 | 'username' => $user_info['username'] |
841 | 879 | ); |
880 | + } |
|
842 | 881 | |
843 | 882 | // This is the one that will go in their inbox. |
844 | 883 | $htmlmessage = $smcFunc['htmlspecialchars']($message, ENT_QUOTES); |
845 | 884 | preparsecode($htmlmessage); |
846 | 885 | $htmlsubject = strtr($smcFunc['htmlspecialchars']($subject), array("\r" => '', "\n" => '', "\t" => '')); |
847 | - if ($smcFunc['strlen']($htmlsubject) > 100) |
|
848 | - $htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100); |
|
886 | + if ($smcFunc['strlen']($htmlsubject) > 100) { |
|
887 | + $htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100); |
|
888 | + } |
|
849 | 889 | |
850 | 890 | // Make sure is an array |
851 | - if (!is_array($recipients)) |
|
852 | - $recipients = array($recipients); |
|
891 | + if (!is_array($recipients)) { |
|
892 | + $recipients = array($recipients); |
|
893 | + } |
|
853 | 894 | |
854 | 895 | // Integrated PMs |
855 | 896 | call_integration_hook('integrate_personal_message', array(&$recipients, &$from, &$subject, &$message)); |
@@ -877,21 +918,23 @@ discard block |
||
877 | 918 | 'usernames' => array_keys($usernames), |
878 | 919 | ) |
879 | 920 | ); |
880 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
881 | - if (isset($usernames[$smcFunc['strtolower']($row['member_name'])])) |
|
921 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
922 | + if (isset($usernames[$smcFunc['strtolower']($row['member_name'])])) |
|
882 | 923 | $usernames[$smcFunc['strtolower']($row['member_name'])] = $row['id_member']; |
924 | + } |
|
883 | 925 | $smcFunc['db_free_result']($request); |
884 | 926 | |
885 | 927 | // Replace the usernames with IDs. Drop usernames that couldn't be found. |
886 | - foreach ($recipients as $rec_type => $rec) |
|
887 | - foreach ($rec as $id => $member) |
|
928 | + foreach ($recipients as $rec_type => $rec) { |
|
929 | + foreach ($rec as $id => $member) |
|
888 | 930 | { |
889 | 931 | if (is_numeric($recipients[$rec_type][$id])) |
890 | 932 | continue; |
933 | + } |
|
891 | 934 | |
892 | - if (!empty($usernames[$member])) |
|
893 | - $recipients[$rec_type][$id] = $usernames[$member]; |
|
894 | - else |
|
935 | + if (!empty($usernames[$member])) { |
|
936 | + $recipients[$rec_type][$id] = $usernames[$member]; |
|
937 | + } else |
|
895 | 938 | { |
896 | 939 | $log['failed'][$id] = sprintf($txt['pm_error_user_not_found'], $recipients[$rec_type][$id]); |
897 | 940 | unset($recipients[$rec_type][$id]); |
@@ -930,8 +973,9 @@ discard block |
||
930 | 973 | foreach ($criteria as $criterium) |
931 | 974 | { |
932 | 975 | $match = false; |
933 | - if (($criterium['t'] == 'mid' && $criterium['v'] == $from['id']) || ($criterium['t'] == 'gid' && in_array($criterium['v'], $user_info['groups'])) || ($criterium['t'] == 'sub' && strpos($subject, $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($message, $criterium['v']) !== false)) |
|
934 | - $delete = true; |
|
976 | + if (($criterium['t'] == 'mid' && $criterium['v'] == $from['id']) || ($criterium['t'] == 'gid' && in_array($criterium['v'], $user_info['groups'])) || ($criterium['t'] == 'sub' && strpos($subject, $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($message, $criterium['v']) !== false)) { |
|
977 | + $delete = true; |
|
978 | + } |
|
935 | 979 | // If we're adding and one criteria don't match then we stop! |
936 | 980 | elseif (!$row['is_or']) |
937 | 981 | { |
@@ -939,8 +983,9 @@ discard block |
||
939 | 983 | break; |
940 | 984 | } |
941 | 985 | } |
942 | - if ($delete) |
|
943 | - $deletes[$row['id_member']] = 1; |
|
986 | + if ($delete) { |
|
987 | + $deletes[$row['id_member']] = 1; |
|
988 | + } |
|
944 | 989 | } |
945 | 990 | $smcFunc['db_free_result']($request); |
946 | 991 | |
@@ -955,8 +1000,9 @@ discard block |
||
955 | 1000 | array( |
956 | 1001 | ) |
957 | 1002 | ); |
958 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
959 | - $message_limit_cache[$row['id_group']] = $row['max_messages']; |
|
1003 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1004 | + $message_limit_cache[$row['id_group']] = $row['max_messages']; |
|
1005 | + } |
|
960 | 1006 | $smcFunc['db_free_result']($request); |
961 | 1007 | } |
962 | 1008 | |
@@ -964,8 +1010,9 @@ discard block |
||
964 | 1010 | require_once($sourcedir . '/Subs-Members.php'); |
965 | 1011 | $pmReadGroups = groupsAllowedTo('pm_read'); |
966 | 1012 | |
967 | - if (empty($modSettings['permission_enable_deny'])) |
|
968 | - $pmReadGroups['denied'] = array(); |
|
1013 | + if (empty($modSettings['permission_enable_deny'])) { |
|
1014 | + $pmReadGroups['denied'] = array(); |
|
1015 | + } |
|
969 | 1016 | |
970 | 1017 | // Load their alert preferences |
971 | 1018 | require_once($sourcedir . '/Subs-Notify.php'); |
@@ -997,8 +1044,9 @@ discard block |
||
997 | 1044 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
998 | 1045 | { |
999 | 1046 | // Don't do anything for members to be deleted! |
1000 | - if (isset($deletes[$row['id_member']])) |
|
1001 | - continue; |
|
1047 | + if (isset($deletes[$row['id_member']])) { |
|
1048 | + continue; |
|
1049 | + } |
|
1002 | 1050 | |
1003 | 1051 | // Load the preferences for this member (if any) |
1004 | 1052 | $prefs = !empty($notifyPrefs[$row['id_member']]) ? $notifyPrefs[$row['id_member']] : array(); |
@@ -1019,8 +1067,9 @@ discard block |
||
1019 | 1067 | { |
1020 | 1068 | foreach ($groups as $id) |
1021 | 1069 | { |
1022 | - if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id]) |
|
1023 | - $message_limit = $message_limit_cache[$id]; |
|
1070 | + if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id]) { |
|
1071 | + $message_limit = $message_limit_cache[$id]; |
|
1072 | + } |
|
1024 | 1073 | } |
1025 | 1074 | |
1026 | 1075 | if ($message_limit > 0 && $message_limit <= $row['instant_messages']) |
@@ -1068,8 +1117,9 @@ discard block |
||
1068 | 1117 | $smcFunc['db_free_result']($request); |
1069 | 1118 | |
1070 | 1119 | // Only 'send' the message if there are any recipients left. |
1071 | - if (empty($all_to)) |
|
1072 | - return $log; |
|
1120 | + if (empty($all_to)) { |
|
1121 | + return $log; |
|
1122 | + } |
|
1073 | 1123 | |
1074 | 1124 | // Insert the message itself and then grab the last insert id. |
1075 | 1125 | $smcFunc['db_insert']('', |
@@ -1090,8 +1140,8 @@ discard block |
||
1090 | 1140 | if (!empty($id_pm)) |
1091 | 1141 | { |
1092 | 1142 | // If this is new we need to set it part of it's own conversation. |
1093 | - if (empty($pm_head)) |
|
1094 | - $smcFunc['db_query']('', ' |
|
1143 | + if (empty($pm_head)) { |
|
1144 | + $smcFunc['db_query']('', ' |
|
1095 | 1145 | UPDATE {db_prefix}personal_messages |
1096 | 1146 | SET id_pm_head = {int:id_pm_head} |
1097 | 1147 | WHERE id_pm = {int:id_pm_head}', |
@@ -1099,6 +1149,7 @@ discard block |
||
1099 | 1149 | 'id_pm_head' => $id_pm, |
1100 | 1150 | ) |
1101 | 1151 | ); |
1152 | + } |
|
1102 | 1153 | |
1103 | 1154 | // Some people think manually deleting personal_messages is fun... it's not. We protect against it though :) |
1104 | 1155 | $smcFunc['db_query']('', ' |
@@ -1114,8 +1165,9 @@ discard block |
||
1114 | 1165 | foreach ($all_to as $to) |
1115 | 1166 | { |
1116 | 1167 | $insertRows[] = array($id_pm, $to, in_array($to, $recipients['bcc']) ? 1 : 0, isset($deletes[$to]) ? 1 : 0, 1); |
1117 | - if (!in_array($to, $recipients['bcc'])) |
|
1118 | - $to_list[] = $to; |
|
1168 | + if (!in_array($to, $recipients['bcc'])) { |
|
1169 | + $to_list[] = $to; |
|
1170 | + } |
|
1119 | 1171 | } |
1120 | 1172 | |
1121 | 1173 | $smcFunc['db_insert']('insert', |
@@ -1133,9 +1185,9 @@ discard block |
||
1133 | 1185 | { |
1134 | 1186 | censorText($message); |
1135 | 1187 | $message = trim(un_htmlspecialchars(strip_tags(strtr(parse_bbc($smcFunc['htmlspecialchars']($message), false), array('<br>' => "\n", '</div>' => "\n", '</li>' => "\n", '[' => '[', ']' => ']'))))); |
1188 | + } else { |
|
1189 | + $message = ''; |
|
1136 | 1190 | } |
1137 | - else |
|
1138 | - $message = ''; |
|
1139 | 1191 | |
1140 | 1192 | $to_names = array(); |
1141 | 1193 | if (count($to_list) > 1) |
@@ -1148,8 +1200,9 @@ discard block |
||
1148 | 1200 | 'to_members' => $to_list, |
1149 | 1201 | ) |
1150 | 1202 | ); |
1151 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1152 | - $to_names[] = un_htmlspecialchars($row['real_name']); |
|
1203 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1204 | + $to_names[] = un_htmlspecialchars($row['real_name']); |
|
1205 | + } |
|
1153 | 1206 | $smcFunc['db_free_result']($request); |
1154 | 1207 | } |
1155 | 1208 | $replacements = array( |
@@ -1177,11 +1230,13 @@ discard block |
||
1177 | 1230 | loadLanguage('index+PersonalMessage'); |
1178 | 1231 | |
1179 | 1232 | // Add one to their unread and read message counts. |
1180 | - foreach ($all_to as $k => $id) |
|
1181 | - if (isset($deletes[$id])) |
|
1233 | + foreach ($all_to as $k => $id) { |
|
1234 | + if (isset($deletes[$id])) |
|
1182 | 1235 | unset($all_to[$k]); |
1183 | - if (!empty($all_to)) |
|
1184 | - updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1)); |
|
1236 | + } |
|
1237 | + if (!empty($all_to)) { |
|
1238 | + updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1)); |
|
1239 | + } |
|
1185 | 1240 | |
1186 | 1241 | return $log; |
1187 | 1242 | } |
@@ -1211,15 +1266,17 @@ discard block |
||
1211 | 1266 | // Let's, for now, assume there are only 'ish characters. |
1212 | 1267 | $simple = true; |
1213 | 1268 | |
1214 | - foreach ($matches[1] as $entity) |
|
1215 | - if ($entity > 128) |
|
1269 | + foreach ($matches[1] as $entity) { |
|
1270 | + if ($entity > 128) |
|
1216 | 1271 | $simple = false; |
1272 | + } |
|
1217 | 1273 | unset($matches); |
1218 | 1274 | |
1219 | - if ($simple) |
|
1220 | - $string = preg_replace_callback('~&#(\d{3,8});~', function($m) |
|
1275 | + if ($simple) { |
|
1276 | + $string = preg_replace_callback('~&#(\d{3,8});~', function($m) |
|
1221 | 1277 | { |
1222 | 1278 | return chr("$m[1]"); |
1279 | + } |
|
1223 | 1280 | }, $string); |
1224 | 1281 | else |
1225 | 1282 | { |
@@ -1227,8 +1284,9 @@ discard block |
||
1227 | 1284 | if (!$context['utf8'] && function_exists('iconv')) |
1228 | 1285 | { |
1229 | 1286 | $newstring = @iconv($context['character_set'], 'UTF-8', $string); |
1230 | - if ($newstring) |
|
1231 | - $string = $newstring; |
|
1287 | + if ($newstring) { |
|
1288 | + $string = $newstring; |
|
1289 | + } |
|
1232 | 1290 | } |
1233 | 1291 | |
1234 | 1292 | $string = preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $string); |
@@ -1244,23 +1302,25 @@ discard block |
||
1244 | 1302 | if (!$context['utf8'] && function_exists('iconv')) |
1245 | 1303 | { |
1246 | 1304 | $newstring = @iconv($context['character_set'], 'UTF-8', $string); |
1247 | - if ($newstring) |
|
1248 | - $string = $newstring; |
|
1305 | + if ($newstring) { |
|
1306 | + $string = $newstring; |
|
1307 | + } |
|
1249 | 1308 | } |
1250 | 1309 | |
1251 | 1310 | $entityConvert = function($m) |
1252 | 1311 | { |
1253 | 1312 | $c = $m[1]; |
1254 | - if (strlen($c) === 1 && ord($c[0]) <= 0x7F) |
|
1255 | - return $c; |
|
1256 | - elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF) |
|
1257 | - return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";"; |
|
1258 | - elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF) |
|
1259 | - return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";"; |
|
1260 | - elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7) |
|
1261 | - return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";"; |
|
1262 | - else |
|
1263 | - return ""; |
|
1313 | + if (strlen($c) === 1 && ord($c[0]) <= 0x7F) { |
|
1314 | + return $c; |
|
1315 | + } elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF) { |
|
1316 | + return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";"; |
|
1317 | + } elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF) { |
|
1318 | + return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";"; |
|
1319 | + } elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7) { |
|
1320 | + return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";"; |
|
1321 | + } else { |
|
1322 | + return ""; |
|
1323 | + } |
|
1264 | 1324 | }; |
1265 | 1325 | |
1266 | 1326 | // Convert all 'special' characters to HTML entities. |
@@ -1274,19 +1334,20 @@ discard block |
||
1274 | 1334 | $string = base64_encode($string); |
1275 | 1335 | |
1276 | 1336 | // Show the characterset and the transfer-encoding for header strings. |
1277 | - if ($with_charset) |
|
1278 | - $string = '=?' . $charset . '?B?' . $string . '?='; |
|
1337 | + if ($with_charset) { |
|
1338 | + $string = '=?' . $charset . '?B?' . $string . '?='; |
|
1339 | + } |
|
1279 | 1340 | |
1280 | 1341 | // Break it up in lines (mail body). |
1281 | - else |
|
1282 | - $string = chunk_split($string, 76, $line_break); |
|
1342 | + else { |
|
1343 | + $string = chunk_split($string, 76, $line_break); |
|
1344 | + } |
|
1283 | 1345 | |
1284 | 1346 | return array($charset, $string, 'base64'); |
1347 | + } else { |
|
1348 | + return array($charset, $string, '7bit'); |
|
1349 | + } |
|
1285 | 1350 | } |
1286 | - |
|
1287 | - else |
|
1288 | - return array($charset, $string, '7bit'); |
|
1289 | -} |
|
1290 | 1351 | |
1291 | 1352 | /** |
1292 | 1353 | * Sends mail, like mail() but over SMTP. |
@@ -1310,8 +1371,9 @@ discard block |
||
1310 | 1371 | if ($modSettings['mail_type'] == 3 && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '') |
1311 | 1372 | { |
1312 | 1373 | $socket = fsockopen($modSettings['smtp_host'], 110, $errno, $errstr, 2); |
1313 | - if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.')) |
|
1314 | - $socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2); |
|
1374 | + if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.')) { |
|
1375 | + $socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2); |
|
1376 | + } |
|
1315 | 1377 | |
1316 | 1378 | if ($socket) |
1317 | 1379 | { |
@@ -1332,8 +1394,9 @@ discard block |
||
1332 | 1394 | // Maybe we can still save this? The port might be wrong. |
1333 | 1395 | if (substr($modSettings['smtp_host'], 0, 4) == 'ssl:' && (empty($modSettings['smtp_port']) || $modSettings['smtp_port'] == 25)) |
1334 | 1396 | { |
1335 | - if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) |
|
1336 | - log_error($txt['smtp_port_ssl']); |
|
1397 | + if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) { |
|
1398 | + log_error($txt['smtp_port_ssl']); |
|
1399 | + } |
|
1337 | 1400 | } |
1338 | 1401 | |
1339 | 1402 | // Unable to connect! Don't show any error message, but just log one and try to continue anyway. |
@@ -1345,20 +1408,23 @@ discard block |
||
1345 | 1408 | } |
1346 | 1409 | |
1347 | 1410 | // Wait for a response of 220, without "-" continuer. |
1348 | - if (!server_parse(null, $socket, '220')) |
|
1349 | - return false; |
|
1411 | + if (!server_parse(null, $socket, '220')) { |
|
1412 | + return false; |
|
1413 | + } |
|
1350 | 1414 | |
1351 | 1415 | // Try and determine the servers name, fall back to the mail servers if not found |
1352 | 1416 | $helo = false; |
1353 | - if (function_exists('gethostname') && gethostname() !== false) |
|
1354 | - $helo = gethostname(); |
|
1355 | - elseif (function_exists('php_uname')) |
|
1356 | - $helo = php_uname('n'); |
|
1357 | - elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME'])) |
|
1358 | - $helo = $_SERVER['SERVER_NAME']; |
|
1417 | + if (function_exists('gethostname') && gethostname() !== false) { |
|
1418 | + $helo = gethostname(); |
|
1419 | + } elseif (function_exists('php_uname')) { |
|
1420 | + $helo = php_uname('n'); |
|
1421 | + } elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME'])) { |
|
1422 | + $helo = $_SERVER['SERVER_NAME']; |
|
1423 | + } |
|
1359 | 1424 | |
1360 | - if (empty($helo)) |
|
1361 | - $helo = $modSettings['smtp_host']; |
|
1425 | + if (empty($helo)) { |
|
1426 | + $helo = $modSettings['smtp_host']; |
|
1427 | + } |
|
1362 | 1428 | |
1363 | 1429 | // SMTP = 1, SMTP - STARTTLS = 2 |
1364 | 1430 | if (in_array($modSettings['mail_type'], array(1, 2)) && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '') |
@@ -1370,33 +1436,39 @@ discard block |
||
1370 | 1436 | if ($modSettings['mail_type'] == 2 && preg_match("~250( |-)STARTTLS~mi", $response)) |
1371 | 1437 | { |
1372 | 1438 | // Send STARTTLS to enable encryption |
1373 | - if (!server_parse('STARTTLS', $socket, '220')) |
|
1374 | - return false; |
|
1439 | + if (!server_parse('STARTTLS', $socket, '220')) { |
|
1440 | + return false; |
|
1441 | + } |
|
1375 | 1442 | // Enable the encryption |
1376 | - if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) |
|
1377 | - return false; |
|
1443 | + if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { |
|
1444 | + return false; |
|
1445 | + } |
|
1378 | 1446 | // Send the EHLO command again |
1379 | - if (!server_parse('EHLO ' . $helo, $socket, null) == '250') |
|
1380 | - return false; |
|
1447 | + if (!server_parse('EHLO ' . $helo, $socket, null) == '250') { |
|
1448 | + return false; |
|
1449 | + } |
|
1381 | 1450 | } |
1382 | 1451 | |
1383 | - if (!server_parse('AUTH LOGIN', $socket, '334')) |
|
1384 | - return false; |
|
1452 | + if (!server_parse('AUTH LOGIN', $socket, '334')) { |
|
1453 | + return false; |
|
1454 | + } |
|
1385 | 1455 | // Send the username and password, encoded. |
1386 | - if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) |
|
1387 | - return false; |
|
1456 | + if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) { |
|
1457 | + return false; |
|
1458 | + } |
|
1388 | 1459 | // The password is already encoded ;) |
1389 | - if (!server_parse($modSettings['smtp_password'], $socket, '235')) |
|
1390 | - return false; |
|
1460 | + if (!server_parse($modSettings['smtp_password'], $socket, '235')) { |
|
1461 | + return false; |
|
1462 | + } |
|
1463 | + } elseif (!server_parse('HELO ' . $helo, $socket, '250')) { |
|
1464 | + return false; |
|
1391 | 1465 | } |
1392 | - elseif (!server_parse('HELO ' . $helo, $socket, '250')) |
|
1393 | - return false; |
|
1394 | - } |
|
1395 | - else |
|
1466 | + } else |
|
1396 | 1467 | { |
1397 | 1468 | // Just say "helo". |
1398 | - if (!server_parse('HELO ' . $helo, $socket, '250')) |
|
1399 | - return false; |
|
1469 | + if (!server_parse('HELO ' . $helo, $socket, '250')) { |
|
1470 | + return false; |
|
1471 | + } |
|
1400 | 1472 | } |
1401 | 1473 | |
1402 | 1474 | // Fix the message for any lines beginning with a period! (the first is ignored, you see.) |
@@ -1409,31 +1481,38 @@ discard block |
||
1409 | 1481 | // Reset the connection to send another email. |
1410 | 1482 | if ($i != 0) |
1411 | 1483 | { |
1412 | - if (!server_parse('RSET', $socket, '250')) |
|
1413 | - return false; |
|
1484 | + if (!server_parse('RSET', $socket, '250')) { |
|
1485 | + return false; |
|
1486 | + } |
|
1414 | 1487 | } |
1415 | 1488 | |
1416 | 1489 | // From, to, and then start the data... |
1417 | - if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) |
|
1418 | - return false; |
|
1419 | - if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) |
|
1420 | - return false; |
|
1421 | - if (!server_parse('DATA', $socket, '354')) |
|
1422 | - return false; |
|
1490 | + if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) { |
|
1491 | + return false; |
|
1492 | + } |
|
1493 | + if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) { |
|
1494 | + return false; |
|
1495 | + } |
|
1496 | + if (!server_parse('DATA', $socket, '354')) { |
|
1497 | + return false; |
|
1498 | + } |
|
1423 | 1499 | fputs($socket, 'Subject: ' . $subject . "\r\n"); |
1424 | - if (strlen($mail_to) > 0) |
|
1425 | - fputs($socket, 'To: <' . $mail_to . '>' . "\r\n"); |
|
1500 | + if (strlen($mail_to) > 0) { |
|
1501 | + fputs($socket, 'To: <' . $mail_to . '>' . "\r\n"); |
|
1502 | + } |
|
1426 | 1503 | fputs($socket, $headers . "\r\n\r\n"); |
1427 | 1504 | fputs($socket, $message . "\r\n"); |
1428 | 1505 | |
1429 | 1506 | // Send a ., or in other words "end of data". |
1430 | - if (!server_parse('.', $socket, '250')) |
|
1431 | - return false; |
|
1507 | + if (!server_parse('.', $socket, '250')) { |
|
1508 | + return false; |
|
1509 | + } |
|
1432 | 1510 | |
1433 | 1511 | // Almost done, almost done... don't stop me just yet! |
1434 | 1512 | @set_time_limit(300); |
1435 | - if (function_exists('apache_reset_timeout')) |
|
1436 | - @apache_reset_timeout(); |
|
1513 | + if (function_exists('apache_reset_timeout')) { |
|
1514 | + @apache_reset_timeout(); |
|
1515 | + } |
|
1437 | 1516 | } |
1438 | 1517 | fputs($socket, 'QUIT' . "\r\n"); |
1439 | 1518 | fclose($socket); |
@@ -1457,8 +1536,9 @@ discard block |
||
1457 | 1536 | { |
1458 | 1537 | global $txt; |
1459 | 1538 | |
1460 | - if ($message !== null) |
|
1461 | - fputs($socket, $message . "\r\n"); |
|
1539 | + if ($message !== null) { |
|
1540 | + fputs($socket, $message . "\r\n"); |
|
1541 | + } |
|
1462 | 1542 | |
1463 | 1543 | // No response yet. |
1464 | 1544 | $server_response = ''; |
@@ -1474,8 +1554,9 @@ discard block |
||
1474 | 1554 | $response .= $server_response; |
1475 | 1555 | } |
1476 | 1556 | |
1477 | - if ($code === null) |
|
1478 | - return substr($server_response, 0, 3); |
|
1557 | + if ($code === null) { |
|
1558 | + return substr($server_response, 0, 3); |
|
1559 | + } |
|
1479 | 1560 | |
1480 | 1561 | if (substr($server_response, 0, 3) != $code) |
1481 | 1562 | { |
@@ -1505,8 +1586,9 @@ discard block |
||
1505 | 1586 | // Create a pspell or enchant dictionary resource |
1506 | 1587 | $dict = spell_init(); |
1507 | 1588 | |
1508 | - if (!isset($_POST['spellstring']) || !$dict) |
|
1509 | - die; |
|
1589 | + if (!isset($_POST['spellstring']) || !$dict) { |
|
1590 | + die; |
|
1591 | + } |
|
1510 | 1592 | |
1511 | 1593 | // Construct a bit of Javascript code. |
1512 | 1594 | $context['spell_js'] = ' |
@@ -1524,8 +1606,9 @@ discard block |
||
1524 | 1606 | $check_word = explode('|', $alphas[$i]); |
1525 | 1607 | |
1526 | 1608 | // If the word is a known word, or spelled right... |
1527 | - if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) |
|
1528 | - continue; |
|
1609 | + if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) { |
|
1610 | + continue; |
|
1611 | + } |
|
1529 | 1612 | |
1530 | 1613 | // Find the word, and move up the "last occurrence" to here. |
1531 | 1614 | $found_words = true; |
@@ -1539,20 +1622,23 @@ discard block |
||
1539 | 1622 | if (!empty($suggestions)) |
1540 | 1623 | { |
1541 | 1624 | // But first check they aren't going to be censored - no naughty words! |
1542 | - foreach ($suggestions as $k => $word) |
|
1543 | - if ($suggestions[$k] != censorText($word)) |
|
1625 | + foreach ($suggestions as $k => $word) { |
|
1626 | + if ($suggestions[$k] != censorText($word)) |
|
1544 | 1627 | unset($suggestions[$k]); |
1628 | + } |
|
1545 | 1629 | |
1546 | - if (!empty($suggestions)) |
|
1547 | - $context['spell_js'] .= '"' . implode('", "', $suggestions) . '"'; |
|
1630 | + if (!empty($suggestions)) { |
|
1631 | + $context['spell_js'] .= '"' . implode('", "', $suggestions) . '"'; |
|
1632 | + } |
|
1548 | 1633 | } |
1549 | 1634 | |
1550 | 1635 | $context['spell_js'] .= ']),'; |
1551 | 1636 | } |
1552 | 1637 | |
1553 | 1638 | // If words were found, take off the last comma. |
1554 | - if ($found_words) |
|
1555 | - $context['spell_js'] = substr($context['spell_js'], 0, -1); |
|
1639 | + if ($found_words) { |
|
1640 | + $context['spell_js'] = substr($context['spell_js'], 0, -1); |
|
1641 | + } |
|
1556 | 1642 | |
1557 | 1643 | $context['spell_js'] .= ' |
1558 | 1644 | );'; |
@@ -1587,11 +1673,13 @@ discard block |
||
1587 | 1673 | global $user_info, $smcFunc; |
1588 | 1674 | |
1589 | 1675 | // Can't do it if there's no topics. |
1590 | - if (empty($topics)) |
|
1591 | - return; |
|
1676 | + if (empty($topics)) { |
|
1677 | + return; |
|
1678 | + } |
|
1592 | 1679 | // It must be an array - it must! |
1593 | - if (!is_array($topics)) |
|
1594 | - $topics = array($topics); |
|
1680 | + if (!is_array($topics)) { |
|
1681 | + $topics = array($topics); |
|
1682 | + } |
|
1595 | 1683 | |
1596 | 1684 | // Get the subject and body... |
1597 | 1685 | $result = $smcFunc['db_query']('', ' |
@@ -1639,14 +1727,15 @@ discard block |
||
1639 | 1727 | } |
1640 | 1728 | $smcFunc['db_free_result']($result); |
1641 | 1729 | |
1642 | - if (!empty($task_rows)) |
|
1643 | - $smcFunc['db_insert']('', |
|
1730 | + if (!empty($task_rows)) { |
|
1731 | + $smcFunc['db_insert']('', |
|
1644 | 1732 | '{db_prefix}background_tasks', |
1645 | 1733 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
1646 | 1734 | $task_rows, |
1647 | 1735 | array('id_task') |
1648 | 1736 | ); |
1649 | -} |
|
1737 | + } |
|
1738 | + } |
|
1650 | 1739 | |
1651 | 1740 | /** |
1652 | 1741 | * Create a post, either as new topic (id_topic = 0) or in an existing one. |
@@ -1684,9 +1773,9 @@ discard block |
||
1684 | 1773 | $msgOptions['send_notifications'] = isset($msgOptions['send_notifications']) ? (bool) $msgOptions['send_notifications'] : true; |
1685 | 1774 | |
1686 | 1775 | // We need to know if the topic is approved. If we're told that's great - if not find out. |
1687 | - if (!$modSettings['postmod_active']) |
|
1688 | - $topicOptions['is_approved'] = true; |
|
1689 | - elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved'])) |
|
1776 | + if (!$modSettings['postmod_active']) { |
|
1777 | + $topicOptions['is_approved'] = true; |
|
1778 | + } elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved'])) |
|
1690 | 1779 | { |
1691 | 1780 | $request = $smcFunc['db_query']('', ' |
1692 | 1781 | SELECT approved |
@@ -1709,8 +1798,7 @@ discard block |
||
1709 | 1798 | $posterOptions['id'] = 0; |
1710 | 1799 | $posterOptions['name'] = $txt['guest_title']; |
1711 | 1800 | $posterOptions['email'] = ''; |
1712 | - } |
|
1713 | - elseif ($posterOptions['id'] != $user_info['id']) |
|
1801 | + } elseif ($posterOptions['id'] != $user_info['id']) |
|
1714 | 1802 | { |
1715 | 1803 | $request = $smcFunc['db_query']('', ' |
1716 | 1804 | SELECT member_name, email_address |
@@ -1728,12 +1816,11 @@ discard block |
||
1728 | 1816 | $posterOptions['id'] = 0; |
1729 | 1817 | $posterOptions['name'] = $txt['guest_title']; |
1730 | 1818 | $posterOptions['email'] = ''; |
1819 | + } else { |
|
1820 | + list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request); |
|
1731 | 1821 | } |
1732 | - else |
|
1733 | - list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request); |
|
1734 | 1822 | $smcFunc['db_free_result']($request); |
1735 | - } |
|
1736 | - else |
|
1823 | + } else |
|
1737 | 1824 | { |
1738 | 1825 | $posterOptions['name'] = $user_info['name']; |
1739 | 1826 | $posterOptions['email'] = $user_info['email']; |
@@ -1743,8 +1830,9 @@ discard block |
||
1743 | 1830 | if (!empty($modSettings['enable_mentions'])) |
1744 | 1831 | { |
1745 | 1832 | $msgOptions['mentioned_members'] = Mentions::getMentionedMembers($msgOptions['body']); |
1746 | - if (!empty($msgOptions['mentioned_members'])) |
|
1747 | - $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']); |
|
1833 | + if (!empty($msgOptions['mentioned_members'])) { |
|
1834 | + $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']); |
|
1835 | + } |
|
1748 | 1836 | } |
1749 | 1837 | |
1750 | 1838 | // It's do or die time: forget any user aborts! |
@@ -1777,12 +1865,13 @@ discard block |
||
1777 | 1865 | $msgOptions['id'] = $smcFunc['db_insert_id']('{db_prefix}messages', 'id_msg'); |
1778 | 1866 | |
1779 | 1867 | // Something went wrong creating the message... |
1780 | - if (empty($msgOptions['id'])) |
|
1781 | - return false; |
|
1868 | + if (empty($msgOptions['id'])) { |
|
1869 | + return false; |
|
1870 | + } |
|
1782 | 1871 | |
1783 | 1872 | // Fix the attachments. |
1784 | - if (!empty($msgOptions['attachments'])) |
|
1785 | - $smcFunc['db_query']('', ' |
|
1873 | + if (!empty($msgOptions['attachments'])) { |
|
1874 | + $smcFunc['db_query']('', ' |
|
1786 | 1875 | UPDATE {db_prefix}attachments |
1787 | 1876 | SET id_msg = {int:id_msg} |
1788 | 1877 | WHERE id_attach IN ({array_int:attachment_list})', |
@@ -1791,6 +1880,7 @@ discard block |
||
1791 | 1880 | 'id_msg' => $msgOptions['id'], |
1792 | 1881 | ) |
1793 | 1882 | ); |
1883 | + } |
|
1794 | 1884 | |
1795 | 1885 | // What if we want to export new posts out to a CMS? |
1796 | 1886 | call_integration_hook('integrate_after_create_post', array($msgOptions, $topicOptions, $posterOptions, $message_columns, $message_parameters)); |
@@ -1868,20 +1958,23 @@ discard block |
||
1868 | 1958 | 'counter_increment' => 1, |
1869 | 1959 | ); |
1870 | 1960 | $topics_columns = array(); |
1871 | - if ($msgOptions['approved']) |
|
1872 | - $topics_columns = array( |
|
1961 | + if ($msgOptions['approved']) { |
|
1962 | + $topics_columns = array( |
|
1873 | 1963 | 'id_member_updated = {int:poster_id}', |
1874 | 1964 | 'id_last_msg = {int:id_msg}', |
1875 | 1965 | 'num_replies = num_replies + {int:counter_increment}', |
1876 | 1966 | ); |
1877 | - else |
|
1878 | - $topics_columns = array( |
|
1967 | + } else { |
|
1968 | + $topics_columns = array( |
|
1879 | 1969 | 'unapproved_posts = unapproved_posts + {int:counter_increment}', |
1880 | 1970 | ); |
1881 | - if ($topicOptions['lock_mode'] !== null) |
|
1882 | - $topics_columns[] = 'locked = {int:locked}'; |
|
1883 | - if ($topicOptions['sticky_mode'] !== null) |
|
1884 | - $topics_columns[] = 'is_sticky = {int:is_sticky}'; |
|
1971 | + } |
|
1972 | + if ($topicOptions['lock_mode'] !== null) { |
|
1973 | + $topics_columns[] = 'locked = {int:locked}'; |
|
1974 | + } |
|
1975 | + if ($topicOptions['sticky_mode'] !== null) { |
|
1976 | + $topics_columns[] = 'is_sticky = {int:is_sticky}'; |
|
1977 | + } |
|
1885 | 1978 | |
1886 | 1979 | call_integration_hook('integrate_modify_topic', array(&$topics_columns, &$update_parameters, &$msgOptions, &$topicOptions, &$posterOptions)); |
1887 | 1980 | |
@@ -1910,8 +2003,8 @@ discard block |
||
1910 | 2003 | ); |
1911 | 2004 | |
1912 | 2005 | // Increase the number of posts and topics on the board. |
1913 | - if ($msgOptions['approved']) |
|
1914 | - $smcFunc['db_query']('', ' |
|
2006 | + if ($msgOptions['approved']) { |
|
2007 | + $smcFunc['db_query']('', ' |
|
1915 | 2008 | UPDATE {db_prefix}boards |
1916 | 2009 | SET num_posts = num_posts + 1' . ($new_topic ? ', num_topics = num_topics + 1' : '') . ' |
1917 | 2010 | WHERE id_board = {int:id_board}', |
@@ -1919,7 +2012,7 @@ discard block |
||
1919 | 2012 | 'id_board' => $topicOptions['board'], |
1920 | 2013 | ) |
1921 | 2014 | ); |
1922 | - else |
|
2015 | + } else |
|
1923 | 2016 | { |
1924 | 2017 | $smcFunc['db_query']('', ' |
1925 | 2018 | UPDATE {db_prefix}boards |
@@ -1989,8 +2082,8 @@ discard block |
||
1989 | 2082 | } |
1990 | 2083 | } |
1991 | 2084 | |
1992 | - if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) |
|
1993 | - $smcFunc['db_insert']('', |
|
2085 | + if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) { |
|
2086 | + $smcFunc['db_insert']('', |
|
1994 | 2087 | '{db_prefix}background_tasks', |
1995 | 2088 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
1996 | 2089 | array( |
@@ -2002,19 +2095,22 @@ discard block |
||
2002 | 2095 | ), |
2003 | 2096 | array('id_task') |
2004 | 2097 | ); |
2098 | + } |
|
2005 | 2099 | |
2006 | 2100 | // If there's a custom search index, it may need updating... |
2007 | 2101 | require_once($sourcedir . '/Search.php'); |
2008 | 2102 | $searchAPI = findSearchAPI(); |
2009 | - if (is_callable(array($searchAPI, 'postCreated'))) |
|
2010 | - $searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions); |
|
2103 | + if (is_callable(array($searchAPI, 'postCreated'))) { |
|
2104 | + $searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions); |
|
2105 | + } |
|
2011 | 2106 | |
2012 | 2107 | // Increase the post counter for the user that created the post. |
2013 | 2108 | if (!empty($posterOptions['update_post_count']) && !empty($posterOptions['id']) && $msgOptions['approved']) |
2014 | 2109 | { |
2015 | 2110 | // Are you the one that happened to create this post? |
2016 | - if ($user_info['id'] == $posterOptions['id']) |
|
2017 | - $user_info['posts']++; |
|
2111 | + if ($user_info['id'] == $posterOptions['id']) { |
|
2112 | + $user_info['posts']++; |
|
2113 | + } |
|
2018 | 2114 | updateMemberData($posterOptions['id'], array('posts' => '+')); |
2019 | 2115 | } |
2020 | 2116 | |
@@ -2022,19 +2118,21 @@ discard block |
||
2022 | 2118 | $_SESSION['last_read_topic'] = 0; |
2023 | 2119 | |
2024 | 2120 | // Better safe than sorry. |
2025 | - if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) |
|
2026 | - $_SESSION['topicseen_cache'][$topicOptions['board']]--; |
|
2121 | + if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) { |
|
2122 | + $_SESSION['topicseen_cache'][$topicOptions['board']]--; |
|
2123 | + } |
|
2027 | 2124 | |
2028 | 2125 | // Update all the stats so everyone knows about this new topic and message. |
2029 | 2126 | updateStats('message', true, $msgOptions['id']); |
2030 | 2127 | |
2031 | 2128 | // Update the last message on the board assuming it's approved AND the topic is. |
2032 | - if ($msgOptions['approved']) |
|
2033 | - updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0); |
|
2129 | + if ($msgOptions['approved']) { |
|
2130 | + updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0); |
|
2131 | + } |
|
2034 | 2132 | |
2035 | 2133 | // Queue createPost background notification |
2036 | - if ($msgOptions['send_notifications'] && $msgOptions['approved']) |
|
2037 | - $smcFunc['db_insert']('', |
|
2134 | + if ($msgOptions['send_notifications'] && $msgOptions['approved']) { |
|
2135 | + $smcFunc['db_insert']('', |
|
2038 | 2136 | '{db_prefix}background_tasks', |
2039 | 2137 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
2040 | 2138 | array('$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', json_encode(array( |
@@ -2045,6 +2143,7 @@ discard block |
||
2045 | 2143 | )), 0), |
2046 | 2144 | array('id_task') |
2047 | 2145 | ); |
2146 | + } |
|
2048 | 2147 | |
2049 | 2148 | // Alright, done now... we can abort now, I guess... at least this much is done. |
2050 | 2149 | ignore_user_abort($previous_ignore_user_abort); |
@@ -2071,14 +2170,18 @@ discard block |
||
2071 | 2170 | |
2072 | 2171 | // This is longer than it has to be, but makes it so we only set/change what we have to. |
2073 | 2172 | $messages_columns = array(); |
2074 | - if (isset($posterOptions['name'])) |
|
2075 | - $messages_columns['poster_name'] = $posterOptions['name']; |
|
2076 | - if (isset($posterOptions['email'])) |
|
2077 | - $messages_columns['poster_email'] = $posterOptions['email']; |
|
2078 | - if (isset($msgOptions['icon'])) |
|
2079 | - $messages_columns['icon'] = $msgOptions['icon']; |
|
2080 | - if (isset($msgOptions['subject'])) |
|
2081 | - $messages_columns['subject'] = $msgOptions['subject']; |
|
2173 | + if (isset($posterOptions['name'])) { |
|
2174 | + $messages_columns['poster_name'] = $posterOptions['name']; |
|
2175 | + } |
|
2176 | + if (isset($posterOptions['email'])) { |
|
2177 | + $messages_columns['poster_email'] = $posterOptions['email']; |
|
2178 | + } |
|
2179 | + if (isset($msgOptions['icon'])) { |
|
2180 | + $messages_columns['icon'] = $msgOptions['icon']; |
|
2181 | + } |
|
2182 | + if (isset($msgOptions['subject'])) { |
|
2183 | + $messages_columns['subject'] = $msgOptions['subject']; |
|
2184 | + } |
|
2082 | 2185 | if (isset($msgOptions['body'])) |
2083 | 2186 | { |
2084 | 2187 | $messages_columns['body'] = $msgOptions['body']; |
@@ -2105,8 +2208,9 @@ discard block |
||
2105 | 2208 | $messages_columns['modified_reason'] = $msgOptions['modify_reason']; |
2106 | 2209 | $messages_columns['id_msg_modified'] = $modSettings['maxMsgID']; |
2107 | 2210 | } |
2108 | - if (isset($msgOptions['smileys_enabled'])) |
|
2109 | - $messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1; |
|
2211 | + if (isset($msgOptions['smileys_enabled'])) { |
|
2212 | + $messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1; |
|
2213 | + } |
|
2110 | 2214 | |
2111 | 2215 | // Which columns need to be ints? |
2112 | 2216 | $messageInts = array('modified_time', 'id_msg_modified', 'smileys_enabled'); |
@@ -2124,23 +2228,27 @@ discard block |
||
2124 | 2228 | { |
2125 | 2229 | preg_match_all('/\[member\=([0-9]+)\]([^\[]*)\[\/member\]/U', $msgOptions['old_body'], $match); |
2126 | 2230 | |
2127 | - if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) |
|
2128 | - foreach ($match[1] as $i => $oldID) |
|
2231 | + if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) { |
|
2232 | + foreach ($match[1] as $i => $oldID) |
|
2129 | 2233 | $oldmentions[$oldID] = array('id' => $oldID, 'real_name' => $match[2][$i]); |
2234 | + } |
|
2130 | 2235 | |
2131 | - if (empty($modSettings['search_custom_index_config'])) |
|
2132 | - unset($msgOptions['old_body']); |
|
2236 | + if (empty($modSettings['search_custom_index_config'])) { |
|
2237 | + unset($msgOptions['old_body']); |
|
2238 | + } |
|
2133 | 2239 | } |
2134 | 2240 | |
2135 | 2241 | $mentions = Mentions::getMentionedMembers($msgOptions['body']); |
2136 | 2242 | $messages_columns['body'] = $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $mentions); |
2137 | 2243 | |
2138 | 2244 | // Remove the poster. |
2139 | - if (isset($mentions[$user_info['id']])) |
|
2140 | - unset($mentions[$user_info['id']]); |
|
2245 | + if (isset($mentions[$user_info['id']])) { |
|
2246 | + unset($mentions[$user_info['id']]); |
|
2247 | + } |
|
2141 | 2248 | |
2142 | - if (isset($oldmentions[$user_info['id']])) |
|
2143 | - unset($oldmentions[$user_info['id']]); |
|
2249 | + if (isset($oldmentions[$user_info['id']])) { |
|
2250 | + unset($oldmentions[$user_info['id']]); |
|
2251 | + } |
|
2144 | 2252 | |
2145 | 2253 | if (is_array($mentions) && is_array($oldmentions) && count(array_diff_key($mentions, $oldmentions)) > 0 && count($mentions) > count($oldmentions)) |
2146 | 2254 | { |
@@ -2170,8 +2278,9 @@ discard block |
||
2170 | 2278 | } |
2171 | 2279 | |
2172 | 2280 | // Nothing to do? |
2173 | - if (empty($messages_columns)) |
|
2174 | - return true; |
|
2281 | + if (empty($messages_columns)) { |
|
2282 | + return true; |
|
2283 | + } |
|
2175 | 2284 | |
2176 | 2285 | // Change the post. |
2177 | 2286 | $smcFunc['db_query']('', ' |
@@ -2232,8 +2341,9 @@ discard block |
||
2232 | 2341 | // If there's a custom search index, it needs to be modified... |
2233 | 2342 | require_once($sourcedir . '/Search.php'); |
2234 | 2343 | $searchAPI = findSearchAPI(); |
2235 | - if (is_callable(array($searchAPI, 'postModified'))) |
|
2236 | - $searchAPI->postModified($msgOptions, $topicOptions, $posterOptions); |
|
2344 | + if (is_callable(array($searchAPI, 'postModified'))) { |
|
2345 | + $searchAPI->postModified($msgOptions, $topicOptions, $posterOptions); |
|
2346 | + } |
|
2237 | 2347 | |
2238 | 2348 | if (isset($msgOptions['subject'])) |
2239 | 2349 | { |
@@ -2247,14 +2357,16 @@ discard block |
||
2247 | 2357 | 'id_first_msg' => $msgOptions['id'], |
2248 | 2358 | ) |
2249 | 2359 | ); |
2250 | - if ($smcFunc['db_num_rows']($request) == 1) |
|
2251 | - updateStats('subject', $topicOptions['id'], $msgOptions['subject']); |
|
2360 | + if ($smcFunc['db_num_rows']($request) == 1) { |
|
2361 | + updateStats('subject', $topicOptions['id'], $msgOptions['subject']); |
|
2362 | + } |
|
2252 | 2363 | $smcFunc['db_free_result']($request); |
2253 | 2364 | } |
2254 | 2365 | |
2255 | 2366 | // Finally, if we are setting the approved state we need to do much more work :( |
2256 | - if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) |
|
2257 | - approvePosts($msgOptions['id'], $msgOptions['approved']); |
|
2367 | + if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) { |
|
2368 | + approvePosts($msgOptions['id'], $msgOptions['approved']); |
|
2369 | + } |
|
2258 | 2370 | |
2259 | 2371 | return true; |
2260 | 2372 | } |
@@ -2271,11 +2383,13 @@ discard block |
||
2271 | 2383 | { |
2272 | 2384 | global $smcFunc; |
2273 | 2385 | |
2274 | - if (!is_array($msgs)) |
|
2275 | - $msgs = array($msgs); |
|
2386 | + if (!is_array($msgs)) { |
|
2387 | + $msgs = array($msgs); |
|
2388 | + } |
|
2276 | 2389 | |
2277 | - if (empty($msgs)) |
|
2278 | - return false; |
|
2390 | + if (empty($msgs)) { |
|
2391 | + return false; |
|
2392 | + } |
|
2279 | 2393 | |
2280 | 2394 | // May as well start at the beginning, working out *what* we need to change. |
2281 | 2395 | $request = $smcFunc['db_query']('', ' |
@@ -2307,20 +2421,22 @@ discard block |
||
2307 | 2421 | $topics[] = $row['id_topic']; |
2308 | 2422 | |
2309 | 2423 | // Ensure our change array exists already. |
2310 | - if (!isset($topic_changes[$row['id_topic']])) |
|
2311 | - $topic_changes[$row['id_topic']] = array( |
|
2424 | + if (!isset($topic_changes[$row['id_topic']])) { |
|
2425 | + $topic_changes[$row['id_topic']] = array( |
|
2312 | 2426 | 'id_last_msg' => $row['id_last_msg'], |
2313 | 2427 | 'approved' => $row['topic_approved'], |
2314 | 2428 | 'replies' => 0, |
2315 | 2429 | 'unapproved_posts' => 0, |
2316 | 2430 | ); |
2317 | - if (!isset($board_changes[$row['id_board']])) |
|
2318 | - $board_changes[$row['id_board']] = array( |
|
2431 | + } |
|
2432 | + if (!isset($board_changes[$row['id_board']])) { |
|
2433 | + $board_changes[$row['id_board']] = array( |
|
2319 | 2434 | 'posts' => 0, |
2320 | 2435 | 'topics' => 0, |
2321 | 2436 | 'unapproved_posts' => 0, |
2322 | 2437 | 'unapproved_topics' => 0, |
2323 | 2438 | ); |
2439 | + } |
|
2324 | 2440 | |
2325 | 2441 | // If it's the first message then the topic state changes! |
2326 | 2442 | if ($row['id_msg'] == $row['id_first_msg']) |
@@ -2341,14 +2457,13 @@ discard block |
||
2341 | 2457 | 'poster' => $row['id_member'], |
2342 | 2458 | 'new_topic' => true, |
2343 | 2459 | ); |
2344 | - } |
|
2345 | - else |
|
2460 | + } else |
|
2346 | 2461 | { |
2347 | 2462 | $topic_changes[$row['id_topic']]['replies'] += $approve ? 1 : -1; |
2348 | 2463 | |
2349 | 2464 | // This will be a post... but don't notify unless it's not followed by approved ones. |
2350 | - if ($row['id_msg'] > $row['id_last_msg']) |
|
2351 | - $notification_posts[$row['id_topic']] = array( |
|
2465 | + if ($row['id_msg'] > $row['id_last_msg']) { |
|
2466 | + $notification_posts[$row['id_topic']] = array( |
|
2352 | 2467 | 'id' => $row['id_msg'], |
2353 | 2468 | 'body' => $row['body'], |
2354 | 2469 | 'subject' => $row['subject'], |
@@ -2359,28 +2474,33 @@ discard block |
||
2359 | 2474 | 'new_topic' => false, |
2360 | 2475 | 'msg' => $row['id_msg'], |
2361 | 2476 | ); |
2477 | + } |
|
2362 | 2478 | } |
2363 | 2479 | |
2364 | 2480 | // If this is being approved and id_msg is higher than the current id_last_msg then it changes. |
2365 | - if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) |
|
2366 | - $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg']; |
|
2481 | + if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) { |
|
2482 | + $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg']; |
|
2483 | + } |
|
2367 | 2484 | // If this is being unapproved, and it's equal to the id_last_msg we need to find a new one! |
2368 | - elseif (!$approve) |
|
2369 | - // Default to the first message and then we'll override in a bit ;) |
|
2485 | + elseif (!$approve) { |
|
2486 | + // Default to the first message and then we'll override in a bit ;) |
|
2370 | 2487 | $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_first_msg']; |
2488 | + } |
|
2371 | 2489 | |
2372 | 2490 | $topic_changes[$row['id_topic']]['unapproved_posts'] += $approve ? -1 : 1; |
2373 | 2491 | $board_changes[$row['id_board']]['unapproved_posts'] += $approve ? -1 : 1; |
2374 | 2492 | $board_changes[$row['id_board']]['posts'] += $approve ? 1 : -1; |
2375 | 2493 | |
2376 | 2494 | // Post count for the user? |
2377 | - if ($row['id_member'] && empty($row['count_posts'])) |
|
2378 | - $member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1; |
|
2495 | + if ($row['id_member'] && empty($row['count_posts'])) { |
|
2496 | + $member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1; |
|
2497 | + } |
|
2379 | 2498 | } |
2380 | 2499 | $smcFunc['db_free_result']($request); |
2381 | 2500 | |
2382 | - if (empty($msgs)) |
|
2383 | - return; |
|
2501 | + if (empty($msgs)) { |
|
2502 | + return; |
|
2503 | + } |
|
2384 | 2504 | |
2385 | 2505 | // Now we have the differences make the changes, first the easy one. |
2386 | 2506 | $smcFunc['db_query']('', ' |
@@ -2407,14 +2527,15 @@ discard block |
||
2407 | 2527 | 'approved' => 1, |
2408 | 2528 | ) |
2409 | 2529 | ); |
2410 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2411 | - $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg']; |
|
2530 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2531 | + $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg']; |
|
2532 | + } |
|
2412 | 2533 | $smcFunc['db_free_result']($request); |
2413 | 2534 | } |
2414 | 2535 | |
2415 | 2536 | // ... next the topics... |
2416 | - foreach ($topic_changes as $id => $changes) |
|
2417 | - $smcFunc['db_query']('', ' |
|
2537 | + foreach ($topic_changes as $id => $changes) { |
|
2538 | + $smcFunc['db_query']('', ' |
|
2418 | 2539 | UPDATE {db_prefix}topics |
2419 | 2540 | SET approved = {int:approved}, unapproved_posts = unapproved_posts + {int:unapproved_posts}, |
2420 | 2541 | num_replies = num_replies + {int:num_replies}, id_last_msg = {int:id_last_msg} |
@@ -2427,10 +2548,11 @@ discard block |
||
2427 | 2548 | 'id_topic' => $id, |
2428 | 2549 | ) |
2429 | 2550 | ); |
2551 | + } |
|
2430 | 2552 | |
2431 | 2553 | // ... finally the boards... |
2432 | - foreach ($board_changes as $id => $changes) |
|
2433 | - $smcFunc['db_query']('', ' |
|
2554 | + foreach ($board_changes as $id => $changes) { |
|
2555 | + $smcFunc['db_query']('', ' |
|
2434 | 2556 | UPDATE {db_prefix}boards |
2435 | 2557 | SET num_posts = num_posts + {int:num_posts}, unapproved_posts = unapproved_posts + {int:unapproved_posts}, |
2436 | 2558 | num_topics = num_topics + {int:num_topics}, unapproved_topics = unapproved_topics + {int:unapproved_topics} |
@@ -2443,13 +2565,14 @@ discard block |
||
2443 | 2565 | 'id_board' => $id, |
2444 | 2566 | ) |
2445 | 2567 | ); |
2568 | + } |
|
2446 | 2569 | |
2447 | 2570 | // Finally, least importantly, notifications! |
2448 | 2571 | if ($approve) |
2449 | 2572 | { |
2450 | 2573 | $task_rows = array(); |
2451 | - foreach (array_merge($notification_topics, $notification_posts) as $topic) |
|
2452 | - $task_rows[] = array( |
|
2574 | + foreach (array_merge($notification_topics, $notification_posts) as $topic) { |
|
2575 | + $task_rows[] = array( |
|
2453 | 2576 | '$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', json_encode(array( |
2454 | 2577 | 'msgOptions' => array( |
2455 | 2578 | 'id' => $topic['msg'], |
@@ -2467,14 +2590,16 @@ discard block |
||
2467 | 2590 | 'type' => $topic['new_topic'] ? 'topic' : 'reply', |
2468 | 2591 | )), 0 |
2469 | 2592 | ); |
2593 | + } |
|
2470 | 2594 | |
2471 | - if ($notify) |
|
2472 | - $smcFunc['db_insert']('', |
|
2595 | + if ($notify) { |
|
2596 | + $smcFunc['db_insert']('', |
|
2473 | 2597 | '{db_prefix}background_tasks', |
2474 | 2598 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
2475 | 2599 | $task_rows, |
2476 | 2600 | array('id_task') |
2477 | 2601 | ); |
2602 | + } |
|
2478 | 2603 | |
2479 | 2604 | $smcFunc['db_query']('', ' |
2480 | 2605 | DELETE FROM {db_prefix}approval_queue |
@@ -2490,8 +2615,9 @@ discard block |
||
2490 | 2615 | else |
2491 | 2616 | { |
2492 | 2617 | $msgInserts = array(); |
2493 | - foreach ($msgs as $msg) |
|
2494 | - $msgInserts[] = array($msg); |
|
2618 | + foreach ($msgs as $msg) { |
|
2619 | + $msgInserts[] = array($msg); |
|
2620 | + } |
|
2495 | 2621 | |
2496 | 2622 | $smcFunc['db_insert']('ignore', |
2497 | 2623 | '{db_prefix}approval_queue', |
@@ -2505,9 +2631,10 @@ discard block |
||
2505 | 2631 | updateLastMessages(array_keys($board_changes)); |
2506 | 2632 | |
2507 | 2633 | // Post count for the members? |
2508 | - if (!empty($member_post_changes)) |
|
2509 | - foreach ($member_post_changes as $id_member => $count_change) |
|
2634 | + if (!empty($member_post_changes)) { |
|
2635 | + foreach ($member_post_changes as $id_member => $count_change) |
|
2510 | 2636 | updateMemberData($id_member, array('posts' => 'posts ' . ($approve ? '+' : '-') . ' ' . $count_change)); |
2637 | + } |
|
2511 | 2638 | |
2512 | 2639 | return true; |
2513 | 2640 | } |
@@ -2524,11 +2651,13 @@ discard block |
||
2524 | 2651 | { |
2525 | 2652 | global $smcFunc; |
2526 | 2653 | |
2527 | - if (!is_array($topics)) |
|
2528 | - $topics = array($topics); |
|
2654 | + if (!is_array($topics)) { |
|
2655 | + $topics = array($topics); |
|
2656 | + } |
|
2529 | 2657 | |
2530 | - if (empty($topics)) |
|
2531 | - return false; |
|
2658 | + if (empty($topics)) { |
|
2659 | + return false; |
|
2660 | + } |
|
2532 | 2661 | |
2533 | 2662 | $approve_type = $approve ? 0 : 1; |
2534 | 2663 | |
@@ -2544,8 +2673,9 @@ discard block |
||
2544 | 2673 | ) |
2545 | 2674 | ); |
2546 | 2675 | $msgs = array(); |
2547 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2548 | - $msgs[] = $row['id_msg']; |
|
2676 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2677 | + $msgs[] = $row['id_msg']; |
|
2678 | + } |
|
2549 | 2679 | $smcFunc['db_free_result']($request); |
2550 | 2680 | |
2551 | 2681 | return approvePosts($msgs, $approve); |
@@ -2568,11 +2698,13 @@ discard block |
||
2568 | 2698 | global $board_info, $board, $smcFunc; |
2569 | 2699 | |
2570 | 2700 | // Please - let's be sane. |
2571 | - if (empty($setboards)) |
|
2572 | - return false; |
|
2701 | + if (empty($setboards)) { |
|
2702 | + return false; |
|
2703 | + } |
|
2573 | 2704 | |
2574 | - if (!is_array($setboards)) |
|
2575 | - $setboards = array($setboards); |
|
2705 | + if (!is_array($setboards)) { |
|
2706 | + $setboards = array($setboards); |
|
2707 | + } |
|
2576 | 2708 | |
2577 | 2709 | // If we don't know the id_msg we need to find it. |
2578 | 2710 | if (!$id_msg) |
@@ -2590,15 +2722,16 @@ discard block |
||
2590 | 2722 | ) |
2591 | 2723 | ); |
2592 | 2724 | $lastMsg = array(); |
2593 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2594 | - $lastMsg[$row['id_board']] = $row['id_msg']; |
|
2725 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2726 | + $lastMsg[$row['id_board']] = $row['id_msg']; |
|
2727 | + } |
|
2595 | 2728 | $smcFunc['db_free_result']($request); |
2596 | - } |
|
2597 | - else |
|
2729 | + } else |
|
2598 | 2730 | { |
2599 | 2731 | // Just to note - there should only be one board passed if we are doing this. |
2600 | - foreach ($setboards as $id_board) |
|
2601 | - $lastMsg[$id_board] = $id_msg; |
|
2732 | + foreach ($setboards as $id_board) { |
|
2733 | + $lastMsg[$id_board] = $id_msg; |
|
2734 | + } |
|
2602 | 2735 | } |
2603 | 2736 | |
2604 | 2737 | $parent_boards = array(); |
@@ -2613,10 +2746,11 @@ discard block |
||
2613 | 2746 | $lastModified[$id_board] = 0; |
2614 | 2747 | } |
2615 | 2748 | |
2616 | - if (!empty($board) && $id_board == $board) |
|
2617 | - $parents = $board_info['parent_boards']; |
|
2618 | - else |
|
2619 | - $parents = getBoardParents($id_board); |
|
2749 | + if (!empty($board) && $id_board == $board) { |
|
2750 | + $parents = $board_info['parent_boards']; |
|
2751 | + } else { |
|
2752 | + $parents = getBoardParents($id_board); |
|
2753 | + } |
|
2620 | 2754 | |
2621 | 2755 | // Ignore any parents on the top child level. |
2622 | 2756 | // @todo Why? |
@@ -2625,10 +2759,11 @@ discard block |
||
2625 | 2759 | if ($parent['level'] != 0) |
2626 | 2760 | { |
2627 | 2761 | // If we're already doing this one as a board, is this a higher last modified? |
2628 | - if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) |
|
2629 | - $lastModified[$id] = $lastModified[$id_board]; |
|
2630 | - elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) |
|
2631 | - $parent_boards[$id] = $lastModified[$id_board]; |
|
2762 | + if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) { |
|
2763 | + $lastModified[$id] = $lastModified[$id_board]; |
|
2764 | + } elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) { |
|
2765 | + $parent_boards[$id] = $lastModified[$id_board]; |
|
2766 | + } |
|
2632 | 2767 | } |
2633 | 2768 | } |
2634 | 2769 | } |
@@ -2641,23 +2776,24 @@ discard block |
||
2641 | 2776 | // Finally, to save on queries make the changes... |
2642 | 2777 | foreach ($parent_boards as $id => $msg) |
2643 | 2778 | { |
2644 | - if (!isset($parent_updates[$msg])) |
|
2645 | - $parent_updates[$msg] = array($id); |
|
2646 | - else |
|
2647 | - $parent_updates[$msg][] = $id; |
|
2779 | + if (!isset($parent_updates[$msg])) { |
|
2780 | + $parent_updates[$msg] = array($id); |
|
2781 | + } else { |
|
2782 | + $parent_updates[$msg][] = $id; |
|
2783 | + } |
|
2648 | 2784 | } |
2649 | 2785 | |
2650 | 2786 | foreach ($lastMsg as $id => $msg) |
2651 | 2787 | { |
2652 | - if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) |
|
2653 | - $board_updates[$msg . '-' . $lastModified[$id]] = array( |
|
2788 | + if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) { |
|
2789 | + $board_updates[$msg . '-' . $lastModified[$id]] = array( |
|
2654 | 2790 | 'id' => $msg, |
2655 | 2791 | 'updated' => $lastModified[$id], |
2656 | 2792 | 'boards' => array($id) |
2657 | 2793 | ); |
2658 | - |
|
2659 | - else |
|
2660 | - $board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id; |
|
2794 | + } else { |
|
2795 | + $board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id; |
|
2796 | + } |
|
2661 | 2797 | } |
2662 | 2798 | |
2663 | 2799 | // Now commit the changes! |
@@ -2749,11 +2885,13 @@ discard block |
||
2749 | 2885 | global $txt, $mbname, $scripturl, $settings; |
2750 | 2886 | |
2751 | 2887 | // First things first, load up the email templates language file, if we need to. |
2752 | - if ($loadLang) |
|
2753 | - loadLanguage('EmailTemplates', $lang); |
|
2888 | + if ($loadLang) { |
|
2889 | + loadLanguage('EmailTemplates', $lang); |
|
2890 | + } |
|
2754 | 2891 | |
2755 | - if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) |
|
2756 | - fatal_lang_error('email_no_template', 'template', array($template)); |
|
2892 | + if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) { |
|
2893 | + fatal_lang_error('email_no_template', 'template', array($template)); |
|
2894 | + } |
|
2757 | 2895 | |
2758 | 2896 | $ret = array( |
2759 | 2897 | 'subject' => $txt[$template . '_subject'], |
@@ -2803,17 +2941,18 @@ discard block |
||
2803 | 2941 | function user_info_callback($matches) |
2804 | 2942 | { |
2805 | 2943 | global $user_info; |
2806 | - if (empty($matches[1])) |
|
2807 | - return ''; |
|
2944 | + if (empty($matches[1])) { |
|
2945 | + return ''; |
|
2946 | + } |
|
2808 | 2947 | |
2809 | 2948 | $use_ref = true; |
2810 | 2949 | $ref = &$user_info; |
2811 | 2950 | |
2812 | 2951 | foreach (explode('.', $matches[1]) as $index) |
2813 | 2952 | { |
2814 | - if ($use_ref && isset($ref[$index])) |
|
2815 | - $ref = &$ref[$index]; |
|
2816 | - else |
|
2953 | + if ($use_ref && isset($ref[$index])) { |
|
2954 | + $ref = &$ref[$index]; |
|
2955 | + } else |
|
2817 | 2956 | { |
2818 | 2957 | $use_ref = false; |
2819 | 2958 | break; |
@@ -2850,8 +2989,7 @@ discard block |
||
2850 | 2989 | if (!empty($lang_locale) && enchant_broker_dict_exists($context['enchant_broker'], $lang_locale)) |
2851 | 2990 | { |
2852 | 2991 | $enchant_link = enchant_broker_request_dict($context['enchant_broker'], $lang_locale); |
2853 | - } |
|
2854 | - elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary'])) |
|
2992 | + } elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary'])) |
|
2855 | 2993 | { |
2856 | 2994 | $enchant_link = enchant_broker_request_dict($context['enchant_broker'], $txt['lang_dictionary']); |
2857 | 2995 | } |
@@ -2861,8 +2999,7 @@ discard block |
||
2861 | 2999 | { |
2862 | 3000 | $context['provider'] = 'enchant'; |
2863 | 3001 | return $enchant_link; |
2864 | - } |
|
2865 | - else |
|
3002 | + } else |
|
2866 | 3003 | { |
2867 | 3004 | // Free up any resources used... |
2868 | 3005 | @enchant_broker_free($context['enchant_broker']); |
@@ -2883,8 +3020,9 @@ discard block |
||
2883 | 3020 | $pspell_link = pspell_new($txt['lang_dictionary'], $txt['lang_spelling'], '', strtr($context['character_set'], array('iso-' => 'iso', 'ISO-' => 'iso')), PSPELL_FAST | PSPELL_RUN_TOGETHER); |
2884 | 3021 | |
2885 | 3022 | // Most people don't have anything but English installed... So we use English as a last resort. |
2886 | - if (!$pspell_link) |
|
2887 | - $pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER); |
|
3023 | + if (!$pspell_link) { |
|
3024 | + $pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER); |
|
3025 | + } |
|
2888 | 3026 | |
2889 | 3027 | error_reporting($old); |
2890 | 3028 | ob_end_clean(); |
@@ -2924,8 +3062,7 @@ discard block |
||
2924 | 3062 | $word = iconv($txt['lang_character_set'], 'UTF-8', $word); |
2925 | 3063 | } |
2926 | 3064 | return enchant_dict_check($dict, $word); |
2927 | - } |
|
2928 | - elseif ($context['provider'] == 'pspell') |
|
3065 | + } elseif ($context['provider'] == 'pspell') |
|
2929 | 3066 | { |
2930 | 3067 | return pspell_check($dict, $word); |
2931 | 3068 | } |
@@ -2961,13 +3098,11 @@ discard block |
||
2961 | 3098 | } |
2962 | 3099 | |
2963 | 3100 | return $suggestions; |
2964 | - } |
|
2965 | - else |
|
3101 | + } else |
|
2966 | 3102 | { |
2967 | 3103 | return enchant_dict_suggest($dict, $word); |
2968 | 3104 | } |
2969 | - } |
|
2970 | - elseif ($context['provider'] == 'pspell') |
|
3105 | + } elseif ($context['provider'] == 'pspell') |
|
2971 | 3106 | { |
2972 | 3107 | return pspell_suggest($dict, $word); |
2973 | 3108 | } |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
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(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(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 = smf_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 => $action) |
993 | 1034 | { |
994 | - if ($action['type'] == 'failure') |
|
995 | - $failed_steps[] = array( |
|
1035 | + if ($action['type'] == 'failure') { |
|
1036 | + $failed_steps[] = array( |
|
996 | 1037 | 'file' => $action['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($action['is_custom'])) |
|
1004 | - $themes_installed[] = $action['is_custom']; |
|
1045 | + if (!empty($action['is_custom'])) { |
|
1046 | + $themes_installed[] = $action['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 = 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'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
2178 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
2179 | + $modSettings['attachmentUploadDir'] = smf_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 = smf_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(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'] = smf_json_decode(base64_decode($_POST['toProcess']), true); |
|
2558 | + if (isset($_POST['toProcess'])) { |
|
2559 | + $_POST['permStatus'] = smf_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(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(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,26 +2617,27 @@ 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... |
2526 | 2635 | unset($context['to_process'][$path]); |
2527 | 2636 | |
2528 | 2637 | // See if we're out of time? |
2529 | - if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit) |
|
2530 | - return false; |
|
2638 | + if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit) { |
|
2639 | + return false; |
|
2640 | + } |
|
2531 | 2641 | } |
2532 | 2642 | } |
2533 | 2643 | // If predefined this is a little different. |
@@ -2595,23 +2705,27 @@ discard block |
||
2595 | 2705 | { |
2596 | 2706 | global $context; |
2597 | 2707 | |
2598 | - if (!empty($data['writable_on'])) |
|
2599 | - if ($context['predefined_type'] == 'standard' || $data['writable_on'] == 'restrictive') |
|
2708 | + if (!empty($data['writable_on'])) { |
|
2709 | + if ($context['predefined_type'] == 'standard' || $data['writable_on'] == 'restrictive') |
|
2600 | 2710 | $context['special_files'][$path] = 1; |
2711 | + } |
|
2601 | 2712 | |
2602 | - if (!empty($data['contents'])) |
|
2603 | - foreach ($data['contents'] as $name => $contents) |
|
2713 | + if (!empty($data['contents'])) { |
|
2714 | + foreach ($data['contents'] as $name => $contents) |
|
2604 | 2715 | build_special_files__recursive($path . '/' . $name, $contents); |
2716 | + } |
|
2605 | 2717 | } |
2606 | 2718 | |
2607 | - foreach ($context['file_tree'] as $path => $data) |
|
2608 | - build_special_files__recursive($path, $data); |
|
2719 | + foreach ($context['file_tree'] as $path => $data) { |
|
2720 | + build_special_files__recursive($path, $data); |
|
2721 | + } |
|
2609 | 2722 | } |
2610 | 2723 | // Free doesn't need special files. |
2611 | - elseif ($context['predefined_type'] == 'free') |
|
2612 | - $context['special_files'] = array(); |
|
2613 | - else |
|
2614 | - $context['special_files'] = smf_json_decode(base64_decode($_POST['specialFiles']), true); |
|
2724 | + elseif ($context['predefined_type'] == 'free') { |
|
2725 | + $context['special_files'] = array(); |
|
2726 | + } else { |
|
2727 | + $context['special_files'] = smf_json_decode(base64_decode($_POST['specialFiles']), true); |
|
2728 | + } |
|
2615 | 2729 | |
2616 | 2730 | // Now we definitely know where we are, we need to go through again doing the chmod! |
2617 | 2731 | foreach ($context['directory_list'] as $path => $dummy) |
@@ -2656,8 +2770,9 @@ discard block |
||
2656 | 2770 | unset($context['directory_list'][$path]); |
2657 | 2771 | |
2658 | 2772 | // See if we're out of time? |
2659 | - if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit) |
|
2660 | - return false; |
|
2773 | + if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit) { |
|
2774 | + return false; |
|
2775 | + } |
|
2661 | 2776 | } |
2662 | 2777 | } |
2663 | 2778 |