@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | 'value' => $txt['name'], |
97 | 97 | ), |
98 | 98 | 'data' => array( |
99 | - 'function' => function ($rowData) use ($scripturl) |
|
99 | + 'function' => function($rowData) use ($scripturl) |
|
100 | 100 | { |
101 | 101 | // Since the moderator group has no explicit members, no link is needed. |
102 | 102 | if ($rowData['id_group'] == 3) |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | 'value' => $txt['moderators'], |
147 | 147 | ), |
148 | 148 | 'data' => array( |
149 | - 'function' => function ($group) use ($txt) |
|
149 | + 'function' => function($group) use ($txt) |
|
150 | 150 | { |
151 | 151 | return empty($group['moderators']) ? '<em>' . $txt['membergroups_new_copy_none'] . '</em>' : implode(', ', $group['moderators']); |
152 | 152 | }, |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | 'value' => $txt['membergroups_members_top'], |
158 | 158 | ), |
159 | 159 | 'data' => array( |
160 | - 'function' => function ($rowData) use ($txt) |
|
160 | + 'function' => function($rowData) use ($txt) |
|
161 | 161 | { |
162 | 162 | // No explicit members for the moderator group. |
163 | 163 | return $rowData['id_group'] == 3 ? $txt['membergroups_guests_na'] : comma_format($rowData['num_members']); |
@@ -745,7 +745,7 @@ discard block |
||
745 | 745 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
746 | 746 | { |
747 | 747 | if (empty($row['reason'])) |
748 | - $reason = '<em>(' . $txt['mc_groupr_no_reason'] . ')</em>'; |
|
748 | + $reason = '<em>(' . $txt['mc_groupr_no_reason'] . ')</em>'; |
|
749 | 749 | else |
750 | 750 | $reason = censorText($row['reason']); |
751 | 751 |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Entry point function, permission checks, admin bars, etc. |
@@ -99,27 +100,27 @@ discard block |
||
99 | 100 | 'function' => function ($rowData) use ($scripturl) |
100 | 101 | { |
101 | 102 | // Since the moderator group has no explicit members, no link is needed. |
102 | - if ($rowData['id_group'] == 3) |
|
103 | - $group_name = $rowData['group_name']; |
|
104 | - else |
|
103 | + if ($rowData['id_group'] == 3) { |
|
104 | + $group_name = $rowData['group_name']; |
|
105 | + } else |
|
105 | 106 | { |
106 | 107 | $color_style = empty($rowData['online_color']) ? '' : sprintf(' style="color: %1$s;"', $rowData['online_color']); |
107 | 108 | |
108 | 109 | if (allowedTo('manage_membergroups')) |
109 | 110 | { |
110 | 111 | $group_name = sprintf('<a href="%1$s?action=admin;area=membergroups;sa=members;group=%2$d"%3$s>%4$s</a>', $scripturl, $rowData['id_group'], $color_style, $rowData['group_name']); |
111 | - } |
|
112 | - else |
|
112 | + } else |
|
113 | 113 | { |
114 | 114 | $group_name = sprintf('<a href="%1$s?action=groups;sa=members;group=%2$d"%3$s>%4$s</a>', $scripturl, $rowData['id_group'], $color_style, $rowData['group_name']); |
115 | 115 | } |
116 | 116 | } |
117 | 117 | |
118 | 118 | // Add a help option for moderator and administrator. |
119 | - if ($rowData['id_group'] == 1) |
|
120 | - $group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_administrator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
|
121 | - elseif ($rowData['id_group'] == 3) |
|
122 | - $group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_moderator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
|
119 | + if ($rowData['id_group'] == 1) { |
|
120 | + $group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_administrator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
|
121 | + } elseif ($rowData['id_group'] == 3) { |
|
122 | + $group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_moderator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
|
123 | + } |
|
123 | 124 | |
124 | 125 | return $group_name; |
125 | 126 | }, |
@@ -198,8 +199,9 @@ discard block |
||
198 | 199 | $_REQUEST['group'] = isset($_REQUEST['group']) ? (int) $_REQUEST['group'] : 0; |
199 | 200 | |
200 | 201 | // No browsing of guests, membergroup 0 or moderators. |
201 | - if (in_array($_REQUEST['group'], array(-1, 0, 3))) |
|
202 | - fatal_lang_error('membergroup_does_not_exist', false); |
|
202 | + if (in_array($_REQUEST['group'], array(-1, 0, 3))) { |
|
203 | + fatal_lang_error('membergroup_does_not_exist', false); |
|
204 | + } |
|
203 | 205 | |
204 | 206 | // Load up the group details. |
205 | 207 | $request = $smcFunc['db_query']('', ' |
@@ -214,8 +216,9 @@ discard block |
||
214 | 216 | ) |
215 | 217 | ); |
216 | 218 | // Doesn't exist? |
217 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
218 | - fatal_lang_error('membergroup_does_not_exist', false); |
|
219 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
220 | + fatal_lang_error('membergroup_does_not_exist', false); |
|
221 | + } |
|
219 | 222 | $context['group'] = $smcFunc['db_fetch_assoc']($request); |
220 | 223 | $smcFunc['db_free_result']($request); |
221 | 224 | |
@@ -248,21 +251,25 @@ discard block |
||
248 | 251 | 'name' => $row['real_name'] |
249 | 252 | ); |
250 | 253 | |
251 | - if ($user_info['id'] == $row['id_member'] && $context['group']['group_type'] != 1) |
|
252 | - $context['group']['can_moderate'] = true; |
|
254 | + if ($user_info['id'] == $row['id_member'] && $context['group']['group_type'] != 1) { |
|
255 | + $context['group']['can_moderate'] = true; |
|
256 | + } |
|
253 | 257 | } |
254 | 258 | $smcFunc['db_free_result']($request); |
255 | 259 | |
256 | 260 | // If this group is hidden then it can only "exists" if the user can moderate it! |
257 | - if ($context['group']['hidden'] && !$context['group']['can_moderate']) |
|
258 | - fatal_lang_error('membergroup_does_not_exist', false); |
|
261 | + if ($context['group']['hidden'] && !$context['group']['can_moderate']) { |
|
262 | + fatal_lang_error('membergroup_does_not_exist', false); |
|
263 | + } |
|
259 | 264 | |
260 | 265 | // You can only assign membership if you are the moderator and/or can manage groups! |
261 | - if (!$context['group']['can_moderate']) |
|
262 | - $context['group']['assignable'] = 0; |
|
266 | + if (!$context['group']['can_moderate']) { |
|
267 | + $context['group']['assignable'] = 0; |
|
268 | + } |
|
263 | 269 | // Non-admins cannot assign admins. |
264 | - elseif ($context['group']['id'] == 1 && !allowedTo('admin_forum')) |
|
265 | - $context['group']['assignable'] = 0; |
|
270 | + elseif ($context['group']['id'] == 1 && !allowedTo('admin_forum')) { |
|
271 | + $context['group']['assignable'] = 0; |
|
272 | + } |
|
266 | 273 | |
267 | 274 | // Removing member from group? |
268 | 275 | if (isset($_POST['remove']) && !empty($_REQUEST['rem']) && is_array($_REQUEST['rem']) && $context['group']['assignable']) |
@@ -271,8 +278,9 @@ discard block |
||
271 | 278 | validateToken('mod-mgm'); |
272 | 279 | |
273 | 280 | // Make sure we're dealing with integers only. |
274 | - foreach ($_REQUEST['rem'] as $key => $group) |
|
275 | - $_REQUEST['rem'][$key] = (int) $group; |
|
281 | + foreach ($_REQUEST['rem'] as $key => $group) { |
|
282 | + $_REQUEST['rem'][$key] = (int) $group; |
|
283 | + } |
|
276 | 284 | |
277 | 285 | require_once($sourcedir . '/Subs-Membergroups.php'); |
278 | 286 | removeMembersFromGroups($_REQUEST['rem'], $_REQUEST['group'], true); |
@@ -295,16 +303,18 @@ discard block |
||
295 | 303 | { |
296 | 304 | $member_names[$index] = trim($smcFunc['strtolower']($member_names[$index])); |
297 | 305 | |
298 | - if (strlen($member_names[$index]) == 0) |
|
299 | - unset($member_names[$index]); |
|
306 | + if (strlen($member_names[$index]) == 0) { |
|
307 | + unset($member_names[$index]); |
|
308 | + } |
|
300 | 309 | } |
301 | 310 | |
302 | 311 | // Any passed by ID? |
303 | 312 | $member_ids = array(); |
304 | - if (!empty($_REQUEST['member_add'])) |
|
305 | - foreach ($_REQUEST['member_add'] as $id) |
|
313 | + if (!empty($_REQUEST['member_add'])) { |
|
314 | + foreach ($_REQUEST['member_add'] as $id) |
|
306 | 315 | if ($id > 0) |
307 | 316 | $member_ids[] = (int) $id; |
317 | + } |
|
308 | 318 | |
309 | 319 | // Construct the query pelements. |
310 | 320 | if (!empty($member_ids)) |
@@ -332,8 +342,9 @@ discard block |
||
332 | 342 | 'id_group' => $_REQUEST['group'], |
333 | 343 | )) |
334 | 344 | ); |
335 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
336 | - $members[] = $row['id_member']; |
|
345 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
346 | + $members[] = $row['id_member']; |
|
347 | + } |
|
337 | 348 | $smcFunc['db_free_result']($request); |
338 | 349 | } |
339 | 350 | |
@@ -372,10 +383,11 @@ discard block |
||
372 | 383 | $context['sort_direction'] = isset($_REQUEST['desc']) ? 'down' : 'up'; |
373 | 384 | |
374 | 385 | // The where on the query is interesting. Non-moderators should only see people who are in this group as primary. |
375 | - if ($context['group']['can_moderate']) |
|
376 | - $where = $context['group']['is_post_group'] ? 'id_post_group = {int:group}' : 'id_group = {int:group} OR FIND_IN_SET({int:group}, additional_groups) != 0'; |
|
377 | - else |
|
378 | - $where = $context['group']['is_post_group'] ? 'id_post_group = {int:group}' : 'id_group = {int:group}'; |
|
386 | + if ($context['group']['can_moderate']) { |
|
387 | + $where = $context['group']['is_post_group'] ? 'id_post_group = {int:group}' : 'id_group = {int:group} OR FIND_IN_SET({int:group}, additional_groups) != 0'; |
|
388 | + } else { |
|
389 | + $where = $context['group']['is_post_group'] ? 'id_post_group = {int:group}' : 'id_group = {int:group}'; |
|
390 | + } |
|
379 | 391 | |
380 | 392 | // Count members of the group. |
381 | 393 | $request = $smcFunc['db_query']('', ' |
@@ -416,8 +428,9 @@ discard block |
||
416 | 428 | $last_online = empty($row['last_login']) ? $txt['never'] : timeformat($row['last_login']); |
417 | 429 | |
418 | 430 | // Italicize the online note if they aren't activated. |
419 | - if ($row['is_activated'] % 10 != 1) |
|
420 | - $last_online = '<em title="' . $txt['not_activated'] . '">' . $last_online . '</em>'; |
|
431 | + if ($row['is_activated'] % 10 != 1) { |
|
432 | + $last_online = '<em title="' . $txt['not_activated'] . '">' . $last_online . '</em>'; |
|
433 | + } |
|
421 | 434 | |
422 | 435 | $context['members'][] = array( |
423 | 436 | 'id' => $row['id_member'], |
@@ -437,9 +450,10 @@ discard block |
||
437 | 450 | $context['page_title'] = $txt['membergroups_members_title'] . ': ' . $context['group']['name']; |
438 | 451 | createToken('mod-mgm'); |
439 | 452 | |
440 | - if ($context['group']['assignable']) |
|
441 | - loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest'); |
|
442 | -} |
|
453 | + if ($context['group']['assignable']) { |
|
454 | + loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest'); |
|
455 | + } |
|
456 | + } |
|
443 | 457 | |
444 | 458 | /** |
445 | 459 | * Show and manage all group requests. |
@@ -453,16 +467,18 @@ discard block |
||
453 | 467 | $context['sub_template'] = 'show_list'; |
454 | 468 | |
455 | 469 | // Verify we can be here. |
456 | - if ($user_info['mod_cache']['gq'] == '0=1') |
|
457 | - isAllowedTo('manage_membergroups'); |
|
470 | + if ($user_info['mod_cache']['gq'] == '0=1') { |
|
471 | + isAllowedTo('manage_membergroups'); |
|
472 | + } |
|
458 | 473 | |
459 | 474 | // Normally, we act normally... |
460 | 475 | $where = ($user_info['mod_cache']['gq'] == '1=1' || $user_info['mod_cache']['gq'] == '0=1' ? $user_info['mod_cache']['gq'] : 'lgr.' . $user_info['mod_cache']['gq']); |
461 | 476 | |
462 | - if (isset($_GET['closed'])) |
|
463 | - $where .= ' AND lgr.status != {int:status_open}'; |
|
464 | - else |
|
465 | - $where .= ' AND lgr.status = {int:status_open}'; |
|
477 | + if (isset($_GET['closed'])) { |
|
478 | + $where .= ' AND lgr.status != {int:status_open}'; |
|
479 | + } else { |
|
480 | + $where .= ' AND lgr.status = {int:status_open}'; |
|
481 | + } |
|
466 | 482 | |
467 | 483 | $where_parameters = array( |
468 | 484 | 'status_open' => 0, |
@@ -475,8 +491,9 @@ discard block |
||
475 | 491 | validateToken('mod-gr'); |
476 | 492 | |
477 | 493 | // Clean the values. |
478 | - foreach ($_POST['groupr'] as $k => $request) |
|
479 | - $_POST['groupr'][$k] = (int) $request; |
|
494 | + foreach ($_POST['groupr'] as $k => $request) { |
|
495 | + $_POST['groupr'][$k] = (int) $request; |
|
496 | + } |
|
480 | 497 | |
481 | 498 | $log_changes = array(); |
482 | 499 | |
@@ -513,8 +530,8 @@ discard block |
||
513 | 530 | $request_list = array(); |
514 | 531 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
515 | 532 | { |
516 | - if (!isset($log_changes[$row['id_request']])) |
|
517 | - $log_changes[$row['id_request']] = array( |
|
533 | + if (!isset($log_changes[$row['id_request']])) { |
|
534 | + $log_changes[$row['id_request']] = array( |
|
518 | 535 | 'id_request' => $row['id_request'], |
519 | 536 | 'status' => $_POST['req_action'] == 'approve' ? 1 : 2, // 1 = approved, 2 = rejected |
520 | 537 | 'id_member_acted' => $user_info['id'], |
@@ -522,6 +539,7 @@ discard block |
||
522 | 539 | 'time_acted' => time(), |
523 | 540 | 'act_reason' => $_POST['req_action'] != 'approve' && !empty($_POST['groupreason']) && !empty($_POST['groupreason'][$row['id_request']]) ? $smcFunc['htmlspecialchars']($_POST['groupreason'][$row['id_request']], ENT_QUOTES) : '', |
524 | 541 | ); |
542 | + } |
|
525 | 543 | $request_list[] = $row['id_request']; |
526 | 544 | } |
527 | 545 | $smcFunc['db_free_result']($request); |
@@ -744,21 +762,24 @@ discard block |
||
744 | 762 | $group_requests = array(); |
745 | 763 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
746 | 764 | { |
747 | - if (empty($row['reason'])) |
|
748 | - $reason = '<em>(' . $txt['mc_groupr_no_reason'] . ')</em>'; |
|
749 | - else |
|
750 | - $reason = censorText($row['reason']); |
|
765 | + if (empty($row['reason'])) { |
|
766 | + $reason = '<em>(' . $txt['mc_groupr_no_reason'] . ')</em>'; |
|
767 | + } else { |
|
768 | + $reason = censorText($row['reason']); |
|
769 | + } |
|
751 | 770 | |
752 | 771 | if (isset($_GET['closed'])) |
753 | 772 | { |
754 | - if ($row['status'] == 1) |
|
755 | - $reason .= '<br><br><strong>' . $txt['mc_groupr_approved'] . '</strong>'; |
|
756 | - elseif ($row['status'] == 2) |
|
757 | - $reason .= '<br><br><strong>' . $txt['mc_groupr_rejected'] . '</strong>'; |
|
773 | + if ($row['status'] == 1) { |
|
774 | + $reason .= '<br><br><strong>' . $txt['mc_groupr_approved'] . '</strong>'; |
|
775 | + } elseif ($row['status'] == 2) { |
|
776 | + $reason .= '<br><br><strong>' . $txt['mc_groupr_rejected'] . '</strong>'; |
|
777 | + } |
|
758 | 778 | |
759 | 779 | $reason .= ' (' . timeformat($row['time_acted']) . ')'; |
760 | - if (!empty($row['act_reason'])) |
|
761 | - $reason .= '<br><br>' . censorText($row['act_reason']); |
|
780 | + if (!empty($row['act_reason'])) { |
|
781 | + $reason .= '<br><br>' . censorText($row['act_reason']); |
|
782 | + } |
|
762 | 783 | } |
763 | 784 | |
764 | 785 | $group_requests[] = array( |
@@ -17,97 +17,97 @@ discard block |
||
17 | 17 | */ |
18 | 18 | class CSS extends Minify |
19 | 19 | { |
20 | - /** |
|
21 | - * @var int |
|
22 | - */ |
|
23 | - protected $maxImportSize = 5; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var string[] |
|
27 | - */ |
|
28 | - protected $importExtensions = array( |
|
29 | - 'gif' => 'data:image/gif', |
|
30 | - 'png' => 'data:image/png', |
|
31 | - 'jpe' => 'data:image/jpeg', |
|
32 | - 'jpg' => 'data:image/jpeg', |
|
33 | - 'jpeg' => 'data:image/jpeg', |
|
34 | - 'svg' => 'data:image/svg+xml', |
|
35 | - 'woff' => 'data:application/x-font-woff', |
|
36 | - 'tif' => 'image/tiff', |
|
37 | - 'tiff' => 'image/tiff', |
|
38 | - 'xbm' => 'image/x-xbitmap', |
|
39 | - ); |
|
40 | - |
|
41 | - /** |
|
42 | - * Set the maximum size if files to be imported. |
|
43 | - * |
|
44 | - * Files larger than this size (in kB) will not be imported into the CSS. |
|
45 | - * Importing files into the CSS as data-uri will save you some connections, |
|
46 | - * but we should only import relatively small decorative images so that our |
|
47 | - * CSS file doesn't get too bulky. |
|
48 | - * |
|
49 | - * @param int $size Size in kB |
|
50 | - */ |
|
51 | - public function setMaxImportSize($size) |
|
52 | - { |
|
53 | - $this->maxImportSize = $size; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Set the type of extensions to be imported into the CSS (to save network |
|
58 | - * connections). |
|
59 | - * Keys of the array should be the file extensions & respective values |
|
60 | - * should be the data type. |
|
61 | - * |
|
62 | - * @param string[] $extensions Array of file extensions |
|
63 | - */ |
|
64 | - public function setImportExtensions(array $extensions) |
|
65 | - { |
|
66 | - $this->importExtensions = $extensions; |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Move any import statements to the top. |
|
71 | - * |
|
72 | - * @param string $content Nearly finished CSS content |
|
73 | - * |
|
74 | - * @return string |
|
75 | - */ |
|
76 | - protected function moveImportsToTop($content) |
|
77 | - { |
|
78 | - if (preg_match_all('/@import[^;]+;/', $content, $matches)) { |
|
79 | - |
|
80 | - // remove from content |
|
81 | - foreach ($matches[0] as $import) { |
|
82 | - $content = str_replace($import, '', $content); |
|
83 | - } |
|
84 | - |
|
85 | - // add to top |
|
86 | - $content = implode('', $matches[0]).$content; |
|
87 | - }; |
|
88 | - |
|
89 | - return $content; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Combine CSS from import statements. |
|
94 | - * |
|
95 | - * @import's will be loaded and their content merged into the original file, |
|
96 | - * to save HTTP requests. |
|
97 | - * |
|
98 | - * @param string $source The file to combine imports for. |
|
99 | - * @param string $content The CSS content to combine imports for. |
|
100 | - * @param string[] $parents Parent paths, for circular reference checks. |
|
101 | - * |
|
102 | - * @return string |
|
103 | - * |
|
104 | - * @throws FileImportException |
|
105 | - */ |
|
106 | - protected function combineImports($source, $content, $parents) |
|
107 | - { |
|
108 | - $importRegexes = array( |
|
109 | - // @import url(xxx) |
|
110 | - '/ |
|
20 | + /** |
|
21 | + * @var int |
|
22 | + */ |
|
23 | + protected $maxImportSize = 5; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var string[] |
|
27 | + */ |
|
28 | + protected $importExtensions = array( |
|
29 | + 'gif' => 'data:image/gif', |
|
30 | + 'png' => 'data:image/png', |
|
31 | + 'jpe' => 'data:image/jpeg', |
|
32 | + 'jpg' => 'data:image/jpeg', |
|
33 | + 'jpeg' => 'data:image/jpeg', |
|
34 | + 'svg' => 'data:image/svg+xml', |
|
35 | + 'woff' => 'data:application/x-font-woff', |
|
36 | + 'tif' => 'image/tiff', |
|
37 | + 'tiff' => 'image/tiff', |
|
38 | + 'xbm' => 'image/x-xbitmap', |
|
39 | + ); |
|
40 | + |
|
41 | + /** |
|
42 | + * Set the maximum size if files to be imported. |
|
43 | + * |
|
44 | + * Files larger than this size (in kB) will not be imported into the CSS. |
|
45 | + * Importing files into the CSS as data-uri will save you some connections, |
|
46 | + * but we should only import relatively small decorative images so that our |
|
47 | + * CSS file doesn't get too bulky. |
|
48 | + * |
|
49 | + * @param int $size Size in kB |
|
50 | + */ |
|
51 | + public function setMaxImportSize($size) |
|
52 | + { |
|
53 | + $this->maxImportSize = $size; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Set the type of extensions to be imported into the CSS (to save network |
|
58 | + * connections). |
|
59 | + * Keys of the array should be the file extensions & respective values |
|
60 | + * should be the data type. |
|
61 | + * |
|
62 | + * @param string[] $extensions Array of file extensions |
|
63 | + */ |
|
64 | + public function setImportExtensions(array $extensions) |
|
65 | + { |
|
66 | + $this->importExtensions = $extensions; |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Move any import statements to the top. |
|
71 | + * |
|
72 | + * @param string $content Nearly finished CSS content |
|
73 | + * |
|
74 | + * @return string |
|
75 | + */ |
|
76 | + protected function moveImportsToTop($content) |
|
77 | + { |
|
78 | + if (preg_match_all('/@import[^;]+;/', $content, $matches)) { |
|
79 | + |
|
80 | + // remove from content |
|
81 | + foreach ($matches[0] as $import) { |
|
82 | + $content = str_replace($import, '', $content); |
|
83 | + } |
|
84 | + |
|
85 | + // add to top |
|
86 | + $content = implode('', $matches[0]).$content; |
|
87 | + }; |
|
88 | + |
|
89 | + return $content; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Combine CSS from import statements. |
|
94 | + * |
|
95 | + * @import's will be loaded and their content merged into the original file, |
|
96 | + * to save HTTP requests. |
|
97 | + * |
|
98 | + * @param string $source The file to combine imports for. |
|
99 | + * @param string $content The CSS content to combine imports for. |
|
100 | + * @param string[] $parents Parent paths, for circular reference checks. |
|
101 | + * |
|
102 | + * @return string |
|
103 | + * |
|
104 | + * @throws FileImportException |
|
105 | + */ |
|
106 | + protected function combineImports($source, $content, $parents) |
|
107 | + { |
|
108 | + $importRegexes = array( |
|
109 | + // @import url(xxx) |
|
110 | + '/ |
|
111 | 111 | # import statement |
112 | 112 | @import |
113 | 113 | |
@@ -152,8 +152,8 @@ discard block |
||
152 | 152 | |
153 | 153 | /ix', |
154 | 154 | |
155 | - // @import 'xxx' |
|
156 | - '/ |
|
155 | + // @import 'xxx' |
|
156 | + '/ |
|
157 | 157 | |
158 | 158 | # import statement |
159 | 159 | @import |
@@ -192,172 +192,172 @@ discard block |
||
192 | 192 | ;? |
193 | 193 | |
194 | 194 | /ix', |
195 | - ); |
|
196 | - |
|
197 | - // find all relative imports in css |
|
198 | - $matches = array(); |
|
199 | - foreach ($importRegexes as $importRegex) { |
|
200 | - if (preg_match_all($importRegex, $content, $regexMatches, PREG_SET_ORDER)) { |
|
201 | - $matches = array_merge($matches, $regexMatches); |
|
202 | - } |
|
203 | - } |
|
204 | - |
|
205 | - $search = array(); |
|
206 | - $replace = array(); |
|
207 | - |
|
208 | - // loop the matches |
|
209 | - foreach ($matches as $match) { |
|
210 | - // get the path for the file that will be imported |
|
211 | - $importPath = dirname($source).'/'.$match['path']; |
|
212 | - |
|
213 | - // only replace the import with the content if we can grab the |
|
214 | - // content of the file |
|
215 | - if ($this->canImportFile($importPath)) { |
|
216 | - // check if current file was not imported previously in the same |
|
217 | - // import chain. |
|
218 | - if (in_array($importPath, $parents)) { |
|
219 | - throw new FileImportException('Failed to import file "'.$importPath.'": circular reference detected.'); |
|
220 | - } |
|
221 | - |
|
222 | - // grab referenced file & minify it (which may include importing |
|
223 | - // yet other @import statements recursively) |
|
224 | - $minifier = new static($importPath); |
|
225 | - $importContent = $minifier->execute($source, $parents); |
|
226 | - |
|
227 | - // check if this is only valid for certain media |
|
228 | - if (!empty($match['media'])) { |
|
229 | - $importContent = '@media '.$match['media'].'{'.$importContent.'}'; |
|
230 | - } |
|
231 | - |
|
232 | - // add to replacement array |
|
233 | - $search[] = $match[0]; |
|
234 | - $replace[] = $importContent; |
|
235 | - } |
|
236 | - } |
|
237 | - |
|
238 | - // replace the import statements |
|
239 | - $content = str_replace($search, $replace, $content); |
|
240 | - |
|
241 | - return $content; |
|
242 | - } |
|
243 | - |
|
244 | - /** |
|
245 | - * Import files into the CSS, base64-ized. |
|
246 | - * |
|
247 | - * @url(image.jpg) images will be loaded and their content merged into the |
|
248 | - * original file, to save HTTP requests. |
|
249 | - * |
|
250 | - * @param string $source The file to import files for. |
|
251 | - * @param string $content The CSS content to import files for. |
|
252 | - * |
|
253 | - * @return string |
|
254 | - */ |
|
255 | - protected function importFiles($source, $content) |
|
256 | - { |
|
257 | - $extensions = array_keys($this->importExtensions); |
|
258 | - $regex = '/url\((["\']?)((?!["\']?data:).*?\.('.implode('|', $extensions).'))\\1\)/i'; |
|
259 | - if ($extensions && preg_match_all($regex, $content, $matches, PREG_SET_ORDER)) { |
|
260 | - $search = array(); |
|
261 | - $replace = array(); |
|
262 | - |
|
263 | - // loop the matches |
|
264 | - foreach ($matches as $match) { |
|
265 | - // get the path for the file that will be imported |
|
266 | - $path = $match[2]; |
|
267 | - $path = dirname($source).'/'.$path; |
|
268 | - $extension = $match[3]; |
|
269 | - |
|
270 | - // only replace the import with the content if we're able to get |
|
271 | - // the content of the file, and it's relatively small |
|
272 | - if ($this->canImportFile($path) && $this->canImportBySize($path)) { |
|
273 | - // grab content && base64-ize |
|
274 | - $importContent = $this->load($path); |
|
275 | - $importContent = base64_encode($importContent); |
|
276 | - |
|
277 | - // build replacement |
|
278 | - $search[] = $match[0]; |
|
279 | - $replace[] = 'url('.$this->importExtensions[$extension].';base64,'.$importContent.')'; |
|
280 | - } |
|
281 | - } |
|
282 | - |
|
283 | - // replace the import statements |
|
284 | - $content = str_replace($search, $replace, $content); |
|
285 | - } |
|
286 | - |
|
287 | - return $content; |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * Minify the data. |
|
292 | - * Perform CSS optimizations. |
|
293 | - * |
|
294 | - * @param string[optional] $path Path to write the data to. |
|
295 | - * @param string[] $parents Parent paths, for circular reference checks. |
|
296 | - * |
|
297 | - * @return string The minified data. |
|
298 | - */ |
|
299 | - public function execute($path = null, $parents = array()) |
|
300 | - { |
|
301 | - $content = ''; |
|
302 | - |
|
303 | - // loop css data (raw data and files) |
|
304 | - foreach ($this->data as $source => $css) { |
|
305 | - /* |
|
195 | + ); |
|
196 | + |
|
197 | + // find all relative imports in css |
|
198 | + $matches = array(); |
|
199 | + foreach ($importRegexes as $importRegex) { |
|
200 | + if (preg_match_all($importRegex, $content, $regexMatches, PREG_SET_ORDER)) { |
|
201 | + $matches = array_merge($matches, $regexMatches); |
|
202 | + } |
|
203 | + } |
|
204 | + |
|
205 | + $search = array(); |
|
206 | + $replace = array(); |
|
207 | + |
|
208 | + // loop the matches |
|
209 | + foreach ($matches as $match) { |
|
210 | + // get the path for the file that will be imported |
|
211 | + $importPath = dirname($source).'/'.$match['path']; |
|
212 | + |
|
213 | + // only replace the import with the content if we can grab the |
|
214 | + // content of the file |
|
215 | + if ($this->canImportFile($importPath)) { |
|
216 | + // check if current file was not imported previously in the same |
|
217 | + // import chain. |
|
218 | + if (in_array($importPath, $parents)) { |
|
219 | + throw new FileImportException('Failed to import file "'.$importPath.'": circular reference detected.'); |
|
220 | + } |
|
221 | + |
|
222 | + // grab referenced file & minify it (which may include importing |
|
223 | + // yet other @import statements recursively) |
|
224 | + $minifier = new static($importPath); |
|
225 | + $importContent = $minifier->execute($source, $parents); |
|
226 | + |
|
227 | + // check if this is only valid for certain media |
|
228 | + if (!empty($match['media'])) { |
|
229 | + $importContent = '@media '.$match['media'].'{'.$importContent.'}'; |
|
230 | + } |
|
231 | + |
|
232 | + // add to replacement array |
|
233 | + $search[] = $match[0]; |
|
234 | + $replace[] = $importContent; |
|
235 | + } |
|
236 | + } |
|
237 | + |
|
238 | + // replace the import statements |
|
239 | + $content = str_replace($search, $replace, $content); |
|
240 | + |
|
241 | + return $content; |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * Import files into the CSS, base64-ized. |
|
246 | + * |
|
247 | + * @url(image.jpg) images will be loaded and their content merged into the |
|
248 | + * original file, to save HTTP requests. |
|
249 | + * |
|
250 | + * @param string $source The file to import files for. |
|
251 | + * @param string $content The CSS content to import files for. |
|
252 | + * |
|
253 | + * @return string |
|
254 | + */ |
|
255 | + protected function importFiles($source, $content) |
|
256 | + { |
|
257 | + $extensions = array_keys($this->importExtensions); |
|
258 | + $regex = '/url\((["\']?)((?!["\']?data:).*?\.('.implode('|', $extensions).'))\\1\)/i'; |
|
259 | + if ($extensions && preg_match_all($regex, $content, $matches, PREG_SET_ORDER)) { |
|
260 | + $search = array(); |
|
261 | + $replace = array(); |
|
262 | + |
|
263 | + // loop the matches |
|
264 | + foreach ($matches as $match) { |
|
265 | + // get the path for the file that will be imported |
|
266 | + $path = $match[2]; |
|
267 | + $path = dirname($source).'/'.$path; |
|
268 | + $extension = $match[3]; |
|
269 | + |
|
270 | + // only replace the import with the content if we're able to get |
|
271 | + // the content of the file, and it's relatively small |
|
272 | + if ($this->canImportFile($path) && $this->canImportBySize($path)) { |
|
273 | + // grab content && base64-ize |
|
274 | + $importContent = $this->load($path); |
|
275 | + $importContent = base64_encode($importContent); |
|
276 | + |
|
277 | + // build replacement |
|
278 | + $search[] = $match[0]; |
|
279 | + $replace[] = 'url('.$this->importExtensions[$extension].';base64,'.$importContent.')'; |
|
280 | + } |
|
281 | + } |
|
282 | + |
|
283 | + // replace the import statements |
|
284 | + $content = str_replace($search, $replace, $content); |
|
285 | + } |
|
286 | + |
|
287 | + return $content; |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * Minify the data. |
|
292 | + * Perform CSS optimizations. |
|
293 | + * |
|
294 | + * @param string[optional] $path Path to write the data to. |
|
295 | + * @param string[] $parents Parent paths, for circular reference checks. |
|
296 | + * |
|
297 | + * @return string The minified data. |
|
298 | + */ |
|
299 | + public function execute($path = null, $parents = array()) |
|
300 | + { |
|
301 | + $content = ''; |
|
302 | + |
|
303 | + // loop css data (raw data and files) |
|
304 | + foreach ($this->data as $source => $css) { |
|
305 | + /* |
|
306 | 306 | * Let's first take out strings & comments, since we can't just remove |
307 | 307 | * whitespace anywhere. If whitespace occurs inside a string, we should |
308 | 308 | * leave it alone. E.g.: |
309 | 309 | * p { content: "a test" } |
310 | 310 | */ |
311 | - $this->extractStrings(); |
|
312 | - $this->stripComments(); |
|
313 | - $css = $this->replace($css); |
|
311 | + $this->extractStrings(); |
|
312 | + $this->stripComments(); |
|
313 | + $css = $this->replace($css); |
|
314 | 314 | |
315 | - $css = $this->stripWhitespace($css); |
|
316 | - $css = $this->shortenHex($css); |
|
317 | - $css = $this->shortenZeroes($css); |
|
318 | - $css = $this->stripEmptyTags($css); |
|
315 | + $css = $this->stripWhitespace($css); |
|
316 | + $css = $this->shortenHex($css); |
|
317 | + $css = $this->shortenZeroes($css); |
|
318 | + $css = $this->stripEmptyTags($css); |
|
319 | 319 | |
320 | - // restore the string we've extracted earlier |
|
321 | - $css = $this->restoreExtractedData($css); |
|
320 | + // restore the string we've extracted earlier |
|
321 | + $css = $this->restoreExtractedData($css); |
|
322 | 322 | |
323 | - $source = is_int($source) ? '' : $source; |
|
324 | - $parents = $source ? array_merge($parents, array($source)) : $parents; |
|
325 | - $css = $this->combineImports($source, $css, $parents); |
|
326 | - $css = $this->importFiles($source, $css); |
|
323 | + $source = is_int($source) ? '' : $source; |
|
324 | + $parents = $source ? array_merge($parents, array($source)) : $parents; |
|
325 | + $css = $this->combineImports($source, $css, $parents); |
|
326 | + $css = $this->importFiles($source, $css); |
|
327 | 327 | |
328 | - /* |
|
328 | + /* |
|
329 | 329 | * If we'll save to a new path, we'll have to fix the relative paths |
330 | 330 | * to be relative no longer to the source file, but to the new path. |
331 | 331 | * If we don't write to a file, fall back to same path so no |
332 | 332 | * conversion happens (because we still want it to go through most |
333 | 333 | * of the move code...) |
334 | 334 | */ |
335 | - $converter = new Converter($source, $path ?: $source); |
|
336 | - $css = $this->move($converter, $css); |
|
337 | - |
|
338 | - // combine css |
|
339 | - $content .= $css; |
|
340 | - } |
|
341 | - |
|
342 | - $content = $this->moveImportsToTop($content); |
|
343 | - |
|
344 | - return $content; |
|
345 | - } |
|
346 | - |
|
347 | - /** |
|
348 | - * Moving a css file should update all relative urls. |
|
349 | - * Relative references (e.g. ../images/image.gif) in a certain css file, |
|
350 | - * will have to be updated when a file is being saved at another location |
|
351 | - * (e.g. ../../images/image.gif, if the new CSS file is 1 folder deeper). |
|
352 | - * |
|
353 | - * @param Converter $converter Relative path converter |
|
354 | - * @param string $content The CSS content to update relative urls for. |
|
355 | - * |
|
356 | - * @return string |
|
357 | - */ |
|
358 | - protected function move(Converter $converter, $content) |
|
359 | - { |
|
360 | - /* |
|
335 | + $converter = new Converter($source, $path ?: $source); |
|
336 | + $css = $this->move($converter, $css); |
|
337 | + |
|
338 | + // combine css |
|
339 | + $content .= $css; |
|
340 | + } |
|
341 | + |
|
342 | + $content = $this->moveImportsToTop($content); |
|
343 | + |
|
344 | + return $content; |
|
345 | + } |
|
346 | + |
|
347 | + /** |
|
348 | + * Moving a css file should update all relative urls. |
|
349 | + * Relative references (e.g. ../images/image.gif) in a certain css file, |
|
350 | + * will have to be updated when a file is being saved at another location |
|
351 | + * (e.g. ../../images/image.gif, if the new CSS file is 1 folder deeper). |
|
352 | + * |
|
353 | + * @param Converter $converter Relative path converter |
|
354 | + * @param string $content The CSS content to update relative urls for. |
|
355 | + * |
|
356 | + * @return string |
|
357 | + */ |
|
358 | + protected function move(Converter $converter, $content) |
|
359 | + { |
|
360 | + /* |
|
361 | 361 | * Relative path references will usually be enclosed by url(). @import |
362 | 362 | * is an exception, where url() is not necessary around the path (but is |
363 | 363 | * allowed). |
@@ -368,9 +368,9 @@ discard block |
||
368 | 368 | * recent PCRE version. That's why I'm doing 2 separate regular |
369 | 369 | * expressions & combining the matches after executing of both. |
370 | 370 | */ |
371 | - $relativeRegexes = array( |
|
372 | - // url(xxx) |
|
373 | - '/ |
|
371 | + $relativeRegexes = array( |
|
372 | + // url(xxx) |
|
373 | + '/ |
|
374 | 374 | # open url() |
375 | 375 | url\( |
376 | 376 | |
@@ -402,8 +402,8 @@ discard block |
||
402 | 402 | |
403 | 403 | /ix', |
404 | 404 | |
405 | - // @import "xxx" |
|
406 | - '/ |
|
405 | + // @import "xxx" |
|
406 | + '/ |
|
407 | 407 | # import statement |
408 | 408 | @import |
409 | 409 | |
@@ -432,167 +432,167 @@ discard block |
||
432 | 432 | (?P=quotes) |
433 | 433 | |
434 | 434 | /ix', |
435 | - ); |
|
436 | - |
|
437 | - // find all relative urls in css |
|
438 | - $matches = array(); |
|
439 | - foreach ($relativeRegexes as $relativeRegex) { |
|
440 | - if (preg_match_all($relativeRegex, $content, $regexMatches, PREG_SET_ORDER)) { |
|
441 | - $matches = array_merge($matches, $regexMatches); |
|
442 | - } |
|
443 | - } |
|
444 | - |
|
445 | - $search = array(); |
|
446 | - $replace = array(); |
|
447 | - |
|
448 | - // loop all urls |
|
449 | - foreach ($matches as $match) { |
|
450 | - // determine if it's a url() or an @import match |
|
451 | - $type = (strpos($match[0], '@import') === 0 ? 'import' : 'url'); |
|
452 | - |
|
453 | - // attempting to interpret GET-params makes no sense, so let's discard them for awhile |
|
454 | - $params = strrchr($match['path'], '?'); |
|
455 | - $url = $params ? substr($match['path'], 0, -strlen($params)) : $match['path']; |
|
456 | - |
|
457 | - // fix relative url |
|
458 | - $url = $converter->convert($url); |
|
459 | - |
|
460 | - // now that the path has been converted, re-apply GET-params |
|
461 | - $url .= $params; |
|
462 | - |
|
463 | - // build replacement |
|
464 | - $search[] = $match[0]; |
|
465 | - if ($type == 'url') { |
|
466 | - $replace[] = 'url('.$url.')'; |
|
467 | - } elseif ($type == 'import') { |
|
468 | - $replace[] = '@import "'.$url.'"'; |
|
469 | - } |
|
470 | - } |
|
471 | - |
|
472 | - // replace urls |
|
473 | - $content = str_replace($search, $replace, $content); |
|
474 | - |
|
475 | - return $content; |
|
476 | - } |
|
477 | - |
|
478 | - /** |
|
479 | - * Shorthand hex color codes. |
|
480 | - * #FF0000 -> #F00. |
|
481 | - * |
|
482 | - * @param string $content The CSS content to shorten the hex color codes for. |
|
483 | - * |
|
484 | - * @return string |
|
485 | - */ |
|
486 | - protected function shortenHex($content) |
|
487 | - { |
|
488 | - $content = preg_replace('/(?<![\'"])#([0-9a-z])\\1([0-9a-z])\\2([0-9a-z])\\3(?![\'"])/i', '#$1$2$3', $content); |
|
489 | - |
|
490 | - return $content; |
|
491 | - } |
|
492 | - |
|
493 | - /** |
|
494 | - * Shorthand 0 values to plain 0, instead of e.g. -0em. |
|
495 | - * |
|
496 | - * @param string $content The CSS content to shorten the zero values for. |
|
497 | - * |
|
498 | - * @return string |
|
499 | - */ |
|
500 | - protected function shortenZeroes($content) |
|
501 | - { |
|
502 | - // reusable bits of code throughout these regexes: |
|
503 | - // before & after are used to make sure we don't match lose unintended |
|
504 | - // 0-like values (e.g. in #000, or in http://url/1.0) |
|
505 | - // units can be stripped from 0 values, or used to recognize non 0 |
|
506 | - // values (where wa may be able to strip a .0 suffix) |
|
507 | - $before = '(?<=[:(, ])'; |
|
508 | - $after = '(?=[ ,);}])'; |
|
509 | - $units = '(em|ex|%|px|cm|mm|in|pt|pc|ch|rem|vh|vw|vmin|vmax|vm)'; |
|
510 | - |
|
511 | - // strip units after zeroes (0px -> 0) |
|
512 | - // NOTE: it should be safe to remove all units for a 0 value, but in |
|
513 | - // practice, Webkit (especially Safari) seems to stumble over at least |
|
514 | - // 0%, potentially other units as well. Only stripping 'px' for now. |
|
515 | - // @see https://github.com/matthiasmullie/minify/issues/60 |
|
516 | - $content = preg_replace('/'.$before.'(-?0*(\.0+)?)(?<=0)px'.$after.'/', '\\1', $content); |
|
517 | - |
|
518 | - // strip 0-digits (.0 -> 0) |
|
519 | - $content = preg_replace('/'.$before.'\.0+'.$units.'?'.$after.'/', '0\\1', $content); |
|
520 | - // strip trailing 0: 50.10 -> 50.1, 50.10px -> 50.1px |
|
521 | - $content = preg_replace('/'.$before.'(-?[0-9]+\.[0-9]+)0+'.$units.'?'.$after.'/', '\\1\\2', $content); |
|
522 | - // strip trailing 0: 50.00 -> 50, 50.00px -> 50px |
|
523 | - $content = preg_replace('/'.$before.'(-?[0-9]+)\.0+'.$units.'?'.$after.'/', '\\1\\2', $content); |
|
524 | - // strip leading 0: 0.1 -> .1, 01.1 -> 1.1 |
|
525 | - $content = preg_replace('/'.$before.'(-?)0+([0-9]*\.[0-9]+)'.$units.'?'.$after.'/', '\\1\\2\\3', $content); |
|
526 | - |
|
527 | - // strip negative zeroes (-0 -> 0) & truncate zeroes (00 -> 0) |
|
528 | - $content = preg_replace('/'.$before.'-?0+'.$units.'?'.$after.'/', '0\\1', $content); |
|
529 | - |
|
530 | - return $content; |
|
531 | - } |
|
532 | - |
|
533 | - /** |
|
534 | - * Strip comments from source code. |
|
535 | - * |
|
536 | - * @param string $content |
|
537 | - * |
|
538 | - * @return string |
|
539 | - */ |
|
540 | - protected function stripEmptyTags($content) |
|
541 | - { |
|
542 | - return preg_replace('/(^|\})[^\{\}]+\{\s*\}/', '\\1', $content); |
|
543 | - } |
|
544 | - |
|
545 | - /** |
|
546 | - * Strip comments from source code. |
|
547 | - */ |
|
548 | - protected function stripComments() |
|
549 | - { |
|
550 | - $this->registerPattern('/\/\*.*?\*\//s', ''); |
|
551 | - } |
|
552 | - |
|
553 | - /** |
|
554 | - * Strip whitespace. |
|
555 | - * |
|
556 | - * @param string $content The CSS content to strip the whitespace for. |
|
557 | - * |
|
558 | - * @return string |
|
559 | - */ |
|
560 | - protected function stripWhitespace($content) |
|
561 | - { |
|
562 | - // remove leading & trailing whitespace |
|
563 | - $content = preg_replace('/^\s*/m', '', $content); |
|
564 | - $content = preg_replace('/\s*$/m', '', $content); |
|
565 | - |
|
566 | - // replace newlines with a single space |
|
567 | - $content = preg_replace('/\s+/', ' ', $content); |
|
568 | - |
|
569 | - // remove whitespace around meta characters |
|
570 | - // inspired by stackoverflow.com/questions/15195750/minify-compress-css-with-regex |
|
571 | - $content = preg_replace('/\s*([\*$~^|]?+=|[{};,>~]|!important\b)\s*/', '$1', $content); |
|
572 | - $content = preg_replace('/([\[(:])\s+/', '$1', $content); |
|
573 | - $content = preg_replace('/\s+([\]\)])/', '$1', $content); |
|
574 | - $content = preg_replace('/\s+(:)(?![^\}]*\{)/', '$1', $content); |
|
575 | - |
|
576 | - // whitespace around + and - can only be stripped in selectors, like |
|
577 | - // :nth-child(3+2n), not in things like calc(3px + 2px) or shorthands |
|
578 | - // like 3px -2px |
|
579 | - $content = preg_replace('/\s*([+-])\s*(?=[^}]*{)/', '$1', $content); |
|
580 | - |
|
581 | - // remove semicolon/whitespace followed by closing bracket |
|
582 | - $content = str_replace(';}', '}', $content); |
|
583 | - |
|
584 | - return trim($content); |
|
585 | - } |
|
586 | - |
|
587 | - /** |
|
588 | - * Check if file is small enough to be imported. |
|
589 | - * |
|
590 | - * @param string $path The path to the file. |
|
591 | - * |
|
592 | - * @return bool |
|
593 | - */ |
|
594 | - protected function canImportBySize($path) |
|
595 | - { |
|
596 | - return ($size = @filesize($path)) && $size <= $this->maxImportSize * 1024; |
|
597 | - } |
|
435 | + ); |
|
436 | + |
|
437 | + // find all relative urls in css |
|
438 | + $matches = array(); |
|
439 | + foreach ($relativeRegexes as $relativeRegex) { |
|
440 | + if (preg_match_all($relativeRegex, $content, $regexMatches, PREG_SET_ORDER)) { |
|
441 | + $matches = array_merge($matches, $regexMatches); |
|
442 | + } |
|
443 | + } |
|
444 | + |
|
445 | + $search = array(); |
|
446 | + $replace = array(); |
|
447 | + |
|
448 | + // loop all urls |
|
449 | + foreach ($matches as $match) { |
|
450 | + // determine if it's a url() or an @import match |
|
451 | + $type = (strpos($match[0], '@import') === 0 ? 'import' : 'url'); |
|
452 | + |
|
453 | + // attempting to interpret GET-params makes no sense, so let's discard them for awhile |
|
454 | + $params = strrchr($match['path'], '?'); |
|
455 | + $url = $params ? substr($match['path'], 0, -strlen($params)) : $match['path']; |
|
456 | + |
|
457 | + // fix relative url |
|
458 | + $url = $converter->convert($url); |
|
459 | + |
|
460 | + // now that the path has been converted, re-apply GET-params |
|
461 | + $url .= $params; |
|
462 | + |
|
463 | + // build replacement |
|
464 | + $search[] = $match[0]; |
|
465 | + if ($type == 'url') { |
|
466 | + $replace[] = 'url('.$url.')'; |
|
467 | + } elseif ($type == 'import') { |
|
468 | + $replace[] = '@import "'.$url.'"'; |
|
469 | + } |
|
470 | + } |
|
471 | + |
|
472 | + // replace urls |
|
473 | + $content = str_replace($search, $replace, $content); |
|
474 | + |
|
475 | + return $content; |
|
476 | + } |
|
477 | + |
|
478 | + /** |
|
479 | + * Shorthand hex color codes. |
|
480 | + * #FF0000 -> #F00. |
|
481 | + * |
|
482 | + * @param string $content The CSS content to shorten the hex color codes for. |
|
483 | + * |
|
484 | + * @return string |
|
485 | + */ |
|
486 | + protected function shortenHex($content) |
|
487 | + { |
|
488 | + $content = preg_replace('/(?<![\'"])#([0-9a-z])\\1([0-9a-z])\\2([0-9a-z])\\3(?![\'"])/i', '#$1$2$3', $content); |
|
489 | + |
|
490 | + return $content; |
|
491 | + } |
|
492 | + |
|
493 | + /** |
|
494 | + * Shorthand 0 values to plain 0, instead of e.g. -0em. |
|
495 | + * |
|
496 | + * @param string $content The CSS content to shorten the zero values for. |
|
497 | + * |
|
498 | + * @return string |
|
499 | + */ |
|
500 | + protected function shortenZeroes($content) |
|
501 | + { |
|
502 | + // reusable bits of code throughout these regexes: |
|
503 | + // before & after are used to make sure we don't match lose unintended |
|
504 | + // 0-like values (e.g. in #000, or in http://url/1.0) |
|
505 | + // units can be stripped from 0 values, or used to recognize non 0 |
|
506 | + // values (where wa may be able to strip a .0 suffix) |
|
507 | + $before = '(?<=[:(, ])'; |
|
508 | + $after = '(?=[ ,);}])'; |
|
509 | + $units = '(em|ex|%|px|cm|mm|in|pt|pc|ch|rem|vh|vw|vmin|vmax|vm)'; |
|
510 | + |
|
511 | + // strip units after zeroes (0px -> 0) |
|
512 | + // NOTE: it should be safe to remove all units for a 0 value, but in |
|
513 | + // practice, Webkit (especially Safari) seems to stumble over at least |
|
514 | + // 0%, potentially other units as well. Only stripping 'px' for now. |
|
515 | + // @see https://github.com/matthiasmullie/minify/issues/60 |
|
516 | + $content = preg_replace('/'.$before.'(-?0*(\.0+)?)(?<=0)px'.$after.'/', '\\1', $content); |
|
517 | + |
|
518 | + // strip 0-digits (.0 -> 0) |
|
519 | + $content = preg_replace('/'.$before.'\.0+'.$units.'?'.$after.'/', '0\\1', $content); |
|
520 | + // strip trailing 0: 50.10 -> 50.1, 50.10px -> 50.1px |
|
521 | + $content = preg_replace('/'.$before.'(-?[0-9]+\.[0-9]+)0+'.$units.'?'.$after.'/', '\\1\\2', $content); |
|
522 | + // strip trailing 0: 50.00 -> 50, 50.00px -> 50px |
|
523 | + $content = preg_replace('/'.$before.'(-?[0-9]+)\.0+'.$units.'?'.$after.'/', '\\1\\2', $content); |
|
524 | + // strip leading 0: 0.1 -> .1, 01.1 -> 1.1 |
|
525 | + $content = preg_replace('/'.$before.'(-?)0+([0-9]*\.[0-9]+)'.$units.'?'.$after.'/', '\\1\\2\\3', $content); |
|
526 | + |
|
527 | + // strip negative zeroes (-0 -> 0) & truncate zeroes (00 -> 0) |
|
528 | + $content = preg_replace('/'.$before.'-?0+'.$units.'?'.$after.'/', '0\\1', $content); |
|
529 | + |
|
530 | + return $content; |
|
531 | + } |
|
532 | + |
|
533 | + /** |
|
534 | + * Strip comments from source code. |
|
535 | + * |
|
536 | + * @param string $content |
|
537 | + * |
|
538 | + * @return string |
|
539 | + */ |
|
540 | + protected function stripEmptyTags($content) |
|
541 | + { |
|
542 | + return preg_replace('/(^|\})[^\{\}]+\{\s*\}/', '\\1', $content); |
|
543 | + } |
|
544 | + |
|
545 | + /** |
|
546 | + * Strip comments from source code. |
|
547 | + */ |
|
548 | + protected function stripComments() |
|
549 | + { |
|
550 | + $this->registerPattern('/\/\*.*?\*\//s', ''); |
|
551 | + } |
|
552 | + |
|
553 | + /** |
|
554 | + * Strip whitespace. |
|
555 | + * |
|
556 | + * @param string $content The CSS content to strip the whitespace for. |
|
557 | + * |
|
558 | + * @return string |
|
559 | + */ |
|
560 | + protected function stripWhitespace($content) |
|
561 | + { |
|
562 | + // remove leading & trailing whitespace |
|
563 | + $content = preg_replace('/^\s*/m', '', $content); |
|
564 | + $content = preg_replace('/\s*$/m', '', $content); |
|
565 | + |
|
566 | + // replace newlines with a single space |
|
567 | + $content = preg_replace('/\s+/', ' ', $content); |
|
568 | + |
|
569 | + // remove whitespace around meta characters |
|
570 | + // inspired by stackoverflow.com/questions/15195750/minify-compress-css-with-regex |
|
571 | + $content = preg_replace('/\s*([\*$~^|]?+=|[{};,>~]|!important\b)\s*/', '$1', $content); |
|
572 | + $content = preg_replace('/([\[(:])\s+/', '$1', $content); |
|
573 | + $content = preg_replace('/\s+([\]\)])/', '$1', $content); |
|
574 | + $content = preg_replace('/\s+(:)(?![^\}]*\{)/', '$1', $content); |
|
575 | + |
|
576 | + // whitespace around + and - can only be stripped in selectors, like |
|
577 | + // :nth-child(3+2n), not in things like calc(3px + 2px) or shorthands |
|
578 | + // like 3px -2px |
|
579 | + $content = preg_replace('/\s*([+-])\s*(?=[^}]*{)/', '$1', $content); |
|
580 | + |
|
581 | + // remove semicolon/whitespace followed by closing bracket |
|
582 | + $content = str_replace(';}', '}', $content); |
|
583 | + |
|
584 | + return trim($content); |
|
585 | + } |
|
586 | + |
|
587 | + /** |
|
588 | + * Check if file is small enough to be imported. |
|
589 | + * |
|
590 | + * @param string $path The path to the file. |
|
591 | + * |
|
592 | + * @return bool |
|
593 | + */ |
|
594 | + protected function canImportBySize($path) |
|
595 | + { |
|
596 | + return ($size = @filesize($path)) && $size <= $this->maxImportSize * 1024; |
|
597 | + } |
|
598 | 598 | } |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | } |
84 | 84 | |
85 | 85 | // add to top |
86 | - $content = implode('', $matches[0]).$content; |
|
86 | + $content = implode('', $matches[0]) . $content; |
|
87 | 87 | }; |
88 | 88 | |
89 | 89 | return $content; |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | // loop the matches |
209 | 209 | foreach ($matches as $match) { |
210 | 210 | // get the path for the file that will be imported |
211 | - $importPath = dirname($source).'/'.$match['path']; |
|
211 | + $importPath = dirname($source) . '/' . $match['path']; |
|
212 | 212 | |
213 | 213 | // only replace the import with the content if we can grab the |
214 | 214 | // content of the file |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | // check if current file was not imported previously in the same |
217 | 217 | // import chain. |
218 | 218 | if (in_array($importPath, $parents)) { |
219 | - throw new FileImportException('Failed to import file "'.$importPath.'": circular reference detected.'); |
|
219 | + throw new FileImportException('Failed to import file "' . $importPath . '": circular reference detected.'); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | // grab referenced file & minify it (which may include importing |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | |
227 | 227 | // check if this is only valid for certain media |
228 | 228 | if (!empty($match['media'])) { |
229 | - $importContent = '@media '.$match['media'].'{'.$importContent.'}'; |
|
229 | + $importContent = '@media ' . $match['media'] . '{' . $importContent . '}'; |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | // add to replacement array |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | protected function importFiles($source, $content) |
256 | 256 | { |
257 | 257 | $extensions = array_keys($this->importExtensions); |
258 | - $regex = '/url\((["\']?)((?!["\']?data:).*?\.('.implode('|', $extensions).'))\\1\)/i'; |
|
258 | + $regex = '/url\((["\']?)((?!["\']?data:).*?\.(' . implode('|', $extensions) . '))\\1\)/i'; |
|
259 | 259 | if ($extensions && preg_match_all($regex, $content, $matches, PREG_SET_ORDER)) { |
260 | 260 | $search = array(); |
261 | 261 | $replace = array(); |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | foreach ($matches as $match) { |
265 | 265 | // get the path for the file that will be imported |
266 | 266 | $path = $match[2]; |
267 | - $path = dirname($source).'/'.$path; |
|
267 | + $path = dirname($source) . '/' . $path; |
|
268 | 268 | $extension = $match[3]; |
269 | 269 | |
270 | 270 | // only replace the import with the content if we're able to get |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | |
277 | 277 | // build replacement |
278 | 278 | $search[] = $match[0]; |
279 | - $replace[] = 'url('.$this->importExtensions[$extension].';base64,'.$importContent.')'; |
|
279 | + $replace[] = 'url(' . $this->importExtensions[$extension] . ';base64,' . $importContent . ')'; |
|
280 | 280 | } |
281 | 281 | } |
282 | 282 | |
@@ -463,9 +463,9 @@ discard block |
||
463 | 463 | // build replacement |
464 | 464 | $search[] = $match[0]; |
465 | 465 | if ($type == 'url') { |
466 | - $replace[] = 'url('.$url.')'; |
|
466 | + $replace[] = 'url(' . $url . ')'; |
|
467 | 467 | } elseif ($type == 'import') { |
468 | - $replace[] = '@import "'.$url.'"'; |
|
468 | + $replace[] = '@import "' . $url . '"'; |
|
469 | 469 | } |
470 | 470 | } |
471 | 471 | |
@@ -513,19 +513,19 @@ discard block |
||
513 | 513 | // practice, Webkit (especially Safari) seems to stumble over at least |
514 | 514 | // 0%, potentially other units as well. Only stripping 'px' for now. |
515 | 515 | // @see https://github.com/matthiasmullie/minify/issues/60 |
516 | - $content = preg_replace('/'.$before.'(-?0*(\.0+)?)(?<=0)px'.$after.'/', '\\1', $content); |
|
516 | + $content = preg_replace('/' . $before . '(-?0*(\.0+)?)(?<=0)px' . $after . '/', '\\1', $content); |
|
517 | 517 | |
518 | 518 | // strip 0-digits (.0 -> 0) |
519 | - $content = preg_replace('/'.$before.'\.0+'.$units.'?'.$after.'/', '0\\1', $content); |
|
519 | + $content = preg_replace('/' . $before . '\.0+' . $units . '?' . $after . '/', '0\\1', $content); |
|
520 | 520 | // strip trailing 0: 50.10 -> 50.1, 50.10px -> 50.1px |
521 | - $content = preg_replace('/'.$before.'(-?[0-9]+\.[0-9]+)0+'.$units.'?'.$after.'/', '\\1\\2', $content); |
|
521 | + $content = preg_replace('/' . $before . '(-?[0-9]+\.[0-9]+)0+' . $units . '?' . $after . '/', '\\1\\2', $content); |
|
522 | 522 | // strip trailing 0: 50.00 -> 50, 50.00px -> 50px |
523 | - $content = preg_replace('/'.$before.'(-?[0-9]+)\.0+'.$units.'?'.$after.'/', '\\1\\2', $content); |
|
523 | + $content = preg_replace('/' . $before . '(-?[0-9]+)\.0+' . $units . '?' . $after . '/', '\\1\\2', $content); |
|
524 | 524 | // strip leading 0: 0.1 -> .1, 01.1 -> 1.1 |
525 | - $content = preg_replace('/'.$before.'(-?)0+([0-9]*\.[0-9]+)'.$units.'?'.$after.'/', '\\1\\2\\3', $content); |
|
525 | + $content = preg_replace('/' . $before . '(-?)0+([0-9]*\.[0-9]+)' . $units . '?' . $after . '/', '\\1\\2\\3', $content); |
|
526 | 526 | |
527 | 527 | // strip negative zeroes (-0 -> 0) & truncate zeroes (00 -> 0) |
528 | - $content = preg_replace('/'.$before.'-?0+'.$units.'?'.$after.'/', '0\\1', $content); |
|
528 | + $content = preg_replace('/' . $before . '-?0+' . $units . '?' . $after . '/', '0\\1', $content); |
|
529 | 529 | |
530 | 530 | return $content; |
531 | 531 | } |
@@ -18,178 +18,178 @@ |
||
18 | 18 | */ |
19 | 19 | class Converter |
20 | 20 | { |
21 | - /** |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $from; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - protected $to; |
|
30 | - |
|
31 | - /** |
|
32 | - * @param string $from The original base path (directory, not file!) |
|
33 | - * @param string $to The new base path (directory, not file!) |
|
34 | - */ |
|
35 | - public function __construct($from, $to) |
|
36 | - { |
|
37 | - $shared = $this->shared($from, $to); |
|
38 | - if ($shared === '') { |
|
39 | - // when both paths have nothing in common, one of them is probably |
|
40 | - // absolute while the other is relative |
|
41 | - $cwd = getcwd(); |
|
42 | - $from = strpos($from, $cwd) === 0 ? $from : $cwd.'/'.$from; |
|
43 | - $to = strpos($to, $cwd) === 0 ? $to : $cwd.'/'.$to; |
|
44 | - |
|
45 | - // or traveling the tree via `..` |
|
46 | - // attempt to resolve path, or assume it's fine if it doesn't exist |
|
47 | - $from = realpath($from) ?: $from; |
|
48 | - $to = realpath($to) ?: $to; |
|
49 | - } |
|
50 | - |
|
51 | - $from = $this->normalize($from); |
|
52 | - $to = $this->normalize($to); |
|
53 | - |
|
54 | - $from = $this->dirname($from); |
|
55 | - $to = $this->dirname($to); |
|
56 | - |
|
57 | - $this->from = $from; |
|
58 | - $this->to = $to; |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Normalize path. |
|
63 | - * |
|
64 | - * @param string $path |
|
65 | - * |
|
66 | - * @return string |
|
67 | - */ |
|
68 | - protected function normalize($path) |
|
69 | - { |
|
70 | - // deal with different operating systems' directory structure |
|
71 | - $path = rtrim(str_replace(DIRECTORY_SEPARATOR, '/', $path), '/'); |
|
72 | - |
|
73 | - /* |
|
21 | + /** |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $from; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + protected $to; |
|
30 | + |
|
31 | + /** |
|
32 | + * @param string $from The original base path (directory, not file!) |
|
33 | + * @param string $to The new base path (directory, not file!) |
|
34 | + */ |
|
35 | + public function __construct($from, $to) |
|
36 | + { |
|
37 | + $shared = $this->shared($from, $to); |
|
38 | + if ($shared === '') { |
|
39 | + // when both paths have nothing in common, one of them is probably |
|
40 | + // absolute while the other is relative |
|
41 | + $cwd = getcwd(); |
|
42 | + $from = strpos($from, $cwd) === 0 ? $from : $cwd.'/'.$from; |
|
43 | + $to = strpos($to, $cwd) === 0 ? $to : $cwd.'/'.$to; |
|
44 | + |
|
45 | + // or traveling the tree via `..` |
|
46 | + // attempt to resolve path, or assume it's fine if it doesn't exist |
|
47 | + $from = realpath($from) ?: $from; |
|
48 | + $to = realpath($to) ?: $to; |
|
49 | + } |
|
50 | + |
|
51 | + $from = $this->normalize($from); |
|
52 | + $to = $this->normalize($to); |
|
53 | + |
|
54 | + $from = $this->dirname($from); |
|
55 | + $to = $this->dirname($to); |
|
56 | + |
|
57 | + $this->from = $from; |
|
58 | + $this->to = $to; |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Normalize path. |
|
63 | + * |
|
64 | + * @param string $path |
|
65 | + * |
|
66 | + * @return string |
|
67 | + */ |
|
68 | + protected function normalize($path) |
|
69 | + { |
|
70 | + // deal with different operating systems' directory structure |
|
71 | + $path = rtrim(str_replace(DIRECTORY_SEPARATOR, '/', $path), '/'); |
|
72 | + |
|
73 | + /* |
|
74 | 74 | * Example: |
75 | 75 | * /home/forkcms/frontend/cache/compiled_templates/../../core/layout/css/../images/img.gif |
76 | 76 | * to |
77 | 77 | * /home/forkcms/frontend/core/layout/images/img.gif |
78 | 78 | */ |
79 | - do { |
|
80 | - $path = preg_replace('/[^\/]+(?<!\.\.)\/\.\.\//', '', $path, -1, $count); |
|
81 | - } while ($count); |
|
82 | - |
|
83 | - return $path; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Figure out the shared path of 2 locations. |
|
88 | - * |
|
89 | - * Example: |
|
90 | - * /home/forkcms/frontend/core/layout/images/img.gif |
|
91 | - * and |
|
92 | - * /home/forkcms/frontend/cache/minified_css |
|
93 | - * share |
|
94 | - * /home/forkcms/frontend |
|
95 | - * |
|
96 | - * @param string $path1 |
|
97 | - * @param string $path2 |
|
98 | - * |
|
99 | - * @return string |
|
100 | - */ |
|
101 | - protected function shared($path1, $path2) |
|
102 | - { |
|
103 | - // $path could theoretically be empty (e.g. no path is given), in which |
|
104 | - // case it shouldn't expand to array(''), which would compare to one's |
|
105 | - // root / |
|
106 | - $path1 = $path1 ? explode('/', $path1) : array(); |
|
107 | - $path2 = $path2 ? explode('/', $path2) : array(); |
|
108 | - |
|
109 | - $shared = array(); |
|
110 | - |
|
111 | - // compare paths & strip identical ancestors |
|
112 | - foreach ($path1 as $i => $chunk) { |
|
113 | - if (isset($path2[$i]) && $path1[$i] == $path2[$i]) { |
|
114 | - $shared[] = $chunk; |
|
115 | - } else { |
|
116 | - break; |
|
117 | - } |
|
118 | - } |
|
119 | - |
|
120 | - return implode('/', $shared); |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Convert paths relative from 1 file to another. |
|
125 | - * |
|
126 | - * E.g. |
|
127 | - * ../images/img.gif relative to /home/forkcms/frontend/core/layout/css |
|
128 | - * should become: |
|
129 | - * ../../core/layout/images/img.gif relative to |
|
130 | - * /home/forkcms/frontend/cache/minified_css |
|
131 | - * |
|
132 | - * @param string $path The relative path that needs to be converted. |
|
133 | - * |
|
134 | - * @return string The new relative path. |
|
135 | - */ |
|
136 | - public function convert($path) |
|
137 | - { |
|
138 | - // quit early if conversion makes no sense |
|
139 | - if ($this->from === $this->to) { |
|
140 | - return $path; |
|
141 | - } |
|
142 | - |
|
143 | - $path = $this->normalize($path); |
|
144 | - // if we're not dealing with a relative path, just return absolute |
|
145 | - if (strpos($path, '/') === 0) { |
|
146 | - return $path; |
|
147 | - } |
|
148 | - |
|
149 | - // normalize paths |
|
150 | - $path = $this->normalize($this->from.'/'.$path); |
|
151 | - |
|
152 | - // strip shared ancestor paths |
|
153 | - $shared = $this->shared($path, $this->to); |
|
154 | - $path = mb_substr($path, mb_strlen($shared)); |
|
155 | - $to = mb_substr($this->to, mb_strlen($shared)); |
|
156 | - |
|
157 | - // add .. for every directory that needs to be traversed to new path |
|
158 | - $to = str_repeat('../', mb_substr_count($to, '/')); |
|
159 | - |
|
160 | - return $to.ltrim($path, '/'); |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Attempt to get the directory name from a path. |
|
165 | - * |
|
166 | - * @param string $path |
|
167 | - * |
|
168 | - * @return string |
|
169 | - */ |
|
170 | - public function dirname($path) |
|
171 | - { |
|
172 | - if (is_file($path)) { |
|
173 | - return dirname($path); |
|
174 | - } |
|
175 | - |
|
176 | - if (is_dir($path)) { |
|
177 | - return rtrim($path, '/'); |
|
178 | - } |
|
179 | - |
|
180 | - // no known file/dir, start making assumptions |
|
181 | - |
|
182 | - // ends in / = dir |
|
183 | - if (mb_substr($path, -1) === '/') { |
|
184 | - return rtrim($path, '/'); |
|
185 | - } |
|
186 | - |
|
187 | - // has a dot in the name, likely a file |
|
188 | - if (preg_match('/.*\..*$/', basename($path)) !== 0) { |
|
189 | - return dirname($path); |
|
190 | - } |
|
191 | - |
|
192 | - // you're on your own here! |
|
193 | - return $path; |
|
194 | - } |
|
79 | + do { |
|
80 | + $path = preg_replace('/[^\/]+(?<!\.\.)\/\.\.\//', '', $path, -1, $count); |
|
81 | + } while ($count); |
|
82 | + |
|
83 | + return $path; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Figure out the shared path of 2 locations. |
|
88 | + * |
|
89 | + * Example: |
|
90 | + * /home/forkcms/frontend/core/layout/images/img.gif |
|
91 | + * and |
|
92 | + * /home/forkcms/frontend/cache/minified_css |
|
93 | + * share |
|
94 | + * /home/forkcms/frontend |
|
95 | + * |
|
96 | + * @param string $path1 |
|
97 | + * @param string $path2 |
|
98 | + * |
|
99 | + * @return string |
|
100 | + */ |
|
101 | + protected function shared($path1, $path2) |
|
102 | + { |
|
103 | + // $path could theoretically be empty (e.g. no path is given), in which |
|
104 | + // case it shouldn't expand to array(''), which would compare to one's |
|
105 | + // root / |
|
106 | + $path1 = $path1 ? explode('/', $path1) : array(); |
|
107 | + $path2 = $path2 ? explode('/', $path2) : array(); |
|
108 | + |
|
109 | + $shared = array(); |
|
110 | + |
|
111 | + // compare paths & strip identical ancestors |
|
112 | + foreach ($path1 as $i => $chunk) { |
|
113 | + if (isset($path2[$i]) && $path1[$i] == $path2[$i]) { |
|
114 | + $shared[] = $chunk; |
|
115 | + } else { |
|
116 | + break; |
|
117 | + } |
|
118 | + } |
|
119 | + |
|
120 | + return implode('/', $shared); |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Convert paths relative from 1 file to another. |
|
125 | + * |
|
126 | + * E.g. |
|
127 | + * ../images/img.gif relative to /home/forkcms/frontend/core/layout/css |
|
128 | + * should become: |
|
129 | + * ../../core/layout/images/img.gif relative to |
|
130 | + * /home/forkcms/frontend/cache/minified_css |
|
131 | + * |
|
132 | + * @param string $path The relative path that needs to be converted. |
|
133 | + * |
|
134 | + * @return string The new relative path. |
|
135 | + */ |
|
136 | + public function convert($path) |
|
137 | + { |
|
138 | + // quit early if conversion makes no sense |
|
139 | + if ($this->from === $this->to) { |
|
140 | + return $path; |
|
141 | + } |
|
142 | + |
|
143 | + $path = $this->normalize($path); |
|
144 | + // if we're not dealing with a relative path, just return absolute |
|
145 | + if (strpos($path, '/') === 0) { |
|
146 | + return $path; |
|
147 | + } |
|
148 | + |
|
149 | + // normalize paths |
|
150 | + $path = $this->normalize($this->from.'/'.$path); |
|
151 | + |
|
152 | + // strip shared ancestor paths |
|
153 | + $shared = $this->shared($path, $this->to); |
|
154 | + $path = mb_substr($path, mb_strlen($shared)); |
|
155 | + $to = mb_substr($this->to, mb_strlen($shared)); |
|
156 | + |
|
157 | + // add .. for every directory that needs to be traversed to new path |
|
158 | + $to = str_repeat('../', mb_substr_count($to, '/')); |
|
159 | + |
|
160 | + return $to.ltrim($path, '/'); |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Attempt to get the directory name from a path. |
|
165 | + * |
|
166 | + * @param string $path |
|
167 | + * |
|
168 | + * @return string |
|
169 | + */ |
|
170 | + public function dirname($path) |
|
171 | + { |
|
172 | + if (is_file($path)) { |
|
173 | + return dirname($path); |
|
174 | + } |
|
175 | + |
|
176 | + if (is_dir($path)) { |
|
177 | + return rtrim($path, '/'); |
|
178 | + } |
|
179 | + |
|
180 | + // no known file/dir, start making assumptions |
|
181 | + |
|
182 | + // ends in / = dir |
|
183 | + if (mb_substr($path, -1) === '/') { |
|
184 | + return rtrim($path, '/'); |
|
185 | + } |
|
186 | + |
|
187 | + // has a dot in the name, likely a file |
|
188 | + if (preg_match('/.*\..*$/', basename($path)) !== 0) { |
|
189 | + return dirname($path); |
|
190 | + } |
|
191 | + |
|
192 | + // you're on your own here! |
|
193 | + return $path; |
|
194 | + } |
|
195 | 195 | } |
@@ -39,8 +39,8 @@ discard block |
||
39 | 39 | // when both paths have nothing in common, one of them is probably |
40 | 40 | // absolute while the other is relative |
41 | 41 | $cwd = getcwd(); |
42 | - $from = strpos($from, $cwd) === 0 ? $from : $cwd.'/'.$from; |
|
43 | - $to = strpos($to, $cwd) === 0 ? $to : $cwd.'/'.$to; |
|
42 | + $from = strpos($from, $cwd) === 0 ? $from : $cwd . '/' . $from; |
|
43 | + $to = strpos($to, $cwd) === 0 ? $to : $cwd . '/' . $to; |
|
44 | 44 | |
45 | 45 | // or traveling the tree via `..` |
46 | 46 | // attempt to resolve path, or assume it's fine if it doesn't exist |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | } |
148 | 148 | |
149 | 149 | // normalize paths |
150 | - $path = $this->normalize($this->from.'/'.$path); |
|
150 | + $path = $this->normalize($this->from . '/' . $path); |
|
151 | 151 | |
152 | 152 | // strip shared ancestor paths |
153 | 153 | $shared = $this->shared($path, $this->to); |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | // add .. for every directory that needs to be traversed to new path |
158 | 158 | $to = str_repeat('../', mb_substr_count($to, '/')); |
159 | 159 | |
160 | - return $to.ltrim($path, '/'); |
|
160 | + return $to . ltrim($path, '/'); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -14,122 +14,122 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class JS extends Minify |
16 | 16 | { |
17 | - /** |
|
18 | - * Var-matching regex based on http://stackoverflow.com/a/9337047/802993. |
|
19 | - * |
|
20 | - * Note that regular expressions using that bit must have the PCRE_UTF8 |
|
21 | - * pattern modifier (/u) set. |
|
22 | - * |
|
23 | - * @var string |
|
24 | - */ |
|
25 | - const REGEX_VARIABLE = '\b[$A-Z\_a-z\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\x{02c1}\x{02c6}-\x{02d1}\x{02e0}-\x{02e4}\x{02ec}\x{02ee}\x{0370}-\x{0374}\x{0376}\x{0377}\x{037a}-\x{037d}\x{0386}\x{0388}-\x{038a}\x{038c}\x{038e}-\x{03a1}\x{03a3}-\x{03f5}\x{03f7}-\x{0481}\x{048a}-\x{0527}\x{0531}-\x{0556}\x{0559}\x{0561}-\x{0587}\x{05d0}-\x{05ea}\x{05f0}-\x{05f2}\x{0620}-\x{064a}\x{066e}\x{066f}\x{0671}-\x{06d3}\x{06d5}\x{06e5}\x{06e6}\x{06ee}\x{06ef}\x{06fa}-\x{06fc}\x{06ff}\x{0710}\x{0712}-\x{072f}\x{074d}-\x{07a5}\x{07b1}\x{07ca}-\x{07ea}\x{07f4}\x{07f5}\x{07fa}\x{0800}-\x{0815}\x{081a}\x{0824}\x{0828}\x{0840}-\x{0858}\x{08a0}\x{08a2}-\x{08ac}\x{0904}-\x{0939}\x{093d}\x{0950}\x{0958}-\x{0961}\x{0971}-\x{0977}\x{0979}-\x{097f}\x{0985}-\x{098c}\x{098f}\x{0990}\x{0993}-\x{09a8}\x{09aa}-\x{09b0}\x{09b2}\x{09b6}-\x{09b9}\x{09bd}\x{09ce}\x{09dc}\x{09dd}\x{09df}-\x{09e1}\x{09f0}\x{09f1}\x{0a05}-\x{0a0a}\x{0a0f}\x{0a10}\x{0a13}-\x{0a28}\x{0a2a}-\x{0a30}\x{0a32}\x{0a33}\x{0a35}\x{0a36}\x{0a38}\x{0a39}\x{0a59}-\x{0a5c}\x{0a5e}\x{0a72}-\x{0a74}\x{0a85}-\x{0a8d}\x{0a8f}-\x{0a91}\x{0a93}-\x{0aa8}\x{0aaa}-\x{0ab0}\x{0ab2}\x{0ab3}\x{0ab5}-\x{0ab9}\x{0abd}\x{0ad0}\x{0ae0}\x{0ae1}\x{0b05}-\x{0b0c}\x{0b0f}\x{0b10}\x{0b13}-\x{0b28}\x{0b2a}-\x{0b30}\x{0b32}\x{0b33}\x{0b35}-\x{0b39}\x{0b3d}\x{0b5c}\x{0b5d}\x{0b5f}-\x{0b61}\x{0b71}\x{0b83}\x{0b85}-\x{0b8a}\x{0b8e}-\x{0b90}\x{0b92}-\x{0b95}\x{0b99}\x{0b9a}\x{0b9c}\x{0b9e}\x{0b9f}\x{0ba3}\x{0ba4}\x{0ba8}-\x{0baa}\x{0bae}-\x{0bb9}\x{0bd0}\x{0c05}-\x{0c0c}\x{0c0e}-\x{0c10}\x{0c12}-\x{0c28}\x{0c2a}-\x{0c33}\x{0c35}-\x{0c39}\x{0c3d}\x{0c58}\x{0c59}\x{0c60}\x{0c61}\x{0c85}-\x{0c8c}\x{0c8e}-\x{0c90}\x{0c92}-\x{0ca8}\x{0caa}-\x{0cb3}\x{0cb5}-\x{0cb9}\x{0cbd}\x{0cde}\x{0ce0}\x{0ce1}\x{0cf1}\x{0cf2}\x{0d05}-\x{0d0c}\x{0d0e}-\x{0d10}\x{0d12}-\x{0d3a}\x{0d3d}\x{0d4e}\x{0d60}\x{0d61}\x{0d7a}-\x{0d7f}\x{0d85}-\x{0d96}\x{0d9a}-\x{0db1}\x{0db3}-\x{0dbb}\x{0dbd}\x{0dc0}-\x{0dc6}\x{0e01}-\x{0e30}\x{0e32}\x{0e33}\x{0e40}-\x{0e46}\x{0e81}\x{0e82}\x{0e84}\x{0e87}\x{0e88}\x{0e8a}\x{0e8d}\x{0e94}-\x{0e97}\x{0e99}-\x{0e9f}\x{0ea1}-\x{0ea3}\x{0ea5}\x{0ea7}\x{0eaa}\x{0eab}\x{0ead}-\x{0eb0}\x{0eb2}\x{0eb3}\x{0ebd}\x{0ec0}-\x{0ec4}\x{0ec6}\x{0edc}-\x{0edf}\x{0f00}\x{0f40}-\x{0f47}\x{0f49}-\x{0f6c}\x{0f88}-\x{0f8c}\x{1000}-\x{102a}\x{103f}\x{1050}-\x{1055}\x{105a}-\x{105d}\x{1061}\x{1065}\x{1066}\x{106e}-\x{1070}\x{1075}-\x{1081}\x{108e}\x{10a0}-\x{10c5}\x{10c7}\x{10cd}\x{10d0}-\x{10fa}\x{10fc}-\x{1248}\x{124a}-\x{124d}\x{1250}-\x{1256}\x{1258}\x{125a}-\x{125d}\x{1260}-\x{1288}\x{128a}-\x{128d}\x{1290}-\x{12b0}\x{12b2}-\x{12b5}\x{12b8}-\x{12be}\x{12c0}\x{12c2}-\x{12c5}\x{12c8}-\x{12d6}\x{12d8}-\x{1310}\x{1312}-\x{1315}\x{1318}-\x{135a}\x{1380}-\x{138f}\x{13a0}-\x{13f4}\x{1401}-\x{166c}\x{166f}-\x{167f}\x{1681}-\x{169a}\x{16a0}-\x{16ea}\x{16ee}-\x{16f0}\x{1700}-\x{170c}\x{170e}-\x{1711}\x{1720}-\x{1731}\x{1740}-\x{1751}\x{1760}-\x{176c}\x{176e}-\x{1770}\x{1780}-\x{17b3}\x{17d7}\x{17dc}\x{1820}-\x{1877}\x{1880}-\x{18a8}\x{18aa}\x{18b0}-\x{18f5}\x{1900}-\x{191c}\x{1950}-\x{196d}\x{1970}-\x{1974}\x{1980}-\x{19ab}\x{19c1}-\x{19c7}\x{1a00}-\x{1a16}\x{1a20}-\x{1a54}\x{1aa7}\x{1b05}-\x{1b33}\x{1b45}-\x{1b4b}\x{1b83}-\x{1ba0}\x{1bae}\x{1baf}\x{1bba}-\x{1be5}\x{1c00}-\x{1c23}\x{1c4d}-\x{1c4f}\x{1c5a}-\x{1c7d}\x{1ce9}-\x{1cec}\x{1cee}-\x{1cf1}\x{1cf5}\x{1cf6}\x{1d00}-\x{1dbf}\x{1e00}-\x{1f15}\x{1f18}-\x{1f1d}\x{1f20}-\x{1f45}\x{1f48}-\x{1f4d}\x{1f50}-\x{1f57}\x{1f59}\x{1f5b}\x{1f5d}\x{1f5f}-\x{1f7d}\x{1f80}-\x{1fb4}\x{1fb6}-\x{1fbc}\x{1fbe}\x{1fc2}-\x{1fc4}\x{1fc6}-\x{1fcc}\x{1fd0}-\x{1fd3}\x{1fd6}-\x{1fdb}\x{1fe0}-\x{1fec}\x{1ff2}-\x{1ff4}\x{1ff6}-\x{1ffc}\x{2071}\x{207f}\x{2090}-\x{209c}\x{2102}\x{2107}\x{210a}-\x{2113}\x{2115}\x{2119}-\x{211d}\x{2124}\x{2126}\x{2128}\x{212a}-\x{212d}\x{212f}-\x{2139}\x{213c}-\x{213f}\x{2145}-\x{2149}\x{214e}\x{2160}-\x{2188}\x{2c00}-\x{2c2e}\x{2c30}-\x{2c5e}\x{2c60}-\x{2ce4}\x{2ceb}-\x{2cee}\x{2cf2}\x{2cf3}\x{2d00}-\x{2d25}\x{2d27}\x{2d2d}\x{2d30}-\x{2d67}\x{2d6f}\x{2d80}-\x{2d96}\x{2da0}-\x{2da6}\x{2da8}-\x{2dae}\x{2db0}-\x{2db6}\x{2db8}-\x{2dbe}\x{2dc0}-\x{2dc6}\x{2dc8}-\x{2dce}\x{2dd0}-\x{2dd6}\x{2dd8}-\x{2dde}\x{2e2f}\x{3005}-\x{3007}\x{3021}-\x{3029}\x{3031}-\x{3035}\x{3038}-\x{303c}\x{3041}-\x{3096}\x{309d}-\x{309f}\x{30a1}-\x{30fa}\x{30fc}-\x{30ff}\x{3105}-\x{312d}\x{3131}-\x{318e}\x{31a0}-\x{31ba}\x{31f0}-\x{31ff}\x{3400}-\x{4db5}\x{4e00}-\x{9fcc}\x{a000}-\x{a48c}\x{a4d0}-\x{a4fd}\x{a500}-\x{a60c}\x{a610}-\x{a61f}\x{a62a}\x{a62b}\x{a640}-\x{a66e}\x{a67f}-\x{a697}\x{a6a0}-\x{a6ef}\x{a717}-\x{a71f}\x{a722}-\x{a788}\x{a78b}-\x{a78e}\x{a790}-\x{a793}\x{a7a0}-\x{a7aa}\x{a7f8}-\x{a801}\x{a803}-\x{a805}\x{a807}-\x{a80a}\x{a80c}-\x{a822}\x{a840}-\x{a873}\x{a882}-\x{a8b3}\x{a8f2}-\x{a8f7}\x{a8fb}\x{a90a}-\x{a925}\x{a930}-\x{a946}\x{a960}-\x{a97c}\x{a984}-\x{a9b2}\x{a9cf}\x{aa00}-\x{aa28}\x{aa40}-\x{aa42}\x{aa44}-\x{aa4b}\x{aa60}-\x{aa76}\x{aa7a}\x{aa80}-\x{aaaf}\x{aab1}\x{aab5}\x{aab6}\x{aab9}-\x{aabd}\x{aac0}\x{aac2}\x{aadb}-\x{aadd}\x{aae0}-\x{aaea}\x{aaf2}-\x{aaf4}\x{ab01}-\x{ab06}\x{ab09}-\x{ab0e}\x{ab11}-\x{ab16}\x{ab20}-\x{ab26}\x{ab28}-\x{ab2e}\x{abc0}-\x{abe2}\x{ac00}-\x{d7a3}\x{d7b0}-\x{d7c6}\x{d7cb}-\x{d7fb}\x{f900}-\x{fa6d}\x{fa70}-\x{fad9}\x{fb00}-\x{fb06}\x{fb13}-\x{fb17}\x{fb1d}\x{fb1f}-\x{fb28}\x{fb2a}-\x{fb36}\x{fb38}-\x{fb3c}\x{fb3e}\x{fb40}\x{fb41}\x{fb43}\x{fb44}\x{fb46}-\x{fbb1}\x{fbd3}-\x{fd3d}\x{fd50}-\x{fd8f}\x{fd92}-\x{fdc7}\x{fdf0}-\x{fdfb}\x{fe70}-\x{fe74}\x{fe76}-\x{fefc}\x{ff21}-\x{ff3a}\x{ff41}-\x{ff5a}\x{ff66}-\x{ffbe}\x{ffc2}-\x{ffc7}\x{ffca}-\x{ffcf}\x{ffd2}-\x{ffd7}\x{ffda}-\x{ffdc}][$A-Z\_a-z\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\x{02c1}\x{02c6}-\x{02d1}\x{02e0}-\x{02e4}\x{02ec}\x{02ee}\x{0370}-\x{0374}\x{0376}\x{0377}\x{037a}-\x{037d}\x{0386}\x{0388}-\x{038a}\x{038c}\x{038e}-\x{03a1}\x{03a3}-\x{03f5}\x{03f7}-\x{0481}\x{048a}-\x{0527}\x{0531}-\x{0556}\x{0559}\x{0561}-\x{0587}\x{05d0}-\x{05ea}\x{05f0}-\x{05f2}\x{0620}-\x{064a}\x{066e}\x{066f}\x{0671}-\x{06d3}\x{06d5}\x{06e5}\x{06e6}\x{06ee}\x{06ef}\x{06fa}-\x{06fc}\x{06ff}\x{0710}\x{0712}-\x{072f}\x{074d}-\x{07a5}\x{07b1}\x{07ca}-\x{07ea}\x{07f4}\x{07f5}\x{07fa}\x{0800}-\x{0815}\x{081a}\x{0824}\x{0828}\x{0840}-\x{0858}\x{08a0}\x{08a2}-\x{08ac}\x{0904}-\x{0939}\x{093d}\x{0950}\x{0958}-\x{0961}\x{0971}-\x{0977}\x{0979}-\x{097f}\x{0985}-\x{098c}\x{098f}\x{0990}\x{0993}-\x{09a8}\x{09aa}-\x{09b0}\x{09b2}\x{09b6}-\x{09b9}\x{09bd}\x{09ce}\x{09dc}\x{09dd}\x{09df}-\x{09e1}\x{09f0}\x{09f1}\x{0a05}-\x{0a0a}\x{0a0f}\x{0a10}\x{0a13}-\x{0a28}\x{0a2a}-\x{0a30}\x{0a32}\x{0a33}\x{0a35}\x{0a36}\x{0a38}\x{0a39}\x{0a59}-\x{0a5c}\x{0a5e}\x{0a72}-\x{0a74}\x{0a85}-\x{0a8d}\x{0a8f}-\x{0a91}\x{0a93}-\x{0aa8}\x{0aaa}-\x{0ab0}\x{0ab2}\x{0ab3}\x{0ab5}-\x{0ab9}\x{0abd}\x{0ad0}\x{0ae0}\x{0ae1}\x{0b05}-\x{0b0c}\x{0b0f}\x{0b10}\x{0b13}-\x{0b28}\x{0b2a}-\x{0b30}\x{0b32}\x{0b33}\x{0b35}-\x{0b39}\x{0b3d}\x{0b5c}\x{0b5d}\x{0b5f}-\x{0b61}\x{0b71}\x{0b83}\x{0b85}-\x{0b8a}\x{0b8e}-\x{0b90}\x{0b92}-\x{0b95}\x{0b99}\x{0b9a}\x{0b9c}\x{0b9e}\x{0b9f}\x{0ba3}\x{0ba4}\x{0ba8}-\x{0baa}\x{0bae}-\x{0bb9}\x{0bd0}\x{0c05}-\x{0c0c}\x{0c0e}-\x{0c10}\x{0c12}-\x{0c28}\x{0c2a}-\x{0c33}\x{0c35}-\x{0c39}\x{0c3d}\x{0c58}\x{0c59}\x{0c60}\x{0c61}\x{0c85}-\x{0c8c}\x{0c8e}-\x{0c90}\x{0c92}-\x{0ca8}\x{0caa}-\x{0cb3}\x{0cb5}-\x{0cb9}\x{0cbd}\x{0cde}\x{0ce0}\x{0ce1}\x{0cf1}\x{0cf2}\x{0d05}-\x{0d0c}\x{0d0e}-\x{0d10}\x{0d12}-\x{0d3a}\x{0d3d}\x{0d4e}\x{0d60}\x{0d61}\x{0d7a}-\x{0d7f}\x{0d85}-\x{0d96}\x{0d9a}-\x{0db1}\x{0db3}-\x{0dbb}\x{0dbd}\x{0dc0}-\x{0dc6}\x{0e01}-\x{0e30}\x{0e32}\x{0e33}\x{0e40}-\x{0e46}\x{0e81}\x{0e82}\x{0e84}\x{0e87}\x{0e88}\x{0e8a}\x{0e8d}\x{0e94}-\x{0e97}\x{0e99}-\x{0e9f}\x{0ea1}-\x{0ea3}\x{0ea5}\x{0ea7}\x{0eaa}\x{0eab}\x{0ead}-\x{0eb0}\x{0eb2}\x{0eb3}\x{0ebd}\x{0ec0}-\x{0ec4}\x{0ec6}\x{0edc}-\x{0edf}\x{0f00}\x{0f40}-\x{0f47}\x{0f49}-\x{0f6c}\x{0f88}-\x{0f8c}\x{1000}-\x{102a}\x{103f}\x{1050}-\x{1055}\x{105a}-\x{105d}\x{1061}\x{1065}\x{1066}\x{106e}-\x{1070}\x{1075}-\x{1081}\x{108e}\x{10a0}-\x{10c5}\x{10c7}\x{10cd}\x{10d0}-\x{10fa}\x{10fc}-\x{1248}\x{124a}-\x{124d}\x{1250}-\x{1256}\x{1258}\x{125a}-\x{125d}\x{1260}-\x{1288}\x{128a}-\x{128d}\x{1290}-\x{12b0}\x{12b2}-\x{12b5}\x{12b8}-\x{12be}\x{12c0}\x{12c2}-\x{12c5}\x{12c8}-\x{12d6}\x{12d8}-\x{1310}\x{1312}-\x{1315}\x{1318}-\x{135a}\x{1380}-\x{138f}\x{13a0}-\x{13f4}\x{1401}-\x{166c}\x{166f}-\x{167f}\x{1681}-\x{169a}\x{16a0}-\x{16ea}\x{16ee}-\x{16f0}\x{1700}-\x{170c}\x{170e}-\x{1711}\x{1720}-\x{1731}\x{1740}-\x{1751}\x{1760}-\x{176c}\x{176e}-\x{1770}\x{1780}-\x{17b3}\x{17d7}\x{17dc}\x{1820}-\x{1877}\x{1880}-\x{18a8}\x{18aa}\x{18b0}-\x{18f5}\x{1900}-\x{191c}\x{1950}-\x{196d}\x{1970}-\x{1974}\x{1980}-\x{19ab}\x{19c1}-\x{19c7}\x{1a00}-\x{1a16}\x{1a20}-\x{1a54}\x{1aa7}\x{1b05}-\x{1b33}\x{1b45}-\x{1b4b}\x{1b83}-\x{1ba0}\x{1bae}\x{1baf}\x{1bba}-\x{1be5}\x{1c00}-\x{1c23}\x{1c4d}-\x{1c4f}\x{1c5a}-\x{1c7d}\x{1ce9}-\x{1cec}\x{1cee}-\x{1cf1}\x{1cf5}\x{1cf6}\x{1d00}-\x{1dbf}\x{1e00}-\x{1f15}\x{1f18}-\x{1f1d}\x{1f20}-\x{1f45}\x{1f48}-\x{1f4d}\x{1f50}-\x{1f57}\x{1f59}\x{1f5b}\x{1f5d}\x{1f5f}-\x{1f7d}\x{1f80}-\x{1fb4}\x{1fb6}-\x{1fbc}\x{1fbe}\x{1fc2}-\x{1fc4}\x{1fc6}-\x{1fcc}\x{1fd0}-\x{1fd3}\x{1fd6}-\x{1fdb}\x{1fe0}-\x{1fec}\x{1ff2}-\x{1ff4}\x{1ff6}-\x{1ffc}\x{2071}\x{207f}\x{2090}-\x{209c}\x{2102}\x{2107}\x{210a}-\x{2113}\x{2115}\x{2119}-\x{211d}\x{2124}\x{2126}\x{2128}\x{212a}-\x{212d}\x{212f}-\x{2139}\x{213c}-\x{213f}\x{2145}-\x{2149}\x{214e}\x{2160}-\x{2188}\x{2c00}-\x{2c2e}\x{2c30}-\x{2c5e}\x{2c60}-\x{2ce4}\x{2ceb}-\x{2cee}\x{2cf2}\x{2cf3}\x{2d00}-\x{2d25}\x{2d27}\x{2d2d}\x{2d30}-\x{2d67}\x{2d6f}\x{2d80}-\x{2d96}\x{2da0}-\x{2da6}\x{2da8}-\x{2dae}\x{2db0}-\x{2db6}\x{2db8}-\x{2dbe}\x{2dc0}-\x{2dc6}\x{2dc8}-\x{2dce}\x{2dd0}-\x{2dd6}\x{2dd8}-\x{2dde}\x{2e2f}\x{3005}-\x{3007}\x{3021}-\x{3029}\x{3031}-\x{3035}\x{3038}-\x{303c}\x{3041}-\x{3096}\x{309d}-\x{309f}\x{30a1}-\x{30fa}\x{30fc}-\x{30ff}\x{3105}-\x{312d}\x{3131}-\x{318e}\x{31a0}-\x{31ba}\x{31f0}-\x{31ff}\x{3400}-\x{4db5}\x{4e00}-\x{9fcc}\x{a000}-\x{a48c}\x{a4d0}-\x{a4fd}\x{a500}-\x{a60c}\x{a610}-\x{a61f}\x{a62a}\x{a62b}\x{a640}-\x{a66e}\x{a67f}-\x{a697}\x{a6a0}-\x{a6ef}\x{a717}-\x{a71f}\x{a722}-\x{a788}\x{a78b}-\x{a78e}\x{a790}-\x{a793}\x{a7a0}-\x{a7aa}\x{a7f8}-\x{a801}\x{a803}-\x{a805}\x{a807}-\x{a80a}\x{a80c}-\x{a822}\x{a840}-\x{a873}\x{a882}-\x{a8b3}\x{a8f2}-\x{a8f7}\x{a8fb}\x{a90a}-\x{a925}\x{a930}-\x{a946}\x{a960}-\x{a97c}\x{a984}-\x{a9b2}\x{a9cf}\x{aa00}-\x{aa28}\x{aa40}-\x{aa42}\x{aa44}-\x{aa4b}\x{aa60}-\x{aa76}\x{aa7a}\x{aa80}-\x{aaaf}\x{aab1}\x{aab5}\x{aab6}\x{aab9}-\x{aabd}\x{aac0}\x{aac2}\x{aadb}-\x{aadd}\x{aae0}-\x{aaea}\x{aaf2}-\x{aaf4}\x{ab01}-\x{ab06}\x{ab09}-\x{ab0e}\x{ab11}-\x{ab16}\x{ab20}-\x{ab26}\x{ab28}-\x{ab2e}\x{abc0}-\x{abe2}\x{ac00}-\x{d7a3}\x{d7b0}-\x{d7c6}\x{d7cb}-\x{d7fb}\x{f900}-\x{fa6d}\x{fa70}-\x{fad9}\x{fb00}-\x{fb06}\x{fb13}-\x{fb17}\x{fb1d}\x{fb1f}-\x{fb28}\x{fb2a}-\x{fb36}\x{fb38}-\x{fb3c}\x{fb3e}\x{fb40}\x{fb41}\x{fb43}\x{fb44}\x{fb46}-\x{fbb1}\x{fbd3}-\x{fd3d}\x{fd50}-\x{fd8f}\x{fd92}-\x{fdc7}\x{fdf0}-\x{fdfb}\x{fe70}-\x{fe74}\x{fe76}-\x{fefc}\x{ff21}-\x{ff3a}\x{ff41}-\x{ff5a}\x{ff66}-\x{ffbe}\x{ffc2}-\x{ffc7}\x{ffca}-\x{ffcf}\x{ffd2}-\x{ffd7}\x{ffda}-\x{ffdc}0-9\x{0300}-\x{036f}\x{0483}-\x{0487}\x{0591}-\x{05bd}\x{05bf}\x{05c1}\x{05c2}\x{05c4}\x{05c5}\x{05c7}\x{0610}-\x{061a}\x{064b}-\x{0669}\x{0670}\x{06d6}-\x{06dc}\x{06df}-\x{06e4}\x{06e7}\x{06e8}\x{06ea}-\x{06ed}\x{06f0}-\x{06f9}\x{0711}\x{0730}-\x{074a}\x{07a6}-\x{07b0}\x{07c0}-\x{07c9}\x{07eb}-\x{07f3}\x{0816}-\x{0819}\x{081b}-\x{0823}\x{0825}-\x{0827}\x{0829}-\x{082d}\x{0859}-\x{085b}\x{08e4}-\x{08fe}\x{0900}-\x{0903}\x{093a}-\x{093c}\x{093e}-\x{094f}\x{0951}-\x{0957}\x{0962}\x{0963}\x{0966}-\x{096f}\x{0981}-\x{0983}\x{09bc}\x{09be}-\x{09c4}\x{09c7}\x{09c8}\x{09cb}-\x{09cd}\x{09d7}\x{09e2}\x{09e3}\x{09e6}-\x{09ef}\x{0a01}-\x{0a03}\x{0a3c}\x{0a3e}-\x{0a42}\x{0a47}\x{0a48}\x{0a4b}-\x{0a4d}\x{0a51}\x{0a66}-\x{0a71}\x{0a75}\x{0a81}-\x{0a83}\x{0abc}\x{0abe}-\x{0ac5}\x{0ac7}-\x{0ac9}\x{0acb}-\x{0acd}\x{0ae2}\x{0ae3}\x{0ae6}-\x{0aef}\x{0b01}-\x{0b03}\x{0b3c}\x{0b3e}-\x{0b44}\x{0b47}\x{0b48}\x{0b4b}-\x{0b4d}\x{0b56}\x{0b57}\x{0b62}\x{0b63}\x{0b66}-\x{0b6f}\x{0b82}\x{0bbe}-\x{0bc2}\x{0bc6}-\x{0bc8}\x{0bca}-\x{0bcd}\x{0bd7}\x{0be6}-\x{0bef}\x{0c01}-\x{0c03}\x{0c3e}-\x{0c44}\x{0c46}-\x{0c48}\x{0c4a}-\x{0c4d}\x{0c55}\x{0c56}\x{0c62}\x{0c63}\x{0c66}-\x{0c6f}\x{0c82}\x{0c83}\x{0cbc}\x{0cbe}-\x{0cc4}\x{0cc6}-\x{0cc8}\x{0cca}-\x{0ccd}\x{0cd5}\x{0cd6}\x{0ce2}\x{0ce3}\x{0ce6}-\x{0cef}\x{0d02}\x{0d03}\x{0d3e}-\x{0d44}\x{0d46}-\x{0d48}\x{0d4a}-\x{0d4d}\x{0d57}\x{0d62}\x{0d63}\x{0d66}-\x{0d6f}\x{0d82}\x{0d83}\x{0dca}\x{0dcf}-\x{0dd4}\x{0dd6}\x{0dd8}-\x{0ddf}\x{0df2}\x{0df3}\x{0e31}\x{0e34}-\x{0e3a}\x{0e47}-\x{0e4e}\x{0e50}-\x{0e59}\x{0eb1}\x{0eb4}-\x{0eb9}\x{0ebb}\x{0ebc}\x{0ec8}-\x{0ecd}\x{0ed0}-\x{0ed9}\x{0f18}\x{0f19}\x{0f20}-\x{0f29}\x{0f35}\x{0f37}\x{0f39}\x{0f3e}\x{0f3f}\x{0f71}-\x{0f84}\x{0f86}\x{0f87}\x{0f8d}-\x{0f97}\x{0f99}-\x{0fbc}\x{0fc6}\x{102b}-\x{103e}\x{1040}-\x{1049}\x{1056}-\x{1059}\x{105e}-\x{1060}\x{1062}-\x{1064}\x{1067}-\x{106d}\x{1071}-\x{1074}\x{1082}-\x{108d}\x{108f}-\x{109d}\x{135d}-\x{135f}\x{1712}-\x{1714}\x{1732}-\x{1734}\x{1752}\x{1753}\x{1772}\x{1773}\x{17b4}-\x{17d3}\x{17dd}\x{17e0}-\x{17e9}\x{180b}-\x{180d}\x{1810}-\x{1819}\x{18a9}\x{1920}-\x{192b}\x{1930}-\x{193b}\x{1946}-\x{194f}\x{19b0}-\x{19c0}\x{19c8}\x{19c9}\x{19d0}-\x{19d9}\x{1a17}-\x{1a1b}\x{1a55}-\x{1a5e}\x{1a60}-\x{1a7c}\x{1a7f}-\x{1a89}\x{1a90}-\x{1a99}\x{1b00}-\x{1b04}\x{1b34}-\x{1b44}\x{1b50}-\x{1b59}\x{1b6b}-\x{1b73}\x{1b80}-\x{1b82}\x{1ba1}-\x{1bad}\x{1bb0}-\x{1bb9}\x{1be6}-\x{1bf3}\x{1c24}-\x{1c37}\x{1c40}-\x{1c49}\x{1c50}-\x{1c59}\x{1cd0}-\x{1cd2}\x{1cd4}-\x{1ce8}\x{1ced}\x{1cf2}-\x{1cf4}\x{1dc0}-\x{1de6}\x{1dfc}-\x{1dff}\x{200c}\x{200d}\x{203f}\x{2040}\x{2054}\x{20d0}-\x{20dc}\x{20e1}\x{20e5}-\x{20f0}\x{2cef}-\x{2cf1}\x{2d7f}\x{2de0}-\x{2dff}\x{302a}-\x{302f}\x{3099}\x{309a}\x{a620}-\x{a629}\x{a66f}\x{a674}-\x{a67d}\x{a69f}\x{a6f0}\x{a6f1}\x{a802}\x{a806}\x{a80b}\x{a823}-\x{a827}\x{a880}\x{a881}\x{a8b4}-\x{a8c4}\x{a8d0}-\x{a8d9}\x{a8e0}-\x{a8f1}\x{a900}-\x{a909}\x{a926}-\x{a92d}\x{a947}-\x{a953}\x{a980}-\x{a983}\x{a9b3}-\x{a9c0}\x{a9d0}-\x{a9d9}\x{aa29}-\x{aa36}\x{aa43}\x{aa4c}\x{aa4d}\x{aa50}-\x{aa59}\x{aa7b}\x{aab0}\x{aab2}-\x{aab4}\x{aab7}\x{aab8}\x{aabe}\x{aabf}\x{aac1}\x{aaeb}-\x{aaef}\x{aaf5}\x{aaf6}\x{abe3}-\x{abea}\x{abec}\x{abed}\x{abf0}-\x{abf9}\x{fb1e}\x{fe00}-\x{fe0f}\x{fe20}-\x{fe26}\x{fe33}\x{fe34}\x{fe4d}-\x{fe4f}\x{ff10}-\x{ff19}\x{ff3f}]*\b'; |
|
26 | - |
|
27 | - /** |
|
28 | - * Full list of JavaScript reserved words. |
|
29 | - * Will be loaded from /data/js/keywords_reserved.txt. |
|
30 | - * |
|
31 | - * @see https://mathiasbynens.be/notes/reserved-keywords |
|
32 | - * |
|
33 | - * @var string[] |
|
34 | - */ |
|
35 | - protected $keywordsReserved = array(); |
|
36 | - |
|
37 | - /** |
|
38 | - * List of JavaScript reserved words that accept a <variable, value, ...> |
|
39 | - * after them. Some end of lines are not the end of a statement, like with |
|
40 | - * these keywords. |
|
41 | - * |
|
42 | - * E.g.: we shouldn't insert a ; after this else |
|
43 | - * else |
|
44 | - * console.log('this is quite fine') |
|
45 | - * |
|
46 | - * Will be loaded from /data/js/keywords_before.txt |
|
47 | - * |
|
48 | - * @var string[] |
|
49 | - */ |
|
50 | - protected $keywordsBefore = array(); |
|
51 | - |
|
52 | - /** |
|
53 | - * List of JavaScript reserved words that accept a <variable, value, ...> |
|
54 | - * before them. Some end of lines are not the end of a statement, like when |
|
55 | - * continued by one of these keywords on the newline. |
|
56 | - * |
|
57 | - * E.g.: we shouldn't insert a ; before this instanceof |
|
58 | - * variable |
|
59 | - * instanceof String |
|
60 | - * |
|
61 | - * Will be loaded from /data/js/keywords_after.txt |
|
62 | - * |
|
63 | - * @var string[] |
|
64 | - */ |
|
65 | - protected $keywordsAfter = array(); |
|
66 | - |
|
67 | - /** |
|
68 | - * List of JavaScript operators that accept a <variable, value, ...> after |
|
69 | - * them. Some end of lines are not the end of a statement, like with these |
|
70 | - * operators. |
|
71 | - * |
|
72 | - * Note: Most operators are fine, we've only removed !, ++ and --. |
|
73 | - * There can't be a newline separating ! and whatever it is negating. |
|
74 | - * ++ & -- have to be joined with the value they're in-/decrementing. |
|
75 | - * |
|
76 | - * Will be loaded from /data/js/operators_before.txt |
|
77 | - * |
|
78 | - * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators |
|
79 | - * |
|
80 | - * @var string[] |
|
81 | - */ |
|
82 | - protected $operatorsBefore = array(); |
|
83 | - |
|
84 | - /** |
|
85 | - * List of JavaScript operators that accept a <variable, value, ...> before |
|
86 | - * them. Some end of lines are not the end of a statement, like when |
|
87 | - * continued by one of these operators on the newline. |
|
88 | - * |
|
89 | - * Note: Most operators are fine, we've only removed ), ], ++ and --. |
|
90 | - * ++ & -- have to be joined with the value they're in-/decrementing. |
|
91 | - * ) & ] are "special" in that they have lots or usecases. () for example |
|
92 | - * is used for function calls, for grouping, in if () and for (), ... |
|
93 | - * |
|
94 | - * Will be loaded from /data/js/operators_after.txt |
|
95 | - * |
|
96 | - * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators |
|
97 | - * |
|
98 | - * @var string[] |
|
99 | - */ |
|
100 | - protected $operatorsAfter = array(); |
|
101 | - |
|
102 | - /** |
|
103 | - * {@inheritdoc} |
|
104 | - */ |
|
105 | - public function __construct() |
|
106 | - { |
|
107 | - call_user_func_array(array('parent', '__construct'), func_get_args()); |
|
108 | - |
|
109 | - $dataDir = __DIR__.'/../data/js/'; |
|
110 | - $options = FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES; |
|
111 | - $this->keywordsReserved = file($dataDir.'keywords_reserved.txt', $options); |
|
112 | - $this->keywordsBefore = file($dataDir.'keywords_before.txt', $options); |
|
113 | - $this->keywordsAfter = file($dataDir.'keywords_after.txt', $options); |
|
114 | - $this->operatorsBefore = file($dataDir.'operators_before.txt', $options); |
|
115 | - $this->operatorsAfter = file($dataDir.'operators_after.txt', $options); |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Minify the data. |
|
120 | - * Perform JS optimizations. |
|
121 | - * |
|
122 | - * @param string[optional] $path Path to write the data to. |
|
123 | - * |
|
124 | - * @return string The minified data. |
|
125 | - */ |
|
126 | - public function execute($path = null) |
|
127 | - { |
|
128 | - $content = ''; |
|
129 | - |
|
130 | - // loop files |
|
131 | - foreach ($this->data as $source => $js) { |
|
132 | - /* |
|
17 | + /** |
|
18 | + * Var-matching regex based on http://stackoverflow.com/a/9337047/802993. |
|
19 | + * |
|
20 | + * Note that regular expressions using that bit must have the PCRE_UTF8 |
|
21 | + * pattern modifier (/u) set. |
|
22 | + * |
|
23 | + * @var string |
|
24 | + */ |
|
25 | + const REGEX_VARIABLE = '\b[$A-Z\_a-z\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\x{02c1}\x{02c6}-\x{02d1}\x{02e0}-\x{02e4}\x{02ec}\x{02ee}\x{0370}-\x{0374}\x{0376}\x{0377}\x{037a}-\x{037d}\x{0386}\x{0388}-\x{038a}\x{038c}\x{038e}-\x{03a1}\x{03a3}-\x{03f5}\x{03f7}-\x{0481}\x{048a}-\x{0527}\x{0531}-\x{0556}\x{0559}\x{0561}-\x{0587}\x{05d0}-\x{05ea}\x{05f0}-\x{05f2}\x{0620}-\x{064a}\x{066e}\x{066f}\x{0671}-\x{06d3}\x{06d5}\x{06e5}\x{06e6}\x{06ee}\x{06ef}\x{06fa}-\x{06fc}\x{06ff}\x{0710}\x{0712}-\x{072f}\x{074d}-\x{07a5}\x{07b1}\x{07ca}-\x{07ea}\x{07f4}\x{07f5}\x{07fa}\x{0800}-\x{0815}\x{081a}\x{0824}\x{0828}\x{0840}-\x{0858}\x{08a0}\x{08a2}-\x{08ac}\x{0904}-\x{0939}\x{093d}\x{0950}\x{0958}-\x{0961}\x{0971}-\x{0977}\x{0979}-\x{097f}\x{0985}-\x{098c}\x{098f}\x{0990}\x{0993}-\x{09a8}\x{09aa}-\x{09b0}\x{09b2}\x{09b6}-\x{09b9}\x{09bd}\x{09ce}\x{09dc}\x{09dd}\x{09df}-\x{09e1}\x{09f0}\x{09f1}\x{0a05}-\x{0a0a}\x{0a0f}\x{0a10}\x{0a13}-\x{0a28}\x{0a2a}-\x{0a30}\x{0a32}\x{0a33}\x{0a35}\x{0a36}\x{0a38}\x{0a39}\x{0a59}-\x{0a5c}\x{0a5e}\x{0a72}-\x{0a74}\x{0a85}-\x{0a8d}\x{0a8f}-\x{0a91}\x{0a93}-\x{0aa8}\x{0aaa}-\x{0ab0}\x{0ab2}\x{0ab3}\x{0ab5}-\x{0ab9}\x{0abd}\x{0ad0}\x{0ae0}\x{0ae1}\x{0b05}-\x{0b0c}\x{0b0f}\x{0b10}\x{0b13}-\x{0b28}\x{0b2a}-\x{0b30}\x{0b32}\x{0b33}\x{0b35}-\x{0b39}\x{0b3d}\x{0b5c}\x{0b5d}\x{0b5f}-\x{0b61}\x{0b71}\x{0b83}\x{0b85}-\x{0b8a}\x{0b8e}-\x{0b90}\x{0b92}-\x{0b95}\x{0b99}\x{0b9a}\x{0b9c}\x{0b9e}\x{0b9f}\x{0ba3}\x{0ba4}\x{0ba8}-\x{0baa}\x{0bae}-\x{0bb9}\x{0bd0}\x{0c05}-\x{0c0c}\x{0c0e}-\x{0c10}\x{0c12}-\x{0c28}\x{0c2a}-\x{0c33}\x{0c35}-\x{0c39}\x{0c3d}\x{0c58}\x{0c59}\x{0c60}\x{0c61}\x{0c85}-\x{0c8c}\x{0c8e}-\x{0c90}\x{0c92}-\x{0ca8}\x{0caa}-\x{0cb3}\x{0cb5}-\x{0cb9}\x{0cbd}\x{0cde}\x{0ce0}\x{0ce1}\x{0cf1}\x{0cf2}\x{0d05}-\x{0d0c}\x{0d0e}-\x{0d10}\x{0d12}-\x{0d3a}\x{0d3d}\x{0d4e}\x{0d60}\x{0d61}\x{0d7a}-\x{0d7f}\x{0d85}-\x{0d96}\x{0d9a}-\x{0db1}\x{0db3}-\x{0dbb}\x{0dbd}\x{0dc0}-\x{0dc6}\x{0e01}-\x{0e30}\x{0e32}\x{0e33}\x{0e40}-\x{0e46}\x{0e81}\x{0e82}\x{0e84}\x{0e87}\x{0e88}\x{0e8a}\x{0e8d}\x{0e94}-\x{0e97}\x{0e99}-\x{0e9f}\x{0ea1}-\x{0ea3}\x{0ea5}\x{0ea7}\x{0eaa}\x{0eab}\x{0ead}-\x{0eb0}\x{0eb2}\x{0eb3}\x{0ebd}\x{0ec0}-\x{0ec4}\x{0ec6}\x{0edc}-\x{0edf}\x{0f00}\x{0f40}-\x{0f47}\x{0f49}-\x{0f6c}\x{0f88}-\x{0f8c}\x{1000}-\x{102a}\x{103f}\x{1050}-\x{1055}\x{105a}-\x{105d}\x{1061}\x{1065}\x{1066}\x{106e}-\x{1070}\x{1075}-\x{1081}\x{108e}\x{10a0}-\x{10c5}\x{10c7}\x{10cd}\x{10d0}-\x{10fa}\x{10fc}-\x{1248}\x{124a}-\x{124d}\x{1250}-\x{1256}\x{1258}\x{125a}-\x{125d}\x{1260}-\x{1288}\x{128a}-\x{128d}\x{1290}-\x{12b0}\x{12b2}-\x{12b5}\x{12b8}-\x{12be}\x{12c0}\x{12c2}-\x{12c5}\x{12c8}-\x{12d6}\x{12d8}-\x{1310}\x{1312}-\x{1315}\x{1318}-\x{135a}\x{1380}-\x{138f}\x{13a0}-\x{13f4}\x{1401}-\x{166c}\x{166f}-\x{167f}\x{1681}-\x{169a}\x{16a0}-\x{16ea}\x{16ee}-\x{16f0}\x{1700}-\x{170c}\x{170e}-\x{1711}\x{1720}-\x{1731}\x{1740}-\x{1751}\x{1760}-\x{176c}\x{176e}-\x{1770}\x{1780}-\x{17b3}\x{17d7}\x{17dc}\x{1820}-\x{1877}\x{1880}-\x{18a8}\x{18aa}\x{18b0}-\x{18f5}\x{1900}-\x{191c}\x{1950}-\x{196d}\x{1970}-\x{1974}\x{1980}-\x{19ab}\x{19c1}-\x{19c7}\x{1a00}-\x{1a16}\x{1a20}-\x{1a54}\x{1aa7}\x{1b05}-\x{1b33}\x{1b45}-\x{1b4b}\x{1b83}-\x{1ba0}\x{1bae}\x{1baf}\x{1bba}-\x{1be5}\x{1c00}-\x{1c23}\x{1c4d}-\x{1c4f}\x{1c5a}-\x{1c7d}\x{1ce9}-\x{1cec}\x{1cee}-\x{1cf1}\x{1cf5}\x{1cf6}\x{1d00}-\x{1dbf}\x{1e00}-\x{1f15}\x{1f18}-\x{1f1d}\x{1f20}-\x{1f45}\x{1f48}-\x{1f4d}\x{1f50}-\x{1f57}\x{1f59}\x{1f5b}\x{1f5d}\x{1f5f}-\x{1f7d}\x{1f80}-\x{1fb4}\x{1fb6}-\x{1fbc}\x{1fbe}\x{1fc2}-\x{1fc4}\x{1fc6}-\x{1fcc}\x{1fd0}-\x{1fd3}\x{1fd6}-\x{1fdb}\x{1fe0}-\x{1fec}\x{1ff2}-\x{1ff4}\x{1ff6}-\x{1ffc}\x{2071}\x{207f}\x{2090}-\x{209c}\x{2102}\x{2107}\x{210a}-\x{2113}\x{2115}\x{2119}-\x{211d}\x{2124}\x{2126}\x{2128}\x{212a}-\x{212d}\x{212f}-\x{2139}\x{213c}-\x{213f}\x{2145}-\x{2149}\x{214e}\x{2160}-\x{2188}\x{2c00}-\x{2c2e}\x{2c30}-\x{2c5e}\x{2c60}-\x{2ce4}\x{2ceb}-\x{2cee}\x{2cf2}\x{2cf3}\x{2d00}-\x{2d25}\x{2d27}\x{2d2d}\x{2d30}-\x{2d67}\x{2d6f}\x{2d80}-\x{2d96}\x{2da0}-\x{2da6}\x{2da8}-\x{2dae}\x{2db0}-\x{2db6}\x{2db8}-\x{2dbe}\x{2dc0}-\x{2dc6}\x{2dc8}-\x{2dce}\x{2dd0}-\x{2dd6}\x{2dd8}-\x{2dde}\x{2e2f}\x{3005}-\x{3007}\x{3021}-\x{3029}\x{3031}-\x{3035}\x{3038}-\x{303c}\x{3041}-\x{3096}\x{309d}-\x{309f}\x{30a1}-\x{30fa}\x{30fc}-\x{30ff}\x{3105}-\x{312d}\x{3131}-\x{318e}\x{31a0}-\x{31ba}\x{31f0}-\x{31ff}\x{3400}-\x{4db5}\x{4e00}-\x{9fcc}\x{a000}-\x{a48c}\x{a4d0}-\x{a4fd}\x{a500}-\x{a60c}\x{a610}-\x{a61f}\x{a62a}\x{a62b}\x{a640}-\x{a66e}\x{a67f}-\x{a697}\x{a6a0}-\x{a6ef}\x{a717}-\x{a71f}\x{a722}-\x{a788}\x{a78b}-\x{a78e}\x{a790}-\x{a793}\x{a7a0}-\x{a7aa}\x{a7f8}-\x{a801}\x{a803}-\x{a805}\x{a807}-\x{a80a}\x{a80c}-\x{a822}\x{a840}-\x{a873}\x{a882}-\x{a8b3}\x{a8f2}-\x{a8f7}\x{a8fb}\x{a90a}-\x{a925}\x{a930}-\x{a946}\x{a960}-\x{a97c}\x{a984}-\x{a9b2}\x{a9cf}\x{aa00}-\x{aa28}\x{aa40}-\x{aa42}\x{aa44}-\x{aa4b}\x{aa60}-\x{aa76}\x{aa7a}\x{aa80}-\x{aaaf}\x{aab1}\x{aab5}\x{aab6}\x{aab9}-\x{aabd}\x{aac0}\x{aac2}\x{aadb}-\x{aadd}\x{aae0}-\x{aaea}\x{aaf2}-\x{aaf4}\x{ab01}-\x{ab06}\x{ab09}-\x{ab0e}\x{ab11}-\x{ab16}\x{ab20}-\x{ab26}\x{ab28}-\x{ab2e}\x{abc0}-\x{abe2}\x{ac00}-\x{d7a3}\x{d7b0}-\x{d7c6}\x{d7cb}-\x{d7fb}\x{f900}-\x{fa6d}\x{fa70}-\x{fad9}\x{fb00}-\x{fb06}\x{fb13}-\x{fb17}\x{fb1d}\x{fb1f}-\x{fb28}\x{fb2a}-\x{fb36}\x{fb38}-\x{fb3c}\x{fb3e}\x{fb40}\x{fb41}\x{fb43}\x{fb44}\x{fb46}-\x{fbb1}\x{fbd3}-\x{fd3d}\x{fd50}-\x{fd8f}\x{fd92}-\x{fdc7}\x{fdf0}-\x{fdfb}\x{fe70}-\x{fe74}\x{fe76}-\x{fefc}\x{ff21}-\x{ff3a}\x{ff41}-\x{ff5a}\x{ff66}-\x{ffbe}\x{ffc2}-\x{ffc7}\x{ffca}-\x{ffcf}\x{ffd2}-\x{ffd7}\x{ffda}-\x{ffdc}][$A-Z\_a-z\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\x{02c1}\x{02c6}-\x{02d1}\x{02e0}-\x{02e4}\x{02ec}\x{02ee}\x{0370}-\x{0374}\x{0376}\x{0377}\x{037a}-\x{037d}\x{0386}\x{0388}-\x{038a}\x{038c}\x{038e}-\x{03a1}\x{03a3}-\x{03f5}\x{03f7}-\x{0481}\x{048a}-\x{0527}\x{0531}-\x{0556}\x{0559}\x{0561}-\x{0587}\x{05d0}-\x{05ea}\x{05f0}-\x{05f2}\x{0620}-\x{064a}\x{066e}\x{066f}\x{0671}-\x{06d3}\x{06d5}\x{06e5}\x{06e6}\x{06ee}\x{06ef}\x{06fa}-\x{06fc}\x{06ff}\x{0710}\x{0712}-\x{072f}\x{074d}-\x{07a5}\x{07b1}\x{07ca}-\x{07ea}\x{07f4}\x{07f5}\x{07fa}\x{0800}-\x{0815}\x{081a}\x{0824}\x{0828}\x{0840}-\x{0858}\x{08a0}\x{08a2}-\x{08ac}\x{0904}-\x{0939}\x{093d}\x{0950}\x{0958}-\x{0961}\x{0971}-\x{0977}\x{0979}-\x{097f}\x{0985}-\x{098c}\x{098f}\x{0990}\x{0993}-\x{09a8}\x{09aa}-\x{09b0}\x{09b2}\x{09b6}-\x{09b9}\x{09bd}\x{09ce}\x{09dc}\x{09dd}\x{09df}-\x{09e1}\x{09f0}\x{09f1}\x{0a05}-\x{0a0a}\x{0a0f}\x{0a10}\x{0a13}-\x{0a28}\x{0a2a}-\x{0a30}\x{0a32}\x{0a33}\x{0a35}\x{0a36}\x{0a38}\x{0a39}\x{0a59}-\x{0a5c}\x{0a5e}\x{0a72}-\x{0a74}\x{0a85}-\x{0a8d}\x{0a8f}-\x{0a91}\x{0a93}-\x{0aa8}\x{0aaa}-\x{0ab0}\x{0ab2}\x{0ab3}\x{0ab5}-\x{0ab9}\x{0abd}\x{0ad0}\x{0ae0}\x{0ae1}\x{0b05}-\x{0b0c}\x{0b0f}\x{0b10}\x{0b13}-\x{0b28}\x{0b2a}-\x{0b30}\x{0b32}\x{0b33}\x{0b35}-\x{0b39}\x{0b3d}\x{0b5c}\x{0b5d}\x{0b5f}-\x{0b61}\x{0b71}\x{0b83}\x{0b85}-\x{0b8a}\x{0b8e}-\x{0b90}\x{0b92}-\x{0b95}\x{0b99}\x{0b9a}\x{0b9c}\x{0b9e}\x{0b9f}\x{0ba3}\x{0ba4}\x{0ba8}-\x{0baa}\x{0bae}-\x{0bb9}\x{0bd0}\x{0c05}-\x{0c0c}\x{0c0e}-\x{0c10}\x{0c12}-\x{0c28}\x{0c2a}-\x{0c33}\x{0c35}-\x{0c39}\x{0c3d}\x{0c58}\x{0c59}\x{0c60}\x{0c61}\x{0c85}-\x{0c8c}\x{0c8e}-\x{0c90}\x{0c92}-\x{0ca8}\x{0caa}-\x{0cb3}\x{0cb5}-\x{0cb9}\x{0cbd}\x{0cde}\x{0ce0}\x{0ce1}\x{0cf1}\x{0cf2}\x{0d05}-\x{0d0c}\x{0d0e}-\x{0d10}\x{0d12}-\x{0d3a}\x{0d3d}\x{0d4e}\x{0d60}\x{0d61}\x{0d7a}-\x{0d7f}\x{0d85}-\x{0d96}\x{0d9a}-\x{0db1}\x{0db3}-\x{0dbb}\x{0dbd}\x{0dc0}-\x{0dc6}\x{0e01}-\x{0e30}\x{0e32}\x{0e33}\x{0e40}-\x{0e46}\x{0e81}\x{0e82}\x{0e84}\x{0e87}\x{0e88}\x{0e8a}\x{0e8d}\x{0e94}-\x{0e97}\x{0e99}-\x{0e9f}\x{0ea1}-\x{0ea3}\x{0ea5}\x{0ea7}\x{0eaa}\x{0eab}\x{0ead}-\x{0eb0}\x{0eb2}\x{0eb3}\x{0ebd}\x{0ec0}-\x{0ec4}\x{0ec6}\x{0edc}-\x{0edf}\x{0f00}\x{0f40}-\x{0f47}\x{0f49}-\x{0f6c}\x{0f88}-\x{0f8c}\x{1000}-\x{102a}\x{103f}\x{1050}-\x{1055}\x{105a}-\x{105d}\x{1061}\x{1065}\x{1066}\x{106e}-\x{1070}\x{1075}-\x{1081}\x{108e}\x{10a0}-\x{10c5}\x{10c7}\x{10cd}\x{10d0}-\x{10fa}\x{10fc}-\x{1248}\x{124a}-\x{124d}\x{1250}-\x{1256}\x{1258}\x{125a}-\x{125d}\x{1260}-\x{1288}\x{128a}-\x{128d}\x{1290}-\x{12b0}\x{12b2}-\x{12b5}\x{12b8}-\x{12be}\x{12c0}\x{12c2}-\x{12c5}\x{12c8}-\x{12d6}\x{12d8}-\x{1310}\x{1312}-\x{1315}\x{1318}-\x{135a}\x{1380}-\x{138f}\x{13a0}-\x{13f4}\x{1401}-\x{166c}\x{166f}-\x{167f}\x{1681}-\x{169a}\x{16a0}-\x{16ea}\x{16ee}-\x{16f0}\x{1700}-\x{170c}\x{170e}-\x{1711}\x{1720}-\x{1731}\x{1740}-\x{1751}\x{1760}-\x{176c}\x{176e}-\x{1770}\x{1780}-\x{17b3}\x{17d7}\x{17dc}\x{1820}-\x{1877}\x{1880}-\x{18a8}\x{18aa}\x{18b0}-\x{18f5}\x{1900}-\x{191c}\x{1950}-\x{196d}\x{1970}-\x{1974}\x{1980}-\x{19ab}\x{19c1}-\x{19c7}\x{1a00}-\x{1a16}\x{1a20}-\x{1a54}\x{1aa7}\x{1b05}-\x{1b33}\x{1b45}-\x{1b4b}\x{1b83}-\x{1ba0}\x{1bae}\x{1baf}\x{1bba}-\x{1be5}\x{1c00}-\x{1c23}\x{1c4d}-\x{1c4f}\x{1c5a}-\x{1c7d}\x{1ce9}-\x{1cec}\x{1cee}-\x{1cf1}\x{1cf5}\x{1cf6}\x{1d00}-\x{1dbf}\x{1e00}-\x{1f15}\x{1f18}-\x{1f1d}\x{1f20}-\x{1f45}\x{1f48}-\x{1f4d}\x{1f50}-\x{1f57}\x{1f59}\x{1f5b}\x{1f5d}\x{1f5f}-\x{1f7d}\x{1f80}-\x{1fb4}\x{1fb6}-\x{1fbc}\x{1fbe}\x{1fc2}-\x{1fc4}\x{1fc6}-\x{1fcc}\x{1fd0}-\x{1fd3}\x{1fd6}-\x{1fdb}\x{1fe0}-\x{1fec}\x{1ff2}-\x{1ff4}\x{1ff6}-\x{1ffc}\x{2071}\x{207f}\x{2090}-\x{209c}\x{2102}\x{2107}\x{210a}-\x{2113}\x{2115}\x{2119}-\x{211d}\x{2124}\x{2126}\x{2128}\x{212a}-\x{212d}\x{212f}-\x{2139}\x{213c}-\x{213f}\x{2145}-\x{2149}\x{214e}\x{2160}-\x{2188}\x{2c00}-\x{2c2e}\x{2c30}-\x{2c5e}\x{2c60}-\x{2ce4}\x{2ceb}-\x{2cee}\x{2cf2}\x{2cf3}\x{2d00}-\x{2d25}\x{2d27}\x{2d2d}\x{2d30}-\x{2d67}\x{2d6f}\x{2d80}-\x{2d96}\x{2da0}-\x{2da6}\x{2da8}-\x{2dae}\x{2db0}-\x{2db6}\x{2db8}-\x{2dbe}\x{2dc0}-\x{2dc6}\x{2dc8}-\x{2dce}\x{2dd0}-\x{2dd6}\x{2dd8}-\x{2dde}\x{2e2f}\x{3005}-\x{3007}\x{3021}-\x{3029}\x{3031}-\x{3035}\x{3038}-\x{303c}\x{3041}-\x{3096}\x{309d}-\x{309f}\x{30a1}-\x{30fa}\x{30fc}-\x{30ff}\x{3105}-\x{312d}\x{3131}-\x{318e}\x{31a0}-\x{31ba}\x{31f0}-\x{31ff}\x{3400}-\x{4db5}\x{4e00}-\x{9fcc}\x{a000}-\x{a48c}\x{a4d0}-\x{a4fd}\x{a500}-\x{a60c}\x{a610}-\x{a61f}\x{a62a}\x{a62b}\x{a640}-\x{a66e}\x{a67f}-\x{a697}\x{a6a0}-\x{a6ef}\x{a717}-\x{a71f}\x{a722}-\x{a788}\x{a78b}-\x{a78e}\x{a790}-\x{a793}\x{a7a0}-\x{a7aa}\x{a7f8}-\x{a801}\x{a803}-\x{a805}\x{a807}-\x{a80a}\x{a80c}-\x{a822}\x{a840}-\x{a873}\x{a882}-\x{a8b3}\x{a8f2}-\x{a8f7}\x{a8fb}\x{a90a}-\x{a925}\x{a930}-\x{a946}\x{a960}-\x{a97c}\x{a984}-\x{a9b2}\x{a9cf}\x{aa00}-\x{aa28}\x{aa40}-\x{aa42}\x{aa44}-\x{aa4b}\x{aa60}-\x{aa76}\x{aa7a}\x{aa80}-\x{aaaf}\x{aab1}\x{aab5}\x{aab6}\x{aab9}-\x{aabd}\x{aac0}\x{aac2}\x{aadb}-\x{aadd}\x{aae0}-\x{aaea}\x{aaf2}-\x{aaf4}\x{ab01}-\x{ab06}\x{ab09}-\x{ab0e}\x{ab11}-\x{ab16}\x{ab20}-\x{ab26}\x{ab28}-\x{ab2e}\x{abc0}-\x{abe2}\x{ac00}-\x{d7a3}\x{d7b0}-\x{d7c6}\x{d7cb}-\x{d7fb}\x{f900}-\x{fa6d}\x{fa70}-\x{fad9}\x{fb00}-\x{fb06}\x{fb13}-\x{fb17}\x{fb1d}\x{fb1f}-\x{fb28}\x{fb2a}-\x{fb36}\x{fb38}-\x{fb3c}\x{fb3e}\x{fb40}\x{fb41}\x{fb43}\x{fb44}\x{fb46}-\x{fbb1}\x{fbd3}-\x{fd3d}\x{fd50}-\x{fd8f}\x{fd92}-\x{fdc7}\x{fdf0}-\x{fdfb}\x{fe70}-\x{fe74}\x{fe76}-\x{fefc}\x{ff21}-\x{ff3a}\x{ff41}-\x{ff5a}\x{ff66}-\x{ffbe}\x{ffc2}-\x{ffc7}\x{ffca}-\x{ffcf}\x{ffd2}-\x{ffd7}\x{ffda}-\x{ffdc}0-9\x{0300}-\x{036f}\x{0483}-\x{0487}\x{0591}-\x{05bd}\x{05bf}\x{05c1}\x{05c2}\x{05c4}\x{05c5}\x{05c7}\x{0610}-\x{061a}\x{064b}-\x{0669}\x{0670}\x{06d6}-\x{06dc}\x{06df}-\x{06e4}\x{06e7}\x{06e8}\x{06ea}-\x{06ed}\x{06f0}-\x{06f9}\x{0711}\x{0730}-\x{074a}\x{07a6}-\x{07b0}\x{07c0}-\x{07c9}\x{07eb}-\x{07f3}\x{0816}-\x{0819}\x{081b}-\x{0823}\x{0825}-\x{0827}\x{0829}-\x{082d}\x{0859}-\x{085b}\x{08e4}-\x{08fe}\x{0900}-\x{0903}\x{093a}-\x{093c}\x{093e}-\x{094f}\x{0951}-\x{0957}\x{0962}\x{0963}\x{0966}-\x{096f}\x{0981}-\x{0983}\x{09bc}\x{09be}-\x{09c4}\x{09c7}\x{09c8}\x{09cb}-\x{09cd}\x{09d7}\x{09e2}\x{09e3}\x{09e6}-\x{09ef}\x{0a01}-\x{0a03}\x{0a3c}\x{0a3e}-\x{0a42}\x{0a47}\x{0a48}\x{0a4b}-\x{0a4d}\x{0a51}\x{0a66}-\x{0a71}\x{0a75}\x{0a81}-\x{0a83}\x{0abc}\x{0abe}-\x{0ac5}\x{0ac7}-\x{0ac9}\x{0acb}-\x{0acd}\x{0ae2}\x{0ae3}\x{0ae6}-\x{0aef}\x{0b01}-\x{0b03}\x{0b3c}\x{0b3e}-\x{0b44}\x{0b47}\x{0b48}\x{0b4b}-\x{0b4d}\x{0b56}\x{0b57}\x{0b62}\x{0b63}\x{0b66}-\x{0b6f}\x{0b82}\x{0bbe}-\x{0bc2}\x{0bc6}-\x{0bc8}\x{0bca}-\x{0bcd}\x{0bd7}\x{0be6}-\x{0bef}\x{0c01}-\x{0c03}\x{0c3e}-\x{0c44}\x{0c46}-\x{0c48}\x{0c4a}-\x{0c4d}\x{0c55}\x{0c56}\x{0c62}\x{0c63}\x{0c66}-\x{0c6f}\x{0c82}\x{0c83}\x{0cbc}\x{0cbe}-\x{0cc4}\x{0cc6}-\x{0cc8}\x{0cca}-\x{0ccd}\x{0cd5}\x{0cd6}\x{0ce2}\x{0ce3}\x{0ce6}-\x{0cef}\x{0d02}\x{0d03}\x{0d3e}-\x{0d44}\x{0d46}-\x{0d48}\x{0d4a}-\x{0d4d}\x{0d57}\x{0d62}\x{0d63}\x{0d66}-\x{0d6f}\x{0d82}\x{0d83}\x{0dca}\x{0dcf}-\x{0dd4}\x{0dd6}\x{0dd8}-\x{0ddf}\x{0df2}\x{0df3}\x{0e31}\x{0e34}-\x{0e3a}\x{0e47}-\x{0e4e}\x{0e50}-\x{0e59}\x{0eb1}\x{0eb4}-\x{0eb9}\x{0ebb}\x{0ebc}\x{0ec8}-\x{0ecd}\x{0ed0}-\x{0ed9}\x{0f18}\x{0f19}\x{0f20}-\x{0f29}\x{0f35}\x{0f37}\x{0f39}\x{0f3e}\x{0f3f}\x{0f71}-\x{0f84}\x{0f86}\x{0f87}\x{0f8d}-\x{0f97}\x{0f99}-\x{0fbc}\x{0fc6}\x{102b}-\x{103e}\x{1040}-\x{1049}\x{1056}-\x{1059}\x{105e}-\x{1060}\x{1062}-\x{1064}\x{1067}-\x{106d}\x{1071}-\x{1074}\x{1082}-\x{108d}\x{108f}-\x{109d}\x{135d}-\x{135f}\x{1712}-\x{1714}\x{1732}-\x{1734}\x{1752}\x{1753}\x{1772}\x{1773}\x{17b4}-\x{17d3}\x{17dd}\x{17e0}-\x{17e9}\x{180b}-\x{180d}\x{1810}-\x{1819}\x{18a9}\x{1920}-\x{192b}\x{1930}-\x{193b}\x{1946}-\x{194f}\x{19b0}-\x{19c0}\x{19c8}\x{19c9}\x{19d0}-\x{19d9}\x{1a17}-\x{1a1b}\x{1a55}-\x{1a5e}\x{1a60}-\x{1a7c}\x{1a7f}-\x{1a89}\x{1a90}-\x{1a99}\x{1b00}-\x{1b04}\x{1b34}-\x{1b44}\x{1b50}-\x{1b59}\x{1b6b}-\x{1b73}\x{1b80}-\x{1b82}\x{1ba1}-\x{1bad}\x{1bb0}-\x{1bb9}\x{1be6}-\x{1bf3}\x{1c24}-\x{1c37}\x{1c40}-\x{1c49}\x{1c50}-\x{1c59}\x{1cd0}-\x{1cd2}\x{1cd4}-\x{1ce8}\x{1ced}\x{1cf2}-\x{1cf4}\x{1dc0}-\x{1de6}\x{1dfc}-\x{1dff}\x{200c}\x{200d}\x{203f}\x{2040}\x{2054}\x{20d0}-\x{20dc}\x{20e1}\x{20e5}-\x{20f0}\x{2cef}-\x{2cf1}\x{2d7f}\x{2de0}-\x{2dff}\x{302a}-\x{302f}\x{3099}\x{309a}\x{a620}-\x{a629}\x{a66f}\x{a674}-\x{a67d}\x{a69f}\x{a6f0}\x{a6f1}\x{a802}\x{a806}\x{a80b}\x{a823}-\x{a827}\x{a880}\x{a881}\x{a8b4}-\x{a8c4}\x{a8d0}-\x{a8d9}\x{a8e0}-\x{a8f1}\x{a900}-\x{a909}\x{a926}-\x{a92d}\x{a947}-\x{a953}\x{a980}-\x{a983}\x{a9b3}-\x{a9c0}\x{a9d0}-\x{a9d9}\x{aa29}-\x{aa36}\x{aa43}\x{aa4c}\x{aa4d}\x{aa50}-\x{aa59}\x{aa7b}\x{aab0}\x{aab2}-\x{aab4}\x{aab7}\x{aab8}\x{aabe}\x{aabf}\x{aac1}\x{aaeb}-\x{aaef}\x{aaf5}\x{aaf6}\x{abe3}-\x{abea}\x{abec}\x{abed}\x{abf0}-\x{abf9}\x{fb1e}\x{fe00}-\x{fe0f}\x{fe20}-\x{fe26}\x{fe33}\x{fe34}\x{fe4d}-\x{fe4f}\x{ff10}-\x{ff19}\x{ff3f}]*\b'; |
|
26 | + |
|
27 | + /** |
|
28 | + * Full list of JavaScript reserved words. |
|
29 | + * Will be loaded from /data/js/keywords_reserved.txt. |
|
30 | + * |
|
31 | + * @see https://mathiasbynens.be/notes/reserved-keywords |
|
32 | + * |
|
33 | + * @var string[] |
|
34 | + */ |
|
35 | + protected $keywordsReserved = array(); |
|
36 | + |
|
37 | + /** |
|
38 | + * List of JavaScript reserved words that accept a <variable, value, ...> |
|
39 | + * after them. Some end of lines are not the end of a statement, like with |
|
40 | + * these keywords. |
|
41 | + * |
|
42 | + * E.g.: we shouldn't insert a ; after this else |
|
43 | + * else |
|
44 | + * console.log('this is quite fine') |
|
45 | + * |
|
46 | + * Will be loaded from /data/js/keywords_before.txt |
|
47 | + * |
|
48 | + * @var string[] |
|
49 | + */ |
|
50 | + protected $keywordsBefore = array(); |
|
51 | + |
|
52 | + /** |
|
53 | + * List of JavaScript reserved words that accept a <variable, value, ...> |
|
54 | + * before them. Some end of lines are not the end of a statement, like when |
|
55 | + * continued by one of these keywords on the newline. |
|
56 | + * |
|
57 | + * E.g.: we shouldn't insert a ; before this instanceof |
|
58 | + * variable |
|
59 | + * instanceof String |
|
60 | + * |
|
61 | + * Will be loaded from /data/js/keywords_after.txt |
|
62 | + * |
|
63 | + * @var string[] |
|
64 | + */ |
|
65 | + protected $keywordsAfter = array(); |
|
66 | + |
|
67 | + /** |
|
68 | + * List of JavaScript operators that accept a <variable, value, ...> after |
|
69 | + * them. Some end of lines are not the end of a statement, like with these |
|
70 | + * operators. |
|
71 | + * |
|
72 | + * Note: Most operators are fine, we've only removed !, ++ and --. |
|
73 | + * There can't be a newline separating ! and whatever it is negating. |
|
74 | + * ++ & -- have to be joined with the value they're in-/decrementing. |
|
75 | + * |
|
76 | + * Will be loaded from /data/js/operators_before.txt |
|
77 | + * |
|
78 | + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators |
|
79 | + * |
|
80 | + * @var string[] |
|
81 | + */ |
|
82 | + protected $operatorsBefore = array(); |
|
83 | + |
|
84 | + /** |
|
85 | + * List of JavaScript operators that accept a <variable, value, ...> before |
|
86 | + * them. Some end of lines are not the end of a statement, like when |
|
87 | + * continued by one of these operators on the newline. |
|
88 | + * |
|
89 | + * Note: Most operators are fine, we've only removed ), ], ++ and --. |
|
90 | + * ++ & -- have to be joined with the value they're in-/decrementing. |
|
91 | + * ) & ] are "special" in that they have lots or usecases. () for example |
|
92 | + * is used for function calls, for grouping, in if () and for (), ... |
|
93 | + * |
|
94 | + * Will be loaded from /data/js/operators_after.txt |
|
95 | + * |
|
96 | + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators |
|
97 | + * |
|
98 | + * @var string[] |
|
99 | + */ |
|
100 | + protected $operatorsAfter = array(); |
|
101 | + |
|
102 | + /** |
|
103 | + * {@inheritdoc} |
|
104 | + */ |
|
105 | + public function __construct() |
|
106 | + { |
|
107 | + call_user_func_array(array('parent', '__construct'), func_get_args()); |
|
108 | + |
|
109 | + $dataDir = __DIR__.'/../data/js/'; |
|
110 | + $options = FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES; |
|
111 | + $this->keywordsReserved = file($dataDir.'keywords_reserved.txt', $options); |
|
112 | + $this->keywordsBefore = file($dataDir.'keywords_before.txt', $options); |
|
113 | + $this->keywordsAfter = file($dataDir.'keywords_after.txt', $options); |
|
114 | + $this->operatorsBefore = file($dataDir.'operators_before.txt', $options); |
|
115 | + $this->operatorsAfter = file($dataDir.'operators_after.txt', $options); |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * Minify the data. |
|
120 | + * Perform JS optimizations. |
|
121 | + * |
|
122 | + * @param string[optional] $path Path to write the data to. |
|
123 | + * |
|
124 | + * @return string The minified data. |
|
125 | + */ |
|
126 | + public function execute($path = null) |
|
127 | + { |
|
128 | + $content = ''; |
|
129 | + |
|
130 | + // loop files |
|
131 | + foreach ($this->data as $source => $js) { |
|
132 | + /* |
|
133 | 133 | * Combine js: separating the scripts by a ; |
134 | 134 | * I'm also adding a newline: it will be eaten when whitespace is |
135 | 135 | * stripped, but we need to make sure we're not just appending |
@@ -137,10 +137,10 @@ discard block |
||
137 | 137 | * singe-line comment on the last line (in which case it would also |
138 | 138 | * be seen as part of that comment) |
139 | 139 | */ |
140 | - $content .= $js."\n;"; |
|
141 | - } |
|
140 | + $content .= $js."\n;"; |
|
141 | + } |
|
142 | 142 | |
143 | - /* |
|
143 | + /* |
|
144 | 144 | * Let's first take out strings, comments and regular expressions. |
145 | 145 | * All of these can contain JS code-like characters, and we should make |
146 | 146 | * sure any further magic ignores anything inside of these. |
@@ -151,159 +151,159 @@ discard block |
||
151 | 151 | * Comments will be removed altogether, strings and regular expressions |
152 | 152 | * will be replaced by placeholder text, which we'll restore later. |
153 | 153 | */ |
154 | - $this->extractStrings('\'"`'); |
|
155 | - $this->stripComments(); |
|
156 | - $this->extractRegex(); |
|
157 | - $content = $this->replace($content); |
|
154 | + $this->extractStrings('\'"`'); |
|
155 | + $this->stripComments(); |
|
156 | + $this->extractRegex(); |
|
157 | + $content = $this->replace($content); |
|
158 | 158 | |
159 | - $content = $this->stripWhitespace($content); |
|
160 | - $content = $this->propertyNotation($content); |
|
161 | - $content = $this->shortenBools($content); |
|
159 | + $content = $this->stripWhitespace($content); |
|
160 | + $content = $this->propertyNotation($content); |
|
161 | + $content = $this->shortenBools($content); |
|
162 | 162 | |
163 | - /* |
|
163 | + /* |
|
164 | 164 | * Earlier, we extracted strings & regular expressions and replaced them |
165 | 165 | * with placeholder text. This will restore them. |
166 | 166 | */ |
167 | - $content = $this->restoreExtractedData($content); |
|
168 | - |
|
169 | - return $content; |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * Strip comments from source code. |
|
174 | - */ |
|
175 | - protected function stripComments() |
|
176 | - { |
|
177 | - // single-line comments |
|
178 | - $this->registerPattern('/\/\/.*$/m', ''); |
|
179 | - |
|
180 | - // multi-line comments |
|
181 | - $this->registerPattern('/\/\*.*?\*\//s', ''); |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * JS can have /-delimited regular expressions, like: /ab+c/.match(string). |
|
186 | - * |
|
187 | - * The content inside the regex can contain characters that may be confused |
|
188 | - * for JS code: e.g. it could contain whitespace it needs to match & we |
|
189 | - * don't want to strip whitespace in there. |
|
190 | - * |
|
191 | - * The regex can be pretty simple: we don't have to care about comments, |
|
192 | - * (which also use slashes) because stripComments() will have stripped those |
|
193 | - * already. |
|
194 | - * |
|
195 | - * This method will replace all string content with simple REGEX# |
|
196 | - * placeholder text, so we've rid all regular expressions from characters |
|
197 | - * that may be misinterpreted. Original regex content will be saved in |
|
198 | - * $this->extracted and after doing all other minifying, we can restore the |
|
199 | - * original content via restoreRegex() |
|
200 | - */ |
|
201 | - protected function extractRegex() |
|
202 | - { |
|
203 | - // PHP only supports $this inside anonymous functions since 5.4 |
|
204 | - $minifier = $this; |
|
205 | - $callback = function ($match) use ($minifier) { |
|
206 | - $count = count($minifier->extracted); |
|
207 | - $placeholder = '/'.$count.'/'; |
|
208 | - $minifier->extracted[$placeholder] = $match[1]; |
|
209 | - |
|
210 | - return $placeholder; |
|
211 | - }; |
|
212 | - |
|
213 | - // it's a regex if we can find an opening and (not escaped) closing /, |
|
214 | - // include \n because it may be there for a reason |
|
215 | - // (https://github.com/matthiasmullie/minify/issues/56) |
|
216 | - $pattern = '(\/.*?(?<!\\\\)(\\\\\\\\)*+\/\n?)'; |
|
217 | - |
|
218 | - // / can't be preceded by variable, value, or similar because then |
|
219 | - // it's going to be division |
|
220 | - // checking for that is complex, so we'll do inverse: |
|
221 | - // * at the beginning of the file, it's not division, but regex |
|
222 | - $this->registerPattern('/^\s*\K'.$pattern.'/', $callback); |
|
223 | - // * following another operator, it's not division, but regex |
|
224 | - $operators = $this->getOperatorsForRegex($this->operatorsBefore, '/'); |
|
225 | - $operators += $this->getKeywordsForRegex($this->keywordsReserved, '/'); |
|
226 | - $this->registerPattern('/(?:'.implode('|', $operators).')\s*\K'.$pattern.'/', $callback); |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * Strip whitespace. |
|
231 | - * |
|
232 | - * We won't strip *all* whitespace, but as much as possible. The thing that |
|
233 | - * we'll preserve are newlines we're unsure about. |
|
234 | - * JavaScript doesn't require statements to be terminated with a semicolon. |
|
235 | - * It will automatically fix missing semicolons with ASI (automatic semi- |
|
236 | - * colon insertion) at the end of line causing errors (without semicolon.) |
|
237 | - * |
|
238 | - * Because it's sometimes hard to tell if a newline is part of a statement |
|
239 | - * that should be terminated or not, we'll just leave some of them alone. |
|
240 | - * |
|
241 | - * @param string $content The content to strip the whitespace for. |
|
242 | - * |
|
243 | - * @return string |
|
244 | - */ |
|
245 | - protected function stripWhitespace($content) |
|
246 | - { |
|
247 | - // uniform line endings, make them all line feed |
|
248 | - $content = str_replace(array("\r\n", "\r"), "\n", $content); |
|
249 | - |
|
250 | - // collapse all non-line feed whitespace into a single space |
|
251 | - $content = preg_replace('/[^\S\n]+/', ' ', $content); |
|
252 | - |
|
253 | - // strip leading & trailing whitespace |
|
254 | - $content = str_replace(array(" \n", "\n "), "\n", $content); |
|
255 | - |
|
256 | - // collapse consecutive line feeds into just 1 |
|
257 | - $content = preg_replace('/\n+/', "\n", $content); |
|
258 | - |
|
259 | - $before = $this->getOperatorsForRegex($this->operatorsBefore, '/'); |
|
260 | - $after = $this->getOperatorsForRegex($this->operatorsAfter, '/'); |
|
261 | - $operators = $before + $after; |
|
262 | - |
|
263 | - // strip whitespace that ends in (or next line begin with) an operator |
|
264 | - // that allows statements to be broken up over multiple lines |
|
265 | - unset($before['+'], $before['-'], $after['+'], $after['-']); |
|
266 | - $content = preg_replace( |
|
267 | - array( |
|
268 | - '/('.implode('|', $before).')\s+/', |
|
269 | - '/\s+('.implode('|', $after).')/', |
|
270 | - ), '\\1', $content |
|
271 | - ); |
|
272 | - |
|
273 | - // make sure + and - can't be mistaken for, or joined into ++ and -- |
|
274 | - $content = preg_replace( |
|
275 | - array( |
|
276 | - '/(?<![\+\-])\s*([\+\-])(?![\+\-])/', |
|
277 | - '/(?<![\+\-])([\+\-])\s*(?![\+\-])/', |
|
278 | - ), '\\1', $content |
|
279 | - ); |
|
280 | - |
|
281 | - /* |
|
167 | + $content = $this->restoreExtractedData($content); |
|
168 | + |
|
169 | + return $content; |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * Strip comments from source code. |
|
174 | + */ |
|
175 | + protected function stripComments() |
|
176 | + { |
|
177 | + // single-line comments |
|
178 | + $this->registerPattern('/\/\/.*$/m', ''); |
|
179 | + |
|
180 | + // multi-line comments |
|
181 | + $this->registerPattern('/\/\*.*?\*\//s', ''); |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * JS can have /-delimited regular expressions, like: /ab+c/.match(string). |
|
186 | + * |
|
187 | + * The content inside the regex can contain characters that may be confused |
|
188 | + * for JS code: e.g. it could contain whitespace it needs to match & we |
|
189 | + * don't want to strip whitespace in there. |
|
190 | + * |
|
191 | + * The regex can be pretty simple: we don't have to care about comments, |
|
192 | + * (which also use slashes) because stripComments() will have stripped those |
|
193 | + * already. |
|
194 | + * |
|
195 | + * This method will replace all string content with simple REGEX# |
|
196 | + * placeholder text, so we've rid all regular expressions from characters |
|
197 | + * that may be misinterpreted. Original regex content will be saved in |
|
198 | + * $this->extracted and after doing all other minifying, we can restore the |
|
199 | + * original content via restoreRegex() |
|
200 | + */ |
|
201 | + protected function extractRegex() |
|
202 | + { |
|
203 | + // PHP only supports $this inside anonymous functions since 5.4 |
|
204 | + $minifier = $this; |
|
205 | + $callback = function ($match) use ($minifier) { |
|
206 | + $count = count($minifier->extracted); |
|
207 | + $placeholder = '/'.$count.'/'; |
|
208 | + $minifier->extracted[$placeholder] = $match[1]; |
|
209 | + |
|
210 | + return $placeholder; |
|
211 | + }; |
|
212 | + |
|
213 | + // it's a regex if we can find an opening and (not escaped) closing /, |
|
214 | + // include \n because it may be there for a reason |
|
215 | + // (https://github.com/matthiasmullie/minify/issues/56) |
|
216 | + $pattern = '(\/.*?(?<!\\\\)(\\\\\\\\)*+\/\n?)'; |
|
217 | + |
|
218 | + // / can't be preceded by variable, value, or similar because then |
|
219 | + // it's going to be division |
|
220 | + // checking for that is complex, so we'll do inverse: |
|
221 | + // * at the beginning of the file, it's not division, but regex |
|
222 | + $this->registerPattern('/^\s*\K'.$pattern.'/', $callback); |
|
223 | + // * following another operator, it's not division, but regex |
|
224 | + $operators = $this->getOperatorsForRegex($this->operatorsBefore, '/'); |
|
225 | + $operators += $this->getKeywordsForRegex($this->keywordsReserved, '/'); |
|
226 | + $this->registerPattern('/(?:'.implode('|', $operators).')\s*\K'.$pattern.'/', $callback); |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * Strip whitespace. |
|
231 | + * |
|
232 | + * We won't strip *all* whitespace, but as much as possible. The thing that |
|
233 | + * we'll preserve are newlines we're unsure about. |
|
234 | + * JavaScript doesn't require statements to be terminated with a semicolon. |
|
235 | + * It will automatically fix missing semicolons with ASI (automatic semi- |
|
236 | + * colon insertion) at the end of line causing errors (without semicolon.) |
|
237 | + * |
|
238 | + * Because it's sometimes hard to tell if a newline is part of a statement |
|
239 | + * that should be terminated or not, we'll just leave some of them alone. |
|
240 | + * |
|
241 | + * @param string $content The content to strip the whitespace for. |
|
242 | + * |
|
243 | + * @return string |
|
244 | + */ |
|
245 | + protected function stripWhitespace($content) |
|
246 | + { |
|
247 | + // uniform line endings, make them all line feed |
|
248 | + $content = str_replace(array("\r\n", "\r"), "\n", $content); |
|
249 | + |
|
250 | + // collapse all non-line feed whitespace into a single space |
|
251 | + $content = preg_replace('/[^\S\n]+/', ' ', $content); |
|
252 | + |
|
253 | + // strip leading & trailing whitespace |
|
254 | + $content = str_replace(array(" \n", "\n "), "\n", $content); |
|
255 | + |
|
256 | + // collapse consecutive line feeds into just 1 |
|
257 | + $content = preg_replace('/\n+/', "\n", $content); |
|
258 | + |
|
259 | + $before = $this->getOperatorsForRegex($this->operatorsBefore, '/'); |
|
260 | + $after = $this->getOperatorsForRegex($this->operatorsAfter, '/'); |
|
261 | + $operators = $before + $after; |
|
262 | + |
|
263 | + // strip whitespace that ends in (or next line begin with) an operator |
|
264 | + // that allows statements to be broken up over multiple lines |
|
265 | + unset($before['+'], $before['-'], $after['+'], $after['-']); |
|
266 | + $content = preg_replace( |
|
267 | + array( |
|
268 | + '/('.implode('|', $before).')\s+/', |
|
269 | + '/\s+('.implode('|', $after).')/', |
|
270 | + ), '\\1', $content |
|
271 | + ); |
|
272 | + |
|
273 | + // make sure + and - can't be mistaken for, or joined into ++ and -- |
|
274 | + $content = preg_replace( |
|
275 | + array( |
|
276 | + '/(?<![\+\-])\s*([\+\-])(?![\+\-])/', |
|
277 | + '/(?<![\+\-])([\+\-])\s*(?![\+\-])/', |
|
278 | + ), '\\1', $content |
|
279 | + ); |
|
280 | + |
|
281 | + /* |
|
282 | 282 | * We didn't strip whitespace after a couple of operators because they |
283 | 283 | * could be used in different contexts and we can't be sure it's ok to |
284 | 284 | * strip the newlines. However, we can safely strip any non-line feed |
285 | 285 | * whitespace that follows them. |
286 | 286 | */ |
287 | - $content = preg_replace('/([\}\)\]])[^\S\n]+(?!'.implode('|', $operators).')/', '\\1', $content); |
|
287 | + $content = preg_replace('/([\}\)\]])[^\S\n]+(?!'.implode('|', $operators).')/', '\\1', $content); |
|
288 | 288 | |
289 | - // collapse whitespace around reserved words into single space |
|
290 | - $before = $this->getKeywordsForRegex($this->keywordsBefore, '/'); |
|
291 | - $after = $this->getKeywordsForRegex($this->keywordsAfter, '/'); |
|
292 | - $content = preg_replace('/(^|[;\}\s])\K('.implode('|', $before).')\s+/', '\\2 ', $content); |
|
293 | - $content = preg_replace('/\s+('.implode('|', $after).')(?=([;\{\s]|$))/', ' \\1', $content); |
|
289 | + // collapse whitespace around reserved words into single space |
|
290 | + $before = $this->getKeywordsForRegex($this->keywordsBefore, '/'); |
|
291 | + $after = $this->getKeywordsForRegex($this->keywordsAfter, '/'); |
|
292 | + $content = preg_replace('/(^|[;\}\s])\K('.implode('|', $before).')\s+/', '\\2 ', $content); |
|
293 | + $content = preg_replace('/\s+('.implode('|', $after).')(?=([;\{\s]|$))/', ' \\1', $content); |
|
294 | 294 | |
295 | - /* |
|
295 | + /* |
|
296 | 296 | * Get rid of double semicolons, except where they can be used like: |
297 | 297 | * "for(v=1,_=b;;)", "for(v=1;;v++)" or "for(;;ja||(ja=true))". |
298 | 298 | * I'll safeguard these double semicolons inside for-loops by |
299 | 299 | * temporarily replacing them with an invalid condition: they won't have |
300 | 300 | * a double semicolon and will be easy to spot to restore afterwards. |
301 | 301 | */ |
302 | - $content = preg_replace('/\bfor\(([^;]*);;([^;]*)\)/', 'for(\\1;-;\\2)', $content); |
|
303 | - $content = preg_replace('/;+/', ';', $content); |
|
304 | - $content = preg_replace('/\bfor\(([^;]*);-;([^;]*)\)/', 'for(\\1;;\\2)', $content); |
|
302 | + $content = preg_replace('/\bfor\(([^;]*);;([^;]*)\)/', 'for(\\1;-;\\2)', $content); |
|
303 | + $content = preg_replace('/;+/', ';', $content); |
|
304 | + $content = preg_replace('/\bfor\(([^;]*);-;([^;]*)\)/', 'for(\\1;;\\2)', $content); |
|
305 | 305 | |
306 | - /* |
|
306 | + /* |
|
307 | 307 | * Next, we'll be removing all semicolons where ASI kicks in. |
308 | 308 | * for-loops however, can have an empty body (ending in only a |
309 | 309 | * semicolon), like: `for(i=1;i<3;i++);` |
@@ -313,9 +313,9 @@ discard block |
||
313 | 313 | * I'm going to double that semicolon (if any) so after the next line, |
314 | 314 | * which strips semicolons here & there, we're still left with this one. |
315 | 315 | */ |
316 | - $content = preg_replace('/(for\([^;]*;[^;]*;[^;\{]*\));(\}|$)/s', '\\1;;\\2', $content); |
|
316 | + $content = preg_replace('/(for\([^;]*;[^;]*;[^;\{]*\));(\}|$)/s', '\\1;;\\2', $content); |
|
317 | 317 | |
318 | - /* |
|
318 | + /* |
|
319 | 319 | * We also can't strip empty else-statements. Even though they're |
320 | 320 | * useless and probably shouldn't be in the code in the first place, we |
321 | 321 | * shouldn't be stripping the `;` that follows it as it breaks the code. |
@@ -323,114 +323,114 @@ discard block |
||
323 | 323 | * |
324 | 324 | * @see https://github.com/matthiasmullie/minify/issues/91 |
325 | 325 | */ |
326 | - $content = preg_replace('/else;/s', '', $content); |
|
326 | + $content = preg_replace('/else;/s', '', $content); |
|
327 | 327 | |
328 | - /* |
|
328 | + /* |
|
329 | 329 | * We also don't really want to terminate statements followed by closing |
330 | 330 | * curly braces (which we've ignored completely up until now) or end-of- |
331 | 331 | * script: ASI will kick in here & we're all about minifying. |
332 | 332 | * Semicolons at beginning of the file don't make any sense either. |
333 | 333 | */ |
334 | - $content = preg_replace('/;(\}|$)/s', '\\1', $content); |
|
335 | - $content = ltrim($content, ';'); |
|
336 | - |
|
337 | - // get rid of remaining whitespace af beginning/end |
|
338 | - return trim($content); |
|
339 | - } |
|
340 | - |
|
341 | - /** |
|
342 | - * We'll strip whitespace around certain operators with regular expressions. |
|
343 | - * This will prepare the given array by escaping all characters. |
|
344 | - * |
|
345 | - * @param string[] $operators |
|
346 | - * @param string $delimiter |
|
347 | - * |
|
348 | - * @return string[] |
|
349 | - */ |
|
350 | - protected function getOperatorsForRegex(array $operators, $delimiter = '/') |
|
351 | - { |
|
352 | - // escape operators for use in regex |
|
353 | - $delimiter = array_fill(0, count($operators), $delimiter); |
|
354 | - $escaped = array_map('preg_quote', $operators, $delimiter); |
|
355 | - |
|
356 | - $operators = array_combine($operators, $escaped); |
|
357 | - |
|
358 | - // ignore + & - for now, they'll get special treatment |
|
359 | - unset($operators['+'], $operators['-']); |
|
360 | - |
|
361 | - // dot can not just immediately follow a number; it can be confused for |
|
362 | - // decimal point, or calling a method on it, e.g. 42 .toString() |
|
363 | - $operators['.'] = '(?<![0-9]\s)\.'; |
|
364 | - |
|
365 | - // don't confuse = with other assignment shortcuts (e.g. +=) |
|
366 | - $chars = preg_quote('+-*\=<>%&|'); |
|
367 | - $operators['='] = '(?<!['.$chars.'])\='; |
|
368 | - |
|
369 | - return $operators; |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * We'll strip whitespace around certain keywords with regular expressions. |
|
374 | - * This will prepare the given array by escaping all characters. |
|
375 | - * |
|
376 | - * @param string[] $keywords |
|
377 | - * @param string $delimiter |
|
378 | - * |
|
379 | - * @return string[] |
|
380 | - */ |
|
381 | - protected function getKeywordsForRegex(array $keywords, $delimiter = '/') |
|
382 | - { |
|
383 | - // escape keywords for use in regex |
|
384 | - $delimiter = array_fill(0, count($keywords), $delimiter); |
|
385 | - $escaped = array_map('preg_quote', $keywords, $delimiter); |
|
386 | - |
|
387 | - // add word boundaries |
|
388 | - array_walk($keywords, function ($value) { |
|
389 | - return '\b'.$value.'\b'; |
|
390 | - }); |
|
391 | - |
|
392 | - $keywords = array_combine($keywords, $escaped); |
|
393 | - |
|
394 | - return $keywords; |
|
395 | - } |
|
396 | - |
|
397 | - /** |
|
398 | - * Replaces all occurrences of array['key'] by array.key. |
|
399 | - * |
|
400 | - * @param string $content |
|
401 | - * |
|
402 | - * @return string |
|
403 | - */ |
|
404 | - protected function propertyNotation($content) |
|
405 | - { |
|
406 | - // PHP only supports $this inside anonymous functions since 5.4 |
|
407 | - $minifier = $this; |
|
408 | - $keywords = $this->keywordsReserved; |
|
409 | - $callback = function ($match) use ($minifier, $keywords) { |
|
410 | - $property = trim($minifier->extracted[$match[1]], '\'"'); |
|
411 | - |
|
412 | - /* |
|
334 | + $content = preg_replace('/;(\}|$)/s', '\\1', $content); |
|
335 | + $content = ltrim($content, ';'); |
|
336 | + |
|
337 | + // get rid of remaining whitespace af beginning/end |
|
338 | + return trim($content); |
|
339 | + } |
|
340 | + |
|
341 | + /** |
|
342 | + * We'll strip whitespace around certain operators with regular expressions. |
|
343 | + * This will prepare the given array by escaping all characters. |
|
344 | + * |
|
345 | + * @param string[] $operators |
|
346 | + * @param string $delimiter |
|
347 | + * |
|
348 | + * @return string[] |
|
349 | + */ |
|
350 | + protected function getOperatorsForRegex(array $operators, $delimiter = '/') |
|
351 | + { |
|
352 | + // escape operators for use in regex |
|
353 | + $delimiter = array_fill(0, count($operators), $delimiter); |
|
354 | + $escaped = array_map('preg_quote', $operators, $delimiter); |
|
355 | + |
|
356 | + $operators = array_combine($operators, $escaped); |
|
357 | + |
|
358 | + // ignore + & - for now, they'll get special treatment |
|
359 | + unset($operators['+'], $operators['-']); |
|
360 | + |
|
361 | + // dot can not just immediately follow a number; it can be confused for |
|
362 | + // decimal point, or calling a method on it, e.g. 42 .toString() |
|
363 | + $operators['.'] = '(?<![0-9]\s)\.'; |
|
364 | + |
|
365 | + // don't confuse = with other assignment shortcuts (e.g. +=) |
|
366 | + $chars = preg_quote('+-*\=<>%&|'); |
|
367 | + $operators['='] = '(?<!['.$chars.'])\='; |
|
368 | + |
|
369 | + return $operators; |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * We'll strip whitespace around certain keywords with regular expressions. |
|
374 | + * This will prepare the given array by escaping all characters. |
|
375 | + * |
|
376 | + * @param string[] $keywords |
|
377 | + * @param string $delimiter |
|
378 | + * |
|
379 | + * @return string[] |
|
380 | + */ |
|
381 | + protected function getKeywordsForRegex(array $keywords, $delimiter = '/') |
|
382 | + { |
|
383 | + // escape keywords for use in regex |
|
384 | + $delimiter = array_fill(0, count($keywords), $delimiter); |
|
385 | + $escaped = array_map('preg_quote', $keywords, $delimiter); |
|
386 | + |
|
387 | + // add word boundaries |
|
388 | + array_walk($keywords, function ($value) { |
|
389 | + return '\b'.$value.'\b'; |
|
390 | + }); |
|
391 | + |
|
392 | + $keywords = array_combine($keywords, $escaped); |
|
393 | + |
|
394 | + return $keywords; |
|
395 | + } |
|
396 | + |
|
397 | + /** |
|
398 | + * Replaces all occurrences of array['key'] by array.key. |
|
399 | + * |
|
400 | + * @param string $content |
|
401 | + * |
|
402 | + * @return string |
|
403 | + */ |
|
404 | + protected function propertyNotation($content) |
|
405 | + { |
|
406 | + // PHP only supports $this inside anonymous functions since 5.4 |
|
407 | + $minifier = $this; |
|
408 | + $keywords = $this->keywordsReserved; |
|
409 | + $callback = function ($match) use ($minifier, $keywords) { |
|
410 | + $property = trim($minifier->extracted[$match[1]], '\'"'); |
|
411 | + |
|
412 | + /* |
|
413 | 413 | * Check if the property is a reserved keyword. In this context (as |
414 | 414 | * property of an object literal/array) it shouldn't matter, but IE8 |
415 | 415 | * freaks out with "Expected identifier". |
416 | 416 | */ |
417 | - if (in_array($property, $keywords)) { |
|
418 | - return $match[0]; |
|
419 | - } |
|
417 | + if (in_array($property, $keywords)) { |
|
418 | + return $match[0]; |
|
419 | + } |
|
420 | 420 | |
421 | - /* |
|
421 | + /* |
|
422 | 422 | * See if the property is in a variable-like format (e.g. |
423 | 423 | * array['key-here'] can't be replaced by array.key-here since '-' |
424 | 424 | * is not a valid character there. |
425 | 425 | */ |
426 | - if (!preg_match('/^'.$minifier::REGEX_VARIABLE.'$/u', $property)) { |
|
427 | - return $match[0]; |
|
428 | - } |
|
426 | + if (!preg_match('/^'.$minifier::REGEX_VARIABLE.'$/u', $property)) { |
|
427 | + return $match[0]; |
|
428 | + } |
|
429 | 429 | |
430 | - return '.'.$property; |
|
431 | - }; |
|
430 | + return '.'.$property; |
|
431 | + }; |
|
432 | 432 | |
433 | - /* |
|
433 | + /* |
|
434 | 434 | * Figure out if previous character is a variable name (of the array |
435 | 435 | * we want to use property notation on) - this is to make sure |
436 | 436 | * standalone ['value'] arrays aren't confused for keys-of-an-array. |
@@ -438,61 +438,61 @@ discard block |
||
438 | 438 | * regex implementation doesn't allow unfixed-length look-behind |
439 | 439 | * assertions. |
440 | 440 | */ |
441 | - preg_match('/(\[[^\]]+\])[^\]]*$/', static::REGEX_VARIABLE, $previousChar); |
|
442 | - $previousChar = $previousChar[1]; |
|
441 | + preg_match('/(\[[^\]]+\])[^\]]*$/', static::REGEX_VARIABLE, $previousChar); |
|
442 | + $previousChar = $previousChar[1]; |
|
443 | 443 | |
444 | - /* |
|
444 | + /* |
|
445 | 445 | * Make sure word preceding the ['value'] is not a keyword, e.g. |
446 | 446 | * return['x']. Because -again- PHP's regex implementation doesn't allow |
447 | 447 | * unfixed-length look-behind assertions, I'm just going to do a lot of |
448 | 448 | * separate look-behind assertions, one for each keyword. |
449 | 449 | */ |
450 | - $keywords = $this->getKeywordsForRegex($keywords); |
|
451 | - $keywords = '(?<!'.implode(')(?<!', $keywords).')'; |
|
452 | - |
|
453 | - return preg_replace_callback('/(?<='.$previousChar.'|\])'.$keywords.'\[(([\'"])[0-9]+\\2)\]/u', $callback, $content); |
|
454 | - } |
|
455 | - |
|
456 | - /** |
|
457 | - * Replaces true & false by !0 and !1. |
|
458 | - * |
|
459 | - * @param string $content |
|
460 | - * |
|
461 | - * @return string |
|
462 | - */ |
|
463 | - protected function shortenBools($content) |
|
464 | - { |
|
465 | - $content = preg_replace('/\btrue\b/', '!0', $content); |
|
466 | - $content = preg_replace('/\bfalse\b/', '!1', $content); |
|
467 | - |
|
468 | - // for(;;) is exactly the same as while(true) |
|
469 | - $content = preg_replace('/\bwhile\(!0\){/', 'for(;;){', $content); |
|
470 | - |
|
471 | - // now make sure we didn't turn any do ... while(true) into do ... for(;;) |
|
472 | - preg_match_all('/\bdo\b/', $content, $dos, PREG_OFFSET_CAPTURE | PREG_SET_ORDER); |
|
473 | - |
|
474 | - // go backward to make sure positional offsets aren't altered when $content changes |
|
475 | - $dos = array_reverse($dos); |
|
476 | - foreach ($dos as $do) { |
|
477 | - $offsetDo = $do[0][1]; |
|
478 | - |
|
479 | - // find all `while` (now `for`) following `do`: one of those must be |
|
480 | - // associated with the `do` and be turned back into `while` |
|
481 | - preg_match_all('/\bfor\(;;\)/', $content, $whiles, PREG_OFFSET_CAPTURE | PREG_SET_ORDER, $offsetDo); |
|
482 | - foreach ($whiles as $while) { |
|
483 | - $offsetWhile = $while[0][1]; |
|
484 | - |
|
485 | - $open = substr_count($content, '{', $offsetDo, $offsetWhile - $offsetDo); |
|
486 | - $close = substr_count($content, '}', $offsetDo, $offsetWhile - $offsetDo); |
|
487 | - if ($open === $close) { |
|
488 | - // only restore `while` if amount of `{` and `}` are the same; |
|
489 | - // otherwise, that `for` isn't associated with this `do` |
|
490 | - $content = substr_replace($content, 'while(!0)', $offsetWhile, strlen('for(;;)')); |
|
491 | - break; |
|
492 | - } |
|
493 | - } |
|
494 | - } |
|
495 | - |
|
496 | - return $content; |
|
497 | - } |
|
450 | + $keywords = $this->getKeywordsForRegex($keywords); |
|
451 | + $keywords = '(?<!'.implode(')(?<!', $keywords).')'; |
|
452 | + |
|
453 | + return preg_replace_callback('/(?<='.$previousChar.'|\])'.$keywords.'\[(([\'"])[0-9]+\\2)\]/u', $callback, $content); |
|
454 | + } |
|
455 | + |
|
456 | + /** |
|
457 | + * Replaces true & false by !0 and !1. |
|
458 | + * |
|
459 | + * @param string $content |
|
460 | + * |
|
461 | + * @return string |
|
462 | + */ |
|
463 | + protected function shortenBools($content) |
|
464 | + { |
|
465 | + $content = preg_replace('/\btrue\b/', '!0', $content); |
|
466 | + $content = preg_replace('/\bfalse\b/', '!1', $content); |
|
467 | + |
|
468 | + // for(;;) is exactly the same as while(true) |
|
469 | + $content = preg_replace('/\bwhile\(!0\){/', 'for(;;){', $content); |
|
470 | + |
|
471 | + // now make sure we didn't turn any do ... while(true) into do ... for(;;) |
|
472 | + preg_match_all('/\bdo\b/', $content, $dos, PREG_OFFSET_CAPTURE | PREG_SET_ORDER); |
|
473 | + |
|
474 | + // go backward to make sure positional offsets aren't altered when $content changes |
|
475 | + $dos = array_reverse($dos); |
|
476 | + foreach ($dos as $do) { |
|
477 | + $offsetDo = $do[0][1]; |
|
478 | + |
|
479 | + // find all `while` (now `for`) following `do`: one of those must be |
|
480 | + // associated with the `do` and be turned back into `while` |
|
481 | + preg_match_all('/\bfor\(;;\)/', $content, $whiles, PREG_OFFSET_CAPTURE | PREG_SET_ORDER, $offsetDo); |
|
482 | + foreach ($whiles as $while) { |
|
483 | + $offsetWhile = $while[0][1]; |
|
484 | + |
|
485 | + $open = substr_count($content, '{', $offsetDo, $offsetWhile - $offsetDo); |
|
486 | + $close = substr_count($content, '}', $offsetDo, $offsetWhile - $offsetDo); |
|
487 | + if ($open === $close) { |
|
488 | + // only restore `while` if amount of `{` and `}` are the same; |
|
489 | + // otherwise, that `for` isn't associated with this `do` |
|
490 | + $content = substr_replace($content, 'while(!0)', $offsetWhile, strlen('for(;;)')); |
|
491 | + break; |
|
492 | + } |
|
493 | + } |
|
494 | + } |
|
495 | + |
|
496 | + return $content; |
|
497 | + } |
|
498 | 498 | } |
@@ -106,13 +106,13 @@ discard block |
||
106 | 106 | { |
107 | 107 | call_user_func_array(array('parent', '__construct'), func_get_args()); |
108 | 108 | |
109 | - $dataDir = __DIR__.'/../data/js/'; |
|
109 | + $dataDir = __DIR__ . '/../data/js/'; |
|
110 | 110 | $options = FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES; |
111 | - $this->keywordsReserved = file($dataDir.'keywords_reserved.txt', $options); |
|
112 | - $this->keywordsBefore = file($dataDir.'keywords_before.txt', $options); |
|
113 | - $this->keywordsAfter = file($dataDir.'keywords_after.txt', $options); |
|
114 | - $this->operatorsBefore = file($dataDir.'operators_before.txt', $options); |
|
115 | - $this->operatorsAfter = file($dataDir.'operators_after.txt', $options); |
|
111 | + $this->keywordsReserved = file($dataDir . 'keywords_reserved.txt', $options); |
|
112 | + $this->keywordsBefore = file($dataDir . 'keywords_before.txt', $options); |
|
113 | + $this->keywordsAfter = file($dataDir . 'keywords_after.txt', $options); |
|
114 | + $this->operatorsBefore = file($dataDir . 'operators_before.txt', $options); |
|
115 | + $this->operatorsAfter = file($dataDir . 'operators_after.txt', $options); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * singe-line comment on the last line (in which case it would also |
138 | 138 | * be seen as part of that comment) |
139 | 139 | */ |
140 | - $content .= $js."\n;"; |
|
140 | + $content .= $js . "\n;"; |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | /* |
@@ -202,9 +202,9 @@ discard block |
||
202 | 202 | { |
203 | 203 | // PHP only supports $this inside anonymous functions since 5.4 |
204 | 204 | $minifier = $this; |
205 | - $callback = function ($match) use ($minifier) { |
|
205 | + $callback = function($match) use ($minifier) { |
|
206 | 206 | $count = count($minifier->extracted); |
207 | - $placeholder = '/'.$count.'/'; |
|
207 | + $placeholder = '/' . $count . '/'; |
|
208 | 208 | $minifier->extracted[$placeholder] = $match[1]; |
209 | 209 | |
210 | 210 | return $placeholder; |
@@ -219,11 +219,11 @@ discard block |
||
219 | 219 | // it's going to be division |
220 | 220 | // checking for that is complex, so we'll do inverse: |
221 | 221 | // * at the beginning of the file, it's not division, but regex |
222 | - $this->registerPattern('/^\s*\K'.$pattern.'/', $callback); |
|
222 | + $this->registerPattern('/^\s*\K' . $pattern . '/', $callback); |
|
223 | 223 | // * following another operator, it's not division, but regex |
224 | 224 | $operators = $this->getOperatorsForRegex($this->operatorsBefore, '/'); |
225 | 225 | $operators += $this->getKeywordsForRegex($this->keywordsReserved, '/'); |
226 | - $this->registerPattern('/(?:'.implode('|', $operators).')\s*\K'.$pattern.'/', $callback); |
|
226 | + $this->registerPattern('/(?:' . implode('|', $operators) . ')\s*\K' . $pattern . '/', $callback); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
@@ -265,8 +265,8 @@ discard block |
||
265 | 265 | unset($before['+'], $before['-'], $after['+'], $after['-']); |
266 | 266 | $content = preg_replace( |
267 | 267 | array( |
268 | - '/('.implode('|', $before).')\s+/', |
|
269 | - '/\s+('.implode('|', $after).')/', |
|
268 | + '/(' . implode('|', $before) . ')\s+/', |
|
269 | + '/\s+(' . implode('|', $after) . ')/', |
|
270 | 270 | ), '\\1', $content |
271 | 271 | ); |
272 | 272 | |
@@ -284,13 +284,13 @@ discard block |
||
284 | 284 | * strip the newlines. However, we can safely strip any non-line feed |
285 | 285 | * whitespace that follows them. |
286 | 286 | */ |
287 | - $content = preg_replace('/([\}\)\]])[^\S\n]+(?!'.implode('|', $operators).')/', '\\1', $content); |
|
287 | + $content = preg_replace('/([\}\)\]])[^\S\n]+(?!' . implode('|', $operators) . ')/', '\\1', $content); |
|
288 | 288 | |
289 | 289 | // collapse whitespace around reserved words into single space |
290 | 290 | $before = $this->getKeywordsForRegex($this->keywordsBefore, '/'); |
291 | 291 | $after = $this->getKeywordsForRegex($this->keywordsAfter, '/'); |
292 | - $content = preg_replace('/(^|[;\}\s])\K('.implode('|', $before).')\s+/', '\\2 ', $content); |
|
293 | - $content = preg_replace('/\s+('.implode('|', $after).')(?=([;\{\s]|$))/', ' \\1', $content); |
|
292 | + $content = preg_replace('/(^|[;\}\s])\K(' . implode('|', $before) . ')\s+/', '\\2 ', $content); |
|
293 | + $content = preg_replace('/\s+(' . implode('|', $after) . ')(?=([;\{\s]|$))/', ' \\1', $content); |
|
294 | 294 | |
295 | 295 | /* |
296 | 296 | * Get rid of double semicolons, except where they can be used like: |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | |
365 | 365 | // don't confuse = with other assignment shortcuts (e.g. +=) |
366 | 366 | $chars = preg_quote('+-*\=<>%&|'); |
367 | - $operators['='] = '(?<!['.$chars.'])\='; |
|
367 | + $operators['='] = '(?<![' . $chars . '])\='; |
|
368 | 368 | |
369 | 369 | return $operators; |
370 | 370 | } |
@@ -385,8 +385,8 @@ discard block |
||
385 | 385 | $escaped = array_map('preg_quote', $keywords, $delimiter); |
386 | 386 | |
387 | 387 | // add word boundaries |
388 | - array_walk($keywords, function ($value) { |
|
389 | - return '\b'.$value.'\b'; |
|
388 | + array_walk($keywords, function($value) { |
|
389 | + return '\b' . $value . '\b'; |
|
390 | 390 | }); |
391 | 391 | |
392 | 392 | $keywords = array_combine($keywords, $escaped); |
@@ -406,7 +406,7 @@ discard block |
||
406 | 406 | // PHP only supports $this inside anonymous functions since 5.4 |
407 | 407 | $minifier = $this; |
408 | 408 | $keywords = $this->keywordsReserved; |
409 | - $callback = function ($match) use ($minifier, $keywords) { |
|
409 | + $callback = function($match) use ($minifier, $keywords) { |
|
410 | 410 | $property = trim($minifier->extracted[$match[1]], '\'"'); |
411 | 411 | |
412 | 412 | /* |
@@ -423,11 +423,11 @@ discard block |
||
423 | 423 | * array['key-here'] can't be replaced by array.key-here since '-' |
424 | 424 | * is not a valid character there. |
425 | 425 | */ |
426 | - if (!preg_match('/^'.$minifier::REGEX_VARIABLE.'$/u', $property)) { |
|
426 | + if (!preg_match('/^' . $minifier::REGEX_VARIABLE . '$/u', $property)) { |
|
427 | 427 | return $match[0]; |
428 | 428 | } |
429 | 429 | |
430 | - return '.'.$property; |
|
430 | + return '.' . $property; |
|
431 | 431 | }; |
432 | 432 | |
433 | 433 | /* |
@@ -448,9 +448,9 @@ discard block |
||
448 | 448 | * separate look-behind assertions, one for each keyword. |
449 | 449 | */ |
450 | 450 | $keywords = $this->getKeywordsForRegex($keywords); |
451 | - $keywords = '(?<!'.implode(')(?<!', $keywords).')'; |
|
451 | + $keywords = '(?<!' . implode(')(?<!', $keywords) . ')'; |
|
452 | 452 | |
453 | - return preg_replace_callback('/(?<='.$previousChar.'|\])'.$keywords.'\[(([\'"])[0-9]+\\2)\]/u', $callback, $content); |
|
453 | + return preg_replace_callback('/(?<=' . $previousChar . '|\])' . $keywords . '\[(([\'"])[0-9]+\\2)\]/u', $callback, $content); |
|
454 | 454 | } |
455 | 455 | |
456 | 456 | /** |
@@ -16,326 +16,326 @@ discard block |
||
16 | 16 | */ |
17 | 17 | abstract class Minify |
18 | 18 | { |
19 | - /** |
|
20 | - * The data to be minified. |
|
21 | - * |
|
22 | - * @var string[] |
|
23 | - */ |
|
24 | - protected $data = array(); |
|
25 | - |
|
26 | - /** |
|
27 | - * Array of patterns to match. |
|
28 | - * |
|
29 | - * @var string[] |
|
30 | - */ |
|
31 | - protected $patterns = array(); |
|
32 | - |
|
33 | - /** |
|
34 | - * This array will hold content of strings and regular expressions that have |
|
35 | - * been extracted from the JS source code, so we can reliably match "code", |
|
36 | - * without having to worry about potential "code-like" characters inside. |
|
37 | - * |
|
38 | - * @var string[] |
|
39 | - */ |
|
40 | - public $extracted = array(); |
|
41 | - |
|
42 | - /** |
|
43 | - * Init the minify class - optionally, code may be passed along already. |
|
44 | - */ |
|
45 | - public function __construct(/* $data = null, ... */) |
|
46 | - { |
|
47 | - // it's possible to add the source through the constructor as well ;) |
|
48 | - if (func_num_args()) { |
|
49 | - call_user_func_array(array($this, 'add'), func_get_args()); |
|
50 | - } |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Add a file or straight-up code to be minified. |
|
55 | - * |
|
56 | - * @param string $data |
|
57 | - */ |
|
58 | - public function add($data /* $data = null, ... */) |
|
59 | - { |
|
60 | - // bogus "usage" of parameter $data: scrutinizer warns this variable is |
|
61 | - // not used (we're using func_get_args instead to support overloading), |
|
62 | - // but it still needs to be defined because it makes no sense to have |
|
63 | - // this function without argument :) |
|
64 | - $args = array($data) + func_get_args(); |
|
65 | - |
|
66 | - // this method can be overloaded |
|
67 | - foreach ($args as $data) { |
|
68 | - // redefine var |
|
69 | - $data = (string) $data; |
|
70 | - |
|
71 | - // load data |
|
72 | - $value = $this->load($data); |
|
73 | - $key = ($data != $value) ? $data : count($this->data); |
|
74 | - |
|
75 | - // store data |
|
76 | - $this->data[$key] = $value; |
|
77 | - } |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Minify the data & (optionally) saves it to a file. |
|
82 | - * |
|
83 | - * @param string[optional] $path Path to write the data to. |
|
84 | - * |
|
85 | - * @return string The minified data. |
|
86 | - */ |
|
87 | - public function minify($path = null) |
|
88 | - { |
|
89 | - $content = $this->execute($path); |
|
90 | - |
|
91 | - // save to path |
|
92 | - if ($path !== null) { |
|
93 | - $this->save($content, $path); |
|
94 | - } |
|
95 | - |
|
96 | - return $content; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Minify & gzip the data & (optionally) saves it to a file. |
|
101 | - * |
|
102 | - * @param string[optional] $path Path to write the data to. |
|
103 | - * @param int[optional] $level Compression level, from 0 to 9. |
|
104 | - * |
|
105 | - * @return string The minified & gzipped data. |
|
106 | - */ |
|
107 | - public function gzip($path = null, $level = 9) |
|
108 | - { |
|
109 | - $content = $this->execute($path); |
|
110 | - $content = gzencode($content, $level, FORCE_GZIP); |
|
111 | - |
|
112 | - // save to path |
|
113 | - if ($path !== null) { |
|
114 | - $this->save($content, $path); |
|
115 | - } |
|
116 | - |
|
117 | - return $content; |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Minify the data & write it to a CacheItemInterface object. |
|
122 | - * |
|
123 | - * @param CacheItemInterface $item Cache item to write the data to. |
|
124 | - * |
|
125 | - * @return CacheItemInterface Cache item with the minifier data. |
|
126 | - */ |
|
127 | - public function cache(CacheItemInterface $item) |
|
128 | - { |
|
129 | - $content = $this->execute(); |
|
130 | - $item->set($content); |
|
131 | - |
|
132 | - return $item; |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Minify the data. |
|
137 | - * |
|
138 | - * @param string[optional] $path Path to write the data to. |
|
139 | - * |
|
140 | - * @return string The minified data. |
|
141 | - */ |
|
142 | - abstract public function execute($path = null); |
|
143 | - |
|
144 | - /** |
|
145 | - * Load data. |
|
146 | - * |
|
147 | - * @param string $data Either a path to a file or the content itself. |
|
148 | - * |
|
149 | - * @return string |
|
150 | - */ |
|
151 | - protected function load($data) |
|
152 | - { |
|
153 | - // check if the data is a file |
|
154 | - if ($this->canImportFile($data)) { |
|
155 | - $data = file_get_contents($data); |
|
156 | - |
|
157 | - // strip BOM, if any |
|
158 | - if (substr($data, 0, 3) == "\xef\xbb\xbf") { |
|
159 | - $data = substr($data, 3); |
|
160 | - } |
|
161 | - } |
|
162 | - |
|
163 | - return $data; |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * Save to file. |
|
168 | - * |
|
169 | - * @param string $content The minified data. |
|
170 | - * @param string $path The path to save the minified data to. |
|
171 | - * |
|
172 | - * @throws IOException |
|
173 | - */ |
|
174 | - protected function save($content, $path) |
|
175 | - { |
|
176 | - $handler = $this->openFileForWriting($path); |
|
177 | - |
|
178 | - $this->writeToFile($handler, $content); |
|
179 | - |
|
180 | - @fclose($handler); |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * Register a pattern to execute against the source content. |
|
185 | - * |
|
186 | - * @param string $pattern PCRE pattern. |
|
187 | - * @param string|callable $replacement Replacement value for matched pattern. |
|
188 | - */ |
|
189 | - protected function registerPattern($pattern, $replacement = '') |
|
190 | - { |
|
191 | - // study the pattern, we'll execute it more than once |
|
192 | - $pattern .= 'S'; |
|
193 | - |
|
194 | - $this->patterns[] = array($pattern, $replacement); |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * We can't "just" run some regular expressions against JavaScript: it's a |
|
199 | - * complex language. E.g. having an occurrence of // xyz would be a comment, |
|
200 | - * unless it's used within a string. Of you could have something that looks |
|
201 | - * like a 'string', but inside a comment. |
|
202 | - * The only way to accurately replace these pieces is to traverse the JS one |
|
203 | - * character at a time and try to find whatever starts first. |
|
204 | - * |
|
205 | - * @param string $content The content to replace patterns in. |
|
206 | - * |
|
207 | - * @return string The (manipulated) content. |
|
208 | - */ |
|
209 | - protected function replace($content) |
|
210 | - { |
|
211 | - $processed = ''; |
|
212 | - $positions = array_fill(0, count($this->patterns), -1); |
|
213 | - $matches = array(); |
|
214 | - |
|
215 | - while ($content) { |
|
216 | - // find first match for all patterns |
|
217 | - foreach ($this->patterns as $i => $pattern) { |
|
218 | - list($pattern, $replacement) = $pattern; |
|
219 | - |
|
220 | - // no need to re-run matches that are still in the part of the |
|
221 | - // content that hasn't been processed |
|
222 | - if ($positions[$i] >= 0) { |
|
223 | - continue; |
|
224 | - } |
|
225 | - |
|
226 | - $match = null; |
|
227 | - if (preg_match($pattern, $content, $match)) { |
|
228 | - $matches[$i] = $match; |
|
229 | - |
|
230 | - // we'll store the match position as well; that way, we |
|
231 | - // don't have to redo all preg_matches after changing only |
|
232 | - // the first (we'll still know where those others are) |
|
233 | - $positions[$i] = strpos($content, $match[0]); |
|
234 | - } else { |
|
235 | - // if the pattern couldn't be matched, there's no point in |
|
236 | - // executing it again in later runs on this same content; |
|
237 | - // ignore this one until we reach end of content |
|
238 | - unset($matches[$i]); |
|
239 | - $positions[$i] = strlen($content); |
|
240 | - } |
|
241 | - } |
|
242 | - |
|
243 | - // no more matches to find: everything's been processed, break out |
|
244 | - if (!$matches) { |
|
245 | - $processed .= $content; |
|
246 | - break; |
|
247 | - } |
|
248 | - |
|
249 | - // see which of the patterns actually found the first thing (we'll |
|
250 | - // only want to execute that one, since we're unsure if what the |
|
251 | - // other found was not inside what the first found) |
|
252 | - $discardLength = min($positions); |
|
253 | - $firstPattern = array_search($discardLength, $positions); |
|
254 | - $match = $matches[$firstPattern][0]; |
|
255 | - |
|
256 | - // execute the pattern that matches earliest in the content string |
|
257 | - list($pattern, $replacement) = $this->patterns[$firstPattern]; |
|
258 | - $replacement = $this->replacePattern($pattern, $replacement, $content); |
|
259 | - |
|
260 | - // figure out which part of the string was unmatched; that's the |
|
261 | - // part we'll execute the patterns on again next |
|
262 | - $content = substr($content, $discardLength); |
|
263 | - $unmatched = (string) substr($content, strpos($content, $match) + strlen($match)); |
|
264 | - |
|
265 | - // move the replaced part to $processed and prepare $content to |
|
266 | - // again match batch of patterns against |
|
267 | - $processed .= substr($replacement, 0, strlen($replacement) - strlen($unmatched)); |
|
268 | - $content = $unmatched; |
|
269 | - |
|
270 | - // first match has been replaced & that content is to be left alone, |
|
271 | - // the next matches will start after this replacement, so we should |
|
272 | - // fix their offsets |
|
273 | - foreach ($positions as $i => $position) { |
|
274 | - $positions[$i] -= $discardLength + strlen($match); |
|
275 | - } |
|
276 | - } |
|
277 | - |
|
278 | - return $processed; |
|
279 | - } |
|
280 | - |
|
281 | - /** |
|
282 | - * This is where a pattern is matched against $content and the matches |
|
283 | - * are replaced by their respective value. |
|
284 | - * This function will be called plenty of times, where $content will always |
|
285 | - * move up 1 character. |
|
286 | - * |
|
287 | - * @param string $pattern Pattern to match. |
|
288 | - * @param string|callable $replacement Replacement value. |
|
289 | - * @param string $content Content to match pattern against. |
|
290 | - * |
|
291 | - * @return string |
|
292 | - */ |
|
293 | - protected function replacePattern($pattern, $replacement, $content) |
|
294 | - { |
|
295 | - if (is_callable($replacement)) { |
|
296 | - return preg_replace_callback($pattern, $replacement, $content, 1, $count); |
|
297 | - } else { |
|
298 | - return preg_replace($pattern, $replacement, $content, 1, $count); |
|
299 | - } |
|
300 | - } |
|
301 | - |
|
302 | - /** |
|
303 | - * Strings are a pattern we need to match, in order to ignore potential |
|
304 | - * code-like content inside them, but we just want all of the string |
|
305 | - * content to remain untouched. |
|
306 | - * |
|
307 | - * This method will replace all string content with simple STRING# |
|
308 | - * placeholder text, so we've rid all strings from characters that may be |
|
309 | - * misinterpreted. Original string content will be saved in $this->extracted |
|
310 | - * and after doing all other minifying, we can restore the original content |
|
311 | - * via restoreStrings(). |
|
312 | - * |
|
313 | - * @param string[optional] $chars |
|
314 | - */ |
|
315 | - protected function extractStrings($chars = '\'"') |
|
316 | - { |
|
317 | - // PHP only supports $this inside anonymous functions since 5.4 |
|
318 | - $minifier = $this; |
|
319 | - $callback = function ($match) use ($minifier) { |
|
320 | - // check the second index here, because the first always contains a quote |
|
321 | - if (!$match[2]) { |
|
322 | - /* |
|
19 | + /** |
|
20 | + * The data to be minified. |
|
21 | + * |
|
22 | + * @var string[] |
|
23 | + */ |
|
24 | + protected $data = array(); |
|
25 | + |
|
26 | + /** |
|
27 | + * Array of patterns to match. |
|
28 | + * |
|
29 | + * @var string[] |
|
30 | + */ |
|
31 | + protected $patterns = array(); |
|
32 | + |
|
33 | + /** |
|
34 | + * This array will hold content of strings and regular expressions that have |
|
35 | + * been extracted from the JS source code, so we can reliably match "code", |
|
36 | + * without having to worry about potential "code-like" characters inside. |
|
37 | + * |
|
38 | + * @var string[] |
|
39 | + */ |
|
40 | + public $extracted = array(); |
|
41 | + |
|
42 | + /** |
|
43 | + * Init the minify class - optionally, code may be passed along already. |
|
44 | + */ |
|
45 | + public function __construct(/* $data = null, ... */) |
|
46 | + { |
|
47 | + // it's possible to add the source through the constructor as well ;) |
|
48 | + if (func_num_args()) { |
|
49 | + call_user_func_array(array($this, 'add'), func_get_args()); |
|
50 | + } |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Add a file or straight-up code to be minified. |
|
55 | + * |
|
56 | + * @param string $data |
|
57 | + */ |
|
58 | + public function add($data /* $data = null, ... */) |
|
59 | + { |
|
60 | + // bogus "usage" of parameter $data: scrutinizer warns this variable is |
|
61 | + // not used (we're using func_get_args instead to support overloading), |
|
62 | + // but it still needs to be defined because it makes no sense to have |
|
63 | + // this function without argument :) |
|
64 | + $args = array($data) + func_get_args(); |
|
65 | + |
|
66 | + // this method can be overloaded |
|
67 | + foreach ($args as $data) { |
|
68 | + // redefine var |
|
69 | + $data = (string) $data; |
|
70 | + |
|
71 | + // load data |
|
72 | + $value = $this->load($data); |
|
73 | + $key = ($data != $value) ? $data : count($this->data); |
|
74 | + |
|
75 | + // store data |
|
76 | + $this->data[$key] = $value; |
|
77 | + } |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Minify the data & (optionally) saves it to a file. |
|
82 | + * |
|
83 | + * @param string[optional] $path Path to write the data to. |
|
84 | + * |
|
85 | + * @return string The minified data. |
|
86 | + */ |
|
87 | + public function minify($path = null) |
|
88 | + { |
|
89 | + $content = $this->execute($path); |
|
90 | + |
|
91 | + // save to path |
|
92 | + if ($path !== null) { |
|
93 | + $this->save($content, $path); |
|
94 | + } |
|
95 | + |
|
96 | + return $content; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Minify & gzip the data & (optionally) saves it to a file. |
|
101 | + * |
|
102 | + * @param string[optional] $path Path to write the data to. |
|
103 | + * @param int[optional] $level Compression level, from 0 to 9. |
|
104 | + * |
|
105 | + * @return string The minified & gzipped data. |
|
106 | + */ |
|
107 | + public function gzip($path = null, $level = 9) |
|
108 | + { |
|
109 | + $content = $this->execute($path); |
|
110 | + $content = gzencode($content, $level, FORCE_GZIP); |
|
111 | + |
|
112 | + // save to path |
|
113 | + if ($path !== null) { |
|
114 | + $this->save($content, $path); |
|
115 | + } |
|
116 | + |
|
117 | + return $content; |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Minify the data & write it to a CacheItemInterface object. |
|
122 | + * |
|
123 | + * @param CacheItemInterface $item Cache item to write the data to. |
|
124 | + * |
|
125 | + * @return CacheItemInterface Cache item with the minifier data. |
|
126 | + */ |
|
127 | + public function cache(CacheItemInterface $item) |
|
128 | + { |
|
129 | + $content = $this->execute(); |
|
130 | + $item->set($content); |
|
131 | + |
|
132 | + return $item; |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Minify the data. |
|
137 | + * |
|
138 | + * @param string[optional] $path Path to write the data to. |
|
139 | + * |
|
140 | + * @return string The minified data. |
|
141 | + */ |
|
142 | + abstract public function execute($path = null); |
|
143 | + |
|
144 | + /** |
|
145 | + * Load data. |
|
146 | + * |
|
147 | + * @param string $data Either a path to a file or the content itself. |
|
148 | + * |
|
149 | + * @return string |
|
150 | + */ |
|
151 | + protected function load($data) |
|
152 | + { |
|
153 | + // check if the data is a file |
|
154 | + if ($this->canImportFile($data)) { |
|
155 | + $data = file_get_contents($data); |
|
156 | + |
|
157 | + // strip BOM, if any |
|
158 | + if (substr($data, 0, 3) == "\xef\xbb\xbf") { |
|
159 | + $data = substr($data, 3); |
|
160 | + } |
|
161 | + } |
|
162 | + |
|
163 | + return $data; |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * Save to file. |
|
168 | + * |
|
169 | + * @param string $content The minified data. |
|
170 | + * @param string $path The path to save the minified data to. |
|
171 | + * |
|
172 | + * @throws IOException |
|
173 | + */ |
|
174 | + protected function save($content, $path) |
|
175 | + { |
|
176 | + $handler = $this->openFileForWriting($path); |
|
177 | + |
|
178 | + $this->writeToFile($handler, $content); |
|
179 | + |
|
180 | + @fclose($handler); |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * Register a pattern to execute against the source content. |
|
185 | + * |
|
186 | + * @param string $pattern PCRE pattern. |
|
187 | + * @param string|callable $replacement Replacement value for matched pattern. |
|
188 | + */ |
|
189 | + protected function registerPattern($pattern, $replacement = '') |
|
190 | + { |
|
191 | + // study the pattern, we'll execute it more than once |
|
192 | + $pattern .= 'S'; |
|
193 | + |
|
194 | + $this->patterns[] = array($pattern, $replacement); |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * We can't "just" run some regular expressions against JavaScript: it's a |
|
199 | + * complex language. E.g. having an occurrence of // xyz would be a comment, |
|
200 | + * unless it's used within a string. Of you could have something that looks |
|
201 | + * like a 'string', but inside a comment. |
|
202 | + * The only way to accurately replace these pieces is to traverse the JS one |
|
203 | + * character at a time and try to find whatever starts first. |
|
204 | + * |
|
205 | + * @param string $content The content to replace patterns in. |
|
206 | + * |
|
207 | + * @return string The (manipulated) content. |
|
208 | + */ |
|
209 | + protected function replace($content) |
|
210 | + { |
|
211 | + $processed = ''; |
|
212 | + $positions = array_fill(0, count($this->patterns), -1); |
|
213 | + $matches = array(); |
|
214 | + |
|
215 | + while ($content) { |
|
216 | + // find first match for all patterns |
|
217 | + foreach ($this->patterns as $i => $pattern) { |
|
218 | + list($pattern, $replacement) = $pattern; |
|
219 | + |
|
220 | + // no need to re-run matches that are still in the part of the |
|
221 | + // content that hasn't been processed |
|
222 | + if ($positions[$i] >= 0) { |
|
223 | + continue; |
|
224 | + } |
|
225 | + |
|
226 | + $match = null; |
|
227 | + if (preg_match($pattern, $content, $match)) { |
|
228 | + $matches[$i] = $match; |
|
229 | + |
|
230 | + // we'll store the match position as well; that way, we |
|
231 | + // don't have to redo all preg_matches after changing only |
|
232 | + // the first (we'll still know where those others are) |
|
233 | + $positions[$i] = strpos($content, $match[0]); |
|
234 | + } else { |
|
235 | + // if the pattern couldn't be matched, there's no point in |
|
236 | + // executing it again in later runs on this same content; |
|
237 | + // ignore this one until we reach end of content |
|
238 | + unset($matches[$i]); |
|
239 | + $positions[$i] = strlen($content); |
|
240 | + } |
|
241 | + } |
|
242 | + |
|
243 | + // no more matches to find: everything's been processed, break out |
|
244 | + if (!$matches) { |
|
245 | + $processed .= $content; |
|
246 | + break; |
|
247 | + } |
|
248 | + |
|
249 | + // see which of the patterns actually found the first thing (we'll |
|
250 | + // only want to execute that one, since we're unsure if what the |
|
251 | + // other found was not inside what the first found) |
|
252 | + $discardLength = min($positions); |
|
253 | + $firstPattern = array_search($discardLength, $positions); |
|
254 | + $match = $matches[$firstPattern][0]; |
|
255 | + |
|
256 | + // execute the pattern that matches earliest in the content string |
|
257 | + list($pattern, $replacement) = $this->patterns[$firstPattern]; |
|
258 | + $replacement = $this->replacePattern($pattern, $replacement, $content); |
|
259 | + |
|
260 | + // figure out which part of the string was unmatched; that's the |
|
261 | + // part we'll execute the patterns on again next |
|
262 | + $content = substr($content, $discardLength); |
|
263 | + $unmatched = (string) substr($content, strpos($content, $match) + strlen($match)); |
|
264 | + |
|
265 | + // move the replaced part to $processed and prepare $content to |
|
266 | + // again match batch of patterns against |
|
267 | + $processed .= substr($replacement, 0, strlen($replacement) - strlen($unmatched)); |
|
268 | + $content = $unmatched; |
|
269 | + |
|
270 | + // first match has been replaced & that content is to be left alone, |
|
271 | + // the next matches will start after this replacement, so we should |
|
272 | + // fix their offsets |
|
273 | + foreach ($positions as $i => $position) { |
|
274 | + $positions[$i] -= $discardLength + strlen($match); |
|
275 | + } |
|
276 | + } |
|
277 | + |
|
278 | + return $processed; |
|
279 | + } |
|
280 | + |
|
281 | + /** |
|
282 | + * This is where a pattern is matched against $content and the matches |
|
283 | + * are replaced by their respective value. |
|
284 | + * This function will be called plenty of times, where $content will always |
|
285 | + * move up 1 character. |
|
286 | + * |
|
287 | + * @param string $pattern Pattern to match. |
|
288 | + * @param string|callable $replacement Replacement value. |
|
289 | + * @param string $content Content to match pattern against. |
|
290 | + * |
|
291 | + * @return string |
|
292 | + */ |
|
293 | + protected function replacePattern($pattern, $replacement, $content) |
|
294 | + { |
|
295 | + if (is_callable($replacement)) { |
|
296 | + return preg_replace_callback($pattern, $replacement, $content, 1, $count); |
|
297 | + } else { |
|
298 | + return preg_replace($pattern, $replacement, $content, 1, $count); |
|
299 | + } |
|
300 | + } |
|
301 | + |
|
302 | + /** |
|
303 | + * Strings are a pattern we need to match, in order to ignore potential |
|
304 | + * code-like content inside them, but we just want all of the string |
|
305 | + * content to remain untouched. |
|
306 | + * |
|
307 | + * This method will replace all string content with simple STRING# |
|
308 | + * placeholder text, so we've rid all strings from characters that may be |
|
309 | + * misinterpreted. Original string content will be saved in $this->extracted |
|
310 | + * and after doing all other minifying, we can restore the original content |
|
311 | + * via restoreStrings(). |
|
312 | + * |
|
313 | + * @param string[optional] $chars |
|
314 | + */ |
|
315 | + protected function extractStrings($chars = '\'"') |
|
316 | + { |
|
317 | + // PHP only supports $this inside anonymous functions since 5.4 |
|
318 | + $minifier = $this; |
|
319 | + $callback = function ($match) use ($minifier) { |
|
320 | + // check the second index here, because the first always contains a quote |
|
321 | + if (!$match[2]) { |
|
322 | + /* |
|
323 | 323 | * Empty strings need no placeholder; they can't be confused for |
324 | 324 | * anything else anyway. |
325 | 325 | * But we still needed to match them, for the extraction routine |
326 | 326 | * to skip over this particular string. |
327 | 327 | */ |
328 | - return $match[0]; |
|
329 | - } |
|
328 | + return $match[0]; |
|
329 | + } |
|
330 | 330 | |
331 | - $count = count($minifier->extracted); |
|
332 | - $placeholder = $match[1].$count.$match[1]; |
|
333 | - $minifier->extracted[$placeholder] = $match[1].$match[2].$match[1]; |
|
331 | + $count = count($minifier->extracted); |
|
332 | + $placeholder = $match[1].$count.$match[1]; |
|
333 | + $minifier->extracted[$placeholder] = $match[1].$match[2].$match[1]; |
|
334 | 334 | |
335 | - return $placeholder; |
|
336 | - }; |
|
335 | + return $placeholder; |
|
336 | + }; |
|
337 | 337 | |
338 | - /* |
|
338 | + /* |
|
339 | 339 | * The \\ messiness explained: |
340 | 340 | * * Don't count ' or " as end-of-string if it's escaped (has backslash |
341 | 341 | * in front of it) |
@@ -347,75 +347,75 @@ discard block |
||
347 | 347 | * considered as escape-char (times 2) and to get it in the regex, |
348 | 348 | * escaped (times 2) |
349 | 349 | */ |
350 | - $this->registerPattern('/(['.$chars.'])(.*?(?<!\\\\)(\\\\\\\\)*+)\\1/s', $callback); |
|
351 | - } |
|
352 | - |
|
353 | - /** |
|
354 | - * This method will restore all extracted data (strings, regexes) that were |
|
355 | - * replaced with placeholder text in extract*(). The original content was |
|
356 | - * saved in $this->extracted. |
|
357 | - * |
|
358 | - * @param string $content |
|
359 | - * |
|
360 | - * @return string |
|
361 | - */ |
|
362 | - protected function restoreExtractedData($content) |
|
363 | - { |
|
364 | - if (!$this->extracted) { |
|
365 | - // nothing was extracted, nothing to restore |
|
366 | - return $content; |
|
367 | - } |
|
368 | - |
|
369 | - $content = strtr($content, $this->extracted); |
|
370 | - |
|
371 | - $this->extracted = array(); |
|
372 | - |
|
373 | - return $content; |
|
374 | - } |
|
375 | - |
|
376 | - /** |
|
377 | - * Check if the path is a regular file and can be read. |
|
378 | - * |
|
379 | - * @param string $path |
|
380 | - * |
|
381 | - * @return bool |
|
382 | - */ |
|
383 | - protected function canImportFile($path) |
|
384 | - { |
|
385 | - return strlen($path) < PHP_MAXPATHLEN && is_file($path) && is_readable($path); |
|
386 | - } |
|
387 | - |
|
388 | - /** |
|
389 | - * Attempts to open file specified by $path for writing. |
|
390 | - * |
|
391 | - * @param string $path The path to the file. |
|
392 | - * |
|
393 | - * @return resource Specifier for the target file. |
|
394 | - * |
|
395 | - * @throws IOException |
|
396 | - */ |
|
397 | - protected function openFileForWriting($path) |
|
398 | - { |
|
399 | - if (($handler = @fopen($path, 'w')) === false) { |
|
400 | - throw new IOException('The file "'.$path.'" could not be opened for writing. Check if PHP has enough permissions.'); |
|
401 | - } |
|
402 | - |
|
403 | - return $handler; |
|
404 | - } |
|
405 | - |
|
406 | - /** |
|
407 | - * Attempts to write $content to the file specified by $handler. $path is used for printing exceptions. |
|
408 | - * |
|
409 | - * @param resource $handler The resource to write to. |
|
410 | - * @param string $content The content to write. |
|
411 | - * @param string $path The path to the file (for exception printing only). |
|
412 | - * |
|
413 | - * @throws IOException |
|
414 | - */ |
|
415 | - protected function writeToFile($handler, $content, $path = '') |
|
416 | - { |
|
417 | - if (($result = @fwrite($handler, $content)) === false || ($result < strlen($content))) { |
|
418 | - throw new IOException('The file "'.$path.'" could not be written to. Check your disk space and file permissions.'); |
|
419 | - } |
|
420 | - } |
|
350 | + $this->registerPattern('/(['.$chars.'])(.*?(?<!\\\\)(\\\\\\\\)*+)\\1/s', $callback); |
|
351 | + } |
|
352 | + |
|
353 | + /** |
|
354 | + * This method will restore all extracted data (strings, regexes) that were |
|
355 | + * replaced with placeholder text in extract*(). The original content was |
|
356 | + * saved in $this->extracted. |
|
357 | + * |
|
358 | + * @param string $content |
|
359 | + * |
|
360 | + * @return string |
|
361 | + */ |
|
362 | + protected function restoreExtractedData($content) |
|
363 | + { |
|
364 | + if (!$this->extracted) { |
|
365 | + // nothing was extracted, nothing to restore |
|
366 | + return $content; |
|
367 | + } |
|
368 | + |
|
369 | + $content = strtr($content, $this->extracted); |
|
370 | + |
|
371 | + $this->extracted = array(); |
|
372 | + |
|
373 | + return $content; |
|
374 | + } |
|
375 | + |
|
376 | + /** |
|
377 | + * Check if the path is a regular file and can be read. |
|
378 | + * |
|
379 | + * @param string $path |
|
380 | + * |
|
381 | + * @return bool |
|
382 | + */ |
|
383 | + protected function canImportFile($path) |
|
384 | + { |
|
385 | + return strlen($path) < PHP_MAXPATHLEN && is_file($path) && is_readable($path); |
|
386 | + } |
|
387 | + |
|
388 | + /** |
|
389 | + * Attempts to open file specified by $path for writing. |
|
390 | + * |
|
391 | + * @param string $path The path to the file. |
|
392 | + * |
|
393 | + * @return resource Specifier for the target file. |
|
394 | + * |
|
395 | + * @throws IOException |
|
396 | + */ |
|
397 | + protected function openFileForWriting($path) |
|
398 | + { |
|
399 | + if (($handler = @fopen($path, 'w')) === false) { |
|
400 | + throw new IOException('The file "'.$path.'" could not be opened for writing. Check if PHP has enough permissions.'); |
|
401 | + } |
|
402 | + |
|
403 | + return $handler; |
|
404 | + } |
|
405 | + |
|
406 | + /** |
|
407 | + * Attempts to write $content to the file specified by $handler. $path is used for printing exceptions. |
|
408 | + * |
|
409 | + * @param resource $handler The resource to write to. |
|
410 | + * @param string $content The content to write. |
|
411 | + * @param string $path The path to the file (for exception printing only). |
|
412 | + * |
|
413 | + * @throws IOException |
|
414 | + */ |
|
415 | + protected function writeToFile($handler, $content, $path = '') |
|
416 | + { |
|
417 | + if (($result = @fwrite($handler, $content)) === false || ($result < strlen($content))) { |
|
418 | + throw new IOException('The file "'.$path.'" could not be written to. Check your disk space and file permissions.'); |
|
419 | + } |
|
420 | + } |
|
421 | 421 | } |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | { |
317 | 317 | // PHP only supports $this inside anonymous functions since 5.4 |
318 | 318 | $minifier = $this; |
319 | - $callback = function ($match) use ($minifier) { |
|
319 | + $callback = function($match) use ($minifier) { |
|
320 | 320 | // check the second index here, because the first always contains a quote |
321 | 321 | if (!$match[2]) { |
322 | 322 | /* |
@@ -329,8 +329,8 @@ discard block |
||
329 | 329 | } |
330 | 330 | |
331 | 331 | $count = count($minifier->extracted); |
332 | - $placeholder = $match[1].$count.$match[1]; |
|
333 | - $minifier->extracted[$placeholder] = $match[1].$match[2].$match[1]; |
|
332 | + $placeholder = $match[1] . $count . $match[1]; |
|
333 | + $minifier->extracted[$placeholder] = $match[1] . $match[2] . $match[1]; |
|
334 | 334 | |
335 | 335 | return $placeholder; |
336 | 336 | }; |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | * considered as escape-char (times 2) and to get it in the regex, |
348 | 348 | * escaped (times 2) |
349 | 349 | */ |
350 | - $this->registerPattern('/(['.$chars.'])(.*?(?<!\\\\)(\\\\\\\\)*+)\\1/s', $callback); |
|
350 | + $this->registerPattern('/([' . $chars . '])(.*?(?<!\\\\)(\\\\\\\\)*+)\\1/s', $callback); |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | /** |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | protected function openFileForWriting($path) |
398 | 398 | { |
399 | 399 | if (($handler = @fopen($path, 'w')) === false) { |
400 | - throw new IOException('The file "'.$path.'" could not be opened for writing. Check if PHP has enough permissions.'); |
|
400 | + throw new IOException('The file "' . $path . '" could not be opened for writing. Check if PHP has enough permissions.'); |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | return $handler; |
@@ -415,7 +415,7 @@ discard block |
||
415 | 415 | protected function writeToFile($handler, $content, $path = '') |
416 | 416 | { |
417 | 417 | if (($result = @fwrite($handler, $content)) === false || ($result < strlen($content))) { |
418 | - throw new IOException('The file "'.$path.'" could not be written to. Check your disk space and file permissions.'); |
|
418 | + throw new IOException('The file "' . $path . '" could not be written to. Check your disk space and file permissions.'); |
|
419 | 419 | } |
420 | 420 | } |
421 | 421 | } |
@@ -12,8 +12,9 @@ discard block |
||
12 | 12 | * @version 2.1 Beta 3 |
13 | 13 | */ |
14 | 14 | |
15 | -if (!defined('SMF')) |
|
15 | +if (!defined('SMF')) { |
|
16 | 16 | die('No direct access...'); |
17 | +} |
|
17 | 18 | |
18 | 19 | /** |
19 | 20 | * This is the controlling delegator |
@@ -38,13 +39,15 @@ discard block |
||
38 | 39 | ); |
39 | 40 | |
40 | 41 | // Any subaction? If none, fall through to the main template, which will ask for one. |
41 | - if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) |
|
42 | - call_helper($subActions[$_REQUEST['sa']]); |
|
42 | + if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) { |
|
43 | + call_helper($subActions[$_REQUEST['sa']]); |
|
44 | + } |
|
43 | 45 | |
44 | 46 | // Creating a one time token. |
45 | - else |
|
46 | - createToken('remind'); |
|
47 | -} |
|
47 | + else { |
|
48 | + createToken('remind'); |
|
49 | + } |
|
50 | + } |
|
48 | 51 | |
49 | 52 | /** |
50 | 53 | * Allows the user to pick how they wish to be reminded |
@@ -62,8 +65,7 @@ discard block |
||
62 | 65 | { |
63 | 66 | $where = 'id_member = {int:id_member}'; |
64 | 67 | $where_params['id_member'] = (int) $_REQUEST['uid']; |
65 | - } |
|
66 | - elseif (isset($_POST['user']) && $_POST['user'] != '') |
|
68 | + } elseif (isset($_POST['user']) && $_POST['user'] != '') |
|
67 | 69 | { |
68 | 70 | $where = 'member_name = {string:member_name}'; |
69 | 71 | $where_params['member_name'] = $_POST['user']; |
@@ -71,8 +73,9 @@ discard block |
||
71 | 73 | } |
72 | 74 | |
73 | 75 | // You must enter a username/email address. |
74 | - if (empty($where)) |
|
75 | - fatal_lang_error('username_no_exist', false); |
|
76 | + if (empty($where)) { |
|
77 | + fatal_lang_error('username_no_exist', false); |
|
78 | + } |
|
76 | 79 | |
77 | 80 | // Make sure we are not being slammed |
78 | 81 | // Don't call this if you're coming from the "Choose a reminder type" page - otherwise you'll likely get an error |
@@ -101,8 +104,9 @@ discard block |
||
101 | 104 | LIMIT 1', |
102 | 105 | $where_params |
103 | 106 | ); |
104 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
105 | - fatal_lang_error('no_user_with_email', false); |
|
107 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
108 | + fatal_lang_error('no_user_with_email', false); |
|
109 | + } |
|
106 | 110 | } |
107 | 111 | |
108 | 112 | $row = $smcFunc['db_fetch_assoc']($request); |
@@ -112,16 +116,18 @@ discard block |
||
112 | 116 | if ($row['is_activated'] != 1) |
113 | 117 | { |
114 | 118 | // Awaiting approval... |
115 | - if (trim($row['validation_code']) == '') |
|
116 | - fatal_error(sprintf($txt['registration_not_approved'], $scripturl . '?action=activate;user=' . $_POST['user']), false); |
|
117 | - else |
|
118 | - fatal_error(sprintf($txt['registration_not_activated'], $scripturl . '?action=activate;user=' . $_POST['user']), false); |
|
119 | + if (trim($row['validation_code']) == '') { |
|
120 | + fatal_error(sprintf($txt['registration_not_approved'], $scripturl . '?action=activate;user=' . $_POST['user']), false); |
|
121 | + } else { |
|
122 | + fatal_error(sprintf($txt['registration_not_activated'], $scripturl . '?action=activate;user=' . $_POST['user']), false); |
|
123 | + } |
|
119 | 124 | } |
120 | 125 | |
121 | 126 | // You can't get emailed if you have no email address. |
122 | 127 | $row['email_address'] = trim($row['email_address']); |
123 | - if ($row['email_address'] == '') |
|
124 | - fatal_error($txt['no_reminder_email'] . '<br>' . $txt['send_email'] . ' <a href="mailto:' . $webmaster_email . '">webmaster</a> ' . $txt['to_ask_password'] . '.'); |
|
128 | + if ($row['email_address'] == '') { |
|
129 | + fatal_error($txt['no_reminder_email'] . '<br>' . $txt['send_email'] . ' <a href="mailto:' . $webmaster_email . '">webmaster</a> ' . $txt['to_ask_password'] . '.'); |
|
130 | + } |
|
125 | 131 | |
126 | 132 | // If they have no secret question then they can only get emailed the item, or they are requesting the email, send them an email. |
127 | 133 | if (empty($row['secret_question']) || (isset($_POST['reminder_type']) && $_POST['reminder_type'] == 'email')) |
@@ -176,8 +182,9 @@ discard block |
||
176 | 182 | loadLanguage('Login'); |
177 | 183 | |
178 | 184 | // You need a code! |
179 | - if (!isset($_REQUEST['code'])) |
|
180 | - fatal_lang_error('no_access', false); |
|
185 | + if (!isset($_REQUEST['code'])) { |
|
186 | + fatal_lang_error('no_access', false); |
|
187 | + } |
|
181 | 188 | |
182 | 189 | // Fill the context array. |
183 | 190 | $context += array( |
@@ -203,16 +210,19 @@ discard block |
||
203 | 210 | checkSession(); |
204 | 211 | validateToken('remind-sp'); |
205 | 212 | |
206 | - if (empty($_POST['u']) || !isset($_POST['passwrd1']) || !isset($_POST['passwrd2'])) |
|
207 | - fatal_lang_error('no_access', false); |
|
213 | + if (empty($_POST['u']) || !isset($_POST['passwrd1']) || !isset($_POST['passwrd2'])) { |
|
214 | + fatal_lang_error('no_access', false); |
|
215 | + } |
|
208 | 216 | |
209 | 217 | $_POST['u'] = (int) $_POST['u']; |
210 | 218 | |
211 | - if ($_POST['passwrd1'] != $_POST['passwrd2']) |
|
212 | - fatal_lang_error('passwords_dont_match', false); |
|
219 | + if ($_POST['passwrd1'] != $_POST['passwrd2']) { |
|
220 | + fatal_lang_error('passwords_dont_match', false); |
|
221 | + } |
|
213 | 222 | |
214 | - if ($_POST['passwrd1'] == '') |
|
215 | - fatal_lang_error('no_password', false); |
|
223 | + if ($_POST['passwrd1'] == '') { |
|
224 | + fatal_lang_error('no_password', false); |
|
225 | + } |
|
216 | 226 | |
217 | 227 | loadLanguage('Login'); |
218 | 228 | |
@@ -232,8 +242,9 @@ discard block |
||
232 | 242 | ); |
233 | 243 | |
234 | 244 | // Does this user exist at all? |
235 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
236 | - fatal_lang_error('invalid_userid', false); |
|
245 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
246 | + fatal_lang_error('invalid_userid', false); |
|
247 | + } |
|
237 | 248 | |
238 | 249 | list ($realCode, $username, $email, $flood_value) = $smcFunc['db_fetch_row']($request); |
239 | 250 | $smcFunc['db_free_result']($request); |
@@ -243,8 +254,9 @@ discard block |
||
243 | 254 | $passwordError = validatePassword($_POST['passwrd1'], $username, array($email)); |
244 | 255 | |
245 | 256 | // What - it's not? |
246 | - if ($passwordError != null) |
|
247 | - fatal_lang_error('profile_error_password_' . $passwordError, false); |
|
257 | + if ($passwordError != null) { |
|
258 | + fatal_lang_error('profile_error_password_' . $passwordError, false); |
|
259 | + } |
|
248 | 260 | |
249 | 261 | require_once($sourcedir . '/LogInOut.php'); |
250 | 262 | |
@@ -291,8 +303,9 @@ discard block |
||
291 | 303 | loadLanguage('Login'); |
292 | 304 | |
293 | 305 | // Check they entered something... |
294 | - if (empty($_REQUEST['uid'])) |
|
295 | - fatal_lang_error('username_no_exist', false); |
|
306 | + if (empty($_REQUEST['uid'])) { |
|
307 | + fatal_lang_error('username_no_exist', false); |
|
308 | + } |
|
296 | 309 | |
297 | 310 | // Get the stuff.... |
298 | 311 | $request = $smcFunc['db_query']('', ' |
@@ -304,15 +317,17 @@ discard block |
||
304 | 317 | 'id_member' => (int) $_REQUEST['uid'], |
305 | 318 | ) |
306 | 319 | ); |
307 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
308 | - fatal_lang_error('username_no_exist', false); |
|
320 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
321 | + fatal_lang_error('username_no_exist', false); |
|
322 | + } |
|
309 | 323 | |
310 | 324 | $row = $smcFunc['db_fetch_assoc']($request); |
311 | 325 | $smcFunc['db_free_result']($request); |
312 | 326 | |
313 | 327 | // If there is NO secret question - then throw an error. |
314 | - if (trim($row['secret_question']) == '') |
|
315 | - fatal_lang_error('registration_no_secret_question', false); |
|
328 | + if (trim($row['secret_question']) == '') { |
|
329 | + fatal_lang_error('registration_no_secret_question', false); |
|
330 | + } |
|
316 | 331 | |
317 | 332 | // Ask for the answer... |
318 | 333 | $context['remind_user'] = $row['id_member']; |
@@ -335,8 +350,9 @@ discard block |
||
335 | 350 | validateToken('remind-sai'); |
336 | 351 | |
337 | 352 | // Hacker? How did you get this far without an email or username? |
338 | - if (empty($_REQUEST['uid'])) |
|
339 | - fatal_lang_error('username_no_exist', false); |
|
353 | + if (empty($_REQUEST['uid'])) { |
|
354 | + fatal_lang_error('username_no_exist', false); |
|
355 | + } |
|
340 | 356 | |
341 | 357 | loadLanguage('Login'); |
342 | 358 | |
@@ -350,8 +366,9 @@ discard block |
||
350 | 366 | 'id_member' => $_REQUEST['uid'], |
351 | 367 | ) |
352 | 368 | ); |
353 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
354 | - fatal_lang_error('username_no_exist', false); |
|
369 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
370 | + fatal_lang_error('username_no_exist', false); |
|
371 | + } |
|
355 | 372 | |
356 | 373 | $row = $smcFunc['db_fetch_assoc']($request); |
357 | 374 | $smcFunc['db_free_result']($request); |
@@ -364,20 +381,23 @@ discard block |
||
364 | 381 | } |
365 | 382 | |
366 | 383 | // You can't use a blank one! |
367 | - if (strlen(trim($_POST['passwrd1'])) === 0) |
|
368 | - fatal_lang_error('no_password', false); |
|
384 | + if (strlen(trim($_POST['passwrd1'])) === 0) { |
|
385 | + fatal_lang_error('no_password', false); |
|
386 | + } |
|
369 | 387 | |
370 | 388 | // They have to be the same too. |
371 | - if ($_POST['passwrd1'] != $_POST['passwrd2']) |
|
372 | - fatal_lang_error('passwords_dont_match', false); |
|
389 | + if ($_POST['passwrd1'] != $_POST['passwrd2']) { |
|
390 | + fatal_lang_error('passwords_dont_match', false); |
|
391 | + } |
|
373 | 392 | |
374 | 393 | // Make sure they have a strong enough password. |
375 | 394 | require_once($sourcedir . '/Subs-Auth.php'); |
376 | 395 | $passwordError = validatePassword($_POST['passwrd1'], $row['member_name'], array($row['email_address'])); |
377 | 396 | |
378 | 397 | // Invalid? |
379 | - if ($passwordError != null) |
|
380 | - fatal_lang_error('profile_error_password_' . $passwordError, false); |
|
398 | + if ($passwordError != null) { |
|
399 | + fatal_lang_error('profile_error_password_' . $passwordError, false); |
|
400 | + } |
|
381 | 401 | |
382 | 402 | // Alright, so long as 'yer sure. |
383 | 403 | updateMemberData($row['id_member'], array('passwd' => hash_password($row['member_name'], $_POST['passwrd1']))); |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 3 |
15 | 15 | */ |
16 | 16 | |
17 | -if (!defined('SMF')) |
|
17 | +if (!defined('SMF')) { |
|
18 | 18 | die('No direct access...'); |
19 | +} |
|
19 | 20 | |
20 | 21 | /** |
21 | 22 | * Allow the user to vote. |
@@ -51,8 +52,9 @@ discard block |
||
51 | 52 | 'not_guest' => 0, |
52 | 53 | ) |
53 | 54 | ); |
54 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
55 | - fatal_lang_error('poll_error', false); |
|
55 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
56 | + fatal_lang_error('poll_error', false); |
|
57 | + } |
|
56 | 58 | $row = $smcFunc['db_fetch_assoc']($request); |
57 | 59 | $smcFunc['db_free_result']($request); |
58 | 60 | |
@@ -60,8 +62,9 @@ discard block |
||
60 | 62 | if ($user_info['is_guest']) |
61 | 63 | { |
62 | 64 | // Guest voting disabled? |
63 | - if (!$row['guest_vote']) |
|
64 | - fatal_lang_error('guest_vote_disabled'); |
|
65 | + if (!$row['guest_vote']) { |
|
66 | + fatal_lang_error('guest_vote_disabled'); |
|
67 | + } |
|
65 | 68 | // Guest already voted? |
66 | 69 | elseif (!empty($_COOKIE['guest_poll_vote']) && preg_match('~^[0-9,;]+$~', $_COOKIE['guest_poll_vote']) && strpos($_COOKIE['guest_poll_vote'], ';' . $row['id_poll'] . ',') !== false) |
67 | 70 | { |
@@ -71,32 +74,36 @@ discard block |
||
71 | 74 | foreach ($guestinfo as $i => $guestvoted) |
72 | 75 | { |
73 | 76 | $guestvoted = explode(',', $guestvoted); |
74 | - if ($guestvoted[0] == $row['id_poll']) |
|
75 | - break; |
|
77 | + if ($guestvoted[0] == $row['id_poll']) { |
|
78 | + break; |
|
79 | + } |
|
76 | 80 | } |
77 | 81 | // Has the poll been reset since guest voted? |
78 | 82 | if ($row['reset_poll'] > $guestvoted[1]) |
79 | 83 | { |
80 | 84 | // Remove the poll info from the cookie to allow guest to vote again |
81 | 85 | unset($guestinfo[$i]); |
82 | - if (!empty($guestinfo)) |
|
83 | - $_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo); |
|
84 | - else |
|
85 | - unset($_COOKIE['guest_poll_vote']); |
|
86 | + if (!empty($guestinfo)) { |
|
87 | + $_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo); |
|
88 | + } else { |
|
89 | + unset($_COOKIE['guest_poll_vote']); |
|
90 | + } |
|
91 | + } else { |
|
92 | + fatal_lang_error('poll_error', false); |
|
86 | 93 | } |
87 | - else |
|
88 | - fatal_lang_error('poll_error', false); |
|
89 | 94 | unset($guestinfo, $guestvoted, $i); |
90 | 95 | } |
91 | 96 | } |
92 | 97 | |
93 | 98 | // Is voting locked or has it expired? |
94 | - if (!empty($row['voting_locked']) || (!empty($row['expire_time']) && time() > $row['expire_time'])) |
|
95 | - fatal_lang_error('poll_error', false); |
|
99 | + if (!empty($row['voting_locked']) || (!empty($row['expire_time']) && time() > $row['expire_time'])) { |
|
100 | + fatal_lang_error('poll_error', false); |
|
101 | + } |
|
96 | 102 | |
97 | 103 | // If they have already voted and aren't allowed to change their vote - hence they are outta here! |
98 | - if (!$user_info['is_guest'] && $row['selected'] != -1 && empty($row['change_vote'])) |
|
99 | - fatal_lang_error('poll_error', false); |
|
104 | + if (!$user_info['is_guest'] && $row['selected'] != -1 && empty($row['change_vote'])) { |
|
105 | + fatal_lang_error('poll_error', false); |
|
106 | + } |
|
100 | 107 | // Otherwise if they can change their vote yet they haven't sent any options... remove their vote and redirect. |
101 | 108 | elseif (!empty($row['change_vote']) && !$user_info['is_guest'] && empty($_POST['options'])) |
102 | 109 | { |
@@ -114,8 +121,9 @@ discard block |
||
114 | 121 | 'id_poll' => $row['id_poll'], |
115 | 122 | ) |
116 | 123 | ); |
117 | - while ($choice = $smcFunc['db_fetch_row']($request)) |
|
118 | - $pollOptions[] = $choice[0]; |
|
124 | + while ($choice = $smcFunc['db_fetch_row']($request)) { |
|
125 | + $pollOptions[] = $choice[0]; |
|
126 | + } |
|
119 | 127 | $smcFunc['db_free_result']($request); |
120 | 128 | |
121 | 129 | // Just skip it if they had voted for nothing before. |
@@ -148,19 +156,22 @@ discard block |
||
148 | 156 | } |
149 | 157 | |
150 | 158 | // Redirect back to the topic so the user can vote again! |
151 | - if (empty($_POST['options'])) |
|
152 | - redirectexit('topic=' . $topic . '.' . $_REQUEST['start']); |
|
159 | + if (empty($_POST['options'])) { |
|
160 | + redirectexit('topic=' . $topic . '.' . $_REQUEST['start']); |
|
161 | + } |
|
153 | 162 | } |
154 | 163 | |
155 | 164 | checkSession('request'); |
156 | 165 | |
157 | 166 | // Make sure the option(s) are valid. |
158 | - if (empty($_POST['options'])) |
|
159 | - fatal_lang_error('didnt_select_vote', false); |
|
167 | + if (empty($_POST['options'])) { |
|
168 | + fatal_lang_error('didnt_select_vote', false); |
|
169 | + } |
|
160 | 170 | |
161 | 171 | // Too many options checked! |
162 | - if (count($_REQUEST['options']) > $row['max_votes']) |
|
163 | - fatal_lang_error('poll_too_many_votes', false, array($row['max_votes'])); |
|
172 | + if (count($_REQUEST['options']) > $row['max_votes']) { |
|
173 | + fatal_lang_error('poll_too_many_votes', false, array($row['max_votes'])); |
|
174 | + } |
|
164 | 175 | |
165 | 176 | $pollOptions = array(); |
166 | 177 | $inserts = array(); |
@@ -250,24 +261,30 @@ discard block |
||
250 | 261 | list ($memberID, $pollID, $voting_locked) = $smcFunc['db_fetch_row']($request); |
251 | 262 | |
252 | 263 | // If the user _can_ modify the poll.... |
253 | - if (!allowedTo('poll_lock_any')) |
|
254 | - isAllowedTo('poll_lock_' . ($user_info['id'] == $memberID ? 'own' : 'any')); |
|
264 | + if (!allowedTo('poll_lock_any')) { |
|
265 | + isAllowedTo('poll_lock_' . ($user_info['id'] == $memberID ? 'own' : 'any')); |
|
266 | + } |
|
255 | 267 | |
256 | 268 | // It's been locked by a non-moderator. |
257 | - if ($voting_locked == '1') |
|
258 | - $voting_locked = '0'; |
|
269 | + if ($voting_locked == '1') { |
|
270 | + $voting_locked = '0'; |
|
271 | + } |
|
259 | 272 | // Locked by a moderator, and this is a moderator. |
260 | - elseif ($voting_locked == '2' && allowedTo('moderate_board')) |
|
261 | - $voting_locked = '0'; |
|
273 | + elseif ($voting_locked == '2' && allowedTo('moderate_board')) { |
|
274 | + $voting_locked = '0'; |
|
275 | + } |
|
262 | 276 | // Sorry, a moderator locked it. |
263 | - elseif ($voting_locked == '2' && !allowedTo('moderate_board')) |
|
264 | - fatal_lang_error('locked_by_admin', 'user'); |
|
277 | + elseif ($voting_locked == '2' && !allowedTo('moderate_board')) { |
|
278 | + fatal_lang_error('locked_by_admin', 'user'); |
|
279 | + } |
|
265 | 280 | // A moderator *is* locking it. |
266 | - elseif ($voting_locked == '0' && allowedTo('moderate_board')) |
|
267 | - $voting_locked = '2'; |
|
281 | + elseif ($voting_locked == '0' && allowedTo('moderate_board')) { |
|
282 | + $voting_locked = '2'; |
|
283 | + } |
|
268 | 284 | // Well, it's gonna be locked one way or another otherwise... |
269 | - else |
|
270 | - $voting_locked = '1'; |
|
285 | + else { |
|
286 | + $voting_locked = '1'; |
|
287 | + } |
|
271 | 288 | |
272 | 289 | // Lock! *Poof* - no one can vote. |
273 | 290 | $smcFunc['db_query']('', ' |
@@ -302,8 +319,9 @@ discard block |
||
302 | 319 | { |
303 | 320 | global $txt, $user_info, $context, $topic, $board, $smcFunc, $sourcedir, $scripturl; |
304 | 321 | |
305 | - if (empty($topic)) |
|
306 | - fatal_lang_error('no_access', false); |
|
322 | + if (empty($topic)) { |
|
323 | + fatal_lang_error('no_access', false); |
|
324 | + } |
|
307 | 325 | |
308 | 326 | loadLanguage('Post'); |
309 | 327 | loadTemplate('Poll'); |
@@ -327,24 +345,28 @@ discard block |
||
327 | 345 | ); |
328 | 346 | |
329 | 347 | // Assume the the topic exists, right? |
330 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
331 | - fatal_lang_error('no_board'); |
|
348 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
349 | + fatal_lang_error('no_board'); |
|
350 | + } |
|
332 | 351 | // Get the poll information. |
333 | 352 | $pollinfo = $smcFunc['db_fetch_assoc']($request); |
334 | 353 | $smcFunc['db_free_result']($request); |
335 | 354 | |
336 | 355 | // If we are adding a new poll - make sure that there isn't already a poll there. |
337 | - if (!$context['is_edit'] && !empty($pollinfo['id_poll'])) |
|
338 | - fatal_lang_error('poll_already_exists'); |
|
356 | + if (!$context['is_edit'] && !empty($pollinfo['id_poll'])) { |
|
357 | + fatal_lang_error('poll_already_exists'); |
|
358 | + } |
|
339 | 359 | // Otherwise, if we're editing it, it does exist I assume? |
340 | - elseif ($context['is_edit'] && empty($pollinfo['id_poll'])) |
|
341 | - fatal_lang_error('poll_not_found'); |
|
360 | + elseif ($context['is_edit'] && empty($pollinfo['id_poll'])) { |
|
361 | + fatal_lang_error('poll_not_found'); |
|
362 | + } |
|
342 | 363 | |
343 | 364 | // Can you do this? |
344 | - if ($context['is_edit'] && !allowedTo('poll_edit_any')) |
|
345 | - isAllowedTo('poll_edit_' . ($user_info['id'] == $pollinfo['id_member_started'] || ($pollinfo['poll_starter'] != 0 && $user_info['id'] == $pollinfo['poll_starter']) ? 'own' : 'any')); |
|
346 | - elseif (!$context['is_edit'] && !allowedTo('poll_add_any')) |
|
347 | - isAllowedTo('poll_add_' . ($user_info['id'] == $pollinfo['id_member_started'] ? 'own' : 'any')); |
|
365 | + if ($context['is_edit'] && !allowedTo('poll_edit_any')) { |
|
366 | + isAllowedTo('poll_edit_' . ($user_info['id'] == $pollinfo['id_member_started'] || ($pollinfo['poll_starter'] != 0 && $user_info['id'] == $pollinfo['poll_starter']) ? 'own' : 'any')); |
|
367 | + } elseif (!$context['is_edit'] && !allowedTo('poll_add_any')) { |
|
368 | + isAllowedTo('poll_add_' . ($user_info['id'] == $pollinfo['id_member_started'] ? 'own' : 'any')); |
|
369 | + } |
|
348 | 370 | $context['can_moderate_poll'] = isset($_REQUEST['add']) ? true : allowedTo('poll_edit_' . ($user_info['id'] == $pollinfo['id_member_started'] || ($pollinfo['poll_starter'] != 0 && $user_info['id'] == $pollinfo['poll_starter']) ? 'own' : 'any')); |
349 | 371 | |
350 | 372 | // Do we enable guest voting? |
@@ -386,12 +408,14 @@ discard block |
||
386 | 408 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
387 | 409 | { |
388 | 410 | // Get the highest id so we can add more without reusing. |
389 | - if ($row['id_choice'] >= $last_id) |
|
390 | - $last_id = $row['id_choice'] + 1; |
|
411 | + if ($row['id_choice'] >= $last_id) { |
|
412 | + $last_id = $row['id_choice'] + 1; |
|
413 | + } |
|
391 | 414 | |
392 | 415 | // They cleared this by either omitting it or emptying it. |
393 | - if (!isset($_POST['options'][$row['id_choice']]) || $_POST['options'][$row['id_choice']] == '') |
|
394 | - continue; |
|
416 | + if (!isset($_POST['options'][$row['id_choice']]) || $_POST['options'][$row['id_choice']] == '') { |
|
417 | + continue; |
|
418 | + } |
|
395 | 419 | |
396 | 420 | censorText($row['label']); |
397 | 421 | |
@@ -409,9 +433,10 @@ discard block |
||
409 | 433 | |
410 | 434 | // Work out how many options we have, so we get the 'is_last' field right... |
411 | 435 | $totalPostOptions = 0; |
412 | - foreach ($_POST['options'] as $id => $label) |
|
413 | - if ($label != '') |
|
436 | + foreach ($_POST['options'] as $id => $label) { |
|
437 | + if ($label != '') |
|
414 | 438 | $totalPostOptions++; |
439 | + } |
|
415 | 440 | |
416 | 441 | $count = 1; |
417 | 442 | // If an option exists, update it. If it is new, add it - but don't reuse ids! |
@@ -420,30 +445,32 @@ discard block |
||
420 | 445 | $label = $smcFunc['htmlspecialchars']($label); |
421 | 446 | censorText($label); |
422 | 447 | |
423 | - if (isset($context['choices'][$id])) |
|
424 | - $context['choices'][$id]['label'] = $label; |
|
425 | - elseif ($label != '') |
|
426 | - $context['choices'][] = array( |
|
448 | + if (isset($context['choices'][$id])) { |
|
449 | + $context['choices'][$id]['label'] = $label; |
|
450 | + } elseif ($label != '') { |
|
451 | + $context['choices'][] = array( |
|
427 | 452 | 'id' => $last_id++, |
428 | 453 | 'number' => $number++, |
429 | 454 | 'label' => $label, |
430 | 455 | 'votes' => -1, |
431 | 456 | 'is_last' => $count++ == $totalPostOptions && $totalPostOptions > 1 ? true : false, |
432 | 457 | ); |
458 | + } |
|
433 | 459 | } |
434 | 460 | |
435 | 461 | // Make sure we have two choices for sure! |
436 | 462 | if ($totalPostOptions < 2) |
437 | 463 | { |
438 | 464 | // Need two? |
439 | - if ($totalPostOptions == 0) |
|
440 | - $context['choices'][] = array( |
|
465 | + if ($totalPostOptions == 0) { |
|
466 | + $context['choices'][] = array( |
|
441 | 467 | 'id' => $last_id++, |
442 | 468 | 'number' => $number++, |
443 | 469 | 'label' => '', |
444 | 470 | 'votes' => -1, |
445 | 471 | 'is_last' => false |
446 | 472 | ); |
473 | + } |
|
447 | 474 | $poll_errors[] = 'poll_few'; |
448 | 475 | } |
449 | 476 | |
@@ -458,12 +485,14 @@ discard block |
||
458 | 485 | |
459 | 486 | $context['last_choice_id'] = $last_id; |
460 | 487 | |
461 | - if ($context['can_moderate_poll']) |
|
462 | - $context['poll']['expiration'] = $_POST['poll_expire']; |
|
488 | + if ($context['can_moderate_poll']) { |
|
489 | + $context['poll']['expiration'] = $_POST['poll_expire']; |
|
490 | + } |
|
463 | 491 | |
464 | 492 | // Check the question/option count for errors. |
465 | - if (trim($_POST['question']) == '' && empty($context['poll_error'])) |
|
466 | - $poll_errors[] = 'no_question'; |
|
493 | + if (trim($_POST['question']) == '' && empty($context['poll_error'])) { |
|
494 | + $poll_errors[] = 'no_question'; |
|
495 | + } |
|
467 | 496 | |
468 | 497 | // No check is needed, since nothing is really posted. |
469 | 498 | checkSubmitOnce('free'); |
@@ -480,8 +509,7 @@ discard block |
||
480 | 509 | $context['poll_error']['messages'][] = $txt['error_' . $poll_error]; |
481 | 510 | } |
482 | 511 | } |
483 | - } |
|
484 | - else |
|
512 | + } else |
|
485 | 513 | { |
486 | 514 | // Basic theme info... |
487 | 515 | $context['poll'] = array( |
@@ -596,18 +624,22 @@ discard block |
||
596 | 624 | global $user_info, $smcFunc, $sourcedir; |
597 | 625 | |
598 | 626 | // Sneaking off, are we? |
599 | - if (empty($_POST)) |
|
600 | - redirectexit('action=editpoll;topic=' . $topic . '.0'); |
|
627 | + if (empty($_POST)) { |
|
628 | + redirectexit('action=editpoll;topic=' . $topic . '.0'); |
|
629 | + } |
|
601 | 630 | |
602 | - if (checkSession('post', '', false) != '') |
|
603 | - $poll_errors[] = 'session_timeout'; |
|
631 | + if (checkSession('post', '', false) != '') { |
|
632 | + $poll_errors[] = 'session_timeout'; |
|
633 | + } |
|
604 | 634 | |
605 | - if (isset($_POST['preview'])) |
|
606 | - return EditPoll(); |
|
635 | + if (isset($_POST['preview'])) { |
|
636 | + return EditPoll(); |
|
637 | + } |
|
607 | 638 | |
608 | 639 | // HACKERS (!!) can't edit :P. |
609 | - if (empty($topic)) |
|
610 | - fatal_lang_error('no_access', false); |
|
640 | + if (empty($topic)) { |
|
641 | + fatal_lang_error('no_access', false); |
|
642 | + } |
|
611 | 643 | |
612 | 644 | // Is this a new poll, or editing an existing? |
613 | 645 | $isEdit = isset($_REQUEST['add']) ? 0 : 1; |
@@ -623,23 +655,27 @@ discard block |
||
623 | 655 | 'current_topic' => $topic, |
624 | 656 | ) |
625 | 657 | ); |
626 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
627 | - fatal_lang_error('no_board'); |
|
658 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
659 | + fatal_lang_error('no_board'); |
|
660 | + } |
|
628 | 661 | $bcinfo = $smcFunc['db_fetch_assoc']($request); |
629 | 662 | $smcFunc['db_free_result']($request); |
630 | 663 | |
631 | 664 | // Check their adding/editing is valid. |
632 | - if (!$isEdit && !empty($bcinfo['id_poll'])) |
|
633 | - fatal_lang_error('poll_already_exists'); |
|
665 | + if (!$isEdit && !empty($bcinfo['id_poll'])) { |
|
666 | + fatal_lang_error('poll_already_exists'); |
|
667 | + } |
|
634 | 668 | // Are we editing a poll which doesn't exist? |
635 | - elseif ($isEdit && empty($bcinfo['id_poll'])) |
|
636 | - fatal_lang_error('poll_not_found'); |
|
669 | + elseif ($isEdit && empty($bcinfo['id_poll'])) { |
|
670 | + fatal_lang_error('poll_not_found'); |
|
671 | + } |
|
637 | 672 | |
638 | 673 | // Check if they have the power to add or edit the poll. |
639 | - if ($isEdit && !allowedTo('poll_edit_any')) |
|
640 | - isAllowedTo('poll_edit_' . ($user_info['id'] == $bcinfo['id_member_started'] || ($bcinfo['poll_starter'] != 0 && $user_info['id'] == $bcinfo['poll_starter']) ? 'own' : 'any')); |
|
641 | - elseif (!$isEdit && !allowedTo('poll_add_any')) |
|
642 | - isAllowedTo('poll_add_' . ($user_info['id'] == $bcinfo['id_member_started'] ? 'own' : 'any')); |
|
674 | + if ($isEdit && !allowedTo('poll_edit_any')) { |
|
675 | + isAllowedTo('poll_edit_' . ($user_info['id'] == $bcinfo['id_member_started'] || ($bcinfo['poll_starter'] != 0 && $user_info['id'] == $bcinfo['poll_starter']) ? 'own' : 'any')); |
|
676 | + } elseif (!$isEdit && !allowedTo('poll_add_any')) { |
|
677 | + isAllowedTo('poll_add_' . ($user_info['id'] == $bcinfo['id_member_started'] ? 'own' : 'any')); |
|
678 | + } |
|
643 | 679 | |
644 | 680 | $optionCount = 0; |
645 | 681 | $idCount = 0; |
@@ -652,14 +688,16 @@ discard block |
||
652 | 688 | $idCount = max($idCount, $k); |
653 | 689 | } |
654 | 690 | } |
655 | - if ($optionCount < 2) |
|
656 | - $poll_errors[] = 'poll_few'; |
|
657 | - elseif ($optionCount > 256 || $idCount > 255) |
|
658 | - $poll_errors[] = 'poll_many'; |
|
691 | + if ($optionCount < 2) { |
|
692 | + $poll_errors[] = 'poll_few'; |
|
693 | + } elseif ($optionCount > 256 || $idCount > 255) { |
|
694 | + $poll_errors[] = 'poll_many'; |
|
695 | + } |
|
659 | 696 | |
660 | 697 | // Also - ensure they are not removing the question. |
661 | - if (trim($_POST['question']) == '') |
|
662 | - $poll_errors[] = 'no_question'; |
|
698 | + if (trim($_POST['question']) == '') { |
|
699 | + $poll_errors[] = 'no_question'; |
|
700 | + } |
|
663 | 701 | |
664 | 702 | // Got any errors to report? |
665 | 703 | if (!empty($poll_errors)) |
@@ -695,8 +733,9 @@ discard block |
||
695 | 733 | { |
696 | 734 | require_once($sourcedir . '/Subs-Members.php'); |
697 | 735 | $allowedGroups = groupsAllowedTo('poll_vote', $board); |
698 | - if (!in_array(-1, $allowedGroups['allowed'])) |
|
699 | - $_POST['poll_guest_vote'] = 0; |
|
736 | + if (!in_array(-1, $allowedGroups['allowed'])) { |
|
737 | + $_POST['poll_guest_vote'] = 0; |
|
738 | + } |
|
700 | 739 | } |
701 | 740 | |
702 | 741 | // Ensure that the number options allowed makes sense, and the expiration date is valid. |
@@ -704,17 +743,19 @@ discard block |
||
704 | 743 | { |
705 | 744 | $_POST['poll_expire'] = $_POST['poll_expire'] > 9999 ? 9999 : ($_POST['poll_expire'] < 0 ? 0 : $_POST['poll_expire']); |
706 | 745 | |
707 | - if (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) |
|
708 | - $_POST['poll_hide'] = 1; |
|
709 | - elseif (!$isEdit || $_POST['poll_expire'] != ceil($bcinfo['expire_time'] <= time() ? -1 : ($bcinfo['expire_time'] - time()) / (3600 * 24))) |
|
710 | - $_POST['poll_expire'] = empty($_POST['poll_expire']) ? '0' : time() + $_POST['poll_expire'] * 3600 * 24; |
|
711 | - else |
|
712 | - $_POST['poll_expire'] = $bcinfo['expire_time']; |
|
746 | + if (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) { |
|
747 | + $_POST['poll_hide'] = 1; |
|
748 | + } elseif (!$isEdit || $_POST['poll_expire'] != ceil($bcinfo['expire_time'] <= time() ? -1 : ($bcinfo['expire_time'] - time()) / (3600 * 24))) { |
|
749 | + $_POST['poll_expire'] = empty($_POST['poll_expire']) ? '0' : time() + $_POST['poll_expire'] * 3600 * 24; |
|
750 | + } else { |
|
751 | + $_POST['poll_expire'] = $bcinfo['expire_time']; |
|
752 | + } |
|
713 | 753 | |
714 | - if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) |
|
715 | - $_POST['poll_max_votes'] = 1; |
|
716 | - else |
|
717 | - $_POST['poll_max_votes'] = (int) $_POST['poll_max_votes']; |
|
754 | + if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) { |
|
755 | + $_POST['poll_max_votes'] = 1; |
|
756 | + } else { |
|
757 | + $_POST['poll_max_votes'] = (int) $_POST['poll_max_votes']; |
|
758 | + } |
|
718 | 759 | } |
719 | 760 | |
720 | 761 | // If we're editing, let's commit the changes. |
@@ -781,8 +822,9 @@ discard block |
||
781 | 822 | ) |
782 | 823 | ); |
783 | 824 | $choices = array(); |
784 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
785 | - $choices[] = $row['id_choice']; |
|
825 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
826 | + $choices[] = $row['id_choice']; |
|
827 | + } |
|
786 | 828 | $smcFunc['db_free_result']($request); |
787 | 829 | |
788 | 830 | $delete_options = array(); |
@@ -795,8 +837,9 @@ discard block |
||
795 | 837 | if (trim($option) == '') |
796 | 838 | { |
797 | 839 | // They want it deleted. Bye. |
798 | - if (in_array($k, $choices)) |
|
799 | - $delete_options[] = $k; |
|
840 | + if (in_array($k, $choices)) { |
|
841 | + $delete_options[] = $k; |
|
842 | + } |
|
800 | 843 | |
801 | 844 | // Skip the rest... |
802 | 845 | continue; |
@@ -806,8 +849,8 @@ discard block |
||
806 | 849 | $option = $smcFunc['htmlspecialchars']($option); |
807 | 850 | |
808 | 851 | // If it's already there, update it. If it's not... add it. |
809 | - if (in_array($k, $choices)) |
|
810 | - $smcFunc['db_query']('', ' |
|
852 | + if (in_array($k, $choices)) { |
|
853 | + $smcFunc['db_query']('', ' |
|
811 | 854 | UPDATE {db_prefix}poll_choices |
812 | 855 | SET label = {string:option_name} |
813 | 856 | WHERE id_poll = {int:id_poll} |
@@ -818,8 +861,8 @@ discard block |
||
818 | 861 | 'option_name' => $option, |
819 | 862 | ) |
820 | 863 | ); |
821 | - else |
|
822 | - $smcFunc['db_insert']('', |
|
864 | + } else { |
|
865 | + $smcFunc['db_insert']('', |
|
823 | 866 | '{db_prefix}poll_choices', |
824 | 867 | array( |
825 | 868 | 'id_poll' => 'int', 'id_choice' => 'int', 'label' => 'string-255', 'votes' => 'int', |
@@ -829,6 +872,7 @@ discard block |
||
829 | 872 | ), |
830 | 873 | array() |
831 | 874 | ); |
875 | + } |
|
832 | 876 | } |
833 | 877 | |
834 | 878 | // I'm sorry, but... well, no one was choosing you. Poor options, I'll put you out of your misery. |
@@ -894,13 +938,11 @@ discard block |
||
894 | 938 | { |
895 | 939 | // Added a poll |
896 | 940 | logAction('add_poll', array('topic' => $topic)); |
897 | - } |
|
898 | - elseif (isset($_REQUEST['deletevotes'])) |
|
941 | + } elseif (isset($_REQUEST['deletevotes'])) |
|
899 | 942 | { |
900 | 943 | // Reset votes |
901 | 944 | logAction('reset_poll', array('topic' => $topic)); |
902 | - } |
|
903 | - else |
|
945 | + } else |
|
904 | 946 | { |
905 | 947 | // Something else |
906 | 948 | logAction('editpoll', array('topic' => $topic)); |
@@ -923,8 +965,9 @@ discard block |
||
923 | 965 | global $topic, $user_info, $smcFunc; |
924 | 966 | |
925 | 967 | // Make sure the topic is not empty. |
926 | - if (empty($topic)) |
|
927 | - fatal_lang_error('no_access', false); |
|
968 | + if (empty($topic)) { |
|
969 | + fatal_lang_error('no_access', false); |
|
970 | + } |
|
928 | 971 | |
929 | 972 | // Verify the session. |
930 | 973 | checkSession('get'); |
@@ -942,8 +985,9 @@ discard block |
||
942 | 985 | 'current_topic' => $topic, |
943 | 986 | ) |
944 | 987 | ); |
945 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
946 | - fatal_lang_error('no_access', false); |
|
988 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
989 | + fatal_lang_error('no_access', false); |
|
990 | + } |
|
947 | 991 | list ($topicStarter, $pollStarter) = $smcFunc['db_fetch_row']($request); |
948 | 992 | $smcFunc['db_free_result']($request); |
949 | 993 |
@@ -798,7 +798,7 @@ discard block |
||
798 | 798 | { |
799 | 799 | // It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat. |
800 | 800 | if ($i % 4 == 0) |
801 | - $parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function ($m) |
|
801 | + $parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) |
|
802 | 802 | { |
803 | 803 | return '[html]' . preg_replace('~<br\s?/?' . '>~i', '<br /><br>', "$m[1]") . '[/html]'; |
804 | 804 | }, $parts[$i]); |
@@ -895,7 +895,7 @@ discard block |
||
895 | 895 | { |
896 | 896 | // Since, they don't belong here. Let's inform the user that they exist.. |
897 | 897 | if (!empty($topic)) |
898 | - $delete_url = $scripturl . '?action=post' .(!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp'; |
|
898 | + $delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp'; |
|
899 | 899 | else |
900 | 900 | $delete_url = $scripturl . '?action=post;board=' . $board . ';delete_temp'; |
901 | 901 | |
@@ -903,7 +903,7 @@ discard block |
||
903 | 903 | $file_list = array(); |
904 | 904 | foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
905 | 905 | if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
906 | - $file_list[] = $attachment['name']; |
|
906 | + $file_list[] = $attachment['name']; |
|
907 | 907 | |
908 | 908 | $_SESSION['temp_attachments']['post']['files'] = $file_list; |
909 | 909 | $file_list = '<div class="attachments">' . implode('<br>', $file_list) . '</div>'; |
@@ -911,7 +911,7 @@ discard block |
||
911 | 911 | if (!empty($_SESSION['temp_attachments']['post']['msg'])) |
912 | 912 | { |
913 | 913 | // We have a message id, so we can link back to the old topic they were trying to edit.. |
914 | - $goback_url = $scripturl . '?action=post' .(!empty($_SESSION['temp_attachments']['post']['msg']) ? (';msg=' . $_SESSION['temp_attachments']['post']['msg']) : '') . (!empty($_SESSION['temp_attachments']['post']['last_msg']) ? (';last_msg=' . $_SESSION['temp_attachments']['post']['last_msg']) : '') . ';topic=' . $_SESSION['temp_attachments']['post']['topic'] . ';additionalOptions'; |
|
914 | + $goback_url = $scripturl . '?action=post' . (!empty($_SESSION['temp_attachments']['post']['msg']) ? (';msg=' . $_SESSION['temp_attachments']['post']['msg']) : '') . (!empty($_SESSION['temp_attachments']['post']['last_msg']) ? (';last_msg=' . $_SESSION['temp_attachments']['post']['last_msg']) : '') . ';topic=' . $_SESSION['temp_attachments']['post']['topic'] . ';additionalOptions'; |
|
915 | 915 | |
916 | 916 | $post_errors[] = array('temp_attachments_found', array($delete_url, $goback_url, $file_list)); |
917 | 917 | $context['ignore_temp_attachments'] = true; |
@@ -1198,55 +1198,55 @@ discard block |
||
1198 | 1198 | foreach ($context['current_attachments'] as $key => $mock) |
1199 | 1199 | addInlineJavaScript(' |
1200 | 1200 | current_attachments.push({ |
1201 | - name: '. JavaScriptEscape($mock['name']) .', |
|
1202 | - size: '. $mock['size'] .', |
|
1203 | - attachID: '. $mock['attachID'] .', |
|
1204 | - approved: '. $mock['approved'] .', |
|
1205 | - type: '. JavaScriptEscape(!empty($mock['mime_type']) ? $mock['mime_type'] : '') .', |
|
1206 | - thumbID: '. (!empty($mock['thumb']) ? $mock['thumb'] : 0) .' |
|
1201 | + name: '. JavaScriptEscape($mock['name']) . ', |
|
1202 | + size: '. $mock['size'] . ', |
|
1203 | + attachID: '. $mock['attachID'] . ', |
|
1204 | + approved: '. $mock['approved'] . ', |
|
1205 | + type: '. JavaScriptEscape(!empty($mock['mime_type']) ? $mock['mime_type'] : '') . ', |
|
1206 | + thumbID: '. (!empty($mock['thumb']) ? $mock['thumb'] : 0) . ' |
|
1207 | 1207 | });', true); |
1208 | 1208 | } |
1209 | 1209 | |
1210 | 1210 | // File Upload. |
1211 | 1211 | if ($context['can_post_attachment']) |
1212 | 1212 | { |
1213 | - $acceptedFiles = implode(',', array_map(function($val) use($smcFunc) { return '.'. $smcFunc['htmltrim']($val);} , explode(',', $context['allowed_extensions']))); |
|
1213 | + $acceptedFiles = implode(',', array_map(function($val) use($smcFunc) { return '.' . $smcFunc['htmltrim']($val); } , explode(',', $context['allowed_extensions']))); |
|
1214 | 1214 | |
1215 | 1215 | loadJavaScriptFile('dropzone.min.js', array('defer' => true), 'smf_dropzone'); |
1216 | 1216 | loadJavaScriptFile('smf_fileUpload.js', array('defer' => true), 'smf_fileUpload'); |
1217 | 1217 | addInlineJavaScript(' |
1218 | 1218 | $(function() { |
1219 | 1219 | smf_fileUpload({ |
1220 | - dictDefaultMessage : '. JavaScriptEscape($txt['attach_drop_zone']) .', |
|
1221 | - dictFallbackMessage : '. JavaScriptEscape($txt['attach_drop_zone_no']) .', |
|
1222 | - dictCancelUpload : '. JavaScriptEscape($txt['modify_cancel']) .', |
|
1223 | - genericError: '. JavaScriptEscape($txt['attach_php_error']) .', |
|
1224 | - text_attachLeft: '. JavaScriptEscape($txt['attached_attachedLeft']) .', |
|
1225 | - text_deleteAttach: '. JavaScriptEscape($txt['attached_file_delete']) .', |
|
1226 | - text_attachDeleted: '. JavaScriptEscape($txt['attached_file_deleted']) .', |
|
1227 | - text_insertBBC: '. JavaScriptEscape($txt['attached_insertBBC']) .', |
|
1228 | - text_attachUploaded: '. JavaScriptEscape($txt['attached_file_uploaded']) .', |
|
1229 | - text_attach_unlimited: '. JavaScriptEscape($txt['attach_drop_unlimited']) .', |
|
1230 | - dictMaxFilesExceeded: '. JavaScriptEscape($txt['more_attachments_error']) .', |
|
1231 | - dictInvalidFileType: '. JavaScriptEscape(sprintf($txt['cant_upload_type'], $context['allowed_extensions'])) .', |
|
1232 | - dictFileTooBig: '. JavaScriptEscape(sprintf($txt['file_too_big'], comma_format($modSettings['attachmentSizeLimit'], 0))) .', |
|
1233 | - maxTotalSize: '. JavaScriptEscape($txt['attach_max_total_file_size_current']) .', |
|
1234 | - acceptedFiles: '. JavaScriptEscape($acceptedFiles) .', |
|
1235 | - maxFilesize: '. (!empty($modSettings['attachmentSizeLimit']) ? $modSettings['attachmentSizeLimit'] : 'null') .', |
|
1236 | - thumbnailWidth: '.(!empty($modSettings['attachmentThumbWidth']) ? $modSettings['attachmentThumbWidth'] : 'null') .', |
|
1237 | - thumbnailHeight: '.(!empty($modSettings['attachmentThumbHeight']) ? $modSettings['attachmentThumbHeight'] : 'null') .', |
|
1238 | - maxFiles: '. (!empty($context['num_allowed_attachments']) ? $context['num_allowed_attachments'] : 'null') .', |
|
1239 | - text_totalMaxSize: '. JavaScriptEscape($txt['attach_max_total_file_size_current']) .', |
|
1240 | - text_max_size_progress: '. JavaScriptEscape($txt['attach_max_size_progress']) .', |
|
1241 | - limitMultiFileUploadSize:'. round(max($modSettings['attachmentPostLimit'] - ($context['attachments']['total_size'] / 1024), 0)) * 1024 .', |
|
1242 | - maxLimitReferenceUploadSize: '. $modSettings['attachmentPostLimit'] * 1024 .', |
|
1220 | + dictDefaultMessage : '. JavaScriptEscape($txt['attach_drop_zone']) . ', |
|
1221 | + dictFallbackMessage : '. JavaScriptEscape($txt['attach_drop_zone_no']) . ', |
|
1222 | + dictCancelUpload : '. JavaScriptEscape($txt['modify_cancel']) . ', |
|
1223 | + genericError: '. JavaScriptEscape($txt['attach_php_error']) . ', |
|
1224 | + text_attachLeft: '. JavaScriptEscape($txt['attached_attachedLeft']) . ', |
|
1225 | + text_deleteAttach: '. JavaScriptEscape($txt['attached_file_delete']) . ', |
|
1226 | + text_attachDeleted: '. JavaScriptEscape($txt['attached_file_deleted']) . ', |
|
1227 | + text_insertBBC: '. JavaScriptEscape($txt['attached_insertBBC']) . ', |
|
1228 | + text_attachUploaded: '. JavaScriptEscape($txt['attached_file_uploaded']) . ', |
|
1229 | + text_attach_unlimited: '. JavaScriptEscape($txt['attach_drop_unlimited']) . ', |
|
1230 | + dictMaxFilesExceeded: '. JavaScriptEscape($txt['more_attachments_error']) . ', |
|
1231 | + dictInvalidFileType: '. JavaScriptEscape(sprintf($txt['cant_upload_type'], $context['allowed_extensions'])) . ', |
|
1232 | + dictFileTooBig: '. JavaScriptEscape(sprintf($txt['file_too_big'], comma_format($modSettings['attachmentSizeLimit'], 0))) . ', |
|
1233 | + maxTotalSize: '. JavaScriptEscape($txt['attach_max_total_file_size_current']) . ', |
|
1234 | + acceptedFiles: '. JavaScriptEscape($acceptedFiles) . ', |
|
1235 | + maxFilesize: '. (!empty($modSettings['attachmentSizeLimit']) ? $modSettings['attachmentSizeLimit'] : 'null') . ', |
|
1236 | + thumbnailWidth: '.(!empty($modSettings['attachmentThumbWidth']) ? $modSettings['attachmentThumbWidth'] : 'null') . ', |
|
1237 | + thumbnailHeight: '.(!empty($modSettings['attachmentThumbHeight']) ? $modSettings['attachmentThumbHeight'] : 'null') . ', |
|
1238 | + maxFiles: '. (!empty($context['num_allowed_attachments']) ? $context['num_allowed_attachments'] : 'null') . ', |
|
1239 | + text_totalMaxSize: '. JavaScriptEscape($txt['attach_max_total_file_size_current']) . ', |
|
1240 | + text_max_size_progress: '. JavaScriptEscape($txt['attach_max_size_progress']) . ', |
|
1241 | + limitMultiFileUploadSize:'. round(max($modSettings['attachmentPostLimit'] - ($context['attachments']['total_size'] / 1024), 0)) * 1024 . ', |
|
1242 | + maxLimitReferenceUploadSize: '. $modSettings['attachmentPostLimit'] * 1024 . ', |
|
1243 | 1243 | }); |
1244 | 1244 | });', true); |
1245 | 1245 | } |
1246 | 1246 | |
1247 | 1247 | // Knowing the current board ID might be handy. |
1248 | 1248 | addInlineJavaScript(' |
1249 | - var current_board = '. (empty($context['current_board']) ? 'null' : $context['current_board']) .';', false); |
|
1249 | + var current_board = '. (empty($context['current_board']) ? 'null' : $context['current_board']) . ';', false); |
|
1250 | 1250 | |
1251 | 1251 | // Finally, load the template. |
1252 | 1252 | if (!isset($_REQUEST['xml'])) |
@@ -1664,7 +1664,7 @@ discard block |
||
1664 | 1664 | } |
1665 | 1665 | |
1666 | 1666 | // Coming from the quickReply? |
1667 | - if(isset($_POST['quickReply'])) |
|
1667 | + if (isset($_POST['quickReply'])) |
|
1668 | 1668 | $_POST['message'] = $_POST['quickReply']; |
1669 | 1669 | |
1670 | 1670 | // Check the subject and message. |
@@ -2456,7 +2456,7 @@ discard block |
||
2456 | 2456 | FROM {db_prefix}messages AS m |
2457 | 2457 | LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member) |
2458 | 2458 | WHERE m.id_topic = {int:current_topic}' . (isset($_REQUEST['msg']) ? ' |
2459 | - AND m.id_msg < {int:id_msg}' : '') .(!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : ' |
|
2459 | + AND m.id_msg < {int:id_msg}' : '') . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : ' |
|
2460 | 2460 | AND m.approved = {int:approved}') . ' |
2461 | 2461 | ORDER BY m.id_msg DESC' . $limit, |
2462 | 2462 | array( |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 3 |
15 | 15 | */ |
16 | 16 | |
17 | -if (!defined('SMF')) |
|
17 | +if (!defined('SMF')) { |
|
18 | 18 | die('No direct access...'); |
19 | +} |
|
19 | 20 | |
20 | 21 | /** |
21 | 22 | * Handles showing the post screen, loading the post to be modified, and loading any post quoted. |
@@ -35,12 +36,14 @@ discard block |
||
35 | 36 | global $sourcedir, $smcFunc, $language; |
36 | 37 | |
37 | 38 | loadLanguage('Post'); |
38 | - if (!empty($modSettings['drafts_post_enabled'])) |
|
39 | - loadLanguage('Drafts'); |
|
39 | + if (!empty($modSettings['drafts_post_enabled'])) { |
|
40 | + loadLanguage('Drafts'); |
|
41 | + } |
|
40 | 42 | |
41 | 43 | // You can't reply with a poll... hacker. |
42 | - if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg'])) |
|
43 | - unset($_REQUEST['poll']); |
|
44 | + if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg'])) { |
|
45 | + unset($_REQUEST['poll']); |
|
46 | + } |
|
44 | 47 | |
45 | 48 | // Posting an event? |
46 | 49 | $context['make_event'] = isset($_REQUEST['calendar']); |
@@ -55,8 +58,9 @@ discard block |
||
55 | 58 | $context['auto_notify'] = !empty($context['notify_prefs']['msg_auto_notify']); |
56 | 59 | |
57 | 60 | // You must be posting to *some* board. |
58 | - if (empty($board) && !$context['make_event']) |
|
59 | - fatal_lang_error('no_board', false); |
|
61 | + if (empty($board) && !$context['make_event']) { |
|
62 | + fatal_lang_error('no_board', false); |
|
63 | + } |
|
60 | 64 | |
61 | 65 | require_once($sourcedir . '/Subs-Post.php'); |
62 | 66 | |
@@ -79,10 +83,11 @@ discard block |
||
79 | 83 | array( |
80 | 84 | 'msg' => (int) $_REQUEST['msg'], |
81 | 85 | )); |
82 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
83 | - unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']); |
|
84 | - else |
|
85 | - list ($topic) = $smcFunc['db_fetch_row']($request); |
|
86 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
87 | + unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']); |
|
88 | + } else { |
|
89 | + list ($topic) = $smcFunc['db_fetch_row']($request); |
|
90 | + } |
|
86 | 91 | $smcFunc['db_free_result']($request); |
87 | 92 | } |
88 | 93 | |
@@ -109,33 +114,36 @@ discard block |
||
109 | 114 | $smcFunc['db_free_result']($request); |
110 | 115 | |
111 | 116 | // If this topic already has a poll, they sure can't add another. |
112 | - if (isset($_REQUEST['poll']) && $pollID > 0) |
|
113 | - unset($_REQUEST['poll']); |
|
117 | + if (isset($_REQUEST['poll']) && $pollID > 0) { |
|
118 | + unset($_REQUEST['poll']); |
|
119 | + } |
|
114 | 120 | |
115 | 121 | if (empty($_REQUEST['msg'])) |
116 | 122 | { |
117 | - if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any'))) |
|
118 | - is_not_guest(); |
|
123 | + if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any'))) { |
|
124 | + is_not_guest(); |
|
125 | + } |
|
119 | 126 | |
120 | 127 | // By default the reply will be approved... |
121 | 128 | $context['becomes_approved'] = true; |
122 | 129 | if ($id_member_poster != $user_info['id'] || $user_info['is_guest']) |
123 | 130 | { |
124 | - if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) |
|
125 | - $context['becomes_approved'] = false; |
|
126 | - else |
|
127 | - isAllowedTo('post_reply_any'); |
|
128 | - } |
|
129 | - elseif (!allowedTo('post_reply_any')) |
|
131 | + if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) { |
|
132 | + $context['becomes_approved'] = false; |
|
133 | + } else { |
|
134 | + isAllowedTo('post_reply_any'); |
|
135 | + } |
|
136 | + } elseif (!allowedTo('post_reply_any')) |
|
130 | 137 | { |
131 | - if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any'))) |
|
132 | - $context['becomes_approved'] = false; |
|
133 | - else |
|
134 | - isAllowedTo('post_reply_own'); |
|
138 | + if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any'))) { |
|
139 | + $context['becomes_approved'] = false; |
|
140 | + } else { |
|
141 | + isAllowedTo('post_reply_own'); |
|
142 | + } |
|
135 | 143 | } |
144 | + } else { |
|
145 | + $context['becomes_approved'] = true; |
|
136 | 146 | } |
137 | - else |
|
138 | - $context['becomes_approved'] = true; |
|
139 | 147 | |
140 | 148 | $context['can_lock'] = allowedTo('lock_any') || ($user_info['id'] == $id_member_poster && allowedTo('lock_own')); |
141 | 149 | $context['can_sticky'] = allowedTo('make_sticky'); |
@@ -147,18 +155,19 @@ discard block |
||
147 | 155 | $context['sticky'] = isset($_REQUEST['sticky']) ? !empty($_REQUEST['sticky']) : $sticky; |
148 | 156 | |
149 | 157 | // Check whether this is a really old post being bumped... |
150 | - if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject'])) |
|
151 | - $post_errors[] = array('old_topic', array($modSettings['oldTopicDays'])); |
|
152 | - } |
|
153 | - else |
|
158 | + if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject'])) { |
|
159 | + $post_errors[] = array('old_topic', array($modSettings['oldTopicDays'])); |
|
160 | + } |
|
161 | + } else |
|
154 | 162 | { |
155 | 163 | $context['becomes_approved'] = true; |
156 | 164 | if ((!$context['make_event'] || !empty($board))) |
157 | 165 | { |
158 | - if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) |
|
159 | - $context['becomes_approved'] = false; |
|
160 | - else |
|
161 | - isAllowedTo('post_new'); |
|
166 | + if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) { |
|
167 | + $context['becomes_approved'] = false; |
|
168 | + } else { |
|
169 | + isAllowedTo('post_new'); |
|
170 | + } |
|
162 | 171 | } |
163 | 172 | |
164 | 173 | $locked = 0; |
@@ -196,20 +205,24 @@ discard block |
||
196 | 205 | } |
197 | 206 | |
198 | 207 | // Don't allow a post if it's locked and you aren't all powerful. |
199 | - if ($locked && !allowedTo('moderate_board')) |
|
200 | - fatal_lang_error('topic_locked', false); |
|
208 | + if ($locked && !allowedTo('moderate_board')) { |
|
209 | + fatal_lang_error('topic_locked', false); |
|
210 | + } |
|
201 | 211 | // Check the users permissions - is the user allowed to add or post a poll? |
202 | 212 | if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1') |
203 | 213 | { |
204 | 214 | // New topic, new poll. |
205 | - if (empty($topic)) |
|
206 | - isAllowedTo('poll_post'); |
|
215 | + if (empty($topic)) { |
|
216 | + isAllowedTo('poll_post'); |
|
217 | + } |
|
207 | 218 | // This is an old topic - but it is yours! Can you add to it? |
208 | - elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any')) |
|
209 | - isAllowedTo('poll_add_own'); |
|
219 | + elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any')) { |
|
220 | + isAllowedTo('poll_add_own'); |
|
221 | + } |
|
210 | 222 | // If you're not the owner, can you add to any poll? |
211 | - else |
|
212 | - isAllowedTo('poll_add_any'); |
|
223 | + else { |
|
224 | + isAllowedTo('poll_add_any'); |
|
225 | + } |
|
213 | 226 | |
214 | 227 | require_once($sourcedir . '/Subs-Members.php'); |
215 | 228 | $allowedVoteGroups = groupsAllowedTo('poll_vote', $board); |
@@ -238,8 +251,9 @@ discard block |
||
238 | 251 | if ($context['make_event']) |
239 | 252 | { |
240 | 253 | // They might want to pick a board. |
241 | - if (!isset($context['current_board'])) |
|
242 | - $context['current_board'] = 0; |
|
254 | + if (!isset($context['current_board'])) { |
|
255 | + $context['current_board'] = 0; |
|
256 | + } |
|
243 | 257 | |
244 | 258 | // Start loading up the event info. |
245 | 259 | $context['event'] = array(); |
@@ -277,26 +291,28 @@ discard block |
||
277 | 291 | $smcFunc['db_free_result']($request); |
278 | 292 | |
279 | 293 | // Make sure the user is allowed to edit this event. |
280 | - if ($row['id_member'] != $user_info['id']) |
|
281 | - isAllowedTo('calendar_edit_any'); |
|
282 | - elseif (!allowedTo('calendar_edit_any')) |
|
283 | - isAllowedTo('calendar_edit_own'); |
|
294 | + if ($row['id_member'] != $user_info['id']) { |
|
295 | + isAllowedTo('calendar_edit_any'); |
|
296 | + } elseif (!allowedTo('calendar_edit_any')) { |
|
297 | + isAllowedTo('calendar_edit_own'); |
|
298 | + } |
|
284 | 299 | |
285 | 300 | $context['event']['month'] = $row['month']; |
286 | 301 | $context['event']['day'] = $row['day']; |
287 | 302 | $context['event']['year'] = $row['year']; |
288 | 303 | $context['event']['title'] = $row['title']; |
289 | 304 | $context['event']['span'] = $row['span'] + 1; |
290 | - } |
|
291 | - else |
|
305 | + } else |
|
292 | 306 | { |
293 | 307 | $today = getdate(); |
294 | 308 | |
295 | 309 | // You must have a month and year specified! |
296 | - if (!isset($_REQUEST['month'])) |
|
297 | - $_REQUEST['month'] = $today['mon']; |
|
298 | - if (!isset($_REQUEST['year'])) |
|
299 | - $_REQUEST['year'] = $today['year']; |
|
310 | + if (!isset($_REQUEST['month'])) { |
|
311 | + $_REQUEST['month'] = $today['mon']; |
|
312 | + } |
|
313 | + if (!isset($_REQUEST['year'])) { |
|
314 | + $_REQUEST['year'] = $today['year']; |
|
315 | + } |
|
300 | 316 | |
301 | 317 | $context['event']['month'] = (int) $_REQUEST['month']; |
302 | 318 | $context['event']['year'] = (int) $_REQUEST['year']; |
@@ -304,15 +320,18 @@ discard block |
||
304 | 320 | $context['event']['span'] = isset($_REQUEST['span']) ? $_REQUEST['span'] : 1; |
305 | 321 | |
306 | 322 | // Make sure the year and month are in the valid range. |
307 | - if ($context['event']['month'] < 1 || $context['event']['month'] > 12) |
|
308 | - fatal_lang_error('invalid_month', false); |
|
309 | - if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear']) |
|
310 | - fatal_lang_error('invalid_year', false); |
|
323 | + if ($context['event']['month'] < 1 || $context['event']['month'] > 12) { |
|
324 | + fatal_lang_error('invalid_month', false); |
|
325 | + } |
|
326 | + if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear']) { |
|
327 | + fatal_lang_error('invalid_year', false); |
|
328 | + } |
|
311 | 329 | |
312 | 330 | // Get a list of boards they can post in. |
313 | 331 | $boards = boardsAllowedTo('post_new'); |
314 | - if (empty($boards)) |
|
315 | - fatal_lang_error('cannot_post_new', 'user'); |
|
332 | + if (empty($boards)) { |
|
333 | + fatal_lang_error('cannot_post_new', 'user'); |
|
334 | + } |
|
316 | 335 | |
317 | 336 | // Load a list of boards for this event in the context. |
318 | 337 | require_once($sourcedir . '/Subs-MessageIndex.php'); |
@@ -357,10 +376,11 @@ discard block |
||
357 | 376 | |
358 | 377 | if (!empty($context['new_replies'])) |
359 | 378 | { |
360 | - if ($context['new_replies'] == 1) |
|
361 | - $txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply']; |
|
362 | - else |
|
363 | - $txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']); |
|
379 | + if ($context['new_replies'] == 1) { |
|
380 | + $txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply']; |
|
381 | + } else { |
|
382 | + $txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']); |
|
383 | + } |
|
364 | 384 | |
365 | 385 | $post_errors[] = 'new_replies'; |
366 | 386 | |
@@ -372,9 +392,9 @@ discard block |
||
372 | 392 | // Get a response prefix (like 'Re:') in the default forum language. |
373 | 393 | if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) |
374 | 394 | { |
375 | - if ($language === $user_info['language']) |
|
376 | - $context['response_prefix'] = $txt['response_prefix']; |
|
377 | - else |
|
395 | + if ($language === $user_info['language']) { |
|
396 | + $context['response_prefix'] = $txt['response_prefix']; |
|
397 | + } else |
|
378 | 398 | { |
379 | 399 | loadLanguage('index', $language, false); |
380 | 400 | $context['response_prefix'] = $txt['response_prefix']; |
@@ -387,8 +407,9 @@ discard block |
||
387 | 407 | // Do we have a body, but an error happened. |
388 | 408 | if (isset($_REQUEST['message']) || isset($_REQUEST['quickReply']) || !empty($context['post_error'])) |
389 | 409 | { |
390 | - if (isset($_REQUEST['quickReply'])) |
|
391 | - $_REQUEST['message'] = $_REQUEST['quickReply']; |
|
410 | + if (isset($_REQUEST['quickReply'])) { |
|
411 | + $_REQUEST['message'] = $_REQUEST['quickReply']; |
|
412 | + } |
|
392 | 413 | |
393 | 414 | // Validate inputs. |
394 | 415 | if (empty($context['post_error'])) |
@@ -396,15 +417,17 @@ discard block |
||
396 | 417 | // This means they didn't click Post and get an error. |
397 | 418 | $really_previewing = true; |
398 | 419 | |
399 | - } |
|
400 | - else |
|
420 | + } else |
|
401 | 421 | { |
402 | - if (!isset($_REQUEST['subject'])) |
|
403 | - $_REQUEST['subject'] = ''; |
|
404 | - if (!isset($_REQUEST['message'])) |
|
405 | - $_REQUEST['message'] = ''; |
|
406 | - if (!isset($_REQUEST['icon'])) |
|
407 | - $_REQUEST['icon'] = 'xx'; |
|
422 | + if (!isset($_REQUEST['subject'])) { |
|
423 | + $_REQUEST['subject'] = ''; |
|
424 | + } |
|
425 | + if (!isset($_REQUEST['message'])) { |
|
426 | + $_REQUEST['message'] = ''; |
|
427 | + } |
|
428 | + if (!isset($_REQUEST['icon'])) { |
|
429 | + $_REQUEST['icon'] = 'xx'; |
|
430 | + } |
|
408 | 431 | |
409 | 432 | // They are previewing if they asked to preview (i.e. came from quick reply). |
410 | 433 | $really_previewing = !empty($_POST['preview']); |
@@ -420,8 +443,9 @@ discard block |
||
420 | 443 | $form_message = $smcFunc['htmlspecialchars']($_REQUEST['message'], ENT_QUOTES); |
421 | 444 | |
422 | 445 | // Make sure the subject isn't too long - taking into account special characters. |
423 | - if ($smcFunc['strlen']($form_subject) > 100) |
|
424 | - $form_subject = $smcFunc['substr']($form_subject, 0, 100); |
|
446 | + if ($smcFunc['strlen']($form_subject) > 100) { |
|
447 | + $form_subject = $smcFunc['substr']($form_subject, 0, 100); |
|
448 | + } |
|
425 | 449 | |
426 | 450 | if (isset($_REQUEST['poll'])) |
427 | 451 | { |
@@ -433,8 +457,9 @@ discard block |
||
433 | 457 | $_POST['options'] = empty($_POST['options']) ? array() : htmlspecialchars__recursive($_POST['options']); |
434 | 458 | foreach ($_POST['options'] as $option) |
435 | 459 | { |
436 | - if (trim($option) == '') |
|
437 | - continue; |
|
460 | + if (trim($option) == '') { |
|
461 | + continue; |
|
462 | + } |
|
438 | 463 | |
439 | 464 | $context['choices'][] = array( |
440 | 465 | 'id' => $choice_id++, |
@@ -496,13 +521,14 @@ discard block |
||
496 | 521 | $context['preview_subject'] = $form_subject; |
497 | 522 | |
498 | 523 | censorText($context['preview_subject']); |
524 | + } else { |
|
525 | + $context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>'; |
|
499 | 526 | } |
500 | - else |
|
501 | - $context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>'; |
|
502 | 527 | |
503 | 528 | // Protect any CDATA blocks. |
504 | - if (isset($_REQUEST['xml'])) |
|
505 | - $context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>')); |
|
529 | + if (isset($_REQUEST['xml'])) { |
|
530 | + $context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]>< == 0) |
|
545 | - fatal_lang_error('no_board', false); |
|
570 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
571 | + fatal_lang_error('no_board', false); |
|
572 | + } |
|
546 | 573 | $row = $smcFunc['db_fetch_assoc']($request); |
547 | 574 | |
548 | 575 | $attachment_stuff = array($row); |
549 | - while ($row2 = $smcFunc['db_fetch_assoc']($request)) |
|
550 | - $attachment_stuff[] = $row2; |
|
576 | + while ($row2 = $smcFunc['db_fetch_assoc']($request)) { |
|
577 | + $attachment_stuff[] = $row2; |
|
578 | + } |
|
551 | 579 | $smcFunc['db_free_result']($request); |
552 | 580 | |
553 | 581 | if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any')) |
554 | 582 | { |
555 | 583 | // Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public. |
556 | - if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) |
|
557 | - fatal_lang_error('modify_post_time_passed', false); |
|
558 | - elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) |
|
559 | - isAllowedTo('modify_replies'); |
|
560 | - else |
|
561 | - isAllowedTo('modify_own'); |
|
584 | + if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) { |
|
585 | + fatal_lang_error('modify_post_time_passed', false); |
|
586 | + } elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) { |
|
587 | + isAllowedTo('modify_replies'); |
|
588 | + } else { |
|
589 | + isAllowedTo('modify_own'); |
|
590 | + } |
|
591 | + } elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) { |
|
592 | + isAllowedTo('modify_replies'); |
|
593 | + } else { |
|
594 | + isAllowedTo('modify_any'); |
|
562 | 595 | } |
563 | - elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) |
|
564 | - isAllowedTo('modify_replies'); |
|
565 | - else |
|
566 | - isAllowedTo('modify_any'); |
|
567 | 596 | |
568 | 597 | if ($context['can_announce'] && !empty($row['id_action'])) |
569 | 598 | { |
@@ -587,8 +616,9 @@ discard block |
||
587 | 616 | |
588 | 617 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
589 | 618 | { |
590 | - if ($row['filesize'] <= 0) |
|
591 | - continue; |
|
619 | + if ($row['filesize'] <= 0) { |
|
620 | + continue; |
|
621 | + } |
|
592 | 622 | $context['current_attachments'][$row['id_attach']] = array( |
593 | 623 | 'name' => $smcFunc['htmlspecialchars']($row['filename']), |
594 | 624 | 'size' => $row['filesize'], |
@@ -658,29 +688,32 @@ discard block |
||
658 | 688 | ) |
659 | 689 | ); |
660 | 690 | // The message they were trying to edit was most likely deleted. |
661 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
662 | - fatal_lang_error('no_message', false); |
|
691 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
692 | + fatal_lang_error('no_message', false); |
|
693 | + } |
|
663 | 694 | $row = $smcFunc['db_fetch_assoc']($request); |
664 | 695 | |
665 | 696 | $attachment_stuff = array($row); |
666 | - while ($row2 = $smcFunc['db_fetch_assoc']($request)) |
|
667 | - $attachment_stuff[] = $row2; |
|
697 | + while ($row2 = $smcFunc['db_fetch_assoc']($request)) { |
|
698 | + $attachment_stuff[] = $row2; |
|
699 | + } |
|
668 | 700 | $smcFunc['db_free_result']($request); |
669 | 701 | |
670 | 702 | if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any')) |
671 | 703 | { |
672 | 704 | // Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public. |
673 | - if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) |
|
674 | - fatal_lang_error('modify_post_time_passed', false); |
|
675 | - elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) |
|
676 | - isAllowedTo('modify_replies'); |
|
677 | - else |
|
678 | - isAllowedTo('modify_own'); |
|
705 | + if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) { |
|
706 | + fatal_lang_error('modify_post_time_passed', false); |
|
707 | + } elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) { |
|
708 | + isAllowedTo('modify_replies'); |
|
709 | + } else { |
|
710 | + isAllowedTo('modify_own'); |
|
711 | + } |
|
712 | + } elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) { |
|
713 | + isAllowedTo('modify_replies'); |
|
714 | + } else { |
|
715 | + isAllowedTo('modify_any'); |
|
679 | 716 | } |
680 | - elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) |
|
681 | - isAllowedTo('modify_replies'); |
|
682 | - else |
|
683 | - isAllowedTo('modify_any'); |
|
684 | 717 | |
685 | 718 | if ($context['can_announce'] && !empty($row['id_action'])) |
686 | 719 | { |
@@ -707,15 +740,17 @@ discard block |
||
707 | 740 | $context['icon'] = $row['icon']; |
708 | 741 | |
709 | 742 | // Show an "approve" box if the user can approve it, and the message isn't approved. |
710 | - if (!$row['approved'] && !$context['show_approval']) |
|
711 | - $context['show_approval'] = allowedTo('approve_posts'); |
|
743 | + if (!$row['approved'] && !$context['show_approval']) { |
|
744 | + $context['show_approval'] = allowedTo('approve_posts'); |
|
745 | + } |
|
712 | 746 | |
713 | 747 | // Sort the attachments so they are in the order saved |
714 | 748 | $temp = array(); |
715 | 749 | foreach ($attachment_stuff as $attachment) |
716 | 750 | { |
717 | - if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable'])) |
|
718 | - $temp[$attachment['id_attach']] = $attachment; |
|
751 | + if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable'])) { |
|
752 | + $temp[$attachment['id_attach']] = $attachment; |
|
753 | + } |
|
719 | 754 | |
720 | 755 | } |
721 | 756 | ksort($temp); |
@@ -777,14 +812,16 @@ discard block |
||
777 | 812 | 'is_approved' => 1, |
778 | 813 | ) |
779 | 814 | ); |
780 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
781 | - fatal_lang_error('quoted_post_deleted', false); |
|
815 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
816 | + fatal_lang_error('quoted_post_deleted', false); |
|
817 | + } |
|
782 | 818 | list ($form_subject, $mname, $mdate, $form_message) = $smcFunc['db_fetch_row']($request); |
783 | 819 | $smcFunc['db_free_result']($request); |
784 | 820 | |
785 | 821 | // Add 'Re: ' to the front of the quoted subject. |
786 | - if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) |
|
787 | - $form_subject = $context['response_prefix'] . $form_subject; |
|
822 | + if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) { |
|
823 | + $form_subject = $context['response_prefix'] . $form_subject; |
|
824 | + } |
|
788 | 825 | |
789 | 826 | // Censor the message and subject. |
790 | 827 | censorText($form_message); |
@@ -797,10 +834,11 @@ discard block |
||
797 | 834 | for ($i = 0, $n = count($parts); $i < $n; $i++) |
798 | 835 | { |
799 | 836 | // It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat. |
800 | - if ($i % 4 == 0) |
|
801 | - $parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function ($m) |
|
837 | + if ($i % 4 == 0) { |
|
838 | + $parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function ($m) |
|
802 | 839 | { |
803 | 840 | return '[html]' . preg_replace('~<br\s?/?' . '>~i', '<br /><br>', "$m[1]") . '[/html]'; |
841 | + } |
|
804 | 842 | }, $parts[$i]); |
805 | 843 | } |
806 | 844 | $form_message = implode('', $parts); |
@@ -809,8 +847,9 @@ discard block |
||
809 | 847 | $form_message = preg_replace('~<br ?/?' . '>~i', "\n", $form_message); |
810 | 848 | |
811 | 849 | // Remove any nested quotes, if necessary. |
812 | - if (!empty($modSettings['removeNestedQuotes'])) |
|
813 | - $form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message); |
|
850 | + if (!empty($modSettings['removeNestedQuotes'])) { |
|
851 | + $form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message); |
|
852 | + } |
|
814 | 853 | |
815 | 854 | // Add a quote string on the front and end. |
816 | 855 | $form_message = '[quote author=' . $mname . ' link=msg=' . (int) $_REQUEST['quote'] . ' date=' . $mdate . ']' . "\n" . rtrim($form_message) . "\n" . '[/quote]'; |
@@ -822,15 +861,15 @@ discard block |
||
822 | 861 | $form_subject = $first_subject; |
823 | 862 | |
824 | 863 | // Add 'Re: ' to the front of the subject. |
825 | - if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) |
|
826 | - $form_subject = $context['response_prefix'] . $form_subject; |
|
864 | + if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) { |
|
865 | + $form_subject = $context['response_prefix'] . $form_subject; |
|
866 | + } |
|
827 | 867 | |
828 | 868 | // Censor the subject. |
829 | 869 | censorText($form_subject); |
830 | 870 | |
831 | 871 | $form_message = ''; |
832 | - } |
|
833 | - else |
|
872 | + } else |
|
834 | 873 | { |
835 | 874 | $form_subject = isset($_GET['subject']) ? $_GET['subject'] : ''; |
836 | 875 | $form_message = ''; |
@@ -848,13 +887,15 @@ discard block |
||
848 | 887 | if (isset($_REQUEST['msg'])) |
849 | 888 | { |
850 | 889 | $context['attachments']['quantity'] = count($context['current_attachments']); |
851 | - foreach ($context['current_attachments'] as $attachment) |
|
852 | - $context['attachments']['total_size'] += $attachment['size']; |
|
890 | + foreach ($context['current_attachments'] as $attachment) { |
|
891 | + $context['attachments']['total_size'] += $attachment['size']; |
|
892 | + } |
|
853 | 893 | } |
854 | 894 | |
855 | 895 | // A bit of house keeping first. |
856 | - if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) |
|
857 | - unset($_SESSION['temp_attachments']); |
|
896 | + if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) { |
|
897 | + unset($_SESSION['temp_attachments']); |
|
898 | + } |
|
858 | 899 | |
859 | 900 | if (!empty($_SESSION['temp_attachments'])) |
860 | 901 | { |
@@ -863,9 +904,10 @@ discard block |
||
863 | 904 | { |
864 | 905 | foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
865 | 906 | { |
866 | - if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
867 | - if (file_exists($attachment['tmp_name'])) |
|
907 | + if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) { |
|
908 | + if (file_exists($attachment['tmp_name'])) |
|
868 | 909 | unlink($attachment['tmp_name']); |
910 | + } |
|
869 | 911 | } |
870 | 912 | $post_errors[] = 'temp_attachments_gone'; |
871 | 913 | $_SESSION['temp_attachments'] = array(); |
@@ -879,8 +921,9 @@ discard block |
||
879 | 921 | // See if any files still exist before showing the warning message and the files attached. |
880 | 922 | foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
881 | 923 | { |
882 | - if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false) |
|
883 | - continue; |
|
924 | + if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false) { |
|
925 | + continue; |
|
926 | + } |
|
884 | 927 | |
885 | 928 | if (file_exists($attachment['tmp_name'])) |
886 | 929 | { |
@@ -890,20 +933,21 @@ discard block |
||
890 | 933 | break; |
891 | 934 | } |
892 | 935 | } |
893 | - } |
|
894 | - else |
|
936 | + } else |
|
895 | 937 | { |
896 | 938 | // Since, they don't belong here. Let's inform the user that they exist.. |
897 | - if (!empty($topic)) |
|
898 | - $delete_url = $scripturl . '?action=post' .(!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp'; |
|
899 | - else |
|
900 | - $delete_url = $scripturl . '?action=post;board=' . $board . ';delete_temp'; |
|
939 | + if (!empty($topic)) { |
|
940 | + $delete_url = $scripturl . '?action=post' .(!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp'; |
|
941 | + } else { |
|
942 | + $delete_url = $scripturl . '?action=post;board=' . $board . ';delete_temp'; |
|
943 | + } |
|
901 | 944 | |
902 | 945 | // Compile a list of the files to show the user. |
903 | 946 | $file_list = array(); |
904 | - foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
|
905 | - if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
947 | + foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) { |
|
948 | + if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
906 | 949 | $file_list[] = $attachment['name']; |
950 | + } |
|
907 | 951 | |
908 | 952 | $_SESSION['temp_attachments']['post']['files'] = $file_list; |
909 | 953 | $file_list = '<div class="attachments">' . implode('<br>', $file_list) . '</div>'; |
@@ -915,8 +959,7 @@ discard block |
||
915 | 959 | |
916 | 960 | $post_errors[] = array('temp_attachments_found', array($delete_url, $goback_url, $file_list)); |
917 | 961 | $context['ignore_temp_attachments'] = true; |
918 | - } |
|
919 | - else |
|
962 | + } else |
|
920 | 963 | { |
921 | 964 | $post_errors[] = array('temp_attachments_lost', array($delete_url, $file_list)); |
922 | 965 | $context['ignore_temp_attachments'] = true; |
@@ -924,16 +967,19 @@ discard block |
||
924 | 967 | } |
925 | 968 | } |
926 | 969 | |
927 | - if (!empty($context['we_are_history'])) |
|
928 | - $post_errors[] = $context['we_are_history']; |
|
970 | + if (!empty($context['we_are_history'])) { |
|
971 | + $post_errors[] = $context['we_are_history']; |
|
972 | + } |
|
929 | 973 | |
930 | 974 | foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
931 | 975 | { |
932 | - if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files'])) |
|
933 | - break; |
|
976 | + if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files'])) { |
|
977 | + break; |
|
978 | + } |
|
934 | 979 | |
935 | - if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) |
|
936 | - continue; |
|
980 | + if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) { |
|
981 | + continue; |
|
982 | + } |
|
937 | 983 | |
938 | 984 | if ($attachID == 'initial_error') |
939 | 985 | { |
@@ -948,15 +994,17 @@ discard block |
||
948 | 994 | { |
949 | 995 | $txt['error_attach_errors'] = empty($txt['error_attach_errors']) ? '<br>' : ''; |
950 | 996 | $txt['error_attach_errors'] .= vsprintf($txt['attach_warning'], $attachment['name']) . '<div style="padding: 0 1em;">'; |
951 | - foreach ($attachment['errors'] as $error) |
|
952 | - $txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >'; |
|
997 | + foreach ($attachment['errors'] as $error) { |
|
998 | + $txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >'; |
|
999 | + } |
|
953 | 1000 | $txt['error_attach_errors'] .= '</div>'; |
954 | 1001 | $post_errors[] = 'attach_errors'; |
955 | 1002 | |
956 | 1003 | // Take out the trash. |
957 | 1004 | unset($_SESSION['temp_attachments'][$attachID]); |
958 | - if (file_exists($attachment['tmp_name'])) |
|
959 | - unlink($attachment['tmp_name']); |
|
1005 | + if (file_exists($attachment['tmp_name'])) { |
|
1006 | + unlink($attachment['tmp_name']); |
|
1007 | + } |
|
960 | 1008 | continue; |
961 | 1009 | } |
962 | 1010 | |
@@ -969,8 +1017,9 @@ discard block |
||
969 | 1017 | |
970 | 1018 | $context['attachments']['quantity']++; |
971 | 1019 | $context['attachments']['total_size'] += $attachment['size']; |
972 | - if (!isset($context['files_in_session_warning'])) |
|
973 | - $context['files_in_session_warning'] = $txt['attached_files_in_session']; |
|
1020 | + if (!isset($context['files_in_session_warning'])) { |
|
1021 | + $context['files_in_session_warning'] = $txt['attached_files_in_session']; |
|
1022 | + } |
|
974 | 1023 | |
975 | 1024 | $context['current_attachments'][$attachID] = array( |
976 | 1025 | 'name' => '<u>' . $smcFunc['htmlspecialchars']($attachment['name']) . '</u>', |
@@ -998,8 +1047,9 @@ discard block |
||
998 | 1047 | } |
999 | 1048 | |
1000 | 1049 | // If they came from quick reply, and have to enter verification details, give them some notice. |
1001 | - if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification'])) |
|
1002 | - $post_errors[] = 'need_qr_verification'; |
|
1050 | + if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification'])) { |
|
1051 | + $post_errors[] = 'need_qr_verification'; |
|
1052 | + } |
|
1003 | 1053 | |
1004 | 1054 | /* |
1005 | 1055 | * There are two error types: serious and minor. Serious errors |
@@ -1016,52 +1066,56 @@ discard block |
||
1016 | 1066 | { |
1017 | 1067 | loadLanguage('Errors'); |
1018 | 1068 | $context['error_type'] = 'minor'; |
1019 | - foreach ($post_errors as $post_error) |
|
1020 | - if (is_array($post_error)) |
|
1069 | + foreach ($post_errors as $post_error) { |
|
1070 | + if (is_array($post_error)) |
|
1021 | 1071 | { |
1022 | 1072 | $post_error_id = $post_error[0]; |
1073 | + } |
|
1023 | 1074 | $context['post_error'][$post_error_id] = vsprintf($txt['error_' . $post_error_id], $post_error[1]); |
1024 | 1075 | |
1025 | 1076 | // If it's not a minor error flag it as such. |
1026 | - if (!in_array($post_error_id, $minor_errors)) |
|
1027 | - $context['error_type'] = 'serious'; |
|
1028 | - } |
|
1029 | - else |
|
1077 | + if (!in_array($post_error_id, $minor_errors)) { |
|
1078 | + $context['error_type'] = 'serious'; |
|
1079 | + } |
|
1080 | + } else |
|
1030 | 1081 | { |
1031 | 1082 | $context['post_error'][$post_error] = $txt['error_' . $post_error]; |
1032 | 1083 | |
1033 | 1084 | // If it's not a minor error flag it as such. |
1034 | - if (!in_array($post_error, $minor_errors)) |
|
1035 | - $context['error_type'] = 'serious'; |
|
1085 | + if (!in_array($post_error, $minor_errors)) { |
|
1086 | + $context['error_type'] = 'serious'; |
|
1087 | + } |
|
1036 | 1088 | } |
1037 | 1089 | } |
1038 | 1090 | |
1039 | 1091 | // What are you doing? Posting a poll, modifying, previewing, new post, or reply... |
1040 | - if (isset($_REQUEST['poll'])) |
|
1041 | - $context['page_title'] = $txt['new_poll']; |
|
1042 | - elseif ($context['make_event']) |
|
1043 | - $context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit']; |
|
1044 | - elseif (isset($_REQUEST['msg'])) |
|
1045 | - $context['page_title'] = $txt['modify_msg']; |
|
1046 | - elseif (isset($_REQUEST['subject'], $context['preview_subject'])) |
|
1047 | - $context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']); |
|
1048 | - elseif (empty($topic)) |
|
1049 | - $context['page_title'] = $txt['start_new_topic']; |
|
1050 | - else |
|
1051 | - $context['page_title'] = $txt['post_reply']; |
|
1092 | + if (isset($_REQUEST['poll'])) { |
|
1093 | + $context['page_title'] = $txt['new_poll']; |
|
1094 | + } elseif ($context['make_event']) { |
|
1095 | + $context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit']; |
|
1096 | + } elseif (isset($_REQUEST['msg'])) { |
|
1097 | + $context['page_title'] = $txt['modify_msg']; |
|
1098 | + } elseif (isset($_REQUEST['subject'], $context['preview_subject'])) { |
|
1099 | + $context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']); |
|
1100 | + } elseif (empty($topic)) { |
|
1101 | + $context['page_title'] = $txt['start_new_topic']; |
|
1102 | + } else { |
|
1103 | + $context['page_title'] = $txt['post_reply']; |
|
1104 | + } |
|
1052 | 1105 | |
1053 | 1106 | // Build the link tree. |
1054 | - if (empty($topic)) |
|
1055 | - $context['linktree'][] = array( |
|
1107 | + if (empty($topic)) { |
|
1108 | + $context['linktree'][] = array( |
|
1056 | 1109 | 'name' => '<em>' . $txt['start_new_topic'] . '</em>' |
1057 | 1110 | ); |
1058 | - else |
|
1059 | - $context['linktree'][] = array( |
|
1111 | + } else { |
|
1112 | + $context['linktree'][] = array( |
|
1060 | 1113 | 'url' => $scripturl . '?topic=' . $topic . '.' . $_REQUEST['start'], |
1061 | 1114 | 'name' => $form_subject, |
1062 | 1115 | 'extra_before' => '<span><strong class="nav">' . $context['page_title'] . ' (</strong></span>', |
1063 | 1116 | 'extra_after' => '<span><strong class="nav">)</strong></span>' |
1064 | 1117 | ); |
1118 | + } |
|
1065 | 1119 | |
1066 | 1120 | $context['subject'] = addcslashes($form_subject, '"'); |
1067 | 1121 | $context['message'] = str_replace(array('"', '<', '>', ' '), array('"', '<', '>', ' '), $form_message); |
@@ -1105,8 +1159,9 @@ discard block |
||
1105 | 1159 | // Message icons - customized icons are off? |
1106 | 1160 | $context['icons'] = getMessageIcons($board); |
1107 | 1161 | |
1108 | - if (!empty($context['icons'])) |
|
1109 | - $context['icons'][count($context['icons']) - 1]['is_last'] = true; |
|
1162 | + if (!empty($context['icons'])) { |
|
1163 | + $context['icons'][count($context['icons']) - 1]['is_last'] = true; |
|
1164 | + } |
|
1110 | 1165 | |
1111 | 1166 | // Are we starting a poll? if set the poll icon as selected if its available |
1112 | 1167 | if (isset($_REQUEST['poll'])) |
@@ -1126,8 +1181,9 @@ discard block |
||
1126 | 1181 | for ($i = 0, $n = count($context['icons']); $i < $n; $i++) |
1127 | 1182 | { |
1128 | 1183 | $context['icons'][$i]['selected'] = $context['icon'] == $context['icons'][$i]['value']; |
1129 | - if ($context['icons'][$i]['selected']) |
|
1130 | - $context['icon_url'] = $context['icons'][$i]['url']; |
|
1184 | + if ($context['icons'][$i]['selected']) { |
|
1185 | + $context['icon_url'] = $context['icons'][$i]['url']; |
|
1186 | + } |
|
1131 | 1187 | } |
1132 | 1188 | if (empty($context['icon_url'])) |
1133 | 1189 | { |
@@ -1141,8 +1197,9 @@ discard block |
||
1141 | 1197 | )); |
1142 | 1198 | } |
1143 | 1199 | |
1144 | - if (!empty($topic) && !empty($modSettings['topicSummaryPosts'])) |
|
1145 | - getTopic(); |
|
1200 | + if (!empty($topic) && !empty($modSettings['topicSummaryPosts'])) { |
|
1201 | + getTopic(); |
|
1202 | + } |
|
1146 | 1203 | |
1147 | 1204 | // If the user can post attachments prepare the warning labels. |
1148 | 1205 | if ($context['can_post_attachment']) |
@@ -1153,15 +1210,17 @@ discard block |
||
1153 | 1210 | $context['attachment_restrictions'] = array(); |
1154 | 1211 | $context['allowed_extensions'] = strtr(strtolower($modSettings['attachmentExtensions']), array(',' => ', ')); |
1155 | 1212 | $attachmentRestrictionTypes = array('attachmentNumPerPostLimit', 'attachmentPostLimit', 'attachmentSizeLimit'); |
1156 | - foreach ($attachmentRestrictionTypes as $type) |
|
1157 | - if (!empty($modSettings[$type])) |
|
1213 | + foreach ($attachmentRestrictionTypes as $type) { |
|
1214 | + if (!empty($modSettings[$type])) |
|
1158 | 1215 | { |
1159 | 1216 | $context['attachment_restrictions'][] = sprintf($txt['attach_restrict_' . $type . ($modSettings[$type] >= 1024 ? '_MB' : '')], comma_format($modSettings[$type], 0)); |
1217 | + } |
|
1160 | 1218 | // Show some numbers. If they exist. |
1161 | - if ($type == 'attachmentNumPerPostLimit' && $context['attachments']['quantity'] > 0) |
|
1162 | - $context['attachment_restrictions'][] = sprintf($txt['attach_remaining'], $modSettings['attachmentNumPerPostLimit'] - $context['attachments']['quantity']); |
|
1163 | - elseif ($type == 'attachmentPostLimit' && $context['attachments']['total_size'] > 0) |
|
1164 | - $context['attachment_restrictions'][] = sprintf($txt['attach_available'], comma_format(round(max($modSettings['attachmentPostLimit'] - ($context['attachments']['total_size'] / 1024), 0)), 0)); |
|
1219 | + if ($type == 'attachmentNumPerPostLimit' && $context['attachments']['quantity'] > 0) { |
|
1220 | + $context['attachment_restrictions'][] = sprintf($txt['attach_remaining'], $modSettings['attachmentNumPerPostLimit'] - $context['attachments']['quantity']); |
|
1221 | + } elseif ($type == 'attachmentPostLimit' && $context['attachments']['total_size'] > 0) { |
|
1222 | + $context['attachment_restrictions'][] = sprintf($txt['attach_available'], comma_format(round(max($modSettings['attachmentPostLimit'] - ($context['attachments']['total_size'] / 1024), 0)), 0)); |
|
1223 | + } |
|
1165 | 1224 | } |
1166 | 1225 | } |
1167 | 1226 | |
@@ -1195,8 +1254,8 @@ discard block |
||
1195 | 1254 | |
1196 | 1255 | if (!empty($context['current_attachments'])) |
1197 | 1256 | { |
1198 | - foreach ($context['current_attachments'] as $key => $mock) |
|
1199 | - addInlineJavaScript(' |
|
1257 | + foreach ($context['current_attachments'] as $key => $mock) { |
|
1258 | + addInlineJavaScript(' |
|
1200 | 1259 | current_attachments.push({ |
1201 | 1260 | name: '. JavaScriptEscape($mock['name']) .', |
1202 | 1261 | size: '. $mock['size'] .', |
@@ -1205,6 +1264,7 @@ discard block |
||
1205 | 1264 | type: '. JavaScriptEscape(!empty($mock['mime_type']) ? $mock['mime_type'] : '') .', |
1206 | 1265 | thumbID: '. (!empty($mock['thumb']) ? $mock['thumb'] : 0) .' |
1207 | 1266 | });', true); |
1267 | + } |
|
1208 | 1268 | } |
1209 | 1269 | |
1210 | 1270 | // File Upload. |
@@ -1249,8 +1309,9 @@ discard block |
||
1249 | 1309 | var current_board = '. (empty($context['current_board']) ? 'null' : $context['current_board']) .';', false); |
1250 | 1310 | |
1251 | 1311 | // Finally, load the template. |
1252 | - if (!isset($_REQUEST['xml'])) |
|
1253 | - loadTemplate('Post'); |
|
1312 | + if (!isset($_REQUEST['xml'])) { |
|
1313 | + loadTemplate('Post'); |
|
1314 | + } |
|
1254 | 1315 | |
1255 | 1316 | call_integration_hook('integrate_post_end'); |
1256 | 1317 | } |
@@ -1271,13 +1332,14 @@ discard block |
||
1271 | 1332 | // Sneaking off, are we? |
1272 | 1333 | if (empty($_POST) && empty($topic)) |
1273 | 1334 | { |
1274 | - if (empty($_SERVER['CONTENT_LENGTH'])) |
|
1275 | - redirectexit('action=post;board=' . $board . '.0'); |
|
1276 | - else |
|
1277 | - fatal_lang_error('post_upload_error', false); |
|
1335 | + if (empty($_SERVER['CONTENT_LENGTH'])) { |
|
1336 | + redirectexit('action=post;board=' . $board . '.0'); |
|
1337 | + } else { |
|
1338 | + fatal_lang_error('post_upload_error', false); |
|
1339 | + } |
|
1340 | + } elseif (empty($_POST) && !empty($topic)) { |
|
1341 | + redirectexit('action=post;topic=' . $topic . '.0'); |
|
1278 | 1342 | } |
1279 | - elseif (empty($_POST) && !empty($topic)) |
|
1280 | - redirectexit('action=post;topic=' . $topic . '.0'); |
|
1281 | 1343 | |
1282 | 1344 | // No need! |
1283 | 1345 | $context['robot_no_index'] = true; |
@@ -1289,8 +1351,9 @@ discard block |
||
1289 | 1351 | $post_errors = array(); |
1290 | 1352 | |
1291 | 1353 | // If the session has timed out, let the user re-submit their form. |
1292 | - if (checkSession('post', '', false) != '') |
|
1293 | - $post_errors[] = 'session_timeout'; |
|
1354 | + if (checkSession('post', '', false) != '') { |
|
1355 | + $post_errors[] = 'session_timeout'; |
|
1356 | + } |
|
1294 | 1357 | |
1295 | 1358 | // Wrong verification code? |
1296 | 1359 | if (!$user_info['is_admin'] && !$user_info['is_mod'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1))) |
@@ -1300,33 +1363,38 @@ discard block |
||
1300 | 1363 | 'id' => 'post', |
1301 | 1364 | ); |
1302 | 1365 | $context['require_verification'] = create_control_verification($verificationOptions, true); |
1303 | - if (is_array($context['require_verification'])) |
|
1304 | - $post_errors = array_merge($post_errors, $context['require_verification']); |
|
1366 | + if (is_array($context['require_verification'])) { |
|
1367 | + $post_errors = array_merge($post_errors, $context['require_verification']); |
|
1368 | + } |
|
1305 | 1369 | } |
1306 | 1370 | |
1307 | 1371 | require_once($sourcedir . '/Subs-Post.php'); |
1308 | 1372 | loadLanguage('Post'); |
1309 | 1373 | |
1310 | 1374 | // Drafts enabled and needed? |
1311 | - if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft']))) |
|
1312 | - require_once($sourcedir . '/Drafts.php'); |
|
1375 | + if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft']))) { |
|
1376 | + require_once($sourcedir . '/Drafts.php'); |
|
1377 | + } |
|
1313 | 1378 | |
1314 | 1379 | // First check to see if they are trying to delete any current attachments. |
1315 | 1380 | if (isset($_POST['attach_del'])) |
1316 | 1381 | { |
1317 | 1382 | $keep_temp = array(); |
1318 | 1383 | $keep_ids = array(); |
1319 | - foreach ($_POST['attach_del'] as $dummy) |
|
1320 | - if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false) |
|
1384 | + foreach ($_POST['attach_del'] as $dummy) { |
|
1385 | + if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false) |
|
1321 | 1386 | $keep_temp[] = $dummy; |
1322 | - else |
|
1323 | - $keep_ids[] = (int) $dummy; |
|
1387 | + } |
|
1388 | + else { |
|
1389 | + $keep_ids[] = (int) $dummy; |
|
1390 | + } |
|
1324 | 1391 | |
1325 | - if (isset($_SESSION['temp_attachments'])) |
|
1326 | - foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
|
1392 | + if (isset($_SESSION['temp_attachments'])) { |
|
1393 | + foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
|
1327 | 1394 | { |
1328 | 1395 | if ((isset($_SESSION['temp_attachments']['post']['files'], $attachment['name']) && in_array($attachment['name'], $_SESSION['temp_attachments']['post']['files'])) || in_array($attachID, $keep_temp) || strpos($attachID, 'post_tmp_' . $user_info['id']) === false) |
1329 | 1396 | continue; |
1397 | + } |
|
1330 | 1398 | |
1331 | 1399 | unset($_SESSION['temp_attachments'][$attachID]); |
1332 | 1400 | unlink($attachment['tmp_name']); |
@@ -1368,24 +1436,28 @@ discard block |
||
1368 | 1436 | $smcFunc['db_free_result']($request); |
1369 | 1437 | |
1370 | 1438 | // Though the topic should be there, it might have vanished. |
1371 | - if (!is_array($topic_info)) |
|
1372 | - fatal_lang_error('topic_doesnt_exist', 404); |
|
1439 | + if (!is_array($topic_info)) { |
|
1440 | + fatal_lang_error('topic_doesnt_exist', 404); |
|
1441 | + } |
|
1373 | 1442 | |
1374 | 1443 | // Did this topic suddenly move? Just checking... |
1375 | - if ($topic_info['id_board'] != $board) |
|
1376 | - fatal_lang_error('not_a_topic'); |
|
1444 | + if ($topic_info['id_board'] != $board) { |
|
1445 | + fatal_lang_error('not_a_topic'); |
|
1446 | + } |
|
1377 | 1447 | } |
1378 | 1448 | |
1379 | 1449 | // Replying to a topic? |
1380 | 1450 | if (!empty($topic) && !isset($_REQUEST['msg'])) |
1381 | 1451 | { |
1382 | 1452 | // Don't allow a post if it's locked. |
1383 | - if ($topic_info['locked'] != 0 && !allowedTo('moderate_board')) |
|
1384 | - fatal_lang_error('topic_locked', false); |
|
1453 | + if ($topic_info['locked'] != 0 && !allowedTo('moderate_board')) { |
|
1454 | + fatal_lang_error('topic_locked', false); |
|
1455 | + } |
|
1385 | 1456 | |
1386 | 1457 | // Sorry, multiple polls aren't allowed... yet. You should stop giving me ideas :P. |
1387 | - if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0) |
|
1388 | - unset($_REQUEST['poll']); |
|
1458 | + if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0) { |
|
1459 | + unset($_REQUEST['poll']); |
|
1460 | + } |
|
1389 | 1461 | |
1390 | 1462 | // Do the permissions and approval stuff... |
1391 | 1463 | $becomesApproved = true; |
@@ -1401,44 +1473,43 @@ discard block |
||
1401 | 1473 | |
1402 | 1474 | // Set a nice session var... |
1403 | 1475 | $_SESSION['becomesUnapproved'] = true; |
1404 | - } |
|
1405 | - |
|
1406 | - elseif ($topic_info['id_member_started'] != $user_info['id']) |
|
1476 | + } elseif ($topic_info['id_member_started'] != $user_info['id']) |
|
1407 | 1477 | { |
1408 | - if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) |
|
1409 | - $becomesApproved = false; |
|
1410 | - |
|
1411 | - else |
|
1412 | - isAllowedTo('post_reply_any'); |
|
1413 | - } |
|
1414 | - elseif (!allowedTo('post_reply_any')) |
|
1478 | + if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) { |
|
1479 | + $becomesApproved = false; |
|
1480 | + } else { |
|
1481 | + isAllowedTo('post_reply_any'); |
|
1482 | + } |
|
1483 | + } elseif (!allowedTo('post_reply_any')) |
|
1415 | 1484 | { |
1416 | - if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) |
|
1417 | - $becomesApproved = false; |
|
1418 | - |
|
1419 | - else |
|
1420 | - isAllowedTo('post_reply_own'); |
|
1485 | + if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) { |
|
1486 | + $becomesApproved = false; |
|
1487 | + } else { |
|
1488 | + isAllowedTo('post_reply_own'); |
|
1489 | + } |
|
1421 | 1490 | } |
1422 | 1491 | |
1423 | 1492 | if (isset($_POST['lock'])) |
1424 | 1493 | { |
1425 | 1494 | // Nothing is changed to the lock. |
1426 | - if ((empty($topic_info['locked']) && empty($_POST['lock'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) |
|
1427 | - unset($_POST['lock']); |
|
1495 | + if ((empty($topic_info['locked']) && empty($_POST['lock'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) { |
|
1496 | + unset($_POST['lock']); |
|
1497 | + } |
|
1428 | 1498 | |
1429 | 1499 | // You're have no permission to lock this topic. |
1430 | - elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) |
|
1431 | - unset($_POST['lock']); |
|
1500 | + elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) { |
|
1501 | + unset($_POST['lock']); |
|
1502 | + } |
|
1432 | 1503 | |
1433 | 1504 | // You are allowed to (un)lock your own topic only. |
1434 | 1505 | elseif (!allowedTo('lock_any')) |
1435 | 1506 | { |
1436 | 1507 | // You cannot override a moderator lock. |
1437 | - if ($topic_info['locked'] == 1) |
|
1438 | - unset($_POST['lock']); |
|
1439 | - |
|
1440 | - else |
|
1441 | - $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
1508 | + if ($topic_info['locked'] == 1) { |
|
1509 | + unset($_POST['lock']); |
|
1510 | + } else { |
|
1511 | + $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
1512 | + } |
|
1442 | 1513 | } |
1443 | 1514 | // Hail mighty moderator, (un)lock this topic immediately. |
1444 | 1515 | else |
@@ -1446,19 +1517,21 @@ discard block |
||
1446 | 1517 | $_POST['lock'] = empty($_POST['lock']) ? 0 : 1; |
1447 | 1518 | |
1448 | 1519 | // Did someone (un)lock this while you were posting? |
1449 | - if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) |
|
1450 | - $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked'; |
|
1520 | + if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) { |
|
1521 | + $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked'; |
|
1522 | + } |
|
1451 | 1523 | } |
1452 | 1524 | } |
1453 | 1525 | |
1454 | 1526 | // So you wanna (un)sticky this...let's see. |
1455 | - if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky'))) |
|
1456 | - unset($_POST['sticky']); |
|
1457 | - elseif (isset($_POST['sticky'])) |
|
1527 | + if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky'))) { |
|
1528 | + unset($_POST['sticky']); |
|
1529 | + } elseif (isset($_POST['sticky'])) |
|
1458 | 1530 | { |
1459 | 1531 | // Did someone (un)sticky this while you were posting? |
1460 | - if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) |
|
1461 | - $post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky'; |
|
1532 | + if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) { |
|
1533 | + $post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky'; |
|
1534 | + } |
|
1462 | 1535 | } |
1463 | 1536 | |
1464 | 1537 | // If drafts are enabled, then pass this off |
@@ -1485,26 +1558,31 @@ discard block |
||
1485 | 1558 | |
1486 | 1559 | // Do like, the permissions, for safety and stuff... |
1487 | 1560 | $becomesApproved = true; |
1488 | - if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) |
|
1489 | - $becomesApproved = false; |
|
1490 | - else |
|
1491 | - isAllowedTo('post_new'); |
|
1561 | + if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) { |
|
1562 | + $becomesApproved = false; |
|
1563 | + } else { |
|
1564 | + isAllowedTo('post_new'); |
|
1565 | + } |
|
1492 | 1566 | |
1493 | 1567 | if (isset($_POST['lock'])) |
1494 | 1568 | { |
1495 | 1569 | // New topics are by default not locked. |
1496 | - if (empty($_POST['lock'])) |
|
1497 | - unset($_POST['lock']); |
|
1570 | + if (empty($_POST['lock'])) { |
|
1571 | + unset($_POST['lock']); |
|
1572 | + } |
|
1498 | 1573 | // Besides, you need permission. |
1499 | - elseif (!allowedTo(array('lock_any', 'lock_own'))) |
|
1500 | - unset($_POST['lock']); |
|
1574 | + elseif (!allowedTo(array('lock_any', 'lock_own'))) { |
|
1575 | + unset($_POST['lock']); |
|
1576 | + } |
|
1501 | 1577 | // A moderator-lock (1) can override a user-lock (2). |
1502 | - else |
|
1503 | - $_POST['lock'] = allowedTo('lock_any') ? 1 : 2; |
|
1578 | + else { |
|
1579 | + $_POST['lock'] = allowedTo('lock_any') ? 1 : 2; |
|
1580 | + } |
|
1504 | 1581 | } |
1505 | 1582 | |
1506 | - if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky'))) |
|
1507 | - unset($_POST['sticky']); |
|
1583 | + if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky'))) { |
|
1584 | + unset($_POST['sticky']); |
|
1585 | + } |
|
1508 | 1586 | |
1509 | 1587 | // Saving your new topic as a draft first? |
1510 | 1588 | if (!empty($modSettings['drafts_post_enabled']) && isset($_POST['save_draft'])) |
@@ -1529,31 +1607,37 @@ discard block |
||
1529 | 1607 | 'id_msg' => $_REQUEST['msg'], |
1530 | 1608 | ) |
1531 | 1609 | ); |
1532 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
1533 | - fatal_lang_error('cant_find_messages', false); |
|
1610 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
1611 | + fatal_lang_error('cant_find_messages', false); |
|
1612 | + } |
|
1534 | 1613 | $row = $smcFunc['db_fetch_assoc']($request); |
1535 | 1614 | $smcFunc['db_free_result']($request); |
1536 | 1615 | |
1537 | - if (!empty($topic_info['locked']) && !allowedTo('moderate_board')) |
|
1538 | - fatal_lang_error('topic_locked', false); |
|
1616 | + if (!empty($topic_info['locked']) && !allowedTo('moderate_board')) { |
|
1617 | + fatal_lang_error('topic_locked', false); |
|
1618 | + } |
|
1539 | 1619 | |
1540 | 1620 | if (isset($_POST['lock'])) |
1541 | 1621 | { |
1542 | 1622 | // Nothing changes to the lock status. |
1543 | - if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) |
|
1544 | - unset($_POST['lock']); |
|
1623 | + if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) { |
|
1624 | + unset($_POST['lock']); |
|
1625 | + } |
|
1545 | 1626 | // You're simply not allowed to (un)lock this. |
1546 | - elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) |
|
1547 | - unset($_POST['lock']); |
|
1627 | + elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) { |
|
1628 | + unset($_POST['lock']); |
|
1629 | + } |
|
1548 | 1630 | // You're only allowed to lock your own topics. |
1549 | 1631 | elseif (!allowedTo('lock_any')) |
1550 | 1632 | { |
1551 | 1633 | // You're not allowed to break a moderator's lock. |
1552 | - if ($topic_info['locked'] == 1) |
|
1553 | - unset($_POST['lock']); |
|
1634 | + if ($topic_info['locked'] == 1) { |
|
1635 | + unset($_POST['lock']); |
|
1636 | + } |
|
1554 | 1637 | // Lock it with a soft lock or unlock it. |
1555 | - else |
|
1556 | - $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
1638 | + else { |
|
1639 | + $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
1640 | + } |
|
1557 | 1641 | } |
1558 | 1642 | // You must be the moderator. |
1559 | 1643 | else |
@@ -1561,44 +1645,46 @@ discard block |
||
1561 | 1645 | $_POST['lock'] = empty($_POST['lock']) ? 0 : 1; |
1562 | 1646 | |
1563 | 1647 | // Did someone (un)lock this while you were posting? |
1564 | - if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) |
|
1565 | - $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked'; |
|
1648 | + if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) { |
|
1649 | + $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked'; |
|
1650 | + } |
|
1566 | 1651 | } |
1567 | 1652 | } |
1568 | 1653 | |
1569 | 1654 | // Change the sticky status of this topic? |
1570 | - if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky'])) |
|
1571 | - unset($_POST['sticky']); |
|
1572 | - elseif (isset($_POST['sticky'])) |
|
1655 | + if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky'])) { |
|
1656 | + unset($_POST['sticky']); |
|
1657 | + } elseif (isset($_POST['sticky'])) |
|
1573 | 1658 | { |
1574 | 1659 | // Did someone (un)sticky this while you were posting? |
1575 | - if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) |
|
1576 | - $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied'; |
|
1660 | + if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) { |
|
1661 | + $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied'; |
|
1662 | + } |
|
1577 | 1663 | } |
1578 | 1664 | |
1579 | 1665 | if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any')) |
1580 | 1666 | { |
1581 | - if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) |
|
1582 | - fatal_lang_error('modify_post_time_passed', false); |
|
1583 | - elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) |
|
1584 | - isAllowedTo('modify_replies'); |
|
1585 | - else |
|
1586 | - isAllowedTo('modify_own'); |
|
1587 | - } |
|
1588 | - elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) |
|
1667 | + if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) { |
|
1668 | + fatal_lang_error('modify_post_time_passed', false); |
|
1669 | + } elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) { |
|
1670 | + isAllowedTo('modify_replies'); |
|
1671 | + } else { |
|
1672 | + isAllowedTo('modify_own'); |
|
1673 | + } |
|
1674 | + } elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) |
|
1589 | 1675 | { |
1590 | 1676 | isAllowedTo('modify_replies'); |
1591 | 1677 | |
1592 | 1678 | // If you're modifying a reply, I say it better be logged... |
1593 | 1679 | $moderationAction = true; |
1594 | - } |
|
1595 | - else |
|
1680 | + } else |
|
1596 | 1681 | { |
1597 | 1682 | isAllowedTo('modify_any'); |
1598 | 1683 | |
1599 | 1684 | // Log it, assuming you're not modifying your own post. |
1600 | - if ($row['id_member'] != $user_info['id']) |
|
1601 | - $moderationAction = true; |
|
1685 | + if ($row['id_member'] != $user_info['id']) { |
|
1686 | + $moderationAction = true; |
|
1687 | + } |
|
1602 | 1688 | } |
1603 | 1689 | |
1604 | 1690 | // If drafts are enabled, then lets send this off to save |
@@ -1635,20 +1721,24 @@ discard block |
||
1635 | 1721 | $_POST['guestname'] = !isset($_POST['guestname']) ? '' : trim($_POST['guestname']); |
1636 | 1722 | $_POST['email'] = !isset($_POST['email']) ? '' : trim($_POST['email']); |
1637 | 1723 | |
1638 | - if ($_POST['guestname'] == '' || $_POST['guestname'] == '_') |
|
1639 | - $post_errors[] = 'no_name'; |
|
1640 | - if ($smcFunc['strlen']($_POST['guestname']) > 25) |
|
1641 | - $post_errors[] = 'long_name'; |
|
1724 | + if ($_POST['guestname'] == '' || $_POST['guestname'] == '_') { |
|
1725 | + $post_errors[] = 'no_name'; |
|
1726 | + } |
|
1727 | + if ($smcFunc['strlen']($_POST['guestname']) > 25) { |
|
1728 | + $post_errors[] = 'long_name'; |
|
1729 | + } |
|
1642 | 1730 | |
1643 | 1731 | if (empty($modSettings['guest_post_no_email'])) |
1644 | 1732 | { |
1645 | 1733 | // Only check if they changed it! |
1646 | 1734 | if (!isset($row) || $row['poster_email'] != $_POST['email']) |
1647 | 1735 | { |
1648 | - if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == '')) |
|
1649 | - $post_errors[] = 'no_email'; |
|
1650 | - if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) |
|
1651 | - $post_errors[] = 'bad_email'; |
|
1736 | + if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == '')) { |
|
1737 | + $post_errors[] = 'no_email'; |
|
1738 | + } |
|
1739 | + if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) { |
|
1740 | + $post_errors[] = 'bad_email'; |
|
1741 | + } |
|
1652 | 1742 | } |
1653 | 1743 | |
1654 | 1744 | // Now make sure this email address is not banned from posting. |
@@ -1664,75 +1754,89 @@ discard block |
||
1664 | 1754 | } |
1665 | 1755 | |
1666 | 1756 | // Coming from the quickReply? |
1667 | - if(isset($_POST['quickReply'])) |
|
1668 | - $_POST['message'] = $_POST['quickReply']; |
|
1757 | + if(isset($_POST['quickReply'])) { |
|
1758 | + $_POST['message'] = $_POST['quickReply']; |
|
1759 | + } |
|
1669 | 1760 | |
1670 | 1761 | // Check the subject and message. |
1671 | - if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '') |
|
1672 | - $post_errors[] = 'no_subject'; |
|
1673 | - if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '') |
|
1674 | - $post_errors[] = 'no_message'; |
|
1675 | - elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) |
|
1676 | - $post_errors[] = array('long_message', array($modSettings['max_messageLength'])); |
|
1677 | - else |
|
1762 | + if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '') { |
|
1763 | + $post_errors[] = 'no_subject'; |
|
1764 | + } |
|
1765 | + if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '') { |
|
1766 | + $post_errors[] = 'no_message'; |
|
1767 | + } elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) { |
|
1768 | + $post_errors[] = array('long_message', array($modSettings['max_messageLength'])); |
|
1769 | + } else |
|
1678 | 1770 | { |
1679 | 1771 | // Prepare the message a bit for some additional testing. |
1680 | 1772 | $_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES); |
1681 | 1773 | |
1682 | 1774 | // Preparse code. (Zef) |
1683 | - if ($user_info['is_guest']) |
|
1684 | - $user_info['name'] = $_POST['guestname']; |
|
1775 | + if ($user_info['is_guest']) { |
|
1776 | + $user_info['name'] = $_POST['guestname']; |
|
1777 | + } |
|
1685 | 1778 | preparsecode($_POST['message']); |
1686 | 1779 | |
1687 | 1780 | // Let's see if there's still some content left without the tags. |
1688 | - if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false)) |
|
1689 | - $post_errors[] = 'no_message'; |
|
1781 | + if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false)) { |
|
1782 | + $post_errors[] = 'no_message'; |
|
1783 | + } |
|
1784 | + } |
|
1785 | + if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '') { |
|
1786 | + $post_errors[] = 'no_event'; |
|
1690 | 1787 | } |
1691 | - if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '') |
|
1692 | - $post_errors[] = 'no_event'; |
|
1693 | 1788 | // You are not! |
1694 | - if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin']) |
|
1695 | - fatal_error('Knave! Masquerader! Charlatan!', false); |
|
1789 | + if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin']) { |
|
1790 | + fatal_error('Knave! Masquerader! Charlatan!', false); |
|
1791 | + } |
|
1696 | 1792 | |
1697 | 1793 | // Validate the poll... |
1698 | 1794 | if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1') |
1699 | 1795 | { |
1700 | - if (!empty($topic) && !isset($_REQUEST['msg'])) |
|
1701 | - fatal_lang_error('no_access', false); |
|
1796 | + if (!empty($topic) && !isset($_REQUEST['msg'])) { |
|
1797 | + fatal_lang_error('no_access', false); |
|
1798 | + } |
|
1702 | 1799 | |
1703 | 1800 | // This is a new topic... so it's a new poll. |
1704 | - if (empty($topic)) |
|
1705 | - isAllowedTo('poll_post'); |
|
1801 | + if (empty($topic)) { |
|
1802 | + isAllowedTo('poll_post'); |
|
1803 | + } |
|
1706 | 1804 | // Can you add to your own topics? |
1707 | - elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any')) |
|
1708 | - isAllowedTo('poll_add_own'); |
|
1805 | + elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any')) { |
|
1806 | + isAllowedTo('poll_add_own'); |
|
1807 | + } |
|
1709 | 1808 | // Can you add polls to any topic, then? |
1710 | - else |
|
1711 | - isAllowedTo('poll_add_any'); |
|
1809 | + else { |
|
1810 | + isAllowedTo('poll_add_any'); |
|
1811 | + } |
|
1712 | 1812 | |
1713 | - if (!isset($_POST['question']) || trim($_POST['question']) == '') |
|
1714 | - $post_errors[] = 'no_question'; |
|
1813 | + if (!isset($_POST['question']) || trim($_POST['question']) == '') { |
|
1814 | + $post_errors[] = 'no_question'; |
|
1815 | + } |
|
1715 | 1816 | |
1716 | 1817 | $_POST['options'] = empty($_POST['options']) ? array() : htmltrim__recursive($_POST['options']); |
1717 | 1818 | |
1718 | 1819 | // Get rid of empty ones. |
1719 | - foreach ($_POST['options'] as $k => $option) |
|
1720 | - if ($option == '') |
|
1820 | + foreach ($_POST['options'] as $k => $option) { |
|
1821 | + if ($option == '') |
|
1721 | 1822 | unset($_POST['options'][$k], $_POST['options'][$k]); |
1823 | + } |
|
1722 | 1824 | |
1723 | 1825 | // What are you going to vote between with one choice?!? |
1724 | - if (count($_POST['options']) < 2) |
|
1725 | - $post_errors[] = 'poll_few'; |
|
1726 | - elseif (count($_POST['options']) > 256) |
|
1727 | - $post_errors[] = 'poll_many'; |
|
1826 | + if (count($_POST['options']) < 2) { |
|
1827 | + $post_errors[] = 'poll_few'; |
|
1828 | + } elseif (count($_POST['options']) > 256) { |
|
1829 | + $post_errors[] = 'poll_many'; |
|
1830 | + } |
|
1728 | 1831 | } |
1729 | 1832 | |
1730 | 1833 | if ($posterIsGuest) |
1731 | 1834 | { |
1732 | 1835 | // If user is a guest, make sure the chosen name isn't taken. |
1733 | 1836 | require_once($sourcedir . '/Subs-Members.php'); |
1734 | - if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name'])) |
|
1735 | - $post_errors[] = 'bad_name'; |
|
1837 | + if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name'])) { |
|
1838 | + $post_errors[] = 'bad_name'; |
|
1839 | + } |
|
1736 | 1840 | } |
1737 | 1841 | // If the user isn't a guest, get his or her name and email. |
1738 | 1842 | elseif (!isset($_REQUEST['msg'])) |
@@ -1763,8 +1867,9 @@ discard block |
||
1763 | 1867 | } |
1764 | 1868 | |
1765 | 1869 | // Make sure the user isn't spamming the board. |
1766 | - if (!isset($_REQUEST['msg'])) |
|
1767 | - spamProtection('post'); |
|
1870 | + if (!isset($_REQUEST['msg'])) { |
|
1871 | + spamProtection('post'); |
|
1872 | + } |
|
1768 | 1873 | |
1769 | 1874 | // At about this point, we're posting and that's that. |
1770 | 1875 | ignore_user_abort(true); |
@@ -1777,32 +1882,36 @@ discard block |
||
1777 | 1882 | $_POST['modify_reason'] = empty($_POST['modify_reason']) ? '' : strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => '')); |
1778 | 1883 | |
1779 | 1884 | // At this point, we want to make sure the subject isn't too long. |
1780 | - if ($smcFunc['strlen']($_POST['subject']) > 100) |
|
1781 | - $_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100); |
|
1885 | + if ($smcFunc['strlen']($_POST['subject']) > 100) { |
|
1886 | + $_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100); |
|
1887 | + } |
|
1782 | 1888 | |
1783 | 1889 | // Same with the "why did you edit this" text. |
1784 | - if ($smcFunc['strlen']($_POST['modify_reason']) > 100) |
|
1785 | - $_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100); |
|
1890 | + if ($smcFunc['strlen']($_POST['modify_reason']) > 100) { |
|
1891 | + $_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100); |
|
1892 | + } |
|
1786 | 1893 | |
1787 | 1894 | // Make the poll... |
1788 | 1895 | if (isset($_REQUEST['poll'])) |
1789 | 1896 | { |
1790 | 1897 | // Make sure that the user has not entered a ridiculous number of options.. |
1791 | - if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) |
|
1792 | - $_POST['poll_max_votes'] = 1; |
|
1793 | - elseif ($_POST['poll_max_votes'] > count($_POST['options'])) |
|
1794 | - $_POST['poll_max_votes'] = count($_POST['options']); |
|
1795 | - else |
|
1796 | - $_POST['poll_max_votes'] = (int) $_POST['poll_max_votes']; |
|
1898 | + if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) { |
|
1899 | + $_POST['poll_max_votes'] = 1; |
|
1900 | + } elseif ($_POST['poll_max_votes'] > count($_POST['options'])) { |
|
1901 | + $_POST['poll_max_votes'] = count($_POST['options']); |
|
1902 | + } else { |
|
1903 | + $_POST['poll_max_votes'] = (int) $_POST['poll_max_votes']; |
|
1904 | + } |
|
1797 | 1905 | |
1798 | 1906 | $_POST['poll_expire'] = (int) $_POST['poll_expire']; |
1799 | 1907 | $_POST['poll_expire'] = $_POST['poll_expire'] > 9999 ? 9999 : ($_POST['poll_expire'] < 0 ? 0 : $_POST['poll_expire']); |
1800 | 1908 | |
1801 | 1909 | // Just set it to zero if it's not there.. |
1802 | - if (!isset($_POST['poll_hide'])) |
|
1803 | - $_POST['poll_hide'] = 0; |
|
1804 | - else |
|
1805 | - $_POST['poll_hide'] = (int) $_POST['poll_hide']; |
|
1910 | + if (!isset($_POST['poll_hide'])) { |
|
1911 | + $_POST['poll_hide'] = 0; |
|
1912 | + } else { |
|
1913 | + $_POST['poll_hide'] = (int) $_POST['poll_hide']; |
|
1914 | + } |
|
1806 | 1915 | $_POST['poll_change_vote'] = isset($_POST['poll_change_vote']) ? 1 : 0; |
1807 | 1916 | |
1808 | 1917 | $_POST['poll_guest_vote'] = isset($_POST['poll_guest_vote']) ? 1 : 0; |
@@ -1811,16 +1920,19 @@ discard block |
||
1811 | 1920 | { |
1812 | 1921 | require_once($sourcedir . '/Subs-Members.php'); |
1813 | 1922 | $allowedVoteGroups = groupsAllowedTo('poll_vote', $board); |
1814 | - if (!in_array(-1, $allowedVoteGroups['allowed'])) |
|
1815 | - $_POST['poll_guest_vote'] = 0; |
|
1923 | + if (!in_array(-1, $allowedVoteGroups['allowed'])) { |
|
1924 | + $_POST['poll_guest_vote'] = 0; |
|
1925 | + } |
|
1816 | 1926 | } |
1817 | 1927 | |
1818 | 1928 | // If the user tries to set the poll too far in advance, don't let them. |
1819 | - if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1) |
|
1820 | - fatal_lang_error('poll_range_error', false); |
|
1929 | + if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1) { |
|
1930 | + fatal_lang_error('poll_range_error', false); |
|
1931 | + } |
|
1821 | 1932 | // Don't allow them to select option 2 for hidden results if it's not time limited. |
1822 | - elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) |
|
1823 | - $_POST['poll_hide'] = 1; |
|
1933 | + elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) { |
|
1934 | + $_POST['poll_hide'] = 1; |
|
1935 | + } |
|
1824 | 1936 | |
1825 | 1937 | // Clean up the question and answers. |
1826 | 1938 | $_POST['question'] = $smcFunc['htmlspecialchars']($_POST['question']); |
@@ -1834,13 +1946,15 @@ discard block |
||
1834 | 1946 | { |
1835 | 1947 | $attachIDs = array(); |
1836 | 1948 | $attach_errors = array(); |
1837 | - if (!empty($context['we_are_history'])) |
|
1838 | - $attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>'; |
|
1949 | + if (!empty($context['we_are_history'])) { |
|
1950 | + $attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>'; |
|
1951 | + } |
|
1839 | 1952 | |
1840 | 1953 | foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
1841 | 1954 | { |
1842 | - if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) |
|
1843 | - continue; |
|
1955 | + if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) { |
|
1956 | + continue; |
|
1957 | + } |
|
1844 | 1958 | |
1845 | 1959 | // If there was an initial error just show that message. |
1846 | 1960 | if ($attachID == 'initial_error') |
@@ -1869,12 +1983,13 @@ discard block |
||
1869 | 1983 | if (createAttachment($attachmentOptions)) |
1870 | 1984 | { |
1871 | 1985 | $attachIDs[] = $attachmentOptions['id']; |
1872 | - if (!empty($attachmentOptions['thumb'])) |
|
1873 | - $attachIDs[] = $attachmentOptions['thumb']; |
|
1986 | + if (!empty($attachmentOptions['thumb'])) { |
|
1987 | + $attachIDs[] = $attachmentOptions['thumb']; |
|
1988 | + } |
|
1874 | 1989 | } |
1990 | + } else { |
|
1991 | + $attach_errors[] = '<dt> </dt>'; |
|
1875 | 1992 | } |
1876 | - else |
|
1877 | - $attach_errors[] = '<dt> </dt>'; |
|
1878 | 1993 | |
1879 | 1994 | if (!empty($attachmentOptions['errors'])) |
1880 | 1995 | { |
@@ -1886,14 +2001,16 @@ discard block |
||
1886 | 2001 | if (!is_array($error)) |
1887 | 2002 | { |
1888 | 2003 | $attach_errors[] = '<dd>' . $txt[$error] . '</dd>'; |
1889 | - if (in_array($error, $log_these)) |
|
1890 | - log_error($attachment['name'] . ': ' . $txt[$error], 'critical'); |
|
2004 | + if (in_array($error, $log_these)) { |
|
2005 | + log_error($attachment['name'] . ': ' . $txt[$error], 'critical'); |
|
2006 | + } |
|
2007 | + } else { |
|
2008 | + $attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>'; |
|
1891 | 2009 | } |
1892 | - else |
|
1893 | - $attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>'; |
|
1894 | 2010 | } |
1895 | - if (file_exists($attachment['tmp_name'])) |
|
1896 | - unlink($attachment['tmp_name']); |
|
2011 | + if (file_exists($attachment['tmp_name'])) { |
|
2012 | + unlink($attachment['tmp_name']); |
|
2013 | + } |
|
1897 | 2014 | } |
1898 | 2015 | } |
1899 | 2016 | unset($_SESSION['temp_attachments']); |
@@ -1934,24 +2051,24 @@ discard block |
||
1934 | 2051 | ); |
1935 | 2052 | |
1936 | 2053 | call_integration_hook('integrate_poll_add_edit', array($id_poll, false)); |
2054 | + } else { |
|
2055 | + $id_poll = 0; |
|
1937 | 2056 | } |
1938 | - else |
|
1939 | - $id_poll = 0; |
|
1940 | 2057 | |
1941 | 2058 | // Creating a new topic? |
1942 | 2059 | $newTopic = empty($_REQUEST['msg']) && empty($topic); |
1943 | 2060 | |
1944 | 2061 | // Check the icon. |
1945 | - if (!isset($_POST['icon'])) |
|
1946 | - $_POST['icon'] = 'xx'; |
|
1947 | - |
|
1948 | - else |
|
2062 | + if (!isset($_POST['icon'])) { |
|
2063 | + $_POST['icon'] = 'xx'; |
|
2064 | + } else |
|
1949 | 2065 | { |
1950 | 2066 | $_POST['icon'] = $smcFunc['htmlspecialchars']($_POST['icon']); |
1951 | 2067 | |
1952 | 2068 | // Need to figure it out if this is a valid icon name. |
1953 | - if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png'))) |
|
1954 | - $_POST['icon'] = 'xx'; |
|
2069 | + if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png'))) { |
|
2070 | + $_POST['icon'] = 'xx'; |
|
2071 | + } |
|
1955 | 2072 | } |
1956 | 2073 | |
1957 | 2074 | // Collect all parameters for the creation or modification of a post. |
@@ -1992,8 +2109,9 @@ discard block |
||
1992 | 2109 | } |
1993 | 2110 | |
1994 | 2111 | // This will save some time... |
1995 | - if (empty($approve_has_changed)) |
|
1996 | - unset($msgOptions['approved']); |
|
2112 | + if (empty($approve_has_changed)) { |
|
2113 | + unset($msgOptions['approved']); |
|
2114 | + } |
|
1997 | 2115 | |
1998 | 2116 | modifyPost($msgOptions, $topicOptions, $posterOptions); |
1999 | 2117 | } |
@@ -2002,8 +2120,9 @@ discard block |
||
2002 | 2120 | { |
2003 | 2121 | createPost($msgOptions, $topicOptions, $posterOptions); |
2004 | 2122 | |
2005 | - if (isset($topicOptions['id'])) |
|
2006 | - $topic = $topicOptions['id']; |
|
2123 | + if (isset($topicOptions['id'])) { |
|
2124 | + $topic = $topicOptions['id']; |
|
2125 | + } |
|
2007 | 2126 | } |
2008 | 2127 | |
2009 | 2128 | // Assign the previously uploaded attachments to the brand new message. |
@@ -2015,8 +2134,9 @@ discard block |
||
2015 | 2134 | } |
2016 | 2135 | |
2017 | 2136 | // If we had a draft for this, its time to remove it since it was just posted |
2018 | - if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft'])) |
|
2019 | - DeleteDraft($_POST['id_draft']); |
|
2137 | + if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft'])) { |
|
2138 | + DeleteDraft($_POST['id_draft']); |
|
2139 | + } |
|
2020 | 2140 | |
2021 | 2141 | // Editing or posting an event? |
2022 | 2142 | if (isset($_POST['calendar']) && (!isset($_REQUEST['eventid']) || $_REQUEST['eventid'] == -1)) |
@@ -2036,8 +2156,7 @@ discard block |
||
2036 | 2156 | 'span' => isset($_POST['span']) && $_POST['span'] > 0 ? min((int) $modSettings['cal_maxspan'], (int) $_POST['span'] - 1) : 0, |
2037 | 2157 | ); |
2038 | 2158 | insertEvent($eventOptions); |
2039 | - } |
|
2040 | - elseif (isset($_POST['calendar'])) |
|
2159 | + } elseif (isset($_POST['calendar'])) |
|
2041 | 2160 | { |
2042 | 2161 | $_REQUEST['eventid'] = (int) $_REQUEST['eventid']; |
2043 | 2162 | |
@@ -2065,14 +2184,15 @@ discard block |
||
2065 | 2184 | } |
2066 | 2185 | |
2067 | 2186 | // Delete it? |
2068 | - if (isset($_REQUEST['deleteevent'])) |
|
2069 | - $smcFunc['db_query']('', ' |
|
2187 | + if (isset($_REQUEST['deleteevent'])) { |
|
2188 | + $smcFunc['db_query']('', ' |
|
2070 | 2189 | DELETE FROM {db_prefix}calendar |
2071 | 2190 | WHERE id_event = {int:id_event}', |
2072 | 2191 | array( |
2073 | 2192 | 'id_event' => $_REQUEST['eventid'], |
2074 | 2193 | ) |
2075 | 2194 | ); |
2195 | + } |
|
2076 | 2196 | // ... or just update it? |
2077 | 2197 | else |
2078 | 2198 | { |
@@ -2116,9 +2236,8 @@ discard block |
||
2116 | 2236 | array($user_info['id'], $topic, 0), |
2117 | 2237 | array('id_member', 'id_topic', 'id_board') |
2118 | 2238 | ); |
2119 | - } |
|
2120 | - elseif (!$newTopic) |
|
2121 | - $smcFunc['db_query']('', ' |
|
2239 | + } elseif (!$newTopic) { |
|
2240 | + $smcFunc['db_query']('', ' |
|
2122 | 2241 | DELETE FROM {db_prefix}log_notify |
2123 | 2242 | WHERE id_member = {int:current_member} |
2124 | 2243 | AND id_topic = {int:current_topic}', |
@@ -2127,16 +2246,20 @@ discard block |
||
2127 | 2246 | 'current_topic' => $topic, |
2128 | 2247 | ) |
2129 | 2248 | ); |
2249 | + } |
|
2130 | 2250 | |
2131 | 2251 | // Log an act of moderation - modifying. |
2132 | - if (!empty($moderationAction)) |
|
2133 | - logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board)); |
|
2252 | + if (!empty($moderationAction)) { |
|
2253 | + logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board)); |
|
2254 | + } |
|
2134 | 2255 | |
2135 | - if (isset($_POST['lock']) && $_POST['lock'] != 2) |
|
2136 | - logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board'])); |
|
2256 | + if (isset($_POST['lock']) && $_POST['lock'] != 2) { |
|
2257 | + logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board'])); |
|
2258 | + } |
|
2137 | 2259 | |
2138 | - if (isset($_POST['sticky'])) |
|
2139 | - logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board'])); |
|
2260 | + if (isset($_POST['sticky'])) { |
|
2261 | + logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board'])); |
|
2262 | + } |
|
2140 | 2263 | |
2141 | 2264 | // Returning to the topic? |
2142 | 2265 | if (!empty($_REQUEST['goback'])) |
@@ -2155,26 +2278,31 @@ discard block |
||
2155 | 2278 | ); |
2156 | 2279 | } |
2157 | 2280 | |
2158 | - if ($board_info['num_topics'] == 0) |
|
2159 | - cache_put_data('board-' . $board, null, 120); |
|
2281 | + if ($board_info['num_topics'] == 0) { |
|
2282 | + cache_put_data('board-' . $board, null, 120); |
|
2283 | + } |
|
2160 | 2284 | |
2161 | 2285 | call_integration_hook('integrate_post2_end'); |
2162 | 2286 | |
2163 | - if (!empty($_POST['announce_topic'])) |
|
2164 | - redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
2287 | + if (!empty($_POST['announce_topic'])) { |
|
2288 | + redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
2289 | + } |
|
2165 | 2290 | |
2166 | - if (!empty($_POST['move']) && allowedTo('move_any')) |
|
2167 | - redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
2291 | + if (!empty($_POST['move']) && allowedTo('move_any')) { |
|
2292 | + redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
2293 | + } |
|
2168 | 2294 | |
2169 | 2295 | // Return to post if the mod is on. |
2170 | - if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback'])) |
|
2171 | - redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie')); |
|
2172 | - elseif (!empty($_REQUEST['goback'])) |
|
2173 | - redirectexit('topic=' . $topic . '.new#new', isBrowser('ie')); |
|
2296 | + if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback'])) { |
|
2297 | + redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie')); |
|
2298 | + } elseif (!empty($_REQUEST['goback'])) { |
|
2299 | + redirectexit('topic=' . $topic . '.new#new', isBrowser('ie')); |
|
2300 | + } |
|
2174 | 2301 | // Dut-dut-duh-duh-DUH-duh-dut-duh-duh! *dances to the Final Fantasy Fanfare...* |
2175 | - else |
|
2176 | - redirectexit('board=' . $board . '.0'); |
|
2177 | -} |
|
2302 | + else { |
|
2303 | + redirectexit('board=' . $board . '.0'); |
|
2304 | + } |
|
2305 | + } |
|
2178 | 2306 | |
2179 | 2307 | /** |
2180 | 2308 | * Handle the announce topic function (action=announce). |
@@ -2192,8 +2320,9 @@ discard block |
||
2192 | 2320 | |
2193 | 2321 | validateSession(); |
2194 | 2322 | |
2195 | - if (empty($topic)) |
|
2196 | - fatal_lang_error('topic_gone', false); |
|
2323 | + if (empty($topic)) { |
|
2324 | + fatal_lang_error('topic_gone', false); |
|
2325 | + } |
|
2197 | 2326 | |
2198 | 2327 | loadLanguage('Post'); |
2199 | 2328 | loadTemplate('Post'); |
@@ -2220,8 +2349,9 @@ discard block |
||
2220 | 2349 | global $txt, $context, $topic, $board, $board_info, $smcFunc; |
2221 | 2350 | |
2222 | 2351 | $groups = array_merge($board_info['groups'], array(1)); |
2223 | - foreach ($groups as $id => $group) |
|
2224 | - $groups[$id] = (int) $group; |
|
2352 | + foreach ($groups as $id => $group) { |
|
2353 | + $groups[$id] = (int) $group; |
|
2354 | + } |
|
2225 | 2355 | |
2226 | 2356 | $context['groups'] = array(); |
2227 | 2357 | if (in_array(0, $groups)) |
@@ -2264,8 +2394,9 @@ discard block |
||
2264 | 2394 | 'group_list' => $groups, |
2265 | 2395 | ) |
2266 | 2396 | ); |
2267 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2268 | - $context['groups'][$row['id_group']]['name'] = $row['group_name']; |
|
2397 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2398 | + $context['groups'][$row['id_group']]['name'] = $row['group_name']; |
|
2399 | + } |
|
2269 | 2400 | $smcFunc['db_free_result']($request); |
2270 | 2401 | |
2271 | 2402 | // Get the subject of the topic we're about to announce. |
@@ -2307,16 +2438,19 @@ discard block |
||
2307 | 2438 | $context['start'] = empty($_REQUEST['start']) ? 0 : (int) $_REQUEST['start']; |
2308 | 2439 | $groups = array_merge($board_info['groups'], array(1)); |
2309 | 2440 | |
2310 | - if (isset($_POST['membergroups'])) |
|
2311 | - $_POST['who'] = explode(',', $_POST['membergroups']); |
|
2441 | + if (isset($_POST['membergroups'])) { |
|
2442 | + $_POST['who'] = explode(',', $_POST['membergroups']); |
|
2443 | + } |
|
2312 | 2444 | |
2313 | 2445 | // Check whether at least one membergroup was selected. |
2314 | - if (empty($_POST['who'])) |
|
2315 | - fatal_lang_error('no_membergroup_selected'); |
|
2446 | + if (empty($_POST['who'])) { |
|
2447 | + fatal_lang_error('no_membergroup_selected'); |
|
2448 | + } |
|
2316 | 2449 | |
2317 | 2450 | // Make sure all membergroups are integers and can access the board of the announcement. |
2318 | - foreach ($_POST['who'] as $id => $mg) |
|
2319 | - $_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0; |
|
2451 | + foreach ($_POST['who'] as $id => $mg) { |
|
2452 | + $_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0; |
|
2453 | + } |
|
2320 | 2454 | |
2321 | 2455 | // Get the topic subject and censor it. |
2322 | 2456 | $request = $smcFunc['db_query']('', ' |
@@ -2362,12 +2496,13 @@ discard block |
||
2362 | 2496 | if ($smcFunc['db_num_rows']($request) == 0) |
2363 | 2497 | { |
2364 | 2498 | logAction('announce_topic', array('topic' => $topic), 'user'); |
2365 | - if (!empty($_REQUEST['move']) && allowedTo('move_any')) |
|
2366 | - redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
2367 | - elseif (!empty($_REQUEST['goback'])) |
|
2368 | - redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie')); |
|
2369 | - else |
|
2370 | - redirectexit('board=' . $board . '.0'); |
|
2499 | + if (!empty($_REQUEST['move']) && allowedTo('move_any')) { |
|
2500 | + redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
2501 | + } elseif (!empty($_REQUEST['goback'])) { |
|
2502 | + redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie')); |
|
2503 | + } else { |
|
2504 | + redirectexit('board=' . $board . '.0'); |
|
2505 | + } |
|
2371 | 2506 | } |
2372 | 2507 | |
2373 | 2508 | $announcements = array(); |
@@ -2386,8 +2521,9 @@ discard block |
||
2386 | 2521 | foreach ($rows as $row) |
2387 | 2522 | { |
2388 | 2523 | // Force them to have it? |
2389 | - if (empty($prefs[$row['id_member']]['announcements'])) |
|
2390 | - continue; |
|
2524 | + if (empty($prefs[$row['id_member']]['announcements'])) { |
|
2525 | + continue; |
|
2526 | + } |
|
2391 | 2527 | |
2392 | 2528 | $cur_language = empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']; |
2393 | 2529 | |
@@ -2415,8 +2551,9 @@ discard block |
||
2415 | 2551 | } |
2416 | 2552 | |
2417 | 2553 | // For each language send a different mail - low priority... |
2418 | - foreach ($announcements as $lang => $mail) |
|
2419 | - sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5); |
|
2554 | + foreach ($announcements as $lang => $mail) { |
|
2555 | + sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5); |
|
2556 | + } |
|
2420 | 2557 | |
2421 | 2558 | $context['percentage_done'] = round(100 * $context['start'] / $modSettings['latestMember'], 1); |
2422 | 2559 | |
@@ -2426,9 +2563,10 @@ discard block |
||
2426 | 2563 | $context['sub_template'] = 'announcement_send'; |
2427 | 2564 | |
2428 | 2565 | // Go back to the correct language for the user ;). |
2429 | - if (!empty($modSettings['userLanguage'])) |
|
2430 | - loadLanguage('Post'); |
|
2431 | -} |
|
2566 | + if (!empty($modSettings['userLanguage'])) { |
|
2567 | + loadLanguage('Post'); |
|
2568 | + } |
|
2569 | + } |
|
2432 | 2570 | |
2433 | 2571 | /** |
2434 | 2572 | * Get the topic for display purposes. |
@@ -2441,12 +2579,13 @@ discard block |
||
2441 | 2579 | { |
2442 | 2580 | global $topic, $modSettings, $context, $smcFunc, $counter, $options; |
2443 | 2581 | |
2444 | - if (isset($_REQUEST['xml'])) |
|
2445 | - $limit = ' |
|
2582 | + if (isset($_REQUEST['xml'])) { |
|
2583 | + $limit = ' |
|
2446 | 2584 | LIMIT ' . (empty($context['new_replies']) ? '0' : $context['new_replies']); |
2447 | - else |
|
2448 | - $limit = empty($modSettings['topicSummaryPosts']) ? '' : ' |
|
2585 | + } else { |
|
2586 | + $limit = empty($modSettings['topicSummaryPosts']) ? '' : ' |
|
2449 | 2587 | LIMIT ' . (int) $modSettings['topicSummaryPosts']; |
2588 | + } |
|
2450 | 2589 | |
2451 | 2590 | // If you're modifying, get only those posts before the current one. (otherwise get all.) |
2452 | 2591 | $request = $smcFunc['db_query']('', ' |
@@ -2484,8 +2623,9 @@ discard block |
||
2484 | 2623 | 'is_ignored' => !empty($modSettings['enable_buddylist']) && !empty($options['posts_apply_ignore_list']) && in_array($row['id_member'], $context['user']['ignoreusers']), |
2485 | 2624 | ); |
2486 | 2625 | |
2487 | - if (!empty($context['new_replies'])) |
|
2488 | - $context['new_replies']--; |
|
2626 | + if (!empty($context['new_replies'])) { |
|
2627 | + $context['new_replies']--; |
|
2628 | + } |
|
2489 | 2629 | } |
2490 | 2630 | $smcFunc['db_free_result']($request); |
2491 | 2631 | } |
@@ -2502,8 +2642,9 @@ discard block |
||
2502 | 2642 | global $sourcedir, $smcFunc; |
2503 | 2643 | |
2504 | 2644 | loadLanguage('Post'); |
2505 | - if (!isset($_REQUEST['xml'])) |
|
2506 | - loadTemplate('Post'); |
|
2645 | + if (!isset($_REQUEST['xml'])) { |
|
2646 | + loadTemplate('Post'); |
|
2647 | + } |
|
2507 | 2648 | |
2508 | 2649 | include_once($sourcedir . '/Subs-Post.php'); |
2509 | 2650 | |
@@ -2534,8 +2675,9 @@ discard block |
||
2534 | 2675 | $smcFunc['db_free_result']($request); |
2535 | 2676 | |
2536 | 2677 | $context['sub_template'] = 'quotefast'; |
2537 | - if (!empty($row)) |
|
2538 | - $can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']); |
|
2678 | + if (!empty($row)) { |
|
2679 | + $can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']); |
|
2680 | + } |
|
2539 | 2681 | |
2540 | 2682 | if (!empty($can_view_post)) |
2541 | 2683 | { |
@@ -2568,8 +2710,9 @@ discard block |
||
2568 | 2710 | } |
2569 | 2711 | |
2570 | 2712 | // Remove any nested quotes. |
2571 | - if (!empty($modSettings['removeNestedQuotes'])) |
|
2572 | - $row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']); |
|
2713 | + if (!empty($modSettings['removeNestedQuotes'])) { |
|
2714 | + $row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']); |
|
2715 | + } |
|
2573 | 2716 | |
2574 | 2717 | $lb = "\n"; |
2575 | 2718 | |
@@ -2595,14 +2738,14 @@ discard block |
||
2595 | 2738 | 'time' => '', |
2596 | 2739 | ), |
2597 | 2740 | ); |
2598 | - } |
|
2599 | - else |
|
2600 | - $context['quote'] = array( |
|
2741 | + } else { |
|
2742 | + $context['quote'] = array( |
|
2601 | 2743 | 'xml' => '', |
2602 | 2744 | 'mozilla' => '', |
2603 | 2745 | 'text' => '', |
2604 | 2746 | ); |
2605 | -} |
|
2747 | + } |
|
2748 | + } |
|
2606 | 2749 | |
2607 | 2750 | /** |
2608 | 2751 | * Used to edit the body or subject of a message inline |
@@ -2614,8 +2757,9 @@ discard block |
||
2614 | 2757 | global $user_info, $context, $smcFunc, $language, $board_info; |
2615 | 2758 | |
2616 | 2759 | // We have to have a topic! |
2617 | - if (empty($topic)) |
|
2618 | - obExit(false); |
|
2760 | + if (empty($topic)) { |
|
2761 | + obExit(false); |
|
2762 | + } |
|
2619 | 2763 | |
2620 | 2764 | checkSession('get'); |
2621 | 2765 | require_once($sourcedir . '/Subs-Post.php'); |
@@ -2641,31 +2785,35 @@ discard block |
||
2641 | 2785 | 'guest_id' => 0, |
2642 | 2786 | ) |
2643 | 2787 | ); |
2644 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
2645 | - fatal_lang_error('no_board', false); |
|
2788 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
2789 | + fatal_lang_error('no_board', false); |
|
2790 | + } |
|
2646 | 2791 | $row = $smcFunc['db_fetch_assoc']($request); |
2647 | 2792 | $smcFunc['db_free_result']($request); |
2648 | 2793 | |
2649 | 2794 | // Change either body or subject requires permissions to modify messages. |
2650 | 2795 | if (isset($_POST['message']) || isset($_POST['subject']) || isset($_REQUEST['icon'])) |
2651 | 2796 | { |
2652 | - if (!empty($row['locked'])) |
|
2653 | - isAllowedTo('moderate_board'); |
|
2797 | + if (!empty($row['locked'])) { |
|
2798 | + isAllowedTo('moderate_board'); |
|
2799 | + } |
|
2654 | 2800 | |
2655 | 2801 | if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any')) |
2656 | 2802 | { |
2657 | - if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) |
|
2658 | - fatal_lang_error('modify_post_time_passed', false); |
|
2659 | - elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) |
|
2660 | - isAllowedTo('modify_replies'); |
|
2661 | - else |
|
2662 | - isAllowedTo('modify_own'); |
|
2803 | + if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) { |
|
2804 | + fatal_lang_error('modify_post_time_passed', false); |
|
2805 | + } elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) { |
|
2806 | + isAllowedTo('modify_replies'); |
|
2807 | + } else { |
|
2808 | + isAllowedTo('modify_own'); |
|
2809 | + } |
|
2663 | 2810 | } |
2664 | 2811 | // Otherwise, they're locked out; someone who can modify the replies is needed. |
2665 | - elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) |
|
2666 | - isAllowedTo('modify_replies'); |
|
2667 | - else |
|
2668 | - isAllowedTo('modify_any'); |
|
2812 | + elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) { |
|
2813 | + isAllowedTo('modify_replies'); |
|
2814 | + } else { |
|
2815 | + isAllowedTo('modify_any'); |
|
2816 | + } |
|
2669 | 2817 | |
2670 | 2818 | // Only log this action if it wasn't your message. |
2671 | 2819 | $moderationAction = $row['id_member'] != $user_info['id']; |
@@ -2677,10 +2825,10 @@ discard block |
||
2677 | 2825 | $_POST['subject'] = strtr($smcFunc['htmlspecialchars']($_POST['subject']), array("\r" => '', "\n" => '', "\t" => '')); |
2678 | 2826 | |
2679 | 2827 | // Maximum number of characters. |
2680 | - if ($smcFunc['strlen']($_POST['subject']) > 100) |
|
2681 | - $_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100); |
|
2682 | - } |
|
2683 | - elseif (isset($_POST['subject'])) |
|
2828 | + if ($smcFunc['strlen']($_POST['subject']) > 100) { |
|
2829 | + $_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100); |
|
2830 | + } |
|
2831 | + } elseif (isset($_POST['subject'])) |
|
2684 | 2832 | { |
2685 | 2833 | $post_errors[] = 'no_subject'; |
2686 | 2834 | unset($_POST['subject']); |
@@ -2692,13 +2840,11 @@ discard block |
||
2692 | 2840 | { |
2693 | 2841 | $post_errors[] = 'no_message'; |
2694 | 2842 | unset($_POST['message']); |
2695 | - } |
|
2696 | - elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) |
|
2843 | + } elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) |
|
2697 | 2844 | { |
2698 | 2845 | $post_errors[] = 'long_message'; |
2699 | 2846 | unset($_POST['message']); |
2700 | - } |
|
2701 | - else |
|
2847 | + } else |
|
2702 | 2848 | { |
2703 | 2849 | $_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES); |
2704 | 2850 | |
@@ -2714,31 +2860,34 @@ discard block |
||
2714 | 2860 | |
2715 | 2861 | if (isset($_POST['lock'])) |
2716 | 2862 | { |
2717 | - if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member'])) |
|
2718 | - unset($_POST['lock']); |
|
2719 | - elseif (!allowedTo('lock_any')) |
|
2863 | + if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member'])) { |
|
2864 | + unset($_POST['lock']); |
|
2865 | + } elseif (!allowedTo('lock_any')) |
|
2720 | 2866 | { |
2721 | - if ($row['locked'] == 1) |
|
2722 | - unset($_POST['lock']); |
|
2723 | - else |
|
2724 | - $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
2867 | + if ($row['locked'] == 1) { |
|
2868 | + unset($_POST['lock']); |
|
2869 | + } else { |
|
2870 | + $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
2871 | + } |
|
2872 | + } elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked']) { |
|
2873 | + unset($_POST['lock']); |
|
2874 | + } else { |
|
2875 | + $_POST['lock'] = empty($_POST['lock']) ? 0 : 1; |
|
2725 | 2876 | } |
2726 | - elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked']) |
|
2727 | - unset($_POST['lock']); |
|
2728 | - else |
|
2729 | - $_POST['lock'] = empty($_POST['lock']) ? 0 : 1; |
|
2730 | 2877 | } |
2731 | 2878 | |
2732 | - if (isset($_POST['sticky']) && !allowedTo('make_sticky')) |
|
2733 | - unset($_POST['sticky']); |
|
2879 | + if (isset($_POST['sticky']) && !allowedTo('make_sticky')) { |
|
2880 | + unset($_POST['sticky']); |
|
2881 | + } |
|
2734 | 2882 | |
2735 | 2883 | if (isset($_POST['modify_reason'])) |
2736 | 2884 | { |
2737 | 2885 | $_POST['modify_reason'] = strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => '')); |
2738 | 2886 | |
2739 | 2887 | // Maximum number of characters. |
2740 | - if ($smcFunc['strlen']($_POST['modify_reason']) > 100) |
|
2741 | - $_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100); |
|
2888 | + if ($smcFunc['strlen']($_POST['modify_reason']) > 100) { |
|
2889 | + $_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100); |
|
2890 | + } |
|
2742 | 2891 | } |
2743 | 2892 | |
2744 | 2893 | if (empty($post_errors)) |
@@ -2775,8 +2924,9 @@ discard block |
||
2775 | 2924 | } |
2776 | 2925 | } |
2777 | 2926 | // If nothing was changed there's no need to add an entry to the moderation log. |
2778 | - else |
|
2779 | - $moderationAction = false; |
|
2927 | + else { |
|
2928 | + $moderationAction = false; |
|
2929 | + } |
|
2780 | 2930 | |
2781 | 2931 | modifyPost($msgOptions, $topicOptions, $posterOptions); |
2782 | 2932 | |
@@ -2794,9 +2944,9 @@ discard block |
||
2794 | 2944 | // Get the proper (default language) response prefix first. |
2795 | 2945 | if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) |
2796 | 2946 | { |
2797 | - if ($language === $user_info['language']) |
|
2798 | - $context['response_prefix'] = $txt['response_prefix']; |
|
2799 | - else |
|
2947 | + if ($language === $user_info['language']) { |
|
2948 | + $context['response_prefix'] = $txt['response_prefix']; |
|
2949 | + } else |
|
2800 | 2950 | { |
2801 | 2951 | loadLanguage('index', $language, false); |
2802 | 2952 | $context['response_prefix'] = $txt['response_prefix']; |
@@ -2818,8 +2968,9 @@ discard block |
||
2818 | 2968 | ); |
2819 | 2969 | } |
2820 | 2970 | |
2821 | - if (!empty($moderationAction)) |
|
2822 | - logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board)); |
|
2971 | + if (!empty($moderationAction)) { |
|
2972 | + logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board)); |
|
2973 | + } |
|
2823 | 2974 | } |
2824 | 2975 | |
2825 | 2976 | if (isset($_REQUEST['xml'])) |
@@ -2860,8 +3011,7 @@ discard block |
||
2860 | 3011 | ); |
2861 | 3012 | |
2862 | 3013 | censorText($context['message']['subject']); |
2863 | - } |
|
2864 | - else |
|
3014 | + } else |
|
2865 | 3015 | { |
2866 | 3016 | $context['message'] = array( |
2867 | 3017 | 'id' => $row['id_msg'], |
@@ -2873,15 +3023,16 @@ discard block |
||
2873 | 3023 | loadLanguage('Errors'); |
2874 | 3024 | foreach ($post_errors as $post_error) |
2875 | 3025 | { |
2876 | - if ($post_error == 'long_message') |
|
2877 | - $context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']); |
|
2878 | - else |
|
2879 | - $context['message']['errors'][] = $txt['error_' . $post_error]; |
|
3026 | + if ($post_error == 'long_message') { |
|
3027 | + $context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']); |
|
3028 | + } else { |
|
3029 | + $context['message']['errors'][] = $txt['error_' . $post_error]; |
|
3030 | + } |
|
2880 | 3031 | } |
2881 | 3032 | } |
3033 | + } else { |
|
3034 | + obExit(false); |
|
3035 | + } |
|
2882 | 3036 | } |
2883 | - else |
|
2884 | - obExit(false); |
|
2885 | -} |
|
2886 | 3037 | |
2887 | 3038 | ?> |
2888 | 3039 | \ No newline at end of file |
@@ -303,7 +303,7 @@ |
||
303 | 303 | ), |
304 | 304 | array( |
305 | 305 | $_POST['msg'], $message['id_topic'], $message['id_board'], $message['id_poster'], $message['real_name'], |
306 | - $message['subject'], $message['body'] , time(), time(), 1, 0, |
|
306 | + $message['subject'], $message['body'], time(), time(), 1, 0, |
|
307 | 307 | ), |
308 | 308 | array('id_report') |
309 | 309 | ); |
@@ -12,8 +12,9 @@ discard block |
||
12 | 12 | * @version 2.1 Beta 3 |
13 | 13 | */ |
14 | 14 | |
15 | -if (!defined('SMF')) |
|
15 | +if (!defined('SMF')) { |
|
16 | 16 | die('No direct access...'); |
17 | +} |
|
17 | 18 | |
18 | 19 | /** |
19 | 20 | * Report a post or profile to the moderator... ask for a comment. |
@@ -35,10 +36,11 @@ discard block |
||
35 | 36 | |
36 | 37 | // You can't use this if it's off or you are not allowed to do it. |
37 | 38 | // If we don't have the ID of something to report, we'll die with a no_access error below |
38 | - if (isset($_REQUEST['msg'])) |
|
39 | - isAllowedTo('report_any'); |
|
40 | - elseif (isset($_REQUEST['u'])) |
|
41 | - isAllowedTo('report_user'); |
|
39 | + if (isset($_REQUEST['msg'])) { |
|
40 | + isAllowedTo('report_any'); |
|
41 | + } elseif (isset($_REQUEST['u'])) { |
|
42 | + isAllowedTo('report_user'); |
|
43 | + } |
|
42 | 44 | |
43 | 45 | // Previewing or modifying? |
44 | 46 | if (isset($_POST['preview']) && !isset($_POST['save'])) |
@@ -56,19 +58,23 @@ discard block |
||
56 | 58 | } |
57 | 59 | |
58 | 60 | // If they're posting, it should be processed by ReportToModerator2. |
59 | - if ((isset($_POST[$context['session_var']]) || isset($_POST['save'])) && empty($context['post_errors']) && !isset($_POST['preview'])) |
|
60 | - ReportToModerator2(); |
|
61 | + if ((isset($_POST[$context['session_var']]) || isset($_POST['save'])) && empty($context['post_errors']) && !isset($_POST['preview'])) { |
|
62 | + ReportToModerator2(); |
|
63 | + } |
|
61 | 64 | |
62 | 65 | // We need a message ID or user ID to check! |
63 | - if (empty($_REQUEST['msg']) && empty($_REQUEST['mid']) && empty($_REQUEST['u'])) |
|
64 | - fatal_lang_error('no_access', false); |
|
66 | + if (empty($_REQUEST['msg']) && empty($_REQUEST['mid']) && empty($_REQUEST['u'])) { |
|
67 | + fatal_lang_error('no_access', false); |
|
68 | + } |
|
65 | 69 | |
66 | 70 | // For compatibility, accept mid, but we should be using msg. (not the flavor kind!) |
67 | - if (!empty($_REQUEST['msg']) || !empty($_REQUEST['mid'])) |
|
68 | - $_REQUEST['msg'] = empty($_REQUEST['msg']) ? (int) $_REQUEST['mid'] : (int) $_REQUEST['msg']; |
|
71 | + if (!empty($_REQUEST['msg']) || !empty($_REQUEST['mid'])) { |
|
72 | + $_REQUEST['msg'] = empty($_REQUEST['msg']) ? (int) $_REQUEST['mid'] : (int) $_REQUEST['msg']; |
|
73 | + } |
|
69 | 74 | // msg and mid empty - assume we're reporting a user |
70 | - elseif (!empty($_REQUEST['u'])) |
|
71 | - $_REQUEST['u'] = (int) $_REQUEST['u']; |
|
75 | + elseif (!empty($_REQUEST['u'])) { |
|
76 | + $_REQUEST['u'] = (int) $_REQUEST['u']; |
|
77 | + } |
|
72 | 78 | |
73 | 79 | // Set up some form values |
74 | 80 | $context['report_type'] = isset($_REQUEST['msg']) ? 'msg' : 'u'; |
@@ -89,8 +95,9 @@ discard block |
||
89 | 95 | 'id_msg' => $_REQUEST['msg'], |
90 | 96 | ) |
91 | 97 | ); |
92 | - if ($smcFunc['db_num_rows']($result) == 0) |
|
93 | - fatal_lang_error('no_board', false); |
|
98 | + if ($smcFunc['db_num_rows']($result) == 0) { |
|
99 | + fatal_lang_error('no_board', false); |
|
100 | + } |
|
94 | 101 | list ($_REQUEST['msg'], $member, $starter) = $smcFunc['db_fetch_row']($result); |
95 | 102 | $smcFunc['db_free_result']($result); |
96 | 103 | |
@@ -101,8 +108,7 @@ discard block |
||
101 | 108 | |
102 | 109 | // The submit URL is different for users than it is for posts |
103 | 110 | $context['submit_url'] = $scripturl . '?action=reporttm;msg=' . $_REQUEST['msg'] . ';topic=' . $topic; |
104 | - } |
|
105 | - else |
|
111 | + } else |
|
106 | 112 | { |
107 | 113 | // Check the user's ID |
108 | 114 | $result = $smcFunc['db_query']('', ' |
@@ -114,8 +120,9 @@ discard block |
||
114 | 120 | ) |
115 | 121 | ); |
116 | 122 | |
117 | - if ($smcFunc['db_num_rows']($result) == 0) |
|
118 | - fatal_lang_error('no_user', false); |
|
123 | + if ($smcFunc['db_num_rows']($result) == 0) { |
|
124 | + fatal_lang_error('no_user', false); |
|
125 | + } |
|
119 | 126 | list($_REQUEST['u'], $display_name, $username) = $smcFunc['db_fetch_row']($result); |
120 | 127 | |
121 | 128 | $context['current_user'] = $_REQUEST['u']; |
@@ -170,10 +177,11 @@ discard block |
||
170 | 177 | is_not_guest(); |
171 | 178 | |
172 | 179 | // You must have the proper permissions! |
173 | - if (isset($_REQUEST['msg'])) |
|
174 | - isAllowedTo('report_any'); |
|
175 | - else |
|
176 | - isAllowedTo('report_user'); |
|
180 | + if (isset($_REQUEST['msg'])) { |
|
181 | + isAllowedTo('report_any'); |
|
182 | + } else { |
|
183 | + isAllowedTo('report_user'); |
|
184 | + } |
|
177 | 185 | |
178 | 186 | // Make sure they aren't spamming. |
179 | 187 | spamProtection('reporttm'); |
@@ -187,17 +195,20 @@ discard block |
||
187 | 195 | $post_errors = array(); |
188 | 196 | |
189 | 197 | // Check their session. |
190 | - if (checkSession('post', '', false) != '') |
|
191 | - $post_errors[] = 'session_timeout'; |
|
198 | + if (checkSession('post', '', false) != '') { |
|
199 | + $post_errors[] = 'session_timeout'; |
|
200 | + } |
|
192 | 201 | |
193 | 202 | // Make sure we have a comment and it's clean. |
194 | - if (!isset($_POST['comment']) || $smcFunc['htmltrim']($_POST['comment']) === '') |
|
195 | - $post_errors[] = 'no_comment'; |
|
203 | + if (!isset($_POST['comment']) || $smcFunc['htmltrim']($_POST['comment']) === '') { |
|
204 | + $post_errors[] = 'no_comment'; |
|
205 | + } |
|
196 | 206 | |
197 | 207 | $poster_comment = strtr($smcFunc['htmlspecialchars']($_POST['comment']), array("\r" => '', "\t" => '')); |
198 | 208 | |
199 | - if ($smcFunc['strlen']($poster_comment) > 254) |
|
200 | - $post_errors[] = 'post_too_long'; |
|
209 | + if ($smcFunc['strlen']($poster_comment) > 254) { |
|
210 | + $post_errors[] = 'post_too_long'; |
|
211 | + } |
|
201 | 212 | |
202 | 213 | // Any errors? |
203 | 214 | if (!empty($post_errors)) |
@@ -205,8 +216,9 @@ discard block |
||
205 | 216 | loadLanguage('Errors'); |
206 | 217 | |
207 | 218 | $context['post_errors'] = array(); |
208 | - foreach ($post_errors as $post_error) |
|
209 | - $context['post_errors'][$post_error] = $txt['error_' . $post_error]; |
|
219 | + foreach ($post_errors as $post_error) { |
|
220 | + $context['post_errors'][$post_error] = $txt['error_' . $post_error]; |
|
221 | + } |
|
210 | 222 | |
211 | 223 | return ReportToModerator(); |
212 | 224 | } |
@@ -215,8 +227,7 @@ discard block |
||
215 | 227 | { |
216 | 228 | // Handle this elsewhere to keep things from getting too long |
217 | 229 | reportPost($_POST['msg'], $poster_comment); |
218 | - } |
|
219 | - else |
|
230 | + } else |
|
220 | 231 | { |
221 | 232 | reportUser($_POST['u'], $poster_comment); |
222 | 233 | } |
@@ -247,8 +258,9 @@ discard block |
||
247 | 258 | 'id_msg' => $_POST['msg'], |
248 | 259 | ) |
249 | 260 | ); |
250 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
251 | - fatal_lang_error('no_board', false); |
|
261 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
262 | + fatal_lang_error('no_board', false); |
|
263 | + } |
|
252 | 264 | $message = $smcFunc['db_fetch_assoc']($request); |
253 | 265 | $smcFunc['db_free_result']($request); |
254 | 266 | |
@@ -268,18 +280,20 @@ discard block |
||
268 | 280 | 'ignored' => 1, |
269 | 281 | ) |
270 | 282 | ); |
271 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
272 | - list ($id_report, $ignore) = $smcFunc['db_fetch_row']($request); |
|
283 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
284 | + list ($id_report, $ignore) = $smcFunc['db_fetch_row']($request); |
|
285 | + } |
|
273 | 286 | |
274 | 287 | $smcFunc['db_free_result']($request); |
275 | 288 | |
276 | 289 | // If we're just going to ignore these, then who gives a monkeys... |
277 | - if (!empty($ignore)) |
|
278 | - redirectexit('topic=' . $topic . '.msg' . $_POST['msg'] . '#msg' . $_POST['msg']); |
|
290 | + if (!empty($ignore)) { |
|
291 | + redirectexit('topic=' . $topic . '.msg' . $_POST['msg'] . '#msg' . $_POST['msg']); |
|
292 | + } |
|
279 | 293 | |
280 | 294 | // Already reported? My god, we could be dealing with a real rogue here... |
281 | - if (!empty($id_report)) |
|
282 | - $smcFunc['db_query']('', ' |
|
295 | + if (!empty($id_report)) { |
|
296 | + $smcFunc['db_query']('', ' |
|
283 | 297 | UPDATE {db_prefix}log_reported |
284 | 298 | SET num_reports = num_reports + 1, time_updated = {int:current_time} |
285 | 299 | WHERE id_report = {int:id_report}', |
@@ -288,11 +302,13 @@ discard block |
||
288 | 302 | 'id_report' => $id_report, |
289 | 303 | ) |
290 | 304 | ); |
305 | + } |
|
291 | 306 | // Otherwise, we shall make one! |
292 | 307 | else |
293 | 308 | { |
294 | - if (empty($message['real_name'])) |
|
295 | - $message['real_name'] = $message['poster_name']; |
|
309 | + if (empty($message['real_name'])) { |
|
310 | + $message['real_name'] = $message['poster_name']; |
|
311 | + } |
|
296 | 312 | |
297 | 313 | $smcFunc['db_insert']('', |
298 | 314 | '{db_prefix}log_reported', |
@@ -371,8 +387,9 @@ discard block |
||
371 | 387 | 'id_member' => $_POST['u'] |
372 | 388 | ) |
373 | 389 | ); |
374 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
375 | - fatal_lang_error('no_user', false); |
|
390 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
391 | + fatal_lang_error('no_user', false); |
|
392 | + } |
|
376 | 393 | $user = $smcFunc['db_fetch_assoc']($request); |
377 | 394 | $smcFunc['db_free_result']($request); |
378 | 395 | |
@@ -393,18 +410,20 @@ discard block |
||
393 | 410 | 'ignored' => 1, |
394 | 411 | ) |
395 | 412 | ); |
396 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
397 | - list ($id_report, $ignore) = $smcFunc['db_fetch_row']($request); |
|
413 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
414 | + list ($id_report, $ignore) = $smcFunc['db_fetch_row']($request); |
|
415 | + } |
|
398 | 416 | |
399 | 417 | $smcFunc['db_free_result']($request); |
400 | 418 | |
401 | 419 | // If we're just going to ignore these, then who gives a monkeys... |
402 | - if (!empty($ignore)) |
|
403 | - redirectexit('action=profile;u=' . $_POST['u']); |
|
420 | + if (!empty($ignore)) { |
|
421 | + redirectexit('action=profile;u=' . $_POST['u']); |
|
422 | + } |
|
404 | 423 | |
405 | 424 | // Already reported? My god, we could be dealing with a real rogue here... |
406 | - if (!empty($id_report)) |
|
407 | - $smcFunc['db_query']('', ' |
|
425 | + if (!empty($id_report)) { |
|
426 | + $smcFunc['db_query']('', ' |
|
408 | 427 | UPDATE {db_prefix}log_reported |
409 | 428 | SET num_reports = num_reports + 1, time_updated = {int:current_time} |
410 | 429 | WHERE id_report = {int:id_report}', |
@@ -413,6 +432,7 @@ discard block |
||
413 | 432 | 'id_report' => $id_report, |
414 | 433 | ) |
415 | 434 | ); |
435 | + } |
|
416 | 436 | // Otherwise, we shall make one! |
417 | 437 | else |
418 | 438 | { |