Test Failed
Push — master ( de7c2b...75b2a8 )
by Maxim
02:54
created
assets/snippets/DocLister/lib/DLphx.class.php 2 patches
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 #	Date: March 22, 2013
11 11
 #
12 12
 ####*/
13
-include_once(MODX_BASE_PATH . 'assets/lib/APIHelpers.class.php');
13
+include_once(MODX_BASE_PATH.'assets/lib/APIHelpers.class.php');
14 14
 
15 15
 /**
16 16
  * Class DLphx
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
         $this->user["usrid"] = isset($_SESSION['webInternalKey']) ? intval($_SESSION['webInternalKey']) : 0;
52 52
         $this->user["id"] = ($this->user["usrid"] > 0) ? (-$this->user["usrid"]) : $this->user["mgrid"];
53 53
 
54
-        $this->debug = (bool)$debug;
54
+        $this->debug = (bool) $debug;
55 55
 
56 56
         $this->maxPasses = ($maxpass != '') ? $maxpass : 50;
57 57
 
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
         preg_match_all('~(?:=`[^`@]*?)(\[\+([^:\+\[\]]+)([^\[\]]*?)\+\])~s', $template, $matches);
96 96
         if ($matches[0]) {
97 97
             $template = str_replace($matches[1], '', $template);
98
-            $this->Log("Cleaning unsolved tags: \n" . implode("\n", $matches[2]));
98
+            $this->Log("Cleaning unsolved tags: \n".implode("\n", $matches[2]));
99 99
         }
100 100
         // Restore non-call characters in the template: [, ]
101 101
         $template = str_replace($this->safetags[1], $this->safetags[2], $template);
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
         }
108 108
         // Write an event log if debugging is enabled and there is something to log
109 109
         if ($this->debug && $this->debugLog) {
110
-            $modx->logEvent($this->curPass, 1, $this->createEventLog(), $this->name . ' ' . $this->version);
110
+            $modx->logEvent($this->curPass, 1, $this->createEventLog(), $this->name.' '.$this->version);
111 111
             $this->debugLog = false;
112 112
         }
113 113
 
@@ -138,8 +138,8 @@  discard block
 block discarded – undo
138 138
             for ($i = 0; $i < $count; $i++) {
139 139
                 $var_search[] = $matches[0][$i];
140 140
                 $input = $matches[1][$i];
141
-                $this->Log('MODX Chunk: ' . $input);
142
-                $input = $modx->mergeChunkContent('{{' . $input . '}}');
141
+                $this->Log('MODX Chunk: '.$input);
142
+                $input = $modx->mergeChunkContent('{{'.$input.'}}');
143 143
                 $var_replace[] = $this->Filter($input, $matches[2][$i]);
144 144
             }
145 145
             $template = str_replace($var_search, $var_replace, $template);
@@ -155,10 +155,10 @@  discard block
 block discarded – undo
155 155
             // for each detected snippet
156 156
             for ($i = 0; $i < $count; $i++) {
157 157
                 $snippet = $matches[2][$i]; // snippet call
158
-                $this->Log("MODx Snippet -> " . $snippet);
158
+                $this->Log("MODx Snippet -> ".$snippet);
159 159
 
160 160
                 // Let MODx evaluate snippet
161
-                $replace = $modx->evalSnippets("[[" . $snippet . "]]");
161
+                $replace = $modx->evalSnippets("[[".$snippet."]]");
162 162
                 $this->LogSnippet($replace);
163 163
 
164 164
                 // Replace values
@@ -187,19 +187,19 @@  discard block
 block discarded – undo
187 187
                 switch ($matches[1][$i]) {
188 188
                     // Document / Template Variable eXtended
189 189
                     case "*":
190
-                        $this->Log("MODx TV/DV: " . $input);
191
-                        $input = $modx->mergeDocumentContent("[*" . $input . "*]");
190
+                        $this->Log("MODx TV/DV: ".$input);
191
+                        $input = $modx->mergeDocumentContent("[*".$input."*]");
192 192
                         $replace = $this->Filter($input, $modifiers);
193 193
                         break;
194 194
                     // MODx Setting eXtended
195 195
                     case "(":
196
-                        $this->Log("MODx Setting variable: " . $input);
197
-                        $input = $modx->mergeSettingsContent("[(" . $input . ")]");
196
+                        $this->Log("MODx Setting variable: ".$input);
197
+                        $input = $modx->mergeSettingsContent("[(".$input.")]");
198 198
                         $replace = $this->Filter($input, $modifiers);
199 199
                         break;
200 200
                     // MODx Placeholder eXtended
201 201
                     default:
202
-                        $this->Log("MODx / PHx placeholder variable: " . $input);
202
+                        $this->Log("MODx / PHx placeholder variable: ".$input);
203 203
                         // Check if placeholder is set
204 204
                         if (!array_key_exists($input, $this->placeholders) && !array_key_exists($input,
205 205
                                 $modx->placeholders)
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
     {
242 242
         global $modx;
243 243
         $output = $input;
244
-        $this->Log("  |--- Input = '" . $output . "'");
244
+        $this->Log("  |--- Input = '".$output."'");
245 245
         if (preg_match_all('~:([^:=]+)(?:=`(.*?)`(?=:[^:=]+|$))?~s', $modifiers, $matches)) {
246 246
             $modifier_cmd = $matches[1]; // modifier command
247 247
             $modifier_value = $matches[2]; // modifier value
@@ -249,9 +249,9 @@  discard block
 block discarded – undo
249 249
             $condition = array();
250 250
             for ($i = 0; $i < $count; $i++) {
251 251
                 $output = trim($output);
252
-                $this->Log("  |--- Modifier = '" . $modifier_cmd[$i] . "'");
252
+                $this->Log("  |--- Modifier = '".$modifier_cmd[$i]."'");
253 253
                 if ($modifier_value[$i] != '') {
254
-                    $this->Log("  |--- Options = '" . $modifier_value[$i] . "'");
254
+                    $this->Log("  |--- Options = '".$modifier_value[$i]."'");
255 255
                 }
256 256
                 switch ($modifier_cmd[$i]) {
257 257
                     #####  Conditional Modifiers
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
                         break;
393 393
                     case "wordwrap": // default: 70
394 394
                         $wrapat = intval($modifier_value[$i]) ? intval($modifier_value[$i]) : 70;
395
-                        $output = preg_replace_callback("@(\b\w+\b)@",function($m) use($wrapat) {return wordwrap($m[1],$wrapat,' ',1);},$output);
395
+                        $output = preg_replace_callback("@(\b\w+\b)@", function($m) use($wrapat) {return wordwrap($m[1], $wrapat, ' ', 1); },$output);
396 396
                         break;
397 397
                     case "limit": // default: 100
398 398
                         $limit = intval($modifier_value[$i]) ? intval($modifier_value[$i]) : 100;
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
                     case "math":
413 413
                         $filter = preg_replace("~([a-zA-Z\n\r\t\s])~", "", $modifier_value[$i]);
414 414
                         $filter = str_replace("?", $output, $filter);
415
-                        $output = eval("return " . $filter . ";");
415
+                        $output = eval("return ".$filter.";");
416 416
                         break;
417 417
                     case "isnotempty":
418 418
                         if (!empty($output)) {
@@ -439,7 +439,7 @@  discard block
 block discarded – undo
439 439
                         break;
440 440
                     case "value":
441 441
                         if ($i > 0 && $modifier_cmd[$i - 1] == "set") {
442
-                            $modx->SetPlaceholder("phx." . $output, $modifier_value[$i]);
442
+                            $modx->SetPlaceholder("phx.".$output, $modifier_value[$i]);
443 443
                         }
444 444
                         $output = null;
445 445
                         break;
@@ -464,12 +464,12 @@  discard block
 block discarded – undo
464 464
                     default:
465 465
                         $snippet = '';
466 466
                         // modified by Anton Kuzmin (23.06.2010) //
467
-                        $snippetName = 'phx:' . $modifier_cmd[$i];
467
+                        $snippetName = 'phx:'.$modifier_cmd[$i];
468 468
                         if (isset($modx->snippetCache[$snippetName])) {
469 469
                             $snippet = $modx->snippetCache[$snippetName];
470 470
                         } else {
471 471
 // not in cache so let's check the db
472
-                            $sql = "SELECT snippet FROM " . $modx->getFullTableName("site_snippets") . " WHERE " . $modx->getFullTableName("site_snippets") . ".name='" . $modx->db->escape($snippetName) . "';";
472
+                            $sql = "SELECT snippet FROM ".$modx->getFullTableName("site_snippets")." WHERE ".$modx->getFullTableName("site_snippets").".name='".$modx->db->escape($snippetName)."';";
473 473
                             $result = $modx->dbQuery($sql);
474 474
                             if ($modx->recordCount($result) == 1) {
475 475
                                 $row = $modx->fetchRow($result);
@@ -478,14 +478,14 @@  discard block
 block discarded – undo
478 478
                             } else {
479 479
                                 if ($modx->recordCount($result) == 0) {
480 480
 // If snippet not found, look in the modifiers folder
481
-                                    $filename = $modx->config['rb_base_dir'] . 'plugins/phx/modifiers/' . $modifier_cmd[$i] . '.phx.php';
481
+                                    $filename = $modx->config['rb_base_dir'].'plugins/phx/modifiers/'.$modifier_cmd[$i].'.phx.php';
482 482
                                     if (@file_exists($filename)) {
483 483
                                         $file_contents = @file_get_contents($filename);
484
-                                        $file_contents = str_replace('<' . '?php', '', $file_contents);
485
-                                        $file_contents = str_replace('?' . '>', '', $file_contents);
484
+                                        $file_contents = str_replace('<'.'?php', '', $file_contents);
485
+                                        $file_contents = str_replace('?'.'>', '', $file_contents);
486 486
                                         $file_contents = str_replace('<?', '', $file_contents);
487 487
                                         $snippet = $modx->snippetCache[$snippetName] = $file_contents;
488
-                                        $modx->snippetCache[$snippetName . 'Props'] = '';
488
+                                        $modx->snippetCache[$snippetName.'Props'] = '';
489 489
                                         $this->Log("  |--- File ($filename) -> Custom Modifier");
490 490
                                     } else {
491 491
                                         $this->Log("  |--- PHX Error:  {$modifier_cmd[$i]} could not be found");
@@ -501,7 +501,7 @@  discard block
 block discarded – undo
501 501
                             $options = $modifier_value[$i];
502 502
                             $custom = eval($cm);
503 503
                             $msg = ob_get_contents();
504
-                            $output = $msg . $custom;
504
+                            $output = $msg.$custom;
505 505
                             ob_end_clean();
506 506
                         } else {
507 507
                             $output = '';
@@ -509,9 +509,9 @@  discard block
 block discarded – undo
509 509
                         break;
510 510
                 }
511 511
                 if (count($condition)) {
512
-                    $this->Log("  |--- Condition = '" . $condition[count($condition) - 1] . "'");
512
+                    $this->Log("  |--- Condition = '".$condition[count($condition) - 1]."'");
513 513
                 }
514
-                $this->Log("  |--- Output = '" . $output . "'");
514
+                $this->Log("  |--- Output = '".$output."'");
515 515
             }
516 516
         }
517 517
 
@@ -520,7 +520,7 @@  discard block
 block discarded – undo
520 520
 
521 521
     private function runCode($code)
522 522
     {
523
-        return eval("return (" . $code . ");");
523
+        return eval("return (".$code.");");
524 524
     }
525 525
     // Event logging (debug)
526 526
     /**
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
             $console = implode("\n", $this->console);
533 533
             $this->console = array();
534 534
 
535
-            return '<pre style="overflow: auto;">' . $console . '</pre>';
535
+            return '<pre style="overflow: auto;">'.$console.'</pre>';
536 536
         }
537 537
     }
538 538
 
@@ -557,8 +557,8 @@  discard block
 block discarded – undo
557 557
     {
558 558
         if ($this->debug) {
559 559
             $this->debugLog = true;
560
-            $this->console[] = (count($this->console) + 1 - $this->curPass) . " [" . strftime("%H:%M:%S",
561
-                    time()) . "] " . $this->LogClean($string);
560
+            $this->console[] = (count($this->console) + 1 - $this->curPass)." [".strftime("%H:%M:%S",
561
+                    time())."] ".$this->LogClean($string);
562 562
         }
563 563
     }
564 564
 
@@ -570,15 +570,15 @@  discard block
 block discarded – undo
570 570
     {
571 571
         if ($this->debug) {
572 572
             $this->debugLog = true;
573
-            $this->console[] = (count($this->console) + 1 - $this->curPass) . " [" . strftime("%H:%M:%S",
574
-                    time()) . "] " . "  |--- Returns: <div style='margin: 10px;'>" . $this->LogClean($string) . "</div>";
573
+            $this->console[] = (count($this->console) + 1 - $this->curPass)." [".strftime("%H:%M:%S",
574
+                    time())."] "."  |--- Returns: <div style='margin: 10px;'>".$this->LogClean($string)."</div>";
575 575
         }
576 576
     }
577 577
 
578 578
     // Log pass
579 579
     public function LogPass()
580 580
     {
581
-        $this->console[] = "<div style='margin: 2px;margin-top: 5px;border-bottom: 1px solid black;'>Pass " . $this->curPass . "</div>";
581
+        $this->console[] = "<div style='margin: 2px;margin-top: 5px;border-bottom: 1px solid black;'>Pass ".$this->curPass."</div>";
582 582
     }
583 583
 
584 584
     // Log pass
@@ -587,7 +587,7 @@  discard block
 block discarded – undo
587 587
      */
588 588
     public function LogSource($string)
589 589
     {
590
-        $this->console[] = "<div style='margin: 2px;margin-top: 5px;border-bottom: 1px solid black;'>Source:</div>" . $this->LogClean($string);
590
+        $this->console[] = "<div style='margin: 2px;margin-top: 5px;border-bottom: 1px solid black;'>Source:</div>".$this->LogClean($string);
591 591
     }
592 592
 
593 593
 
@@ -639,7 +639,7 @@  discard block
 block discarded – undo
639 639
         if (!array_key_exists($userid, $this->cache["mo"])) {
640 640
             $tbl = $modx->getFullTableName("webgroup_names");
641 641
             $tbl2 = $modx->getFullTableName("web_groups");
642
-            $sql = "SELECT wgn.name FROM $tbl wgn INNER JOIN $tbl2 wg ON wg.webgroup=wgn.id AND wg.webuser='" . $userid . "'";
642
+            $sql = "SELECT wgn.name FROM $tbl wgn INNER JOIN $tbl2 wg ON wg.webgroup=wgn.id AND wg.webuser='".$userid."'";
643 643
             $this->cache["mo"][$userid] = $grpNames = $modx->db->getColumn("name", $sql);
644 644
         } else {
645 645
             $grpNames = $this->cache["mo"][$userid];
@@ -747,7 +747,7 @@  discard block
 block discarded – undo
747 747
     public function ucfirst($str)
748 748
     {
749 749
         if (function_exists('mb_strtoupper') && function_exists('mb_substr') && function_exists('mb_strlen')) {
750
-            return mb_strtoupper(mb_substr($str, 0, 1)) . mb_substr($str, 1, mb_strlen($str));
750
+            return mb_strtoupper(mb_substr($str, 0, 1)).mb_substr($str, 1, mb_strlen($str));
751 751
         }
752 752
 
753 753
         return ucfirst($str);
@@ -760,7 +760,7 @@  discard block
 block discarded – undo
760 760
     public function lcfirst($str)
761 761
     {
762 762
         if (function_exists('mb_strtolower') && function_exists('mb_substr') && function_exists('mb_strlen')) {
763
-            return mb_strtolower(mb_substr($str, 0, 1)) . mb_substr($str, 1, mb_strlen($str));
763
+            return mb_strtolower(mb_substr($str, 0, 1)).mb_substr($str, 1, mb_strlen($str));
764 764
         }
765 765
 
766 766
         return lcfirst($str);
Please login to merge, or discard this patch.
Braces   +119 added lines, -119 removed lines patch added patch discarded remove patch
@@ -15,8 +15,8 @@  discard block
 block discarded – undo
15 15
 /**
16 16
  * Class DLphx
17 17
  */
18
-class DLphx
19
-{
18
+class DLphx
19
+{
20 20
     public $placeholders = array();
21 21
     public $name = 'PHx';
22 22
     public $version = '2.2.0';
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
      * @param int|bool|string $debug
44 44
      * @param int $maxpass
45 45
      */
46
-    public function __construct($debug = false, $maxpass = 50)
47
-    {
46
+    public function __construct($debug = false, $maxpass = 50)
47
+    {
48 48
         global $modx;
49 49
 
50 50
         $this->user["mgrid"] = isset($_SESSION['mgrInternalKey']) ? intval($_SESSION['mgrInternalKey']) : 0;
@@ -56,14 +56,14 @@  discard block
 block discarded – undo
56 56
         $this->maxPasses = ($maxpass != '') ? $maxpass : 50;
57 57
 
58 58
         $modx->setPlaceholder("phx", "&_PHX_INTERNAL_&");
59
-        if (function_exists('mb_internal_encoding')) {
59
+        if (function_exists('mb_internal_encoding')) {
60 60
             mb_internal_encoding($modx->config['modx_charset']);
61 61
         }
62 62
     }
63 63
 
64 64
     // Plugin event hook for MODx
65
-    public function OnParseDocument()
66
-    {
65
+    public function OnParseDocument()
66
+    {
67 67
         global $modx;
68 68
         // Get document output from MODx
69 69
         $template = $modx->documentOutput;
@@ -78,11 +78,11 @@  discard block
 block discarded – undo
78 78
      * @param string $template
79 79
      * @return mixed|string
80 80
      */
81
-    public function Parse($template = '')
82
-    {
81
+    public function Parse($template = '')
82
+    {
83 83
         global $modx;
84 84
         // If we already reached max passes don't get at it again.
85
-        if ($this->curPass == $this->maxPasses) {
85
+        if ($this->curPass == $this->maxPasses) {
86 86
             return $template;
87 87
         }
88 88
         // Set template pre-process hash
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
         $template = $this->ParseValues($template);
94 94
         // clean up unused placeholders that have modifiers attached (MODx can't clean them)
95 95
         preg_match_all('~(?:=`[^`@]*?)(\[\+([^:\+\[\]]+)([^\[\]]*?)\+\])~s', $template, $matches);
96
-        if ($matches[0]) {
96
+        if ($matches[0]) {
97 97
             $template = str_replace($matches[1], '', $template);
98 98
             $this->Log("Cleaning unsolved tags: \n" . implode("\n", $matches[2]));
99 99
         }
@@ -102,11 +102,11 @@  discard block
 block discarded – undo
102 102
         // Set template post-process hash
103 103
         $et = md5($template);
104 104
         // If template has changed, parse it once more...
105
-        if ($st != $et) {
105
+        if ($st != $et) {
106 106
             $template = $this->Parse($template);
107 107
         }
108 108
         // Write an event log if debugging is enabled and there is something to log
109
-        if ($this->debug && $this->debugLog) {
109
+        if ($this->debug && $this->debugLog) {
110 110
             $modx->logEvent($this->curPass, 1, $this->createEventLog(), $this->name . ' ' . $this->version);
111 111
             $this->debugLog = false;
112 112
         }
@@ -120,8 +120,8 @@  discard block
 block discarded – undo
120 120
      * @param string $template
121 121
      * @return mixed|string
122 122
      */
123
-    public function ParseValues($template = '')
124
-    {
123
+    public function ParseValues($template = '')
124
+    {
125 125
         global $modx;
126 126
 
127 127
         $this->curPass = $this->curPass + 1;
@@ -130,12 +130,12 @@  discard block
 block discarded – undo
130 130
         $this->LogPass();
131 131
 
132 132
         // MODX Chunks
133
-        if (preg_match_all('~(?<!(?:then|else)=`){{([^:\+{}]+)([^{}]*?)}}~s', $template, $matches)) {
133
+        if (preg_match_all('~(?<!(?:then|else)=`){{([^:\+{}]+)([^{}]*?)}}~s', $template, $matches)) {
134 134
             $this->Log('MODX Chunks -> Merging all chunk tags');
135 135
             $count = count($matches[0]);
136 136
             $var_search = array();
137 137
             $var_replace = array();
138
-            for ($i = 0; $i < $count; $i++) {
138
+            for ($i = 0; $i < $count; $i++) {
139 139
                 $var_search[] = $matches[0][$i];
140 140
                 $input = $matches[1][$i];
141 141
                 $this->Log('MODX Chunk: ' . $input);
@@ -147,13 +147,13 @@  discard block
 block discarded – undo
147 147
 
148 148
         // MODx Snippets
149 149
         //if ( preg_match_all('~\[(\[|!)([^\[]*?)(!|\])\]~s',$template, $matches)) {
150
-        if (preg_match_all('~(?<!(?:then|else)=`)\[(\[)([^\[]*?)(\])\]~s', $template, $matches)) {
150
+        if (preg_match_all('~(?<!(?:then|else)=`)\[(\[)([^\[]*?)(\])\]~s', $template, $matches)) {
151 151
             $count = count($matches[0]);
152 152
             $var_search = array();
153 153
             $var_replace = array();
154 154
 
155 155
             // for each detected snippet
156
-            for ($i = 0; $i < $count; $i++) {
156
+            for ($i = 0; $i < $count; $i++) {
157 157
                 $snippet = $matches[2][$i]; // snippet call
158 158
                 $this->Log("MODx Snippet -> " . $snippet);
159 159
 
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
         }
170 170
 
171 171
         // PHx / MODx Tags
172
-        if (preg_match_all('~\[(\+|\*|\()([^:\+\[\]]+)([^\[\]]*?)(\1|\))\]~s', $template, $matches)) {
172
+        if (preg_match_all('~\[(\+|\*|\()([^:\+\[\]]+)([^\[\]]*?)(\1|\))\]~s', $template, $matches)) {
173 173
 
174 174
             //$matches[0] // Complete string that's need to be replaced
175 175
             //$matches[1] // Type
@@ -180,11 +180,11 @@  discard block
 block discarded – undo
180 180
             $count = count($matches[0]);
181 181
             $var_search = array();
182 182
             $var_replace = array();
183
-            for ($i = 0; $i < $count; $i++) {
183
+            for ($i = 0; $i < $count; $i++) {
184 184
                 $input = $matches[2][$i];
185 185
                 $modifiers = $matches[3][$i];
186 186
                 $var_search[] = $matches[0][$i];
187
-                switch ($matches[1][$i]) {
187
+                switch ($matches[1][$i]) {
188 188
                     // Document / Template Variable eXtended
189 189
                     case "*":
190 190
                         $this->Log("MODx TV/DV: " . $input);
@@ -203,10 +203,10 @@  discard block
 block discarded – undo
203 203
                         // Check if placeholder is set
204 204
                         if (!array_key_exists($input, $this->placeholders) && !array_key_exists($input,
205 205
                                 $modx->placeholders)
206
-                        ) {
206
+                        ) {
207 207
                             // not set so try again later.
208 208
                             $input = '';
209
-                        } else {
209
+                        } else {
210 210
                             // is set, get value and run filter
211 211
                             $input = $this->getPHxVariable($input);
212 212
                         }
@@ -220,11 +220,11 @@  discard block
 block discarded – undo
220 220
         $et = md5($template); // Post-process template hash
221 221
 
222 222
         // Log an event if this was the maximum pass
223
-        if ($this->curPass == $this->maxPasses) {
223
+        if ($this->curPass == $this->maxPasses) {
224 224
             $this->Log("Max passes reached. infinite loop protection so exiting.\n If you need the extra passes set the max passes to the highest count of nested tags in your template.");
225 225
         }
226 226
         // If this pass is not at maximum passes and the template hash is not the same, get at it again.
227
-        if (($this->curPass < $this->maxPasses) && ($st != $et)) {
227
+        if (($this->curPass < $this->maxPasses) && ($st != $et)) {
228 228
             $template = $this->ParseValues($template);
229 229
         }
230 230
 
@@ -237,23 +237,23 @@  discard block
 block discarded – undo
237 237
      * @param $modifiers
238 238
      * @return mixed|null|string
239 239
      */
240
-    public function Filter($input, $modifiers)
241
-    {
240
+    public function Filter($input, $modifiers)
241
+    {
242 242
         global $modx;
243 243
         $output = $input;
244 244
         $this->Log("  |--- Input = '" . $output . "'");
245
-        if (preg_match_all('~:([^:=]+)(?:=`(.*?)`(?=:[^:=]+|$))?~s', $modifiers, $matches)) {
245
+        if (preg_match_all('~:([^:=]+)(?:=`(.*?)`(?=:[^:=]+|$))?~s', $modifiers, $matches)) {
246 246
             $modifier_cmd = $matches[1]; // modifier command
247 247
             $modifier_value = $matches[2]; // modifier value
248 248
             $count = count($modifier_cmd);
249 249
             $condition = array();
250
-            for ($i = 0; $i < $count; $i++) {
250
+            for ($i = 0; $i < $count; $i++) {
251 251
                 $output = trim($output);
252 252
                 $this->Log("  |--- Modifier = '" . $modifier_cmd[$i] . "'");
253
-                if ($modifier_value[$i] != '') {
253
+                if ($modifier_value[$i] != '') {
254 254
                     $this->Log("  |--- Options = '" . $modifier_value[$i] . "'");
255 255
                 }
256
-                switch ($modifier_cmd[$i]) {
256
+                switch ($modifier_cmd[$i]) {
257 257
                     #####  Conditional Modifiers
258 258
                     case "input":
259 259
                     case "if":
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
                     case "ir":
296 296
                     case "memberof":
297 297
                     case "mo": // Is Member Of  (same as inrole but this one can be stringed as a conditional)
298
-                        if ($output == "&_PHX_INTERNAL_&") {
298
+                        if ($output == "&_PHX_INTERNAL_&") {
299 299
                             $output = $this->user["id"];
300 300
                         }
301 301
                         $grps = ($this->strlen($modifier_value[$i]) > 0) ? explode(",", $modifier_value[$i]) : array();
@@ -310,23 +310,23 @@  discard block
 block discarded – undo
310 310
                     case "show":
311 311
                         $conditional = implode(' ', $condition);
312 312
                         $isvalid = intval($this->runCode($conditional));
313
-                        if (!$isvalid) {
313
+                        if (!$isvalid) {
314 314
                             $output = null;
315 315
                         }
316 316
                         break;
317 317
                     case "then":
318 318
                         $conditional = implode(' ', $condition);
319 319
                         $isvalid = intval($this->runCode($conditional));
320
-                        if ($isvalid) {
320
+                        if ($isvalid) {
321 321
                             $output = $modifier_value[$i];
322
-                        } else {
322
+                        } else {
323 323
                             $output = null;
324 324
                         }
325 325
                         break;
326 326
                     case "else":
327 327
                         $conditional = implode(' ', $condition);
328 328
                         $isvalid = intval($this->runCode($condition));
329
-                        if (!$isvalid) {
329
+                        if (!$isvalid) {
330 330
                             $output = $modifier_value[$i];
331 331
                         }
332 332
                         break;
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
                         $raw = explode("&", $modifier_value[$i]);
335 335
                         $map = array();
336 336
                         $count = count($raw);
337
-                        for ($m = 0; $m < $count; $m++) {
337
+                        for ($m = 0; $m < $count; $m++) {
338 338
                             $mi = explode("=", $raw[$m]);
339 339
                             $map[$mi[0]] = $mi[1];
340 340
                         }
@@ -415,13 +415,13 @@  discard block
 block discarded – undo
415 415
                         $output = eval("return " . $filter . ";");
416 416
                         break;
417 417
                     case "isnotempty":
418
-                        if (!empty($output)) {
418
+                        if (!empty($output)) {
419 419
                             $output = $modifier_value[$i];
420 420
                         }
421 421
                         break;
422 422
                     case "isempty":
423 423
                     case "ifempty":
424
-                        if (empty($output)) {
424
+                        if (empty($output)) {
425 425
                             $output = $modifier_value[$i];
426 426
                         }
427 427
                         break;
@@ -433,12 +433,12 @@  discard block
 block discarded – undo
433 433
                         break;
434 434
                     case "set":
435 435
                         $c = $i + 1;
436
-                        if ($count > $c && $modifier_cmd[$c] == "value") {
436
+                        if ($count > $c && $modifier_cmd[$c] == "value") {
437 437
                             $output = preg_replace("~([^a-zA-Z0-9])~", "", $modifier_value[$i]);
438 438
                         }
439 439
                         break;
440 440
                     case "value":
441
-                        if ($i > 0 && $modifier_cmd[$i - 1] == "set") {
441
+                        if ($i > 0 && $modifier_cmd[$i - 1] == "set") {
442 442
                             $modx->SetPlaceholder("phx." . $output, $modifier_value[$i]);
443 443
                         }
444 444
                         $output = null;
@@ -447,13 +447,13 @@  discard block
 block discarded – undo
447 447
                         $output = md5($output);
448 448
                         break;
449 449
                     case "userinfo":
450
-                        if ($output == "&_PHX_INTERNAL_&") {
450
+                        if ($output == "&_PHX_INTERNAL_&") {
451 451
                             $output = $this->user["id"];
452 452
                         }
453 453
                         $output = $this->ModUser($output, $modifier_value[$i]);
454 454
                         break;
455 455
                     case "inrole": // deprecated
456
-                        if ($output == "&_PHX_INTERNAL_&") {
456
+                        if ($output == "&_PHX_INTERNAL_&") {
457 457
                             $output = $this->user["id"];
458 458
                         }
459 459
                         $grps = ($this->strlen($modifier_value[$i]) > 0) ? explode(",", $modifier_value[$i]) : array();
@@ -465,21 +465,21 @@  discard block
 block discarded – undo
465 465
                         $snippet = '';
466 466
                         // modified by Anton Kuzmin (23.06.2010) //
467 467
                         $snippetName = 'phx:' . $modifier_cmd[$i];
468
-                        if (isset($modx->snippetCache[$snippetName])) {
468
+                        if (isset($modx->snippetCache[$snippetName])) {
469 469
                             $snippet = $modx->snippetCache[$snippetName];
470
-                        } else {
470
+                        } else {
471 471
 // not in cache so let's check the db
472 472
                             $sql = "SELECT snippet FROM " . $modx->getFullTableName("site_snippets") . " WHERE " . $modx->getFullTableName("site_snippets") . ".name='" . $modx->db->escape($snippetName) . "';";
473 473
                             $result = $modx->dbQuery($sql);
474
-                            if ($modx->recordCount($result) == 1) {
474
+                            if ($modx->recordCount($result) == 1) {
475 475
                                 $row = $modx->fetchRow($result);
476 476
                                 $snippet = $modx->snippetCache[$row['name']] = $row['snippet'];
477 477
                                 $this->Log("  |--- DB -> Custom Modifier");
478
-                            } else {
479
-                                if ($modx->recordCount($result) == 0) {
478
+                            } else {
479
+                                if ($modx->recordCount($result) == 0) {
480 480
 // If snippet not found, look in the modifiers folder
481 481
                                     $filename = $modx->config['rb_base_dir'] . 'plugins/phx/modifiers/' . $modifier_cmd[$i] . '.phx.php';
482
-                                    if (@file_exists($filename)) {
482
+                                    if (@file_exists($filename)) {
483 483
                                         $file_contents = @file_get_contents($filename);
484 484
                                         $file_contents = str_replace('<' . '?php', '', $file_contents);
485 485
                                         $file_contents = str_replace('?' . '>', '', $file_contents);
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
                                         $snippet = $modx->snippetCache[$snippetName] = $file_contents;
488 488
                                         $modx->snippetCache[$snippetName . 'Props'] = '';
489 489
                                         $this->Log("  |--- File ($filename) -> Custom Modifier");
490
-                                    } else {
490
+                                    } else {
491 491
                                         $this->Log("  |--- PHX Error:  {$modifier_cmd[$i]} could not be found");
492 492
                                     }
493 493
                                 }
@@ -496,19 +496,19 @@  discard block
 block discarded – undo
496 496
                         $cm = $snippet;
497 497
                         // end //
498 498
 
499
-                        if (!empty($cm)) {
499
+                        if (!empty($cm)) {
500 500
                             ob_start();
501 501
                             $options = $modifier_value[$i];
502 502
                             $custom = eval($cm);
503 503
                             $msg = ob_get_contents();
504 504
                             $output = $msg . $custom;
505 505
                             ob_end_clean();
506
-                        } else {
506
+                        } else {
507 507
                             $output = '';
508 508
                         }
509 509
                         break;
510 510
                 }
511
-                if (count($condition)) {
511
+                if (count($condition)) {
512 512
                     $this->Log("  |--- Condition = '" . $condition[count($condition) - 1] . "'");
513 513
                 }
514 514
                 $this->Log("  |--- Output = '" . $output . "'");
@@ -518,17 +518,17 @@  discard block
 block discarded – undo
518 518
         return $output;
519 519
     }
520 520
 
521
-    private function runCode($code)
522
-    {
521
+    private function runCode($code)
522
+    {
523 523
         return eval("return (" . $code . ");");
524 524
     }
525 525
     // Event logging (debug)
526 526
     /**
527 527
      * @return string
528 528
      */
529
-    public function createEventLog()
530
-    {
531
-        if (!empty($this->console)) {
529
+    public function createEventLog()
530
+    {
531
+        if (!empty($this->console)) {
532 532
             $console = implode("\n", $this->console);
533 533
             $this->console = array();
534 534
 
@@ -541,8 +541,8 @@  discard block
 block discarded – undo
541 541
      * @param $string
542 542
      * @return array|mixed|string
543 543
      */
544
-    public function LogClean($string)
545
-    {
544
+    public function LogClean($string)
545
+    {
546 546
         $string = preg_replace("/&amp;(#[0-9]+|[a-z]+);/i", "&$1;", $string);
547 547
         $string = APIHelpers::sanitarTag($string);
548 548
 
@@ -553,9 +553,9 @@  discard block
 block discarded – undo
553 553
     /**
554 554
      * @param $string
555 555
      */
556
-    public function Log($string)
557
-    {
558
-        if ($this->debug) {
556
+    public function Log($string)
557
+    {
558
+        if ($this->debug) {
559 559
             $this->debugLog = true;
560 560
             $this->console[] = (count($this->console) + 1 - $this->curPass) . " [" . strftime("%H:%M:%S",
561 561
                     time()) . "] " . $this->LogClean($string);
@@ -566,9 +566,9 @@  discard block
 block discarded – undo
566 566
     /**
567 567
      * @param $string
568 568
      */
569
-    public function LogSnippet($string)
570
-    {
571
-        if ($this->debug) {
569
+    public function LogSnippet($string)
570
+    {
571
+        if ($this->debug) {
572 572
             $this->debugLog = true;
573 573
             $this->console[] = (count($this->console) + 1 - $this->curPass) . " [" . strftime("%H:%M:%S",
574 574
                     time()) . "] " . "  |--- Returns: <div style='margin: 10px;'>" . $this->LogClean($string) . "</div>";
@@ -576,8 +576,8 @@  discard block
 block discarded – undo
576 576
     }
577 577
 
578 578
     // Log pass
579
-    public function LogPass()
580
-    {
579
+    public function LogPass()
580
+    {
581 581
         $this->console[] = "<div style='margin: 2px;margin-top: 5px;border-bottom: 1px solid black;'>Pass " . $this->curPass . "</div>";
582 582
     }
583 583
 
@@ -585,8 +585,8 @@  discard block
 block discarded – undo
585 585
     /**
586 586
      * @param $string
587 587
      */
588
-    public function LogSource($string)
589
-    {
588
+    public function LogSource($string)
589
+    {
590 590
         $this->console[] = "<div style='margin: 2px;margin-top: 5px;border-bottom: 1px solid black;'>Source:</div>" . $this->LogClean($string);
591 591
     }
592 592
 
@@ -598,17 +598,17 @@  discard block
 block discarded – undo
598 598
      * @param $field
599 599
      * @return mixed
600 600
      */
601
-    public function ModUser($userid, $field)
602
-    {
601
+    public function ModUser($userid, $field)
602
+    {
603 603
         global $modx;
604
-        if (!array_key_exists($userid, $this->cache["ui"])) {
605
-            if (intval($userid) < 0) {
604
+        if (!array_key_exists($userid, $this->cache["ui"])) {
605
+            if (intval($userid) < 0) {
606 606
                 $user = $modx->getWebUserInfo(-($userid));
607
-            } else {
607
+            } else {
608 608
                 $user = $modx->getUserInfo($userid);
609 609
             }
610 610
             $this->cache["ui"][$userid] = $user;
611
-        } else {
611
+        } else {
612 612
             $user = $this->cache["ui"][$userid];
613 613
         }
614 614
 
@@ -621,32 +621,32 @@  discard block
 block discarded – undo
621 621
      * @param array $groupNames
622 622
      * @return bool
623 623
      */
624
-    public function isMemberOfWebGroupByUserId($userid = 0, $groupNames = array())
625
-    {
624
+    public function isMemberOfWebGroupByUserId($userid = 0, $groupNames = array())
625
+    {
626 626
         global $modx;
627 627
 
628 628
         // if $groupNames is not an array return false
629
-        if (!is_array($groupNames)) {
629
+        if (!is_array($groupNames)) {
630 630
             return false;
631 631
         }
632 632
 
633 633
         // if the user id is a negative number make it positive
634
-        if (intval($userid) < 0) {
634
+        if (intval($userid) < 0) {
635 635
             $userid = -($userid);
636 636
         }
637 637
 
638 638
         // Creates an array with all webgroups the user id is in
639
-        if (!array_key_exists($userid, $this->cache["mo"])) {
639
+        if (!array_key_exists($userid, $this->cache["mo"])) {
640 640
             $tbl = $modx->getFullTableName("webgroup_names");
641 641
             $tbl2 = $modx->getFullTableName("web_groups");
642 642
             $sql = "SELECT wgn.name FROM $tbl wgn INNER JOIN $tbl2 wg ON wg.webgroup=wgn.id AND wg.webuser='" . $userid . "'";
643 643
             $this->cache["mo"][$userid] = $grpNames = $modx->db->getColumn("name", $sql);
644
-        } else {
644
+        } else {
645 645
             $grpNames = $this->cache["mo"][$userid];
646 646
         }
647 647
         // Check if a supplied group matches a webgroup from the array we just created
648
-        foreach ($groupNames as $k => $v) {
649
-            if (in_array(trim($v), $grpNames)) {
648
+        foreach ($groupNames as $k => $v) {
649
+            if (in_array(trim($v), $grpNames)) {
650 650
                 return true;
651 651
             }
652 652
         }
@@ -660,14 +660,14 @@  discard block
 block discarded – undo
660 660
      * @param $name
661 661
      * @return mixed|string
662 662
      */
663
-    public function getPHxVariable($name)
664
-    {
663
+    public function getPHxVariable($name)
664
+    {
665 665
         global $modx;
666 666
         // Check if this variable is created by PHx
667
-        if (array_key_exists($name, $this->placeholders)) {
667
+        if (array_key_exists($name, $this->placeholders)) {
668 668
             // Return the value from PHx
669 669
             return $this->placeholders[$name];
670
-        } else {
670
+        } else {
671 671
             // Return the value from MODx
672 672
             return $modx->getPlaceholder($name);
673 673
         }
@@ -678,9 +678,9 @@  discard block
 block discarded – undo
678 678
      * @param $name
679 679
      * @param $value
680 680
      */
681
-    public function setPHxVariable($name, $value)
682
-    {
683
-        if ($name != "phx") {
681
+    public function setPHxVariable($name, $value)
682
+    {
683
+        if ($name != "phx") {
684 684
             $this->placeholders[$name] = $value;
685 685
         }
686 686
     }
@@ -692,9 +692,9 @@  discard block
 block discarded – undo
692 692
      * @param null $l
693 693
      * @return string
694 694
      */
695
-    public function substr($str, $s, $l = null)
696
-    {
697
-        if (function_exists('mb_substr')) {
695
+    public function substr($str, $s, $l = null)
696
+    {
697
+        if (function_exists('mb_substr')) {
698 698
             return mb_substr($str, $s, $l);
699 699
         }
700 700
 
@@ -705,9 +705,9 @@  discard block
 block discarded – undo
705 705
      * @param $str
706 706
      * @return int
707 707
      */
708
-    public function strlen($str)
709
-    {
710
-        if (function_exists('mb_strlen')) {
708
+    public function strlen($str)
709
+    {
710
+        if (function_exists('mb_strlen')) {
711 711
             return mb_strlen($str);
712 712
         }
713 713
 
@@ -718,9 +718,9 @@  discard block
 block discarded – undo
718 718
      * @param $str
719 719
      * @return string
720 720
      */
721
-    public function strtolower($str)
722
-    {
723
-        if (function_exists('mb_strtolower')) {
721
+    public function strtolower($str)
722
+    {
723
+        if (function_exists('mb_strtolower')) {
724 724
             return mb_strtolower($str);
725 725
         }
726 726
 
@@ -731,9 +731,9 @@  discard block
 block discarded – undo
731 731
      * @param $str
732 732
      * @return string
733 733
      */
734
-    public function strtoupper($str)
735
-    {
736
-        if (function_exists('mb_strtoupper')) {
734
+    public function strtoupper($str)
735
+    {
736
+        if (function_exists('mb_strtoupper')) {
737 737
             return mb_strtoupper($str);
738 738
         }
739 739
 
@@ -744,9 +744,9 @@  discard block
 block discarded – undo
744 744
      * @param $str
745 745
      * @return string
746 746
      */
747
-    public function ucfirst($str)
748
-    {
749
-        if (function_exists('mb_strtoupper') && function_exists('mb_substr') && function_exists('mb_strlen')) {
747
+    public function ucfirst($str)
748
+    {
749
+        if (function_exists('mb_strtoupper') && function_exists('mb_substr') && function_exists('mb_strlen')) {
750 750
             return mb_strtoupper(mb_substr($str, 0, 1)) . mb_substr($str, 1, mb_strlen($str));
751 751
         }
752 752
 
@@ -757,9 +757,9 @@  discard block
 block discarded – undo
757 757
      * @param $str
758 758
      * @return string
759 759
      */
760
-    public function lcfirst($str)
761
-    {
762
-        if (function_exists('mb_strtolower') && function_exists('mb_substr') && function_exists('mb_strlen')) {
760
+    public function lcfirst($str)
761
+    {
762
+        if (function_exists('mb_strtolower') && function_exists('mb_substr') && function_exists('mb_strlen')) {
763 763
             return mb_strtolower(mb_substr($str, 0, 1)) . mb_substr($str, 1, mb_strlen($str));
764 764
         }
765 765
 
@@ -770,9 +770,9 @@  discard block
 block discarded – undo
770 770
      * @param $str
771 771
      * @return string
772 772
      */
773
-    public function ucwords($str)
774
-    {
775
-        if (function_exists('mb_convert_case')) {
773
+    public function ucwords($str)
774
+    {
775
+        if (function_exists('mb_convert_case')) {
776 776
             return mb_convert_case($str, MB_CASE_TITLE);
777 777
         }
778 778
 
@@ -783,8 +783,8 @@  discard block
 block discarded – undo
783 783
      * @param $str
784 784
      * @return string
785 785
      */
786
-    public function strrev($str)
787
-    {
786
+    public function strrev($str)
787
+    {
788 788
         preg_match_all('/./us', $str, $ar);
789 789
 
790 790
         return implode(array_reverse($ar[0]));
@@ -794,8 +794,8 @@  discard block
 block discarded – undo
794 794
      * @param $str
795 795
      * @return string
796 796
      */
797
-    public function str_shuffle($str)
798
-    {
797
+    public function str_shuffle($str)
798
+    {
799 799
         preg_match_all('/./us', $str, $ar);
800 800
         shuffle($ar[0]);
801 801
 
@@ -806,8 +806,8 @@  discard block
 block discarded – undo
806 806
      * @param $str
807 807
      * @return int
808 808
      */
809
-    public function str_word_count($str)
810
-    {
809
+    public function str_word_count($str)
810
+    {
811 811
         return count(preg_split('~[^\p{L}\p{N}\']+~u', $str));
812 812
     }
813 813
 }
Please login to merge, or discard this patch.
assets/snippets/DocLister/core/extender/cache.extender.inc 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -18,10 +18,10 @@  discard block
 block discarded – undo
18 18
      */
19 19
     protected function run()
20 20
     {
21
-        $result = (bool)$this->getCFGDef('cache', 1) && isset($this->modx->cache) && ($this->modx->cache instanceof Cache);
21
+        $result = (bool) $this->getCFGDef('cache', 1) && isset($this->modx->cache) && ($this->modx->cache instanceof Cache);
22 22
         $this->enabled = $result;
23 23
         if ($result) {
24
-            $this->setCacheLifetime((int)$this->getCFGDef('cacheLifetime', 0));
24
+            $this->setCacheLifetime((int) $this->getCFGDef('cacheLifetime', 0));
25 25
             $this->setCacheKey();
26 26
         }
27 27
         return $result;
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
     {
38 38
         $out = false;
39 39
         if ($this->enabled) {
40
-            $key = $this->getCacheKey() . '_' . $postfix;
40
+            $key = $this->getCacheKey().'_'.$postfix;
41 41
             $lifetime = $this->getCacheLifetime();
42 42
             $out = $this->modx->cache->save($key, $data, $lifetime);
43 43
         }
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
     {
54 54
         $out = false;
55 55
         if ($this->enabled) {
56
-            $key = $this->getCacheKey() . '_' . $postfix;
56
+            $key = $this->getCacheKey().'_'.$postfix;
57 57
             $out = $this->modx->cache->fetch($key);
58 58
         }
59 59
 
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
      */
80 80
     public function setCacheLifetime($time = 0)
81 81
     {
82
-        $time = (int)$time;
82
+        $time = (int) $time;
83 83
         $this->lifetime = $time;
84 84
 
85 85
         return $this;
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
         } else {
99 99
             $config = $this->DocLister->config->getConfig();
100 100
             $key = md5(json_encode($config));
101
-            $strategy = $this->getCFGDef('cacheStrategy','');
101
+            $strategy = $this->getCFGDef('cacheStrategy', '');
102 102
             switch ($strategy) {
103 103
                 case 'user':
104 104
                     $uid = $this->modx->getLoginUserID('web');
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
                 case 'usergroup':
108 108
                     $uid = $this->modx->getLoginUserID('web');
109 109
                     if ($uid && !empty($_SESSION['webUserGroupNames'])) {
110
-                        $key .= '_webgroups_' . md5(implode(',', $_SESSION['webUserGroupNames']));
110
+                        $key .= '_webgroups_'.md5(implode(',', $_SESSION['webUserGroupNames']));
111 111
                     }
112 112
                     break;
113 113
             }
Please login to merge, or discard this patch.
assets/snippets/DocLister/core/extender/tv.extender.inc 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
         $tvPrefix = $this->_TVprefix;
126 126
 
127 127
         while ($item = $this->modx->db->getRow($rs)) {
128
-            $out[$item['contentid']][$tvPrefix . $tv[$item['tmplvarid']]] = $item['value'];
128
+            $out[$item['contentid']][$tvPrefix.$tv[$item['tmplvarid']]] = $item['value'];
129 129
         }
130 130
         $tmp = explode(",", $this->DocLister->sanitarIn($IDs, ',', false));
131 131
         foreach ($tmp as $item) {
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
                 $out = array_unique($tmp);
178 178
                 $tmp = array();
179 179
                 foreach ($out as $item) {
180
-                    $tmp[] = $this->_TVprefix . $item;
180
+                    $tmp[] = $this->_TVprefix.$item;
181 181
                 }
182 182
             }
183 183
         } else {
@@ -196,8 +196,8 @@  discard block
 block discarded – undo
196 196
      */
197 197
     public function renderTV($iddoc, $tvname, $tvval, $param)
198 198
     {
199
-        include_once MODX_MANAGER_PATH . "includes/tmplvars.format.inc.php";
200
-        include_once MODX_MANAGER_PATH . "includes/tmplvars.commands.inc.php";
199
+        include_once MODX_MANAGER_PATH."includes/tmplvars.format.inc.php";
200
+        include_once MODX_MANAGER_PATH."includes/tmplvars.commands.inc.php";
201 201
 
202 202
         return getTVDisplayFormat($tvname, $tvval, $param['display'], $param['display_params'], $param['type'], $iddoc,
203 203
             '');
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
         $out = array();
234 234
         foreach ($tvId as $id) {
235 235
             $name = $tvs[$id];
236
-            $out[$this->_TVprefix . $name] = $this->modx->_TVnames[$name]['default'];
236
+            $out[$this->_TVprefix.$name] = $this->modx->_TVnames[$name]['default'];
237 237
         }
238 238
 
239 239
         return $out;
@@ -272,20 +272,20 @@  discard block
 block discarded – undo
272 272
                 $item = explode(" ", trim($item), 2);
273 273
                 if (isset($TVnames[$item[0]])) {
274 274
                     $exists = $this->DocLister->checkTableAlias($item[0], $this->tvValuesTable());
275
-                    $prefix = 'dltv_' . $item[0] . '_' . ($i + 1);
275
+                    $prefix = 'dltv_'.$item[0].'_'.($i + 1);
276 276
                     $prefix = $this->storeTable ? $this->DocLister->TableAlias($item[0], $this->tvValuesTable(),
277 277
                         $prefix) : $prefix;
278 278
                     if (!$exists) {
279
-                        $table .= " LEFT JOIN " . $this->DocLister->getTable($this->tvValuesTable(), $prefix) . "
280
-                        on `" . $prefix . "`.`contentid`=`c`.`id` AND `" . $prefix . "`.`tmplvarid`=" . $TVnames[$item[0]];
279
+                        $table .= " LEFT JOIN ".$this->DocLister->getTable($this->tvValuesTable(), $prefix)."
280
+                        on `" . $prefix."`.`contentid`=`c`.`id` AND `".$prefix."`.`tmplvarid`=".$TVnames[$item[0]];
281 281
                     }
282 282
                     if (in_array($item[0], $withDefault)) {
283 283
                         $exists = $this->DocLister->checkTableAlias($item[0], "site_tmplvars");
284 284
                         $dPrefix = $this->storeTable ? $this->DocLister->TableAlias($item[0], "site_tmplvars",
285
-                            'd_' . $prefix) : 'd_' . $prefix;
285
+                            'd_'.$prefix) : 'd_'.$prefix;
286 286
                         if (!$exists) {
287
-                            $table .= " LEFT JOIN " . $this->DocLister->getTable("site_tmplvars",
288
-                                    $dPrefix) . " on `" . $dPrefix . "`.`id` = " . $TVnames[$item[0]];
287
+                            $table .= " LEFT JOIN ".$this->DocLister->getTable("site_tmplvars",
288
+                                    $dPrefix)." on `".$dPrefix."`.`id` = ".$TVnames[$item[0]];
289 289
                         }
290 290
                         $field = "IFNULL(`{$prefix}`.`value`, `{$dPrefix}`.`default_text`)";
291 291
                     } else {
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
                 }
296 296
                 $item = implode(" ", $item);
297 297
             }
298
-            $sort = "ORDER BY " . implode(",", $matches);
298
+            $sort = "ORDER BY ".implode(",", $matches);
299 299
         }
300 300
 
301 301
         return array($table, $sort);
Please login to merge, or discard this patch.
Braces   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -13,8 +13,8 @@  discard block
 block discarded – undo
13 13
  * Обработка TV параметров перед выводом
14 14
  *
15 15
  */
16
-class tv_DL_Extender extends extDocLister
17
-{
16
+class tv_DL_Extender extends extDocLister
17
+{
18 18
     /**
19 19
      * @var mixed|string
20 20
      */
@@ -37,10 +37,10 @@  discard block
 block discarded – undo
37 37
      * @param DocLister $DocLister
38 38
      * @param $name
39 39
      */
40
-    public function __construct($DocLister, $name)
41
-    {
40
+    public function __construct($DocLister, $name)
41
+    {
42 42
         parent::__construct($DocLister, $name);
43
-        if (!isset($this->modx->_TVnames)) {
43
+        if (!isset($this->modx->_TVnames)) {
44 44
             $this->modx->_TVnames = array();
45 45
         }
46 46
         $this->tvValuesTable = $this->DocLister->getCFGDef('tvValuesTable', $this->tvValuesTable());
@@ -51,26 +51,26 @@  discard block
 block discarded – undo
51 51
     /**
52 52
      * @return bool
53 53
      */
54
-    protected function run()
55
-    {
54
+    protected function run()
55
+    {
56 56
         return true;
57 57
     }
58 58
 
59 59
     /**
60 60
      * @return mixed|string
61 61
      */
62
-    public function tvValuesTable()
63
-    {
62
+    public function tvValuesTable()
63
+    {
64 64
         return $this->tvValuesTable;
65 65
     }
66 66
 
67 67
     /**
68 68
      * @return mixed
69 69
      */
70
-    public function getTVnames()
71
-    {
70
+    public function getTVnames()
71
+    {
72 72
         $out = array();
73
-        foreach ($this->modx->_TVnames as $name => $tv) {
73
+        foreach ($this->modx->_TVnames as $name => $tv) {
74 74
             $out[$name] = $tv['id'];
75 75
         }
76 76
 
@@ -81,16 +81,16 @@  discard block
 block discarded – undo
81 81
      * @param bool $reload
82 82
      * @return mixed
83 83
      */
84
-    public function getAllTV_Name($reload = false)
85
-    {
86
-        if (empty($this->modx->_TVnames) || $reload) {
84
+    public function getAllTV_Name($reload = false)
85
+    {
86
+        if (empty($this->modx->_TVnames) || $reload) {
87 87
             $this->modx->_TVnames = $this->loadFromCache('_TVnames');
88
-            if ($this->modx->_TVnames === false) {
88
+            if ($this->modx->_TVnames === false) {
89 89
                 $this->modx->_TVnames = array();
90 90
                 $from = $this->DocLister->getTable('site_tmplvars');
91 91
                 $rs = $this->DocLister->dbQuery("SELECT `id`, `name`, `default_text`, `type` FROM {$from}");
92 92
 
93
-                while ($item = $this->modx->db->getRow($rs)) {
93
+                while ($item = $this->modx->db->getRow($rs)) {
94 94
                     $this->modx->_TVnames[$item['name']] = array(
95 95
                         "id"   => $item['id'],
96 96
                         "type" => $item['type'],
@@ -109,11 +109,11 @@  discard block
 block discarded – undo
109 109
      * @param $tvlist
110 110
      * @return array
111 111
      */
112
-    public function getTVList($IDs, $tvlist)
113
-    {
112
+    public function getTVList($IDs, $tvlist)
113
+    {
114 114
         $out = array();
115 115
         $tv = $this->getTVid($tvlist);
116
-        if (empty($tv)) {
116
+        if (empty($tv)) {
117 117
             return $out;
118 118
         }
119 119
         $tvId = array_keys($tv);
@@ -124,24 +124,24 @@  discard block
 block discarded – undo
124 124
         $rs = $this->DocLister->dbQuery("SELECT tmplvarid,value,contentid FROM {$tbl_site_tmplvar_contentvalues} WHERE {$where}");
125 125
         $tvPrefix = $this->_TVprefix;
126 126
 
127
-        while ($item = $this->modx->db->getRow($rs)) {
127
+        while ($item = $this->modx->db->getRow($rs)) {
128 128
             $out[$item['contentid']][$tvPrefix . $tv[$item['tmplvarid']]] = $item['value'];
129 129
         }
130 130
         $tmp = explode(",", $this->DocLister->sanitarIn($IDs, ',', false));
131
-        foreach ($tmp as $item) {
132
-            if (!isset($out[$item])) {
131
+        foreach ($tmp as $item) {
132
+            if (!isset($out[$item])) {
133 133
                 $out[$item] = array();
134 134
             };
135 135
         }
136 136
         $renderTV = $this->getListRenderTV();
137 137
         $tvDef = $this->loadTVDefault($tvId);
138 138
         $TVkeys = array_keys($tvDef);
139
-        foreach ($out as $itemid => $item) {
140
-            foreach ($TVkeys as $name) {
141
-                if (!isset($out[$itemid][$name])) {
139
+        foreach ($out as $itemid => $item) {
140
+            foreach ($TVkeys as $name) {
141
+                if (!isset($out[$itemid][$name])) {
142 142
                     $out[$itemid][$name] = $tvDef[$name];
143 143
                 }
144
-                if (in_array($name, $renderTV) || $renderTV == array("*")) {
144
+                if (in_array($name, $renderTV) || $renderTV == array("*")) {
145 145
                     $out[$itemid][$name] = $this->renderTV($itemid, $name, $out[$itemid][$name], $tvDef[$name]);
146 146
                 }
147 147
             }
@@ -153,10 +153,10 @@  discard block
 block discarded – undo
153 153
     /**
154 154
      * @return mixed|string
155 155
      */
156
-    public function getTVprefix()
157
-    {
156
+    public function getTVprefix()
157
+    {
158 158
         $tvPrefix = $this->DocLister->getCFGDef('tvPrefix', 'tv');
159
-        if (!empty($tvPrefix)) {
159
+        if (!empty($tvPrefix)) {
160 160
             $tvPrefix .= '.';
161 161
         }
162 162
 
@@ -166,21 +166,21 @@  discard block
 block discarded – undo
166 166
     /**
167 167
      * @return array|mixed
168 168
      */
169
-    public function getListRenderTV()
170
-    {
169
+    public function getListRenderTV()
170
+    {
171 171
         $tmp = $this->DocLister->getCFGDef('renderTV', '');
172
-        if ($tmp != '' && $tmp != '*') {
172
+        if ($tmp != '' && $tmp != '*') {
173 173
             $tmp = explode(",", $tmp);
174
-            if (in_array("*", $tmp)) {
174
+            if (in_array("*", $tmp)) {
175 175
                 $tmp = array("*");
176
-            } else {
176
+            } else {
177 177
                 $out = array_unique($tmp);
178 178
                 $tmp = array();
179
-                foreach ($out as $item) {
179
+                foreach ($out as $item) {
180 180
                     $tmp[] = $this->_TVprefix . $item;
181 181
                 }
182 182
             }
183
-        } else {
183
+        } else {
184 184
             $tmp = array($tmp);
185 185
         }
186 186
 
@@ -194,8 +194,8 @@  discard block
 block discarded – undo
194 194
      * @param $param
195 195
      * @return mixed
196 196
      */
197
-    public function renderTV($iddoc, $tvname, $tvval, $param)
198
-    {
197
+    public function renderTV($iddoc, $tvname, $tvval, $param)
198
+    {
199 199
         include_once MODX_MANAGER_PATH . "includes/tmplvars.format.inc.php";
200 200
         include_once MODX_MANAGER_PATH . "includes/tmplvars.commands.inc.php";
201 201
 
@@ -207,15 +207,15 @@  discard block
 block discarded – undo
207 207
      * @param $tvlist
208 208
      * @return array
209 209
      */
210
-    public function getTVid($tvlist)
211
-    {
212
-        if (!empty($tvlist) && is_scalar($tvlist)) {
210
+    public function getTVid($tvlist)
211
+    {
212
+        if (!empty($tvlist) && is_scalar($tvlist)) {
213 213
             $tvlist = explode(",", $tvlist);
214 214
         }
215 215
         $out = array();
216
-        foreach ($tvlist as $tv) {
216
+        foreach ($tvlist as $tv) {
217 217
             $tv = trim($tv);
218
-            if (isset($this->modx->_TVnames[$tv])) {
218
+            if (isset($this->modx->_TVnames[$tv])) {
219 219
                 $out[$this->modx->_TVnames[$tv]['id']] = $tv;
220 220
             }
221 221
         }
@@ -227,11 +227,11 @@  discard block
 block discarded – undo
227 227
      * @param array $tvId
228 228
      * @return array
229 229
      */
230
-    public function loadTVDefault($tvId)
231
-    {
230
+    public function loadTVDefault($tvId)
231
+    {
232 232
         $tvs = array_flip($this->getTVnames());
233 233
         $out = array();
234
-        foreach ($tvId as $id) {
234
+        foreach ($tvId as $id) {
235 235
             $name = $tvs[$id];
236 236
             $out[$this->_TVprefix . $name] = $this->modx->_TVnames[$name]['default'];
237 237
         }
@@ -243,8 +243,8 @@  discard block
 block discarded – undo
243 243
      * @param $name
244 244
      * @return string
245 245
      */
246
-    public function addTVSortWithDefault($name)
247
-    {
246
+    public function addTVSortWithDefault($name)
247
+    {
248 248
         $dTV = explode(',', $this->DocLister->getCFGDef('tvSortWithDefault', ''));
249 249
         $dTV[] = $name;
250 250
         $tvList = implode(",", array_unique($dTV));
@@ -258,37 +258,37 @@  discard block
 block discarded – undo
258 258
      * @param $sort
259 259
      * @return array
260 260
      */
261
-    public function injectSortByTV($table, $sort)
262
-    {
263
-        if (preg_match("/^ORDER BY (.*)/", $sort, $match)) {
261
+    public function injectSortByTV($table, $sort)
262
+    {
263
+        if (preg_match("/^ORDER BY (.*)/", $sort, $match)) {
264 264
             $TVnames = $this->getTVnames();
265
-            if (!is_array($TVnames)) {
265
+            if (!is_array($TVnames)) {
266 266
                 $TVnames = array();
267 267
             }
268 268
             $matches = explode(",", $match[1]);
269 269
             $sortType = explode(",", $this->DocLister->getCFGDef('tvSortType'));
270 270
             $withDefault = explode(",", $this->DocLister->getCFGDef('tvSortWithDefault'));
271
-            foreach ($matches as $i => &$item) {
271
+            foreach ($matches as $i => &$item) {
272 272
                 $item = explode(" ", trim($item), 2);
273
-                if (isset($TVnames[$item[0]])) {
273
+                if (isset($TVnames[$item[0]])) {
274 274
                     $exists = $this->DocLister->checkTableAlias($item[0], $this->tvValuesTable());
275 275
                     $prefix = 'dltv_' . $item[0] . '_' . ($i + 1);
276 276
                     $prefix = $this->storeTable ? $this->DocLister->TableAlias($item[0], $this->tvValuesTable(),
277 277
                         $prefix) : $prefix;
278
-                    if (!$exists) {
278
+                    if (!$exists) {
279 279
                         $table .= " LEFT JOIN " . $this->DocLister->getTable($this->tvValuesTable(), $prefix) . "
280 280
                         on `" . $prefix . "`.`contentid`=`c`.`id` AND `" . $prefix . "`.`tmplvarid`=" . $TVnames[$item[0]];
281 281
                     }
282
-                    if (in_array($item[0], $withDefault)) {
282
+                    if (in_array($item[0], $withDefault)) {
283 283
                         $exists = $this->DocLister->checkTableAlias($item[0], "site_tmplvars");
284 284
                         $dPrefix = $this->storeTable ? $this->DocLister->TableAlias($item[0], "site_tmplvars",
285 285
                             'd_' . $prefix) : 'd_' . $prefix;
286
-                        if (!$exists) {
286
+                        if (!$exists) {
287 287
                             $table .= " LEFT JOIN " . $this->DocLister->getTable("site_tmplvars",
288 288
                                     $dPrefix) . " on `" . $dPrefix . "`.`id` = " . $TVnames[$item[0]];
289 289
                         }
290 290
                         $field = "IFNULL(`{$prefix}`.`value`, `{$dPrefix}`.`default_text`)";
291
-                    } else {
291
+                    } else {
292 292
                         $field = "`{$prefix}`.`value`";
293 293
                     }
294 294
                     $item[0] = $this->DocLister->changeSortType($field, isset($sortType[$i]) ? $sortType[$i] : null);
@@ -305,10 +305,10 @@  discard block
 block discarded – undo
305 305
      * @param $key
306 306
      * @return mixed
307 307
      */
308
-    private function loadFromCache($key)
309
-    {
308
+    private function loadFromCache($key)
309
+    {
310 310
         $out = false;
311
-        if ($this->cache) {
311
+        if ($this->cache) {
312 312
             $out = $this->modx->cache->fetch($key);
313 313
         }
314 314
 
@@ -320,10 +320,10 @@  discard block
 block discarded – undo
320 320
      * @param string $key
321 321
      * @return bool
322 322
      */
323
-    private function saveToCache($data, $key)
324
-    {
323
+    private function saveToCache($data, $key)
324
+    {
325 325
         $out = false;
326
-        if ($this->cache) {
326
+        if ($this->cache) {
327 327
             $out = $this->modx->cache->save($key, $data, 0);
328 328
         }
329 329
 
Please login to merge, or discard this patch.
assets/snippets/DocLister/core/controller/site_content.php 2 patches
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
                         if (!$item[$date] && $date == 'pub_date' && isset($item['createdon'])) {
157 157
                             $date = 'createdon';
158 158
                         }
159
-                        $_date = is_numeric($item[$date]) && $item[$date] == (int)$item[$date] ? $item[$date] : strtotime($item[$date]);
159
+                        $_date = is_numeric($item[$date]) && $item[$date] == (int) $item[$date] ? $item[$date] : strtotime($item[$date]);
160 160
                         if ($_date !== false) {
161 161
                             $_date = $_date + $this->modx->config['server_offset_time'];
162 162
                             $dateFormat = $this->getCFGDef('dateFormat', '%d.%b.%y %H:%M');
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 
188 188
                     if ($this->getCFGDef('contentPlaceholder', 0) !== 0) {
189 189
                         $this->toPlaceholders($tmp, 1,
190
-                            "item[" . $i . "]"); // [+item[x]+] – individual placeholder for each iteration documents on this page
190
+                            "item[".$i."]"); // [+item[x]+] – individual placeholder for each iteration documents on this page
191 191
                     }
192 192
                     $out .= $tmp;
193 193
                     if (next($this->_docs) !== false) {
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
                     if (!$row[$date] && $date == 'pub_date' && isset($row['createdon'])) {
242 242
                         $date = 'createdon';
243 243
                     }
244
-                    $_date = is_numeric($row[$date]) && $row[$date] == (int)$row[$date] ? $row[$date] : strtotime($row[$date]);
244
+                    $_date = is_numeric($row[$date]) && $row[$date] == (int) $row[$date] ? $row[$date] : strtotime($row[$date]);
245 245
                     if ($_date !== false) {
246 246
                         $_date = $_date + $this->modx->config['server_offset_time'];
247 247
                         $dateFormat = $this->getCFGDef('dateFormat', '%d.%b.%y %H:%M');
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
                     $row['title'] = empty($row['menutitle']) ? $row['pagetitle'] : $row['menutitle'];
258 258
                 }
259 259
             }
260
-            if ((bool)$this->getCFGDef('makeUrl', 1) && (array('1') == $fields || in_array('url', $fields))
260
+            if ((bool) $this->getCFGDef('makeUrl', 1) && (array('1') == $fields || in_array('url', $fields))
261 261
             ) {
262 262
                 if (isset($row['type']) && $row['type'] == 'reference' && isset($row['content'])) {
263 263
                     $row['url'] = is_numeric($row['content']) ? $this->modx->makeUrl($row['content'], '', '',
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
                 $q_true = $q_true ? $q_true : $this->getCFGDef('idType', 'parents') == 'parents';
299 299
                 $where = $this->getCFGDef('addWhereList', '');
300 300
                 $where = sqlHelper::trimLogicalOp($where);
301
-                $where = ($where ? $where . ' AND ' : '') . $this->_filters['where'];
301
+                $where = ($where ? $where.' AND ' : '').$this->_filters['where'];
302 302
                 if ($where != '' && $this->_filters['where'] != '') {
303 303
                     $where .= " AND ";
304 304
                 }
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
                         case 'parents':
320 320
                             switch ($this->getCFGDef('showParent', '0')) {
321 321
                                 case '-1':
322
-                                    $tmpWhere = "c.parent IN (" . $sanitarInIDs . ")";
322
+                                    $tmpWhere = "c.parent IN (".$sanitarInIDs.")";
323 323
                                     break;
324 324
                                 case 0:
325 325
                                     $tmpWhere = "c.parent IN ({$sanitarInIDs}) AND c.id NOT IN({$sanitarInIDs})";
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
                             }
332 332
                             if (($addDocs = $this->getCFGDef('documents', '')) != '') {
333 333
                                 $addDocs = $this->sanitarIn($this->cleanIDs($addDocs));
334
-                                $whereArr[] = "((" . $tmpWhere . ") OR c.id IN({$addDocs}))";
334
+                                $whereArr[] = "((".$tmpWhere.") OR c.id IN({$addDocs}))";
335 335
                             } else {
336 336
                                 $whereArr[] = $tmpWhere;
337 337
                             }
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
                             break;
343 343
                     }
344 344
                 }
345
-                $from = $tbl_site_content . " " . $this->_filters['join'];
345
+                $from = $tbl_site_content." ".$this->_filters['join'];
346 346
                 $where = sqlHelper::trimLogicalOp($where);
347 347
 
348 348
                 $q_true = $q_true ? $q_true : trim($where) != 'WHERE';
@@ -386,12 +386,12 @@  discard block
 block discarded – undo
386 386
             $where = $this->getCFGDef('addWhereList', '');
387 387
             $where = sqlHelper::trimLogicalOp($where);
388 388
 
389
-            $where = ($where ? $where . ' AND ' : '') . $this->_filters['where'];
389
+            $where = ($where ? $where.' AND ' : '').$this->_filters['where'];
390 390
             $where = sqlHelper::trimLogicalOp($where);
391 391
 
392 392
             $tbl_site_content = $this->getTable('site_content', 'c');
393 393
             if ($sanitarInIDs != "''") {
394
-                $where .= ($where ? " AND " : "") . "c.id IN ({$sanitarInIDs}) AND";
394
+                $where .= ($where ? " AND " : "")."c.id IN ({$sanitarInIDs}) AND";
395 395
             }
396 396
             $where = sqlHelper::trimLogicalOp($where);
397 397
 
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
             $fields = $this->getCFGDef('selectFields', 'c.*');
415 415
             $group = $this->getGroupSQL($this->getCFGDef('groupBy', ''));
416 416
             $sort = $this->SortOrderSQL("if(c.pub_date=0,c.createdon,c.pub_date)");
417
-            list($tbl_site_content, $sort) = $this->injectSortByTV($tbl_site_content . ' ' . $this->_filters['join'],
417
+            list($tbl_site_content, $sort) = $this->injectSortByTV($tbl_site_content.' '.$this->_filters['join'],
418 418
                 $sort);
419 419
 
420 420
             $limit = $this->LimitSQL($this->getCFGDef('queryLimit', 0));
@@ -501,21 +501,21 @@  discard block
 block discarded – undo
501 501
         $tbl_site_content = $this->getTable('site_content', 'c');
502 502
 
503 503
         $sort = $this->SortOrderSQL("if(c.pub_date=0,c.createdon,c.pub_date)");
504
-        list($from, $sort) = $this->injectSortByTV($tbl_site_content . ' ' . $this->_filters['join'], $sort);
504
+        list($from, $sort) = $this->injectSortByTV($tbl_site_content.' '.$this->_filters['join'], $sort);
505 505
         $sanitarInIDs = $this->sanitarIn($this->IDs);
506 506
 
507 507
         $tmpWhere = null;
508 508
         if ($sanitarInIDs != "''") {
509 509
             switch ($this->getCFGDef('showParent', '0')) {
510 510
                 case '-1':
511
-                    $tmpWhere = "c.parent IN (" . $sanitarInIDs . ")";
511
+                    $tmpWhere = "c.parent IN (".$sanitarInIDs.")";
512 512
                     break;
513 513
                 case 0:
514
-                    $tmpWhere = "c.parent IN (" . $sanitarInIDs . ") AND c.id NOT IN(" . $sanitarInIDs . ")";
514
+                    $tmpWhere = "c.parent IN (".$sanitarInIDs.") AND c.id NOT IN(".$sanitarInIDs.")";
515 515
                     break;
516 516
                 case 1:
517 517
                 default:
518
-                    $tmpWhere = "(c.parent IN (" . $sanitarInIDs . ") OR c.id IN({$sanitarInIDs}))";
518
+                    $tmpWhere = "(c.parent IN (".$sanitarInIDs.") OR c.id IN({$sanitarInIDs}))";
519 519
                     break;
520 520
             }
521 521
         }
@@ -524,7 +524,7 @@  discard block
 block discarded – undo
524 524
             if (empty($tmpWhere)) {
525 525
                 $tmpWhere = "c.id IN({$addDocs})";
526 526
             } else {
527
-                $tmpWhere = "((" . $tmpWhere . ") OR c.id IN({$addDocs}))";
527
+                $tmpWhere = "((".$tmpWhere.") OR c.id IN({$addDocs}))";
528 528
             }
529 529
         }
530 530
         if (!empty($tmpWhere)) {
@@ -534,7 +534,7 @@  discard block
 block discarded – undo
534 534
             $where[] = "c.deleted=0 AND c.published=1";
535 535
         }
536 536
         if (!empty($where)) {
537
-            $where = "WHERE " . implode(" AND ", $where);
537
+            $where = "WHERE ".implode(" AND ", $where);
538 538
         } else {
539 539
             $where = '';
540 540
         }
@@ -542,9 +542,9 @@  discard block
 block discarded – undo
542 542
         $group = $this->getGroupSQL($this->getCFGDef('groupBy', ''));
543 543
 
544 544
         if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) {
545
-            $rs = $this->dbQuery("SELECT {$fields} FROM " . $from . " " . $where . " " .
546
-                $group . " " .
547
-                $sort . " " .
545
+            $rs = $this->dbQuery("SELECT {$fields} FROM ".$from." ".$where." ".
546
+                $group." ".
547
+                $sort." ".
548 548
                 $this->LimitSQL($this->getCFGDef('queryLimit', 0))
549 549
             );
550 550
 
@@ -566,7 +566,7 @@  discard block
 block discarded – undo
566 566
         $type = trim($type);
567 567
         switch (strtoupper($type)) {
568 568
             case 'TVDATETIME':
569
-                $field = "STR_TO_DATE(" . $field . ",'%d-%m-%Y %H:%i:%s')";
569
+                $field = "STR_TO_DATE(".$field.",'%d-%m-%Y %H:%i:%s')";
570 570
                 break;
571 571
             default:
572 572
                 $field = parent::changeSortType($field, $type);
Please login to merge, or discard this patch.
Upper-Lower-Casing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
                 }
305 305
                 $where = sqlHelper::trimLogicalOp($where);
306 306
 
307
-                $where = "WHERE {$where}";
307
+                $where = "where {$where}";
308 308
                 $whereArr = array();
309 309
                 if (!$this->getCFGDef('showNoPublish', 0)) {
310 310
                     $whereArr[] = "c.deleted=0 AND c.published=1";
@@ -397,15 +397,15 @@  discard block
 block discarded – undo
397 397
 
398 398
             if ($this->getCFGDef('showNoPublish', 0)) {
399 399
                 if ($where != '') {
400
-                    $where = "WHERE {$where}";
400
+                    $where = "where {$where}";
401 401
                 } else {
402 402
                     $where = '';
403 403
                 }
404 404
             } else {
405 405
                 if ($where != '') {
406
-                    $where = "WHERE {$where} AND ";
406
+                    $where = "where {$where} AND ";
407 407
                 } else {
408
-                    $where = "WHERE {$where} ";
408
+                    $where = "where {$where} ";
409 409
                 }
410 410
                 $where .= "c.deleted=0 AND c.published=1";
411 411
             }
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
 
420 420
             $limit = $this->LimitSQL($this->getCFGDef('queryLimit', 0));
421 421
 
422
-            $rs = $this->dbQuery("SELECT {$fields} FROM {$tbl_site_content} {$where} {$group} {$sort} {$limit}");
422
+            $rs = $this->dbQuery("select {$fields} FROM {$tbl_site_content} {$where} {$group} {$sort} {$limit}");
423 423
 
424 424
             while ($item = $this->modx->db->getRow($rs)) {
425 425
                 $out[$item['id']] = $item;
@@ -447,9 +447,9 @@  discard block
 block discarded – undo
447 447
             $tbl_site_content = $this->getTable('site_content', 'c');
448 448
             $sanitarInIDs = $this->sanitarIn($id);
449 449
             if ($this->getCFGDef('showNoPublish', 0)) {
450
-                $where = "WHERE {$where} c.parent IN ({$sanitarInIDs}) AND c.isfolder=1";
450
+                $where = "where {$where} c.parent IN ({$sanitarInIDs}) AND c.isfolder=1";
451 451
             } else {
452
-                $where = "WHERE {$where} c.parent IN ({$sanitarInIDs}) AND c.deleted=0 AND c.published=1 AND c.isfolder=1";
452
+                $where = "where {$where} c.parent IN ({$sanitarInIDs}) AND c.deleted=0 AND c.published=1 AND c.isfolder=1";
453 453
             }
454 454
 
455 455
             $rs = $this->dbQuery("SELECT id FROM {$tbl_site_content} {$where}");
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
         $group = $this->getGroupSQL($this->getCFGDef('groupBy', ''));
543 543
 
544 544
         if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) {
545
-            $rs = $this->dbQuery("SELECT {$fields} FROM " . $from . " " . $where . " " .
545
+            $rs = $this->dbQuery("select {$fields} FROM " . $from . " " . $where . " " .
546 546
                 $group . " " .
547 547
                 $sort . " " .
548 548
                 $this->LimitSQL($this->getCFGDef('queryLimit', 0))
Please login to merge, or discard this patch.
assets/snippets/DocLister/core/controller/site_content_menu.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
      */
28 28
     public function setIDs($IDs)
29 29
     {
30
-        $this->debug->debug('set ID list ' . $this->debug->dumpData($IDs), 'setIDs', 2);
30
+        $this->debug->debug('set ID list '.$this->debug->dumpData($IDs), 'setIDs', 2);
31 31
         $IDs = $this->cleanIDs($IDs);
32 32
         $this->debug->debugEnd("setIDs");
33 33
 
@@ -280,13 +280,13 @@  discard block
 block discarded – undo
280 280
                 }
281 281
 
282 282
                 if (isset($data['wrap'])) {
283
-                    if(is_array($data['wrap'])) {
283
+                    if (is_array($data['wrap'])) {
284 284
                         $data['wrap'] = $this->parseRow($data['wrap']);
285 285
                     }
286 286
                     $data['wrap'] = $this->parseOuter($data);
287 287
                 }
288 288
                 $hideSubMenus = $this->getCFGDef('hideSubMenus', 0);
289
-                $hideSubMenus = !$hideSubMenus || ($hideSubMenus && in_array((int)$data['parent'],
289
+                $hideSubMenus = !$hideSubMenus || ($hideSubMenus && in_array((int) $data['parent'],
290 290
                             $this->activeBranch));
291 291
                 if ($hideSubMenus) {
292 292
                     $docs[$currentLevel - 1][$data['parent']]['wrap'][] = $data;
@@ -437,8 +437,8 @@  discard block
 block discarded – undo
437 437
      */
438 438
     public function getHereId()
439 439
     {
440
-        if (!$hereId = (int)$this->getCFGDef('hereId')) {
441
-            $hereId = isset($this->modx->documentIdentifier) ? (int)$this->modx->documentIdentifier : 0;
440
+        if (!$hereId = (int) $this->getCFGDef('hereId')) {
441
+            $hereId = isset($this->modx->documentIdentifier) ? (int) $this->modx->documentIdentifier : 0;
442 442
         }
443 443
 
444 444
         return $hereId;
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
             'evenClass'    => ''
465 465
         );
466 466
         if (isset($data['state'])) {
467
-            $classes['stateClass'] = $this->getCFGDef($data['state'] . 'Class', $data['state']);
467
+            $classes['stateClass'] = $this->getCFGDef($data['state'].'Class', $data['state']);
468 468
         }
469 469
         if (isset($data['here'])) {
470 470
             $classes['hereClass'] = $this->getCFGDef('hereClass', 'current');
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
             $classes['lastClass'] = $this->getCFGDef('lastClass', 'last');
486 486
         }
487 487
         if ($levelClass = $this->getCFGDef('levelClass', 'level')) {
488
-            $classes['levelClass'] = $levelClass . $data['level'];
488
+            $classes['levelClass'] = $levelClass.$data['level'];
489 489
         }
490 490
         if (isset($data['type']) && $data['type'] == 'reference') {
491 491
             $classes['webLinkClass'] = $this->getCFGDef('webLinkClass');
@@ -576,7 +576,7 @@  discard block
 block discarded – undo
576 576
                 }
577 577
 
578 578
                 $hideSubMenus = $this->getCFGDef('hideSubMenus', 0);
579
-                $hideSubMenus = !$hideSubMenus || ($hideSubMenus && in_array((int)$data['parent'],
579
+                $hideSubMenus = !$hideSubMenus || ($hideSubMenus && in_array((int) $data['parent'],
580 580
                             $this->activeBranch));
581 581
                 if ($hideSubMenus) {
582 582
                     $docs[$currentLevel - 1][$data['parent']]['children'][] = $data;
@@ -611,6 +611,6 @@  discard block
 block discarded – undo
611 611
      */
612 612
     public function getCFGDef($name, $def = null)
613 613
     {
614
-        return parent::getCFGDef($name . $this->currentLevel, parent::getCFGDef($name, $def));
614
+        return parent::getCFGDef($name.$this->currentLevel, parent::getCFGDef($name, $def));
615 615
     }
616 616
 }
Please login to merge, or discard this patch.
Braces   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -9,8 +9,8 @@  discard block
 block discarded – undo
9 9
  * @license GNU General Public License (GPL), http://www.gnu.org/copyleft/gpl.html
10 10
  * @author Agel_Nash <[email protected]>, kabachello <[email protected]>
11 11
  */
12
-class site_content_menuDocLister extends site_contentDocLister
13
-{
12
+class site_content_menuDocLister extends site_contentDocLister
13
+{
14 14
     public $levels = array();
15 15
     protected $currentLevel = 1;
16 16
     protected $docTvs = array();
@@ -25,8 +25,8 @@  discard block
 block discarded – undo
25 25
      * @param mixed $IDs список id документов по которым необходима выборка
26 26
      * @return array очищенный массив
27 27
      */
28
-    public function setIDs($IDs)
29
-    {
28
+    public function setIDs($IDs)
29
+    {
30 30
         $this->debug->debug('set ID list ' . $this->debug->dumpData($IDs), 'setIDs', 2);
31 31
         $IDs = $this->cleanIDs($IDs);
32 32
         $this->debug->debugEnd("setIDs");
@@ -38,15 +38,15 @@  discard block
 block discarded – undo
38 38
      * @param string $tvlist
39 39
      * @return array
40 40
      */
41
-    public function getDocs($tvlist = '')
42
-    {
41
+    public function getDocs($tvlist = '')
42
+    {
43 43
         $this->extTV->getAllTV_Name();
44
-        if ($ids = $this->getCFGDef('documents')) {
44
+        if ($ids = $this->getCFGDef('documents')) {
45 45
             $this->setIDs($ids);
46 46
             $docs = $this->getDocList();
47 47
             $display = count($docs);
48 48
             $iteration = 1;
49
-            foreach ($docs as $id => &$item) {
49
+            foreach ($docs as $id => &$item) {
50 50
                 $item['iteration'] = $iteration++;
51 51
                 $item['_display'] = $display;
52 52
                 $item['_parent'] = $item['parent'];
@@ -54,53 +54,53 @@  discard block
 block discarded – undo
54 54
             }
55 55
             $this->levels[1] = $docs;
56 56
             $this->setActiveBranch($this->getHereId(), 1);
57
-        } else {
57
+        } else {
58 58
             $this->_getChildren();
59 59
         }
60 60
 
61
-        if ($tvlist == '') {
61
+        if ($tvlist == '') {
62 62
             $tvlist = $this->getCFGDef('tvList', '');
63 63
         }
64 64
 
65
-        if ($tvlist != '') {
65
+        if ($tvlist != '') {
66 66
             $ids = array();
67
-            foreach ($this->levels as $level => $docs) {
67
+            foreach ($this->levels as $level => $docs) {
68 68
                 $ids = array_merge($ids, array_keys($docs));
69 69
             }
70
-            if (!empty($ids)) {
70
+            if (!empty($ids)) {
71 71
                 $tv = $this->extTV->getTVList($ids, $tvlist);
72
-                if (!is_array($tv)) {
72
+                if (!is_array($tv)) {
73 73
                     $tv = array();
74 74
                 }
75 75
                 $this->docTvs = $tv;
76 76
             }
77 77
 
78 78
         }
79
-        if ($this->getCFGDef('countChildren', 0)) {
79
+        if ($this->getCFGDef('countChildren', 0)) {
80 80
             $this->countChildren();
81 81
         }
82 82
         //TODO кэширование
83 83
         return $this->levels;
84 84
     }
85 85
 
86
-    public function _getChildren()
87
-    {
86
+    public function _getChildren()
87
+    {
88 88
         $maxDepth = $this->getCFGDef('maxDepth', 10);
89
-        if ($this->getCFGDef('hideSubMenus', 0) && empty($this->getCFGDef('openIds'))) {
89
+        if ($this->getCFGDef('hideSubMenus', 0) && empty($this->getCFGDef('openIds'))) {
90 90
             $maxDepth = min($maxDepth, $this->setActiveBranch($this->getHereId()));
91
-            if (empty(array_intersect($this->IDs, $this->activeBranch))) {
91
+            if (empty(array_intersect($this->IDs, $this->activeBranch))) {
92 92
                 $maxDepth = 1;
93 93
                 $this->config->setConfig(array('hideSubMenus' => 0));
94 94
             };
95
-        } else {
95
+        } else {
96 96
             $this->setActiveBranch($this->getHereId());
97 97
         }
98
-        if ($oIds = $this->getCFGDef('openIds')) {
98
+        if ($oIds = $this->getCFGDef('openIds')) {
99 99
             $maxDepth = 1;
100 100
             $oIds = $this->cleanIDs($oIds);
101 101
             $oIds[] = $this->getHereId();
102
-            foreach ($oIds as $id) {
103
-                if (($c = $this->setActiveBranch($id)) > $maxDepth) {
102
+            foreach ($oIds as $id) {
103
+                if (($c = $this->setActiveBranch($id)) > $maxDepth) {
104 104
                     $maxDepth = $c;
105 105
                 }
106 106
             }
@@ -108,44 +108,44 @@  discard block
 block discarded – undo
108 108
         }
109 109
         $currentLevel = &$this->currentLevel;
110 110
         $currentLevel = 1;
111
-        if ($this->getCFGDef('showParent', 0) && in_array(0, $this->IDs)) {
111
+        if ($this->getCFGDef('showParent', 0) && in_array(0, $this->IDs)) {
112 112
             $this->config->setConfig(array('showParent' => 0));
113 113
         }
114 114
         $joinMenus = $this->getCFGDef('joinMenus', 0) && !$this->getCFGDef('showParent', 0);
115
-        while ($currentLevel <= $maxDepth) {
115
+        while ($currentLevel <= $maxDepth) {
116 116
             $orderBy = $this->getCFGDef('orderBy');
117
-            if ($this->getCFGDef('showParent', 0) && $currentLevel == 1) {
117
+            if ($this->getCFGDef('showParent', 0) && $currentLevel == 1) {
118 118
                 $docs = $this->getDocList();
119 119
                 $this->config->setConfig(array('showParent' => 0));
120
-            } else {
120
+            } else {
121 121
                 $docs = $this->getChildrenList();
122 122
             }
123
-            if ($currentLevel == 1 && $joinMenus) {
123
+            if ($currentLevel == 1 && $joinMenus) {
124 124
                 $tmp = array();
125 125
                 $display = 0;
126 126
                 $iteration = 1;
127
-                foreach ($docs as $id => $item) {
127
+                foreach ($docs as $id => $item) {
128 128
                     $tmp[$item['parent']][] = $item['id'];
129 129
                     $display++;
130 130
                 }
131
-                foreach ($tmp as $id => $item) {
132
-                    foreach ($item as $_id) {
131
+                foreach ($tmp as $id => $item) {
132
+                    foreach ($item as $_id) {
133 133
                         $docs[$_id]['_display'] = $display;
134 134
                         $docs[$_id]['iteration'] = $iteration++;
135 135
                     }
136 136
                 }
137 137
                 unset($tmp);
138
-            } else {
139
-                foreach ($docs as $id => &$item) {
138
+            } else {
139
+                foreach ($docs as $id => &$item) {
140 140
                     $parent = $item['parent'];
141
-                    if (!isset($this->display[$parent])) {
141
+                    if (!isset($this->display[$parent])) {
142 142
                         $this->display[$parent] = 1;
143 143
                     }
144 144
                     $item['iteration'] = $this->display[$parent]++;
145 145
                 }
146 146
             }
147 147
             $this->config->setConfig(array('orderBy' => $orderBy));
148
-            if (empty($docs)) {
148
+            if (empty($docs)) {
149 149
                 break;
150 150
             }
151 151
             $this->levels[$currentLevel++] = $docs;
@@ -159,8 +159,8 @@  discard block
 block discarded – undo
159 159
      * @param $id
160 160
      * @param int $maxDepth
161 161
      */
162
-    public function setActiveBranch($id, $maxDepth = 10)
163
-    {
162
+    public function setActiveBranch($id, $maxDepth = 10)
163
+    {
164 164
         $ids = array_values($this->modx->getParentIds($id, $maxDepth));
165 165
         $ids[] = $id;
166 166
         $ids[] = 0;
@@ -173,29 +173,29 @@  discard block
 block discarded – undo
173 173
     /**
174 174
      * Подсчет количества непосредственных дочерних документов
175 175
      */
176
-    public function countChildren()
177
-    {
176
+    public function countChildren()
177
+    {
178 178
         $ids = array();
179 179
         $out = &$this->countChildren;
180
-        foreach ($this->levels as $level => $docs) {
180
+        foreach ($this->levels as $level => $docs) {
181 181
             $ids = array_merge($ids, array_keys($docs));
182 182
         }
183 183
         $maxDepth = count($this->levels);
184 184
         $currentDepth = 1;
185
-        while ($currentDepth <= $maxDepth) {
185
+        while ($currentDepth <= $maxDepth) {
186 186
             $_ids = implode(',', $ids);
187
-            if (empty($_ids)) {
187
+            if (empty($_ids)) {
188 188
                 break;
189 189
             }
190 190
             $q = $this->dbQuery("SELECT `parent`,COUNT(*) as `count` FROM {$this->getTable('site_content')} WHERE `parent` IN ({$_ids}) AND `published`=1 AND `deleted`=0 GROUP BY `parent`");
191 191
             $_ids = array();
192
-            while ($row = $this->modx->db->getRow($q)) {
192
+            while ($row = $this->modx->db->getRow($q)) {
193 193
                 $_ids[] = $row['parent'];
194 194
                 $out[$row['parent']] = $row['count'];
195 195
             }
196
-            if (!empty($_ids)) {
196
+            if (!empty($_ids)) {
197 197
                 $ids = $this->diff($ids, $_ids);
198
-            } else {
198
+            } else {
199 199
                 break;
200 200
             }
201 201
             $currentDepth++;
@@ -208,12 +208,12 @@  discard block
 block discarded – undo
208 208
      * @param $a
209 209
      * @return array
210 210
      */
211
-    private function diff($b, $a)
212
-    {
211
+    private function diff($b, $a)
212
+    {
213 213
         $at = array_flip($a);
214 214
         $d = array();
215
-        foreach ($b as $i) {
216
-            if (!isset($at[$i])) {
215
+        foreach ($b as $i) {
216
+            if (!isset($at[$i])) {
217 217
                 $d[] = $i;
218 218
             }
219 219
         }
@@ -228,17 +228,17 @@  discard block
 block discarded – undo
228 228
      * @param string $tpl шаблон
229 229
      * @return string
230 230
      */
231
-    public function render($tpl = '')
232
-    {
231
+    public function render($tpl = '')
232
+    {
233 233
         $this->debug->debug(array('Render data with template ' => $tpl), 'render', 2, array('html'));
234
-        if (empty($this->levels)) {
234
+        if (empty($this->levels)) {
235 235
             $noneTpl = $this->getCFGDef('noneTpl');
236 236
             $out = $noneTpl ? $this->parseChunk($noneTpl, array()) : '';
237
-        } else {
237
+        } else {
238 238
             $out = $this->_render($tpl);
239 239
         }
240 240
 
241
-        if ($out) {
241
+        if ($out) {
242 242
             $this->outData = DLTemplate::getInstance($this->modx)->parseDocumentSource($out);
243 243
         }
244 244
         $this->debug->debugEnd('render');
@@ -250,37 +250,37 @@  discard block
 block discarded – undo
250 250
      * @param string $tpl
251 251
      * @return string
252 252
      */
253
-    public function _render($tpl = '')
254
-    {
253
+    public function _render($tpl = '')
254
+    {
255 255
         $currentLevel = &$this->currentLevel;
256 256
         $currentLevel = count($this->levels);
257 257
         $docs = $this->levels;
258 258
         /** @var prepare_DL_Extender_ $extPrepare */
259 259
         $extPrepare = $this->getExtender('prepare');
260
-        while ($currentLevel > 0) {
261
-            foreach ($docs[$currentLevel] as $id => &$data) {
262
-                if ($out = $this->prepareData($data)) {
263
-                    if (is_array($out)) {
260
+        while ($currentLevel > 0) {
261
+            foreach ($docs[$currentLevel] as $id => &$data) {
262
+                if ($out = $this->prepareData($data)) {
263
+                    if (is_array($out)) {
264 264
                         $data = $out;
265 265
                     }
266 266
                 };
267
-                if (!isset($data['maxLevel'])) {
267
+                if (!isset($data['maxLevel'])) {
268 268
                     $data['maxLevel'] = 1;
269 269
                     $docs[$currentLevel - 1][$data['parent']]['maxLevel'] = 0;
270 270
                 }
271 271
 
272
-                if ($extPrepare) {
272
+                if ($extPrepare) {
273 273
                     $data = $extPrepare->init($this, array(
274 274
                         'data'      => $data,
275 275
                         'nameParam' => 'prepare'
276 276
                     ));
277
-                    if (is_bool($data) && $data === false) {
277
+                    if (is_bool($data) && $data === false) {
278 278
                         continue;
279 279
                     }
280 280
                 }
281 281
 
282
-                if (isset($data['wrap'])) {
283
-                    if(is_array($data['wrap'])) {
282
+                if (isset($data['wrap'])) {
283
+                    if(is_array($data['wrap'])) {
284 284
                         $data['wrap'] = $this->parseRow($data['wrap']);
285 285
                     }
286 286
                     $data['wrap'] = $this->parseOuter($data);
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
                 $hideSubMenus = $this->getCFGDef('hideSubMenus', 0);
289 289
                 $hideSubMenus = !$hideSubMenus || ($hideSubMenus && in_array((int)$data['parent'],
290 290
                             $this->activeBranch));
291
-                if ($hideSubMenus) {
291
+                if ($hideSubMenus) {
292 292
                     $docs[$currentLevel - 1][$data['parent']]['wrap'][] = $data;
293 293
                 }
294 294
             }
@@ -298,17 +298,17 @@  discard block
 block discarded – undo
298 298
         unset($data);
299 299
         $out = '';
300 300
         $joinMenus = $this->getCFGDef('joinMenus', 0) && !$this->getCFGDef('showParent', 0);
301
-        foreach ($docs[0] as $id => $data) {
302
-            if (isset($data['wrap'])) {
303
-                if ($joinMenus) {
301
+        foreach ($docs[0] as $id => $data) {
302
+            if (isset($data['wrap'])) {
303
+                if ($joinMenus) {
304 304
                     $out .= $this->parseRow($data['wrap']);
305
-                } else {
305
+                } else {
306 306
                     $data['wrap'] = $this->parseRow($data['wrap']);
307 307
                     $out .= $this->parseOuter($data);
308 308
                 }
309 309
             }
310 310
         }
311
-        if ($joinMenus) {
311
+        if ($joinMenus) {
312 312
             $out = $this->parseOuter(array('wrap' => $out));
313 313
         }
314 314
 
@@ -320,33 +320,33 @@  discard block
 block discarded – undo
320 320
      * @param $data
321 321
      * @return array
322 322
      */
323
-    public function prepareData($data)
324
-    {
323
+    public function prepareData($data)
324
+    {
325 325
         /**
326 326
          * @var e_DL_Extender $extE
327 327
          */
328 328
         $extE = $this->getExtender('e', true, true);
329 329
         $id = $data['id'];
330
-        if (isset($this->docTvs[$id])) {
330
+        if (isset($this->docTvs[$id])) {
331 331
             $data = array_merge($data, $this->docTvs[$id]);
332 332
         }
333
-        if ($id == $this->getHereId()) {
333
+        if ($id == $this->getHereId()) {
334 334
             $data['here'] = 1;
335 335
         }
336
-        if (!isset($data['here']) && in_array($id, $this->activeBranch)) {
336
+        if (!isset($data['here']) && in_array($id, $this->activeBranch)) {
337 337
             $data['active'] = 1;
338 338
         }
339
-        if ($this->getCFGDef('hideSubMenus') && isset($data['isfolder']) && $data['isfolder']) {
339
+        if ($this->getCFGDef('hideSubMenus') && isset($data['isfolder']) && $data['isfolder']) {
340 340
             $data['state'] = in_array($data['id'], $this->activeBranch) ? 'open' : 'closed';
341 341
         }
342 342
 
343
-        if (!isset($data['_display'])) {
343
+        if (!isset($data['_display'])) {
344 344
             $data['_display'] = $this->display[$data['parent']] - 1;
345 345
         }
346
-        if ($data['iteration'] == 1) {
346
+        if ($data['iteration'] == 1) {
347 347
             $data['first'] = 1;
348 348
         }
349
-        if ($data['iteration'] == $data['_display']) {
349
+        if ($data['iteration'] == $data['_display']) {
350 350
             $data['last'] = 1;
351 351
         }
352 352
 
@@ -354,12 +354,12 @@  discard block
 block discarded – undo
354 354
         $data[$titleField] = isset($data['menutitle']) && !empty($data['menutitle']) ? $data['menutitle'] : $data['pagetitle'];
355 355
         $data['level'] = $this->currentLevel;
356 356
         $data['url'] = $this->makeUrl($data);
357
-        if ($this->getCFGDef('countChildren', 0)) {
357
+        if ($this->getCFGDef('countChildren', 0)) {
358 358
             $data['count'] = isset($this->countChildren[$data['id']]) ? $this->countChildren[$data['id']] : 0;
359 359
         }
360 360
 
361
-        if ($out = $extE->init($this, compact('data'))) {
362
-            if (is_array($out)) {
361
+        if ($out = $extE->init($this, compact('data'))) {
362
+            if (is_array($out)) {
363 363
                 $data = $out;
364 364
             }
365 365
         }
@@ -372,16 +372,16 @@  discard block
 block discarded – undo
372 372
      * @param array $data
373 373
      * @return string
374 374
      */
375
-    public function parseOuter($data = array())
376
-    {
375
+    public function parseOuter($data = array())
376
+    {
377 377
         $tpl = $this->getCFGDef('outerTpl', '@CODE:<ul[+classes+]>[+wrap+]</ul>');
378 378
         $classes = '';
379 379
         $classNames = $this->getCFGDef('outerClass');
380
-        if ($this->currentLevel >= 1) {
380
+        if ($this->currentLevel >= 1) {
381 381
             $tpl = $this->getCFGDef('innerTpl', $tpl);
382 382
             $classNames = $this->getCFGDef('innerClass');
383 383
         }
384
-        if ($classNames) {
384
+        if ($classNames) {
385 385
             $classes = " class=\"{$classNames}\"";
386 386
         }
387 387
         $tpl = isset($data['_renderOuterTpl']) ? $data['_renderOuterTpl'] : $tpl;
@@ -398,10 +398,10 @@  discard block
 block discarded – undo
398 398
      * @param array $data
399 399
      * @return string
400 400
      */
401
-    public function parseRow($data = array())
402
-    {
401
+    public function parseRow($data = array())
402
+    {
403 403
         $out = '';
404
-        foreach ($data as $iteration => $item) {
404
+        foreach ($data as $iteration => $item) {
405 405
             $tpl = isset($item['_renderRowTpl']) ? $item['_renderRowTpl'] : $this->getRowTemplate($item);
406 406
             $item = array_merge($item, $this->getClasses($item));
407 407
             $out .= $this->parseChunk($tpl, $item);
@@ -415,14 +415,14 @@  discard block
 block discarded – undo
415 415
      * @param array $data
416 416
      * @return string
417 417
      */
418
-    protected function makeUrl($data = array())
419
-    {
418
+    protected function makeUrl($data = array())
419
+    {
420 420
         $out = '';
421
-        if ($this->getCFGDef('makeUrl', 1)) {
422
-            if (isset($data['type']) && $data['type'] == 'reference' && isset($data['content'])) {
421
+        if ($this->getCFGDef('makeUrl', 1)) {
422
+            if (isset($data['type']) && $data['type'] == 'reference' && isset($data['content'])) {
423 423
                 $out = is_numeric($data['content']) ? $this->modx->makeUrl($data['content'], '', '',
424 424
                     $this->getCFGDef('urlScheme', '')) : $data['content'];
425
-            } else {
425
+            } else {
426 426
                 $out = isset($data['id']) && is_numeric($data['id']) ? $this->modx->makeUrl($data['id'], '', '',
427 427
                     $this->getCFGDef('urlScheme', '')) : '';
428 428
             }
@@ -435,9 +435,9 @@  discard block
 block discarded – undo
435 435
      * Вовзращает id текущего документа
436 436
      * @return int
437 437
      */
438
-    public function getHereId()
439
-    {
440
-        if (!$hereId = (int)$this->getCFGDef('hereId')) {
438
+    public function getHereId()
439
+    {
440
+        if (!$hereId = (int)$this->getCFGDef('hereId')) {
441 441
             $hereId = isset($this->modx->documentIdentifier) ? (int)$this->modx->documentIdentifier : 0;
442 442
         }
443 443
 
@@ -449,8 +449,8 @@  discard block
 block discarded – undo
449 449
      * @param array $data
450 450
      * @return array
451 451
      */
452
-    protected function getClasses($data = array())
453
-    {
452
+    protected function getClasses($data = array())
453
+    {
454 454
         $classes = isset($data['classes']) ? $data['classes'] : array(
455 455
             'rowClass'     => '',
456 456
             'firstClass'   => '',
@@ -463,34 +463,34 @@  discard block
 block discarded – undo
463 463
             'oddClass'     => '',
464 464
             'evenClass'    => ''
465 465
         );
466
-        if (isset($data['state'])) {
466
+        if (isset($data['state'])) {
467 467
             $classes['stateClass'] = $this->getCFGDef($data['state'] . 'Class', $data['state']);
468 468
         }
469
-        if (isset($data['here'])) {
469
+        if (isset($data['here'])) {
470 470
             $classes['hereClass'] = $this->getCFGDef('hereClass', 'current');
471 471
         }
472
-        if (isset($data['active'])) {
472
+        if (isset($data['active'])) {
473 473
             $classes['activeClass'] = $this->getCFGDef('activeClass', 'active');
474 474
         }
475 475
         $classes['rowClass'] = $this->getCFGDef('rowClass');
476
-        if ($data['iteration'] % 2 == 1) {
476
+        if ($data['iteration'] % 2 == 1) {
477 477
             $classes['oddClass'] = $this->getCFGDef('oddClass', 'odd');
478
-        } else {
478
+        } else {
479 479
             $classes['evenClass'] = $this->getCFGDef('evenClass', 'even');
480 480
         }
481
-        if (isset($data['first'])) {
481
+        if (isset($data['first'])) {
482 482
             $classes['firstClass'] = $this->getCFGDef('firstClass', 'first');
483 483
         }
484
-        if (isset($data['last'])) {
484
+        if (isset($data['last'])) {
485 485
             $classes['lastClass'] = $this->getCFGDef('lastClass', 'last');
486 486
         }
487
-        if ($levelClass = $this->getCFGDef('levelClass', 'level')) {
487
+        if ($levelClass = $this->getCFGDef('levelClass', 'level')) {
488 488
             $classes['levelClass'] = $levelClass . $data['level'];
489 489
         }
490
-        if (isset($data['type']) && $data['type'] == 'reference') {
490
+        if (isset($data['type']) && $data['type'] == 'reference') {
491 491
             $classes['webLinkClass'] = $this->getCFGDef('webLinkClass');
492 492
         }
493
-        if (!empty($data['wrap'])) {
493
+        if (!empty($data['wrap'])) {
494 494
             $classes['parentClass'] = $this->getCFGDef('parentClass');
495 495
         }
496 496
         $classNames = implode(' ', array_filter(array_values($classes)));
@@ -505,28 +505,28 @@  discard block
 block discarded – undo
505 505
      * @param array $data
506 506
      * @return string
507 507
      */
508
-    protected function getRowTemplate($data = array())
509
-    {
508
+    protected function getRowTemplate($data = array())
509
+    {
510 510
         $tpl = $this->getCFGDef('rowTpl', '@CODE:<li[+classes+]><a href="[+url+]">[+title+]</a></li>');
511
-        if (!empty($data['wrap'])) {
511
+        if (!empty($data['wrap'])) {
512 512
             $tpl = $this->getCFGDef('parentRowTpl',
513 513
                 '@CODE:<li[+classes+]><a href="[+url+]">[+title+]</a>[+wrap+]</li>');
514 514
             if ((isset($data['template']) && !$data['template']) || (isset($data['link_attributes']) && strpos($data['link_attributes'],
515 515
                         'category') !== false)
516
-            ) {
516
+            ) {
517 517
                 $tpl = $this->getCFGDef('categoryFolderTpl', $tpl);
518
-            } elseif (isset($data['here'])) {
518
+            } elseif (isset($data['here'])) {
519 519
                 $tpl = $this->getCFGDef('parentRowHereTpl', $tpl);
520
-            } elseif (isset($data['active'])) {
520
+            } elseif (isset($data['active'])) {
521 521
                 $tpl = $this->getCFGDef('parentRowActiveTpl', $tpl);
522 522
             }
523
-        } elseif ($data['level'] > 1) {
523
+        } elseif ($data['level'] > 1) {
524 524
             $tpl = $this->getCFGDef('innerRowTpl', $tpl);
525
-            if (isset($data['here'])) {
525
+            if (isset($data['here'])) {
526 526
                 $tpl = $this->getCFGDef('innerRowHereTpl', $tpl);
527 527
             }
528
-        } else {
529
-            if (isset($data['here'])) {
528
+        } else {
529
+            if (isset($data['here'])) {
530 530
                 $tpl = $this->getCFGDef('rowHereTpl', $tpl);
531 531
             }
532 532
         }
@@ -540,37 +540,37 @@  discard block
 block discarded – undo
540 540
      * @param array $array
541 541
      * @return string
542 542
      */
543
-    public function getJSON($data, $fields, $array = array())
544
-    {
543
+    public function getJSON($data, $fields, $array = array())
544
+    {
545 545
         $currentLevel = &$this->currentLevel;
546 546
         $currentLevel = count($this->levels);
547 547
         $docs = $this->levels;
548 548
 
549
-        if (empty($docs)) {
549
+        if (empty($docs)) {
550 550
             return '[]';
551 551
         }
552 552
 
553 553
         /** @var prepare_DL_Extender_ $extPrepare */
554 554
         $extPrepare = $this->getExtender('prepare');
555 555
 
556
-        while ($currentLevel > 0) {
557
-            foreach ($docs[$currentLevel] as $id => &$data) {
558
-                if ($out = $this->prepareData($data)) {
559
-                    if (is_array($out)) {
556
+        while ($currentLevel > 0) {
557
+            foreach ($docs[$currentLevel] as $id => &$data) {
558
+                if ($out = $this->prepareData($data)) {
559
+                    if (is_array($out)) {
560 560
                         $data = $out;
561 561
                     }
562 562
                 };
563 563
 
564
-                if (isset($data['here']) || isset($data['active'])) {
564
+                if (isset($data['here']) || isset($data['active'])) {
565 565
                     $docs[$currentLevel - 1][$data['parent']]['active'] = 1;
566 566
                 }
567 567
 
568
-                if ($extPrepare) {
568
+                if ($extPrepare) {
569 569
                     $data = $extPrepare->init($this, array(
570 570
                         'data'      => $data,
571 571
                         'nameParam' => 'prepare'
572 572
                     ));
573
-                    if (is_bool($data) && $data === false) {
573
+                    if (is_bool($data) && $data === false) {
574 574
                         continue;
575 575
                     }
576 576
                 }
@@ -578,7 +578,7 @@  discard block
 block discarded – undo
578 578
                 $hideSubMenus = $this->getCFGDef('hideSubMenus', 0);
579 579
                 $hideSubMenus = !$hideSubMenus || ($hideSubMenus && in_array((int)$data['parent'],
580 580
                             $this->activeBranch));
581
-                if ($hideSubMenus) {
581
+                if ($hideSubMenus) {
582 582
                     $docs[$currentLevel - 1][$data['parent']]['children'][] = $data;
583 583
                 }
584 584
             }
@@ -588,11 +588,11 @@  discard block
 block discarded – undo
588 588
         unset($data);
589 589
         $out = array();
590 590
         $joinMenus = $this->getCFGDef('joinMenus', 0) && !$this->getCFGDef('showParent', 0);
591
-        foreach ($docs[0] as $id => $data) {
592
-            if (isset($data['children'])) {
593
-                if ($joinMenus) {
591
+        foreach ($docs[0] as $id => $data) {
592
+            if (isset($data['children'])) {
593
+                if ($joinMenus) {
594 594
                     $out = array_merge($out, $data['children']);
595
-                } else {
595
+                } else {
596 596
                     $out[] = $data['children'];
597 597
                 }
598 598
             }
@@ -609,8 +609,8 @@  discard block
 block discarded – undo
609 609
      * @param mixed $def значение по умолчанию, если в конфиге нет искомого параметра
610 610
      * @return mixed значение из конфига
611 611
      */
612
-    public function getCFGDef($name, $def = null)
613
-    {
612
+    public function getCFGDef($name, $def = null)
613
+    {
614 614
         return parent::getCFGDef($name . $this->currentLevel, parent::getCFGDef($name, $def));
615 615
     }
616 616
 }
Please login to merge, or discard this patch.
assets/lib/Formatter/SqlFormatter.php 2 patches
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -757,15 +757,15 @@  discard block
 block discarded – undo
757 757
         self::$reserved = array_keys($reservedMap);
758 758
 
759 759
         // Set up regular expressions
760
-        self::$regex_boundaries = '(' . implode('|',
761
-                array_map(array(__CLASS__, 'quote_regex'), self::$boundaries)) . ')';
762
-        self::$regex_reserved = '(' . implode('|', array_map(array(__CLASS__, 'quote_regex'), self::$reserved)) . ')';
760
+        self::$regex_boundaries = '('.implode('|',
761
+                array_map(array(__CLASS__, 'quote_regex'), self::$boundaries)).')';
762
+        self::$regex_reserved = '('.implode('|', array_map(array(__CLASS__, 'quote_regex'), self::$reserved)).')';
763 763
         self::$regex_reserved_toplevel = str_replace(' ', '\\s+',
764
-            '(' . implode('|', array_map(array(__CLASS__, 'quote_regex'), self::$reserved_toplevel)) . ')');
764
+            '('.implode('|', array_map(array(__CLASS__, 'quote_regex'), self::$reserved_toplevel)).')');
765 765
         self::$regex_reserved_newline = str_replace(' ', '\\s+',
766
-            '(' . implode('|', array_map(array(__CLASS__, 'quote_regex'), self::$reserved_newline)) . ')');
766
+            '('.implode('|', array_map(array(__CLASS__, 'quote_regex'), self::$reserved_newline)).')');
767 767
 
768
-        self::$regex_function = '(' . implode('|', array_map(array(__CLASS__, 'quote_regex'), self::$functions)) . ')';
768
+        self::$regex_function = '('.implode('|', array_map(array(__CLASS__, 'quote_regex'), self::$functions)).')';
769 769
 
770 770
         self::$init = true;
771 771
     }
@@ -830,10 +830,10 @@  discard block
 block discarded – undo
830 830
 
831 831
             // If the variable name is quoted
832 832
             if ($string[1] === '"' || $string[1] === '\'' || $string[1] === '`') {
833
-                $ret[self::TOKEN_VALUE] = $string[0] . self::getQuotedString(substr($string, 1));
833
+                $ret[self::TOKEN_VALUE] = $string[0].self::getQuotedString(substr($string, 1));
834 834
             } // Non-quoted variable name
835 835
             else {
836
-                preg_match('/^(' . $string[0] . '[a-zA-Z0-9\._\$]+)/', $string, $matches);
836
+                preg_match('/^('.$string[0].'[a-zA-Z0-9\._\$]+)/', $string, $matches);
837 837
                 if (!empty($matches)) {
838 838
                     $ret[self::TOKEN_VALUE] = $matches[1];
839 839
                 }
@@ -845,7 +845,7 @@  discard block
 block discarded – undo
845 845
         }
846 846
 
847 847
         // Number (decimal, binary, or hex)
848
-        if (preg_match('/^([0-9]+(\.[0-9]+)?|0x[0-9a-fA-F]+|0b[01]+)($|\s|"\'`|' . self::$regex_boundaries . ')/',
848
+        if (preg_match('/^([0-9]+(\.[0-9]+)?|0x[0-9a-fA-F]+|0b[01]+)($|\s|"\'`|'.self::$regex_boundaries.')/',
849 849
             $string, $matches)) {
850 850
             return array(
851 851
                 self::TOKEN_VALUE => $matches[1],
@@ -854,7 +854,7 @@  discard block
 block discarded – undo
854 854
         }
855 855
 
856 856
         // Boundary Character (punctuation and symbols)
857
-        if (preg_match('/^(' . self::$regex_boundaries . ')/', $string, $matches)) {
857
+        if (preg_match('/^('.self::$regex_boundaries.')/', $string, $matches)) {
858 858
             return array(
859 859
                 self::TOKEN_VALUE => $matches[1],
860 860
                 self::TOKEN_TYPE  => self::TOKEN_TYPE_BOUNDARY
@@ -866,7 +866,7 @@  discard block
 block discarded – undo
866 866
         if (!$previous || !isset($previous[self::TOKEN_VALUE]) || $previous[self::TOKEN_VALUE] !== '.') {
867 867
             $upper = strtoupper($string);
868 868
             // Top Level Reserved Word
869
-            if (preg_match('/^(' . self::$regex_reserved_toplevel . ')($|\s|' . self::$regex_boundaries . ')/', $upper,
869
+            if (preg_match('/^('.self::$regex_reserved_toplevel.')($|\s|'.self::$regex_boundaries.')/', $upper,
870 870
                 $matches)) {
871 871
                 return array(
872 872
                     self::TOKEN_TYPE  => self::TOKEN_TYPE_RESERVED_TOPLEVEL,
@@ -874,7 +874,7 @@  discard block
 block discarded – undo
874 874
                 );
875 875
             }
876 876
             // Newline Reserved Word
877
-            if (preg_match('/^(' . self::$regex_reserved_newline . ')($|\s|' . self::$regex_boundaries . ')/', $upper,
877
+            if (preg_match('/^('.self::$regex_reserved_newline.')($|\s|'.self::$regex_boundaries.')/', $upper,
878 878
                 $matches)) {
879 879
                 return array(
880 880
                     self::TOKEN_TYPE  => self::TOKEN_TYPE_RESERVED_NEWLINE,
@@ -882,7 +882,7 @@  discard block
 block discarded – undo
882 882
                 );
883 883
             }
884 884
             // Other Reserved Word
885
-            if (preg_match('/^(' . self::$regex_reserved . ')($|\s|' . self::$regex_boundaries . ')/', $upper,
885
+            if (preg_match('/^('.self::$regex_reserved.')($|\s|'.self::$regex_boundaries.')/', $upper,
886 886
                 $matches)) {
887 887
                 return array(
888 888
                     self::TOKEN_TYPE  => self::TOKEN_TYPE_RESERVED,
@@ -895,7 +895,7 @@  discard block
 block discarded – undo
895 895
         // this makes it so "count(" is considered a function, but "count" alone is not
896 896
         $upper = strtoupper($string);
897 897
         // function
898
-        if (preg_match('/^(' . self::$regex_function . '[(]|\s|[)])/', $upper, $matches)) {
898
+        if (preg_match('/^('.self::$regex_function.'[(]|\s|[)])/', $upper, $matches)) {
899 899
             return array(
900 900
                 self::TOKEN_TYPE  => self::TOKEN_TYPE_RESERVED,
901 901
                 self::TOKEN_VALUE => substr($string, 0, strlen($matches[1]) - 1)
@@ -903,7 +903,7 @@  discard block
 block discarded – undo
903 903
         }
904 904
 
905 905
         // Non reserved word
906
-        preg_match('/^(.*?)($|\s|["\'`]|' . self::$regex_boundaries . ')/', $string, $matches);
906
+        preg_match('/^(.*?)($|\s|["\'`]|'.self::$regex_boundaries.')/', $string, $matches);
907 907
 
908 908
         return array(
909 909
             self::TOKEN_VALUE => $matches[1],
@@ -1065,7 +1065,7 @@  discard block
 block discarded – undo
1065 1065
 
1066 1066
             // If we need a new line before the token
1067 1067
             if ($newline) {
1068
-                $return .= "\n" . str_repeat($tab, $indent_level);
1068
+                $return .= "\n".str_repeat($tab, $indent_level);
1069 1069
                 $newline = false;
1070 1070
                 $added_newline = true;
1071 1071
             } else {
@@ -1076,8 +1076,8 @@  discard block
 block discarded – undo
1076 1076
             if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
1077 1077
                 if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
1078 1078
                     $indent = str_repeat($tab, $indent_level);
1079
-                    $return .= "\n" . $indent;
1080
-                    $highlighted = str_replace("\n", "\n" . $indent, $highlighted);
1079
+                    $return .= "\n".$indent;
1080
+                    $highlighted = str_replace("\n", "\n".$indent, $highlighted);
1081 1081
                 }
1082 1082
 
1083 1083
                 $return .= $highlighted;
@@ -1093,12 +1093,12 @@  discard block
 block discarded – undo
1093 1093
                     if ($inline_indented) {
1094 1094
                         array_shift($indent_types);
1095 1095
                         $indent_level--;
1096
-                        $return .= "\n" . str_repeat($tab, $indent_level);
1096
+                        $return .= "\n".str_repeat($tab, $indent_level);
1097 1097
                     }
1098 1098
 
1099 1099
                     $inline_parentheses = false;
1100 1100
 
1101
-                    $return .= $highlighted . ' ';
1101
+                    $return .= $highlighted.' ';
1102 1102
                     continue;
1103 1103
                 }
1104 1104
 
@@ -1185,14 +1185,14 @@  discard block
 block discarded – undo
1185 1185
                     $indent_level = 0;
1186 1186
 
1187 1187
                     if ($highlight) {
1188
-                        $return .= "\n" . self::highlightError($token[self::TOKEN_VALUE]);
1188
+                        $return .= "\n".self::highlightError($token[self::TOKEN_VALUE]);
1189 1189
                         continue;
1190 1190
                     }
1191 1191
                 }
1192 1192
 
1193 1193
                 // Add a newline before the closing parentheses (if not already added)
1194 1194
                 if (!$added_newline) {
1195
-                    $return .= "\n" . str_repeat($tab, $indent_level);
1195
+                    $return .= "\n".str_repeat($tab, $indent_level);
1196 1196
                 }
1197 1197
             } // Top level reserved words start a new line and increase the special indent level
1198 1198
             elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_TOPLEVEL) {
@@ -1209,10 +1209,10 @@  discard block
 block discarded – undo
1209 1209
                 $newline = true;
1210 1210
                 // Add a newline before the top level reserved word (if not already added)
1211 1211
                 if (!$added_newline) {
1212
-                    $return .= "\n" . str_repeat($tab, $indent_level);
1212
+                    $return .= "\n".str_repeat($tab, $indent_level);
1213 1213
                 } // If we already added a newline, redo the indentation since it may be different now
1214 1214
                 else {
1215
-                    $return = rtrim($return, $tab) . str_repeat($tab, $indent_level);
1215
+                    $return = rtrim($return, $tab).str_repeat($tab, $indent_level);
1216 1216
                 }
1217 1217
 
1218 1218
                 // If the token may have extra whitespace
@@ -1242,7 +1242,7 @@  discard block
 block discarded – undo
1242 1242
             elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE) {
1243 1243
                 // Add a newline before the reserved word (if not already added)
1244 1244
                 if (!$added_newline) {
1245
-                    $return .= "\n" . str_repeat($tab, $indent_level);
1245
+                    $return .= "\n".str_repeat($tab, $indent_level);
1246 1246
                 }
1247 1247
 
1248 1248
                 // If the token may have extra whitespace
@@ -1265,7 +1265,7 @@  discard block
 block discarded – undo
1265 1265
                 $return = rtrim($return, ' ');
1266 1266
             }
1267 1267
 
1268
-            $return .= $highlighted . ' ';
1268
+            $return .= $highlighted.' ';
1269 1269
 
1270 1270
             // If the token shouldn't have a space after it
1271 1271
             if ($token[self::TOKEN_VALUE] === '(' || $token[self::TOKEN_VALUE] === '.') {
@@ -1283,7 +1283,7 @@  discard block
 block discarded – undo
1283 1283
 
1284 1284
         // If there are unmatched parentheses
1285 1285
         if ($highlight && array_search('block', $indent_types) !== false) {
1286
-            $return .= "\n" . self::highlightError("WARNING: unclosed parentheses or section");
1286
+            $return .= "\n".self::highlightError("WARNING: unclosed parentheses or section");
1287 1287
         }
1288 1288
 
1289 1289
         // Replace tab characters with the configuration tab character
@@ -1336,7 +1336,7 @@  discard block
 block discarded – undo
1336 1336
             // If this is a query separator
1337 1337
             if ($token[self::TOKEN_VALUE] === ';') {
1338 1338
                 if (!$empty) {
1339
-                    $queries[] = $current_query . ';';
1339
+                    $queries[] = $current_query.';';
1340 1340
                 }
1341 1341
                 $current_query = '';
1342 1342
                 $empty = true;
@@ -1482,9 +1482,9 @@  discard block
 block discarded – undo
1482 1482
     protected static function highlightQuote($value)
1483 1483
     {
1484 1484
         if (self::is_cli()) {
1485
-            return self::$cli_quote . $value . "\x1b[0m";
1485
+            return self::$cli_quote.$value."\x1b[0m";
1486 1486
         } else {
1487
-            return '<span ' . self::$quote_attributes . '>' . $value . '</span>';
1487
+            return '<span '.self::$quote_attributes.'>'.$value.'</span>';
1488 1488
         }
1489 1489
     }
1490 1490
 
@@ -1498,9 +1498,9 @@  discard block
 block discarded – undo
1498 1498
     protected static function highlightBacktickQuote($value)
1499 1499
     {
1500 1500
         if (self::is_cli()) {
1501
-            return self::$cli_backtick_quote . $value . "\x1b[0m";
1501
+            return self::$cli_backtick_quote.$value."\x1b[0m";
1502 1502
         } else {
1503
-            return '<span ' . self::$backtick_quote_attributes . '>' . $value . '</span>';
1503
+            return '<span '.self::$backtick_quote_attributes.'>'.$value.'</span>';
1504 1504
         }
1505 1505
     }
1506 1506
 
@@ -1514,9 +1514,9 @@  discard block
 block discarded – undo
1514 1514
     protected static function highlightReservedWord($value)
1515 1515
     {
1516 1516
         if (self::is_cli()) {
1517
-            return self::$cli_reserved . $value . "\x1b[0m";
1517
+            return self::$cli_reserved.$value."\x1b[0m";
1518 1518
         } else {
1519
-            return '<span ' . self::$reserved_attributes . '>' . $value . '</span>';
1519
+            return '<span '.self::$reserved_attributes.'>'.$value.'</span>';
1520 1520
         }
1521 1521
     }
1522 1522
 
@@ -1534,9 +1534,9 @@  discard block
 block discarded – undo
1534 1534
         }
1535 1535
 
1536 1536
         if (self::is_cli()) {
1537
-            return self::$cli_boundary . $value . "\x1b[0m";
1537
+            return self::$cli_boundary.$value."\x1b[0m";
1538 1538
         } else {
1539
-            return '<span ' . self::$boundary_attributes . '>' . $value . '</span>';
1539
+            return '<span '.self::$boundary_attributes.'>'.$value.'</span>';
1540 1540
         }
1541 1541
     }
1542 1542
 
@@ -1550,9 +1550,9 @@  discard block
 block discarded – undo
1550 1550
     protected static function highlightNumber($value)
1551 1551
     {
1552 1552
         if (self::is_cli()) {
1553
-            return self::$cli_number . $value . "\x1b[0m";
1553
+            return self::$cli_number.$value."\x1b[0m";
1554 1554
         } else {
1555
-            return '<span ' . self::$number_attributes . '>' . $value . '</span>';
1555
+            return '<span '.self::$number_attributes.'>'.$value.'</span>';
1556 1556
         }
1557 1557
     }
1558 1558
 
@@ -1566,9 +1566,9 @@  discard block
 block discarded – undo
1566 1566
     protected static function highlightError($value)
1567 1567
     {
1568 1568
         if (self::is_cli()) {
1569
-            return self::$cli_error . $value . "\x1b[0m";
1569
+            return self::$cli_error.$value."\x1b[0m";
1570 1570
         } else {
1571
-            return '<span ' . self::$error_attributes . '>' . $value . '</span>';
1571
+            return '<span '.self::$error_attributes.'>'.$value.'</span>';
1572 1572
         }
1573 1573
     }
1574 1574
 
@@ -1582,9 +1582,9 @@  discard block
 block discarded – undo
1582 1582
     protected static function highlightComment($value)
1583 1583
     {
1584 1584
         if (self::is_cli()) {
1585
-            return self::$cli_comment . $value . "\x1b[0m";
1585
+            return self::$cli_comment.$value."\x1b[0m";
1586 1586
         } else {
1587
-            return '<span ' . self::$comment_attributes . '>' . $value . '</span>';
1587
+            return '<span '.self::$comment_attributes.'>'.$value.'</span>';
1588 1588
         }
1589 1589
     }
1590 1590
 
@@ -1598,9 +1598,9 @@  discard block
 block discarded – undo
1598 1598
     protected static function highlightWord($value)
1599 1599
     {
1600 1600
         if (self::is_cli()) {
1601
-            return self::$cli_word . $value . "\x1b[0m";
1601
+            return self::$cli_word.$value."\x1b[0m";
1602 1602
         } else {
1603
-            return '<span ' . self::$word_attributes . '>' . $value . '</span>';
1603
+            return '<span '.self::$word_attributes.'>'.$value.'</span>';
1604 1604
         }
1605 1605
     }
1606 1606
 
@@ -1614,9 +1614,9 @@  discard block
 block discarded – undo
1614 1614
     protected static function highlightVariable($value)
1615 1615
     {
1616 1616
         if (self::is_cli()) {
1617
-            return self::$cli_variable . $value . "\x1b[0m";
1617
+            return self::$cli_variable.$value."\x1b[0m";
1618 1618
         } else {
1619
-            return '<span ' . self::$variable_attributes . '>' . $value . '</span>';
1619
+            return '<span '.self::$variable_attributes.'>'.$value.'</span>';
1620 1620
         }
1621 1621
     }
1622 1622
 
@@ -1642,14 +1642,14 @@  discard block
 block discarded – undo
1642 1642
     private static function output($string)
1643 1643
     {
1644 1644
         if (self::is_cli()) {
1645
-            return $string . "\n";
1645
+            return $string."\n";
1646 1646
         } else {
1647 1647
             $string = trim($string);
1648 1648
             if (!self::$use_pre) {
1649 1649
                 return $string;
1650 1650
             }
1651 1651
 
1652
-            return '<pre ' . self::$pre_attributes . '>' . $string . '</pre>';
1652
+            return '<pre '.self::$pre_attributes.'>'.$string.'</pre>';
1653 1653
         }
1654 1654
     }
1655 1655
 
Please login to merge, or discard this patch.
Braces   +182 added lines, -182 removed lines patch added patch discarded remove patch
@@ -12,8 +12,8 @@  discard block
 block discarded – undo
12 12
  * @link       http://github.com/jdorn/sql-formatter
13 13
  * @version    1.2.18
14 14
  */
15
-class SqlFormatter
16
-{
15
+class SqlFormatter
16
+{
17 17
     // Constants for token types
18 18
     const TOKEN_TYPE_WHITESPACE = 0;
19 19
     const TOKEN_TYPE_WORD = 1;
@@ -732,8 +732,8 @@  discard block
 block discarded – undo
732 732
      * Get stats about the token cache
733 733
      * @return Array An array containing the keys 'hits', 'misses', 'entries', and 'size' in bytes
734 734
      */
735
-    public static function getCacheStats()
736
-    {
735
+    public static function getCacheStats()
736
+    {
737 737
         return array(
738 738
             'hits'    => self::$cache_hits,
739 739
             'misses'  => self::$cache_misses,
@@ -745,9 +745,9 @@  discard block
 block discarded – undo
745 745
     /**
746 746
      * Stuff that only needs to be done once.  Builds regular expressions and sorts the reserved words.
747 747
      */
748
-    protected static function init()
749
-    {
750
-        if (self::$init) {
748
+    protected static function init()
749
+    {
750
+        if (self::$init) {
751 751
             return;
752 752
         }
753 753
 
@@ -779,10 +779,10 @@  discard block
 block discarded – undo
779 779
      *
780 780
      * @return Array An associative array containing the type and value of the token.
781 781
      */
782
-    protected static function getNextToken($string, $previous = null)
783
-    {
782
+    protected static function getNextToken($string, $previous = null)
783
+    {
784 784
         // Whitespace
785
-        if (preg_match('/^\s+/', $string, $matches)) {
785
+        if (preg_match('/^\s+/', $string, $matches)) {
786 786
             return array(
787 787
                 self::TOKEN_VALUE => $matches[0],
788 788
                 self::TOKEN_TYPE  => self::TOKEN_TYPE_WHITESPACE
@@ -790,18 +790,18 @@  discard block
 block discarded – undo
790 790
         }
791 791
 
792 792
         // Comment
793
-        if ($string[0] === '#' || (isset($string[1]) && ($string[0] === '-' && $string[1] === '-') || ($string[0] === '/' && $string[1] === '*'))) {
793
+        if ($string[0] === '#' || (isset($string[1]) && ($string[0] === '-' && $string[1] === '-') || ($string[0] === '/' && $string[1] === '*'))) {
794 794
             // Comment until end of line
795
-            if ($string[0] === '-' || $string[0] === '#') {
795
+            if ($string[0] === '-' || $string[0] === '#') {
796 796
                 $last = strpos($string, "\n");
797 797
                 $type = self::TOKEN_TYPE_COMMENT;
798
-            } else {
798
+            } else {
799 799
 // Comment until closing comment tag
800 800
                 $last = strpos($string, "*/", 2) + 2;
801 801
                 $type = self::TOKEN_TYPE_BLOCK_COMMENT;
802 802
             }
803 803
 
804
-            if ($last === false) {
804
+            if ($last === false) {
805 805
                 $last = strlen($string);
806 806
             }
807 807
 
@@ -812,7 +812,7 @@  discard block
 block discarded – undo
812 812
         }
813 813
 
814 814
         // Quoted String
815
-        if ($string[0] === '"' || $string[0] === '\'' || $string[0] === '`' || $string[0] === '[') {
815
+        if ($string[0] === '"' || $string[0] === '\'' || $string[0] === '`' || $string[0] === '[') {
816 816
             $return = array(
817 817
                 self::TOKEN_TYPE  => (($string[0] === '`' || $string[0] === '[') ? self::TOKEN_TYPE_BACKTICK_QUOTE : self::TOKEN_TYPE_QUOTE),
818 818
                 self::TOKEN_VALUE => self::getQuotedString($string)
@@ -822,31 +822,31 @@  discard block
 block discarded – undo
822 822
         }
823 823
 
824 824
         // User-defined Variable
825
-        if (($string[0] === '@' || $string[0] === ':') && isset($string[1])) {
825
+        if (($string[0] === '@' || $string[0] === ':') && isset($string[1])) {
826 826
             $ret = array(
827 827
                 self::TOKEN_VALUE => null,
828 828
                 self::TOKEN_TYPE  => self::TOKEN_TYPE_VARIABLE
829 829
             );
830 830
 
831 831
             // If the variable name is quoted
832
-            if ($string[1] === '"' || $string[1] === '\'' || $string[1] === '`') {
832
+            if ($string[1] === '"' || $string[1] === '\'' || $string[1] === '`') {
833 833
                 $ret[self::TOKEN_VALUE] = $string[0] . self::getQuotedString(substr($string, 1));
834 834
             } // Non-quoted variable name
835
-            else {
835
+            else {
836 836
                 preg_match('/^(' . $string[0] . '[a-zA-Z0-9\._\$]+)/', $string, $matches);
837
-                if (!empty($matches)) {
837
+                if (!empty($matches)) {
838 838
                     $ret[self::TOKEN_VALUE] = $matches[1];
839 839
                 }
840 840
             }
841 841
 
842
-            if ($ret[self::TOKEN_VALUE] !== null) {
842
+            if ($ret[self::TOKEN_VALUE] !== null) {
843 843
                 return $ret;
844 844
             }
845 845
         }
846 846
 
847 847
         // Number (decimal, binary, or hex)
848 848
         if (preg_match('/^([0-9]+(\.[0-9]+)?|0x[0-9a-fA-F]+|0b[01]+)($|\s|"\'`|' . self::$regex_boundaries . ')/',
849
-            $string, $matches)) {
849
+            $string, $matches)) {
850 850
             return array(
851 851
                 self::TOKEN_VALUE => $matches[1],
852 852
                 self::TOKEN_TYPE  => self::TOKEN_TYPE_NUMBER
@@ -854,7 +854,7 @@  discard block
 block discarded – undo
854 854
         }
855 855
 
856 856
         // Boundary Character (punctuation and symbols)
857
-        if (preg_match('/^(' . self::$regex_boundaries . ')/', $string, $matches)) {
857
+        if (preg_match('/^(' . self::$regex_boundaries . ')/', $string, $matches)) {
858 858
             return array(
859 859
                 self::TOKEN_VALUE => $matches[1],
860 860
                 self::TOKEN_TYPE  => self::TOKEN_TYPE_BOUNDARY
@@ -863,11 +863,11 @@  discard block
 block discarded – undo
863 863
 
864 864
         // A reserved word cannot be preceded by a '.'
865 865
         // this makes it so in "mytable.from", "from" is not considered a reserved word
866
-        if (!$previous || !isset($previous[self::TOKEN_VALUE]) || $previous[self::TOKEN_VALUE] !== '.') {
866
+        if (!$previous || !isset($previous[self::TOKEN_VALUE]) || $previous[self::TOKEN_VALUE] !== '.') {
867 867
             $upper = strtoupper($string);
868 868
             // Top Level Reserved Word
869 869
             if (preg_match('/^(' . self::$regex_reserved_toplevel . ')($|\s|' . self::$regex_boundaries . ')/', $upper,
870
-                $matches)) {
870
+                $matches)) {
871 871
                 return array(
872 872
                     self::TOKEN_TYPE  => self::TOKEN_TYPE_RESERVED_TOPLEVEL,
873 873
                     self::TOKEN_VALUE => substr($string, 0, strlen($matches[1]))
@@ -875,7 +875,7 @@  discard block
 block discarded – undo
875 875
             }
876 876
             // Newline Reserved Word
877 877
             if (preg_match('/^(' . self::$regex_reserved_newline . ')($|\s|' . self::$regex_boundaries . ')/', $upper,
878
-                $matches)) {
878
+                $matches)) {
879 879
                 return array(
880 880
                     self::TOKEN_TYPE  => self::TOKEN_TYPE_RESERVED_NEWLINE,
881 881
                     self::TOKEN_VALUE => substr($string, 0, strlen($matches[1]))
@@ -883,7 +883,7 @@  discard block
 block discarded – undo
883 883
             }
884 884
             // Other Reserved Word
885 885
             if (preg_match('/^(' . self::$regex_reserved . ')($|\s|' . self::$regex_boundaries . ')/', $upper,
886
-                $matches)) {
886
+                $matches)) {
887 887
                 return array(
888 888
                     self::TOKEN_TYPE  => self::TOKEN_TYPE_RESERVED,
889 889
                     self::TOKEN_VALUE => substr($string, 0, strlen($matches[1]))
@@ -895,7 +895,7 @@  discard block
 block discarded – undo
895 895
         // this makes it so "count(" is considered a function, but "count" alone is not
896 896
         $upper = strtoupper($string);
897 897
         // function
898
-        if (preg_match('/^(' . self::$regex_function . '[(]|\s|[)])/', $upper, $matches)) {
898
+        if (preg_match('/^(' . self::$regex_function . '[(]|\s|[)])/', $upper, $matches)) {
899 899
             return array(
900 900
                 self::TOKEN_TYPE  => self::TOKEN_TYPE_RESERVED,
901 901
                 self::TOKEN_VALUE => substr($string, 0, strlen($matches[1]) - 1)
@@ -915,8 +915,8 @@  discard block
 block discarded – undo
915 915
      * @param $string
916 916
      * @return null
917 917
      */
918
-    protected static function getQuotedString($string)
919
-    {
918
+    protected static function getQuotedString($string)
919
+    {
920 920
         $ret = null;
921 921
 
922 922
         // This checks for the following patterns:
@@ -925,7 +925,7 @@  discard block
 block discarded – undo
925 925
         // 3. double quoted string using "" or \" to escape
926 926
         // 4. single quoted string using '' or \' to escape
927 927
         if (preg_match('/^(((`[^`]*($|`))+)|((\[[^\]]*($|\]))(\][^\]]*($|\]))*)|(("[^"\\\\]*(?:\\\\.[^"\\\\]*)*("|$))+)|((\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*(\'|$))+))/s',
928
-            $string, $matches)) {
928
+            $string, $matches)) {
929 929
             $ret = $matches[1];
930 930
         }
931 931
 
@@ -940,8 +940,8 @@  discard block
 block discarded – undo
940 940
      *
941 941
      * @return Array An array of tokens.
942 942
      */
943
-    protected static function tokenize($string)
944
-    {
943
+    protected static function tokenize($string)
944
+    {
945 945
         self::init();
946 946
 
947 947
         $tokens = array();
@@ -954,9 +954,9 @@  discard block
 block discarded – undo
954 954
         $current_length = strlen($string);
955 955
 
956 956
         // Keep processing the string until it is empty
957
-        while ($current_length) {
957
+        while ($current_length) {
958 958
             // If the string stopped shrinking, there was a problem
959
-            if ($old_string_len <= $current_length) {
959
+            if ($old_string_len <= $current_length) {
960 960
                 $tokens[] = array(
961 961
                     self::TOKEN_VALUE => $string,
962 962
                     self::TOKEN_TYPE  => self::TOKEN_TYPE_ERROR
@@ -967,26 +967,26 @@  discard block
 block discarded – undo
967 967
             $old_string_len = $current_length;
968 968
 
969 969
             // Determine if we can use caching
970
-            if ($current_length >= self::$max_cachekey_size) {
970
+            if ($current_length >= self::$max_cachekey_size) {
971 971
                 $cacheKey = substr($string, 0, self::$max_cachekey_size);
972
-            } else {
972
+            } else {
973 973
                 $cacheKey = false;
974 974
             }
975 975
 
976 976
             // See if the token is already cached
977
-            if ($cacheKey !== false && isset(self::$token_cache[$cacheKey])) {
977
+            if ($cacheKey !== false && isset(self::$token_cache[$cacheKey])) {
978 978
                 // Retrieve from cache
979 979
                 $token = self::$token_cache[$cacheKey];
980 980
                 $token_length = strlen($token[self::TOKEN_VALUE]);
981 981
                 self::$cache_hits++;
982
-            } else {
982
+            } else {
983 983
                 // Get the next token and the token type
984 984
                 $token = self::getNextToken($string, $token);
985 985
                 $token_length = strlen($token[self::TOKEN_VALUE]);
986 986
                 self::$cache_misses++;
987 987
 
988 988
                 // If the token is shorter than the max length, store it in cache
989
-                if ($cacheKey !== false && $token_length < self::$max_cachekey_size) {
989
+                if ($cacheKey !== false && $token_length < self::$max_cachekey_size) {
990 990
                     self::$token_cache[$cacheKey] = $token;
991 991
                 }
992 992
             }
@@ -1010,8 +1010,8 @@  discard block
 block discarded – undo
1010 1010
      *
1011 1011
      * @return String The SQL string with HTML styles and formatting wrapped in a <pre> tag
1012 1012
      */
1013
-    public static function format($string, $highlight = true)
1014
-    {
1013
+    public static function format($string, $highlight = true)
1014
+    {
1015 1015
         // This variable will be populated with formatted html
1016 1016
         $return = '';
1017 1017
 
@@ -1033,48 +1033,48 @@  discard block
 block discarded – undo
1033 1033
 
1034 1034
         // Remove existing whitespace
1035 1035
         $tokens = array();
1036
-        foreach ($original_tokens as $i => $token) {
1037
-            if ($token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
1036
+        foreach ($original_tokens as $i => $token) {
1037
+            if ($token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
1038 1038
                 $token['i'] = $i;
1039 1039
                 $tokens[] = $token;
1040 1040
             }
1041 1041
         }
1042 1042
 
1043 1043
         // Format token by token
1044
-        foreach ($tokens as $i => $token) {
1044
+        foreach ($tokens as $i => $token) {
1045 1045
             // Get highlighted token if doing syntax highlighting
1046
-            if ($highlight) {
1046
+            if ($highlight) {
1047 1047
                 $highlighted = self::highlightToken($token);
1048
-            } else {
1048
+            } else {
1049 1049
 // If returning raw text
1050 1050
                 $highlighted = $token[self::TOKEN_VALUE];
1051 1051
             }
1052 1052
 
1053 1053
             // If we are increasing the special indent level now
1054
-            if ($increase_special_indent) {
1054
+            if ($increase_special_indent) {
1055 1055
                 $indent_level++;
1056 1056
                 $increase_special_indent = false;
1057 1057
                 array_unshift($indent_types, 'special');
1058 1058
             }
1059 1059
             // If we are increasing the block indent level now
1060
-            if ($increase_block_indent) {
1060
+            if ($increase_block_indent) {
1061 1061
                 $indent_level++;
1062 1062
                 $increase_block_indent = false;
1063 1063
                 array_unshift($indent_types, 'block');
1064 1064
             }
1065 1065
 
1066 1066
             // If we need a new line before the token
1067
-            if ($newline) {
1067
+            if ($newline) {
1068 1068
                 $return .= "\n" . str_repeat($tab, $indent_level);
1069 1069
                 $newline = false;
1070 1070
                 $added_newline = true;
1071
-            } else {
1071
+            } else {
1072 1072
                 $added_newline = false;
1073 1073
             }
1074 1074
 
1075 1075
             // Display comments directly where they appear in the source
1076
-            if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
1077
-                if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
1076
+            if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
1077
+                if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
1078 1078
                     $indent = str_repeat($tab, $indent_level);
1079 1079
                     $return .= "\n" . $indent;
1080 1080
                     $highlighted = str_replace("\n", "\n" . $indent, $highlighted);
@@ -1085,12 +1085,12 @@  discard block
 block discarded – undo
1085 1085
                 continue;
1086 1086
             }
1087 1087
 
1088
-            if ($inline_parentheses) {
1088
+            if ($inline_parentheses) {
1089 1089
                 // End of inline parentheses
1090
-                if ($token[self::TOKEN_VALUE] === ')') {
1090
+                if ($token[self::TOKEN_VALUE] === ')') {
1091 1091
                     $return = rtrim($return, ' ');
1092 1092
 
1093
-                    if ($inline_indented) {
1093
+                    if ($inline_indented) {
1094 1094
                         array_shift($indent_types);
1095 1095
                         $indent_level--;
1096 1096
                         $return .= "\n" . str_repeat($tab, $indent_level);
@@ -1102,8 +1102,8 @@  discard block
 block discarded – undo
1102 1102
                     continue;
1103 1103
                 }
1104 1104
 
1105
-                if ($token[self::TOKEN_VALUE] === ',') {
1106
-                    if ($inline_count >= 30) {
1105
+                if ($token[self::TOKEN_VALUE] === ',') {
1106
+                    if ($inline_count >= 30) {
1107 1107
                         $inline_count = 0;
1108 1108
                         $newline = true;
1109 1109
                     }
@@ -1113,21 +1113,21 @@  discard block
 block discarded – undo
1113 1113
             }
1114 1114
 
1115 1115
             // Opening parentheses increase the block indent level and start a new line
1116
-            if ($token[self::TOKEN_VALUE] === '(') {
1116
+            if ($token[self::TOKEN_VALUE] === '(') {
1117 1117
                 // First check if this should be an inline parentheses block
1118 1118
                 // Examples are "NOW()", "COUNT(*)", "int(10)", key(`somecolumn`), DECIMAL(7,2)
1119 1119
                 // Allow up to 3 non-whitespace tokens inside inline parentheses
1120 1120
                 $length = 0;
1121
-                for ($j = 1; $j <= 250; $j++) {
1121
+                for ($j = 1; $j <= 250; $j++) {
1122 1122
                     // Reached end of string
1123
-                    if (!isset($tokens[$i + $j])) {
1123
+                    if (!isset($tokens[$i + $j])) {
1124 1124
                         break;
1125 1125
                     }
1126 1126
 
1127 1127
                     $next = $tokens[$i + $j];
1128 1128
 
1129 1129
                     // Reached closing parentheses, able to inline it
1130
-                    if ($next[self::TOKEN_VALUE] === ')') {
1130
+                    if ($next[self::TOKEN_VALUE] === ')') {
1131 1131
                         $inline_parentheses = true;
1132 1132
                         $inline_count = 0;
1133 1133
                         $inline_indented = false;
@@ -1135,72 +1135,72 @@  discard block
 block discarded – undo
1135 1135
                     }
1136 1136
 
1137 1137
                     // Reached an invalid token for inline parentheses
1138
-                    if ($next[self::TOKEN_VALUE] === ';' || $next[self::TOKEN_VALUE] === '(') {
1138
+                    if ($next[self::TOKEN_VALUE] === ';' || $next[self::TOKEN_VALUE] === '(') {
1139 1139
                         break;
1140 1140
                     }
1141 1141
 
1142 1142
                     // Reached an invalid token type for inline parentheses
1143
-                    if ($next[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_TOPLEVEL || $next[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE || $next[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $next[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
1143
+                    if ($next[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_TOPLEVEL || $next[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE || $next[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $next[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
1144 1144
                         break;
1145 1145
                     }
1146 1146
 
1147 1147
                     $length += strlen($next[self::TOKEN_VALUE]);
1148 1148
                 }
1149 1149
 
1150
-                if ($inline_parentheses && $length > 30) {
1150
+                if ($inline_parentheses && $length > 30) {
1151 1151
                     $increase_block_indent = true;
1152 1152
                     $inline_indented = true;
1153 1153
                     $newline = true;
1154 1154
                 }
1155 1155
 
1156 1156
                 // Take out the preceding space unless there was whitespace there in the original query
1157
-                if (isset($original_tokens[$token['i'] - 1]) && $original_tokens[$token['i'] - 1][self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
1157
+                if (isset($original_tokens[$token['i'] - 1]) && $original_tokens[$token['i'] - 1][self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
1158 1158
                     $return = rtrim($return, ' ');
1159 1159
                 }
1160 1160
 
1161
-                if (!$inline_parentheses) {
1161
+                if (!$inline_parentheses) {
1162 1162
                     $increase_block_indent = true;
1163 1163
                     // Add a newline after the parentheses
1164 1164
                     $newline = true;
1165 1165
                 }
1166 1166
 
1167 1167
             } // Closing parentheses decrease the block indent level
1168
-            elseif ($token[self::TOKEN_VALUE] === ')') {
1168
+            elseif ($token[self::TOKEN_VALUE] === ')') {
1169 1169
                 // Remove whitespace before the closing parentheses
1170 1170
                 $return = rtrim($return, ' ');
1171 1171
 
1172 1172
                 $indent_level--;
1173 1173
 
1174 1174
                 // Reset indent level
1175
-                while ($j = array_shift($indent_types)) {
1176
-                    if ($j === 'special') {
1175
+                while ($j = array_shift($indent_types)) {
1176
+                    if ($j === 'special') {
1177 1177
                         $indent_level--;
1178
-                    } else {
1178
+                    } else {
1179 1179
                         break;
1180 1180
                     }
1181 1181
                 }
1182 1182
 
1183
-                if ($indent_level < 0) {
1183
+                if ($indent_level < 0) {
1184 1184
                     // This is an error
1185 1185
                     $indent_level = 0;
1186 1186
 
1187
-                    if ($highlight) {
1187
+                    if ($highlight) {
1188 1188
                         $return .= "\n" . self::highlightError($token[self::TOKEN_VALUE]);
1189 1189
                         continue;
1190 1190
                     }
1191 1191
                 }
1192 1192
 
1193 1193
                 // Add a newline before the closing parentheses (if not already added)
1194
-                if (!$added_newline) {
1194
+                if (!$added_newline) {
1195 1195
                     $return .= "\n" . str_repeat($tab, $indent_level);
1196 1196
                 }
1197 1197
             } // Top level reserved words start a new line and increase the special indent level
1198
-            elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_TOPLEVEL) {
1198
+            elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_TOPLEVEL) {
1199 1199
                 $increase_special_indent = true;
1200 1200
 
1201 1201
                 // If the last indent type was 'special', decrease the special indent for this round
1202 1202
                 reset($indent_types);
1203
-                if (current($indent_types) === 'special') {
1203
+                if (current($indent_types) === 'special') {
1204 1204
                     $indent_level--;
1205 1205
                     array_shift($indent_types);
1206 1206
                 }
@@ -1208,88 +1208,88 @@  discard block
 block discarded – undo
1208 1208
                 // Add a newline after the top level reserved word
1209 1209
                 $newline = true;
1210 1210
                 // Add a newline before the top level reserved word (if not already added)
1211
-                if (!$added_newline) {
1211
+                if (!$added_newline) {
1212 1212
                     $return .= "\n" . str_repeat($tab, $indent_level);
1213 1213
                 } // If we already added a newline, redo the indentation since it may be different now
1214
-                else {
1214
+                else {
1215 1215
                     $return = rtrim($return, $tab) . str_repeat($tab, $indent_level);
1216 1216
                 }
1217 1217
 
1218 1218
                 // If the token may have extra whitespace
1219 1219
                 if (strpos($token[self::TOKEN_VALUE], ' ') !== false || strpos($token[self::TOKEN_VALUE],
1220 1220
                         "\n") !== false || strpos($token[self::TOKEN_VALUE], "\t") !== false
1221
-                ) {
1221
+                ) {
1222 1222
                     $highlighted = preg_replace('/\s+/', ' ', $highlighted);
1223 1223
                 }
1224 1224
                 //if SQL 'LIMIT' clause, start variable to reset newline
1225
-                if ($token[self::TOKEN_VALUE] === 'LIMIT' && !$inline_parentheses) {
1225
+                if ($token[self::TOKEN_VALUE] === 'LIMIT' && !$inline_parentheses) {
1226 1226
                     $clause_limit = true;
1227 1227
                 }
1228 1228
             } // Checks if we are out of the limit clause
1229
-            elseif ($clause_limit && $token[self::TOKEN_VALUE] !== "," && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_NUMBER && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
1229
+            elseif ($clause_limit && $token[self::TOKEN_VALUE] !== "," && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_NUMBER && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
1230 1230
                 $clause_limit = false;
1231 1231
             } // Commas start a new line (unless within inline parentheses or SQL 'LIMIT' clause)
1232
-            elseif ($token[self::TOKEN_VALUE] === ',' && !$inline_parentheses) {
1232
+            elseif ($token[self::TOKEN_VALUE] === ',' && !$inline_parentheses) {
1233 1233
                 //If the previous TOKEN_VALUE is 'LIMIT', resets new line
1234
-                if ($clause_limit === true) {
1234
+                if ($clause_limit === true) {
1235 1235
                     $newline = false;
1236 1236
                     $clause_limit = false;
1237 1237
                 } // All other cases of commas
1238
-                else {
1238
+                else {
1239 1239
                     $newline = true;
1240 1240
                 }
1241 1241
             } // Newline reserved words start a new line
1242
-            elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE) {
1242
+            elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE) {
1243 1243
                 // Add a newline before the reserved word (if not already added)
1244
-                if (!$added_newline) {
1244
+                if (!$added_newline) {
1245 1245
                     $return .= "\n" . str_repeat($tab, $indent_level);
1246 1246
                 }
1247 1247
 
1248 1248
                 // If the token may have extra whitespace
1249 1249
                 if (strpos($token[self::TOKEN_VALUE], ' ') !== false || strpos($token[self::TOKEN_VALUE],
1250 1250
                         "\n") !== false || strpos($token[self::TOKEN_VALUE], "\t") !== false
1251
-                ) {
1251
+                ) {
1252 1252
                     $highlighted = preg_replace('/\s+/', ' ', $highlighted);
1253 1253
                 }
1254 1254
             } // Multiple boundary characters in a row should not have spaces between them (not including parentheses)
1255
-            elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BOUNDARY) {
1256
-                if (isset($tokens[$i - 1]) && $tokens[$i - 1][self::TOKEN_TYPE] === self::TOKEN_TYPE_BOUNDARY) {
1257
-                    if (isset($original_tokens[$token['i'] - 1]) && $original_tokens[$token['i'] - 1][self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
1255
+            elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BOUNDARY) {
1256
+                if (isset($tokens[$i - 1]) && $tokens[$i - 1][self::TOKEN_TYPE] === self::TOKEN_TYPE_BOUNDARY) {
1257
+                    if (isset($original_tokens[$token['i'] - 1]) && $original_tokens[$token['i'] - 1][self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
1258 1258
                         $return = rtrim($return, ' ');
1259 1259
                     }
1260 1260
                 }
1261 1261
             }
1262 1262
 
1263 1263
             // If the token shouldn't have a space before it
1264
-            if ($token[self::TOKEN_VALUE] === '.' || $token[self::TOKEN_VALUE] === ',' || $token[self::TOKEN_VALUE] === ';') {
1264
+            if ($token[self::TOKEN_VALUE] === '.' || $token[self::TOKEN_VALUE] === ',' || $token[self::TOKEN_VALUE] === ';') {
1265 1265
                 $return = rtrim($return, ' ');
1266 1266
             }
1267 1267
 
1268 1268
             $return .= $highlighted . ' ';
1269 1269
 
1270 1270
             // If the token shouldn't have a space after it
1271
-            if ($token[self::TOKEN_VALUE] === '(' || $token[self::TOKEN_VALUE] === '.') {
1271
+            if ($token[self::TOKEN_VALUE] === '(' || $token[self::TOKEN_VALUE] === '.') {
1272 1272
                 $return = rtrim($return, ' ');
1273 1273
             }
1274 1274
 
1275 1275
             // If this is the "-" of a negative number, it shouldn't have a space after it
1276
-            if ($token[self::TOKEN_VALUE] === '-' && isset($tokens[$i + 1]) && $tokens[$i + 1][self::TOKEN_TYPE] === self::TOKEN_TYPE_NUMBER && isset($tokens[$i - 1])) {
1276
+            if ($token[self::TOKEN_VALUE] === '-' && isset($tokens[$i + 1]) && $tokens[$i + 1][self::TOKEN_TYPE] === self::TOKEN_TYPE_NUMBER && isset($tokens[$i - 1])) {
1277 1277
                 $prev = $tokens[$i - 1][self::TOKEN_TYPE];
1278
-                if ($prev !== self::TOKEN_TYPE_QUOTE && $prev !== self::TOKEN_TYPE_BACKTICK_QUOTE && $prev !== self::TOKEN_TYPE_WORD && $prev !== self::TOKEN_TYPE_NUMBER) {
1278
+                if ($prev !== self::TOKEN_TYPE_QUOTE && $prev !== self::TOKEN_TYPE_BACKTICK_QUOTE && $prev !== self::TOKEN_TYPE_WORD && $prev !== self::TOKEN_TYPE_NUMBER) {
1279 1279
                     $return = rtrim($return, ' ');
1280 1280
                 }
1281 1281
             }
1282 1282
         }
1283 1283
 
1284 1284
         // If there are unmatched parentheses
1285
-        if ($highlight && array_search('block', $indent_types) !== false) {
1285
+        if ($highlight && array_search('block', $indent_types) !== false) {
1286 1286
             $return .= "\n" . self::highlightError("WARNING: unclosed parentheses or section");
1287 1287
         }
1288 1288
 
1289 1289
         // Replace tab characters with the configuration tab character
1290 1290
         $return = trim(str_replace("\t", self::$tab, $return));
1291 1291
 
1292
-        if ($highlight) {
1292
+        if ($highlight) {
1293 1293
             $return = self::output($return);
1294 1294
         }
1295 1295
 
@@ -1303,13 +1303,13 @@  discard block
 block discarded – undo
1303 1303
      *
1304 1304
      * @return String The SQL string with HTML styles applied
1305 1305
      */
1306
-    public static function highlight($string)
1307
-    {
1306
+    public static function highlight($string)
1307
+    {
1308 1308
         $tokens = self::tokenize($string);
1309 1309
 
1310 1310
         $return = '';
1311 1311
 
1312
-        foreach ($tokens as $token) {
1312
+        foreach ($tokens as $token) {
1313 1313
             $return .= self::highlightToken($token);
1314 1314
         }
1315 1315
 
@@ -1324,18 +1324,18 @@  discard block
 block discarded – undo
1324 1324
      *
1325 1325
      * @return Array An array of individual query strings without trailing semicolons
1326 1326
      */
1327
-    public static function splitQuery($string)
1328
-    {
1327
+    public static function splitQuery($string)
1328
+    {
1329 1329
         $queries = array();
1330 1330
         $current_query = '';
1331 1331
         $empty = true;
1332 1332
 
1333 1333
         $tokens = self::tokenize($string);
1334 1334
 
1335
-        foreach ($tokens as $token) {
1335
+        foreach ($tokens as $token) {
1336 1336
             // If this is a query separator
1337
-            if ($token[self::TOKEN_VALUE] === ';') {
1338
-                if (!$empty) {
1337
+            if ($token[self::TOKEN_VALUE] === ';') {
1338
+                if (!$empty) {
1339 1339
                     $queries[] = $current_query . ';';
1340 1340
                 }
1341 1341
                 $current_query = '';
@@ -1344,14 +1344,14 @@  discard block
 block discarded – undo
1344 1344
             }
1345 1345
 
1346 1346
             // If this is a non-empty character
1347
-            if ($token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_COMMENT && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_BLOCK_COMMENT) {
1347
+            if ($token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_COMMENT && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_BLOCK_COMMENT) {
1348 1348
                 $empty = false;
1349 1349
             }
1350 1350
 
1351 1351
             $current_query .= $token[self::TOKEN_VALUE];
1352 1352
         }
1353 1353
 
1354
-        if (!$empty) {
1354
+        if (!$empty) {
1355 1355
             $queries[] = trim($current_query);
1356 1356
         }
1357 1357
 
@@ -1365,15 +1365,15 @@  discard block
 block discarded – undo
1365 1365
      *
1366 1366
      * @return String The SQL string without comments
1367 1367
      */
1368
-    public static function removeComments($string)
1369
-    {
1368
+    public static function removeComments($string)
1369
+    {
1370 1370
         $result = '';
1371 1371
 
1372 1372
         $tokens = self::tokenize($string);
1373 1373
 
1374
-        foreach ($tokens as $token) {
1374
+        foreach ($tokens as $token) {
1375 1375
             // Skip comment tokens
1376
-            if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
1376
+            if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
1377 1377
                 continue;
1378 1378
             }
1379 1379
 
@@ -1391,32 +1391,32 @@  discard block
 block discarded – undo
1391 1391
      *
1392 1392
      * @return String The SQL string without comments
1393 1393
      */
1394
-    public static function compress($string)
1395
-    {
1394
+    public static function compress($string)
1395
+    {
1396 1396
         $result = '';
1397 1397
 
1398 1398
         $tokens = self::tokenize($string);
1399 1399
 
1400 1400
         $whitespace = true;
1401
-        foreach ($tokens as $token) {
1401
+        foreach ($tokens as $token) {
1402 1402
             // Skip comment tokens
1403
-            if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
1403
+            if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
1404 1404
                 continue;
1405 1405
             } // Remove extra whitespace in reserved words (e.g "OUTER     JOIN" becomes "OUTER JOIN")
1406
-            elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_TOPLEVEL) {
1406
+            elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_TOPLEVEL) {
1407 1407
                 $token[self::TOKEN_VALUE] = preg_replace('/\s+/', ' ', $token[self::TOKEN_VALUE]);
1408 1408
             }
1409 1409
 
1410
-            if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_WHITESPACE) {
1410
+            if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_WHITESPACE) {
1411 1411
                 // If the last token was whitespace, don't add another one
1412
-                if ($whitespace) {
1412
+                if ($whitespace) {
1413 1413
                     continue;
1414
-                } else {
1414
+                } else {
1415 1415
                     $whitespace = true;
1416 1416
                     // Convert all whitespace to a single space
1417 1417
                     $token[self::TOKEN_VALUE] = ' ';
1418 1418
                 }
1419
-            } else {
1419
+            } else {
1420 1420
                 $whitespace = false;
1421 1421
             }
1422 1422
 
@@ -1433,39 +1433,39 @@  discard block
 block discarded – undo
1433 1433
      *
1434 1434
      * @return String HTML code of the highlighted token.
1435 1435
      */
1436
-    protected static function highlightToken($token)
1437
-    {
1436
+    protected static function highlightToken($token)
1437
+    {
1438 1438
         $type = $token[self::TOKEN_TYPE];
1439 1439
 
1440
-        if (self::is_cli()) {
1440
+        if (self::is_cli()) {
1441 1441
             $token = $token[self::TOKEN_VALUE];
1442
-        } else {
1443
-            if (defined('ENT_IGNORE')) {
1442
+        } else {
1443
+            if (defined('ENT_IGNORE')) {
1444 1444
                 $token = htmlentities($token[self::TOKEN_VALUE], ENT_COMPAT | ENT_IGNORE, 'UTF-8');
1445
-            } else {
1445
+            } else {
1446 1446
                 $token = htmlentities($token[self::TOKEN_VALUE], ENT_COMPAT, 'UTF-8');
1447 1447
             }
1448 1448
         }
1449 1449
 
1450
-        if ($type === self::TOKEN_TYPE_BOUNDARY) {
1450
+        if ($type === self::TOKEN_TYPE_BOUNDARY) {
1451 1451
             return self::highlightBoundary($token);
1452
-        } elseif ($type === self::TOKEN_TYPE_WORD) {
1452
+        } elseif ($type === self::TOKEN_TYPE_WORD) {
1453 1453
             return self::highlightWord($token);
1454
-        } elseif ($type === self::TOKEN_TYPE_BACKTICK_QUOTE) {
1454
+        } elseif ($type === self::TOKEN_TYPE_BACKTICK_QUOTE) {
1455 1455
             return self::highlightBacktickQuote($token);
1456
-        } elseif ($type === self::TOKEN_TYPE_QUOTE) {
1456
+        } elseif ($type === self::TOKEN_TYPE_QUOTE) {
1457 1457
             return self::highlightQuote($token);
1458
-        } elseif ($type === self::TOKEN_TYPE_RESERVED) {
1458
+        } elseif ($type === self::TOKEN_TYPE_RESERVED) {
1459 1459
             return self::highlightReservedWord($token);
1460
-        } elseif ($type === self::TOKEN_TYPE_RESERVED_TOPLEVEL) {
1460
+        } elseif ($type === self::TOKEN_TYPE_RESERVED_TOPLEVEL) {
1461 1461
             return self::highlightReservedWord($token);
1462
-        } elseif ($type === self::TOKEN_TYPE_RESERVED_NEWLINE) {
1462
+        } elseif ($type === self::TOKEN_TYPE_RESERVED_NEWLINE) {
1463 1463
             return self::highlightReservedWord($token);
1464
-        } elseif ($type === self::TOKEN_TYPE_NUMBER) {
1464
+        } elseif ($type === self::TOKEN_TYPE_NUMBER) {
1465 1465
             return self::highlightNumber($token);
1466
-        } elseif ($type === self::TOKEN_TYPE_VARIABLE) {
1466
+        } elseif ($type === self::TOKEN_TYPE_VARIABLE) {
1467 1467
             return self::highlightVariable($token);
1468
-        } elseif ($type === self::TOKEN_TYPE_COMMENT || $type === self::TOKEN_TYPE_BLOCK_COMMENT) {
1468
+        } elseif ($type === self::TOKEN_TYPE_COMMENT || $type === self::TOKEN_TYPE_BLOCK_COMMENT) {
1469 1469
             return self::highlightComment($token);
1470 1470
         }
1471 1471
 
@@ -1479,11 +1479,11 @@  discard block
 block discarded – undo
1479 1479
      *
1480 1480
      * @return String HTML code of the highlighted token.
1481 1481
      */
1482
-    protected static function highlightQuote($value)
1483
-    {
1484
-        if (self::is_cli()) {
1482
+    protected static function highlightQuote($value)
1483
+    {
1484
+        if (self::is_cli()) {
1485 1485
             return self::$cli_quote . $value . "\x1b[0m";
1486
-        } else {
1486
+        } else {
1487 1487
             return '<span ' . self::$quote_attributes . '>' . $value . '</span>';
1488 1488
         }
1489 1489
     }
@@ -1495,11 +1495,11 @@  discard block
 block discarded – undo
1495 1495
      *
1496 1496
      * @return String HTML code of the highlighted token.
1497 1497
      */
1498
-    protected static function highlightBacktickQuote($value)
1499
-    {
1500
-        if (self::is_cli()) {
1498
+    protected static function highlightBacktickQuote($value)
1499
+    {
1500
+        if (self::is_cli()) {
1501 1501
             return self::$cli_backtick_quote . $value . "\x1b[0m";
1502
-        } else {
1502
+        } else {
1503 1503
             return '<span ' . self::$backtick_quote_attributes . '>' . $value . '</span>';
1504 1504
         }
1505 1505
     }
@@ -1511,11 +1511,11 @@  discard block
 block discarded – undo
1511 1511
      *
1512 1512
      * @return String HTML code of the highlighted token.
1513 1513
      */
1514
-    protected static function highlightReservedWord($value)
1515
-    {
1516
-        if (self::is_cli()) {
1514
+    protected static function highlightReservedWord($value)
1515
+    {
1516
+        if (self::is_cli()) {
1517 1517
             return self::$cli_reserved . $value . "\x1b[0m";
1518
-        } else {
1518
+        } else {
1519 1519
             return '<span ' . self::$reserved_attributes . '>' . $value . '</span>';
1520 1520
         }
1521 1521
     }
@@ -1527,15 +1527,15 @@  discard block
 block discarded – undo
1527 1527
      *
1528 1528
      * @return String HTML code of the highlighted token.
1529 1529
      */
1530
-    protected static function highlightBoundary($value)
1531
-    {
1532
-        if ($value === '(' || $value === ')') {
1530
+    protected static function highlightBoundary($value)
1531
+    {
1532
+        if ($value === '(' || $value === ')') {
1533 1533
             return $value;
1534 1534
         }
1535 1535
 
1536
-        if (self::is_cli()) {
1536
+        if (self::is_cli()) {
1537 1537
             return self::$cli_boundary . $value . "\x1b[0m";
1538
-        } else {
1538
+        } else {
1539 1539
             return '<span ' . self::$boundary_attributes . '>' . $value . '</span>';
1540 1540
         }
1541 1541
     }
@@ -1547,11 +1547,11 @@  discard block
 block discarded – undo
1547 1547
      *
1548 1548
      * @return String HTML code of the highlighted token.
1549 1549
      */
1550
-    protected static function highlightNumber($value)
1551
-    {
1552
-        if (self::is_cli()) {
1550
+    protected static function highlightNumber($value)
1551
+    {
1552
+        if (self::is_cli()) {
1553 1553
             return self::$cli_number . $value . "\x1b[0m";
1554
-        } else {
1554
+        } else {
1555 1555
             return '<span ' . self::$number_attributes . '>' . $value . '</span>';
1556 1556
         }
1557 1557
     }
@@ -1563,11 +1563,11 @@  discard block
 block discarded – undo
1563 1563
      *
1564 1564
      * @return String HTML code of the highlighted token.
1565 1565
      */
1566
-    protected static function highlightError($value)
1567
-    {
1568
-        if (self::is_cli()) {
1566
+    protected static function highlightError($value)
1567
+    {
1568
+        if (self::is_cli()) {
1569 1569
             return self::$cli_error . $value . "\x1b[0m";
1570
-        } else {
1570
+        } else {
1571 1571
             return '<span ' . self::$error_attributes . '>' . $value . '</span>';
1572 1572
         }
1573 1573
     }
@@ -1579,11 +1579,11 @@  discard block
 block discarded – undo
1579 1579
      *
1580 1580
      * @return String HTML code of the highlighted token.
1581 1581
      */
1582
-    protected static function highlightComment($value)
1583
-    {
1584
-        if (self::is_cli()) {
1582
+    protected static function highlightComment($value)
1583
+    {
1584
+        if (self::is_cli()) {
1585 1585
             return self::$cli_comment . $value . "\x1b[0m";
1586
-        } else {
1586
+        } else {
1587 1587
             return '<span ' . self::$comment_attributes . '>' . $value . '</span>';
1588 1588
         }
1589 1589
     }
@@ -1595,11 +1595,11 @@  discard block
 block discarded – undo
1595 1595
      *
1596 1596
      * @return String HTML code of the highlighted token.
1597 1597
      */
1598
-    protected static function highlightWord($value)
1599
-    {
1600
-        if (self::is_cli()) {
1598
+    protected static function highlightWord($value)
1599
+    {
1600
+        if (self::is_cli()) {
1601 1601
             return self::$cli_word . $value . "\x1b[0m";
1602
-        } else {
1602
+        } else {
1603 1603
             return '<span ' . self::$word_attributes . '>' . $value . '</span>';
1604 1604
         }
1605 1605
     }
@@ -1611,11 +1611,11 @@  discard block
 block discarded – undo
1611 1611
      *
1612 1612
      * @return String HTML code of the highlighted token.
1613 1613
      */
1614
-    protected static function highlightVariable($value)
1615
-    {
1616
-        if (self::is_cli()) {
1614
+    protected static function highlightVariable($value)
1615
+    {
1616
+        if (self::is_cli()) {
1617 1617
             return self::$cli_variable . $value . "\x1b[0m";
1618
-        } else {
1618
+        } else {
1619 1619
             return '<span ' . self::$variable_attributes . '>' . $value . '</span>';
1620 1620
         }
1621 1621
     }
@@ -1627,8 +1627,8 @@  discard block
 block discarded – undo
1627 1627
      *
1628 1628
      * @return String The quoted string
1629 1629
      */
1630
-    private static function quote_regex($a)
1631
-    {
1630
+    private static function quote_regex($a)
1631
+    {
1632 1632
         return preg_quote($a, '/');
1633 1633
     }
1634 1634
 
@@ -1639,13 +1639,13 @@  discard block
 block discarded – undo
1639 1639
      *
1640 1640
      * @return String The quoted string
1641 1641
      */
1642
-    private static function output($string)
1643
-    {
1644
-        if (self::is_cli()) {
1642
+    private static function output($string)
1643
+    {
1644
+        if (self::is_cli()) {
1645 1645
             return $string . "\n";
1646
-        } else {
1646
+        } else {
1647 1647
             $string = trim($string);
1648
-            if (!self::$use_pre) {
1648
+            if (!self::$use_pre) {
1649 1649
                 return $string;
1650 1650
             }
1651 1651
 
@@ -1656,11 +1656,11 @@  discard block
 block discarded – undo
1656 1656
     /**
1657 1657
      * @return bool
1658 1658
      */
1659
-    private static function is_cli()
1660
-    {
1661
-        if (isset(self::$cli)) {
1659
+    private static function is_cli()
1660
+    {
1661
+        if (isset(self::$cli)) {
1662 1662
             return self::$cli;
1663
-        } else {
1663
+        } else {
1664 1664
             return php_sapi_name() === 'cli';
1665 1665
         }
1666 1666
     }
Please login to merge, or discard this patch.
assets/lib/SimpleTab/table.abstract.php 3 patches
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php namespace SimpleTab;
2 2
 
3
-require_once(MODX_BASE_PATH . 'assets/lib/MODxAPI/autoTable.abstract.php');
4
-require_once(MODX_BASE_PATH . 'assets/lib/Helpers/FS.php');
5
-require_once(MODX_BASE_PATH . 'assets/lib/Helpers/PHPThumb.php');
3
+require_once(MODX_BASE_PATH.'assets/lib/MODxAPI/autoTable.abstract.php');
4
+require_once(MODX_BASE_PATH.'assets/lib/Helpers/FS.php');
5
+require_once(MODX_BASE_PATH.'assets/lib/Helpers/PHPThumb.php');
6 6
 
7 7
 /**
8 8
  * Class dataTable
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
         $rows = $this->query("SELECT MIN(`{$this->indexName}`) FROM {$table} WHERE `{$this->pkName}` IN ({$ids})");
60 60
         $index = $this->modx->db->getValue($rows);
61 61
         $index = $index - 1;
62
-        $this->query("SET @index := " . $index);
62
+        $this->query("SET @index := ".$index);
63 63
         $this->query("UPDATE {$table} SET `{$this->indexName}` = (@index := @index + 1) WHERE (`{$this->indexName}`>{$index} AND `{$this->rfName}`={$rid} AND `{$this->pkName}` NOT IN ({$ids})) ORDER BY `{$this->indexName}` ASC");
64 64
         $out = $this->modx->db->getAffectedRows();
65 65
 
@@ -94,13 +94,13 @@  discard block
 block discarded – undo
94 94
         $cnt = count($ids);
95 95
         $ids = implode(',', $ids);
96 96
         if ($dir == 'top') {
97
-            $this->query("SET @index := " . ($index - $cnt - 1));
97
+            $this->query("SET @index := ".($index - $cnt - 1));
98 98
             $this->query("UPDATE {$table} SET `{$this->indexName}` = (@index := @index + 1) WHERE (`{$this->pkName}` IN ({$ids})) ORDER BY `{$this->indexName}` ASC");
99 99
             $this->query("SET @index := -1");
100 100
         } else {
101 101
             $this->query("SET @index := -1");
102 102
             $this->query("UPDATE {$table} SET `{$this->indexName}` = (@index := @index + 1) WHERE (`{$this->pkName}` IN ({$ids})) ORDER BY `{$this->indexName}` ASC");
103
-            $this->query("SET @index := " . ($cnt - 1));
103
+            $this->query("SET @index := ".($cnt - 1));
104 104
         }
105 105
         $this->query("UPDATE {$table} SET `{$this->indexName}` = (@index := @index + 1) WHERE (`{$this->pkName}` NOT IN ({$ids})) AND `{$this->rfName}` = {$rid} ORDER BY `{$this->indexName}` ASC");
106 106
         $out = $this->modx->db->getAffectedRows();
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
             return;
120 120
         }
121 121
         if ($this->fs->checkFile($url)) {
122
-            unlink(MODX_BASE_PATH . $url);
122
+            unlink(MODX_BASE_PATH.$url);
123 123
         }
124 124
         $dir = $this->fs->takeFileDir($url);
125 125
         $iterator = new \FilesystemIterator($dir);
@@ -129,8 +129,8 @@  discard block
 block discarded – undo
129 129
         if ($cache) {
130 130
             return;
131 131
         }
132
-        $thumbsCache = \APIhelpers::getkey($this->params,'thumbsCache',$this->thumbsCache);
133
-        $thumb = $thumbsCache . $url;
132
+        $thumbsCache = \APIhelpers::getkey($this->params, 'thumbsCache', $this->thumbsCache);
133
+        $thumb = $thumbsCache.$url;
134 134
         if ($this->fs->checkFile($thumb)) {
135 135
             $this->deleteThumb($thumb, true);
136 136
         }
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
         $filename = $this->fs->takeFileName($name);
184 184
         $ext = $this->fs->takeFileExt($name);
185 185
 
186
-        return $this->modx->stripAlias($filename) . '.' . $ext;
186
+        return $this->modx->stripAlias($filename).'.'.$ext;
187 187
     }
188 188
 
189 189
     /**
@@ -196,12 +196,12 @@  discard block
 block discarded – undo
196 196
      */
197 197
     public function reorder($source, $target, $point, $rid, $orderDir)
198 198
     {
199
-        $rid = (int)$rid;
199
+        $rid = (int) $rid;
200 200
         $point = strtolower($point);
201 201
         $orderDir = strtolower($orderDir);
202
-        $sourceIndex = (int)$source[$this->indexName];
203
-        $targetIndex = (int)$target[$this->indexName];
204
-        $sourceId = (int)$source[$this->pkName];
202
+        $sourceIndex = (int) $source[$this->indexName];
203
+        $targetIndex = (int) $target[$this->indexName];
204
+        $sourceId = (int) $source[$this->pkName];
205 205
         $table = $this->makeTable($this->table);
206 206
         $rows = 0;
207 207
         /* more refactoring  needed */
@@ -246,8 +246,8 @@  discard block
 block discarded – undo
246 246
             return false;
247 247
         }
248 248
         $thumb = new \Helpers\PHPThumb();
249
-        $inputFile = MODX_BASE_PATH . $this->fs->relativePath($url);
250
-        $outputFile = MODX_BASE_PATH . $this->fs->relativePath($folder) . '/' . $this->fs->relativePath($url);
249
+        $inputFile = MODX_BASE_PATH.$this->fs->relativePath($url);
250
+        $outputFile = MODX_BASE_PATH.$this->fs->relativePath($folder).'/'.$this->fs->relativePath($url);
251 251
         $dir = $this->fs->takeFileDir($outputFile);
252 252
         $this->fs->makeDir($dir, $this->modx->config['new_folder_permissions']);
253 253
         if ($thumb->create($inputFile, $outputFile, $options)) {
Please login to merge, or discard this patch.
Braces   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -8,8 +8,8 @@  discard block
 block discarded – undo
8 8
  * Class dataTable
9 9
  * @package SimpleTab
10 10
  */
11
-class dataTable extends \autoTable
12
-{
11
+class dataTable extends \autoTable
12
+{
13 13
     /**
14 14
      * @var array
15 15
      */
@@ -40,8 +40,8 @@  discard block
 block discarded – undo
40 40
      * @param \DocumentParser $modx
41 41
      * @param bool $debug
42 42
      */
43
-    public function __construct($modx, $debug = false)
44
-    {
43
+    public function __construct($modx, $debug = false)
44
+    {
45 45
         parent::__construct($modx, $debug);
46 46
         $this->modx = $modx;
47 47
         $this->fs = \Helpers\FS::getInstance();
@@ -51,8 +51,8 @@  discard block
 block discarded – undo
51 51
      * @param $ids
52 52
      * @param $rid
53 53
      */
54
-    protected function clearIndexes($ids, $rid)
55
-    {
54
+    protected function clearIndexes($ids, $rid)
55
+    {
56 56
         $ids = $this->cleanIDs($ids, ',', array(0));
57 57
         $ids = $this->sanitarIn($ids);
58 58
         $table = $this->makeTable($this->table);
@@ -70,8 +70,8 @@  discard block
 block discarded – undo
70 70
      * @param $field
71 71
      * @return $this
72 72
      */
73
-    public function touch($field)
74
-    {
73
+    public function touch($field)
74
+    {
75 75
         $this->set($field, date('Y-m-d H:i:s', time() + $this->modx->config['server_offset_time']));
76 76
 
77 77
         return $this;
@@ -82,22 +82,22 @@  discard block
 block discarded – undo
82 82
      * @param $dir
83 83
      * @param $rid
84 84
      */
85
-    public function place($ids, $dir, $rid)
86
-    {
85
+    public function place($ids, $dir, $rid)
86
+    {
87 87
         $table = $this->makeTable($this->table);
88 88
         $ids = $this->cleanIDs($ids, ',', array(0));
89
-        if (empty($ids) || is_scalar($ids)) {
89
+        if (empty($ids) || is_scalar($ids)) {
90 90
             return false;
91 91
         }
92 92
         $rows = $this->query("SELECT count(`{$this->pkName}`) FROM {$table} WHERE `{$this->rfName}`={$rid}");
93 93
         $index = $this->modx->db->getValue($rows);
94 94
         $cnt = count($ids);
95 95
         $ids = implode(',', $ids);
96
-        if ($dir == 'top') {
96
+        if ($dir == 'top') {
97 97
             $this->query("SET @index := " . ($index - $cnt - 1));
98 98
             $this->query("UPDATE {$table} SET `{$this->indexName}` = (@index := @index + 1) WHERE (`{$this->pkName}` IN ({$ids})) ORDER BY `{$this->indexName}` ASC");
99 99
             $this->query("SET @index := -1");
100
-        } else {
100
+        } else {
101 101
             $this->query("SET @index := -1");
102 102
             $this->query("UPDATE {$table} SET `{$this->indexName}` = (@index := @index + 1) WHERE (`{$this->pkName}` IN ({$ids})) ORDER BY `{$this->indexName}` ASC");
103 103
             $this->query("SET @index := " . ($cnt - 1));
@@ -112,26 +112,26 @@  discard block
 block discarded – undo
112 112
      * @param $url
113 113
      * @param bool $cache
114 114
      */
115
-    public function deleteThumb($url, $cache = false)
116
-    {
115
+    public function deleteThumb($url, $cache = false)
116
+    {
117 117
         $url = $this->fs->relativePath($url);
118
-        if (empty($url)) {
118
+        if (empty($url)) {
119 119
             return;
120 120
         }
121
-        if ($this->fs->checkFile($url)) {
121
+        if ($this->fs->checkFile($url)) {
122 122
             unlink(MODX_BASE_PATH . $url);
123 123
         }
124 124
         $dir = $this->fs->takeFileDir($url);
125 125
         $iterator = new \FilesystemIterator($dir);
126
-        if (!$iterator->valid()) {
126
+        if (!$iterator->valid()) {
127 127
             rmdir($dir);
128 128
         }
129
-        if ($cache) {
129
+        if ($cache) {
130 130
             return;
131 131
         }
132 132
         $thumbsCache = \APIhelpers::getkey($this->params,'thumbsCache',$this->thumbsCache);
133 133
         $thumb = $thumbsCache . $url;
134
-        if ($this->fs->checkFile($thumb)) {
134
+        if ($this->fs->checkFile($thumb)) {
135 135
             $this->deleteThumb($thumb, true);
136 136
         }
137 137
     }
@@ -141,8 +141,8 @@  discard block
 block discarded – undo
141 141
      * @param bool $fire_events
142 142
      * @return $this
143 143
      */
144
-    public function delete($ids, $fire_events = false)
145
-    {
144
+    public function delete($ids, $fire_events = false)
145
+    {
146 146
         $out = parent::delete($ids, $fire_events);
147 147
         $this->query("ALTER TABLE {$this->makeTable($this->table)} AUTO_INCREMENT = 1");
148 148
 
@@ -155,8 +155,8 @@  discard block
 block discarded – undo
155 155
      * @param bool $fire_events
156 156
      * @return $this
157 157
      */
158
-    public function deleteAll($ids, $rid, $fire_events = false)
159
-    {
158
+    public function deleteAll($ids, $rid, $fire_events = false)
159
+    {
160 160
         $this->clearIndexes($ids, $rid);
161 161
 
162 162
         return $this->delete($ids, $fire_events);
@@ -165,8 +165,8 @@  discard block
 block discarded – undo
165 165
     /**
166 166
      * @return array
167 167
      */
168
-    public function fieldNames()
169
-    {
168
+    public function fieldNames()
169
+    {
170 170
         $fields = array_keys($this->getDefaultFields());
171 171
         $fields[] = $this->fieldPKName();
172 172
 
@@ -177,8 +177,8 @@  discard block
 block discarded – undo
177 177
      * @param  string $name
178 178
      * @return string
179 179
      */
180
-    public function stripName($name)
181
-    {
180
+    public function stripName($name)
181
+    {
182 182
 
183 183
         $filename = $this->fs->takeFileName($name);
184 184
         $ext = $this->fs->takeFileExt($name);
@@ -194,8 +194,8 @@  discard block
 block discarded – undo
194 194
      * @param $orderDir
195 195
      * @return int|void
196 196
      */
197
-    public function reorder($source, $target, $point, $rid, $orderDir)
198
-    {
197
+    public function reorder($source, $target, $point, $rid, $orderDir)
198
+    {
199 199
         $rid = (int)$rid;
200 200
         $point = strtolower($point);
201 201
         $orderDir = strtolower($orderDir);
@@ -205,25 +205,25 @@  discard block
 block discarded – undo
205 205
         $table = $this->makeTable($this->table);
206 206
         $rows = 0;
207 207
         /* more refactoring  needed */
208
-        if ($targetIndex < $sourceIndex) {
209
-            if (($point == 'top' && $orderDir == 'asc') || ($point == 'bottom' && $orderDir == 'desc')) {
208
+        if ($targetIndex < $sourceIndex) {
209
+            if (($point == 'top' && $orderDir == 'asc') || ($point == 'bottom' && $orderDir == 'desc')) {
210 210
                 $this->modx->db->update("`{$this->indexName}`=`{$this->indexName}`+1", $table,
211 211
                     "`{$this->indexName}`>={$targetIndex} AND `{$this->indexName}`<{$sourceIndex} AND `{$this->rfName}`={$rid}");
212 212
                 $rows = $this->modx->db->update("`{$this->indexName}`={$targetIndex}", $table,
213 213
                     "`{$this->pkName}`={$sourceId}");
214
-            } elseif (($point == 'bottom' && $orderDir == 'asc') || ($point == 'top' && $orderDir == 'desc')) {
214
+            } elseif (($point == 'bottom' && $orderDir == 'asc') || ($point == 'top' && $orderDir == 'desc')) {
215 215
                 $this->modx->db->update("`{$this->indexName}`=`{$this->indexName}`+1", $table,
216 216
                     "`{$this->indexName}`>{$targetIndex} AND `{$this->indexName}`<{$sourceIndex} AND `{$this->rfName}`={$rid}");
217 217
                 $rows = $this->modx->db->update("`{$this->indexName}`=1+{$targetIndex}", $table,
218 218
                     "`{$this->pkName}`={$sourceId}");
219 219
             }
220
-        } else {
221
-            if (($point == 'bottom' && $orderDir == 'asc') || ($point == 'top' && $orderDir == 'desc')) {
220
+        } else {
221
+            if (($point == 'bottom' && $orderDir == 'asc') || ($point == 'top' && $orderDir == 'desc')) {
222 222
                 $this->modx->db->update("`{$this->indexName}`=`{$this->indexName}`-1", $table,
223 223
                     "`{$this->indexName}`<={$targetIndex} AND `{$this->indexName}`>={$sourceIndex} AND `{$this->rfName}`={$rid}");
224 224
                 $rows = $this->modx->db->update("`{$this->indexName}`={$targetIndex}", $table,
225 225
                     "`{$this->pkName}`={$sourceId}");
226
-            } elseif (($point == 'top' && $orderDir == 'asc') || ($point == 'bottom' && $orderDir == 'desc')) {
226
+            } elseif (($point == 'top' && $orderDir == 'asc') || ($point == 'bottom' && $orderDir == 'desc')) {
227 227
                 $this->modx->db->update("`{$this->indexName}`=`{$this->indexName}`-1", $table,
228 228
                     "`{$this->indexName}`<{$targetIndex} AND `{$this->indexName}`>={$sourceIndex} AND `{$this->rfName}`={$rid}");
229 229
                 $rows = $this->modx->db->update("`{$this->indexName}`=-1+{$targetIndex}", $table,
@@ -240,9 +240,9 @@  discard block
 block discarded – undo
240 240
      * @param $options
241 241
      * @return bool
242 242
      */
243
-    public function makeThumb($folder, $url, $options)
244
-    {
245
-        if (empty($url)) {
243
+    public function makeThumb($folder, $url, $options)
244
+    {
245
+        if (empty($url)) {
246 246
             return false;
247 247
         }
248 248
         $thumb = new \Helpers\PHPThumb();
@@ -250,9 +250,9 @@  discard block
 block discarded – undo
250 250
         $outputFile = MODX_BASE_PATH . $this->fs->relativePath($folder) . '/' . $this->fs->relativePath($url);
251 251
         $dir = $this->fs->takeFileDir($outputFile);
252 252
         $this->fs->makeDir($dir, $this->modx->config['new_folder_permissions']);
253
-        if ($thumb->create($inputFile, $outputFile, $options)) {
253
+        if ($thumb->create($inputFile, $outputFile, $options)) {
254 254
             return true;
255
-        } else {
255
+        } else {
256 256
             $this->modx->logEvent(0, 3, $thumb->debugMessages, __NAMESPACE__);
257 257
 
258 258
             return false;
@@ -262,17 +262,17 @@  discard block
 block discarded – undo
262 262
     /**
263 263
      * @return array
264 264
      */
265
-    public function getParams()
266
-    {
265
+    public function getParams()
266
+    {
267 267
         return $this->params;
268 268
     }
269 269
 
270 270
     /**
271 271
      * @param array $params
272 272
      */
273
-    public function setParams($params = array())
274
-    {
275
-        if (is_array($params)) {
273
+    public function setParams($params = array())
274
+    {
275
+        if (is_array($params)) {
276 276
             $this->params = $params;
277 277
         }
278 278
     }
Please login to merge, or discard this patch.
Upper-Lower-Casing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
         $index = $this->modx->db->getValue($rows);
61 61
         $index = $index - 1;
62 62
         $this->query("SET @index := " . $index);
63
-        $this->query("UPDATE {$table} SET `{$this->indexName}` = (@index := @index + 1) WHERE (`{$this->indexName}`>{$index} AND `{$this->rfName}`={$rid} AND `{$this->pkName}` NOT IN ({$ids})) ORDER BY `{$this->indexName}` ASC");
63
+        $this->query("update {$table} SET `{$this->indexName}` = (@index := @index + 1) WHERE (`{$this->indexName}`>{$index} AND `{$this->rfName}`={$rid} AND `{$this->pkName}` NOT IN ({$ids})) ORDER BY `{$this->indexName}` ASC");
64 64
         $out = $this->modx->db->getAffectedRows();
65 65
 
66 66
         return $out;
@@ -95,14 +95,14 @@  discard block
 block discarded – undo
95 95
         $ids = implode(',', $ids);
96 96
         if ($dir == 'top') {
97 97
             $this->query("SET @index := " . ($index - $cnt - 1));
98
-            $this->query("UPDATE {$table} SET `{$this->indexName}` = (@index := @index + 1) WHERE (`{$this->pkName}` IN ({$ids})) ORDER BY `{$this->indexName}` ASC");
98
+            $this->query("update {$table} SET `{$this->indexName}` = (@index := @index + 1) WHERE (`{$this->pkName}` IN ({$ids})) ORDER BY `{$this->indexName}` ASC");
99 99
             $this->query("SET @index := -1");
100 100
         } else {
101 101
             $this->query("SET @index := -1");
102
-            $this->query("UPDATE {$table} SET `{$this->indexName}` = (@index := @index + 1) WHERE (`{$this->pkName}` IN ({$ids})) ORDER BY `{$this->indexName}` ASC");
102
+            $this->query("update {$table} SET `{$this->indexName}` = (@index := @index + 1) WHERE (`{$this->pkName}` IN ({$ids})) ORDER BY `{$this->indexName}` ASC");
103 103
             $this->query("SET @index := " . ($cnt - 1));
104 104
         }
105
-        $this->query("UPDATE {$table} SET `{$this->indexName}` = (@index := @index + 1) WHERE (`{$this->pkName}` NOT IN ({$ids})) AND `{$this->rfName}` = {$rid} ORDER BY `{$this->indexName}` ASC");
105
+        $this->query("update {$table} SET `{$this->indexName}` = (@index := @index + 1) WHERE (`{$this->pkName}` NOT IN ({$ids})) AND `{$this->rfName}` = {$rid} ORDER BY `{$this->indexName}` ASC");
106 106
         $out = $this->modx->db->getAffectedRows();
107 107
 
108 108
         return $out;
Please login to merge, or discard this patch.
assets/lib/MODxAPI/MODx.php 2 patches
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2
-include_once(MODX_BASE_PATH . 'assets/lib/APIHelpers.class.php');
3
-include_once(MODX_BASE_PATH . 'assets/snippets/DocLister/lib/jsonHelper.class.php');
4
-include_once(MODX_BASE_PATH . 'assets/snippets/DocLister/lib/DLCollection.class.php');
2
+include_once(MODX_BASE_PATH.'assets/lib/APIHelpers.class.php');
3
+include_once(MODX_BASE_PATH.'assets/snippets/DocLister/lib/jsonHelper.class.php');
4
+include_once(MODX_BASE_PATH.'assets/snippets/DocLister/lib/DLCollection.class.php');
5 5
 
6 6
 use \Doctrine\Common\Cache\Cache;
7 7
 
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
      */
170 170
     public function setDebug($flag)
171 171
     {
172
-        $this->_debug = (bool)$flag;
172
+        $this->_debug = (bool) $flag;
173 173
 
174 174
         return $this;
175 175
     }
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
         $value = trim($value);
200 200
         if (!empty($value)) {
201 201
             if (!is_numeric($value)) {
202
-                $value = (int)strtotime($value);
202
+                $value = (int) strtotime($value);
203 203
             }
204 204
             if (!empty($value)) {
205 205
                 $value += $this->modxConfig('server_offset_time');
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
      */
277 277
     final public function invokeEvent($name, $data = array(), $flag = false)
278 278
     {
279
-        if ((bool)$flag === true) {
279
+        if ((bool) $flag === true) {
280 280
             $this->modx->invokeEvent($name, $data);
281 281
         }
282 282
 
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
      */
292 292
     final public function getInvokeEventResult($name, $data = array(), $flag = null)
293 293
     {
294
-        $flag = (isset($flag) && $flag != '') ? (bool)$flag : false;
294
+        $flag = (isset($flag) && $flag != '') ? (bool) $flag : false;
295 295
 
296 296
         return $flag ? $this->modx->invokeEvent($name, $data) : false;
297 297
     }
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
      */
321 321
     final public function list_log($flush = false)
322 322
     {
323
-        echo '<pre>' . print_r(APIHelpers::sanitarTag($this->log), true) . '</pre>';
323
+        echo '<pre>'.print_r(APIHelpers::sanitarTag($this->log), true).'</pre>';
324 324
         if ($flush) {
325 325
             $this->clearLog();
326 326
         }
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
     {
337 337
         $path = $this->modx->getCachePath();
338 338
         if ($full) {
339
-            $path = MODX_BASE_PATH . substr($path, strlen(MODX_BASE_URL));
339
+            $path = MODX_BASE_PATH.substr($path, strlen(MODX_BASE_URL));
340 340
         }
341 341
 
342 342
         return $path;
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
         $IDs = array();
352 352
         if ($custom === false) {
353 353
             $this->modx->clearCache();
354
-            include_once(MODX_MANAGER_PATH . 'processors/cache_sync.class.processor.php');
354
+            include_once(MODX_MANAGER_PATH.'processors/cache_sync.class.processor.php');
355 355
             $sync = new synccache();
356 356
             $path = $this->getCachePath(true);
357 357
             $sync->setCachepath($path);
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
             }
371 371
             if (is_array($custom)) {
372 372
                 foreach ($custom as $id) {
373
-                    $tmp = glob(MODX_BASE_PATH . "assets/cache/docid_" . $id . $cacheFile);
373
+                    $tmp = glob(MODX_BASE_PATH."assets/cache/docid_".$id.$cacheFile);
374 374
                     foreach ($tmp as $file) {
375 375
                         if (is_readable($file)) {
376 376
                             unlink($file);
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
      */
425 425
     public function hasIgnore()
426 426
     {
427
-        return (bool)$this->ignoreError;
427
+        return (bool) $this->ignoreError;
428 428
     }
429 429
 
430 430
     /**
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
             if ($this->issetField($key) && is_scalar($this->field[$key])) {
491 491
                 $tmp = "`{$key}`='{$this->escape($this->field[$key])}'";
492 492
             } else {
493
-                throw new Exception("{$key} is invalid <pre>" . print_r($this->field[$key], true) . "</pre>");
493
+                throw new Exception("{$key} is invalid <pre>".print_r($this->field[$key], true)."</pre>");
494 494
             }
495 495
         }
496 496
         if (!empty($tmp) && $this->isChanged($key)) {
@@ -564,16 +564,16 @@  discard block
 block discarded – undo
564 564
                 $IDs = explode($sep, $IDs);
565 565
             } else {
566 566
                 $IDs = array();
567
-                throw new Exception('Invalid IDs list <pre>' . print_r($IDs, 1) . '</pre>');
567
+                throw new Exception('Invalid IDs list <pre>'.print_r($IDs, 1).'</pre>');
568 568
             }
569 569
         }
570 570
         foreach ($IDs as $item) {
571 571
             $item = trim($item);
572
-            if (is_scalar($item) && (int)$item >= 0) { //Fix 0xfffffffff
573
-                if (!empty($ignore) && in_array((int)$item, $ignore, true)) {
574
-                    $this->log[] = 'Ignore id ' . (int)$item;
572
+            if (is_scalar($item) && (int) $item >= 0) { //Fix 0xfffffffff
573
+                if (!empty($ignore) && in_array((int) $item, $ignore, true)) {
574
+                    $this->log[] = 'Ignore id '.(int) $item;
575 575
                 } else {
576
-                    $out[] = (int)$item;
576
+                    $out[] = (int) $item;
577 577
                 }
578 578
             }
579 579
         }
@@ -601,14 +601,14 @@  discard block
 block discarded – undo
601 601
                 call_user_func_array($callback, array($json));
602 602
             } else {
603 603
                 if (isset($callback)) {
604
-                    throw new Exception("Can't call callback JSON unpack <pre>" . print_r($callback, 1) . "</pre>");
604
+                    throw new Exception("Can't call callback JSON unpack <pre>".print_r($callback, 1)."</pre>");
605 605
                 }
606 606
                 foreach ($json as $key => $val) {
607 607
                     $this->set($key, $val);
608 608
                 }
609 609
             }
610 610
         } else {
611
-            throw new Exception('Error from JSON decode: <pre>' . print_r($data, 1) . '</pre>');
611
+            throw new Exception('Error from JSON decode: <pre>'.print_r($data, 1).'</pre>');
612 612
         }
613 613
 
614 614
         return $this;
@@ -626,13 +626,13 @@  discard block
 block discarded – undo
626 626
             $data = call_user_func_array($callback, array($data));
627 627
         } else {
628 628
             if (isset($callback)) {
629
-                throw new Exception("Can't call callback JSON pre pack <pre>" . print_r($callback, 1) . "</pre>");
629
+                throw new Exception("Can't call callback JSON pre pack <pre>".print_r($callback, 1)."</pre>");
630 630
             }
631 631
         }
632 632
         $json = json_encode($data);
633 633
 
634 634
         if ($this->jsonError($data)) {
635
-            throw new Exception('Error from JSON decode: <pre>' . print_r($data, 1) . '</pre>');
635
+            throw new Exception('Error from JSON decode: <pre>'.print_r($data, 1).'</pre>');
636 636
         }
637 637
 
638 638
         return $json;
@@ -663,11 +663,11 @@  discard block
 block discarded – undo
663 663
         $tpl = '';
664 664
         $plh = '[+key+]';
665 665
         if ($prefix !== '') {
666
-            $tpl = $prefix . $sep;
666
+            $tpl = $prefix.$sep;
667 667
         }
668 668
         $tpl .= $plh;
669 669
         if ($suffix !== '') {
670
-            $tpl .= $sep . $suffix;
670
+            $tpl .= $sep.$suffix;
671 671
         }
672 672
         $out = array();
673 673
         $fields = $this->field;
@@ -717,7 +717,7 @@  discard block
 block discarded – undo
717 717
                 $out[] = $this->escape($item);
718 718
             }
719 719
         }
720
-        $out = empty($out) ? '' : "'" . implode("','", $out) . "'";
720
+        $out = empty($out) ? '' : "'".implode("','", $out)."'";
721 721
 
722 722
         return $out;
723 723
     }
@@ -735,7 +735,7 @@  discard block
 block discarded – undo
735 735
             foreach ($field as $_field) {
736 736
                 $val = $this->get($_field);
737 737
                 if ($val != '') {
738
-                    $where[] = "`" . $this->escape($_field) . "` = '" . $this->escape($val) . "'";
738
+                    $where[] = "`".$this->escape($_field)."` = '".$this->escape($val)."'";
739 739
                 }
740 740
             }
741 741
             $where = implode(' AND ', $where);
@@ -743,12 +743,12 @@  discard block
 block discarded – undo
743 743
             $where = '';
744 744
             $val = $this->get($field);
745 745
             if ($val != '') {
746
-                $where = "`" . $this->escape($field) . "` = '" . $this->escape($val) . "'";
746
+                $where = "`".$this->escape($field)."` = '".$this->escape($val)."'";
747 747
             }
748 748
         }
749 749
 
750 750
         if ($where != '') {
751
-            $sql = $this->query("SELECT `" . $this->escape($PK) . "` FROM " . $this->makeTable($table) . " WHERE " . $where);
751
+            $sql = $this->query("SELECT `".$this->escape($PK)."` FROM ".$this->makeTable($table)." WHERE ".$where);
752 752
             $id = $this->modx->db->getValue($sql);
753 753
             if (!$id || (!$this->newDoc && $id == $this->getID())) {
754 754
                 $flag = true;
@@ -854,7 +854,7 @@  discard block
 block discarded – undo
854 854
         if (version_compare($tmp, $version, '>=')) {
855 855
             $flag = true;
856 856
             if ($dmi3yy) {
857
-                $flag = (boolean)preg_match('/^' . $tmp . '(.*)\-d/', $currentVer);
857
+                $flag = (boolean) preg_match('/^'.$tmp.'(.*)\-d/', $currentVer);
858 858
             }
859 859
         }
860 860
 
@@ -948,7 +948,7 @@  discard block
 block discarded – undo
948 948
      */
949 949
     public function getNoEncodeFields()
950 950
     {
951
-        return $this->_decodedFields->filter(function ($value) {
951
+        return $this->_decodedFields->filter(function($value){
952 952
             return ($value === false);
953 953
         });
954 954
     }
@@ -959,7 +959,7 @@  discard block
 block discarded – undo
959 959
      */
960 960
     public function getNoDecodeFields()
961 961
     {
962
-        return $this->_decodedFields->filter(function ($value) {
962
+        return $this->_decodedFields->filter(function($value){
963 963
             return ($value === true);
964 964
         });
965 965
     }
Please login to merge, or discard this patch.
Braces   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -569,7 +569,8 @@  discard block
 block discarded – undo
569 569
         }
570 570
         foreach ($IDs as $item) {
571 571
             $item = trim($item);
572
-            if (is_scalar($item) && (int)$item >= 0) { //Fix 0xfffffffff
572
+            if (is_scalar($item) && (int)$item >= 0) {
573
+//Fix 0xfffffffff
573 574
                 if (!empty($ignore) && in_array((int)$item, $ignore, true)) {
574 575
                     $this->log[] = 'Ignore id ' . (int)$item;
575 576
                 } else {
@@ -948,7 +949,7 @@  discard block
 block discarded – undo
948 949
      */
949 950
     public function getNoEncodeFields()
950 951
     {
951
-        return $this->_decodedFields->filter(function ($value) {
952
+        return $this->_decodedFields->filter(function ($value){
952 953
             return ($value === false);
953 954
         });
954 955
     }
@@ -959,7 +960,7 @@  discard block
 block discarded – undo
959 960
      */
960 961
     public function getNoDecodeFields()
961 962
     {
962
-        return $this->_decodedFields->filter(function ($value) {
963
+        return $this->_decodedFields->filter(function ($value){
963 964
             return ($value === true);
964 965
         });
965 966
     }
Please login to merge, or discard this patch.
assets/lib/MODxAPI/modResource.php 3 patches
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
         $this->get_TV();
165 165
         $uTable = $this->makeTable("manager_users");
166 166
         $aTable = $this->makeTable("user_attributes");
167
-        $query = "SELECT `u`.`id`, `a`.`email`, `u`.`username`  FROM " . $aTable . " as `a` LEFT JOIN " . $uTable . " as `u` ON `u`.`id`=`a`.`internalKey`";
167
+        $query = "SELECT `u`.`id`, `a`.`email`, `u`.`username`  FROM ".$aTable." as `a` LEFT JOIN ".$uTable." as `u` ON `u`.`id`=`a`.`internalKey`";
168 168
         $query = $this->query($query);
169 169
         $this->managerUsers = new DLCollection($modx, empty($query) ? array() : $query);
170 170
     }
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
     public function getUrl()
229 229
     {
230 230
         $out = null;
231
-        $id = (int)$this->getID();
231
+        $id = (int) $this->getID();
232 232
         if (!empty($id)) {
233 233
             $out = $this->modx->makeUrl($id);
234 234
         }
@@ -281,8 +281,8 @@  discard block
 block discarded – undo
281 281
     {
282 282
         $out = null;
283 283
         if ($this->getID() > 0) {
284
-            include_once MODX_MANAGER_PATH . "includes/tmplvars.format.inc.php";
285
-            include_once MODX_MANAGER_PATH . "includes/tmplvars.commands.inc.php";
284
+            include_once MODX_MANAGER_PATH."includes/tmplvars.format.inc.php";
285
+            include_once MODX_MANAGER_PATH."includes/tmplvars.commands.inc.php";
286 286
             $tvval = $this->get($tvname);
287 287
             if ($this->isTVarrayField($tvname) && is_array($tvval)) {
288 288
                 $tvval = implode('||', $tvval);
@@ -326,14 +326,14 @@  discard block
 block discarded – undo
326 326
         if ((is_scalar($value) || $this->isTVarrayField($key) || $this->isJsonField($key)) && is_scalar($key) && !empty($key)) {
327 327
             switch ($key) {
328 328
                 case 'parent':
329
-                    $value = (int)$value;
329
+                    $value = (int) $value;
330 330
                     break;
331 331
                 case 'template':
332 332
                     $value = trim($value);
333 333
                     $value = $this->setTemplate($value);
334 334
                     break;
335 335
                 case 'published':
336
-                    $value = (int)((bool)$value);
336
+                    $value = (int) ((bool) $value);
337 337
                     if ($value) {
338 338
                         $this->field['publishedon'] = time() + $this->modxConfig('server_offset_time');
339 339
                     }
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
                     }
354 354
                     break;
355 355
                 case 'deleted':
356
-                    $value = (int)((bool)$value);
356
+                    $value = (int) ((bool) $value);
357 357
                     if ($value) {
358 358
                         $this->field['deletedon'] = time() + $this->modxConfig('server_offset_time');
359 359
                     } else {
@@ -395,11 +395,11 @@  discard block
 block discarded – undo
395 395
     protected function getUser($value, $default = 0)
396 396
     {
397 397
         $currentAdmin = APIHelpers::getkey($_SESSION, 'mgrInternalKey', 0);
398
-        $value = (int)$value;
398
+        $value = (int) $value;
399 399
         if (!empty($value)) {
400 400
             $by = $this->findUserBy($value);
401
-            $exists = $this->managerUsers->exists(function ($key, Helpers\Collection $val) use ($by, $value) {
402
-                return ($val->containsKey($by) && $val->get($by) === (string)$value);
401
+            $exists = $this->managerUsers->exists(function($key, Helpers\Collection $val) use ($by, $value) {
402
+                return ($val->containsKey($by) && $val->get($by) === (string) $value);
403 403
             });
404 404
             if (!$exists) {
405 405
                 $value = 0;
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
     protected function findUserBy($data)
420 420
     {
421 421
         switch (true) {
422
-            case (is_int($data) || ((int)$data > 0 && (string)intval($data) === $data)):
422
+            case (is_int($data) || ((int) $data > 0 && (string) intval($data) === $data)):
423 423
                 $find = 'id';
424 424
                 break;
425 425
             case filter_var($data, FILTER_VALIDATE_EMAIL):
@@ -469,9 +469,9 @@  discard block
 block discarded – undo
469 469
             $this->markAllEncode();
470 470
             $this->newDoc = false;
471 471
 
472
-            $result = $this->query("SELECT * from {$this->makeTable('site_content')} where `id`=" . (int)$id);
472
+            $result = $this->query("SELECT * from {$this->makeTable('site_content')} where `id`=".(int) $id);
473 473
             $this->fromArray($this->modx->db->getRow($result));
474
-            $result = $this->query("SELECT * from {$this->makeTable('site_tmplvar_contentvalues')} where `contentid`=" . (int)$id);
474
+            $result = $this->query("SELECT * from {$this->makeTable('site_tmplvar_contentvalues')} where `contentid`=".(int) $id);
475 475
             while ($row = $this->modx->db->getRow($result)) {
476 476
                 $this->field[$this->tvid[$row['tmplvarid']]] = $row['value'];
477 477
             }
@@ -498,7 +498,7 @@  discard block
 block discarded – undo
498 498
     {
499 499
         $parent = null;
500 500
         if ($this->field['pagetitle'] == '') {
501
-            $this->log['emptyPagetitle'] = 'Pagetitle is empty in <pre>' . print_r($this->field, true) . '</pre>';
501
+            $this->log['emptyPagetitle'] = 'Pagetitle is empty in <pre>'.print_r($this->field, true).'</pre>';
502 502
 
503 503
             return false;
504 504
         }
@@ -551,7 +551,7 @@  discard block
 block discarded – undo
551 551
             }
552 552
             switch (true) {
553 553
                 case $key == 'parent':
554
-                    $parent = (int)$this->get($key);
554
+                    $parent = (int) $this->get($key);
555 555
                     $q = $this->query("SELECT count(`id`) FROM {$this->makeTable('site_content')} WHERE `id`='{$parent}'");
556 556
                     if ($this->modx->db->getValue($q) != 1) {
557 557
                         $parent = 0;
@@ -570,10 +570,10 @@  discard block
 block discarded – undo
570 570
 
571 571
         if (!empty($this->set)) {
572 572
             if ($this->newDoc) {
573
-                $SQL = "INSERT into {$this->makeTable('site_content')} SET " . implode(', ', $this->set);
573
+                $SQL = "INSERT into {$this->makeTable('site_content')} SET ".implode(', ', $this->set);
574 574
             } else {
575
-                $SQL = "UPDATE {$this->makeTable('site_content')} SET " . implode(', ',
576
-                        $this->set) . " WHERE `id` = " . $this->id;
575
+                $SQL = "UPDATE {$this->makeTable('site_content')} SET ".implode(', ',
576
+                        $this->set)." WHERE `id` = ".$this->id;
577 577
             }
578 578
             $this->query($SQL);
579 579
 
@@ -657,12 +657,12 @@  discard block
 block discarded – undo
657 657
         $_ids = $this->cleanIDs($ids, ',', $ignore);
658 658
         if (is_array($_ids) && $_ids != array()) {
659 659
             $id = $this->sanitarIn($_ids);
660
-            $uid = (int)$this->modx->getLoginUserId();
660
+            $uid = (int) $this->modx->getLoginUserId();
661 661
             $deletedon = time() + $this->modxConfig('server_offset_time');
662 662
             $this->query("UPDATE {$this->makeTable('site_content')} SET `deleted`=1, `deletedby`={$uid}, `deletedon`={$deletedon} WHERE `id` IN ({$id})");
663 663
         } else {
664
-            throw new Exception('Invalid IDs list for mark trash: <pre>' . print_r($ids,
665
-                    1) . '</pre> please, check ignore list: <pre>' . print_r($ignore, 1) . '</pre>');
664
+            throw new Exception('Invalid IDs list for mark trash: <pre>'.print_r($ids,
665
+                    1).'</pre> please, check ignore list: <pre>'.print_r($ignore, 1).'</pre>');
666 666
         }
667 667
 
668 668
         return $this;
@@ -744,15 +744,15 @@  discard block
 block discarded – undo
744 744
     {
745 745
         $ignore = array(
746 746
             0, //empty document
747
-            (int)$this->modxConfig('site_start'),
748
-            (int)$this->modxConfig('error_page'),
749
-            (int)$this->modxConfig('unauthorized_page'),
750
-            (int)$this->modxConfig('site_unavailable_page')
747
+            (int) $this->modxConfig('site_start'),
748
+            (int) $this->modxConfig('error_page'),
749
+            (int) $this->modxConfig('unauthorized_page'),
750
+            (int) $this->modxConfig('site_unavailable_page')
751 751
         );
752 752
         $data = $this->query("SELECT DISTINCT setting_value FROM {$this->makeTable('web_user_settings')} WHERE `setting_name`='login_home' AND `setting_value`!=''");
753 753
         $data = $this->modx->db->makeArray($data);
754 754
         foreach ($data as $item) {
755
-            $ignore[] = (int)$item['setting_value'];
755
+            $ignore[] = (int) $item['setting_value'];
756 756
         }
757 757
 
758 758
         return array_unique($ignore);
@@ -775,9 +775,9 @@  discard block
 block discarded – undo
775 775
             }
776 776
             if (($flag && $this->newDoc) || (!$this->newDoc && $flag && $this->id != $flag)) {
777 777
                 $suffix = substr($alias, -2);
778
-                if (preg_match('/-(\d+)/', $suffix, $tmp) && isset($tmp[1]) && (int)$tmp[1] > 1) {
779
-                    $suffix = (int)$tmp[1] + 1;
780
-                    $alias = substr($alias, 0, -2) . '-' . $suffix;
778
+                if (preg_match('/-(\d+)/', $suffix, $tmp) && isset($tmp[1]) && (int) $tmp[1] > 1) {
779
+                    $suffix = (int) $tmp[1] + 1;
780
+                    $alias = substr($alias, 0, -2).'-'.$suffix;
781 781
                 } else {
782 782
                     $alias .= '-2';
783 783
                 }
@@ -806,7 +806,7 @@  discard block
 block discarded – undo
806 806
         $this->modx->_TVnames = $this->loadFromCache('_TVnames');
807 807
         if ($this->modx->_TVnames === false || empty($this->modx->_TVnames) || $reload) {
808 808
             $this->modx->_TVnames = array();
809
-            $result = $this->query('SELECT `id`,`name`,`default_text`,`type` FROM ' . $this->makeTable('site_tmplvars'));
809
+            $result = $this->query('SELECT `id`,`name`,`default_text`,`type` FROM '.$this->makeTable('site_tmplvars'));
810 810
             while ($row = $this->modx->db->GetRow($result)) {
811 811
                 $this->modx->_TVnames[$row['name']] = array(
812 812
                     "id"      => $row['id'],
@@ -840,7 +840,7 @@  discard block
 block discarded – undo
840 840
     {
841 841
         $this->tvTpl = $this->loadFromCache('_tvTpl');
842 842
         if ($this->tvTpl === false) {
843
-            $q = $this->query("SELECT `tmplvarid`, `templateid` FROM " . $this->makeTable('site_tmplvar_templates'));
843
+            $q = $this->query("SELECT `tmplvarid`, `templateid` FROM ".$this->makeTable('site_tmplvar_templates'));
844 844
             $this->tvTpl = array();
845 845
             while ($item = $this->modx->db->getRow($q)) {
846 846
                 $this->tvTpl[$item['templateid']][] = $item['tmplvarid'];
@@ -875,20 +875,20 @@  discard block
 block discarded – undo
875 875
      */
876 876
     public function setTemplate($tpl)
877 877
     {
878
-        if (!is_numeric($tpl) || $tpl != (int)$tpl) {
878
+        if (!is_numeric($tpl) || $tpl != (int) $tpl) {
879 879
             if (is_scalar($tpl)) {
880
-                $sql = "SELECT `id` FROM {$this->makeTable('site_templates')} WHERE `templatename` = '" . $this->escape($tpl) . "'";
880
+                $sql = "SELECT `id` FROM {$this->makeTable('site_templates')} WHERE `templatename` = '".$this->escape($tpl)."'";
881 881
                 $rs = $this->query($sql);
882 882
                 if (!$rs || $this->modx->db->getRecordCount($rs) <= 0) {
883 883
                     throw new Exception("Template {$tpl} is not exists");
884 884
                 }
885 885
                 $tpl = $this->modx->db->getValue($rs);
886 886
             } else {
887
-                throw new Exception("Invalid template name: " . print_r($tpl, 1));
887
+                throw new Exception("Invalid template name: ".print_r($tpl, 1));
888 888
             }
889 889
         }
890 890
 
891
-        return (int)$tpl;
891
+        return (int) $tpl;
892 892
     }
893 893
 
894 894
     /**
@@ -1012,7 +1012,7 @@  discard block
 block discarded – undo
1012 1012
         if ($this->isEncodableField($field)) {
1013 1013
             $data = $this->get($field);
1014 1014
             if ($this->isTVarrayField($field)) {
1015
-                $out = is_array($data) ? implode('||', $data) : (string)$data;
1015
+                $out = is_array($data) ? implode('||', $data) : (string) $data;
1016 1016
             } else {
1017 1017
                 $out = json_encode($data);
1018 1018
             }
@@ -1075,7 +1075,7 @@  discard block
 block discarded – undo
1075 1075
             $docgroup_names = $this->makeTable('documentgroup_names');
1076 1076
 
1077 1077
             $rs = $this->query("SELECT `dg`.`document_group`, `dgn`.`name` FROM {$doc_groups} as `dg` INNER JOIN {$docgroup_names} as `dgn` ON `dgn`.`id`=`dg`.`document_group`
1078
-                WHERE `dg`.`document` = " . $doc->getID());
1078
+                WHERE `dg`.`document` = ".$doc->getID());
1079 1079
             while ($row = $this->modx->db->getRow($rs)) {
1080 1080
                 $out[$row['document_group']] = $row['name'];
1081 1081
             }
Please login to merge, or discard this patch.
Braces   +188 added lines, -188 removed lines patch added patch discarded remove patch
@@ -4,8 +4,8 @@  discard block
 block discarded – undo
4 4
 /**
5 5
  * Class modResource
6 6
  */
7
-class modResource extends MODxAPI
8
-{
7
+class modResource extends MODxAPI
8
+{
9 9
     /**
10 10
      * @var string
11 11
      */
@@ -158,8 +158,8 @@  discard block
 block discarded – undo
158 158
      * @param DocumentParser $modx
159 159
      * @param bool $debug
160 160
      */
161
-    public function __construct($modx, $debug = false)
162
-    {
161
+    public function __construct($modx, $debug = false)
162
+    {
163 163
         parent::__construct($modx, $debug);
164 164
         $this->get_TV();
165 165
         $uTable = $this->makeTable("manager_users");
@@ -172,8 +172,8 @@  discard block
 block discarded – undo
172 172
     /**
173 173
      * @return array
174 174
      */
175
-    public function toArrayMain()
176
-    {
175
+    public function toArrayMain()
176
+    {
177 177
         $out = array_intersect_key(parent::toArray(), $this->default_field);
178 178
 
179 179
         return $out;
@@ -183,20 +183,20 @@  discard block
 block discarded – undo
183 183
      * @param bool $render
184 184
      * @return array
185 185
      */
186
-    public function toArrayTV($render = false)
187
-    {
186
+    public function toArrayTV($render = false)
187
+    {
188 188
         $out = array_diff_key(parent::toArray(), $this->default_field);
189 189
         $tpl = $this->get('template');
190 190
         $tvTPL = APIHelpers::getkey($this->tvTpl, $tpl, array());
191
-        foreach ($tvTPL as $item) {
192
-            if (isset($this->tvid[$item]) && !array_key_exists($this->tvid[$item], $out)) {
191
+        foreach ($tvTPL as $item) {
192
+            if (isset($this->tvid[$item]) && !array_key_exists($this->tvid[$item], $out)) {
193 193
                 $value = $this->get($this->tvid[$item]);
194 194
                 $out[$this->tvid[$item]] = empty($value) ? $this->tvd[$this->tvid[$item]] : $value;
195 195
             }
196 196
 
197 197
         }
198
-        if ($render) {
199
-            foreach ($out as $key => $val) {
198
+        if ($render) {
199
+            foreach ($out as $key => $val) {
200 200
                 $out[$key] = $this->renderTV($key);
201 201
             }
202 202
         }
@@ -211,8 +211,8 @@  discard block
 block discarded – undo
211 211
      * @param bool $render
212 212
      * @return array
213 213
      */
214
-    public function toArray($prefix = '', $suffix = '', $sep = '_', $render = true)
215
-    {
214
+    public function toArray($prefix = '', $suffix = '', $sep = '_', $render = true)
215
+    {
216 216
         $out = array_merge(
217 217
             $this->toArrayMain(),
218 218
             $this->toArrayTV($render),
@@ -225,11 +225,11 @@  discard block
 block discarded – undo
225 225
     /**
226 226
      * @return null|string
227 227
      */
228
-    public function getUrl()
229
-    {
228
+    public function getUrl()
229
+    {
230 230
         $out = null;
231 231
         $id = (int)$this->getID();
232
-        if (!empty($id)) {
232
+        if (!empty($id)) {
233 233
             $out = $this->modx->makeUrl($id);
234 234
         }
235 235
 
@@ -241,10 +241,10 @@  discard block
 block discarded – undo
241 241
      * @param string $second
242 242
      * @return mixed
243 243
      */
244
-    public function getTitle($main = 'menutitle', $second = 'pagetitle')
245
-    {
244
+    public function getTitle($main = 'menutitle', $second = 'pagetitle')
245
+    {
246 246
         $title = $this->get($main);
247
-        if (empty($title) && $title !== '0') {
247
+        if (empty($title) && $title !== '0') {
248 248
             $title = $this->get($second);
249 249
         }
250 250
 
@@ -254,8 +254,8 @@  discard block
 block discarded – undo
254 254
     /**
255 255
      * @return bool
256 256
      */
257
-    public function isWebShow()
258
-    {
257
+    public function isWebShow()
258
+    {
259 259
         $pub = ($this->get('publishedon') < time() && $this->get('published'));
260 260
         $unpub = ($this->get('unpub_date') == 0 || $this->get('unpub_date') > time());
261 261
         $del = ($this->get('deleted') == 0 && ($this->get('deletedon') == 0 || $this->get('deletedon') > time()));
@@ -266,8 +266,8 @@  discard block
 block discarded – undo
266 266
     /**
267 267
      * @return $this
268 268
      */
269
-    public function touch()
270
-    {
269
+    public function touch()
270
+    {
271 271
         $this->set('editedon', time());
272 272
 
273 273
         return $this;
@@ -277,14 +277,14 @@  discard block
 block discarded – undo
277 277
      * @param $tvname
278 278
      * @return null|string
279 279
      */
280
-    public function renderTV($tvname)
281
-    {
280
+    public function renderTV($tvname)
281
+    {
282 282
         $out = null;
283
-        if ($this->getID() > 0) {
283
+        if ($this->getID() > 0) {
284 284
             include_once MODX_MANAGER_PATH . "includes/tmplvars.format.inc.php";
285 285
             include_once MODX_MANAGER_PATH . "includes/tmplvars.commands.inc.php";
286 286
             $tvval = $this->get($tvname);
287
-            if ($this->isTVarrayField($tvname) && is_array($tvval)) {
287
+            if ($this->isTVarrayField($tvname) && is_array($tvval)) {
288 288
                 $tvval = implode('||', $tvval);
289 289
             }
290 290
             $param = APIHelpers::getkey($this->tvd, $tvname, array());
@@ -301,14 +301,14 @@  discard block
 block discarded – undo
301 301
      * @param $key
302 302
      * @return mixed
303 303
      */
304
-    public function get($key)
305
-    {
304
+    public function get($key)
305
+    {
306 306
         $out = parent::get($key);
307
-        if (isset($this->tv[$key])) {
307
+        if (isset($this->tv[$key])) {
308 308
             $tpl = $this->get('template');
309 309
             $tvTPL = APIHelpers::getkey($this->tvTpl, $tpl, array());
310 310
             $tvID = APIHelpers::getkey($this->tv, $key, 0);
311
-            if (in_array($tvID, $tvTPL) && is_null($out)) {
311
+            if (in_array($tvID, $tvTPL) && is_null($out)) {
312 312
                 $out = APIHelpers::getkey($this->tvd, $key, null);
313 313
             }
314 314
         }
@@ -321,10 +321,10 @@  discard block
 block discarded – undo
321 321
      * @param $value
322 322
      * @return $this
323 323
      */
324
-    public function set($key, $value)
325
-    {
326
-        if ((is_scalar($value) || $this->isTVarrayField($key) || $this->isJsonField($key)) && is_scalar($key) && !empty($key)) {
327
-            switch ($key) {
324
+    public function set($key, $value)
325
+    {
326
+        if ((is_scalar($value) || $this->isTVarrayField($key) || $this->isJsonField($key)) && is_scalar($key) && !empty($key)) {
327
+            switch ($key) {
328 328
                 case 'parent':
329 329
                     $value = (int)$value;
330 330
                     break;
@@ -334,38 +334,38 @@  discard block
 block discarded – undo
334 334
                     break;
335 335
                 case 'published':
336 336
                     $value = (int)((bool)$value);
337
-                    if ($value) {
337
+                    if ($value) {
338 338
                         $this->field['publishedon'] = time() + $this->modxConfig('server_offset_time');
339 339
                     }
340 340
                     break;
341 341
                 case 'pub_date':
342 342
                     $value = $this->getTime($value);
343
-                    if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) {
343
+                    if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) {
344 344
                         $this->field['published'] = 1;
345 345
                         $this->field['publishedon'] = $value;
346 346
                     }
347 347
                     break;
348 348
                 case 'unpub_date':
349 349
                     $value = $this->getTime($value);
350
-                    if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) {
350
+                    if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) {
351 351
                         $this->field['published'] = 0;
352 352
                         $this->field['publishedon'] = 0;
353 353
                     }
354 354
                     break;
355 355
                 case 'deleted':
356 356
                     $value = (int)((bool)$value);
357
-                    if ($value) {
357
+                    if ($value) {
358 358
                         $this->field['deletedon'] = time() + $this->modxConfig('server_offset_time');
359
-                    } else {
359
+                    } else {
360 360
                         $this->field['deletedon'] = 0;
361 361
                     }
362 362
                     break;
363 363
                 case 'deletedon':
364 364
                     $value = $this->getTime($value);
365
-                    if ($value > 0 && time() + $this->modxConfig('server_offset_time') < $value) {
365
+                    if ($value > 0 && time() + $this->modxConfig('server_offset_time') < $value) {
366 366
                         $value = 0;
367 367
                     }
368
-                    if ($value) {
368
+                    if ($value) {
369 369
                         $this->field['deleted'] = 1;
370 370
                     }
371 371
                     break;
@@ -392,20 +392,20 @@  discard block
 block discarded – undo
392 392
      * @param int $default
393 393
      * @return int|mixed
394 394
      */
395
-    protected function getUser($value, $default = 0)
396
-    {
395
+    protected function getUser($value, $default = 0)
396
+    {
397 397
         $currentAdmin = APIHelpers::getkey($_SESSION, 'mgrInternalKey', 0);
398 398
         $value = (int)$value;
399
-        if (!empty($value)) {
399
+        if (!empty($value)) {
400 400
             $by = $this->findUserBy($value);
401
-            $exists = $this->managerUsers->exists(function ($key, Helpers\Collection $val) use ($by, $value) {
401
+            $exists = $this->managerUsers->exists(function ($key, Helpers\Collection $val) use ($by, $value){
402 402
                 return ($val->containsKey($by) && $val->get($by) === (string)$value);
403 403
             });
404
-            if (!$exists) {
404
+            if (!$exists) {
405 405
                 $value = 0;
406 406
             }
407 407
         }
408
-        if (empty($value)) {
408
+        if (empty($value)) {
409 409
             $value = empty($currentAdmin) ? $default : $currentAdmin;
410 410
         }
411 411
 
@@ -416,9 +416,9 @@  discard block
 block discarded – undo
416 416
      * @param $data
417 417
      * @return bool|string
418 418
      */
419
-    protected function findUserBy($data)
420
-    {
421
-        switch (true) {
419
+    protected function findUserBy($data)
420
+    {
421
+        switch (true) {
422 422
             case (is_int($data) || ((int)$data > 0 && (string)intval($data) === $data)):
423 423
                 $find = 'id';
424 424
                 break;
@@ -439,11 +439,11 @@  discard block
 block discarded – undo
439 439
      * @param array $data
440 440
      * @return $this
441 441
      */
442
-    public function create($data = array())
443
-    {
442
+    public function create($data = array())
443
+    {
444 444
         $this->close();
445 445
         $fld = array();
446
-        foreach ($this->tvd as $name => $tv) {
446
+        foreach ($this->tvd as $name => $tv) {
447 447
             $fld[$name] = $tv['value'];
448 448
         };
449 449
         $this->store($fld);
@@ -461,10 +461,10 @@  discard block
 block discarded – undo
461 461
      * @param $id
462 462
      * @return $this
463 463
      */
464
-    public function edit($id)
465
-    {
464
+    public function edit($id)
465
+    {
466 466
         $id = is_scalar($id) ? trim($id) : '';
467
-        if ($this->getID() != $id) {
467
+        if ($this->getID() != $id) {
468 468
             $this->close();
469 469
             $this->markAllEncode();
470 470
             $this->newDoc = false;
@@ -472,12 +472,12 @@  discard block
 block discarded – undo
472 472
             $result = $this->query("SELECT * from {$this->makeTable('site_content')} where `id`=" . (int)$id);
473 473
             $this->fromArray($this->modx->db->getRow($result));
474 474
             $result = $this->query("SELECT * from {$this->makeTable('site_tmplvar_contentvalues')} where `contentid`=" . (int)$id);
475
-            while ($row = $this->modx->db->getRow($result)) {
475
+            while ($row = $this->modx->db->getRow($result)) {
476 476
                 $this->field[$this->tvid[$row['tmplvarid']]] = $row['value'];
477 477
             }
478
-            if (empty($this->field['id'])) {
478
+            if (empty($this->field['id'])) {
479 479
                 $this->id = null;
480
-            } else {
480
+            } else {
481 481
                 $this->id = $this->field['id'];
482 482
                 $this->set('editedby', null)->touch();
483 483
                 $this->decodeFields();
@@ -494,10 +494,10 @@  discard block
 block discarded – undo
494 494
      * @param bool $clearCache
495 495
      * @return bool|null
496 496
      */
497
-    public function save($fire_events = false, $clearCache = false)
498
-    {
497
+    public function save($fire_events = false, $clearCache = false)
498
+    {
499 499
         $parent = null;
500
-        if ($this->field['pagetitle'] == '') {
500
+        if ($this->field['pagetitle'] == '') {
501 501
             $this->log['emptyPagetitle'] = 'Pagetitle is empty in <pre>' . print_r($this->field, true) . '</pre>';
502 502
 
503 503
             return false;
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
             $this->field['parent'] == 0 &&
510 510
             !$this->modxConfig('udperms_allowroot') &&
511 511
             !($uid && isset($_SESSION['mgrRole']) && $_SESSION['mgrRole'] == 1)
512
-        ) {
512
+        ) {
513 513
             $this->log['rootForbidden'] = 'Only Administrators can create documents in the root folder because udperms_allowroot setting is off';
514 514
 
515 515
             return false;
@@ -525,11 +525,11 @@  discard block
 block discarded – undo
525 525
         ), $fire_events);
526 526
 
527 527
         $fld = $this->encodeFields()->toArray(null, null, null, false);
528
-        foreach ($this->default_field as $key => $value) {
528
+        foreach ($this->default_field as $key => $value) {
529 529
             $tmp = $this->get($key);
530
-            if ($this->newDoc && (!is_int($tmp) && $tmp == '')) {
531
-                if ($tmp == $value) {
532
-                    switch ($key) {
530
+            if ($this->newDoc && (!is_int($tmp) && $tmp == '')) {
531
+                if ($tmp == $value) {
532
+                    switch ($key) {
533 533
                         case 'cacheable':
534 534
                             $value = $this->modxConfig('cache_default');
535 535
                             break;
@@ -549,11 +549,11 @@  discard block
 block discarded – undo
549 549
                 }
550 550
                 $this->field[$key] = $value;
551 551
             }
552
-            switch (true) {
552
+            switch (true) {
553 553
                 case $key == 'parent':
554 554
                     $parent = (int)$this->get($key);
555 555
                     $q = $this->query("SELECT count(`id`) FROM {$this->makeTable('site_content')} WHERE `id`='{$parent}'");
556
-                    if ($this->modx->db->getValue($q) != 1) {
556
+                    if ($this->modx->db->getValue($q) != 1) {
557 557
                         $parent = 0;
558 558
                     }
559 559
                     $this->field[$key] = $parent;
@@ -568,38 +568,38 @@  discard block
 block discarded – undo
568 568
             unset($fld[$key]);
569 569
         }
570 570
 
571
-        if (!empty($this->set)) {
572
-            if ($this->newDoc) {
571
+        if (!empty($this->set)) {
572
+            if ($this->newDoc) {
573 573
                 $SQL = "INSERT into {$this->makeTable('site_content')} SET " . implode(', ', $this->set);
574
-            } else {
574
+            } else {
575 575
                 $SQL = "UPDATE {$this->makeTable('site_content')} SET " . implode(', ',
576 576
                         $this->set) . " WHERE `id` = " . $this->id;
577 577
             }
578 578
             $this->query($SQL);
579 579
 
580
-            if ($this->newDoc) {
580
+            if ($this->newDoc) {
581 581
                 $this->id = $this->modx->db->getInsertId();
582 582
             }
583 583
 
584
-            if ($parent > 0) {
584
+            if ($parent > 0) {
585 585
                 $this->query("UPDATE {$this->makeTable('site_content')} SET `isfolder`='1' WHERE `id`='{$parent}'");
586 586
             }
587 587
         }
588 588
 
589 589
         $_deleteTVs = $_insertTVs = array();
590
-        foreach ($fld as $key => $value) {
591
-            if (empty($this->tv[$key]) || !$this->isChanged($key) || !$this->belongsToTemplate($this->tv[$key])) {
590
+        foreach ($fld as $key => $value) {
591
+            if (empty($this->tv[$key]) || !$this->isChanged($key) || !$this->belongsToTemplate($this->tv[$key])) {
592 592
                 continue;
593
-            } elseif ($value === '') {
593
+            } elseif ($value === '') {
594 594
                 $_deleteTVs[] = $this->tv[$key];
595
-            } else {
595
+            } else {
596 596
                 $_insertTVs[$this->tv[$key]] = $this->escape($value);
597 597
             }
598 598
         }
599 599
 
600
-        if (!empty($_insertTVs)) {
600
+        if (!empty($_insertTVs)) {
601 601
             $values = array();
602
-            foreach ($_insertTVs as $id => $value) {
602
+            foreach ($_insertTVs as $id => $value) {
603 603
                 $values[] = "({$this->id}, {$id}, '{$value}')";
604 604
             }
605 605
             $values = implode(',', $values);
@@ -607,17 +607,17 @@  discard block
 block discarded – undo
607 607
     `value` = VALUES(`value`)");
608 608
         }
609 609
 
610
-        if (!empty($_deleteTVs)) {
610
+        if (!empty($_deleteTVs)) {
611 611
             $ids = implode(',', $_deleteTVs);
612 612
             $this->query("DELETE FROM {$this->makeTable('site_tmplvar_contentvalues')} WHERE `contentid` = '{$this->id}' AND `tmplvarid` IN ({$ids})");
613 613
         }
614 614
 
615
-        if (!isset($this->mode)) {
615
+        if (!isset($this->mode)) {
616 616
             $this->mode = $this->newDoc ? "new" : "upd";
617 617
             $this->newDoc = false;
618 618
         }
619 619
 
620
-        if (!empty($this->groupIds)) {
620
+        if (!empty($this->groupIds)) {
621 621
             $this->setDocumentGroups($this->id, $this->groupIds);
622 622
         }
623 623
         $this->invokeEvent('OnDocFormSave', array(
@@ -627,7 +627,7 @@  discard block
 block discarded – undo
627 627
             'docObj' => $this
628 628
         ), $fire_events);
629 629
 
630
-        if ($clearCache) {
630
+        if ($clearCache) {
631 631
             $this->clearCache($fire_events);
632 632
         }
633 633
         $this->decodeFields();
@@ -639,8 +639,8 @@  discard block
 block discarded – undo
639 639
      * @param $tvId
640 640
      * @return bool
641 641
      */
642
-    protected function belongsToTemplate($tvId)
643
-    {
642
+    protected function belongsToTemplate($tvId)
643
+    {
644 644
         $template = $this->get('template');
645 645
 
646 646
         return isset($this->tvTpl[$template]) && in_array($tvId, $this->tvTpl[$template]);
@@ -651,16 +651,16 @@  discard block
 block discarded – undo
651 651
      * @return $this
652 652
      * @throws Exception
653 653
      */
654
-    public function toTrash($ids)
655
-    {
654
+    public function toTrash($ids)
655
+    {
656 656
         $ignore = $this->systemID();
657 657
         $_ids = $this->cleanIDs($ids, ',', $ignore);
658
-        if (is_array($_ids) && $_ids != array()) {
658
+        if (is_array($_ids) && $_ids != array()) {
659 659
             $id = $this->sanitarIn($_ids);
660 660
             $uid = (int)$this->modx->getLoginUserId();
661 661
             $deletedon = time() + $this->modxConfig('server_offset_time');
662 662
             $this->query("UPDATE {$this->makeTable('site_content')} SET `deleted`=1, `deletedby`={$uid}, `deletedon`={$deletedon} WHERE `id` IN ({$id})");
663
-        } else {
663
+        } else {
664 664
             throw new Exception('Invalid IDs list for mark trash: <pre>' . print_r($ids,
665 665
                     1) . '</pre> please, check ignore list: <pre>' . print_r($ignore, 1) . '</pre>');
666 666
         }
@@ -672,11 +672,11 @@  discard block
 block discarded – undo
672 672
      * @param bool $fire_events
673 673
      * @return $this
674 674
      */
675
-    public function clearTrash($fire_events = false)
676
-    {
675
+    public function clearTrash($fire_events = false)
676
+    {
677 677
         $q = $this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `deleted`='1'");
678 678
         $_ids = $this->modx->db->getColumn('id', $q);
679
-        if (is_array($_ids) && $_ids != array()) {
679
+        if (is_array($_ids) && $_ids != array()) {
680 680
             $this->invokeEvent('OnBeforeEmptyTrash', array(
681 681
                 "ids" => $_ids
682 682
             ), $fire_events);
@@ -698,15 +698,15 @@  discard block
 block discarded – undo
698 698
      * @param int|bool $depth
699 699
      * @return array
700 700
      */
701
-    public function children($ids, $depth)
702
-    {
701
+    public function children($ids, $depth)
702
+    {
703 703
         $_ids = $this->cleanIDs($ids, ',');
704
-        if (is_array($_ids) && $_ids != array()) {
704
+        if (is_array($_ids) && $_ids != array()) {
705 705
             $id = $this->sanitarIn($_ids);
706
-            if (!empty($id)) {
706
+            if (!empty($id)) {
707 707
                 $q = $this->query("SELECT `id` FROM {$this->makeTable('site_content')} where `parent` IN ({$id})");
708 708
                 $id = $this->modx->db->getColumn('id', $q);
709
-                if ($depth > 0 || $depth === true) {
709
+                if ($depth > 0 || $depth === true) {
710 710
                     $id = $this->children($id, is_bool($depth) ? $depth : ($depth - 1));
711 711
                 }
712 712
                 $_ids = array_merge($_ids, $id);
@@ -722,8 +722,8 @@  discard block
 block discarded – undo
722 722
      * @return $this
723 723
      * @throws Exception
724 724
      */
725
-    public function delete($ids, $fire_events = false)
726
-    {
725
+    public function delete($ids, $fire_events = false)
726
+    {
727 727
         $ids = $this->children($ids, true);
728 728
         $_ids = $this->cleanIDs($ids, ',', $this->systemID());
729 729
         $this->invokeEvent('OnBeforeDocFormDelete', array(
@@ -740,8 +740,8 @@  discard block
 block discarded – undo
740 740
     /**
741 741
      * @return array
742 742
      */
743
-    private function systemID()
744
-    {
743
+    private function systemID()
744
+    {
745 745
         $ignore = array(
746 746
             0, //empty document
747 747
             (int)$this->modxConfig('site_start'),
@@ -751,7 +751,7 @@  discard block
 block discarded – undo
751 751
         );
752 752
         $data = $this->query("SELECT DISTINCT setting_value FROM {$this->makeTable('web_user_settings')} WHERE `setting_name`='login_home' AND `setting_value`!=''");
753 753
         $data = $this->modx->db->makeArray($data);
754
-        foreach ($data as $item) {
754
+        foreach ($data as $item) {
755 755
             $ignore[] = (int)$item['setting_value'];
756 756
         }
757 757
 
@@ -763,22 +763,22 @@  discard block
 block discarded – undo
763 763
      * @param $alias
764 764
      * @return string
765 765
      */
766
-    protected function checkAlias($alias)
767
-    {
766
+    protected function checkAlias($alias)
767
+    {
768 768
         $alias = strtolower($alias);
769
-        if ($this->modxConfig('friendly_urls')) {
769
+        if ($this->modxConfig('friendly_urls')) {
770 770
             $_alias = $this->escape($alias);
771
-            if ((!$this->modxConfig('allow_duplicate_alias') && !$this->modxConfig('use_alias_path')) || ($this->modxConfig('allow_duplicate_alias') && $this->modxConfig('use_alias_path'))) {
771
+            if ((!$this->modxConfig('allow_duplicate_alias') && !$this->modxConfig('use_alias_path')) || ($this->modxConfig('allow_duplicate_alias') && $this->modxConfig('use_alias_path'))) {
772 772
                 $flag = $this->modx->db->getValue($this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `alias`='{$_alias}' AND `parent`={$this->get('parent')} LIMIT 1"));
773
-            } else {
773
+            } else {
774 774
                 $flag = $this->modx->db->getValue($this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `alias`='{$_alias}' LIMIT 1"));
775 775
             }
776
-            if (($flag && $this->newDoc) || (!$this->newDoc && $flag && $this->id != $flag)) {
776
+            if (($flag && $this->newDoc) || (!$this->newDoc && $flag && $this->id != $flag)) {
777 777
                 $suffix = substr($alias, -2);
778
-                if (preg_match('/-(\d+)/', $suffix, $tmp) && isset($tmp[1]) && (int)$tmp[1] > 1) {
778
+                if (preg_match('/-(\d+)/', $suffix, $tmp) && isset($tmp[1]) && (int)$tmp[1] > 1) {
779 779
                     $suffix = (int)$tmp[1] + 1;
780 780
                     $alias = substr($alias, 0, -2) . '-' . $suffix;
781
-                } else {
781
+                } else {
782 782
                     $alias .= '-2';
783 783
                 }
784 784
                 $alias = $this->checkAlias($alias);
@@ -792,8 +792,8 @@  discard block
 block discarded – undo
792 792
      * @param $key
793 793
      * @return bool
794 794
      */
795
-    public function issetField($key)
796
-    {
795
+    public function issetField($key)
796
+    {
797 797
         return (array_key_exists($key, $this->default_field) || array_key_exists($key, $this->tv));
798 798
     }
799 799
 
@@ -801,13 +801,13 @@  discard block
 block discarded – undo
801 801
      * @param bool $reload
802 802
      * @return $this
803 803
      */
804
-    protected function get_TV($reload = false)
805
-    {
804
+    protected function get_TV($reload = false)
805
+    {
806 806
         $this->modx->_TVnames = $this->loadFromCache('_TVnames');
807
-        if ($this->modx->_TVnames === false || empty($this->modx->_TVnames) || $reload) {
807
+        if ($this->modx->_TVnames === false || empty($this->modx->_TVnames) || $reload) {
808 808
             $this->modx->_TVnames = array();
809 809
             $result = $this->query('SELECT `id`,`name`,`default_text`,`type` FROM ' . $this->makeTable('site_tmplvars'));
810
-            while ($row = $this->modx->db->GetRow($result)) {
810
+            while ($row = $this->modx->db->GetRow($result)) {
811 811
                 $this->modx->_TVnames[$row['name']] = array(
812 812
                     "id"      => $row['id'],
813 813
                     "type"    => $row['type'],
@@ -818,14 +818,14 @@  discard block
 block discarded – undo
818 818
         }
819 819
         $arrayTypes = array('checkbox', 'listbox-multiple');
820 820
         $arrayTVs = array();
821
-        foreach ($this->modx->_TVnames as $name => $data) {
821
+        foreach ($this->modx->_TVnames as $name => $data) {
822 822
             $this->tvid[$data['id']] = $name;
823 823
             $this->tv[$name] = $data['id'];
824
-            if (in_array($data['type'], $arrayTypes)) {
824
+            if (in_array($data['type'], $arrayTypes)) {
825 825
                 $arrayTVs[] = $name;
826 826
             }
827 827
         }
828
-        if (empty($this->tvaFields)) {
828
+        if (empty($this->tvaFields)) {
829 829
             $this->tvaFields = $arrayTVs;
830 830
         }
831 831
         $this->loadTVTemplate()->loadTVDefault(array_values($this->tv));
@@ -836,13 +836,13 @@  discard block
 block discarded – undo
836 836
     /**
837 837
      * @return $this
838 838
      */
839
-    protected function loadTVTemplate()
840
-    {
839
+    protected function loadTVTemplate()
840
+    {
841 841
         $this->tvTpl = $this->loadFromCache('_tvTpl');
842
-        if ($this->tvTpl === false) {
842
+        if ($this->tvTpl === false) {
843 843
             $q = $this->query("SELECT `tmplvarid`, `templateid` FROM " . $this->makeTable('site_tmplvar_templates'));
844 844
             $this->tvTpl = array();
845
-            while ($item = $this->modx->db->getRow($q)) {
845
+            while ($item = $this->modx->db->getRow($q)) {
846 846
                 $this->tvTpl[$item['templateid']][] = $item['tmplvarid'];
847 847
             }
848 848
             $this->saveToCache($this->tvTpl, '_tvTpl');
@@ -855,11 +855,11 @@  discard block
 block discarded – undo
855 855
      * @param array $tvId
856 856
      * @return $this
857 857
      */
858
-    protected function loadTVDefault(array $tvId = array())
859
-    {
860
-        if (is_array($tvId) && !empty($tvId)) {
858
+    protected function loadTVDefault(array $tvId = array())
859
+    {
860
+        if (is_array($tvId) && !empty($tvId)) {
861 861
             $this->tvd = array();
862
-            foreach ($tvId as $id) {
862
+            foreach ($tvId as $id) {
863 863
                 $name = $this->tvid[$id];
864 864
                 $this->tvd[$name] = $this->modx->_TVnames[$name]['default'];
865 865
             }
@@ -873,17 +873,17 @@  discard block
 block discarded – undo
873 873
      * @return int
874 874
      * @throws Exception
875 875
      */
876
-    public function setTemplate($tpl)
877
-    {
878
-        if (!is_numeric($tpl) || $tpl != (int)$tpl) {
879
-            if (is_scalar($tpl)) {
876
+    public function setTemplate($tpl)
877
+    {
878
+        if (!is_numeric($tpl) || $tpl != (int)$tpl) {
879
+            if (is_scalar($tpl)) {
880 880
                 $sql = "SELECT `id` FROM {$this->makeTable('site_templates')} WHERE `templatename` = '" . $this->escape($tpl) . "'";
881 881
                 $rs = $this->query($sql);
882
-                if (!$rs || $this->modx->db->getRecordCount($rs) <= 0) {
882
+                if (!$rs || $this->modx->db->getRecordCount($rs) <= 0) {
883 883
                     throw new Exception("Template {$tpl} is not exists");
884 884
                 }
885 885
                 $tpl = $this->modx->db->getValue($rs);
886
-            } else {
886
+            } else {
887 887
                 throw new Exception("Invalid template name: " . print_r($tpl, 1));
888 888
             }
889 889
         }
@@ -894,14 +894,14 @@  discard block
 block discarded – undo
894 894
     /**
895 895
      * @return string
896 896
      */
897
-    protected function getAlias()
898
-    {
899
-        if ($this->modxConfig('friendly_urls') && $this->modxConfig('automatic_alias') && $this->get('alias') == '') {
897
+    protected function getAlias()
898
+    {
899
+        if ($this->modxConfig('friendly_urls') && $this->modxConfig('automatic_alias') && $this->get('alias') == '') {
900 900
             $alias = strtr($this->get('pagetitle'), $this->table);
901
-        } else {
902
-            if ($this->get('alias') != '') {
901
+        } else {
902
+            if ($this->get('alias') != '') {
903 903
                 $alias = $this->get('alias');
904
-            } else {
904
+            } else {
905 905
                 $alias = '';
906 906
             }
907 907
         }
@@ -918,10 +918,10 @@  discard block
 block discarded – undo
918 918
      *
919 919
      * Пересчет menuindex по полю таблицы site_content
920 920
      */
921
-    public function updateMenuindex($parent, $criteria = 'id', $dir = 'asc')
922
-    {
921
+    public function updateMenuindex($parent, $criteria = 'id', $dir = 'asc')
922
+    {
923 923
         $dir = strtolower($dir) == 'desc' ? 'desc' : 'asc';
924
-        if (is_integer($parent) && $criteria !== '') {
924
+        if (is_integer($parent) && $criteria !== '') {
925 925
             $this->query("SET @index := 0");
926 926
             $this->query("UPDATE {$this->makeTable('site_content')} SET `menuindex` = (@index := @index + 1) WHERE `parent`={$parent} ORDER BY {$criteria} {$dir}");
927 927
         }
@@ -934,37 +934,37 @@  discard block
 block discarded – undo
934 934
      *
935 935
      * @return $this
936 936
      */
937
-    public function setDefaultTemplate()
938
-    {
937
+    public function setDefaultTemplate()
938
+    {
939 939
         $parent = $this->get('parent');
940 940
         $template = $this->modxConfig('default_template');
941
-        switch ($this->modxConfig('auto_template_logic')) {
941
+        switch ($this->modxConfig('auto_template_logic')) {
942 942
             case 'sibling':
943
-                if (!$parent) {
943
+                if (!$parent) {
944 944
                     $site_start = $this->modxConfig('site_start');
945 945
                     $where = "sc.isfolder=0 AND sc.id!={$site_start}";
946 946
                     $sibl = $this->modx->getDocumentChildren($parent, 1, 0, 'template', $where, 'menuindex', 'ASC', 1);
947
-                    if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') {
947
+                    if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') {
948 948
                         $template = $sibl[0]['template'];
949 949
                     }
950
-                } else {
950
+                } else {
951 951
                     $sibl = $this->modx->getDocumentChildren($parent, 1, 0, 'template', 'isfolder=0', 'menuindex',
952 952
                         'ASC', 1);
953
-                    if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') {
953
+                    if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') {
954 954
                         $template = $sibl[0]['template'];
955
-                    } else {
955
+                    } else {
956 956
                         $sibl = $this->modx->getDocumentChildren($parent, 0, 0, 'template', 'isfolder=0', 'menuindex',
957 957
                             'ASC', 1);
958
-                        if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') {
958
+                        if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') {
959 959
                             $template = $sibl[0]['template'];
960 960
                         }
961 961
                     }
962 962
                 }
963 963
                 break;
964 964
             case 'parent':
965
-                if ($parent) {
965
+                if ($parent) {
966 966
                     $_parent = $this->modx->getPageInfo($parent, 0, 'template');
967
-                    if (isset($_parent['template'])) {
967
+                    if (isset($_parent['template'])) {
968 968
                         $template = $_parent['template'];
969 969
                     }
970 970
                 }
@@ -981,18 +981,18 @@  discard block
 block discarded – undo
981 981
      * @param  bool $store обновить распакованное поле
982 982
      * @return array ассоциативный массив с данными из json строки
983 983
      */
984
-    public function decodeField($field, $store = false)
985
-    {
984
+    public function decodeField($field, $store = false)
985
+    {
986 986
         $out = array();
987
-        if ($this->isDecodableField($field)) {
987
+        if ($this->isDecodableField($field)) {
988 988
             $data = $this->get($field);
989
-            if ($this->isTVarrayField($field)) {
989
+            if ($this->isTVarrayField($field)) {
990 990
                 $out = explode('||', $data);
991
-            } else {
991
+            } else {
992 992
                 $out = jsonHelper::jsonDecode($data, array('assoc' => true), true);
993 993
             }
994 994
         }
995
-        if ($store) {
995
+        if ($store) {
996 996
             $this->field[$field] = $out;
997 997
             $this->markAsDecode($field);
998 998
         }
@@ -1006,18 +1006,18 @@  discard block
 block discarded – undo
1006 1006
      * @param  bool $store обновить запакованное поле
1007 1007
      * @return string|null json строка
1008 1008
      */
1009
-    public function encodeField($field, $store = false)
1010
-    {
1009
+    public function encodeField($field, $store = false)
1010
+    {
1011 1011
         $out = null;
1012
-        if ($this->isEncodableField($field)) {
1012
+        if ($this->isEncodableField($field)) {
1013 1013
             $data = $this->get($field);
1014
-            if ($this->isTVarrayField($field)) {
1014
+            if ($this->isTVarrayField($field)) {
1015 1015
                 $out = is_array($data) ? implode('||', $data) : (string)$data;
1016
-            } else {
1016
+            } else {
1017 1017
                 $out = json_encode($data);
1018 1018
             }
1019 1019
         }
1020
-        if ($store) {
1020
+        if ($store) {
1021 1021
             $this->field[$field] = $out;
1022 1022
             $this->markAsEncode($field);
1023 1023
         }
@@ -1030,8 +1030,8 @@  discard block
 block discarded – undo
1030 1030
      * @param  string $field имя поля
1031 1031
      * @return boolean
1032 1032
      */
1033
-    public function isTVarrayField($field)
1034
-    {
1033
+    public function isTVarrayField($field)
1034
+    {
1035 1035
         return (is_scalar($field) && in_array($field, $this->tvaFields));
1036 1036
     }
1037 1037
 
@@ -1039,10 +1039,10 @@  discard block
 block discarded – undo
1039 1039
      * Пометить все поля как запакованные
1040 1040
      * @return $this
1041 1041
      */
1042
-    public function markAllEncode()
1043
-    {
1042
+    public function markAllEncode()
1043
+    {
1044 1044
         parent::markAllEncode();
1045
-        foreach ($this->tvaFields as $field) {
1045
+        foreach ($this->tvaFields as $field) {
1046 1046
             $this->markAsEncode($field);
1047 1047
         }
1048 1048
 
@@ -1053,10 +1053,10 @@  discard block
 block discarded – undo
1053 1053
      * Пометить все поля как распакованные
1054 1054
      * @return $this
1055 1055
      */
1056
-    public function markAllDecode()
1057
-    {
1056
+    public function markAllDecode()
1057
+    {
1058 1058
         parent::markAllDecode();
1059
-        foreach ($this->tvaFields as $field) {
1059
+        foreach ($this->tvaFields as $field) {
1060 1060
             $this->markAsDecode($field);
1061 1061
         }
1062 1062
 
@@ -1066,17 +1066,17 @@  discard block
 block discarded – undo
1066 1066
     /**
1067 1067
      * @param int $docId
1068 1068
      */
1069
-    public function getDocumentGroups($docId = 0)
1070
-    {
1069
+    public function getDocumentGroups($docId = 0)
1070
+    {
1071 1071
         $out = array();
1072 1072
         $doc = $this->switchObject($docId);
1073
-        if (null !== $doc->getID()) {
1073
+        if (null !== $doc->getID()) {
1074 1074
             $doc_groups = $this->makeTable('document_groups');
1075 1075
             $docgroup_names = $this->makeTable('documentgroup_names');
1076 1076
 
1077 1077
             $rs = $this->query("SELECT `dg`.`document_group`, `dgn`.`name` FROM {$doc_groups} as `dg` INNER JOIN {$docgroup_names} as `dgn` ON `dgn`.`id`=`dg`.`document_group`
1078 1078
                 WHERE `dg`.`document` = " . $doc->getID());
1079
-            while ($row = $this->modx->db->getRow($rs)) {
1079
+            while ($row = $this->modx->db->getRow($rs)) {
1080 1080
                 $out[$row['document_group']] = $row['name'];
1081 1081
             }
1082 1082
 
@@ -1091,20 +1091,20 @@  discard block
 block discarded – undo
1091 1091
      * @param array $groupIds
1092 1092
      * @return $this
1093 1093
      */
1094
-    public function setDocumentGroups($docId = 0, $groupIds = array())
1095
-    {
1096
-        if (!is_array($groupIds)) {
1094
+    public function setDocumentGroups($docId = 0, $groupIds = array())
1095
+    {
1096
+        if (!is_array($groupIds)) {
1097 1097
             return $this;
1098 1098
         }
1099
-        if ($this->newDoc && $docId == 0) {
1099
+        if ($this->newDoc && $docId == 0) {
1100 1100
             $this->groupIds = $groupIds;
1101
-        } else {
1101
+        } else {
1102 1102
             $doc = $this->switchObject($docId);
1103
-            if ($id = $doc->getID()) {
1104
-                foreach ($groupIds as $gid) {
1103
+            if ($id = $doc->getID()) {
1104
+                foreach ($groupIds as $gid) {
1105 1105
                     $this->query("REPLACE INTO {$this->makeTable('document_groups')} (`document_group`, `document`) VALUES ('{$gid}', '{$id}')");
1106 1106
                 }
1107
-                if (!$this->newDoc) {
1107
+                if (!$this->newDoc) {
1108 1108
                     $groupIds = empty($groupIds) ? '0' : implode(',', $groupIds);
1109 1109
                     $this->query("DELETE FROM {$this->makeTable('document_groups')} WHERE `document`={$id} AND `document_group` NOT IN ({$groupIds})");
1110 1110
                 }
Please login to merge, or discard this patch.
Upper-Lower-Casing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -572,7 +572,7 @@  discard block
 block discarded – undo
572 572
             if ($this->newDoc) {
573 573
                 $SQL = "INSERT into {$this->makeTable('site_content')} SET " . implode(', ', $this->set);
574 574
             } else {
575
-                $SQL = "UPDATE {$this->makeTable('site_content')} SET " . implode(', ',
575
+                $SQL = "update {$this->makeTable('site_content')} SET " . implode(', ',
576 576
                         $this->set) . " WHERE `id` = " . $this->id;
577 577
             }
578 578
             $this->query($SQL);
@@ -582,7 +582,7 @@  discard block
 block discarded – undo
582 582
             }
583 583
 
584 584
             if ($parent > 0) {
585
-                $this->query("UPDATE {$this->makeTable('site_content')} SET `isfolder`='1' WHERE `id`='{$parent}'");
585
+                $this->query("update {$this->makeTable('site_content')} SET `isfolder`='1' WHERE `id`='{$parent}'");
586 586
             }
587 587
         }
588 588
 
@@ -659,7 +659,7 @@  discard block
 block discarded – undo
659 659
             $id = $this->sanitarIn($_ids);
660 660
             $uid = (int)$this->modx->getLoginUserId();
661 661
             $deletedon = time() + $this->modxConfig('server_offset_time');
662
-            $this->query("UPDATE {$this->makeTable('site_content')} SET `deleted`=1, `deletedby`={$uid}, `deletedon`={$deletedon} WHERE `id` IN ({$id})");
662
+            $this->query("update {$this->makeTable('site_content')} SET `deleted`=1, `deletedby`={$uid}, `deletedon`={$deletedon} WHERE `id` IN ({$id})");
663 663
         } else {
664 664
             throw new Exception('Invalid IDs list for mark trash: <pre>' . print_r($ids,
665 665
                     1) . '</pre> please, check ignore list: <pre>' . print_r($ignore, 1) . '</pre>');
@@ -880,7 +880,7 @@  discard block
 block discarded – undo
880 880
                 $sql = "SELECT `id` FROM {$this->makeTable('site_templates')} WHERE `templatename` = '" . $this->escape($tpl) . "'";
881 881
                 $rs = $this->query($sql);
882 882
                 if (!$rs || $this->modx->db->getRecordCount($rs) <= 0) {
883
-                    throw new Exception("Template {$tpl} is not exists");
883
+                    throw new Exception("template {$tpl} is not exists");
884 884
                 }
885 885
                 $tpl = $this->modx->db->getValue($rs);
886 886
             } else {
@@ -923,7 +923,7 @@  discard block
 block discarded – undo
923 923
         $dir = strtolower($dir) == 'desc' ? 'desc' : 'asc';
924 924
         if (is_integer($parent) && $criteria !== '') {
925 925
             $this->query("SET @index := 0");
926
-            $this->query("UPDATE {$this->makeTable('site_content')} SET `menuindex` = (@index := @index + 1) WHERE `parent`={$parent} ORDER BY {$criteria} {$dir}");
926
+            $this->query("update {$this->makeTable('site_content')} SET `menuindex` = (@index := @index + 1) WHERE `parent`={$parent} ORDER BY {$criteria} {$dir}");
927 927
         }
928 928
 
929 929
         return $this;
Please login to merge, or discard this patch.