@@ -243,6 +243,7 @@ |
||
243 | 243 | * @param null|array The groups to remove the member(s) from. If null, the specified members are stripped from all their membergroups. |
244 | 244 | * @param bool $permissionCheckDone Whether we've already checked permissions prior to calling this function |
245 | 245 | * @param bool $ignoreProtected Whether to ignore protected groups |
246 | + * @param integer $groups |
|
246 | 247 | * @return bool Whether the operation was successful |
247 | 248 | */ |
248 | 249 | function removeMembersFromGroups($members, $groups = null, $permissionCheckDone = false, $ignoreProtected = false) |
@@ -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 | * Delete one of more membergroups. |
@@ -31,15 +32,16 @@ discard block |
||
31 | 32 | global $smcFunc, $modSettings, $txt; |
32 | 33 | |
33 | 34 | // Make sure it's an array. |
34 | - if (!is_array($groups)) |
|
35 | - $groups = array((int) $groups); |
|
36 | - else |
|
35 | + if (!is_array($groups)) { |
|
36 | + $groups = array((int) $groups); |
|
37 | + } else |
|
37 | 38 | { |
38 | 39 | $groups = array_unique($groups); |
39 | 40 | |
40 | 41 | // Make sure all groups are integer. |
41 | - foreach ($groups as $key => $value) |
|
42 | - $groups[$key] = (int) $value; |
|
42 | + foreach ($groups as $key => $value) { |
|
43 | + $groups[$key] = (int) $value; |
|
44 | + } |
|
43 | 45 | } |
44 | 46 | |
45 | 47 | // Some groups are protected (guests, administrators, moderators, newbies). |
@@ -56,15 +58,17 @@ discard block |
||
56 | 58 | 'is_protected' => 1, |
57 | 59 | ) |
58 | 60 | ); |
59 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
60 | - $protected_groups[] = $row['id_group']; |
|
61 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
62 | + $protected_groups[] = $row['id_group']; |
|
63 | + } |
|
61 | 64 | $smcFunc['db_free_result']($request); |
62 | 65 | } |
63 | 66 | |
64 | 67 | // Make sure they don't delete protected groups! |
65 | 68 | $groups = array_diff($groups, array_unique($protected_groups)); |
66 | - if (empty($groups)) |
|
67 | - return 'no_group_found'; |
|
69 | + if (empty($groups)) { |
|
70 | + return 'no_group_found'; |
|
71 | + } |
|
68 | 72 | |
69 | 73 | // Make sure they don't try to delete a group attached to a paid subscription. |
70 | 74 | $subscriptions = array(); |
@@ -74,13 +78,14 @@ discard block |
||
74 | 78 | ORDER BY name'); |
75 | 79 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
76 | 80 | { |
77 | - if (in_array($row['id_group'], $groups)) |
|
78 | - $subscriptions[] = $row['name']; |
|
79 | - else |
|
81 | + if (in_array($row['id_group'], $groups)) { |
|
82 | + $subscriptions[] = $row['name']; |
|
83 | + } else |
|
80 | 84 | { |
81 | 85 | $add_groups = explode(',', $row['add_groups']); |
82 | - if (count(array_intersect($add_groups, $groups)) != 0) |
|
83 | - $subscriptions[] = $row['name']; |
|
86 | + if (count(array_intersect($add_groups, $groups)) != 0) { |
|
87 | + $subscriptions[] = $row['name']; |
|
88 | + } |
|
84 | 89 | } |
85 | 90 | } |
86 | 91 | $smcFunc['db_free_result']($request); |
@@ -101,8 +106,9 @@ discard block |
||
101 | 106 | 'group_list' => $groups, |
102 | 107 | ) |
103 | 108 | ); |
104 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
105 | - logAction('delete_group', array('group' => $row['group_name']), 'admin'); |
|
109 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
110 | + logAction('delete_group', array('group' => $row['group_name']), 'admin'); |
|
111 | + } |
|
106 | 112 | $smcFunc['db_free_result']($request); |
107 | 113 | |
108 | 114 | call_integration_hook('integrate_delete_membergroups', array($groups)); |
@@ -187,12 +193,14 @@ discard block |
||
187 | 193 | ) |
188 | 194 | ); |
189 | 195 | $updates = array(); |
190 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
191 | - $updates[$row['additional_groups']][] = $row['id_member']; |
|
196 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
197 | + $updates[$row['additional_groups']][] = $row['id_member']; |
|
198 | + } |
|
192 | 199 | $smcFunc['db_free_result']($request); |
193 | 200 | |
194 | - foreach ($updates as $additional_groups => $memberArray) |
|
195 | - updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), $groups)))); |
|
201 | + foreach ($updates as $additional_groups => $memberArray) { |
|
202 | + updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), $groups)))); |
|
203 | + } |
|
196 | 204 | |
197 | 205 | // No boards can provide access to these membergroups anymore. |
198 | 206 | $request = $smcFunc['db_query']('', ' |
@@ -204,12 +212,13 @@ discard block |
||
204 | 212 | ) |
205 | 213 | ); |
206 | 214 | $updates = array(); |
207 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
208 | - $updates[$row['member_groups']][] = $row['id_board']; |
|
215 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
216 | + $updates[$row['member_groups']][] = $row['id_board']; |
|
217 | + } |
|
209 | 218 | $smcFunc['db_free_result']($request); |
210 | 219 | |
211 | - foreach ($updates as $member_groups => $boardArray) |
|
212 | - $smcFunc['db_query']('', ' |
|
220 | + foreach ($updates as $member_groups => $boardArray) { |
|
221 | + $smcFunc['db_query']('', ' |
|
213 | 222 | UPDATE {db_prefix}boards |
214 | 223 | SET member_groups = {string:member_groups} |
215 | 224 | WHERE id_board IN ({array_int:board_lists})', |
@@ -218,6 +227,7 @@ discard block |
||
218 | 227 | 'member_groups' => implode(',', array_diff(explode(',', $member_groups), $groups)), |
219 | 228 | ) |
220 | 229 | ); |
230 | + } |
|
221 | 231 | |
222 | 232 | // Recalculate the post groups, as they likely changed. |
223 | 233 | updateStats('postgroups'); |
@@ -225,8 +235,9 @@ discard block |
||
225 | 235 | // Make a note of the fact that the cache may be wrong. |
226 | 236 | $settings_update = array('settings_updated' => time()); |
227 | 237 | // Have we deleted the spider group? |
228 | - if (isset($modSettings['spider_group']) && in_array($modSettings['spider_group'], $groups)) |
|
229 | - $settings_update['spider_group'] = 0; |
|
238 | + if (isset($modSettings['spider_group']) && in_array($modSettings['spider_group'], $groups)) { |
|
239 | + $settings_update['spider_group'] = 0; |
|
240 | + } |
|
230 | 241 | |
231 | 242 | updateSettings($settings_update); |
232 | 243 | |
@@ -250,22 +261,24 @@ discard block |
||
250 | 261 | global $smcFunc, $modSettings, $sourcedir; |
251 | 262 | |
252 | 263 | // You're getting nowhere without this permission, unless of course you are the group's moderator. |
253 | - if (!$permissionCheckDone) |
|
254 | - isAllowedTo('manage_membergroups'); |
|
264 | + if (!$permissionCheckDone) { |
|
265 | + isAllowedTo('manage_membergroups'); |
|
266 | + } |
|
255 | 267 | |
256 | 268 | // Assume something will happen. |
257 | 269 | updateSettings(array('settings_updated' => time())); |
258 | 270 | |
259 | 271 | // Cleaning the input. |
260 | - if (!is_array($members)) |
|
261 | - $members = array((int) $members); |
|
262 | - else |
|
272 | + if (!is_array($members)) { |
|
273 | + $members = array((int) $members); |
|
274 | + } else |
|
263 | 275 | { |
264 | 276 | $members = array_unique($members); |
265 | 277 | |
266 | 278 | // Cast the members to integer. |
267 | - foreach ($members as $key => $value) |
|
268 | - $members[$key] = (int) $value; |
|
279 | + foreach ($members as $key => $value) { |
|
280 | + $members[$key] = (int) $value; |
|
281 | + } |
|
269 | 282 | } |
270 | 283 | |
271 | 284 | // Before we get started, let's check we won't leave the admin group empty! |
@@ -277,14 +290,15 @@ discard block |
||
277 | 290 | // Remove any admins if there are too many. |
278 | 291 | $non_changing_admins = array_diff(array_keys($admins), $members); |
279 | 292 | |
280 | - if (empty($non_changing_admins)) |
|
281 | - $members = array_diff($members, array_keys($admins)); |
|
293 | + if (empty($non_changing_admins)) { |
|
294 | + $members = array_diff($members, array_keys($admins)); |
|
295 | + } |
|
282 | 296 | } |
283 | 297 | |
284 | 298 | // Just in case. |
285 | - if (empty($members)) |
|
286 | - return false; |
|
287 | - elseif ($groups === null) |
|
299 | + if (empty($members)) { |
|
300 | + return false; |
|
301 | + } elseif ($groups === null) |
|
288 | 302 | { |
289 | 303 | // Wanna remove all groups from these members? That's easy. |
290 | 304 | $smcFunc['db_query']('', ' |
@@ -306,20 +320,21 @@ discard block |
||
306 | 320 | updateStats('postgroups', $members); |
307 | 321 | |
308 | 322 | // Log what just happened. |
309 | - foreach ($members as $member) |
|
310 | - logAction('removed_all_groups', array('member' => $member), 'admin'); |
|
323 | + foreach ($members as $member) { |
|
324 | + logAction('removed_all_groups', array('member' => $member), 'admin'); |
|
325 | + } |
|
311 | 326 | |
312 | 327 | return true; |
313 | - } |
|
314 | - elseif (!is_array($groups)) |
|
315 | - $groups = array((int) $groups); |
|
316 | - else |
|
328 | + } elseif (!is_array($groups)) { |
|
329 | + $groups = array((int) $groups); |
|
330 | + } else |
|
317 | 331 | { |
318 | 332 | $groups = array_unique($groups); |
319 | 333 | |
320 | 334 | // Make sure all groups are integer. |
321 | - foreach ($groups as $key => $value) |
|
322 | - $groups[$key] = (int) $value; |
|
335 | + foreach ($groups as $key => $value) { |
|
336 | + $groups[$key] = (int) $value; |
|
337 | + } |
|
323 | 338 | } |
324 | 339 | |
325 | 340 | // Fetch a list of groups members cannot be assigned to explicitly, and the group names of the ones we want. |
@@ -335,10 +350,11 @@ discard block |
||
335 | 350 | $group_names = array(); |
336 | 351 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
337 | 352 | { |
338 | - if ($row['min_posts'] != -1) |
|
339 | - $implicitGroups[] = $row['id_group']; |
|
340 | - else |
|
341 | - $group_names[$row['id_group']] = $row['group_name']; |
|
353 | + if ($row['min_posts'] != -1) { |
|
354 | + $implicitGroups[] = $row['id_group']; |
|
355 | + } else { |
|
356 | + $group_names[$row['id_group']] = $row['group_name']; |
|
357 | + } |
|
342 | 358 | } |
343 | 359 | $smcFunc['db_free_result']($request); |
344 | 360 | |
@@ -357,8 +373,9 @@ discard block |
||
357 | 373 | ) |
358 | 374 | ); |
359 | 375 | $protected_groups = array(1); |
360 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
361 | - $protected_groups[] = $row['id_group']; |
|
376 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
377 | + $protected_groups[] = $row['id_group']; |
|
378 | + } |
|
362 | 379 | $smcFunc['db_free_result']($request); |
363 | 380 | |
364 | 381 | // If you're not an admin yourself, you can't touch protected groups! |
@@ -366,8 +383,9 @@ discard block |
||
366 | 383 | } |
367 | 384 | |
368 | 385 | // Only continue if there are still groups and members left. |
369 | - if (empty($groups) || empty($members)) |
|
370 | - return false; |
|
386 | + if (empty($groups) || empty($members)) { |
|
387 | + return false; |
|
388 | + } |
|
371 | 389 | |
372 | 390 | // First, reset those who have this as their primary group - this is the easy one. |
373 | 391 | $log_inserts = array(); |
@@ -381,8 +399,9 @@ discard block |
||
381 | 399 | 'member_list' => $members, |
382 | 400 | ) |
383 | 401 | ); |
384 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
385 | - $log_inserts[] = array('group' => $group_names[$row['id_group']], 'member' => $row['id_member']); |
|
402 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
403 | + $log_inserts[] = array('group' => $group_names[$row['id_group']], 'member' => $row['id_member']); |
|
404 | + } |
|
386 | 405 | $smcFunc['db_free_result']($request); |
387 | 406 | |
388 | 407 | $smcFunc['db_query']('', ' |
@@ -414,16 +433,17 @@ discard block |
||
414 | 433 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
415 | 434 | { |
416 | 435 | // What log entries must we make for this one, eh? |
417 | - foreach (explode(',', $row['additional_groups']) as $group) |
|
418 | - if (in_array($group, $groups)) |
|
436 | + foreach (explode(',', $row['additional_groups']) as $group) { |
|
437 | + if (in_array($group, $groups)) |
|
419 | 438 | $log_inserts[] = array('group' => $group_names[$group], 'member' => $row['id_member']); |
439 | + } |
|
420 | 440 | |
421 | 441 | $updates[$row['additional_groups']][] = $row['id_member']; |
422 | 442 | } |
423 | 443 | $smcFunc['db_free_result']($request); |
424 | 444 | |
425 | - foreach ($updates as $additional_groups => $memberArray) |
|
426 | - $smcFunc['db_query']('', ' |
|
445 | + foreach ($updates as $additional_groups => $memberArray) { |
|
446 | + $smcFunc['db_query']('', ' |
|
427 | 447 | UPDATE {db_prefix}members |
428 | 448 | SET additional_groups = {string:additional_groups} |
429 | 449 | WHERE id_member IN ({array_int:member_list})', |
@@ -432,6 +452,7 @@ discard block |
||
432 | 452 | 'additional_groups' => implode(',', array_diff(explode(',', $additional_groups), $groups)), |
433 | 453 | ) |
434 | 454 | ); |
455 | + } |
|
435 | 456 | |
436 | 457 | // Their post groups may have changed now... |
437 | 458 | updateStats('postgroups', $members); |
@@ -440,8 +461,9 @@ discard block |
||
440 | 461 | if (!empty($log_inserts) && !empty($modSettings['modlog_enabled'])) |
441 | 462 | { |
442 | 463 | require_once($sourcedir . '/Logging.php'); |
443 | - foreach ($log_inserts as $extra) |
|
444 | - logAction('removed_from_group', $extra, 'admin'); |
|
464 | + foreach ($log_inserts as $extra) { |
|
465 | + logAction('removed_from_group', $extra, 'admin'); |
|
466 | + } |
|
445 | 467 | } |
446 | 468 | |
447 | 469 | // Mission successful. |
@@ -477,21 +499,23 @@ discard block |
||
477 | 499 | global $smcFunc, $sourcedir; |
478 | 500 | |
479 | 501 | // Show your licence, but only if it hasn't been done yet. |
480 | - if (!$permissionCheckDone) |
|
481 | - isAllowedTo('manage_membergroups'); |
|
502 | + if (!$permissionCheckDone) { |
|
503 | + isAllowedTo('manage_membergroups'); |
|
504 | + } |
|
482 | 505 | |
483 | 506 | // Make sure we don't keep old stuff cached. |
484 | 507 | updateSettings(array('settings_updated' => time())); |
485 | 508 | |
486 | - if (!is_array($members)) |
|
487 | - $members = array((int) $members); |
|
488 | - else |
|
509 | + if (!is_array($members)) { |
|
510 | + $members = array((int) $members); |
|
511 | + } else |
|
489 | 512 | { |
490 | 513 | $members = array_unique($members); |
491 | 514 | |
492 | 515 | // Make sure all members are integer. |
493 | - foreach ($members as $key => $value) |
|
494 | - $members[$key] = (int) $value; |
|
516 | + foreach ($members as $key => $value) { |
|
517 | + $members[$key] = (int) $value; |
|
518 | + } |
|
495 | 519 | } |
496 | 520 | $group = (int) $group; |
497 | 521 | |
@@ -508,20 +532,23 @@ discard block |
||
508 | 532 | $group_names = array(); |
509 | 533 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
510 | 534 | { |
511 | - if ($row['min_posts'] != -1) |
|
512 | - $implicitGroups[] = $row['id_group']; |
|
513 | - else |
|
514 | - $group_names[$row['id_group']] = $row['group_name']; |
|
535 | + if ($row['min_posts'] != -1) { |
|
536 | + $implicitGroups[] = $row['id_group']; |
|
537 | + } else { |
|
538 | + $group_names[$row['id_group']] = $row['group_name']; |
|
539 | + } |
|
515 | 540 | } |
516 | 541 | $smcFunc['db_free_result']($request); |
517 | 542 | |
518 | 543 | // Sorry, you can't join an implicit group. |
519 | - if (in_array($group, $implicitGroups) || empty($members)) |
|
520 | - return false; |
|
544 | + if (in_array($group, $implicitGroups) || empty($members)) { |
|
545 | + return false; |
|
546 | + } |
|
521 | 547 | |
522 | 548 | // Only admins can add admins... |
523 | - if (!allowedTo('admin_forum') && $group == 1) |
|
524 | - return false; |
|
549 | + if (!allowedTo('admin_forum') && $group == 1) { |
|
550 | + return false; |
|
551 | + } |
|
525 | 552 | // ... and assign protected groups! |
526 | 553 | elseif (!allowedTo('admin_forum') && !$ignoreProtected) |
527 | 554 | { |
@@ -539,13 +566,14 @@ discard block |
||
539 | 566 | $smcFunc['db_free_result']($request); |
540 | 567 | |
541 | 568 | // Is it protected? |
542 | - if ($is_protected == 1) |
|
543 | - return false; |
|
569 | + if ($is_protected == 1) { |
|
570 | + return false; |
|
571 | + } |
|
544 | 572 | } |
545 | 573 | |
546 | 574 | // Do the actual updates. |
547 | - if ($type == 'only_additional') |
|
548 | - $smcFunc['db_query']('', ' |
|
575 | + if ($type == 'only_additional') { |
|
576 | + $smcFunc['db_query']('', ' |
|
549 | 577 | UPDATE {db_prefix}members |
550 | 578 | SET additional_groups = CASE WHEN additional_groups = {string:blank_string} THEN {string:id_group_string} ELSE CONCAT(additional_groups, {string:id_group_string_extend}) END |
551 | 579 | WHERE id_member IN ({array_int:member_list}) |
@@ -559,8 +587,8 @@ discard block |
||
559 | 587 | 'blank_string' => '', |
560 | 588 | ) |
561 | 589 | ); |
562 | - elseif ($type == 'only_primary' || $type == 'force_primary') |
|
563 | - $smcFunc['db_query']('', ' |
|
590 | + } elseif ($type == 'only_primary' || $type == 'force_primary') { |
|
591 | + $smcFunc['db_query']('', ' |
|
564 | 592 | UPDATE {db_prefix}members |
565 | 593 | SET id_group = {int:id_group} |
566 | 594 | WHERE id_member IN ({array_int:member_list})' . ($type == 'force_primary' ? '' : ' |
@@ -572,8 +600,8 @@ discard block |
||
572 | 600 | 'regular_group' => 0, |
573 | 601 | ) |
574 | 602 | ); |
575 | - elseif ($type == 'auto') |
|
576 | - $smcFunc['db_query']('', ' |
|
603 | + } elseif ($type == 'auto') { |
|
604 | + $smcFunc['db_query']('', ' |
|
577 | 605 | UPDATE {db_prefix}members |
578 | 606 | SET |
579 | 607 | id_group = CASE WHEN id_group = {int:regular_group} THEN {int:id_group} ELSE id_group END, |
@@ -592,9 +620,11 @@ discard block |
||
592 | 620 | 'id_group_string_extend' => ',' . $group, |
593 | 621 | ) |
594 | 622 | ); |
623 | + } |
|
595 | 624 | // Ack!!? What happened? |
596 | - else |
|
597 | - trigger_error('addMembersToGroup(): Unknown type \'' . $type . '\'', E_USER_WARNING); |
|
625 | + else { |
|
626 | + trigger_error('addMembersToGroup(): Unknown type \'' . $type . '\'', E_USER_WARNING); |
|
627 | + } |
|
598 | 628 | |
599 | 629 | call_integration_hook('integrate_add_members_to_group', array($members, $group, &$group_names)); |
600 | 630 | |
@@ -603,8 +633,9 @@ discard block |
||
603 | 633 | |
604 | 634 | // Log the data. |
605 | 635 | require_once($sourcedir . '/Logging.php'); |
606 | - foreach ($members as $member) |
|
607 | - logAction('added_to_group', array('group' => $group_names[$group], 'member' => $member), 'admin'); |
|
636 | + foreach ($members as $member) { |
|
637 | + logAction('added_to_group', array('group' => $group_names[$group], 'member' => $member), 'admin'); |
|
638 | + } |
|
608 | 639 | |
609 | 640 | return true; |
610 | 641 | } |
@@ -632,8 +663,9 @@ discard block |
||
632 | 663 | ) |
633 | 664 | ); |
634 | 665 | $members = array(); |
635 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
636 | - $members[$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
666 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
667 | + $members[$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
668 | + } |
|
637 | 669 | $smcFunc['db_free_result']($request); |
638 | 670 | |
639 | 671 | // If there are more than $limit members, add a 'more' link. |
@@ -641,10 +673,10 @@ discard block |
||
641 | 673 | { |
642 | 674 | array_pop($members); |
643 | 675 | return true; |
676 | + } else { |
|
677 | + return false; |
|
678 | + } |
|
644 | 679 | } |
645 | - else |
|
646 | - return false; |
|
647 | -} |
|
648 | 680 | |
649 | 681 | /** |
650 | 682 | * Retrieve a list of (visible) membergroups used by the cache. |
@@ -669,8 +701,9 @@ discard block |
||
669 | 701 | ) |
670 | 702 | ); |
671 | 703 | $groupCache = array(); |
672 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
673 | - $groupCache[] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_group'] . '" ' . ($row['online_color'] ? 'style="color: ' . $row['online_color'] . '"' : '') . '>' . $row['group_name'] . '</a>'; |
|
704 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
705 | + $groupCache[] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_group'] . '" ' . ($row['online_color'] ? 'style="color: ' . $row['online_color'] . '"' : '') . '>' . $row['group_name'] . '</a>'; |
|
706 | + } |
|
674 | 707 | $smcFunc['db_free_result']($request); |
675 | 708 | |
676 | 709 | return array( |
@@ -718,8 +751,9 @@ discard block |
||
718 | 751 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
719 | 752 | { |
720 | 753 | // We only list the groups they can see. |
721 | - if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups')) |
|
722 | - continue; |
|
754 | + if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups')) { |
|
755 | + continue; |
|
756 | + } |
|
723 | 757 | |
724 | 758 | $row['icons'] = explode('#', $row['icons']); |
725 | 759 | |
@@ -754,12 +788,11 @@ discard block |
||
754 | 788 | 'group_list' => $group_ids, |
755 | 789 | ) |
756 | 790 | ); |
757 | - while ($row = $smcFunc['db_fetch_assoc']($query)) |
|
758 | - $groups[$row['id_group']]['num_members'] += $row['num_members']; |
|
791 | + while ($row = $smcFunc['db_fetch_assoc']($query)) { |
|
792 | + $groups[$row['id_group']]['num_members'] += $row['num_members']; |
|
793 | + } |
|
759 | 794 | $smcFunc['db_free_result']($query); |
760 | - } |
|
761 | - |
|
762 | - else |
|
795 | + } else |
|
763 | 796 | { |
764 | 797 | $query = $smcFunc['db_query']('', ' |
765 | 798 | SELECT id_group, COUNT(*) AS num_members |
@@ -770,8 +803,9 @@ discard block |
||
770 | 803 | 'group_list' => $group_ids, |
771 | 804 | ) |
772 | 805 | ); |
773 | - while ($row = $smcFunc['db_fetch_assoc']($query)) |
|
774 | - $groups[$row['id_group']]['num_members'] += $row['num_members']; |
|
806 | + while ($row = $smcFunc['db_fetch_assoc']($query)) { |
|
807 | + $groups[$row['id_group']]['num_members'] += $row['num_members']; |
|
808 | + } |
|
775 | 809 | $smcFunc['db_free_result']($query); |
776 | 810 | |
777 | 811 | // Only do additional groups if we can moderate... |
@@ -790,8 +824,9 @@ discard block |
||
790 | 824 | 'blank_string' => '', |
791 | 825 | ) |
792 | 826 | ); |
793 | - while ($row = $smcFunc['db_fetch_assoc']($query)) |
|
794 | - $groups[$row['id_group']]['num_members'] += $row['num_members']; |
|
827 | + while ($row = $smcFunc['db_fetch_assoc']($query)) { |
|
828 | + $groups[$row['id_group']]['num_members'] += $row['num_members']; |
|
829 | + } |
|
795 | 830 | $smcFunc['db_free_result']($query); |
796 | 831 | } |
797 | 832 | } |
@@ -805,8 +840,9 @@ discard block |
||
805 | 840 | 'group_list' => $group_ids, |
806 | 841 | ) |
807 | 842 | ); |
808 | - while ($row = $smcFunc['db_fetch_assoc']($query)) |
|
809 | - $groups[$row['id_group']]['moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
843 | + while ($row = $smcFunc['db_fetch_assoc']($query)) { |
|
844 | + $groups[$row['id_group']]['moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
845 | + } |
|
810 | 846 | $smcFunc['db_free_result']($query); |
811 | 847 | } |
812 | 848 | |
@@ -815,8 +851,9 @@ discard block |
||
815 | 851 | { |
816 | 852 | $sort_ascending = strpos($sort, 'DESC') === false; |
817 | 853 | |
818 | - foreach ($groups as $group) |
|
819 | - $sort_array[] = $group['id_group'] != 3 ? (int) $group['num_members'] : -1; |
|
854 | + foreach ($groups as $group) { |
|
855 | + $sort_array[] = $group['id_group'] != 3 ? (int) $group['num_members'] : -1; |
|
856 | + } |
|
820 | 857 | |
821 | 858 | array_multisort($sort_array, $sort_ascending ? SORT_ASC : SORT_DESC, SORT_REGULAR, $groups); |
822 | 859 | } |
@@ -286,7 +286,7 @@ |
||
286 | 286 | /** |
287 | 287 | * Delete a menu. |
288 | 288 | * @param string $menu_id The ID of the menu to destroy or 'last' for the most recent one |
289 | - * @return bool|void False if the menu doesn't exist, nothing otherwise |
|
289 | + * @return false|null False if the menu doesn't exist, nothing otherwise |
|
290 | 290 | */ |
291 | 291 | function destroyMenu($menu_id = 'last') |
292 | 292 | { |
@@ -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 | * Create a menu. |
@@ -64,22 +65,26 @@ discard block |
||
64 | 65 | $menu_context['current_action'] = isset($menuOptions['action']) ? $menuOptions['action'] : $context['current_action']; |
65 | 66 | |
66 | 67 | // Allow extend *any* menu with a single hook |
67 | - if (!empty($menu_context['current_action'])) |
|
68 | - call_integration_hook('integrate_' . $menu_context['current_action'] . '_areas', array(&$menuData)); |
|
68 | + if (!empty($menu_context['current_action'])) { |
|
69 | + call_integration_hook('integrate_' . $menu_context['current_action'] . '_areas', array(&$menuData)); |
|
70 | + } |
|
69 | 71 | |
70 | 72 | // What is the current area selected? |
71 | - if (isset($menuOptions['current_area']) || isset($_GET['area'])) |
|
72 | - $menu_context['current_area'] = isset($menuOptions['current_area']) ? $menuOptions['current_area'] : $_GET['area']; |
|
73 | + if (isset($menuOptions['current_area']) || isset($_GET['area'])) { |
|
74 | + $menu_context['current_area'] = isset($menuOptions['current_area']) ? $menuOptions['current_area'] : $_GET['area']; |
|
75 | + } |
|
73 | 76 | |
74 | 77 | // Build a list of additional parameters that should go in the URL. |
75 | 78 | $menu_context['extra_parameters'] = ''; |
76 | - if (!empty($menuOptions['extra_url_parameters'])) |
|
77 | - foreach ($menuOptions['extra_url_parameters'] as $key => $value) |
|
79 | + if (!empty($menuOptions['extra_url_parameters'])) { |
|
80 | + foreach ($menuOptions['extra_url_parameters'] as $key => $value) |
|
78 | 81 | $menu_context['extra_parameters'] .= ';' . $key . '=' . $value; |
82 | + } |
|
79 | 83 | |
80 | 84 | // Only include the session ID in the URL if it's strictly necessary. |
81 | - if (empty($menuOptions['disable_url_session_check'])) |
|
82 | - $menu_context['extra_parameters'] .= ';' . $context['session_var'] . '=' . $context['session_id']; |
|
85 | + if (empty($menuOptions['disable_url_session_check'])) { |
|
86 | + $menu_context['extra_parameters'] .= ';' . $context['session_var'] . '=' . $context['session_id']; |
|
87 | + } |
|
83 | 88 | |
84 | 89 | $include_data = array(); |
85 | 90 | |
@@ -87,8 +92,9 @@ discard block |
||
87 | 92 | foreach ($menuData as $section_id => $section) |
88 | 93 | { |
89 | 94 | // Is this enabled - or has as permission check - which fails? |
90 | - if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($section['permission']) && !allowedTo($section['permission']))) |
|
91 | - continue; |
|
95 | + if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($section['permission']) && !allowedTo($section['permission']))) { |
|
96 | + continue; |
|
97 | + } |
|
92 | 98 | |
93 | 99 | // Now we cycle through the sections to pick the right area. |
94 | 100 | foreach ($section['areas'] as $area_id => $area) |
@@ -110,41 +116,45 @@ discard block |
||
110 | 116 | if (empty($area['hidden'])) |
111 | 117 | { |
112 | 118 | // First time this section? |
113 | - if (!isset($menu_context['sections'][$section_id])) |
|
114 | - $menu_context['sections'][$section_id]['title'] = $section['title']; |
|
119 | + if (!isset($menu_context['sections'][$section_id])) { |
|
120 | + $menu_context['sections'][$section_id]['title'] = $section['title']; |
|
121 | + } |
|
115 | 122 | |
116 | 123 | $menu_context['sections'][$section_id]['areas'][$area_id] = array('label' => isset($area['label']) ? $area['label'] : $txt[$area_id]); |
117 | 124 | // We'll need the ID as well... |
118 | 125 | $menu_context['sections'][$section_id]['id'] = $section_id; |
119 | 126 | // Does it have a custom URL? |
120 | - if (isset($area['custom_url'])) |
|
121 | - $menu_context['sections'][$section_id]['areas'][$area_id]['url'] = $area['custom_url']; |
|
127 | + if (isset($area['custom_url'])) { |
|
128 | + $menu_context['sections'][$section_id]['areas'][$area_id]['url'] = $area['custom_url']; |
|
129 | + } |
|
122 | 130 | |
123 | 131 | // Does this area have its own icon? |
124 | - if (!isset($area['force_menu_into_arms_of_another_menu']) && $user_info['name'] == 'iamanoompaloompa') |
|
125 | - $menu_context['sections'][$section_id]['areas'][$area_id] = safe_unserialize(base64_decode('YTozOntzOjU6ImxhYmVsIjtzOjEyOiJPb21wYSBMb29tcGEiO3M6MzoidXJsIjtzOjQzOiJodHRwOi8vZW4ud2lraXBlZGlhLm9yZy93aWtpL09vbXBhX0xvb21wYXM/IjtzOjQ6Imljb24iO3M6ODY6IjxpbWcgc3JjPSJodHRwOi8vd3d3LnNpbXBsZW1hY2hpbmVzLm9yZy9pbWFnZXMvb29tcGEuZ2lmIiBhbHQ9IkknbSBhbiBPb21wYSBMb29tcGEiIC8+Ijt9')); |
|
126 | - elseif (isset($area['icon']) && file_exists($settings['theme_dir'] . '/images/admin/' . $area['icon'])) |
|
127 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['images_url'] . '/admin/' . $area['icon'] . '" alt="">'; |
|
128 | - elseif (isset($area['icon']) && file_exists($settings['default_theme_dir'] . '/images/admin/' . $area['icon'])) |
|
129 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['default_images_url'] . '/admin/' . $area['icon'] . '" alt="">'; |
|
130 | - elseif (isset($area['icon'])) |
|
131 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area['icon'] . '"></span>'; |
|
132 | - else |
|
133 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area_id . '"></span>'; |
|
134 | - |
|
135 | - if (isset($area['icon_class']) && empty($menu_context['sections'][$section_id]['areas'][$area_id]['icon'])) |
|
136 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . $area['icon_class']; |
|
137 | - elseif (isset($area['icon'])) |
|
132 | + if (!isset($area['force_menu_into_arms_of_another_menu']) && $user_info['name'] == 'iamanoompaloompa') { |
|
133 | + $menu_context['sections'][$section_id]['areas'][$area_id] = safe_unserialize(base64_decode('YTozOntzOjU6ImxhYmVsIjtzOjEyOiJPb21wYSBMb29tcGEiO3M6MzoidXJsIjtzOjQzOiJodHRwOi8vZW4ud2lraXBlZGlhLm9yZy93aWtpL09vbXBhX0xvb21wYXM/IjtzOjQ6Imljb24iO3M6ODY6IjxpbWcgc3JjPSJodHRwOi8vd3d3LnNpbXBsZW1hY2hpbmVzLm9yZy9pbWFnZXMvb29tcGEuZ2lmIiBhbHQ9IkknbSBhbiBPb21wYSBMb29tcGEiIC8+Ijt9')); |
|
134 | + } elseif (isset($area['icon']) && file_exists($settings['theme_dir'] . '/images/admin/' . $area['icon'])) { |
|
135 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['images_url'] . '/admin/' . $area['icon'] . '" alt="">'; |
|
136 | + } elseif (isset($area['icon']) && file_exists($settings['default_theme_dir'] . '/images/admin/' . $area['icon'])) { |
|
137 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['default_images_url'] . '/admin/' . $area['icon'] . '" alt="">'; |
|
138 | + } elseif (isset($area['icon'])) { |
|
139 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area['icon'] . '"></span>'; |
|
140 | + } else { |
|
141 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area_id . '"></span>'; |
|
142 | + } |
|
143 | + |
|
144 | + if (isset($area['icon_class']) && empty($menu_context['sections'][$section_id]['areas'][$area_id]['icon'])) { |
|
145 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . $area['icon_class']; |
|
146 | + } elseif (isset($area['icon'])) |
|
138 | 147 | { |
139 | - if ((substr($area['icon'], -4) === '.png' || substr($area['icon'], -4) === '.gif') && file_exists($settings['theme_dir'] . '/images/admin/big/' . $area['icon'])) |
|
140 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['theme_url'] . '/images/admin/big/' . $area['icon']; |
|
141 | - elseif ((substr($area['icon'], -4) === '.png' || substr($area['icon'], -4) === '.gif') && file_exists($settings['default_theme_dir'] . '/images/admin/big/' . $area['icon'])) |
|
142 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['default_theme_url'] . '/images/admin/big/' . $area['icon']; |
|
148 | + if ((substr($area['icon'], -4) === '.png' || substr($area['icon'], -4) === '.gif') && file_exists($settings['theme_dir'] . '/images/admin/big/' . $area['icon'])) { |
|
149 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['theme_url'] . '/images/admin/big/' . $area['icon']; |
|
150 | + } elseif ((substr($area['icon'], -4) === '.png' || substr($area['icon'], -4) === '.gif') && file_exists($settings['default_theme_dir'] . '/images/admin/big/' . $area['icon'])) { |
|
151 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['default_theme_url'] . '/images/admin/big/' . $area['icon']; |
|
152 | + } |
|
143 | 153 | |
144 | 154 | $menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area['icon']); |
155 | + } else { |
|
156 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area_id); |
|
145 | 157 | } |
146 | - else |
|
147 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area_id); |
|
148 | 158 | |
149 | 159 | // Some areas may be listed but not active, which we show as greyed out. |
150 | 160 | $menu_context['sections'][$section_id]['areas'][$area_id]['inactive'] = !empty($area['inactive']); |
@@ -158,35 +168,41 @@ discard block |
||
158 | 168 | { |
159 | 169 | if ((empty($sub[1]) || allowedTo($sub[1])) && (!isset($sub['enabled']) || !empty($sub['enabled']))) |
160 | 170 | { |
161 | - if ($first_sa == null) |
|
162 | - $first_sa = $sa; |
|
171 | + if ($first_sa == null) { |
|
172 | + $first_sa = $sa; |
|
173 | + } |
|
163 | 174 | |
164 | 175 | $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa] = array('label' => $sub[0]); |
165 | 176 | // Custom URL? |
166 | - if (isset($sub['url'])) |
|
167 | - $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['url'] = $sub['url']; |
|
177 | + if (isset($sub['url'])) { |
|
178 | + $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['url'] = $sub['url']; |
|
179 | + } |
|
168 | 180 | |
169 | 181 | // A bit complicated - but is this set? |
170 | 182 | if ($menu_context['current_area'] == $area_id) |
171 | 183 | { |
172 | 184 | // Save which is the first... |
173 | - if (empty($first_sa)) |
|
174 | - $first_sa = $sa; |
|
185 | + if (empty($first_sa)) { |
|
186 | + $first_sa = $sa; |
|
187 | + } |
|
175 | 188 | |
176 | 189 | // Is this the current subsection? |
177 | - if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == $sa) |
|
178 | - $menu_context['current_subsection'] = $sa; |
|
190 | + if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == $sa) { |
|
191 | + $menu_context['current_subsection'] = $sa; |
|
192 | + } |
|
179 | 193 | // Otherwise is it the default? |
180 | - elseif (!isset($menu_context['current_subsection']) && !empty($sub[2])) |
|
181 | - $menu_context['current_subsection'] = $sa; |
|
194 | + elseif (!isset($menu_context['current_subsection']) && !empty($sub[2])) { |
|
195 | + $menu_context['current_subsection'] = $sa; |
|
196 | + } |
|
182 | 197 | } |
183 | 198 | |
184 | 199 | // Let's assume this is the last, for now. |
185 | 200 | $last_sa = $sa; |
186 | 201 | } |
187 | 202 | // Mark it as disabled... |
188 | - else |
|
189 | - $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['disabled'] = true; |
|
203 | + else { |
|
204 | + $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['disabled'] = true; |
|
205 | + } |
|
190 | 206 | } |
191 | 207 | |
192 | 208 | // Set which one is first, last and selected in the group. |
@@ -195,8 +211,9 @@ discard block |
||
195 | 211 | $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$context['right_to_left'] ? $last_sa : $first_sa]['is_first'] = true; |
196 | 212 | $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$context['right_to_left'] ? $first_sa : $last_sa]['is_last'] = true; |
197 | 213 | |
198 | - if ($menu_context['current_area'] == $area_id && !isset($menu_context['current_subsection'])) |
|
199 | - $menu_context['current_subsection'] = $first_sa; |
|
214 | + if ($menu_context['current_area'] == $area_id && !isset($menu_context['current_subsection'])) { |
|
215 | + $menu_context['current_subsection'] = $first_sa; |
|
216 | + } |
|
200 | 217 | } |
201 | 218 | } |
202 | 219 | } |
@@ -230,23 +247,26 @@ discard block |
||
230 | 247 | $menu_context['base_url'] = isset($menuOptions['base_url']) ? $menuOptions['base_url'] : $scripturl . '?action=' . $menu_context['current_action']; |
231 | 248 | |
232 | 249 | // If we didn't find the area we were looking for go to a default one. |
233 | - if (isset($backup_area) && empty($found_section)) |
|
234 | - $menu_context['current_area'] = $backup_area; |
|
250 | + if (isset($backup_area) && empty($found_section)) { |
|
251 | + $menu_context['current_area'] = $backup_area; |
|
252 | + } |
|
235 | 253 | |
236 | 254 | // If there are sections quickly goes through all the sections to check if the base menu has an url |
237 | 255 | if (!empty($menu_context['current_section'])) |
238 | 256 | { |
239 | 257 | $menu_context['sections'][$menu_context['current_section']]['selected'] = true; |
240 | 258 | $menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['selected'] = true; |
241 | - if (!empty($menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']])) |
|
242 | - $menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']]['selected'] = true; |
|
259 | + if (!empty($menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']])) { |
|
260 | + $menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']]['selected'] = true; |
|
261 | + } |
|
243 | 262 | |
244 | - foreach ($menu_context['sections'] as $section_id => $section) |
|
245 | - foreach ($section['areas'] as $area_id => $area) |
|
263 | + foreach ($menu_context['sections'] as $section_id => $section) { |
|
264 | + foreach ($section['areas'] as $area_id => $area) |
|
246 | 265 | { |
247 | 266 | if (!isset($menu_context['sections'][$section_id]['url'])) |
248 | 267 | { |
249 | 268 | $menu_context['sections'][$section_id]['url'] = isset($area['url']) ? $area['url'] : $menu_context['base_url'] . ';area=' . $area_id; |
269 | + } |
|
250 | 270 | break; |
251 | 271 | } |
252 | 272 | } |
@@ -257,8 +277,9 @@ discard block |
||
257 | 277 | { |
258 | 278 | // Never happened! |
259 | 279 | $context['max_menu_id']--; |
260 | - if ($context['max_menu_id'] == 0) |
|
261 | - unset($context['max_menu_id']); |
|
280 | + if ($context['max_menu_id'] == 0) { |
|
281 | + unset($context['max_menu_id']); |
|
282 | + } |
|
262 | 283 | |
263 | 284 | return false; |
264 | 285 | } |
@@ -269,8 +290,9 @@ discard block |
||
269 | 290 | $context['template_layers'][] = $menu_context['layer_name']; |
270 | 291 | |
271 | 292 | // Check we had something - for sanity sake. |
272 | - if (empty($include_data)) |
|
273 | - return false; |
|
293 | + if (empty($include_data)) { |
|
294 | + return false; |
|
295 | + } |
|
274 | 296 | |
275 | 297 | // Finally - return information on the selected item. |
276 | 298 | $include_data += array( |
@@ -293,12 +315,14 @@ discard block |
||
293 | 315 | global $context; |
294 | 316 | |
295 | 317 | $menu_name = $menu_id == 'last' && isset($context['max_menu_id']) && isset($context['menu_data_' . $context['max_menu_id']]) ? 'menu_data_' . $context['max_menu_id'] : 'menu_data_' . $menu_id; |
296 | - if (!isset($context[$menu_name])) |
|
297 | - return false; |
|
318 | + if (!isset($context[$menu_name])) { |
|
319 | + return false; |
|
320 | + } |
|
298 | 321 | |
299 | 322 | $layer_index = array_search($context[$menu_name]['layer_name'], $context['template_layers']); |
300 | - if ($layer_index !== false) |
|
301 | - unset($context['template_layers'][$layer_index]); |
|
323 | + if ($layer_index !== false) { |
|
324 | + unset($context['template_layers'][$layer_index]); |
|
325 | + } |
|
302 | 326 | |
303 | 327 | unset($context[$menu_name]); |
304 | 328 | } |
@@ -1451,7 +1451,7 @@ discard block |
||
1451 | 1451 | * @param resource $socket Socket to send on |
1452 | 1452 | * @param string $code The expected response code |
1453 | 1453 | * @param string $response The response from the SMTP server |
1454 | - * @return bool Whether it responded as such. |
|
1454 | + * @return string|boolean Whether it responded as such. |
|
1455 | 1455 | */ |
1456 | 1456 | function server_parse($message, $socket, $code, &$response = null) |
1457 | 1457 | { |
@@ -2265,7 +2265,7 @@ discard block |
||
2265 | 2265 | * @param array $msgs Array of message ids |
2266 | 2266 | * @param bool $approve Whether to approve the posts (if false, posts are unapproved) |
2267 | 2267 | * @param bool $notify Whether to notify users |
2268 | - * @return bool Whether the operation was successful |
|
2268 | + * @return null|boolean Whether the operation was successful |
|
2269 | 2269 | */ |
2270 | 2270 | function approvePosts($msgs, $approve = true, $notify = true) |
2271 | 2271 | { |
@@ -2518,7 +2518,7 @@ discard block |
||
2518 | 2518 | * |
2519 | 2519 | * @param array $topics Array of topic ids |
2520 | 2520 | * @param bool $approve Whether to approve the topics. If false, unapproves them instead |
2521 | - * @return bool Whether the operation was successful |
|
2521 | + * @return null|boolean Whether the operation was successful |
|
2522 | 2522 | */ |
2523 | 2523 | function approveTopics($topics, $approve = true) |
2524 | 2524 | { |
@@ -2908,7 +2908,7 @@ discard block |
||
2908 | 2908 | * |
2909 | 2909 | * @param resource $dict An enchant or pspell dictionary resource set up by {@link spell_init()} |
2910 | 2910 | * @param string $word A word to check the spelling of |
2911 | - * @return bool Whether or not the specified word is spelled properly |
|
2911 | + * @return boolean|null Whether or not the specified word is spelled properly |
|
2912 | 2912 | */ |
2913 | 2913 | function spell_check($dict, $word) |
2914 | 2914 | { |
@@ -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[1]), 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 | } |
@@ -831,23 +869,26 @@ discard block |
||
831 | 869 | 'sent' => array() |
832 | 870 | ); |
833 | 871 | |
834 | - if ($from === null) |
|
835 | - $from = array( |
|
872 | + if ($from === null) { |
|
873 | + $from = array( |
|
836 | 874 | 'id' => $user_info['id'], |
837 | 875 | 'name' => $user_info['name'], |
838 | 876 | 'username' => $user_info['username'] |
839 | 877 | ); |
878 | + } |
|
840 | 879 | |
841 | 880 | // This is the one that will go in their inbox. |
842 | 881 | $htmlmessage = $smcFunc['htmlspecialchars']($message, ENT_QUOTES); |
843 | 882 | preparsecode($htmlmessage); |
844 | 883 | $htmlsubject = strtr($smcFunc['htmlspecialchars']($subject), array("\r" => '', "\n" => '', "\t" => '')); |
845 | - if ($smcFunc['strlen']($htmlsubject) > 100) |
|
846 | - $htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100); |
|
884 | + if ($smcFunc['strlen']($htmlsubject) > 100) { |
|
885 | + $htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100); |
|
886 | + } |
|
847 | 887 | |
848 | 888 | // Make sure is an array |
849 | - if (!is_array($recipients)) |
|
850 | - $recipients = array($recipients); |
|
889 | + if (!is_array($recipients)) { |
|
890 | + $recipients = array($recipients); |
|
891 | + } |
|
851 | 892 | |
852 | 893 | // Integrated PMs |
853 | 894 | call_integration_hook('integrate_personal_message', array(&$recipients, &$from, &$subject, &$message)); |
@@ -875,21 +916,23 @@ discard block |
||
875 | 916 | 'usernames' => array_keys($usernames), |
876 | 917 | ) |
877 | 918 | ); |
878 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
879 | - if (isset($usernames[$smcFunc['strtolower']($row['member_name'])])) |
|
919 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
920 | + if (isset($usernames[$smcFunc['strtolower']($row['member_name'])])) |
|
880 | 921 | $usernames[$smcFunc['strtolower']($row['member_name'])] = $row['id_member']; |
922 | + } |
|
881 | 923 | $smcFunc['db_free_result']($request); |
882 | 924 | |
883 | 925 | // Replace the usernames with IDs. Drop usernames that couldn't be found. |
884 | - foreach ($recipients as $rec_type => $rec) |
|
885 | - foreach ($rec as $id => $member) |
|
926 | + foreach ($recipients as $rec_type => $rec) { |
|
927 | + foreach ($rec as $id => $member) |
|
886 | 928 | { |
887 | 929 | if (is_numeric($recipients[$rec_type][$id])) |
888 | 930 | continue; |
931 | + } |
|
889 | 932 | |
890 | - if (!empty($usernames[$member])) |
|
891 | - $recipients[$rec_type][$id] = $usernames[$member]; |
|
892 | - else |
|
933 | + if (!empty($usernames[$member])) { |
|
934 | + $recipients[$rec_type][$id] = $usernames[$member]; |
|
935 | + } else |
|
893 | 936 | { |
894 | 937 | $log['failed'][$id] = sprintf($txt['pm_error_user_not_found'], $recipients[$rec_type][$id]); |
895 | 938 | unset($recipients[$rec_type][$id]); |
@@ -927,8 +970,9 @@ discard block |
||
927 | 970 | $delete = false; |
928 | 971 | foreach ($criteria as $criterium) |
929 | 972 | { |
930 | - 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)) |
|
931 | - $delete = true; |
|
973 | + 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)) { |
|
974 | + $delete = true; |
|
975 | + } |
|
932 | 976 | // If we're adding and one criteria don't match then we stop! |
933 | 977 | elseif (!$row['is_or']) |
934 | 978 | { |
@@ -936,8 +980,9 @@ discard block |
||
936 | 980 | break; |
937 | 981 | } |
938 | 982 | } |
939 | - if ($delete) |
|
940 | - $deletes[$row['id_member']] = 1; |
|
983 | + if ($delete) { |
|
984 | + $deletes[$row['id_member']] = 1; |
|
985 | + } |
|
941 | 986 | } |
942 | 987 | $smcFunc['db_free_result']($request); |
943 | 988 | |
@@ -952,8 +997,9 @@ discard block |
||
952 | 997 | array( |
953 | 998 | ) |
954 | 999 | ); |
955 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
956 | - $message_limit_cache[$row['id_group']] = $row['max_messages']; |
|
1000 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1001 | + $message_limit_cache[$row['id_group']] = $row['max_messages']; |
|
1002 | + } |
|
957 | 1003 | $smcFunc['db_free_result']($request); |
958 | 1004 | } |
959 | 1005 | |
@@ -961,8 +1007,9 @@ discard block |
||
961 | 1007 | require_once($sourcedir . '/Subs-Members.php'); |
962 | 1008 | $pmReadGroups = groupsAllowedTo('pm_read'); |
963 | 1009 | |
964 | - if (empty($modSettings['permission_enable_deny'])) |
|
965 | - $pmReadGroups['denied'] = array(); |
|
1010 | + if (empty($modSettings['permission_enable_deny'])) { |
|
1011 | + $pmReadGroups['denied'] = array(); |
|
1012 | + } |
|
966 | 1013 | |
967 | 1014 | // Load their alert preferences |
968 | 1015 | require_once($sourcedir . '/Subs-Notify.php'); |
@@ -994,8 +1041,9 @@ discard block |
||
994 | 1041 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
995 | 1042 | { |
996 | 1043 | // Don't do anything for members to be deleted! |
997 | - if (isset($deletes[$row['id_member']])) |
|
998 | - continue; |
|
1044 | + if (isset($deletes[$row['id_member']])) { |
|
1045 | + continue; |
|
1046 | + } |
|
999 | 1047 | |
1000 | 1048 | // Load the preferences for this member (if any) |
1001 | 1049 | $prefs = !empty($notifyPrefs[$row['id_member']]) ? $notifyPrefs[$row['id_member']] : array(); |
@@ -1016,8 +1064,9 @@ discard block |
||
1016 | 1064 | { |
1017 | 1065 | foreach ($groups as $id) |
1018 | 1066 | { |
1019 | - if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id]) |
|
1020 | - $message_limit = $message_limit_cache[$id]; |
|
1067 | + if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id]) { |
|
1068 | + $message_limit = $message_limit_cache[$id]; |
|
1069 | + } |
|
1021 | 1070 | } |
1022 | 1071 | |
1023 | 1072 | if ($message_limit > 0 && $message_limit <= $row['instant_messages']) |
@@ -1065,8 +1114,9 @@ discard block |
||
1065 | 1114 | $smcFunc['db_free_result']($request); |
1066 | 1115 | |
1067 | 1116 | // Only 'send' the message if there are any recipients left. |
1068 | - if (empty($all_to)) |
|
1069 | - return $log; |
|
1117 | + if (empty($all_to)) { |
|
1118 | + return $log; |
|
1119 | + } |
|
1070 | 1120 | |
1071 | 1121 | // Insert the message itself and then grab the last insert id. |
1072 | 1122 | $id_pm = $smcFunc['db_insert']('', |
@@ -1087,8 +1137,8 @@ discard block |
||
1087 | 1137 | if (!empty($id_pm)) |
1088 | 1138 | { |
1089 | 1139 | // If this is new we need to set it part of it's own conversation. |
1090 | - if (empty($pm_head)) |
|
1091 | - $smcFunc['db_query']('', ' |
|
1140 | + if (empty($pm_head)) { |
|
1141 | + $smcFunc['db_query']('', ' |
|
1092 | 1142 | UPDATE {db_prefix}personal_messages |
1093 | 1143 | SET id_pm_head = {int:id_pm_head} |
1094 | 1144 | WHERE id_pm = {int:id_pm_head}', |
@@ -1096,6 +1146,7 @@ discard block |
||
1096 | 1146 | 'id_pm_head' => $id_pm, |
1097 | 1147 | ) |
1098 | 1148 | ); |
1149 | + } |
|
1099 | 1150 | |
1100 | 1151 | // Some people think manually deleting personal_messages is fun... it's not. We protect against it though :) |
1101 | 1152 | $smcFunc['db_query']('', ' |
@@ -1111,8 +1162,9 @@ discard block |
||
1111 | 1162 | foreach ($all_to as $to) |
1112 | 1163 | { |
1113 | 1164 | $insertRows[] = array($id_pm, $to, in_array($to, $recipients['bcc']) ? 1 : 0, isset($deletes[$to]) ? 1 : 0, 1); |
1114 | - if (!in_array($to, $recipients['bcc'])) |
|
1115 | - $to_list[] = $to; |
|
1165 | + if (!in_array($to, $recipients['bcc'])) { |
|
1166 | + $to_list[] = $to; |
|
1167 | + } |
|
1116 | 1168 | } |
1117 | 1169 | |
1118 | 1170 | $smcFunc['db_insert']('insert', |
@@ -1130,9 +1182,9 @@ discard block |
||
1130 | 1182 | { |
1131 | 1183 | censorText($message); |
1132 | 1184 | $message = trim(un_htmlspecialchars(strip_tags(strtr(parse_bbc($smcFunc['htmlspecialchars']($message), false), array('<br>' => "\n", '</div>' => "\n", '</li>' => "\n", '[' => '[', ']' => ']'))))); |
1185 | + } else { |
|
1186 | + $message = ''; |
|
1133 | 1187 | } |
1134 | - else |
|
1135 | - $message = ''; |
|
1136 | 1188 | |
1137 | 1189 | $to_names = array(); |
1138 | 1190 | if (count($to_list) > 1) |
@@ -1145,8 +1197,9 @@ discard block |
||
1145 | 1197 | 'to_members' => $to_list, |
1146 | 1198 | ) |
1147 | 1199 | ); |
1148 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1149 | - $to_names[] = un_htmlspecialchars($row['real_name']); |
|
1200 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1201 | + $to_names[] = un_htmlspecialchars($row['real_name']); |
|
1202 | + } |
|
1150 | 1203 | $smcFunc['db_free_result']($request); |
1151 | 1204 | } |
1152 | 1205 | $replacements = array( |
@@ -1174,11 +1227,13 @@ discard block |
||
1174 | 1227 | loadLanguage('index+PersonalMessage'); |
1175 | 1228 | |
1176 | 1229 | // Add one to their unread and read message counts. |
1177 | - foreach ($all_to as $k => $id) |
|
1178 | - if (isset($deletes[$id])) |
|
1230 | + foreach ($all_to as $k => $id) { |
|
1231 | + if (isset($deletes[$id])) |
|
1179 | 1232 | unset($all_to[$k]); |
1180 | - if (!empty($all_to)) |
|
1181 | - updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1)); |
|
1233 | + } |
|
1234 | + if (!empty($all_to)) { |
|
1235 | + updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1)); |
|
1236 | + } |
|
1182 | 1237 | |
1183 | 1238 | return $log; |
1184 | 1239 | } |
@@ -1208,15 +1263,17 @@ discard block |
||
1208 | 1263 | // Let's, for now, assume there are only 'ish characters. |
1209 | 1264 | $simple = true; |
1210 | 1265 | |
1211 | - foreach ($matches[1] as $entity) |
|
1212 | - if ($entity > 128) |
|
1266 | + foreach ($matches[1] as $entity) { |
|
1267 | + if ($entity > 128) |
|
1213 | 1268 | $simple = false; |
1269 | + } |
|
1214 | 1270 | unset($matches); |
1215 | 1271 | |
1216 | - if ($simple) |
|
1217 | - $string = preg_replace_callback('~&#(\d{3,8});~', function($m) |
|
1272 | + if ($simple) { |
|
1273 | + $string = preg_replace_callback('~&#(\d{3,8});~', function($m) |
|
1218 | 1274 | { |
1219 | 1275 | return chr("$m[1]"); |
1276 | + } |
|
1220 | 1277 | }, $string); |
1221 | 1278 | else |
1222 | 1279 | { |
@@ -1224,8 +1281,9 @@ discard block |
||
1224 | 1281 | if (!$context['utf8'] && function_exists('iconv')) |
1225 | 1282 | { |
1226 | 1283 | $newstring = @iconv($context['character_set'], 'UTF-8', $string); |
1227 | - if ($newstring) |
|
1228 | - $string = $newstring; |
|
1284 | + if ($newstring) { |
|
1285 | + $string = $newstring; |
|
1286 | + } |
|
1229 | 1287 | } |
1230 | 1288 | |
1231 | 1289 | $string = preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $string); |
@@ -1241,23 +1299,25 @@ discard block |
||
1241 | 1299 | if (!$context['utf8'] && function_exists('iconv')) |
1242 | 1300 | { |
1243 | 1301 | $newstring = @iconv($context['character_set'], 'UTF-8', $string); |
1244 | - if ($newstring) |
|
1245 | - $string = $newstring; |
|
1302 | + if ($newstring) { |
|
1303 | + $string = $newstring; |
|
1304 | + } |
|
1246 | 1305 | } |
1247 | 1306 | |
1248 | 1307 | $entityConvert = function($m) |
1249 | 1308 | { |
1250 | 1309 | $c = $m[1]; |
1251 | - if (strlen($c) === 1 && ord($c[0]) <= 0x7F) |
|
1252 | - return $c; |
|
1253 | - elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF) |
|
1254 | - return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";"; |
|
1255 | - elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF) |
|
1256 | - return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";"; |
|
1257 | - elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7) |
|
1258 | - return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";"; |
|
1259 | - else |
|
1260 | - return ""; |
|
1310 | + if (strlen($c) === 1 && ord($c[0]) <= 0x7F) { |
|
1311 | + return $c; |
|
1312 | + } elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF) { |
|
1313 | + return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";"; |
|
1314 | + } elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF) { |
|
1315 | + return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";"; |
|
1316 | + } elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7) { |
|
1317 | + return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";"; |
|
1318 | + } else { |
|
1319 | + return ""; |
|
1320 | + } |
|
1261 | 1321 | }; |
1262 | 1322 | |
1263 | 1323 | // Convert all 'special' characters to HTML entities. |
@@ -1271,19 +1331,20 @@ discard block |
||
1271 | 1331 | $string = base64_encode($string); |
1272 | 1332 | |
1273 | 1333 | // Show the characterset and the transfer-encoding for header strings. |
1274 | - if ($with_charset) |
|
1275 | - $string = '=?' . $charset . '?B?' . $string . '?='; |
|
1334 | + if ($with_charset) { |
|
1335 | + $string = '=?' . $charset . '?B?' . $string . '?='; |
|
1336 | + } |
|
1276 | 1337 | |
1277 | 1338 | // Break it up in lines (mail body). |
1278 | - else |
|
1279 | - $string = chunk_split($string, 76, $line_break); |
|
1339 | + else { |
|
1340 | + $string = chunk_split($string, 76, $line_break); |
|
1341 | + } |
|
1280 | 1342 | |
1281 | 1343 | return array($charset, $string, 'base64'); |
1344 | + } else { |
|
1345 | + return array($charset, $string, '7bit'); |
|
1346 | + } |
|
1282 | 1347 | } |
1283 | - |
|
1284 | - else |
|
1285 | - return array($charset, $string, '7bit'); |
|
1286 | -} |
|
1287 | 1348 | |
1288 | 1349 | /** |
1289 | 1350 | * Sends mail, like mail() but over SMTP. |
@@ -1307,8 +1368,9 @@ discard block |
||
1307 | 1368 | if ($modSettings['mail_type'] == 3 && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '') |
1308 | 1369 | { |
1309 | 1370 | $socket = fsockopen($modSettings['smtp_host'], 110, $errno, $errstr, 2); |
1310 | - if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.')) |
|
1311 | - $socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2); |
|
1371 | + if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.')) { |
|
1372 | + $socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2); |
|
1373 | + } |
|
1312 | 1374 | |
1313 | 1375 | if ($socket) |
1314 | 1376 | { |
@@ -1329,8 +1391,9 @@ discard block |
||
1329 | 1391 | // Maybe we can still save this? The port might be wrong. |
1330 | 1392 | if (substr($modSettings['smtp_host'], 0, 4) == 'ssl:' && (empty($modSettings['smtp_port']) || $modSettings['smtp_port'] == 25)) |
1331 | 1393 | { |
1332 | - if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) |
|
1333 | - log_error($txt['smtp_port_ssl']); |
|
1394 | + if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) { |
|
1395 | + log_error($txt['smtp_port_ssl']); |
|
1396 | + } |
|
1334 | 1397 | } |
1335 | 1398 | |
1336 | 1399 | // Unable to connect! Don't show any error message, but just log one and try to continue anyway. |
@@ -1342,20 +1405,23 @@ discard block |
||
1342 | 1405 | } |
1343 | 1406 | |
1344 | 1407 | // Wait for a response of 220, without "-" continuer. |
1345 | - if (!server_parse(null, $socket, '220')) |
|
1346 | - return false; |
|
1408 | + if (!server_parse(null, $socket, '220')) { |
|
1409 | + return false; |
|
1410 | + } |
|
1347 | 1411 | |
1348 | 1412 | // Try and determine the servers name, fall back to the mail servers if not found |
1349 | 1413 | $helo = false; |
1350 | - if (function_exists('gethostname') && gethostname() !== false) |
|
1351 | - $helo = gethostname(); |
|
1352 | - elseif (function_exists('php_uname')) |
|
1353 | - $helo = php_uname('n'); |
|
1354 | - elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME'])) |
|
1355 | - $helo = $_SERVER['SERVER_NAME']; |
|
1414 | + if (function_exists('gethostname') && gethostname() !== false) { |
|
1415 | + $helo = gethostname(); |
|
1416 | + } elseif (function_exists('php_uname')) { |
|
1417 | + $helo = php_uname('n'); |
|
1418 | + } elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME'])) { |
|
1419 | + $helo = $_SERVER['SERVER_NAME']; |
|
1420 | + } |
|
1356 | 1421 | |
1357 | - if (empty($helo)) |
|
1358 | - $helo = $modSettings['smtp_host']; |
|
1422 | + if (empty($helo)) { |
|
1423 | + $helo = $modSettings['smtp_host']; |
|
1424 | + } |
|
1359 | 1425 | |
1360 | 1426 | // SMTP = 1, SMTP - STARTTLS = 2 |
1361 | 1427 | if (in_array($modSettings['mail_type'], array(1, 2)) && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '') |
@@ -1367,33 +1433,39 @@ discard block |
||
1367 | 1433 | if ($modSettings['mail_type'] == 2 && preg_match("~250( |-)STARTTLS~mi", $response)) |
1368 | 1434 | { |
1369 | 1435 | // Send STARTTLS to enable encryption |
1370 | - if (!server_parse('STARTTLS', $socket, '220')) |
|
1371 | - return false; |
|
1436 | + if (!server_parse('STARTTLS', $socket, '220')) { |
|
1437 | + return false; |
|
1438 | + } |
|
1372 | 1439 | // Enable the encryption |
1373 | - if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) |
|
1374 | - return false; |
|
1440 | + if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { |
|
1441 | + return false; |
|
1442 | + } |
|
1375 | 1443 | // Send the EHLO command again |
1376 | - if (!server_parse('EHLO ' . $helo, $socket, null) == '250') |
|
1377 | - return false; |
|
1444 | + if (!server_parse('EHLO ' . $helo, $socket, null) == '250') { |
|
1445 | + return false; |
|
1446 | + } |
|
1378 | 1447 | } |
1379 | 1448 | |
1380 | - if (!server_parse('AUTH LOGIN', $socket, '334')) |
|
1381 | - return false; |
|
1449 | + if (!server_parse('AUTH LOGIN', $socket, '334')) { |
|
1450 | + return false; |
|
1451 | + } |
|
1382 | 1452 | // Send the username and password, encoded. |
1383 | - if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) |
|
1384 | - return false; |
|
1453 | + if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) { |
|
1454 | + return false; |
|
1455 | + } |
|
1385 | 1456 | // The password is already encoded ;) |
1386 | - if (!server_parse($modSettings['smtp_password'], $socket, '235')) |
|
1387 | - return false; |
|
1457 | + if (!server_parse($modSettings['smtp_password'], $socket, '235')) { |
|
1458 | + return false; |
|
1459 | + } |
|
1460 | + } elseif (!server_parse('HELO ' . $helo, $socket, '250')) { |
|
1461 | + return false; |
|
1388 | 1462 | } |
1389 | - elseif (!server_parse('HELO ' . $helo, $socket, '250')) |
|
1390 | - return false; |
|
1391 | - } |
|
1392 | - else |
|
1463 | + } else |
|
1393 | 1464 | { |
1394 | 1465 | // Just say "helo". |
1395 | - if (!server_parse('HELO ' . $helo, $socket, '250')) |
|
1396 | - return false; |
|
1466 | + if (!server_parse('HELO ' . $helo, $socket, '250')) { |
|
1467 | + return false; |
|
1468 | + } |
|
1397 | 1469 | } |
1398 | 1470 | |
1399 | 1471 | // Fix the message for any lines beginning with a period! (the first is ignored, you see.) |
@@ -1406,31 +1478,38 @@ discard block |
||
1406 | 1478 | // Reset the connection to send another email. |
1407 | 1479 | if ($i != 0) |
1408 | 1480 | { |
1409 | - if (!server_parse('RSET', $socket, '250')) |
|
1410 | - return false; |
|
1481 | + if (!server_parse('RSET', $socket, '250')) { |
|
1482 | + return false; |
|
1483 | + } |
|
1411 | 1484 | } |
1412 | 1485 | |
1413 | 1486 | // From, to, and then start the data... |
1414 | - if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) |
|
1415 | - return false; |
|
1416 | - if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) |
|
1417 | - return false; |
|
1418 | - if (!server_parse('DATA', $socket, '354')) |
|
1419 | - return false; |
|
1487 | + if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) { |
|
1488 | + return false; |
|
1489 | + } |
|
1490 | + if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) { |
|
1491 | + return false; |
|
1492 | + } |
|
1493 | + if (!server_parse('DATA', $socket, '354')) { |
|
1494 | + return false; |
|
1495 | + } |
|
1420 | 1496 | fputs($socket, 'Subject: ' . $subject . "\r\n"); |
1421 | - if (strlen($mail_to) > 0) |
|
1422 | - fputs($socket, 'To: <' . $mail_to . '>' . "\r\n"); |
|
1497 | + if (strlen($mail_to) > 0) { |
|
1498 | + fputs($socket, 'To: <' . $mail_to . '>' . "\r\n"); |
|
1499 | + } |
|
1423 | 1500 | fputs($socket, $headers . "\r\n\r\n"); |
1424 | 1501 | fputs($socket, $message . "\r\n"); |
1425 | 1502 | |
1426 | 1503 | // Send a ., or in other words "end of data". |
1427 | - if (!server_parse('.', $socket, '250')) |
|
1428 | - return false; |
|
1504 | + if (!server_parse('.', $socket, '250')) { |
|
1505 | + return false; |
|
1506 | + } |
|
1429 | 1507 | |
1430 | 1508 | // Almost done, almost done... don't stop me just yet! |
1431 | 1509 | @set_time_limit(300); |
1432 | - if (function_exists('apache_reset_timeout')) |
|
1433 | - @apache_reset_timeout(); |
|
1510 | + if (function_exists('apache_reset_timeout')) { |
|
1511 | + @apache_reset_timeout(); |
|
1512 | + } |
|
1434 | 1513 | } |
1435 | 1514 | fputs($socket, 'QUIT' . "\r\n"); |
1436 | 1515 | fclose($socket); |
@@ -1454,8 +1533,9 @@ discard block |
||
1454 | 1533 | { |
1455 | 1534 | global $txt; |
1456 | 1535 | |
1457 | - if ($message !== null) |
|
1458 | - fputs($socket, $message . "\r\n"); |
|
1536 | + if ($message !== null) { |
|
1537 | + fputs($socket, $message . "\r\n"); |
|
1538 | + } |
|
1459 | 1539 | |
1460 | 1540 | // No response yet. |
1461 | 1541 | $server_response = ''; |
@@ -1471,8 +1551,9 @@ discard block |
||
1471 | 1551 | $response .= $server_response; |
1472 | 1552 | } |
1473 | 1553 | |
1474 | - if ($code === null) |
|
1475 | - return substr($server_response, 0, 3); |
|
1554 | + if ($code === null) { |
|
1555 | + return substr($server_response, 0, 3); |
|
1556 | + } |
|
1476 | 1557 | |
1477 | 1558 | if (substr($server_response, 0, 3) != $code) |
1478 | 1559 | { |
@@ -1502,8 +1583,9 @@ discard block |
||
1502 | 1583 | // Create a pspell or enchant dictionary resource |
1503 | 1584 | $dict = spell_init(); |
1504 | 1585 | |
1505 | - if (!isset($_POST['spellstring']) || !$dict) |
|
1506 | - die; |
|
1586 | + if (!isset($_POST['spellstring']) || !$dict) { |
|
1587 | + die; |
|
1588 | + } |
|
1507 | 1589 | |
1508 | 1590 | // Construct a bit of Javascript code. |
1509 | 1591 | $context['spell_js'] = ' |
@@ -1521,8 +1603,9 @@ discard block |
||
1521 | 1603 | $check_word = explode('|', $alphas[$i]); |
1522 | 1604 | |
1523 | 1605 | // If the word is a known word, or spelled right... |
1524 | - if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) |
|
1525 | - continue; |
|
1606 | + if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) { |
|
1607 | + continue; |
|
1608 | + } |
|
1526 | 1609 | |
1527 | 1610 | // Find the word, and move up the "last occurrence" to here. |
1528 | 1611 | $found_words = true; |
@@ -1536,20 +1619,23 @@ discard block |
||
1536 | 1619 | if (!empty($suggestions)) |
1537 | 1620 | { |
1538 | 1621 | // But first check they aren't going to be censored - no naughty words! |
1539 | - foreach ($suggestions as $k => $word) |
|
1540 | - if ($suggestions[$k] != censorText($word)) |
|
1622 | + foreach ($suggestions as $k => $word) { |
|
1623 | + if ($suggestions[$k] != censorText($word)) |
|
1541 | 1624 | unset($suggestions[$k]); |
1625 | + } |
|
1542 | 1626 | |
1543 | - if (!empty($suggestions)) |
|
1544 | - $context['spell_js'] .= '"' . implode('", "', $suggestions) . '"'; |
|
1627 | + if (!empty($suggestions)) { |
|
1628 | + $context['spell_js'] .= '"' . implode('", "', $suggestions) . '"'; |
|
1629 | + } |
|
1545 | 1630 | } |
1546 | 1631 | |
1547 | 1632 | $context['spell_js'] .= ']),'; |
1548 | 1633 | } |
1549 | 1634 | |
1550 | 1635 | // If words were found, take off the last comma. |
1551 | - if ($found_words) |
|
1552 | - $context['spell_js'] = substr($context['spell_js'], 0, -1); |
|
1636 | + if ($found_words) { |
|
1637 | + $context['spell_js'] = substr($context['spell_js'], 0, -1); |
|
1638 | + } |
|
1553 | 1639 | |
1554 | 1640 | $context['spell_js'] .= ' |
1555 | 1641 | );'; |
@@ -1584,11 +1670,13 @@ discard block |
||
1584 | 1670 | global $user_info, $smcFunc; |
1585 | 1671 | |
1586 | 1672 | // Can't do it if there's no topics. |
1587 | - if (empty($topics)) |
|
1588 | - return; |
|
1673 | + if (empty($topics)) { |
|
1674 | + return; |
|
1675 | + } |
|
1589 | 1676 | // It must be an array - it must! |
1590 | - if (!is_array($topics)) |
|
1591 | - $topics = array($topics); |
|
1677 | + if (!is_array($topics)) { |
|
1678 | + $topics = array($topics); |
|
1679 | + } |
|
1592 | 1680 | |
1593 | 1681 | // Get the subject and body... |
1594 | 1682 | $result = $smcFunc['db_query']('', ' |
@@ -1636,14 +1724,15 @@ discard block |
||
1636 | 1724 | } |
1637 | 1725 | $smcFunc['db_free_result']($result); |
1638 | 1726 | |
1639 | - if (!empty($task_rows)) |
|
1640 | - $smcFunc['db_insert']('', |
|
1727 | + if (!empty($task_rows)) { |
|
1728 | + $smcFunc['db_insert']('', |
|
1641 | 1729 | '{db_prefix}background_tasks', |
1642 | 1730 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
1643 | 1731 | $task_rows, |
1644 | 1732 | array('id_task') |
1645 | 1733 | ); |
1646 | -} |
|
1734 | + } |
|
1735 | + } |
|
1647 | 1736 | |
1648 | 1737 | /** |
1649 | 1738 | * Create a post, either as new topic (id_topic = 0) or in an existing one. |
@@ -1681,9 +1770,9 @@ discard block |
||
1681 | 1770 | $msgOptions['send_notifications'] = isset($msgOptions['send_notifications']) ? (bool) $msgOptions['send_notifications'] : true; |
1682 | 1771 | |
1683 | 1772 | // We need to know if the topic is approved. If we're told that's great - if not find out. |
1684 | - if (!$modSettings['postmod_active']) |
|
1685 | - $topicOptions['is_approved'] = true; |
|
1686 | - elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved'])) |
|
1773 | + if (!$modSettings['postmod_active']) { |
|
1774 | + $topicOptions['is_approved'] = true; |
|
1775 | + } elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved'])) |
|
1687 | 1776 | { |
1688 | 1777 | $request = $smcFunc['db_query']('', ' |
1689 | 1778 | SELECT approved |
@@ -1706,8 +1795,7 @@ discard block |
||
1706 | 1795 | $posterOptions['id'] = 0; |
1707 | 1796 | $posterOptions['name'] = $txt['guest_title']; |
1708 | 1797 | $posterOptions['email'] = ''; |
1709 | - } |
|
1710 | - elseif ($posterOptions['id'] != $user_info['id']) |
|
1798 | + } elseif ($posterOptions['id'] != $user_info['id']) |
|
1711 | 1799 | { |
1712 | 1800 | $request = $smcFunc['db_query']('', ' |
1713 | 1801 | SELECT member_name, email_address |
@@ -1725,12 +1813,11 @@ discard block |
||
1725 | 1813 | $posterOptions['id'] = 0; |
1726 | 1814 | $posterOptions['name'] = $txt['guest_title']; |
1727 | 1815 | $posterOptions['email'] = ''; |
1816 | + } else { |
|
1817 | + list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request); |
|
1728 | 1818 | } |
1729 | - else |
|
1730 | - list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request); |
|
1731 | 1819 | $smcFunc['db_free_result']($request); |
1732 | - } |
|
1733 | - else |
|
1820 | + } else |
|
1734 | 1821 | { |
1735 | 1822 | $posterOptions['name'] = $user_info['name']; |
1736 | 1823 | $posterOptions['email'] = $user_info['email']; |
@@ -1740,8 +1827,9 @@ discard block |
||
1740 | 1827 | if (!empty($modSettings['enable_mentions'])) |
1741 | 1828 | { |
1742 | 1829 | $msgOptions['mentioned_members'] = Mentions::getMentionedMembers($msgOptions['body']); |
1743 | - if (!empty($msgOptions['mentioned_members'])) |
|
1744 | - $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']); |
|
1830 | + if (!empty($msgOptions['mentioned_members'])) { |
|
1831 | + $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']); |
|
1832 | + } |
|
1745 | 1833 | } |
1746 | 1834 | |
1747 | 1835 | // It's do or die time: forget any user aborts! |
@@ -1774,12 +1862,13 @@ discard block |
||
1774 | 1862 | ); |
1775 | 1863 | |
1776 | 1864 | // Something went wrong creating the message... |
1777 | - if (empty($msgOptions['id'])) |
|
1778 | - return false; |
|
1865 | + if (empty($msgOptions['id'])) { |
|
1866 | + return false; |
|
1867 | + } |
|
1779 | 1868 | |
1780 | 1869 | // Fix the attachments. |
1781 | - if (!empty($msgOptions['attachments'])) |
|
1782 | - $smcFunc['db_query']('', ' |
|
1870 | + if (!empty($msgOptions['attachments'])) { |
|
1871 | + $smcFunc['db_query']('', ' |
|
1783 | 1872 | UPDATE {db_prefix}attachments |
1784 | 1873 | SET id_msg = {int:id_msg} |
1785 | 1874 | WHERE id_attach IN ({array_int:attachment_list})', |
@@ -1788,6 +1877,7 @@ discard block |
||
1788 | 1877 | 'id_msg' => $msgOptions['id'], |
1789 | 1878 | ) |
1790 | 1879 | ); |
1880 | + } |
|
1791 | 1881 | |
1792 | 1882 | // What if we want to export new posts out to a CMS? |
1793 | 1883 | call_integration_hook('integrate_after_create_post', array($msgOptions, $topicOptions, $posterOptions, $message_columns, $message_parameters)); |
@@ -1864,20 +1954,23 @@ discard block |
||
1864 | 1954 | 'id_topic' => $topicOptions['id'], |
1865 | 1955 | 'counter_increment' => 1, |
1866 | 1956 | ); |
1867 | - if ($msgOptions['approved']) |
|
1868 | - $topics_columns = array( |
|
1957 | + if ($msgOptions['approved']) { |
|
1958 | + $topics_columns = array( |
|
1869 | 1959 | 'id_member_updated = {int:poster_id}', |
1870 | 1960 | 'id_last_msg = {int:id_msg}', |
1871 | 1961 | 'num_replies = num_replies + {int:counter_increment}', |
1872 | 1962 | ); |
1873 | - else |
|
1874 | - $topics_columns = array( |
|
1963 | + } else { |
|
1964 | + $topics_columns = array( |
|
1875 | 1965 | 'unapproved_posts = unapproved_posts + {int:counter_increment}', |
1876 | 1966 | ); |
1877 | - if ($topicOptions['lock_mode'] !== null) |
|
1878 | - $topics_columns[] = 'locked = {int:locked}'; |
|
1879 | - if ($topicOptions['sticky_mode'] !== null) |
|
1880 | - $topics_columns[] = 'is_sticky = {int:is_sticky}'; |
|
1967 | + } |
|
1968 | + if ($topicOptions['lock_mode'] !== null) { |
|
1969 | + $topics_columns[] = 'locked = {int:locked}'; |
|
1970 | + } |
|
1971 | + if ($topicOptions['sticky_mode'] !== null) { |
|
1972 | + $topics_columns[] = 'is_sticky = {int:is_sticky}'; |
|
1973 | + } |
|
1881 | 1974 | |
1882 | 1975 | call_integration_hook('integrate_modify_topic', array(&$topics_columns, &$update_parameters, &$msgOptions, &$topicOptions, &$posterOptions)); |
1883 | 1976 | |
@@ -1906,8 +1999,8 @@ discard block |
||
1906 | 1999 | ); |
1907 | 2000 | |
1908 | 2001 | // Increase the number of posts and topics on the board. |
1909 | - if ($msgOptions['approved']) |
|
1910 | - $smcFunc['db_query']('', ' |
|
2002 | + if ($msgOptions['approved']) { |
|
2003 | + $smcFunc['db_query']('', ' |
|
1911 | 2004 | UPDATE {db_prefix}boards |
1912 | 2005 | SET num_posts = num_posts + 1' . ($new_topic ? ', num_topics = num_topics + 1' : '') . ' |
1913 | 2006 | WHERE id_board = {int:id_board}', |
@@ -1915,7 +2008,7 @@ discard block |
||
1915 | 2008 | 'id_board' => $topicOptions['board'], |
1916 | 2009 | ) |
1917 | 2010 | ); |
1918 | - else |
|
2011 | + } else |
|
1919 | 2012 | { |
1920 | 2013 | $smcFunc['db_query']('', ' |
1921 | 2014 | UPDATE {db_prefix}boards |
@@ -1985,8 +2078,8 @@ discard block |
||
1985 | 2078 | } |
1986 | 2079 | } |
1987 | 2080 | |
1988 | - if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) |
|
1989 | - $smcFunc['db_insert']('', |
|
2081 | + if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) { |
|
2082 | + $smcFunc['db_insert']('', |
|
1990 | 2083 | '{db_prefix}background_tasks', |
1991 | 2084 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
1992 | 2085 | array( |
@@ -1998,19 +2091,22 @@ discard block |
||
1998 | 2091 | ), |
1999 | 2092 | array('id_task') |
2000 | 2093 | ); |
2094 | + } |
|
2001 | 2095 | |
2002 | 2096 | // If there's a custom search index, it may need updating... |
2003 | 2097 | require_once($sourcedir . '/Search.php'); |
2004 | 2098 | $searchAPI = findSearchAPI(); |
2005 | - if (is_callable(array($searchAPI, 'postCreated'))) |
|
2006 | - $searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions); |
|
2099 | + if (is_callable(array($searchAPI, 'postCreated'))) { |
|
2100 | + $searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions); |
|
2101 | + } |
|
2007 | 2102 | |
2008 | 2103 | // Increase the post counter for the user that created the post. |
2009 | 2104 | if (!empty($posterOptions['update_post_count']) && !empty($posterOptions['id']) && $msgOptions['approved']) |
2010 | 2105 | { |
2011 | 2106 | // Are you the one that happened to create this post? |
2012 | - if ($user_info['id'] == $posterOptions['id']) |
|
2013 | - $user_info['posts']++; |
|
2107 | + if ($user_info['id'] == $posterOptions['id']) { |
|
2108 | + $user_info['posts']++; |
|
2109 | + } |
|
2014 | 2110 | updateMemberData($posterOptions['id'], array('posts' => '+')); |
2015 | 2111 | } |
2016 | 2112 | |
@@ -2018,19 +2114,21 @@ discard block |
||
2018 | 2114 | $_SESSION['last_read_topic'] = 0; |
2019 | 2115 | |
2020 | 2116 | // Better safe than sorry. |
2021 | - if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) |
|
2022 | - $_SESSION['topicseen_cache'][$topicOptions['board']]--; |
|
2117 | + if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) { |
|
2118 | + $_SESSION['topicseen_cache'][$topicOptions['board']]--; |
|
2119 | + } |
|
2023 | 2120 | |
2024 | 2121 | // Update all the stats so everyone knows about this new topic and message. |
2025 | 2122 | updateStats('message', true, $msgOptions['id']); |
2026 | 2123 | |
2027 | 2124 | // Update the last message on the board assuming it's approved AND the topic is. |
2028 | - if ($msgOptions['approved']) |
|
2029 | - updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0); |
|
2125 | + if ($msgOptions['approved']) { |
|
2126 | + updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0); |
|
2127 | + } |
|
2030 | 2128 | |
2031 | 2129 | // Queue createPost background notification |
2032 | - if ($msgOptions['send_notifications'] && $msgOptions['approved']) |
|
2033 | - $smcFunc['db_insert']('', |
|
2130 | + if ($msgOptions['send_notifications'] && $msgOptions['approved']) { |
|
2131 | + $smcFunc['db_insert']('', |
|
2034 | 2132 | '{db_prefix}background_tasks', |
2035 | 2133 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
2036 | 2134 | array('$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', json_encode(array( |
@@ -2041,6 +2139,7 @@ discard block |
||
2041 | 2139 | )), 0), |
2042 | 2140 | array('id_task') |
2043 | 2141 | ); |
2142 | + } |
|
2044 | 2143 | |
2045 | 2144 | // Alright, done now... we can abort now, I guess... at least this much is done. |
2046 | 2145 | ignore_user_abort($previous_ignore_user_abort); |
@@ -2067,14 +2166,18 @@ discard block |
||
2067 | 2166 | |
2068 | 2167 | // This is longer than it has to be, but makes it so we only set/change what we have to. |
2069 | 2168 | $messages_columns = array(); |
2070 | - if (isset($posterOptions['name'])) |
|
2071 | - $messages_columns['poster_name'] = $posterOptions['name']; |
|
2072 | - if (isset($posterOptions['email'])) |
|
2073 | - $messages_columns['poster_email'] = $posterOptions['email']; |
|
2074 | - if (isset($msgOptions['icon'])) |
|
2075 | - $messages_columns['icon'] = $msgOptions['icon']; |
|
2076 | - if (isset($msgOptions['subject'])) |
|
2077 | - $messages_columns['subject'] = $msgOptions['subject']; |
|
2169 | + if (isset($posterOptions['name'])) { |
|
2170 | + $messages_columns['poster_name'] = $posterOptions['name']; |
|
2171 | + } |
|
2172 | + if (isset($posterOptions['email'])) { |
|
2173 | + $messages_columns['poster_email'] = $posterOptions['email']; |
|
2174 | + } |
|
2175 | + if (isset($msgOptions['icon'])) { |
|
2176 | + $messages_columns['icon'] = $msgOptions['icon']; |
|
2177 | + } |
|
2178 | + if (isset($msgOptions['subject'])) { |
|
2179 | + $messages_columns['subject'] = $msgOptions['subject']; |
|
2180 | + } |
|
2078 | 2181 | if (isset($msgOptions['body'])) |
2079 | 2182 | { |
2080 | 2183 | $messages_columns['body'] = $msgOptions['body']; |
@@ -2101,8 +2204,9 @@ discard block |
||
2101 | 2204 | $messages_columns['modified_reason'] = $msgOptions['modify_reason']; |
2102 | 2205 | $messages_columns['id_msg_modified'] = $modSettings['maxMsgID']; |
2103 | 2206 | } |
2104 | - if (isset($msgOptions['smileys_enabled'])) |
|
2105 | - $messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1; |
|
2207 | + if (isset($msgOptions['smileys_enabled'])) { |
|
2208 | + $messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1; |
|
2209 | + } |
|
2106 | 2210 | |
2107 | 2211 | // Which columns need to be ints? |
2108 | 2212 | $messageInts = array('modified_time', 'id_msg_modified', 'smileys_enabled'); |
@@ -2120,23 +2224,27 @@ discard block |
||
2120 | 2224 | { |
2121 | 2225 | preg_match_all('/\[member\=([0-9]+)\]([^\[]*)\[\/member\]/U', $msgOptions['old_body'], $match); |
2122 | 2226 | |
2123 | - if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) |
|
2124 | - foreach ($match[1] as $i => $oldID) |
|
2227 | + if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) { |
|
2228 | + foreach ($match[1] as $i => $oldID) |
|
2125 | 2229 | $oldmentions[$oldID] = array('id' => $oldID, 'real_name' => $match[2][$i]); |
2230 | + } |
|
2126 | 2231 | |
2127 | - if (empty($modSettings['search_custom_index_config'])) |
|
2128 | - unset($msgOptions['old_body']); |
|
2232 | + if (empty($modSettings['search_custom_index_config'])) { |
|
2233 | + unset($msgOptions['old_body']); |
|
2234 | + } |
|
2129 | 2235 | } |
2130 | 2236 | |
2131 | 2237 | $mentions = Mentions::getMentionedMembers($msgOptions['body']); |
2132 | 2238 | $messages_columns['body'] = $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $mentions); |
2133 | 2239 | |
2134 | 2240 | // Remove the poster. |
2135 | - if (isset($mentions[$user_info['id']])) |
|
2136 | - unset($mentions[$user_info['id']]); |
|
2241 | + if (isset($mentions[$user_info['id']])) { |
|
2242 | + unset($mentions[$user_info['id']]); |
|
2243 | + } |
|
2137 | 2244 | |
2138 | - if (isset($oldmentions[$user_info['id']])) |
|
2139 | - unset($oldmentions[$user_info['id']]); |
|
2245 | + if (isset($oldmentions[$user_info['id']])) { |
|
2246 | + unset($oldmentions[$user_info['id']]); |
|
2247 | + } |
|
2140 | 2248 | |
2141 | 2249 | if (is_array($mentions) && is_array($oldmentions) && count(array_diff_key($mentions, $oldmentions)) > 0 && count($mentions) > count($oldmentions)) |
2142 | 2250 | { |
@@ -2166,8 +2274,9 @@ discard block |
||
2166 | 2274 | } |
2167 | 2275 | |
2168 | 2276 | // Nothing to do? |
2169 | - if (empty($messages_columns)) |
|
2170 | - return true; |
|
2277 | + if (empty($messages_columns)) { |
|
2278 | + return true; |
|
2279 | + } |
|
2171 | 2280 | |
2172 | 2281 | // Change the post. |
2173 | 2282 | $smcFunc['db_query']('', ' |
@@ -2228,8 +2337,9 @@ discard block |
||
2228 | 2337 | // If there's a custom search index, it needs to be modified... |
2229 | 2338 | require_once($sourcedir . '/Search.php'); |
2230 | 2339 | $searchAPI = findSearchAPI(); |
2231 | - if (is_callable(array($searchAPI, 'postModified'))) |
|
2232 | - $searchAPI->postModified($msgOptions, $topicOptions, $posterOptions); |
|
2340 | + if (is_callable(array($searchAPI, 'postModified'))) { |
|
2341 | + $searchAPI->postModified($msgOptions, $topicOptions, $posterOptions); |
|
2342 | + } |
|
2233 | 2343 | |
2234 | 2344 | if (isset($msgOptions['subject'])) |
2235 | 2345 | { |
@@ -2243,14 +2353,16 @@ discard block |
||
2243 | 2353 | 'id_first_msg' => $msgOptions['id'], |
2244 | 2354 | ) |
2245 | 2355 | ); |
2246 | - if ($smcFunc['db_num_rows']($request) == 1) |
|
2247 | - updateStats('subject', $topicOptions['id'], $msgOptions['subject']); |
|
2356 | + if ($smcFunc['db_num_rows']($request) == 1) { |
|
2357 | + updateStats('subject', $topicOptions['id'], $msgOptions['subject']); |
|
2358 | + } |
|
2248 | 2359 | $smcFunc['db_free_result']($request); |
2249 | 2360 | } |
2250 | 2361 | |
2251 | 2362 | // Finally, if we are setting the approved state we need to do much more work :( |
2252 | - if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) |
|
2253 | - approvePosts($msgOptions['id'], $msgOptions['approved']); |
|
2363 | + if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) { |
|
2364 | + approvePosts($msgOptions['id'], $msgOptions['approved']); |
|
2365 | + } |
|
2254 | 2366 | |
2255 | 2367 | return true; |
2256 | 2368 | } |
@@ -2267,11 +2379,13 @@ discard block |
||
2267 | 2379 | { |
2268 | 2380 | global $smcFunc; |
2269 | 2381 | |
2270 | - if (!is_array($msgs)) |
|
2271 | - $msgs = array($msgs); |
|
2382 | + if (!is_array($msgs)) { |
|
2383 | + $msgs = array($msgs); |
|
2384 | + } |
|
2272 | 2385 | |
2273 | - if (empty($msgs)) |
|
2274 | - return false; |
|
2386 | + if (empty($msgs)) { |
|
2387 | + return false; |
|
2388 | + } |
|
2275 | 2389 | |
2276 | 2390 | // May as well start at the beginning, working out *what* we need to change. |
2277 | 2391 | $request = $smcFunc['db_query']('', ' |
@@ -2303,20 +2417,22 @@ discard block |
||
2303 | 2417 | $topics[] = $row['id_topic']; |
2304 | 2418 | |
2305 | 2419 | // Ensure our change array exists already. |
2306 | - if (!isset($topic_changes[$row['id_topic']])) |
|
2307 | - $topic_changes[$row['id_topic']] = array( |
|
2420 | + if (!isset($topic_changes[$row['id_topic']])) { |
|
2421 | + $topic_changes[$row['id_topic']] = array( |
|
2308 | 2422 | 'id_last_msg' => $row['id_last_msg'], |
2309 | 2423 | 'approved' => $row['topic_approved'], |
2310 | 2424 | 'replies' => 0, |
2311 | 2425 | 'unapproved_posts' => 0, |
2312 | 2426 | ); |
2313 | - if (!isset($board_changes[$row['id_board']])) |
|
2314 | - $board_changes[$row['id_board']] = array( |
|
2427 | + } |
|
2428 | + if (!isset($board_changes[$row['id_board']])) { |
|
2429 | + $board_changes[$row['id_board']] = array( |
|
2315 | 2430 | 'posts' => 0, |
2316 | 2431 | 'topics' => 0, |
2317 | 2432 | 'unapproved_posts' => 0, |
2318 | 2433 | 'unapproved_topics' => 0, |
2319 | 2434 | ); |
2435 | + } |
|
2320 | 2436 | |
2321 | 2437 | // If it's the first message then the topic state changes! |
2322 | 2438 | if ($row['id_msg'] == $row['id_first_msg']) |
@@ -2337,14 +2453,13 @@ discard block |
||
2337 | 2453 | 'poster' => $row['id_member'], |
2338 | 2454 | 'new_topic' => true, |
2339 | 2455 | ); |
2340 | - } |
|
2341 | - else |
|
2456 | + } else |
|
2342 | 2457 | { |
2343 | 2458 | $topic_changes[$row['id_topic']]['replies'] += $approve ? 1 : -1; |
2344 | 2459 | |
2345 | 2460 | // This will be a post... but don't notify unless it's not followed by approved ones. |
2346 | - if ($row['id_msg'] > $row['id_last_msg']) |
|
2347 | - $notification_posts[$row['id_topic']] = array( |
|
2461 | + if ($row['id_msg'] > $row['id_last_msg']) { |
|
2462 | + $notification_posts[$row['id_topic']] = array( |
|
2348 | 2463 | 'id' => $row['id_msg'], |
2349 | 2464 | 'body' => $row['body'], |
2350 | 2465 | 'subject' => $row['subject'], |
@@ -2355,28 +2470,33 @@ discard block |
||
2355 | 2470 | 'new_topic' => false, |
2356 | 2471 | 'msg' => $row['id_msg'], |
2357 | 2472 | ); |
2473 | + } |
|
2358 | 2474 | } |
2359 | 2475 | |
2360 | 2476 | // If this is being approved and id_msg is higher than the current id_last_msg then it changes. |
2361 | - if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) |
|
2362 | - $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg']; |
|
2477 | + if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) { |
|
2478 | + $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg']; |
|
2479 | + } |
|
2363 | 2480 | // If this is being unapproved, and it's equal to the id_last_msg we need to find a new one! |
2364 | - elseif (!$approve) |
|
2365 | - // Default to the first message and then we'll override in a bit ;) |
|
2481 | + elseif (!$approve) { |
|
2482 | + // Default to the first message and then we'll override in a bit ;) |
|
2366 | 2483 | $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_first_msg']; |
2484 | + } |
|
2367 | 2485 | |
2368 | 2486 | $topic_changes[$row['id_topic']]['unapproved_posts'] += $approve ? -1 : 1; |
2369 | 2487 | $board_changes[$row['id_board']]['unapproved_posts'] += $approve ? -1 : 1; |
2370 | 2488 | $board_changes[$row['id_board']]['posts'] += $approve ? 1 : -1; |
2371 | 2489 | |
2372 | 2490 | // Post count for the user? |
2373 | - if ($row['id_member'] && empty($row['count_posts'])) |
|
2374 | - $member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1; |
|
2491 | + if ($row['id_member'] && empty($row['count_posts'])) { |
|
2492 | + $member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1; |
|
2493 | + } |
|
2375 | 2494 | } |
2376 | 2495 | $smcFunc['db_free_result']($request); |
2377 | 2496 | |
2378 | - if (empty($msgs)) |
|
2379 | - return; |
|
2497 | + if (empty($msgs)) { |
|
2498 | + return; |
|
2499 | + } |
|
2380 | 2500 | |
2381 | 2501 | // Now we have the differences make the changes, first the easy one. |
2382 | 2502 | $smcFunc['db_query']('', ' |
@@ -2403,14 +2523,15 @@ discard block |
||
2403 | 2523 | 'approved' => 1, |
2404 | 2524 | ) |
2405 | 2525 | ); |
2406 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2407 | - $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg']; |
|
2526 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2527 | + $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg']; |
|
2528 | + } |
|
2408 | 2529 | $smcFunc['db_free_result']($request); |
2409 | 2530 | } |
2410 | 2531 | |
2411 | 2532 | // ... next the topics... |
2412 | - foreach ($topic_changes as $id => $changes) |
|
2413 | - $smcFunc['db_query']('', ' |
|
2533 | + foreach ($topic_changes as $id => $changes) { |
|
2534 | + $smcFunc['db_query']('', ' |
|
2414 | 2535 | UPDATE {db_prefix}topics |
2415 | 2536 | SET approved = {int:approved}, unapproved_posts = unapproved_posts + {int:unapproved_posts}, |
2416 | 2537 | num_replies = num_replies + {int:num_replies}, id_last_msg = {int:id_last_msg} |
@@ -2423,10 +2544,11 @@ discard block |
||
2423 | 2544 | 'id_topic' => $id, |
2424 | 2545 | ) |
2425 | 2546 | ); |
2547 | + } |
|
2426 | 2548 | |
2427 | 2549 | // ... finally the boards... |
2428 | - foreach ($board_changes as $id => $changes) |
|
2429 | - $smcFunc['db_query']('', ' |
|
2550 | + foreach ($board_changes as $id => $changes) { |
|
2551 | + $smcFunc['db_query']('', ' |
|
2430 | 2552 | UPDATE {db_prefix}boards |
2431 | 2553 | SET num_posts = num_posts + {int:num_posts}, unapproved_posts = unapproved_posts + {int:unapproved_posts}, |
2432 | 2554 | num_topics = num_topics + {int:num_topics}, unapproved_topics = unapproved_topics + {int:unapproved_topics} |
@@ -2439,13 +2561,14 @@ discard block |
||
2439 | 2561 | 'id_board' => $id, |
2440 | 2562 | ) |
2441 | 2563 | ); |
2564 | + } |
|
2442 | 2565 | |
2443 | 2566 | // Finally, least importantly, notifications! |
2444 | 2567 | if ($approve) |
2445 | 2568 | { |
2446 | 2569 | $task_rows = array(); |
2447 | - foreach (array_merge($notification_topics, $notification_posts) as $topic) |
|
2448 | - $task_rows[] = array( |
|
2570 | + foreach (array_merge($notification_topics, $notification_posts) as $topic) { |
|
2571 | + $task_rows[] = array( |
|
2449 | 2572 | '$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', json_encode(array( |
2450 | 2573 | 'msgOptions' => array( |
2451 | 2574 | 'id' => $topic['msg'], |
@@ -2463,14 +2586,16 @@ discard block |
||
2463 | 2586 | 'type' => $topic['new_topic'] ? 'topic' : 'reply', |
2464 | 2587 | )), 0 |
2465 | 2588 | ); |
2589 | + } |
|
2466 | 2590 | |
2467 | - if ($notify) |
|
2468 | - $smcFunc['db_insert']('', |
|
2591 | + if ($notify) { |
|
2592 | + $smcFunc['db_insert']('', |
|
2469 | 2593 | '{db_prefix}background_tasks', |
2470 | 2594 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
2471 | 2595 | $task_rows, |
2472 | 2596 | array('id_task') |
2473 | 2597 | ); |
2598 | + } |
|
2474 | 2599 | |
2475 | 2600 | $smcFunc['db_query']('', ' |
2476 | 2601 | DELETE FROM {db_prefix}approval_queue |
@@ -2486,8 +2611,9 @@ discard block |
||
2486 | 2611 | else |
2487 | 2612 | { |
2488 | 2613 | $msgInserts = array(); |
2489 | - foreach ($msgs as $msg) |
|
2490 | - $msgInserts[] = array($msg); |
|
2614 | + foreach ($msgs as $msg) { |
|
2615 | + $msgInserts[] = array($msg); |
|
2616 | + } |
|
2491 | 2617 | |
2492 | 2618 | $smcFunc['db_insert']('ignore', |
2493 | 2619 | '{db_prefix}approval_queue', |
@@ -2501,9 +2627,10 @@ discard block |
||
2501 | 2627 | updateLastMessages(array_keys($board_changes)); |
2502 | 2628 | |
2503 | 2629 | // Post count for the members? |
2504 | - if (!empty($member_post_changes)) |
|
2505 | - foreach ($member_post_changes as $id_member => $count_change) |
|
2630 | + if (!empty($member_post_changes)) { |
|
2631 | + foreach ($member_post_changes as $id_member => $count_change) |
|
2506 | 2632 | updateMemberData($id_member, array('posts' => 'posts ' . ($approve ? '+' : '-') . ' ' . $count_change)); |
2633 | + } |
|
2507 | 2634 | |
2508 | 2635 | return true; |
2509 | 2636 | } |
@@ -2520,11 +2647,13 @@ discard block |
||
2520 | 2647 | { |
2521 | 2648 | global $smcFunc; |
2522 | 2649 | |
2523 | - if (!is_array($topics)) |
|
2524 | - $topics = array($topics); |
|
2650 | + if (!is_array($topics)) { |
|
2651 | + $topics = array($topics); |
|
2652 | + } |
|
2525 | 2653 | |
2526 | - if (empty($topics)) |
|
2527 | - return false; |
|
2654 | + if (empty($topics)) { |
|
2655 | + return false; |
|
2656 | + } |
|
2528 | 2657 | |
2529 | 2658 | $approve_type = $approve ? 0 : 1; |
2530 | 2659 | |
@@ -2540,8 +2669,9 @@ discard block |
||
2540 | 2669 | ) |
2541 | 2670 | ); |
2542 | 2671 | $msgs = array(); |
2543 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2544 | - $msgs[] = $row['id_msg']; |
|
2672 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2673 | + $msgs[] = $row['id_msg']; |
|
2674 | + } |
|
2545 | 2675 | $smcFunc['db_free_result']($request); |
2546 | 2676 | |
2547 | 2677 | return approvePosts($msgs, $approve); |
@@ -2564,11 +2694,13 @@ discard block |
||
2564 | 2694 | global $board_info, $board, $smcFunc; |
2565 | 2695 | |
2566 | 2696 | // Please - let's be sane. |
2567 | - if (empty($setboards)) |
|
2568 | - return false; |
|
2697 | + if (empty($setboards)) { |
|
2698 | + return false; |
|
2699 | + } |
|
2569 | 2700 | |
2570 | - if (!is_array($setboards)) |
|
2571 | - $setboards = array($setboards); |
|
2701 | + if (!is_array($setboards)) { |
|
2702 | + $setboards = array($setboards); |
|
2703 | + } |
|
2572 | 2704 | |
2573 | 2705 | // If we don't know the id_msg we need to find it. |
2574 | 2706 | if (!$id_msg) |
@@ -2586,15 +2718,16 @@ discard block |
||
2586 | 2718 | ) |
2587 | 2719 | ); |
2588 | 2720 | $lastMsg = array(); |
2589 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2590 | - $lastMsg[$row['id_board']] = $row['id_msg']; |
|
2721 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2722 | + $lastMsg[$row['id_board']] = $row['id_msg']; |
|
2723 | + } |
|
2591 | 2724 | $smcFunc['db_free_result']($request); |
2592 | - } |
|
2593 | - else |
|
2725 | + } else |
|
2594 | 2726 | { |
2595 | 2727 | // Just to note - there should only be one board passed if we are doing this. |
2596 | - foreach ($setboards as $id_board) |
|
2597 | - $lastMsg[$id_board] = $id_msg; |
|
2728 | + foreach ($setboards as $id_board) { |
|
2729 | + $lastMsg[$id_board] = $id_msg; |
|
2730 | + } |
|
2598 | 2731 | } |
2599 | 2732 | |
2600 | 2733 | $parent_boards = array(); |
@@ -2609,10 +2742,11 @@ discard block |
||
2609 | 2742 | $lastModified[$id_board] = 0; |
2610 | 2743 | } |
2611 | 2744 | |
2612 | - if (!empty($board) && $id_board == $board) |
|
2613 | - $parents = $board_info['parent_boards']; |
|
2614 | - else |
|
2615 | - $parents = getBoardParents($id_board); |
|
2745 | + if (!empty($board) && $id_board == $board) { |
|
2746 | + $parents = $board_info['parent_boards']; |
|
2747 | + } else { |
|
2748 | + $parents = getBoardParents($id_board); |
|
2749 | + } |
|
2616 | 2750 | |
2617 | 2751 | // Ignore any parents on the top child level. |
2618 | 2752 | // @todo Why? |
@@ -2621,10 +2755,11 @@ discard block |
||
2621 | 2755 | if ($parent['level'] != 0) |
2622 | 2756 | { |
2623 | 2757 | // If we're already doing this one as a board, is this a higher last modified? |
2624 | - if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) |
|
2625 | - $lastModified[$id] = $lastModified[$id_board]; |
|
2626 | - elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) |
|
2627 | - $parent_boards[$id] = $lastModified[$id_board]; |
|
2758 | + if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) { |
|
2759 | + $lastModified[$id] = $lastModified[$id_board]; |
|
2760 | + } elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) { |
|
2761 | + $parent_boards[$id] = $lastModified[$id_board]; |
|
2762 | + } |
|
2628 | 2763 | } |
2629 | 2764 | } |
2630 | 2765 | } |
@@ -2637,23 +2772,24 @@ discard block |
||
2637 | 2772 | // Finally, to save on queries make the changes... |
2638 | 2773 | foreach ($parent_boards as $id => $msg) |
2639 | 2774 | { |
2640 | - if (!isset($parent_updates[$msg])) |
|
2641 | - $parent_updates[$msg] = array($id); |
|
2642 | - else |
|
2643 | - $parent_updates[$msg][] = $id; |
|
2775 | + if (!isset($parent_updates[$msg])) { |
|
2776 | + $parent_updates[$msg] = array($id); |
|
2777 | + } else { |
|
2778 | + $parent_updates[$msg][] = $id; |
|
2779 | + } |
|
2644 | 2780 | } |
2645 | 2781 | |
2646 | 2782 | foreach ($lastMsg as $id => $msg) |
2647 | 2783 | { |
2648 | - if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) |
|
2649 | - $board_updates[$msg . '-' . $lastModified[$id]] = array( |
|
2784 | + if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) { |
|
2785 | + $board_updates[$msg . '-' . $lastModified[$id]] = array( |
|
2650 | 2786 | 'id' => $msg, |
2651 | 2787 | 'updated' => $lastModified[$id], |
2652 | 2788 | 'boards' => array($id) |
2653 | 2789 | ); |
2654 | - |
|
2655 | - else |
|
2656 | - $board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id; |
|
2790 | + } else { |
|
2791 | + $board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id; |
|
2792 | + } |
|
2657 | 2793 | } |
2658 | 2794 | |
2659 | 2795 | // Now commit the changes! |
@@ -2745,11 +2881,13 @@ discard block |
||
2745 | 2881 | global $txt, $mbname, $scripturl, $settings; |
2746 | 2882 | |
2747 | 2883 | // First things first, load up the email templates language file, if we need to. |
2748 | - if ($loadLang) |
|
2749 | - loadLanguage('EmailTemplates', $lang); |
|
2884 | + if ($loadLang) { |
|
2885 | + loadLanguage('EmailTemplates', $lang); |
|
2886 | + } |
|
2750 | 2887 | |
2751 | - if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) |
|
2752 | - fatal_lang_error('email_no_template', 'template', array($template)); |
|
2888 | + if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) { |
|
2889 | + fatal_lang_error('email_no_template', 'template', array($template)); |
|
2890 | + } |
|
2753 | 2891 | |
2754 | 2892 | $ret = array( |
2755 | 2893 | 'subject' => $txt[$template . '_subject'], |
@@ -2799,17 +2937,18 @@ discard block |
||
2799 | 2937 | function user_info_callback($matches) |
2800 | 2938 | { |
2801 | 2939 | global $user_info; |
2802 | - if (empty($matches[1])) |
|
2803 | - return ''; |
|
2940 | + if (empty($matches[1])) { |
|
2941 | + return ''; |
|
2942 | + } |
|
2804 | 2943 | |
2805 | 2944 | $use_ref = true; |
2806 | 2945 | $ref = &$user_info; |
2807 | 2946 | |
2808 | 2947 | foreach (explode('.', $matches[1]) as $index) |
2809 | 2948 | { |
2810 | - if ($use_ref && isset($ref[$index])) |
|
2811 | - $ref = &$ref[$index]; |
|
2812 | - else |
|
2949 | + if ($use_ref && isset($ref[$index])) { |
|
2950 | + $ref = &$ref[$index]; |
|
2951 | + } else |
|
2813 | 2952 | { |
2814 | 2953 | $use_ref = false; |
2815 | 2954 | break; |
@@ -2846,8 +2985,7 @@ discard block |
||
2846 | 2985 | if (!empty($lang_locale) && enchant_broker_dict_exists($context['enchant_broker'], $lang_locale)) |
2847 | 2986 | { |
2848 | 2987 | $enchant_link = enchant_broker_request_dict($context['enchant_broker'], $lang_locale); |
2849 | - } |
|
2850 | - elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary'])) |
|
2988 | + } elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary'])) |
|
2851 | 2989 | { |
2852 | 2990 | $enchant_link = enchant_broker_request_dict($context['enchant_broker'], $txt['lang_dictionary']); |
2853 | 2991 | } |
@@ -2857,8 +2995,7 @@ discard block |
||
2857 | 2995 | { |
2858 | 2996 | $context['provider'] = 'enchant'; |
2859 | 2997 | return $enchant_link; |
2860 | - } |
|
2861 | - else |
|
2998 | + } else |
|
2862 | 2999 | { |
2863 | 3000 | // Free up any resources used... |
2864 | 3001 | @enchant_broker_free($context['enchant_broker']); |
@@ -2879,8 +3016,9 @@ discard block |
||
2879 | 3016 | $pspell_link = pspell_new($txt['lang_dictionary'], $txt['lang_spelling'], '', strtr($context['character_set'], array('iso-' => 'iso', 'ISO-' => 'iso')), PSPELL_FAST | PSPELL_RUN_TOGETHER); |
2880 | 3017 | |
2881 | 3018 | // Most people don't have anything but English installed... So we use English as a last resort. |
2882 | - if (!$pspell_link) |
|
2883 | - $pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER); |
|
3019 | + if (!$pspell_link) { |
|
3020 | + $pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER); |
|
3021 | + } |
|
2884 | 3022 | |
2885 | 3023 | error_reporting($old); |
2886 | 3024 | ob_end_clean(); |
@@ -2920,8 +3058,7 @@ discard block |
||
2920 | 3058 | $word = iconv($txt['lang_character_set'], 'UTF-8', $word); |
2921 | 3059 | } |
2922 | 3060 | return enchant_dict_check($dict, $word); |
2923 | - } |
|
2924 | - elseif ($context['provider'] == 'pspell') |
|
3061 | + } elseif ($context['provider'] == 'pspell') |
|
2925 | 3062 | { |
2926 | 3063 | return pspell_check($dict, $word); |
2927 | 3064 | } |
@@ -2957,13 +3094,11 @@ discard block |
||
2957 | 3094 | } |
2958 | 3095 | |
2959 | 3096 | return $suggestions; |
2960 | - } |
|
2961 | - else |
|
3097 | + } else |
|
2962 | 3098 | { |
2963 | 3099 | return enchant_dict_suggest($dict, $word); |
2964 | 3100 | } |
2965 | - } |
|
2966 | - elseif ($context['provider'] == 'pspell') |
|
3101 | + } elseif ($context['provider'] == 'pspell') |
|
2967 | 3102 | { |
2968 | 3103 | return pspell_suggest($dict, $word); |
2969 | 3104 | } |
@@ -566,7 +566,7 @@ discard block |
||
566 | 566 | * |
567 | 567 | * @param int $report_id The report ID is used to fire a notification about the event. |
568 | 568 | * @param array $data a formatted array of data to be inserted. Should be already properly sanitized. |
569 | - * @return bool Boolean false if no data was provided. |
|
569 | + * @return false|null Boolean false if no data was provided. |
|
570 | 570 | */ |
571 | 571 | function saveModComment($report_id, $data) |
572 | 572 | { |
@@ -632,8 +632,8 @@ discard block |
||
632 | 632 | * Saves the new information whenever a moderator comment is edited. |
633 | 633 | * |
634 | 634 | * @param int $comment_id The edited moderator comment ID. |
635 | - * @param array $data The new data to de inserted. Should be already properly sanitized. |
|
636 | - * @return bool Boolean false if no data or no comment ID was provided. |
|
635 | + * @param string $edited_comment |
|
636 | + * @return false|null Boolean false if no data or no comment ID was provided. |
|
637 | 637 | */ |
638 | 638 | function editModComment($comment_id, $edited_comment) |
639 | 639 | { |
@@ -657,7 +657,7 @@ discard block |
||
657 | 657 | * Deletes a moderator comment from the DB. |
658 | 658 | * |
659 | 659 | * @param int $comment_id The moderator comment ID used to identify which report will be deleted. |
660 | - * @return bool Boolean false if no data was provided. |
|
660 | + * @return false|null Boolean false if no data was provided. |
|
661 | 661 | */ |
662 | 662 | function deleteModComment($comment_id) |
663 | 663 | { |
@@ -130,7 +130,6 @@ |
||
130 | 130 | * |
131 | 131 | * @param int $closed 1 for counting closed reports, 0 for open ones. |
132 | 132 | * @return integer How many reports. |
133 | - |
|
134 | 133 | */ |
135 | 134 | function countReports($closed = 0) |
136 | 135 | { |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | $smcFunc['db_query']('', ' |
50 | 50 | UPDATE {db_prefix}log_reported |
51 | 51 | SET {raw:action} = {string:value} |
52 | - '. (is_array($report_id) ? 'WHERE id_report IN ({array_int:id_report})' : 'WHERE id_report = {int:id_report}') .' |
|
52 | + '. (is_array($report_id) ? 'WHERE id_report IN ({array_int:id_report})' : 'WHERE id_report = {int:id_report}') . ' |
|
53 | 53 | ' . $board_query, |
54 | 54 | array( |
55 | 55 | 'action' => $action, |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | ) |
98 | 98 | ); |
99 | 99 | |
100 | - while($row = $smcFunc['db_fetch_assoc']($request)) |
|
100 | + while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
101 | 101 | $extra[$row['id_report']] = array( |
102 | 102 | 'report' => $row['id_report'], |
103 | 103 | 'member' => $row['id_member'], |
@@ -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 | * Updates a report with the given parameters. Logs each action via logAction() |
@@ -28,19 +29,20 @@ discard block |
||
28 | 29 | global $smcFunc, $user_info, $context; |
29 | 30 | |
30 | 31 | // Don't bother. |
31 | - if (empty($action) || empty($report_id)) |
|
32 | - return false; |
|
32 | + if (empty($action) || empty($report_id)) { |
|
33 | + return false; |
|
34 | + } |
|
33 | 35 | |
34 | 36 | // Add the "_all" thingy. |
35 | - if ($action == 'ignore') |
|
36 | - $action = 'ignore_all'; |
|
37 | + if ($action == 'ignore') { |
|
38 | + $action = 'ignore_all'; |
|
39 | + } |
|
37 | 40 | |
38 | 41 | // We don't need the board query for reported members |
39 | 42 | if ($context['report_type'] == 'members') |
40 | 43 | { |
41 | 44 | $board_query = ''; |
42 | - } |
|
43 | - else |
|
45 | + } else |
|
44 | 46 | { |
45 | 47 | $board_query = ' AND ' . $user_info['mod_cache']['bq']; |
46 | 48 | } |
@@ -76,17 +78,17 @@ discard block |
||
76 | 78 | ) |
77 | 79 | ); |
78 | 80 | |
79 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
80 | - $extra[$row['id_report']] = array( |
|
81 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
82 | + $extra[$row['id_report']] = array( |
|
81 | 83 | 'report' => $row['id_report'], |
82 | 84 | 'board' => $row['id_board'], |
83 | 85 | 'message' => $row['id_msg'], |
84 | 86 | 'topic' => $row['id_topic'], |
85 | 87 | ); |
88 | + } |
|
86 | 89 | |
87 | 90 | $smcFunc['db_free_result']($request); |
88 | - } |
|
89 | - else |
|
91 | + } else |
|
90 | 92 | { |
91 | 93 | $request = $smcFunc['db_query']('', ' |
92 | 94 | SELECT id_report, id_member, membername |
@@ -97,28 +99,32 @@ discard block |
||
97 | 99 | ) |
98 | 100 | ); |
99 | 101 | |
100 | - while($row = $smcFunc['db_fetch_assoc']($request)) |
|
101 | - $extra[$row['id_report']] = array( |
|
102 | + while($row = $smcFunc['db_fetch_assoc']($request)) { |
|
103 | + $extra[$row['id_report']] = array( |
|
102 | 104 | 'report' => $row['id_report'], |
103 | 105 | 'member' => $row['id_member'], |
104 | 106 | ); |
107 | + } |
|
105 | 108 | |
106 | 109 | $smcFunc['db_free_result']($request); |
107 | 110 | } |
108 | 111 | |
109 | 112 | // Back to "ignore". |
110 | - if ($action == 'ignore_all') |
|
111 | - $action = 'ignore'; |
|
113 | + if ($action == 'ignore_all') { |
|
114 | + $action = 'ignore'; |
|
115 | + } |
|
112 | 116 | |
113 | 117 | $log_report = $action == 'ignore' ? (!empty($value) ? 'ignore' : 'unignore') : (!empty($value) ? 'close' : 'open'); |
114 | 118 | |
115 | - if ($context['report_type'] == 'members') |
|
116 | - $log_report .= '_user'; |
|
119 | + if ($context['report_type'] == 'members') { |
|
120 | + $log_report .= '_user'; |
|
121 | + } |
|
117 | 122 | |
118 | 123 | // Log this action. |
119 | - if (!empty($extra)) |
|
120 | - foreach ($extra as $report) |
|
124 | + if (!empty($extra)) { |
|
125 | + foreach ($extra as $report) |
|
121 | 126 | logAction($log_report . '_report', $report); |
127 | + } |
|
122 | 128 | |
123 | 129 | // Time to update. |
124 | 130 | updateSettings(array('last_mod_report_action' => time())); |
@@ -142,14 +148,12 @@ discard block |
||
142 | 148 | if ($context['report_type'] == 'members') |
143 | 149 | { |
144 | 150 | $and = 'lr.id_board = 0'; |
145 | - } |
|
146 | - else |
|
151 | + } else |
|
147 | 152 | { |
148 | 153 | if ($user_info['mod_cache']['bq'] == '1=1' || $user_info['mod_cache']['bq'] == '0=1') |
149 | 154 | { |
150 | 155 | $bq = $user_info['mod_cache']['bq']; |
151 | - } |
|
152 | - else |
|
156 | + } else |
|
153 | 157 | { |
154 | 158 | $bq = 'lr.' . $user_info['mod_cache']['bq']; |
155 | 159 | } |
@@ -205,8 +209,7 @@ discard block |
||
205 | 209 | 'max' => 10, |
206 | 210 | ) |
207 | 211 | ); |
208 | - } |
|
209 | - else |
|
212 | + } else |
|
210 | 213 | { |
211 | 214 | $request = $smcFunc['db_query']('', ' |
212 | 215 | SELECT lr.id_report, lr.id_msg, lr.id_topic, lr.id_board, lr.id_member, lr.subject, lr.body, |
@@ -254,8 +257,7 @@ discard block |
||
254 | 257 | 'href' => $scripturl . '?action=profile;u=' . $row['id_user'], |
255 | 258 | ), |
256 | 259 | ); |
257 | - } |
|
258 | - else |
|
260 | + } else |
|
259 | 261 | { |
260 | 262 | $report_boards_ids[] = $row['id_board']; |
261 | 263 | $extraDetails = array( |
@@ -295,14 +297,16 @@ discard block |
||
295 | 297 | ) |
296 | 298 | ); |
297 | 299 | |
298 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
299 | - $board_names[$row['id_board']] = $row['name']; |
|
300 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
301 | + $board_names[$row['id_board']] = $row['name']; |
|
302 | + } |
|
300 | 303 | |
301 | 304 | $smcFunc['db_free_result']($request); |
302 | 305 | |
303 | - foreach ($reports as $id_report => $report) |
|
304 | - if (!empty($board_names[$report['topic']['id_board']])) |
|
306 | + foreach ($reports as $id_report => $report) { |
|
307 | + if (!empty($board_names[$report['topic']['id_board']])) |
|
305 | 308 | $reports[$id_report]['topic']['board_name'] = $board_names[$report['topic']['id_board']]; |
309 | + } |
|
306 | 310 | } |
307 | 311 | |
308 | 312 | // Now get all the people who reported it. |
@@ -352,10 +356,11 @@ discard block |
||
352 | 356 | { |
353 | 357 | global $user_info, $smcFunc; |
354 | 358 | |
355 | - if ($type == 'members') |
|
356 | - $bq = ''; |
|
357 | - else |
|
358 | - $bq = ' AND ' . $user_info['mod_cache']['bq']; |
|
359 | + if ($type == 'members') { |
|
360 | + $bq = ''; |
|
361 | + } else { |
|
362 | + $bq = ' AND ' . $user_info['mod_cache']['bq']; |
|
363 | + } |
|
359 | 364 | |
360 | 365 | $request = $smcFunc['db_query']('', ' |
361 | 366 | SELECT COUNT(*) |
@@ -394,8 +399,9 @@ discard block |
||
394 | 399 | { |
395 | 400 | global $smcFunc, $user_info, $context; |
396 | 401 | |
397 | - if (empty($report_id)) |
|
398 | - return false; |
|
402 | + if (empty($report_id)) { |
|
403 | + return false; |
|
404 | + } |
|
399 | 405 | |
400 | 406 | // We don't need all this info if we're only getting user info |
401 | 407 | if ($context['report_type'] == 'members') |
@@ -413,8 +419,7 @@ discard block |
||
413 | 419 | 'id_report' => $report_id, |
414 | 420 | ) |
415 | 421 | ); |
416 | - } |
|
417 | - else |
|
422 | + } else |
|
418 | 423 | { |
419 | 424 | // Get the report details, need this so we can limit access to a particular board. |
420 | 425 | $request = $smcFunc['db_query']('', ' |
@@ -433,8 +438,9 @@ discard block |
||
433 | 438 | } |
434 | 439 | |
435 | 440 | // So did we find anything? |
436 | - if (!$smcFunc['db_num_rows']($request)) |
|
437 | - return false; |
|
441 | + if (!$smcFunc['db_num_rows']($request)) { |
|
442 | + return false; |
|
443 | + } |
|
438 | 444 | |
439 | 445 | // Woohoo we found a report and they can see it! |
440 | 446 | $row = $smcFunc['db_fetch_assoc']($request); |
@@ -453,8 +459,9 @@ discard block |
||
453 | 459 | { |
454 | 460 | global $smcFunc, $scripturl, $user_info, $txt; |
455 | 461 | |
456 | - if (empty($report_id)) |
|
457 | - return false; |
|
462 | + if (empty($report_id)) { |
|
463 | + return false; |
|
464 | + } |
|
458 | 465 | |
459 | 466 | $report = array( |
460 | 467 | 'comments' => array(), |
@@ -535,8 +542,9 @@ discard block |
||
535 | 542 | { |
536 | 543 | global $smcFunc, $user_info; |
537 | 544 | |
538 | - if (empty($comment_id)) |
|
539 | - return false; |
|
545 | + if (empty($comment_id)) { |
|
546 | + return false; |
|
547 | + } |
|
540 | 548 | |
541 | 549 | $request = $smcFunc['db_query']('', ' |
542 | 550 | SELECT id_comment, id_notice, log_time, body, id_member |
@@ -553,8 +561,9 @@ discard block |
||
553 | 561 | $smcFunc['db_free_result']($request); |
554 | 562 | |
555 | 563 | // Add the permission |
556 | - if (!empty($comment)) |
|
557 | - $comment['can_edit'] = allowedTo('admin_forum') || (($user_info['id'] == $comment['id_member'])); |
|
564 | + if (!empty($comment)) { |
|
565 | + $comment['can_edit'] = allowedTo('admin_forum') || (($user_info['id'] == $comment['id_member'])); |
|
566 | + } |
|
558 | 567 | |
559 | 568 | return $comment; |
560 | 569 | } |
@@ -570,8 +579,9 @@ discard block |
||
570 | 579 | { |
571 | 580 | global $smcFunc, $user_info, $context; |
572 | 581 | |
573 | - if (empty($data)) |
|
574 | - return false; |
|
582 | + if (empty($data)) { |
|
583 | + return false; |
|
584 | + } |
|
575 | 585 | |
576 | 586 | $data = array_merge(array($user_info['id'], $user_info['name'], 'reportc', ''), $data); |
577 | 587 | |
@@ -600,8 +610,7 @@ discard block |
||
600 | 610 | 'comment_id' => $last_comment, |
601 | 611 | 'time' => time(), |
602 | 612 | ); |
603 | - } |
|
604 | - else |
|
613 | + } else |
|
605 | 614 | { |
606 | 615 | $prefix = 'Msg'; |
607 | 616 | $data = array( |
@@ -617,14 +626,15 @@ discard block |
||
617 | 626 | } |
618 | 627 | |
619 | 628 | // And get ready to notify people. |
620 | - if (!empty($report)) |
|
621 | - $smcFunc['db_insert']('insert', |
|
629 | + if (!empty($report)) { |
|
630 | + $smcFunc['db_insert']('insert', |
|
622 | 631 | '{db_prefix}background_tasks', |
623 | 632 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
624 | 633 | array('$sourcedir/tasks/' . $prefix . 'ReportReply-Notify.php', $prefix . 'ReportReply_Notify_Background', json_encode($data), 0), |
625 | 634 | array('id_task') |
626 | 635 | ); |
627 | -} |
|
636 | + } |
|
637 | + } |
|
628 | 638 | |
629 | 639 | /** |
630 | 640 | * Saves the new information whenever a moderator comment is edited. |
@@ -637,8 +647,9 @@ discard block |
||
637 | 647 | { |
638 | 648 | global $smcFunc; |
639 | 649 | |
640 | - if (empty($comment_id) || empty($edited_comment)) |
|
641 | - return false; |
|
650 | + if (empty($comment_id) || empty($edited_comment)) { |
|
651 | + return false; |
|
652 | + } |
|
642 | 653 | |
643 | 654 | $smcFunc['db_query']('', ' |
644 | 655 | UPDATE {db_prefix}log_comments |
@@ -661,8 +672,9 @@ discard block |
||
661 | 672 | { |
662 | 673 | global $smcFunc; |
663 | 674 | |
664 | - if (empty($comment_id)) |
|
665 | - return false; |
|
675 | + if (empty($comment_id)) { |
|
676 | + return false; |
|
677 | + } |
|
666 | 678 | |
667 | 679 | $smcFunc['db_query']('', ' |
668 | 680 | DELETE FROM {db_prefix}log_comments |
@@ -24,7 +24,7 @@ |
||
24 | 24 | * Used by VerificationCode() (Register.php). |
25 | 25 | * |
26 | 26 | * @param string $word |
27 | - * @return boolean false on failure |
|
27 | + * @return null|false false on failure |
|
28 | 28 | */ |
29 | 29 | |
30 | 30 | function createWaveFile($word) |
@@ -38,7 +38,7 @@ |
||
38 | 38 | cache_put_data('wave_file/' . $user_info['ip2'], $ip2 ? $ip2 + 1 : 1, 20); |
39 | 39 | |
40 | 40 | // Fixate randomization for this word. |
41 | - $tmp = unpack('n', md5($word . session_id())); |
|
41 | + $tmp = unpack('n', md5($word . session_id())); |
|
42 | 42 | mt_srand(end($tmp)); |
43 | 43 | |
44 | 44 | // Try to see if there's a sound font in the user's language. |
@@ -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 | |
@@ -42,16 +44,19 @@ discard block |
||
42 | 44 | mt_srand(end($tmp)); |
43 | 45 | |
44 | 46 | // Try to see if there's a sound font in the user's language. |
45 | - if (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.' . $user_info['language'] . '.wav')) |
|
46 | - $sound_language = $user_info['language']; |
|
47 | + if (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.' . $user_info['language'] . '.wav')) { |
|
48 | + $sound_language = $user_info['language']; |
|
49 | + } |
|
47 | 50 | |
48 | 51 | // English should be there. |
49 | - elseif (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.english.wav')) |
|
50 | - $sound_language = 'english'; |
|
52 | + elseif (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.english.wav')) { |
|
53 | + $sound_language = 'english'; |
|
54 | + } |
|
51 | 55 | |
52 | 56 | // Guess not... |
53 | - else |
|
54 | - return false; |
|
57 | + else { |
|
58 | + return false; |
|
59 | + } |
|
55 | 60 | |
56 | 61 | // File names are in lower case so lets make sure that we are only using a lower case string |
57 | 62 | $word = strtolower($word); |
@@ -61,20 +66,25 @@ discard block |
||
61 | 66 | for ($i = 0; $i < strlen($word); $i++) |
62 | 67 | { |
63 | 68 | $sound_letter = implode('', file($settings['default_theme_dir'] . '/fonts/sound/' . $word{$i} . '.' . $sound_language . '.wav')); |
64 | - if (strpos($sound_letter, 'data') === false) |
|
65 | - return false; |
|
69 | + if (strpos($sound_letter, 'data') === false) { |
|
70 | + return false; |
|
71 | + } |
|
66 | 72 | |
67 | 73 | $sound_letter = substr($sound_letter, strpos($sound_letter, 'data') + 8); |
68 | 74 | switch ($word{$i} === 's' ? 0 : mt_rand(0, 2)) |
69 | 75 | { |
70 | - case 0 : for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++) |
|
71 | - for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++) |
|
72 | - $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))); |
|
76 | + case 0 : for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++) { |
|
77 | + for ($k = 0, $m = round(mt_rand(15, 25) / 10); |
|
78 | + } |
|
79 | + $k < $m; $k++) { |
|
80 | + $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))); |
|
81 | + } |
|
73 | 82 | break; |
74 | 83 | |
75 | 84 | case 1: |
76 | - for ($j = 0, $n = strlen($sound_letter) - 1; $j < $n; $j += 2) |
|
77 | - $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} : ''); |
|
85 | + for ($j = 0, $n = strlen($sound_letter) - 1; $j < $n; $j += 2) { |
|
86 | + $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} : ''); |
|
87 | + } |
|
78 | 88 | $sound_word .= str_repeat($sound_letter{$n}, 2); |
79 | 89 | break; |
80 | 90 | |
@@ -82,10 +92,12 @@ discard block |
||
82 | 92 | $shift = 0; |
83 | 93 | for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++) |
84 | 94 | { |
85 | - if (mt_rand(0, 10) === 0) |
|
86 | - $shift += mt_rand(-3, 3); |
|
87 | - for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++) |
|
88 | - $sound_word .= chr(min(max(ord($sound_letter{$j}) + $shift, 0x00), 0xFF)); |
|
95 | + if (mt_rand(0, 10) === 0) { |
|
96 | + $shift += mt_rand(-3, 3); |
|
97 | + } |
|
98 | + for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++) { |
|
99 | + $sound_word .= chr(min(max(ord($sound_letter{$j}) + $shift, 0x00), 0xFF)); |
|
100 | + } |
|
89 | 101 | } |
90 | 102 | break; |
91 | 103 |
@@ -425,7 +425,7 @@ |
||
425 | 425 | * |
426 | 426 | * This is a recursive function, it will call itself if there are subdirs inside the main directory. |
427 | 427 | * @param string $path The absolute path to the directory to be removed |
428 | - * @return bool true when success, false on error. |
|
428 | + * @return false|null true when success, false on error. |
|
429 | 429 | */ |
430 | 430 | function remove_dir($path) |
431 | 431 | { |
@@ -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 | * Gets a single theme's info. |
@@ -27,8 +28,9 @@ discard block |
||
27 | 28 | global $smcFunc, $modSettings; |
28 | 29 | |
29 | 30 | // No data, no fun! |
30 | - if (empty($id)) |
|
31 | - return false; |
|
31 | + if (empty($id)) { |
|
32 | + return false; |
|
33 | + } |
|
32 | 34 | |
33 | 35 | // Make sure $id is an int. |
34 | 36 | $id = (int) $id; |
@@ -171,8 +173,9 @@ discard block |
||
171 | 173 | global $sourcedir, $forum_version, $txt, $scripturl, $context; |
172 | 174 | global $explicit_images; |
173 | 175 | |
174 | - if (empty($path)) |
|
175 | - return false; |
|
176 | + if (empty($path)) { |
|
177 | + return false; |
|
178 | + } |
|
176 | 179 | |
177 | 180 | $xml_data = array(); |
178 | 181 | $explicit_images = false; |
@@ -229,9 +232,10 @@ discard block |
||
229 | 232 | ); |
230 | 233 | |
231 | 234 | // Assign the values to be stored. |
232 | - foreach ($xml_elements as $var => $name) |
|
233 | - if (!empty($theme_info_xml[$name])) |
|
235 | + foreach ($xml_elements as $var => $name) { |
|
236 | + if (!empty($theme_info_xml[$name])) |
|
234 | 237 | $xml_data[$var] = $theme_info_xml[$name]; |
238 | + } |
|
235 | 239 | |
236 | 240 | // Add the supported versions. |
237 | 241 | $xml_data['install_for'] = $install_versions; |
@@ -243,8 +247,9 @@ discard block |
||
243 | 247 | $explicit_images = true; |
244 | 248 | } |
245 | 249 | |
246 | - if (!empty($theme_info_xml['extra'])) |
|
247 | - $xml_data += smf_json_decode($theme_info_xml['extra'], true); |
|
250 | + if (!empty($theme_info_xml['extra'])) { |
|
251 | + $xml_data += smf_json_decode($theme_info_xml['extra'], true); |
|
252 | + } |
|
248 | 253 | |
249 | 254 | return $xml_data; |
250 | 255 | } |
@@ -262,12 +267,14 @@ discard block |
||
262 | 267 | global $settings, $explicit_images; |
263 | 268 | |
264 | 269 | // External use? no problem! |
265 | - if ($to_install) |
|
266 | - $context['to_install'] = $to_install; |
|
270 | + if ($to_install) { |
|
271 | + $context['to_install'] = $to_install; |
|
272 | + } |
|
267 | 273 | |
268 | 274 | // One last check. |
269 | - if (empty($context['to_install']['theme_dir']) || basename($context['to_install']['theme_dir']) == 'Themes') |
|
270 | - fatal_lang_error('theme_install_invalid_dir', false); |
|
275 | + if (empty($context['to_install']['theme_dir']) || basename($context['to_install']['theme_dir']) == 'Themes') { |
|
276 | + fatal_lang_error('theme_install_invalid_dir', false); |
|
277 | + } |
|
271 | 278 | |
272 | 279 | // OK, is this a newer version of an already installed theme? |
273 | 280 | if (!empty($context['to_install']['version'])) |
@@ -292,8 +299,8 @@ discard block |
||
292 | 299 | $smcFunc['db_free_result']($request); |
293 | 300 | |
294 | 301 | // Got something, lets figure it out what to do next. |
295 | - if (!empty($to_update) && !empty($to_update['version'])) |
|
296 | - switch (compareVersions($context['to_install']['version'], $to_update['version'])) |
|
302 | + if (!empty($to_update) && !empty($to_update['version'])) { |
|
303 | + switch (compareVersions($context['to_install']['version'], $to_update['version'])) |
|
297 | 304 | { |
298 | 305 | case 1: // Got a newer version, update the old entry. |
299 | 306 | $smcFunc['db_query']('', ' |
@@ -307,6 +314,7 @@ discard block |
||
307 | 314 | 'id_theme' => $to_update['id_theme'], |
308 | 315 | ) |
309 | 316 | ); |
317 | + } |
|
310 | 318 | |
311 | 319 | // Done with the update, tell the user about it. |
312 | 320 | $context['to_install']['updated'] = true; |
@@ -372,13 +380,15 @@ discard block |
||
372 | 380 | $context['to_install']['base_theme_url'] = $temp['theme_url']; |
373 | 381 | $context['to_install']['base_theme_dir'] = $temp['theme_dir']; |
374 | 382 | |
375 | - if (empty($explicit_images) && !empty($context['to_install']['base_theme_url'])) |
|
376 | - $context['to_install']['theme_url'] = $context['to_install']['base_theme_url']; |
|
383 | + if (empty($explicit_images) && !empty($context['to_install']['base_theme_url'])) { |
|
384 | + $context['to_install']['theme_url'] = $context['to_install']['base_theme_url']; |
|
385 | + } |
|
377 | 386 | } |
378 | 387 | |
379 | 388 | // Nope, sorry, couldn't find any theme already installed. |
380 | - else |
|
381 | - fatal_lang_error('package_get_error_theme_no_based_on_found', false, $context['to_install']['based_on']); |
|
389 | + else { |
|
390 | + fatal_lang_error('package_get_error_theme_no_based_on_found', false, $context['to_install']['based_on']); |
|
391 | + } |
|
382 | 392 | } |
383 | 393 | |
384 | 394 | unset($context['to_install']['based_on']); |
@@ -401,16 +411,18 @@ discard block |
||
401 | 411 | call_integration_hook('integrate_theme_install', array(&$context['to_install'], $id_theme)); |
402 | 412 | |
403 | 413 | $inserts = array(); |
404 | - foreach ($context['to_install'] as $var => $val) |
|
405 | - $inserts[] = array($id_theme, $var, $val); |
|
414 | + foreach ($context['to_install'] as $var => $val) { |
|
415 | + $inserts[] = array($id_theme, $var, $val); |
|
416 | + } |
|
406 | 417 | |
407 | - if (!empty($inserts)) |
|
408 | - $smcFunc['db_insert']('insert', |
|
418 | + if (!empty($inserts)) { |
|
419 | + $smcFunc['db_insert']('insert', |
|
409 | 420 | '{db_prefix}themes', |
410 | 421 | array('id_theme' => 'int', 'variable' => 'string-255', 'value' => 'string-65534'), |
411 | 422 | $inserts, |
412 | 423 | array('id_theme', 'variable') |
413 | 424 | ); |
425 | + } |
|
414 | 426 | |
415 | 427 | // Update the known and enable Theme's settings. |
416 | 428 | $known = strtr($modSettings['knownThemes'] . ',' . $id_theme, array(',,' => ',')); |
@@ -429,21 +441,24 @@ discard block |
||
429 | 441 | */ |
430 | 442 | function remove_dir($path) |
431 | 443 | { |
432 | - if (empty($path)) |
|
433 | - return false; |
|
444 | + if (empty($path)) { |
|
445 | + return false; |
|
446 | + } |
|
434 | 447 | |
435 | 448 | if (is_dir($path)) |
436 | 449 | { |
437 | 450 | $objects = scandir($path); |
438 | 451 | |
439 | - foreach ($objects as $object) |
|
440 | - if ($object != '.' && $object != '..') |
|
452 | + foreach ($objects as $object) { |
|
453 | + if ($object != '.' && $object != '..') |
|
441 | 454 | { |
442 | 455 | if (filetype($path . '/' . $object) == 'dir') |
443 | 456 | remove_dir($path . '/' . $object); |
457 | + } |
|
444 | 458 | |
445 | - else |
|
446 | - unlink($path . '/' . $object); |
|
459 | + else { |
|
460 | + unlink($path . '/' . $object); |
|
461 | + } |
|
447 | 462 | } |
448 | 463 | } |
449 | 464 | |
@@ -462,8 +477,9 @@ discard block |
||
462 | 477 | global $smcFunc, $modSettings; |
463 | 478 | |
464 | 479 | // Can't delete the default theme, sorry! |
465 | - if (empty($themeID) || $themeID == 1) |
|
466 | - return false; |
|
480 | + if (empty($themeID) || $themeID == 1) { |
|
481 | + return false; |
|
482 | + } |
|
467 | 483 | |
468 | 484 | $known = explode(',', $modSettings['knownThemes']); |
469 | 485 | $enable = explode(',', $modSettings['enableThemes']); |
@@ -513,8 +529,9 @@ discard block |
||
513 | 529 | updateSettings(array('enableThemes' => $enable, 'knownThemes' => $known)); |
514 | 530 | |
515 | 531 | // Fix it if the theme was the overall default theme. |
516 | - if ($modSettings['theme_guests'] == $themeID) |
|
517 | - updateSettings(array('theme_guests' => '1')); |
|
532 | + if ($modSettings['theme_guests'] == $themeID) { |
|
533 | + updateSettings(array('theme_guests' => '1')); |
|
534 | + } |
|
518 | 535 | |
519 | 536 | return true; |
520 | 537 | } |
@@ -531,13 +548,15 @@ discard block |
||
531 | 548 | global $scripturl, $txt, $context; |
532 | 549 | |
533 | 550 | // Is it even a directory? |
534 | - if (!is_dir($path)) |
|
535 | - fatal_lang_error('error_invalid_dir', 'critical'); |
|
551 | + if (!is_dir($path)) { |
|
552 | + fatal_lang_error('error_invalid_dir', 'critical'); |
|
553 | + } |
|
536 | 554 | |
537 | 555 | $dir = dir($path); |
538 | 556 | $entries = array(); |
539 | - while ($entry = $dir->read()) |
|
540 | - $entries[] = $entry; |
|
557 | + while ($entry = $dir->read()) { |
|
558 | + $entries[] = $entry; |
|
559 | + } |
|
541 | 560 | $dir->close(); |
542 | 561 | |
543 | 562 | natcasesort($entries); |
@@ -548,11 +567,12 @@ discard block |
||
548 | 567 | foreach ($entries as $entry) |
549 | 568 | { |
550 | 569 | // Skip all dot files, including .htaccess. |
551 | - if (substr($entry, 0, 1) == '.' || $entry == 'CVS') |
|
552 | - continue; |
|
570 | + if (substr($entry, 0, 1) == '.' || $entry == 'CVS') { |
|
571 | + continue; |
|
572 | + } |
|
553 | 573 | |
554 | - if (is_dir($path . '/' . $entry)) |
|
555 | - $listing1[] = array( |
|
574 | + if (is_dir($path . '/' . $entry)) { |
|
575 | + $listing1[] = array( |
|
556 | 576 | 'filename' => $entry, |
557 | 577 | 'is_writable' => is_writable($path . '/' . $entry), |
558 | 578 | 'is_directory' => true, |
@@ -562,13 +582,14 @@ discard block |
||
562 | 582 | 'href' => $scripturl . '?action=admin;area=theme;th=' . $_GET['th'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';sa=edit;directory=' . $relative . $entry, |
563 | 583 | 'size' => '', |
564 | 584 | ); |
565 | - else |
|
585 | + } else |
|
566 | 586 | { |
567 | 587 | $size = filesize($path . '/' . $entry); |
568 | - if ($size > 2048 || $size == 1024) |
|
569 | - $size = comma_format($size / 1024) . ' ' . $txt['themeadmin_edit_kilobytes']; |
|
570 | - else |
|
571 | - $size = comma_format($size) . ' ' . $txt['themeadmin_edit_bytes']; |
|
588 | + if ($size > 2048 || $size == 1024) { |
|
589 | + $size = comma_format($size / 1024) . ' ' . $txt['themeadmin_edit_kilobytes']; |
|
590 | + } else { |
|
591 | + $size = comma_format($size) . ' ' . $txt['themeadmin_edit_bytes']; |
|
592 | + } |
|
572 | 593 | |
573 | 594 | $listing2[] = array( |
574 | 595 | 'filename' => $entry, |
@@ -402,7 +402,7 @@ |
||
402 | 402 | * A private function to find out the subscription details. |
403 | 403 | * |
404 | 404 | * @access private |
405 | - * @return boolean|void False on failure, otherwise just sets $_POST['item_number'] |
|
405 | + * @return false|null False on failure, otherwise just sets $_POST['item_number'] |
|
406 | 406 | */ |
407 | 407 | private function _findSubscription() |
408 | 408 | { |
@@ -236,7 +236,7 @@ |
||
236 | 236 | $header = 'POST /cgi-bin/webscr HTTP/1.1' . "\r\n"; |
237 | 237 | $header .= 'Content-Type: application/x-www-form-urlencoded' . "\r\n"; |
238 | 238 | $header .= 'Host: www.' . (!empty($modSettings['paidsubs_test']) ? 'sandbox.' : '') . 'paypal.com' . "\r\n"; |
239 | - $header .= 'Content-Length: ' . strlen ($requestString) . "\r\n"; |
|
239 | + $header .= 'Content-Length: ' . strlen($requestString) . "\r\n"; |
|
240 | 240 | $header .= 'Connection: close' . "\r\n\r\n"; |
241 | 241 | |
242 | 242 | // Open the connection. |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | // This won't be dedicated without this - this must exist in each gateway! |
15 | 15 | // SMF Payment Gateway: paypal |
16 | 16 | |
17 | -if (!defined('SMF')) |
|
17 | +if (!defined('SMF')) { |
|
18 | 18 | die('No direct access...'); |
19 | +} |
|
19 | 20 | |
20 | 21 | /** |
21 | 22 | * Class for returning available form data for this gateway |
@@ -118,8 +119,7 @@ discard block |
||
118 | 119 | { |
119 | 120 | $return_data['hidden']['p3'] = 1; |
120 | 121 | $return_data['hidden']['t3'] = strtoupper(substr($period, 0, 1)); |
121 | - } |
|
122 | - else |
|
122 | + } else |
|
123 | 123 | { |
124 | 124 | preg_match('~(\d*)(\w)~', $sub_data['real_length'], $match); |
125 | 125 | $unit = $match[1]; |
@@ -130,14 +130,15 @@ discard block |
||
130 | 130 | } |
131 | 131 | |
132 | 132 | // If it's repeatable do some javascript to respect this idea. |
133 | - if (!empty($sub_data['repeatable'])) |
|
134 | - $return_data['javascript'] = ' |
|
133 | + if (!empty($sub_data['repeatable'])) { |
|
134 | + $return_data['javascript'] = ' |
|
135 | 135 | document.write(\'<label for="do_paypal_recur"><input type="checkbox" name="do_paypal_recur" id="do_paypal_recur" checked onclick="switchPaypalRecur();" class="input_check">' . $txt['paid_make_recurring'] . '</label><br>\'); |
136 | 136 | |
137 | 137 | function switchPaypalRecur() |
138 | 138 | { |
139 | 139 | document.getElementById("paypal_cmd").value = document.getElementById("do_paypal_recur").checked ? "_xclick-subscriptions" : "_xclick"; |
140 | 140 | }'; |
141 | + } |
|
141 | 142 | |
142 | 143 | return $return_data; |
143 | 144 | } |
@@ -160,20 +161,24 @@ discard block |
||
160 | 161 | global $modSettings; |
161 | 162 | |
162 | 163 | // Has the user set up an email address? |
163 | - if ((empty($modSettings['paidsubs_test']) && empty($modSettings['paypal_email'])) || (!empty($modSettings['paidsubs_test']) && empty($modSettings['paypal_sandbox_email']))) |
|
164 | - return false; |
|
164 | + if ((empty($modSettings['paidsubs_test']) && empty($modSettings['paypal_email'])) || (!empty($modSettings['paidsubs_test']) && empty($modSettings['paypal_sandbox_email']))) { |
|
165 | + return false; |
|
166 | + } |
|
165 | 167 | // Check the correct transaction types are even here. |
166 | - if ((!isset($_POST['txn_type']) && !isset($_POST['payment_status'])) || (!isset($_POST['business']) && !isset($_POST['receiver_email']))) |
|
167 | - return false; |
|
168 | + if ((!isset($_POST['txn_type']) && !isset($_POST['payment_status'])) || (!isset($_POST['business']) && !isset($_POST['receiver_email']))) { |
|
169 | + return false; |
|
170 | + } |
|
168 | 171 | // Correct email address? |
169 | - if (!isset($_POST['business'])) |
|
170 | - $_POST['business'] = $_POST['receiver_email']; |
|
172 | + if (!isset($_POST['business'])) { |
|
173 | + $_POST['business'] = $_POST['receiver_email']; |
|
174 | + } |
|
171 | 175 | |
172 | 176 | // Are we testing? |
173 | - if (empty($modSettings['paidsubs_test']) && strtolower($modSettings['paypal_sandbox_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', strtolower($modSettings['paypal_additional_emails']))))) |
|
174 | - return false; |
|
175 | - elseif (strtolower($modSettings['paypal_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', $modSettings['paypal_additional_emails'])))) |
|
176 | - return false; |
|
177 | + if (empty($modSettings['paidsubs_test']) && strtolower($modSettings['paypal_sandbox_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', strtolower($modSettings['paypal_additional_emails']))))) { |
|
178 | + return false; |
|
179 | + } elseif (strtolower($modSettings['paypal_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', $modSettings['paypal_additional_emails'])))) { |
|
180 | + return false; |
|
181 | + } |
|
177 | 182 | return true; |
178 | 183 | } |
179 | 184 | |
@@ -192,15 +197,17 @@ discard block |
||
192 | 197 | global $modSettings, $txt; |
193 | 198 | |
194 | 199 | // Put this to some default value. |
195 | - if (!isset($_POST['txn_type'])) |
|
196 | - $_POST['txn_type'] = ''; |
|
200 | + if (!isset($_POST['txn_type'])) { |
|
201 | + $_POST['txn_type'] = ''; |
|
202 | + } |
|
197 | 203 | |
198 | 204 | // Build the request string - starting with the minimum requirement. |
199 | 205 | $requestString = 'cmd=_notify-validate'; |
200 | 206 | |
201 | 207 | // Now my dear, add all the posted bits in the order we got them |
202 | - foreach ($_POST as $k => $v) |
|
203 | - $requestString .= '&' . $k . '=' . urlencode($v); |
|
208 | + foreach ($_POST as $k => $v) { |
|
209 | + $requestString .= '&' . $k . '=' . urlencode($v); |
|
210 | + } |
|
204 | 211 | |
205 | 212 | // Can we use curl? |
206 | 213 | if (function_exists('curl_init') && $curl = curl_init((!empty($modSettings['paidsubs_test']) ? 'https://www.sandbox.' : 'https://www.') . 'paypal.com/cgi-bin/webscr')) |
@@ -240,14 +247,16 @@ discard block |
||
240 | 247 | $header .= 'Connection: close' . "\r\n\r\n"; |
241 | 248 | |
242 | 249 | // Open the connection. |
243 | - if (!empty($modSettings['paidsubs_test'])) |
|
244 | - $fp = fsockopen('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30); |
|
245 | - else |
|
246 | - $fp = fsockopen('www.paypal.com', 80, $errno, $errstr, 30); |
|
250 | + if (!empty($modSettings['paidsubs_test'])) { |
|
251 | + $fp = fsockopen('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30); |
|
252 | + } else { |
|
253 | + $fp = fsockopen('www.paypal.com', 80, $errno, $errstr, 30); |
|
254 | + } |
|
247 | 255 | |
248 | 256 | // Did it work? |
249 | - if (!$fp) |
|
250 | - generateSubscriptionError($txt['paypal_could_not_connect']); |
|
257 | + if (!$fp) { |
|
258 | + generateSubscriptionError($txt['paypal_could_not_connect']); |
|
259 | + } |
|
251 | 260 | |
252 | 261 | // Put the data to the port. |
253 | 262 | fputs($fp, $header . $requestString); |
@@ -256,8 +265,9 @@ discard block |
||
256 | 265 | while (!feof($fp)) |
257 | 266 | { |
258 | 267 | $this->return_data = fgets($fp, 1024); |
259 | - if (strcmp(trim($this->return_data), 'VERIFIED') === 0) |
|
260 | - break; |
|
268 | + if (strcmp(trim($this->return_data), 'VERIFIED') === 0) { |
|
269 | + break; |
|
270 | + } |
|
261 | 271 | } |
262 | 272 | |
263 | 273 | // Clean up. |
@@ -265,28 +275,34 @@ discard block |
||
265 | 275 | } |
266 | 276 | |
267 | 277 | // If this isn't verified then give up... |
268 | - if (strcmp(trim($this->return_data), 'VERIFIED') !== 0) |
|
269 | - exit; |
|
278 | + if (strcmp(trim($this->return_data), 'VERIFIED') !== 0) { |
|
279 | + exit; |
|
280 | + } |
|
270 | 281 | |
271 | 282 | // Check that this is intended for us. |
272 | - if (strtolower($modSettings['paypal_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', strtolower($modSettings['paypal_additional_emails']))))) |
|
273 | - exit; |
|
283 | + if (strtolower($modSettings['paypal_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', strtolower($modSettings['paypal_additional_emails']))))) { |
|
284 | + exit; |
|
285 | + } |
|
274 | 286 | |
275 | 287 | // Is this a subscription - and if so is it a secondary payment that we need to process? |
276 | 288 | // If so, make sure we get it in the expected format. Seems PayPal sometimes sends it without urlencoding. |
277 | - if (!empty($_POST['item_number']) && strpos($_POST['item_number'], ' ') !== false) |
|
278 | - $_POST['item_number'] = str_replace(' ', '+', $_POST['item_number']); |
|
279 | - if ($this->isSubscription() && (empty($_POST['item_number']) || strpos($_POST['item_number'], '+') === false)) |
|
280 | - // Calculate the subscription it relates to! |
|
289 | + if (!empty($_POST['item_number']) && strpos($_POST['item_number'], ' ') !== false) { |
|
290 | + $_POST['item_number'] = str_replace(' ', '+', $_POST['item_number']); |
|
291 | + } |
|
292 | + if ($this->isSubscription() && (empty($_POST['item_number']) || strpos($_POST['item_number'], '+') === false)) { |
|
293 | + // Calculate the subscription it relates to! |
|
281 | 294 | $this->_findSubscription(); |
295 | + } |
|
282 | 296 | |
283 | 297 | // Verify the currency! |
284 | - if (strtolower($_POST['mc_currency']) !== strtolower($modSettings['paid_currency_code'])) |
|
285 | - exit; |
|
298 | + if (strtolower($_POST['mc_currency']) !== strtolower($modSettings['paid_currency_code'])) { |
|
299 | + exit; |
|
300 | + } |
|
286 | 301 | |
287 | 302 | // Can't exist if it doesn't contain anything. |
288 | - if (empty($_POST['item_number'])) |
|
289 | - exit; |
|
303 | + if (empty($_POST['item_number'])) { |
|
304 | + exit; |
|
305 | + } |
|
290 | 306 | |
291 | 307 | // Return the id_sub and id_member |
292 | 308 | return explode('+', $_POST['item_number']); |
@@ -299,10 +315,11 @@ discard block |
||
299 | 315 | */ |
300 | 316 | public function isRefund() |
301 | 317 | { |
302 | - if ($_POST['payment_status'] === 'Refunded' || $_POST['payment_status'] === 'Reversed' || $_POST['txn_type'] === 'Refunded' || ($_POST['txn_type'] === 'reversal' && $_POST['payment_status'] === 'Completed')) |
|
303 | - return true; |
|
304 | - else |
|
305 | - return false; |
|
318 | + if ($_POST['payment_status'] === 'Refunded' || $_POST['payment_status'] === 'Reversed' || $_POST['txn_type'] === 'Refunded' || ($_POST['txn_type'] === 'reversal' && $_POST['payment_status'] === 'Completed')) { |
|
319 | + return true; |
|
320 | + } else { |
|
321 | + return false; |
|
322 | + } |
|
306 | 323 | } |
307 | 324 | |
308 | 325 | /** |
@@ -312,10 +329,11 @@ discard block |
||
312 | 329 | */ |
313 | 330 | public function isSubscription() |
314 | 331 | { |
315 | - if (substr($_POST['txn_type'], 0, 14) === 'subscr_payment' && $_POST['payment_status'] === 'Completed') |
|
316 | - return true; |
|
317 | - else |
|
318 | - return false; |
|
332 | + if (substr($_POST['txn_type'], 0, 14) === 'subscr_payment' && $_POST['payment_status'] === 'Completed') { |
|
333 | + return true; |
|
334 | + } else { |
|
335 | + return false; |
|
336 | + } |
|
319 | 337 | } |
320 | 338 | |
321 | 339 | /** |
@@ -325,10 +343,11 @@ discard block |
||
325 | 343 | */ |
326 | 344 | public function isPayment() |
327 | 345 | { |
328 | - if ($_POST['payment_status'] === 'Completed' && $_POST['txn_type'] === 'web_accept') |
|
329 | - return true; |
|
330 | - else |
|
331 | - return false; |
|
346 | + if ($_POST['payment_status'] === 'Completed' && $_POST['txn_type'] === 'web_accept') { |
|
347 | + return true; |
|
348 | + } else { |
|
349 | + return false; |
|
350 | + } |
|
332 | 351 | } |
333 | 352 | |
334 | 353 | /** |
@@ -341,10 +360,11 @@ discard block |
||
341 | 360 | // subscr_cancel is sent when the user cancels, subscr_eot is sent when the subscription reaches final payment |
342 | 361 | // Neither require us to *do* anything as per performCancel(). |
343 | 362 | // subscr_eot, if sent, indicates an end of payments term. |
344 | - if (substr($_POST['txn_type'], 0, 13) === 'subscr_cancel' || substr($_POST['txn_type'], 0, 10) === 'subscr_eot') |
|
345 | - return true; |
|
346 | - else |
|
347 | - return false; |
|
363 | + if (substr($_POST['txn_type'], 0, 13) === 'subscr_cancel' || substr($_POST['txn_type'], 0, 10) === 'subscr_eot') { |
|
364 | + return true; |
|
365 | + } else { |
|
366 | + return false; |
|
367 | + } |
|
348 | 368 | } |
349 | 369 | |
350 | 370 | /** |
@@ -409,8 +429,9 @@ discard block |
||
409 | 429 | global $smcFunc; |
410 | 430 | |
411 | 431 | // Assume we have this? |
412 | - if (empty($_POST['subscr_id'])) |
|
413 | - return false; |
|
432 | + if (empty($_POST['subscr_id'])) { |
|
433 | + return false; |
|
434 | + } |
|
414 | 435 | |
415 | 436 | // Do we have this in the database? |
416 | 437 | $request = $smcFunc['db_query']('', ' |
@@ -439,11 +460,12 @@ discard block |
||
439 | 460 | 'payer_email' => $_POST['payer_email'], |
440 | 461 | ) |
441 | 462 | ); |
442 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
443 | - return false; |
|
463 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
464 | + return false; |
|
465 | + } |
|
466 | + } else { |
|
467 | + return false; |
|
444 | 468 | } |
445 | - else |
|
446 | - return false; |
|
447 | 469 | } |
448 | 470 | list ($member_id, $subscription_id) = $smcFunc['db_fetch_row']($request); |
449 | 471 | $_POST['item_number'] = $member_id . '+' . $subscription_id; |
@@ -21,7 +21,7 @@ |
||
21 | 21 | { |
22 | 22 | /** |
23 | 23 | * This executes the task - loads up the information, puts the email in the queue and inserts alerts as needed. |
24 | - * @return bool Always returns true |
|
24 | + * @return boolean|null Always returns true |
|
25 | 25 | */ |
26 | 26 | public function execute() |
27 | 27 | { |
@@ -32,8 +32,9 @@ discard block |
||
32 | 32 | $members = membersAllowedTo('calendar_view'); |
33 | 33 | |
34 | 34 | // Don't alert the event creator |
35 | - if (!empty($this->_details['sender_id'])) |
|
36 | - $members = array_diff($members, array($this->_details['sender_id'])); |
|
35 | + if (!empty($this->_details['sender_id'])) { |
|
36 | + $members = array_diff($members, array($this->_details['sender_id'])); |
|
37 | + } |
|
37 | 38 | |
38 | 39 | // Having successfully figured this out, now let's get the preferences of everyone. |
39 | 40 | require_once($sourcedir . '/Subs-Notify.php'); |
@@ -44,10 +45,11 @@ discard block |
||
44 | 45 | if (!empty($this->_details['sender_id']) && empty($this->_details['sender_name'])) |
45 | 46 | { |
46 | 47 | loadMemberData($this->_details['sender_id'], 'minimal'); |
47 | - if (!empty($user_profile[$this->_details['sender_id']])) |
|
48 | - $this->_details['sender_name'] = $user_profile[$this->_details['sender_id']]['real_name']; |
|
49 | - else |
|
50 | - $this->_details['sender_id'] = 0; |
|
48 | + if (!empty($user_profile[$this->_details['sender_id']])) { |
|
49 | + $this->_details['sender_name'] = $user_profile[$this->_details['sender_id']]['real_name']; |
|
50 | + } else { |
|
51 | + $this->_details['sender_id'] = 0; |
|
52 | + } |
|
51 | 53 | } |
52 | 54 | |
53 | 55 | // So now we find out who wants what. |
@@ -59,9 +61,10 @@ discard block |
||
59 | 61 | |
60 | 62 | foreach ($prefs as $member => $pref_option) |
61 | 63 | { |
62 | - foreach ($alert_bits as $type => $bitvalue) |
|
63 | - if ($pref_option['event_new'] & $bitvalue) |
|
64 | + foreach ($alert_bits as $type => $bitvalue) { |
|
65 | + if ($pref_option['event_new'] & $bitvalue) |
|
64 | 66 | $notifies[$type][] = $member; |
67 | + } |
|
65 | 68 | } |
66 | 69 | |
67 | 70 | // Firstly, anyone who wants alerts. |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | class EventNew_Notify_Background extends SMF_BackgroundTask |
21 | 21 | { |
22 | 22 | /** |
23 | - * This executes the task - loads up the information, puts the email in the queue and inserts alerts as needed. |
|
23 | + * This executes the task - loads up the information, puts the email in the queue and inserts alerts as needed. |
|
24 | 24 | * @return bool Always returns true |
25 | 25 | */ |
26 | 26 | public function execute() |
@@ -81,8 +81,8 @@ discard block |
||
81 | 81 | 'content_action' => empty($this->_details['sender_id']) ? 'new_guest' : 'new', |
82 | 82 | 'is_read' => 0, |
83 | 83 | 'extra' => json_encode( |
84 | - array( |
|
85 | - "event_id" => $this->_details['event_id'], |
|
84 | + array( |
|
85 | + "event_id" => $this->_details['event_id'], |
|
86 | 86 | "event_title" => $this->_details['event_title'] |
87 | 87 | ) |
88 | 88 | ), |
@@ -80,7 +80,7 @@ |
||
80 | 80 | /** |
81 | 81 | * Handles retrieving previews of news items, newsletters, signatures and warnings. |
82 | 82 | * Calls the appropriate function based on $_POST['item'] |
83 | - * @return void|bool Returns false if $_POST['item'] isn't set or isn't valid |
|
83 | + * @return false|null Returns false if $_POST['item'] isn't set or isn't valid |
|
84 | 84 | */ |
85 | 85 | function RetrievePreview() |
86 | 86 | { |
@@ -272,13 +272,13 @@ |
||
272 | 272 | $context['post_error']['messages'][] = $txt['mc_warning_template_error_no_body']; |
273 | 273 | // Add in few replacements. |
274 | 274 | /** |
275 | - * These are the defaults: |
|
276 | - * - {MEMBER} - Member Name. => current user for review |
|
277 | - * - {MESSAGE} - Link to Offending Post. (If Applicable) => not applicable here, so not replaced |
|
278 | - * - {FORUMNAME} - Forum Name. |
|
279 | - * - {SCRIPTURL} - Web address of forum. |
|
280 | - * - {REGARDS} - Standard email sign-off. |
|
281 | - */ |
|
275 | + * These are the defaults: |
|
276 | + * - {MEMBER} - Member Name. => current user for review |
|
277 | + * - {MESSAGE} - Link to Offending Post. (If Applicable) => not applicable here, so not replaced |
|
278 | + * - {FORUMNAME} - Forum Name. |
|
279 | + * - {SCRIPTURL} - Web address of forum. |
|
280 | + * - {REGARDS} - Standard email sign-off. |
|
281 | + */ |
|
282 | 282 | $find = array( |
283 | 283 | '{MEMBER}', |
284 | 284 | '{FORUMNAME}', |
@@ -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 | * The main handler and designator for AJAX stuff - jumpto, message icons and previews |
@@ -32,8 +33,9 @@ discard block |
||
32 | 33 | // Easy adding of sub actions. |
33 | 34 | call_integration_hook('integrate_XMLhttpMain_subActions', array(&$subActions)); |
34 | 35 | |
35 | - if (!isset($_REQUEST['sa'], $subActions[$_REQUEST['sa']])) |
|
36 | - fatal_lang_error('no_access', false); |
|
36 | + if (!isset($_REQUEST['sa'], $subActions[$_REQUEST['sa']])) { |
|
37 | + fatal_lang_error('no_access', false); |
|
38 | + } |
|
37 | 39 | |
38 | 40 | call_helper($subActions[$_REQUEST['sa']]); |
39 | 41 | } |
@@ -57,8 +59,9 @@ discard block |
||
57 | 59 | foreach ($context['jump_to'] as $id_cat => $cat) |
58 | 60 | { |
59 | 61 | $context['jump_to'][$id_cat]['name'] = un_htmlspecialchars(strip_tags($cat['name'])); |
60 | - foreach ($cat['boards'] as $id_board => $board) |
|
61 | - $context['jump_to'][$id_cat]['boards'][$id_board]['name'] = un_htmlspecialchars(strip_tags($board['name'])); |
|
62 | + foreach ($cat['boards'] as $id_board => $board) { |
|
63 | + $context['jump_to'][$id_cat]['boards'][$id_board]['name'] = un_htmlspecialchars(strip_tags($board['name'])); |
|
64 | + } |
|
62 | 65 | } |
63 | 66 | |
64 | 67 | $context['sub_template'] = 'jump_to'; |
@@ -95,8 +98,9 @@ discard block |
||
95 | 98 | |
96 | 99 | $context['sub_template'] = 'generic_xml'; |
97 | 100 | |
98 | - if (!isset($_POST['item']) || !in_array($_POST['item'], $items)) |
|
99 | - return false; |
|
101 | + if (!isset($_POST['item']) || !in_array($_POST['item'], $items)) { |
|
102 | + return false; |
|
103 | + } |
|
100 | 104 | |
101 | 105 | $_POST['item'](); |
102 | 106 | } |
@@ -112,10 +116,11 @@ discard block |
||
112 | 116 | |
113 | 117 | $errors = array(); |
114 | 118 | $news = !isset($_POST['news']) ? '' : $smcFunc['htmlspecialchars']($_POST['news'], ENT_QUOTES); |
115 | - if (empty($news)) |
|
116 | - $errors[] = array('value' => 'no_news'); |
|
117 | - else |
|
118 | - preparsecode($news); |
|
119 | + if (empty($news)) { |
|
120 | + $errors[] = array('value' => 'no_news'); |
|
121 | + } else { |
|
122 | + preparsecode($news); |
|
123 | + } |
|
119 | 124 | |
120 | 125 | $context['xml_data'] = array( |
121 | 126 | 'news' => array( |
@@ -148,10 +153,12 @@ discard block |
||
148 | 153 | $context['send_pm'] = !empty($_POST['send_pm']) ? 1 : 0; |
149 | 154 | $context['send_html'] = !empty($_POST['send_html']) ? 1 : 0; |
150 | 155 | |
151 | - if (empty($_POST['subject'])) |
|
152 | - $context['post_error']['messages'][] = $txt['error_no_subject']; |
|
153 | - if (empty($_POST['message'])) |
|
154 | - $context['post_error']['messages'][] = $txt['error_no_message']; |
|
156 | + if (empty($_POST['subject'])) { |
|
157 | + $context['post_error']['messages'][] = $txt['error_no_subject']; |
|
158 | + } |
|
159 | + if (empty($_POST['message'])) { |
|
160 | + $context['post_error']['messages'][] = $txt['error_no_message']; |
|
161 | + } |
|
155 | 162 | |
156 | 163 | prepareMailingForPreview(); |
157 | 164 | |
@@ -196,38 +203,41 @@ discard block |
||
196 | 203 | $preview_signature = !empty($_POST['signature']) ? $_POST['signature'] : $txt['no_signature_preview']; |
197 | 204 | $validation = profileValidateSignature($preview_signature); |
198 | 205 | |
199 | - if ($validation !== true && $validation !== false) |
|
200 | - $errors[] = array('value' => $txt['profile_error_' . $validation], 'attributes' => array('type' => 'error')); |
|
206 | + if ($validation !== true && $validation !== false) { |
|
207 | + $errors[] = array('value' => $txt['profile_error_' . $validation], 'attributes' => array('type' => 'error')); |
|
208 | + } |
|
201 | 209 | |
202 | 210 | censorText($preview_signature); |
203 | 211 | $preview_signature = parse_bbc($preview_signature, true, 'sig' . $user); |
204 | - } |
|
205 | - elseif (!$can_change) |
|
212 | + } elseif (!$can_change) |
|
206 | 213 | { |
207 | - if ($is_owner) |
|
208 | - $errors[] = array('value' => $txt['cannot_profile_extra_own'], 'attributes' => array('type' => 'error')); |
|
209 | - else |
|
210 | - $errors[] = array('value' => $txt['cannot_profile_extra_any'], 'attributes' => array('type' => 'error')); |
|
214 | + if ($is_owner) { |
|
215 | + $errors[] = array('value' => $txt['cannot_profile_extra_own'], 'attributes' => array('type' => 'error')); |
|
216 | + } else { |
|
217 | + $errors[] = array('value' => $txt['cannot_profile_extra_any'], 'attributes' => array('type' => 'error')); |
|
218 | + } |
|
219 | + } else { |
|
220 | + $errors[] = array('value' => $txt['no_user_selected'], 'attributes' => array('type' => 'error')); |
|
211 | 221 | } |
212 | - else |
|
213 | - $errors[] = array('value' => $txt['no_user_selected'], 'attributes' => array('type' => 'error')); |
|
214 | 222 | |
215 | 223 | $context['xml_data']['signatures'] = array( |
216 | 224 | 'identifier' => 'signature', |
217 | 225 | 'children' => array() |
218 | 226 | ); |
219 | - if (isset($current_signature)) |
|
220 | - $context['xml_data']['signatures']['children'][] = array( |
|
227 | + if (isset($current_signature)) { |
|
228 | + $context['xml_data']['signatures']['children'][] = array( |
|
221 | 229 | 'value' => $current_signature, |
222 | 230 | 'attributes' => array('type' => 'current'), |
223 | 231 | ); |
224 | - if (isset($preview_signature)) |
|
225 | - $context['xml_data']['signatures']['children'][] = array( |
|
232 | + } |
|
233 | + if (isset($preview_signature)) { |
|
234 | + $context['xml_data']['signatures']['children'][] = array( |
|
226 | 235 | 'value' => $preview_signature, |
227 | 236 | 'attributes' => array('type' => 'preview'), |
228 | 237 | ); |
229 | - if (!empty($errors)) |
|
230 | - $context['xml_data']['errors'] = array( |
|
238 | + } |
|
239 | + if (!empty($errors)) { |
|
240 | + $context['xml_data']['errors'] = array( |
|
231 | 241 | 'identifier' => 'error', |
232 | 242 | 'children' => array_merge( |
233 | 243 | array( |
@@ -239,7 +249,8 @@ discard block |
||
239 | 249 | $errors |
240 | 250 | ), |
241 | 251 | ); |
242 | -} |
|
252 | + } |
|
253 | + } |
|
243 | 254 | |
244 | 255 | /** |
245 | 256 | * Handles previewing user warnings |
@@ -259,15 +270,17 @@ discard block |
||
259 | 270 | $context['preview_subject'] = !empty($_POST['title']) ? trim($smcFunc['htmlspecialchars']($_POST['title'])) : ''; |
260 | 271 | if (isset($_POST['issuing'])) |
261 | 272 | { |
262 | - if (empty($_POST['title']) || empty($_POST['body'])) |
|
263 | - $context['post_error']['messages'][] = $txt['warning_notify_blank']; |
|
264 | - } |
|
265 | - else |
|
273 | + if (empty($_POST['title']) || empty($_POST['body'])) { |
|
274 | + $context['post_error']['messages'][] = $txt['warning_notify_blank']; |
|
275 | + } |
|
276 | + } else |
|
266 | 277 | { |
267 | - if (empty($_POST['title'])) |
|
268 | - $context['post_error']['messages'][] = $txt['mc_warning_template_error_no_title']; |
|
269 | - if (empty($_POST['body'])) |
|
270 | - $context['post_error']['messages'][] = $txt['mc_warning_template_error_no_body']; |
|
278 | + if (empty($_POST['title'])) { |
|
279 | + $context['post_error']['messages'][] = $txt['mc_warning_template_error_no_title']; |
|
280 | + } |
|
281 | + if (empty($_POST['body'])) { |
|
282 | + $context['post_error']['messages'][] = $txt['mc_warning_template_error_no_body']; |
|
283 | + } |
|
271 | 284 | // Add in few replacements. |
272 | 285 | /** |
273 | 286 | * These are the defaults: |
@@ -298,9 +311,9 @@ discard block |
||
298 | 311 | $warning_body = parse_bbc($warning_body, true); |
299 | 312 | } |
300 | 313 | $context['preview_message'] = $warning_body; |
314 | + } else { |
|
315 | + $context['post_error']['messages'][] = array('value' => $txt['cannot_issue_warning'], 'attributes' => array('type' => 'error')); |
|
301 | 316 | } |
302 | - else |
|
303 | - $context['post_error']['messages'][] = array('value' => $txt['cannot_issue_warning'], 'attributes' => array('type' => 'error')); |
|
304 | 317 | |
305 | 318 | $context['sub_template'] = 'warning'; |
306 | 319 | } |