@@ -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); |
@@ -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 | var $placeholders = array(); |
8 | 8 | var $vars = array(); |
@@ -24,14 +24,14 @@ discard block |
||
24 | 24 | $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'; |
25 | 25 | } |
26 | 26 | |
27 | - function phxFilter($key,$value,$modifiers) |
|
27 | + function phxFilter($key, $value, $modifiers) |
|
28 | 28 | { |
29 | 29 | global $modx; |
30 | - if(substr($modifiers,0,3)!=='id(') $value = $this->parseDocumentSource($value); |
|
30 | + if (substr($modifiers, 0, 3) !== 'id(') $value = $this->parseDocumentSource($value); |
|
31 | 31 | $this->srcValue = $value; |
32 | 32 | $modifiers = trim($modifiers); |
33 | - $modifiers = ':'.trim($modifiers,':'); |
|
34 | - $modifiers = str_replace(array("\r\n","\r"), "\n", $modifiers); |
|
33 | + $modifiers = ':'.trim($modifiers, ':'); |
|
34 | + $modifiers = str_replace(array("\r\n", "\r"), "\n", $modifiers); |
|
35 | 35 | $modifiers = $this->splitEachModifiers($modifiers); |
36 | 36 | |
37 | 37 | $this->placeholders = array(); |
@@ -39,117 +39,117 @@ discard block |
||
39 | 39 | $this->placeholders['dummy'] = ''; |
40 | 40 | $this->condition = array(); |
41 | 41 | $this->vars = array(); |
42 | - $this->vars['name'] = & $key; |
|
43 | - $value = $this->parsePhx($key,$value,$modifiers); |
|
42 | + $this->vars['name'] = & $key; |
|
43 | + $value = $this->parsePhx($key, $value, $modifiers); |
|
44 | 44 | $this->vars = array(); |
45 | 45 | return $value; |
46 | 46 | } |
47 | 47 | |
48 | - function _getDelim($mode,$modifiers) { |
|
49 | - $c = substr($modifiers,0,1); |
|
50 | - if(!in_array($c, array('"', "'", '`')) ) return false; |
|
48 | + function _getDelim($mode, $modifiers){ |
|
49 | + $c = substr($modifiers, 0, 1); |
|
50 | + if (!in_array($c, array('"', "'", '`'))) return false; |
|
51 | 51 | |
52 | - $modifiers = substr($modifiers,1); |
|
53 | - $closure = $mode=='(' ? "{$c})" : $c; |
|
54 | - if(strpos($modifiers, $closure)===false) return false; |
|
52 | + $modifiers = substr($modifiers, 1); |
|
53 | + $closure = $mode == '(' ? "{$c})" : $c; |
|
54 | + if (strpos($modifiers, $closure) === false) return false; |
|
55 | 55 | |
56 | 56 | return $c; |
57 | 57 | } |
58 | 58 | |
59 | - function _getOpt($mode,$delim,$modifiers) { |
|
60 | - if($delim) { |
|
61 | - if($mode=='(') return substr($modifiers,1,strpos($modifiers, $delim . ')' )-1); |
|
59 | + function _getOpt($mode, $delim, $modifiers){ |
|
60 | + if ($delim) { |
|
61 | + if ($mode == '(') return substr($modifiers, 1, strpos($modifiers, $delim.')') - 1); |
|
62 | 62 | |
63 | - return substr($modifiers,1,strpos($modifiers,$delim,1)-1); |
|
63 | + return substr($modifiers, 1, strpos($modifiers, $delim, 1) - 1); |
|
64 | 64 | } |
65 | 65 | else { |
66 | - if($mode=='(') return substr($modifiers,0,strpos($modifiers, ')') ); |
|
66 | + if ($mode == '(') return substr($modifiers, 0, strpos($modifiers, ')')); |
|
67 | 67 | |
68 | 68 | $chars = str_split($modifiers); |
69 | - $opt=''; |
|
70 | - foreach($chars as $c) { |
|
71 | - if($c==':' || $c==')') break; |
|
72 | - $opt .=$c; |
|
69 | + $opt = ''; |
|
70 | + foreach ($chars as $c) { |
|
71 | + if ($c == ':' || $c == ')') break; |
|
72 | + $opt .= $c; |
|
73 | 73 | } |
74 | 74 | return $opt; |
75 | 75 | } |
76 | 76 | } |
77 | - function _getRemainModifiers($mode,$delim,$modifiers) { |
|
78 | - if($delim) { |
|
79 | - if($mode=='(') |
|
80 | - return $this->_fetchContent($modifiers, $delim . ')'); |
|
77 | + function _getRemainModifiers($mode, $delim, $modifiers){ |
|
78 | + if ($delim) { |
|
79 | + if ($mode == '(') |
|
80 | + return $this->_fetchContent($modifiers, $delim.')'); |
|
81 | 81 | else { |
82 | 82 | $modifiers = trim($modifiers); |
83 | - $modifiers = substr($modifiers,1); |
|
83 | + $modifiers = substr($modifiers, 1); |
|
84 | 84 | return $this->_fetchContent($modifiers, $delim); |
85 | 85 | } |
86 | 86 | } |
87 | 87 | else { |
88 | - if($mode=='(') return $this->_fetchContent($modifiers, ')'); |
|
88 | + if ($mode == '(') return $this->_fetchContent($modifiers, ')'); |
|
89 | 89 | $chars = str_split($modifiers); |
90 | - foreach($chars as $c) { |
|
91 | - if($c==':') return $modifiers; |
|
92 | - else $modifiers = substr($modifiers,1); |
|
90 | + foreach ($chars as $c) { |
|
91 | + if ($c == ':') return $modifiers; |
|
92 | + else $modifiers = substr($modifiers, 1); |
|
93 | 93 | } |
94 | 94 | return $modifiers; |
95 | 95 | } |
96 | 96 | } |
97 | 97 | |
98 | - function _fetchContent($string,$delim) { |
|
98 | + function _fetchContent($string, $delim){ |
|
99 | 99 | $len = strlen($delim); |
100 | 100 | $string = $this->parseDocumentSource($string); |
101 | - return substr($string,strpos($string, $delim)+$len); |
|
101 | + return substr($string, strpos($string, $delim) + $len); |
|
102 | 102 | } |
103 | 103 | |
104 | - function splitEachModifiers($modifiers) { |
|
104 | + function splitEachModifiers($modifiers){ |
|
105 | 105 | global $modx; |
106 | 106 | |
107 | 107 | $cmd = ''; |
108 | 108 | $bt = ''; |
109 | - while($bt!==$modifiers) { |
|
109 | + while ($bt !== $modifiers) { |
|
110 | 110 | $bt = $modifiers; |
111 | - $c = substr($modifiers,0,1); |
|
112 | - $modifiers = substr($modifiers,1); |
|
111 | + $c = substr($modifiers, 0, 1); |
|
112 | + $modifiers = substr($modifiers, 1); |
|
113 | 113 | |
114 | - if($c===':' && preg_match('@^(!?[<>=]{1,2})@', $modifiers, $match)) { // :=, :!=, :<=, :>=, :!<=, :!>= |
|
115 | - $c = substr($modifiers,strlen($match[1]),1); |
|
114 | + if ($c === ':' && preg_match('@^(!?[<>=]{1,2})@', $modifiers, $match)) { // :=, :!=, :<=, :>=, :!<=, :!>= |
|
115 | + $c = substr($modifiers, strlen($match[1]), 1); |
|
116 | 116 | $debuginfo = "#i=0 #c=[{$c}] #m=[{$modifiers}]"; |
117 | - if($c==='(') $modifiers = substr($modifiers,strlen($match[1])+1); |
|
118 | - else $modifiers = substr($modifiers,strlen($match[1])); |
|
117 | + if ($c === '(') $modifiers = substr($modifiers, strlen($match[1]) + 1); |
|
118 | + else $modifiers = substr($modifiers, strlen($match[1])); |
|
119 | 119 | |
120 | - $delim = $this->_getDelim($c,$modifiers); |
|
121 | - $opt = $this->_getOpt($c,$delim,$modifiers); |
|
122 | - $modifiers = trim($this->_getRemainModifiers($c,$delim,$modifiers)); |
|
120 | + $delim = $this->_getDelim($c, $modifiers); |
|
121 | + $opt = $this->_getOpt($c, $delim, $modifiers); |
|
122 | + $modifiers = trim($this->_getRemainModifiers($c, $delim, $modifiers)); |
|
123 | 123 | |
124 | - $result[]=array('cmd'=>trim($match[1]),'opt'=>$opt,'debuginfo'=>$debuginfo); |
|
124 | + $result[] = array('cmd'=>trim($match[1]), 'opt'=>$opt, 'debuginfo'=>$debuginfo); |
|
125 | 125 | $cmd = ''; |
126 | 126 | } |
127 | - elseif(in_array($c,array('+','-','*','/')) && preg_match('@^[0-9]+@', $modifiers, $match)) { // :+3, :-3, :*3 ... |
|
128 | - $modifiers = substr($modifiers,strlen($match[0])); |
|
129 | - $result[]=array('cmd'=>'math','opt'=>'%s'.$c.$match[0]); |
|
127 | + elseif (in_array($c, array('+', '-', '*', '/')) && preg_match('@^[0-9]+@', $modifiers, $match)) { // :+3, :-3, :*3 ... |
|
128 | + $modifiers = substr($modifiers, strlen($match[0])); |
|
129 | + $result[] = array('cmd'=>'math', 'opt'=>'%s'.$c.$match[0]); |
|
130 | 130 | $cmd = ''; |
131 | 131 | } |
132 | - elseif($c==='(' || $c==='=') { |
|
132 | + elseif ($c === '(' || $c === '=') { |
|
133 | 133 | $modifiers = $m1 = trim($modifiers); |
134 | - $delim = $this->_getDelim($c,$modifiers); |
|
135 | - $opt = $this->_getOpt($c,$delim,$modifiers); |
|
136 | - $modifiers = trim($this->_getRemainModifiers($c,$delim,$modifiers)); |
|
134 | + $delim = $this->_getDelim($c, $modifiers); |
|
135 | + $opt = $this->_getOpt($c, $delim, $modifiers); |
|
136 | + $modifiers = trim($this->_getRemainModifiers($c, $delim, $modifiers)); |
|
137 | 137 | $debuginfo = "#i=1 #c=[{$c}] #delim=[{$delim}] #m1=[{$m1}] remainMdf=[{$modifiers}]"; |
138 | 138 | |
139 | - $result[]=array('cmd'=>trim($cmd),'opt'=>$opt,'debuginfo'=>$debuginfo); |
|
139 | + $result[] = array('cmd'=>trim($cmd), 'opt'=>$opt, 'debuginfo'=>$debuginfo); |
|
140 | 140 | |
141 | 141 | $cmd = ''; |
142 | 142 | } |
143 | - elseif($c==':') { |
|
143 | + elseif ($c == ':') { |
|
144 | 144 | $debuginfo = "#i=2 #c=[{$c}] #m=[{$modifiers}]"; |
145 | - if($cmd!=='') $result[]=array('cmd'=>trim($cmd),'opt'=>'','debuginfo'=>$debuginfo); |
|
145 | + if ($cmd !== '') $result[] = array('cmd'=>trim($cmd), 'opt'=>'', 'debuginfo'=>$debuginfo); |
|
146 | 146 | |
147 | 147 | $cmd = ''; |
148 | 148 | } |
149 | - elseif(trim($modifiers)=='' && trim($cmd)!=='') { |
|
149 | + elseif (trim($modifiers) == '' && trim($cmd) !== '') { |
|
150 | 150 | $debuginfo = "#i=3 #c=[{$c}] #m=[{$modifiers}]"; |
151 | 151 | $cmd .= $c; |
152 | - $result[]=array('cmd'=>trim($cmd),'opt'=>'','debuginfo'=>$debuginfo); |
|
152 | + $result[] = array('cmd'=>trim($cmd), 'opt'=>'', 'debuginfo'=>$debuginfo); |
|
153 | 153 | |
154 | 154 | break; |
155 | 155 | } |
@@ -158,64 +158,64 @@ discard block |
||
158 | 158 | } |
159 | 159 | } |
160 | 160 | |
161 | - if(empty($result)) return array(); |
|
161 | + if (empty($result)) return array(); |
|
162 | 162 | |
163 | - foreach($result as $i=>$a) |
|
163 | + foreach ($result as $i=>$a) |
|
164 | 164 | { |
165 | 165 | $a['opt'] = $this->parseDocumentSource($a['opt']); |
166 | - $result[$i]['opt'] = $modx->mergePlaceholderContent($a['opt'],$this->placeholders); |
|
166 | + $result[$i]['opt'] = $modx->mergePlaceholderContent($a['opt'], $this->placeholders); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | return $result; |
170 | 170 | } |
171 | 171 | |
172 | - function parsePhx($key,$value,$modifiers) |
|
172 | + function parsePhx($key, $value, $modifiers) |
|
173 | 173 | { |
174 | 174 | global $modx; |
175 | - $cacheKey = md5(sprintf('parsePhx#%s#%s#%s',$key,$value,print_r($modifiers,true))); |
|
176 | - if(isset($this->tmpCache[$cacheKey])) return $this->tmpCache[$cacheKey]; |
|
177 | - if(empty($modifiers)) return ''; |
|
175 | + $cacheKey = md5(sprintf('parsePhx#%s#%s#%s', $key, $value, print_r($modifiers, true))); |
|
176 | + if (isset($this->tmpCache[$cacheKey])) return $this->tmpCache[$cacheKey]; |
|
177 | + if (empty($modifiers)) return ''; |
|
178 | 178 | |
179 | - foreach($modifiers as $m) |
|
179 | + foreach ($modifiers as $m) |
|
180 | 180 | { |
181 | 181 | $lastKey = strtolower($m['cmd']); |
182 | 182 | } |
183 | - $_ = explode(',',$this->condModifiers); |
|
184 | - if(in_array($lastKey,$_)) |
|
183 | + $_ = explode(',', $this->condModifiers); |
|
184 | + if (in_array($lastKey, $_)) |
|
185 | 185 | { |
186 | - $modifiers[] = array('cmd'=>'then','opt'=>'1'); |
|
187 | - $modifiers[] = array('cmd'=>'else','opt'=>'0'); |
|
186 | + $modifiers[] = array('cmd'=>'then', 'opt'=>'1'); |
|
187 | + $modifiers[] = array('cmd'=>'else', 'opt'=>'0'); |
|
188 | 188 | } |
189 | 189 | |
190 | - foreach($modifiers as $i=>$a) |
|
190 | + foreach ($modifiers as $i=>$a) |
|
191 | 191 | { |
192 | - $value = $this->Filter($key,$value, $a['cmd'], $a['opt']); |
|
192 | + $value = $this->Filter($key, $value, $a['cmd'], $a['opt']); |
|
193 | 193 | } |
194 | 194 | $this->tmpCache[$cacheKey] = $value; |
195 | 195 | return $value; |
196 | 196 | } |
197 | 197 | |
198 | 198 | // Parser: modifier detection and eXtended processing if needed |
199 | - function Filter($key, $value, $cmd, $opt='') |
|
199 | + function Filter($key, $value, $cmd, $opt = '') |
|
200 | 200 | { |
201 | 201 | global $modx; |
202 | 202 | |
203 | - if($key==='documentObject') $value = $modx->documentIdentifier; |
|
203 | + if ($key === 'documentObject') $value = $modx->documentIdentifier; |
|
204 | 204 | $cmd = $this->parseDocumentSource($cmd); |
205 | - if(preg_match('@^[1-9][/0-9]*$@',$cmd)) |
|
205 | + if (preg_match('@^[1-9][/0-9]*$@', $cmd)) |
|
206 | 206 | { |
207 | - if(strpos($cmd,'/')!==false) |
|
208 | - $cmd = $this->substr($cmd,strrpos($cmd,'/')+1); |
|
207 | + if (strpos($cmd, '/') !== false) |
|
208 | + $cmd = $this->substr($cmd, strrpos($cmd, '/') + 1); |
|
209 | 209 | $opt = $cmd; |
210 | 210 | $cmd = 'id'; |
211 | 211 | } |
212 | 212 | |
213 | - if(isset($modx->snippetCache["phx:{$cmd}"])) $this->elmName = "phx:{$cmd}"; |
|
214 | - elseif(isset($modx->chunkCache["phx:{$cmd}"])) $this->elmName = "phx:{$cmd}"; |
|
213 | + if (isset($modx->snippetCache["phx:{$cmd}"])) $this->elmName = "phx:{$cmd}"; |
|
214 | + elseif (isset($modx->chunkCache["phx:{$cmd}"])) $this->elmName = "phx:{$cmd}"; |
|
215 | 215 | else $this->elmName = ''; |
216 | 216 | |
217 | 217 | $cmd = strtolower($cmd); |
218 | - if($this->elmName!=='') |
|
218 | + if ($this->elmName !== '') |
|
219 | 219 | $value = $this->getValueFromElement($key, $value, $cmd, $opt); |
220 | 220 | else |
221 | 221 | $value = $this->getValueFromPreset($key, $value, $cmd, $opt); |
@@ -225,12 +225,12 @@ discard block |
||
225 | 225 | return $value; |
226 | 226 | } |
227 | 227 | |
228 | - function isEmpty($cmd,$value) |
|
228 | + function isEmpty($cmd, $value) |
|
229 | 229 | { |
230 | - if($value!=='') return false; |
|
230 | + if ($value !== '') return false; |
|
231 | 231 | |
232 | - $_ = explode(',', $this->condModifiers . ',_default,default,if,input,or,and,show,this,select,switch,then,else,id,ifempty,smart_desc,smart_description,summary'); |
|
233 | - if(in_array($cmd,$_)) return false; |
|
232 | + $_ = explode(',', $this->condModifiers.',_default,default,if,input,or,and,show,this,select,switch,then,else,id,ifempty,smart_desc,smart_description,summary'); |
|
233 | + if (in_array($cmd, $_)) return false; |
|
234 | 234 | else return true; |
235 | 235 | } |
236 | 236 | |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | { |
239 | 239 | global $modx; |
240 | 240 | |
241 | - if($this->isEmpty($cmd,$value)) return ''; |
|
241 | + if ($this->isEmpty($cmd, $value)) return ''; |
|
242 | 242 | |
243 | 243 | $this->key = $key; |
244 | 244 | $this->value = $value; |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | ##### Conditional Modifiers |
250 | 250 | case 'input': |
251 | 251 | case 'if': |
252 | - if(!$opt) return $value; |
|
252 | + if (!$opt) return $value; |
|
253 | 253 | return $opt; |
254 | 254 | case '=': |
255 | 255 | case 'eq': |
@@ -262,9 +262,9 @@ discard block |
||
262 | 262 | case 'isnot': |
263 | 263 | case 'isnt': |
264 | 264 | case 'not': |
265 | - $this->condition[] = intval($value != $opt);break; |
|
265 | + $this->condition[] = intval($value != $opt); break; |
|
266 | 266 | case '%': |
267 | - $this->condition[] = intval($value%$opt==0);break; |
|
267 | + $this->condition[] = intval($value % $opt == 0); break; |
|
268 | 268 | case 'isempty': |
269 | 269 | $this->condition[] = intval(empty($value)); break; |
270 | 270 | case 'isntempty': |
@@ -274,57 +274,57 @@ discard block |
||
274 | 274 | case 'gte': |
275 | 275 | case 'eg': |
276 | 276 | case 'isgte': |
277 | - $this->condition[] = intval($value >= $opt);break; |
|
277 | + $this->condition[] = intval($value >= $opt); break; |
|
278 | 278 | case '<=': |
279 | 279 | case 'lte': |
280 | 280 | case 'el': |
281 | 281 | case 'islte': |
282 | - $this->condition[] = intval($value <= $opt);break; |
|
282 | + $this->condition[] = intval($value <= $opt); break; |
|
283 | 283 | case '>': |
284 | 284 | case 'gt': |
285 | 285 | case 'greaterthan': |
286 | 286 | case 'isgreaterthan': |
287 | 287 | case 'isgt': |
288 | - $this->condition[] = intval($value > $opt);break; |
|
288 | + $this->condition[] = intval($value > $opt); break; |
|
289 | 289 | case '<': |
290 | 290 | case 'lt': |
291 | 291 | case 'lowerthan': |
292 | 292 | case 'islowerthan': |
293 | 293 | case 'islt': |
294 | - $this->condition[] = intval($value < $opt);break; |
|
294 | + $this->condition[] = intval($value < $opt); break; |
|
295 | 295 | case 'find': |
296 | - $this->condition[] = intval(strpos($value, $opt)!==false);break; |
|
296 | + $this->condition[] = intval(strpos($value, $opt) !== false); break; |
|
297 | 297 | case 'inarray': |
298 | 298 | case 'in_array': |
299 | 299 | case 'in': |
300 | 300 | $opt = explode(',', $opt); |
301 | - $this->condition[] = intval(in_array($value, $opt)!==false);break; |
|
301 | + $this->condition[] = intval(in_array($value, $opt) !== false); break; |
|
302 | 302 | case 'wildcard_match': |
303 | 303 | case 'wcard_match': |
304 | 304 | case 'wildcard': |
305 | 305 | case 'wcard': |
306 | 306 | case 'fnmatch': |
307 | - $this->condition[] = intval(fnmatch($opt, $value)!==false);break; |
|
307 | + $this->condition[] = intval(fnmatch($opt, $value) !== false); break; |
|
308 | 308 | case 'is_file': |
309 | 309 | case 'is_dir': |
310 | 310 | case 'file_exists': |
311 | 311 | case 'is_readable': |
312 | 312 | case 'is_writable': |
313 | - if(!$opt) $path = $value; |
|
313 | + if (!$opt) $path = $value; |
|
314 | 314 | else $path = $opt; |
315 | - if(strpos($path,MODX_MANAGER_PATH)!==false) exit('Can not read core path'); |
|
316 | - if(strpos($path,$modx->config['base_path'])===false) $path = ltrim($path,'/'); |
|
317 | - $this->condition[] = intval($cmd($path)!==false);break; |
|
315 | + if (strpos($path, MODX_MANAGER_PATH) !== false) exit('Can not read core path'); |
|
316 | + if (strpos($path, $modx->config['base_path']) === false) $path = ltrim($path, '/'); |
|
317 | + $this->condition[] = intval($cmd($path) !== false); break; |
|
318 | 318 | case 'is_image': |
319 | - if(!$opt) $path = $value; |
|
319 | + if (!$opt) $path = $value; |
|
320 | 320 | else $path = $opt; |
321 | - if(!is_file($path)) {$this->condition[]='0';break;} |
|
321 | + if (!is_file($path)) {$this->condition[] = '0'; break; } |
|
322 | 322 | $_ = getimagesize($path); |
323 | - $this->condition[] = intval($_[0]);break; |
|
323 | + $this->condition[] = intval($_[0]); break; |
|
324 | 324 | case 'regex': |
325 | 325 | case 'preg': |
326 | 326 | case 'preg_match': |
327 | - $this->condition[] = intval(preg_match($opt,$value));break; |
|
327 | + $this->condition[] = intval(preg_match($opt, $value)); break; |
|
328 | 328 | case 'isinrole': |
329 | 329 | case 'ir': |
330 | 330 | case 'memberof': |
@@ -333,50 +333,50 @@ discard block |
||
333 | 333 | $this->condition[] = $this->includeMdfFile('memberof'); |
334 | 334 | break; |
335 | 335 | case 'or': |
336 | - $this->condition[] = '||';break; |
|
336 | + $this->condition[] = '||'; break; |
|
337 | 337 | case 'and': |
338 | - $this->condition[] = '&&';break; |
|
338 | + $this->condition[] = '&&'; break; |
|
339 | 339 | case 'show': |
340 | 340 | case 'this': |
341 | - $conditional = join(' ',$this->condition); |
|
341 | + $conditional = join(' ', $this->condition); |
|
342 | 342 | $isvalid = intval(eval("return ({$conditional});")); |
343 | 343 | if ($isvalid) return $this->srcValue; |
344 | 344 | return NULL; |
345 | 345 | case 'then': |
346 | - $conditional = join(' ',$this->condition); |
|
346 | + $conditional = join(' ', $this->condition); |
|
347 | 347 | $isvalid = intval(eval("return ({$conditional});")); |
348 | 348 | if ($isvalid) return $opt; |
349 | 349 | return null; |
350 | 350 | case 'else': |
351 | - $conditional = join(' ',$this->condition); |
|
351 | + $conditional = join(' ', $this->condition); |
|
352 | 352 | $isvalid = intval(eval("return ({$conditional});")); |
353 | 353 | if (!$isvalid) return $opt; |
354 | 354 | break; |
355 | 355 | case 'select': |
356 | 356 | case 'switch': |
357 | - $raw = explode('&',$opt); |
|
357 | + $raw = explode('&', $opt); |
|
358 | 358 | $map = array(); |
359 | 359 | $c = count($raw); |
360 | - for($m=0; $m<$c; $m++) { |
|
361 | - $mi = explode('=',$raw[$m],2); |
|
360 | + for ($m = 0; $m < $c; $m++) { |
|
361 | + $mi = explode('=', $raw[$m], 2); |
|
362 | 362 | $map[$mi[0]] = $mi[1]; |
363 | 363 | } |
364 | - if(isset($map[$value])) return $map[$value]; |
|
364 | + if (isset($map[$value])) return $map[$value]; |
|
365 | 365 | else return ''; |
366 | 366 | ##### End of Conditional Modifiers |
367 | 367 | |
368 | 368 | ##### Encode / Decode / Hash / Escape |
369 | 369 | case 'htmlent': |
370 | 370 | case 'htmlentities': |
371 | - return htmlentities($value,ENT_QUOTES,$modx->config['modx_charset']); |
|
371 | + return htmlentities($value, ENT_QUOTES, $modx->config['modx_charset']); |
|
372 | 372 | case 'html_entity_decode': |
373 | 373 | case 'decode_html': |
374 | 374 | case 'html_decode': |
375 | - return html_entity_decode($value,ENT_QUOTES,$modx->config['modx_charset']); |
|
375 | + return html_entity_decode($value, ENT_QUOTES, $modx->config['modx_charset']); |
|
376 | 376 | case 'esc': |
377 | 377 | case 'escape': |
378 | 378 | $value = preg_replace('/&(#[0-9]+|[a-z]+);/i', '&$1;', htmlspecialchars($value, ENT_QUOTES, $modx->config['modx_charset'])); |
379 | - return str_replace(array('[', ']', '`'),array('[', ']', '`'),$value); |
|
379 | + return str_replace(array('[', ']', '`'), array('[', ']', '`'), $value); |
|
380 | 380 | case 'sql_escape': |
381 | 381 | case 'encode_js': |
382 | 382 | return $modx->db->escape($value); |
@@ -386,39 +386,39 @@ discard block |
||
386 | 386 | case 'html_encode': |
387 | 387 | return preg_replace('/&(#[0-9]+|[a-z]+);/i', '&$1;', htmlspecialchars($value, ENT_QUOTES, $modx->config['modx_charset'])); |
388 | 388 | case 'spam_protect': |
389 | - return str_replace(array('@','.'),array('@','.'),$value); |
|
389 | + return str_replace(array('@', '.'), array('@', '.'), $value); |
|
390 | 390 | case 'strip': |
391 | - if($opt==='') $opt = ' '; |
|
391 | + if ($opt === '') $opt = ' '; |
|
392 | 392 | return preg_replace('/[\n\r\t\s]+/', $opt, $value); |
393 | 393 | case 'strip_linefeeds': |
394 | - return str_replace(array("\n","\r"), '', $value); |
|
394 | + return str_replace(array("\n", "\r"), '', $value); |
|
395 | 395 | case 'notags': |
396 | 396 | case 'strip_tags': |
397 | 397 | case 'remove_html': |
398 | - if($opt!=='') |
|
398 | + if ($opt !== '') |
|
399 | 399 | { |
400 | 400 | $param = array(); |
401 | - foreach(explode(',',$opt) as $v) |
|
401 | + foreach (explode(',', $opt) as $v) |
|
402 | 402 | { |
403 | - $v = trim($v,'</> '); |
|
403 | + $v = trim($v, '</> '); |
|
404 | 404 | $param[] = "<{$v}>"; |
405 | 405 | } |
406 | - $params = join(',',$param); |
|
406 | + $params = join(',', $param); |
|
407 | 407 | } |
408 | 408 | else $params = ''; |
409 | - if(!strpos($params,'<br>')===false) { |
|
410 | - $value = preg_replace('@(<br[ /]*>)\n@','$1',$value); |
|
411 | - $value = preg_replace('@<br[ /]*>@',"\n",$value); |
|
409 | + if (!strpos($params, '<br>') === false) { |
|
410 | + $value = preg_replace('@(<br[ /]*>)\n@', '$1', $value); |
|
411 | + $value = preg_replace('@<br[ /]*>@', "\n", $value); |
|
412 | 412 | } |
413 | - return $this->strip_tags($value,$params); |
|
413 | + return $this->strip_tags($value, $params); |
|
414 | 414 | case 'urlencode': |
415 | 415 | case 'url_encode': |
416 | 416 | case 'encode_url': |
417 | 417 | return urlencode($value); |
418 | 418 | case 'base64_decode': |
419 | - if($opt!=='false') $opt = true; |
|
419 | + if ($opt !== 'false') $opt = true; |
|
420 | 420 | else $opt = false; |
421 | - return base64_decode($value,$opt); |
|
421 | + return base64_decode($value, $opt); |
|
422 | 422 | case 'encode_sha1': $cmd = 'sha1'; |
423 | 423 | case 'addslashes': |
424 | 424 | case 'urldecode': |
@@ -442,18 +442,18 @@ discard block |
||
442 | 442 | case 'upper_case': |
443 | 443 | return $this->strtoupper($value); |
444 | 444 | case 'capitalize': |
445 | - $_ = explode(' ',$value); |
|
446 | - foreach($_ as $i=>$v) |
|
445 | + $_ = explode(' ', $value); |
|
446 | + foreach ($_ as $i=>$v) |
|
447 | 447 | { |
448 | 448 | $_[$i] = ucfirst($v); |
449 | 449 | } |
450 | - return join(' ',$_); |
|
450 | + return join(' ', $_); |
|
451 | 451 | case 'zenhan': |
452 | - if(empty($opt)) $opt='VKas'; |
|
453 | - return mb_convert_kana($value,$opt,$modx->config['modx_charset']); |
|
452 | + if (empty($opt)) $opt = 'VKas'; |
|
453 | + return mb_convert_kana($value, $opt, $modx->config['modx_charset']); |
|
454 | 454 | case 'hanzen': |
455 | - if(empty($opt)) $opt='VKAS'; |
|
456 | - return mb_convert_kana($value,$opt,$modx->config['modx_charset']); |
|
455 | + if (empty($opt)) $opt = 'VKAS'; |
|
456 | + return mb_convert_kana($value, $opt, $modx->config['modx_charset']); |
|
457 | 457 | case 'str_shuffle': |
458 | 458 | case 'shuffle': |
459 | 459 | return $this->str_shuffle($value); |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | return $this->strlen($value); |
468 | 468 | case 'count_words': |
469 | 469 | $value = trim($value); |
470 | - return count(preg_split('/\s+/',$value)); |
|
470 | + return count(preg_split('/\s+/', $value)); |
|
471 | 471 | case 'str_word_count': |
472 | 472 | case 'word_count': |
473 | 473 | case 'wordcount': |
@@ -475,55 +475,55 @@ discard block |
||
475 | 475 | case 'count_paragraphs': |
476 | 476 | $value = trim($value); |
477 | 477 | $value = preg_replace('/\r/', '', $value); |
478 | - return count(preg_split('/\n+/',$value)); |
|
478 | + return count(preg_split('/\n+/', $value)); |
|
479 | 479 | case 'strpos': |
480 | - if($opt!=0&&empty($opt)) return $value; |
|
481 | - return $this->strpos($value,$opt); |
|
480 | + if ($opt != 0 && empty($opt)) return $value; |
|
481 | + return $this->strpos($value, $opt); |
|
482 | 482 | case 'wordwrap': |
483 | 483 | // default: 70 |
484 | 484 | $wrapat = intval($opt) ? intval($opt) : 70; |
485 | 485 | if (version_compare(PHP_VERSION, '5.3.0') >= 0) return $this->includeMdfFile('wordwrap'); |
486 | - else return preg_replace("@(\b\w+\b)@e","wordwrap('\\1',\$wrapat,' ',1)",$value); |
|
486 | + else return preg_replace("@(\b\w+\b)@e", "wordwrap('\\1',\$wrapat,' ',1)", $value); |
|
487 | 487 | case 'wrap_text': |
488 | - $width = preg_match('/^[1-9][0-9]*$/',$opt) ? $opt : 70; |
|
489 | - if($modx->config['manager_language']==='japanese-utf8') { |
|
488 | + $width = preg_match('/^[1-9][0-9]*$/', $opt) ? $opt : 70; |
|
489 | + if ($modx->config['manager_language'] === 'japanese-utf8') { |
|
490 | 490 | $chunk = array(); |
491 | - $bt=''; |
|
492 | - while($bt!=$value) { |
|
491 | + $bt = ''; |
|
492 | + while ($bt != $value) { |
|
493 | 493 | $bt = $value; |
494 | - if($this->strlen($value)<$width) { |
|
494 | + if ($this->strlen($value) < $width) { |
|
495 | 495 | $chunk[] = $value; |
496 | 496 | break; |
497 | 497 | } |
498 | - $chunk[] = $this->substr($value,0,$width); |
|
499 | - $value = $this->substr($value,$width); |
|
498 | + $chunk[] = $this->substr($value, 0, $width); |
|
499 | + $value = $this->substr($value, $width); |
|
500 | 500 | } |
501 | - return join("\n",$chunk); |
|
501 | + return join("\n", $chunk); |
|
502 | 502 | } |
503 | 503 | else |
504 | - return wordwrap($value,$width,"\n",true); |
|
504 | + return wordwrap($value, $width, "\n", true); |
|
505 | 505 | case 'substr': |
506 | - if(empty($opt)) break; |
|
507 | - if(strpos($opt,',')!==false) { |
|
508 | - list($b,$e) = explode(',',$opt,2); |
|
509 | - return $this->substr($value,$b,(int)$e); |
|
506 | + if (empty($opt)) break; |
|
507 | + if (strpos($opt, ',') !== false) { |
|
508 | + list($b, $e) = explode(',', $opt, 2); |
|
509 | + return $this->substr($value, $b, (int) $e); |
|
510 | 510 | } |
511 | - else return $this->substr($value,$opt); |
|
511 | + else return $this->substr($value, $opt); |
|
512 | 512 | case 'limit': |
513 | 513 | case 'trim_to': // http://www.movabletype.jp/documentation/appendices/modifiers/trim_to.html |
514 | - if(strpos($opt,'+')!==false) |
|
515 | - list($len,$str) = explode('+',$opt,2); |
|
514 | + if (strpos($opt, '+') !== false) |
|
515 | + list($len, $str) = explode('+', $opt, 2); |
|
516 | 516 | else { |
517 | 517 | $len = $opt; |
518 | 518 | $str = ''; |
519 | 519 | } |
520 | - if($len==='') $len = 100; |
|
521 | - if(abs($len) > $this->strlen($value)) $str =''; |
|
522 | - if(preg_match('/^[1-9][0-9]*$/',$len)) { |
|
523 | - return $this->substr($value,0,$len) . $str; |
|
520 | + if ($len === '') $len = 100; |
|
521 | + if (abs($len) > $this->strlen($value)) $str = ''; |
|
522 | + if (preg_match('/^[1-9][0-9]*$/', $len)) { |
|
523 | + return $this->substr($value, 0, $len).$str; |
|
524 | 524 | } |
525 | - elseif(preg_match('/^\-[1-9][0-9]*$/',$len)) { |
|
526 | - return $str . $this->substr($value,$len); |
|
525 | + elseif (preg_match('/^\-[1-9][0-9]*$/', $len)) { |
|
526 | + return $str.$this->substr($value, $len); |
|
527 | 527 | } |
528 | 528 | break; |
529 | 529 | case 'summary': |
@@ -532,81 +532,81 @@ discard block |
||
532 | 532 | return $this->includeMdfFile('summary'); |
533 | 533 | case 'replace': |
534 | 534 | case 'str_replace': |
535 | - if(empty($opt) || strpos($opt,',')===false) break; |
|
536 | - if (substr_count($opt, ',') ==1) $delim = ','; |
|
537 | - elseif(substr_count($opt, '|') ==1) $delim = '|'; |
|
538 | - elseif(substr_count($opt, '=>')==1) $delim = '=>'; |
|
539 | - elseif(substr_count($opt, '/') ==1) $delim = '/'; |
|
535 | + if (empty($opt) || strpos($opt, ',') === false) break; |
|
536 | + if (substr_count($opt, ',') == 1) $delim = ','; |
|
537 | + elseif (substr_count($opt, '|') == 1) $delim = '|'; |
|
538 | + elseif (substr_count($opt, '=>') == 1) $delim = '=>'; |
|
539 | + elseif (substr_count($opt, '/') == 1) $delim = '/'; |
|
540 | 540 | else break; |
541 | - list($s,$r) = explode($delim,$opt); |
|
542 | - if($value!=='') return str_replace($s,$r,$value); |
|
541 | + list($s, $r) = explode($delim, $opt); |
|
542 | + if ($value !== '') return str_replace($s, $r, $value); |
|
543 | 543 | break; |
544 | 544 | case 'replace_to': |
545 | 545 | case 'tpl': |
546 | - if($value!=='') return str_replace(array('[+value+]','[+output+]','{value}','%s'),$value,$opt); |
|
546 | + if ($value !== '') return str_replace(array('[+value+]', '[+output+]', '{value}', '%s'), $value, $opt); |
|
547 | 547 | break; |
548 | 548 | case 'eachtpl': |
549 | - $value = explode('||',$value); |
|
549 | + $value = explode('||', $value); |
|
550 | 550 | $_ = array(); |
551 | - foreach($value as $v) { |
|
552 | - $_[] = str_replace(array('[+value+]','[+output+]','{value}','%s'),$v,$opt); |
|
551 | + foreach ($value as $v) { |
|
552 | + $_[] = str_replace(array('[+value+]', '[+output+]', '{value}', '%s'), $v, $opt); |
|
553 | 553 | } |
554 | 554 | return join("\n", $_); |
555 | 555 | case 'array_pop': |
556 | 556 | case 'array_shift': |
557 | - if(strpos($value,'||')!==false) $delim = '||'; |
|
557 | + if (strpos($value, '||') !== false) $delim = '||'; |
|
558 | 558 | else $delim = ','; |
559 | - return $cmd(explode($delim,$value)); |
|
559 | + return $cmd(explode($delim, $value)); |
|
560 | 560 | case 'preg_replace': |
561 | 561 | case 'regex_replace': |
562 | - if(empty($opt) || strpos($opt,',')===false) break; |
|
563 | - list($s,$r) = explode(',',$opt,2); |
|
564 | - if($value!=='') return preg_replace($s,$r,$value); |
|
562 | + if (empty($opt) || strpos($opt, ',') === false) break; |
|
563 | + list($s, $r) = explode(',', $opt, 2); |
|
564 | + if ($value !== '') return preg_replace($s, $r, $value); |
|
565 | 565 | break; |
566 | 566 | case 'cat': |
567 | 567 | case 'concatenate': |
568 | 568 | case '.': |
569 | - if($value!=='') return $value . $opt; |
|
569 | + if ($value !== '') return $value.$opt; |
|
570 | 570 | break; |
571 | 571 | case 'sprintf': |
572 | 572 | case 'string_format': |
573 | - if($value!=='') return sprintf($opt,$value); |
|
573 | + if ($value !== '') return sprintf($opt, $value); |
|
574 | 574 | break; |
575 | 575 | case 'number_format': |
576 | - if($opt=='') $opt = 0; |
|
577 | - return number_format($value,$opt); |
|
576 | + if ($opt == '') $opt = 0; |
|
577 | + return number_format($value, $opt); |
|
578 | 578 | case 'money_format': |
579 | - setlocale(LC_MONETARY,setlocale(LC_TIME,0)); |
|
580 | - if($value!=='') return money_format($opt,(double)$value); |
|
579 | + setlocale(LC_MONETARY, setlocale(LC_TIME, 0)); |
|
580 | + if ($value !== '') return money_format($opt, (double) $value); |
|
581 | 581 | break; |
582 | 582 | case 'tobool': |
583 | 583 | return boolval($value); |
584 | 584 | case 'nl2lf': |
585 | - if($value!=='') return str_replace(array("\r\n","\n", "\r"), '\n', $value); |
|
585 | + if ($value !== '') return str_replace(array("\r\n", "\n", "\r"), '\n', $value); |
|
586 | 586 | break; |
587 | 587 | case 'br2nl': |
588 | 588 | return preg_replace('@<br[\s/]*>@i', "\n", $value); |
589 | 589 | case 'nl2br': |
590 | 590 | if (version_compare(PHP_VERSION, '5.3.0', '<')) |
591 | 591 | return nl2br($value); |
592 | - if($opt!=='') |
|
592 | + if ($opt !== '') |
|
593 | 593 | { |
594 | 594 | $opt = trim($opt); |
595 | 595 | $opt = strtolower($opt); |
596 | - if($opt==='false') $opt = false; |
|
597 | - elseif($opt==='0') $opt = false; |
|
596 | + if ($opt === 'false') $opt = false; |
|
597 | + elseif ($opt === '0') $opt = false; |
|
598 | 598 | else $opt = true; |
599 | 599 | } |
600 | - elseif(isset($modx->config['mce_element_format'])&&$modx->config['mce_element_format']==='html') |
|
600 | + elseif (isset($modx->config['mce_element_format']) && $modx->config['mce_element_format'] === 'html') |
|
601 | 601 | $opt = false; |
602 | 602 | else $opt = true; |
603 | - return nl2br($value,$opt); |
|
603 | + return nl2br($value, $opt); |
|
604 | 604 | case 'ltrim': |
605 | 605 | case 'rtrim': |
606 | 606 | case 'trim': // ref http://mblo.info/modifiers/custom-modifiers/rtrim_opt.html |
607 | - if($opt==='') |
|
607 | + if ($opt === '') |
|
608 | 608 | return $cmd($value); |
609 | - else return $cmd($value,$opt); |
|
609 | + else return $cmd($value, $opt); |
|
610 | 610 | // These are all straight wrappers for PHP functions |
611 | 611 | case 'ucfirst': |
612 | 612 | case 'lcfirst': |
@@ -617,16 +617,16 @@ discard block |
||
617 | 617 | case 'strftime': |
618 | 618 | case 'date': |
619 | 619 | case 'dateformat': |
620 | - if(empty($opt)) $opt = $modx->toDateFormat(null, 'formatOnly'); |
|
621 | - if(!preg_match('@^[0-9]+$@',$value)) $value = strtotime($value); |
|
622 | - if(strpos($opt,'%')!==false) |
|
623 | - return strftime($opt,0+$value); |
|
620 | + if (empty($opt)) $opt = $modx->toDateFormat(null, 'formatOnly'); |
|
621 | + if (!preg_match('@^[0-9]+$@', $value)) $value = strtotime($value); |
|
622 | + if (strpos($opt, '%') !== false) |
|
623 | + return strftime($opt, 0 + $value); |
|
624 | 624 | else |
625 | - return date($opt,0+$value); |
|
625 | + return date($opt, 0 + $value); |
|
626 | 626 | case 'time': |
627 | - if(empty($opt)) $opt = '%H:%M'; |
|
628 | - if(!preg_match('@^[0-9]+$@',$value)) $value = strtotime($value); |
|
629 | - return strftime($opt,0+$value); |
|
627 | + if (empty($opt)) $opt = '%H:%M'; |
|
628 | + if (!preg_match('@^[0-9]+$@', $value)) $value = strtotime($value); |
|
629 | + return strftime($opt, 0 + $value); |
|
630 | 630 | case 'strtotime': |
631 | 631 | return strtotime($value); |
632 | 632 | ##### mathematical function |
@@ -635,40 +635,40 @@ discard block |
||
635 | 635 | case 'tofloat': |
636 | 636 | return floatval($value); |
637 | 637 | case 'round': |
638 | - if(!$opt) $opt = 0; |
|
639 | - return $cmd($value,$opt); |
|
638 | + if (!$opt) $opt = 0; |
|
639 | + return $cmd($value, $opt); |
|
640 | 640 | case 'max': |
641 | 641 | case 'min': |
642 | - return $cmd(explode(',',$value)); |
|
642 | + return $cmd(explode(',', $value)); |
|
643 | 643 | case 'floor': |
644 | 644 | case 'ceil': |
645 | 645 | case 'abs': |
646 | 646 | return $cmd($value); |
647 | 647 | case 'math': |
648 | 648 | case 'calc': |
649 | - $value = (int)$value; |
|
650 | - if(empty($value)) $value = '0'; |
|
651 | - $filter = str_replace(array('[+value+]','[+output+]','{value}','%s'),'?',$opt); |
|
652 | - $filter = preg_replace('@([a-zA-Z\n\r\t\s])@','',$filter); |
|
653 | - if(strpos($filter,'?')===false) $filter = "?{$filter}"; |
|
654 | - $filter = str_replace('?',$value,$filter); |
|
649 | + $value = (int) $value; |
|
650 | + if (empty($value)) $value = '0'; |
|
651 | + $filter = str_replace(array('[+value+]', '[+output+]', '{value}', '%s'), '?', $opt); |
|
652 | + $filter = preg_replace('@([a-zA-Z\n\r\t\s])@', '', $filter); |
|
653 | + if (strpos($filter, '?') === false) $filter = "?{$filter}"; |
|
654 | + $filter = str_replace('?', $value, $filter); |
|
655 | 655 | return eval("return {$filter};"); |
656 | 656 | case 'count': |
657 | - if($value=='') return 0; |
|
658 | - $value = explode(',',$value); |
|
657 | + if ($value == '') return 0; |
|
658 | + $value = explode(',', $value); |
|
659 | 659 | return count($value); |
660 | 660 | case 'sort': |
661 | 661 | case 'rsort': |
662 | - if(strpos($value,"\n")!==false) $delim="\n"; |
|
662 | + if (strpos($value, "\n") !== false) $delim = "\n"; |
|
663 | 663 | else $delim = ','; |
664 | - $swap = explode($delim,$value); |
|
665 | - if(!$opt) $opt = SORT_REGULAR; |
|
664 | + $swap = explode($delim, $value); |
|
665 | + if (!$opt) $opt = SORT_REGULAR; |
|
666 | 666 | else $opt = constant($opt); |
667 | - $cmd($swap,$opt); |
|
668 | - return join($delim,$swap); |
|
667 | + $cmd($swap, $opt); |
|
668 | + return join($delim, $swap); |
|
669 | 669 | ##### Resource fields |
670 | 670 | case 'id': |
671 | - if($opt) return $this->getDocumentObject($opt,$key); |
|
671 | + if ($opt) return $this->getDocumentObject($opt, $key); |
|
672 | 672 | break; |
673 | 673 | case 'type': |
674 | 674 | case 'contenttype': |
@@ -705,36 +705,36 @@ discard block |
||
705 | 705 | case 'privatemgr': |
706 | 706 | case 'content_dispo': |
707 | 707 | case 'hidemenu': |
708 | - if($cmd==='contenttype') $cmd = 'contentType'; |
|
709 | - return $this->getDocumentObject($value,$cmd); |
|
708 | + if ($cmd === 'contenttype') $cmd = 'contentType'; |
|
709 | + return $this->getDocumentObject($value, $cmd); |
|
710 | 710 | case 'title': |
711 | - $pagetitle = $this->getDocumentObject($value,'pagetitle'); |
|
712 | - $longtitle = $this->getDocumentObject($value,'longtitle'); |
|
711 | + $pagetitle = $this->getDocumentObject($value, 'pagetitle'); |
|
712 | + $longtitle = $this->getDocumentObject($value, 'longtitle'); |
|
713 | 713 | return $longtitle ? $longtitle : $pagetitle; |
714 | 714 | case 'shorttitle': |
715 | - $pagetitle = $this->getDocumentObject($value,'pagetitle'); |
|
716 | - $menutitle = $this->getDocumentObject($value,'menutitle'); |
|
715 | + $pagetitle = $this->getDocumentObject($value, 'pagetitle'); |
|
716 | + $menutitle = $this->getDocumentObject($value, 'menutitle'); |
|
717 | 717 | return $menutitle ? $menutitle : $pagetitle; |
718 | 718 | case 'templatename': |
719 | - $rs = $modx->db->select('templatename','[+prefix+]site_templates',"id='{$value}'"); |
|
719 | + $rs = $modx->db->select('templatename', '[+prefix+]site_templates', "id='{$value}'"); |
|
720 | 720 | $templateName = $modx->db->getValue($rs); |
721 | 721 | return !$templateName ? '(blank)' : $templateName; |
722 | 722 | case 'getfield': |
723 | - if(!$opt) $opt = 'content'; |
|
724 | - return $modx->getField($opt,$value); |
|
723 | + if (!$opt) $opt = 'content'; |
|
724 | + return $modx->getField($opt, $value); |
|
725 | 725 | case 'children': |
726 | 726 | case 'childids': |
727 | - if($value=='') $value = 0; // 値がない場合はルートと見なす |
|
727 | + if ($value == '') $value = 0; // 値がない場合はルートと見なす |
|
728 | 728 | $published = 1; |
729 | - if($opt=='') $opt = 'page'; |
|
730 | - $_ = explode(',',$opt); |
|
729 | + if ($opt == '') $opt = 'page'; |
|
730 | + $_ = explode(',', $opt); |
|
731 | 731 | $where = array(); |
732 | - foreach($_ as $opt) { |
|
733 | - switch(trim($opt)) { |
|
732 | + foreach ($_ as $opt) { |
|
733 | + switch (trim($opt)) { |
|
734 | 734 | case 'page'; case '!folder'; case '!isfolder': $where[] = 'sc.isfolder=0'; break; |
735 | 735 | case 'folder'; case 'isfolder': $where[] = 'sc.isfolder=1'; break; |
736 | - case 'menu'; case 'show_menu': $where[] = 'sc.hidemenu=0'; break; |
|
737 | - case '!menu'; case '!show_menu': $where[] = 'sc.hidemenu=1'; break; |
|
736 | + case 'menu'; case 'show_menu': $where[] = 'sc.hidemenu=0'; break; |
|
737 | + case '!menu'; case '!show_menu': $where[] = 'sc.hidemenu=1'; break; |
|
738 | 738 | case 'published': $published = 1; break; |
739 | 739 | case '!published': $published = 0; break; |
740 | 740 | } |
@@ -742,69 +742,69 @@ discard block |
||
742 | 742 | $where = join(' AND ', $where); |
743 | 743 | $children = $modx->getDocumentChildren($value, $published, '0', 'id', $where); |
744 | 744 | $result = array(); |
745 | - foreach((array)$children as $child){ |
|
745 | + foreach ((array) $children as $child) { |
|
746 | 746 | $result[] = $child['id']; |
747 | 747 | } |
748 | 748 | return join(',', $result); |
749 | 749 | case 'fullurl': |
750 | - if(!is_numeric($value)) return $value; |
|
750 | + if (!is_numeric($value)) return $value; |
|
751 | 751 | return $modx->makeUrl($value); |
752 | 752 | case 'makeurl': |
753 | - if(!is_numeric($value)) return $value; |
|
754 | - if(!$opt) $opt = 'full'; |
|
755 | - return $modx->makeUrl($value,'','',$opt); |
|
753 | + if (!is_numeric($value)) return $value; |
|
754 | + if (!$opt) $opt = 'full'; |
|
755 | + return $modx->makeUrl($value, '', '', $opt); |
|
756 | 756 | |
757 | 757 | ##### File system |
758 | 758 | case 'getimageinfo': |
759 | 759 | case 'imageinfo': |
760 | - if(!is_file($value)) return ''; |
|
760 | + if (!is_file($value)) return ''; |
|
761 | 761 | $_ = getimagesize($value); |
762 | - if(!$_[0]) return ''; |
|
762 | + if (!$_[0]) return ''; |
|
763 | 763 | $info['width'] = $_[0]; |
764 | 764 | $info['height'] = $_[1]; |
765 | - if ($_[0] > $_[1]) $info['aspect'] = 'landscape'; |
|
766 | - elseif($_[0] < $_[1]) $info['aspect'] = 'portrait'; |
|
765 | + if ($_[0] > $_[1]) $info['aspect'] = 'landscape'; |
|
766 | + elseif ($_[0] < $_[1]) $info['aspect'] = 'portrait'; |
|
767 | 767 | else $info['aspect'] = 'square'; |
768 | - switch($_[2]) { |
|
768 | + switch ($_[2]) { |
|
769 | 769 | case IMAGETYPE_GIF : $info['type'] = 'gif'; break; |
770 | 770 | case IMAGETYPE_JPEG : $info['type'] = 'jpg'; break; |
771 | 771 | case IMAGETYPE_PNG : $info['type'] = 'png'; break; |
772 | 772 | default : $info['type'] = 'unknown'; |
773 | 773 | } |
774 | 774 | $info['attrib'] = $_[3]; |
775 | - switch($opt) { |
|
775 | + switch ($opt) { |
|
776 | 776 | case 'width' : return $info['width']; |
777 | 777 | case 'height': return $info['height']; |
778 | 778 | case 'aspect': return $info['aspect']; |
779 | 779 | case 'type' : return $info['type']; |
780 | 780 | case 'attrib': return $info['attrib']; |
781 | - default : return print_r($info,true); |
|
781 | + default : return print_r($info, true); |
|
782 | 782 | } |
783 | 783 | |
784 | 784 | case 'file_get_contents': |
785 | 785 | case 'readfile': |
786 | - if(!is_file($value)) return $value; |
|
786 | + if (!is_file($value)) return $value; |
|
787 | 787 | $value = realpath($value); |
788 | - if(strpos($value,MODX_MANAGER_PATH)!==false) exit('Can not read core file'); |
|
789 | - $ext = strtolower(substr($value,-4)); |
|
790 | - if($ext==='.php') exit('Can not read php file'); |
|
791 | - if($ext==='.cgi') exit('Can not read cgi file'); |
|
788 | + if (strpos($value, MODX_MANAGER_PATH) !== false) exit('Can not read core file'); |
|
789 | + $ext = strtolower(substr($value, -4)); |
|
790 | + if ($ext === '.php') exit('Can not read php file'); |
|
791 | + if ($ext === '.cgi') exit('Can not read cgi file'); |
|
792 | 792 | return file_get_contents($value); |
793 | 793 | case 'filesize': |
794 | - if($value == '') return ''; |
|
794 | + if ($value == '') return ''; |
|
795 | 795 | $filename = $value; |
796 | 796 | |
797 | 797 | $site_url = $modx->config['site_url']; |
798 | - if(strpos($filename,$site_url) === 0) |
|
799 | - $filename = substr($filename,0,strlen($site_url)); |
|
800 | - $filename = trim($filename,'/'); |
|
798 | + if (strpos($filename, $site_url) === 0) |
|
799 | + $filename = substr($filename, 0, strlen($site_url)); |
|
800 | + $filename = trim($filename, '/'); |
|
801 | 801 | |
802 | - $opt = trim($opt,'/'); |
|
803 | - if($opt!=='') $opt .= '/'; |
|
802 | + $opt = trim($opt, '/'); |
|
803 | + if ($opt !== '') $opt .= '/'; |
|
804 | 804 | |
805 | 805 | $filename = MODX_BASE_PATH.$opt.$filename; |
806 | 806 | |
807 | - if(is_file($filename)){ |
|
807 | + if (is_file($filename)) { |
|
808 | 808 | clearstatcache(); |
809 | 809 | $size = filesize($filename); |
810 | 810 | return $size; |
@@ -837,10 +837,10 @@ discard block |
||
837 | 837 | $this->opt = $cmd; |
838 | 838 | return $this->includeMdfFile('moduser'); |
839 | 839 | case 'userinfo': |
840 | - if(empty($opt)) $this->opt = 'username'; |
|
840 | + if (empty($opt)) $this->opt = 'username'; |
|
841 | 841 | return $this->includeMdfFile('moduser'); |
842 | 842 | case 'webuserinfo': |
843 | - if(empty($opt)) $this->opt = 'username'; |
|
843 | + if (empty($opt)) $this->opt = 'username'; |
|
844 | 844 | $this->value = -$value; |
845 | 845 | return $this->includeMdfFile('moduser'); |
846 | 846 | ##### Special functions |
@@ -851,28 +851,28 @@ discard block |
||
851 | 851 | case 'ifnotempty': |
852 | 852 | if (!empty($value)) return $opt; break; |
853 | 853 | case 'datagrid': |
854 | - include_once(MODX_CORE_PATH . 'controls/datagrid.class.php'); |
|
854 | + include_once(MODX_CORE_PATH.'controls/datagrid.class.php'); |
|
855 | 855 | $grd = new DataGrid(); |
856 | 856 | $grd->ds = trim($value); |
857 | 857 | $grd->itemStyle = ''; |
858 | 858 | $grd->altItemStyle = ''; |
859 | - $pos = strpos($value,"\n"); |
|
860 | - if($pos) $_ = substr($value,0,$pos); |
|
859 | + $pos = strpos($value, "\n"); |
|
860 | + if ($pos) $_ = substr($value, 0, $pos); |
|
861 | 861 | else $_ = $pos; |
862 | - $grd->cdelim = strpos($_,"\t")!==false ? 'tab' : ','; |
|
862 | + $grd->cdelim = strpos($_, "\t") !== false ? 'tab' : ','; |
|
863 | 863 | return $grd->render(); |
864 | 864 | case 'rotate': |
865 | 865 | case 'evenodd': |
866 | - if(strpos($opt,',')===false) $opt = 'odd,even'; |
|
866 | + if (strpos($opt, ',') === false) $opt = 'odd,even'; |
|
867 | 867 | $_ = explode(',', $opt); |
868 | 868 | $c = count($_); |
869 | 869 | $i = $value + $c; |
870 | 870 | $i = $i % $c; |
871 | 871 | return $_[$i]; |
872 | 872 | case 'takeval': |
873 | - $arr = explode(",",$opt); |
|
873 | + $arr = explode(",", $opt); |
|
874 | 874 | $idx = $value; |
875 | - if(!is_numeric($idx)) return $value; |
|
875 | + if (!is_numeric($idx)) return $value; |
|
876 | 876 | return $arr[$idx]; |
877 | 877 | case 'getimage': |
878 | 878 | return $this->includeMdfFile('getimage'); |
@@ -880,17 +880,17 @@ discard block |
||
880 | 880 | return $modx->nicesize($value); |
881 | 881 | case 'googlemap': |
882 | 882 | case 'googlemaps': |
883 | - if(empty($opt)) $opt = 'border:none;width:500px;height:350px;'; |
|
883 | + if (empty($opt)) $opt = 'border:none;width:500px;height:350px;'; |
|
884 | 884 | $tpl = '<iframe style="[+style+]" src="https://maps.google.co.jp/maps?ll=[+value+]&output=embed&z=15"></iframe>'; |
885 | 885 | $ph['style'] = $opt; |
886 | 886 | $ph['value'] = $value; |
887 | - return $modx->parseText($tpl,$ph); |
|
887 | + return $modx->parseText($tpl, $ph); |
|
888 | 888 | case 'youtube': |
889 | 889 | case 'youtube16x9': |
890 | - if(empty($opt)) $opt = 560; |
|
891 | - $h = round($opt*0.5625); |
|
890 | + if (empty($opt)) $opt = 560; |
|
891 | + $h = round($opt * 0.5625); |
|
892 | 892 | $tpl = '<iframe width="%s" height="%s" src="https://www.youtube.com/embed/%s" frameborder="0" allowfullscreen></iframe>'; |
893 | - return sprintf($tpl,$opt,$h,$value); |
|
893 | + return sprintf($tpl, $opt, $h, $value); |
|
894 | 894 | //case 'youtube4x3':%s*0.75+25 |
895 | 895 | case 'setvar': |
896 | 896 | $modx->placeholders[$opt] = $value; |
@@ -920,7 +920,7 @@ discard block |
||
920 | 920 | return $value; |
921 | 921 | } |
922 | 922 | |
923 | - function includeMdfFile($cmd) { |
|
923 | + function includeMdfFile($cmd){ |
|
924 | 924 | global $modx; |
925 | 925 | $key = $this->key; |
926 | 926 | $value = $this->value; |
@@ -931,54 +931,54 @@ discard block |
||
931 | 931 | function getValueFromElement($key, $value, $cmd, $opt) |
932 | 932 | { |
933 | 933 | global $modx; |
934 | - if( isset($modx->snippetCache[$this->elmName]) ) |
|
934 | + if (isset($modx->snippetCache[$this->elmName])) |
|
935 | 935 | { |
936 | 936 | $php = $modx->snippetCache[$this->elmName]; |
937 | 937 | } |
938 | 938 | else |
939 | 939 | { |
940 | 940 | $esc_elmName = $modx->db->escape($this->elmName); |
941 | - $result = $modx->db->select('snippet','[+prefix+]site_snippets',"name='{$esc_elmName}'"); |
|
941 | + $result = $modx->db->select('snippet', '[+prefix+]site_snippets', "name='{$esc_elmName}'"); |
|
942 | 942 | $total = $modx->db->getRecordCount($result); |
943 | - if($total == 1) |
|
943 | + if ($total == 1) |
|
944 | 944 | { |
945 | 945 | $row = $modx->db->getRow($result); |
946 | 946 | $php = $row['snippet']; |
947 | 947 | } |
948 | - elseif($total == 0) |
|
948 | + elseif ($total == 0) |
|
949 | 949 | { |
950 | 950 | $assets_path = MODX_BASE_PATH.'assets/'; |
951 | - if(is_file($assets_path."modifiers/mdf_{$cmd}.inc.php")) |
|
951 | + if (is_file($assets_path."modifiers/mdf_{$cmd}.inc.php")) |
|
952 | 952 | $modifiers_path = $assets_path."modifiers/mdf_{$cmd}.inc.php"; |
953 | - elseif(is_file($assets_path."plugins/phx/modifiers/{$cmd}.phx.php")) |
|
953 | + elseif (is_file($assets_path."plugins/phx/modifiers/{$cmd}.phx.php")) |
|
954 | 954 | $modifiers_path = $assets_path."plugins/phx/modifiers/{$cmd}.phx.php"; |
955 | - elseif(is_file(MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php")) |
|
955 | + elseif (is_file(MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php")) |
|
956 | 956 | $modifiers_path = MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php"; |
957 | 957 | else $modifiers_path = false; |
958 | 958 | |
959 | - if($modifiers_path) { |
|
959 | + if ($modifiers_path) { |
|
960 | 960 | $php = @file_get_contents($modifiers_path); |
961 | 961 | $php = trim($php); |
962 | - if(substr($php,0,5)==='<?php') $php = substr($php,6); |
|
963 | - if(substr($php,0,2)==='<?') $php = substr($php,3); |
|
964 | - if(substr($php,-2)==='?>') $php = substr($php,0,-2); |
|
965 | - if($this->elmName!=='') |
|
962 | + if (substr($php, 0, 5) === '<?php') $php = substr($php, 6); |
|
963 | + if (substr($php, 0, 2) === '<?') $php = substr($php, 3); |
|
964 | + if (substr($php, -2) === '?>') $php = substr($php, 0, -2); |
|
965 | + if ($this->elmName !== '') |
|
966 | 966 | $modx->snippetCache[$this->elmName.'Props'] = ''; |
967 | 967 | } |
968 | 968 | else |
969 | 969 | $php = false; |
970 | 970 | } |
971 | 971 | else $php = false; |
972 | - if($this->elmName!=='') $modx->snippetCache[$this->elmName]= $php; |
|
972 | + if ($this->elmName !== '') $modx->snippetCache[$this->elmName] = $php; |
|
973 | 973 | } |
974 | - if($php==='') $php=false; |
|
974 | + if ($php === '') $php = false; |
|
975 | 975 | |
976 | - if($php===false) $html = $modx->getChunk($this->elmName); |
|
976 | + if ($php === false) $html = $modx->getChunk($this->elmName); |
|
977 | 977 | else $html = false; |
978 | 978 | |
979 | 979 | $self = '[+output+]'; |
980 | 980 | |
981 | - if($php !== false) |
|
981 | + if ($php !== false) |
|
982 | 982 | { |
983 | 983 | ob_start(); |
984 | 984 | $options = $opt; |
@@ -991,71 +991,71 @@ discard block |
||
991 | 991 | $this->vars['options'] = & $opt; |
992 | 992 | $custom = eval($php); |
993 | 993 | $msg = ob_get_contents(); |
994 | - if($value===$this->bt) $value = $msg . $custom; |
|
994 | + if ($value === $this->bt) $value = $msg.$custom; |
|
995 | 995 | ob_end_clean(); |
996 | 996 | } |
997 | - elseif($html!==false && isset($value) && $value!=='') |
|
997 | + elseif ($html !== false && isset($value) && $value !== '') |
|
998 | 998 | { |
999 | - $html = str_replace(array($self,'[+value+]'), $value, $html); |
|
1000 | - $value = str_replace(array('[+options+]','[+param+]'), $opt, $html); |
|
999 | + $html = str_replace(array($self, '[+value+]'), $value, $html); |
|
1000 | + $value = str_replace(array('[+options+]', '[+param+]'), $opt, $html); |
|
1001 | 1001 | } |
1002 | 1002 | else return false; |
1003 | 1003 | |
1004 | - if($php===false && $html===false && $value!=='' |
|
1005 | - && (strpos($cmd,'[+value+]')!==false || strpos($cmd,$self)!==false)) |
|
1004 | + if ($php === false && $html === false && $value !== '' |
|
1005 | + && (strpos($cmd, '[+value+]') !== false || strpos($cmd, $self) !== false)) |
|
1006 | 1006 | { |
1007 | - $value = str_replace(array('[+value+]',$self),$value,$cmd); |
|
1007 | + $value = str_replace(array('[+value+]', $self), $value, $cmd); |
|
1008 | 1008 | } |
1009 | 1009 | return $value; |
1010 | 1010 | } |
1011 | 1011 | |
1012 | - function parseDocumentSource($content='') |
|
1012 | + function parseDocumentSource($content = '') |
|
1013 | 1013 | { |
1014 | 1014 | global $modx; |
1015 | 1015 | |
1016 | - if(strpos($content,'[')===false && strpos($content,'{')===false) return $content; |
|
1016 | + if (strpos($content, '[') === false && strpos($content, '{') === false) return $content; |
|
1017 | 1017 | |
1018 | - if(!$modx->maxParserPasses) $modx->maxParserPasses = 10; |
|
1019 | - $bt=''; |
|
1020 | - $i=0; |
|
1021 | - while($bt!==$content) |
|
1018 | + if (!$modx->maxParserPasses) $modx->maxParserPasses = 10; |
|
1019 | + $bt = ''; |
|
1020 | + $i = 0; |
|
1021 | + while ($bt !== $content) |
|
1022 | 1022 | { |
1023 | 1023 | $bt = $content; |
1024 | - if(strpos($content,'[*')!==false && $modx->documentIdentifier) |
|
1024 | + if (strpos($content, '[*') !== false && $modx->documentIdentifier) |
|
1025 | 1025 | $content = $modx->mergeDocumentContent($content); |
1026 | - if(strpos($content,'[(')!==false) $content = $modx->mergeSettingsContent($content); |
|
1027 | - if(strpos($content,'{{')!==false) $content = $modx->mergeChunkContent($content); |
|
1028 | - if(strpos($content,'[!')!==false) $content = str_replace(array('[!','!]'),array('[[',']]'),$content); |
|
1029 | - if(strpos($content,'[[')!==false) $content = $modx->evalSnippets($content); |
|
1026 | + if (strpos($content, '[(') !== false) $content = $modx->mergeSettingsContent($content); |
|
1027 | + if (strpos($content, '{{') !== false) $content = $modx->mergeChunkContent($content); |
|
1028 | + if (strpos($content, '[!') !== false) $content = str_replace(array('[!', '!]'), array('[[', ']]'), $content); |
|
1029 | + if (strpos($content, '[[') !== false) $content = $modx->evalSnippets($content); |
|
1030 | 1030 | |
1031 | - if($content===$bt) break; |
|
1032 | - if($modx->maxParserPasses < $i) break; |
|
1031 | + if ($content === $bt) break; |
|
1032 | + if ($modx->maxParserPasses < $i) break; |
|
1033 | 1033 | $i++; |
1034 | 1034 | } |
1035 | 1035 | return $content; |
1036 | 1036 | } |
1037 | 1037 | |
1038 | - function getDocumentObject($target='',$field='pagetitle') |
|
1038 | + function getDocumentObject($target = '', $field = 'pagetitle') |
|
1039 | 1039 | { |
1040 | 1040 | global $modx; |
1041 | 1041 | |
1042 | 1042 | $target = trim($target); |
1043 | - if(empty($target)) $target = $modx->config['site_start']; |
|
1044 | - if(preg_match('@^[1-9][0-9]*$@',$target)) $method='id'; |
|
1043 | + if (empty($target)) $target = $modx->config['site_start']; |
|
1044 | + if (preg_match('@^[1-9][0-9]*$@', $target)) $method = 'id'; |
|
1045 | 1045 | else $method = 'alias'; |
1046 | 1046 | |
1047 | - if(!isset($this->documentObject[$target])) |
|
1047 | + if (!isset($this->documentObject[$target])) |
|
1048 | 1048 | { |
1049 | - $this->documentObject[$target] = $modx->getDocumentObject($method,$target,'direct'); |
|
1049 | + $this->documentObject[$target] = $modx->getDocumentObject($method, $target, 'direct'); |
|
1050 | 1050 | } |
1051 | 1051 | |
1052 | - if($this->documentObject[$target]['publishedon']==='0') |
|
1052 | + if ($this->documentObject[$target]['publishedon'] === '0') |
|
1053 | 1053 | return ''; |
1054 | - elseif(isset($this->documentObject[$target][$field])) |
|
1054 | + elseif (isset($this->documentObject[$target][$field])) |
|
1055 | 1055 | { |
1056 | - if(is_array($this->documentObject[$target][$field])) |
|
1056 | + if (is_array($this->documentObject[$target][$field])) |
|
1057 | 1057 | { |
1058 | - $a = $modx->getTemplateVarOutput($field,$target); |
|
1058 | + $a = $modx->getTemplateVarOutput($field, $target); |
|
1059 | 1059 | $this->documentObject[$target][$field] = $a[$field]; |
1060 | 1060 | } |
1061 | 1061 | } |
@@ -1064,8 +1064,8 @@ discard block |
||
1064 | 1064 | return $this->documentObject[$target][$field]; |
1065 | 1065 | } |
1066 | 1066 | |
1067 | - function setPlaceholders($value = '', $key = '', $path = '') { |
|
1068 | - if($path!=='') $key = "{$path}.{$key}"; |
|
1067 | + function setPlaceholders($value = '', $key = '', $path = ''){ |
|
1068 | + if ($path !== '') $key = "{$path}.{$key}"; |
|
1069 | 1069 | if (is_array($value)) { |
1070 | 1070 | foreach ($value as $subkey => $subval) { |
1071 | 1071 | $this->setPlaceholders($subval, $subkey, $key); |
@@ -1075,77 +1075,77 @@ discard block |
||
1075 | 1075 | } |
1076 | 1076 | |
1077 | 1077 | // Sets a placeholder variable which can only be access by Modifiers |
1078 | - function setModifiersVariable($key, $value) { |
|
1078 | + function setModifiersVariable($key, $value){ |
|
1079 | 1079 | if ($key != 'phx' && $key != 'dummy') $this->placeholders[$key] = $value; |
1080 | 1080 | } |
1081 | 1081 | |
1082 | 1082 | //mbstring |
1083 | - function substr($str, $s, $l = null) { |
|
1083 | + function substr($str, $s, $l = null){ |
|
1084 | 1084 | global $modx; |
1085 | - if(is_null($l)) $l = $this->strlen($str); |
|
1085 | + if (is_null($l)) $l = $this->strlen($str); |
|
1086 | 1086 | if (function_exists('mb_substr')) |
1087 | 1087 | { |
1088 | - if(strpos($str,"\r")!==false) |
|
1089 | - $str = str_replace(array("\r\n","\r"), "\n", $str); |
|
1088 | + if (strpos($str, "\r") !== false) |
|
1089 | + $str = str_replace(array("\r\n", "\r"), "\n", $str); |
|
1090 | 1090 | return mb_substr($str, $s, $l, $modx->config['modx_charset']); |
1091 | 1091 | } |
1092 | 1092 | return substr($str, $s, $l); |
1093 | 1093 | } |
1094 | - function strpos($haystack,$needle,$offset=0) { |
|
1094 | + function strpos($haystack, $needle, $offset = 0){ |
|
1095 | 1095 | global $modx; |
1096 | - if (function_exists('mb_strpos')) return mb_strpos($haystack,$needle,$offset,$modx->config['modx_charset']); |
|
1097 | - return strpos($haystack,$needle,$offset); |
|
1096 | + if (function_exists('mb_strpos')) return mb_strpos($haystack, $needle, $offset, $modx->config['modx_charset']); |
|
1097 | + return strpos($haystack, $needle, $offset); |
|
1098 | 1098 | } |
1099 | - function strlen($str) { |
|
1099 | + function strlen($str){ |
|
1100 | 1100 | global $modx; |
1101 | - if (function_exists('mb_strlen')) return mb_strlen(str_replace("\r\n", "\n", $str),$modx->config['modx_charset']); |
|
1101 | + if (function_exists('mb_strlen')) return mb_strlen(str_replace("\r\n", "\n", $str), $modx->config['modx_charset']); |
|
1102 | 1102 | return strlen($str); |
1103 | 1103 | } |
1104 | - function strtolower($str) { |
|
1104 | + function strtolower($str){ |
|
1105 | 1105 | if (function_exists('mb_strtolower')) return mb_strtolower($str); |
1106 | 1106 | return strtolower($str); |
1107 | 1107 | } |
1108 | - function strtoupper($str) { |
|
1108 | + function strtoupper($str){ |
|
1109 | 1109 | if (function_exists('mb_strtoupper')) return mb_strtoupper($str); |
1110 | 1110 | return strtoupper($str); |
1111 | 1111 | } |
1112 | - function ucfirst($str) { |
|
1112 | + function ucfirst($str){ |
|
1113 | 1113 | if (function_exists('mb_strtoupper')) |
1114 | 1114 | return mb_strtoupper($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str)); |
1115 | 1115 | return ucfirst($str); |
1116 | 1116 | } |
1117 | - function lcfirst($str) { |
|
1117 | + function lcfirst($str){ |
|
1118 | 1118 | if (function_exists('mb_strtolower')) |
1119 | 1119 | return mb_strtolower($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str)); |
1120 | 1120 | return lcfirst($str); |
1121 | 1121 | } |
1122 | - function ucwords($str) { |
|
1122 | + function ucwords($str){ |
|
1123 | 1123 | if (function_exists('mb_convert_case')) |
1124 | 1124 | return mb_convert_case($str, MB_CASE_TITLE); |
1125 | 1125 | return ucwords($str); |
1126 | 1126 | } |
1127 | - function strrev($str) { |
|
1127 | + function strrev($str){ |
|
1128 | 1128 | preg_match_all('/./us', $str, $ar); |
1129 | 1129 | return join(array_reverse($ar[0])); |
1130 | 1130 | } |
1131 | - function str_shuffle($str) { |
|
1131 | + function str_shuffle($str){ |
|
1132 | 1132 | preg_match_all('/./us', $str, $ar); |
1133 | 1133 | shuffle($ar[0]); |
1134 | 1134 | return join($ar[0]); |
1135 | 1135 | } |
1136 | - function str_word_count($str) { |
|
1137 | - return count(preg_split('~[^\p{L}\p{N}\']+~u',$str)); |
|
1136 | + function str_word_count($str){ |
|
1137 | + return count(preg_split('~[^\p{L}\p{N}\']+~u', $str)); |
|
1138 | 1138 | } |
1139 | - function strip_tags($value,$params='') { |
|
1139 | + function strip_tags($value, $params = ''){ |
|
1140 | 1140 | global $modx; |
1141 | 1141 | |
1142 | - if(stripos($params,'style')===false && stripos($value,'</style>')!==false) { |
|
1142 | + if (stripos($params, 'style') === false && stripos($value, '</style>') !== false) { |
|
1143 | 1143 | $value = preg_replace('@<style.*?>.*?</style>@is', '', $value); |
1144 | 1144 | } |
1145 | - if(stripos($params,'script')===false && stripos($value,'</script>')!==false) { |
|
1145 | + if (stripos($params, 'script') === false && stripos($value, '</script>') !== false) { |
|
1146 | 1146 | $value = preg_replace('@<script.*?>.*?</script>@is', '', $value); |
1147 | 1147 | } |
1148 | 1148 | |
1149 | - return trim(strip_tags($value,$params)); |
|
1149 | + return trim(strip_tags($value, $params)); |
|
1150 | 1150 | } |
1151 | 1151 | } |
@@ -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; |
@@ -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,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, '[%', '%]'); |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * |
9 | 9 | * @author Jason Coward <[email protected]> (MODX) |
10 | 10 | */ |
11 | -class MakeTable { |
|
11 | +class MakeTable{ |
|
12 | 12 | var $actionField; |
13 | 13 | var $cellAction; |
14 | 14 | var $linkAction; |
@@ -31,26 +31,26 @@ discard block |
||
31 | 31 | var $columnWidths; |
32 | 32 | var $selectedValues; |
33 | 33 | |
34 | - function __construct() { |
|
35 | - $this->fieldHeaders= array(); |
|
36 | - $this->excludeFields= array(); |
|
37 | - $this->actionField= ''; |
|
38 | - $this->cellAction= ''; |
|
39 | - $this->linkAction= ''; |
|
40 | - $this->tableWidth= ''; |
|
41 | - $this->tableClass= ''; |
|
42 | - $this->rowHeaderClass= ''; |
|
43 | - $this->columnHeaderClass= ''; |
|
44 | - $this->rowRegularClass= ''; |
|
45 | - $this->rowAlternateClass= 'alt'; |
|
46 | - $this->formName= 'tableForm'; |
|
47 | - $this->formAction= '[~[*id*]~]'; |
|
48 | - $this->formElementName= ''; |
|
49 | - $this->formElementType= ''; |
|
50 | - $this->rowAlternatingScheme= 'EVEN'; |
|
51 | - $this->allOption= 0; |
|
52 | - $this->selectedValues= array(); |
|
53 | - $this->extra= ''; |
|
34 | + function __construct(){ |
|
35 | + $this->fieldHeaders = array(); |
|
36 | + $this->excludeFields = array(); |
|
37 | + $this->actionField = ''; |
|
38 | + $this->cellAction = ''; |
|
39 | + $this->linkAction = ''; |
|
40 | + $this->tableWidth = ''; |
|
41 | + $this->tableClass = ''; |
|
42 | + $this->rowHeaderClass = ''; |
|
43 | + $this->columnHeaderClass = ''; |
|
44 | + $this->rowRegularClass = ''; |
|
45 | + $this->rowAlternateClass = 'alt'; |
|
46 | + $this->formName = 'tableForm'; |
|
47 | + $this->formAction = '[~[*id*]~]'; |
|
48 | + $this->formElementName = ''; |
|
49 | + $this->formElementType = ''; |
|
50 | + $this->rowAlternatingScheme = 'EVEN'; |
|
51 | + $this->allOption = 0; |
|
52 | + $this->selectedValues = array(); |
|
53 | + $this->extra = ''; |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
@@ -58,8 +58,8 @@ discard block |
||
58 | 58 | * |
59 | 59 | * @param $value A URL to execute when table cells are clicked. |
60 | 60 | */ |
61 | - function setCellAction($value) { |
|
62 | - $this->cellAction= $this->prepareLink($value); |
|
61 | + function setCellAction($value){ |
|
62 | + $this->cellAction = $this->prepareLink($value); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -67,8 +67,8 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @param $value A URL to execute when text within table cells are clicked. |
69 | 69 | */ |
70 | - function setLinkAction($value) { |
|
71 | - $this->linkAction= $this->prepareLink($value); |
|
70 | + function setLinkAction($value){ |
|
71 | + $this->linkAction = $this->prepareLink($value); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | * |
77 | 77 | * @param $value A valid width attribute for the HTML TABLE tag |
78 | 78 | */ |
79 | - function setTableWidth($value) { |
|
80 | - $this->tableWidth= $value; |
|
79 | + function setTableWidth($value){ |
|
80 | + $this->tableWidth = $value; |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -85,8 +85,8 @@ discard block |
||
85 | 85 | * |
86 | 86 | * @param $value A class for the main HTML TABLE. |
87 | 87 | */ |
88 | - function setTableClass($value) { |
|
89 | - $this->tableClass= $value; |
|
88 | + function setTableClass($value){ |
|
89 | + $this->tableClass = $value; |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -94,8 +94,8 @@ discard block |
||
94 | 94 | * |
95 | 95 | * @param $value A class for the main HTML TABLE. |
96 | 96 | */ |
97 | - function setTableID($value) { |
|
98 | - $this->tableID= $value; |
|
97 | + function setTableID($value){ |
|
98 | + $this->tableID = $value; |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -103,8 +103,8 @@ discard block |
||
103 | 103 | * |
104 | 104 | * @param $value A class for the table header row. |
105 | 105 | */ |
106 | - function setRowHeaderClass($value) { |
|
107 | - $this->rowHeaderClass= $value; |
|
106 | + function setRowHeaderClass($value){ |
|
107 | + $this->rowHeaderClass = $value; |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -112,8 +112,8 @@ discard block |
||
112 | 112 | * |
113 | 113 | * @param $value A class for the table header row. |
114 | 114 | */ |
115 | - function setThHeaderClass($value) { |
|
116 | - $this->thClass= $value; |
|
115 | + function setThHeaderClass($value){ |
|
116 | + $this->thClass = $value; |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
@@ -121,8 +121,8 @@ discard block |
||
121 | 121 | * |
122 | 122 | * @param $value A class for the column header row. |
123 | 123 | */ |
124 | - function setColumnHeaderClass($value) { |
|
125 | - $this->columnHeaderClass= $value; |
|
124 | + function setColumnHeaderClass($value){ |
|
125 | + $this->columnHeaderClass = $value; |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -130,8 +130,8 @@ discard block |
||
130 | 130 | * |
131 | 131 | * @param $value A class for regular table rows. |
132 | 132 | */ |
133 | - function setRowRegularClass($value) { |
|
134 | - $this->rowRegularClass= $value; |
|
133 | + function setRowRegularClass($value){ |
|
134 | + $this->rowRegularClass = $value; |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | * |
140 | 140 | * @param $value A class for alternate table rows. |
141 | 141 | */ |
142 | - function setRowAlternateClass($value) { |
|
143 | - $this->rowAlternateClass= $value; |
|
142 | + function setRowAlternateClass($value){ |
|
143 | + $this->rowAlternateClass = $value; |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -148,8 +148,8 @@ discard block |
||
148 | 148 | * |
149 | 149 | * @param $value Indicates the INPUT form element type attribute. |
150 | 150 | */ |
151 | - function setFormElementType($value) { |
|
152 | - $this->formElementType= $value; |
|
151 | + function setFormElementType($value){ |
|
152 | + $this->formElementType = $value; |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -157,8 +157,8 @@ discard block |
||
157 | 157 | * |
158 | 158 | * @param $value Indicates the INPUT form element name attribute. |
159 | 159 | */ |
160 | - function setFormElementName($value) { |
|
161 | - $this->formElementName= $value; |
|
160 | + function setFormElementName($value){ |
|
161 | + $this->formElementName = $value; |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -167,8 +167,8 @@ discard block |
||
167 | 167 | * |
168 | 168 | * @param $value Indicates the FORM name attribute. |
169 | 169 | */ |
170 | - function setFormName($value) { |
|
171 | - $this->formName= $value; |
|
170 | + function setFormName($value){ |
|
171 | + $this->formName = $value; |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -176,8 +176,8 @@ discard block |
||
176 | 176 | * |
177 | 177 | * @param $value Indicates the FORM action attribute. |
178 | 178 | */ |
179 | - function setFormAction($value) { |
|
180 | - $this->formAction= $value; |
|
179 | + function setFormAction($value){ |
|
180 | + $this->formAction = $value; |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
@@ -185,8 +185,8 @@ discard block |
||
185 | 185 | * |
186 | 186 | * @param $value An Array of field keys to exclude from the table. |
187 | 187 | */ |
188 | - function setExcludeFields($value) { |
|
189 | - $this->excludeFields= $value; |
|
188 | + function setExcludeFields($value){ |
|
189 | + $this->excludeFields = $value; |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
@@ -194,8 +194,8 @@ discard block |
||
194 | 194 | * |
195 | 195 | * @param $value 'ODD' or 'EVEN' to indicate the alternate row scheme. |
196 | 196 | */ |
197 | - function setRowAlternatingScheme($value) { |
|
198 | - $this->rowAlternatingScheme= $value; |
|
197 | + function setRowAlternatingScheme($value){ |
|
198 | + $this->rowAlternatingScheme = $value; |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | /** |
@@ -204,8 +204,8 @@ discard block |
||
204 | 204 | * |
205 | 205 | * @param $value The key of the field to add as a query string parameter. |
206 | 206 | */ |
207 | - function setActionFieldName($value) { |
|
208 | - $this->actionField= $value; |
|
207 | + function setActionFieldName($value){ |
|
208 | + $this->actionField = $value; |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
@@ -214,8 +214,8 @@ discard block |
||
214 | 214 | * @param $value An Array of column widths in the order of the keys in the |
215 | 215 | * source table array. |
216 | 216 | */ |
217 | - function setColumnWidths($widthArray) { |
|
218 | - $this->columnWidths= $widthArray; |
|
217 | + function setColumnWidths($widthArray){ |
|
218 | + $this->columnWidths = $widthArray; |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
@@ -223,8 +223,8 @@ discard block |
||
223 | 223 | * |
224 | 224 | * @param $value Indicates the INPUT form element type attribute. |
225 | 225 | */ |
226 | - function setSelectedValues($valueArray) { |
|
227 | - $this->selectedValues= $valueArray; |
|
226 | + function setSelectedValues($valueArray){ |
|
227 | + $this->selectedValues = $valueArray; |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | /** |
@@ -233,8 +233,8 @@ discard block |
||
233 | 233 | * |
234 | 234 | * @param $value A string of additional content. |
235 | 235 | */ |
236 | - function setExtra($value) { |
|
237 | - $this->extra= $value; |
|
236 | + function setExtra($value){ |
|
237 | + $this->extra = $value; |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
@@ -242,10 +242,10 @@ discard block |
||
242 | 242 | * |
243 | 243 | * @param $columnPosition The index of the column to get the width for. |
244 | 244 | */ |
245 | - function getColumnWidth($columnPosition) { |
|
246 | - $currentWidth= ''; |
|
245 | + function getColumnWidth($columnPosition){ |
|
246 | + $currentWidth = ''; |
|
247 | 247 | if (is_array($this->columnWidths)) { |
248 | - $currentWidth= $this->columnWidths[$columnPosition] ? ' width="'.$this->columnWidths[$columnPosition].'" ' : ''; |
|
248 | + $currentWidth = $this->columnWidths[$columnPosition] ? ' width="'.$this->columnWidths[$columnPosition].'" ' : ''; |
|
249 | 249 | } |
250 | 250 | return $currentWidth; |
251 | 251 | } |
@@ -255,19 +255,19 @@ discard block |
||
255 | 255 | * |
256 | 256 | * @param $value The position of the current row being rendered. |
257 | 257 | */ |
258 | - function determineRowClass($position) { |
|
258 | + function determineRowClass($position){ |
|
259 | 259 | switch ($this->rowAlternatingScheme) { |
260 | 260 | case 'ODD' : |
261 | - $modRemainder= 1; |
|
261 | + $modRemainder = 1; |
|
262 | 262 | break; |
263 | 263 | case 'EVEN' : |
264 | - $modRemainder= 0; |
|
264 | + $modRemainder = 0; |
|
265 | 265 | break; |
266 | 266 | } |
267 | 267 | if ($position % 2 == $modRemainder) { |
268 | - $currentClass= $this->rowRegularClass; |
|
268 | + $currentClass = $this->rowRegularClass; |
|
269 | 269 | } else { |
270 | - $currentClass= $this->rowAlternateClass; |
|
270 | + $currentClass = $this->rowAlternateClass; |
|
271 | 271 | } |
272 | 272 | return ' class="'.$currentClass.'"'; |
273 | 273 | } |
@@ -278,9 +278,9 @@ discard block |
||
278 | 278 | * |
279 | 279 | * @param $value Indicates the INPUT form element type attribute. |
280 | 280 | */ |
281 | - function getCellAction($currentActionFieldValue) { |
|
281 | + function getCellAction($currentActionFieldValue){ |
|
282 | 282 | if ($this->cellAction) { |
283 | - $cellAction= ' onClick="javascript:window.location=\''.$this->cellAction.$this->actionField.'='.urlencode($currentActionFieldValue).'\'" '; |
|
283 | + $cellAction = ' onClick="javascript:window.location=\''.$this->cellAction.$this->actionField.'='.urlencode($currentActionFieldValue).'\'" '; |
|
284 | 284 | } |
285 | 285 | return $cellAction; |
286 | 286 | } |
@@ -291,10 +291,10 @@ discard block |
||
291 | 291 | * @param $currentActionFieldValue The value to be applied to the link action. |
292 | 292 | * @param $value The value of the cell. |
293 | 293 | */ |
294 | - function createCellText($currentActionFieldValue, $value) { |
|
294 | + function createCellText($currentActionFieldValue, $value){ |
|
295 | 295 | $cell .= $value; |
296 | 296 | if ($this->linkAction) { |
297 | - $cell= '<a href="'.$this->linkAction.$this->actionField.'='.urlencode($currentActionFieldValue).'">'.$cell.'</a>'; |
|
297 | + $cell = '<a href="'.$this->linkAction.$this->actionField.'='.urlencode($currentActionFieldValue).'">'.$cell.'</a>'; |
|
298 | 298 | } |
299 | 299 | return $cell; |
300 | 300 | } |
@@ -303,8 +303,8 @@ discard block |
||
303 | 303 | * Sets an option to generate a check all link when checkbox is indicated |
304 | 304 | * as the table formElementType. |
305 | 305 | */ |
306 | - function setAllOption() { |
|
307 | - $this->allOption= 1; |
|
306 | + function setAllOption(){ |
|
307 | + $this->allOption = 1; |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | /** |
@@ -312,11 +312,11 @@ discard block |
||
312 | 312 | * |
313 | 313 | * @param $value Indicates the INPUT form element type attribute. |
314 | 314 | */ |
315 | - function prepareLink($link) { |
|
315 | + function prepareLink($link){ |
|
316 | 316 | if (strstr($link, '?')) { |
317 | - $end= '&'; |
|
317 | + $end = '&'; |
|
318 | 318 | } else { |
319 | - $end= '?'; |
|
319 | + $end = '?'; |
|
320 | 320 | } |
321 | 321 | return $link.$end; |
322 | 322 | } |
@@ -331,20 +331,20 @@ discard block |
||
331 | 331 | * the $fieldsArray where the values represent the alt heading content |
332 | 332 | * for each column. |
333 | 333 | */ |
334 | - function create($fieldsArray, $fieldHeadersArray=array(),$linkpage="") { |
|
334 | + function create($fieldsArray, $fieldHeadersArray = array(), $linkpage = ""){ |
|
335 | 335 | global $_lang; |
336 | 336 | if (is_array($fieldsArray)) { |
337 | - $i= 0; |
|
337 | + $i = 0; |
|
338 | 338 | foreach ($fieldsArray as $fieldName => $fieldValue) { |
339 | 339 | $table .= "\t<tr".$this->determineRowClass($i).">\n"; |
340 | - $currentActionFieldValue= $fieldValue[$this->actionField]; |
|
340 | + $currentActionFieldValue = $fieldValue[$this->actionField]; |
|
341 | 341 | if (is_array($this->selectedValues)) { |
342 | - $isChecked= array_search($currentActionFieldValue, $this->selectedValues)===false? 0 : 1; |
|
342 | + $isChecked = array_search($currentActionFieldValue, $this->selectedValues) === false ? 0 : 1; |
|
343 | 343 | } else { |
344 | - $isChecked= false; |
|
344 | + $isChecked = false; |
|
345 | 345 | } |
346 | 346 | $table .= $this->addFormField($currentActionFieldValue, $isChecked); |
347 | - $colPosition= 0; |
|
347 | + $colPosition = 0; |
|
348 | 348 | foreach ($fieldValue as $key => $value) { |
349 | 349 | if (!in_array($key, $this->excludeFields)) { |
350 | 350 | $table .= "\t\t<td".$this->getCellAction($currentActionFieldValue).">"; |
@@ -352,20 +352,20 @@ discard block |
||
352 | 352 | $table .= "</td>\n"; |
353 | 353 | if ($i == 0) { |
354 | 354 | if (empty ($header) && $this->formElementType) { |
355 | - $header .= "\t\t<th style=\"width:32px\" ".($this->thClass ? 'class="'.$this->thClass.'"' : '').">". ($this->allOption ? '<a href="javascript:clickAll()">all</a>' : '')."</th>\n"; |
|
355 | + $header .= "\t\t<th style=\"width:32px\" ".($this->thClass ? 'class="'.$this->thClass.'"' : '').">".($this->allOption ? '<a href="javascript:clickAll()">all</a>' : '')."</th>\n"; |
|
356 | 356 | } |
357 | - $headerText= array_key_exists($key, $fieldHeadersArray)? $fieldHeadersArray[$key]: $key; |
|
357 | + $headerText = array_key_exists($key, $fieldHeadersArray) ? $fieldHeadersArray[$key] : $key; |
|
358 | 358 | $header .= "\t\t<th".$this->getColumnWidth($colPosition).($this->thClass ? ' class="'.$this->thClass.'" ' : '').">".$headerText."</th>\n"; |
359 | 359 | } |
360 | - $colPosition ++; |
|
360 | + $colPosition++; |
|
361 | 361 | } |
362 | 362 | } |
363 | - $i ++; |
|
363 | + $i++; |
|
364 | 364 | $table .= "\t</tr>\n"; |
365 | 365 | } |
366 | - $table= "\n".'<table'. ($this->tableWidth ? ' width="'.$this->tableWidth.'"' : ''). ($this->tableClass ? ' class="'.$this->tableClass.'"' : ''). ($this->tableID ? ' id="'.$this->tableID.'"' : '').">\n". ($header ? "\t<thead>\n\t<tr class=\"".$this->rowHeaderClass."\">\n".$header."\t</tr>\n\t</thead>\n" : '').$table."</table>\n"; |
|
366 | + $table = "\n".'<table'.($this->tableWidth ? ' width="'.$this->tableWidth.'"' : '').($this->tableClass ? ' class="'.$this->tableClass.'"' : '').($this->tableID ? ' id="'.$this->tableID.'"' : '').">\n".($header ? "\t<thead>\n\t<tr class=\"".$this->rowHeaderClass."\">\n".$header."\t</tr>\n\t</thead>\n" : '').$table."</table>\n"; |
|
367 | 367 | if ($this->formElementType) { |
368 | - $table= "\n".'<form id="'.$this->formName.'" name="'.$this->formName.'" action="'.$this->formAction.'" method="POST">'.$table; |
|
368 | + $table = "\n".'<form id="'.$this->formName.'" name="'.$this->formName.'" action="'.$this->formAction.'" method="POST">'.$table; |
|
369 | 369 | } |
370 | 370 | if (strlen($this->pageNav) > 1) {//changed to display the pagination if exists. |
371 | 371 | /* commented this part because of cookie |
@@ -400,9 +400,9 @@ discard block |
||
400 | 400 | } |
401 | 401 | if ($this->formElementType) { |
402 | 402 | if ($this->extra) { |
403 | - $table.= "\n".$this->extra."\n"; |
|
403 | + $table .= "\n".$this->extra."\n"; |
|
404 | 404 | } |
405 | - $table.= "\n".'</form>'."\n"; |
|
405 | + $table .= "\n".'</form>'."\n"; |
|
406 | 406 | } |
407 | 407 | return $table; |
408 | 408 | } |
@@ -414,36 +414,36 @@ discard block |
||
414 | 414 | * @param $numRecords The number of records to show per page. |
415 | 415 | * @param $qs An optional query string to be appended to the paging links |
416 | 416 | */ |
417 | - function createPagingNavigation($numRecords, $qs='') { |
|
417 | + function createPagingNavigation($numRecords, $qs = ''){ |
|
418 | 418 | global $_lang; |
419 | - $currentPage= (is_numeric($_GET['page']) ? $_GET['page'] : 1); |
|
420 | - $numPages= ceil($numRecords / MAX_DISPLAY_RECORDS_NUM); |
|
419 | + $currentPage = (is_numeric($_GET['page']) ? $_GET['page'] : 1); |
|
420 | + $numPages = ceil($numRecords / MAX_DISPLAY_RECORDS_NUM); |
|
421 | 421 | if ($numPages > 1) { |
422 | - $currentURL= empty($qs)? '': '?'.$qs; |
|
422 | + $currentURL = empty($qs) ? '' : '?'.$qs; |
|
423 | 423 | if ($currentPage > 6) { |
424 | 424 | $nav .= $this->createPageLink($currentURL, 1, $_lang["pagination_table_first"]); |
425 | 425 | } |
426 | 426 | if ($currentPage != 1) { |
427 | - $nav .= $this->createPageLink($currentURL, $currentPage -1, '<<'); |
|
427 | + $nav .= $this->createPageLink($currentURL, $currentPage - 1, '<<'); |
|
428 | 428 | } |
429 | - $offset= -4 + ($currentPage < 5 ? (5 - $currentPage) : 0); |
|
430 | - $i= 1; |
|
429 | + $offset = -4 + ($currentPage < 5 ? (5 - $currentPage) : 0); |
|
430 | + $i = 1; |
|
431 | 431 | while ($i < 10 && ($currentPage + $offset <= $numPages)) { |
432 | 432 | if ($currentPage == $currentPage + $offset) |
433 | 433 | $nav .= $this->createPageLink($currentURL, $currentPage + $offset, $currentPage + $offset, true); |
434 | 434 | else |
435 | 435 | $nav .= $this->createPageLink($currentURL, $currentPage + $offset, $currentPage + $offset); |
436 | - $i ++; |
|
437 | - $offset ++; |
|
436 | + $i++; |
|
437 | + $offset++; |
|
438 | 438 | } |
439 | 439 | if ($currentPage < $numPages) { |
440 | - $nav .= $this->createPageLink($currentURL, $currentPage +1, '>>'); |
|
440 | + $nav .= $this->createPageLink($currentURL, $currentPage + 1, '>>'); |
|
441 | 441 | } |
442 | 442 | if ($currentPage != $numPages) { |
443 | 443 | $nav .= $this->createPageLink($currentURL, $numPages, $_lang["pagination_table_last"]); |
444 | 444 | } |
445 | 445 | } |
446 | - $this->pageNav= ' '.$nav; |
|
446 | + $this->pageNav = ' '.$nav; |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
@@ -455,13 +455,13 @@ discard block |
||
455 | 455 | * @param $currentPage Indicates if the link is to the current page. |
456 | 456 | * @param $qs And optional query string to be appended to the link. |
457 | 457 | */ |
458 | - function createPageLink($link='', $pageNum, $displayText, $currentPage=false, $qs='') { |
|
458 | + function createPageLink($link = '', $pageNum, $displayText, $currentPage = false, $qs = ''){ |
|
459 | 459 | global $modx; |
460 | - $orderBy= !empty($_GET['orderby'])? '&orderby=' . $_GET['orderby']: ''; |
|
461 | - $orderDir= !empty($_GET['orderdir'])? '&orderdir=' . $_GET['orderdir']: ''; |
|
462 | - if (!empty($qs)) $qs= "?$qs"; |
|
463 | - $link= empty($link)? $modx->makeUrl($modx->documentIdentifier, $modx->documentObject['alias'], $qs . "page=$pageNum$orderBy$orderDir"): $this->prepareLink($link) . "page=$pageNum"; |
|
464 | - $nav .= '<li'.($currentPage? ' class="currentPage"': '').'><a'.($currentPage? ' class="currentPage"': '').' href="'.$link.'">'.$displayText.'</a></li>'."\n"; |
|
460 | + $orderBy = !empty($_GET['orderby']) ? '&orderby='.$_GET['orderby'] : ''; |
|
461 | + $orderDir = !empty($_GET['orderdir']) ? '&orderdir='.$_GET['orderdir'] : ''; |
|
462 | + if (!empty($qs)) $qs = "?$qs"; |
|
463 | + $link = empty($link) ? $modx->makeUrl($modx->documentIdentifier, $modx->documentObject['alias'], $qs."page=$pageNum$orderBy$orderDir") : $this->prepareLink($link)."page=$pageNum"; |
|
464 | + $nav .= '<li'.($currentPage ? ' class="currentPage"' : '').'><a'.($currentPage ? ' class="currentPage"' : '').' href="'.$link.'">'.$displayText.'</a></li>'."\n"; |
|
465 | 465 | return $nav; |
466 | 466 | } |
467 | 467 | |
@@ -472,10 +472,10 @@ discard block |
||
472 | 472 | * @param $isChecked Indicates if the checked attribute should apply to the |
473 | 473 | * element. |
474 | 474 | */ |
475 | - function addFormField($value, $isChecked) { |
|
475 | + function addFormField($value, $isChecked){ |
|
476 | 476 | if ($this->formElementType) { |
477 | - $checked= $isChecked? "checked ": ""; |
|
478 | - $field= "\t\t".'<td><input type="'.$this->formElementType.'" name="'. ($this->formElementName ? $this->formElementName : $value).'" value="'.$value.'" '.$checked.'/></td>'."\n"; |
|
477 | + $checked = $isChecked ? "checked " : ""; |
|
478 | + $field = "\t\t".'<td><input type="'.$this->formElementType.'" name="'.($this->formElementName ? $this->formElementName : $value).'" value="'.$value.'" '.$checked.'/></td>'."\n"; |
|
479 | 479 | } |
480 | 480 | return $field; |
481 | 481 | } |
@@ -484,9 +484,9 @@ discard block |
||
484 | 484 | * Generates the proper LIMIT clause for queries to retrieve paged results in |
485 | 485 | * a MakeTable $fieldsArray. |
486 | 486 | */ |
487 | - function handlePaging() { |
|
488 | - $offset= (is_numeric($_GET['page']) && $_GET['page'] > 0) ? $_GET['page'] - 1 : 0; |
|
489 | - $limitClause= ' LIMIT '. ($offset * MAX_DISPLAY_RECORDS_NUM).', '.MAX_DISPLAY_RECORDS_NUM; |
|
487 | + function handlePaging(){ |
|
488 | + $offset = (is_numeric($_GET['page']) && $_GET['page'] > 0) ? $_GET['page'] - 1 : 0; |
|
489 | + $limitClause = ' LIMIT '.($offset * MAX_DISPLAY_RECORDS_NUM).', '.MAX_DISPLAY_RECORDS_NUM; |
|
490 | 490 | return $limitClause; |
491 | 491 | } |
492 | 492 | |
@@ -496,12 +496,12 @@ discard block |
||
496 | 496 | * |
497 | 497 | * @param $natural_order If true, the results are returned in natural order. |
498 | 498 | */ |
499 | - function handleSorting($natural_order=false) { |
|
500 | - $orderByClause= ''; |
|
499 | + function handleSorting($natural_order = false){ |
|
500 | + $orderByClause = ''; |
|
501 | 501 | if (!$natural_order) { |
502 | - $orderby= !empty($_GET['orderby'])? $_GET['orderby']: "id"; |
|
503 | - $orderdir= !empty($_GET['orderdir'])? $_GET['orderdir']: "DESC"; |
|
504 | - $orderbyClause= !empty($orderby)? ' ORDER BY ' . $orderby . ' ' . $orderdir . ' ': ""; |
|
502 | + $orderby = !empty($_GET['orderby']) ? $_GET['orderby'] : "id"; |
|
503 | + $orderdir = !empty($_GET['orderdir']) ? $_GET['orderdir'] : "DESC"; |
|
504 | + $orderbyClause = !empty($orderby) ? ' ORDER BY '.$orderby.' '.$orderdir.' ' : ""; |
|
505 | 505 | } |
506 | 506 | return $orderbyClause; |
507 | 507 | } |
@@ -514,15 +514,15 @@ discard block |
||
514 | 514 | * @param $text The text for the link (e.g. table column header). |
515 | 515 | * @param $qs An optional query string to append to the order by link. |
516 | 516 | */ |
517 | - function prepareOrderByLink($key, $text, $qs='') { |
|
517 | + function prepareOrderByLink($key, $text, $qs = ''){ |
|
518 | 518 | global $modx; |
519 | 519 | if (!empty($_GET['orderdir'])) { |
520 | - $orderDir= strtolower($_GET['orderdir'])=='desc'? '&orderdir=asc': '&orderdir=desc'; |
|
520 | + $orderDir = strtolower($_GET['orderdir']) == 'desc' ? '&orderdir=asc' : '&orderdir=desc'; |
|
521 | 521 | } else { |
522 | - $orderDir= '&orderdir=asc'; |
|
522 | + $orderDir = '&orderdir=asc'; |
|
523 | 523 | } |
524 | 524 | if (!empty($qs)) { |
525 | - if (!strrpos($qs, '&')==strlen($qs)-1) $qs.= '&'; |
|
525 | + if (!strrpos($qs, '&') == strlen($qs) - 1) $qs .= '&'; |
|
526 | 526 | } |
527 | 527 | return '<a href="[~'.$modx->documentIdentifier.'~]?'.$qs.'orderby='.$key.$orderDir.'">'.$text.'</a>'; |
528 | 528 | } |
@@ -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 join( DIRECTORY_SEPARATOR, array( $this->BASE_CACHE, $filename ) ); |
|
169 | + function file_name($url){ |
|
170 | + $filename = md5($url); |
|
171 | + return join(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 | } |
@@ -22,35 +22,35 @@ |
||
22 | 22 | NOTE: http://www.w3.org/TR/NOTE-datetime |
23 | 23 | \*======================================================================*/ |
24 | 24 | |
25 | -function parse_w3cdtf ( $date_str ) { |
|
25 | +function parse_w3cdtf($date_str){ |
|
26 | 26 | |
27 | 27 | # regex to match wc3dtf |
28 | 28 | $pat = "/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(:(\d{2}))?(?:([-+])(\d{2}):?(\d{2})|(Z))?/"; |
29 | 29 | |
30 | - if ( preg_match( $pat, $date_str, $match ) ) { |
|
31 | - list( $year, $month, $day, $hours, $minutes, $seconds) = |
|
32 | - array( $match[1], $match[2], $match[3], $match[4], $match[5], $match[6]); |
|
30 | + if (preg_match($pat, $date_str, $match)) { |
|
31 | + list($year, $month, $day, $hours, $minutes, $seconds) = |
|
32 | + array($match[1], $match[2], $match[3], $match[4], $match[5], $match[6]); |
|
33 | 33 | |
34 | 34 | # calc epoch for current date assuming GMT |
35 | - $epoch = gmmktime( $hours, $minutes, $seconds, $month, $day, $year); |
|
35 | + $epoch = gmmktime($hours, $minutes, $seconds, $month, $day, $year); |
|
36 | 36 | |
37 | 37 | $offset = 0; |
38 | - if ( $match[10] == 'Z' ) { |
|
38 | + if ($match[10] == 'Z') { |
|
39 | 39 | # zulu time, aka GMT |
40 | 40 | } |
41 | 41 | else { |
42 | - list( $tz_mod, $tz_hour, $tz_min ) = |
|
43 | - array( $match[8], $match[9], $match[10]); |
|
42 | + list($tz_mod, $tz_hour, $tz_min) = |
|
43 | + array($match[8], $match[9], $match[10]); |
|
44 | 44 | |
45 | 45 | # zero out the variables |
46 | - if ( ! $tz_hour ) { $tz_hour = 0; } |
|
47 | - if ( ! $tz_min ) { $tz_min = 0; } |
|
46 | + if (!$tz_hour) { $tz_hour = 0; } |
|
47 | + if (!$tz_min) { $tz_min = 0; } |
|
48 | 48 | |
49 | - $offset_secs = (($tz_hour*60)+$tz_min)*60; |
|
49 | + $offset_secs = (($tz_hour * 60) + $tz_min) * 60; |
|
50 | 50 | |
51 | 51 | # is timezone ahead of GMT? then subtract offset |
52 | 52 | # |
53 | - if ( $tz_mod == '+' ) { |
|
53 | + if ($tz_mod == '+') { |
|
54 | 54 | $offset_secs = $offset_secs * -1; |
55 | 55 | } |
56 | 56 |
@@ -24,19 +24,19 @@ discard block |
||
24 | 24 | } |
25 | 25 | |
26 | 26 | if (!defined('MAGPIE_DIR')) { |
27 | - define('MAGPIE_DIR', dirname(__FILE__) . DIR_SEP); |
|
27 | + define('MAGPIE_DIR', dirname(__FILE__).DIR_SEP); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | if (!defined('MAGPIE_CACHE_DIR')) { |
31 | - define('MAGPIE_CACHE_DIR', MODX_BASE_PATH . 'assets/cache/rss'); |
|
31 | + define('MAGPIE_CACHE_DIR', MODX_BASE_PATH.'assets/cache/rss'); |
|
32 | 32 | } |
33 | 33 | |
34 | -require_once( MAGPIE_DIR . 'rss_parse.inc' ); |
|
35 | -require_once( MAGPIE_DIR . 'rss_cache.inc' ); |
|
34 | +require_once(MAGPIE_DIR.'rss_parse.inc'); |
|
35 | +require_once(MAGPIE_DIR.'rss_cache.inc'); |
|
36 | 36 | |
37 | 37 | // for including 3rd party libraries |
38 | -define('MAGPIE_EXTLIB', MAGPIE_DIR . 'extlib' . DIR_SEP); |
|
39 | -require_once( MAGPIE_EXTLIB . 'Snoopy.class.inc'); |
|
38 | +define('MAGPIE_EXTLIB', MAGPIE_DIR.'extlib'.DIR_SEP); |
|
39 | +require_once(MAGPIE_EXTLIB.'Snoopy.class.inc'); |
|
40 | 40 | |
41 | 41 | |
42 | 42 | /* |
@@ -89,21 +89,21 @@ discard block |
||
89 | 89 | |
90 | 90 | $MAGPIE_ERROR = ""; |
91 | 91 | |
92 | -function fetch_rss ($url) { |
|
92 | +function fetch_rss($url){ |
|
93 | 93 | // initialize constants |
94 | 94 | init(); |
95 | 95 | |
96 | - if ( !isset($url) ) { |
|
96 | + if (!isset($url)) { |
|
97 | 97 | error("fetch_rss called without a url"); |
98 | 98 | return false; |
99 | 99 | } |
100 | 100 | |
101 | 101 | // if cache is disabled |
102 | - if ( !MAGPIE_CACHE_ON ) { |
|
102 | + if (!MAGPIE_CACHE_ON) { |
|
103 | 103 | // fetch file, and parse it |
104 | - $resp = _fetch_remote_file( $url ); |
|
105 | - if ( is_success( $resp->status ) ) { |
|
106 | - return _response_to_rss( $resp ); |
|
104 | + $resp = _fetch_remote_file($url); |
|
105 | + if (is_success($resp->status)) { |
|
106 | + return _response_to_rss($resp); |
|
107 | 107 | } |
108 | 108 | else { |
109 | 109 | error("Failed to fetch $url and cache is off"); |
@@ -118,34 +118,34 @@ discard block |
||
118 | 118 | // 3. if cached obj fails freshness check, fetch remote |
119 | 119 | // 4. if remote fails, return stale object, or error |
120 | 120 | |
121 | - $cache = new RSSCache( MAGPIE_CACHE_DIR, MAGPIE_CACHE_AGE ); |
|
121 | + $cache = new RSSCache(MAGPIE_CACHE_DIR, MAGPIE_CACHE_AGE); |
|
122 | 122 | |
123 | 123 | if (MAGPIE_DEBUG and $cache->ERROR) { |
124 | 124 | debug($cache->ERROR, E_USER_WARNING); |
125 | 125 | } |
126 | 126 | |
127 | 127 | |
128 | - $cache_status = 0; // response of check_cache |
|
128 | + $cache_status = 0; // response of check_cache |
|
129 | 129 | $request_headers = array(); // HTTP headers to send with fetch |
130 | - $rss = 0; // parsed RSS object |
|
131 | - $errormsg = 0; // errors, if any |
|
130 | + $rss = 0; // parsed RSS object |
|
131 | + $errormsg = 0; // errors, if any |
|
132 | 132 | |
133 | 133 | // store parsed XML by desired output encoding |
134 | 134 | // as character munging happens at parse time |
135 | - $cache_key = $url . MAGPIE_OUTPUT_ENCODING; |
|
135 | + $cache_key = $url.MAGPIE_OUTPUT_ENCODING; |
|
136 | 136 | |
137 | 137 | if (!$cache->ERROR) { |
138 | 138 | // return cache HIT, MISS, or STALE |
139 | - $cache_status = $cache->check_cache( $cache_key); |
|
139 | + $cache_status = $cache->check_cache($cache_key); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | // if object cached, and cache is fresh, return cached obj |
143 | - if ( $cache_status == 'HIT' ) { |
|
144 | - $rss = $cache->get( $cache_key ); |
|
145 | - if ( isset($rss) and $rss ) { |
|
143 | + if ($cache_status == 'HIT') { |
|
144 | + $rss = $cache->get($cache_key); |
|
145 | + if (isset($rss) and $rss) { |
|
146 | 146 | // should be cache age |
147 | 147 | $rss->from_cache = 1; |
148 | - if ( MAGPIE_DEBUG > 1) { |
|
148 | + if (MAGPIE_DEBUG > 1) { |
|
149 | 149 | debug("MagpieRSS: Cache HIT", E_USER_NOTICE); |
150 | 150 | } |
151 | 151 | return $rss; |
@@ -155,50 +155,50 @@ discard block |
||
155 | 155 | // else attempt a conditional get |
156 | 156 | |
157 | 157 | // setup headers |
158 | - if ( $cache_status == 'STALE' ) { |
|
159 | - $rss = $cache->get( $cache_key ); |
|
160 | - if ( $rss and $rss->etag and $rss->last_modified ) { |
|
158 | + if ($cache_status == 'STALE') { |
|
159 | + $rss = $cache->get($cache_key); |
|
160 | + if ($rss and $rss->etag and $rss->last_modified) { |
|
161 | 161 | $request_headers['If-None-Match'] = $rss->etag; |
162 | 162 | $request_headers['If-Last-Modified'] = $rss->last_modified; |
163 | 163 | } |
164 | 164 | } |
165 | 165 | |
166 | - $resp = _fetch_remote_file( $url, $request_headers ); |
|
166 | + $resp = _fetch_remote_file($url, $request_headers); |
|
167 | 167 | |
168 | 168 | if (isset($resp) and $resp) { |
169 | - if ($resp->status == '304' ) { |
|
169 | + if ($resp->status == '304') { |
|
170 | 170 | // we have the most current copy |
171 | - if ( MAGPIE_DEBUG > 1) { |
|
171 | + if (MAGPIE_DEBUG > 1) { |
|
172 | 172 | debug("Got 304 for $url"); |
173 | 173 | } |
174 | 174 | // reset cache on 304 (at minutillo insistent prodding) |
175 | 175 | $cache->set($cache_key, $rss); |
176 | 176 | return $rss; |
177 | 177 | } |
178 | - elseif ( is_success( $resp->status ) ) { |
|
179 | - $rss = _response_to_rss( $resp ); |
|
180 | - if ( $rss ) { |
|
178 | + elseif (is_success($resp->status)) { |
|
179 | + $rss = _response_to_rss($resp); |
|
180 | + if ($rss) { |
|
181 | 181 | if (MAGPIE_DEBUG > 1) { |
182 | 182 | debug("Fetch successful"); |
183 | 183 | } |
184 | 184 | // add object to cache |
185 | - $cache->set( $cache_key, $rss ); |
|
185 | + $cache->set($cache_key, $rss); |
|
186 | 186 | return $rss; |
187 | 187 | } |
188 | 188 | } |
189 | 189 | else { |
190 | 190 | $errormsg = "Failed to fetch $url "; |
191 | - if ( $resp->status == '-100' ) { |
|
192 | - $errormsg .= "(Request timed out after " . MAGPIE_FETCH_TIME_OUT . " seconds)"; |
|
191 | + if ($resp->status == '-100') { |
|
192 | + $errormsg .= "(Request timed out after ".MAGPIE_FETCH_TIME_OUT." seconds)"; |
|
193 | 193 | } |
194 | - elseif ( $resp->error ) { |
|
194 | + elseif ($resp->error) { |
|
195 | 195 | # compensate for Snoopy's annoying habbit to tacking |
196 | 196 | # on '\n' |
197 | 197 | $http_error = substr($resp->error, 0, -2); |
198 | 198 | $errormsg .= "(HTTP Error: $http_error)"; |
199 | 199 | } |
200 | 200 | else { |
201 | - $errormsg .= "(HTTP Response: " . $resp->response_code .')'; |
|
201 | + $errormsg .= "(HTTP Response: ".$resp->response_code.')'; |
|
202 | 202 | } |
203 | 203 | } |
204 | 204 | } |
@@ -210,14 +210,14 @@ discard block |
||
210 | 210 | |
211 | 211 | // attempt to return cached object |
212 | 212 | if ($rss) { |
213 | - if ( MAGPIE_DEBUG ) { |
|
213 | + if (MAGPIE_DEBUG) { |
|
214 | 214 | debug("Returning STALE object for $url"); |
215 | 215 | } |
216 | 216 | return $rss; |
217 | 217 | } |
218 | 218 | |
219 | 219 | // else we totally failed |
220 | - error( $errormsg ); |
|
220 | + error($errormsg); |
|
221 | 221 | |
222 | 222 | return false; |
223 | 223 | |
@@ -229,21 +229,21 @@ discard block |
||
229 | 229 | Purpose: set MAGPIE_ERROR, and trigger error |
230 | 230 | \*=======================================================================*/ |
231 | 231 | |
232 | -function error ($errormsg, $lvl=E_USER_WARNING) { |
|
232 | +function error($errormsg, $lvl = E_USER_WARNING){ |
|
233 | 233 | global $MAGPIE_ERROR; |
234 | 234 | |
235 | 235 | // append PHP's error message if track_errors enabled |
236 | - if ( isset($php_errormsg) ) { |
|
236 | + if (isset($php_errormsg)) { |
|
237 | 237 | $errormsg .= " ($php_errormsg)"; |
238 | 238 | } |
239 | - if ( $errormsg ) { |
|
239 | + if ($errormsg) { |
|
240 | 240 | $errormsg = "MagpieRSS: $errormsg"; |
241 | 241 | $MAGPIE_ERROR = $errormsg; |
242 | - trigger_error( $errormsg, $lvl); |
|
242 | + trigger_error($errormsg, $lvl); |
|
243 | 243 | } |
244 | 244 | } |
245 | 245 | |
246 | -function debug ($debugmsg, $lvl=E_USER_NOTICE) { |
|
246 | +function debug($debugmsg, $lvl = E_USER_NOTICE){ |
|
247 | 247 | trigger_error("MagpieRSS [debug] $debugmsg", $lvl); |
248 | 248 | } |
249 | 249 | |
@@ -251,10 +251,10 @@ discard block |
||
251 | 251 | Function: magpie_error |
252 | 252 | Purpose: accessor for the magpie error variable |
253 | 253 | \*=======================================================================*/ |
254 | -function magpie_error ($errormsg="") { |
|
254 | +function magpie_error($errormsg = ""){ |
|
255 | 255 | global $MAGPIE_ERROR; |
256 | 256 | |
257 | - if ( isset($errormsg) and $errormsg ) { |
|
257 | + if (isset($errormsg) and $errormsg) { |
|
258 | 258 | $MAGPIE_ERROR = $errormsg; |
259 | 259 | } |
260 | 260 | |
@@ -268,13 +268,13 @@ discard block |
||
268 | 268 | headers to send along with the request (optional) |
269 | 269 | Output: an HTTP response object (see Snoopy.class.inc) |
270 | 270 | \*=======================================================================*/ |
271 | -function _fetch_remote_file ($url, $headers = "" ) { |
|
271 | +function _fetch_remote_file($url, $headers = ""){ |
|
272 | 272 | // Snoopy is an HTTP client in PHP |
273 | 273 | $client = new Snoopy(); |
274 | 274 | $client->agent = MAGPIE_USER_AGENT; |
275 | 275 | $client->read_timeout = MAGPIE_FETCH_TIME_OUT; |
276 | 276 | $client->use_gzip = MAGPIE_USE_GZIP; |
277 | - if (is_array($headers) ) { |
|
277 | + if (is_array($headers)) { |
|
278 | 278 | $client->rawheaders = $headers; |
279 | 279 | } |
280 | 280 | |
@@ -289,14 +289,14 @@ discard block |
||
289 | 289 | Input: an HTTP response object (see Snoopy) |
290 | 290 | Output: parsed RSS object (see rss_parse) |
291 | 291 | \*=======================================================================*/ |
292 | -function _response_to_rss ($resp) { |
|
293 | - $rss = new MagpieRSS( $resp->results, MAGPIE_OUTPUT_ENCODING, MAGPIE_INPUT_ENCODING, MAGPIE_DETECT_ENCODING ); |
|
292 | +function _response_to_rss($resp){ |
|
293 | + $rss = new MagpieRSS($resp->results, MAGPIE_OUTPUT_ENCODING, MAGPIE_INPUT_ENCODING, MAGPIE_DETECT_ENCODING); |
|
294 | 294 | |
295 | 295 | // if RSS parsed successfully |
296 | - if ( $rss and !$rss->ERROR) { |
|
296 | + if ($rss and !$rss->ERROR) { |
|
297 | 297 | |
298 | 298 | // find Etag, and Last-Modified |
299 | - foreach($resp->headers as $h) { |
|
299 | + foreach ($resp->headers as $h) { |
|
300 | 300 | // 2003-03-02 - Nicola Asuni (www.tecnick.com) - fixed bug "Undefined offset: 1" |
301 | 301 | if (strpos($h, ": ")) { |
302 | 302 | list($field, $val) = explode(": ", $h, 2); |
@@ -306,11 +306,11 @@ discard block |
||
306 | 306 | $val = ""; |
307 | 307 | } |
308 | 308 | |
309 | - if ( $field == 'ETag' ) { |
|
309 | + if ($field == 'ETag') { |
|
310 | 310 | $rss->etag = $val; |
311 | 311 | } |
312 | 312 | |
313 | - if ( $field == 'Last-Modified' ) { |
|
313 | + if ($field == 'Last-Modified') { |
|
314 | 314 | $rss->last_modified = $val; |
315 | 315 | } |
316 | 316 | } |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | $errormsg = "Failed to parse RSS file."; |
322 | 322 | |
323 | 323 | if ($rss) { |
324 | - $errormsg .= " (" . $rss->ERROR . ")"; |
|
324 | + $errormsg .= " (".$rss->ERROR.")"; |
|
325 | 325 | } |
326 | 326 | error($errormsg); |
327 | 327 | |
@@ -334,67 +334,67 @@ discard block |
||
334 | 334 | Purpose: setup constants with default values |
335 | 335 | check for user overrides |
336 | 336 | \*=======================================================================*/ |
337 | -function init () { |
|
338 | - if ( defined('MAGPIE_INITALIZED') ) { |
|
337 | +function init(){ |
|
338 | + if (defined('MAGPIE_INITALIZED')) { |
|
339 | 339 | return; |
340 | 340 | } |
341 | 341 | else { |
342 | 342 | define('MAGPIE_INITALIZED', true); |
343 | 343 | } |
344 | 344 | |
345 | - if ( !defined('MAGPIE_CACHE_ON') ) { |
|
345 | + if (!defined('MAGPIE_CACHE_ON')) { |
|
346 | 346 | define('MAGPIE_CACHE_ON', true); |
347 | 347 | } |
348 | 348 | |
349 | - if ( !defined('MAGPIE_CACHE_DIR') ) { |
|
349 | + if (!defined('MAGPIE_CACHE_DIR')) { |
|
350 | 350 | define('MAGPIE_CACHE_DIR', './cache'); |
351 | 351 | } |
352 | 352 | |
353 | - if ( !defined('MAGPIE_CACHE_AGE') ) { |
|
354 | - define('MAGPIE_CACHE_AGE', 60*60); // one hour |
|
353 | + if (!defined('MAGPIE_CACHE_AGE')) { |
|
354 | + define('MAGPIE_CACHE_AGE', 60 * 60); // one hour |
|
355 | 355 | } |
356 | 356 | |
357 | - if ( !defined('MAGPIE_CACHE_FRESH_ONLY') ) { |
|
357 | + if (!defined('MAGPIE_CACHE_FRESH_ONLY')) { |
|
358 | 358 | define('MAGPIE_CACHE_FRESH_ONLY', false); |
359 | 359 | } |
360 | 360 | |
361 | - if ( !defined('MAGPIE_OUTPUT_ENCODING') ) { |
|
361 | + if (!defined('MAGPIE_OUTPUT_ENCODING')) { |
|
362 | 362 | global $modx_manager_charset; |
363 | - if(empty($modx_manager_charset)) $modx_manager_charset = 'ISO-8859-1'; |
|
363 | + if (empty($modx_manager_charset)) $modx_manager_charset = 'ISO-8859-1'; |
|
364 | 364 | define('MAGPIE_OUTPUT_ENCODING', $modx_manager_charset); |
365 | 365 | } |
366 | 366 | |
367 | - if ( !defined('MAGPIE_INPUT_ENCODING') ) { |
|
367 | + if (!defined('MAGPIE_INPUT_ENCODING')) { |
|
368 | 368 | define('MAGPIE_INPUT_ENCODING', null); |
369 | 369 | } |
370 | 370 | |
371 | - if ( !defined('MAGPIE_DETECT_ENCODING') ) { |
|
371 | + if (!defined('MAGPIE_DETECT_ENCODING')) { |
|
372 | 372 | define('MAGPIE_DETECT_ENCODING', true); |
373 | 373 | } |
374 | 374 | |
375 | - if ( !defined('MAGPIE_DEBUG') ) { |
|
375 | + if (!defined('MAGPIE_DEBUG')) { |
|
376 | 376 | define('MAGPIE_DEBUG', 0); |
377 | 377 | } |
378 | 378 | |
379 | - if ( !defined('MAGPIE_USER_AGENT') ) { |
|
380 | - $ua = 'MagpieRSS/'. MAGPIE_VERSION . ' (+http://magpierss.sf.net'; |
|
379 | + if (!defined('MAGPIE_USER_AGENT')) { |
|
380 | + $ua = 'MagpieRSS/'.MAGPIE_VERSION.' (+http://magpierss.sf.net'; |
|
381 | 381 | |
382 | - if ( MAGPIE_CACHE_ON ) { |
|
383 | - $ua = $ua . ')'; |
|
382 | + if (MAGPIE_CACHE_ON) { |
|
383 | + $ua = $ua.')'; |
|
384 | 384 | } |
385 | 385 | else { |
386 | - $ua = $ua . '; No cache)'; |
|
386 | + $ua = $ua.'; No cache)'; |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | define('MAGPIE_USER_AGENT', $ua); |
390 | 390 | } |
391 | 391 | |
392 | - if ( !defined('MAGPIE_FETCH_TIME_OUT') ) { |
|
392 | + if (!defined('MAGPIE_FETCH_TIME_OUT')) { |
|
393 | 393 | define('MAGPIE_FETCH_TIME_OUT', 5); // 5 second timeout |
394 | 394 | } |
395 | 395 | |
396 | 396 | // use gzip encoding to fetch rss files if supported? |
397 | - if ( !defined('MAGPIE_USE_GZIP') ) { |
|
397 | + if (!defined('MAGPIE_USE_GZIP')) { |
|
398 | 398 | define('MAGPIE_USE_GZIP', true); |
399 | 399 | } |
400 | 400 | } |
@@ -417,7 +417,7 @@ discard block |
||
417 | 417 | Function: is_info |
418 | 418 | Purpose: return true if Informational status code |
419 | 419 | \*=======================================================================*/ |
420 | -function is_info ($sc) { |
|
420 | +function is_info($sc){ |
|
421 | 421 | return $sc >= 100 && $sc < 200; |
422 | 422 | } |
423 | 423 | |
@@ -425,7 +425,7 @@ discard block |
||
425 | 425 | Function: is_success |
426 | 426 | Purpose: return true if Successful status code |
427 | 427 | \*=======================================================================*/ |
428 | -function is_success ($sc) { |
|
428 | +function is_success($sc){ |
|
429 | 429 | return $sc >= 200 && $sc < 300; |
430 | 430 | } |
431 | 431 | |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | Function: is_redirect |
434 | 434 | Purpose: return true if Redirection status code |
435 | 435 | \*=======================================================================*/ |
436 | -function is_redirect ($sc) { |
|
436 | +function is_redirect($sc){ |
|
437 | 437 | return $sc >= 300 && $sc < 400; |
438 | 438 | } |
439 | 439 | |
@@ -441,7 +441,7 @@ discard block |
||
441 | 441 | Function: is_error |
442 | 442 | Purpose: return true if Error status code |
443 | 443 | \*=======================================================================*/ |
444 | -function is_error ($sc) { |
|
444 | +function is_error($sc){ |
|
445 | 445 | return $sc >= 400 && $sc < 600; |
446 | 446 | } |
447 | 447 | |
@@ -449,7 +449,7 @@ discard block |
||
449 | 449 | Function: is_client_error |
450 | 450 | Purpose: return true if Error status code, and its a client error |
451 | 451 | \*=======================================================================*/ |
452 | -function is_client_error ($sc) { |
|
452 | +function is_client_error($sc){ |
|
453 | 453 | return $sc >= 400 && $sc < 500; |
454 | 454 | } |
455 | 455 | |
@@ -457,6 +457,6 @@ discard block |
||
457 | 457 | Function: is_client_error |
458 | 458 | Purpose: return true if Error status code, and its a server error |
459 | 459 | \*=======================================================================*/ |
460 | -function is_server_error ($sc) { |
|
460 | +function is_server_error($sc){ |
|
461 | 461 | return $sc >= 500 && $sc < 600; |
462 | 462 | } |