@@ -2,26 +2,26 @@ |
||
2 | 2 | // todo file_put_contents(), strftime(), mb_*() |
3 | 3 | class PHPCOMPAT |
4 | 4 | { |
5 | - function __construct() |
|
6 | - { |
|
7 | - } |
|
5 | + function __construct() |
|
6 | + { |
|
7 | + } |
|
8 | 8 | |
9 | - function htmlspecialchars($str='', $flags = ENT_COMPAT, $encode='') |
|
10 | - { |
|
11 | - global $modx; |
|
9 | + function htmlspecialchars($str='', $flags = ENT_COMPAT, $encode='') |
|
10 | + { |
|
11 | + global $modx; |
|
12 | 12 | |
13 | - if($str=='') return ''; |
|
13 | + if($str=='') return ''; |
|
14 | 14 | |
15 | - if($encode=='') $encode = $modx->config['modx_charset']; |
|
15 | + if($encode=='') $encode = $modx->config['modx_charset']; |
|
16 | 16 | |
17 | - $ent_str = htmlspecialchars($str, $flags, $encode); |
|
17 | + $ent_str = htmlspecialchars($str, $flags, $encode); |
|
18 | 18 | |
19 | - if(!empty($str) && empty($ent_str)) |
|
20 | - { |
|
21 | - $detect_order = implode(',', mb_detect_order()); |
|
22 | - $ent_str = mb_convert_encoding($str, $encode, $detect_order); |
|
23 | - } |
|
19 | + if(!empty($str) && empty($ent_str)) |
|
20 | + { |
|
21 | + $detect_order = implode(',', mb_detect_order()); |
|
22 | + $ent_str = mb_convert_encoding($str, $encode, $detect_order); |
|
23 | + } |
|
24 | 24 | |
25 | - return $ent_str; |
|
26 | - } |
|
25 | + return $ent_str; |
|
26 | + } |
|
27 | 27 | } |
@@ -6,17 +6,17 @@ |
||
6 | 6 | { |
7 | 7 | } |
8 | 8 | |
9 | - function htmlspecialchars($str='', $flags = ENT_COMPAT, $encode='') |
|
9 | + function htmlspecialchars($str = '', $flags = ENT_COMPAT, $encode = '') |
|
10 | 10 | { |
11 | 11 | global $modx; |
12 | 12 | |
13 | - if($str=='') return ''; |
|
13 | + if ($str == '') return ''; |
|
14 | 14 | |
15 | - if($encode=='') $encode = $modx->config['modx_charset']; |
|
15 | + if ($encode == '') $encode = $modx->config['modx_charset']; |
|
16 | 16 | |
17 | 17 | $ent_str = htmlspecialchars($str, $flags, $encode); |
18 | 18 | |
19 | - if(!empty($str) && empty($ent_str)) |
|
19 | + if (!empty($str) && empty($ent_str)) |
|
20 | 20 | { |
21 | 21 | $detect_order = implode(',', mb_detect_order()); |
22 | 22 | $ent_str = mb_convert_encoding($str, $encode, $detect_order); |
@@ -10,14 +10,17 @@ |
||
10 | 10 | { |
11 | 11 | global $modx; |
12 | 12 | |
13 | - if($str=='') return ''; |
|
13 | + if($str=='') { |
|
14 | + return ''; |
|
15 | + } |
|
14 | 16 | |
15 | - if($encode=='') $encode = $modx->config['modx_charset']; |
|
17 | + if($encode=='') { |
|
18 | + $encode = $modx->config['modx_charset']; |
|
19 | + } |
|
16 | 20 | |
17 | 21 | $ent_str = htmlspecialchars($str, $flags, $encode); |
18 | 22 | |
19 | - if(!empty($str) && empty($ent_str)) |
|
20 | - { |
|
23 | + if(!empty($str) && empty($ent_str)) { |
|
21 | 24 | $detect_order = implode(',', mb_detect_order()); |
22 | 25 | $ent_str = mb_convert_encoding($str, $encode, $detect_order); |
23 | 26 | } |
@@ -6,6 +6,9 @@ |
||
6 | 6 | { |
7 | 7 | } |
8 | 8 | |
9 | + /** |
|
10 | + * @param integer $flags |
|
11 | + */ |
|
9 | 12 | function htmlspecialchars($str='', $flags = ENT_COMPAT, $encode='') |
10 | 13 | { |
11 | 14 | global $modx; |
@@ -598,7 +598,7 @@ discard block |
||
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 |
||
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); |
@@ -30,6 +30,11 @@ discard block |
||
30 | 30 | $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'; |
31 | 31 | } |
32 | 32 | |
33 | + /** |
|
34 | + * @param string $key |
|
35 | + * @param string $value |
|
36 | + * @param string|false $modifiers |
|
37 | + */ |
|
33 | 38 | public function phxFilter($key,$value,$modifiers) |
34 | 39 | { |
35 | 40 | global $modx; |
@@ -51,6 +56,10 @@ discard block |
||
51 | 56 | return $value; |
52 | 57 | } |
53 | 58 | |
59 | + /** |
|
60 | + * @param string $mode |
|
61 | + * @param string $modifiers |
|
62 | + */ |
|
54 | 63 | public function _getDelim($mode,$modifiers) { |
55 | 64 | $c = substr($modifiers,0,1); |
56 | 65 | if(!in_array($c, array('"', "'", '`')) ) return false; |
@@ -62,6 +71,11 @@ discard block |
||
62 | 71 | return $c; |
63 | 72 | } |
64 | 73 | |
74 | + /** |
|
75 | + * @param string $mode |
|
76 | + * @param false|string $delim |
|
77 | + * @param string $modifiers |
|
78 | + */ |
|
65 | 79 | public function _getOpt($mode,$delim,$modifiers) { |
66 | 80 | if($delim) { |
67 | 81 | if($mode=='(') return substr($modifiers,1,strpos($modifiers, $delim . ')' )-1); |
@@ -80,6 +94,14 @@ discard block |
||
80 | 94 | return $opt; |
81 | 95 | } |
82 | 96 | } |
97 | + |
|
98 | + /** |
|
99 | + * @param string $mode |
|
100 | + * @param false|string $delim |
|
101 | + * @param string $modifiers |
|
102 | + * |
|
103 | + * @return string |
|
104 | + */ |
|
83 | 105 | public function _getRemainModifiers($mode,$delim,$modifiers) { |
84 | 106 | if($delim) { |
85 | 107 | if($mode=='(') |
@@ -107,6 +129,9 @@ discard block |
||
107 | 129 | return substr($string,strpos($string, $delim)+$len); |
108 | 130 | } |
109 | 131 | |
132 | + /** |
|
133 | + * @param string $modifiers |
|
134 | + */ |
|
110 | 135 | public function splitEachModifiers($modifiers) { |
111 | 136 | global $modx; |
112 | 137 | |
@@ -242,6 +267,9 @@ discard block |
||
242 | 267 | else return true; |
243 | 268 | } |
244 | 269 | |
270 | + /** |
|
271 | + * @param string $cmd |
|
272 | + */ |
|
245 | 273 | public function getValueFromPreset($key, $value, $cmd, $opt) |
246 | 274 | { |
247 | 275 | global $modx; |
@@ -927,6 +955,9 @@ discard block |
||
927 | 955 | return $value; |
928 | 956 | } |
929 | 957 | |
958 | + /** |
|
959 | + * @param string $cmd |
|
960 | + */ |
|
930 | 961 | public function includeMdfFile($cmd) { |
931 | 962 | global $modx; |
932 | 963 | $key = $this->key; |
@@ -1082,6 +1113,10 @@ discard block |
||
1082 | 1113 | } |
1083 | 1114 | |
1084 | 1115 | // Sets a placeholder variable which can only be access by Modifiers |
1116 | + |
|
1117 | + /** |
|
1118 | + * @param string $value |
|
1119 | + */ |
|
1085 | 1120 | public function setModifiersVariable($key, $value) { |
1086 | 1121 | if ($key != 'phx' && $key != 'dummy') $this->placeholders[$key] = $value; |
1087 | 1122 | } |
@@ -1,8 +1,8 @@ discard block |
||
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 | public $placeholders = array(); |
8 | 8 | public $vars = array(); |
@@ -30,14 +30,14 @@ discard block |
||
30 | 30 | $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'; |
31 | 31 | } |
32 | 32 | |
33 | - public function phxFilter($key,$value,$modifiers) |
|
33 | + public function phxFilter($key, $value, $modifiers) |
|
34 | 34 | { |
35 | 35 | global $modx; |
36 | - if(substr($modifiers,0,3)!=='id(') $value = $this->parseDocumentSource($value); |
|
36 | + if (substr($modifiers, 0, 3) !== 'id(') $value = $this->parseDocumentSource($value); |
|
37 | 37 | $this->srcValue = $value; |
38 | 38 | $modifiers = trim($modifiers); |
39 | - $modifiers = ':'.trim($modifiers,':'); |
|
40 | - $modifiers = str_replace(array("\r\n","\r"), "\n", $modifiers); |
|
39 | + $modifiers = ':'.trim($modifiers, ':'); |
|
40 | + $modifiers = str_replace(array("\r\n", "\r"), "\n", $modifiers); |
|
41 | 41 | $modifiers = $this->splitEachModifiers($modifiers); |
42 | 42 | |
43 | 43 | $this->placeholders = array(); |
@@ -45,118 +45,118 @@ discard block |
||
45 | 45 | $this->placeholders['dummy'] = ''; |
46 | 46 | $this->condition = array(); |
47 | 47 | $this->vars = array(); |
48 | - $this->vars['name'] = & $key; |
|
49 | - $value = $this->parsePhx($key,$value,$modifiers); |
|
48 | + $this->vars['name'] = & $key; |
|
49 | + $value = $this->parsePhx($key, $value, $modifiers); |
|
50 | 50 | $this->vars = array(); |
51 | 51 | return $value; |
52 | 52 | } |
53 | 53 | |
54 | - public function _getDelim($mode,$modifiers) { |
|
55 | - $c = substr($modifiers,0,1); |
|
56 | - if(!in_array($c, array('"', "'", '`')) ) return false; |
|
54 | + public function _getDelim($mode, $modifiers){ |
|
55 | + $c = substr($modifiers, 0, 1); |
|
56 | + if (!in_array($c, array('"', "'", '`'))) return false; |
|
57 | 57 | |
58 | - $modifiers = substr($modifiers,1); |
|
59 | - $closure = $mode=='(' ? "{$c})" : $c; |
|
60 | - if(strpos($modifiers, $closure)===false) return false; |
|
58 | + $modifiers = substr($modifiers, 1); |
|
59 | + $closure = $mode == '(' ? "{$c})" : $c; |
|
60 | + if (strpos($modifiers, $closure) === false) return false; |
|
61 | 61 | |
62 | 62 | return $c; |
63 | 63 | } |
64 | 64 | |
65 | - public function _getOpt($mode,$delim,$modifiers) { |
|
66 | - if($delim) { |
|
67 | - if($mode=='(') return substr($modifiers,1,strpos($modifiers, $delim . ')' )-1); |
|
65 | + public function _getOpt($mode, $delim, $modifiers){ |
|
66 | + if ($delim) { |
|
67 | + if ($mode == '(') return substr($modifiers, 1, strpos($modifiers, $delim.')') - 1); |
|
68 | 68 | |
69 | - return substr($modifiers,1,strpos($modifiers,$delim,1)-1); |
|
69 | + return substr($modifiers, 1, strpos($modifiers, $delim, 1) - 1); |
|
70 | 70 | } |
71 | 71 | else { |
72 | - if($mode=='(') return substr($modifiers,0,strpos($modifiers, ')') ); |
|
72 | + if ($mode == '(') return substr($modifiers, 0, strpos($modifiers, ')')); |
|
73 | 73 | |
74 | 74 | $chars = str_split($modifiers); |
75 | - $opt=''; |
|
76 | - foreach($chars as $c) { |
|
77 | - if($c==':' || $c==')') break; |
|
78 | - $opt .=$c; |
|
75 | + $opt = ''; |
|
76 | + foreach ($chars as $c) { |
|
77 | + if ($c == ':' || $c == ')') break; |
|
78 | + $opt .= $c; |
|
79 | 79 | } |
80 | 80 | return $opt; |
81 | 81 | } |
82 | 82 | } |
83 | - public function _getRemainModifiers($mode,$delim,$modifiers) { |
|
84 | - if($delim) { |
|
85 | - if($mode=='(') |
|
86 | - return $this->_fetchContent($modifiers, $delim . ')'); |
|
83 | + public function _getRemainModifiers($mode, $delim, $modifiers){ |
|
84 | + if ($delim) { |
|
85 | + if ($mode == '(') |
|
86 | + return $this->_fetchContent($modifiers, $delim.')'); |
|
87 | 87 | else { |
88 | 88 | $modifiers = trim($modifiers); |
89 | - $modifiers = substr($modifiers,1); |
|
89 | + $modifiers = substr($modifiers, 1); |
|
90 | 90 | return $this->_fetchContent($modifiers, $delim); |
91 | 91 | } |
92 | 92 | } |
93 | 93 | else { |
94 | - if($mode=='(') return $this->_fetchContent($modifiers, ')'); |
|
94 | + if ($mode == '(') return $this->_fetchContent($modifiers, ')'); |
|
95 | 95 | $chars = str_split($modifiers); |
96 | - foreach($chars as $c) { |
|
97 | - if($c==':') return $modifiers; |
|
98 | - else $modifiers = substr($modifiers,1); |
|
96 | + foreach ($chars as $c) { |
|
97 | + if ($c == ':') return $modifiers; |
|
98 | + else $modifiers = substr($modifiers, 1); |
|
99 | 99 | } |
100 | 100 | return $modifiers; |
101 | 101 | } |
102 | 102 | } |
103 | 103 | |
104 | - public function _fetchContent($string,$delim) { |
|
104 | + public function _fetchContent($string, $delim){ |
|
105 | 105 | $len = strlen($delim); |
106 | 106 | $string = $this->parseDocumentSource($string); |
107 | - return substr($string,strpos($string, $delim)+$len); |
|
107 | + return substr($string, strpos($string, $delim) + $len); |
|
108 | 108 | } |
109 | 109 | |
110 | - public function splitEachModifiers($modifiers) { |
|
110 | + public function splitEachModifiers($modifiers){ |
|
111 | 111 | global $modx; |
112 | 112 | |
113 | 113 | $cmd = ''; |
114 | 114 | $bt = ''; |
115 | 115 | $result = array(); |
116 | - while($bt!==$modifiers) { |
|
116 | + while ($bt !== $modifiers) { |
|
117 | 117 | $bt = $modifiers; |
118 | - $c = substr($modifiers,0,1); |
|
119 | - $modifiers = substr($modifiers,1); |
|
118 | + $c = substr($modifiers, 0, 1); |
|
119 | + $modifiers = substr($modifiers, 1); |
|
120 | 120 | |
121 | - if($c===':' && preg_match('@^(!?[<>=]{1,2})@', $modifiers, $match)) { // :=, :!=, :<=, :>=, :!<=, :!>= |
|
122 | - $c = substr($modifiers,strlen($match[1]),1); |
|
121 | + if ($c === ':' && preg_match('@^(!?[<>=]{1,2})@', $modifiers, $match)) { // :=, :!=, :<=, :>=, :!<=, :!>= |
|
122 | + $c = substr($modifiers, strlen($match[1]), 1); |
|
123 | 123 | $debuginfo = "#i=0 #c=[{$c}] #m=[{$modifiers}]"; |
124 | - if($c==='(') $modifiers = substr($modifiers,strlen($match[1])+1); |
|
125 | - else $modifiers = substr($modifiers,strlen($match[1])); |
|
124 | + if ($c === '(') $modifiers = substr($modifiers, strlen($match[1]) + 1); |
|
125 | + else $modifiers = substr($modifiers, strlen($match[1])); |
|
126 | 126 | |
127 | - $delim = $this->_getDelim($c,$modifiers); |
|
128 | - $opt = $this->_getOpt($c,$delim,$modifiers); |
|
129 | - $modifiers = trim($this->_getRemainModifiers($c,$delim,$modifiers)); |
|
127 | + $delim = $this->_getDelim($c, $modifiers); |
|
128 | + $opt = $this->_getOpt($c, $delim, $modifiers); |
|
129 | + $modifiers = trim($this->_getRemainModifiers($c, $delim, $modifiers)); |
|
130 | 130 | |
131 | - $result[]=array('cmd'=>trim($match[1]),'opt'=>$opt,'debuginfo'=>$debuginfo); |
|
131 | + $result[] = array('cmd'=>trim($match[1]), 'opt'=>$opt, 'debuginfo'=>$debuginfo); |
|
132 | 132 | $cmd = ''; |
133 | 133 | } |
134 | - elseif(in_array($c,array('+','-','*','/')) && preg_match('@^[0-9]+@', $modifiers, $match)) { // :+3, :-3, :*3 ... |
|
135 | - $modifiers = substr($modifiers,strlen($match[0])); |
|
136 | - $result[]=array('cmd'=>'math','opt'=>'%s'.$c.$match[0]); |
|
134 | + elseif (in_array($c, array('+', '-', '*', '/')) && preg_match('@^[0-9]+@', $modifiers, $match)) { // :+3, :-3, :*3 ... |
|
135 | + $modifiers = substr($modifiers, strlen($match[0])); |
|
136 | + $result[] = array('cmd'=>'math', 'opt'=>'%s'.$c.$match[0]); |
|
137 | 137 | $cmd = ''; |
138 | 138 | } |
139 | - elseif($c==='(' || $c==='=') { |
|
139 | + elseif ($c === '(' || $c === '=') { |
|
140 | 140 | $modifiers = $m1 = trim($modifiers); |
141 | - $delim = $this->_getDelim($c,$modifiers); |
|
142 | - $opt = $this->_getOpt($c,$delim,$modifiers); |
|
143 | - $modifiers = trim($this->_getRemainModifiers($c,$delim,$modifiers)); |
|
141 | + $delim = $this->_getDelim($c, $modifiers); |
|
142 | + $opt = $this->_getOpt($c, $delim, $modifiers); |
|
143 | + $modifiers = trim($this->_getRemainModifiers($c, $delim, $modifiers)); |
|
144 | 144 | $debuginfo = "#i=1 #c=[{$c}] #delim=[{$delim}] #m1=[{$m1}] remainMdf=[{$modifiers}]"; |
145 | 145 | |
146 | - $result[]=array('cmd'=>trim($cmd),'opt'=>$opt,'debuginfo'=>$debuginfo); |
|
146 | + $result[] = array('cmd'=>trim($cmd), 'opt'=>$opt, 'debuginfo'=>$debuginfo); |
|
147 | 147 | |
148 | 148 | $cmd = ''; |
149 | 149 | } |
150 | - elseif($c==':') { |
|
150 | + elseif ($c == ':') { |
|
151 | 151 | $debuginfo = "#i=2 #c=[{$c}] #m=[{$modifiers}]"; |
152 | - if($cmd!=='') $result[]=array('cmd'=>trim($cmd),'opt'=>'','debuginfo'=>$debuginfo); |
|
152 | + if ($cmd !== '') $result[] = array('cmd'=>trim($cmd), 'opt'=>'', 'debuginfo'=>$debuginfo); |
|
153 | 153 | |
154 | 154 | $cmd = ''; |
155 | 155 | } |
156 | - elseif(trim($modifiers)=='' && trim($cmd)!=='') { |
|
156 | + elseif (trim($modifiers) == '' && trim($cmd) !== '') { |
|
157 | 157 | $debuginfo = "#i=3 #c=[{$c}] #m=[{$modifiers}]"; |
158 | 158 | $cmd .= $c; |
159 | - $result[]=array('cmd'=>trim($cmd),'opt'=>'','debuginfo'=>$debuginfo); |
|
159 | + $result[] = array('cmd'=>trim($cmd), 'opt'=>'', 'debuginfo'=>$debuginfo); |
|
160 | 160 | |
161 | 161 | break; |
162 | 162 | } |
@@ -165,65 +165,65 @@ discard block |
||
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
168 | - if(empty($result)) return array(); |
|
168 | + if (empty($result)) return array(); |
|
169 | 169 | |
170 | - foreach($result as $i=>$a) |
|
170 | + foreach ($result as $i=>$a) |
|
171 | 171 | { |
172 | 172 | $a['opt'] = $this->parseDocumentSource($a['opt']); |
173 | - $result[$i]['opt'] = $modx->mergePlaceholderContent($a['opt'],$this->placeholders); |
|
173 | + $result[$i]['opt'] = $modx->mergePlaceholderContent($a['opt'], $this->placeholders); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | return $result; |
177 | 177 | } |
178 | 178 | |
179 | - public function parsePhx($key,$value,$modifiers) |
|
179 | + public function parsePhx($key, $value, $modifiers) |
|
180 | 180 | { |
181 | 181 | global $modx; |
182 | 182 | $lastKey = ''; |
183 | - $cacheKey = md5(sprintf('parsePhx#%s#%s#%s',$key,$value,print_r($modifiers,true))); |
|
184 | - if(isset($this->tmpCache[$cacheKey])) return $this->tmpCache[$cacheKey]; |
|
185 | - if(empty($modifiers)) return ''; |
|
183 | + $cacheKey = md5(sprintf('parsePhx#%s#%s#%s', $key, $value, print_r($modifiers, true))); |
|
184 | + if (isset($this->tmpCache[$cacheKey])) return $this->tmpCache[$cacheKey]; |
|
185 | + if (empty($modifiers)) return ''; |
|
186 | 186 | |
187 | - foreach($modifiers as $m) |
|
187 | + foreach ($modifiers as $m) |
|
188 | 188 | { |
189 | 189 | $lastKey = strtolower($m['cmd']); |
190 | 190 | } |
191 | - $_ = explode(',',$this->condModifiers); |
|
192 | - if(in_array($lastKey,$_)) |
|
191 | + $_ = explode(',', $this->condModifiers); |
|
192 | + if (in_array($lastKey, $_)) |
|
193 | 193 | { |
194 | - $modifiers[] = array('cmd'=>'then','opt'=>'1'); |
|
195 | - $modifiers[] = array('cmd'=>'else','opt'=>'0'); |
|
194 | + $modifiers[] = array('cmd'=>'then', 'opt'=>'1'); |
|
195 | + $modifiers[] = array('cmd'=>'else', 'opt'=>'0'); |
|
196 | 196 | } |
197 | 197 | |
198 | - foreach($modifiers as $i=>$a) |
|
198 | + foreach ($modifiers as $i=>$a) |
|
199 | 199 | { |
200 | - $value = $this->Filter($key,$value, $a['cmd'], $a['opt']); |
|
200 | + $value = $this->Filter($key, $value, $a['cmd'], $a['opt']); |
|
201 | 201 | } |
202 | 202 | $this->tmpCache[$cacheKey] = $value; |
203 | 203 | return $value; |
204 | 204 | } |
205 | 205 | |
206 | 206 | // Parser: modifier detection and eXtended processing if needed |
207 | - public function Filter($key, $value, $cmd, $opt='') |
|
207 | + public function Filter($key, $value, $cmd, $opt = '') |
|
208 | 208 | { |
209 | 209 | global $modx; |
210 | 210 | |
211 | - if($key==='documentObject') $value = $modx->documentIdentifier; |
|
211 | + if ($key === 'documentObject') $value = $modx->documentIdentifier; |
|
212 | 212 | $cmd = $this->parseDocumentSource($cmd); |
213 | - if(preg_match('@^[1-9][/0-9]*$@',$cmd)) |
|
213 | + if (preg_match('@^[1-9][/0-9]*$@', $cmd)) |
|
214 | 214 | { |
215 | - if(strpos($cmd,'/')!==false) |
|
216 | - $cmd = $this->substr($cmd,strrpos($cmd,'/')+1); |
|
215 | + if (strpos($cmd, '/') !== false) |
|
216 | + $cmd = $this->substr($cmd, strrpos($cmd, '/') + 1); |
|
217 | 217 | $opt = $cmd; |
218 | 218 | $cmd = 'id'; |
219 | 219 | } |
220 | 220 | |
221 | - if(isset($modx->snippetCache["phx:{$cmd}"])) $this->elmName = "phx:{$cmd}"; |
|
222 | - elseif(isset($modx->chunkCache["phx:{$cmd}"])) $this->elmName = "phx:{$cmd}"; |
|
221 | + if (isset($modx->snippetCache["phx:{$cmd}"])) $this->elmName = "phx:{$cmd}"; |
|
222 | + elseif (isset($modx->chunkCache["phx:{$cmd}"])) $this->elmName = "phx:{$cmd}"; |
|
223 | 223 | else $this->elmName = ''; |
224 | 224 | |
225 | 225 | $cmd = strtolower($cmd); |
226 | - if($this->elmName!=='') |
|
226 | + if ($this->elmName !== '') |
|
227 | 227 | $value = $this->getValueFromElement($key, $value, $cmd, $opt); |
228 | 228 | else |
229 | 229 | $value = $this->getValueFromPreset($key, $value, $cmd, $opt); |
@@ -233,12 +233,12 @@ discard block |
||
233 | 233 | return $value; |
234 | 234 | } |
235 | 235 | |
236 | - public function isEmpty($cmd,$value) |
|
236 | + public function isEmpty($cmd, $value) |
|
237 | 237 | { |
238 | - if($value!=='') return false; |
|
238 | + if ($value !== '') return false; |
|
239 | 239 | |
240 | - $_ = explode(',', $this->condModifiers . ',_default,default,if,input,or,and,show,this,select,switch,then,else,id,ifempty,smart_desc,smart_description,summary'); |
|
241 | - if(in_array($cmd,$_)) return false; |
|
240 | + $_ = explode(',', $this->condModifiers.',_default,default,if,input,or,and,show,this,select,switch,then,else,id,ifempty,smart_desc,smart_description,summary'); |
|
241 | + if (in_array($cmd, $_)) return false; |
|
242 | 242 | else return true; |
243 | 243 | } |
244 | 244 | |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | { |
247 | 247 | global $modx; |
248 | 248 | |
249 | - if($this->isEmpty($cmd,$value)) return ''; |
|
249 | + if ($this->isEmpty($cmd, $value)) return ''; |
|
250 | 250 | |
251 | 251 | $this->key = $key; |
252 | 252 | $this->value = $value; |
@@ -257,83 +257,83 @@ discard block |
||
257 | 257 | ##### Conditional Modifiers |
258 | 258 | case 'input': |
259 | 259 | case 'if': |
260 | - if(!$opt) return $value; |
|
260 | + if (!$opt) return $value; |
|
261 | 261 | return $opt; |
262 | 262 | case '=': |
263 | 263 | case 'eq': |
264 | 264 | case 'is': |
265 | 265 | case 'equals': |
266 | - $this->condition[] = (int)($value == $opt); break; |
|
266 | + $this->condition[] = (int) ($value == $opt); break; |
|
267 | 267 | case 'neq': |
268 | 268 | case 'ne': |
269 | 269 | case 'notequals': |
270 | 270 | case 'isnot': |
271 | 271 | case 'isnt': |
272 | 272 | case 'not': |
273 | - $this->condition[] = (int)($value != $opt);break; |
|
273 | + $this->condition[] = (int) ($value != $opt); break; |
|
274 | 274 | case '%': |
275 | - $this->condition[] = (int)($value%$opt==0);break; |
|
275 | + $this->condition[] = (int) ($value % $opt == 0); break; |
|
276 | 276 | case 'isempty': |
277 | - $this->condition[] = (int)(empty($value)); break; |
|
277 | + $this->condition[] = (int) (empty($value)); break; |
|
278 | 278 | case 'isntempty': |
279 | 279 | case 'isnotempty': |
280 | - $this->condition[] = (int)(!empty($value)); break; |
|
280 | + $this->condition[] = (int) (!empty($value)); break; |
|
281 | 281 | case '>=': |
282 | 282 | case 'gte': |
283 | 283 | case 'eg': |
284 | 284 | case 'isgte': |
285 | - $this->condition[] = (int)($value >= $opt);break; |
|
285 | + $this->condition[] = (int) ($value >= $opt); break; |
|
286 | 286 | case '<=': |
287 | 287 | case 'lte': |
288 | 288 | case 'el': |
289 | 289 | case 'islte': |
290 | - $this->condition[] = (int)($value <= $opt);break; |
|
290 | + $this->condition[] = (int) ($value <= $opt); break; |
|
291 | 291 | case '>': |
292 | 292 | case 'gt': |
293 | 293 | case 'greaterthan': |
294 | 294 | case 'isgreaterthan': |
295 | 295 | case 'isgt': |
296 | - $this->condition[] = (int)($value > $opt);break; |
|
296 | + $this->condition[] = (int) ($value > $opt); break; |
|
297 | 297 | case '<': |
298 | 298 | case 'lt': |
299 | 299 | case 'lowerthan': |
300 | 300 | case 'islowerthan': |
301 | 301 | case 'islt': |
302 | - $this->condition[] = (int)($value < $opt);break; |
|
302 | + $this->condition[] = (int) ($value < $opt); break; |
|
303 | 303 | case 'find': |
304 | - $this->condition[] = (int)(strpos($value, $opt)!==false);break; |
|
304 | + $this->condition[] = (int) (strpos($value, $opt) !== false); break; |
|
305 | 305 | case 'inarray': |
306 | 306 | case 'in_array': |
307 | 307 | case 'in': |
308 | 308 | $opt = explode(',', $opt); |
309 | - $this->condition[] = (int)(in_array($value, $opt)!==false);break; |
|
309 | + $this->condition[] = (int) (in_array($value, $opt) !== false); break; |
|
310 | 310 | case 'wildcard_match': |
311 | 311 | case 'wcard_match': |
312 | 312 | case 'wildcard': |
313 | 313 | case 'wcard': |
314 | 314 | case 'fnmatch': |
315 | - $this->condition[] = (int)(fnmatch($opt, $value)!==false);break; |
|
315 | + $this->condition[] = (int) (fnmatch($opt, $value) !== false); break; |
|
316 | 316 | case 'is_file': |
317 | 317 | case 'is_dir': |
318 | 318 | case 'file_exists': |
319 | 319 | case 'is_readable': |
320 | 320 | case 'is_writable': |
321 | - if(!$opt) $path = $value; |
|
321 | + if (!$opt) $path = $value; |
|
322 | 322 | else $path = $opt; |
323 | - if(strpos($path,MODX_MANAGER_PATH)!==false) exit('Can not read core path'); |
|
324 | - if(strpos($path,$modx->config['base_path'])===false) $path = ltrim($path,'/'); |
|
325 | - $this->condition[] = (int)($cmd($path)!==false);break; |
|
323 | + if (strpos($path, MODX_MANAGER_PATH) !== false) exit('Can not read core path'); |
|
324 | + if (strpos($path, $modx->config['base_path']) === false) $path = ltrim($path, '/'); |
|
325 | + $this->condition[] = (int) ($cmd($path) !== false); break; |
|
326 | 326 | case 'is_image': |
327 | - if(!$opt) $path = $value; |
|
327 | + if (!$opt) $path = $value; |
|
328 | 328 | else $path = $opt; |
329 | - if(!is_file($path)) {$this->condition[]='0';break;} |
|
329 | + if (!is_file($path)) {$this->condition[] = '0'; break; } |
|
330 | 330 | $_ = getimagesize($path); |
331 | - $this->condition[] = (int)($_[0]);break; |
|
331 | + $this->condition[] = (int) ($_[0]); break; |
|
332 | 332 | case 'regex': |
333 | 333 | case 'preg': |
334 | 334 | case 'preg_match': |
335 | 335 | case 'isinrole': |
336 | - $this->condition[] = (int)(preg_match($opt,$value));break; |
|
336 | + $this->condition[] = (int) (preg_match($opt, $value)); break; |
|
337 | 337 | case 'ir': |
338 | 338 | case 'memberof': |
339 | 339 | case 'mo': |
@@ -341,50 +341,50 @@ discard block |
||
341 | 341 | $this->condition[] = $this->includeMdfFile('memberof'); |
342 | 342 | break; |
343 | 343 | case 'or': |
344 | - $this->condition[] = '||';break; |
|
344 | + $this->condition[] = '||'; break; |
|
345 | 345 | case 'and': |
346 | - $this->condition[] = '&&';break; |
|
346 | + $this->condition[] = '&&'; break; |
|
347 | 347 | case 'show': |
348 | 348 | case 'this': |
349 | - $conditional = implode(' ',$this->condition); |
|
350 | - $isvalid = (int)(eval("return ({$conditional});")); |
|
349 | + $conditional = implode(' ', $this->condition); |
|
350 | + $isvalid = (int) (eval("return ({$conditional});")); |
|
351 | 351 | if ($isvalid) return $this->srcValue; |
352 | 352 | return NULL; |
353 | 353 | case 'then': |
354 | - $conditional = implode(' ',$this->condition); |
|
355 | - $isvalid = (int)eval("return ({$conditional});"); |
|
354 | + $conditional = implode(' ', $this->condition); |
|
355 | + $isvalid = (int) eval("return ({$conditional});"); |
|
356 | 356 | if ($isvalid) return $opt; |
357 | 357 | return null; |
358 | 358 | case 'else': |
359 | - $conditional = implode(' ',$this->condition); |
|
360 | - $isvalid = (int)eval("return ({$conditional});"); |
|
359 | + $conditional = implode(' ', $this->condition); |
|
360 | + $isvalid = (int) eval("return ({$conditional});"); |
|
361 | 361 | if (!$isvalid) return $opt; |
362 | 362 | break; |
363 | 363 | case 'select': |
364 | 364 | case 'switch': |
365 | - $raw = explode('&',$opt); |
|
365 | + $raw = explode('&', $opt); |
|
366 | 366 | $map = array(); |
367 | 367 | $c = count($raw); |
368 | - for($m=0; $m<$c; $m++) { |
|
369 | - $mi = explode('=',$raw[$m],2); |
|
368 | + for ($m = 0; $m < $c; $m++) { |
|
369 | + $mi = explode('=', $raw[$m], 2); |
|
370 | 370 | $map[$mi[0]] = $mi[1]; |
371 | 371 | } |
372 | - if(isset($map[$value])) return $map[$value]; |
|
372 | + if (isset($map[$value])) return $map[$value]; |
|
373 | 373 | else return ''; |
374 | 374 | ##### End of Conditional Modifiers |
375 | 375 | |
376 | 376 | ##### Encode / Decode / Hash / Escape |
377 | 377 | case 'htmlent': |
378 | 378 | case 'htmlentities': |
379 | - return htmlentities($value,ENT_QUOTES,$modx->config['modx_charset']); |
|
379 | + return htmlentities($value, ENT_QUOTES, $modx->config['modx_charset']); |
|
380 | 380 | case 'html_entity_decode': |
381 | 381 | case 'decode_html': |
382 | 382 | case 'html_decode': |
383 | - return html_entity_decode($value,ENT_QUOTES,$modx->config['modx_charset']); |
|
383 | + return html_entity_decode($value, ENT_QUOTES, $modx->config['modx_charset']); |
|
384 | 384 | case 'esc': |
385 | 385 | case 'escape': |
386 | 386 | $value = preg_replace('/&(#[0-9]+|[a-z]+);/i', '&$1;', htmlspecialchars($value, ENT_QUOTES, $modx->config['modx_charset'])); |
387 | - return str_replace(array('[', ']', '`'),array('[', ']', '`'),$value); |
|
387 | + return str_replace(array('[', ']', '`'), array('[', ']', '`'), $value); |
|
388 | 388 | case 'sql_escape': |
389 | 389 | case 'encode_js': |
390 | 390 | return $modx->db->escape($value); |
@@ -394,39 +394,39 @@ discard block |
||
394 | 394 | case 'html_encode': |
395 | 395 | return preg_replace('/&(#[0-9]+|[a-z]+);/i', '&$1;', htmlspecialchars($value, ENT_QUOTES, $modx->config['modx_charset'])); |
396 | 396 | case 'spam_protect': |
397 | - return str_replace(array('@','.'),array('@','.'),$value); |
|
397 | + return str_replace(array('@', '.'), array('@', '.'), $value); |
|
398 | 398 | case 'strip': |
399 | - if($opt==='') $opt = ' '; |
|
399 | + if ($opt === '') $opt = ' '; |
|
400 | 400 | return preg_replace('/[\n\r\t\s]+/', $opt, $value); |
401 | 401 | case 'strip_linefeeds': |
402 | - return str_replace(array("\n","\r"), '', $value); |
|
402 | + return str_replace(array("\n", "\r"), '', $value); |
|
403 | 403 | case 'notags': |
404 | 404 | case 'strip_tags': |
405 | 405 | case 'remove_html': |
406 | - if($opt!=='') |
|
406 | + if ($opt !== '') |
|
407 | 407 | { |
408 | 408 | $param = array(); |
409 | - foreach(explode(',',$opt) as $v) |
|
409 | + foreach (explode(',', $opt) as $v) |
|
410 | 410 | { |
411 | - $v = trim($v,'</> '); |
|
411 | + $v = trim($v, '</> '); |
|
412 | 412 | $param[] = "<{$v}>"; |
413 | 413 | } |
414 | - $params = implode(',',$param); |
|
414 | + $params = implode(',', $param); |
|
415 | 415 | } |
416 | 416 | else $params = ''; |
417 | - if(!strpos($params,'<br>')===false) { |
|
418 | - $value = preg_replace('@(<br[ /]*>)\n@','$1',$value); |
|
419 | - $value = preg_replace('@<br[ /]*>@',"\n",$value); |
|
417 | + if (!strpos($params, '<br>') === false) { |
|
418 | + $value = preg_replace('@(<br[ /]*>)\n@', '$1', $value); |
|
419 | + $value = preg_replace('@<br[ /]*>@', "\n", $value); |
|
420 | 420 | } |
421 | - return $this->strip_tags($value,$params); |
|
421 | + return $this->strip_tags($value, $params); |
|
422 | 422 | case 'urlencode': |
423 | 423 | case 'url_encode': |
424 | 424 | case 'encode_url': |
425 | 425 | return urlencode($value); |
426 | 426 | case 'base64_decode': |
427 | - if($opt!=='false') $opt = true; |
|
427 | + if ($opt !== 'false') $opt = true; |
|
428 | 428 | else $opt = false; |
429 | - return base64_decode($value,$opt); |
|
429 | + return base64_decode($value, $opt); |
|
430 | 430 | case 'encode_sha1': $cmd = 'sha1'; |
431 | 431 | case 'addslashes': |
432 | 432 | case 'urldecode': |
@@ -450,18 +450,18 @@ discard block |
||
450 | 450 | case 'upper_case': |
451 | 451 | return $this->strtoupper($value); |
452 | 452 | case 'capitalize': |
453 | - $_ = explode(' ',$value); |
|
454 | - foreach($_ as $i=>$v) |
|
453 | + $_ = explode(' ', $value); |
|
454 | + foreach ($_ as $i=>$v) |
|
455 | 455 | { |
456 | 456 | $_[$i] = ucfirst($v); |
457 | 457 | } |
458 | - return implode(' ',$_); |
|
458 | + return implode(' ', $_); |
|
459 | 459 | case 'zenhan': |
460 | - if(empty($opt)) $opt='VKas'; |
|
461 | - return mb_convert_kana($value,$opt,$modx->config['modx_charset']); |
|
460 | + if (empty($opt)) $opt = 'VKas'; |
|
461 | + return mb_convert_kana($value, $opt, $modx->config['modx_charset']); |
|
462 | 462 | case 'hanzen': |
463 | - if(empty($opt)) $opt='VKAS'; |
|
464 | - return mb_convert_kana($value,$opt,$modx->config['modx_charset']); |
|
463 | + if (empty($opt)) $opt = 'VKAS'; |
|
464 | + return mb_convert_kana($value, $opt, $modx->config['modx_charset']); |
|
465 | 465 | case 'str_shuffle': |
466 | 466 | case 'shuffle': |
467 | 467 | return $this->str_shuffle($value); |
@@ -475,7 +475,7 @@ discard block |
||
475 | 475 | return $this->strlen($value); |
476 | 476 | case 'count_words': |
477 | 477 | $value = trim($value); |
478 | - return count(preg_split('/\s+/',$value)); |
|
478 | + return count(preg_split('/\s+/', $value)); |
|
479 | 479 | case 'str_word_count': |
480 | 480 | case 'word_count': |
481 | 481 | case 'wordcount': |
@@ -483,55 +483,55 @@ discard block |
||
483 | 483 | case 'count_paragraphs': |
484 | 484 | $value = trim($value); |
485 | 485 | $value = preg_replace('/\r/', '', $value); |
486 | - return count(preg_split('/\n+/',$value)); |
|
486 | + return count(preg_split('/\n+/', $value)); |
|
487 | 487 | case 'strpos': |
488 | - if($opt!=0&&empty($opt)) return $value; |
|
489 | - return $this->strpos($value,$opt); |
|
488 | + if ($opt != 0 && empty($opt)) return $value; |
|
489 | + return $this->strpos($value, $opt); |
|
490 | 490 | case 'wordwrap': |
491 | 491 | // default: 70 |
492 | - $wrapat = (int)$opt > 0 ? (int)$opt : 70; |
|
492 | + $wrapat = (int) $opt > 0 ? (int) $opt : 70; |
|
493 | 493 | if (version_compare(PHP_VERSION, '5.3.0') >= 0) return $this->includeMdfFile('wordwrap'); |
494 | - else return preg_replace("@(\b\w+\b)@e","wordwrap('\\1',\$wrapat,' ',1)",$value); |
|
494 | + else return preg_replace("@(\b\w+\b)@e", "wordwrap('\\1',\$wrapat,' ',1)", $value); |
|
495 | 495 | case 'wrap_text': |
496 | - $width = preg_match('/^[1-9][0-9]*$/',$opt) ? $opt : 70; |
|
497 | - if($modx->config['manager_language']==='japanese-utf8') { |
|
496 | + $width = preg_match('/^[1-9][0-9]*$/', $opt) ? $opt : 70; |
|
497 | + if ($modx->config['manager_language'] === 'japanese-utf8') { |
|
498 | 498 | $chunk = array(); |
499 | - $bt=''; |
|
500 | - while($bt!=$value) { |
|
499 | + $bt = ''; |
|
500 | + while ($bt != $value) { |
|
501 | 501 | $bt = $value; |
502 | - if($this->strlen($value)<$width) { |
|
502 | + if ($this->strlen($value) < $width) { |
|
503 | 503 | $chunk[] = $value; |
504 | 504 | break; |
505 | 505 | } |
506 | - $chunk[] = $this->substr($value,0,$width); |
|
507 | - $value = $this->substr($value,$width); |
|
506 | + $chunk[] = $this->substr($value, 0, $width); |
|
507 | + $value = $this->substr($value, $width); |
|
508 | 508 | } |
509 | - return implode("\n",$chunk); |
|
509 | + return implode("\n", $chunk); |
|
510 | 510 | } |
511 | 511 | else |
512 | - return wordwrap($value,$width,"\n",true); |
|
512 | + return wordwrap($value, $width, "\n", true); |
|
513 | 513 | case 'substr': |
514 | - if(empty($opt)) break; |
|
515 | - if(strpos($opt,',')!==false) { |
|
516 | - list($b,$e) = explode(',',$opt,2); |
|
517 | - return $this->substr($value,$b,(int)$e); |
|
514 | + if (empty($opt)) break; |
|
515 | + if (strpos($opt, ',') !== false) { |
|
516 | + list($b, $e) = explode(',', $opt, 2); |
|
517 | + return $this->substr($value, $b, (int) $e); |
|
518 | 518 | } |
519 | - else return $this->substr($value,$opt); |
|
519 | + else return $this->substr($value, $opt); |
|
520 | 520 | case 'limit': |
521 | 521 | case 'trim_to': // http://www.movabletype.jp/documentation/appendices/modifiers/trim_to.html |
522 | - if(strpos($opt,'+')!==false) |
|
523 | - list($len,$str) = explode('+',$opt,2); |
|
522 | + if (strpos($opt, '+') !== false) |
|
523 | + list($len, $str) = explode('+', $opt, 2); |
|
524 | 524 | else { |
525 | 525 | $len = $opt; |
526 | 526 | $str = ''; |
527 | 527 | } |
528 | - if($len==='') $len = 100; |
|
529 | - if(abs($len) > $this->strlen($value)) $str =''; |
|
530 | - if(preg_match('/^[1-9][0-9]*$/',$len)) { |
|
531 | - return $this->substr($value,0,$len) . $str; |
|
528 | + if ($len === '') $len = 100; |
|
529 | + if (abs($len) > $this->strlen($value)) $str = ''; |
|
530 | + if (preg_match('/^[1-9][0-9]*$/', $len)) { |
|
531 | + return $this->substr($value, 0, $len).$str; |
|
532 | 532 | } |
533 | - elseif(preg_match('/^\-[1-9][0-9]*$/',$len)) { |
|
534 | - return $str . $this->substr($value,$len); |
|
533 | + elseif (preg_match('/^\-[1-9][0-9]*$/', $len)) { |
|
534 | + return $str.$this->substr($value, $len); |
|
535 | 535 | } |
536 | 536 | break; |
537 | 537 | case 'summary': |
@@ -540,81 +540,81 @@ discard block |
||
540 | 540 | return $this->includeMdfFile('summary'); |
541 | 541 | case 'replace': |
542 | 542 | case 'str_replace': |
543 | - if(empty($opt) || strpos($opt,',')===false) break; |
|
544 | - if (substr_count($opt, ',') ==1) $delim = ','; |
|
545 | - elseif(substr_count($opt, '|') ==1) $delim = '|'; |
|
546 | - elseif(substr_count($opt, '=>')==1) $delim = '=>'; |
|
547 | - elseif(substr_count($opt, '/') ==1) $delim = '/'; |
|
543 | + if (empty($opt) || strpos($opt, ',') === false) break; |
|
544 | + if (substr_count($opt, ',') == 1) $delim = ','; |
|
545 | + elseif (substr_count($opt, '|') == 1) $delim = '|'; |
|
546 | + elseif (substr_count($opt, '=>') == 1) $delim = '=>'; |
|
547 | + elseif (substr_count($opt, '/') == 1) $delim = '/'; |
|
548 | 548 | else break; |
549 | - list($s,$r) = explode($delim,$opt); |
|
550 | - if($value!=='') return str_replace($s,$r,$value); |
|
549 | + list($s, $r) = explode($delim, $opt); |
|
550 | + if ($value !== '') return str_replace($s, $r, $value); |
|
551 | 551 | break; |
552 | 552 | case 'replace_to': |
553 | 553 | case 'tpl': |
554 | - if($value!=='') return str_replace(array('[+value+]','[+output+]','{value}','%s'),$value,$opt); |
|
554 | + if ($value !== '') return str_replace(array('[+value+]', '[+output+]', '{value}', '%s'), $value, $opt); |
|
555 | 555 | break; |
556 | 556 | case 'eachtpl': |
557 | - $value = explode('||',$value); |
|
557 | + $value = explode('||', $value); |
|
558 | 558 | $_ = array(); |
559 | - foreach($value as $v) { |
|
560 | - $_[] = str_replace(array('[+value+]','[+output+]','{value}','%s'),$v,$opt); |
|
559 | + foreach ($value as $v) { |
|
560 | + $_[] = str_replace(array('[+value+]', '[+output+]', '{value}', '%s'), $v, $opt); |
|
561 | 561 | } |
562 | 562 | return implode("\n", $_); |
563 | 563 | case 'array_pop': |
564 | 564 | case 'array_shift': |
565 | - if(strpos($value,'||')!==false) $delim = '||'; |
|
565 | + if (strpos($value, '||') !== false) $delim = '||'; |
|
566 | 566 | else $delim = ','; |
567 | - return $cmd(explode($delim,$value)); |
|
567 | + return $cmd(explode($delim, $value)); |
|
568 | 568 | case 'preg_replace': |
569 | 569 | case 'regex_replace': |
570 | - if(empty($opt) || strpos($opt,',')===false) break; |
|
571 | - list($s,$r) = explode(',',$opt,2); |
|
572 | - if($value!=='') return preg_replace($s,$r,$value); |
|
570 | + if (empty($opt) || strpos($opt, ',') === false) break; |
|
571 | + list($s, $r) = explode(',', $opt, 2); |
|
572 | + if ($value !== '') return preg_replace($s, $r, $value); |
|
573 | 573 | break; |
574 | 574 | case 'cat': |
575 | 575 | case 'concatenate': |
576 | 576 | case '.': |
577 | - if($value!=='') return $value . $opt; |
|
577 | + if ($value !== '') return $value.$opt; |
|
578 | 578 | break; |
579 | 579 | case 'sprintf': |
580 | 580 | case 'string_format': |
581 | - if($value!=='') return sprintf($opt,$value); |
|
581 | + if ($value !== '') return sprintf($opt, $value); |
|
582 | 582 | break; |
583 | 583 | case 'number_format': |
584 | - if($opt=='') $opt = 0; |
|
585 | - return number_format($value,$opt); |
|
584 | + if ($opt == '') $opt = 0; |
|
585 | + return number_format($value, $opt); |
|
586 | 586 | case 'money_format': |
587 | - setlocale(LC_MONETARY,setlocale(LC_TIME,0)); |
|
588 | - if($value!=='') return money_format($opt,(double)$value); |
|
587 | + setlocale(LC_MONETARY, setlocale(LC_TIME, 0)); |
|
588 | + if ($value !== '') return money_format($opt, (double) $value); |
|
589 | 589 | break; |
590 | 590 | case 'tobool': |
591 | 591 | return boolval($value); |
592 | 592 | case 'nl2lf': |
593 | - if($value!=='') return str_replace(array("\r\n","\n", "\r"), '\n', $value); |
|
593 | + if ($value !== '') return str_replace(array("\r\n", "\n", "\r"), '\n', $value); |
|
594 | 594 | break; |
595 | 595 | case 'br2nl': |
596 | 596 | return preg_replace('@<br[\s/]*>@i', "\n", $value); |
597 | 597 | case 'nl2br': |
598 | 598 | if (version_compare(PHP_VERSION, '5.3.0', '<')) |
599 | 599 | return nl2br($value); |
600 | - if($opt!=='') |
|
600 | + if ($opt !== '') |
|
601 | 601 | { |
602 | 602 | $opt = trim($opt); |
603 | 603 | $opt = strtolower($opt); |
604 | - if($opt==='false') $opt = false; |
|
605 | - elseif($opt==='0') $opt = false; |
|
604 | + if ($opt === 'false') $opt = false; |
|
605 | + elseif ($opt === '0') $opt = false; |
|
606 | 606 | else $opt = true; |
607 | 607 | } |
608 | - elseif(isset($modx->config['mce_element_format'])&&$modx->config['mce_element_format']==='html') |
|
608 | + elseif (isset($modx->config['mce_element_format']) && $modx->config['mce_element_format'] === 'html') |
|
609 | 609 | $opt = false; |
610 | 610 | else $opt = true; |
611 | - return nl2br($value,$opt); |
|
611 | + return nl2br($value, $opt); |
|
612 | 612 | case 'ltrim': |
613 | 613 | case 'rtrim': |
614 | 614 | case 'trim': // ref http://mblo.info/modifiers/custom-modifiers/rtrim_opt.html |
615 | - if($opt==='') |
|
615 | + if ($opt === '') |
|
616 | 616 | return $cmd($value); |
617 | - else return $cmd($value,$opt); |
|
617 | + else return $cmd($value, $opt); |
|
618 | 618 | // These are all straight wrappers for PHP functions |
619 | 619 | case 'ucfirst': |
620 | 620 | case 'lcfirst': |
@@ -625,58 +625,58 @@ discard block |
||
625 | 625 | case 'strftime': |
626 | 626 | case 'date': |
627 | 627 | case 'dateformat': |
628 | - if(empty($opt)) $opt = $modx->toDateFormat(null, 'formatOnly'); |
|
629 | - if(!preg_match('@^[0-9]+$@',$value)) $value = strtotime($value); |
|
630 | - if(strpos($opt,'%')!==false) |
|
631 | - return strftime($opt,0+$value); |
|
628 | + if (empty($opt)) $opt = $modx->toDateFormat(null, 'formatOnly'); |
|
629 | + if (!preg_match('@^[0-9]+$@', $value)) $value = strtotime($value); |
|
630 | + if (strpos($opt, '%') !== false) |
|
631 | + return strftime($opt, 0 + $value); |
|
632 | 632 | else |
633 | - return date($opt,0+$value); |
|
633 | + return date($opt, 0 + $value); |
|
634 | 634 | case 'time': |
635 | - if(empty($opt)) $opt = '%H:%M'; |
|
636 | - if(!preg_match('@^[0-9]+$@',$value)) $value = strtotime($value); |
|
637 | - return strftime($opt,0+$value); |
|
635 | + if (empty($opt)) $opt = '%H:%M'; |
|
636 | + if (!preg_match('@^[0-9]+$@', $value)) $value = strtotime($value); |
|
637 | + return strftime($opt, 0 + $value); |
|
638 | 638 | case 'strtotime': |
639 | 639 | return strtotime($value); |
640 | 640 | ##### mathematical function |
641 | 641 | case 'toint': |
642 | - return (int)$value; |
|
642 | + return (int) $value; |
|
643 | 643 | case 'tofloat': |
644 | 644 | return floatval($value); |
645 | 645 | case 'round': |
646 | - if(!$opt) $opt = 0; |
|
647 | - return $cmd($value,$opt); |
|
646 | + if (!$opt) $opt = 0; |
|
647 | + return $cmd($value, $opt); |
|
648 | 648 | case 'max': |
649 | 649 | case 'min': |
650 | - return $cmd(explode(',',$value)); |
|
650 | + return $cmd(explode(',', $value)); |
|
651 | 651 | case 'floor': |
652 | 652 | case 'ceil': |
653 | 653 | case 'abs': |
654 | 654 | return $cmd($value); |
655 | 655 | case 'math': |
656 | 656 | case 'calc': |
657 | - $value = (int)$value; |
|
658 | - if(empty($value)) $value = '0'; |
|
659 | - $filter = str_replace(array('[+value+]','[+output+]','{value}','%s'),'?',$opt); |
|
660 | - $filter = preg_replace('@([a-zA-Z\n\r\t\s])@','',$filter); |
|
661 | - if(strpos($filter,'?')===false) $filter = "?{$filter}"; |
|
662 | - $filter = str_replace('?',$value,$filter); |
|
657 | + $value = (int) $value; |
|
658 | + if (empty($value)) $value = '0'; |
|
659 | + $filter = str_replace(array('[+value+]', '[+output+]', '{value}', '%s'), '?', $opt); |
|
660 | + $filter = preg_replace('@([a-zA-Z\n\r\t\s])@', '', $filter); |
|
661 | + if (strpos($filter, '?') === false) $filter = "?{$filter}"; |
|
662 | + $filter = str_replace('?', $value, $filter); |
|
663 | 663 | return eval("return {$filter};"); |
664 | 664 | case 'count': |
665 | - if($value=='') return 0; |
|
666 | - $value = explode(',',$value); |
|
665 | + if ($value == '') return 0; |
|
666 | + $value = explode(',', $value); |
|
667 | 667 | return count($value); |
668 | 668 | case 'sort': |
669 | 669 | case 'rsort': |
670 | - if(strpos($value,"\n")!==false) $delim="\n"; |
|
670 | + if (strpos($value, "\n") !== false) $delim = "\n"; |
|
671 | 671 | else $delim = ','; |
672 | - $swap = explode($delim,$value); |
|
673 | - if(!$opt) $opt = SORT_REGULAR; |
|
672 | + $swap = explode($delim, $value); |
|
673 | + if (!$opt) $opt = SORT_REGULAR; |
|
674 | 674 | else $opt = constant($opt); |
675 | - $cmd($swap,$opt); |
|
676 | - return implode($delim,$swap); |
|
675 | + $cmd($swap, $opt); |
|
676 | + return implode($delim, $swap); |
|
677 | 677 | ##### Resource fields |
678 | 678 | case 'id': |
679 | - if($opt) return $this->getDocumentObject($opt,$key); |
|
679 | + if ($opt) return $this->getDocumentObject($opt, $key); |
|
680 | 680 | break; |
681 | 681 | case 'type': |
682 | 682 | case 'contenttype': |
@@ -713,36 +713,36 @@ discard block |
||
713 | 713 | case 'privatemgr': |
714 | 714 | case 'content_dispo': |
715 | 715 | case 'hidemenu': |
716 | - if($cmd==='contenttype') $cmd = 'contentType'; |
|
717 | - return $this->getDocumentObject($value,$cmd); |
|
716 | + if ($cmd === 'contenttype') $cmd = 'contentType'; |
|
717 | + return $this->getDocumentObject($value, $cmd); |
|
718 | 718 | case 'title': |
719 | - $pagetitle = $this->getDocumentObject($value,'pagetitle'); |
|
720 | - $longtitle = $this->getDocumentObject($value,'longtitle'); |
|
719 | + $pagetitle = $this->getDocumentObject($value, 'pagetitle'); |
|
720 | + $longtitle = $this->getDocumentObject($value, 'longtitle'); |
|
721 | 721 | return $longtitle ? $longtitle : $pagetitle; |
722 | 722 | case 'shorttitle': |
723 | - $pagetitle = $this->getDocumentObject($value,'pagetitle'); |
|
724 | - $menutitle = $this->getDocumentObject($value,'menutitle'); |
|
723 | + $pagetitle = $this->getDocumentObject($value, 'pagetitle'); |
|
724 | + $menutitle = $this->getDocumentObject($value, 'menutitle'); |
|
725 | 725 | return $menutitle ? $menutitle : $pagetitle; |
726 | 726 | case 'templatename': |
727 | - $rs = $modx->db->select('templatename','[+prefix+]site_templates',"id='{$value}'"); |
|
727 | + $rs = $modx->db->select('templatename', '[+prefix+]site_templates', "id='{$value}'"); |
|
728 | 728 | $templateName = $modx->db->getValue($rs); |
729 | 729 | return !$templateName ? '(blank)' : $templateName; |
730 | 730 | case 'getfield': |
731 | - if(!$opt) $opt = 'content'; |
|
732 | - return $modx->getField($opt,$value); |
|
731 | + if (!$opt) $opt = 'content'; |
|
732 | + return $modx->getField($opt, $value); |
|
733 | 733 | case 'children': |
734 | 734 | case 'childids': |
735 | - if($value=='') $value = 0; // 値がない場合はルートと見なす |
|
735 | + if ($value == '') $value = 0; // 値がない場合はルートと見なす |
|
736 | 736 | $published = 1; |
737 | - if($opt=='') $opt = 'page'; |
|
738 | - $_ = explode(',',$opt); |
|
737 | + if ($opt == '') $opt = 'page'; |
|
738 | + $_ = explode(',', $opt); |
|
739 | 739 | $where = array(); |
740 | - foreach($_ as $opt) { |
|
741 | - switch(trim($opt)) { |
|
740 | + foreach ($_ as $opt) { |
|
741 | + switch (trim($opt)) { |
|
742 | 742 | case 'page'; case '!folder'; case '!isfolder': $where[] = 'sc.isfolder=0'; break; |
743 | 743 | case 'folder'; case 'isfolder': $where[] = 'sc.isfolder=1'; break; |
744 | - case 'menu'; case 'show_menu': $where[] = 'sc.hidemenu=0'; break; |
|
745 | - case '!menu'; case '!show_menu': $where[] = 'sc.hidemenu=1'; break; |
|
744 | + case 'menu'; case 'show_menu': $where[] = 'sc.hidemenu=0'; break; |
|
745 | + case '!menu'; case '!show_menu': $where[] = 'sc.hidemenu=1'; break; |
|
746 | 746 | case 'published': $published = 1; break; |
747 | 747 | case '!published': $published = 0; break; |
748 | 748 | } |
@@ -750,69 +750,69 @@ discard block |
||
750 | 750 | $where = implode(' AND ', $where); |
751 | 751 | $children = $modx->getDocumentChildren($value, $published, '0', 'id', $where); |
752 | 752 | $result = array(); |
753 | - foreach((array)$children as $child){ |
|
753 | + foreach ((array) $children as $child) { |
|
754 | 754 | $result[] = $child['id']; |
755 | 755 | } |
756 | 756 | return implode(',', $result); |
757 | 757 | case 'fullurl': |
758 | - if(!is_numeric($value)) return $value; |
|
758 | + if (!is_numeric($value)) return $value; |
|
759 | 759 | return $modx->makeUrl($value); |
760 | 760 | case 'makeurl': |
761 | - if(!is_numeric($value)) return $value; |
|
762 | - if(!$opt) $opt = 'full'; |
|
763 | - return $modx->makeUrl($value,'','',$opt); |
|
761 | + if (!is_numeric($value)) return $value; |
|
762 | + if (!$opt) $opt = 'full'; |
|
763 | + return $modx->makeUrl($value, '', '', $opt); |
|
764 | 764 | |
765 | 765 | ##### File system |
766 | 766 | case 'getimageinfo': |
767 | 767 | case 'imageinfo': |
768 | - if(!is_file($value)) return ''; |
|
768 | + if (!is_file($value)) return ''; |
|
769 | 769 | $_ = getimagesize($value); |
770 | - if(!$_[0]) return ''; |
|
770 | + if (!$_[0]) return ''; |
|
771 | 771 | $info['width'] = $_[0]; |
772 | 772 | $info['height'] = $_[1]; |
773 | - if ($_[0] > $_[1]) $info['aspect'] = 'landscape'; |
|
774 | - elseif($_[0] < $_[1]) $info['aspect'] = 'portrait'; |
|
773 | + if ($_[0] > $_[1]) $info['aspect'] = 'landscape'; |
|
774 | + elseif ($_[0] < $_[1]) $info['aspect'] = 'portrait'; |
|
775 | 775 | else $info['aspect'] = 'square'; |
776 | - switch($_[2]) { |
|
776 | + switch ($_[2]) { |
|
777 | 777 | case IMAGETYPE_GIF : $info['type'] = 'gif'; break; |
778 | 778 | case IMAGETYPE_JPEG : $info['type'] = 'jpg'; break; |
779 | 779 | case IMAGETYPE_PNG : $info['type'] = 'png'; break; |
780 | 780 | default : $info['type'] = 'unknown'; |
781 | 781 | } |
782 | 782 | $info['attrib'] = $_[3]; |
783 | - switch($opt) { |
|
783 | + switch ($opt) { |
|
784 | 784 | case 'width' : return $info['width']; |
785 | 785 | case 'height': return $info['height']; |
786 | 786 | case 'aspect': return $info['aspect']; |
787 | 787 | case 'type' : return $info['type']; |
788 | 788 | case 'attrib': return $info['attrib']; |
789 | - default : return print_r($info,true); |
|
789 | + default : return print_r($info, true); |
|
790 | 790 | } |
791 | 791 | |
792 | 792 | case 'file_get_contents': |
793 | 793 | case 'readfile': |
794 | - if(!is_file($value)) return $value; |
|
794 | + if (!is_file($value)) return $value; |
|
795 | 795 | $value = realpath($value); |
796 | - if(strpos($value,MODX_MANAGER_PATH)!==false) exit('Can not read core file'); |
|
797 | - $ext = strtolower(substr($value,-4)); |
|
798 | - if($ext==='.php') exit('Can not read php file'); |
|
799 | - if($ext==='.cgi') exit('Can not read cgi file'); |
|
796 | + if (strpos($value, MODX_MANAGER_PATH) !== false) exit('Can not read core file'); |
|
797 | + $ext = strtolower(substr($value, -4)); |
|
798 | + if ($ext === '.php') exit('Can not read php file'); |
|
799 | + if ($ext === '.cgi') exit('Can not read cgi file'); |
|
800 | 800 | return file_get_contents($value); |
801 | 801 | case 'filesize': |
802 | - if($value == '') return ''; |
|
802 | + if ($value == '') return ''; |
|
803 | 803 | $filename = $value; |
804 | 804 | |
805 | 805 | $site_url = $modx->config['site_url']; |
806 | - if(strpos($filename,$site_url) === 0) |
|
807 | - $filename = substr($filename,0,strlen($site_url)); |
|
808 | - $filename = trim($filename,'/'); |
|
806 | + if (strpos($filename, $site_url) === 0) |
|
807 | + $filename = substr($filename, 0, strlen($site_url)); |
|
808 | + $filename = trim($filename, '/'); |
|
809 | 809 | |
810 | - $opt = trim($opt,'/'); |
|
811 | - if($opt!=='') $opt .= '/'; |
|
810 | + $opt = trim($opt, '/'); |
|
811 | + if ($opt !== '') $opt .= '/'; |
|
812 | 812 | |
813 | 813 | $filename = MODX_BASE_PATH.$opt.$filename; |
814 | 814 | |
815 | - if(is_file($filename)){ |
|
815 | + if (is_file($filename)) { |
|
816 | 816 | clearstatcache(); |
817 | 817 | $size = filesize($filename); |
818 | 818 | return $size; |
@@ -845,10 +845,10 @@ discard block |
||
845 | 845 | $this->opt = $cmd; |
846 | 846 | return $this->includeMdfFile('moduser'); |
847 | 847 | case 'userinfo': |
848 | - if(empty($opt)) $this->opt = 'username'; |
|
848 | + if (empty($opt)) $this->opt = 'username'; |
|
849 | 849 | return $this->includeMdfFile('moduser'); |
850 | 850 | case 'webuserinfo': |
851 | - if(empty($opt)) $this->opt = 'username'; |
|
851 | + if (empty($opt)) $this->opt = 'username'; |
|
852 | 852 | $this->value = -$value; |
853 | 853 | return $this->includeMdfFile('moduser'); |
854 | 854 | ##### Special functions |
@@ -859,27 +859,27 @@ discard block |
||
859 | 859 | case 'ifnotempty': |
860 | 860 | if (!empty($value)) return $opt; break; |
861 | 861 | case 'datagrid': |
862 | - include_once(MODX_CORE_PATH . 'controls/datagrid.class.php'); |
|
862 | + include_once(MODX_CORE_PATH.'controls/datagrid.class.php'); |
|
863 | 863 | $grd = new DataGrid(null, trim($value)); |
864 | 864 | $grd->itemStyle = ''; |
865 | 865 | $grd->altItemStyle = ''; |
866 | - $pos = strpos($value,"\n"); |
|
867 | - if($pos) $_ = substr($value,0,$pos); |
|
866 | + $pos = strpos($value, "\n"); |
|
867 | + if ($pos) $_ = substr($value, 0, $pos); |
|
868 | 868 | else $_ = $pos; |
869 | - $grd->cdelim = strpos($_,"\t")!==false ? 'tab' : ','; |
|
869 | + $grd->cdelim = strpos($_, "\t") !== false ? 'tab' : ','; |
|
870 | 870 | return $grd->render(); |
871 | 871 | case 'rotate': |
872 | 872 | case 'evenodd': |
873 | - if(strpos($opt,',')===false) $opt = 'odd,even'; |
|
873 | + if (strpos($opt, ',') === false) $opt = 'odd,even'; |
|
874 | 874 | $_ = explode(',', $opt); |
875 | 875 | $c = count($_); |
876 | 876 | $i = $value + $c; |
877 | 877 | $i = $i % $c; |
878 | 878 | return $_[$i]; |
879 | 879 | case 'takeval': |
880 | - $arr = explode(",",$opt); |
|
880 | + $arr = explode(",", $opt); |
|
881 | 881 | $idx = $value; |
882 | - if(!is_numeric($idx)) return $value; |
|
882 | + if (!is_numeric($idx)) return $value; |
|
883 | 883 | return $arr[$idx]; |
884 | 884 | case 'getimage': |
885 | 885 | return $this->includeMdfFile('getimage'); |
@@ -887,17 +887,17 @@ discard block |
||
887 | 887 | return $modx->nicesize($value); |
888 | 888 | case 'googlemap': |
889 | 889 | case 'googlemaps': |
890 | - if(empty($opt)) $opt = 'border:none;width:500px;height:350px;'; |
|
890 | + if (empty($opt)) $opt = 'border:none;width:500px;height:350px;'; |
|
891 | 891 | $tpl = '<iframe style="[+style+]" src="https://maps.google.co.jp/maps?ll=[+value+]&output=embed&z=15"></iframe>'; |
892 | 892 | $ph['style'] = $opt; |
893 | 893 | $ph['value'] = $value; |
894 | - return $modx->parseText($tpl,$ph); |
|
894 | + return $modx->parseText($tpl, $ph); |
|
895 | 895 | case 'youtube': |
896 | 896 | case 'youtube16x9': |
897 | - if(empty($opt)) $opt = 560; |
|
898 | - $h = round($opt*0.5625); |
|
897 | + if (empty($opt)) $opt = 560; |
|
898 | + $h = round($opt * 0.5625); |
|
899 | 899 | $tpl = '<iframe width="%s" height="%s" src="https://www.youtube.com/embed/%s" frameborder="0" allowfullscreen></iframe>'; |
900 | - return sprintf($tpl,$opt,$h,$value); |
|
900 | + return sprintf($tpl, $opt, $h, $value); |
|
901 | 901 | //case 'youtube4x3':%s*0.75+25 |
902 | 902 | case 'setvar': |
903 | 903 | $modx->placeholders[$opt] = $value; |
@@ -927,7 +927,7 @@ discard block |
||
927 | 927 | return $value; |
928 | 928 | } |
929 | 929 | |
930 | - public function includeMdfFile($cmd) { |
|
930 | + public function includeMdfFile($cmd){ |
|
931 | 931 | global $modx; |
932 | 932 | $key = $this->key; |
933 | 933 | $value = $this->value; |
@@ -938,54 +938,54 @@ discard block |
||
938 | 938 | public function getValueFromElement($key, $value, $cmd, $opt) |
939 | 939 | { |
940 | 940 | global $modx; |
941 | - if( isset($modx->snippetCache[$this->elmName]) ) |
|
941 | + if (isset($modx->snippetCache[$this->elmName])) |
|
942 | 942 | { |
943 | 943 | $php = $modx->snippetCache[$this->elmName]; |
944 | 944 | } |
945 | 945 | else |
946 | 946 | { |
947 | 947 | $esc_elmName = $modx->db->escape($this->elmName); |
948 | - $result = $modx->db->select('snippet','[+prefix+]site_snippets',"name='{$esc_elmName}'"); |
|
948 | + $result = $modx->db->select('snippet', '[+prefix+]site_snippets', "name='{$esc_elmName}'"); |
|
949 | 949 | $total = $modx->db->getRecordCount($result); |
950 | - if($total == 1) |
|
950 | + if ($total == 1) |
|
951 | 951 | { |
952 | 952 | $row = $modx->db->getRow($result); |
953 | 953 | $php = $row['snippet']; |
954 | 954 | } |
955 | - elseif($total == 0) |
|
955 | + elseif ($total == 0) |
|
956 | 956 | { |
957 | 957 | $assets_path = MODX_BASE_PATH.'assets/'; |
958 | - if(is_file($assets_path."modifiers/mdf_{$cmd}.inc.php")) |
|
958 | + if (is_file($assets_path."modifiers/mdf_{$cmd}.inc.php")) |
|
959 | 959 | $modifiers_path = $assets_path."modifiers/mdf_{$cmd}.inc.php"; |
960 | - elseif(is_file($assets_path."plugins/phx/modifiers/{$cmd}.phx.php")) |
|
960 | + elseif (is_file($assets_path."plugins/phx/modifiers/{$cmd}.phx.php")) |
|
961 | 961 | $modifiers_path = $assets_path."plugins/phx/modifiers/{$cmd}.phx.php"; |
962 | - elseif(is_file(MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php")) |
|
962 | + elseif (is_file(MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php")) |
|
963 | 963 | $modifiers_path = MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php"; |
964 | 964 | else $modifiers_path = false; |
965 | 965 | |
966 | - if($modifiers_path !== false) { |
|
966 | + if ($modifiers_path !== false) { |
|
967 | 967 | $php = @file_get_contents($modifiers_path); |
968 | 968 | $php = trim($php); |
969 | - if(substr($php,0,5)==='<?php') $php = substr($php,6); |
|
970 | - if(substr($php,0,2)==='<?') $php = substr($php,3); |
|
971 | - if(substr($php,-2)==='?>') $php = substr($php,0,-2); |
|
972 | - if($this->elmName!=='') |
|
969 | + if (substr($php, 0, 5) === '<?php') $php = substr($php, 6); |
|
970 | + if (substr($php, 0, 2) === '<?') $php = substr($php, 3); |
|
971 | + if (substr($php, -2) === '?>') $php = substr($php, 0, -2); |
|
972 | + if ($this->elmName !== '') |
|
973 | 973 | $modx->snippetCache[$this->elmName.'Props'] = ''; |
974 | 974 | } |
975 | 975 | else |
976 | 976 | $php = false; |
977 | 977 | } |
978 | 978 | else $php = false; |
979 | - if($this->elmName!=='') $modx->snippetCache[$this->elmName]= $php; |
|
979 | + if ($this->elmName !== '') $modx->snippetCache[$this->elmName] = $php; |
|
980 | 980 | } |
981 | - if($php==='') $php=false; |
|
981 | + if ($php === '') $php = false; |
|
982 | 982 | |
983 | - if($php===false) $html = $modx->getChunk($this->elmName); |
|
983 | + if ($php === false) $html = $modx->getChunk($this->elmName); |
|
984 | 984 | else $html = false; |
985 | 985 | |
986 | 986 | $self = '[+output+]'; |
987 | 987 | |
988 | - if($php !== false) |
|
988 | + if ($php !== false) |
|
989 | 989 | { |
990 | 990 | ob_start(); |
991 | 991 | $options = $opt; |
@@ -998,71 +998,71 @@ discard block |
||
998 | 998 | $this->vars['options'] = & $opt; |
999 | 999 | $custom = eval($php); |
1000 | 1000 | $msg = ob_get_contents(); |
1001 | - if($value===$this->bt) $value = $msg . $custom; |
|
1001 | + if ($value === $this->bt) $value = $msg.$custom; |
|
1002 | 1002 | ob_end_clean(); |
1003 | 1003 | } |
1004 | - elseif($html!==false && isset($value) && $value!=='') |
|
1004 | + elseif ($html !== false && isset($value) && $value !== '') |
|
1005 | 1005 | { |
1006 | - $html = str_replace(array($self,'[+value+]'), $value, $html); |
|
1007 | - $value = str_replace(array('[+options+]','[+param+]'), $opt, $html); |
|
1006 | + $html = str_replace(array($self, '[+value+]'), $value, $html); |
|
1007 | + $value = str_replace(array('[+options+]', '[+param+]'), $opt, $html); |
|
1008 | 1008 | } |
1009 | 1009 | else return false; |
1010 | 1010 | |
1011 | - if($php===false && $html===false && $value!=='' |
|
1012 | - && (strpos($cmd,'[+value+]')!==false || strpos($cmd,$self)!==false)) |
|
1011 | + if ($php === false && $html === false && $value !== '' |
|
1012 | + && (strpos($cmd, '[+value+]') !== false || strpos($cmd, $self) !== false)) |
|
1013 | 1013 | { |
1014 | - $value = str_replace(array('[+value+]',$self),$value,$cmd); |
|
1014 | + $value = str_replace(array('[+value+]', $self), $value, $cmd); |
|
1015 | 1015 | } |
1016 | 1016 | return $value; |
1017 | 1017 | } |
1018 | 1018 | |
1019 | - public function parseDocumentSource($content='') |
|
1019 | + public function parseDocumentSource($content = '') |
|
1020 | 1020 | { |
1021 | 1021 | global $modx; |
1022 | 1022 | |
1023 | - if(strpos($content,'[')===false && strpos($content,'{')===false) return $content; |
|
1023 | + if (strpos($content, '[') === false && strpos($content, '{') === false) return $content; |
|
1024 | 1024 | |
1025 | - if(!$modx->maxParserPasses) $modx->maxParserPasses = 10; |
|
1026 | - $bt=''; |
|
1027 | - $i=0; |
|
1028 | - while($bt!==$content) |
|
1025 | + if (!$modx->maxParserPasses) $modx->maxParserPasses = 10; |
|
1026 | + $bt = ''; |
|
1027 | + $i = 0; |
|
1028 | + while ($bt !== $content) |
|
1029 | 1029 | { |
1030 | 1030 | $bt = $content; |
1031 | - if(strpos($content,'[*')!==false && $modx->documentIdentifier) |
|
1031 | + if (strpos($content, '[*') !== false && $modx->documentIdentifier) |
|
1032 | 1032 | $content = $modx->mergeDocumentContent($content); |
1033 | - if(strpos($content,'[(')!==false) $content = $modx->mergeSettingsContent($content); |
|
1034 | - if(strpos($content,'{{')!==false) $content = $modx->mergeChunkContent($content); |
|
1035 | - if(strpos($content,'[!')!==false) $content = str_replace(array('[!','!]'),array('[[',']]'),$content); |
|
1036 | - if(strpos($content,'[[')!==false) $content = $modx->evalSnippets($content); |
|
1033 | + if (strpos($content, '[(') !== false) $content = $modx->mergeSettingsContent($content); |
|
1034 | + if (strpos($content, '{{') !== false) $content = $modx->mergeChunkContent($content); |
|
1035 | + if (strpos($content, '[!') !== false) $content = str_replace(array('[!', '!]'), array('[[', ']]'), $content); |
|
1036 | + if (strpos($content, '[[') !== false) $content = $modx->evalSnippets($content); |
|
1037 | 1037 | |
1038 | - if($content===$bt) break; |
|
1039 | - if($modx->maxParserPasses < $i) break; |
|
1038 | + if ($content === $bt) break; |
|
1039 | + if ($modx->maxParserPasses < $i) break; |
|
1040 | 1040 | $i++; |
1041 | 1041 | } |
1042 | 1042 | return $content; |
1043 | 1043 | } |
1044 | 1044 | |
1045 | - public function getDocumentObject($target='',$field='pagetitle') |
|
1045 | + public function getDocumentObject($target = '', $field = 'pagetitle') |
|
1046 | 1046 | { |
1047 | 1047 | global $modx; |
1048 | 1048 | |
1049 | 1049 | $target = trim($target); |
1050 | - if(empty($target)) $target = $modx->config['site_start']; |
|
1051 | - if(preg_match('@^[1-9][0-9]*$@',$target)) $method='id'; |
|
1050 | + if (empty($target)) $target = $modx->config['site_start']; |
|
1051 | + if (preg_match('@^[1-9][0-9]*$@', $target)) $method = 'id'; |
|
1052 | 1052 | else $method = 'alias'; |
1053 | 1053 | |
1054 | - if(!isset($this->documentObject[$target])) |
|
1054 | + if (!isset($this->documentObject[$target])) |
|
1055 | 1055 | { |
1056 | - $this->documentObject[$target] = $modx->getDocumentObject($method,$target,'direct'); |
|
1056 | + $this->documentObject[$target] = $modx->getDocumentObject($method, $target, 'direct'); |
|
1057 | 1057 | } |
1058 | 1058 | |
1059 | - if($this->documentObject[$target]['publishedon']==='0') |
|
1059 | + if ($this->documentObject[$target]['publishedon'] === '0') |
|
1060 | 1060 | return ''; |
1061 | - elseif(isset($this->documentObject[$target][$field])) |
|
1061 | + elseif (isset($this->documentObject[$target][$field])) |
|
1062 | 1062 | { |
1063 | - if(is_array($this->documentObject[$target][$field])) |
|
1063 | + if (is_array($this->documentObject[$target][$field])) |
|
1064 | 1064 | { |
1065 | - $a = $modx->getTemplateVarOutput($field,$target); |
|
1065 | + $a = $modx->getTemplateVarOutput($field, $target); |
|
1066 | 1066 | $this->documentObject[$target][$field] = $a[$field]; |
1067 | 1067 | } |
1068 | 1068 | } |
@@ -1071,8 +1071,8 @@ discard block |
||
1071 | 1071 | return $this->documentObject[$target][$field]; |
1072 | 1072 | } |
1073 | 1073 | |
1074 | - public function setPlaceholders($value = '', $key = '', $path = '') { |
|
1075 | - if($path!=='') $key = "{$path}.{$key}"; |
|
1074 | + public function setPlaceholders($value = '', $key = '', $path = ''){ |
|
1075 | + if ($path !== '') $key = "{$path}.{$key}"; |
|
1076 | 1076 | if (is_array($value)) { |
1077 | 1077 | foreach ($value as $subkey => $subval) { |
1078 | 1078 | $this->setPlaceholders($subval, $subkey, $key); |
@@ -1082,77 +1082,77 @@ discard block |
||
1082 | 1082 | } |
1083 | 1083 | |
1084 | 1084 | // Sets a placeholder variable which can only be access by Modifiers |
1085 | - public function setModifiersVariable($key, $value) { |
|
1085 | + public function setModifiersVariable($key, $value){ |
|
1086 | 1086 | if ($key != 'phx' && $key != 'dummy') $this->placeholders[$key] = $value; |
1087 | 1087 | } |
1088 | 1088 | |
1089 | 1089 | //mbstring |
1090 | - public function substr($str, $s, $l = null) { |
|
1090 | + public function substr($str, $s, $l = null){ |
|
1091 | 1091 | global $modx; |
1092 | - if(is_null($l)) $l = $this->strlen($str); |
|
1092 | + if (is_null($l)) $l = $this->strlen($str); |
|
1093 | 1093 | if (function_exists('mb_substr')) |
1094 | 1094 | { |
1095 | - if(strpos($str,"\r")!==false) |
|
1096 | - $str = str_replace(array("\r\n","\r"), "\n", $str); |
|
1095 | + if (strpos($str, "\r") !== false) |
|
1096 | + $str = str_replace(array("\r\n", "\r"), "\n", $str); |
|
1097 | 1097 | return mb_substr($str, $s, $l, $modx->config['modx_charset']); |
1098 | 1098 | } |
1099 | 1099 | return substr($str, $s, $l); |
1100 | 1100 | } |
1101 | - public function strpos($haystack,$needle,$offset=0) { |
|
1101 | + public function strpos($haystack, $needle, $offset = 0){ |
|
1102 | 1102 | global $modx; |
1103 | - if (function_exists('mb_strpos')) return mb_strpos($haystack,$needle,$offset,$modx->config['modx_charset']); |
|
1104 | - return strpos($haystack,$needle,$offset); |
|
1103 | + if (function_exists('mb_strpos')) return mb_strpos($haystack, $needle, $offset, $modx->config['modx_charset']); |
|
1104 | + return strpos($haystack, $needle, $offset); |
|
1105 | 1105 | } |
1106 | - public function strlen($str) { |
|
1106 | + public function strlen($str){ |
|
1107 | 1107 | global $modx; |
1108 | - if (function_exists('mb_strlen')) return mb_strlen(str_replace("\r\n", "\n", $str),$modx->config['modx_charset']); |
|
1108 | + if (function_exists('mb_strlen')) return mb_strlen(str_replace("\r\n", "\n", $str), $modx->config['modx_charset']); |
|
1109 | 1109 | return strlen($str); |
1110 | 1110 | } |
1111 | - public function strtolower($str) { |
|
1111 | + public function strtolower($str){ |
|
1112 | 1112 | if (function_exists('mb_strtolower')) return mb_strtolower($str); |
1113 | 1113 | return strtolower($str); |
1114 | 1114 | } |
1115 | - public function strtoupper($str) { |
|
1115 | + public function strtoupper($str){ |
|
1116 | 1116 | if (function_exists('mb_strtoupper')) return mb_strtoupper($str); |
1117 | 1117 | return strtoupper($str); |
1118 | 1118 | } |
1119 | - public function ucfirst($str) { |
|
1119 | + public function ucfirst($str){ |
|
1120 | 1120 | if (function_exists('mb_strtoupper')) |
1121 | 1121 | return mb_strtoupper($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str)); |
1122 | 1122 | return ucfirst($str); |
1123 | 1123 | } |
1124 | - public function lcfirst($str) { |
|
1124 | + public function lcfirst($str){ |
|
1125 | 1125 | if (function_exists('mb_strtolower')) |
1126 | 1126 | return mb_strtolower($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str)); |
1127 | 1127 | return lcfirst($str); |
1128 | 1128 | } |
1129 | - public function ucwords($str) { |
|
1129 | + public function ucwords($str){ |
|
1130 | 1130 | if (function_exists('mb_convert_case')) |
1131 | 1131 | return mb_convert_case($str, MB_CASE_TITLE); |
1132 | 1132 | return ucwords($str); |
1133 | 1133 | } |
1134 | - public function strrev($str) { |
|
1134 | + public function strrev($str){ |
|
1135 | 1135 | preg_match_all('/./us', $str, $ar); |
1136 | 1136 | return implode(array_reverse($ar[0])); |
1137 | 1137 | } |
1138 | - public function str_shuffle($str) { |
|
1138 | + public function str_shuffle($str){ |
|
1139 | 1139 | preg_match_all('/./us', $str, $ar); |
1140 | 1140 | shuffle($ar[0]); |
1141 | 1141 | return implode($ar[0]); |
1142 | 1142 | } |
1143 | - public function str_word_count($str) { |
|
1144 | - return count(preg_split('~[^\p{L}\p{N}\']+~u',$str)); |
|
1143 | + public function str_word_count($str){ |
|
1144 | + return count(preg_split('~[^\p{L}\p{N}\']+~u', $str)); |
|
1145 | 1145 | } |
1146 | - public function strip_tags($value,$params='') { |
|
1146 | + public function strip_tags($value, $params = ''){ |
|
1147 | 1147 | global $modx; |
1148 | 1148 | |
1149 | - if(stripos($params,'style')===false && stripos($value,'</style>')!==false) { |
|
1149 | + if (stripos($params, 'style') === false && stripos($value, '</style>') !== false) { |
|
1150 | 1150 | $value = preg_replace('@<style.*?>.*?</style>@is', '', $value); |
1151 | 1151 | } |
1152 | - if(stripos($params,'script')===false && stripos($value,'</script>')!==false) { |
|
1152 | + if (stripos($params, 'script') === false && stripos($value, '</script>') !== false) { |
|
1153 | 1153 | $value = preg_replace('@<script.*?>.*?</script>@is', '', $value); |
1154 | 1154 | } |
1155 | 1155 | |
1156 | - return trim(strip_tags($value,$params)); |
|
1156 | + return trim(strip_tags($value, $params)); |
|
1157 | 1157 | } |
1158 | 1158 | } |
@@ -1,8 +1,11 @@ discard block |
||
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 | public $placeholders = array(); |
8 | 11 | public $vars = array(); |
@@ -26,14 +29,18 @@ discard block |
||
26 | 29 | { |
27 | 30 | global $modx; |
28 | 31 | |
29 | - if (function_exists('mb_internal_encoding')) mb_internal_encoding($modx->config['modx_charset']); |
|
32 | + if (function_exists('mb_internal_encoding')) { |
|
33 | + mb_internal_encoding($modx->config['modx_charset']); |
|
34 | + } |
|
30 | 35 | $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'; |
31 | 36 | } |
32 | 37 | |
33 | 38 | public function phxFilter($key,$value,$modifiers) |
34 | 39 | { |
35 | 40 | global $modx; |
36 | - if(substr($modifiers,0,3)!=='id(') $value = $this->parseDocumentSource($value); |
|
41 | + if(substr($modifiers,0,3)!=='id(') { |
|
42 | + $value = $this->parseDocumentSource($value); |
|
43 | + } |
|
37 | 44 | $this->srcValue = $value; |
38 | 45 | $modifiers = trim($modifiers); |
39 | 46 | $modifiers = ':'.trim($modifiers,':'); |
@@ -51,63 +58,81 @@ discard block |
||
51 | 58 | return $value; |
52 | 59 | } |
53 | 60 | |
54 | - public function _getDelim($mode,$modifiers) { |
|
61 | + public function _getDelim($mode,$modifiers) |
|
62 | + { |
|
55 | 63 | $c = substr($modifiers,0,1); |
56 | - if(!in_array($c, array('"', "'", '`')) ) return false; |
|
64 | + if(!in_array($c, array('"', "'", '`')) ) { |
|
65 | + return false; |
|
66 | + } |
|
57 | 67 | |
58 | 68 | $modifiers = substr($modifiers,1); |
59 | 69 | $closure = $mode=='(' ? "{$c})" : $c; |
60 | - if(strpos($modifiers, $closure)===false) return false; |
|
70 | + if(strpos($modifiers, $closure)===false) { |
|
71 | + return false; |
|
72 | + } |
|
61 | 73 | |
62 | 74 | return $c; |
63 | 75 | } |
64 | 76 | |
65 | - public function _getOpt($mode,$delim,$modifiers) { |
|
77 | + public function _getOpt($mode,$delim,$modifiers) |
|
78 | + { |
|
66 | 79 | if($delim) { |
67 | - if($mode=='(') return substr($modifiers,1,strpos($modifiers, $delim . ')' )-1); |
|
80 | + if($mode=='(') { |
|
81 | + return substr($modifiers,1,strpos($modifiers, $delim . ')' )-1); |
|
82 | + } |
|
68 | 83 | |
69 | 84 | return substr($modifiers,1,strpos($modifiers,$delim,1)-1); |
70 | - } |
|
71 | - else { |
|
72 | - if($mode=='(') return substr($modifiers,0,strpos($modifiers, ')') ); |
|
85 | + } else { |
|
86 | + if($mode=='(') { |
|
87 | + return substr($modifiers,0,strpos($modifiers, ')') ); |
|
88 | + } |
|
73 | 89 | |
74 | 90 | $chars = str_split($modifiers); |
75 | 91 | $opt=''; |
76 | 92 | foreach($chars as $c) { |
77 | - if($c==':' || $c==')') break; |
|
93 | + if($c==':' || $c==')') { |
|
94 | + break; |
|
95 | + } |
|
78 | 96 | $opt .=$c; |
79 | 97 | } |
80 | 98 | return $opt; |
81 | 99 | } |
82 | 100 | } |
83 | - public function _getRemainModifiers($mode,$delim,$modifiers) { |
|
101 | + public function _getRemainModifiers($mode,$delim,$modifiers) |
|
102 | + { |
|
84 | 103 | if($delim) { |
85 | - if($mode=='(') |
|
86 | - return $this->_fetchContent($modifiers, $delim . ')'); |
|
87 | - else { |
|
104 | + if($mode=='(') { |
|
105 | + return $this->_fetchContent($modifiers, $delim . ')'); |
|
106 | + } else { |
|
88 | 107 | $modifiers = trim($modifiers); |
89 | 108 | $modifiers = substr($modifiers,1); |
90 | 109 | return $this->_fetchContent($modifiers, $delim); |
91 | 110 | } |
92 | - } |
|
93 | - else { |
|
94 | - if($mode=='(') return $this->_fetchContent($modifiers, ')'); |
|
111 | + } else { |
|
112 | + if($mode=='(') { |
|
113 | + return $this->_fetchContent($modifiers, ')'); |
|
114 | + } |
|
95 | 115 | $chars = str_split($modifiers); |
96 | 116 | foreach($chars as $c) { |
97 | - if($c==':') return $modifiers; |
|
98 | - else $modifiers = substr($modifiers,1); |
|
117 | + if($c==':') { |
|
118 | + return $modifiers; |
|
119 | + } else { |
|
120 | + $modifiers = substr($modifiers,1); |
|
121 | + } |
|
99 | 122 | } |
100 | 123 | return $modifiers; |
101 | 124 | } |
102 | 125 | } |
103 | 126 | |
104 | - public function _fetchContent($string,$delim) { |
|
127 | + public function _fetchContent($string,$delim) |
|
128 | + { |
|
105 | 129 | $len = strlen($delim); |
106 | 130 | $string = $this->parseDocumentSource($string); |
107 | 131 | return substr($string,strpos($string, $delim)+$len); |
108 | 132 | } |
109 | 133 | |
110 | - public function splitEachModifiers($modifiers) { |
|
134 | + public function splitEachModifiers($modifiers) |
|
135 | + { |
|
111 | 136 | global $modx; |
112 | 137 | |
113 | 138 | $cmd = ''; |
@@ -118,11 +143,15 @@ discard block |
||
118 | 143 | $c = substr($modifiers,0,1); |
119 | 144 | $modifiers = substr($modifiers,1); |
120 | 145 | |
121 | - if($c===':' && preg_match('@^(!?[<>=]{1,2})@', $modifiers, $match)) { // :=, :!=, :<=, :>=, :!<=, :!>= |
|
146 | + if($c===':' && preg_match('@^(!?[<>=]{1,2})@', $modifiers, $match)) { |
|
147 | +// :=, :!=, :<=, :>=, :!<=, :!>= |
|
122 | 148 | $c = substr($modifiers,strlen($match[1]),1); |
123 | 149 | $debuginfo = "#i=0 #c=[{$c}] #m=[{$modifiers}]"; |
124 | - if($c==='(') $modifiers = substr($modifiers,strlen($match[1])+1); |
|
125 | - else $modifiers = substr($modifiers,strlen($match[1])); |
|
150 | + if($c==='(') { |
|
151 | + $modifiers = substr($modifiers,strlen($match[1])+1); |
|
152 | + } else { |
|
153 | + $modifiers = substr($modifiers,strlen($match[1])); |
|
154 | + } |
|
126 | 155 | |
127 | 156 | $delim = $this->_getDelim($c,$modifiers); |
128 | 157 | $opt = $this->_getOpt($c,$delim,$modifiers); |
@@ -130,13 +159,12 @@ discard block |
||
130 | 159 | |
131 | 160 | $result[]=array('cmd'=>trim($match[1]),'opt'=>$opt,'debuginfo'=>$debuginfo); |
132 | 161 | $cmd = ''; |
133 | - } |
|
134 | - elseif(in_array($c,array('+','-','*','/')) && preg_match('@^[0-9]+@', $modifiers, $match)) { // :+3, :-3, :*3 ... |
|
162 | + } elseif(in_array($c,array('+','-','*','/')) && preg_match('@^[0-9]+@', $modifiers, $match)) { |
|
163 | +// :+3, :-3, :*3 ... |
|
135 | 164 | $modifiers = substr($modifiers,strlen($match[0])); |
136 | 165 | $result[]=array('cmd'=>'math','opt'=>'%s'.$c.$match[0]); |
137 | 166 | $cmd = ''; |
138 | - } |
|
139 | - elseif($c==='(' || $c==='=') { |
|
167 | + } elseif($c==='(' || $c==='=') { |
|
140 | 168 | $modifiers = $m1 = trim($modifiers); |
141 | 169 | $delim = $this->_getDelim($c,$modifiers); |
142 | 170 | $opt = $this->_getOpt($c,$delim,$modifiers); |
@@ -146,29 +174,29 @@ discard block |
||
146 | 174 | $result[]=array('cmd'=>trim($cmd),'opt'=>$opt,'debuginfo'=>$debuginfo); |
147 | 175 | |
148 | 176 | $cmd = ''; |
149 | - } |
|
150 | - elseif($c==':') { |
|
177 | + } elseif($c==':') { |
|
151 | 178 | $debuginfo = "#i=2 #c=[{$c}] #m=[{$modifiers}]"; |
152 | - if($cmd!=='') $result[]=array('cmd'=>trim($cmd),'opt'=>'','debuginfo'=>$debuginfo); |
|
179 | + if($cmd!=='') { |
|
180 | + $result[]=array('cmd'=>trim($cmd),'opt'=>'','debuginfo'=>$debuginfo); |
|
181 | + } |
|
153 | 182 | |
154 | 183 | $cmd = ''; |
155 | - } |
|
156 | - elseif(trim($modifiers)=='' && trim($cmd)!=='') { |
|
184 | + } elseif(trim($modifiers)=='' && trim($cmd)!=='') { |
|
157 | 185 | $debuginfo = "#i=3 #c=[{$c}] #m=[{$modifiers}]"; |
158 | 186 | $cmd .= $c; |
159 | 187 | $result[]=array('cmd'=>trim($cmd),'opt'=>'','debuginfo'=>$debuginfo); |
160 | 188 | |
161 | 189 | break; |
162 | - } |
|
163 | - else { |
|
190 | + } else { |
|
164 | 191 | $cmd .= $c; |
165 | 192 | } |
166 | 193 | } |
167 | 194 | |
168 | - if(empty($result)) return array(); |
|
195 | + if(empty($result)) { |
|
196 | + return array(); |
|
197 | + } |
|
169 | 198 | |
170 | - foreach($result as $i=>$a) |
|
171 | - { |
|
199 | + foreach($result as $i=>$a) { |
|
172 | 200 | $a['opt'] = $this->parseDocumentSource($a['opt']); |
173 | 201 | $result[$i]['opt'] = $modx->mergePlaceholderContent($a['opt'],$this->placeholders); |
174 | 202 | } |
@@ -181,22 +209,23 @@ discard block |
||
181 | 209 | global $modx; |
182 | 210 | $lastKey = ''; |
183 | 211 | $cacheKey = md5(sprintf('parsePhx#%s#%s#%s',$key,$value,print_r($modifiers,true))); |
184 | - if(isset($this->tmpCache[$cacheKey])) return $this->tmpCache[$cacheKey]; |
|
185 | - if(empty($modifiers)) return ''; |
|
212 | + if(isset($this->tmpCache[$cacheKey])) { |
|
213 | + return $this->tmpCache[$cacheKey]; |
|
214 | + } |
|
215 | + if(empty($modifiers)) { |
|
216 | + return ''; |
|
217 | + } |
|
186 | 218 | |
187 | - foreach($modifiers as $m) |
|
188 | - { |
|
219 | + foreach($modifiers as $m) { |
|
189 | 220 | $lastKey = strtolower($m['cmd']); |
190 | 221 | } |
191 | 222 | $_ = explode(',',$this->condModifiers); |
192 | - if(in_array($lastKey,$_)) |
|
193 | - { |
|
223 | + if(in_array($lastKey,$_)) { |
|
194 | 224 | $modifiers[] = array('cmd'=>'then','opt'=>'1'); |
195 | 225 | $modifiers[] = array('cmd'=>'else','opt'=>'0'); |
196 | 226 | } |
197 | 227 | |
198 | - foreach($modifiers as $i=>$a) |
|
199 | - { |
|
228 | + foreach($modifiers as $i=>$a) { |
|
200 | 229 | $value = $this->Filter($key,$value, $a['cmd'], $a['opt']); |
201 | 230 | } |
202 | 231 | $this->tmpCache[$cacheKey] = $value; |
@@ -208,25 +237,32 @@ discard block |
||
208 | 237 | { |
209 | 238 | global $modx; |
210 | 239 | |
211 | - if($key==='documentObject') $value = $modx->documentIdentifier; |
|
240 | + if($key==='documentObject') { |
|
241 | + $value = $modx->documentIdentifier; |
|
242 | + } |
|
212 | 243 | $cmd = $this->parseDocumentSource($cmd); |
213 | - if(preg_match('@^[1-9][/0-9]*$@',$cmd)) |
|
214 | - { |
|
215 | - if(strpos($cmd,'/')!==false) |
|
216 | - $cmd = $this->substr($cmd,strrpos($cmd,'/')+1); |
|
244 | + if(preg_match('@^[1-9][/0-9]*$@',$cmd)) { |
|
245 | + if(strpos($cmd,'/')!==false) { |
|
246 | + $cmd = $this->substr($cmd,strrpos($cmd,'/')+1); |
|
247 | + } |
|
217 | 248 | $opt = $cmd; |
218 | 249 | $cmd = 'id'; |
219 | 250 | } |
220 | 251 | |
221 | - if(isset($modx->snippetCache["phx:{$cmd}"])) $this->elmName = "phx:{$cmd}"; |
|
222 | - elseif(isset($modx->chunkCache["phx:{$cmd}"])) $this->elmName = "phx:{$cmd}"; |
|
223 | - else $this->elmName = ''; |
|
252 | + if(isset($modx->snippetCache["phx:{$cmd}"])) { |
|
253 | + $this->elmName = "phx:{$cmd}"; |
|
254 | + } elseif(isset($modx->chunkCache["phx:{$cmd}"])) { |
|
255 | + $this->elmName = "phx:{$cmd}"; |
|
256 | + } else { |
|
257 | + $this->elmName = ''; |
|
258 | + } |
|
224 | 259 | |
225 | 260 | $cmd = strtolower($cmd); |
226 | - if($this->elmName!=='') |
|
227 | - $value = $this->getValueFromElement($key, $value, $cmd, $opt); |
|
228 | - else |
|
229 | - $value = $this->getValueFromPreset($key, $value, $cmd, $opt); |
|
261 | + if($this->elmName!=='') { |
|
262 | + $value = $this->getValueFromElement($key, $value, $cmd, $opt); |
|
263 | + } else { |
|
264 | + $value = $this->getValueFromPreset($key, $value, $cmd, $opt); |
|
265 | + } |
|
230 | 266 | |
231 | 267 | $value = str_replace('[+key+]', $key, $value); |
232 | 268 | |
@@ -235,29 +271,37 @@ discard block |
||
235 | 271 | |
236 | 272 | public function isEmpty($cmd,$value) |
237 | 273 | { |
238 | - if($value!=='') return false; |
|
274 | + if($value!=='') { |
|
275 | + return false; |
|
276 | + } |
|
239 | 277 | |
240 | 278 | $_ = explode(',', $this->condModifiers . ',_default,default,if,input,or,and,show,this,select,switch,then,else,id,ifempty,smart_desc,smart_description,summary'); |
241 | - if(in_array($cmd,$_)) return false; |
|
242 | - else return true; |
|
279 | + if(in_array($cmd,$_)) { |
|
280 | + return false; |
|
281 | + } else { |
|
282 | + return true; |
|
283 | + } |
|
243 | 284 | } |
244 | 285 | |
245 | 286 | public function getValueFromPreset($key, $value, $cmd, $opt) |
246 | 287 | { |
247 | 288 | global $modx; |
248 | 289 | |
249 | - if($this->isEmpty($cmd,$value)) return ''; |
|
290 | + if($this->isEmpty($cmd,$value)) { |
|
291 | + return ''; |
|
292 | + } |
|
250 | 293 | |
251 | 294 | $this->key = $key; |
252 | 295 | $this->value = $value; |
253 | 296 | $this->opt = $opt; |
254 | 297 | |
255 | - switch ($cmd) |
|
256 | - { |
|
298 | + switch ($cmd) { |
|
257 | 299 | ##### Conditional Modifiers |
258 | 300 | case 'input': |
259 | 301 | case 'if': |
260 | - if(!$opt) return $value; |
|
302 | + if(!$opt) { |
|
303 | + return $value; |
|
304 | + } |
|
261 | 305 | return $opt; |
262 | 306 | case '=': |
263 | 307 | case 'eq': |
@@ -318,14 +362,24 @@ discard block |
||
318 | 362 | case 'file_exists': |
319 | 363 | case 'is_readable': |
320 | 364 | case 'is_writable': |
321 | - if(!$opt) $path = $value; |
|
322 | - else $path = $opt; |
|
323 | - if(strpos($path,MODX_MANAGER_PATH)!==false) exit('Can not read core path'); |
|
324 | - if(strpos($path,$modx->config['base_path'])===false) $path = ltrim($path,'/'); |
|
365 | + if(!$opt) { |
|
366 | + $path = $value; |
|
367 | + } else { |
|
368 | + $path = $opt; |
|
369 | + } |
|
370 | + if(strpos($path,MODX_MANAGER_PATH)!==false) { |
|
371 | + exit('Can not read core path'); |
|
372 | + } |
|
373 | + if(strpos($path,$modx->config['base_path'])===false) { |
|
374 | + $path = ltrim($path,'/'); |
|
375 | + } |
|
325 | 376 | $this->condition[] = (int)($cmd($path)!==false);break; |
326 | 377 | case 'is_image': |
327 | - if(!$opt) $path = $value; |
|
328 | - else $path = $opt; |
|
378 | + if(!$opt) { |
|
379 | + $path = $value; |
|
380 | + } else { |
|
381 | + $path = $opt; |
|
382 | + } |
|
329 | 383 | if(!is_file($path)) {$this->condition[]='0';break;} |
330 | 384 | $_ = getimagesize($path); |
331 | 385 | $this->condition[] = (int)($_[0]);break; |
@@ -348,17 +402,23 @@ discard block |
||
348 | 402 | case 'this': |
349 | 403 | $conditional = implode(' ',$this->condition); |
350 | 404 | $isvalid = (int)(eval("return ({$conditional});")); |
351 | - if ($isvalid) return $this->srcValue; |
|
405 | + if ($isvalid) { |
|
406 | + return $this->srcValue; |
|
407 | + } |
|
352 | 408 | return NULL; |
353 | 409 | case 'then': |
354 | 410 | $conditional = implode(' ',$this->condition); |
355 | 411 | $isvalid = (int)eval("return ({$conditional});"); |
356 | - if ($isvalid) return $opt; |
|
412 | + if ($isvalid) { |
|
413 | + return $opt; |
|
414 | + } |
|
357 | 415 | return null; |
358 | 416 | case 'else': |
359 | 417 | $conditional = implode(' ',$this->condition); |
360 | 418 | $isvalid = (int)eval("return ({$conditional});"); |
361 | - if (!$isvalid) return $opt; |
|
419 | + if (!$isvalid) { |
|
420 | + return $opt; |
|
421 | + } |
|
362 | 422 | break; |
363 | 423 | case 'select': |
364 | 424 | case 'switch': |
@@ -369,8 +429,11 @@ discard block |
||
369 | 429 | $mi = explode('=',$raw[$m],2); |
370 | 430 | $map[$mi[0]] = $mi[1]; |
371 | 431 | } |
372 | - if(isset($map[$value])) return $map[$value]; |
|
373 | - else return ''; |
|
432 | + if(isset($map[$value])) { |
|
433 | + return $map[$value]; |
|
434 | + } else { |
|
435 | + return ''; |
|
436 | + } |
|
374 | 437 | ##### End of Conditional Modifiers |
375 | 438 | |
376 | 439 | ##### Encode / Decode / Hash / Escape |
@@ -396,24 +459,25 @@ discard block |
||
396 | 459 | case 'spam_protect': |
397 | 460 | return str_replace(array('@','.'),array('@','.'),$value); |
398 | 461 | case 'strip': |
399 | - if($opt==='') $opt = ' '; |
|
462 | + if($opt==='') { |
|
463 | + $opt = ' '; |
|
464 | + } |
|
400 | 465 | return preg_replace('/[\n\r\t\s]+/', $opt, $value); |
401 | 466 | case 'strip_linefeeds': |
402 | 467 | return str_replace(array("\n","\r"), '', $value); |
403 | 468 | case 'notags': |
404 | 469 | case 'strip_tags': |
405 | 470 | case 'remove_html': |
406 | - if($opt!=='') |
|
407 | - { |
|
471 | + if($opt!=='') { |
|
408 | 472 | $param = array(); |
409 | - foreach(explode(',',$opt) as $v) |
|
410 | - { |
|
473 | + foreach(explode(',',$opt) as $v) { |
|
411 | 474 | $v = trim($v,'</> '); |
412 | 475 | $param[] = "<{$v}>"; |
413 | 476 | } |
414 | 477 | $params = implode(',',$param); |
478 | + } else { |
|
479 | + $params = ''; |
|
415 | 480 | } |
416 | - else $params = ''; |
|
417 | 481 | if(!strpos($params,'<br>')===false) { |
418 | 482 | $value = preg_replace('@(<br[ /]*>)\n@','$1',$value); |
419 | 483 | $value = preg_replace('@<br[ /]*>@',"\n",$value); |
@@ -424,8 +488,11 @@ discard block |
||
424 | 488 | case 'encode_url': |
425 | 489 | return urlencode($value); |
426 | 490 | case 'base64_decode': |
427 | - if($opt!=='false') $opt = true; |
|
428 | - else $opt = false; |
|
491 | + if($opt!=='false') { |
|
492 | + $opt = true; |
|
493 | + } else { |
|
494 | + $opt = false; |
|
495 | + } |
|
429 | 496 | return base64_decode($value,$opt); |
430 | 497 | case 'encode_sha1': $cmd = 'sha1'; |
431 | 498 | case 'addslashes': |
@@ -451,16 +518,19 @@ discard block |
||
451 | 518 | return $this->strtoupper($value); |
452 | 519 | case 'capitalize': |
453 | 520 | $_ = explode(' ',$value); |
454 | - foreach($_ as $i=>$v) |
|
455 | - { |
|
521 | + foreach($_ as $i=>$v) { |
|
456 | 522 | $_[$i] = ucfirst($v); |
457 | 523 | } |
458 | 524 | return implode(' ',$_); |
459 | 525 | case 'zenhan': |
460 | - if(empty($opt)) $opt='VKas'; |
|
526 | + if(empty($opt)) { |
|
527 | + $opt='VKas'; |
|
528 | + } |
|
461 | 529 | return mb_convert_kana($value,$opt,$modx->config['modx_charset']); |
462 | 530 | case 'hanzen': |
463 | - if(empty($opt)) $opt='VKAS'; |
|
531 | + if(empty($opt)) { |
|
532 | + $opt='VKAS'; |
|
533 | + } |
|
464 | 534 | return mb_convert_kana($value,$opt,$modx->config['modx_charset']); |
465 | 535 | case 'str_shuffle': |
466 | 536 | case 'shuffle': |
@@ -485,13 +555,18 @@ discard block |
||
485 | 555 | $value = preg_replace('/\r/', '', $value); |
486 | 556 | return count(preg_split('/\n+/',$value)); |
487 | 557 | case 'strpos': |
488 | - if($opt!=0&&empty($opt)) return $value; |
|
558 | + if($opt!=0&&empty($opt)) { |
|
559 | + return $value; |
|
560 | + } |
|
489 | 561 | return $this->strpos($value,$opt); |
490 | 562 | case 'wordwrap': |
491 | 563 | // default: 70 |
492 | 564 | $wrapat = (int)$opt > 0 ? (int)$opt : 70; |
493 | - if (version_compare(PHP_VERSION, '5.3.0') >= 0) return $this->includeMdfFile('wordwrap'); |
|
494 | - else return preg_replace("@(\b\w+\b)@e","wordwrap('\\1',\$wrapat,' ',1)",$value); |
|
565 | + if (version_compare(PHP_VERSION, '5.3.0') >= 0) { |
|
566 | + return $this->includeMdfFile('wordwrap'); |
|
567 | + } else { |
|
568 | + return preg_replace("@(\b\w+\b)@e","wordwrap('\\1',\$wrapat,' ',1)",$value); |
|
569 | + } |
|
495 | 570 | case 'wrap_text': |
496 | 571 | $width = preg_match('/^[1-9][0-9]*$/',$opt) ? $opt : 70; |
497 | 572 | if($modx->config['manager_language']==='japanese-utf8') { |
@@ -507,30 +582,36 @@ discard block |
||
507 | 582 | $value = $this->substr($value,$width); |
508 | 583 | } |
509 | 584 | return implode("\n",$chunk); |
585 | + } else { |
|
586 | + return wordwrap($value,$width,"\n",true); |
|
510 | 587 | } |
511 | - else |
|
512 | - return wordwrap($value,$width,"\n",true); |
|
513 | 588 | case 'substr': |
514 | - if(empty($opt)) break; |
|
589 | + if(empty($opt)) { |
|
590 | + break; |
|
591 | + } |
|
515 | 592 | if(strpos($opt,',')!==false) { |
516 | 593 | list($b,$e) = explode(',',$opt,2); |
517 | 594 | return $this->substr($value,$b,(int)$e); |
595 | + } else { |
|
596 | + return $this->substr($value,$opt); |
|
518 | 597 | } |
519 | - else return $this->substr($value,$opt); |
|
520 | 598 | case 'limit': |
521 | 599 | case 'trim_to': // http://www.movabletype.jp/documentation/appendices/modifiers/trim_to.html |
522 | - if(strpos($opt,'+')!==false) |
|
523 | - list($len,$str) = explode('+',$opt,2); |
|
524 | - else { |
|
600 | + if(strpos($opt,'+')!==false) { |
|
601 | + list($len,$str) = explode('+',$opt,2); |
|
602 | + } else { |
|
525 | 603 | $len = $opt; |
526 | 604 | $str = ''; |
527 | 605 | } |
528 | - if($len==='') $len = 100; |
|
529 | - if(abs($len) > $this->strlen($value)) $str =''; |
|
606 | + if($len==='') { |
|
607 | + $len = 100; |
|
608 | + } |
|
609 | + if(abs($len) > $this->strlen($value)) { |
|
610 | + $str =''; |
|
611 | + } |
|
530 | 612 | if(preg_match('/^[1-9][0-9]*$/',$len)) { |
531 | 613 | return $this->substr($value,0,$len) . $str; |
532 | - } |
|
533 | - elseif(preg_match('/^\-[1-9][0-9]*$/',$len)) { |
|
614 | + } elseif(preg_match('/^\-[1-9][0-9]*$/',$len)) { |
|
534 | 615 | return $str . $this->substr($value,$len); |
535 | 616 | } |
536 | 617 | break; |
@@ -540,18 +621,30 @@ discard block |
||
540 | 621 | return $this->includeMdfFile('summary'); |
541 | 622 | case 'replace': |
542 | 623 | case 'str_replace': |
543 | - if(empty($opt) || strpos($opt,',')===false) break; |
|
544 | - if (substr_count($opt, ',') ==1) $delim = ','; |
|
545 | - elseif(substr_count($opt, '|') ==1) $delim = '|'; |
|
546 | - elseif(substr_count($opt, '=>')==1) $delim = '=>'; |
|
547 | - elseif(substr_count($opt, '/') ==1) $delim = '/'; |
|
548 | - else break; |
|
624 | + if(empty($opt) || strpos($opt,',')===false) { |
|
625 | + break; |
|
626 | + } |
|
627 | + if (substr_count($opt, ',') ==1) { |
|
628 | + $delim = ','; |
|
629 | + } elseif(substr_count($opt, '|') ==1) { |
|
630 | + $delim = '|'; |
|
631 | + } elseif(substr_count($opt, '=>')==1) { |
|
632 | + $delim = '=>'; |
|
633 | + } elseif(substr_count($opt, '/') ==1) { |
|
634 | + $delim = '/'; |
|
635 | + } else { |
|
636 | + break; |
|
637 | + } |
|
549 | 638 | list($s,$r) = explode($delim,$opt); |
550 | - if($value!=='') return str_replace($s,$r,$value); |
|
639 | + if($value!=='') { |
|
640 | + return str_replace($s,$r,$value); |
|
641 | + } |
|
551 | 642 | break; |
552 | 643 | case 'replace_to': |
553 | 644 | case 'tpl': |
554 | - if($value!=='') return str_replace(array('[+value+]','[+output+]','{value}','%s'),$value,$opt); |
|
645 | + if($value!=='') { |
|
646 | + return str_replace(array('[+value+]','[+output+]','{value}','%s'),$value,$opt); |
|
647 | + } |
|
555 | 648 | break; |
556 | 649 | case 'eachtpl': |
557 | 650 | $value = explode('||',$value); |
@@ -562,59 +655,83 @@ discard block |
||
562 | 655 | return implode("\n", $_); |
563 | 656 | case 'array_pop': |
564 | 657 | case 'array_shift': |
565 | - if(strpos($value,'||')!==false) $delim = '||'; |
|
566 | - else $delim = ','; |
|
658 | + if(strpos($value,'||')!==false) { |
|
659 | + $delim = '||'; |
|
660 | + } else { |
|
661 | + $delim = ','; |
|
662 | + } |
|
567 | 663 | return $cmd(explode($delim,$value)); |
568 | 664 | case 'preg_replace': |
569 | 665 | case 'regex_replace': |
570 | - if(empty($opt) || strpos($opt,',')===false) break; |
|
666 | + if(empty($opt) || strpos($opt,',')===false) { |
|
667 | + break; |
|
668 | + } |
|
571 | 669 | list($s,$r) = explode(',',$opt,2); |
572 | - if($value!=='') return preg_replace($s,$r,$value); |
|
670 | + if($value!=='') { |
|
671 | + return preg_replace($s,$r,$value); |
|
672 | + } |
|
573 | 673 | break; |
574 | 674 | case 'cat': |
575 | 675 | case 'concatenate': |
576 | 676 | case '.': |
577 | - if($value!=='') return $value . $opt; |
|
677 | + if($value!=='') { |
|
678 | + return $value . $opt; |
|
679 | + } |
|
578 | 680 | break; |
579 | 681 | case 'sprintf': |
580 | 682 | case 'string_format': |
581 | - if($value!=='') return sprintf($opt,$value); |
|
683 | + if($value!=='') { |
|
684 | + return sprintf($opt,$value); |
|
685 | + } |
|
582 | 686 | break; |
583 | 687 | case 'number_format': |
584 | - if($opt=='') $opt = 0; |
|
688 | + if($opt=='') { |
|
689 | + $opt = 0; |
|
690 | + } |
|
585 | 691 | return number_format($value,$opt); |
586 | 692 | case 'money_format': |
587 | 693 | setlocale(LC_MONETARY,setlocale(LC_TIME,0)); |
588 | - if($value!=='') return money_format($opt,(double)$value); |
|
694 | + if($value!=='') { |
|
695 | + return money_format($opt,(double)$value); |
|
696 | + } |
|
589 | 697 | break; |
590 | 698 | case 'tobool': |
591 | 699 | return boolval($value); |
592 | 700 | case 'nl2lf': |
593 | - if($value!=='') return str_replace(array("\r\n","\n", "\r"), '\n', $value); |
|
701 | + if($value!=='') { |
|
702 | + return str_replace(array("\r\n","\n", "\r"), '\n', $value); |
|
703 | + } |
|
594 | 704 | break; |
595 | 705 | case 'br2nl': |
596 | 706 | return preg_replace('@<br[\s/]*>@i', "\n", $value); |
597 | 707 | case 'nl2br': |
598 | - if (version_compare(PHP_VERSION, '5.3.0', '<')) |
|
599 | - return nl2br($value); |
|
600 | - if($opt!=='') |
|
601 | - { |
|
708 | + if (version_compare(PHP_VERSION, '5.3.0', '<')) { |
|
709 | + return nl2br($value); |
|
710 | + } |
|
711 | + if($opt!=='') { |
|
602 | 712 | $opt = trim($opt); |
603 | 713 | $opt = strtolower($opt); |
604 | - if($opt==='false') $opt = false; |
|
605 | - elseif($opt==='0') $opt = false; |
|
606 | - else $opt = true; |
|
714 | + if($opt==='false') { |
|
715 | + $opt = false; |
|
716 | + } elseif($opt==='0') { |
|
717 | + $opt = false; |
|
718 | + } else { |
|
719 | + $opt = true; |
|
720 | + } |
|
721 | + } elseif(isset($modx->config['mce_element_format'])&&$modx->config['mce_element_format']==='html') { |
|
722 | + $opt = false; |
|
723 | + } else { |
|
724 | + $opt = true; |
|
607 | 725 | } |
608 | - elseif(isset($modx->config['mce_element_format'])&&$modx->config['mce_element_format']==='html') |
|
609 | - $opt = false; |
|
610 | - else $opt = true; |
|
611 | 726 | return nl2br($value,$opt); |
612 | 727 | case 'ltrim': |
613 | 728 | case 'rtrim': |
614 | 729 | case 'trim': // ref http://mblo.info/modifiers/custom-modifiers/rtrim_opt.html |
615 | - if($opt==='') |
|
616 | - return $cmd($value); |
|
617 | - else return $cmd($value,$opt); |
|
730 | + if($opt==='') { |
|
731 | + return $cmd($value); |
|
732 | + } else { |
|
733 | + return $cmd($value,$opt); |
|
734 | + } |
|
618 | 735 | // These are all straight wrappers for PHP functions |
619 | 736 | case 'ucfirst': |
620 | 737 | case 'lcfirst': |
@@ -625,15 +742,24 @@ discard block |
||
625 | 742 | case 'strftime': |
626 | 743 | case 'date': |
627 | 744 | case 'dateformat': |
628 | - if(empty($opt)) $opt = $modx->toDateFormat(null, 'formatOnly'); |
|
629 | - if(!preg_match('@^[0-9]+$@',$value)) $value = strtotime($value); |
|
630 | - if(strpos($opt,'%')!==false) |
|
631 | - return strftime($opt,0+$value); |
|
632 | - else |
|
633 | - return date($opt,0+$value); |
|
745 | + if(empty($opt)) { |
|
746 | + $opt = $modx->toDateFormat(null, 'formatOnly'); |
|
747 | + } |
|
748 | + if(!preg_match('@^[0-9]+$@',$value)) { |
|
749 | + $value = strtotime($value); |
|
750 | + } |
|
751 | + if(strpos($opt,'%')!==false) { |
|
752 | + return strftime($opt,0+$value); |
|
753 | + } else { |
|
754 | + return date($opt,0+$value); |
|
755 | + } |
|
634 | 756 | case 'time': |
635 | - if(empty($opt)) $opt = '%H:%M'; |
|
636 | - if(!preg_match('@^[0-9]+$@',$value)) $value = strtotime($value); |
|
757 | + if(empty($opt)) { |
|
758 | + $opt = '%H:%M'; |
|
759 | + } |
|
760 | + if(!preg_match('@^[0-9]+$@',$value)) { |
|
761 | + $value = strtotime($value); |
|
762 | + } |
|
637 | 763 | return strftime($opt,0+$value); |
638 | 764 | case 'strtotime': |
639 | 765 | return strtotime($value); |
@@ -643,7 +769,9 @@ discard block |
||
643 | 769 | case 'tofloat': |
644 | 770 | return floatval($value); |
645 | 771 | case 'round': |
646 | - if(!$opt) $opt = 0; |
|
772 | + if(!$opt) { |
|
773 | + $opt = 0; |
|
774 | + } |
|
647 | 775 | return $cmd($value,$opt); |
648 | 776 | case 'max': |
649 | 777 | case 'min': |
@@ -655,28 +783,42 @@ discard block |
||
655 | 783 | case 'math': |
656 | 784 | case 'calc': |
657 | 785 | $value = (int)$value; |
658 | - if(empty($value)) $value = '0'; |
|
786 | + if(empty($value)) { |
|
787 | + $value = '0'; |
|
788 | + } |
|
659 | 789 | $filter = str_replace(array('[+value+]','[+output+]','{value}','%s'),'?',$opt); |
660 | 790 | $filter = preg_replace('@([a-zA-Z\n\r\t\s])@','',$filter); |
661 | - if(strpos($filter,'?')===false) $filter = "?{$filter}"; |
|
791 | + if(strpos($filter,'?')===false) { |
|
792 | + $filter = "?{$filter}"; |
|
793 | + } |
|
662 | 794 | $filter = str_replace('?',$value,$filter); |
663 | 795 | return eval("return {$filter};"); |
664 | 796 | case 'count': |
665 | - if($value=='') return 0; |
|
797 | + if($value=='') { |
|
798 | + return 0; |
|
799 | + } |
|
666 | 800 | $value = explode(',',$value); |
667 | 801 | return count($value); |
668 | 802 | case 'sort': |
669 | 803 | case 'rsort': |
670 | - if(strpos($value,"\n")!==false) $delim="\n"; |
|
671 | - else $delim = ','; |
|
804 | + if(strpos($value,"\n")!==false) { |
|
805 | + $delim="\n"; |
|
806 | + } else { |
|
807 | + $delim = ','; |
|
808 | + } |
|
672 | 809 | $swap = explode($delim,$value); |
673 | - if(!$opt) $opt = SORT_REGULAR; |
|
674 | - else $opt = constant($opt); |
|
810 | + if(!$opt) { |
|
811 | + $opt = SORT_REGULAR; |
|
812 | + } else { |
|
813 | + $opt = constant($opt); |
|
814 | + } |
|
675 | 815 | $cmd($swap,$opt); |
676 | 816 | return implode($delim,$swap); |
677 | 817 | ##### Resource fields |
678 | 818 | case 'id': |
679 | - if($opt) return $this->getDocumentObject($opt,$key); |
|
819 | + if($opt) { |
|
820 | + return $this->getDocumentObject($opt,$key); |
|
821 | + } |
|
680 | 822 | break; |
681 | 823 | case 'type': |
682 | 824 | case 'contenttype': |
@@ -713,7 +855,9 @@ discard block |
||
713 | 855 | case 'privatemgr': |
714 | 856 | case 'content_dispo': |
715 | 857 | case 'hidemenu': |
716 | - if($cmd==='contenttype') $cmd = 'contentType'; |
|
858 | + if($cmd==='contenttype') { |
|
859 | + $cmd = 'contentType'; |
|
860 | + } |
|
717 | 861 | return $this->getDocumentObject($value,$cmd); |
718 | 862 | case 'title': |
719 | 863 | $pagetitle = $this->getDocumentObject($value,'pagetitle'); |
@@ -728,13 +872,20 @@ discard block |
||
728 | 872 | $templateName = $modx->db->getValue($rs); |
729 | 873 | return !$templateName ? '(blank)' : $templateName; |
730 | 874 | case 'getfield': |
731 | - if(!$opt) $opt = 'content'; |
|
875 | + if(!$opt) { |
|
876 | + $opt = 'content'; |
|
877 | + } |
|
732 | 878 | return $modx->getField($opt,$value); |
733 | 879 | case 'children': |
734 | 880 | case 'childids': |
735 | - if($value=='') $value = 0; // 値がない場合はルートと見なす |
|
881 | + if($value=='') { |
|
882 | + $value = 0; |
|
883 | + } |
|
884 | + // 値がない場合はルートと見なす |
|
736 | 885 | $published = 1; |
737 | - if($opt=='') $opt = 'page'; |
|
886 | + if($opt=='') { |
|
887 | + $opt = 'page'; |
|
888 | + } |
|
738 | 889 | $_ = explode(',',$opt); |
739 | 890 | $where = array(); |
740 | 891 | foreach($_ as $opt) { |
@@ -750,29 +901,43 @@ discard block |
||
750 | 901 | $where = implode(' AND ', $where); |
751 | 902 | $children = $modx->getDocumentChildren($value, $published, '0', 'id', $where); |
752 | 903 | $result = array(); |
753 | - foreach((array)$children as $child){ |
|
904 | + foreach((array)$children as $child) { |
|
754 | 905 | $result[] = $child['id']; |
755 | 906 | } |
756 | 907 | return implode(',', $result); |
757 | 908 | case 'fullurl': |
758 | - if(!is_numeric($value)) return $value; |
|
909 | + if(!is_numeric($value)) { |
|
910 | + return $value; |
|
911 | + } |
|
759 | 912 | return $modx->makeUrl($value); |
760 | 913 | case 'makeurl': |
761 | - if(!is_numeric($value)) return $value; |
|
762 | - if(!$opt) $opt = 'full'; |
|
914 | + if(!is_numeric($value)) { |
|
915 | + return $value; |
|
916 | + } |
|
917 | + if(!$opt) { |
|
918 | + $opt = 'full'; |
|
919 | + } |
|
763 | 920 | return $modx->makeUrl($value,'','',$opt); |
764 | 921 | |
765 | 922 | ##### File system |
766 | 923 | case 'getimageinfo': |
767 | 924 | case 'imageinfo': |
768 | - if(!is_file($value)) return ''; |
|
925 | + if(!is_file($value)) { |
|
926 | + return ''; |
|
927 | + } |
|
769 | 928 | $_ = getimagesize($value); |
770 | - if(!$_[0]) return ''; |
|
929 | + if(!$_[0]) { |
|
930 | + return ''; |
|
931 | + } |
|
771 | 932 | $info['width'] = $_[0]; |
772 | 933 | $info['height'] = $_[1]; |
773 | - if ($_[0] > $_[1]) $info['aspect'] = 'landscape'; |
|
774 | - elseif($_[0] < $_[1]) $info['aspect'] = 'portrait'; |
|
775 | - else $info['aspect'] = 'square'; |
|
934 | + if ($_[0] > $_[1]) { |
|
935 | + $info['aspect'] = 'landscape'; |
|
936 | + } elseif($_[0] < $_[1]) { |
|
937 | + $info['aspect'] = 'portrait'; |
|
938 | + } else { |
|
939 | + $info['aspect'] = 'square'; |
|
940 | + } |
|
776 | 941 | switch($_[2]) { |
777 | 942 | case IMAGETYPE_GIF : $info['type'] = 'gif'; break; |
778 | 943 | case IMAGETYPE_JPEG : $info['type'] = 'jpg'; break; |
@@ -791,33 +956,47 @@ discard block |
||
791 | 956 | |
792 | 957 | case 'file_get_contents': |
793 | 958 | case 'readfile': |
794 | - if(!is_file($value)) return $value; |
|
959 | + if(!is_file($value)) { |
|
960 | + return $value; |
|
961 | + } |
|
795 | 962 | $value = realpath($value); |
796 | - if(strpos($value,MODX_MANAGER_PATH)!==false) exit('Can not read core file'); |
|
963 | + if(strpos($value,MODX_MANAGER_PATH)!==false) { |
|
964 | + exit('Can not read core file'); |
|
965 | + } |
|
797 | 966 | $ext = strtolower(substr($value,-4)); |
798 | - if($ext==='.php') exit('Can not read php file'); |
|
799 | - if($ext==='.cgi') exit('Can not read cgi file'); |
|
967 | + if($ext==='.php') { |
|
968 | + exit('Can not read php file'); |
|
969 | + } |
|
970 | + if($ext==='.cgi') { |
|
971 | + exit('Can not read cgi file'); |
|
972 | + } |
|
800 | 973 | return file_get_contents($value); |
801 | 974 | case 'filesize': |
802 | - if($value == '') return ''; |
|
975 | + if($value == '') { |
|
976 | + return ''; |
|
977 | + } |
|
803 | 978 | $filename = $value; |
804 | 979 | |
805 | 980 | $site_url = $modx->config['site_url']; |
806 | - if(strpos($filename,$site_url) === 0) |
|
807 | - $filename = substr($filename,0,strlen($site_url)); |
|
981 | + if(strpos($filename,$site_url) === 0) { |
|
982 | + $filename = substr($filename,0,strlen($site_url)); |
|
983 | + } |
|
808 | 984 | $filename = trim($filename,'/'); |
809 | 985 | |
810 | 986 | $opt = trim($opt,'/'); |
811 | - if($opt!=='') $opt .= '/'; |
|
987 | + if($opt!=='') { |
|
988 | + $opt .= '/'; |
|
989 | + } |
|
812 | 990 | |
813 | 991 | $filename = MODX_BASE_PATH.$opt.$filename; |
814 | 992 | |
815 | - if(is_file($filename)){ |
|
993 | + if(is_file($filename)) { |
|
816 | 994 | clearstatcache(); |
817 | 995 | $size = filesize($filename); |
818 | 996 | return $size; |
997 | + } else { |
|
998 | + return ''; |
|
819 | 999 | } |
820 | - else return ''; |
|
821 | 1000 | ##### User info |
822 | 1001 | case 'username': |
823 | 1002 | case 'fullname': |
@@ -845,32 +1024,47 @@ discard block |
||
845 | 1024 | $this->opt = $cmd; |
846 | 1025 | return $this->includeMdfFile('moduser'); |
847 | 1026 | case 'userinfo': |
848 | - if(empty($opt)) $this->opt = 'username'; |
|
1027 | + if(empty($opt)) { |
|
1028 | + $this->opt = 'username'; |
|
1029 | + } |
|
849 | 1030 | return $this->includeMdfFile('moduser'); |
850 | 1031 | case 'webuserinfo': |
851 | - if(empty($opt)) $this->opt = 'username'; |
|
1032 | + if(empty($opt)) { |
|
1033 | + $this->opt = 'username'; |
|
1034 | + } |
|
852 | 1035 | $this->value = -$value; |
853 | 1036 | return $this->includeMdfFile('moduser'); |
854 | 1037 | ##### Special functions |
855 | 1038 | case 'ifempty': |
856 | 1039 | case '_default': |
857 | 1040 | case 'default': |
858 | - if (empty($value)) return $opt; break; |
|
1041 | + if (empty($value)) { |
|
1042 | + return $opt; |
|
1043 | + } |
|
1044 | + break; |
|
859 | 1045 | case 'ifnotempty': |
860 | - if (!empty($value)) return $opt; break; |
|
1046 | + if (!empty($value)) { |
|
1047 | + return $opt; |
|
1048 | + } |
|
1049 | + break; |
|
861 | 1050 | case 'datagrid': |
862 | 1051 | include_once(MODX_CORE_PATH . 'controls/datagrid.class.php'); |
863 | 1052 | $grd = new DataGrid(null, trim($value)); |
864 | 1053 | $grd->itemStyle = ''; |
865 | 1054 | $grd->altItemStyle = ''; |
866 | 1055 | $pos = strpos($value,"\n"); |
867 | - if($pos) $_ = substr($value,0,$pos); |
|
868 | - else $_ = $pos; |
|
1056 | + if($pos) { |
|
1057 | + $_ = substr($value,0,$pos); |
|
1058 | + } else { |
|
1059 | + $_ = $pos; |
|
1060 | + } |
|
869 | 1061 | $grd->cdelim = strpos($_,"\t")!==false ? 'tab' : ','; |
870 | 1062 | return $grd->render(); |
871 | 1063 | case 'rotate': |
872 | 1064 | case 'evenodd': |
873 | - if(strpos($opt,',')===false) $opt = 'odd,even'; |
|
1065 | + if(strpos($opt,',')===false) { |
|
1066 | + $opt = 'odd,even'; |
|
1067 | + } |
|
874 | 1068 | $_ = explode(',', $opt); |
875 | 1069 | $c = count($_); |
876 | 1070 | $i = $value + $c; |
@@ -879,7 +1073,9 @@ discard block |
||
879 | 1073 | case 'takeval': |
880 | 1074 | $arr = explode(",",$opt); |
881 | 1075 | $idx = $value; |
882 | - if(!is_numeric($idx)) return $value; |
|
1076 | + if(!is_numeric($idx)) { |
|
1077 | + return $value; |
|
1078 | + } |
|
883 | 1079 | return $arr[$idx]; |
884 | 1080 | case 'getimage': |
885 | 1081 | return $this->includeMdfFile('getimage'); |
@@ -887,14 +1083,18 @@ discard block |
||
887 | 1083 | return $modx->nicesize($value); |
888 | 1084 | case 'googlemap': |
889 | 1085 | case 'googlemaps': |
890 | - if(empty($opt)) $opt = 'border:none;width:500px;height:350px;'; |
|
1086 | + if(empty($opt)) { |
|
1087 | + $opt = 'border:none;width:500px;height:350px;'; |
|
1088 | + } |
|
891 | 1089 | $tpl = '<iframe style="[+style+]" src="https://maps.google.co.jp/maps?ll=[+value+]&output=embed&z=15"></iframe>'; |
892 | 1090 | $ph['style'] = $opt; |
893 | 1091 | $ph['value'] = $value; |
894 | 1092 | return $modx->parseText($tpl,$ph); |
895 | 1093 | case 'youtube': |
896 | 1094 | case 'youtube16x9': |
897 | - if(empty($opt)) $opt = 560; |
|
1095 | + if(empty($opt)) { |
|
1096 | + $opt = 560; |
|
1097 | + } |
|
898 | 1098 | $h = round($opt*0.5625); |
899 | 1099 | $tpl = '<iframe width="%s" height="%s" src="https://www.youtube.com/embed/%s" frameborder="0" allowfullscreen></iframe>'; |
900 | 1100 | return sprintf($tpl,$opt,$h,$value); |
@@ -927,7 +1127,8 @@ discard block |
||
927 | 1127 | return $value; |
928 | 1128 | } |
929 | 1129 | |
930 | - public function includeMdfFile($cmd) { |
|
1130 | + public function includeMdfFile($cmd) |
|
1131 | + { |
|
931 | 1132 | global $modx; |
932 | 1133 | $key = $this->key; |
933 | 1134 | $value = $this->value; |
@@ -938,55 +1139,65 @@ discard block |
||
938 | 1139 | public function getValueFromElement($key, $value, $cmd, $opt) |
939 | 1140 | { |
940 | 1141 | global $modx; |
941 | - if( isset($modx->snippetCache[$this->elmName]) ) |
|
942 | - { |
|
1142 | + if( isset($modx->snippetCache[$this->elmName]) ) { |
|
943 | 1143 | $php = $modx->snippetCache[$this->elmName]; |
944 | - } |
|
945 | - else |
|
946 | - { |
|
1144 | + } else { |
|
947 | 1145 | $esc_elmName = $modx->db->escape($this->elmName); |
948 | 1146 | $result = $modx->db->select('snippet','[+prefix+]site_snippets',"name='{$esc_elmName}'"); |
949 | 1147 | $total = $modx->db->getRecordCount($result); |
950 | - if($total == 1) |
|
951 | - { |
|
1148 | + if($total == 1) { |
|
952 | 1149 | $row = $modx->db->getRow($result); |
953 | 1150 | $php = $row['snippet']; |
954 | - } |
|
955 | - elseif($total == 0) |
|
956 | - { |
|
1151 | + } elseif($total == 0) { |
|
957 | 1152 | $assets_path = MODX_BASE_PATH.'assets/'; |
958 | - if(is_file($assets_path."modifiers/mdf_{$cmd}.inc.php")) |
|
959 | - $modifiers_path = $assets_path."modifiers/mdf_{$cmd}.inc.php"; |
|
960 | - elseif(is_file($assets_path."plugins/phx/modifiers/{$cmd}.phx.php")) |
|
961 | - $modifiers_path = $assets_path."plugins/phx/modifiers/{$cmd}.phx.php"; |
|
962 | - elseif(is_file(MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php")) |
|
963 | - $modifiers_path = MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php"; |
|
964 | - else $modifiers_path = false; |
|
1153 | + if(is_file($assets_path."modifiers/mdf_{$cmd}.inc.php")) { |
|
1154 | + $modifiers_path = $assets_path."modifiers/mdf_{$cmd}.inc.php"; |
|
1155 | + } elseif(is_file($assets_path."plugins/phx/modifiers/{$cmd}.phx.php")) { |
|
1156 | + $modifiers_path = $assets_path."plugins/phx/modifiers/{$cmd}.phx.php"; |
|
1157 | + } elseif(is_file(MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php")) { |
|
1158 | + $modifiers_path = MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php"; |
|
1159 | + } else { |
|
1160 | + $modifiers_path = false; |
|
1161 | + } |
|
965 | 1162 | |
966 | 1163 | if($modifiers_path !== false) { |
967 | 1164 | $php = @file_get_contents($modifiers_path); |
968 | 1165 | $php = trim($php); |
969 | - if(substr($php,0,5)==='<?php') $php = substr($php,6); |
|
970 | - if(substr($php,0,2)==='<?') $php = substr($php,3); |
|
971 | - if(substr($php,-2)==='?>') $php = substr($php,0,-2); |
|
972 | - if($this->elmName!=='') |
|
973 | - $modx->snippetCache[$this->elmName.'Props'] = ''; |
|
974 | - } |
|
975 | - else |
|
976 | - $php = false; |
|
1166 | + if(substr($php,0,5)==='<?php') { |
|
1167 | + $php = substr($php,6); |
|
1168 | + } |
|
1169 | + if(substr($php,0,2)==='<?') { |
|
1170 | + $php = substr($php,3); |
|
1171 | + } |
|
1172 | + if(substr($php,-2)==='?>') { |
|
1173 | + $php = substr($php,0,-2); |
|
1174 | + } |
|
1175 | + if($this->elmName!=='') { |
|
1176 | + $modx->snippetCache[$this->elmName.'Props'] = ''; |
|
1177 | + } |
|
1178 | + } else { |
|
1179 | + $php = false; |
|
1180 | + } |
|
1181 | + } else { |
|
1182 | + $php = false; |
|
1183 | + } |
|
1184 | + if($this->elmName!=='') { |
|
1185 | + $modx->snippetCache[$this->elmName]= $php; |
|
977 | 1186 | } |
978 | - else $php = false; |
|
979 | - if($this->elmName!=='') $modx->snippetCache[$this->elmName]= $php; |
|
980 | 1187 | } |
981 | - if($php==='') $php=false; |
|
1188 | + if($php==='') { |
|
1189 | + $php=false; |
|
1190 | + } |
|
982 | 1191 | |
983 | - if($php===false) $html = $modx->getChunk($this->elmName); |
|
984 | - else $html = false; |
|
1192 | + if($php===false) { |
|
1193 | + $html = $modx->getChunk($this->elmName); |
|
1194 | + } else { |
|
1195 | + $html = false; |
|
1196 | + } |
|
985 | 1197 | |
986 | 1198 | $self = '[+output+]'; |
987 | 1199 | |
988 | - if($php !== false) |
|
989 | - { |
|
1200 | + if($php !== false) { |
|
990 | 1201 | ob_start(); |
991 | 1202 | $options = $opt; |
992 | 1203 | $output = $value; |
@@ -998,19 +1209,19 @@ discard block |
||
998 | 1209 | $this->vars['options'] = & $opt; |
999 | 1210 | $custom = eval($php); |
1000 | 1211 | $msg = ob_get_contents(); |
1001 | - if($value===$this->bt) $value = $msg . $custom; |
|
1212 | + if($value===$this->bt) { |
|
1213 | + $value = $msg . $custom; |
|
1214 | + } |
|
1002 | 1215 | ob_end_clean(); |
1003 | - } |
|
1004 | - elseif($html!==false && isset($value) && $value!=='') |
|
1005 | - { |
|
1216 | + } elseif($html!==false && isset($value) && $value!=='') { |
|
1006 | 1217 | $html = str_replace(array($self,'[+value+]'), $value, $html); |
1007 | 1218 | $value = str_replace(array('[+options+]','[+param+]'), $opt, $html); |
1219 | + } else { |
|
1220 | + return false; |
|
1008 | 1221 | } |
1009 | - else return false; |
|
1010 | 1222 | |
1011 | 1223 | if($php===false && $html===false && $value!=='' |
1012 | - && (strpos($cmd,'[+value+]')!==false || strpos($cmd,$self)!==false)) |
|
1013 | - { |
|
1224 | + && (strpos($cmd,'[+value+]')!==false || strpos($cmd,$self)!==false)) { |
|
1014 | 1225 | $value = str_replace(array('[+value+]',$self),$value,$cmd); |
1015 | 1226 | } |
1016 | 1227 | return $value; |
@@ -1020,23 +1231,39 @@ discard block |
||
1020 | 1231 | { |
1021 | 1232 | global $modx; |
1022 | 1233 | |
1023 | - if(strpos($content,'[')===false && strpos($content,'{')===false) return $content; |
|
1234 | + if(strpos($content,'[')===false && strpos($content,'{')===false) { |
|
1235 | + return $content; |
|
1236 | + } |
|
1024 | 1237 | |
1025 | - if(!$modx->maxParserPasses) $modx->maxParserPasses = 10; |
|
1238 | + if(!$modx->maxParserPasses) { |
|
1239 | + $modx->maxParserPasses = 10; |
|
1240 | + } |
|
1026 | 1241 | $bt=''; |
1027 | 1242 | $i=0; |
1028 | - while($bt!==$content) |
|
1029 | - { |
|
1243 | + while($bt!==$content) { |
|
1030 | 1244 | $bt = $content; |
1031 | - if(strpos($content,'[*')!==false && $modx->documentIdentifier) |
|
1032 | - $content = $modx->mergeDocumentContent($content); |
|
1033 | - if(strpos($content,'[(')!==false) $content = $modx->mergeSettingsContent($content); |
|
1034 | - if(strpos($content,'{{')!==false) $content = $modx->mergeChunkContent($content); |
|
1035 | - if(strpos($content,'[!')!==false) $content = str_replace(array('[!','!]'),array('[[',']]'),$content); |
|
1036 | - if(strpos($content,'[[')!==false) $content = $modx->evalSnippets($content); |
|
1037 | - |
|
1038 | - if($content===$bt) break; |
|
1039 | - if($modx->maxParserPasses < $i) break; |
|
1245 | + if(strpos($content,'[*')!==false && $modx->documentIdentifier) { |
|
1246 | + $content = $modx->mergeDocumentContent($content); |
|
1247 | + } |
|
1248 | + if(strpos($content,'[(')!==false) { |
|
1249 | + $content = $modx->mergeSettingsContent($content); |
|
1250 | + } |
|
1251 | + if(strpos($content,'{{')!==false) { |
|
1252 | + $content = $modx->mergeChunkContent($content); |
|
1253 | + } |
|
1254 | + if(strpos($content,'[!')!==false) { |
|
1255 | + $content = str_replace(array('[!','!]'),array('[[',']]'),$content); |
|
1256 | + } |
|
1257 | + if(strpos($content,'[[')!==false) { |
|
1258 | + $content = $modx->evalSnippets($content); |
|
1259 | + } |
|
1260 | + |
|
1261 | + if($content===$bt) { |
|
1262 | + break; |
|
1263 | + } |
|
1264 | + if($modx->maxParserPasses < $i) { |
|
1265 | + break; |
|
1266 | + } |
|
1040 | 1267 | $i++; |
1041 | 1268 | } |
1042 | 1269 | return $content; |
@@ -1047,103 +1274,138 @@ discard block |
||
1047 | 1274 | global $modx; |
1048 | 1275 | |
1049 | 1276 | $target = trim($target); |
1050 | - if(empty($target)) $target = $modx->config['site_start']; |
|
1051 | - if(preg_match('@^[1-9][0-9]*$@',$target)) $method='id'; |
|
1052 | - else $method = 'alias'; |
|
1277 | + if(empty($target)) { |
|
1278 | + $target = $modx->config['site_start']; |
|
1279 | + } |
|
1280 | + if(preg_match('@^[1-9][0-9]*$@',$target)) { |
|
1281 | + $method='id'; |
|
1282 | + } else { |
|
1283 | + $method = 'alias'; |
|
1284 | + } |
|
1053 | 1285 | |
1054 | - if(!isset($this->documentObject[$target])) |
|
1055 | - { |
|
1286 | + if(!isset($this->documentObject[$target])) { |
|
1056 | 1287 | $this->documentObject[$target] = $modx->getDocumentObject($method,$target,'direct'); |
1057 | 1288 | } |
1058 | 1289 | |
1059 | - if($this->documentObject[$target]['publishedon']==='0') |
|
1060 | - return ''; |
|
1061 | - elseif(isset($this->documentObject[$target][$field])) |
|
1062 | - { |
|
1063 | - if(is_array($this->documentObject[$target][$field])) |
|
1064 | - { |
|
1290 | + if($this->documentObject[$target]['publishedon']==='0') { |
|
1291 | + return ''; |
|
1292 | + } elseif(isset($this->documentObject[$target][$field])) { |
|
1293 | + if(is_array($this->documentObject[$target][$field])) { |
|
1065 | 1294 | $a = $modx->getTemplateVarOutput($field,$target); |
1066 | 1295 | $this->documentObject[$target][$field] = $a[$field]; |
1067 | 1296 | } |
1297 | + } else { |
|
1298 | + $this->documentObject[$target][$field] = false; |
|
1068 | 1299 | } |
1069 | - else $this->documentObject[$target][$field] = false; |
|
1070 | 1300 | |
1071 | 1301 | return $this->documentObject[$target][$field]; |
1072 | 1302 | } |
1073 | 1303 | |
1074 | - public function setPlaceholders($value = '', $key = '', $path = '') { |
|
1075 | - if($path!=='') $key = "{$path}.{$key}"; |
|
1304 | + public function setPlaceholders($value = '', $key = '', $path = '') |
|
1305 | + { |
|
1306 | + if($path!=='') { |
|
1307 | + $key = "{$path}.{$key}"; |
|
1308 | + } |
|
1076 | 1309 | if (is_array($value)) { |
1077 | 1310 | foreach ($value as $subkey => $subval) { |
1078 | 1311 | $this->setPlaceholders($subval, $subkey, $key); |
1079 | 1312 | } |
1313 | + } else { |
|
1314 | + $this->setModifiersVariable($key, $value); |
|
1080 | 1315 | } |
1081 | - else $this->setModifiersVariable($key, $value); |
|
1082 | 1316 | } |
1083 | 1317 | |
1084 | 1318 | // Sets a placeholder variable which can only be access by Modifiers |
1085 | - public function setModifiersVariable($key, $value) { |
|
1086 | - if ($key != 'phx' && $key != 'dummy') $this->placeholders[$key] = $value; |
|
1319 | + public function setModifiersVariable($key, $value) |
|
1320 | + { |
|
1321 | + if ($key != 'phx' && $key != 'dummy') { |
|
1322 | + $this->placeholders[$key] = $value; |
|
1323 | + } |
|
1087 | 1324 | } |
1088 | 1325 | |
1089 | 1326 | //mbstring |
1090 | - public function substr($str, $s, $l = null) { |
|
1327 | + public function substr($str, $s, $l = null) |
|
1328 | + { |
|
1091 | 1329 | global $modx; |
1092 | - if(is_null($l)) $l = $this->strlen($str); |
|
1093 | - if (function_exists('mb_substr')) |
|
1094 | - { |
|
1095 | - if(strpos($str,"\r")!==false) |
|
1096 | - $str = str_replace(array("\r\n","\r"), "\n", $str); |
|
1330 | + if(is_null($l)) { |
|
1331 | + $l = $this->strlen($str); |
|
1332 | + } |
|
1333 | + if (function_exists('mb_substr')) { |
|
1334 | + if(strpos($str,"\r")!==false) { |
|
1335 | + $str = str_replace(array("\r\n","\r"), "\n", $str); |
|
1336 | + } |
|
1097 | 1337 | return mb_substr($str, $s, $l, $modx->config['modx_charset']); |
1098 | 1338 | } |
1099 | 1339 | return substr($str, $s, $l); |
1100 | 1340 | } |
1101 | - public function strpos($haystack,$needle,$offset=0) { |
|
1341 | + public function strpos($haystack,$needle,$offset=0) |
|
1342 | + { |
|
1102 | 1343 | global $modx; |
1103 | - if (function_exists('mb_strpos')) return mb_strpos($haystack,$needle,$offset,$modx->config['modx_charset']); |
|
1344 | + if (function_exists('mb_strpos')) { |
|
1345 | + return mb_strpos($haystack,$needle,$offset,$modx->config['modx_charset']); |
|
1346 | + } |
|
1104 | 1347 | return strpos($haystack,$needle,$offset); |
1105 | 1348 | } |
1106 | - public function strlen($str) { |
|
1349 | + public function strlen($str) |
|
1350 | + { |
|
1107 | 1351 | global $modx; |
1108 | - if (function_exists('mb_strlen')) return mb_strlen(str_replace("\r\n", "\n", $str),$modx->config['modx_charset']); |
|
1352 | + if (function_exists('mb_strlen')) { |
|
1353 | + return mb_strlen(str_replace("\r\n", "\n", $str),$modx->config['modx_charset']); |
|
1354 | + } |
|
1109 | 1355 | return strlen($str); |
1110 | 1356 | } |
1111 | - public function strtolower($str) { |
|
1112 | - if (function_exists('mb_strtolower')) return mb_strtolower($str); |
|
1357 | + public function strtolower($str) |
|
1358 | + { |
|
1359 | + if (function_exists('mb_strtolower')) { |
|
1360 | + return mb_strtolower($str); |
|
1361 | + } |
|
1113 | 1362 | return strtolower($str); |
1114 | 1363 | } |
1115 | - public function strtoupper($str) { |
|
1116 | - if (function_exists('mb_strtoupper')) return mb_strtoupper($str); |
|
1364 | + public function strtoupper($str) |
|
1365 | + { |
|
1366 | + if (function_exists('mb_strtoupper')) { |
|
1367 | + return mb_strtoupper($str); |
|
1368 | + } |
|
1117 | 1369 | return strtoupper($str); |
1118 | 1370 | } |
1119 | - public function ucfirst($str) { |
|
1120 | - if (function_exists('mb_strtoupper')) |
|
1121 | - return mb_strtoupper($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str)); |
|
1371 | + public function ucfirst($str) |
|
1372 | + { |
|
1373 | + if (function_exists('mb_strtoupper')) { |
|
1374 | + return mb_strtoupper($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str)); |
|
1375 | + } |
|
1122 | 1376 | return ucfirst($str); |
1123 | 1377 | } |
1124 | - public function lcfirst($str) { |
|
1125 | - if (function_exists('mb_strtolower')) |
|
1126 | - return mb_strtolower($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str)); |
|
1378 | + public function lcfirst($str) |
|
1379 | + { |
|
1380 | + if (function_exists('mb_strtolower')) { |
|
1381 | + return mb_strtolower($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str)); |
|
1382 | + } |
|
1127 | 1383 | return lcfirst($str); |
1128 | 1384 | } |
1129 | - public function ucwords($str) { |
|
1130 | - if (function_exists('mb_convert_case')) |
|
1131 | - return mb_convert_case($str, MB_CASE_TITLE); |
|
1385 | + public function ucwords($str) |
|
1386 | + { |
|
1387 | + if (function_exists('mb_convert_case')) { |
|
1388 | + return mb_convert_case($str, MB_CASE_TITLE); |
|
1389 | + } |
|
1132 | 1390 | return ucwords($str); |
1133 | 1391 | } |
1134 | - public function strrev($str) { |
|
1392 | + public function strrev($str) |
|
1393 | + { |
|
1135 | 1394 | preg_match_all('/./us', $str, $ar); |
1136 | 1395 | return implode(array_reverse($ar[0])); |
1137 | 1396 | } |
1138 | - public function str_shuffle($str) { |
|
1397 | + public function str_shuffle($str) |
|
1398 | + { |
|
1139 | 1399 | preg_match_all('/./us', $str, $ar); |
1140 | 1400 | shuffle($ar[0]); |
1141 | 1401 | return implode($ar[0]); |
1142 | 1402 | } |
1143 | - public function str_word_count($str) { |
|
1403 | + public function str_word_count($str) |
|
1404 | + { |
|
1144 | 1405 | return count(preg_split('~[^\p{L}\p{N}\']+~u',$str)); |
1145 | 1406 | } |
1146 | - public function strip_tags($value,$params='') { |
|
1407 | + public function strip_tags($value,$params='') |
|
1408 | + { |
|
1147 | 1409 | global $modx; |
1148 | 1410 | |
1149 | 1411 | if(stripos($params,'style')===false && stripos($value,'</style>')!==false) { |
@@ -349,7 +349,7 @@ |
||
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});"); |
@@ -6,9 +6,9 @@ |
||
6 | 6 | * Time: 14:17 |
7 | 7 | */ |
8 | 8 | |
9 | -if (!include_once(MODX_MANAGER_PATH . 'includes/extenders/modxmailer.class.inc.php')){ |
|
9 | +if (!include_once(MODX_MANAGER_PATH.'includes/extenders/modxmailer.class.inc.php')) { |
|
10 | 10 | return false; |
11 | -}else{ |
|
11 | +} else { |
|
12 | 12 | $this->mail = new MODxMailer; |
13 | 13 | $this->mail->init($this); |
14 | 14 | return true; |
@@ -6,9 +6,9 @@ |
||
6 | 6 | * Time: 14:17 |
7 | 7 | */ |
8 | 8 | |
9 | -if (!include_once(MODX_MANAGER_PATH . 'includes/extenders/modxmailer.class.inc.php')){ |
|
9 | +if (!include_once(MODX_MANAGER_PATH . 'includes/extenders/modxmailer.class.inc.php')) { |
|
10 | 10 | return false; |
11 | -}else{ |
|
11 | +} else { |
|
12 | 12 | $this->mail = new MODxMailer; |
13 | 13 | $this->mail->init($this); |
14 | 14 | return true; |
@@ -248,9 +248,9 @@ |
||
248 | 248 | echo '<span class="notok">' . $_lang['failed'] . '</span></b>' . $_lang['table_prefix_not_exist'] . '</p>'; |
249 | 249 | $errors++; |
250 | 250 | echo '<p>' . $_lang['table_prefix_not_exist_note'] . '</p>'; |
251 | - } else { |
|
251 | + } else { |
|
252 | 252 | echo '<span class="ok">' . $_lang['ok'] . '</span></p>'; |
253 | - } |
|
253 | + } |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | // check mysql version |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if( ! function_exists('f_owc')){ |
|
2 | +if (!function_exists('f_owc')) { |
|
3 | 3 | /** |
4 | 4 | * @param $path |
5 | 5 | * @param $data |
@@ -12,30 +12,30 @@ discard block |
||
12 | 12 | fwrite($hnd, $data); |
13 | 13 | fclose($hnd); |
14 | 14 | |
15 | - if(null !== $mode) chmod($path, $mode); |
|
16 | - }catch(Exception $e){ |
|
15 | + if (null !== $mode) chmod($path, $mode); |
|
16 | + } catch (Exception $e) { |
|
17 | 17 | // Nothing, this is NOT normal |
18 | 18 | unset($e); |
19 | 19 | } |
20 | 20 | } |
21 | 21 | } |
22 | 22 | |
23 | -$installMode = isset($_POST['installmode']) ? (int)$_POST['installmode'] : 0; |
|
24 | -if( ! isset($_lang)) $_lang = array(); |
|
23 | +$installMode = isset($_POST['installmode']) ? (int) $_POST['installmode'] : 0; |
|
24 | +if (!isset($_lang)) $_lang = array(); |
|
25 | 25 | |
26 | 26 | echo '<div class="stepcontainer"> |
27 | 27 | <ul class="progressbar"> |
28 | - <li class="visited">' . $_lang['choose_language'] . '</li> |
|
29 | - <li class="visited">' . $_lang['installation_mode'] . '</li> |
|
30 | - <li class="visited">' . $_lang['optional_items'] . '</li> |
|
31 | - <li class="active">' . $_lang['preinstall_validation'] . '</li> |
|
32 | - <li>' . $_lang['install_results'] . '</li> |
|
28 | + <li class="visited">' . $_lang['choose_language'].'</li> |
|
29 | + <li class="visited">' . $_lang['installation_mode'].'</li> |
|
30 | + <li class="visited">' . $_lang['optional_items'].'</li> |
|
31 | + <li class="active">' . $_lang['preinstall_validation'].'</li> |
|
32 | + <li>' . $_lang['install_results'].'</li> |
|
33 | 33 | </ul> |
34 | 34 | <div class="clearleft"></div> |
35 | 35 | </div>'; |
36 | 36 | |
37 | -echo '<h2>' . $_lang['preinstall_validation'] . '</h2>'; |
|
38 | -echo '<h3>' . $_lang['summary_setup_check'] . '</h3>'; |
|
37 | +echo '<h2>'.$_lang['preinstall_validation'].'</h2>'; |
|
38 | +echo '<h3>'.$_lang['summary_setup_check'].'</h3>'; |
|
39 | 39 | |
40 | 40 | $errors = 0; |
41 | 41 | |
@@ -43,73 +43,73 @@ discard block |
||
43 | 43 | // check PHP version |
44 | 44 | define('PHP_MIN_VERSION', '5.4.0'); |
45 | 45 | $phpMinVersion = PHP_MIN_VERSION; // Maybe not necessary. For backward compatibility |
46 | -echo '<p>' . $_lang['checking_php_version']; |
|
46 | +echo '<p>'.$_lang['checking_php_version']; |
|
47 | 47 | // -1 if left is less, 0 if equal, +1 if left is higher |
48 | 48 | if (version_compare(phpversion(), PHP_MIN_VERSION) < 0) { |
49 | 49 | $errors++; |
50 | - $tmp = $_lang['you_running_php'] . phpversion() . str_replace('[+min_version+]', PHP_MIN_VERSION, $_lang["modx_requires_php"]); |
|
51 | - echo '<span class="notok">' . $_lang['failed'] . '</span>' . $tmp . '</p>'; |
|
50 | + $tmp = $_lang['you_running_php'].phpversion().str_replace('[+min_version+]', PHP_MIN_VERSION, $_lang["modx_requires_php"]); |
|
51 | + echo '<span class="notok">'.$_lang['failed'].'</span>'.$tmp.'</p>'; |
|
52 | 52 | } else { |
53 | - echo '<span class="ok">' . $_lang['ok'] . '</span></p>'; |
|
53 | + echo '<span class="ok">'.$_lang['ok'].'</span></p>'; |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | |
57 | 57 | // check if iconv is available |
58 | -echo '<p>' . $_lang['checking_iconv']; |
|
58 | +echo '<p>'.$_lang['checking_iconv']; |
|
59 | 59 | $iconv = (int) function_exists('iconv'); |
60 | -if ($iconv == '0'){ |
|
61 | - echo '<span class="notok">' . $_lang['failed'].'</span></p><p><strong>'.$_lang['checking_iconv_note'].'</strong></p>'; |
|
60 | +if ($iconv == '0') { |
|
61 | + echo '<span class="notok">'.$_lang['failed'].'</span></p><p><strong>'.$_lang['checking_iconv_note'].'</strong></p>'; |
|
62 | 62 | $errors++; |
63 | 63 | } else { |
64 | - echo '<span class="ok">' . $_lang['ok'] . '</span></p>'; |
|
64 | + echo '<span class="ok">'.$_lang['ok'].'</span></p>'; |
|
65 | 65 | } |
66 | 66 | // check sessions |
67 | -echo '<p>' . $_lang['checking_sessions']; |
|
67 | +echo '<p>'.$_lang['checking_sessions']; |
|
68 | 68 | if ($_SESSION['test'] != 1) { |
69 | - echo '<span class="notok">' . $_lang['failed']. '</span></p>'; |
|
69 | + echo '<span class="notok">'.$_lang['failed'].'</span></p>'; |
|
70 | 70 | $errors++; |
71 | 71 | } else { |
72 | - echo '<span class="ok">' . $_lang['ok'] . '</span></p>'; |
|
72 | + echo '<span class="ok">'.$_lang['ok'].'</span></p>'; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | |
76 | 76 | // check directories |
77 | 77 | // cache exists? |
78 | -echo '<p>' . $_lang['checking_if_cache_exist']; |
|
78 | +echo '<p>'.$_lang['checking_if_cache_exist']; |
|
79 | 79 | if (!file_exists("../assets/cache") || !file_exists("../assets/cache/rss")) { |
80 | - echo '<span class="notok">' . $_lang['failed'] . '</span></p>'; |
|
80 | + echo '<span class="notok">'.$_lang['failed'].'</span></p>'; |
|
81 | 81 | $errors++; |
82 | 82 | } else { |
83 | - echo '<span class="ok">' . $_lang['ok'] . '</span></p>'; |
|
83 | + echo '<span class="ok">'.$_lang['ok'].'</span></p>'; |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | |
87 | 87 | // cache writable? |
88 | -echo '<p>' . $_lang['checking_if_cache_writable']; |
|
88 | +echo '<p>'.$_lang['checking_if_cache_writable']; |
|
89 | 89 | if (!is_writable("../assets/cache")) { |
90 | 90 | $errors++; |
91 | - echo '<span class="notok">' . $_lang['failed'] . '</span></p>'; |
|
91 | + echo '<span class="notok">'.$_lang['failed'].'</span></p>'; |
|
92 | 92 | } else { |
93 | - echo '<span class="ok">' . $_lang['ok'] . '</span></p>'; |
|
93 | + echo '<span class="ok">'.$_lang['ok'].'</span></p>'; |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | |
97 | 97 | // cache files writable? |
98 | -echo '<p>' . $_lang['checking_if_cache_file_writable']; |
|
98 | +echo '<p>'.$_lang['checking_if_cache_file_writable']; |
|
99 | 99 | $tmp = "../assets/cache/siteCache.idx.php"; |
100 | -if ( ! file_exists($tmp)) { |
|
100 | +if (!file_exists($tmp)) { |
|
101 | 101 | f_owc($tmp, "<?php //EVO site cache file ?>"); |
102 | 102 | } |
103 | -if ( ! is_writable($tmp)) { |
|
103 | +if (!is_writable($tmp)) { |
|
104 | 104 | $errors++; |
105 | - echo '<span class="notok">' . $_lang['failed'] . '</span></p>'; |
|
105 | + echo '<span class="notok">'.$_lang['failed'].'</span></p>'; |
|
106 | 106 | } else { |
107 | 107 | echo '<span class="ok">'.$_lang['ok'].'</span></p>'; |
108 | 108 | } |
109 | 109 | |
110 | 110 | |
111 | 111 | echo '<p>'.$_lang['checking_if_cache_file2_writable']; |
112 | -if ( ! is_writable("../assets/cache/sitePublishing.idx.php")) { |
|
112 | +if (!is_writable("../assets/cache/sitePublishing.idx.php")) { |
|
113 | 113 | $errors++; |
114 | 114 | echo '<span class="notok">'.$_lang['failed'].'</span></p>'; |
115 | 115 | } else { |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | |
120 | 120 | // File Browser directories exists? |
121 | 121 | echo '<p>'.$_lang['checking_if_images_exist']; |
122 | -switch(true){ |
|
122 | +switch (true) { |
|
123 | 123 | case !file_exists("../assets/images"): |
124 | 124 | case !file_exists("../assets/files"): |
125 | 125 | case !file_exists("../assets/backup"): |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | |
135 | 135 | // File Browser directories writable? |
136 | 136 | echo '<p>'.$_lang['checking_if_images_writable']; |
137 | -switch(true){ |
|
137 | +switch (true) { |
|
138 | 138 | case !is_writable("../assets/images"): |
139 | 139 | case !is_writable("../assets/files"): |
140 | 140 | case !is_writable("../assets/backup"): |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | $database_charset = substr($database_collation, 0, strpos($database_collation, '_') - 1); |
195 | 195 | $database_connection_charset = $_POST['database_connection_charset']; |
196 | 196 | $database_connection_method = $_POST['database_connection_method']; |
197 | - $dbase = '`' . $_POST['database_name'] . '`'; |
|
197 | + $dbase = '`'.$_POST['database_name'].'`'; |
|
198 | 198 | $table_prefix = $_POST['tableprefix']; |
199 | 199 | } |
200 | 200 | echo '<p>'.$_lang['creating_database_connection']; |
@@ -234,54 +234,54 @@ discard block |
||
234 | 234 | |
235 | 235 | // check table prefix |
236 | 236 | if ($conn && $installMode == 0) { |
237 | - echo '<p>' . $_lang['checking_table_prefix'] . $table_prefix . '`: '; |
|
238 | - if ($rs= mysqli_query($conn, "SELECT COUNT(*) FROM $dbase.`" . $table_prefix . "site_content`")) { |
|
239 | - echo '<span class="notok">' . $_lang['failed'] . '</span></b>' . $_lang['table_prefix_already_inuse'] . '</p>'; |
|
237 | + echo '<p>'.$_lang['checking_table_prefix'].$table_prefix.'`: '; |
|
238 | + if ($rs = mysqli_query($conn, "SELECT COUNT(*) FROM $dbase.`".$table_prefix."site_content`")) { |
|
239 | + echo '<span class="notok">'.$_lang['failed'].'</span></b>'.$_lang['table_prefix_already_inuse'].'</p>'; |
|
240 | 240 | $errors++; |
241 | - echo "<p>" . $_lang['table_prefix_already_inuse_note'] . '</p>'; |
|
241 | + echo "<p>".$_lang['table_prefix_already_inuse_note'].'</p>'; |
|
242 | 242 | } else { |
243 | - echo '<span class="ok">' . $_lang['ok'] . '</span></p>'; |
|
243 | + echo '<span class="ok">'.$_lang['ok'].'</span></p>'; |
|
244 | 244 | } |
245 | 245 | } elseif ($conn && $installMode == 2) { |
246 | - echo '<p>' . $_lang['checking_table_prefix'] . $table_prefix . '`: '; |
|
247 | - if (!$rs = mysqli_query($conn, "SELECT COUNT(*) FROM $dbase.`" . $table_prefix . "site_content`")) { |
|
248 | - echo '<span class="notok">' . $_lang['failed'] . '</span></b>' . $_lang['table_prefix_not_exist'] . '</p>'; |
|
246 | + echo '<p>'.$_lang['checking_table_prefix'].$table_prefix.'`: '; |
|
247 | + if (!$rs = mysqli_query($conn, "SELECT COUNT(*) FROM $dbase.`".$table_prefix."site_content`")) { |
|
248 | + echo '<span class="notok">'.$_lang['failed'].'</span></b>'.$_lang['table_prefix_not_exist'].'</p>'; |
|
249 | 249 | $errors++; |
250 | - echo '<p>' . $_lang['table_prefix_not_exist_note'] . '</p>'; |
|
250 | + echo '<p>'.$_lang['table_prefix_not_exist_note'].'</p>'; |
|
251 | 251 | } else { |
252 | - echo '<span class="ok">' . $_lang['ok'] . '</span></p>'; |
|
252 | + echo '<span class="ok">'.$_lang['ok'].'</span></p>'; |
|
253 | 253 | } |
254 | 254 | } |
255 | 255 | |
256 | 256 | // check mysql version |
257 | 257 | if ($conn) { |
258 | - echo '<p>' . $_lang['checking_mysql_version']; |
|
259 | - if ( version_compare(mysqli_get_server_info($conn), '5.0.51', '=') ) { |
|
260 | - echo '<span class="notok">' . $_lang['warning'] . '</span></b> <strong>' . $_lang['mysql_5051'] . '</strong></p>'; |
|
261 | - echo '<p><span class="notok">' . $_lang['mysql_5051_warning'] . '</span></p>'; |
|
258 | + echo '<p>'.$_lang['checking_mysql_version']; |
|
259 | + if (version_compare(mysqli_get_server_info($conn), '5.0.51', '=')) { |
|
260 | + echo '<span class="notok">'.$_lang['warning'].'</span></b> <strong>'.$_lang['mysql_5051'].'</strong></p>'; |
|
261 | + echo '<p><span class="notok">'.$_lang['mysql_5051_warning'].'</span></p>'; |
|
262 | 262 | } else { |
263 | - echo '<span class="ok">' . $_lang['ok'] . '</span> <strong>' . $_lang['mysql_version_is'] . mysqli_get_server_info($conn) . '</strong></p>'; |
|
263 | + echo '<span class="ok">'.$_lang['ok'].'</span> <strong>'.$_lang['mysql_version_is'].mysqli_get_server_info($conn).'</strong></p>'; |
|
264 | 264 | } |
265 | 265 | } |
266 | 266 | |
267 | 267 | // check for strict mode |
268 | 268 | if ($conn) { |
269 | - echo '<p>'. $_lang['checking_mysql_strict_mode']; |
|
269 | + echo '<p>'.$_lang['checking_mysql_strict_mode']; |
|
270 | 270 | $mysqlmode = mysqli_query($conn, "SELECT @@global.sql_mode"); |
271 | - if (mysqli_num_rows($mysqlmode) > 0){ |
|
271 | + if (mysqli_num_rows($mysqlmode) > 0) { |
|
272 | 272 | $modes = mysqli_fetch_array($mysqlmode, MYSQLI_NUM); |
273 | 273 | //$modes = array("STRICT_TRANS_TABLES"); // for testing |
274 | 274 | // print_r($modes); |
275 | 275 | foreach ($modes as $mode) { |
276 | 276 | if (stristr($mode, "STRICT_TRANS_TABLES") !== false || stristr($mode, "STRICT_ALL_TABLES") !== false) { |
277 | - echo '<span class="notok">' . $_lang['warning'] . '</span></b> <strong> ' . $_lang['strict_mode'] . '</strong></p>'; |
|
278 | - echo '<p><span class="notok">' . $_lang['strict_mode_error'] . '</span></p>'; |
|
277 | + echo '<span class="notok">'.$_lang['warning'].'</span></b> <strong> '.$_lang['strict_mode'].'</strong></p>'; |
|
278 | + echo '<p><span class="notok">'.$_lang['strict_mode_error'].'</span></p>'; |
|
279 | 279 | } else { |
280 | - echo '<span class="ok">' . $_lang['ok'] . '</span></p>'; |
|
280 | + echo '<span class="ok">'.$_lang['ok'].'</span></p>'; |
|
281 | 281 | } |
282 | 282 | } |
283 | 283 | } else { |
284 | - echo '<span class="ok">' . $_lang['ok'] . '</span></p>'; |
|
284 | + echo '<span class="ok">'.$_lang['ok'].'</span></p>'; |
|
285 | 285 | } |
286 | 286 | } |
287 | 287 | // Version and strict mode check end |
@@ -297,18 +297,18 @@ discard block |
||
297 | 297 | f_owc("../assets/cache/installProc.inc.php", '<?php $installStartTime = '.time().'; ?>'); |
298 | 298 | } |
299 | 299 | |
300 | -if($installMode > 0 && $_POST['installdata'] == "1") { |
|
301 | - echo '<p class="notes"><strong>' . $_lang['sample_web_site'] . ':</strong> ' . $_lang['sample_web_site_note'] . '</p>'; |
|
300 | +if ($installMode > 0 && $_POST['installdata'] == "1") { |
|
301 | + echo '<p class="notes"><strong>'.$_lang['sample_web_site'].':</strong> '.$_lang['sample_web_site_note'].'</p>'; |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | if ($errors > 0) { |
305 | 305 | echo '<p>'; |
306 | - echo $_lang['setup_cannot_continue'] . ' '; |
|
306 | + echo $_lang['setup_cannot_continue'].' '; |
|
307 | 307 | |
308 | - if($errors > 1){ |
|
309 | - echo $errors . " " . $_lang['errors'] . $_lang['please_correct_errors'] . $_lang['and_try_again_plural']; |
|
310 | - }else{ |
|
311 | - echo $_lang['error'] . $_lang['please_correct_error'] . $_lang['and_try_again']; |
|
308 | + if ($errors > 1) { |
|
309 | + echo $errors." ".$_lang['errors'].$_lang['please_correct_errors'].$_lang['and_try_again_plural']; |
|
310 | + } else { |
|
311 | + echo $_lang['error'].$_lang['please_correct_error'].$_lang['and_try_again']; |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | echo $_lang['visit_forum']; |
@@ -317,10 +317,10 @@ discard block |
||
317 | 317 | |
318 | 318 | echo '<p> </p>'; |
319 | 319 | |
320 | -$nextAction= $errors > 0 ? 'summary' : 'install'; |
|
321 | -$nextButton= $errors > 0 ? $_lang['retry'] : $_lang['install']; |
|
322 | -$nextVisibility= $errors > 0 || isset($_POST['chkagree']) ? 'visible' : 'hidden'; |
|
323 | -$agreeToggle= $errors > 0 ? '' : ' onclick="if(document.getElementById(\'chkagree\').checked){document.getElementById(\'nextbutton\').style.visibility=\'visible\';}else{document.getElementById(\'nextbutton\').style.visibility=\'hidden\';}"'; |
|
320 | +$nextAction = $errors > 0 ? 'summary' : 'install'; |
|
321 | +$nextButton = $errors > 0 ? $_lang['retry'] : $_lang['install']; |
|
322 | +$nextVisibility = $errors > 0 || isset($_POST['chkagree']) ? 'visible' : 'hidden'; |
|
323 | +$agreeToggle = $errors > 0 ? '' : ' onclick="if(document.getElementById(\'chkagree\').checked){document.getElementById(\'nextbutton\').style.visibility=\'visible\';}else{document.getElementById(\'nextbutton\').style.visibility=\'hidden\';}"'; |
|
324 | 324 | ?> |
325 | 325 | <form name="install" id="install_form" action="index.php?action=<?php echo $nextAction ?>" method="post"> |
326 | 326 | <div> |
@@ -342,32 +342,32 @@ discard block |
||
342 | 342 | |
343 | 343 | <input type="hidden" value="<?php echo $_POST['installdata'] ?>" name="installdata" /> |
344 | 344 | <?php |
345 | - $templates = isset ($_POST['template']) ? $_POST['template'] : array (); |
|
345 | + $templates = isset ($_POST['template']) ? $_POST['template'] : array(); |
|
346 | 346 | foreach ($templates as $i => $template) echo '<input type="hidden" name="template[]" value="'.$template.'" />'; |
347 | 347 | |
348 | - $tvs = isset ($_POST['tv']) ? $_POST['tv'] : array (); |
|
348 | + $tvs = isset ($_POST['tv']) ? $_POST['tv'] : array(); |
|
349 | 349 | foreach ($tvs as $i => $tv) echo '<input type="hidden" name="tv[]" value="'.$tv.'" />'; |
350 | 350 | |
351 | - $chunks = isset ($_POST['chunk']) ? $_POST['chunk'] : array (); |
|
351 | + $chunks = isset ($_POST['chunk']) ? $_POST['chunk'] : array(); |
|
352 | 352 | foreach ($chunks as $i => $chunk) echo '<input type="hidden" name="chunk[]" value="'.$chunk.'" />'; |
353 | 353 | |
354 | - $snippets = isset ($_POST['snippet']) ? $_POST['snippet'] : array (); |
|
354 | + $snippets = isset ($_POST['snippet']) ? $_POST['snippet'] : array(); |
|
355 | 355 | foreach ($snippets as $i => $snippet) echo '<input type="hidden" name="snippet[]" value="'.$snippet.'" />'; |
356 | 356 | |
357 | - $plugins = isset ($_POST['plugin']) ? $_POST['plugin'] : array (); |
|
357 | + $plugins = isset ($_POST['plugin']) ? $_POST['plugin'] : array(); |
|
358 | 358 | foreach ($plugins as $i => $plugin) echo '<input type="hidden" name="plugin[]" value="'.$plugin.'" />'; |
359 | 359 | |
360 | - $modules = isset ($_POST['module']) ? $_POST['module'] : array (); |
|
360 | + $modules = isset ($_POST['module']) ? $_POST['module'] : array(); |
|
361 | 361 | foreach ($modules as $i => $module) echo '<input type="hidden" name="module[]" value="'.$module.'" />'; |
362 | 362 | ?> |
363 | 363 | </div> |
364 | 364 | |
365 | -<h2><?php echo $_lang['agree_to_terms'];?></h2> |
|
365 | +<h2><?php echo $_lang['agree_to_terms']; ?></h2> |
|
366 | 366 | <p> |
367 | -<input type="checkbox" value="1" id="chkagree" name="chkagree" style="line-height:18px" <?php echo isset($_POST['chkagree']) ? 'checked="checked" ':""; ?><?php echo $agreeToggle;?>/><label for="chkagree" style="display:inline;float:none;line-height:18px;"> <?php echo $_lang['iagree_box']?> </label> |
|
367 | +<input type="checkbox" value="1" id="chkagree" name="chkagree" style="line-height:18px" <?php echo isset($_POST['chkagree']) ? 'checked="checked" ' : ""; ?><?php echo $agreeToggle; ?>/><label for="chkagree" style="display:inline;float:none;line-height:18px;"> <?php echo $_lang['iagree_box']?> </label> |
|
368 | 368 | </p> |
369 | 369 | <p class="buttonlinks"> |
370 | 370 | <a href="javascript:document.getElementById('install_form').action='index.php?action=options&language=<?php echo $install_language?>';document.getElementById('install_form').submit();" class="prev" title="<?php echo $_lang['btnback_value']?>"><span><?php echo $_lang['btnback_value']?></span></a> |
371 | - <a id="nextbutton" href="javascript:document.getElementById('install_form').submit();" title="<?php echo $nextButton ?>" style="visibility:<?php echo $nextVisibility;?>"><span><?php echo $nextButton ?></span></a> |
|
371 | + <a id="nextbutton" href="javascript:document.getElementById('install_form').submit();" title="<?php echo $nextButton ?>" style="visibility:<?php echo $nextVisibility; ?>"><span><?php echo $nextButton ?></span></a> |
|
372 | 372 | </p> |
373 | 373 | </form> |
@@ -1,19 +1,22 @@ discard block |
||
1 | 1 | <?php |
2 | -if( ! function_exists('f_owc')){ |
|
2 | +if( ! function_exists('f_owc')) { |
|
3 | 3 | /** |
4 | 4 | * @param $path |
5 | 5 | * @param $data |
6 | 6 | * @param null|int $mode |
7 | 7 | */ |
8 | - function f_owc($path, $data, $mode = null){ |
|
8 | + function f_owc($path, $data, $mode = null) |
|
9 | + { |
|
9 | 10 | try { |
10 | 11 | // make an attempt to create the file |
11 | 12 | $hnd = fopen($path, 'w'); |
12 | 13 | fwrite($hnd, $data); |
13 | 14 | fclose($hnd); |
14 | 15 | |
15 | - if(null !== $mode) chmod($path, $mode); |
|
16 | - }catch(Exception $e){ |
|
16 | + if(null !== $mode) { |
|
17 | + chmod($path, $mode); |
|
18 | + } |
|
19 | + } catch(Exception $e) { |
|
17 | 20 | // Nothing, this is NOT normal |
18 | 21 | unset($e); |
19 | 22 | } |
@@ -21,7 +24,9 @@ discard block |
||
21 | 24 | } |
22 | 25 | |
23 | 26 | $installMode = isset($_POST['installmode']) ? (int)$_POST['installmode'] : 0; |
24 | -if( ! isset($_lang)) $_lang = array(); |
|
27 | +if( ! isset($_lang)) { |
|
28 | + $_lang = array(); |
|
29 | +} |
|
25 | 30 | |
26 | 31 | echo '<div class="stepcontainer"> |
27 | 32 | <ul class="progressbar"> |
@@ -57,7 +62,7 @@ discard block |
||
57 | 62 | // check if iconv is available |
58 | 63 | echo '<p>' . $_lang['checking_iconv']; |
59 | 64 | $iconv = (int) function_exists('iconv'); |
60 | -if ($iconv == '0'){ |
|
65 | +if ($iconv == '0') { |
|
61 | 66 | echo '<span class="notok">' . $_lang['failed'].'</span></p><p><strong>'.$_lang['checking_iconv_note'].'</strong></p>'; |
62 | 67 | $errors++; |
63 | 68 | } else { |
@@ -119,7 +124,7 @@ discard block |
||
119 | 124 | |
120 | 125 | // File Browser directories exists? |
121 | 126 | echo '<p>'.$_lang['checking_if_images_exist']; |
122 | -switch(true){ |
|
127 | +switch(true) { |
|
123 | 128 | case !file_exists("../assets/images"): |
124 | 129 | case !file_exists("../assets/files"): |
125 | 130 | case !file_exists("../assets/backup"): |
@@ -134,7 +139,7 @@ discard block |
||
134 | 139 | |
135 | 140 | // File Browser directories writable? |
136 | 141 | echo '<p>'.$_lang['checking_if_images_writable']; |
137 | -switch(true){ |
|
142 | +switch(true) { |
|
138 | 143 | case !is_writable("../assets/images"): |
139 | 144 | case !is_writable("../assets/files"): |
140 | 145 | case !is_writable("../assets/backup"): |
@@ -268,7 +273,7 @@ discard block |
||
268 | 273 | if ($conn) { |
269 | 274 | echo '<p>'. $_lang['checking_mysql_strict_mode']; |
270 | 275 | $mysqlmode = mysqli_query($conn, "SELECT @@global.sql_mode"); |
271 | - if (mysqli_num_rows($mysqlmode) > 0){ |
|
276 | + if (mysqli_num_rows($mysqlmode) > 0) { |
|
272 | 277 | $modes = mysqli_fetch_array($mysqlmode, MYSQLI_NUM); |
273 | 278 | //$modes = array("STRICT_TRANS_TABLES"); // for testing |
274 | 279 | // print_r($modes); |
@@ -305,9 +310,9 @@ discard block |
||
305 | 310 | echo '<p>'; |
306 | 311 | echo $_lang['setup_cannot_continue'] . ' '; |
307 | 312 | |
308 | - if($errors > 1){ |
|
313 | + if($errors > 1) { |
|
309 | 314 | echo $errors . " " . $_lang['errors'] . $_lang['please_correct_errors'] . $_lang['and_try_again_plural']; |
310 | - }else{ |
|
315 | + } else { |
|
311 | 316 | echo $_lang['error'] . $_lang['please_correct_error'] . $_lang['and_try_again']; |
312 | 317 | } |
313 | 318 | |
@@ -343,23 +348,35 @@ discard block |
||
343 | 348 | <input type="hidden" value="<?php echo $_POST['installdata'] ?>" name="installdata" /> |
344 | 349 | <?php |
345 | 350 | $templates = isset ($_POST['template']) ? $_POST['template'] : array (); |
346 | - foreach ($templates as $i => $template) echo '<input type="hidden" name="template[]" value="'.$template.'" />'; |
|
351 | + foreach ($templates as $i => $template) { |
|
352 | + echo '<input type="hidden" name="template[]" value="'.$template.'" />'; |
|
353 | + } |
|
347 | 354 | |
348 | 355 | $tvs = isset ($_POST['tv']) ? $_POST['tv'] : array (); |
349 | - foreach ($tvs as $i => $tv) echo '<input type="hidden" name="tv[]" value="'.$tv.'" />'; |
|
356 | + foreach ($tvs as $i => $tv) { |
|
357 | + echo '<input type="hidden" name="tv[]" value="'.$tv.'" />'; |
|
358 | + } |
|
350 | 359 | |
351 | 360 | $chunks = isset ($_POST['chunk']) ? $_POST['chunk'] : array (); |
352 | - foreach ($chunks as $i => $chunk) echo '<input type="hidden" name="chunk[]" value="'.$chunk.'" />'; |
|
361 | + foreach ($chunks as $i => $chunk) { |
|
362 | + echo '<input type="hidden" name="chunk[]" value="'.$chunk.'" />'; |
|
363 | + } |
|
353 | 364 | |
354 | 365 | $snippets = isset ($_POST['snippet']) ? $_POST['snippet'] : array (); |
355 | - foreach ($snippets as $i => $snippet) echo '<input type="hidden" name="snippet[]" value="'.$snippet.'" />'; |
|
366 | + foreach ($snippets as $i => $snippet) { |
|
367 | + echo '<input type="hidden" name="snippet[]" value="'.$snippet.'" />'; |
|
368 | + } |
|
356 | 369 | |
357 | 370 | $plugins = isset ($_POST['plugin']) ? $_POST['plugin'] : array (); |
358 | - foreach ($plugins as $i => $plugin) echo '<input type="hidden" name="plugin[]" value="'.$plugin.'" />'; |
|
371 | + foreach ($plugins as $i => $plugin) { |
|
372 | + echo '<input type="hidden" name="plugin[]" value="'.$plugin.'" />'; |
|
373 | + } |
|
359 | 374 | |
360 | 375 | $modules = isset ($_POST['module']) ? $_POST['module'] : array (); |
361 | - foreach ($modules as $i => $module) echo '<input type="hidden" name="module[]" value="'.$module.'" />'; |
|
362 | -?> |
|
376 | + foreach ($modules as $i => $module) { |
|
377 | + echo '<input type="hidden" name="module[]" value="'.$module.'" />'; |
|
378 | + } |
|
379 | + ?> |
|
363 | 380 | </div> |
364 | 381 | |
365 | 382 | <h2><?php echo $_lang['agree_to_terms'];?></h2> |
@@ -207,7 +207,7 @@ |
||
207 | 207 | |
208 | 208 | |
209 | 209 | // make sure we can use the database |
210 | -if ($installMode > 0 && !mysqli_query($conn, "USE {$dbase}")) { |
|
210 | +if ($installMode > 0 && !mysqli_query($conn, "use {$dbase}")) { |
|
211 | 211 | $errors++; |
212 | 212 | echo '<span class="notok">'.$_lang['database_use_failed'].'</span><p />'.$_lang["database_use_failed_note"].'</p>'; |
213 | 213 | } |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Determine upgradeability |
3 | 3 | $upgradeable = 0; |
4 | -if (is_file($base_path . MGR_DIR . '/includes/config.inc.php')) { // Include the file so we can test its validity |
|
5 | - include $base_path . MGR_DIR . '/includes/config.inc.php'; |
|
4 | +if (is_file($base_path.MGR_DIR.'/includes/config.inc.php')) { // Include the file so we can test its validity |
|
5 | + include $base_path.MGR_DIR.'/includes/config.inc.php'; |
|
6 | 6 | // We need to have all connection settings - tho prefix may be empty so we have to ignore it |
7 | 7 | if (isset($dbase)) { |
8 | 8 | if (!$conn = @mysqli_connect($database_server, $database_user, $database_password)) |
@@ -17,16 +17,16 @@ discard block |
||
17 | 17 | } |
18 | 18 | |
19 | 19 | $ph['moduleName'] = $moduleName; |
20 | -$ph['displayNew'] = ($upgradeable!=0) ? 'display:none;' : ''; |
|
21 | -$ph['displayUpg'] = ($upgradeable==0) ? 'display:none;' : ''; |
|
20 | +$ph['displayNew'] = ($upgradeable != 0) ? 'display:none;' : ''; |
|
21 | +$ph['displayUpg'] = ($upgradeable == 0) ? 'display:none;' : ''; |
|
22 | 22 | $ph['displayAdvUpg'] = $ph['displayUpg']; |
23 | -$ph['checkedNew'] = !$upgradeable ? 'checked' : ''; |
|
24 | -$ph['checkedUpg'] = ($_POST['installmode']==1 || $upgradeable==1) ? 'checked' : ''; |
|
25 | -$ph['checkedAdvUpg'] = ($_POST['installmode']==2 || $upgradeable==2) ? 'checked' : ''; |
|
23 | +$ph['checkedNew'] = !$upgradeable ? 'checked' : ''; |
|
24 | +$ph['checkedUpg'] = ($_POST['installmode'] == 1 || $upgradeable == 1) ? 'checked' : ''; |
|
25 | +$ph['checkedAdvUpg'] = ($_POST['installmode'] == 2 || $upgradeable == 2) ? 'checked' : ''; |
|
26 | 26 | $ph['install_language'] = $install_language; |
27 | -$ph['disabledUpg'] = ($upgradeable!=1) ? 'disabled' : ''; |
|
28 | -$ph['disabledAdvUpg'] = ($upgradeable==0) ? 'disabled' : ''; |
|
27 | +$ph['disabledUpg'] = ($upgradeable != 1) ? 'disabled' : ''; |
|
28 | +$ph['disabledAdvUpg'] = ($upgradeable == 0) ? 'disabled' : ''; |
|
29 | 29 | |
30 | -$tpl = file_get_contents($base_path . 'install/actions/tpl_mode.html'); |
|
30 | +$tpl = file_get_contents($base_path.'install/actions/tpl_mode.html'); |
|
31 | 31 | $content = parse($tpl, $ph); |
32 | -echo parse($content, $_lang,'[%','%]'); |
|
32 | +echo parse($content, $_lang, '[%', '%]'); |
@@ -1,20 +1,22 @@ |
||
1 | 1 | <?php |
2 | 2 | // Determine upgradeability |
3 | 3 | $upgradeable = 0; |
4 | -if (is_file($base_path . MGR_DIR . '/includes/config.inc.php')) { // Include the file so we can test its validity |
|
4 | +if (is_file($base_path . MGR_DIR . '/includes/config.inc.php')) { |
|
5 | +// Include the file so we can test its validity |
|
5 | 6 | include $base_path . MGR_DIR . '/includes/config.inc.php'; |
6 | 7 | // We need to have all connection settings - tho prefix may be empty so we have to ignore it |
7 | 8 | if (isset($dbase)) { |
8 | - if (!$conn = @mysqli_connect($database_server, $database_user, $database_password)) |
|
9 | - $upgradeable = isset($_POST['installmode']) && $_POST['installmode'] == 'new' ? 0 : 2; |
|
10 | - elseif (!@mysqli_select_db($conn, trim($dbase, '`'))) |
|
11 | - $upgradeable = isset($_POST['installmode']) && $_POST['installmode'] == 'new' ? 0 : 2; |
|
12 | - else |
|
13 | - $upgradeable = 1; |
|
9 | + if (!$conn = @mysqli_connect($database_server, $database_user, $database_password)) { |
|
10 | + $upgradeable = isset($_POST['installmode']) && $_POST['installmode'] == 'new' ? 0 : 2; |
|
11 | + } elseif (!@mysqli_select_db($conn, trim($dbase, '`'))) { |
|
12 | + $upgradeable = isset($_POST['installmode']) && $_POST['installmode'] == 'new' ? 0 : 2; |
|
13 | + } else { |
|
14 | + $upgradeable = 1; |
|
15 | + } |
|
16 | + } else { |
|
17 | + $upgradeable = 2; |
|
18 | + } |
|
14 | 19 | } |
15 | - else |
|
16 | - $upgradeable = 2; |
|
17 | -} |
|
18 | 20 | |
19 | 21 | $ph['moduleName'] = $moduleName; |
20 | 22 | $ph['displayNew'] = ($upgradeable!=0) ? 'display:none;' : ''; |
@@ -15,7 +15,7 @@ |
||
15 | 15 | case 1: |
16 | 16 | include $base_path . MGR_DIR . '/includes/config.inc.php'; |
17 | 17 | if (@ $conn = mysqli_connect($database_server, $database_user, $database_password)) { |
18 | - if (@ mysqli_query($conn, "USE {$dbase}")) { |
|
18 | + if (@ mysqli_query($conn, "use {$dbase}")) { |
|
19 | 19 | if (!$rs = mysqli_query($conn, "show session variables like 'collation_database'")) { |
20 | 20 | $rs = mysqli_query($conn, "show session variables like 'collation_server'"); |
21 | 21 | } |
@@ -190,53 +190,53 @@ |
||
190 | 190 | } |
191 | 191 | |
192 | 192 | switch($installMode){ |
193 | - case 0: |
|
194 | - case 2: |
|
195 | - $database_collation = isset($_POST['database_collation']) ? $_POST['database_collation'] : 'utf8_general_ci'; |
|
196 | - $database_charset = substr($database_collation, 0, strpos($database_collation, '_')); |
|
197 | - $_POST['database_connection_charset'] = $database_charset; |
|
198 | - if(empty($_SESSION['databaseloginpassword'])) |
|
199 | - $_SESSION['databaseloginpassword'] = $_POST['databaseloginpassword']; |
|
200 | - if(empty($_SESSION['databaseloginname'])) |
|
201 | - $_SESSION['databaseloginname'] = $_POST['databaseloginname']; |
|
202 | - break; |
|
203 | - case 1: |
|
204 | - include $base_path . MGR_DIR . '/includes/config.inc.php'; |
|
205 | - if (@ $conn = mysqli_connect($database_server, $database_user, $database_password)) { |
|
206 | - if (@ mysqli_query($conn, "USE {$dbase}")) { |
|
207 | - if (!$rs = mysqli_query($conn, "show session variables like 'collation_database'")) { |
|
208 | - $rs = mysqli_query($conn, "show session variables like 'collation_server'"); |
|
209 | - } |
|
210 | - if ($rs && $collation = mysqli_fetch_row($rs)) { |
|
211 | - $database_collation = trim($collation[1]); |
|
193 | + case 0: |
|
194 | + case 2: |
|
195 | + $database_collation = isset($_POST['database_collation']) ? $_POST['database_collation'] : 'utf8_general_ci'; |
|
196 | + $database_charset = substr($database_collation, 0, strpos($database_collation, '_')); |
|
197 | + $_POST['database_connection_charset'] = $database_charset; |
|
198 | + if(empty($_SESSION['databaseloginpassword'])) |
|
199 | + $_SESSION['databaseloginpassword'] = $_POST['databaseloginpassword']; |
|
200 | + if(empty($_SESSION['databaseloginname'])) |
|
201 | + $_SESSION['databaseloginname'] = $_POST['databaseloginname']; |
|
202 | + break; |
|
203 | + case 1: |
|
204 | + include $base_path . MGR_DIR . '/includes/config.inc.php'; |
|
205 | + if (@ $conn = mysqli_connect($database_server, $database_user, $database_password)) { |
|
206 | + if (@ mysqli_query($conn, "USE {$dbase}")) { |
|
207 | + if (!$rs = mysqli_query($conn, "show session variables like 'collation_database'")) { |
|
208 | + $rs = mysqli_query($conn, "show session variables like 'collation_server'"); |
|
209 | + } |
|
210 | + if ($rs && $collation = mysqli_fetch_row($rs)) { |
|
211 | + $database_collation = trim($collation[1]); |
|
212 | + } |
|
212 | 213 | } |
213 | 214 | } |
214 | - } |
|
215 | - if (empty ($database_collation)) $database_collation = 'utf8_general_ci'; |
|
215 | + if (empty ($database_collation)) $database_collation = 'utf8_general_ci'; |
|
216 | 216 | |
217 | - $database_charset = substr($database_collation, 0, strpos($database_collation, '_')); |
|
218 | - if (!isset ($database_connection_charset) || empty ($database_connection_charset)) { |
|
219 | - $database_connection_charset = $database_charset; |
|
220 | - } |
|
217 | + $database_charset = substr($database_collation, 0, strpos($database_collation, '_')); |
|
218 | + if (!isset ($database_connection_charset) || empty ($database_connection_charset)) { |
|
219 | + $database_connection_charset = $database_charset; |
|
220 | + } |
|
221 | 221 | |
222 | - if (!isset ($database_connection_method) || empty ($database_connection_method)) { |
|
223 | - $database_connection_method = 'SET CHARACTER SET'; |
|
224 | - if (function_exists('mysqli_set_charset')) mysqli_set_charset($conn, $database_connection_charset); |
|
225 | - } |
|
226 | - if ($database_connection_method != 'SET NAMES' && $database_connection_charset != $database_charset) { |
|
227 | - $database_connection_method = 'SET NAMES'; |
|
228 | - } |
|
222 | + if (!isset ($database_connection_method) || empty ($database_connection_method)) { |
|
223 | + $database_connection_method = 'SET CHARACTER SET'; |
|
224 | + if (function_exists('mysqli_set_charset')) mysqli_set_charset($conn, $database_connection_charset); |
|
225 | + } |
|
226 | + if ($database_connection_method != 'SET NAMES' && $database_connection_charset != $database_charset) { |
|
227 | + $database_connection_method = 'SET NAMES'; |
|
228 | + } |
|
229 | 229 | |
230 | - $_POST['database_name'] = $dbase; |
|
231 | - $_POST['tableprefix'] = $table_prefix; |
|
232 | - $_POST['database_connection_charset'] = $database_connection_charset; |
|
233 | - $_POST['database_connection_method'] = $database_connection_method; |
|
234 | - $_POST['databasehost'] = $database_server; |
|
235 | - $_SESSION['databaseloginname'] = $database_user; |
|
236 | - $_SESSION['databaseloginpassword'] = $database_password; |
|
237 | - break; |
|
238 | - default: |
|
239 | - throw new Exception('installmode is undefined'); |
|
230 | + $_POST['database_name'] = $dbase; |
|
231 | + $_POST['tableprefix'] = $table_prefix; |
|
232 | + $_POST['database_connection_charset'] = $database_connection_charset; |
|
233 | + $_POST['database_connection_method'] = $database_connection_method; |
|
234 | + $_POST['databasehost'] = $database_server; |
|
235 | + $_SESSION['databaseloginname'] = $database_user; |
|
236 | + $_SESSION['databaseloginpassword'] = $database_password; |
|
237 | + break; |
|
238 | + default: |
|
239 | + throw new Exception('installmode is undefined'); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | $ph['install_language'] = $install_language; |
@@ -189,16 +189,18 @@ discard block |
||
189 | 189 | } |
190 | 190 | } |
191 | 191 | |
192 | -switch($installMode){ |
|
192 | +switch($installMode) { |
|
193 | 193 | case 0: |
194 | 194 | case 2: |
195 | 195 | $database_collation = isset($_POST['database_collation']) ? $_POST['database_collation'] : 'utf8_general_ci'; |
196 | 196 | $database_charset = substr($database_collation, 0, strpos($database_collation, '_')); |
197 | 197 | $_POST['database_connection_charset'] = $database_charset; |
198 | - if(empty($_SESSION['databaseloginpassword'])) |
|
199 | - $_SESSION['databaseloginpassword'] = $_POST['databaseloginpassword']; |
|
200 | - if(empty($_SESSION['databaseloginname'])) |
|
201 | - $_SESSION['databaseloginname'] = $_POST['databaseloginname']; |
|
198 | + if(empty($_SESSION['databaseloginpassword'])) { |
|
199 | + $_SESSION['databaseloginpassword'] = $_POST['databaseloginpassword']; |
|
200 | + } |
|
201 | + if(empty($_SESSION['databaseloginname'])) { |
|
202 | + $_SESSION['databaseloginname'] = $_POST['databaseloginname']; |
|
203 | + } |
|
202 | 204 | break; |
203 | 205 | case 1: |
204 | 206 | include $base_path . MGR_DIR . '/includes/config.inc.php'; |
@@ -212,7 +214,9 @@ discard block |
||
212 | 214 | } |
213 | 215 | } |
214 | 216 | } |
215 | - if (empty ($database_collation)) $database_collation = 'utf8_general_ci'; |
|
217 | + if (empty ($database_collation)) { |
|
218 | + $database_collation = 'utf8_general_ci'; |
|
219 | + } |
|
216 | 220 | |
217 | 221 | $database_charset = substr($database_collation, 0, strpos($database_collation, '_')); |
218 | 222 | if (!isset ($database_connection_charset) || empty ($database_connection_charset)) { |
@@ -221,7 +225,9 @@ discard block |
||
221 | 225 | |
222 | 226 | if (!isset ($database_connection_method) || empty ($database_connection_method)) { |
223 | 227 | $database_connection_method = 'SET CHARACTER SET'; |
224 | - if (function_exists('mysqli_set_charset')) mysqli_set_charset($conn, $database_connection_charset); |
|
228 | + if (function_exists('mysqli_set_charset')) { |
|
229 | + mysqli_set_charset($conn, $database_connection_charset); |
|
230 | + } |
|
225 | 231 | } |
226 | 232 | if ($database_connection_method != 'SET NAMES' && $database_connection_charset != $database_charset) { |
227 | 233 | $database_connection_method = 'SET NAMES'; |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | -$installMode = isset($_POST['installmode']) ? (int)$_POST['installmode'] : 0; |
|
2 | +$installMode = isset($_POST['installmode']) ? (int) $_POST['installmode'] : 0; |
|
3 | 3 | |
4 | -if( ! function_exists('getTemplates')) { |
|
4 | +if (!function_exists('getTemplates')) { |
|
5 | 5 | /** |
6 | 6 | * @param array $presets |
7 | 7 | * @return string |
@@ -26,12 +26,12 @@ discard block |
||
26 | 26 | $i++; |
27 | 27 | } |
28 | 28 | if (0 < count($_)) { |
29 | - return '<h3>[%templates%]</h3>' . implode("\n", $_); |
|
29 | + return '<h3>[%templates%]</h3>'.implode("\n", $_); |
|
30 | 30 | } |
31 | 31 | } |
32 | 32 | } |
33 | 33 | |
34 | -if( ! function_exists('getTVs')) { |
|
34 | +if (!function_exists('getTVs')) { |
|
35 | 35 | /** |
36 | 36 | * @param array $presets |
37 | 37 | * @return string |
@@ -57,12 +57,12 @@ discard block |
||
57 | 57 | $i++; |
58 | 58 | } |
59 | 59 | if (0 < count($_)) { |
60 | - return '<h3>[%tvs%]</h3>' . implode("\n", $_); |
|
60 | + return '<h3>[%tvs%]</h3>'.implode("\n", $_); |
|
61 | 61 | } |
62 | 62 | } |
63 | 63 | } |
64 | 64 | |
65 | -if( ! function_exists('getChunks')) { |
|
65 | +if (!function_exists('getChunks')) { |
|
66 | 66 | /** |
67 | 67 | * display chunks |
68 | 68 | * |
@@ -89,12 +89,12 @@ discard block |
||
89 | 89 | $i++; |
90 | 90 | } |
91 | 91 | if (0 < count($_)) { |
92 | - return '<h3>[%chunks%]</h3>' . implode("\n", $_); |
|
92 | + return '<h3>[%chunks%]</h3>'.implode("\n", $_); |
|
93 | 93 | } |
94 | 94 | } |
95 | 95 | } |
96 | 96 | |
97 | -if( ! function_exists('getModules')) { |
|
97 | +if (!function_exists('getModules')) { |
|
98 | 98 | /** |
99 | 99 | * display modules |
100 | 100 | * |
@@ -121,12 +121,12 @@ discard block |
||
121 | 121 | $i++; |
122 | 122 | } |
123 | 123 | if (0 < count($_)) { |
124 | - return '<h3>[%modules%]</h3>' . implode("\n", $_); |
|
124 | + return '<h3>[%modules%]</h3>'.implode("\n", $_); |
|
125 | 125 | } |
126 | 126 | } |
127 | 127 | } |
128 | 128 | |
129 | -if( ! function_exists('getPlugins')) { |
|
129 | +if (!function_exists('getPlugins')) { |
|
130 | 130 | /** |
131 | 131 | * display plugins |
132 | 132 | * |
@@ -157,12 +157,12 @@ discard block |
||
157 | 157 | $i++; |
158 | 158 | } |
159 | 159 | if (0 < count($_)) { |
160 | - return '<h3>[%plugins%]</h3>' . implode("\n", $_); |
|
160 | + return '<h3>[%plugins%]</h3>'.implode("\n", $_); |
|
161 | 161 | } |
162 | 162 | } |
163 | 163 | } |
164 | 164 | |
165 | -if( ! function_exists('getSnippets')) { |
|
165 | +if (!function_exists('getSnippets')) { |
|
166 | 166 | /** |
167 | 167 | * display snippets |
168 | 168 | * |
@@ -189,24 +189,24 @@ discard block |
||
189 | 189 | $i++; |
190 | 190 | } |
191 | 191 | if (0 < count($_)) { |
192 | - return '<h3>[%snippets%]</h3>' . implode("\n", $_); |
|
192 | + return '<h3>[%snippets%]</h3>'.implode("\n", $_); |
|
193 | 193 | } |
194 | 194 | } |
195 | 195 | } |
196 | 196 | |
197 | -switch($installMode){ |
|
197 | +switch ($installMode) { |
|
198 | 198 | case 0: |
199 | 199 | case 2: |
200 | 200 | $database_collation = isset($_POST['database_collation']) ? $_POST['database_collation'] : 'utf8_general_ci'; |
201 | 201 | $database_charset = substr($database_collation, 0, strpos($database_collation, '_')); |
202 | 202 | $_POST['database_connection_charset'] = $database_charset; |
203 | - if(empty($_SESSION['databaseloginpassword'])) |
|
203 | + if (empty($_SESSION['databaseloginpassword'])) |
|
204 | 204 | $_SESSION['databaseloginpassword'] = $_POST['databaseloginpassword']; |
205 | - if(empty($_SESSION['databaseloginname'])) |
|
205 | + if (empty($_SESSION['databaseloginname'])) |
|
206 | 206 | $_SESSION['databaseloginname'] = $_POST['databaseloginname']; |
207 | 207 | break; |
208 | 208 | case 1: |
209 | - include $base_path . MGR_DIR . '/includes/config.inc.php'; |
|
209 | + include $base_path.MGR_DIR.'/includes/config.inc.php'; |
|
210 | 210 | if (@ $conn = mysqli_connect($database_server, $database_user, $database_password)) { |
211 | 211 | if (@ mysqli_query($conn, "USE {$dbase}")) { |
212 | 212 | if (!$rs = mysqli_query($conn, "show session variables like 'collation_database'")) { |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | $ph['checked'] = isset ($_POST['installdata']) && $_POST['installdata'] == "1" ? 'checked' : ''; |
262 | 262 | |
263 | 263 | # load setup information file |
264 | -include($base_path . 'install/setup.info.php'); |
|
264 | +include($base_path.'install/setup.info.php'); |
|
265 | 265 | $ph['templates'] = getTemplates($moduleTemplates); |
266 | 266 | $ph['tvs'] = getTVs($moduleTVs); |
267 | 267 | $ph['chunks'] = getChunks($moduleChunks); |
@@ -271,6 +271,6 @@ discard block |
||
271 | 271 | |
272 | 272 | $ph['action'] = ($installMode == 1) ? 'mode' : 'connection'; |
273 | 273 | |
274 | -$tpl = file_get_contents($base_path . 'install/actions/tpl_options.html'); |
|
275 | -$content = parse($tpl,$ph); |
|
276 | -echo parse($content,$_lang,'[%','%]'); |
|
274 | +$tpl = file_get_contents($base_path.'install/actions/tpl_options.html'); |
|
275 | +$content = parse($tpl, $ph); |
|
276 | +echo parse($content, $_lang, '[%', '%]'); |
@@ -48,6 +48,9 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -94,13 +94,13 @@ discard block |
||
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 |
||
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 |
@@ -16,27 +16,27 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -16,12 +16,14 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -3,23 +3,23 @@ |
||
3 | 3 | |
4 | 4 | // START HACK |
5 | 5 | if (isset ($modx)) { |
6 | - $user_id = $modx->getLoginUserID(); |
|
6 | + $user_id = $modx->getLoginUserID(); |
|
7 | 7 | } else { |
8 | - $user_id = $_SESSION['mgrInternalKey']; |
|
8 | + $user_id = $_SESSION['mgrInternalKey']; |
|
9 | 9 | } |
10 | 10 | // END HACK |
11 | 11 | |
12 | 12 | if (!empty($user_id)) { |
13 | - // Raymond: grab the user settings from the database. |
|
14 | - $rs = $modx->db->select('setting_name, setting_value', $modx->getFullTableName('user_settings'), "user=".$modx->getLoginUserID()); |
|
13 | + // Raymond: grab the user settings from the database. |
|
14 | + $rs = $modx->db->select('setting_name, setting_value', $modx->getFullTableName('user_settings'), "user=".$modx->getLoginUserID()); |
|
15 | 15 | |
16 | - $which_browser_default = $which_browser; |
|
17 | - while ($row = $modx->db->getRow($rs)) { |
|
18 | - if($row['setting_name'] == 'which_browser' && $row['setting_value'] == 'default') $row['setting_value'] = $which_browser_default; |
|
19 | - $settings[$row['setting_name']] = $row['setting_value']; |
|
20 | - if (isset($modx->config)) { |
|
21 | - $modx->config[$row['setting_name']] = $row['setting_value']; |
|
22 | - } |
|
23 | - } |
|
24 | - extract($settings, EXTR_OVERWRITE); |
|
16 | + $which_browser_default = $which_browser; |
|
17 | + while ($row = $modx->db->getRow($rs)) { |
|
18 | + if($row['setting_name'] == 'which_browser' && $row['setting_value'] == 'default') $row['setting_value'] = $which_browser_default; |
|
19 | + $settings[$row['setting_name']] = $row['setting_value']; |
|
20 | + if (isset($modx->config)) { |
|
21 | + $modx->config[$row['setting_name']] = $row['setting_value']; |
|
22 | + } |
|
23 | + } |
|
24 | + extract($settings, EXTR_OVERWRITE); |
|
25 | 25 | } |
@@ -1,5 +1,5 @@ discard block |
||
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 | |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | |
18 | 18 | $which_browser_default = $which_browser; |
19 | 19 | while ($row = $modx->db->getRow($rs)) { |
20 | - if($row['setting_name'] == 'which_browser' && $row['setting_value'] == 'default') $row['setting_value'] = $which_browser_default; |
|
20 | + if ($row['setting_name'] == 'which_browser' && $row['setting_value'] == 'default') $row['setting_value'] = $which_browser_default; |
|
21 | 21 | $settings[$row['setting_name']] = $row['setting_value']; |
22 | 22 | if (isset($modx->config)) { |
23 | 23 | $modx->config[$row['setting_name']] = $row['setting_value']; |
@@ -17,7 +17,9 @@ |
||
17 | 17 | |
18 | 18 | $which_browser_default = $which_browser; |
19 | 19 | while ($row = $modx->db->getRow($rs)) { |
20 | - if($row['setting_name'] == 'which_browser' && $row['setting_value'] == 'default') $row['setting_value'] = $which_browser_default; |
|
20 | + if($row['setting_name'] == 'which_browser' && $row['setting_value'] == 'default') { |
|
21 | + $row['setting_value'] = $which_browser_default; |
|
22 | + } |
|
21 | 23 | $settings[$row['setting_name']] = $row['setting_value']; |
22 | 24 | if (isset($modx->config)) { |
23 | 25 | $modx->config[$row['setting_name']] = $row['setting_value']; |
@@ -11,18 +11,18 @@ |
||
11 | 11 | */ |
12 | 12 | |
13 | 13 | function secureWebDocument($docid='') { |
14 | - global $modx; |
|
14 | + global $modx; |
|
15 | 15 | |
16 | - $modx->db->update('privateweb = 0', $modx->getFullTableName("site_content"), ($docid>0 ? "id='$docid'":"privateweb = 1")); |
|
17 | - $rs = $modx->db->select( |
|
18 | - 'DISTINCT sc.id', |
|
19 | - $modx->getFullTableName("site_content")." sc |
|
16 | + $modx->db->update('privateweb = 0', $modx->getFullTableName("site_content"), ($docid>0 ? "id='$docid'":"privateweb = 1")); |
|
17 | + $rs = $modx->db->select( |
|
18 | + 'DISTINCT sc.id', |
|
19 | + $modx->getFullTableName("site_content")." sc |
|
20 | 20 | LEFT JOIN ".$modx->getFullTableName("document_groups")." dg ON dg.document = sc.id |
21 | 21 | LEFT JOIN ".$modx->getFullTableName("webgroup_access")." wga ON wga.documentgroup = dg.document_group", |
22 | - ($docid>0 ? " sc.id='{$docid}' AND ":"")."wga.id>0" |
|
23 | - ); |
|
24 | - $ids = $modx->db->getColumn("id",$rs); |
|
25 | - if(count($ids)>0) { |
|
26 | - $modx->db->update('privateweb = 1', $modx->getFullTableName("site_content"), "id IN (".implode(", ",$ids).")"); |
|
27 | - } |
|
22 | + ($docid>0 ? " sc.id='{$docid}' AND ":"")."wga.id>0" |
|
23 | + ); |
|
24 | + $ids = $modx->db->getColumn("id",$rs); |
|
25 | + if(count($ids)>0) { |
|
26 | + $modx->db->update('privateweb = 1', $modx->getFullTableName("site_content"), "id IN (".implode(", ",$ids).")"); |
|
27 | + } |
|
28 | 28 | } |
@@ -1,5 +1,5 @@ discard block |
||
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 | |
@@ -12,19 +12,19 @@ discard block |
||
12 | 12 | * |
13 | 13 | */ |
14 | 14 | |
15 | -function secureWebDocument($docid='') { |
|
15 | +function secureWebDocument($docid = ''){ |
|
16 | 16 | global $modx; |
17 | 17 | |
18 | - $modx->db->update('privateweb = 0', $modx->getFullTableName("site_content"), ($docid>0 ? "id='$docid'":"privateweb = 1")); |
|
18 | + $modx->db->update('privateweb = 0', $modx->getFullTableName("site_content"), ($docid > 0 ? "id='$docid'" : "privateweb = 1")); |
|
19 | 19 | $rs = $modx->db->select( |
20 | 20 | 'DISTINCT sc.id', |
21 | 21 | $modx->getFullTableName("site_content")." sc |
22 | 22 | LEFT JOIN ".$modx->getFullTableName("document_groups")." dg ON dg.document = sc.id |
23 | 23 | LEFT JOIN ".$modx->getFullTableName("webgroup_access")." wga ON wga.documentgroup = dg.document_group", |
24 | - ($docid>0 ? " sc.id='{$docid}' AND ":"")."wga.id>0" |
|
24 | + ($docid > 0 ? " sc.id='{$docid}' AND " : "")."wga.id>0" |
|
25 | 25 | ); |
26 | - $ids = $modx->db->getColumn("id",$rs); |
|
27 | - if(count($ids)>0) { |
|
28 | - $modx->db->update('privateweb = 1', $modx->getFullTableName("site_content"), "id IN (".implode(", ",$ids).")"); |
|
26 | + $ids = $modx->db->getColumn("id", $rs); |
|
27 | + if (count($ids) > 0) { |
|
28 | + $modx->db->update('privateweb = 1', $modx->getFullTableName("site_content"), "id IN (".implode(", ", $ids).")"); |
|
29 | 29 | } |
30 | 30 | } |
@@ -12,7 +12,8 @@ |
||
12 | 12 | * |
13 | 13 | */ |
14 | 14 | |
15 | -function secureWebDocument($docid='') { |
|
15 | +function secureWebDocument($docid='') |
|
16 | +{ |
|
16 | 17 | global $modx; |
17 | 18 | |
18 | 19 | $modx->db->update('privateweb = 0', $modx->getFullTableName("site_content"), ($docid>0 ? "id='$docid'":"privateweb = 1")); |