Completed
Pull Request — develop (#689)
by Alexander
05:50
created
manager/includes/document.parser.class.inc.php 1 patch
Braces   +59 added lines, -28 removed lines patch added patch discarded remove patch
@@ -701,13 +701,15 @@  discard block
 block discarded – undo
701 701
             $this->virtualDir = '';
702 702
         }
703 703
 
704
-        if (preg_match('@^[1-9][0-9]*$@', $q) && !isset($this->documentListing[$q])) { /* we got an ID returned, check to make sure it's not an alias */
704
+        if (preg_match('@^[1-9][0-9]*$@', $q) && !isset($this->documentListing[$q])) {
705
+/* we got an ID returned, check to make sure it's not an alias */
705 706
             /* FS#476 and FS#308: check that id is valid in terms of virtualDir structure */
706 707
             if ($this->config['use_alias_path'] == 1) {
707 708
                 if (($this->virtualDir != '' && !isset($this->documentListing[$this->virtualDir . '/' . $q]) || ($this->virtualDir == '' && !isset($this->documentListing[$q]))) && (($this->virtualDir != '' && isset($this->documentListing[$this->virtualDir]) && in_array($q, $this->getChildIds($this->documentListing[$this->virtualDir], 1))) || ($this->virtualDir == '' && in_array($q, $this->getChildIds(0, 1))))) {
708 709
                     $this->documentMethod = 'id';
709 710
                     return $q;
710
-                } else { /* not a valid id in terms of virtualDir, treat as alias */
711
+                } else {
712
+/* not a valid id in terms of virtualDir, treat as alias */
711 713
                     $this->documentMethod = 'alias';
712 714
                     return $q;
713 715
                 }
@@ -715,7 +717,8 @@  discard block
 block discarded – undo
715 717
                 $this->documentMethod = 'id';
716 718
                 return $q;
717 719
             }
718
-        } else { /* we didn't get an ID back, so instead we assume it's an alias */
720
+        } else {
721
+/* we didn't get an ID back, so instead we assume it's an alias */
719 722
             if ($this->config['friendly_alias_urls'] != 1) {
720 723
                 $q = $qOrig;
721 724
             }
@@ -745,13 +748,14 @@  discard block
 block discarded – undo
745 748
      * @param $id
746 749
      * @return array|mixed|null|string
747 750
      */
748
-    public function makePageCacheKey($id){
751
+    public function makePageCacheKey($id)
752
+    {
749 753
         $hash = $id;
750 754
         $tmp = null;
751 755
         $params = array();
752
-        if(!empty($this->systemCacheKey)){
756
+        if(!empty($this->systemCacheKey)) {
753 757
             $hash = $this->systemCacheKey;
754
-        }else {
758
+        } else {
755 759
             if (!empty($_GET)) {
756 760
                 // Sort GET parameters so that the order of parameters on the HTTP request don't affect the generated cache ID.
757 761
                 $params = $_GET;
@@ -760,7 +764,7 @@  discard block
 block discarded – undo
760 764
             }
761 765
         }
762 766
         $evtOut = $this->invokeEvent("OnMakePageCacheKey", array ("hash" => $hash, "id" => $id, 'params' => $params));
763
-        if (is_array($evtOut) && count($evtOut) > 0){
767
+        if (is_array($evtOut) && count($evtOut) > 0) {
764 768
             $tmp = array_pop($evtOut);
765 769
         }
766 770
         return empty($tmp) ? $hash : $tmp;
@@ -1087,7 +1091,8 @@  discard block
 block discarded – undo
1087 1091
         $where = "pub_date <= {$timeNow} AND pub_date!=0 AND published=0";
1088 1092
         $result_pub = $this->db->select( 'id', '[+prefix+]site_content',  $where);
1089 1093
         $this->db->update($field, '[+prefix+]site_content', $where);
1090
-        if ($this->db->getRecordCount($result_pub) >= 1) { //Event unPublished doc
1094
+        if ($this->db->getRecordCount($result_pub) >= 1) {
1095
+//Event unPublished doc
1091 1096
             while ($row_pub = $this->db->getRow($result_pub)) {
1092 1097
                 $this->invokeEvent("OnDocUnPublished", array(
1093 1098
                     "docid" => $row_pub['id']
@@ -1100,7 +1105,8 @@  discard block
 block discarded – undo
1100 1105
         $where = "unpub_date <= {$timeNow} AND unpub_date!=0 AND published=1";
1101 1106
         $result_unpub = $this->db->select( 'id', '[+prefix+]site_content',  $where);
1102 1107
         $this->db->update($field, '[+prefix+]site_content', $where);
1103
-        if ($this->db->getRecordCount($result_unpub) >= 1) { //Event unPublished doc
1108
+        if ($this->db->getRecordCount($result_unpub) >= 1) {
1109
+//Event unPublished doc
1104 1110
             while ($row_unpub = $this->db->getRow($result_unpub)) {
1105 1111
                 $this->invokeEvent("OnDocUnPublished", array(
1106 1112
                     "docid" => $row_unpub['id']
@@ -1187,10 +1193,18 @@  discard block
 block discarded – undo
1187 1193
             return array();
1188 1194
         }
1189 1195
         $spacer = md5('<<<EVO>>>');
1190
-        if($left==='{{' && strpos($content,';}}')!==false)  $content = str_replace(';}}', sprintf(';}%s}',   $spacer),$content);
1191
-        if($left==='{{' && strpos($content,'{{}}')!==false) $content = str_replace('{{}}',sprintf('{%$1s{}%$1s}',$spacer),$content);
1192
-        if($left==='[[' && strpos($content,']]]]')!==false) $content = str_replace(']]]]',sprintf(']]%s]]',  $spacer),$content);
1193
-        if($left==='[[' && strpos($content,']]]')!==false)  $content = str_replace(']]]', sprintf(']%s]]',   $spacer),$content);
1196
+        if($left==='{{' && strpos($content,';}}')!==false) {
1197
+            $content = str_replace(';}}', sprintf(';}%s}',   $spacer),$content);
1198
+        }
1199
+        if($left==='{{' && strpos($content,'{{}}')!==false) {
1200
+            $content = str_replace('{{}}',sprintf('{%$1s{}%$1s}',$spacer),$content);
1201
+        }
1202
+        if($left==='[[' && strpos($content,']]]]')!==false) {
1203
+            $content = str_replace(']]]]',sprintf(']]%s]]',  $spacer),$content);
1204
+        }
1205
+        if($left==='[[' && strpos($content,']]]')!==false) {
1206
+            $content = str_replace(']]]', sprintf(']%s]]',   $spacer),$content);
1207
+        }
1194 1208
 
1195 1209
         $pos['<![CDATA['] = strpos($content, '<![CDATA[');
1196 1210
         $pos[']]>'] = strpos($content, ']]>');
@@ -1243,7 +1257,8 @@  discard block
 block discarded – undo
1243 1257
                         }
1244 1258
                     }
1245 1259
 
1246
-                    if (!in_array($fetch, $tags)) {  // Avoid double Matches
1260
+                    if (!in_array($fetch, $tags)) {
1261
+// Avoid double Matches
1247 1262
                         $tags[] = $fetch; // Fetch
1248 1263
                     };
1249 1264
                     $fetch = ''; // and reset
@@ -1261,7 +1276,9 @@  discard block
 block discarded – undo
1261 1276
             }
1262 1277
         }
1263 1278
         foreach($tags as $i=>$tag) {
1264
-            if(strpos($tag,$spacer)!==false) $tags[$i] = str_replace($spacer, '', $tag);
1279
+            if(strpos($tag,$spacer)!==false) {
1280
+                $tags[$i] = str_replace($spacer, '', $tag);
1281
+            }
1265 1282
         }
1266 1283
         return $tags;
1267 1284
     }
@@ -1301,7 +1318,10 @@  discard block
 block discarded – undo
1301 1318
         }
1302 1319
 
1303 1320
         foreach ($matches[1] as $i => $key) {
1304
-            if(strpos($key,'[+')!==false) continue; // Allow chunk {{chunk?&param=`xxx`}} with [*tv_name_[+param+]*] as content
1321
+            if(strpos($key,'[+')!==false) {
1322
+                continue;
1323
+            }
1324
+            // Allow chunk {{chunk?&param=`xxx`}} with [*tv_name_[+param+]*] as content
1305 1325
             if (substr($key, 0, 1) == '#') {
1306 1326
                 $key = substr($key, 1);
1307 1327
             } // remove # for QuickEdit format
@@ -2026,7 +2046,8 @@  discard block
 block discarded – undo
2026 2046
      * @return mixed|string
2027 2047
      */
2028 2048
     public function _getSGVar($value)
2029
-    { // Get super globals
2049
+    {
2050
+// Get super globals
2030 2051
         $key = $value;
2031 2052
         $_ = $this->config['enable_filter'];
2032 2053
         $this->config['enable_filter'] = 1;
@@ -2430,7 +2451,8 @@  discard block
 block discarded – undo
2430 2451
         if ($this->config['friendly_urls'] == 1) {
2431 2452
             $aliases = array();
2432 2453
             if (is_array($this->documentListing)) {
2433
-                foreach ($this->documentListing as $path => $docid) { // This is big Loop on large site!
2454
+                foreach ($this->documentListing as $path => $docid) {
2455
+// This is big Loop on large site!
2434 2456
                     $aliases[$docid] = $path;
2435 2457
                     $isfolder[$docid] = $this->aliasListing[$docid]['isfolder'];
2436 2458
                 }
@@ -2463,7 +2485,7 @@  discard block
 block discarded – undo
2463 2485
             $isfriendly = ($this->config['friendly_alias_urls'] == 1 ? 1 : 0);
2464 2486
             $pref = $this->config['friendly_url_prefix'];
2465 2487
             $suff = $this->config['friendly_url_suffix'];
2466
-            $documentSource = preg_replace_callback($in, function ($m) use ($aliases, $isfolder, $isfriendly, $pref, $suff) {
2488
+            $documentSource = preg_replace_callback($in, function ($m) use ($aliases, $isfolder, $isfriendly, $pref, $suff){
2467 2489
                 global $modx;
2468 2490
                 $thealias = $aliases[$m[1]];
2469 2491
                 $thefolder = $isfolder[$m[1]];
@@ -4239,7 +4261,8 @@  discard block
 block discarded – undo
4239 4261
         if (isset ($this->snippetCache[$snippetName])) {
4240 4262
             $snippet = $this->snippetCache[$snippetName];
4241 4263
             $properties = !empty($this->snippetCache[$snippetName . "Props"]) ? $this->snippetCache[$snippetName . "Props"] : '';
4242
-        } else { // not in cache so let's check the db
4264
+        } else {
4265
+// not in cache so let's check the db
4243 4266
             $sql = "SELECT ss.`name`, ss.`snippet`, ss.`properties`, sm.properties as `sharedproperties` FROM " . $this->getFullTableName("site_snippets") . " as ss LEFT JOIN " . $this->getFullTableName('site_modules') . " as sm on sm.guid=ss.moduleguid WHERE ss.`name`='" . $this->db->escape($snippetName) . "'  AND ss.disabled=0;";
4244 4267
             $result = $this->db->query($sql);
4245 4268
             if ($this->db->getRecordCount($result) == 1) {
@@ -4740,7 +4763,7 @@  discard block
 block discarded – undo
4740 4763
             $result = $this->db->makeArray($rs);
4741 4764
 
4742 4765
             // get default/built-in template variables
4743
-            if(is_array($docRow)){
4766
+            if(is_array($docRow)) {
4744 4767
                 ksort($docRow);
4745 4768
 
4746 4769
                 foreach ($docRow as $key => $value) {
@@ -5219,12 +5242,16 @@  discard block
 block discarded – undo
5219 5242
             return '';
5220 5243
         } // nothing to register
5221 5244
         if (!is_array($options)) {
5222
-            if (is_bool($options))  // backward compatibility with old plaintext parameter
5245
+            if (is_bool($options)) {
5246
+                // backward compatibility with old plaintext parameter
5223 5247
             {
5224 5248
                 $options = array('plaintext' => $options);
5225
-            } elseif (is_string($options)) // Also allow script name as 2nd param
5249
+            }
5250
+            } elseif (is_string($options)) {
5251
+                // Also allow script name as 2nd param
5226 5252
             {
5227 5253
                 $options = array('name' => $options);
5254
+            }
5228 5255
             } else {
5229 5256
                 $options = array();
5230 5257
             }
@@ -5236,7 +5263,8 @@  discard block
 block discarded – undo
5236 5263
         unset($overwritepos); // probably unnecessary--just making sure
5237 5264
 
5238 5265
         $useThisVer = true;
5239
-        if (isset($this->loadedjscripts[$key])) { // a matching script was found
5266
+        if (isset($this->loadedjscripts[$key])) {
5267
+// a matching script was found
5240 5268
             // if existing script is a startup script, make sure the candidate is also a startup script
5241 5269
             if ($this->loadedjscripts[$key]['startup']) {
5242 5270
                 $startup = true;
@@ -5256,7 +5284,8 @@  discard block
 block discarded – undo
5256 5284
                     // overwrite the old script (the position may be important for dependent scripts)
5257 5285
                     $overwritepos = $this->loadedjscripts[$key]['pos'];
5258 5286
                 }
5259
-            } else { // Use the original version
5287
+            } else {
5288
+// Use the original version
5260 5289
                 if ($startup == true && $this->loadedjscripts[$key]['startup'] == false) {
5261 5290
                     // need to move the exisiting script to the head
5262 5291
                     $version = $this->loadedjscripts[$key][$version];
@@ -5381,7 +5410,8 @@  discard block
 block discarded – undo
5381 5410
         }
5382 5411
 
5383 5412
         $results = null;
5384
-        foreach ($this->pluginEvent[$evtName] as $pluginName) { // start for loop
5413
+        foreach ($this->pluginEvent[$evtName] as $pluginName) {
5414
+// start for loop
5385 5415
             if ($this->dumpPlugins) {
5386 5416
                 $eventtime = $this->getMicroTime();
5387 5417
             }
@@ -5929,7 +5959,8 @@  discard block
 block discarded – undo
5929 5959
      * @return bool
5930 5960
      */
5931 5961
     public function isSafeCode($phpcode = '', $safe_functions = '')
5932
-    { // return true or false
5962
+    {
5963
+// return true or false
5933 5964
         if ($safe_functions == '') {
5934 5965
             return false;
5935 5966
         }
@@ -6345,7 +6376,7 @@  discard block
 block discarded – undo
6345 6376
             $args = array_pad(array(), $_, '$var');
6346 6377
             $args = implode(", ", $args);
6347 6378
             $modx = &$this;
6348
-            $args = preg_replace_callback('/\$var/', function () use ($modx, &$tmp, $val) {
6379
+            $args = preg_replace_callback('/\$var/', function () use ($modx, &$tmp, $val){
6349 6380
                 $arg = $val['args'][$tmp - 1];
6350 6381
                 switch (true) {
6351 6382
                     case is_null($arg): {
Please login to merge, or discard this patch.