Completed
Push — develop ( d271f8...cb7ecf )
by Serg
08:17 queued 57s
created
manager/includes/extenders/modifiers/mdf_getimage.inc.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,16 +1,16 @@
 block discarded – undo
1 1
 <?php
2 2
 $pattern = '/<img[\s\n]+.*src=[\s\n]*"([^"]+\.(jpg|jpeg|png|gif))"[^>]+>/i';
3
-preg_match_all($pattern , $value , $images);
4
-if($opt==='')
3
+preg_match_all($pattern, $value, $images);
4
+if ($opt === '')
5 5
 {
6
-    if($images[1][0])  return $images[1][0];
6
+    if ($images[1][0])  return $images[1][0];
7 7
     else               return '';
8 8
 }
9 9
 else
10 10
 {
11
-    foreach($images[0] as $i=>$image)
11
+    foreach ($images[0] as $i=>$image)
12 12
     {
13
-        if(strpos($image,$opt)!==false) return $images[1][$i];
13
+        if (strpos($image, $opt) !== false) return $images[1][$i];
14 14
     }
15 15
 }
16 16
 
Please login to merge, or discard this patch.
Braces   +11 added lines, -10 removed lines patch added patch discarded remove patch
@@ -1,16 +1,17 @@
 block discarded – undo
1 1
 <?php
2 2
 $pattern = '/<img[\s\n]+.*src=[\s\n]*"([^"]+\.(jpg|jpeg|png|gif))"[^>]+>/i';
3 3
 preg_match_all($pattern , $value , $images);
4
-if($opt==='')
5
-{
6
-    if($images[1][0])  return $images[1][0];
7
-    else               return '';
8
-}
9
-else
10
-{
11
-    foreach($images[0] as $i=>$image)
12
-    {
13
-        if(strpos($image,$opt)!==false) return $images[1][$i];
4
+if($opt==='') {
5
+    if($images[1][0]) {
6
+        return $images[1][0];
7
+    } else {
8
+        return '';
9
+    }
10
+    } else {
11
+    foreach($images[0] as $i=>$image) {
12
+        if(strpos($image,$opt)!==false) {
13
+            return $images[1][$i];
14
+        }
14 15
     }
15 16
 }
16 17
 
Please login to merge, or discard this patch.
manager/includes/extenders/modifiers/mdf_wordwrap.inc.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,2 +1,2 @@
 block discarded – undo
1 1
 <?php
2
-return preg_replace_callback("~(\b\w+\b)~",function($m) use($wrapat) {return wordwrap($m[1],$wrapat,' ',1);},$value);
2
+return preg_replace_callback("~(\b\w+\b)~", function($m) use($wrapat) {return wordwrap($m[1], $wrapat, ' ', 1); },$value);
Please login to merge, or discard this patch.
manager/includes/extenders/modifiers/mdf_addbreak.inc.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,21 +1,21 @@
 block discarded – undo
1 1
 <?php
2 2
 $text = $modx->filter->parseDocumentSource($value);
3
-$text = str_replace(array("\r\n","\r"),"\n",$text);
3
+$text = str_replace(array("\r\n", "\r"), "\n", $text);
4 4
 
5 5
 $blockElms  = 'br,table,tbody,tr,td,th,thead,tfoot,caption,colgroup,div';
6 6
 $blockElms .= ',dl,dd,dt,ul,ol,li,pre,select,option,form,map,area,blockquote';
7 7
 $blockElms .= ',address,math,style,input,p,h1,h2,h3,h4,h5,h6,hr,object,param,embed';
8 8
 $blockElms .= ',noframes,noscript,section,article,aside,hgroup,footer,address,code';
9 9
 $blockElms = explode(',', $blockElms);
10
-$lines = explode("\n",$text);
10
+$lines = explode("\n", $text);
11 11
 $c = count($lines);
12
-foreach($lines as $i=>$line)
12
+foreach ($lines as $i=>$line)
13 13
 {
14 14
     $line = rtrim($line);
15
-    if($i===$c-1) break;
16
-    foreach($blockElms as $block)
15
+    if ($i === $c - 1) break;
16
+    foreach ($blockElms as $block)
17 17
     {
18
-        if(preg_match("@</?{$block}" . '[^>]*>$@',$line))
18
+        if (preg_match("@</?{$block}".'[^>]*>$@', $line))
19 19
             continue 2;
20 20
     }
21 21
     $lines[$i] = "{$line}<br />";
Please login to merge, or discard this patch.
Braces   +8 added lines, -7 removed lines patch added patch discarded remove patch
@@ -9,14 +9,15 @@
 block discarded – undo
9 9
 $blockElms = explode(',', $blockElms);
10 10
 $lines = explode("\n",$text);
11 11
 $c = count($lines);
12
-foreach($lines as $i=>$line)
13
-{
12
+foreach($lines as $i=>$line) {
14 13
     $line = rtrim($line);
15
-    if($i===$c-1) break;
16
-    foreach($blockElms as $block)
17
-    {
18
-        if(preg_match("@</?{$block}" . '[^>]*>$@',$line))
19
-            continue 2;
14
+    if($i===$c-1) {
15
+        break;
16
+    }
17
+    foreach($blockElms as $block) {
18
+        if(preg_match("@</?{$block}" . '[^>]*>$@',$line)) {
19
+                    continue 2;
20
+        }
20 21
     }
21 22
     $lines[$i] = "{$line}<br />";
22 23
 }
Please login to merge, or discard this patch.
manager/includes/extenders/modifiers/mdf_memberof.inc.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -2,22 +2,22 @@
 block discarded – undo
2 2
 $userID = abs($modx->getLoginUserID('web'));
3 3
 $modx->qs_hash = md5($modx->qs_hash."^{$userID}^");
4 4
 
5
-$groupNames = ($this->strlen($opt) > 0 ) ? explode(',',$opt) : array();
5
+$groupNames = ($this->strlen($opt) > 0) ? explode(',', $opt) : array();
6 6
 
7 7
 // if $groupNames is not an array return false
8
-if(!is_array($groupNames)) return 0;
8
+if (!is_array($groupNames)) return 0;
9 9
 
10 10
 // Creates an array with all webgroups the user id is in
11 11
 if (isset($modx->filter->cache['mo'][$userID])) $grpNames = $modx->filter->cache['mo'][$userID];
12 12
 else {
13
-    $from = sprintf("[+prefix+]webgroup_names wgn INNER JOIN [+prefix+]web_groups wg ON wg.webgroup=wgn.id AND wg.webuser='%s'",$userID);
14
-    $rs = $modx->db->select('wgn.name',$from);
15
-    $modx->filter->cache['mo'][$userID] = $grpNames = $modx->db->getColumn('name',$rs);
13
+    $from = sprintf("[+prefix+]webgroup_names wgn INNER JOIN [+prefix+]web_groups wg ON wg.webgroup=wgn.id AND wg.webuser='%s'", $userID);
14
+    $rs = $modx->db->select('wgn.name', $from);
15
+    $modx->filter->cache['mo'][$userID] = $grpNames = $modx->db->getColumn('name', $rs);
16 16
 }
17 17
 
18 18
 // Check if a supplied group matches a webgroup from the array we just created
19
-foreach($groupNames as $k=>$v) {
20
-    if(in_array(trim($v),$grpNames)) return 1;
19
+foreach ($groupNames as $k=>$v) {
20
+    if (in_array(trim($v), $grpNames)) return 1;
21 21
 }
22 22
 
23 23
 // If we get here the above logic did not find a match, so return false
Please login to merge, or discard this patch.
Braces   +10 added lines, -5 removed lines patch added patch discarded remove patch
@@ -5,11 +5,14 @@  discard block
 block discarded – undo
5 5
 $groupNames = ($this->strlen($opt) > 0 ) ? explode(',',$opt) : array();
6 6
 
7 7
 // if $groupNames is not an array return false
8
-if(!is_array($groupNames)) return 0;
8
+if(!is_array($groupNames)) {
9
+    return 0;
10
+}
9 11
 
10 12
 // Creates an array with all webgroups the user id is in
11
-if (isset($modx->filter->cache['mo'][$userID])) $grpNames = $modx->filter->cache['mo'][$userID];
12
-else {
13
+if (isset($modx->filter->cache['mo'][$userID])) {
14
+    $grpNames = $modx->filter->cache['mo'][$userID];
15
+} else {
13 16
     $from = sprintf("[+prefix+]webgroup_names wgn INNER JOIN [+prefix+]web_groups wg ON wg.webgroup=wgn.id AND wg.webuser='%s'",$userID);
14 17
     $rs = $modx->db->select('wgn.name',$from);
15 18
     $modx->filter->cache['mo'][$userID] = $grpNames = $modx->db->getColumn('name',$rs);
@@ -17,8 +20,10 @@  discard block
 block discarded – undo
17 20
 
18 21
 // Check if a supplied group matches a webgroup from the array we just created
19 22
 foreach($groupNames as $k=>$v) {
20
-    if(in_array(trim($v),$grpNames)) return 1;
21
-}
23
+    if(in_array(trim($v),$grpNames)) {
24
+        return 1;
25
+    }
26
+    }
22 27
 
23 28
 // If we get here the above logic did not find a match, so return false
24 29
 return 0;
Please login to merge, or discard this patch.
manager/includes/extenders/message.quit.inc.php 2 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -19,60 +19,60 @@
 block discarded – undo
19 19
 </head><body>
20 20
 ";
21 21
 if($is_error) {
22
-	$parsedMessageString .= "<h3 style='color:red;background:#e0e0e0;padding:2px;'>&nbsp;MODX Parse Error </h3>
22
+    $parsedMessageString .= "<h3 style='color:red;background:#e0e0e0;padding:2px;'>&nbsp;MODX Parse Error </h3>
23 23
 	<table border='0' cellpadding='1' cellspacing='0'>
24 24
 	<tr><td colspan='3'>MODX encountered the following error while attempting to parse the requested resource:</td></tr>
25 25
 	<tr><td colspan='3'><b style='color:red;'>&laquo; $msg &raquo;</b></td></tr>";
26 26
 } else {
27
-	$parsedMessageString .= "<h3 style='color:#003399; background:#eeeeee;padding:2px;'>&nbsp;MODX Debug/ stop message </h3>
27
+    $parsedMessageString .= "<h3 style='color:#003399; background:#eeeeee;padding:2px;'>&nbsp;MODX Debug/ stop message </h3>
28 28
 	<table border='0' cellpadding='1' cellspacing='0'>
29 29
 	<tr><td colspan='3'>The MODX parser recieved the following debug/ stop message:</td></tr>
30 30
 	<tr><td colspan='3'><b style='color:#003399;'>&laquo; $msg &raquo;</b></td></tr>";
31 31
 }
32 32
 
33 33
 if(!empty($query)) {
34
-	$parsedMessageString .= "<tr><td colspan='3'><hr size='1' width='98%' style='color:#e0e0e0'/><b style='color:#999;font-size: 9px;border-left:1px solid #c0c0c0; margin-left:10px;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SQL:&nbsp;<span id='sqlHolder'>$query</span></b><hr size='1' width='98%' style='color:#e0e0e0'/>
34
+    $parsedMessageString .= "<tr><td colspan='3'><hr size='1' width='98%' style='color:#e0e0e0'/><b style='color:#999;font-size: 9px;border-left:1px solid #c0c0c0; margin-left:10px;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SQL:&nbsp;<span id='sqlHolder'>$query</span></b><hr size='1' width='98%' style='color:#e0e0e0'/>
35 35
 	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:copyToClip();' style='color:#821517;font-size: 9px; text-decoration: none'>[Copy SQL to ClipBoard]</a><textarea id='holdtext' style='display:none;'></textarea></td></tr>";
36 36
 }
37 37
 
38 38
 if($text!='') {
39 39
 
40
-	$errortype = array (
41
-		E_ERROR          => "Error",
42
-		E_WARNING        => "Warning",
43
-		E_PARSE          => "Parsing Error",
44
-		E_NOTICE          => "Notice",
45
-		E_CORE_ERROR      => "Core Error",
46
-		E_CORE_WARNING    => "Core Warning",
47
-		E_COMPILE_ERROR  => "Compile Error",
48
-		E_COMPILE_WARNING => "Compile Warning",
49
-		E_USER_ERROR      => "User Error",
50
-		E_USER_WARNING    => "User Warning",
51
-		E_USER_NOTICE    => "User Notice",
52
-	);
40
+    $errortype = array (
41
+        E_ERROR          => "Error",
42
+        E_WARNING        => "Warning",
43
+        E_PARSE          => "Parsing Error",
44
+        E_NOTICE          => "Notice",
45
+        E_CORE_ERROR      => "Core Error",
46
+        E_CORE_WARNING    => "Core Warning",
47
+        E_COMPILE_ERROR  => "Compile Error",
48
+        E_COMPILE_WARNING => "Compile Warning",
49
+        E_USER_ERROR      => "User Error",
50
+        E_USER_WARNING    => "User Warning",
51
+        E_USER_NOTICE    => "User Notice",
52
+    );
53 53
 
54
-	$parsedMessageString .= "<tr><td>&nbsp;</td></tr><tr><td colspan='3'><b>PHP error debug</b></td></tr>";
54
+    $parsedMessageString .= "<tr><td>&nbsp;</td></tr><tr><td colspan='3'><b>PHP error debug</b></td></tr>";
55 55
 
56
-	$parsedMessageString .= "<tr><td valign='top'>&nbsp;&nbsp;Error: </td>";
57
-	$parsedMessageString .= "<td colspan='2'>$text</td><td>&nbsp;</td>";
58
-	$parsedMessageString .= "</tr>";
56
+    $parsedMessageString .= "<tr><td valign='top'>&nbsp;&nbsp;Error: </td>";
57
+    $parsedMessageString .= "<td colspan='2'>$text</td><td>&nbsp;</td>";
58
+    $parsedMessageString .= "</tr>";
59 59
 
60
-	$parsedMessageString .= "<tr><td valign='top'>&nbsp;&nbsp;Error type/ Nr.: </td>";
61
-	$parsedMessageString .= "<td colspan='2'>".$errortype[$nr]." - $nr</b></td><td>&nbsp;</td>";
62
-	$parsedMessageString .= "</tr>";
60
+    $parsedMessageString .= "<tr><td valign='top'>&nbsp;&nbsp;Error type/ Nr.: </td>";
61
+    $parsedMessageString .= "<td colspan='2'>".$errortype[$nr]." - $nr</b></td><td>&nbsp;</td>";
62
+    $parsedMessageString .= "</tr>";
63 63
 
64
-	$parsedMessageString .= "<tr><td>&nbsp;&nbsp;File: </td>";
65
-	$parsedMessageString .= "<td colspan='2'>$file</td><td>&nbsp;</td>";
66
-	$parsedMessageString .= "</tr>";
64
+    $parsedMessageString .= "<tr><td>&nbsp;&nbsp;File: </td>";
65
+    $parsedMessageString .= "<td colspan='2'>$file</td><td>&nbsp;</td>";
66
+    $parsedMessageString .= "</tr>";
67 67
 
68
-	$parsedMessageString .= "<tr><td>&nbsp;&nbsp;Line: </td>";
69
-	$parsedMessageString .= "<td colspan='2'>$line</td><td>&nbsp;</td>";
70
-	$parsedMessageString .= "</tr>";
71
-	if($source!='') {
72
-		$parsedMessageString .= "<tr><td valign='top'>&nbsp;&nbsp;Line $line source: </td>";
73
-		$parsedMessageString .= "<td colspan='2'>$source</td><td>&nbsp;</td>";
74
-		$parsedMessageString .= "</tr>";
75
-	}
68
+    $parsedMessageString .= "<tr><td>&nbsp;&nbsp;Line: </td>";
69
+    $parsedMessageString .= "<td colspan='2'>$line</td><td>&nbsp;</td>";
70
+    $parsedMessageString .= "</tr>";
71
+    if($source!='') {
72
+        $parsedMessageString .= "<tr><td valign='top'>&nbsp;&nbsp;Line $line source: </td>";
73
+        $parsedMessageString .= "<td colspan='2'>$source</td><td>&nbsp;</td>";
74
+        $parsedMessageString .= "</tr>";
75
+    }
76 76
 }
77 77
 
78 78
 $parsedMessageString .= "<tr><td>&nbsp;</td></tr><tr><td colspan='3'><b>Parser timing</b></td></tr>";
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Message Quit Template
4 4
  *
5 5
  */
6
-if(( ! defined('IN_MANAGER_MODE') || IN_MANAGER_MODE !== true) && IN_PARSER_MODE!="true") {
6
+if ((!defined('IN_MANAGER_MODE') || IN_MANAGER_MODE !== true) && IN_PARSER_MODE != "true") {
7 7
     die("<b>INCLUDE ACCESS ERROR</b><br /><br />Direct access to this file prohibited.");
8 8
 }
9 9
 
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 </script>
21 21
 </head><body>
22 22
 ";
23
-if($is_error) {
23
+if ($is_error) {
24 24
 	$parsedMessageString .= "<h3 style='color:red;background:#e0e0e0;padding:2px;'>&nbsp;MODX Parse Error </h3>
25 25
 	<table border='0' cellpadding='1' cellspacing='0'>
26 26
 	<tr><td colspan='3'>MODX encountered the following error while attempting to parse the requested resource:</td></tr>
@@ -32,14 +32,14 @@  discard block
 block discarded – undo
32 32
 	<tr><td colspan='3'><b style='color:#003399;'>&laquo; $msg &raquo;</b></td></tr>";
33 33
 }
34 34
 
35
-if(!empty($query)) {
35
+if (!empty($query)) {
36 36
 	$parsedMessageString .= "<tr><td colspan='3'><hr size='1' width='98%' style='color:#e0e0e0'/><b style='color:#999;font-size: 9px;border-left:1px solid #c0c0c0; margin-left:10px;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SQL:&nbsp;<span id='sqlHolder'>$query</span></b><hr size='1' width='98%' style='color:#e0e0e0'/>
37 37
 	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:copyToClip();' style='color:#821517;font-size: 9px; text-decoration: none'>[Copy SQL to ClipBoard]</a><textarea id='holdtext' style='display:none;'></textarea></td></tr>";
38 38
 }
39 39
 
40
-if($text!='') {
40
+if ($text != '') {
41 41
 
42
-	$errortype = array (
42
+	$errortype = array(
43 43
 		E_ERROR          => "Error",
44 44
 		E_WARNING        => "Warning",
45 45
 		E_PARSE          => "Parsing Error",
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 	$parsedMessageString .= "<tr><td>&nbsp;&nbsp;Line: </td>";
71 71
 	$parsedMessageString .= "<td colspan='2'>$line</td><td>&nbsp;</td>";
72 72
 	$parsedMessageString .= "</tr>";
73
-	if($source!='') {
73
+	if ($source != '') {
74 74
 		$parsedMessageString .= "<tr><td valign='top'>&nbsp;&nbsp;Line $line source: </td>";
75 75
 		$parsedMessageString .= "<td colspan='2'>$source</td><td>&nbsp;</td>";
76 76
 		$parsedMessageString .= "</tr>";
Please login to merge, or discard this patch.
manager/includes/extenders/modifiers.class.inc.php 5 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -598,7 +598,7 @@  discard block
 block discarded – undo
598 598
                     else               $opt = true;
599 599
                 }
600 600
                 elseif(isset($modx->config['mce_element_format'])&&$modx->config['mce_element_format']==='html')
601
-                                       $opt = false;
601
+                                        $opt = false;
602 602
                 else                   $opt = true;
603 603
                 return nl2br($value,$opt);
604 604
             case 'ltrim':
@@ -1022,7 +1022,7 @@  discard block
 block discarded – undo
1022 1022
         {
1023 1023
             $bt = $content;
1024 1024
             if(strpos($content,'[*')!==false && $modx->documentIdentifier)
1025
-                                              $content = $modx->mergeDocumentContent($content);
1025
+                                                $content = $modx->mergeDocumentContent($content);
1026 1026
             if(strpos($content,'[(')!==false) $content = $modx->mergeSettingsContent($content);
1027 1027
             if(strpos($content,'{{')!==false) $content = $modx->mergeChunkContent($content);
1028 1028
             if(strpos($content,'[!')!==false) $content = str_replace(array('[!','!]'),array('[[',']]'),$content);
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -349,7 +349,7 @@
 block discarded – undo
349 349
                 $conditional = implode(' ',$this->condition);
350 350
                 $isvalid = (int)(eval("return ({$conditional});"));
351 351
                 if ($isvalid) return $this->srcValue;
352
-                return NULL;
352
+                return null;
353 353
             case 'then':
354 354
                 $conditional = implode(' ',$this->condition);
355 355
                 $isvalid = (int)eval("return ({$conditional});");
Please login to merge, or discard this patch.
Doc Comments   +27 added lines, -1 removed lines patch added patch discarded remove patch
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
     /**
95 95
      * @param string $mode
96 96
      * @param string $modifiers
97
-     * @return bool|string
97
+     * @return false|string
98 98
      */
99 99
     public function _getDelim($mode,$modifiers) {
100 100
         $c = substr($modifiers,0,1);
@@ -131,6 +131,14 @@  discard block
 block discarded – undo
131 131
             return $opt;
132 132
         }
133 133
     }
134
+
135
+    /**
136
+     * @param string $mode
137
+     * @param false|string $delim
138
+     * @param string $modifiers
139
+     *
140
+     * @return string
141
+     */
134 142
     public function _getRemainModifiers($mode,$delim,$modifiers) {
135 143
         if($delim) {
136 144
             if($mode=='(')
@@ -158,6 +166,9 @@  discard block
 block discarded – undo
158 166
         return substr($string,strpos($string, $delim)+$len);
159 167
     }
160 168
 
169
+    /**
170
+     * @param string $modifiers
171
+     */
161 172
     public function splitEachModifiers($modifiers) {
162 173
         $modx = evolutionCMS();
163 174
 
@@ -227,6 +238,10 @@  discard block
 block discarded – undo
227 238
         return $result;
228 239
     }
229 240
 
241
+    /**
242
+     * @param string $key
243
+     * @param string $value
244
+     */
230 245
     public function parsePhx($key,$value,$modifiers)
231 246
     {
232 247
         $modx = evolutionCMS();
@@ -293,6 +308,10 @@  discard block
 block discarded – undo
293 308
         else                  return true;
294 309
     }
295 310
 
311
+    /**
312
+     * @param string $cmd
313
+     * @param string $opt
314
+     */
296 315
     public function getValueFromPreset($key, $value, $cmd, $opt)
297 316
     {
298 317
         $modx = evolutionCMS();
@@ -978,6 +997,9 @@  discard block
 block discarded – undo
978 997
         return $value;
979 998
     }
980 999
 
1000
+    /**
1001
+     * @param string $cmd
1002
+     */
981 1003
     public function includeMdfFile($cmd) {
982 1004
         $modx = evolutionCMS();
983 1005
         $key = $this->key;
@@ -1133,6 +1155,10 @@  discard block
 block discarded – undo
1133 1155
     }
1134 1156
 
1135 1157
     // Sets a placeholder variable which can only be access by Modifiers
1158
+
1159
+    /**
1160
+     * @param string $value
1161
+     */
1136 1162
     public function setModifiersVariable($key, $value) {
1137 1163
         if ($key != 'phx' && $key != 'dummy') $this->placeholders[$key] = $value;
1138 1164
     }
Please login to merge, or discard this patch.
Spacing   +350 added lines, -350 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if(!defined('MODX_CORE_PATH')) define('MODX_CORE_PATH', MODX_MANAGER_PATH.'includes/');
3
+if (!defined('MODX_CORE_PATH')) define('MODX_CORE_PATH', MODX_MANAGER_PATH.'includes/');
4 4
 
5
-class MODIFIERS {
5
+class MODIFIERS{
6 6
     /**
7 7
      * @var array
8 8
      */
@@ -70,14 +70,14 @@  discard block
 block discarded – undo
70 70
      * @param string $modifiers
71 71
      * @return bool|mixed|string
72 72
      */
73
-    public function phxFilter($key,$value,$modifiers)
73
+    public function phxFilter($key, $value, $modifiers)
74 74
     {
75 75
         $modx = evolutionCMS();
76
-        if(substr($modifiers,0,3)!=='id(') $value = $this->parseDocumentSource($value);
76
+        if (substr($modifiers, 0, 3) !== 'id(') $value = $this->parseDocumentSource($value);
77 77
         $this->srcValue = $value;
78 78
         $modifiers = trim($modifiers);
79
-        $modifiers = ':'.trim($modifiers,':');
80
-        $modifiers = str_replace(array("\r\n","\r"), "\n", $modifiers);
79
+        $modifiers = ':'.trim($modifiers, ':');
80
+        $modifiers = str_replace(array("\r\n", "\r"), "\n", $modifiers);
81 81
         $modifiers = $this->splitEachModifiers($modifiers);
82 82
 
83 83
         $this->placeholders = array();
@@ -85,8 +85,8 @@  discard block
 block discarded – undo
85 85
         $this->placeholders['dummy'] = '';
86 86
         $this->condition = array();
87 87
         $this->vars = array();
88
-        $this->vars['name']    = & $key;
89
-        $value = $this->parsePhx($key,$value,$modifiers);
88
+        $this->vars['name'] = & $key;
89
+        $value = $this->parsePhx($key, $value, $modifiers);
90 90
         $this->vars = array();
91 91
         return $value;
92 92
     }
@@ -96,13 +96,13 @@  discard block
 block discarded – undo
96 96
      * @param string $modifiers
97 97
      * @return bool|string
98 98
      */
99
-    public function _getDelim($mode,$modifiers) {
100
-        $c = substr($modifiers,0,1);
101
-        if(!in_array($c, array('"', "'", '`')) ) return false;
99
+    public function _getDelim($mode, $modifiers){
100
+        $c = substr($modifiers, 0, 1);
101
+        if (!in_array($c, array('"', "'", '`'))) return false;
102 102
 
103
-        $modifiers = substr($modifiers,1);
104
-        $closure = $mode=='(' ? "{$c})" : $c;
105
-        if(strpos($modifiers, $closure)===false) return false;
103
+        $modifiers = substr($modifiers, 1);
104
+        $closure = $mode == '(' ? "{$c})" : $c;
105
+        if (strpos($modifiers, $closure) === false) return false;
106 106
 
107 107
         return  $c;
108 108
     }
@@ -113,101 +113,101 @@  discard block
 block discarded – undo
113 113
      * @param string $modifiers
114 114
      * @return bool|string
115 115
      */
116
-    public function _getOpt($mode,$delim,$modifiers) {
117
-        if($delim) {
118
-            if($mode=='(') return substr($modifiers,1,strpos($modifiers, $delim . ')' )-1);
116
+    public function _getOpt($mode, $delim, $modifiers){
117
+        if ($delim) {
118
+            if ($mode == '(') return substr($modifiers, 1, strpos($modifiers, $delim.')') - 1);
119 119
 
120
-            return substr($modifiers,1,strpos($modifiers,$delim,1)-1);
120
+            return substr($modifiers, 1, strpos($modifiers, $delim, 1) - 1);
121 121
         }
122 122
         else {
123
-            if($mode=='(') return substr($modifiers,0,strpos($modifiers, ')') );
123
+            if ($mode == '(') return substr($modifiers, 0, strpos($modifiers, ')'));
124 124
 
125 125
             $chars = str_split($modifiers);
126
-            $opt='';
127
-            foreach($chars as $c) {
128
-                if($c==':' || $c==')') break;
129
-                $opt .=$c;
126
+            $opt = '';
127
+            foreach ($chars as $c) {
128
+                if ($c == ':' || $c == ')') break;
129
+                $opt .= $c;
130 130
             }
131 131
             return $opt;
132 132
         }
133 133
     }
134
-    public function _getRemainModifiers($mode,$delim,$modifiers) {
135
-        if($delim) {
136
-            if($mode=='(')
137
-                return $this->_fetchContent($modifiers, $delim . ')');
134
+    public function _getRemainModifiers($mode, $delim, $modifiers){
135
+        if ($delim) {
136
+            if ($mode == '(')
137
+                return $this->_fetchContent($modifiers, $delim.')');
138 138
             else {
139 139
                 $modifiers = trim($modifiers);
140
-                $modifiers = substr($modifiers,1);
140
+                $modifiers = substr($modifiers, 1);
141 141
                 return $this->_fetchContent($modifiers, $delim);
142 142
             }
143 143
         }
144 144
         else {
145
-            if($mode=='(') return $this->_fetchContent($modifiers, ')');
145
+            if ($mode == '(') return $this->_fetchContent($modifiers, ')');
146 146
             $chars = str_split($modifiers);
147
-            foreach($chars as $c) {
148
-                if($c==':') return $modifiers;
149
-                else $modifiers = substr($modifiers,1);
147
+            foreach ($chars as $c) {
148
+                if ($c == ':') return $modifiers;
149
+                else $modifiers = substr($modifiers, 1);
150 150
             }
151 151
             return $modifiers;
152 152
         }
153 153
     }
154 154
 
155
-    public function _fetchContent($string,$delim) {
155
+    public function _fetchContent($string, $delim){
156 156
         $len = strlen($delim);
157 157
         $string = $this->parseDocumentSource($string);
158
-        return substr($string,strpos($string, $delim)+$len);
158
+        return substr($string, strpos($string, $delim) + $len);
159 159
     }
160 160
 
161
-    public function splitEachModifiers($modifiers) {
161
+    public function splitEachModifiers($modifiers){
162 162
         $modx = evolutionCMS();
163 163
 
164 164
         $cmd = '';
165 165
         $bt = '';
166 166
         $result = array();
167
-        while($bt!==$modifiers) {
167
+        while ($bt !== $modifiers) {
168 168
             $bt = $modifiers;
169
-            $c = substr($modifiers,0,1);
170
-            $modifiers = substr($modifiers,1);
169
+            $c = substr($modifiers, 0, 1);
170
+            $modifiers = substr($modifiers, 1);
171 171
 
172
-            if($c===':' && preg_match('@^(!?[<>=]{1,2})@', $modifiers, $match)) { // :=, :!=, :<=, :>=, :!<=, :!>=
173
-                $c = substr($modifiers,strlen($match[1]),1);
172
+            if ($c === ':' && preg_match('@^(!?[<>=]{1,2})@', $modifiers, $match)) { // :=, :!=, :<=, :>=, :!<=, :!>=
173
+                $c = substr($modifiers, strlen($match[1]), 1);
174 174
                 $debuginfo = "#i=0 #c=[{$c}] #m=[{$modifiers}]";
175
-                if($c==='(') $modifiers = substr($modifiers,strlen($match[1])+1);
176
-                else         $modifiers = substr($modifiers,strlen($match[1]));
175
+                if ($c === '(') $modifiers = substr($modifiers, strlen($match[1]) + 1);
176
+                else         $modifiers = substr($modifiers, strlen($match[1]));
177 177
 
178
-                $delim     = $this->_getDelim($c,$modifiers);
179
-                $opt       = $this->_getOpt($c,$delim,$modifiers);
180
-                $modifiers = trim($this->_getRemainModifiers($c,$delim,$modifiers));
178
+                $delim     = $this->_getDelim($c, $modifiers);
179
+                $opt       = $this->_getOpt($c, $delim, $modifiers);
180
+                $modifiers = trim($this->_getRemainModifiers($c, $delim, $modifiers));
181 181
 
182
-                $result[]=array('cmd'=>trim($match[1]),'opt'=>$opt,'debuginfo'=>$debuginfo);
182
+                $result[] = array('cmd'=>trim($match[1]), 'opt'=>$opt, 'debuginfo'=>$debuginfo);
183 183
                 $cmd = '';
184 184
             }
185
-            elseif(in_array($c,array('+','-','*','/')) && preg_match('@^[0-9]+@', $modifiers, $match)) { // :+3, :-3, :*3 ...
186
-                $modifiers = substr($modifiers,strlen($match[0]));
187
-                $result[]=array('cmd'=>'math','opt'=>'%s'.$c.$match[0]);
185
+            elseif (in_array($c, array('+', '-', '*', '/')) && preg_match('@^[0-9]+@', $modifiers, $match)) { // :+3, :-3, :*3 ...
186
+                $modifiers = substr($modifiers, strlen($match[0]));
187
+                $result[] = array('cmd'=>'math', 'opt'=>'%s'.$c.$match[0]);
188 188
                 $cmd = '';
189 189
             }
190
-            elseif($c==='(' || $c==='=') {
190
+            elseif ($c === '(' || $c === '=') {
191 191
                 $modifiers = $m1 = trim($modifiers);
192
-                $delim     = $this->_getDelim($c,$modifiers);
193
-                $opt       = $this->_getOpt($c,$delim,$modifiers);
194
-                $modifiers = trim($this->_getRemainModifiers($c,$delim,$modifiers));
192
+                $delim     = $this->_getDelim($c, $modifiers);
193
+                $opt       = $this->_getOpt($c, $delim, $modifiers);
194
+                $modifiers = trim($this->_getRemainModifiers($c, $delim, $modifiers));
195 195
                 $debuginfo = "#i=1 #c=[{$c}] #delim=[{$delim}] #m1=[{$m1}] remainMdf=[{$modifiers}]";
196 196
 
197
-                $result[]=array('cmd'=>trim($cmd),'opt'=>$opt,'debuginfo'=>$debuginfo);
197
+                $result[] = array('cmd'=>trim($cmd), 'opt'=>$opt, 'debuginfo'=>$debuginfo);
198 198
 
199 199
                 $cmd = '';
200 200
             }
201
-            elseif($c==':') {
201
+            elseif ($c == ':') {
202 202
                 $debuginfo = "#i=2 #c=[{$c}] #m=[{$modifiers}]";
203
-                if($cmd!=='') $result[]=array('cmd'=>trim($cmd),'opt'=>'','debuginfo'=>$debuginfo);
203
+                if ($cmd !== '') $result[] = array('cmd'=>trim($cmd), 'opt'=>'', 'debuginfo'=>$debuginfo);
204 204
 
205 205
                 $cmd = '';
206 206
             }
207
-            elseif(trim($modifiers)=='' && trim($cmd)!=='') {
207
+            elseif (trim($modifiers) == '' && trim($cmd) !== '') {
208 208
                 $debuginfo = "#i=3 #c=[{$c}] #m=[{$modifiers}]";
209 209
                 $cmd .= $c;
210
-                $result[]=array('cmd'=>trim($cmd),'opt'=>'','debuginfo'=>$debuginfo);
210
+                $result[] = array('cmd'=>trim($cmd), 'opt'=>'', 'debuginfo'=>$debuginfo);
211 211
 
212 212
                 break;
213 213
             }
@@ -216,65 +216,65 @@  discard block
 block discarded – undo
216 216
             }
217 217
         }
218 218
 
219
-        if(empty($result)) return array();
219
+        if (empty($result)) return array();
220 220
 
221
-        foreach($result as $i=>$a)
221
+        foreach ($result as $i=>$a)
222 222
         {
223 223
             $a['opt'] = $this->parseDocumentSource($a['opt']);
224
-            $result[$i]['opt'] = $modx->mergePlaceholderContent($a['opt'],$this->placeholders);
224
+            $result[$i]['opt'] = $modx->mergePlaceholderContent($a['opt'], $this->placeholders);
225 225
         }
226 226
 
227 227
         return $result;
228 228
     }
229 229
 
230
-    public function parsePhx($key,$value,$modifiers)
230
+    public function parsePhx($key, $value, $modifiers)
231 231
     {
232 232
         $modx = evolutionCMS();
233 233
         $lastKey = '';
234
-        $cacheKey = md5(sprintf('parsePhx#%s#%s#%s',$key,$value,print_r($modifiers,true)));
235
-        if(isset($this->tmpCache[$cacheKey])) return $this->tmpCache[$cacheKey];
236
-        if(empty($modifiers)) return '';
234
+        $cacheKey = md5(sprintf('parsePhx#%s#%s#%s', $key, $value, print_r($modifiers, true)));
235
+        if (isset($this->tmpCache[$cacheKey])) return $this->tmpCache[$cacheKey];
236
+        if (empty($modifiers)) return '';
237 237
 
238
-        foreach($modifiers as $m)
238
+        foreach ($modifiers as $m)
239 239
         {
240 240
             $lastKey = strtolower($m['cmd']);
241 241
         }
242
-        $_ = explode(',',$this->condModifiers);
243
-        if(in_array($lastKey,$_))
242
+        $_ = explode(',', $this->condModifiers);
243
+        if (in_array($lastKey, $_))
244 244
         {
245
-            $modifiers[] = array('cmd'=>'then','opt'=>'1');
246
-            $modifiers[] = array('cmd'=>'else','opt'=>'0');
245
+            $modifiers[] = array('cmd'=>'then', 'opt'=>'1');
246
+            $modifiers[] = array('cmd'=>'else', 'opt'=>'0');
247 247
         }
248 248
 
249
-        foreach($modifiers as $i=>$a)
249
+        foreach ($modifiers as $i=>$a)
250 250
         {
251
-            $value = $this->Filter($key,$value, $a['cmd'], $a['opt']);
251
+            $value = $this->Filter($key, $value, $a['cmd'], $a['opt']);
252 252
         }
253 253
         $this->tmpCache[$cacheKey] = $value;
254 254
         return $value;
255 255
     }
256 256
 
257 257
     // Parser: modifier detection and eXtended processing if needed
258
-    public function Filter($key, $value, $cmd, $opt='')
258
+    public function Filter($key, $value, $cmd, $opt = '')
259 259
     {
260 260
         $modx = evolutionCMS();
261 261
 
262
-        if($key==='documentObject') $value = $modx->documentIdentifier;
262
+        if ($key === 'documentObject') $value = $modx->documentIdentifier;
263 263
         $cmd = $this->parseDocumentSource($cmd);
264
-        if(preg_match('@^[1-9][/0-9]*$@',$cmd))
264
+        if (preg_match('@^[1-9][/0-9]*$@', $cmd))
265 265
         {
266
-            if(strpos($cmd,'/')!==false)
267
-                $cmd = $this->substr($cmd,strrpos($cmd,'/')+1);
266
+            if (strpos($cmd, '/') !== false)
267
+                $cmd = $this->substr($cmd, strrpos($cmd, '/') + 1);
268 268
             $opt = $cmd;
269 269
             $cmd = 'id';
270 270
         }
271 271
 
272
-        if(isset($modx->snippetCache["phx:{$cmd}"]))   $this->elmName = "phx:{$cmd}";
273
-        elseif(isset($modx->chunkCache["phx:{$cmd}"])) $this->elmName = "phx:{$cmd}";
272
+        if (isset($modx->snippetCache["phx:{$cmd}"]))   $this->elmName = "phx:{$cmd}";
273
+        elseif (isset($modx->chunkCache["phx:{$cmd}"])) $this->elmName = "phx:{$cmd}";
274 274
         else                                           $this->elmName = '';
275 275
 
276 276
         $cmd = strtolower($cmd);
277
-        if($this->elmName!=='')
277
+        if ($this->elmName !== '')
278 278
             $value = $this->getValueFromElement($key, $value, $cmd, $opt);
279 279
         else
280 280
             $value = $this->getValueFromPreset($key, $value, $cmd, $opt);
@@ -284,12 +284,12 @@  discard block
 block discarded – undo
284 284
         return $value;
285 285
     }
286 286
 
287
-    public function isEmpty($cmd,$value)
287
+    public function isEmpty($cmd, $value)
288 288
     {
289
-        if($value!=='') return false;
289
+        if ($value !== '') return false;
290 290
 
291
-        $_ = explode(',', $this->condModifiers . ',_default,default,if,input,or,and,show,this,select,switch,then,else,id,ifempty,smart_desc,smart_description,summary');
292
-        if(in_array($cmd,$_)) return false;
291
+        $_ = explode(',', $this->condModifiers.',_default,default,if,input,or,and,show,this,select,switch,then,else,id,ifempty,smart_desc,smart_description,summary');
292
+        if (in_array($cmd, $_)) return false;
293 293
         else                  return true;
294 294
     }
295 295
 
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
     {
298 298
         $modx = evolutionCMS();
299 299
 
300
-        if($this->isEmpty($cmd,$value)) return '';
300
+        if ($this->isEmpty($cmd, $value)) return '';
301 301
 
302 302
         $this->key = $key;
303 303
         $this->value  = $value;
@@ -308,83 +308,83 @@  discard block
 block discarded – undo
308 308
             #####  Conditional Modifiers
309 309
             case 'input':
310 310
             case 'if':
311
-                if(!$opt) return $value;
311
+                if (!$opt) return $value;
312 312
                 return $opt;
313 313
             case '=':
314 314
             case 'eq':
315 315
             case 'is':
316 316
             case 'equals':
317
-                $this->condition[] = (int)($value == $opt); break;
317
+                $this->condition[] = (int) ($value == $opt); break;
318 318
             case 'neq':
319 319
             case 'ne':
320 320
             case 'notequals':
321 321
             case 'isnot':
322 322
             case 'isnt':
323 323
             case 'not':
324
-                $this->condition[] = (int)($value != $opt);break;
324
+                $this->condition[] = (int) ($value != $opt); break;
325 325
             case '%':
326
-                $this->condition[] = (int)($value%$opt==0);break;
326
+                $this->condition[] = (int) ($value % $opt == 0); break;
327 327
             case 'isempty':
328
-                $this->condition[] = (int)(empty($value)); break;
328
+                $this->condition[] = (int) (empty($value)); break;
329 329
             case 'isntempty':
330 330
             case 'isnotempty':
331
-                $this->condition[] = (int)(!empty($value)); break;
331
+                $this->condition[] = (int) (!empty($value)); break;
332 332
             case '>=':
333 333
             case 'gte':
334 334
             case 'eg':
335 335
             case 'isgte':
336
-                $this->condition[] = (int)($value >= $opt);break;
336
+                $this->condition[] = (int) ($value >= $opt); break;
337 337
             case '<=':
338 338
             case 'lte':
339 339
             case 'el':
340 340
             case 'islte':
341
-                $this->condition[] = (int)($value <= $opt);break;
341
+                $this->condition[] = (int) ($value <= $opt); break;
342 342
             case '>':
343 343
             case 'gt':
344 344
             case 'greaterthan':
345 345
             case 'isgreaterthan':
346 346
             case 'isgt':
347
-                $this->condition[] = (int)($value > $opt);break;
347
+                $this->condition[] = (int) ($value > $opt); break;
348 348
             case '<':
349 349
             case 'lt':
350 350
             case 'lowerthan':
351 351
             case 'islowerthan':
352 352
             case 'islt':
353
-                $this->condition[] = (int)($value < $opt);break;
353
+                $this->condition[] = (int) ($value < $opt); break;
354 354
             case 'find':
355
-                $this->condition[] = (int)(strpos($value, $opt)!==false);break;
355
+                $this->condition[] = (int) (strpos($value, $opt) !== false); break;
356 356
             case 'inarray':
357 357
             case 'in_array':
358 358
             case 'in':
359 359
                 $opt = explode(',', $opt);
360
-                $this->condition[] = (int)(in_array($value, $opt)!==false);break;
360
+                $this->condition[] = (int) (in_array($value, $opt) !== false); break;
361 361
             case 'wildcard_match':
362 362
             case 'wcard_match':
363 363
             case 'wildcard':
364 364
             case 'wcard':
365 365
             case 'fnmatch':
366
-                $this->condition[] = (int)(fnmatch($opt, $value)!==false);break;
366
+                $this->condition[] = (int) (fnmatch($opt, $value) !== false); break;
367 367
             case 'is_file':
368 368
             case 'is_dir':
369 369
             case 'file_exists':
370 370
             case 'is_readable':
371 371
             case 'is_writable':
372
-                if(!$opt) $path = $value;
372
+                if (!$opt) $path = $value;
373 373
                 else      $path = $opt;
374
-                if(strpos($path,MODX_MANAGER_PATH)!==false) exit('Can not read core path');
375
-                if(strpos($path,$modx->config['base_path'])===false) $path = ltrim($path,'/');
376
-                $this->condition[] = (int)($cmd($path)!==false);break;
374
+                if (strpos($path, MODX_MANAGER_PATH) !== false) exit('Can not read core path');
375
+                if (strpos($path, $modx->config['base_path']) === false) $path = ltrim($path, '/');
376
+                $this->condition[] = (int) ($cmd($path) !== false); break;
377 377
             case 'is_image':
378
-                if(!$opt) $path = $value;
378
+                if (!$opt) $path = $value;
379 379
                 else      $path = $opt;
380
-                if(!is_file($path)) {$this->condition[]='0';break;}
380
+                if (!is_file($path)) {$this->condition[] = '0'; break; }
381 381
                 $_ = getimagesize($path);
382
-                $this->condition[] = (int)($_[0]);break;
382
+                $this->condition[] = (int) ($_[0]); break;
383 383
             case 'regex':
384 384
             case 'preg':
385 385
             case 'preg_match':
386 386
             case 'isinrole':
387
-            $this->condition[] = (int)(preg_match($opt,$value));break;
387
+            $this->condition[] = (int) (preg_match($opt, $value)); break;
388 388
             case 'ir':
389 389
             case 'memberof':
390 390
             case 'mo':
@@ -392,50 +392,50 @@  discard block
 block discarded – undo
392 392
                 $this->condition[] = $this->includeMdfFile('memberof');
393 393
                 break;
394 394
             case 'or':
395
-                $this->condition[] = '||';break;
395
+                $this->condition[] = '||'; break;
396 396
             case 'and':
397
-                $this->condition[] = '&&';break;
397
+                $this->condition[] = '&&'; break;
398 398
             case 'show':
399 399
             case 'this':
400
-                $conditional = implode(' ',$this->condition);
401
-                $isvalid = (int)(eval("return ({$conditional});"));
400
+                $conditional = implode(' ', $this->condition);
401
+                $isvalid = (int) (eval("return ({$conditional});"));
402 402
                 if ($isvalid) return $this->srcValue;
403 403
                 return NULL;
404 404
             case 'then':
405
-                $conditional = implode(' ',$this->condition);
406
-                $isvalid = (int)eval("return ({$conditional});");
405
+                $conditional = implode(' ', $this->condition);
406
+                $isvalid = (int) eval("return ({$conditional});");
407 407
                 if ($isvalid)  return $opt;
408 408
                 return null;
409 409
             case 'else':
410
-                $conditional = implode(' ',$this->condition);
411
-                $isvalid = (int)eval("return ({$conditional});");
410
+                $conditional = implode(' ', $this->condition);
411
+                $isvalid = (int) eval("return ({$conditional});");
412 412
                 if (!$isvalid) return $opt;
413 413
                 break;
414 414
             case 'select':
415 415
             case 'switch':
416
-                $raw = explode('&',$opt);
416
+                $raw = explode('&', $opt);
417 417
                 $map = array();
418 418
                 $c = count($raw);
419
-                for($m=0; $m<$c; $m++) {
420
-                    $mi = explode('=',$raw[$m],2);
419
+                for ($m = 0; $m < $c; $m++) {
420
+                    $mi = explode('=', $raw[$m], 2);
421 421
                     $map[$mi[0]] = $mi[1];
422 422
                 }
423
-                if(isset($map[$value])) return $map[$value];
423
+                if (isset($map[$value])) return $map[$value];
424 424
                 else                    return '';
425 425
             ##### End of Conditional Modifiers
426 426
 
427 427
             #####  Encode / Decode / Hash / Escape
428 428
             case 'htmlent':
429 429
             case 'htmlentities':
430
-                return htmlentities($value,ENT_QUOTES,$modx->config['modx_charset']);
430
+                return htmlentities($value, ENT_QUOTES, $modx->config['modx_charset']);
431 431
             case 'html_entity_decode':
432 432
             case 'decode_html':
433 433
             case 'html_decode':
434
-                return html_entity_decode($value,ENT_QUOTES,$modx->config['modx_charset']);
434
+                return html_entity_decode($value, ENT_QUOTES, $modx->config['modx_charset']);
435 435
             case 'esc':
436 436
             case 'escape':
437 437
                 $value = preg_replace('/&amp;(#[0-9]+|[a-z]+);/i', '&$1;', htmlspecialchars($value, ENT_QUOTES, $modx->config['modx_charset']));
438
-                return str_replace(array('[', ']', '`'),array('&#91;', '&#93;', '&#96;'),$value);
438
+                return str_replace(array('[', ']', '`'), array('&#91;', '&#93;', '&#96;'), $value);
439 439
             case 'sql_escape':
440 440
             case 'encode_js':
441 441
                 return $modx->db->escape($value);
@@ -445,39 +445,39 @@  discard block
 block discarded – undo
445 445
             case 'html_encode':
446 446
                 return preg_replace('/&amp;(#[0-9]+|[a-z]+);/i', '&$1;', htmlspecialchars($value, ENT_QUOTES, $modx->config['modx_charset']));
447 447
             case 'spam_protect':
448
-                return str_replace(array('@','.'),array('&#64;','&#46;'),$value);
448
+                return str_replace(array('@', '.'), array('&#64;', '&#46;'), $value);
449 449
             case 'strip':
450
-                if($opt==='') $opt = ' ';
450
+                if ($opt === '') $opt = ' ';
451 451
                 return preg_replace('/[\n\r\t\s]+/', $opt, $value);
452 452
             case 'strip_linefeeds':
453
-                return str_replace(array("\n","\r"), '', $value);
453
+                return str_replace(array("\n", "\r"), '', $value);
454 454
             case 'notags':
455 455
             case 'strip_tags':
456 456
             case 'remove_html':
457
-                if($opt!=='')
457
+                if ($opt !== '')
458 458
                 {
459 459
                     $param = array();
460
-                    foreach(explode(',',$opt) as $v)
460
+                    foreach (explode(',', $opt) as $v)
461 461
                     {
462
-                        $v = trim($v,'</> ');
462
+                        $v = trim($v, '</> ');
463 463
                         $param[] = "<{$v}>";
464 464
                     }
465
-                    $params = implode(',',$param);
465
+                    $params = implode(',', $param);
466 466
                 }
467 467
                 else $params = '';
468
-                if(!strpos($params,'<br>')===false) {
469
-                    $value = preg_replace('@(<br[ /]*>)\n@','$1',$value);
470
-                    $value = preg_replace('@<br[ /]*>@',"\n",$value);
468
+                if (!strpos($params, '<br>') === false) {
469
+                    $value = preg_replace('@(<br[ /]*>)\n@', '$1', $value);
470
+                    $value = preg_replace('@<br[ /]*>@', "\n", $value);
471 471
                 }
472
-                return $this->strip_tags($value,$params);
472
+                return $this->strip_tags($value, $params);
473 473
             case 'urlencode':
474 474
             case 'url_encode':
475 475
             case 'encode_url':
476 476
                 return urlencode($value);
477 477
             case 'base64_decode':
478
-                if($opt!=='false') $opt = true;
478
+                if ($opt !== 'false') $opt = true;
479 479
                 else               $opt = false;
480
-                return base64_decode($value,$opt);
480
+                return base64_decode($value, $opt);
481 481
             case 'encode_sha1': $cmd = 'sha1';
482 482
             case 'addslashes':
483 483
             case 'urldecode':
@@ -501,18 +501,18 @@  discard block
 block discarded – undo
501 501
             case 'upper_case':
502 502
                 return $this->strtoupper($value);
503 503
             case 'capitalize':
504
-                $_ = explode(' ',$value);
505
-                foreach($_ as $i=>$v)
504
+                $_ = explode(' ', $value);
505
+                foreach ($_ as $i=>$v)
506 506
                 {
507 507
                     $_[$i] = ucfirst($v);
508 508
                 }
509
-                return implode(' ',$_);
509
+                return implode(' ', $_);
510 510
             case 'zenhan':
511
-                if(empty($opt)) $opt='VKas';
512
-                return mb_convert_kana($value,$opt,$modx->config['modx_charset']);
511
+                if (empty($opt)) $opt = 'VKas';
512
+                return mb_convert_kana($value, $opt, $modx->config['modx_charset']);
513 513
             case 'hanzen':
514
-                if(empty($opt)) $opt='VKAS';
515
-                return mb_convert_kana($value,$opt,$modx->config['modx_charset']);
514
+                if (empty($opt)) $opt = 'VKAS';
515
+                return mb_convert_kana($value, $opt, $modx->config['modx_charset']);
516 516
             case 'str_shuffle':
517 517
             case 'shuffle':
518 518
                 return $this->str_shuffle($value);
@@ -526,7 +526,7 @@  discard block
 block discarded – undo
526 526
                 return $this->strlen($value);
527 527
             case 'count_words':
528 528
                 $value = trim($value);
529
-                return count(preg_split('/\s+/',$value));
529
+                return count(preg_split('/\s+/', $value));
530 530
             case 'str_word_count':
531 531
             case 'word_count':
532 532
             case 'wordcount':
@@ -534,55 +534,55 @@  discard block
 block discarded – undo
534 534
             case 'count_paragraphs':
535 535
                 $value = trim($value);
536 536
                 $value = preg_replace('/\r/', '', $value);
537
-                return count(preg_split('/\n+/',$value));
537
+                return count(preg_split('/\n+/', $value));
538 538
             case 'strpos':
539
-                if($opt!=0&&empty($opt)) return $value;
540
-                return $this->strpos($value,$opt);
539
+                if ($opt != 0 && empty($opt)) return $value;
540
+                return $this->strpos($value, $opt);
541 541
             case 'wordwrap':
542 542
                 // default: 70
543
-                  $wrapat = (int)$opt > 0 ? (int)$opt : 70;
543
+                  $wrapat = (int) $opt > 0 ? (int) $opt : 70;
544 544
                 if (version_compare(PHP_VERSION, '5.3.0') >= 0) return $this->includeMdfFile('wordwrap');
545
-                else return preg_replace("@(\b\w+\b)@e","wordwrap('\\1',\$wrapat,' ',1)",$value);
545
+                else return preg_replace("@(\b\w+\b)@e", "wordwrap('\\1',\$wrapat,' ',1)", $value);
546 546
             case 'wrap_text':
547
-                $width = preg_match('/^[1-9][0-9]*$/',$opt) ? $opt : 70;
548
-                if($modx->config['manager_language']==='japanese-utf8') {
547
+                $width = preg_match('/^[1-9][0-9]*$/', $opt) ? $opt : 70;
548
+                if ($modx->config['manager_language'] === 'japanese-utf8') {
549 549
                     $chunk = array();
550
-                    $bt='';
551
-                    while($bt!=$value) {
550
+                    $bt = '';
551
+                    while ($bt != $value) {
552 552
                         $bt = $value;
553
-                        if($this->strlen($value)<$width) {
553
+                        if ($this->strlen($value) < $width) {
554 554
                             $chunk[] = $value;
555 555
                             break;
556 556
                         }
557
-                        $chunk[] = $this->substr($value,0,$width);
558
-                        $value = $this->substr($value,$width);
557
+                        $chunk[] = $this->substr($value, 0, $width);
558
+                        $value = $this->substr($value, $width);
559 559
                     }
560
-                    return implode("\n",$chunk);
560
+                    return implode("\n", $chunk);
561 561
                 }
562 562
                 else
563
-                    return wordwrap($value,$width,"\n",true);
563
+                    return wordwrap($value, $width, "\n", true);
564 564
             case 'substr':
565
-                if(empty($opt)) break;
566
-                if(strpos($opt,',')!==false) {
567
-                    list($b,$e) = explode(',',$opt,2);
568
-                    return $this->substr($value,$b,(int)$e);
565
+                if (empty($opt)) break;
566
+                if (strpos($opt, ',') !== false) {
567
+                    list($b, $e) = explode(',', $opt, 2);
568
+                    return $this->substr($value, $b, (int) $e);
569 569
                 }
570
-                else return $this->substr($value,$opt);
570
+                else return $this->substr($value, $opt);
571 571
             case 'limit':
572 572
             case 'trim_to': // http://www.movabletype.jp/documentation/appendices/modifiers/trim_to.html
573
-                if(strpos($opt,'+')!==false)
574
-                    list($len,$str) = explode('+',$opt,2);
573
+                if (strpos($opt, '+') !== false)
574
+                    list($len, $str) = explode('+', $opt, 2);
575 575
                 else {
576 576
                     $len = $opt;
577 577
                     $str = '';
578 578
                 }
579
-                if($len==='') $len = 100;
580
-                if(abs($len) > $this->strlen($value)) $str ='';
581
-                if(preg_match('/^[1-9][0-9]*$/',$len)) {
582
-                    return $this->substr($value,0,$len) . $str;
579
+                if ($len === '') $len = 100;
580
+                if (abs($len) > $this->strlen($value)) $str = '';
581
+                if (preg_match('/^[1-9][0-9]*$/', $len)) {
582
+                    return $this->substr($value, 0, $len).$str;
583 583
                 }
584
-                elseif(preg_match('/^\-[1-9][0-9]*$/',$len)) {
585
-                    return $str . $this->substr($value,$len);
584
+                elseif (preg_match('/^\-[1-9][0-9]*$/', $len)) {
585
+                    return $str.$this->substr($value, $len);
586 586
                 }
587 587
                 break;
588 588
             case 'summary':
@@ -591,81 +591,81 @@  discard block
 block discarded – undo
591 591
                 return $this->includeMdfFile('summary');
592 592
             case 'replace':
593 593
             case 'str_replace':
594
-                if(empty($opt) || strpos($opt,',')===false) break;
595
-                if    (substr_count($opt, ',') ==1) $delim = ',';
596
-                elseif(substr_count($opt, '|') ==1) $delim = '|';
597
-                elseif(substr_count($opt, '=>')==1) $delim = '=>';
598
-                elseif(substr_count($opt, '/') ==1) $delim = '/';
594
+                if (empty($opt) || strpos($opt, ',') === false) break;
595
+                if (substr_count($opt, ',') == 1) $delim = ',';
596
+                elseif (substr_count($opt, '|') == 1) $delim = '|';
597
+                elseif (substr_count($opt, '=>') == 1) $delim = '=>';
598
+                elseif (substr_count($opt, '/') == 1) $delim = '/';
599 599
                 else break;
600
-                list($s,$r) = explode($delim,$opt);
601
-                if($value!=='') return str_replace($s,$r,$value);
600
+                list($s, $r) = explode($delim, $opt);
601
+                if ($value !== '') return str_replace($s, $r, $value);
602 602
                 break;
603 603
             case 'replace_to':
604 604
             case 'tpl':
605
-                if($value!=='') return str_replace(array('[+value+]','[+output+]','{value}','%s'),$value,$opt);
605
+                if ($value !== '') return str_replace(array('[+value+]', '[+output+]', '{value}', '%s'), $value, $opt);
606 606
                 break;
607 607
             case 'eachtpl':
608
-                $value = explode('||',$value);
608
+                $value = explode('||', $value);
609 609
                 $_ = array();
610
-                foreach($value as $v) {
611
-                    $_[] = str_replace(array('[+value+]','[+output+]','{value}','%s'),$v,$opt);
610
+                foreach ($value as $v) {
611
+                    $_[] = str_replace(array('[+value+]', '[+output+]', '{value}', '%s'), $v, $opt);
612 612
                 }
613 613
                 return implode("\n", $_);
614 614
             case 'array_pop':
615 615
             case 'array_shift':
616
-                if(strpos($value,'||')!==false) $delim = '||';
616
+                if (strpos($value, '||') !== false) $delim = '||';
617 617
                 else                            $delim = ',';
618
-                return $cmd(explode($delim,$value));
618
+                return $cmd(explode($delim, $value));
619 619
             case 'preg_replace':
620 620
             case 'regex_replace':
621
-                if(empty($opt) || strpos($opt,',')===false) break;
622
-                list($s,$r) = explode(',',$opt,2);
623
-                if($value!=='') return preg_replace($s,$r,$value);
621
+                if (empty($opt) || strpos($opt, ',') === false) break;
622
+                list($s, $r) = explode(',', $opt, 2);
623
+                if ($value !== '') return preg_replace($s, $r, $value);
624 624
                 break;
625 625
             case 'cat':
626 626
             case 'concatenate':
627 627
             case '.':
628
-                if($value!=='') return $value . $opt;
628
+                if ($value !== '') return $value.$opt;
629 629
                 break;
630 630
             case 'sprintf':
631 631
             case 'string_format':
632
-                if($value!=='') return sprintf($opt,$value);
632
+                if ($value !== '') return sprintf($opt, $value);
633 633
                 break;
634 634
             case 'number_format':
635
-                    if($opt=='') $opt = 0;
636
-                    return number_format($value,$opt);
635
+                    if ($opt == '') $opt = 0;
636
+                    return number_format($value, $opt);
637 637
             case 'money_format':
638
-                    setlocale(LC_MONETARY,setlocale(LC_TIME,0));
639
-                    if($value!=='') return money_format($opt,(double)$value);
638
+                    setlocale(LC_MONETARY, setlocale(LC_TIME, 0));
639
+                    if ($value !== '') return money_format($opt, (double) $value);
640 640
                     break;
641 641
             case 'tobool':
642 642
                 return boolval($value);
643 643
             case 'nl2lf':
644
-                if($value!=='') return str_replace(array("\r\n","\n", "\r"), '\n', $value);
644
+                if ($value !== '') return str_replace(array("\r\n", "\n", "\r"), '\n', $value);
645 645
                 break;
646 646
             case 'br2nl':
647 647
                 return preg_replace('@<br[\s/]*>@i', "\n", $value);
648 648
             case 'nl2br':
649 649
                 if (version_compare(PHP_VERSION, '5.3.0', '<'))
650 650
                     return nl2br($value);
651
-                if($opt!=='')
651
+                if ($opt !== '')
652 652
                 {
653 653
                     $opt = trim($opt);
654 654
                     $opt = strtolower($opt);
655
-                    if($opt==='false') $opt = false;
656
-                    elseif($opt==='0') $opt = false;
655
+                    if ($opt === 'false') $opt = false;
656
+                    elseif ($opt === '0') $opt = false;
657 657
                     else               $opt = true;
658 658
                 }
659
-                elseif(isset($modx->config['mce_element_format'])&&$modx->config['mce_element_format']==='html')
659
+                elseif (isset($modx->config['mce_element_format']) && $modx->config['mce_element_format'] === 'html')
660 660
                                        $opt = false;
661 661
                 else                   $opt = true;
662
-                return nl2br($value,$opt);
662
+                return nl2br($value, $opt);
663 663
             case 'ltrim':
664 664
             case 'rtrim':
665 665
             case 'trim': // ref http://mblo.info/modifiers/custom-modifiers/rtrim_opt.html
666
-                if($opt==='')
666
+                if ($opt === '')
667 667
                     return $cmd($value);
668
-                else return $cmd($value,$opt);
668
+                else return $cmd($value, $opt);
669 669
             // These are all straight wrappers for PHP functions
670 670
             case 'ucfirst':
671 671
             case 'lcfirst':
@@ -676,58 +676,58 @@  discard block
 block discarded – undo
676 676
             case 'strftime':
677 677
             case 'date':
678 678
             case 'dateformat':
679
-                if(empty($opt)) $opt = $modx->toDateFormat(null, 'formatOnly');
680
-                if(!preg_match('@^[0-9]+$@',$value)) $value = strtotime($value);
681
-                if(strpos($opt,'%')!==false)
682
-                    return strftime($opt,0+$value);
679
+                if (empty($opt)) $opt = $modx->toDateFormat(null, 'formatOnly');
680
+                if (!preg_match('@^[0-9]+$@', $value)) $value = strtotime($value);
681
+                if (strpos($opt, '%') !== false)
682
+                    return strftime($opt, 0 + $value);
683 683
                 else
684
-                    return date($opt,0+$value);
684
+                    return date($opt, 0 + $value);
685 685
             case 'time':
686
-                if(empty($opt)) $opt = '%H:%M';
687
-                if(!preg_match('@^[0-9]+$@',$value)) $value = strtotime($value);
688
-                return strftime($opt,0+$value);
686
+                if (empty($opt)) $opt = '%H:%M';
687
+                if (!preg_match('@^[0-9]+$@', $value)) $value = strtotime($value);
688
+                return strftime($opt, 0 + $value);
689 689
             case 'strtotime':
690 690
                 return strtotime($value);
691 691
             #####  mathematical function
692 692
             case 'toint':
693
-                return (int)$value;
693
+                return (int) $value;
694 694
             case 'tofloat':
695 695
                 return floatval($value);
696 696
             case 'round':
697
-                if(!$opt) $opt = 0;
698
-                return $cmd($value,$opt);
697
+                if (!$opt) $opt = 0;
698
+                return $cmd($value, $opt);
699 699
             case 'max':
700 700
             case 'min':
701
-                return $cmd(explode(',',$value));
701
+                return $cmd(explode(',', $value));
702 702
             case 'floor':
703 703
             case 'ceil':
704 704
             case 'abs':
705 705
                 return $cmd($value);
706 706
             case 'math':
707 707
             case 'calc':
708
-                $value = (int)$value;
709
-                if(empty($value)) $value = '0';
710
-                $filter = str_replace(array('[+value+]','[+output+]','{value}','%s'),'?',$opt);
711
-                $filter = preg_replace('@([a-zA-Z\n\r\t\s])@','',$filter);
712
-                if(strpos($filter,'?')===false) $filter = "?{$filter}";
713
-                $filter = str_replace('?',$value,$filter);
708
+                $value = (int) $value;
709
+                if (empty($value)) $value = '0';
710
+                $filter = str_replace(array('[+value+]', '[+output+]', '{value}', '%s'), '?', $opt);
711
+                $filter = preg_replace('@([a-zA-Z\n\r\t\s])@', '', $filter);
712
+                if (strpos($filter, '?') === false) $filter = "?{$filter}";
713
+                $filter = str_replace('?', $value, $filter);
714 714
                 return eval("return {$filter};");
715 715
             case 'count':
716
-                if($value=='') return 0;
717
-                $value = explode(',',$value);
716
+                if ($value == '') return 0;
717
+                $value = explode(',', $value);
718 718
                 return count($value);
719 719
             case 'sort':
720 720
             case 'rsort':
721
-                if(strpos($value,"\n")!==false) $delim="\n";
721
+                if (strpos($value, "\n") !== false) $delim = "\n";
722 722
                 else $delim = ',';
723
-                $swap = explode($delim,$value);
724
-                if(!$opt) $opt = SORT_REGULAR;
723
+                $swap = explode($delim, $value);
724
+                if (!$opt) $opt = SORT_REGULAR;
725 725
                 else      $opt = constant($opt);
726
-                $cmd($swap,$opt);
727
-                return implode($delim,$swap);
726
+                $cmd($swap, $opt);
727
+                return implode($delim, $swap);
728 728
             #####  Resource fields
729 729
             case 'id':
730
-                if($opt) return $this->getDocumentObject($opt,$key);
730
+                if ($opt) return $this->getDocumentObject($opt, $key);
731 731
                 break;
732 732
             case 'type':
733 733
             case 'contenttype':
@@ -764,36 +764,36 @@  discard block
 block discarded – undo
764 764
             case 'privatemgr':
765 765
             case 'content_dispo':
766 766
             case 'hidemenu':
767
-                if($cmd==='contenttype') $cmd = 'contentType';
768
-                return $this->getDocumentObject($value,$cmd);
767
+                if ($cmd === 'contenttype') $cmd = 'contentType';
768
+                return $this->getDocumentObject($value, $cmd);
769 769
             case 'title':
770
-                $pagetitle = $this->getDocumentObject($value,'pagetitle');
771
-                $longtitle = $this->getDocumentObject($value,'longtitle');
770
+                $pagetitle = $this->getDocumentObject($value, 'pagetitle');
771
+                $longtitle = $this->getDocumentObject($value, 'longtitle');
772 772
                 return $longtitle ? $longtitle : $pagetitle;
773 773
             case 'shorttitle':
774
-                $pagetitle = $this->getDocumentObject($value,'pagetitle');
775
-                $menutitle = $this->getDocumentObject($value,'menutitle');
774
+                $pagetitle = $this->getDocumentObject($value, 'pagetitle');
775
+                $menutitle = $this->getDocumentObject($value, 'menutitle');
776 776
                 return $menutitle ? $menutitle : $pagetitle;
777 777
             case 'templatename':
778
-                $rs = $modx->db->select('templatename','[+prefix+]site_templates',"id='{$value}'");
778
+                $rs = $modx->db->select('templatename', '[+prefix+]site_templates', "id='{$value}'");
779 779
                 $templateName = $modx->db->getValue($rs);
780 780
                 return !$templateName ? '(blank)' : $templateName;
781 781
             case 'getfield':
782
-                if(!$opt) $opt = 'content';
783
-                return $modx->getField($opt,$value);
782
+                if (!$opt) $opt = 'content';
783
+                return $modx->getField($opt, $value);
784 784
             case 'children':
785 785
             case 'childids':
786
-                if($value=='') $value = 0; // 値がない場合はルートと見なす
786
+                if ($value == '') $value = 0; // 値がない場合はルートと見なす
787 787
                 $published = 1;
788
-                if($opt=='') $opt = 'page';
789
-                $_ = explode(',',$opt);
788
+                if ($opt == '') $opt = 'page';
789
+                $_ = explode(',', $opt);
790 790
                 $where = array();
791
-                foreach($_ as $opt) {
792
-                    switch(trim($opt)) {
791
+                foreach ($_ as $opt) {
792
+                    switch (trim($opt)) {
793 793
                         case 'page'; case '!folder'; case '!isfolder': $where[] = 'sc.isfolder=0'; break;
794 794
                         case 'folder'; case 'isfolder':                $where[] = 'sc.isfolder=1'; break;
795
-                        case  'menu';  case  'show_menu':              $where[] = 'sc.hidemenu=0'; break;
796
-                        case '!menu';  case '!show_menu':              $where[] = 'sc.hidemenu=1'; break;
795
+                        case  'menu'; case  'show_menu':              $where[] = 'sc.hidemenu=0'; break;
796
+                        case '!menu'; case '!show_menu':              $where[] = 'sc.hidemenu=1'; break;
797 797
                         case  'published':                             $published = 1; break;
798 798
                         case '!published':                             $published = 0; break;
799 799
                     }
@@ -801,69 +801,69 @@  discard block
 block discarded – undo
801 801
                 $where = implode(' AND ', $where);
802 802
                 $children = $modx->getDocumentChildren($value, $published, '0', 'id', $where);
803 803
                 $result = array();
804
-                foreach((array)$children as $child){
804
+                foreach ((array) $children as $child) {
805 805
                     $result[] = $child['id'];
806 806
                 }
807 807
                 return implode(',', $result);
808 808
             case 'fullurl':
809
-                if(!is_numeric($value)) return $value;
809
+                if (!is_numeric($value)) return $value;
810 810
                 return $modx->makeUrl($value);
811 811
             case 'makeurl':
812
-                if(!is_numeric($value)) return $value;
813
-                if(!$opt) $opt = 'full';
814
-                return $modx->makeUrl($value,'','',$opt);
812
+                if (!is_numeric($value)) return $value;
813
+                if (!$opt) $opt = 'full';
814
+                return $modx->makeUrl($value, '', '', $opt);
815 815
 
816 816
             #####  File system
817 817
             case 'getimageinfo':
818 818
             case 'imageinfo':
819
-                if(!is_file($value)) return '';
819
+                if (!is_file($value)) return '';
820 820
                 $_ = getimagesize($value);
821
-                if(!$_[0]) return '';
821
+                if (!$_[0]) return '';
822 822
                 $info['width']  = $_[0];
823 823
                 $info['height'] = $_[1];
824
-                if    ($_[0] > $_[1]) $info['aspect'] = 'landscape';
825
-                elseif($_[0] < $_[1]) $info['aspect'] = 'portrait';
824
+                if ($_[0] > $_[1]) $info['aspect'] = 'landscape';
825
+                elseif ($_[0] < $_[1]) $info['aspect'] = 'portrait';
826 826
                 else                  $info['aspect'] = 'square';
827
-                switch($_[2]) {
827
+                switch ($_[2]) {
828 828
                     case IMAGETYPE_GIF  : $info['type'] = 'gif'; break;
829 829
                     case IMAGETYPE_JPEG : $info['type'] = 'jpg'; break;
830 830
                     case IMAGETYPE_PNG  : $info['type'] = 'png'; break;
831 831
                     default             : $info['type'] = 'unknown';
832 832
                 }
833 833
                 $info['attrib'] = $_[3];
834
-                switch($opt) {
834
+                switch ($opt) {
835 835
                     case 'width' : return $info['width'];
836 836
                     case 'height': return $info['height'];
837 837
                     case 'aspect': return $info['aspect'];
838 838
                     case 'type'  : return $info['type'];
839 839
                     case 'attrib': return $info['attrib'];
840
-                    default      : return print_r($info,true);
840
+                    default      : return print_r($info, true);
841 841
                 }
842 842
 
843 843
             case 'file_get_contents':
844 844
             case 'readfile':
845
-                if(!is_file($value)) return $value;
845
+                if (!is_file($value)) return $value;
846 846
                 $value = realpath($value);
847
-                if(strpos($value,MODX_MANAGER_PATH)!==false) exit('Can not read core file');
848
-                $ext = strtolower(substr($value,-4));
849
-                if($ext==='.php') exit('Can not read php file');
850
-                if($ext==='.cgi') exit('Can not read cgi file');
847
+                if (strpos($value, MODX_MANAGER_PATH) !== false) exit('Can not read core file');
848
+                $ext = strtolower(substr($value, -4));
849
+                if ($ext === '.php') exit('Can not read php file');
850
+                if ($ext === '.cgi') exit('Can not read cgi file');
851 851
                 return file_get_contents($value);
852 852
             case 'filesize':
853
-                if($value == '') return '';
853
+                if ($value == '') return '';
854 854
                 $filename = $value;
855 855
 
856 856
                 $site_url = $modx->config['site_url'];
857
-                if(strpos($filename,$site_url) === 0)
858
-                    $filename = substr($filename,0,strlen($site_url));
859
-                $filename = trim($filename,'/');
857
+                if (strpos($filename, $site_url) === 0)
858
+                    $filename = substr($filename, 0, strlen($site_url));
859
+                $filename = trim($filename, '/');
860 860
 
861
-                $opt = trim($opt,'/');
862
-                if($opt!=='') $opt .= '/';
861
+                $opt = trim($opt, '/');
862
+                if ($opt !== '') $opt .= '/';
863 863
 
864 864
                 $filename = MODX_BASE_PATH.$opt.$filename;
865 865
 
866
-                if(is_file($filename)){
866
+                if (is_file($filename)) {
867 867
                     clearstatcache();
868 868
                     $size = filesize($filename);
869 869
                     return $size;
@@ -896,10 +896,10 @@  discard block
 block discarded – undo
896 896
                 $this->opt = $cmd;
897 897
                 return $this->includeMdfFile('moduser');
898 898
             case 'userinfo':
899
-                if(empty($opt)) $this->opt = 'username';
899
+                if (empty($opt)) $this->opt = 'username';
900 900
                 return $this->includeMdfFile('moduser');
901 901
             case 'webuserinfo':
902
-                if(empty($opt)) $this->opt = 'username';
902
+                if (empty($opt)) $this->opt = 'username';
903 903
                 $this->value = -$value;
904 904
                 return $this->includeMdfFile('moduser');
905 905
             #####  Special functions
@@ -910,27 +910,27 @@  discard block
 block discarded – undo
910 910
             case 'ifnotempty':
911 911
                 if (!empty($value)) return $opt; break;
912 912
             case 'datagrid':
913
-                include_once(MODX_CORE_PATH . 'controls/datagrid.class.php');
913
+                include_once(MODX_CORE_PATH.'controls/datagrid.class.php');
914 914
                 $grd = new DataGrid(null, trim($value));
915 915
                 $grd->itemStyle = '';
916 916
                 $grd->altItemStyle = '';
917
-                $pos = strpos($value,"\n");
918
-                if($pos) $_ = substr($value,0,$pos);
917
+                $pos = strpos($value, "\n");
918
+                if ($pos) $_ = substr($value, 0, $pos);
919 919
                 else $_ = $pos;
920
-                $grd->cdelim = strpos($_,"\t")!==false ? 'tab' : ',';
920
+                $grd->cdelim = strpos($_, "\t") !== false ? 'tab' : ',';
921 921
                 return $grd->render();
922 922
             case 'rotate':
923 923
             case 'evenodd':
924
-                if(strpos($opt,',')===false) $opt = 'odd,even';
924
+                if (strpos($opt, ',') === false) $opt = 'odd,even';
925 925
                 $_ = explode(',', $opt);
926 926
                 $c = count($_);
927 927
                 $i = $value + $c;
928 928
                 $i = $i % $c;
929 929
                 return $_[$i];
930 930
             case 'takeval':
931
-                $arr = explode(",",$opt);
931
+                $arr = explode(",", $opt);
932 932
                 $idx = $value;
933
-                if(!is_numeric($idx)) return $value;
933
+                if (!is_numeric($idx)) return $value;
934 934
                 return $arr[$idx];
935 935
             case 'getimage':
936 936
                 return $this->includeMdfFile('getimage');
@@ -938,17 +938,17 @@  discard block
 block discarded – undo
938 938
                     return $modx->nicesize($value);
939 939
             case 'googlemap':
940 940
             case 'googlemaps':
941
-                if(empty($opt)) $opt = 'border:none;width:500px;height:350px;';
941
+                if (empty($opt)) $opt = 'border:none;width:500px;height:350px;';
942 942
                 $tpl = '<iframe style="[+style+]" src="https://maps.google.co.jp/maps?ll=[+value+]&output=embed&z=15"></iframe>';
943 943
                 $ph['style'] = $opt;
944 944
                 $ph['value'] = $value;
945
-                return $modx->parseText($tpl,$ph);
945
+                return $modx->parseText($tpl, $ph);
946 946
             case 'youtube':
947 947
             case 'youtube16x9':
948
-                if(empty($opt)) $opt = 560;
949
-                $h = round($opt*0.5625);
948
+                if (empty($opt)) $opt = 560;
949
+                $h = round($opt * 0.5625);
950 950
                 $tpl = '<iframe width="%s" height="%s" src="https://www.youtube.com/embed/%s" frameborder="0" allowfullscreen></iframe>';
951
-                return sprintf($tpl,$opt,$h,$value);
951
+                return sprintf($tpl, $opt, $h, $value);
952 952
             //case 'youtube4x3':%s*0.75+25
953 953
             case 'setvar':
954 954
                 $modx->placeholders[$opt] = $value;
@@ -978,7 +978,7 @@  discard block
 block discarded – undo
978 978
         return $value;
979 979
     }
980 980
 
981
-    public function includeMdfFile($cmd) {
981
+    public function includeMdfFile($cmd){
982 982
         $modx = evolutionCMS();
983 983
         $key = $this->key;
984 984
         $value  = $this->value;
@@ -989,54 +989,54 @@  discard block
 block discarded – undo
989 989
     public function getValueFromElement($key, $value, $cmd, $opt)
990 990
     {
991 991
         $modx = evolutionCMS();
992
-        if( isset($modx->snippetCache[$this->elmName]) )
992
+        if (isset($modx->snippetCache[$this->elmName]))
993 993
         {
994 994
             $php = $modx->snippetCache[$this->elmName];
995 995
         }
996 996
         else
997 997
         {
998 998
             $esc_elmName = $modx->db->escape($this->elmName);
999
-            $result = $modx->db->select('snippet','[+prefix+]site_snippets',"name='{$esc_elmName}'");
999
+            $result = $modx->db->select('snippet', '[+prefix+]site_snippets', "name='{$esc_elmName}'");
1000 1000
             $total = $modx->db->getRecordCount($result);
1001
-            if($total == 1)
1001
+            if ($total == 1)
1002 1002
             {
1003 1003
                 $row = $modx->db->getRow($result);
1004 1004
                 $php = $row['snippet'];
1005 1005
             }
1006
-            elseif($total == 0)
1006
+            elseif ($total == 0)
1007 1007
             {
1008 1008
                 $assets_path = MODX_BASE_PATH.'assets/';
1009
-                if(is_file($assets_path."modifiers/mdf_{$cmd}.inc.php"))
1009
+                if (is_file($assets_path."modifiers/mdf_{$cmd}.inc.php"))
1010 1010
                     $modifiers_path = $assets_path."modifiers/mdf_{$cmd}.inc.php";
1011
-                elseif(is_file($assets_path."plugins/phx/modifiers/{$cmd}.phx.php"))
1011
+                elseif (is_file($assets_path."plugins/phx/modifiers/{$cmd}.phx.php"))
1012 1012
                     $modifiers_path = $assets_path."plugins/phx/modifiers/{$cmd}.phx.php";
1013
-                elseif(is_file(MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php"))
1013
+                elseif (is_file(MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php"))
1014 1014
                     $modifiers_path = MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php";
1015 1015
                 else $modifiers_path = false;
1016 1016
 
1017
-                if($modifiers_path !== false) {
1017
+                if ($modifiers_path !== false) {
1018 1018
                     $php = @file_get_contents($modifiers_path);
1019 1019
                     $php = trim($php);
1020
-                    if(substr($php,0,5)==='<?php') $php = substr($php,6);
1021
-                    if(substr($php,0,2)==='<?')    $php = substr($php,3);
1022
-                    if(substr($php,-2)==='?>')     $php = substr($php,0,-2);
1023
-                    if($this->elmName!=='')
1020
+                    if (substr($php, 0, 5) === '<?php') $php = substr($php, 6);
1021
+                    if (substr($php, 0, 2) === '<?')    $php = substr($php, 3);
1022
+                    if (substr($php, -2) === '?>')     $php = substr($php, 0, -2);
1023
+                    if ($this->elmName !== '')
1024 1024
                         $modx->snippetCache[$this->elmName.'Props'] = '';
1025 1025
                 }
1026 1026
                 else
1027 1027
                     $php = false;
1028 1028
             }
1029 1029
             else $php = false;
1030
-            if($this->elmName!=='') $modx->snippetCache[$this->elmName]= $php;
1030
+            if ($this->elmName !== '') $modx->snippetCache[$this->elmName] = $php;
1031 1031
         }
1032
-        if($php==='') $php=false;
1032
+        if ($php === '') $php = false;
1033 1033
 
1034
-        if($php===false) $html = $modx->getChunk($this->elmName);
1034
+        if ($php === false) $html = $modx->getChunk($this->elmName);
1035 1035
         else             $html = false;
1036 1036
 
1037 1037
         $self = '[+output+]';
1038 1038
 
1039
-        if($php !== false)
1039
+        if ($php !== false)
1040 1040
         {
1041 1041
             ob_start();
1042 1042
             $options = $opt;
@@ -1049,71 +1049,71 @@  discard block
 block discarded – undo
1049 1049
             $this->vars['options'] = & $opt;
1050 1050
             $custom = eval($php);
1051 1051
             $msg = ob_get_contents();
1052
-            if($value===$this->bt) $value = $msg . $custom;
1052
+            if ($value === $this->bt) $value = $msg.$custom;
1053 1053
             ob_end_clean();
1054 1054
         }
1055
-        elseif($html!==false && isset($value) && $value!=='')
1055
+        elseif ($html !== false && isset($value) && $value !== '')
1056 1056
         {
1057
-            $html = str_replace(array($self,'[+value+]'), $value, $html);
1058
-            $value = str_replace(array('[+options+]','[+param+]'), $opt, $html);
1057
+            $html = str_replace(array($self, '[+value+]'), $value, $html);
1058
+            $value = str_replace(array('[+options+]', '[+param+]'), $opt, $html);
1059 1059
         }
1060 1060
         else return false;
1061 1061
 
1062
-        if($php===false && $html===false && $value!==''
1063
-           && (strpos($cmd,'[+value+]')!==false || strpos($cmd,$self)!==false))
1062
+        if ($php === false && $html === false && $value !== ''
1063
+           && (strpos($cmd, '[+value+]') !== false || strpos($cmd, $self) !== false))
1064 1064
         {
1065
-            $value = str_replace(array('[+value+]',$self),$value,$cmd);
1065
+            $value = str_replace(array('[+value+]', $self), $value, $cmd);
1066 1066
         }
1067 1067
         return $value;
1068 1068
     }
1069 1069
 
1070
-    public function parseDocumentSource($content='')
1070
+    public function parseDocumentSource($content = '')
1071 1071
     {
1072 1072
         $modx = evolutionCMS();
1073 1073
 
1074
-        if(strpos($content,'[')===false && strpos($content,'{')===false) return $content;
1074
+        if (strpos($content, '[') === false && strpos($content, '{') === false) return $content;
1075 1075
 
1076
-        if(!$modx->maxParserPasses) $modx->maxParserPasses = 10;
1077
-        $bt='';
1078
-        $i=0;
1079
-        while($bt!==$content)
1076
+        if (!$modx->maxParserPasses) $modx->maxParserPasses = 10;
1077
+        $bt = '';
1078
+        $i = 0;
1079
+        while ($bt !== $content)
1080 1080
         {
1081 1081
             $bt = $content;
1082
-            if(strpos($content,'[*')!==false && $modx->documentIdentifier)
1082
+            if (strpos($content, '[*') !== false && $modx->documentIdentifier)
1083 1083
                                               $content = $modx->mergeDocumentContent($content);
1084
-            if(strpos($content,'[(')!==false) $content = $modx->mergeSettingsContent($content);
1085
-            if(strpos($content,'{{')!==false) $content = $modx->mergeChunkContent($content);
1086
-            if(strpos($content,'[!')!==false) $content = str_replace(array('[!','!]'),array('[[',']]'),$content);
1087
-            if(strpos($content,'[[')!==false) $content = $modx->evalSnippets($content);
1084
+            if (strpos($content, '[(') !== false) $content = $modx->mergeSettingsContent($content);
1085
+            if (strpos($content, '{{') !== false) $content = $modx->mergeChunkContent($content);
1086
+            if (strpos($content, '[!') !== false) $content = str_replace(array('[!', '!]'), array('[[', ']]'), $content);
1087
+            if (strpos($content, '[[') !== false) $content = $modx->evalSnippets($content);
1088 1088
 
1089
-            if($content===$bt)              break;
1090
-            if($modx->maxParserPasses < $i) break;
1089
+            if ($content === $bt)              break;
1090
+            if ($modx->maxParserPasses < $i) break;
1091 1091
             $i++;
1092 1092
         }
1093 1093
         return $content;
1094 1094
     }
1095 1095
 
1096
-    public function getDocumentObject($target='',$field='pagetitle')
1096
+    public function getDocumentObject($target = '', $field = 'pagetitle')
1097 1097
     {
1098 1098
         $modx = evolutionCMS();
1099 1099
 
1100 1100
         $target = trim($target);
1101
-        if(empty($target)) $target = $modx->config['site_start'];
1102
-        if(preg_match('@^[1-9][0-9]*$@',$target)) $method='id';
1101
+        if (empty($target)) $target = $modx->config['site_start'];
1102
+        if (preg_match('@^[1-9][0-9]*$@', $target)) $method = 'id';
1103 1103
         else $method = 'alias';
1104 1104
 
1105
-        if(!isset($this->documentObject[$target]))
1105
+        if (!isset($this->documentObject[$target]))
1106 1106
         {
1107
-            $this->documentObject[$target] = $modx->getDocumentObject($method,$target,'direct');
1107
+            $this->documentObject[$target] = $modx->getDocumentObject($method, $target, 'direct');
1108 1108
         }
1109 1109
 
1110
-        if($this->documentObject[$target]['publishedon']==='0')
1110
+        if ($this->documentObject[$target]['publishedon'] === '0')
1111 1111
             return '';
1112
-        elseif(isset($this->documentObject[$target][$field]))
1112
+        elseif (isset($this->documentObject[$target][$field]))
1113 1113
         {
1114
-            if(is_array($this->documentObject[$target][$field]))
1114
+            if (is_array($this->documentObject[$target][$field]))
1115 1115
             {
1116
-                $a = $modx->getTemplateVarOutput($field,$target);
1116
+                $a = $modx->getTemplateVarOutput($field, $target);
1117 1117
                 $this->documentObject[$target][$field] = $a[$field];
1118 1118
             }
1119 1119
         }
@@ -1122,8 +1122,8 @@  discard block
 block discarded – undo
1122 1122
         return $this->documentObject[$target][$field];
1123 1123
     }
1124 1124
 
1125
-    public function setPlaceholders($value = '', $key = '', $path = '') {
1126
-        if($path!=='') $key = "{$path}.{$key}";
1125
+    public function setPlaceholders($value = '', $key = '', $path = ''){
1126
+        if ($path !== '') $key = "{$path}.{$key}";
1127 1127
         if (is_array($value)) {
1128 1128
             foreach ($value as $subkey => $subval) {
1129 1129
                 $this->setPlaceholders($subval, $subkey, $key);
@@ -1133,77 +1133,77 @@  discard block
 block discarded – undo
1133 1133
     }
1134 1134
 
1135 1135
     // Sets a placeholder variable which can only be access by Modifiers
1136
-    public function setModifiersVariable($key, $value) {
1136
+    public function setModifiersVariable($key, $value){
1137 1137
         if ($key != 'phx' && $key != 'dummy') $this->placeholders[$key] = $value;
1138 1138
     }
1139 1139
 
1140 1140
     //mbstring
1141
-    public function substr($str, $s, $l = null) {
1141
+    public function substr($str, $s, $l = null){
1142 1142
         $modx = evolutionCMS();
1143
-        if(is_null($l)) $l = $this->strlen($str);
1143
+        if (is_null($l)) $l = $this->strlen($str);
1144 1144
         if (function_exists('mb_substr'))
1145 1145
         {
1146
-            if(strpos($str,"\r")!==false)
1147
-                $str = str_replace(array("\r\n","\r"), "\n", $str);
1146
+            if (strpos($str, "\r") !== false)
1147
+                $str = str_replace(array("\r\n", "\r"), "\n", $str);
1148 1148
             return mb_substr($str, $s, $l, $modx->config['modx_charset']);
1149 1149
         }
1150 1150
         return substr($str, $s, $l);
1151 1151
     }
1152
-    public function strpos($haystack,$needle,$offset=0) {
1152
+    public function strpos($haystack, $needle, $offset = 0){
1153 1153
         $modx = evolutionCMS();
1154
-        if (function_exists('mb_strpos')) return mb_strpos($haystack,$needle,$offset,$modx->config['modx_charset']);
1155
-        return strpos($haystack,$needle,$offset);
1154
+        if (function_exists('mb_strpos')) return mb_strpos($haystack, $needle, $offset, $modx->config['modx_charset']);
1155
+        return strpos($haystack, $needle, $offset);
1156 1156
     }
1157
-    public function strlen($str) {
1157
+    public function strlen($str){
1158 1158
         $modx = evolutionCMS();
1159
-        if (function_exists('mb_strlen')) return mb_strlen(str_replace("\r\n", "\n", $str),$modx->config['modx_charset']);
1159
+        if (function_exists('mb_strlen')) return mb_strlen(str_replace("\r\n", "\n", $str), $modx->config['modx_charset']);
1160 1160
         return strlen($str);
1161 1161
     }
1162
-    public function strtolower($str) {
1162
+    public function strtolower($str){
1163 1163
         if (function_exists('mb_strtolower')) return mb_strtolower($str);
1164 1164
         return strtolower($str);
1165 1165
     }
1166
-    public function strtoupper($str) {
1166
+    public function strtoupper($str){
1167 1167
         if (function_exists('mb_strtoupper')) return mb_strtoupper($str);
1168 1168
         return strtoupper($str);
1169 1169
     }
1170
-    public function ucfirst($str) {
1170
+    public function ucfirst($str){
1171 1171
         if (function_exists('mb_strtoupper'))
1172 1172
             return mb_strtoupper($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str));
1173 1173
         return ucfirst($str);
1174 1174
     }
1175
-    public function lcfirst($str) {
1175
+    public function lcfirst($str){
1176 1176
         if (function_exists('mb_strtolower'))
1177 1177
             return mb_strtolower($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str));
1178 1178
         return lcfirst($str);
1179 1179
     }
1180
-    public function ucwords($str) {
1180
+    public function ucwords($str){
1181 1181
         if (function_exists('mb_convert_case'))
1182 1182
             return mb_convert_case($str, MB_CASE_TITLE);
1183 1183
         return ucwords($str);
1184 1184
     }
1185
-    public function strrev($str) {
1185
+    public function strrev($str){
1186 1186
         preg_match_all('/./us', $str, $ar);
1187 1187
         return implode(array_reverse($ar[0]));
1188 1188
     }
1189
-    public function str_shuffle($str) {
1189
+    public function str_shuffle($str){
1190 1190
         preg_match_all('/./us', $str, $ar);
1191 1191
         shuffle($ar[0]);
1192 1192
         return implode($ar[0]);
1193 1193
     }
1194
-    public function str_word_count($str) {
1195
-        return count(preg_split('~[^\p{L}\p{N}\']+~u',$str));
1194
+    public function str_word_count($str){
1195
+        return count(preg_split('~[^\p{L}\p{N}\']+~u', $str));
1196 1196
     }
1197
-    public function strip_tags($value,$params='') {
1197
+    public function strip_tags($value, $params = ''){
1198 1198
         $modx = evolutionCMS();
1199 1199
 
1200
-        if(stripos($params,'style')===false && stripos($value,'</style>')!==false) {
1200
+        if (stripos($params, 'style') === false && stripos($value, '</style>') !== false) {
1201 1201
             $value = preg_replace('@<style.*?>.*?</style>@is', '', $value);
1202 1202
         }
1203
-        if(stripos($params,'script')===false && stripos($value,'</script>')!==false) {
1203
+        if (stripos($params, 'script') === false && stripos($value, '</script>') !== false) {
1204 1204
             $value = preg_replace('@<script.*?>.*?</script>@is', '', $value);
1205 1205
         }
1206 1206
 
1207
-        return trim(strip_tags($value,$params));
1207
+        return trim(strip_tags($value, $params));
1208 1208
     }
1209 1209
 }
Please login to merge, or discard this patch.
Braces   +544 added lines, -282 removed lines patch added patch discarded remove patch
@@ -1,8 +1,11 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if(!defined('MODX_CORE_PATH')) define('MODX_CORE_PATH', MODX_MANAGER_PATH.'includes/');
3
+if(!defined('MODX_CORE_PATH')) {
4
+    define('MODX_CORE_PATH', MODX_MANAGER_PATH.'includes/');
5
+}
4 6
 
5
-class MODIFIERS {
7
+class MODIFIERS
8
+{
6 9
     /**
7 10
      * @var array
8 11
      */
@@ -60,7 +63,9 @@  discard block
 block discarded – undo
60 63
     public function __construct()
61 64
     {
62 65
         $modx = evolutionCMS();
63
-        if (function_exists('mb_internal_encoding')) mb_internal_encoding($modx->config['modx_charset']);
66
+        if (function_exists('mb_internal_encoding')) {
67
+            mb_internal_encoding($modx->config['modx_charset']);
68
+        }
64 69
         $this->condModifiers = '=,is,eq,equals,ne,neq,notequals,isnot,isnt,not,%,isempty,isnotempty,isntempty,>=,gte,eg,gte,greaterthan,>,gt,isgreaterthan,isgt,lowerthan,<,lt,<=,lte,islte,islowerthan,islt,el,find,in,inarray,in_array,fnmatch,wcard,wcard_match,wildcard,wildcard_match,is_file,is_dir,file_exists,is_readable,is_writable,is_image,regex,preg,preg_match,memberof,mo,isinrole,ir';
65 70
     }
66 71
 
@@ -73,7 +78,9 @@  discard block
 block discarded – undo
73 78
     public function phxFilter($key,$value,$modifiers)
74 79
     {
75 80
         $modx = evolutionCMS();
76
-        if(substr($modifiers,0,3)!=='id(') $value = $this->parseDocumentSource($value);
81
+        if(substr($modifiers,0,3)!=='id(') {
82
+            $value = $this->parseDocumentSource($value);
83
+        }
77 84
         $this->srcValue = $value;
78 85
         $modifiers = trim($modifiers);
79 86
         $modifiers = ':'.trim($modifiers,':');
@@ -96,13 +103,18 @@  discard block
 block discarded – undo
96 103
      * @param string $modifiers
97 104
      * @return bool|string
98 105
      */
99
-    public function _getDelim($mode,$modifiers) {
106
+    public function _getDelim($mode,$modifiers)
107
+    {
100 108
         $c = substr($modifiers,0,1);
101
-        if(!in_array($c, array('"', "'", '`')) ) return false;
109
+        if(!in_array($c, array('"', "'", '`')) ) {
110
+            return false;
111
+        }
102 112
 
103 113
         $modifiers = substr($modifiers,1);
104 114
         $closure = $mode=='(' ? "{$c})" : $c;
105
-        if(strpos($modifiers, $closure)===false) return false;
115
+        if(strpos($modifiers, $closure)===false) {
116
+            return false;
117
+        }
106 118
 
107 119
         return  $c;
108 120
     }
@@ -113,52 +125,65 @@  discard block
 block discarded – undo
113 125
      * @param string $modifiers
114 126
      * @return bool|string
115 127
      */
116
-    public function _getOpt($mode,$delim,$modifiers) {
128
+    public function _getOpt($mode,$delim,$modifiers)
129
+    {
117 130
         if($delim) {
118
-            if($mode=='(') return substr($modifiers,1,strpos($modifiers, $delim . ')' )-1);
131
+            if($mode=='(') {
132
+                return substr($modifiers,1,strpos($modifiers, $delim . ')' )-1);
133
+            }
119 134
 
120 135
             return substr($modifiers,1,strpos($modifiers,$delim,1)-1);
121
-        }
122
-        else {
123
-            if($mode=='(') return substr($modifiers,0,strpos($modifiers, ')') );
136
+        } else {
137
+            if($mode=='(') {
138
+                return substr($modifiers,0,strpos($modifiers, ')') );
139
+            }
124 140
 
125 141
             $chars = str_split($modifiers);
126 142
             $opt='';
127 143
             foreach($chars as $c) {
128
-                if($c==':' || $c==')') break;
144
+                if($c==':' || $c==')') {
145
+                    break;
146
+                }
129 147
                 $opt .=$c;
130 148
             }
131 149
             return $opt;
132 150
         }
133 151
     }
134
-    public function _getRemainModifiers($mode,$delim,$modifiers) {
152
+    public function _getRemainModifiers($mode,$delim,$modifiers)
153
+    {
135 154
         if($delim) {
136
-            if($mode=='(')
137
-                return $this->_fetchContent($modifiers, $delim . ')');
138
-            else {
155
+            if($mode=='(') {
156
+                            return $this->_fetchContent($modifiers, $delim . ')');
157
+            } else {
139 158
                 $modifiers = trim($modifiers);
140 159
                 $modifiers = substr($modifiers,1);
141 160
                 return $this->_fetchContent($modifiers, $delim);
142 161
             }
143
-        }
144
-        else {
145
-            if($mode=='(') return $this->_fetchContent($modifiers, ')');
162
+        } else {
163
+            if($mode=='(') {
164
+                return $this->_fetchContent($modifiers, ')');
165
+            }
146 166
             $chars = str_split($modifiers);
147 167
             foreach($chars as $c) {
148
-                if($c==':') return $modifiers;
149
-                else $modifiers = substr($modifiers,1);
168
+                if($c==':') {
169
+                    return $modifiers;
170
+                } else {
171
+                    $modifiers = substr($modifiers,1);
172
+                }
150 173
             }
151 174
             return $modifiers;
152 175
         }
153 176
     }
154 177
 
155
-    public function _fetchContent($string,$delim) {
178
+    public function _fetchContent($string,$delim)
179
+    {
156 180
         $len = strlen($delim);
157 181
         $string = $this->parseDocumentSource($string);
158 182
         return substr($string,strpos($string, $delim)+$len);
159 183
     }
160 184
 
161
-    public function splitEachModifiers($modifiers) {
185
+    public function splitEachModifiers($modifiers)
186
+    {
162 187
         $modx = evolutionCMS();
163 188
 
164 189
         $cmd = '';
@@ -169,11 +194,15 @@  discard block
 block discarded – undo
169 194
             $c = substr($modifiers,0,1);
170 195
             $modifiers = substr($modifiers,1);
171 196
 
172
-            if($c===':' && preg_match('@^(!?[<>=]{1,2})@', $modifiers, $match)) { // :=, :!=, :<=, :>=, :!<=, :!>=
197
+            if($c===':' && preg_match('@^(!?[<>=]{1,2})@', $modifiers, $match)) {
198
+// :=, :!=, :<=, :>=, :!<=, :!>=
173 199
                 $c = substr($modifiers,strlen($match[1]),1);
174 200
                 $debuginfo = "#i=0 #c=[{$c}] #m=[{$modifiers}]";
175
-                if($c==='(') $modifiers = substr($modifiers,strlen($match[1])+1);
176
-                else         $modifiers = substr($modifiers,strlen($match[1]));
201
+                if($c==='(') {
202
+                    $modifiers = substr($modifiers,strlen($match[1])+1);
203
+                } else {
204
+                    $modifiers = substr($modifiers,strlen($match[1]));
205
+                }
177 206
 
178 207
                 $delim     = $this->_getDelim($c,$modifiers);
179 208
                 $opt       = $this->_getOpt($c,$delim,$modifiers);
@@ -181,13 +210,12 @@  discard block
 block discarded – undo
181 210
 
182 211
                 $result[]=array('cmd'=>trim($match[1]),'opt'=>$opt,'debuginfo'=>$debuginfo);
183 212
                 $cmd = '';
184
-            }
185
-            elseif(in_array($c,array('+','-','*','/')) && preg_match('@^[0-9]+@', $modifiers, $match)) { // :+3, :-3, :*3 ...
213
+            } elseif(in_array($c,array('+','-','*','/')) && preg_match('@^[0-9]+@', $modifiers, $match)) {
214
+// :+3, :-3, :*3 ...
186 215
                 $modifiers = substr($modifiers,strlen($match[0]));
187 216
                 $result[]=array('cmd'=>'math','opt'=>'%s'.$c.$match[0]);
188 217
                 $cmd = '';
189
-            }
190
-            elseif($c==='(' || $c==='=') {
218
+            } elseif($c==='(' || $c==='=') {
191 219
                 $modifiers = $m1 = trim($modifiers);
192 220
                 $delim     = $this->_getDelim($c,$modifiers);
193 221
                 $opt       = $this->_getOpt($c,$delim,$modifiers);
@@ -197,29 +225,29 @@  discard block
 block discarded – undo
197 225
                 $result[]=array('cmd'=>trim($cmd),'opt'=>$opt,'debuginfo'=>$debuginfo);
198 226
 
199 227
                 $cmd = '';
200
-            }
201
-            elseif($c==':') {
228
+            } elseif($c==':') {
202 229
                 $debuginfo = "#i=2 #c=[{$c}] #m=[{$modifiers}]";
203
-                if($cmd!=='') $result[]=array('cmd'=>trim($cmd),'opt'=>'','debuginfo'=>$debuginfo);
230
+                if($cmd!=='') {
231
+                    $result[]=array('cmd'=>trim($cmd),'opt'=>'','debuginfo'=>$debuginfo);
232
+                }
204 233
 
205 234
                 $cmd = '';
206
-            }
207
-            elseif(trim($modifiers)=='' && trim($cmd)!=='') {
235
+            } elseif(trim($modifiers)=='' && trim($cmd)!=='') {
208 236
                 $debuginfo = "#i=3 #c=[{$c}] #m=[{$modifiers}]";
209 237
                 $cmd .= $c;
210 238
                 $result[]=array('cmd'=>trim($cmd),'opt'=>'','debuginfo'=>$debuginfo);
211 239
 
212 240
                 break;
213
-            }
214
-            else {
241
+            } else {
215 242
                 $cmd .= $c;
216 243
             }
217 244
         }
218 245
 
219
-        if(empty($result)) return array();
246
+        if(empty($result)) {
247
+            return array();
248
+        }
220 249
 
221
-        foreach($result as $i=>$a)
222
-        {
250
+        foreach($result as $i=>$a) {
223 251
             $a['opt'] = $this->parseDocumentSource($a['opt']);
224 252
             $result[$i]['opt'] = $modx->mergePlaceholderContent($a['opt'],$this->placeholders);
225 253
         }
@@ -232,22 +260,23 @@  discard block
 block discarded – undo
232 260
         $modx = evolutionCMS();
233 261
         $lastKey = '';
234 262
         $cacheKey = md5(sprintf('parsePhx#%s#%s#%s',$key,$value,print_r($modifiers,true)));
235
-        if(isset($this->tmpCache[$cacheKey])) return $this->tmpCache[$cacheKey];
236
-        if(empty($modifiers)) return '';
263
+        if(isset($this->tmpCache[$cacheKey])) {
264
+            return $this->tmpCache[$cacheKey];
265
+        }
266
+        if(empty($modifiers)) {
267
+            return '';
268
+        }
237 269
 
238
-        foreach($modifiers as $m)
239
-        {
270
+        foreach($modifiers as $m) {
240 271
             $lastKey = strtolower($m['cmd']);
241 272
         }
242 273
         $_ = explode(',',$this->condModifiers);
243
-        if(in_array($lastKey,$_))
244
-        {
274
+        if(in_array($lastKey,$_)) {
245 275
             $modifiers[] = array('cmd'=>'then','opt'=>'1');
246 276
             $modifiers[] = array('cmd'=>'else','opt'=>'0');
247 277
         }
248 278
 
249
-        foreach($modifiers as $i=>$a)
250
-        {
279
+        foreach($modifiers as $i=>$a) {
251 280
             $value = $this->Filter($key,$value, $a['cmd'], $a['opt']);
252 281
         }
253 282
         $this->tmpCache[$cacheKey] = $value;
@@ -259,25 +288,32 @@  discard block
 block discarded – undo
259 288
     {
260 289
         $modx = evolutionCMS();
261 290
 
262
-        if($key==='documentObject') $value = $modx->documentIdentifier;
291
+        if($key==='documentObject') {
292
+            $value = $modx->documentIdentifier;
293
+        }
263 294
         $cmd = $this->parseDocumentSource($cmd);
264
-        if(preg_match('@^[1-9][/0-9]*$@',$cmd))
265
-        {
266
-            if(strpos($cmd,'/')!==false)
267
-                $cmd = $this->substr($cmd,strrpos($cmd,'/')+1);
295
+        if(preg_match('@^[1-9][/0-9]*$@',$cmd)) {
296
+            if(strpos($cmd,'/')!==false) {
297
+                            $cmd = $this->substr($cmd,strrpos($cmd,'/')+1);
298
+            }
268 299
             $opt = $cmd;
269 300
             $cmd = 'id';
270 301
         }
271 302
 
272
-        if(isset($modx->snippetCache["phx:{$cmd}"]))   $this->elmName = "phx:{$cmd}";
273
-        elseif(isset($modx->chunkCache["phx:{$cmd}"])) $this->elmName = "phx:{$cmd}";
274
-        else                                           $this->elmName = '';
303
+        if(isset($modx->snippetCache["phx:{$cmd}"])) {
304
+            $this->elmName = "phx:{$cmd}";
305
+        } elseif(isset($modx->chunkCache["phx:{$cmd}"])) {
306
+            $this->elmName = "phx:{$cmd}";
307
+        } else {
308
+            $this->elmName = '';
309
+        }
275 310
 
276 311
         $cmd = strtolower($cmd);
277
-        if($this->elmName!=='')
278
-            $value = $this->getValueFromElement($key, $value, $cmd, $opt);
279
-        else
280
-            $value = $this->getValueFromPreset($key, $value, $cmd, $opt);
312
+        if($this->elmName!=='') {
313
+                    $value = $this->getValueFromElement($key, $value, $cmd, $opt);
314
+        } else {
315
+                    $value = $this->getValueFromPreset($key, $value, $cmd, $opt);
316
+        }
281 317
 
282 318
         $value = str_replace('[+key+]', $key, $value);
283 319
 
@@ -286,29 +322,37 @@  discard block
 block discarded – undo
286 322
 
287 323
     public function isEmpty($cmd,$value)
288 324
     {
289
-        if($value!=='') return false;
325
+        if($value!=='') {
326
+            return false;
327
+        }
290 328
 
291 329
         $_ = explode(',', $this->condModifiers . ',_default,default,if,input,or,and,show,this,select,switch,then,else,id,ifempty,smart_desc,smart_description,summary');
292
-        if(in_array($cmd,$_)) return false;
293
-        else                  return true;
330
+        if(in_array($cmd,$_)) {
331
+            return false;
332
+        } else {
333
+            return true;
334
+        }
294 335
     }
295 336
 
296 337
     public function getValueFromPreset($key, $value, $cmd, $opt)
297 338
     {
298 339
         $modx = evolutionCMS();
299 340
 
300
-        if($this->isEmpty($cmd,$value)) return '';
341
+        if($this->isEmpty($cmd,$value)) {
342
+            return '';
343
+        }
301 344
 
302 345
         $this->key = $key;
303 346
         $this->value  = $value;
304 347
         $this->opt    = $opt;
305 348
 
306
-        switch ($cmd)
307
-        {
349
+        switch ($cmd) {
308 350
             #####  Conditional Modifiers
309 351
             case 'input':
310 352
             case 'if':
311
-                if(!$opt) return $value;
353
+                if(!$opt) {
354
+                    return $value;
355
+                }
312 356
                 return $opt;
313 357
             case '=':
314 358
             case 'eq':
@@ -369,14 +413,24 @@  discard block
 block discarded – undo
369 413
             case 'file_exists':
370 414
             case 'is_readable':
371 415
             case 'is_writable':
372
-                if(!$opt) $path = $value;
373
-                else      $path = $opt;
374
-                if(strpos($path,MODX_MANAGER_PATH)!==false) exit('Can not read core path');
375
-                if(strpos($path,$modx->config['base_path'])===false) $path = ltrim($path,'/');
416
+                if(!$opt) {
417
+                    $path = $value;
418
+                } else {
419
+                    $path = $opt;
420
+                }
421
+                if(strpos($path,MODX_MANAGER_PATH)!==false) {
422
+                    exit('Can not read core path');
423
+                }
424
+                if(strpos($path,$modx->config['base_path'])===false) {
425
+                    $path = ltrim($path,'/');
426
+                }
376 427
                 $this->condition[] = (int)($cmd($path)!==false);break;
377 428
             case 'is_image':
378
-                if(!$opt) $path = $value;
379
-                else      $path = $opt;
429
+                if(!$opt) {
430
+                    $path = $value;
431
+                } else {
432
+                    $path = $opt;
433
+                }
380 434
                 if(!is_file($path)) {$this->condition[]='0';break;}
381 435
                 $_ = getimagesize($path);
382 436
                 $this->condition[] = (int)($_[0]);break;
@@ -399,17 +453,23 @@  discard block
 block discarded – undo
399 453
             case 'this':
400 454
                 $conditional = implode(' ',$this->condition);
401 455
                 $isvalid = (int)(eval("return ({$conditional});"));
402
-                if ($isvalid) return $this->srcValue;
456
+                if ($isvalid) {
457
+                    return $this->srcValue;
458
+                }
403 459
                 return NULL;
404 460
             case 'then':
405 461
                 $conditional = implode(' ',$this->condition);
406 462
                 $isvalid = (int)eval("return ({$conditional});");
407
-                if ($isvalid)  return $opt;
463
+                if ($isvalid) {
464
+                    return $opt;
465
+                }
408 466
                 return null;
409 467
             case 'else':
410 468
                 $conditional = implode(' ',$this->condition);
411 469
                 $isvalid = (int)eval("return ({$conditional});");
412
-                if (!$isvalid) return $opt;
470
+                if (!$isvalid) {
471
+                    return $opt;
472
+                }
413 473
                 break;
414 474
             case 'select':
415 475
             case 'switch':
@@ -420,8 +480,11 @@  discard block
 block discarded – undo
420 480
                     $mi = explode('=',$raw[$m],2);
421 481
                     $map[$mi[0]] = $mi[1];
422 482
                 }
423
-                if(isset($map[$value])) return $map[$value];
424
-                else                    return '';
483
+                if(isset($map[$value])) {
484
+                    return $map[$value];
485
+                } else {
486
+                    return '';
487
+                }
425 488
             ##### End of Conditional Modifiers
426 489
 
427 490
             #####  Encode / Decode / Hash / Escape
@@ -447,24 +510,25 @@  discard block
 block discarded – undo
447 510
             case 'spam_protect':
448 511
                 return str_replace(array('@','.'),array('&#64;','&#46;'),$value);
449 512
             case 'strip':
450
-                if($opt==='') $opt = ' ';
513
+                if($opt==='') {
514
+                    $opt = ' ';
515
+                }
451 516
                 return preg_replace('/[\n\r\t\s]+/', $opt, $value);
452 517
             case 'strip_linefeeds':
453 518
                 return str_replace(array("\n","\r"), '', $value);
454 519
             case 'notags':
455 520
             case 'strip_tags':
456 521
             case 'remove_html':
457
-                if($opt!=='')
458
-                {
522
+                if($opt!=='') {
459 523
                     $param = array();
460
-                    foreach(explode(',',$opt) as $v)
461
-                    {
524
+                    foreach(explode(',',$opt) as $v) {
462 525
                         $v = trim($v,'</> ');
463 526
                         $param[] = "<{$v}>";
464 527
                     }
465 528
                     $params = implode(',',$param);
529
+                } else {
530
+                    $params = '';
466 531
                 }
467
-                else $params = '';
468 532
                 if(!strpos($params,'<br>')===false) {
469 533
                     $value = preg_replace('@(<br[ /]*>)\n@','$1',$value);
470 534
                     $value = preg_replace('@<br[ /]*>@',"\n",$value);
@@ -475,8 +539,11 @@  discard block
 block discarded – undo
475 539
             case 'encode_url':
476 540
                 return urlencode($value);
477 541
             case 'base64_decode':
478
-                if($opt!=='false') $opt = true;
479
-                else               $opt = false;
542
+                if($opt!=='false') {
543
+                    $opt = true;
544
+                } else {
545
+                    $opt = false;
546
+                }
480 547
                 return base64_decode($value,$opt);
481 548
             case 'encode_sha1': $cmd = 'sha1';
482 549
             case 'addslashes':
@@ -502,16 +569,19 @@  discard block
 block discarded – undo
502 569
                 return $this->strtoupper($value);
503 570
             case 'capitalize':
504 571
                 $_ = explode(' ',$value);
505
-                foreach($_ as $i=>$v)
506
-                {
572
+                foreach($_ as $i=>$v) {
507 573
                     $_[$i] = ucfirst($v);
508 574
                 }
509 575
                 return implode(' ',$_);
510 576
             case 'zenhan':
511
-                if(empty($opt)) $opt='VKas';
577
+                if(empty($opt)) {
578
+                    $opt='VKas';
579
+                }
512 580
                 return mb_convert_kana($value,$opt,$modx->config['modx_charset']);
513 581
             case 'hanzen':
514
-                if(empty($opt)) $opt='VKAS';
582
+                if(empty($opt)) {
583
+                    $opt='VKAS';
584
+                }
515 585
                 return mb_convert_kana($value,$opt,$modx->config['modx_charset']);
516 586
             case 'str_shuffle':
517 587
             case 'shuffle':
@@ -536,13 +606,18 @@  discard block
 block discarded – undo
536 606
                 $value = preg_replace('/\r/', '', $value);
537 607
                 return count(preg_split('/\n+/',$value));
538 608
             case 'strpos':
539
-                if($opt!=0&&empty($opt)) return $value;
609
+                if($opt!=0&&empty($opt)) {
610
+                    return $value;
611
+                }
540 612
                 return $this->strpos($value,$opt);
541 613
             case 'wordwrap':
542 614
                 // default: 70
543 615
                   $wrapat = (int)$opt > 0 ? (int)$opt : 70;
544
-                if (version_compare(PHP_VERSION, '5.3.0') >= 0) return $this->includeMdfFile('wordwrap');
545
-                else return preg_replace("@(\b\w+\b)@e","wordwrap('\\1',\$wrapat,' ',1)",$value);
616
+                if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
617
+                    return $this->includeMdfFile('wordwrap');
618
+                } else {
619
+                    return preg_replace("@(\b\w+\b)@e","wordwrap('\\1',\$wrapat,' ',1)",$value);
620
+                }
546 621
             case 'wrap_text':
547 622
                 $width = preg_match('/^[1-9][0-9]*$/',$opt) ? $opt : 70;
548 623
                 if($modx->config['manager_language']==='japanese-utf8') {
@@ -558,30 +633,36 @@  discard block
 block discarded – undo
558 633
                         $value = $this->substr($value,$width);
559 634
                     }
560 635
                     return implode("\n",$chunk);
636
+                } else {
637
+                                    return wordwrap($value,$width,"\n",true);
561 638
                 }
562
-                else
563
-                    return wordwrap($value,$width,"\n",true);
564 639
             case 'substr':
565
-                if(empty($opt)) break;
640
+                if(empty($opt)) {
641
+                    break;
642
+                }
566 643
                 if(strpos($opt,',')!==false) {
567 644
                     list($b,$e) = explode(',',$opt,2);
568 645
                     return $this->substr($value,$b,(int)$e);
646
+                } else {
647
+                    return $this->substr($value,$opt);
569 648
                 }
570
-                else return $this->substr($value,$opt);
571 649
             case 'limit':
572 650
             case 'trim_to': // http://www.movabletype.jp/documentation/appendices/modifiers/trim_to.html
573
-                if(strpos($opt,'+')!==false)
574
-                    list($len,$str) = explode('+',$opt,2);
575
-                else {
651
+                if(strpos($opt,'+')!==false) {
652
+                                    list($len,$str) = explode('+',$opt,2);
653
+                } else {
576 654
                     $len = $opt;
577 655
                     $str = '';
578 656
                 }
579
-                if($len==='') $len = 100;
580
-                if(abs($len) > $this->strlen($value)) $str ='';
657
+                if($len==='') {
658
+                    $len = 100;
659
+                }
660
+                if(abs($len) > $this->strlen($value)) {
661
+                    $str ='';
662
+                }
581 663
                 if(preg_match('/^[1-9][0-9]*$/',$len)) {
582 664
                     return $this->substr($value,0,$len) . $str;
583
-                }
584
-                elseif(preg_match('/^\-[1-9][0-9]*$/',$len)) {
665
+                } elseif(preg_match('/^\-[1-9][0-9]*$/',$len)) {
585 666
                     return $str . $this->substr($value,$len);
586 667
                 }
587 668
                 break;
@@ -591,18 +672,30 @@  discard block
 block discarded – undo
591 672
                 return $this->includeMdfFile('summary');
592 673
             case 'replace':
593 674
             case 'str_replace':
594
-                if(empty($opt) || strpos($opt,',')===false) break;
595
-                if    (substr_count($opt, ',') ==1) $delim = ',';
596
-                elseif(substr_count($opt, '|') ==1) $delim = '|';
597
-                elseif(substr_count($opt, '=>')==1) $delim = '=>';
598
-                elseif(substr_count($opt, '/') ==1) $delim = '/';
599
-                else break;
675
+                if(empty($opt) || strpos($opt,',')===false) {
676
+                    break;
677
+                }
678
+                if    (substr_count($opt, ',') ==1) {
679
+                    $delim = ',';
680
+                } elseif(substr_count($opt, '|') ==1) {
681
+                    $delim = '|';
682
+                } elseif(substr_count($opt, '=>')==1) {
683
+                    $delim = '=>';
684
+                } elseif(substr_count($opt, '/') ==1) {
685
+                    $delim = '/';
686
+                } else {
687
+                    break;
688
+                }
600 689
                 list($s,$r) = explode($delim,$opt);
601
-                if($value!=='') return str_replace($s,$r,$value);
690
+                if($value!=='') {
691
+                    return str_replace($s,$r,$value);
692
+                }
602 693
                 break;
603 694
             case 'replace_to':
604 695
             case 'tpl':
605
-                if($value!=='') return str_replace(array('[+value+]','[+output+]','{value}','%s'),$value,$opt);
696
+                if($value!=='') {
697
+                    return str_replace(array('[+value+]','[+output+]','{value}','%s'),$value,$opt);
698
+                }
606 699
                 break;
607 700
             case 'eachtpl':
608 701
                 $value = explode('||',$value);
@@ -613,59 +706,83 @@  discard block
 block discarded – undo
613 706
                 return implode("\n", $_);
614 707
             case 'array_pop':
615 708
             case 'array_shift':
616
-                if(strpos($value,'||')!==false) $delim = '||';
617
-                else                            $delim = ',';
709
+                if(strpos($value,'||')!==false) {
710
+                    $delim = '||';
711
+                } else {
712
+                    $delim = ',';
713
+                }
618 714
                 return $cmd(explode($delim,$value));
619 715
             case 'preg_replace':
620 716
             case 'regex_replace':
621
-                if(empty($opt) || strpos($opt,',')===false) break;
717
+                if(empty($opt) || strpos($opt,',')===false) {
718
+                    break;
719
+                }
622 720
                 list($s,$r) = explode(',',$opt,2);
623
-                if($value!=='') return preg_replace($s,$r,$value);
721
+                if($value!=='') {
722
+                    return preg_replace($s,$r,$value);
723
+                }
624 724
                 break;
625 725
             case 'cat':
626 726
             case 'concatenate':
627 727
             case '.':
628
-                if($value!=='') return $value . $opt;
728
+                if($value!=='') {
729
+                    return $value . $opt;
730
+                }
629 731
                 break;
630 732
             case 'sprintf':
631 733
             case 'string_format':
632
-                if($value!=='') return sprintf($opt,$value);
734
+                if($value!=='') {
735
+                    return sprintf($opt,$value);
736
+                }
633 737
                 break;
634 738
             case 'number_format':
635
-                    if($opt=='') $opt = 0;
739
+                    if($opt=='') {
740
+                        $opt = 0;
741
+                    }
636 742
                     return number_format($value,$opt);
637 743
             case 'money_format':
638 744
                     setlocale(LC_MONETARY,setlocale(LC_TIME,0));
639
-                    if($value!=='') return money_format($opt,(double)$value);
745
+                    if($value!=='') {
746
+                        return money_format($opt,(double)$value);
747
+                    }
640 748
                     break;
641 749
             case 'tobool':
642 750
                 return boolval($value);
643 751
             case 'nl2lf':
644
-                if($value!=='') return str_replace(array("\r\n","\n", "\r"), '\n', $value);
752
+                if($value!=='') {
753
+                    return str_replace(array("\r\n","\n", "\r"), '\n', $value);
754
+                }
645 755
                 break;
646 756
             case 'br2nl':
647 757
                 return preg_replace('@<br[\s/]*>@i', "\n", $value);
648 758
             case 'nl2br':
649
-                if (version_compare(PHP_VERSION, '5.3.0', '<'))
650
-                    return nl2br($value);
651
-                if($opt!=='')
652
-                {
759
+                if (version_compare(PHP_VERSION, '5.3.0', '<')) {
760
+                                    return nl2br($value);
761
+                }
762
+                if($opt!=='') {
653 763
                     $opt = trim($opt);
654 764
                     $opt = strtolower($opt);
655
-                    if($opt==='false') $opt = false;
656
-                    elseif($opt==='0') $opt = false;
657
-                    else               $opt = true;
765
+                    if($opt==='false') {
766
+                        $opt = false;
767
+                    } elseif($opt==='0') {
768
+                        $opt = false;
769
+                    } else {
770
+                        $opt = true;
771
+                    }
772
+                } elseif(isset($modx->config['mce_element_format'])&&$modx->config['mce_element_format']==='html') {
773
+                                                       $opt = false;
774
+                } else {
775
+                    $opt = true;
658 776
                 }
659
-                elseif(isset($modx->config['mce_element_format'])&&$modx->config['mce_element_format']==='html')
660
-                                       $opt = false;
661
-                else                   $opt = true;
662 777
                 return nl2br($value,$opt);
663 778
             case 'ltrim':
664 779
             case 'rtrim':
665 780
             case 'trim': // ref http://mblo.info/modifiers/custom-modifiers/rtrim_opt.html
666
-                if($opt==='')
667
-                    return $cmd($value);
668
-                else return $cmd($value,$opt);
781
+                if($opt==='') {
782
+                                    return $cmd($value);
783
+                } else {
784
+                    return $cmd($value,$opt);
785
+                }
669 786
             // These are all straight wrappers for PHP functions
670 787
             case 'ucfirst':
671 788
             case 'lcfirst':
@@ -676,15 +793,24 @@  discard block
 block discarded – undo
676 793
             case 'strftime':
677 794
             case 'date':
678 795
             case 'dateformat':
679
-                if(empty($opt)) $opt = $modx->toDateFormat(null, 'formatOnly');
680
-                if(!preg_match('@^[0-9]+$@',$value)) $value = strtotime($value);
681
-                if(strpos($opt,'%')!==false)
682
-                    return strftime($opt,0+$value);
683
-                else
684
-                    return date($opt,0+$value);
796
+                if(empty($opt)) {
797
+                    $opt = $modx->toDateFormat(null, 'formatOnly');
798
+                }
799
+                if(!preg_match('@^[0-9]+$@',$value)) {
800
+                    $value = strtotime($value);
801
+                }
802
+                if(strpos($opt,'%')!==false) {
803
+                                    return strftime($opt,0+$value);
804
+                } else {
805
+                                    return date($opt,0+$value);
806
+                }
685 807
             case 'time':
686
-                if(empty($opt)) $opt = '%H:%M';
687
-                if(!preg_match('@^[0-9]+$@',$value)) $value = strtotime($value);
808
+                if(empty($opt)) {
809
+                    $opt = '%H:%M';
810
+                }
811
+                if(!preg_match('@^[0-9]+$@',$value)) {
812
+                    $value = strtotime($value);
813
+                }
688 814
                 return strftime($opt,0+$value);
689 815
             case 'strtotime':
690 816
                 return strtotime($value);
@@ -694,7 +820,9 @@  discard block
 block discarded – undo
694 820
             case 'tofloat':
695 821
                 return floatval($value);
696 822
             case 'round':
697
-                if(!$opt) $opt = 0;
823
+                if(!$opt) {
824
+                    $opt = 0;
825
+                }
698 826
                 return $cmd($value,$opt);
699 827
             case 'max':
700 828
             case 'min':
@@ -706,28 +834,42 @@  discard block
 block discarded – undo
706 834
             case 'math':
707 835
             case 'calc':
708 836
                 $value = (int)$value;
709
-                if(empty($value)) $value = '0';
837
+                if(empty($value)) {
838
+                    $value = '0';
839
+                }
710 840
                 $filter = str_replace(array('[+value+]','[+output+]','{value}','%s'),'?',$opt);
711 841
                 $filter = preg_replace('@([a-zA-Z\n\r\t\s])@','',$filter);
712
-                if(strpos($filter,'?')===false) $filter = "?{$filter}";
842
+                if(strpos($filter,'?')===false) {
843
+                    $filter = "?{$filter}";
844
+                }
713 845
                 $filter = str_replace('?',$value,$filter);
714 846
                 return eval("return {$filter};");
715 847
             case 'count':
716
-                if($value=='') return 0;
848
+                if($value=='') {
849
+                    return 0;
850
+                }
717 851
                 $value = explode(',',$value);
718 852
                 return count($value);
719 853
             case 'sort':
720 854
             case 'rsort':
721
-                if(strpos($value,"\n")!==false) $delim="\n";
722
-                else $delim = ',';
855
+                if(strpos($value,"\n")!==false) {
856
+                    $delim="\n";
857
+                } else {
858
+                    $delim = ',';
859
+                }
723 860
                 $swap = explode($delim,$value);
724
-                if(!$opt) $opt = SORT_REGULAR;
725
-                else      $opt = constant($opt);
861
+                if(!$opt) {
862
+                    $opt = SORT_REGULAR;
863
+                } else {
864
+                    $opt = constant($opt);
865
+                }
726 866
                 $cmd($swap,$opt);
727 867
                 return implode($delim,$swap);
728 868
             #####  Resource fields
729 869
             case 'id':
730
-                if($opt) return $this->getDocumentObject($opt,$key);
870
+                if($opt) {
871
+                    return $this->getDocumentObject($opt,$key);
872
+                }
731 873
                 break;
732 874
             case 'type':
733 875
             case 'contenttype':
@@ -764,7 +906,9 @@  discard block
 block discarded – undo
764 906
             case 'privatemgr':
765 907
             case 'content_dispo':
766 908
             case 'hidemenu':
767
-                if($cmd==='contenttype') $cmd = 'contentType';
909
+                if($cmd==='contenttype') {
910
+                    $cmd = 'contentType';
911
+                }
768 912
                 return $this->getDocumentObject($value,$cmd);
769 913
             case 'title':
770 914
                 $pagetitle = $this->getDocumentObject($value,'pagetitle');
@@ -779,13 +923,20 @@  discard block
 block discarded – undo
779 923
                 $templateName = $modx->db->getValue($rs);
780 924
                 return !$templateName ? '(blank)' : $templateName;
781 925
             case 'getfield':
782
-                if(!$opt) $opt = 'content';
926
+                if(!$opt) {
927
+                    $opt = 'content';
928
+                }
783 929
                 return $modx->getField($opt,$value);
784 930
             case 'children':
785 931
             case 'childids':
786
-                if($value=='') $value = 0; // 値がない場合はルートと見なす
932
+                if($value=='') {
933
+                    $value = 0;
934
+                }
935
+                // 値がない場合はルートと見なす
787 936
                 $published = 1;
788
-                if($opt=='') $opt = 'page';
937
+                if($opt=='') {
938
+                    $opt = 'page';
939
+                }
789 940
                 $_ = explode(',',$opt);
790 941
                 $where = array();
791 942
                 foreach($_ as $opt) {
@@ -801,29 +952,43 @@  discard block
 block discarded – undo
801 952
                 $where = implode(' AND ', $where);
802 953
                 $children = $modx->getDocumentChildren($value, $published, '0', 'id', $where);
803 954
                 $result = array();
804
-                foreach((array)$children as $child){
955
+                foreach((array)$children as $child) {
805 956
                     $result[] = $child['id'];
806 957
                 }
807 958
                 return implode(',', $result);
808 959
             case 'fullurl':
809
-                if(!is_numeric($value)) return $value;
960
+                if(!is_numeric($value)) {
961
+                    return $value;
962
+                }
810 963
                 return $modx->makeUrl($value);
811 964
             case 'makeurl':
812
-                if(!is_numeric($value)) return $value;
813
-                if(!$opt) $opt = 'full';
965
+                if(!is_numeric($value)) {
966
+                    return $value;
967
+                }
968
+                if(!$opt) {
969
+                    $opt = 'full';
970
+                }
814 971
                 return $modx->makeUrl($value,'','',$opt);
815 972
 
816 973
             #####  File system
817 974
             case 'getimageinfo':
818 975
             case 'imageinfo':
819
-                if(!is_file($value)) return '';
976
+                if(!is_file($value)) {
977
+                    return '';
978
+                }
820 979
                 $_ = getimagesize($value);
821
-                if(!$_[0]) return '';
980
+                if(!$_[0]) {
981
+                    return '';
982
+                }
822 983
                 $info['width']  = $_[0];
823 984
                 $info['height'] = $_[1];
824
-                if    ($_[0] > $_[1]) $info['aspect'] = 'landscape';
825
-                elseif($_[0] < $_[1]) $info['aspect'] = 'portrait';
826
-                else                  $info['aspect'] = 'square';
985
+                if    ($_[0] > $_[1]) {
986
+                    $info['aspect'] = 'landscape';
987
+                } elseif($_[0] < $_[1]) {
988
+                    $info['aspect'] = 'portrait';
989
+                } else {
990
+                    $info['aspect'] = 'square';
991
+                }
827 992
                 switch($_[2]) {
828 993
                     case IMAGETYPE_GIF  : $info['type'] = 'gif'; break;
829 994
                     case IMAGETYPE_JPEG : $info['type'] = 'jpg'; break;
@@ -842,33 +1007,47 @@  discard block
 block discarded – undo
842 1007
 
843 1008
             case 'file_get_contents':
844 1009
             case 'readfile':
845
-                if(!is_file($value)) return $value;
1010
+                if(!is_file($value)) {
1011
+                    return $value;
1012
+                }
846 1013
                 $value = realpath($value);
847
-                if(strpos($value,MODX_MANAGER_PATH)!==false) exit('Can not read core file');
1014
+                if(strpos($value,MODX_MANAGER_PATH)!==false) {
1015
+                    exit('Can not read core file');
1016
+                }
848 1017
                 $ext = strtolower(substr($value,-4));
849
-                if($ext==='.php') exit('Can not read php file');
850
-                if($ext==='.cgi') exit('Can not read cgi file');
1018
+                if($ext==='.php') {
1019
+                    exit('Can not read php file');
1020
+                }
1021
+                if($ext==='.cgi') {
1022
+                    exit('Can not read cgi file');
1023
+                }
851 1024
                 return file_get_contents($value);
852 1025
             case 'filesize':
853
-                if($value == '') return '';
1026
+                if($value == '') {
1027
+                    return '';
1028
+                }
854 1029
                 $filename = $value;
855 1030
 
856 1031
                 $site_url = $modx->config['site_url'];
857
-                if(strpos($filename,$site_url) === 0)
858
-                    $filename = substr($filename,0,strlen($site_url));
1032
+                if(strpos($filename,$site_url) === 0) {
1033
+                                    $filename = substr($filename,0,strlen($site_url));
1034
+                }
859 1035
                 $filename = trim($filename,'/');
860 1036
 
861 1037
                 $opt = trim($opt,'/');
862
-                if($opt!=='') $opt .= '/';
1038
+                if($opt!=='') {
1039
+                    $opt .= '/';
1040
+                }
863 1041
 
864 1042
                 $filename = MODX_BASE_PATH.$opt.$filename;
865 1043
 
866
-                if(is_file($filename)){
1044
+                if(is_file($filename)) {
867 1045
                     clearstatcache();
868 1046
                     $size = filesize($filename);
869 1047
                     return $size;
1048
+                } else {
1049
+                    return '';
870 1050
                 }
871
-                else return '';
872 1051
             #####  User info
873 1052
             case 'username':
874 1053
             case 'fullname':
@@ -896,32 +1075,47 @@  discard block
 block discarded – undo
896 1075
                 $this->opt = $cmd;
897 1076
                 return $this->includeMdfFile('moduser');
898 1077
             case 'userinfo':
899
-                if(empty($opt)) $this->opt = 'username';
1078
+                if(empty($opt)) {
1079
+                    $this->opt = 'username';
1080
+                }
900 1081
                 return $this->includeMdfFile('moduser');
901 1082
             case 'webuserinfo':
902
-                if(empty($opt)) $this->opt = 'username';
1083
+                if(empty($opt)) {
1084
+                    $this->opt = 'username';
1085
+                }
903 1086
                 $this->value = -$value;
904 1087
                 return $this->includeMdfFile('moduser');
905 1088
             #####  Special functions
906 1089
             case 'ifempty':
907 1090
             case '_default':
908 1091
             case 'default':
909
-                if (empty($value)) return $opt; break;
1092
+                if (empty($value)) {
1093
+                    return $opt;
1094
+                }
1095
+                break;
910 1096
             case 'ifnotempty':
911
-                if (!empty($value)) return $opt; break;
1097
+                if (!empty($value)) {
1098
+                    return $opt;
1099
+                }
1100
+                break;
912 1101
             case 'datagrid':
913 1102
                 include_once(MODX_CORE_PATH . 'controls/datagrid.class.php');
914 1103
                 $grd = new DataGrid(null, trim($value));
915 1104
                 $grd->itemStyle = '';
916 1105
                 $grd->altItemStyle = '';
917 1106
                 $pos = strpos($value,"\n");
918
-                if($pos) $_ = substr($value,0,$pos);
919
-                else $_ = $pos;
1107
+                if($pos) {
1108
+                    $_ = substr($value,0,$pos);
1109
+                } else {
1110
+                    $_ = $pos;
1111
+                }
920 1112
                 $grd->cdelim = strpos($_,"\t")!==false ? 'tab' : ',';
921 1113
                 return $grd->render();
922 1114
             case 'rotate':
923 1115
             case 'evenodd':
924
-                if(strpos($opt,',')===false) $opt = 'odd,even';
1116
+                if(strpos($opt,',')===false) {
1117
+                    $opt = 'odd,even';
1118
+                }
925 1119
                 $_ = explode(',', $opt);
926 1120
                 $c = count($_);
927 1121
                 $i = $value + $c;
@@ -930,7 +1124,9 @@  discard block
 block discarded – undo
930 1124
             case 'takeval':
931 1125
                 $arr = explode(",",$opt);
932 1126
                 $idx = $value;
933
-                if(!is_numeric($idx)) return $value;
1127
+                if(!is_numeric($idx)) {
1128
+                    return $value;
1129
+                }
934 1130
                 return $arr[$idx];
935 1131
             case 'getimage':
936 1132
                 return $this->includeMdfFile('getimage');
@@ -938,14 +1134,18 @@  discard block
 block discarded – undo
938 1134
                     return $modx->nicesize($value);
939 1135
             case 'googlemap':
940 1136
             case 'googlemaps':
941
-                if(empty($opt)) $opt = 'border:none;width:500px;height:350px;';
1137
+                if(empty($opt)) {
1138
+                    $opt = 'border:none;width:500px;height:350px;';
1139
+                }
942 1140
                 $tpl = '<iframe style="[+style+]" src="https://maps.google.co.jp/maps?ll=[+value+]&output=embed&z=15"></iframe>';
943 1141
                 $ph['style'] = $opt;
944 1142
                 $ph['value'] = $value;
945 1143
                 return $modx->parseText($tpl,$ph);
946 1144
             case 'youtube':
947 1145
             case 'youtube16x9':
948
-                if(empty($opt)) $opt = 560;
1146
+                if(empty($opt)) {
1147
+                    $opt = 560;
1148
+                }
949 1149
                 $h = round($opt*0.5625);
950 1150
                 $tpl = '<iframe width="%s" height="%s" src="https://www.youtube.com/embed/%s" frameborder="0" allowfullscreen></iframe>';
951 1151
                 return sprintf($tpl,$opt,$h,$value);
@@ -978,7 +1178,8 @@  discard block
 block discarded – undo
978 1178
         return $value;
979 1179
     }
980 1180
 
981
-    public function includeMdfFile($cmd) {
1181
+    public function includeMdfFile($cmd)
1182
+    {
982 1183
         $modx = evolutionCMS();
983 1184
         $key = $this->key;
984 1185
         $value  = $this->value;
@@ -989,55 +1190,65 @@  discard block
 block discarded – undo
989 1190
     public function getValueFromElement($key, $value, $cmd, $opt)
990 1191
     {
991 1192
         $modx = evolutionCMS();
992
-        if( isset($modx->snippetCache[$this->elmName]) )
993
-        {
1193
+        if( isset($modx->snippetCache[$this->elmName]) ) {
994 1194
             $php = $modx->snippetCache[$this->elmName];
995
-        }
996
-        else
997
-        {
1195
+        } else {
998 1196
             $esc_elmName = $modx->db->escape($this->elmName);
999 1197
             $result = $modx->db->select('snippet','[+prefix+]site_snippets',"name='{$esc_elmName}'");
1000 1198
             $total = $modx->db->getRecordCount($result);
1001
-            if($total == 1)
1002
-            {
1199
+            if($total == 1) {
1003 1200
                 $row = $modx->db->getRow($result);
1004 1201
                 $php = $row['snippet'];
1005
-            }
1006
-            elseif($total == 0)
1007
-            {
1202
+            } elseif($total == 0) {
1008 1203
                 $assets_path = MODX_BASE_PATH.'assets/';
1009
-                if(is_file($assets_path."modifiers/mdf_{$cmd}.inc.php"))
1010
-                    $modifiers_path = $assets_path."modifiers/mdf_{$cmd}.inc.php";
1011
-                elseif(is_file($assets_path."plugins/phx/modifiers/{$cmd}.phx.php"))
1012
-                    $modifiers_path = $assets_path."plugins/phx/modifiers/{$cmd}.phx.php";
1013
-                elseif(is_file(MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php"))
1014
-                    $modifiers_path = MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php";
1015
-                else $modifiers_path = false;
1204
+                if(is_file($assets_path."modifiers/mdf_{$cmd}.inc.php")) {
1205
+                                    $modifiers_path = $assets_path."modifiers/mdf_{$cmd}.inc.php";
1206
+                } elseif(is_file($assets_path."plugins/phx/modifiers/{$cmd}.phx.php")) {
1207
+                                    $modifiers_path = $assets_path."plugins/phx/modifiers/{$cmd}.phx.php";
1208
+                } elseif(is_file(MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php")) {
1209
+                                    $modifiers_path = MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php";
1210
+                } else {
1211
+                    $modifiers_path = false;
1212
+                }
1016 1213
 
1017 1214
                 if($modifiers_path !== false) {
1018 1215
                     $php = @file_get_contents($modifiers_path);
1019 1216
                     $php = trim($php);
1020
-                    if(substr($php,0,5)==='<?php') $php = substr($php,6);
1021
-                    if(substr($php,0,2)==='<?')    $php = substr($php,3);
1022
-                    if(substr($php,-2)==='?>')     $php = substr($php,0,-2);
1023
-                    if($this->elmName!=='')
1024
-                        $modx->snippetCache[$this->elmName.'Props'] = '';
1025
-                }
1026
-                else
1027
-                    $php = false;
1217
+                    if(substr($php,0,5)==='<?php') {
1218
+                        $php = substr($php,6);
1219
+                    }
1220
+                    if(substr($php,0,2)==='<?') {
1221
+                        $php = substr($php,3);
1222
+                    }
1223
+                    if(substr($php,-2)==='?>') {
1224
+                        $php = substr($php,0,-2);
1225
+                    }
1226
+                    if($this->elmName!=='') {
1227
+                                            $modx->snippetCache[$this->elmName.'Props'] = '';
1228
+                    }
1229
+                } else {
1230
+                                    $php = false;
1231
+                }
1232
+            } else {
1233
+                $php = false;
1234
+            }
1235
+            if($this->elmName!=='') {
1236
+                $modx->snippetCache[$this->elmName]= $php;
1028 1237
             }
1029
-            else $php = false;
1030
-            if($this->elmName!=='') $modx->snippetCache[$this->elmName]= $php;
1031 1238
         }
1032
-        if($php==='') $php=false;
1239
+        if($php==='') {
1240
+            $php=false;
1241
+        }
1033 1242
 
1034
-        if($php===false) $html = $modx->getChunk($this->elmName);
1035
-        else             $html = false;
1243
+        if($php===false) {
1244
+            $html = $modx->getChunk($this->elmName);
1245
+        } else {
1246
+            $html = false;
1247
+        }
1036 1248
 
1037 1249
         $self = '[+output+]';
1038 1250
 
1039
-        if($php !== false)
1040
-        {
1251
+        if($php !== false) {
1041 1252
             ob_start();
1042 1253
             $options = $opt;
1043 1254
             $output = $value;
@@ -1049,19 +1260,19 @@  discard block
 block discarded – undo
1049 1260
             $this->vars['options'] = & $opt;
1050 1261
             $custom = eval($php);
1051 1262
             $msg = ob_get_contents();
1052
-            if($value===$this->bt) $value = $msg . $custom;
1263
+            if($value===$this->bt) {
1264
+                $value = $msg . $custom;
1265
+            }
1053 1266
             ob_end_clean();
1054
-        }
1055
-        elseif($html!==false && isset($value) && $value!=='')
1056
-        {
1267
+        } elseif($html!==false && isset($value) && $value!=='') {
1057 1268
             $html = str_replace(array($self,'[+value+]'), $value, $html);
1058 1269
             $value = str_replace(array('[+options+]','[+param+]'), $opt, $html);
1270
+        } else {
1271
+            return false;
1059 1272
         }
1060
-        else return false;
1061 1273
 
1062 1274
         if($php===false && $html===false && $value!==''
1063
-           && (strpos($cmd,'[+value+]')!==false || strpos($cmd,$self)!==false))
1064
-        {
1275
+           && (strpos($cmd,'[+value+]')!==false || strpos($cmd,$self)!==false)) {
1065 1276
             $value = str_replace(array('[+value+]',$self),$value,$cmd);
1066 1277
         }
1067 1278
         return $value;
@@ -1071,23 +1282,39 @@  discard block
 block discarded – undo
1071 1282
     {
1072 1283
         $modx = evolutionCMS();
1073 1284
 
1074
-        if(strpos($content,'[')===false && strpos($content,'{')===false) return $content;
1285
+        if(strpos($content,'[')===false && strpos($content,'{')===false) {
1286
+            return $content;
1287
+        }
1075 1288
 
1076
-        if(!$modx->maxParserPasses) $modx->maxParserPasses = 10;
1289
+        if(!$modx->maxParserPasses) {
1290
+            $modx->maxParserPasses = 10;
1291
+        }
1077 1292
         $bt='';
1078 1293
         $i=0;
1079
-        while($bt!==$content)
1080
-        {
1294
+        while($bt!==$content) {
1081 1295
             $bt = $content;
1082
-            if(strpos($content,'[*')!==false && $modx->documentIdentifier)
1083
-                                              $content = $modx->mergeDocumentContent($content);
1084
-            if(strpos($content,'[(')!==false) $content = $modx->mergeSettingsContent($content);
1085
-            if(strpos($content,'{{')!==false) $content = $modx->mergeChunkContent($content);
1086
-            if(strpos($content,'[!')!==false) $content = str_replace(array('[!','!]'),array('[[',']]'),$content);
1087
-            if(strpos($content,'[[')!==false) $content = $modx->evalSnippets($content);
1088
-
1089
-            if($content===$bt)              break;
1090
-            if($modx->maxParserPasses < $i) break;
1296
+            if(strpos($content,'[*')!==false && $modx->documentIdentifier) {
1297
+                                                          $content = $modx->mergeDocumentContent($content);
1298
+            }
1299
+            if(strpos($content,'[(')!==false) {
1300
+                $content = $modx->mergeSettingsContent($content);
1301
+            }
1302
+            if(strpos($content,'{{')!==false) {
1303
+                $content = $modx->mergeChunkContent($content);
1304
+            }
1305
+            if(strpos($content,'[!')!==false) {
1306
+                $content = str_replace(array('[!','!]'),array('[[',']]'),$content);
1307
+            }
1308
+            if(strpos($content,'[[')!==false) {
1309
+                $content = $modx->evalSnippets($content);
1310
+            }
1311
+
1312
+            if($content===$bt) {
1313
+                break;
1314
+            }
1315
+            if($modx->maxParserPasses < $i) {
1316
+                break;
1317
+            }
1091 1318
             $i++;
1092 1319
         }
1093 1320
         return $content;
@@ -1098,103 +1325,138 @@  discard block
 block discarded – undo
1098 1325
         $modx = evolutionCMS();
1099 1326
 
1100 1327
         $target = trim($target);
1101
-        if(empty($target)) $target = $modx->config['site_start'];
1102
-        if(preg_match('@^[1-9][0-9]*$@',$target)) $method='id';
1103
-        else $method = 'alias';
1328
+        if(empty($target)) {
1329
+            $target = $modx->config['site_start'];
1330
+        }
1331
+        if(preg_match('@^[1-9][0-9]*$@',$target)) {
1332
+            $method='id';
1333
+        } else {
1334
+            $method = 'alias';
1335
+        }
1104 1336
 
1105
-        if(!isset($this->documentObject[$target]))
1106
-        {
1337
+        if(!isset($this->documentObject[$target])) {
1107 1338
             $this->documentObject[$target] = $modx->getDocumentObject($method,$target,'direct');
1108 1339
         }
1109 1340
 
1110
-        if($this->documentObject[$target]['publishedon']==='0')
1111
-            return '';
1112
-        elseif(isset($this->documentObject[$target][$field]))
1113
-        {
1114
-            if(is_array($this->documentObject[$target][$field]))
1115
-            {
1341
+        if($this->documentObject[$target]['publishedon']==='0') {
1342
+                    return '';
1343
+        } elseif(isset($this->documentObject[$target][$field])) {
1344
+            if(is_array($this->documentObject[$target][$field])) {
1116 1345
                 $a = $modx->getTemplateVarOutput($field,$target);
1117 1346
                 $this->documentObject[$target][$field] = $a[$field];
1118 1347
             }
1348
+        } else {
1349
+            $this->documentObject[$target][$field] = false;
1119 1350
         }
1120
-        else $this->documentObject[$target][$field] = false;
1121 1351
 
1122 1352
         return $this->documentObject[$target][$field];
1123 1353
     }
1124 1354
 
1125
-    public function setPlaceholders($value = '', $key = '', $path = '') {
1126
-        if($path!=='') $key = "{$path}.{$key}";
1355
+    public function setPlaceholders($value = '', $key = '', $path = '')
1356
+    {
1357
+        if($path!=='') {
1358
+            $key = "{$path}.{$key}";
1359
+        }
1127 1360
         if (is_array($value)) {
1128 1361
             foreach ($value as $subkey => $subval) {
1129 1362
                 $this->setPlaceholders($subval, $subkey, $key);
1130 1363
             }
1364
+        } else {
1365
+            $this->setModifiersVariable($key, $value);
1131 1366
         }
1132
-        else $this->setModifiersVariable($key, $value);
1133 1367
     }
1134 1368
 
1135 1369
     // Sets a placeholder variable which can only be access by Modifiers
1136
-    public function setModifiersVariable($key, $value) {
1137
-        if ($key != 'phx' && $key != 'dummy') $this->placeholders[$key] = $value;
1370
+    public function setModifiersVariable($key, $value)
1371
+    {
1372
+        if ($key != 'phx' && $key != 'dummy') {
1373
+            $this->placeholders[$key] = $value;
1374
+        }
1138 1375
     }
1139 1376
 
1140 1377
     //mbstring
1141
-    public function substr($str, $s, $l = null) {
1378
+    public function substr($str, $s, $l = null)
1379
+    {
1142 1380
         $modx = evolutionCMS();
1143
-        if(is_null($l)) $l = $this->strlen($str);
1144
-        if (function_exists('mb_substr'))
1145
-        {
1146
-            if(strpos($str,"\r")!==false)
1147
-                $str = str_replace(array("\r\n","\r"), "\n", $str);
1381
+        if(is_null($l)) {
1382
+            $l = $this->strlen($str);
1383
+        }
1384
+        if (function_exists('mb_substr')) {
1385
+            if(strpos($str,"\r")!==false) {
1386
+                            $str = str_replace(array("\r\n","\r"), "\n", $str);
1387
+            }
1148 1388
             return mb_substr($str, $s, $l, $modx->config['modx_charset']);
1149 1389
         }
1150 1390
         return substr($str, $s, $l);
1151 1391
     }
1152
-    public function strpos($haystack,$needle,$offset=0) {
1392
+    public function strpos($haystack,$needle,$offset=0)
1393
+    {
1153 1394
         $modx = evolutionCMS();
1154
-        if (function_exists('mb_strpos')) return mb_strpos($haystack,$needle,$offset,$modx->config['modx_charset']);
1395
+        if (function_exists('mb_strpos')) {
1396
+            return mb_strpos($haystack,$needle,$offset,$modx->config['modx_charset']);
1397
+        }
1155 1398
         return strpos($haystack,$needle,$offset);
1156 1399
     }
1157
-    public function strlen($str) {
1400
+    public function strlen($str)
1401
+    {
1158 1402
         $modx = evolutionCMS();
1159
-        if (function_exists('mb_strlen')) return mb_strlen(str_replace("\r\n", "\n", $str),$modx->config['modx_charset']);
1403
+        if (function_exists('mb_strlen')) {
1404
+            return mb_strlen(str_replace("\r\n", "\n", $str),$modx->config['modx_charset']);
1405
+        }
1160 1406
         return strlen($str);
1161 1407
     }
1162
-    public function strtolower($str) {
1163
-        if (function_exists('mb_strtolower')) return mb_strtolower($str);
1408
+    public function strtolower($str)
1409
+    {
1410
+        if (function_exists('mb_strtolower')) {
1411
+            return mb_strtolower($str);
1412
+        }
1164 1413
         return strtolower($str);
1165 1414
     }
1166
-    public function strtoupper($str) {
1167
-        if (function_exists('mb_strtoupper')) return mb_strtoupper($str);
1415
+    public function strtoupper($str)
1416
+    {
1417
+        if (function_exists('mb_strtoupper')) {
1418
+            return mb_strtoupper($str);
1419
+        }
1168 1420
         return strtoupper($str);
1169 1421
     }
1170
-    public function ucfirst($str) {
1171
-        if (function_exists('mb_strtoupper'))
1172
-            return mb_strtoupper($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str));
1422
+    public function ucfirst($str)
1423
+    {
1424
+        if (function_exists('mb_strtoupper')) {
1425
+                    return mb_strtoupper($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str));
1426
+        }
1173 1427
         return ucfirst($str);
1174 1428
     }
1175
-    public function lcfirst($str) {
1176
-        if (function_exists('mb_strtolower'))
1177
-            return mb_strtolower($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str));
1429
+    public function lcfirst($str)
1430
+    {
1431
+        if (function_exists('mb_strtolower')) {
1432
+                    return mb_strtolower($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str));
1433
+        }
1178 1434
         return lcfirst($str);
1179 1435
     }
1180
-    public function ucwords($str) {
1181
-        if (function_exists('mb_convert_case'))
1182
-            return mb_convert_case($str, MB_CASE_TITLE);
1436
+    public function ucwords($str)
1437
+    {
1438
+        if (function_exists('mb_convert_case')) {
1439
+                    return mb_convert_case($str, MB_CASE_TITLE);
1440
+        }
1183 1441
         return ucwords($str);
1184 1442
     }
1185
-    public function strrev($str) {
1443
+    public function strrev($str)
1444
+    {
1186 1445
         preg_match_all('/./us', $str, $ar);
1187 1446
         return implode(array_reverse($ar[0]));
1188 1447
     }
1189
-    public function str_shuffle($str) {
1448
+    public function str_shuffle($str)
1449
+    {
1190 1450
         preg_match_all('/./us', $str, $ar);
1191 1451
         shuffle($ar[0]);
1192 1452
         return implode($ar[0]);
1193 1453
     }
1194
-    public function str_word_count($str) {
1454
+    public function str_word_count($str)
1455
+    {
1195 1456
         return count(preg_split('~[^\p{L}\p{N}\']+~u',$str));
1196 1457
     }
1197
-    public function strip_tags($value,$params='') {
1458
+    public function strip_tags($value,$params='')
1459
+    {
1198 1460
         $modx = evolutionCMS();
1199 1461
 
1200 1462
         if(stripos($params,'style')===false && stripos($value,'</style>')!==false) {
Please login to merge, or discard this patch.
manager/media/rss/rss_cache.inc 4 patches
Doc Comments   +12 added lines patch added patch discarded remove patch
@@ -48,6 +48,9 @@  discard block
 block discarded – undo
48 48
     Input:      url from wich the rss file was fetched
49 49
     Output:     true on sucess
50 50
 \*=======================================================================*/
51
+    /**
52
+     * @param string $url
53
+     */
51 54
     function set ($url, $rss) {
52 55
         $this->ERROR = "";
53 56
         $cache_file = $this->file_name( $url );
@@ -74,6 +77,9 @@  discard block
 block discarded – undo
74 77
     Input:      url from wich the rss file was fetched
75 78
     Output:     cached object on HIT, false on MISS
76 79
 \*=======================================================================*/
80
+    /**
81
+     * @param string $url
82
+     */
77 83
     function get ($url) {
78 84
         $this->ERROR = "";
79 85
         $cache_file = $this->file_name( $url );
@@ -110,6 +116,9 @@  discard block
 block discarded – undo
110 116
     Input:      url from wich the rss file was fetched
111 117
     Output:     cached object on HIT, false on MISS
112 118
 \*=======================================================================*/
119
+    /**
120
+     * @param string $url
121
+     */
113 122
     function check_cache ( $url ) {
114 123
         $this->ERROR = "";
115 124
         $filename = $this->file_name( $url );
@@ -156,6 +165,9 @@  discard block
 block discarded – undo
156 165
 /*=======================================================================*\
157 166
     Function:   unserialize
158 167
 \*=======================================================================*/
168
+    /**
169
+     * @param string $data
170
+     */
159 171
     function unserialize ( $data ) {
160 172
         return unserialize( $data );
161 173
     }
Please login to merge, or discard this patch.
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -94,13 +94,13 @@  discard block
 block discarded – undo
94 94
         }
95 95
 
96 96
         if ($filesize = filesize($cache_file) ) {
97
-        	$data = fread( $fp, filesize($cache_file) );
98
-        	$rss = $this->unserialize( $data );
97
+            $data = fread( $fp, filesize($cache_file) );
98
+            $rss = $this->unserialize( $data );
99 99
 
100
-        	return $rss;
101
-    	}
100
+            return $rss;
101
+        }
102 102
 
103
-    	return 0;
103
+        return 0;
104 104
     }
105 105
 
106 106
 /*=======================================================================*\
@@ -134,17 +134,17 @@  discard block
 block discarded – undo
134 134
         }
135 135
     }
136 136
 
137
-	function cache_age( $cache_key ) {
138
-		$filename = $this->file_name( $url );
139
-		if ( file_exists( $filename ) ) {
140
-			$mtime = filemtime( $filename );
137
+    function cache_age( $cache_key ) {
138
+        $filename = $this->file_name( $url );
139
+        if ( file_exists( $filename ) ) {
140
+            $mtime = filemtime( $filename );
141 141
             $age = time() - $mtime;
142
-			return $age;
143
-		}
144
-		else {
145
-			return -1;
146
-		}
147
-	}
142
+            return $age;
143
+        }
144
+        else {
145
+            return -1;
146
+        }
147
+    }
148 148
 
149 149
 /*=======================================================================*\
150 150
     Function:   serialize
Please login to merge, or discard this patch.
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -16,27 +16,27 @@  discard block
 block discarded – undo
16 16
  *
17 17
  */
18 18
 
19
-class RSSCache {
20
-    var $BASE_CACHE = './cache';    // where the cache files are stored
21
-    var $MAX_AGE    = 3600;         // when are files stale, default one hour
22
-    var $ERROR      = "";           // accumulate error messages
19
+class RSSCache{
20
+    var $BASE_CACHE = './cache'; // where the cache files are stored
21
+    var $MAX_AGE    = 3600; // when are files stale, default one hour
22
+    var $ERROR      = ""; // accumulate error messages
23 23
 
24
-    function __construct($base='', $age='') {
25
-        if ( $base ) {
24
+    function __construct($base = '', $age = ''){
25
+        if ($base) {
26 26
             $this->BASE_CACHE = $base;
27 27
         }
28
-        if ( $age ) {
28
+        if ($age) {
29 29
             $this->MAX_AGE = $age;
30 30
         }
31 31
 
32 32
         // attempt to make the cache directory
33
-        if ( ! file_exists( $this->BASE_CACHE ) ) {
34
-            $status = @mkdir( $this->BASE_CACHE, 0755 );
33
+        if (!file_exists($this->BASE_CACHE)) {
34
+            $status = @mkdir($this->BASE_CACHE, 0755);
35 35
 
36 36
             // if make failed
37
-            if ( ! $status ) {
37
+            if (!$status) {
38 38
                 $this->error(
39
-                    "Cache couldn't make dir '" . $this->BASE_CACHE . "'."
39
+                    "Cache couldn't make dir '".$this->BASE_CACHE."'."
40 40
                 );
41 41
             }
42 42
         }
@@ -48,12 +48,12 @@  discard block
 block discarded – undo
48 48
     Input:      url from wich the rss file was fetched
49 49
     Output:     true on sucess
50 50
 \*=======================================================================*/
51
-    function set ($url, $rss) {
51
+    function set($url, $rss){
52 52
         $this->ERROR = "";
53
-        $cache_file = $this->file_name( $url );
54
-        $fp = @fopen( $cache_file, 'w' );
53
+        $cache_file = $this->file_name($url);
54
+        $fp = @fopen($cache_file, 'w');
55 55
 
56
-        if ( ! $fp ) {
56
+        if (!$fp) {
57 57
             $this->error(
58 58
                 "Cache unable to open file for writing: $cache_file"
59 59
             );
@@ -61,9 +61,9 @@  discard block
 block discarded – undo
61 61
         }
62 62
 
63 63
 
64
-        $data = $this->serialize( $rss );
65
-        fwrite( $fp, $data );
66
-        fclose( $fp );
64
+        $data = $this->serialize($rss);
65
+        fwrite($fp, $data);
66
+        fclose($fp);
67 67
 
68 68
         return $cache_file;
69 69
     }
@@ -74,11 +74,11 @@  discard block
 block discarded – undo
74 74
     Input:      url from wich the rss file was fetched
75 75
     Output:     cached object on HIT, false on MISS
76 76
 \*=======================================================================*/
77
-    function get ($url) {
77
+    function get($url){
78 78
         $this->ERROR = "";
79
-        $cache_file = $this->file_name( $url );
79
+        $cache_file = $this->file_name($url);
80 80
 
81
-        if ( ! file_exists( $cache_file ) ) {
81
+        if (!file_exists($cache_file)) {
82 82
             $this->debug(
83 83
                 "Cache doesn't contain: $url (cache file: $cache_file)"
84 84
             );
@@ -86,16 +86,16 @@  discard block
 block discarded – undo
86 86
         }
87 87
 
88 88
         $fp = @fopen($cache_file, 'r');
89
-        if ( ! $fp ) {
89
+        if (!$fp) {
90 90
             $this->error(
91 91
                 "Failed to open cache file for reading: $cache_file"
92 92
             );
93 93
             return 0;
94 94
         }
95 95
 
96
-        if ($filesize = filesize($cache_file) ) {
97
-        	$data = fread( $fp, filesize($cache_file) );
98
-        	$rss = $this->unserialize( $data );
96
+        if ($filesize = filesize($cache_file)) {
97
+        	$data = fread($fp, filesize($cache_file));
98
+        	$rss = $this->unserialize($data);
99 99
 
100 100
         	return $rss;
101 101
     	}
@@ -110,16 +110,16 @@  discard block
 block discarded – undo
110 110
     Input:      url from wich the rss file was fetched
111 111
     Output:     cached object on HIT, false on MISS
112 112
 \*=======================================================================*/
113
-    function check_cache ( $url ) {
113
+    function check_cache($url){
114 114
         $this->ERROR = "";
115
-        $filename = $this->file_name( $url );
115
+        $filename = $this->file_name($url);
116 116
 
117
-        if ( file_exists( $filename ) ) {
117
+        if (file_exists($filename)) {
118 118
             // find how long ago the file was added to the cache
119 119
             // and whether that is longer then MAX_AGE
120
-            $mtime = filemtime( $filename );
120
+            $mtime = filemtime($filename);
121 121
             $age = time() - $mtime;
122
-            if ( $this->MAX_AGE > $age ) {
122
+            if ($this->MAX_AGE > $age) {
123 123
                 // object exists and is current
124 124
                 return 'HIT';
125 125
             }
@@ -134,10 +134,10 @@  discard block
 block discarded – undo
134 134
         }
135 135
     }
136 136
 
137
-	function cache_age( $cache_key ) {
138
-		$filename = $this->file_name( $url );
139
-		if ( file_exists( $filename ) ) {
140
-			$mtime = filemtime( $filename );
137
+	function cache_age($cache_key){
138
+		$filename = $this->file_name($url);
139
+		if (file_exists($filename)) {
140
+			$mtime = filemtime($filename);
141 141
             $age = time() - $mtime;
142 142
 			return $age;
143 143
 		}
@@ -149,15 +149,15 @@  discard block
 block discarded – undo
149 149
 /*=======================================================================*\
150 150
     Function:   serialize
151 151
 \*=======================================================================*/
152
-    function serialize ( $rss ) {
153
-        return serialize( $rss );
152
+    function serialize($rss){
153
+        return serialize($rss);
154 154
     }
155 155
 
156 156
 /*=======================================================================*\
157 157
     Function:   unserialize
158 158
 \*=======================================================================*/
159
-    function unserialize ( $data ) {
160
-        return unserialize( $data );
159
+    function unserialize($data){
160
+        return unserialize($data);
161 161
     }
162 162
 
163 163
 /*=======================================================================*\
@@ -166,31 +166,31 @@  discard block
 block discarded – undo
166 166
     Input:      url from wich the rss file was fetched
167 167
     Output:     a file name
168 168
 \*=======================================================================*/
169
-    function file_name ($url) {
170
-        $filename = md5( $url );
171
-        return implode( DIRECTORY_SEPARATOR, array( $this->BASE_CACHE, $filename ) );
169
+    function file_name($url){
170
+        $filename = md5($url);
171
+        return implode(DIRECTORY_SEPARATOR, array($this->BASE_CACHE, $filename));
172 172
     }
173 173
 
174 174
 /*=======================================================================*\
175 175
     Function:   error
176 176
     Purpose:    register error
177 177
 \*=======================================================================*/
178
-    function error ($errormsg, $lvl=E_USER_WARNING) {
178
+    function error($errormsg, $lvl = E_USER_WARNING){
179 179
         // append PHP's error message if track_errors enabled
180
-        if ( isset($php_errormsg) ) {
180
+        if (isset($php_errormsg)) {
181 181
             $errormsg .= " ($php_errormsg)";
182 182
         }
183 183
         $this->ERROR = $errormsg;
184
-        if ( MAGPIE_DEBUG ) {
185
-            trigger_error( $errormsg, $lvl);
184
+        if (MAGPIE_DEBUG) {
185
+            trigger_error($errormsg, $lvl);
186 186
         }
187 187
         else {
188
-            error_log( $errormsg, 0);
188
+            error_log($errormsg, 0);
189 189
         }
190 190
     }
191 191
 
192
-    function debug ($debugmsg, $lvl=E_USER_NOTICE) {
193
-        if ( MAGPIE_DEBUG ) {
192
+    function debug($debugmsg, $lvl = E_USER_NOTICE){
193
+        if (MAGPIE_DEBUG) {
194 194
             $this->error("MagpieRSS [debug] $debugmsg", $lvl);
195 195
         }
196 196
     }
Please login to merge, or discard this patch.
Braces   +26 added lines, -19 removed lines patch added patch discarded remove patch
@@ -16,12 +16,14 @@  discard block
 block discarded – undo
16 16
  *
17 17
  */
18 18
 
19
-class RSSCache {
19
+class RSSCache
20
+{
20 21
     var $BASE_CACHE = './cache';    // where the cache files are stored
21 22
     var $MAX_AGE    = 3600;         // when are files stale, default one hour
22 23
     var $ERROR      = "";           // accumulate error messages
23 24
 
24
-    function __construct($base='', $age='') {
25
+    function __construct($base='', $age='')
26
+    {
25 27
         if ( $base ) {
26 28
             $this->BASE_CACHE = $base;
27 29
         }
@@ -48,7 +50,8 @@  discard block
 block discarded – undo
48 50
     Input:      url from wich the rss file was fetched
49 51
     Output:     true on sucess
50 52
 \*=======================================================================*/
51
-    function set ($url, $rss) {
53
+    function set ($url, $rss)
54
+    {
52 55
         $this->ERROR = "";
53 56
         $cache_file = $this->file_name( $url );
54 57
         $fp = @fopen( $cache_file, 'w' );
@@ -74,7 +77,8 @@  discard block
 block discarded – undo
74 77
     Input:      url from wich the rss file was fetched
75 78
     Output:     cached object on HIT, false on MISS
76 79
 \*=======================================================================*/
77
-    function get ($url) {
80
+    function get ($url)
81
+    {
78 82
         $this->ERROR = "";
79 83
         $cache_file = $this->file_name( $url );
80 84
 
@@ -110,7 +114,8 @@  discard block
 block discarded – undo
110 114
     Input:      url from wich the rss file was fetched
111 115
     Output:     cached object on HIT, false on MISS
112 116
 \*=======================================================================*/
113
-    function check_cache ( $url ) {
117
+    function check_cache ( $url )
118
+    {
114 119
         $this->ERROR = "";
115 120
         $filename = $this->file_name( $url );
116 121
 
@@ -122,26 +127,24 @@  discard block
 block discarded – undo
122 127
             if ( $this->MAX_AGE > $age ) {
123 128
                 // object exists and is current
124 129
                 return 'HIT';
125
-            }
126
-            else {
130
+            } else {
127 131
                 // object exists but is old
128 132
                 return 'STALE';
129 133
             }
130
-        }
131
-        else {
134
+        } else {
132 135
             // object does not exist
133 136
             return 'MISS';
134 137
         }
135 138
     }
136 139
 
137
-	function cache_age( $cache_key ) {
140
+	function cache_age( $cache_key )
141
+	{
138 142
 		$filename = $this->file_name( $url );
139 143
 		if ( file_exists( $filename ) ) {
140 144
 			$mtime = filemtime( $filename );
141 145
             $age = time() - $mtime;
142 146
 			return $age;
143
-		}
144
-		else {
147
+		} else {
145 148
 			return -1;
146 149
 		}
147 150
 	}
@@ -149,14 +152,16 @@  discard block
 block discarded – undo
149 152
 /*=======================================================================*\
150 153
     Function:   serialize
151 154
 \*=======================================================================*/
152
-    function serialize ( $rss ) {
155
+    function serialize ( $rss )
156
+    {
153 157
         return serialize( $rss );
154 158
     }
155 159
 
156 160
 /*=======================================================================*\
157 161
     Function:   unserialize
158 162
 \*=======================================================================*/
159
-    function unserialize ( $data ) {
163
+    function unserialize ( $data )
164
+    {
160 165
         return unserialize( $data );
161 166
     }
162 167
 
@@ -166,7 +171,8 @@  discard block
 block discarded – undo
166 171
     Input:      url from wich the rss file was fetched
167 172
     Output:     a file name
168 173
 \*=======================================================================*/
169
-    function file_name ($url) {
174
+    function file_name ($url)
175
+    {
170 176
         $filename = md5( $url );
171 177
         return implode( DIRECTORY_SEPARATOR, array( $this->BASE_CACHE, $filename ) );
172 178
     }
@@ -175,7 +181,8 @@  discard block
 block discarded – undo
175 181
     Function:   error
176 182
     Purpose:    register error
177 183
 \*=======================================================================*/
178
-    function error ($errormsg, $lvl=E_USER_WARNING) {
184
+    function error ($errormsg, $lvl=E_USER_WARNING)
185
+    {
179 186
         // append PHP's error message if track_errors enabled
180 187
         if ( isset($php_errormsg) ) {
181 188
             $errormsg .= " ($php_errormsg)";
@@ -183,13 +190,13 @@  discard block
 block discarded – undo
183 190
         $this->ERROR = $errormsg;
184 191
         if ( MAGPIE_DEBUG ) {
185 192
             trigger_error( $errormsg, $lvl);
186
-        }
187
-        else {
193
+        } else {
188 194
             error_log( $errormsg, 0);
189 195
         }
190 196
     }
191 197
 
192
-    function debug ($debugmsg, $lvl=E_USER_NOTICE) {
198
+    function debug ($debugmsg, $lvl=E_USER_NOTICE)
199
+    {
193 200
         if ( MAGPIE_DEBUG ) {
194 201
             $this->error("MagpieRSS [debug] $debugmsg", $lvl);
195 202
         }
Please login to merge, or discard this patch.
manager/includes/manager.lockout.inc.php 3 patches
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 
23 23
     // load template
24 24
     if(!isset($modx->config['manager_lockout_tpl']) || empty($modx->config['manager_lockout_tpl'])) {
25
-    	$modx->config['manager_lockout_tpl'] = MODX_MANAGER_PATH . 'media/style/common/manager.lockout.tpl';
25
+        $modx->config['manager_lockout_tpl'] = MODX_MANAGER_PATH . 'media/style/common/manager.lockout.tpl';
26 26
     }
27 27
 
28 28
     $target = $modx->config['manager_lockout_tpl'];
@@ -30,40 +30,40 @@  discard block
 block discarded – undo
30 30
     $target = $modx->mergeSettingsContent($target);
31 31
 
32 32
     if(substr($target,0,1)==='@') {
33
-    	if(substr($target,0,6)==='@CHUNK') {
34
-    		$target = trim(substr($target,7));
35
-    		$lockout_tpl = $modx->getChunk($target);
36
-    	}
37
-    	elseif(substr($target,0,5)==='@FILE') {
38
-    		$target = trim(substr($target,6));
39
-    		$lockout_tpl = file_get_contents($target);
40
-    	}
41
-	} else {
42
-    	$chunk = $modx->getChunk($target);
43
-    	if($chunk!==false && !empty($chunk)) {
44
-    		$lockout_tpl = $chunk;
45
-    	}
46
-    	elseif(is_file(MODX_BASE_PATH . $target)) {
47
-    		$target = MODX_BASE_PATH . $target;
48
-    		$lockout_tpl = file_get_contents($target);
49
-    	}
50
-    	elseif(is_file(MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/manager.lockout.tpl')) {
51
-    		$target = MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/manager.lockout.tpl';
52
-    		$lockout_tpl = file_get_contents($target);
53
-    	}
54
-	elseif(is_file(MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/templates/actions/manager.lockout.tpl')) {
55
-		$target = MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/templates/actions/manager.lockout.tpl';
56
-		$login_tpl = file_get_contents($target);
57
-	}
58
-    	elseif(is_file(MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/html/manager.lockout.html')) { // ClipperCMS compatible
59
-    		$target = MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/html/manager.lockout.html';
60
-    		$lockout_tpl = file_get_contents($target);
61
-    	}
62
-    	else {
63
-    		$target = MODX_MANAGER_PATH . 'media/style/common/manager.lockout.tpl';
64
-    		$lockout_tpl = file_get_contents($target);
65
-    	}
66
-	}
33
+        if(substr($target,0,6)==='@CHUNK') {
34
+            $target = trim(substr($target,7));
35
+            $lockout_tpl = $modx->getChunk($target);
36
+        }
37
+        elseif(substr($target,0,5)==='@FILE') {
38
+            $target = trim(substr($target,6));
39
+            $lockout_tpl = file_get_contents($target);
40
+        }
41
+    } else {
42
+        $chunk = $modx->getChunk($target);
43
+        if($chunk!==false && !empty($chunk)) {
44
+            $lockout_tpl = $chunk;
45
+        }
46
+        elseif(is_file(MODX_BASE_PATH . $target)) {
47
+            $target = MODX_BASE_PATH . $target;
48
+            $lockout_tpl = file_get_contents($target);
49
+        }
50
+        elseif(is_file(MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/manager.lockout.tpl')) {
51
+            $target = MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/manager.lockout.tpl';
52
+            $lockout_tpl = file_get_contents($target);
53
+        }
54
+    elseif(is_file(MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/templates/actions/manager.lockout.tpl')) {
55
+        $target = MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/templates/actions/manager.lockout.tpl';
56
+        $login_tpl = file_get_contents($target);
57
+    }
58
+        elseif(is_file(MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/html/manager.lockout.html')) { // ClipperCMS compatible
59
+            $target = MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/html/manager.lockout.html';
60
+            $lockout_tpl = file_get_contents($target);
61
+        }
62
+        else {
63
+            $target = MODX_MANAGER_PATH . 'media/style/common/manager.lockout.tpl';
64
+            $lockout_tpl = file_get_contents($target);
65
+        }
66
+    }
67 67
 
68 68
     // merge placeholders
69 69
     $lockout_tpl = $modx->mergePlaceholderContent($lockout_tpl);
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -1,75 +1,75 @@
 block discarded – undo
1 1
 <?php
2
-if( ! defined('IN_MANAGER_MODE') || IN_MANAGER_MODE !== true) {
2
+if (!defined('IN_MANAGER_MODE') || IN_MANAGER_MODE !== true) {
3 3
     die("<b>INCLUDE_ORDERING_ERROR</b><br /><br />Please use the EVO Content Manager instead of accessing this file directly.");
4 4
 }
5 5
 
6
-if($modx->manager->action!='8' && isset($_SESSION['mgrValidated'])){
6
+if ($modx->manager->action != '8' && isset($_SESSION['mgrValidated'])) {
7 7
 
8
-    $homeurl = $modx->makeUrl($manager_login_startup>0 ? $manager_login_startup:$site_start);
8
+    $homeurl = $modx->makeUrl($manager_login_startup > 0 ? $manager_login_startup : $site_start);
9 9
     $logouturl = MODX_MANAGER_URL.'index.php?a=8';
10 10
 
11
-    $modx->setPlaceholder('modx_charset',$modx_manager_charset);
12
-    $modx->setPlaceholder('theme',$manager_theme);
11
+    $modx->setPlaceholder('modx_charset', $modx_manager_charset);
12
+    $modx->setPlaceholder('theme', $manager_theme);
13 13
 
14
-    $modx->setPlaceholder('site_name',$site_name);
15
-    $modx->setPlaceholder('logo_slogan',$_lang["logo_slogan"]);
16
-    $modx->setPlaceholder('manager_lockout_message',$_lang["manager_lockout_message"]);
14
+    $modx->setPlaceholder('site_name', $site_name);
15
+    $modx->setPlaceholder('logo_slogan', $_lang["logo_slogan"]);
16
+    $modx->setPlaceholder('manager_lockout_message', $_lang["manager_lockout_message"]);
17 17
 
18
-    $modx->setPlaceholder('home',$_lang["home"]);
19
-    $modx->setPlaceholder('homeurl',$homeurl);
20
-    $modx->setPlaceholder('logout',$_lang["logout"]);
21
-    $modx->setPlaceholder('logouturl',$logouturl);
22
-    $modx->setPlaceholder('manager_theme_url',MODX_MANAGER_URL . 'media/style/' . $modx->config['manager_theme'] . '/');
23
-    $modx->setPlaceholder('year',date('Y'));
18
+    $modx->setPlaceholder('home', $_lang["home"]);
19
+    $modx->setPlaceholder('homeurl', $homeurl);
20
+    $modx->setPlaceholder('logout', $_lang["logout"]);
21
+    $modx->setPlaceholder('logouturl', $logouturl);
22
+    $modx->setPlaceholder('manager_theme_url', MODX_MANAGER_URL.'media/style/'.$modx->config['manager_theme'].'/');
23
+    $modx->setPlaceholder('year', date('Y'));
24 24
 
25 25
     // load template
26
-    if(!isset($modx->config['manager_lockout_tpl']) || empty($modx->config['manager_lockout_tpl'])) {
27
-    	$modx->config['manager_lockout_tpl'] = MODX_MANAGER_PATH . 'media/style/common/manager.lockout.tpl';
26
+    if (!isset($modx->config['manager_lockout_tpl']) || empty($modx->config['manager_lockout_tpl'])) {
27
+    	$modx->config['manager_lockout_tpl'] = MODX_MANAGER_PATH.'media/style/common/manager.lockout.tpl';
28 28
     }
29 29
 
30 30
     $target = $modx->config['manager_lockout_tpl'];
31 31
     $target = str_replace('[+base_path+]', MODX_BASE_PATH, $target);
32 32
     $target = $modx->mergeSettingsContent($target);
33 33
 
34
-    if(substr($target,0,1)==='@') {
35
-    	if(substr($target,0,6)==='@CHUNK') {
36
-    		$target = trim(substr($target,7));
34
+    if (substr($target, 0, 1) === '@') {
35
+    	if (substr($target, 0, 6) === '@CHUNK') {
36
+    		$target = trim(substr($target, 7));
37 37
     		$lockout_tpl = $modx->getChunk($target);
38 38
     	}
39
-    	elseif(substr($target,0,5)==='@FILE') {
40
-    		$target = trim(substr($target,6));
39
+    	elseif (substr($target, 0, 5) === '@FILE') {
40
+    		$target = trim(substr($target, 6));
41 41
     		$lockout_tpl = file_get_contents($target);
42 42
     	}
43 43
 	} else {
44 44
     	$chunk = $modx->getChunk($target);
45
-    	if($chunk!==false && !empty($chunk)) {
45
+    	if ($chunk !== false && !empty($chunk)) {
46 46
     		$lockout_tpl = $chunk;
47 47
     	}
48
-    	elseif(is_file(MODX_BASE_PATH . $target)) {
49
-    		$target = MODX_BASE_PATH . $target;
48
+    	elseif (is_file(MODX_BASE_PATH.$target)) {
49
+    		$target = MODX_BASE_PATH.$target;
50 50
     		$lockout_tpl = file_get_contents($target);
51 51
     	}
52
-    	elseif(is_file(MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/manager.lockout.tpl')) {
53
-    		$target = MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/manager.lockout.tpl';
52
+    	elseif (is_file(MODX_MANAGER_PATH.'media/style/'.$modx->config['manager_theme'].'/manager.lockout.tpl')) {
53
+    		$target = MODX_MANAGER_PATH.'media/style/'.$modx->config['manager_theme'].'/manager.lockout.tpl';
54 54
     		$lockout_tpl = file_get_contents($target);
55 55
     	}
56
-	elseif(is_file(MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/templates/actions/manager.lockout.tpl')) {
57
-		$target = MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/templates/actions/manager.lockout.tpl';
56
+	elseif (is_file(MODX_MANAGER_PATH.'media/style/'.$modx->config['manager_theme'].'/templates/actions/manager.lockout.tpl')) {
57
+		$target = MODX_MANAGER_PATH.'media/style/'.$modx->config['manager_theme'].'/templates/actions/manager.lockout.tpl';
58 58
 		$login_tpl = file_get_contents($target);
59 59
 	}
60
-    	elseif(is_file(MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/html/manager.lockout.html')) { // ClipperCMS compatible
61
-    		$target = MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/html/manager.lockout.html';
60
+    	elseif (is_file(MODX_MANAGER_PATH.'media/style/'.$modx->config['manager_theme'].'/html/manager.lockout.html')) { // ClipperCMS compatible
61
+    		$target = MODX_MANAGER_PATH.'media/style/'.$modx->config['manager_theme'].'/html/manager.lockout.html';
62 62
     		$lockout_tpl = file_get_contents($target);
63 63
     	}
64 64
     	else {
65
-    		$target = MODX_MANAGER_PATH . 'media/style/common/manager.lockout.tpl';
65
+    		$target = MODX_MANAGER_PATH.'media/style/common/manager.lockout.tpl';
66 66
     		$lockout_tpl = file_get_contents($target);
67 67
     	}
68 68
 	}
69 69
 
70 70
     // merge placeholders
71 71
     $lockout_tpl = $modx->mergePlaceholderContent($lockout_tpl);
72
-    $regx = strpos($lockout_tpl,'[[+')!==false ? '~\[\[\+(.*?)\]\]~' : '~\[\+(.*?)\+\]~'; // little tweak for newer parsers
72
+    $regx = strpos($lockout_tpl, '[[+') !== false ? '~\[\[\+(.*?)\]\]~' : '~\[\+(.*?)\+\]~'; // little tweak for newer parsers
73 73
     $lockout_tpl = preg_replace($regx, '', $lockout_tpl); //cleanup
74 74
 
75 75
     echo $lockout_tpl;
Please login to merge, or discard this patch.
Braces   +8 added lines, -13 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
     die("<b>INCLUDE_ORDERING_ERROR</b><br /><br />Please use the EVO Content Manager instead of accessing this file directly.");
4 4
 }
5 5
 
6
-if($modx->manager->action!='8' && isset($_SESSION['mgrValidated'])){
6
+if($modx->manager->action!='8' && isset($_SESSION['mgrValidated'])) {
7 7
 
8 8
     $homeurl = $modx->makeUrl($manager_login_startup>0 ? $manager_login_startup:$site_start);
9 9
     $logouturl = MODX_MANAGER_URL.'index.php?a=8';
@@ -35,8 +35,7 @@  discard block
 block discarded – undo
35 35
     	if(substr($target,0,6)==='@CHUNK') {
36 36
     		$target = trim(substr($target,7));
37 37
     		$lockout_tpl = $modx->getChunk($target);
38
-    	}
39
-    	elseif(substr($target,0,5)==='@FILE') {
38
+    	} elseif(substr($target,0,5)==='@FILE') {
40 39
     		$target = trim(substr($target,6));
41 40
     		$lockout_tpl = file_get_contents($target);
42 41
     	}
@@ -44,24 +43,20 @@  discard block
 block discarded – undo
44 43
     	$chunk = $modx->getChunk($target);
45 44
     	if($chunk!==false && !empty($chunk)) {
46 45
     		$lockout_tpl = $chunk;
47
-    	}
48
-    	elseif(is_file(MODX_BASE_PATH . $target)) {
46
+    	} elseif(is_file(MODX_BASE_PATH . $target)) {
49 47
     		$target = MODX_BASE_PATH . $target;
50 48
     		$lockout_tpl = file_get_contents($target);
51
-    	}
52
-    	elseif(is_file(MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/manager.lockout.tpl')) {
49
+    	} elseif(is_file(MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/manager.lockout.tpl')) {
53 50
     		$target = MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/manager.lockout.tpl';
54 51
     		$lockout_tpl = file_get_contents($target);
55
-    	}
56
-	elseif(is_file(MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/templates/actions/manager.lockout.tpl')) {
52
+    	} elseif(is_file(MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/templates/actions/manager.lockout.tpl')) {
57 53
 		$target = MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/templates/actions/manager.lockout.tpl';
58 54
 		$login_tpl = file_get_contents($target);
59
-	}
60
-    	elseif(is_file(MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/html/manager.lockout.html')) { // ClipperCMS compatible
55
+	} elseif(is_file(MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/html/manager.lockout.html')) {
56
+// ClipperCMS compatible
61 57
     		$target = MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/html/manager.lockout.html';
62 58
     		$lockout_tpl = file_get_contents($target);
63
-    	}
64
-    	else {
59
+    	} else {
65 60
     		$target = MODX_MANAGER_PATH . 'media/style/common/manager.lockout.tpl';
66 61
     		$lockout_tpl = file_get_contents($target);
67 62
     	}
Please login to merge, or discard this patch.
manager/media/rss/rss_parse.inc 4 patches
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -98,8 +98,8 @@  discard block
 block discarded – undo
98 98
         #
99 99
         if (!function_exists('xml_parser_create')) {
100 100
             $this->error( "Failed to load PHP's XML Extension. " .
101
-                          "http://www.php.net/manual/en/ref.xml.php",
102
-                           E_USER_ERROR );
101
+                            "http://www.php.net/manual/en/ref.xml.php",
102
+                            E_USER_ERROR );
103 103
         }
104 104
 
105 105
         list($parser, $source) = $this->create_parser($source,
@@ -108,8 +108,8 @@  discard block
 block discarded – undo
108 108
 
109 109
         if (!is_resource($parser)) {
110 110
             $this->error( "Failed to create an instance of PHP's XML parser. " .
111
-                          "http://www.php.net/manual/en/ref.xml.php",
112
-                          E_USER_ERROR );
111
+                            "http://www.php.net/manual/en/ref.xml.php",
112
+                            E_USER_ERROR );
113 113
         }
114 114
 
115 115
 
@@ -445,9 +445,9 @@  discard block
 block discarded – undo
445 445
     }
446 446
 
447 447
     /**
448
-    * return XML parser, and possibly re-encoded source
449
-    *
450
-    */
448
+     * return XML parser, and possibly re-encoded source
449
+     *
450
+     */
451 451
     function create_parser($source, $out_enc, $in_enc, $detect) {
452 452
         if ( substr(phpversion(),0,1) == 5) {
453 453
             $parser = $this->php5_create_parser($in_enc, $detect);
@@ -464,14 +464,14 @@  discard block
 block discarded – undo
464 464
     }
465 465
 
466 466
     /**
467
-    * Instantiate an XML parser under PHP5
468
-    *
469
-    * PHP5 will do a fine job of detecting input encoding
470
-    * if passed an empty string as the encoding.
471
-    *
472
-    * All hail libxml2!
473
-    *
474
-    */
467
+     * Instantiate an XML parser under PHP5
468
+     *
469
+     * PHP5 will do a fine job of detecting input encoding
470
+     * if passed an empty string as the encoding.
471
+     *
472
+     * All hail libxml2!
473
+     *
474
+     */
475 475
     function php5_create_parser($in_enc, $detect) {
476 476
         // by default php5 does a fine job of detecting input encodings
477 477
         if(!$detect && $in_enc) {
@@ -483,20 +483,20 @@  discard block
 block discarded – undo
483 483
     }
484 484
 
485 485
     /**
486
-    * Instaniate an XML parser under PHP4
487
-    *
488
-    * Unfortunately PHP4's support for character encodings
489
-    * and especially XML and character encodings sucks.  As
490
-    * long as the documents you parse only contain characters
491
-    * from the ISO-8859-1 character set (a superset of ASCII,
492
-    * and a subset of UTF-8) you're fine.  However once you
493
-    * step out of that comfy little world things get mad, bad,
494
-    * and dangerous to know.
495
-    *
496
-    * The following code is based on SJM's work with FoF
497
-    * @see http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss
498
-    *
499
-    */
486
+     * Instaniate an XML parser under PHP4
487
+     *
488
+     * Unfortunately PHP4's support for character encodings
489
+     * and especially XML and character encodings sucks.  As
490
+     * long as the documents you parse only contain characters
491
+     * from the ISO-8859-1 character set (a superset of ASCII,
492
+     * and a subset of UTF-8) you're fine.  However once you
493
+     * step out of that comfy little world things get mad, bad,
494
+     * and dangerous to know.
495
+     *
496
+     * The following code is based on SJM's work with FoF
497
+     * @see http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss
498
+     *
499
+     */
500 500
     function php4_create_parser($source, $in_enc, $detect) {
501 501
         if ( !$detect ) {
502 502
             return array(xml_parser_create($in_enc), $source);
@@ -540,8 +540,8 @@  discard block
 block discarded – undo
540 540
 
541 541
         // else
542 542
         $this->error("Feed is in an unsupported character encoding. ($in_enc) " .
543
-                     "You may see strange artifacts, and mangled characters.",
544
-                     E_USER_NOTICE);
543
+                        "You may see strange artifacts, and mangled characters.",
544
+                        E_USER_NOTICE);
545 545
 
546 546
         return array(xml_parser_create(), $source);
547 547
     }
@@ -587,26 +587,26 @@  discard block
 block discarded – undo
587 587
 // courtesy, Ryan Currie, [email protected]
588 588
 
589 589
 if (!function_exists('array_change_key_case')) {
590
-	define('CASE_UPPER', 1);
591
-	define('CASE_LOWER', 0);
590
+    define('CASE_UPPER', 1);
591
+    define('CASE_LOWER', 0);
592 592
 
593 593
 
594
-	function array_change_key_case($array, $case=CASE_LOWER) {
594
+    function array_change_key_case($array, $case=CASE_LOWER) {
595 595
         $output = array();
596 596
         switch($case){
597
-           case CASE_LOWER:
597
+            case CASE_LOWER:
598 598
                $cmd='strtolower';
599
-               break;
600
-           case CASE_UPPER:
599
+                break;
600
+            case CASE_UPPER:
601 601
                $cmd='strtoupper';
602
-               break;
603
-           default:
602
+                break;
603
+            default:
604 604
                $cmd = '';
605 605
         }
606 606
         foreach($array as $key=>$value) {
607 607
             $output[empty($cmd) ? $key : $cmd($key)] = $value;
608 608
         }
609 609
         return $output;
610
-	}
610
+    }
611 611
 
612 612
 }
Please login to merge, or discard this patch.
Doc Comments   +14 added lines patch added patch discarded remove patch
@@ -332,6 +332,10 @@  discard block
 block discarded – undo
332 332
     }
333 333
 
334 334
     // smart append - field and namespace aware
335
+
336
+    /**
337
+     * @param string $el
338
+     */
335 339
     function append($el, $text) {
336 340
         if (!$el) {
337 341
             return;
@@ -447,6 +451,10 @@  discard block
 block discarded – undo
447 451
     /**
448 452
     * return XML parser, and possibly re-encoded source
449 453
     *
454
+    * @param string $source
455
+    * @param string $out_enc
456
+    * @param string|null $in_enc
457
+    * @param boolean $detect
450 458
     */
451 459
     function create_parser($source, $out_enc, $in_enc, $detect) {
452 460
         if ( substr(phpversion(),0,1) == 5) {
@@ -556,6 +564,9 @@  discard block
 block discarded – undo
556 564
         }
557 565
     }
558 566
 
567
+    /**
568
+     * @param integer $lvl
569
+     */
559 570
     function error ($errormsg, $lvl=E_USER_WARNING) {
560 571
         // append PHP's error message if track_errors enabled
561 572
         if ( isset($php_errormsg) ) {
@@ -591,6 +602,9 @@  discard block
 block discarded – undo
591 602
 	define('CASE_LOWER', 0);
592 603
 
593 604
 
605
+	/**
606
+	 * @param integer $case
607
+	 */
594 608
 	function array_change_key_case($array, $case=CASE_LOWER) {
595 609
         $output = array();
596 610
         switch($case){
Please login to merge, or discard this patch.
Spacing   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 define('RSS', 'RSS');
24 24
 define('ATOM', 'Atom');
25 25
 
26
-require_once (MAGPIE_DIR . 'rss_utils.inc');
26
+require_once (MAGPIE_DIR.'rss_utils.inc');
27 27
 
28 28
 /**
29 29
 * Hybrid parser, and object, takes RSS as a string and returns a simple object.
@@ -31,19 +31,19 @@  discard block
 block discarded – undo
31 31
 * see: rss_fetch.inc for a simpler interface with integrated caching support
32 32
 *
33 33
 */
34
-class MagpieRSS {
34
+class MagpieRSS{
35 35
     var $parser;
36 36
 
37
-    var $current_item   = array();  // item currently being parsed
38
-    var $items          = array();  // collection of parsed items
39
-    var $channel        = array();  // hash of channel fields
37
+    var $current_item   = array(); // item currently being parsed
38
+    var $items          = array(); // collection of parsed items
39
+    var $channel        = array(); // hash of channel fields
40 40
     var $textinput      = array();
41 41
     var $image          = array();
42 42
     var $feed_type;
43 43
     var $feed_version;
44
-    var $encoding       = '';       // output encoding of parsed rss
44
+    var $encoding       = ''; // output encoding of parsed rss
45 45
 
46
-    var $_source_encoding = '';     // only set if we have to parse xml prolog
46
+    var $_source_encoding = ''; // only set if we have to parse xml prolog
47 47
 
48 48
     var $ERROR = "";
49 49
     var $WARNING = "";
@@ -91,15 +91,15 @@  discard block
 block discarded – undo
91 91
      *                                  source encoding. (caveat emptor)
92 92
      *
93 93
      */
94
-    function __construct($source, $output_encoding='ISO-8859-1',
95
-                        $input_encoding=null, $detect_encoding=true)
94
+    function __construct($source, $output_encoding = 'ISO-8859-1',
95
+                        $input_encoding = null, $detect_encoding = true)
96 96
     {
97 97
         # if PHP xml isn't compiled in, die
98 98
         #
99 99
         if (!function_exists('xml_parser_create')) {
100
-            $this->error( "Failed to load PHP's XML Extension. " .
100
+            $this->error("Failed to load PHP's XML Extension. ".
101 101
                           "http://www.php.net/manual/en/ref.xml.php",
102
-                           E_USER_ERROR );
102
+                           E_USER_ERROR);
103 103
         }
104 104
 
105 105
         list($parser, $source) = $this->create_parser($source,
@@ -107,9 +107,9 @@  discard block
 block discarded – undo
107 107
 
108 108
 
109 109
         if (!is_resource($parser)) {
110
-            $this->error( "Failed to create an instance of PHP's XML parser. " .
110
+            $this->error("Failed to create an instance of PHP's XML parser. ".
111 111
                           "http://www.php.net/manual/en/ref.xml.php",
112
-                          E_USER_ERROR );
112
+                          E_USER_ERROR);
113 113
         }
114 114
 
115 115
 
@@ -118,57 +118,57 @@  discard block
 block discarded – undo
118 118
         # pass in parser, and a reference to this object
119 119
         # setup handlers
120 120
         #
121
-        xml_set_object( $this->parser, $this );
121
+        xml_set_object($this->parser, $this);
122 122
         xml_set_element_handler($this->parser,
123
-                'feed_start_element', 'feed_end_element' );
123
+                'feed_start_element', 'feed_end_element');
124 124
 
125
-        xml_set_character_data_handler( $this->parser, 'feed_cdata' );
125
+        xml_set_character_data_handler($this->parser, 'feed_cdata');
126 126
 
127
-        $status = xml_parse( $this->parser, $source );
127
+        $status = xml_parse($this->parser, $source);
128 128
 
129
-        if (! $status ) {
130
-            $errorcode = xml_get_error_code( $this->parser );
131
-            if ( $errorcode != XML_ERROR_NONE ) {
132
-                $xml_error = xml_error_string( $errorcode );
129
+        if (!$status) {
130
+            $errorcode = xml_get_error_code($this->parser);
131
+            if ($errorcode != XML_ERROR_NONE) {
132
+                $xml_error = xml_error_string($errorcode);
133 133
                 $error_line = xml_get_current_line_number($this->parser);
134 134
                 $error_col = xml_get_current_column_number($this->parser);
135 135
                 $errormsg = "$xml_error at line $error_line, column $error_col";
136 136
 
137
-                $this->error( $errormsg );
137
+                $this->error($errormsg);
138 138
             }
139 139
         }
140 140
 
141
-        xml_parser_free( $this->parser );
141
+        xml_parser_free($this->parser);
142 142
 
143 143
         $this->normalize();
144 144
     }
145 145
 
146
-    function feed_start_element($p, $element, &$attrs) {
146
+    function feed_start_element($p, $element, &$attrs){
147 147
         $el = $element = strtolower($element);
148 148
         $attrs = array_change_key_case($attrs, CASE_LOWER);
149 149
 
150 150
         // check for a namespace, and split if found
151 151
         $ns = false;
152
-        if ( strpos( $element, ':' ) ) {
153
-            list($ns, $el) = explode( ':', $element, 2);
152
+        if (strpos($element, ':')) {
153
+            list($ns, $el) = explode(':', $element, 2);
154 154
         }
155
-        if ( $ns and $ns != 'rdf' ) {
155
+        if ($ns and $ns != 'rdf') {
156 156
             $this->current_namespace = $ns;
157 157
         }
158 158
 
159 159
         # if feed type isn't set, then this is first element of feed
160 160
         # identify feed from root element
161 161
         #
162
-        if (!isset($this->feed_type) ) {
163
-            if ( $el == 'rdf' ) {
162
+        if (!isset($this->feed_type)) {
163
+            if ($el == 'rdf') {
164 164
                 $this->feed_type = RSS;
165 165
                 $this->feed_version = '1.0';
166 166
             }
167
-            elseif ( $el == 'rss' ) {
167
+            elseif ($el == 'rss') {
168 168
                 $this->feed_type = RSS;
169 169
                 $this->feed_version = $attrs['version'];
170 170
             }
171
-            elseif ( $el == 'feed' ) {
171
+            elseif ($el == 'feed') {
172 172
                 $this->feed_type = ATOM;
173 173
                 $this->feed_version = $attrs['version'];
174 174
                 $this->inchannel = true;
@@ -176,14 +176,14 @@  discard block
 block discarded – undo
176 176
             return;
177 177
         }
178 178
 
179
-        if ( $el == 'channel' )
179
+        if ($el == 'channel')
180 180
         {
181 181
             $this->inchannel = true;
182 182
         }
183
-        elseif ($el == 'item' or $el == 'entry' )
183
+        elseif ($el == 'item' or $el == 'entry')
184 184
         {
185 185
             $this->initem = true;
186
-            if ( isset($attrs['rdf:about']) ) {
186
+            if (isset($attrs['rdf:about'])) {
187 187
                 $this->current_item['about'] = $attrs['rdf:about'];
188 188
             }
189 189
         }
@@ -207,10 +207,10 @@  discard block
 block discarded – undo
207 207
         }
208 208
 
209 209
         # handle atom content constructs
210
-        elseif ( $this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) )
210
+        elseif ($this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS))
211 211
         {
212 212
             // avoid clashing w/ RSS mod_content
213
-            if ($el == 'content' ) {
213
+            if ($el == 'content') {
214 214
                 $el = 'atom_content';
215 215
             }
216 216
 
@@ -220,31 +220,31 @@  discard block
 block discarded – undo
220 220
         }
221 221
 
222 222
         // if inside an Atom content construct (e.g. content or summary) field treat tags as text
223
-        elseif ($this->feed_type == ATOM and $this->incontent )
223
+        elseif ($this->feed_type == ATOM and $this->incontent)
224 224
         {
225 225
             // if tags are inlined, then flatten
226 226
             $attrs_str = implode(' ',
227 227
                     array_map('map_attrs',
228 228
                     array_keys($attrs),
229
-                    array_values($attrs) ) );
229
+                    array_values($attrs)));
230 230
 
231
-            $this->append_content( "<$element $attrs_str>"  );
231
+            $this->append_content("<$element $attrs_str>");
232 232
 
233
-            array_unshift( $this->stack, $el );
233
+            array_unshift($this->stack, $el);
234 234
         }
235 235
 
236 236
         // Atom support many links per containging element.
237 237
         // Magpie treats link elements of type rel='alternate'
238 238
         // as being equivalent to RSS's simple link element.
239 239
         //
240
-        elseif ($this->feed_type == ATOM and $el == 'link' )
240
+        elseif ($this->feed_type == ATOM and $el == 'link')
241 241
         {
242
-            if ( isset($attrs['rel']) and $attrs['rel'] == 'alternate' )
242
+            if (isset($attrs['rel']) and $attrs['rel'] == 'alternate')
243 243
             {
244 244
                 $link_el = 'link';
245 245
             }
246 246
             else {
247
-                $link_el = 'link_' . $attrs['rel'];
247
+                $link_el = 'link_'.$attrs['rel'];
248 248
             }
249 249
 
250 250
             $this->append($link_el, $attrs['href']);
@@ -257,10 +257,10 @@  discard block
 block discarded – undo
257 257
 
258 258
 
259 259
 
260
-    function feed_cdata ($p, $text) {
260
+    function feed_cdata($p, $text){
261 261
         if ($this->feed_type == ATOM and $this->incontent)
262 262
         {
263
-            $this->append_content( $text );
263
+            $this->append_content($text);
264 264
         }
265 265
         else {
266 266
             $current_el = implode('_', array_reverse($this->stack));
@@ -268,35 +268,35 @@  discard block
 block discarded – undo
268 268
         }
269 269
     }
270 270
 
271
-    function feed_end_element ($p, $el) {
271
+    function feed_end_element($p, $el){
272 272
         $el = strtolower($el);
273 273
 
274
-        if ( $el == 'item' or $el == 'entry' )
274
+        if ($el == 'item' or $el == 'entry')
275 275
         {
276 276
             $this->items[] = $this->current_item;
277 277
             $this->current_item = array();
278 278
             $this->initem = false;
279 279
         }
280
-        elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'textinput' )
280
+        elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'textinput')
281 281
         {
282 282
             $this->intextinput = false;
283 283
         }
284
-        elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'image' )
284
+        elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'image')
285 285
         {
286 286
             $this->inimage = false;
287 287
         }
288
-        elseif ($this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) )
288
+        elseif ($this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS))
289 289
         {
290 290
             $this->incontent = false;
291 291
         }
292
-        elseif ($el == 'channel' or $el == 'feed' )
292
+        elseif ($el == 'channel' or $el == 'feed')
293 293
         {
294 294
             $this->inchannel = false;
295 295
         }
296
-        elseif ($this->feed_type == ATOM and $this->incontent  ) {
296
+        elseif ($this->feed_type == ATOM and $this->incontent) {
297 297
             // balance tags properly
298 298
             // note:  i don't think this is actually neccessary
299
-            if ( $this->stack[0] == $el )
299
+            if ($this->stack[0] == $el)
300 300
             {
301 301
                 $this->append_content("</$el>");
302 302
             }
@@ -304,91 +304,91 @@  discard block
 block discarded – undo
304 304
                 $this->append_content("<$el />");
305 305
             }
306 306
 
307
-            array_shift( $this->stack );
307
+            array_shift($this->stack);
308 308
         }
309 309
         else {
310
-            array_shift( $this->stack );
310
+            array_shift($this->stack);
311 311
         }
312 312
 
313 313
         $this->current_namespace = false;
314 314
     }
315 315
 
316
-    function concat (&$str1, $str2="") {
317
-        if (!isset($str1) ) {
318
-            $str1="";
316
+    function concat(&$str1, $str2 = ""){
317
+        if (!isset($str1)) {
318
+            $str1 = "";
319 319
         }
320 320
         $str1 .= $str2;
321 321
     }
322 322
 
323 323
 
324 324
 
325
-    function append_content($text) {
326
-        if ( $this->initem ) {
327
-            $this->concat( $this->current_item[ $this->incontent ], $text );
325
+    function append_content($text){
326
+        if ($this->initem) {
327
+            $this->concat($this->current_item[$this->incontent], $text);
328 328
         }
329
-        elseif ( $this->inchannel ) {
330
-            $this->concat( $this->channel[ $this->incontent ], $text );
329
+        elseif ($this->inchannel) {
330
+            $this->concat($this->channel[$this->incontent], $text);
331 331
         }
332 332
     }
333 333
 
334 334
     // smart append - field and namespace aware
335
-    function append($el, $text) {
335
+    function append($el, $text){
336 336
         if (!$el) {
337 337
             return;
338 338
         }
339
-        if ( $this->current_namespace )
339
+        if ($this->current_namespace)
340 340
         {
341
-            if ( $this->initem ) {
341
+            if ($this->initem) {
342 342
                 $this->concat(
343
-                    $this->current_item[ $this->current_namespace ][ $el ], $text);
343
+                    $this->current_item[$this->current_namespace][$el], $text);
344 344
             }
345 345
             elseif ($this->inchannel) {
346 346
                 $this->concat(
347
-                    $this->channel[ $this->current_namespace][ $el ], $text );
347
+                    $this->channel[$this->current_namespace][$el], $text );
348 348
             }
349 349
             elseif ($this->intextinput) {
350 350
                 $this->concat(
351
-                    $this->textinput[ $this->current_namespace][ $el ], $text );
351
+                    $this->textinput[$this->current_namespace][$el], $text );
352 352
             }
353 353
             elseif ($this->inimage) {
354 354
                 $this->concat(
355
-                    $this->image[ $this->current_namespace ][ $el ], $text );
355
+                    $this->image[$this->current_namespace][$el], $text );
356 356
             }
357 357
         }
358 358
         else {
359
-            if ( $this->initem ) {
359
+            if ($this->initem) {
360 360
                 $this->concat(
361
-                    $this->current_item[ $el ], $text);
361
+                    $this->current_item[$el], $text);
362 362
             }
363 363
             elseif ($this->intextinput) {
364 364
                 $this->concat(
365
-                    $this->textinput[ $el ], $text );
365
+                    $this->textinput[$el], $text );
366 366
             }
367 367
             elseif ($this->inimage) {
368 368
                 $this->concat(
369
-                    $this->image[ $el ], $text );
369
+                    $this->image[$el], $text );
370 370
             }
371 371
             elseif ($this->inchannel) {
372 372
                 $this->concat(
373
-                    $this->channel[ $el ], $text );
373
+                    $this->channel[$el], $text );
374 374
             }
375 375
 
376 376
         }
377 377
     }
378 378
 
379
-    function normalize () {
379
+    function normalize(){
380 380
         // if atom populate rss fields
381
-        if ( $this->is_atom() ) {
381
+        if ($this->is_atom()) {
382 382
             $this->channel['description'] = $this->channel['tagline'];
383
-            for ( $i = 0; $i < count($this->items); $i++) {
383
+            for ($i = 0; $i < count($this->items); $i++) {
384 384
                 $item = $this->items[$i];
385
-                if ( isset($item['summary']) )
385
+                if (isset($item['summary']))
386 386
                     $item['description'] = $item['summary'];
387
-                if ( isset($item['atom_content']))
387
+                if (isset($item['atom_content']))
388 388
                     $item['content']['encoded'] = $item['atom_content'];
389 389
 
390
-                $atom_date = (isset($item['issued']) ) ? $item['issued'] : $item['modified'];
391
-                if ( $atom_date ) {
390
+                $atom_date = (isset($item['issued'])) ? $item['issued'] : $item['modified'];
391
+                if ($atom_date) {
392 392
                     $epoch = @parse_w3cdtf($atom_date);
393 393
                     if ($epoch and $epoch > 0) {
394 394
                         $item['date_timestamp'] = $epoch;
@@ -398,22 +398,22 @@  discard block
 block discarded – undo
398 398
                 $this->items[$i] = $item;
399 399
             }
400 400
         }
401
-        elseif ( $this->is_rss() ) {
401
+        elseif ($this->is_rss()) {
402 402
             $this->channel['tagline'] = $this->channel['description'];
403
-            for ( $i = 0; $i < count($this->items); $i++) {
403
+            for ($i = 0; $i < count($this->items); $i++) {
404 404
                 $item = $this->items[$i];
405
-                if ( isset($item['description']))
405
+                if (isset($item['description']))
406 406
                     $item['summary'] = $item['description'];
407
-                if ( isset($item['content']['encoded'] ) )
407
+                if (isset($item['content']['encoded']))
408 408
                     $item['atom_content'] = $item['content']['encoded'];
409 409
 
410
-                if ( $this->is_rss() == '1.0' and isset($item['dc']['date']) ) {
410
+                if ($this->is_rss() == '1.0' and isset($item['dc']['date'])) {
411 411
                     $epoch = @parse_w3cdtf($item['dc']['date']);
412 412
                     if ($epoch and $epoch > 0) {
413 413
                         $item['date_timestamp'] = $epoch;
414 414
                     }
415 415
                 }
416
-                elseif ( isset($item['pubdate']) ) {
416
+                elseif (isset($item['pubdate'])) {
417 417
                     $epoch = @strtotime($item['pubdate']);
418 418
                     if ($epoch > 0) {
419 419
                         $item['date_timestamp'] = $epoch;
@@ -426,8 +426,8 @@  discard block
 block discarded – undo
426 426
     }
427 427
 
428 428
 
429
-    function is_rss () {
430
-        if ( $this->feed_type == RSS ) {
429
+    function is_rss(){
430
+        if ($this->feed_type == RSS) {
431 431
             return $this->feed_version;
432 432
         }
433 433
         else {
@@ -435,8 +435,8 @@  discard block
 block discarded – undo
435 435
         }
436 436
     }
437 437
 
438
-    function is_atom() {
439
-        if ( $this->feed_type == ATOM ) {
438
+    function is_atom(){
439
+        if ($this->feed_type == ATOM) {
440 440
             return $this->feed_version;
441 441
         }
442 442
         else {
@@ -448,8 +448,8 @@  discard block
 block discarded – undo
448 448
     * return XML parser, and possibly re-encoded source
449 449
     *
450 450
     */
451
-    function create_parser($source, $out_enc, $in_enc, $detect) {
452
-        if ( substr(phpversion(),0,1) == 5) {
451
+    function create_parser($source, $out_enc, $in_enc, $detect){
452
+        if (substr(phpversion(), 0, 1) == 5) {
453 453
             $parser = $this->php5_create_parser($in_enc, $detect);
454 454
         }
455 455
         else {
@@ -472,9 +472,9 @@  discard block
 block discarded – undo
472 472
     * All hail libxml2!
473 473
     *
474 474
     */
475
-    function php5_create_parser($in_enc, $detect) {
475
+    function php5_create_parser($in_enc, $detect){
476 476
         // by default php5 does a fine job of detecting input encodings
477
-        if(!$detect && $in_enc) {
477
+        if (!$detect && $in_enc) {
478 478
             return xml_parser_create($in_enc);
479 479
         }
480 480
         else {
@@ -497,8 +497,8 @@  discard block
 block discarded – undo
497 497
     * @see http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss
498 498
     *
499 499
     */
500
-    function php4_create_parser($source, $in_enc, $detect) {
501
-        if ( !$detect ) {
500
+    function php4_create_parser($source, $in_enc, $detect){
501
+        if (!$detect) {
502 502
             return array(xml_parser_create($in_enc), $source);
503 503
         }
504 504
 
@@ -522,8 +522,8 @@  discard block
 block discarded – undo
522 522
         // cast the XML to a known encoding
523 523
         // @see http://php.net/iconv
524 524
 
525
-        if (function_exists('iconv'))  {
526
-            $encoded_source = iconv($in_enc,'UTF-8', $source);
525
+        if (function_exists('iconv')) {
526
+            $encoded_source = iconv($in_enc, 'UTF-8', $source);
527 527
             if ($encoded_source) {
528 528
                 return array(xml_parser_create('UTF-8'), $encoded_source);
529 529
             }
@@ -531,24 +531,24 @@  discard block
 block discarded – undo
531 531
 
532 532
         // iconv didn't work, try mb_convert_encoding
533 533
         // @see http://php.net/mbstring
534
-        if(function_exists('mb_convert_encoding')) {
535
-            $encoded_source = mb_convert_encoding($source, 'UTF-8', $in_enc );
534
+        if (function_exists('mb_convert_encoding')) {
535
+            $encoded_source = mb_convert_encoding($source, 'UTF-8', $in_enc);
536 536
             if ($encoded_source) {
537 537
                 return array(xml_parser_create('UTF-8'), $encoded_source);
538 538
             }
539 539
         }
540 540
 
541 541
         // else
542
-        $this->error("Feed is in an unsupported character encoding. ($in_enc) " .
542
+        $this->error("Feed is in an unsupported character encoding. ($in_enc) ".
543 543
                      "You may see strange artifacts, and mangled characters.",
544 544
                      E_USER_NOTICE);
545 545
 
546 546
         return array(xml_parser_create(), $source);
547 547
     }
548 548
 
549
-    function known_encoding($enc) {
549
+    function known_encoding($enc){
550 550
         $enc = strtoupper($enc);
551
-        if ( in_array($enc, $this->_KNOWN_ENCODINGS) ) {
551
+        if (in_array($enc, $this->_KNOWN_ENCODINGS)) {
552 552
             return $enc;
553 553
         }
554 554
         else {
@@ -556,20 +556,20 @@  discard block
 block discarded – undo
556 556
         }
557 557
     }
558 558
 
559
-    function error ($errormsg, $lvl=E_USER_WARNING) {
559
+    function error($errormsg, $lvl = E_USER_WARNING){
560 560
         // append PHP's error message if track_errors enabled
561
-        if ( isset($php_errormsg) ) {
561
+        if (isset($php_errormsg)) {
562 562
             $errormsg .= " ($php_errormsg)";
563 563
         }
564
-        if ( MAGPIE_DEBUG ) {
565
-            trigger_error( $errormsg, $lvl);
564
+        if (MAGPIE_DEBUG) {
565
+            trigger_error($errormsg, $lvl);
566 566
         }
567 567
         else {
568
-            error_log( $errormsg, 0);
568
+            error_log($errormsg, 0);
569 569
         }
570 570
 
571
-        $notices = E_USER_NOTICE|E_NOTICE;
572
-        if ( $lvl&$notices ) {
571
+        $notices = E_USER_NOTICE | E_NOTICE;
572
+        if ($lvl & $notices) {
573 573
             $this->WARNING = $errormsg;
574 574
         } else {
575 575
             $this->ERROR = $errormsg;
@@ -579,7 +579,7 @@  discard block
 block discarded – undo
579 579
 
580 580
 } // end class RSS
581 581
 
582
-function map_attrs($k, $v) {
582
+function map_attrs($k, $v){
583 583
     return "$k=\"$v\"";
584 584
 }
585 585
 
@@ -591,19 +591,19 @@  discard block
 block discarded – undo
591 591
 	define('CASE_LOWER', 0);
592 592
 
593 593
 
594
-	function array_change_key_case($array, $case=CASE_LOWER) {
594
+	function array_change_key_case($array, $case = CASE_LOWER){
595 595
         $output = array();
596
-        switch($case){
596
+        switch ($case) {
597 597
            case CASE_LOWER:
598
-               $cmd='strtolower';
598
+               $cmd = 'strtolower';
599 599
                break;
600 600
            case CASE_UPPER:
601
-               $cmd='strtoupper';
601
+               $cmd = 'strtoupper';
602 602
                break;
603 603
            default:
604 604
                $cmd = '';
605 605
         }
606
-        foreach($array as $key=>$value) {
606
+        foreach ($array as $key=>$value) {
607 607
             $output[empty($cmd) ? $key : $cmd($key)] = $value;
608 608
         }
609 609
         return $output;
Please login to merge, or discard this patch.
Braces   +89 added lines, -115 removed lines patch added patch discarded remove patch
@@ -31,7 +31,8 @@  discard block
 block discarded – undo
31 31
 * see: rss_fetch.inc for a simpler interface with integrated caching support
32 32
 *
33 33
 */
34
-class MagpieRSS {
34
+class MagpieRSS
35
+{
35 36
     var $parser;
36 37
 
37 38
     var $current_item   = array();  // item currently being parsed
@@ -143,7 +144,8 @@  discard block
 block discarded – undo
143 144
         $this->normalize();
144 145
     }
145 146
 
146
-    function feed_start_element($p, $element, &$attrs) {
147
+    function feed_start_element($p, $element, &$attrs)
148
+    {
147 149
         $el = $element = strtolower($element);
148 150
         $attrs = array_change_key_case($attrs, CASE_LOWER);
149 151
 
@@ -163,12 +165,10 @@  discard block
 block discarded – undo
163 165
             if ( $el == 'rdf' ) {
164 166
                 $this->feed_type = RSS;
165 167
                 $this->feed_version = '1.0';
166
-            }
167
-            elseif ( $el == 'rss' ) {
168
+            } elseif ( $el == 'rss' ) {
168 169
                 $this->feed_type = RSS;
169 170
                 $this->feed_version = $attrs['version'];
170
-            }
171
-            elseif ( $el == 'feed' ) {
171
+            } elseif ( $el == 'feed' ) {
172 172
                 $this->feed_type = ATOM;
173 173
                 $this->feed_version = $attrs['version'];
174 174
                 $this->inchannel = true;
@@ -176,12 +176,9 @@  discard block
 block discarded – undo
176 176
             return;
177 177
         }
178 178
 
179
-        if ( $el == 'channel' )
180
-        {
179
+        if ( $el == 'channel' ) {
181 180
             $this->inchannel = true;
182
-        }
183
-        elseif ($el == 'item' or $el == 'entry' )
184
-        {
181
+        } elseif ($el == 'item' or $el == 'entry' ) {
185 182
             $this->initem = true;
186 183
             if ( isset($attrs['rdf:about']) ) {
187 184
                 $this->current_item['about'] = $attrs['rdf:about'];
@@ -193,22 +190,17 @@  discard block
 block discarded – undo
193 190
         elseif (
194 191
             $this->feed_type == RSS and
195 192
             $this->current_namespace == '' and
196
-            $el == 'textinput' )
197
-        {
193
+            $el == 'textinput' ) {
198 194
             $this->intextinput = true;
199
-        }
200
-
201
-        elseif (
195
+        } elseif (
202 196
             $this->feed_type == RSS and
203 197
             $this->current_namespace == '' and
204
-            $el == 'image' )
205
-        {
198
+            $el == 'image' ) {
206 199
             $this->inimage = true;
207 200
         }
208 201
 
209 202
         # handle atom content constructs
210
-        elseif ( $this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) )
211
-        {
203
+        elseif ( $this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) ) {
212 204
             // avoid clashing w/ RSS mod_content
213 205
             if ($el == 'content' ) {
214 206
                 $el = 'atom_content';
@@ -220,8 +212,7 @@  discard block
 block discarded – undo
220 212
         }
221 213
 
222 214
         // if inside an Atom content construct (e.g. content or summary) field treat tags as text
223
-        elseif ($this->feed_type == ATOM and $this->incontent )
224
-        {
215
+        elseif ($this->feed_type == ATOM and $this->incontent ) {
225 216
             // if tags are inlined, then flatten
226 217
             $attrs_str = implode(' ',
227 218
                     array_map('map_attrs',
@@ -237,13 +228,10 @@  discard block
 block discarded – undo
237 228
         // Magpie treats link elements of type rel='alternate'
238 229
         // as being equivalent to RSS's simple link element.
239 230
         //
240
-        elseif ($this->feed_type == ATOM and $el == 'link' )
241
-        {
242
-            if ( isset($attrs['rel']) and $attrs['rel'] == 'alternate' )
243
-            {
231
+        elseif ($this->feed_type == ATOM and $el == 'link' ) {
232
+            if ( isset($attrs['rel']) and $attrs['rel'] == 'alternate' ) {
244 233
                 $link_el = 'link';
245
-            }
246
-            else {
234
+            } else {
247 235
                 $link_el = 'link_' . $attrs['rel'];
248 236
             }
249 237
 
@@ -257,63 +245,51 @@  discard block
 block discarded – undo
257 245
 
258 246
 
259 247
 
260
-    function feed_cdata ($p, $text) {
261
-        if ($this->feed_type == ATOM and $this->incontent)
262
-        {
248
+    function feed_cdata ($p, $text)
249
+    {
250
+        if ($this->feed_type == ATOM and $this->incontent) {
263 251
             $this->append_content( $text );
264
-        }
265
-        else {
252
+        } else {
266 253
             $current_el = implode('_', array_reverse($this->stack));
267 254
             $this->append($current_el, $text);
268 255
         }
269 256
     }
270 257
 
271
-    function feed_end_element ($p, $el) {
258
+    function feed_end_element ($p, $el)
259
+    {
272 260
         $el = strtolower($el);
273 261
 
274
-        if ( $el == 'item' or $el == 'entry' )
275
-        {
262
+        if ( $el == 'item' or $el == 'entry' ) {
276 263
             $this->items[] = $this->current_item;
277 264
             $this->current_item = array();
278 265
             $this->initem = false;
279
-        }
280
-        elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'textinput' )
281
-        {
266
+        } elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'textinput' ) {
282 267
             $this->intextinput = false;
283
-        }
284
-        elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'image' )
285
-        {
268
+        } elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'image' ) {
286 269
             $this->inimage = false;
287
-        }
288
-        elseif ($this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) )
289
-        {
270
+        } elseif ($this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) ) {
290 271
             $this->incontent = false;
291
-        }
292
-        elseif ($el == 'channel' or $el == 'feed' )
293
-        {
272
+        } elseif ($el == 'channel' or $el == 'feed' ) {
294 273
             $this->inchannel = false;
295
-        }
296
-        elseif ($this->feed_type == ATOM and $this->incontent  ) {
274
+        } elseif ($this->feed_type == ATOM and $this->incontent  ) {
297 275
             // balance tags properly
298 276
             // note:  i don't think this is actually neccessary
299
-            if ( $this->stack[0] == $el )
300
-            {
277
+            if ( $this->stack[0] == $el ) {
301 278
                 $this->append_content("</$el>");
302
-            }
303
-            else {
279
+            } else {
304 280
                 $this->append_content("<$el />");
305 281
             }
306 282
 
307 283
             array_shift( $this->stack );
308
-        }
309
-        else {
284
+        } else {
310 285
             array_shift( $this->stack );
311 286
         }
312 287
 
313 288
         $this->current_namespace = false;
314 289
     }
315 290
 
316
-    function concat (&$str1, $str2="") {
291
+    function concat (&$str1, $str2="")
292
+    {
317 293
         if (!isset($str1) ) {
318 294
             $str1="";
319 295
         }
@@ -322,53 +298,46 @@  discard block
 block discarded – undo
322 298
 
323 299
 
324 300
 
325
-    function append_content($text) {
301
+    function append_content($text)
302
+    {
326 303
         if ( $this->initem ) {
327 304
             $this->concat( $this->current_item[ $this->incontent ], $text );
328
-        }
329
-        elseif ( $this->inchannel ) {
305
+        } elseif ( $this->inchannel ) {
330 306
             $this->concat( $this->channel[ $this->incontent ], $text );
331 307
         }
332 308
     }
333 309
 
334 310
     // smart append - field and namespace aware
335
-    function append($el, $text) {
311
+    function append($el, $text)
312
+    {
336 313
         if (!$el) {
337 314
             return;
338 315
         }
339
-        if ( $this->current_namespace )
340
-        {
316
+        if ( $this->current_namespace ) {
341 317
             if ( $this->initem ) {
342 318
                 $this->concat(
343 319
                     $this->current_item[ $this->current_namespace ][ $el ], $text);
344
-            }
345
-            elseif ($this->inchannel) {
320
+            } elseif ($this->inchannel) {
346 321
                 $this->concat(
347 322
                     $this->channel[ $this->current_namespace][ $el ], $text );
348
-            }
349
-            elseif ($this->intextinput) {
323
+            } elseif ($this->intextinput) {
350 324
                 $this->concat(
351 325
                     $this->textinput[ $this->current_namespace][ $el ], $text );
352
-            }
353
-            elseif ($this->inimage) {
326
+            } elseif ($this->inimage) {
354 327
                 $this->concat(
355 328
                     $this->image[ $this->current_namespace ][ $el ], $text );
356 329
             }
357
-        }
358
-        else {
330
+        } else {
359 331
             if ( $this->initem ) {
360 332
                 $this->concat(
361 333
                     $this->current_item[ $el ], $text);
362
-            }
363
-            elseif ($this->intextinput) {
334
+            } elseif ($this->intextinput) {
364 335
                 $this->concat(
365 336
                     $this->textinput[ $el ], $text );
366
-            }
367
-            elseif ($this->inimage) {
337
+            } elseif ($this->inimage) {
368 338
                 $this->concat(
369 339
                     $this->image[ $el ], $text );
370
-            }
371
-            elseif ($this->inchannel) {
340
+            } elseif ($this->inchannel) {
372 341
                 $this->concat(
373 342
                     $this->channel[ $el ], $text );
374 343
             }
@@ -376,16 +345,19 @@  discard block
 block discarded – undo
376 345
         }
377 346
     }
378 347
 
379
-    function normalize () {
348
+    function normalize ()
349
+    {
380 350
         // if atom populate rss fields
381 351
         if ( $this->is_atom() ) {
382 352
             $this->channel['description'] = $this->channel['tagline'];
383 353
             for ( $i = 0; $i < count($this->items); $i++) {
384 354
                 $item = $this->items[$i];
385
-                if ( isset($item['summary']) )
386
-                    $item['description'] = $item['summary'];
387
-                if ( isset($item['atom_content']))
388
-                    $item['content']['encoded'] = $item['atom_content'];
355
+                if ( isset($item['summary']) ) {
356
+                                    $item['description'] = $item['summary'];
357
+                }
358
+                if ( isset($item['atom_content'])) {
359
+                                    $item['content']['encoded'] = $item['atom_content'];
360
+                }
389 361
 
390 362
                 $atom_date = (isset($item['issued']) ) ? $item['issued'] : $item['modified'];
391 363
                 if ( $atom_date ) {
@@ -397,23 +369,23 @@  discard block
 block discarded – undo
397 369
 
398 370
                 $this->items[$i] = $item;
399 371
             }
400
-        }
401
-        elseif ( $this->is_rss() ) {
372
+        } elseif ( $this->is_rss() ) {
402 373
             $this->channel['tagline'] = $this->channel['description'];
403 374
             for ( $i = 0; $i < count($this->items); $i++) {
404 375
                 $item = $this->items[$i];
405
-                if ( isset($item['description']))
406
-                    $item['summary'] = $item['description'];
407
-                if ( isset($item['content']['encoded'] ) )
408
-                    $item['atom_content'] = $item['content']['encoded'];
376
+                if ( isset($item['description'])) {
377
+                                    $item['summary'] = $item['description'];
378
+                }
379
+                if ( isset($item['content']['encoded'] ) ) {
380
+                                    $item['atom_content'] = $item['content']['encoded'];
381
+                }
409 382
 
410 383
                 if ( $this->is_rss() == '1.0' and isset($item['dc']['date']) ) {
411 384
                     $epoch = @parse_w3cdtf($item['dc']['date']);
412 385
                     if ($epoch and $epoch > 0) {
413 386
                         $item['date_timestamp'] = $epoch;
414 387
                     }
415
-                }
416
-                elseif ( isset($item['pubdate']) ) {
388
+                } elseif ( isset($item['pubdate']) ) {
417 389
                     $epoch = @strtotime($item['pubdate']);
418 390
                     if ($epoch > 0) {
419 391
                         $item['date_timestamp'] = $epoch;
@@ -426,20 +398,20 @@  discard block
 block discarded – undo
426 398
     }
427 399
 
428 400
 
429
-    function is_rss () {
401
+    function is_rss ()
402
+    {
430 403
         if ( $this->feed_type == RSS ) {
431 404
             return $this->feed_version;
432
-        }
433
-        else {
405
+        } else {
434 406
             return false;
435 407
         }
436 408
     }
437 409
 
438
-    function is_atom() {
410
+    function is_atom()
411
+    {
439 412
         if ( $this->feed_type == ATOM ) {
440 413
             return $this->feed_version;
441
-        }
442
-        else {
414
+        } else {
443 415
             return false;
444 416
         }
445 417
     }
@@ -448,11 +420,11 @@  discard block
 block discarded – undo
448 420
     * return XML parser, and possibly re-encoded source
449 421
     *
450 422
     */
451
-    function create_parser($source, $out_enc, $in_enc, $detect) {
423
+    function create_parser($source, $out_enc, $in_enc, $detect)
424
+    {
452 425
         if ( substr(phpversion(),0,1) == 5) {
453 426
             $parser = $this->php5_create_parser($in_enc, $detect);
454
-        }
455
-        else {
427
+        } else {
456 428
             list($parser, $source) = $this->php4_create_parser($source, $in_enc, $detect);
457 429
         }
458 430
         if ($out_enc) {
@@ -472,12 +444,12 @@  discard block
 block discarded – undo
472 444
     * All hail libxml2!
473 445
     *
474 446
     */
475
-    function php5_create_parser($in_enc, $detect) {
447
+    function php5_create_parser($in_enc, $detect)
448
+    {
476 449
         // by default php5 does a fine job of detecting input encodings
477 450
         if(!$detect && $in_enc) {
478 451
             return xml_parser_create($in_enc);
479
-        }
480
-        else {
452
+        } else {
481 453
             return xml_parser_create('');
482 454
         }
483 455
     }
@@ -497,7 +469,8 @@  discard block
 block discarded – undo
497 469
     * @see http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss
498 470
     *
499 471
     */
500
-    function php4_create_parser($source, $in_enc, $detect) {
472
+    function php4_create_parser($source, $in_enc, $detect)
473
+    {
501 474
         if ( !$detect ) {
502 475
             return array(xml_parser_create($in_enc), $source);
503 476
         }
@@ -506,8 +479,7 @@  discard block
 block discarded – undo
506 479
             if (preg_match('/<?xml.*encoding=[\'"](.*?)[\'"].*?>/m', $source, $m)) {
507 480
                 $in_enc = strtoupper($m[1]);
508 481
                 $this->source_encoding = $in_enc;
509
-            }
510
-            else {
482
+            } else {
511 483
                 $in_enc = 'UTF-8';
512 484
             }
513 485
         }
@@ -522,7 +494,7 @@  discard block
 block discarded – undo
522 494
         // cast the XML to a known encoding
523 495
         // @see http://php.net/iconv
524 496
 
525
-        if (function_exists('iconv'))  {
497
+        if (function_exists('iconv')) {
526 498
             $encoded_source = iconv($in_enc,'UTF-8', $source);
527 499
             if ($encoded_source) {
528 500
                 return array(xml_parser_create('UTF-8'), $encoded_source);
@@ -546,25 +518,25 @@  discard block
 block discarded – undo
546 518
         return array(xml_parser_create(), $source);
547 519
     }
548 520
 
549
-    function known_encoding($enc) {
521
+    function known_encoding($enc)
522
+    {
550 523
         $enc = strtoupper($enc);
551 524
         if ( in_array($enc, $this->_KNOWN_ENCODINGS) ) {
552 525
             return $enc;
553
-        }
554
-        else {
526
+        } else {
555 527
             return false;
556 528
         }
557 529
     }
558 530
 
559
-    function error ($errormsg, $lvl=E_USER_WARNING) {
531
+    function error ($errormsg, $lvl=E_USER_WARNING)
532
+    {
560 533
         // append PHP's error message if track_errors enabled
561 534
         if ( isset($php_errormsg) ) {
562 535
             $errormsg .= " ($php_errormsg)";
563 536
         }
564 537
         if ( MAGPIE_DEBUG ) {
565 538
             trigger_error( $errormsg, $lvl);
566
-        }
567
-        else {
539
+        } else {
568 540
             error_log( $errormsg, 0);
569 541
         }
570 542
 
@@ -579,7 +551,8 @@  discard block
 block discarded – undo
579 551
 
580 552
 } // end class RSS
581 553
 
582
-function map_attrs($k, $v) {
554
+function map_attrs($k, $v)
555
+{
583 556
     return "$k=\"$v\"";
584 557
 }
585 558
 
@@ -591,9 +564,10 @@  discard block
 block discarded – undo
591 564
 	define('CASE_LOWER', 0);
592 565
 
593 566
 
594
-	function array_change_key_case($array, $case=CASE_LOWER) {
567
+	function array_change_key_case($array, $case=CASE_LOWER)
568
+	{
595 569
         $output = array();
596
-        switch($case){
570
+        switch($case) {
597 571
            case CASE_LOWER:
598 572
                $cmd='strtolower';
599 573
                break;
Please login to merge, or discard this patch.