Completed
Push — develop ( 4e806c...6a553b )
by Agel_Nash
10:03
created
manager/media/style/default/ajax.php 1 patch
Braces   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -7,11 +7,11 @@  discard block
 block discarded – undo
7 7
 
8 8
 $modx->getDatabase()->connect();
9 9
 
10
-if (empty ($modx->config)) {
10
+if (empty ($modx->config)) {
11 11
     $modx->getSettings();
12 12
 }
13 13
 
14
-if (!isset($_SESSION['mgrValidated']) || !isset($_SERVER['HTTP_X_REQUESTED_WITH']) || (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') || ($_SERVER['REQUEST_METHOD'] != 'POST')) {
14
+if (!isset($_SESSION['mgrValidated']) || !isset($_SERVER['HTTP_X_REQUESTED_WITH']) || (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') || ($_SERVER['REQUEST_METHOD'] != 'POST')) {
15 15
     $modx->sendErrorPage();
16 16
 }
17 17
 
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 
20 20
 $_lang = array();
21 21
 include_once MODX_MANAGER_PATH . '/includes/lang/english.inc.php';
22
-if ($modx->config['manager_language'] != 'english') {
22
+if ($modx->config['manager_language'] != 'english') {
23 23
     include_once MODX_MANAGER_PATH . '/includes/lang/' . $modx->config['manager_language'] . '.inc.php';
24 24
 }
25 25
 include_once MODX_MANAGER_PATH . '/media/style/' . $modx->config['manager_theme'] . '/style.php';
@@ -32,12 +32,12 @@  discard block
 block discarded – undo
32 32
 // set limit sql query
33 33
 $limit = !empty($modx->config['number_of_results']) ? (int) $modx->config['number_of_results'] : 100;
34 34
 
35
-if (isset($action)) {
36
-    switch ($action) {
35
+if (isset($action)) {
36
+    switch ($action) {
37 37
 
38 38
         case '1': {
39 39
 
40
-            switch ($frame) {
40
+            switch ($frame) {
41 41
                 case 'nodes':
42 42
                     include_once MODX_MANAGER_PATH . '/frames/nodes.php';
43 43
 
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 
52 52
             $elements = isset($_REQUEST['elements']) && is_scalar($_REQUEST['elements']) ? htmlentities($_REQUEST['elements']) : '';
53 53
 
54
-            if ($elements) {
54
+            if ($elements) {
55 55
                 $output = '';
56 56
                 $items = '';
57 57
                 $sql = '';
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
                 $sqlLike = $filter ? 'WHERE t1.name LIKE "' . $modx->getDatabase()->escape($filter) . '%"' : '';
61 61
                 $sqlLimit = $sqlLike ? '' : 'LIMIT ' . $limit;
62 62
 
63
-                switch ($elements) {
63
+                switch ($elements) {
64 64
                     case 'element_templates':
65 65
                         $a = 16;
66 66
                         $sqlLike = $filter ? 'WHERE t1.templatename LIKE "' . $modx->getDatabase()->escape($filter) . '%"' : '';
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
                         ORDER BY t1.templatename ASC
71 71
                         ' . $sqlLimit);
72 72
 
73
-                        if ($modx->hasPermission('new_template')) {
73
+                        if ($modx->hasPermission('new_template')) {
74 74
                             $output .= '<li><a id="a_19" href="index.php?a=19" target="main"><i class="fa fa-plus"></i>' . $_lang['new_template'] . '</a></li>';
75 75
                         }
76 76
 
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
                         ORDER BY t1.name ASC
87 87
                         ' . $sqlLimit);
88 88
 
89
-                        if ($modx->hasPermission('edit_template') && $modx->hasPermission('edit_snippet') && $modx->hasPermission('edit_chunk') && $modx->hasPermission('edit_plugin')) {
89
+                        if ($modx->hasPermission('edit_template') && $modx->hasPermission('edit_snippet') && $modx->hasPermission('edit_chunk') && $modx->hasPermission('edit_plugin')) {
90 90
                             $output .= '<li><a id="a_300" href="index.php?a=300" target="main"><i class="fa fa-plus"></i>' . $_lang['new_tmplvars'] . '</a></li>';
91 91
                         }
92 92
 
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
                         ORDER BY t1.name ASC
101 101
                         ' . $sqlLimit);
102 102
 
103
-                        if ($modx->hasPermission('new_chunk')) {
103
+                        if ($modx->hasPermission('new_chunk')) {
104 104
                             $output .= '<li><a id="a_77" href="index.php?a=77" target="main"><i class="fa fa-plus"></i>' . $_lang['new_htmlsnippet'] . '</a></li>';
105 105
                         }
106 106
 
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
                         ORDER BY t1.name ASC
115 115
                         ' . $sqlLimit);
116 116
 
117
-                        if ($modx->hasPermission('new_snippet')) {
117
+                        if ($modx->hasPermission('new_snippet')) {
118 118
                             $output .= '<li><a id="a_23" href="index.php?a=23" target="main"><i class="fa fa-plus"></i>' . $_lang['new_snippet'] . '</a></li>';
119 119
                         }
120 120
 
@@ -128,19 +128,19 @@  discard block
 block discarded – undo
128 128
                         ORDER BY t1.name ASC
129 129
                         ' . $sqlLimit);
130 130
 
131
-                        if ($modx->hasPermission('new_plugin')) {
131
+                        if ($modx->hasPermission('new_plugin')) {
132 132
                             $output .= '<li><a id="a_101" href="index.php?a=101" target="main"><i class="fa fa-plus"></i>' . $_lang['new_plugin'] . '</a></li>';
133 133
                         }
134 134
 
135 135
                         break;
136 136
                 }
137 137
 
138
-                if ($count = $modx->getDatabase()->getRecordCount($sql)) {
139
-                    if ($count == $limit) {
138
+                if ($count = $modx->getDatabase()->getRecordCount($sql)) {
139
+                    if ($count == $limit) {
140 140
                         $output .= '<li class="item-input"><input type="text" name="filter" class="dropdown-item form-control form-control-sm" autocomplete="off" /></li>';
141 141
                     }
142
-                    while ($row = $modx->getDatabase()->getRow($sql)) {
143
-                        if (($row['disabled'] || $row['locked']) && $role != 1) {
142
+                    while ($row = $modx->getDatabase()->getRow($sql)) {
143
+                        if (($row['disabled'] || $row['locked']) && $role != 1) {
144 144
                             continue;
145 145
                         }
146 146
 
@@ -148,9 +148,9 @@  discard block
 block discarded – undo
148 148
                     }
149 149
                 }
150 150
 
151
-                if (isset($_REQUEST['filter'])) {
151
+                if (isset($_REQUEST['filter'])) {
152 152
                     $output = $items;
153
-                } else {
153
+                } else {
154 154
                     $output .= $items;
155 155
                 }
156 156
 
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
             $sqlLike = $filter ? 'WHERE t1.username LIKE "' . $modx->getDatabase()->escape($filter) . '%"' : '';
169 169
             $sqlLimit = $sqlLike ? '' : 'LIMIT ' . $limit;
170 170
 
171
-            if(!$modx->hasPermission('save_role')) {
171
+            if(!$modx->hasPermission('save_role')) {
172 172
                 $sqlLike .= $sqlLike ? ' AND ' : 'WHERE ';
173 173
                 $sqlLike .= 't2.role != 1';
174 174
             }
@@ -180,22 +180,22 @@  discard block
 block discarded – undo
180 180
 				ORDER BY t1.username ASC
181 181
 				' . $sqlLimit);
182 182
 
183
-            if ($modx->hasPermission('new_user')) {
183
+            if ($modx->hasPermission('new_user')) {
184 184
                 $output .= '<li><a id="a_11" href="index.php?a=11" target="main"><i class="fa fa-plus"></i>' . $_lang['new_user'] . '</a></li>';
185 185
             }
186 186
 
187
-            if ($count = $modx->getDatabase()->getRecordCount($sql)) {
188
-                if ($count == $limit) {
187
+            if ($count = $modx->getDatabase()->getRecordCount($sql)) {
188
+                if ($count == $limit) {
189 189
                     $output .= '<li class="item-input"><input type="text" name="filter" class="dropdown-item form-control form-control-sm" autocomplete="off" /></li>';
190 190
                 }
191
-                while ($row = $modx->getDatabase()->getRow($sql)) {
191
+                while ($row = $modx->getDatabase()->getRow($sql)) {
192 192
                     $items .= '<li class="item ' . ($row['blocked'] ? 'disabled' : '') . '"><a id="a_' . $a . '__id_' . $row['id'] . '" href="index.php?a=' . $a . '&id=' . $row['id'] . '" target="main">' . $row['name'] . ' <small>(' . $row['id'] . ')</small></a></li>';
193 193
                 }
194 194
             }
195 195
 
196
-            if (isset($_REQUEST['filter'])) {
196
+            if (isset($_REQUEST['filter'])) {
197 197
                 $output = $items;
198
-            } else {
198
+            } else {
199 199
                 $output .= $items;
200 200
             }
201 201
 
@@ -219,22 +219,22 @@  discard block
 block discarded – undo
219 219
 				ORDER BY t1.username ASC
220 220
 				' . $sqlLimit);
221 221
 
222
-            if ($modx->hasPermission('new_web_user')) {
222
+            if ($modx->hasPermission('new_web_user')) {
223 223
                 $output .= '<li><a id="a_87" href="index.php?a=87" target="main"><i class="fa fa-plus"></i>' . $_lang['new_web_user'] . '</a></li>';
224 224
             }
225 225
 
226
-            if ($count = $modx->getDatabase()->getRecordCount($sql)) {
227
-                if ($count == $limit) {
226
+            if ($count = $modx->getDatabase()->getRecordCount($sql)) {
227
+                if ($count == $limit) {
228 228
                     $output .= '<li class="item-input"><input type="text" name="filter" class="dropdown-item form-control form-control-sm" autocomplete="off" /></li>';
229 229
                 }
230
-                while ($row = $modx->getDatabase()->getRow($sql)) {
230
+                while ($row = $modx->getDatabase()->getRow($sql)) {
231 231
                     $items .= '<li class="item ' . ($row['blocked'] ? 'disabled' : '') . '"><a id="a_' . $a . '__id_' . $row['id'] . '" href="index.php?a=' . $a . '&id=' . $row['id'] . '" target="main">' . $row['name'] . ' <small>(' . $row['id'] . ')</small></a></li>';
232 232
                 }
233 233
             }
234 234
 
235
-            if (isset($_REQUEST['filter'])) {
235
+            if (isset($_REQUEST['filter'])) {
236 236
                 $output = $items;
237
-            } else {
237
+            } else {
238 238
                 $output .= $items;
239 239
             }
240 240
 
@@ -248,8 +248,8 @@  discard block
 block discarded – undo
248 248
             $type = isset($_REQUEST['type']) && is_scalar($_REQUEST['type']) ? $modx->getDatabase()->escape($_REQUEST['type']) : false;
249 249
             $contextmenu = '';
250 250
 
251
-            if ($role && $name && $type) {
252
-                switch ($type) {
251
+            if ($role && $name && $type) {
252
+                switch ($type) {
253 253
                     case 'Snippet':
254 254
                     case 'SnippetNoCache': {
255 255
 
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 						WHERE name="' . $name . '"
259 259
 						LIMIT 1');
260 260
 
261
-                        if ($modx->getDatabase()->getRecordCount($sql)) {
261
+                        if ($modx->getDatabase()->getRecordCount($sql)) {
262 262
                             $row = $modx->getDatabase()->getRow($sql);
263 263
                             $contextmenu = array(
264 264
                                 'header' => array(
@@ -269,13 +269,13 @@  discard block
 block discarded – undo
269 269
                                     'url' => "index.php?a=22&id=" . $row['id']
270 270
                                 )
271 271
                             );
272
-                            if (!empty($row['description'])) {
272
+                            if (!empty($row['description'])) {
273 273
                                 $contextmenu['seperator'] = '';
274 274
                                 $contextmenu['description'] = array(
275 275
                                     'innerHTML' => '<i class="fa fa-info"></i> ' . $row['description']
276 276
                                 );
277 277
                             }
278
-                        } else {
278
+                        } else {
279 279
                             $contextmenu = array(
280 280
                                 'header' => array(
281 281
                                     'innerHTML' => '<i class="fa fa-code"></i> ' . $name
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
 						WHERE name="' . $name . '"
297 297
 						LIMIT 1');
298 298
 
299
-                        if ($modx->getDatabase()->getRecordCount($sql)) {
299
+                        if ($modx->getDatabase()->getRecordCount($sql)) {
300 300
                             $row = $modx->getDatabase()->getRow($sql);
301 301
                             $contextmenu = array(
302 302
                                 'header' => array(
@@ -307,13 +307,13 @@  discard block
 block discarded – undo
307 307
                                     'url' => "index.php?a=78&id=" . $row['id']
308 308
                                 )
309 309
                             );
310
-                            if (!empty($row['description'])) {
310
+                            if (!empty($row['description'])) {
311 311
                                 $contextmenu['seperator'] = '';
312 312
                                 $contextmenu['description'] = array(
313 313
                                     'innerHTML' => '<i class="fa fa-info"></i> ' . $row['description']
314 314
                                 );
315 315
                             }
316
-                        } else {
316
+                        } else {
317 317
                             $contextmenu = array(
318 318
                                 'header' => array(
319 319
                                     'innerHTML' => '<i class="fa fa-th-large"></i> ' . $name
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 						WHERE name="' . $name . '"
334 334
 						LIMIT 1');
335 335
 
336
-                        if ($modx->getDatabase()->getRecordCount($sql)) {
336
+                        if ($modx->getDatabase()->getRecordCount($sql)) {
337 337
                             $row = $modx->getDatabase()->getRow($sql);
338 338
                             $contextmenu = array(
339 339
                                 'header' => array(
@@ -344,20 +344,20 @@  discard block
 block discarded – undo
344 344
                                     'url' => "index.php?a=78&id=" . $row['id']
345 345
                                 )
346 346
                             );
347
-                            if (!empty($row['description'])) {
347
+                            if (!empty($row['description'])) {
348 348
                                 $contextmenu['seperator'] = '';
349 349
                                 $contextmenu['description'] = array(
350 350
                                     'innerHTML' => '<i class="fa fa-info"></i> ' . $row['description']
351 351
                                 );
352 352
                             }
353
-                        } else {
353
+                        } else {
354 354
 
355 355
                             $sql = $modx->getDatabase()->query('SELECT *
356 356
 							FROM ' . $modx->getDatabase()->getFullTableName('site_snippets') . '
357 357
 							WHERE name="' . $name . '"
358 358
 							LIMIT 1');
359 359
 
360
-                            if ($modx->getDatabase()->getRecordCount($sql)) {
360
+                            if ($modx->getDatabase()->getRecordCount($sql)) {
361 361
                                 $row = $modx->getDatabase()->getRow($sql);
362 362
                                 $contextmenu = array(
363 363
                                     'header' => array(
@@ -368,13 +368,13 @@  discard block
 block discarded – undo
368 368
                                         'url' => "index.php?a=22&id=" . $row['id']
369 369
                                     )
370 370
                                 );
371
-                                if (!empty($row['description'])) {
371
+                                if (!empty($row['description'])) {
372 372
                                     $contextmenu['seperator'] = '';
373 373
                                     $contextmenu['description'] = array(
374 374
                                         'innerHTML' => '<i class="fa fa-info"></i> ' . $row['description']
375 375
                                     );
376 376
                                 }
377
-                            } else {
377
+                            } else {
378 378
                                 $contextmenu = array(
379 379
                                     'header' => array(
380 380
                                         'innerHTML' => '<i class="fa fa-code"></i> ' . $name
@@ -436,7 +436,7 @@  discard block
 block discarded – undo
436 436
                             'alias_visible'
437 437
                         );
438 438
 
439
-                        if (in_array($name, $default_field)) {
439
+                        if (in_array($name, $default_field)) {
440 440
                             return;
441 441
                         }
442 442
 
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
 						WHERE name="' . $name . '"
446 446
 						LIMIT 1');
447 447
 
448
-                        if ($modx->getDatabase()->getRecordCount($sql)) {
448
+                        if ($modx->getDatabase()->getRecordCount($sql)) {
449 449
                             $row = $modx->getDatabase()->getRow($sql);
450 450
                             $contextmenu = array(
451 451
                                 'header' => array(
@@ -456,13 +456,13 @@  discard block
 block discarded – undo
456 456
                                     'url' => "index.php?a=301&id=" . $row['id']
457 457
                                 )
458 458
                             );
459
-                            if (!empty($row['description'])) {
459
+                            if (!empty($row['description'])) {
460 460
                                 $contextmenu['seperator'] = '';
461 461
                                 $contextmenu['description'] = array(
462 462
                                     'innerHTML' => '<i class="fa fa-info"></i> ' . $row['description']
463 463
                                 );
464 464
                             }
465
-                        } else {
465
+                        } else {
466 466
                             $contextmenu = array(
467 467
                                 'header' => array(
468 468
                                     'innerHTML' => '<i class="fa fa-list-alt"></i> ' . $name
@@ -487,13 +487,13 @@  discard block
 block discarded – undo
487 487
         case 'movedocument' : {
488 488
             $json = array();
489 489
 
490
-            if ($modx->hasPermission('new_document') && $modx->hasPermission('edit_document') && $modx->hasPermission('save_document')) {
490
+            if ($modx->hasPermission('new_document') && $modx->hasPermission('edit_document') && $modx->hasPermission('save_document')) {
491 491
                 $id = !empty($_REQUEST['id']) ? (int)$_REQUEST['id'] : '';
492 492
                 $parent = isset($_REQUEST['parent']) ? (int)$_REQUEST['parent'] : 0;
493 493
                 $menuindex = isset($_REQUEST['menuindex']) && is_scalar($_REQUEST['menuindex']) ? $_REQUEST['menuindex'] : 0;
494 494
 
495 495
                 // set parent
496
-                if ($id && $parent >= 0) {
496
+                if ($id && $parent >= 0) {
497 497
 
498 498
                     // find older parent
499 499
                     $parentOld = $modx->getDatabase()->getValue($modx->getDatabase()->select('parent', $modx->getDatabase()->getFullTableName('site_content'), 'id=' . $id));
@@ -504,31 +504,31 @@  discard block
 block discarded – undo
504 504
                         'new_parent'  => $parent,
505 505
                     ]);
506 506
 
507
-                    if (is_array($eventOut) && count($eventOut) > 0) {
507
+                    if (is_array($eventOut) && count($eventOut) > 0) {
508 508
                         $eventParent = array_pop($eventOut);
509 509
 
510
-                        if ($eventParent == $parentOld) {
510
+                        if ($eventParent == $parentOld) {
511 511
                             $json['errors'] = $_lang['error_movedocument2'];
512
-                        } else {
512
+                        } else {
513 513
                             $parent = $eventParent;
514 514
                         }
515 515
                     }
516 516
 
517
-                    if (empty($json['errors'])) {
517
+                    if (empty($json['errors'])) {
518 518
                         // check privileges user for move docs
519
-                        if (!empty($modx->config['tree_show_protected']) && $role != 1) {
519
+                        if (!empty($modx->config['tree_show_protected']) && $role != 1) {
520 520
                             $sql = $modx->getDatabase()->select('*', $modx->getDatabase()->getFullTableName('document_groups'), 'document IN(' . $id . ',' . $parent . ',' . $parentOld . ')');
521
-                            if ($modx->getDatabase()->getRecordCount($sql)) {
521
+                            if ($modx->getDatabase()->getRecordCount($sql)) {
522 522
                                 $document_groups = array();
523
-                                while ($row = $modx->getDatabase()->getRow($sql)) {
523
+                                while ($row = $modx->getDatabase()->getRow($sql)) {
524 524
                                     $document_groups[$row['document']]['groups'][] = $row['document_group'];
525 525
                                 }
526
-                                foreach ($document_groups as $key => $value) {
527
-                                    if (($key == $parent || $key == $parentOld || $key == $id) && !in_array($role, $value['groups'])) {
526
+                                foreach ($document_groups as $key => $value) {
527
+                                    if (($key == $parent || $key == $parentOld || $key == $id) && !in_array($role, $value['groups'])) {
528 528
                                         $json['errors'] = $_lang["error_no_privileges"];
529 529
                                     }
530 530
                                 }
531
-                                if ($json['errors']) {
531
+                                if ($json['errors']) {
532 532
                                     header('content-type: application/json');
533 533
                                     echo json_encode($json, JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE);
534 534
                                     break;
@@ -536,9 +536,9 @@  discard block
 block discarded – undo
536 536
                             }
537 537
                         }
538 538
 
539
-                        if ($parent == 0 && $parent != $parentOld && !$modx->config['udperms_allowroot'] && $role != 1) {
539
+                        if ($parent == 0 && $parent != $parentOld && !$modx->config['udperms_allowroot'] && $role != 1) {
540 540
                             $json['errors'] = $_lang["error_no_privileges"];
541
-                        } else {
541
+                        } else {
542 542
                             // set new parent
543 543
                             $modx->getDatabase()->update(array(
544 544
                                 'parent' => $parent
@@ -548,13 +548,13 @@  discard block
 block discarded – undo
548 548
                                 'isfolder' => 1
549 549
                             ), $modx->getDatabase()->getFullTableName('site_content'), 'id=' . $parent);
550 550
 
551
-                            if ($parent != $parentOld) {
551
+                            if ($parent != $parentOld) {
552 552
                                 // check children docs and set parent isfolder
553
-                                if ($modx->getDatabase()->getRecordCount($modx->getDatabase()->select('id', $modx->getDatabase()->getFullTableName('site_content'), 'parent=' . $parentOld))) {
553
+                                if ($modx->getDatabase()->getRecordCount($modx->getDatabase()->select('id', $modx->getDatabase()->getFullTableName('site_content'), 'parent=' . $parentOld))) {
554 554
                                     $modx->getDatabase()->update(array(
555 555
                                         'isfolder' => 1
556 556
                                     ), $modx->getDatabase()->getFullTableName('site_content'), 'id=' . $parentOld);
557
-                                } else {
557
+                                } else {
558 558
                                     $modx->getDatabase()->update(array(
559 559
                                         'isfolder' => 0
560 560
                                     ), $modx->getDatabase()->getFullTableName('site_content'), 'id=' . $parentOld);
@@ -562,16 +562,16 @@  discard block
 block discarded – undo
562 562
                             }
563 563
 
564 564
                             // set menuindex
565
-                            if (!empty($menuindex)) {
565
+                            if (!empty($menuindex)) {
566 566
                                 $menuindex = explode(',', $menuindex);
567
-                                foreach ($menuindex as $key => $value) {
567
+                                foreach ($menuindex as $key => $value) {
568 568
                                     $modx->getDatabase()->query('UPDATE ' . $modx->getDatabase()->getFullTableName('site_content') . ' SET menuindex=' . $key . ' WHERE id=' . $value);
569 569
                                 }
570
-                            } else {
570
+                            } else {
571 571
                                 // TODO: max(*) menuindex
572 572
                             }
573 573
 
574
-                            if (!$json['errors']) {
574
+                            if (!$json['errors']) {
575 575
                                 $json['success'] = $_lang["actioncomplete"];
576 576
 
577 577
                                 $modx->invokeEvent('onAfterMoveDocument', [
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
                         }
584 584
                     }
585 585
                 }
586
-            } else {
586
+            } else {
587 587
                 $json['errors'] = $_lang["error_no_privileges"];
588 588
             }
589 589
 
@@ -599,7 +599,7 @@  discard block
 block discarded – undo
599 599
 
600 600
             $output = !!$modx->elementIsLocked($type, $id, true);
601 601
 
602
-            if (!$output) {
602
+            if (!$output) {
603 603
                 $docgrp = (isset($_SESSION['mgrDocgroups']) && is_array($_SESSION['mgrDocgroups'])) ? implode(',', $_SESSION['mgrDocgroups']) : '';
604 604
                 $docgrp_cond = $docgrp ? ' OR dg.document_group IN (' . $docgrp . ')' : '';
605 605
                 $sql = '
@@ -608,7 +608,7 @@  discard block
 block discarded – undo
608 608
                     LEFT JOIN ' . $modx->getDatabase()->getFullTableName('document_groups') . ' dg ON dg.document=sc.id
609 609
                     WHERE sc.id=' . $id . ' GROUP BY sc.id';
610 610
                 $sql = $modx->getDatabase()->query($sql);
611
-                if ($modx->getDatabase()->getRecordCount($sql)) {
611
+                if ($modx->getDatabase()->getRecordCount($sql)) {
612 612
                     $row = $modx->getDatabase()->getRow($sql);
613 613
                     $output = !!$row['locked'];
614 614
                 }
Please login to merge, or discard this patch.
manager/includes/src/Core.php 1 patch
Braces   +62 added lines, -31 removed lines patch added patch discarded remove patch
@@ -281,7 +281,8 @@  discard block
 block discarded – undo
281 281
         return $service;
282 282
     }
283 283
 
284
-    private function checkServiceAlias($name){
284
+    private function checkServiceAlias($name)
285
+    {
285 286
         foreach ($this->providerAliases as $alias => $interface) {
286 287
             if($name === $interface) {
287 288
                 return $alias;
@@ -963,13 +964,15 @@  discard block
 block discarded – undo
963 964
             $this->virtualDir = '';
964 965
         }
965 966
 
966
-        if (preg_match('@^[1-9][0-9]*$@', $q) && !isset($this->documentListing[$q])) { /* we got an ID returned, check to make sure it's not an alias */
967
+        if (preg_match('@^[1-9][0-9]*$@', $q) && !isset($this->documentListing[$q])) {
968
+/* we got an ID returned, check to make sure it's not an alias */
967 969
             /* FS#476 and FS#308: check that id is valid in terms of virtualDir structure */
968 970
             if ($this->config['use_alias_path'] == 1) {
969 971
                 if (($this->virtualDir != '' && !isset($this->documentListing[$this->virtualDir . '/' . $q]) || ($this->virtualDir == '' && !isset($this->documentListing[$q]))) && (($this->virtualDir != '' && isset($this->documentListing[$this->virtualDir]) && in_array($q, $this->getChildIds($this->documentListing[$this->virtualDir], 1))) || ($this->virtualDir == '' && in_array($q, $this->getChildIds(0, 1))))) {
970 972
                     $this->documentMethod = 'id';
971 973
                     return $q;
972
-                } else { /* not a valid id in terms of virtualDir, treat as alias */
974
+                } else {
975
+/* not a valid id in terms of virtualDir, treat as alias */
973 976
                     $this->documentMethod = 'alias';
974 977
                     return $q;
975 978
                 }
@@ -977,7 +980,8 @@  discard block
 block discarded – undo
977 980
                 $this->documentMethod = 'id';
978 981
                 return $q;
979 982
             }
980
-        } else { /* we didn't get an ID back, so instead we assume it's an alias */
983
+        } else {
984
+/* we didn't get an ID back, so instead we assume it's an alias */
981 985
             if ($this->config['friendly_alias_urls'] != 1) {
982 986
                 $q = $qOrig;
983 987
             }
@@ -1007,13 +1011,14 @@  discard block
 block discarded – undo
1007 1011
      * @param $id
1008 1012
      * @return array|mixed|null|string
1009 1013
      */
1010
-    public function makePageCacheKey($id){
1014
+    public function makePageCacheKey($id)
1015
+    {
1011 1016
         $hash = $id;
1012 1017
         $tmp = null;
1013 1018
         $params = array();
1014
-        if(!empty($this->systemCacheKey)){
1019
+        if(!empty($this->systemCacheKey)) {
1015 1020
             $hash = $this->systemCacheKey;
1016
-        }else {
1021
+        } else {
1017 1022
             if (!empty($_GET)) {
1018 1023
                 // Sort GET parameters so that the order of parameters on the HTTP request don't affect the generated cache ID.
1019 1024
                 $params = $_GET;
@@ -1022,7 +1027,7 @@  discard block
 block discarded – undo
1022 1027
             }
1023 1028
         }
1024 1029
         $evtOut = $this->invokeEvent("OnMakePageCacheKey", array ("hash" => $hash, "id" => $id, 'params' => $params));
1025
-        if (is_array($evtOut) && count($evtOut) > 0){
1030
+        if (is_array($evtOut) && count($evtOut) > 0) {
1026 1031
             $tmp = array_pop($evtOut);
1027 1032
         }
1028 1033
         return empty($tmp) ? $hash : $tmp;
@@ -1359,7 +1364,8 @@  discard block
 block discarded – undo
1359 1364
             $where
1360 1365
         );
1361 1366
         $this->getDatabase()->update($field, $this->getDatabase()->getFullTableName('site_content'), $where);
1362
-        if ($this->getDatabase()->getRecordCount($result_pub) >= 1) { //Event unPublished doc
1367
+        if ($this->getDatabase()->getRecordCount($result_pub) >= 1) {
1368
+//Event unPublished doc
1363 1369
             while ($row_pub = $this->getDatabase()->getRow($result_pub)) {
1364 1370
                 $this->invokeEvent("OnDocUnPublished", array(
1365 1371
                     "docid" => $row_pub['id']
@@ -1376,7 +1382,8 @@  discard block
 block discarded – undo
1376 1382
             $where
1377 1383
         );
1378 1384
         $this->getDatabase()->update($field, $this->getDatabase()->getFullTableName('site_content'), $where);
1379
-        if ($this->getDatabase()->getRecordCount($result_unpub) >= 1) { //Event unPublished doc
1385
+        if ($this->getDatabase()->getRecordCount($result_unpub) >= 1) {
1386
+//Event unPublished doc
1380 1387
             while ($row_unpub = $this->getDatabase()->getRow($result_unpub)) {
1381 1388
                 $this->invokeEvent("OnDocUnPublished", array(
1382 1389
                     "docid" => $row_unpub['id']
@@ -1467,10 +1474,18 @@  discard block
 block discarded – undo
1467 1474
             return array();
1468 1475
         }
1469 1476
         $spacer = md5('<<<EVO>>>');
1470
-        if($left==='{{' && strpos($content,';}}')!==false)  $content = str_replace(';}}', sprintf(';}%s}',   $spacer),$content);
1471
-        if($left==='{{' && strpos($content,'{{}}')!==false) $content = str_replace('{{}}',sprintf('{%$1s{}%$1s}',$spacer),$content);
1472
-        if($left==='[[' && strpos($content,']]]]')!==false) $content = str_replace(']]]]',sprintf(']]%s]]',  $spacer),$content);
1473
-        if($left==='[[' && strpos($content,']]]')!==false)  $content = str_replace(']]]', sprintf(']%s]]',   $spacer),$content);
1477
+        if($left==='{{' && strpos($content,';}}')!==false) {
1478
+            $content = str_replace(';}}', sprintf(';}%s}',   $spacer),$content);
1479
+        }
1480
+        if($left==='{{' && strpos($content,'{{}}')!==false) {
1481
+            $content = str_replace('{{}}',sprintf('{%$1s{}%$1s}',$spacer),$content);
1482
+        }
1483
+        if($left==='[[' && strpos($content,']]]]')!==false) {
1484
+            $content = str_replace(']]]]',sprintf(']]%s]]',  $spacer),$content);
1485
+        }
1486
+        if($left==='[[' && strpos($content,']]]')!==false) {
1487
+            $content = str_replace(']]]', sprintf(']%s]]',   $spacer),$content);
1488
+        }
1474 1489
 
1475 1490
         $pos['<![CDATA['] = strpos($content, '<![CDATA[');
1476 1491
         $pos[']]>'] = strpos($content, ']]>');
@@ -1523,7 +1538,8 @@  discard block
 block discarded – undo
1523 1538
                         }
1524 1539
                     }
1525 1540
 
1526
-                    if (!in_array($fetch, $tags)) {  // Avoid double Matches
1541
+                    if (!in_array($fetch, $tags)) {
1542
+// Avoid double Matches
1527 1543
                         $tags[] = $fetch; // Fetch
1528 1544
                     };
1529 1545
                     $fetch = ''; // and reset
@@ -1541,7 +1557,9 @@  discard block
 block discarded – undo
1541 1557
             }
1542 1558
         }
1543 1559
         foreach($tags as $i=>$tag) {
1544
-            if(strpos($tag,$spacer)!==false) $tags[$i] = str_replace($spacer, '', $tag);
1560
+            if(strpos($tag,$spacer)!==false) {
1561
+                $tags[$i] = str_replace($spacer, '', $tag);
1562
+            }
1545 1563
         }
1546 1564
         return $tags;
1547 1565
     }
@@ -1581,7 +1599,10 @@  discard block
 block discarded – undo
1581 1599
         }
1582 1600
 
1583 1601
         foreach ($matches[1] as $i => $key) {
1584
-            if(strpos($key,'[+')!==false) continue; // Allow chunk {{chunk?&param=`xxx`}} with [*tv_name_[+param+]*] as content
1602
+            if(strpos($key,'[+')!==false) {
1603
+                continue;
1604
+            }
1605
+            // Allow chunk {{chunk?&param=`xxx`}} with [*tv_name_[+param+]*] as content
1585 1606
             if (substr($key, 0, 1) == '#') {
1586 1607
                 $key = substr($key, 1);
1587 1608
             } // remove # for QuickEdit format
@@ -2307,7 +2328,8 @@  discard block
 block discarded – undo
2307 2328
      * @return mixed|string
2308 2329
      */
2309 2330
     public function _getSGVar($value)
2310
-    { // Get super globals
2331
+    {
2332
+// Get super globals
2311 2333
         $key = $value;
2312 2334
         $_ = $this->config['enable_filter'];
2313 2335
         $this->config['enable_filter'] = 1;
@@ -2716,7 +2738,8 @@  discard block
 block discarded – undo
2716 2738
         if ($this->config['friendly_urls'] == 1) {
2717 2739
             $aliases = array();
2718 2740
             if (is_array($this->documentListing)) {
2719
-                foreach ($this->documentListing as $path => $docid) { // This is big Loop on large site!
2741
+                foreach ($this->documentListing as $path => $docid) {
2742
+// This is big Loop on large site!
2720 2743
                     $aliases[$docid] = $path;
2721 2744
                     $isfolder[$docid] = $this->aliasListing[$docid]['isfolder'];
2722 2745
                 }
@@ -2749,7 +2772,7 @@  discard block
 block discarded – undo
2749 2772
             $isfriendly = ($this->config['friendly_alias_urls'] == 1 ? 1 : 0);
2750 2773
             $pref = $this->config['friendly_url_prefix'];
2751 2774
             $suff = $this->config['friendly_url_suffix'];
2752
-            $documentSource = preg_replace_callback($in, function ($m) use ($aliases, $isfolder, $isfriendly, $pref, $suff) {
2775
+            $documentSource = preg_replace_callback($in, function ($m) use ($aliases, $isfolder, $isfriendly, $pref, $suff){
2753 2776
                 global $modx;
2754 2777
                 $thealias = $aliases[$m[1]];
2755 2778
                 $thefolder = $isfolder[$m[1]];
@@ -4533,7 +4556,8 @@  discard block
 block discarded – undo
4533 4556
         if (isset ($this->snippetCache[$snippetName])) {
4534 4557
             $snippet = $this->snippetCache[$snippetName];
4535 4558
             $properties = !empty($this->snippetCache[$snippetName . "Props"]) ? $this->snippetCache[$snippetName . "Props"] : '';
4536
-        } else { // not in cache so let's check the db
4559
+        } else {
4560
+// not in cache so let's check the db
4537 4561
             $sql = "SELECT ss.`name`, ss.`snippet`, ss.`properties`, sm.properties as `sharedproperties` FROM " . $this->getDatabase()->getFullTableName("site_snippets") . " as ss LEFT JOIN " . $this->getDatabase()->getFullTableName('site_modules') . " as sm on sm.guid=ss.moduleguid WHERE ss.`name`='" . $this->getDatabase()->escape($snippetName) . "'  AND ss.disabled=0;";
4538 4562
             $result = $this->getDatabase()->query($sql);
4539 4563
             if ($this->getDatabase()->getRecordCount($result) == 1) {
@@ -5047,7 +5071,7 @@  discard block
 block discarded – undo
5047 5071
             $result = $this->getDatabase()->makeArray($rs);
5048 5072
 
5049 5073
             // get default/built-in template variables
5050
-            if(is_array($docRow)){
5074
+            if(is_array($docRow)) {
5051 5075
                 ksort($docRow);
5052 5076
 
5053 5077
                 foreach ($docRow as $key => $value) {
@@ -5524,12 +5548,16 @@  discard block
 block discarded – undo
5524 5548
             return '';
5525 5549
         } // nothing to register
5526 5550
         if (!is_array($options)) {
5527
-            if (is_bool($options))  // backward compatibility with old plaintext parameter
5551
+            if (is_bool($options)) {
5552
+                // backward compatibility with old plaintext parameter
5528 5553
             {
5529 5554
                 $options = array('plaintext' => $options);
5530
-            } elseif (is_string($options)) // Also allow script name as 2nd param
5555
+            }
5556
+            } elseif (is_string($options)) {
5557
+                // Also allow script name as 2nd param
5531 5558
             {
5532 5559
                 $options = array('name' => $options);
5560
+            }
5533 5561
             } else {
5534 5562
                 $options = array();
5535 5563
             }
@@ -5541,7 +5569,8 @@  discard block
 block discarded – undo
5541 5569
         unset($overwritepos); // probably unnecessary--just making sure
5542 5570
 
5543 5571
         $useThisVer = true;
5544
-        if (isset($this->loadedjscripts[$key])) { // a matching script was found
5572
+        if (isset($this->loadedjscripts[$key])) {
5573
+// a matching script was found
5545 5574
             // if existing script is a startup script, make sure the candidate is also a startup script
5546 5575
             if ($this->loadedjscripts[$key]['startup']) {
5547 5576
                 $startup = true;
@@ -5561,7 +5590,8 @@  discard block
 block discarded – undo
5561 5590
                     // overwrite the old script (the position may be important for dependent scripts)
5562 5591
                     $overwritepos = $this->loadedjscripts[$key]['pos'];
5563 5592
                 }
5564
-            } else { // Use the original version
5593
+            } else {
5594
+// Use the original version
5565 5595
                 if ($startup == true && $this->loadedjscripts[$key]['startup'] == false) {
5566 5596
                     // need to move the exisiting script to the head
5567 5597
                     $version = $this->loadedjscripts[$key][$version];
@@ -5686,7 +5716,8 @@  discard block
 block discarded – undo
5686 5716
         }
5687 5717
 
5688 5718
         $results = null;
5689
-        foreach ($this->pluginEvent[$evtName] as $pluginName) { // start for loop
5719
+        foreach ($this->pluginEvent[$evtName] as $pluginName) {
5720
+// start for loop
5690 5721
             if ($this->dumpPlugins) {
5691 5722
                 $eventtime = $this->getMicroTime();
5692 5723
             }
@@ -5832,8 +5863,7 @@  discard block
 block discarded – undo
5832 5863
                     }
5833 5864
                 }
5834 5865
             }
5835
-        }
5836
-        elseif(\is_array($propertyString)) {
5866
+        } elseif(\is_array($propertyString)) {
5837 5867
             $property = $propertyString;
5838 5868
         }
5839 5869
         if (!empty($elementName) && !empty($elementType)) {
@@ -6280,7 +6310,8 @@  discard block
 block discarded – undo
6280 6310
      * @return bool
6281 6311
      */
6282 6312
     public function isSafeCode($phpcode = '', $safe_functions = '')
6283
-    { // return true or false
6313
+    {
6314
+// return true or false
6284 6315
         if ($safe_functions == '') {
6285 6316
             return false;
6286 6317
         }
@@ -6689,7 +6720,7 @@  discard block
 block discarded – undo
6689 6720
             $args = array_pad(array(), $_, '$var');
6690 6721
             $args = implode(", ", $args);
6691 6722
             $modx = &$this;
6692
-            $args = preg_replace_callback('/\$var/', function () use ($modx, &$tmp, $val) {
6723
+            $args = preg_replace_callback('/\$var/', function () use ($modx, &$tmp, $val){
6693 6724
                 $arg = $val['args'][$tmp - 1];
6694 6725
                 switch (true) {
6695 6726
                     case is_null($arg): {
Please login to merge, or discard this patch.
manager/includes/src/Cache.php 1 patch
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -82,7 +82,8 @@  discard block
 block discarded – undo
82 82
      * @return string
83 83
      */
84 84
     public function getParents($id, $path = '')
85
-    { // modx:returns child's parent
85
+    {
86
+// modx:returns child's parent
86 87
         $modx = evolutionCMS();
87 88
         if (empty($this->aliases)) {
88 89
             $rs = $modx->getDatabase()->select(
@@ -481,7 +482,8 @@  discard block
 block discarded – undo
481 482
                         $_ = trim($_);
482 483
                     }
483 484
                     $lastChar = substr($_, -1);
484
-                    if (!in_array($lastChar, $chars)) {// ,320,327,288,284,289
485
+                    if (!in_array($lastChar, $chars)) {
486
+// ,320,327,288,284,289
485 487
                         if (!in_array($prev_token,
486 488
                             array(T_FOREACH, T_WHILE, T_FOR, T_BOOLEAN_AND, T_BOOLEAN_OR, T_DOUBLE_ARROW))) {
487 489
                             $_ .= ' ';
Please login to merge, or discard this patch.
manager/includes/src/Legacy/mgrResources.php 1 patch
Braces   +23 added lines, -12 removed lines patch added patch discarded remove patch
@@ -1,6 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php namespace EvolutionCMS\Legacy;
2 2
 
3
-class mgrResources {
3
+class mgrResources
4
+{
4 5
     /**
5 6
      * @var array
6 7
      */
@@ -21,7 +22,8 @@  discard block
 block discarded – undo
21 22
     /**
22 23
      * mgrResources constructor.
23 24
      */
24
-    public function __construct() {
25
+    public function __construct()
26
+    {
25 27
         $this->setTypes();
26 28
         $this->queryItemsFromDB();
27 29
         $this->prepareCategoryArrays();
@@ -30,7 +32,8 @@  discard block
 block discarded – undo
30 32
     /**
31 33
      * @return void
32 34
      */
33
-    public function setTypes() {
35
+    public function setTypes()
36
+    {
34 37
         global $_lang;
35 38
         $this->types['site_templates']    = array(
36 39
             'title'=>$_lang["manage_templates"],
@@ -68,7 +71,8 @@  discard block
 block discarded – undo
68 71
     /**
69 72
      * @return void
70 73
      */
71
-    public function queryItemsFromDB() {
74
+    public function queryItemsFromDB()
75
+    {
72 76
         foreach($this->types as $resourceTable=>$type) {
73 77
             if($this->hasAnyPermissions($type['permissions'])) {
74 78
                 $nameField = isset($type['name']) ? $type['name'] : 'name';
@@ -81,11 +85,13 @@  discard block
 block discarded – undo
81 85
      * @param array $permissions
82 86
      * @return bool
83 87
      */
84
-    public function hasAnyPermissions($permissions) {
88
+    public function hasAnyPermissions($permissions)
89
+    {
85 90
         $modx = evolutionCMS();
86 91
 
87
-        foreach($permissions as $p)
88
-            if($modx->hasPermission($p)) return true;
92
+        foreach($permissions as $p) {
93
+                    if($modx->hasPermission($p)) return true;
94
+        }
89 95
 
90 96
         return false;
91 97
     }
@@ -95,7 +101,8 @@  discard block
 block discarded – undo
95 101
      * @param string $nameField
96 102
      * @return array|bool
97 103
      */
98
-    public function queryResources($resourceTable, $nameField = 'name') {
104
+    public function queryResources($resourceTable, $nameField = 'name')
105
+    {
99 106
         $modx = evolutionCMS(); global $_lang;
100 107
 
101 108
         $allowed = array(
@@ -112,8 +119,9 @@  discard block
 block discarded – undo
112 119
             $tvsql    = 'site_tmplvars.caption, ';
113 120
             $tvjoin   = sprintf('LEFT JOIN %s AS stt ON site_tmplvars.id=stt.tmplvarid GROUP BY site_tmplvars.id,reltpl', $modx->getDatabase()->getFullTableName('site_tmplvar_templates'));
114 121
             $sttfield = 'IF(stt.templateid,1,0) AS reltpl,';
122
+        } else {
123
+            $sttfield = '';
115 124
         }
116
-        else $sttfield = '';
117 125
 
118 126
         $selectableTemplates = $resourceTable === 'site_templates' ? "{$resourceTable}.selectable, " : "";
119 127
 
@@ -126,7 +134,9 @@  discard block
 block discarded – undo
126 134
         );
127 135
         $limit = $modx->getDatabase()->getRecordCount($rs);
128 136
 
129
-        if($limit < 1) return false;
137
+        if($limit < 1) {
138
+            return false;
139
+        }
130 140
 
131 141
         $result = array();
132 142
         while ($row = $modx->getDatabase()->getRow($rs)) {
@@ -138,7 +148,8 @@  discard block
 block discarded – undo
138 148
     /**
139 149
      * @return void
140 150
      */
141
-    public function prepareCategoryArrays() {
151
+    public function prepareCategoryArrays()
152
+    {
142 153
         foreach($this->items as $type=>$items) {
143 154
             foreach((array)$items as $item) {
144 155
                 $catid = $item['catid'] ? $item['catid'] : 0;
@@ -154,7 +165,7 @@  discard block
 block discarded – undo
154 165
 
155 166
         // Now sort by name
156 167
         foreach($this->itemsPerCategory as $catid=>$items) {
157
-            usort($this->itemsPerCategory[$catid], function ($a, $b) {
168
+            usort($this->itemsPerCategory[$catid], function ($a, $b){
158 169
                 return strcasecmp($a['name'], $b['name']);
159 170
             });
160 171
         }
Please login to merge, or discard this patch.
manager/includes/functions/processors.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -384,10 +384,12 @@
 block discarded – undo
384 384
         $failedlogins += 1;
385 385
 
386 386
         $fields = array('failedlogincount' => $failedlogins);
387
-        if ($failedlogins >= $failed_allowed) //block user for too many fail attempts
387
+        if ($failedlogins >= $failed_allowed) {
388
+            //block user for too many fail attempts
388 389
         {
389 390
             $fields['blockeduntil'] = time() + ($blocked_minutes * 60);
390 391
         }
392
+        }
391 393
 
392 394
         $modx->getDatabase()->update(
393 395
             $fields,
Please login to merge, or discard this patch.
manager/includes/extenders/modifiers/mdf_memberof.inc.php 1 patch
Braces   +10 added lines, -5 removed lines patch added patch discarded remove patch
@@ -5,11 +5,14 @@  discard block
 block discarded – undo
5 5
 $groupNames = ($this->strlen($opt) > 0 ) ? explode(',',$opt) : array();
6 6
 
7 7
 // if $groupNames is not an array return false
8
-if(!is_array($groupNames)) return 0;
8
+if(!is_array($groupNames)) {
9
+    return 0;
10
+}
9 11
 
10 12
 // Creates an array with all webgroups the user id is in
11
-if (isset($modx->getModifiers()->cache['mo'][$userID])) $grpNames = $modx->getModifiers()->cache['mo'][$userID];
12
-else {
13
+if (isset($modx->getModifiers()->cache['mo'][$userID])) {
14
+    $grpNames = $modx->getModifiers()->cache['mo'][$userID];
15
+} else {
13 16
     $from = sprintf(
14 17
         $modx->getDatabase()->getFullTableName('webgroup_names') .
15 18
         " wgn INNER JOIN " .
@@ -24,8 +27,10 @@  discard block
 block discarded – undo
24 27
 
25 28
 // Check if a supplied group matches a webgroup from the array we just created
26 29
 foreach($groupNames as $k=>$v) {
27
-    if(in_array(trim($v),$grpNames)) return 1;
28
-}
30
+    if(in_array(trim($v),$grpNames)) {
31
+        return 1;
32
+    }
33
+    }
29 34
 
30 35
 // If we get here the above logic did not find a match, so return false
31 36
 return 0;
Please login to merge, or discard this patch.