@@ -15,6 +15,8 @@ discard block |
||
15 | 15 | |
16 | 16 | /** |
17 | 17 | * @note Automatically normalizes scheme and port |
18 | + * @param string|null $host |
|
19 | + * @param integer|null $port |
|
18 | 20 | */ |
19 | 21 | public function __construct($scheme, $userinfo, $host, $port, $path, $query, $fragment) { |
20 | 22 | $this->scheme = is_null($scheme) || ctype_lower($scheme) ? $scheme : strtolower($scheme); |
@@ -58,7 +60,7 @@ discard block |
||
58 | 60 | * this URI in order to get it into a compliant form. |
59 | 61 | * @param $config Instance of HTMLPurifier_Config |
60 | 62 | * @param $context Instance of HTMLPurifier_Context |
61 | - * @return True if validation/filtering succeeds, false if failure |
|
63 | + * @return boolean if validation/filtering succeeds, false if failure |
|
62 | 64 | */ |
63 | 65 | public function validate($config, $context) { |
64 | 66 |
@@ -11,231 +11,231 @@ |
||
11 | 11 | class HTMLPurifier_URI |
12 | 12 | { |
13 | 13 | |
14 | - public $scheme, $userinfo, $host, $port, $path, $query, $fragment; |
|
15 | - |
|
16 | - /** |
|
17 | - * @note Automatically normalizes scheme and port |
|
18 | - */ |
|
19 | - public function __construct($scheme, $userinfo, $host, $port, $path, $query, $fragment) { |
|
20 | - $this->scheme = is_null($scheme) || ctype_lower($scheme) ? $scheme : strtolower($scheme); |
|
21 | - $this->userinfo = $userinfo; |
|
22 | - $this->host = $host; |
|
23 | - $this->port = is_null($port) ? $port : (int) $port; |
|
24 | - $this->path = $path; |
|
25 | - $this->query = $query; |
|
26 | - $this->fragment = $fragment; |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * Retrieves a scheme object corresponding to the URI's scheme/default |
|
31 | - * @param $config Instance of HTMLPurifier_Config |
|
32 | - * @param $context Instance of HTMLPurifier_Context |
|
33 | - * @return Scheme object appropriate for validating this URI |
|
34 | - */ |
|
35 | - public function getSchemeObj($config, $context) { |
|
36 | - $registry = HTMLPurifier_URISchemeRegistry::instance(); |
|
37 | - if ($this->scheme !== null) { |
|
38 | - $scheme_obj = $registry->getScheme($this->scheme, $config, $context); |
|
39 | - if (!$scheme_obj) return false; // invalid scheme, clean it out |
|
40 | - } else { |
|
41 | - // no scheme: retrieve the default one |
|
42 | - $def = $config->getDefinition('URI'); |
|
43 | - $scheme_obj = $def->getDefaultScheme($config, $context); |
|
44 | - if (!$scheme_obj) { |
|
45 | - // something funky happened to the default scheme object |
|
46 | - trigger_error( |
|
47 | - 'Default scheme object "' . $def->defaultScheme . '" was not readable', |
|
48 | - E_USER_WARNING |
|
49 | - ); |
|
50 | - return false; |
|
51 | - } |
|
52 | - } |
|
53 | - return $scheme_obj; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Generic validation method applicable for all schemes. May modify |
|
58 | - * this URI in order to get it into a compliant form. |
|
59 | - * @param $config Instance of HTMLPurifier_Config |
|
60 | - * @param $context Instance of HTMLPurifier_Context |
|
61 | - * @return True if validation/filtering succeeds, false if failure |
|
62 | - */ |
|
63 | - public function validate($config, $context) { |
|
64 | - |
|
65 | - // ABNF definitions from RFC 3986 |
|
66 | - $chars_sub_delims = '!$&\'()*+,;='; |
|
67 | - $chars_gen_delims = ':/?#[]@'; |
|
68 | - $chars_pchar = $chars_sub_delims . ':@'; |
|
69 | - |
|
70 | - // validate host |
|
71 | - if (!is_null($this->host)) { |
|
72 | - $host_def = new HTMLPurifier_AttrDef_URI_Host(); |
|
73 | - $this->host = $host_def->validate($this->host, $config, $context); |
|
74 | - if ($this->host === false) $this->host = null; |
|
75 | - } |
|
76 | - |
|
77 | - // validate scheme |
|
78 | - // NOTE: It's not appropriate to check whether or not this |
|
79 | - // scheme is in our registry, since a URIFilter may convert a |
|
80 | - // URI that we don't allow into one we do. So instead, we just |
|
81 | - // check if the scheme can be dropped because there is no host |
|
82 | - // and it is our default scheme. |
|
83 | - if (!is_null($this->scheme) && is_null($this->host) || $this->host === '') { |
|
84 | - // support for relative paths is pretty abysmal when the |
|
85 | - // scheme is present, so axe it when possible |
|
86 | - $def = $config->getDefinition('URI'); |
|
87 | - if ($def->defaultScheme === $this->scheme) { |
|
88 | - $this->scheme = null; |
|
89 | - } |
|
90 | - } |
|
91 | - |
|
92 | - // validate username |
|
93 | - if (!is_null($this->userinfo)) { |
|
94 | - $encoder = new HTMLPurifier_PercentEncoder($chars_sub_delims . ':'); |
|
95 | - $this->userinfo = $encoder->encode($this->userinfo); |
|
96 | - } |
|
97 | - |
|
98 | - // validate port |
|
99 | - if (!is_null($this->port)) { |
|
100 | - if ($this->port < 1 || $this->port > 65535) $this->port = null; |
|
101 | - } |
|
102 | - |
|
103 | - // validate path |
|
104 | - $path_parts = array(); |
|
105 | - $segments_encoder = new HTMLPurifier_PercentEncoder($chars_pchar . '/'); |
|
106 | - if (!is_null($this->host)) { // this catches $this->host === '' |
|
107 | - // path-abempty (hier and relative) |
|
108 | - // http://www.example.com/my/path |
|
109 | - // //www.example.com/my/path (looks odd, but works, and |
|
110 | - // recognized by most browsers) |
|
111 | - // (this set is valid or invalid on a scheme by scheme |
|
112 | - // basis, so we'll deal with it later) |
|
113 | - // file:///my/path |
|
114 | - // ///my/path |
|
115 | - $this->path = $segments_encoder->encode($this->path); |
|
116 | - } elseif ($this->path !== '') { |
|
117 | - if ($this->path[0] === '/') { |
|
118 | - // path-absolute (hier and relative) |
|
119 | - // http:/my/path |
|
120 | - // /my/path |
|
121 | - if (strlen($this->path) >= 2 && $this->path[1] === '/') { |
|
122 | - // This could happen if both the host gets stripped |
|
123 | - // out |
|
124 | - // http://my/path |
|
125 | - // //my/path |
|
126 | - $this->path = ''; |
|
127 | - } else { |
|
128 | - $this->path = $segments_encoder->encode($this->path); |
|
129 | - } |
|
130 | - } elseif (!is_null($this->scheme)) { |
|
131 | - // path-rootless (hier) |
|
132 | - // http:my/path |
|
133 | - // Short circuit evaluation means we don't need to check nz |
|
134 | - $this->path = $segments_encoder->encode($this->path); |
|
135 | - } else { |
|
136 | - // path-noscheme (relative) |
|
137 | - // my/path |
|
138 | - // (once again, not checking nz) |
|
139 | - $segment_nc_encoder = new HTMLPurifier_PercentEncoder($chars_sub_delims . '@'); |
|
140 | - $c = strpos($this->path, '/'); |
|
141 | - if ($c !== false) { |
|
142 | - $this->path = |
|
143 | - $segment_nc_encoder->encode(substr($this->path, 0, $c)) . |
|
144 | - $segments_encoder->encode(substr($this->path, $c)); |
|
145 | - } else { |
|
146 | - $this->path = $segment_nc_encoder->encode($this->path); |
|
147 | - } |
|
148 | - } |
|
149 | - } else { |
|
150 | - // path-empty (hier and relative) |
|
151 | - $this->path = ''; // just to be safe |
|
152 | - } |
|
153 | - |
|
154 | - // qf = query and fragment |
|
155 | - $qf_encoder = new HTMLPurifier_PercentEncoder($chars_pchar . '/?'); |
|
156 | - |
|
157 | - if (!is_null($this->query)) { |
|
158 | - $this->query = $qf_encoder->encode($this->query); |
|
159 | - } |
|
160 | - |
|
161 | - if (!is_null($this->fragment)) { |
|
162 | - $this->fragment = $qf_encoder->encode($this->fragment); |
|
163 | - } |
|
164 | - |
|
165 | - return true; |
|
166 | - |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Convert URI back to string |
|
171 | - * @return String URI appropriate for output |
|
172 | - */ |
|
173 | - public function toString() { |
|
174 | - // reconstruct authority |
|
175 | - $authority = null; |
|
176 | - // there is a rendering difference between a null authority |
|
177 | - // (http:foo-bar) and an empty string authority |
|
178 | - // (http:///foo-bar). |
|
179 | - if (!is_null($this->host)) { |
|
180 | - $authority = ''; |
|
181 | - if(!is_null($this->userinfo)) $authority .= $this->userinfo . '@'; |
|
182 | - $authority .= $this->host; |
|
183 | - if(!is_null($this->port)) $authority .= ':' . $this->port; |
|
184 | - } |
|
185 | - |
|
186 | - // Reconstruct the result |
|
187 | - // One might wonder about parsing quirks from browsers after |
|
188 | - // this reconstruction. Unfortunately, parsing behavior depends |
|
189 | - // on what *scheme* was employed (file:///foo is handled *very* |
|
190 | - // differently than http:///foo), so unfortunately we have to |
|
191 | - // defer to the schemes to do the right thing. |
|
192 | - $result = ''; |
|
193 | - if (!is_null($this->scheme)) $result .= $this->scheme . ':'; |
|
194 | - if (!is_null($authority)) $result .= '//' . $authority; |
|
195 | - $result .= $this->path; |
|
196 | - if (!is_null($this->query)) $result .= '?' . $this->query; |
|
197 | - if (!is_null($this->fragment)) $result .= '#' . $this->fragment; |
|
198 | - |
|
199 | - return $result; |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Returns true if this URL might be considered a 'local' URL given |
|
204 | - * the current context. This is true when the host is null, or |
|
205 | - * when it matches the host supplied to the configuration. |
|
206 | - * |
|
207 | - * Note that this does not do any scheme checking, so it is mostly |
|
208 | - * only appropriate for metadata that doesn't care about protocol |
|
209 | - * security. isBenign is probably what you actually want. |
|
210 | - */ |
|
211 | - public function isLocal($config, $context) { |
|
212 | - if ($this->host === null) return true; |
|
213 | - $uri_def = $config->getDefinition('URI'); |
|
214 | - if ($uri_def->host === $this->host) return true; |
|
215 | - return false; |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * Returns true if this URL should be considered a 'benign' URL, |
|
220 | - * that is: |
|
221 | - * |
|
222 | - * - It is a local URL (isLocal), and |
|
223 | - * - It has a equal or better level of security |
|
224 | - */ |
|
225 | - public function isBenign($config, $context) { |
|
226 | - if (!$this->isLocal($config, $context)) return false; |
|
227 | - |
|
228 | - $scheme_obj = $this->getSchemeObj($config, $context); |
|
229 | - if (!$scheme_obj) return false; // conservative approach |
|
230 | - |
|
231 | - $current_scheme_obj = $config->getDefinition('URI')->getDefaultScheme($config, $context); |
|
232 | - if ($current_scheme_obj->secure) { |
|
233 | - if (!$scheme_obj->secure) { |
|
234 | - return false; |
|
235 | - } |
|
236 | - } |
|
237 | - return true; |
|
238 | - } |
|
14 | + public $scheme, $userinfo, $host, $port, $path, $query, $fragment; |
|
15 | + |
|
16 | + /** |
|
17 | + * @note Automatically normalizes scheme and port |
|
18 | + */ |
|
19 | + public function __construct($scheme, $userinfo, $host, $port, $path, $query, $fragment) { |
|
20 | + $this->scheme = is_null($scheme) || ctype_lower($scheme) ? $scheme : strtolower($scheme); |
|
21 | + $this->userinfo = $userinfo; |
|
22 | + $this->host = $host; |
|
23 | + $this->port = is_null($port) ? $port : (int) $port; |
|
24 | + $this->path = $path; |
|
25 | + $this->query = $query; |
|
26 | + $this->fragment = $fragment; |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * Retrieves a scheme object corresponding to the URI's scheme/default |
|
31 | + * @param $config Instance of HTMLPurifier_Config |
|
32 | + * @param $context Instance of HTMLPurifier_Context |
|
33 | + * @return Scheme object appropriate for validating this URI |
|
34 | + */ |
|
35 | + public function getSchemeObj($config, $context) { |
|
36 | + $registry = HTMLPurifier_URISchemeRegistry::instance(); |
|
37 | + if ($this->scheme !== null) { |
|
38 | + $scheme_obj = $registry->getScheme($this->scheme, $config, $context); |
|
39 | + if (!$scheme_obj) return false; // invalid scheme, clean it out |
|
40 | + } else { |
|
41 | + // no scheme: retrieve the default one |
|
42 | + $def = $config->getDefinition('URI'); |
|
43 | + $scheme_obj = $def->getDefaultScheme($config, $context); |
|
44 | + if (!$scheme_obj) { |
|
45 | + // something funky happened to the default scheme object |
|
46 | + trigger_error( |
|
47 | + 'Default scheme object "' . $def->defaultScheme . '" was not readable', |
|
48 | + E_USER_WARNING |
|
49 | + ); |
|
50 | + return false; |
|
51 | + } |
|
52 | + } |
|
53 | + return $scheme_obj; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Generic validation method applicable for all schemes. May modify |
|
58 | + * this URI in order to get it into a compliant form. |
|
59 | + * @param $config Instance of HTMLPurifier_Config |
|
60 | + * @param $context Instance of HTMLPurifier_Context |
|
61 | + * @return True if validation/filtering succeeds, false if failure |
|
62 | + */ |
|
63 | + public function validate($config, $context) { |
|
64 | + |
|
65 | + // ABNF definitions from RFC 3986 |
|
66 | + $chars_sub_delims = '!$&\'()*+,;='; |
|
67 | + $chars_gen_delims = ':/?#[]@'; |
|
68 | + $chars_pchar = $chars_sub_delims . ':@'; |
|
69 | + |
|
70 | + // validate host |
|
71 | + if (!is_null($this->host)) { |
|
72 | + $host_def = new HTMLPurifier_AttrDef_URI_Host(); |
|
73 | + $this->host = $host_def->validate($this->host, $config, $context); |
|
74 | + if ($this->host === false) $this->host = null; |
|
75 | + } |
|
76 | + |
|
77 | + // validate scheme |
|
78 | + // NOTE: It's not appropriate to check whether or not this |
|
79 | + // scheme is in our registry, since a URIFilter may convert a |
|
80 | + // URI that we don't allow into one we do. So instead, we just |
|
81 | + // check if the scheme can be dropped because there is no host |
|
82 | + // and it is our default scheme. |
|
83 | + if (!is_null($this->scheme) && is_null($this->host) || $this->host === '') { |
|
84 | + // support for relative paths is pretty abysmal when the |
|
85 | + // scheme is present, so axe it when possible |
|
86 | + $def = $config->getDefinition('URI'); |
|
87 | + if ($def->defaultScheme === $this->scheme) { |
|
88 | + $this->scheme = null; |
|
89 | + } |
|
90 | + } |
|
91 | + |
|
92 | + // validate username |
|
93 | + if (!is_null($this->userinfo)) { |
|
94 | + $encoder = new HTMLPurifier_PercentEncoder($chars_sub_delims . ':'); |
|
95 | + $this->userinfo = $encoder->encode($this->userinfo); |
|
96 | + } |
|
97 | + |
|
98 | + // validate port |
|
99 | + if (!is_null($this->port)) { |
|
100 | + if ($this->port < 1 || $this->port > 65535) $this->port = null; |
|
101 | + } |
|
102 | + |
|
103 | + // validate path |
|
104 | + $path_parts = array(); |
|
105 | + $segments_encoder = new HTMLPurifier_PercentEncoder($chars_pchar . '/'); |
|
106 | + if (!is_null($this->host)) { // this catches $this->host === '' |
|
107 | + // path-abempty (hier and relative) |
|
108 | + // http://www.example.com/my/path |
|
109 | + // //www.example.com/my/path (looks odd, but works, and |
|
110 | + // recognized by most browsers) |
|
111 | + // (this set is valid or invalid on a scheme by scheme |
|
112 | + // basis, so we'll deal with it later) |
|
113 | + // file:///my/path |
|
114 | + // ///my/path |
|
115 | + $this->path = $segments_encoder->encode($this->path); |
|
116 | + } elseif ($this->path !== '') { |
|
117 | + if ($this->path[0] === '/') { |
|
118 | + // path-absolute (hier and relative) |
|
119 | + // http:/my/path |
|
120 | + // /my/path |
|
121 | + if (strlen($this->path) >= 2 && $this->path[1] === '/') { |
|
122 | + // This could happen if both the host gets stripped |
|
123 | + // out |
|
124 | + // http://my/path |
|
125 | + // //my/path |
|
126 | + $this->path = ''; |
|
127 | + } else { |
|
128 | + $this->path = $segments_encoder->encode($this->path); |
|
129 | + } |
|
130 | + } elseif (!is_null($this->scheme)) { |
|
131 | + // path-rootless (hier) |
|
132 | + // http:my/path |
|
133 | + // Short circuit evaluation means we don't need to check nz |
|
134 | + $this->path = $segments_encoder->encode($this->path); |
|
135 | + } else { |
|
136 | + // path-noscheme (relative) |
|
137 | + // my/path |
|
138 | + // (once again, not checking nz) |
|
139 | + $segment_nc_encoder = new HTMLPurifier_PercentEncoder($chars_sub_delims . '@'); |
|
140 | + $c = strpos($this->path, '/'); |
|
141 | + if ($c !== false) { |
|
142 | + $this->path = |
|
143 | + $segment_nc_encoder->encode(substr($this->path, 0, $c)) . |
|
144 | + $segments_encoder->encode(substr($this->path, $c)); |
|
145 | + } else { |
|
146 | + $this->path = $segment_nc_encoder->encode($this->path); |
|
147 | + } |
|
148 | + } |
|
149 | + } else { |
|
150 | + // path-empty (hier and relative) |
|
151 | + $this->path = ''; // just to be safe |
|
152 | + } |
|
153 | + |
|
154 | + // qf = query and fragment |
|
155 | + $qf_encoder = new HTMLPurifier_PercentEncoder($chars_pchar . '/?'); |
|
156 | + |
|
157 | + if (!is_null($this->query)) { |
|
158 | + $this->query = $qf_encoder->encode($this->query); |
|
159 | + } |
|
160 | + |
|
161 | + if (!is_null($this->fragment)) { |
|
162 | + $this->fragment = $qf_encoder->encode($this->fragment); |
|
163 | + } |
|
164 | + |
|
165 | + return true; |
|
166 | + |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Convert URI back to string |
|
171 | + * @return String URI appropriate for output |
|
172 | + */ |
|
173 | + public function toString() { |
|
174 | + // reconstruct authority |
|
175 | + $authority = null; |
|
176 | + // there is a rendering difference between a null authority |
|
177 | + // (http:foo-bar) and an empty string authority |
|
178 | + // (http:///foo-bar). |
|
179 | + if (!is_null($this->host)) { |
|
180 | + $authority = ''; |
|
181 | + if(!is_null($this->userinfo)) $authority .= $this->userinfo . '@'; |
|
182 | + $authority .= $this->host; |
|
183 | + if(!is_null($this->port)) $authority .= ':' . $this->port; |
|
184 | + } |
|
185 | + |
|
186 | + // Reconstruct the result |
|
187 | + // One might wonder about parsing quirks from browsers after |
|
188 | + // this reconstruction. Unfortunately, parsing behavior depends |
|
189 | + // on what *scheme* was employed (file:///foo is handled *very* |
|
190 | + // differently than http:///foo), so unfortunately we have to |
|
191 | + // defer to the schemes to do the right thing. |
|
192 | + $result = ''; |
|
193 | + if (!is_null($this->scheme)) $result .= $this->scheme . ':'; |
|
194 | + if (!is_null($authority)) $result .= '//' . $authority; |
|
195 | + $result .= $this->path; |
|
196 | + if (!is_null($this->query)) $result .= '?' . $this->query; |
|
197 | + if (!is_null($this->fragment)) $result .= '#' . $this->fragment; |
|
198 | + |
|
199 | + return $result; |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Returns true if this URL might be considered a 'local' URL given |
|
204 | + * the current context. This is true when the host is null, or |
|
205 | + * when it matches the host supplied to the configuration. |
|
206 | + * |
|
207 | + * Note that this does not do any scheme checking, so it is mostly |
|
208 | + * only appropriate for metadata that doesn't care about protocol |
|
209 | + * security. isBenign is probably what you actually want. |
|
210 | + */ |
|
211 | + public function isLocal($config, $context) { |
|
212 | + if ($this->host === null) return true; |
|
213 | + $uri_def = $config->getDefinition('URI'); |
|
214 | + if ($uri_def->host === $this->host) return true; |
|
215 | + return false; |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * Returns true if this URL should be considered a 'benign' URL, |
|
220 | + * that is: |
|
221 | + * |
|
222 | + * - It is a local URL (isLocal), and |
|
223 | + * - It has a equal or better level of security |
|
224 | + */ |
|
225 | + public function isBenign($config, $context) { |
|
226 | + if (!$this->isLocal($config, $context)) return false; |
|
227 | + |
|
228 | + $scheme_obj = $this->getSchemeObj($config, $context); |
|
229 | + if (!$scheme_obj) return false; // conservative approach |
|
230 | + |
|
231 | + $current_scheme_obj = $config->getDefinition('URI')->getDefaultScheme($config, $context); |
|
232 | + if ($current_scheme_obj->secure) { |
|
233 | + if (!$scheme_obj->secure) { |
|
234 | + return false; |
|
235 | + } |
|
236 | + } |
|
237 | + return true; |
|
238 | + } |
|
239 | 239 | |
240 | 240 | } |
241 | 241 |
@@ -36,7 +36,10 @@ discard block |
||
36 | 36 | $registry = HTMLPurifier_URISchemeRegistry::instance(); |
37 | 37 | if ($this->scheme !== null) { |
38 | 38 | $scheme_obj = $registry->getScheme($this->scheme, $config, $context); |
39 | - if (!$scheme_obj) return false; // invalid scheme, clean it out |
|
39 | + if (!$scheme_obj) { |
|
40 | + return false; |
|
41 | + } |
|
42 | + // invalid scheme, clean it out |
|
40 | 43 | } else { |
41 | 44 | // no scheme: retrieve the default one |
42 | 45 | $def = $config->getDefinition('URI'); |
@@ -71,7 +74,9 @@ discard block |
||
71 | 74 | if (!is_null($this->host)) { |
72 | 75 | $host_def = new HTMLPurifier_AttrDef_URI_Host(); |
73 | 76 | $this->host = $host_def->validate($this->host, $config, $context); |
74 | - if ($this->host === false) $this->host = null; |
|
77 | + if ($this->host === false) { |
|
78 | + $this->host = null; |
|
79 | + } |
|
75 | 80 | } |
76 | 81 | |
77 | 82 | // validate scheme |
@@ -97,7 +102,9 @@ discard block |
||
97 | 102 | |
98 | 103 | // validate port |
99 | 104 | if (!is_null($this->port)) { |
100 | - if ($this->port < 1 || $this->port > 65535) $this->port = null; |
|
105 | + if ($this->port < 1 || $this->port > 65535) { |
|
106 | + $this->port = null; |
|
107 | + } |
|
101 | 108 | } |
102 | 109 | |
103 | 110 | // validate path |
@@ -178,9 +185,13 @@ discard block |
||
178 | 185 | // (http:///foo-bar). |
179 | 186 | if (!is_null($this->host)) { |
180 | 187 | $authority = ''; |
181 | - if(!is_null($this->userinfo)) $authority .= $this->userinfo . '@'; |
|
188 | + if(!is_null($this->userinfo)) { |
|
189 | + $authority .= $this->userinfo . '@'; |
|
190 | + } |
|
182 | 191 | $authority .= $this->host; |
183 | - if(!is_null($this->port)) $authority .= ':' . $this->port; |
|
192 | + if(!is_null($this->port)) { |
|
193 | + $authority .= ':' . $this->port; |
|
194 | + } |
|
184 | 195 | } |
185 | 196 | |
186 | 197 | // Reconstruct the result |
@@ -190,11 +201,19 @@ discard block |
||
190 | 201 | // differently than http:///foo), so unfortunately we have to |
191 | 202 | // defer to the schemes to do the right thing. |
192 | 203 | $result = ''; |
193 | - if (!is_null($this->scheme)) $result .= $this->scheme . ':'; |
|
194 | - if (!is_null($authority)) $result .= '//' . $authority; |
|
204 | + if (!is_null($this->scheme)) { |
|
205 | + $result .= $this->scheme . ':'; |
|
206 | + } |
|
207 | + if (!is_null($authority)) { |
|
208 | + $result .= '//' . $authority; |
|
209 | + } |
|
195 | 210 | $result .= $this->path; |
196 | - if (!is_null($this->query)) $result .= '?' . $this->query; |
|
197 | - if (!is_null($this->fragment)) $result .= '#' . $this->fragment; |
|
211 | + if (!is_null($this->query)) { |
|
212 | + $result .= '?' . $this->query; |
|
213 | + } |
|
214 | + if (!is_null($this->fragment)) { |
|
215 | + $result .= '#' . $this->fragment; |
|
216 | + } |
|
198 | 217 | |
199 | 218 | return $result; |
200 | 219 | } |
@@ -209,9 +228,13 @@ discard block |
||
209 | 228 | * security. isBenign is probably what you actually want. |
210 | 229 | */ |
211 | 230 | public function isLocal($config, $context) { |
212 | - if ($this->host === null) return true; |
|
231 | + if ($this->host === null) { |
|
232 | + return true; |
|
233 | + } |
|
213 | 234 | $uri_def = $config->getDefinition('URI'); |
214 | - if ($uri_def->host === $this->host) return true; |
|
235 | + if ($uri_def->host === $this->host) { |
|
236 | + return true; |
|
237 | + } |
|
215 | 238 | return false; |
216 | 239 | } |
217 | 240 | |
@@ -223,10 +246,15 @@ discard block |
||
223 | 246 | * - It has a equal or better level of security |
224 | 247 | */ |
225 | 248 | public function isBenign($config, $context) { |
226 | - if (!$this->isLocal($config, $context)) return false; |
|
249 | + if (!$this->isLocal($config, $context)) { |
|
250 | + return false; |
|
251 | + } |
|
227 | 252 | |
228 | 253 | $scheme_obj = $this->getSchemeObj($config, $context); |
229 | - if (!$scheme_obj) return false; // conservative approach |
|
254 | + if (!$scheme_obj) { |
|
255 | + return false; |
|
256 | + } |
|
257 | + // conservative approach |
|
230 | 258 | |
231 | 259 | $current_scheme_obj = $config->getDefinition('URI')->getDefaultScheme($config, $context); |
232 | 260 | if ($current_scheme_obj->secure) { |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | if (!$scheme_obj) { |
45 | 45 | // something funky happened to the default scheme object |
46 | 46 | trigger_error( |
47 | - 'Default scheme object "' . $def->defaultScheme . '" was not readable', |
|
47 | + 'Default scheme object "'.$def->defaultScheme.'" was not readable', |
|
48 | 48 | E_USER_WARNING |
49 | 49 | ); |
50 | 50 | return false; |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | // ABNF definitions from RFC 3986 |
66 | 66 | $chars_sub_delims = '!$&\'()*+,;='; |
67 | 67 | $chars_gen_delims = ':/?#[]@'; |
68 | - $chars_pchar = $chars_sub_delims . ':@'; |
|
68 | + $chars_pchar = $chars_sub_delims.':@'; |
|
69 | 69 | |
70 | 70 | // validate host |
71 | 71 | if (!is_null($this->host)) { |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | |
92 | 92 | // validate username |
93 | 93 | if (!is_null($this->userinfo)) { |
94 | - $encoder = new HTMLPurifier_PercentEncoder($chars_sub_delims . ':'); |
|
94 | + $encoder = new HTMLPurifier_PercentEncoder($chars_sub_delims.':'); |
|
95 | 95 | $this->userinfo = $encoder->encode($this->userinfo); |
96 | 96 | } |
97 | 97 | |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | |
103 | 103 | // validate path |
104 | 104 | $path_parts = array(); |
105 | - $segments_encoder = new HTMLPurifier_PercentEncoder($chars_pchar . '/'); |
|
105 | + $segments_encoder = new HTMLPurifier_PercentEncoder($chars_pchar.'/'); |
|
106 | 106 | if (!is_null($this->host)) { // this catches $this->host === '' |
107 | 107 | // path-abempty (hier and relative) |
108 | 108 | // http://www.example.com/my/path |
@@ -136,11 +136,11 @@ discard block |
||
136 | 136 | // path-noscheme (relative) |
137 | 137 | // my/path |
138 | 138 | // (once again, not checking nz) |
139 | - $segment_nc_encoder = new HTMLPurifier_PercentEncoder($chars_sub_delims . '@'); |
|
139 | + $segment_nc_encoder = new HTMLPurifier_PercentEncoder($chars_sub_delims.'@'); |
|
140 | 140 | $c = strpos($this->path, '/'); |
141 | 141 | if ($c !== false) { |
142 | 142 | $this->path = |
143 | - $segment_nc_encoder->encode(substr($this->path, 0, $c)) . |
|
143 | + $segment_nc_encoder->encode(substr($this->path, 0, $c)). |
|
144 | 144 | $segments_encoder->encode(substr($this->path, $c)); |
145 | 145 | } else { |
146 | 146 | $this->path = $segment_nc_encoder->encode($this->path); |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | } |
153 | 153 | |
154 | 154 | // qf = query and fragment |
155 | - $qf_encoder = new HTMLPurifier_PercentEncoder($chars_pchar . '/?'); |
|
155 | + $qf_encoder = new HTMLPurifier_PercentEncoder($chars_pchar.'/?'); |
|
156 | 156 | |
157 | 157 | if (!is_null($this->query)) { |
158 | 158 | $this->query = $qf_encoder->encode($this->query); |
@@ -178,9 +178,9 @@ discard block |
||
178 | 178 | // (http:///foo-bar). |
179 | 179 | if (!is_null($this->host)) { |
180 | 180 | $authority = ''; |
181 | - if(!is_null($this->userinfo)) $authority .= $this->userinfo . '@'; |
|
181 | + if (!is_null($this->userinfo)) $authority .= $this->userinfo.'@'; |
|
182 | 182 | $authority .= $this->host; |
183 | - if(!is_null($this->port)) $authority .= ':' . $this->port; |
|
183 | + if (!is_null($this->port)) $authority .= ':'.$this->port; |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | // Reconstruct the result |
@@ -190,11 +190,11 @@ discard block |
||
190 | 190 | // differently than http:///foo), so unfortunately we have to |
191 | 191 | // defer to the schemes to do the right thing. |
192 | 192 | $result = ''; |
193 | - if (!is_null($this->scheme)) $result .= $this->scheme . ':'; |
|
194 | - if (!is_null($authority)) $result .= '//' . $authority; |
|
193 | + if (!is_null($this->scheme)) $result .= $this->scheme.':'; |
|
194 | + if (!is_null($authority)) $result .= '//'.$authority; |
|
195 | 195 | $result .= $this->path; |
196 | - if (!is_null($this->query)) $result .= '?' . $this->query; |
|
197 | - if (!is_null($this->fragment)) $result .= '#' . $this->fragment; |
|
196 | + if (!is_null($this->query)) $result .= '?'.$this->query; |
|
197 | + if (!is_null($this->fragment)) $result .= '#'.$this->fragment; |
|
198 | 198 | |
199 | 199 | return $result; |
200 | 200 | } |
@@ -109,6 +109,7 @@ discard block |
||
109 | 109 | /** |
110 | 110 | * Actually implements the parsing. Base implementation is to not |
111 | 111 | * do anything to $var. Subclasses should overload this! |
112 | + * @param boolean $allow_null |
|
112 | 113 | */ |
113 | 114 | protected function parseImplementation($var, $type, $allow_null) { |
114 | 115 | return $var; |
@@ -116,6 +117,7 @@ discard block |
||
116 | 117 | |
117 | 118 | /** |
118 | 119 | * Throws an exception. |
120 | + * @param string $msg |
|
119 | 121 | */ |
120 | 122 | protected function error($msg) { |
121 | 123 | throw new HTMLPurifier_VarParserException($msg); |
@@ -126,6 +128,7 @@ discard block |
||
126 | 128 | * @note This should not ever be called. It would be called if we |
127 | 129 | * extend the allowed values of HTMLPurifier_VarParser without |
128 | 130 | * updating subclasses. |
131 | + * @param string $class |
|
129 | 132 | */ |
130 | 133 | protected function errorInconsistent($class, $type) { |
131 | 134 | throw new HTMLPurifier_Exception("Inconsistency in $class: ".HTMLPurifier_VarParser::getTypeName($type)." not implemented"); |
@@ -7,147 +7,147 @@ |
||
7 | 7 | class HTMLPurifier_VarParser |
8 | 8 | { |
9 | 9 | |
10 | - const STRING = 1; |
|
11 | - const ISTRING = 2; |
|
12 | - const TEXT = 3; |
|
13 | - const ITEXT = 4; |
|
14 | - const INT = 5; |
|
15 | - const FLOAT = 6; |
|
16 | - const BOOL = 7; |
|
17 | - const LOOKUP = 8; |
|
18 | - const ALIST = 9; |
|
19 | - const HASH = 10; |
|
20 | - const MIXED = 11; |
|
10 | + const STRING = 1; |
|
11 | + const ISTRING = 2; |
|
12 | + const TEXT = 3; |
|
13 | + const ITEXT = 4; |
|
14 | + const INT = 5; |
|
15 | + const FLOAT = 6; |
|
16 | + const BOOL = 7; |
|
17 | + const LOOKUP = 8; |
|
18 | + const ALIST = 9; |
|
19 | + const HASH = 10; |
|
20 | + const MIXED = 11; |
|
21 | 21 | |
22 | - /** |
|
23 | - * Lookup table of allowed types. Mainly for backwards compatibility, but |
|
24 | - * also convenient for transforming string type names to the integer constants. |
|
25 | - */ |
|
26 | - static public $types = array( |
|
27 | - 'string' => self::STRING, |
|
28 | - 'istring' => self::ISTRING, |
|
29 | - 'text' => self::TEXT, |
|
30 | - 'itext' => self::ITEXT, |
|
31 | - 'int' => self::INT, |
|
32 | - 'float' => self::FLOAT, |
|
33 | - 'bool' => self::BOOL, |
|
34 | - 'lookup' => self::LOOKUP, |
|
35 | - 'list' => self::ALIST, |
|
36 | - 'hash' => self::HASH, |
|
37 | - 'mixed' => self::MIXED |
|
38 | - ); |
|
22 | + /** |
|
23 | + * Lookup table of allowed types. Mainly for backwards compatibility, but |
|
24 | + * also convenient for transforming string type names to the integer constants. |
|
25 | + */ |
|
26 | + static public $types = array( |
|
27 | + 'string' => self::STRING, |
|
28 | + 'istring' => self::ISTRING, |
|
29 | + 'text' => self::TEXT, |
|
30 | + 'itext' => self::ITEXT, |
|
31 | + 'int' => self::INT, |
|
32 | + 'float' => self::FLOAT, |
|
33 | + 'bool' => self::BOOL, |
|
34 | + 'lookup' => self::LOOKUP, |
|
35 | + 'list' => self::ALIST, |
|
36 | + 'hash' => self::HASH, |
|
37 | + 'mixed' => self::MIXED |
|
38 | + ); |
|
39 | 39 | |
40 | - /** |
|
41 | - * Lookup table of types that are string, and can have aliases or |
|
42 | - * allowed value lists. |
|
43 | - */ |
|
44 | - static public $stringTypes = array( |
|
45 | - self::STRING => true, |
|
46 | - self::ISTRING => true, |
|
47 | - self::TEXT => true, |
|
48 | - self::ITEXT => true, |
|
49 | - ); |
|
40 | + /** |
|
41 | + * Lookup table of types that are string, and can have aliases or |
|
42 | + * allowed value lists. |
|
43 | + */ |
|
44 | + static public $stringTypes = array( |
|
45 | + self::STRING => true, |
|
46 | + self::ISTRING => true, |
|
47 | + self::TEXT => true, |
|
48 | + self::ITEXT => true, |
|
49 | + ); |
|
50 | 50 | |
51 | - /** |
|
52 | - * Validate a variable according to type. Throws |
|
53 | - * HTMLPurifier_VarParserException if invalid. |
|
54 | - * It may return NULL as a valid type if $allow_null is true. |
|
55 | - * |
|
56 | - * @param $var Variable to validate |
|
57 | - * @param $type Type of variable, see HTMLPurifier_VarParser->types |
|
58 | - * @param $allow_null Whether or not to permit null as a value |
|
59 | - * @return Validated and type-coerced variable |
|
60 | - */ |
|
61 | - final public function parse($var, $type, $allow_null = false) { |
|
62 | - if (is_string($type)) { |
|
63 | - if (!isset(HTMLPurifier_VarParser::$types[$type])) { |
|
64 | - throw new HTMLPurifier_VarParserException("Invalid type '$type'"); |
|
65 | - } else { |
|
66 | - $type = HTMLPurifier_VarParser::$types[$type]; |
|
67 | - } |
|
68 | - } |
|
69 | - $var = $this->parseImplementation($var, $type, $allow_null); |
|
70 | - if ($allow_null && $var === null) return null; |
|
71 | - // These are basic checks, to make sure nothing horribly wrong |
|
72 | - // happened in our implementations. |
|
73 | - switch ($type) { |
|
74 | - case (self::STRING): |
|
75 | - case (self::ISTRING): |
|
76 | - case (self::TEXT): |
|
77 | - case (self::ITEXT): |
|
78 | - if (!is_string($var)) break; |
|
79 | - if ($type == self::ISTRING || $type == self::ITEXT) $var = strtolower($var); |
|
80 | - return $var; |
|
81 | - case (self::INT): |
|
82 | - if (!is_int($var)) break; |
|
83 | - return $var; |
|
84 | - case (self::FLOAT): |
|
85 | - if (!is_float($var)) break; |
|
86 | - return $var; |
|
87 | - case (self::BOOL): |
|
88 | - if (!is_bool($var)) break; |
|
89 | - return $var; |
|
90 | - case (self::LOOKUP): |
|
91 | - case (self::ALIST): |
|
92 | - case (self::HASH): |
|
93 | - if (!is_array($var)) break; |
|
94 | - if ($type === self::LOOKUP) { |
|
95 | - foreach ($var as $k) if ($k !== true) $this->error('Lookup table contains value other than true'); |
|
96 | - } elseif ($type === self::ALIST) { |
|
97 | - $keys = array_keys($var); |
|
98 | - if (array_keys($keys) !== $keys) $this->error('Indices for list are not uniform'); |
|
99 | - } |
|
100 | - return $var; |
|
101 | - case (self::MIXED): |
|
102 | - return $var; |
|
103 | - default: |
|
104 | - $this->errorInconsistent(get_class($this), $type); |
|
105 | - } |
|
106 | - $this->errorGeneric($var, $type); |
|
107 | - } |
|
51 | + /** |
|
52 | + * Validate a variable according to type. Throws |
|
53 | + * HTMLPurifier_VarParserException if invalid. |
|
54 | + * It may return NULL as a valid type if $allow_null is true. |
|
55 | + * |
|
56 | + * @param $var Variable to validate |
|
57 | + * @param $type Type of variable, see HTMLPurifier_VarParser->types |
|
58 | + * @param $allow_null Whether or not to permit null as a value |
|
59 | + * @return Validated and type-coerced variable |
|
60 | + */ |
|
61 | + final public function parse($var, $type, $allow_null = false) { |
|
62 | + if (is_string($type)) { |
|
63 | + if (!isset(HTMLPurifier_VarParser::$types[$type])) { |
|
64 | + throw new HTMLPurifier_VarParserException("Invalid type '$type'"); |
|
65 | + } else { |
|
66 | + $type = HTMLPurifier_VarParser::$types[$type]; |
|
67 | + } |
|
68 | + } |
|
69 | + $var = $this->parseImplementation($var, $type, $allow_null); |
|
70 | + if ($allow_null && $var === null) return null; |
|
71 | + // These are basic checks, to make sure nothing horribly wrong |
|
72 | + // happened in our implementations. |
|
73 | + switch ($type) { |
|
74 | + case (self::STRING): |
|
75 | + case (self::ISTRING): |
|
76 | + case (self::TEXT): |
|
77 | + case (self::ITEXT): |
|
78 | + if (!is_string($var)) break; |
|
79 | + if ($type == self::ISTRING || $type == self::ITEXT) $var = strtolower($var); |
|
80 | + return $var; |
|
81 | + case (self::INT): |
|
82 | + if (!is_int($var)) break; |
|
83 | + return $var; |
|
84 | + case (self::FLOAT): |
|
85 | + if (!is_float($var)) break; |
|
86 | + return $var; |
|
87 | + case (self::BOOL): |
|
88 | + if (!is_bool($var)) break; |
|
89 | + return $var; |
|
90 | + case (self::LOOKUP): |
|
91 | + case (self::ALIST): |
|
92 | + case (self::HASH): |
|
93 | + if (!is_array($var)) break; |
|
94 | + if ($type === self::LOOKUP) { |
|
95 | + foreach ($var as $k) if ($k !== true) $this->error('Lookup table contains value other than true'); |
|
96 | + } elseif ($type === self::ALIST) { |
|
97 | + $keys = array_keys($var); |
|
98 | + if (array_keys($keys) !== $keys) $this->error('Indices for list are not uniform'); |
|
99 | + } |
|
100 | + return $var; |
|
101 | + case (self::MIXED): |
|
102 | + return $var; |
|
103 | + default: |
|
104 | + $this->errorInconsistent(get_class($this), $type); |
|
105 | + } |
|
106 | + $this->errorGeneric($var, $type); |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * Actually implements the parsing. Base implementation is to not |
|
111 | - * do anything to $var. Subclasses should overload this! |
|
112 | - */ |
|
113 | - protected function parseImplementation($var, $type, $allow_null) { |
|
114 | - return $var; |
|
115 | - } |
|
109 | + /** |
|
110 | + * Actually implements the parsing. Base implementation is to not |
|
111 | + * do anything to $var. Subclasses should overload this! |
|
112 | + */ |
|
113 | + protected function parseImplementation($var, $type, $allow_null) { |
|
114 | + return $var; |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * Throws an exception. |
|
119 | - */ |
|
120 | - protected function error($msg) { |
|
121 | - throw new HTMLPurifier_VarParserException($msg); |
|
122 | - } |
|
117 | + /** |
|
118 | + * Throws an exception. |
|
119 | + */ |
|
120 | + protected function error($msg) { |
|
121 | + throw new HTMLPurifier_VarParserException($msg); |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * Throws an inconsistency exception. |
|
126 | - * @note This should not ever be called. It would be called if we |
|
127 | - * extend the allowed values of HTMLPurifier_VarParser without |
|
128 | - * updating subclasses. |
|
129 | - */ |
|
130 | - protected function errorInconsistent($class, $type) { |
|
131 | - throw new HTMLPurifier_Exception("Inconsistency in $class: ".HTMLPurifier_VarParser::getTypeName($type)." not implemented"); |
|
132 | - } |
|
124 | + /** |
|
125 | + * Throws an inconsistency exception. |
|
126 | + * @note This should not ever be called. It would be called if we |
|
127 | + * extend the allowed values of HTMLPurifier_VarParser without |
|
128 | + * updating subclasses. |
|
129 | + */ |
|
130 | + protected function errorInconsistent($class, $type) { |
|
131 | + throw new HTMLPurifier_Exception("Inconsistency in $class: ".HTMLPurifier_VarParser::getTypeName($type)." not implemented"); |
|
132 | + } |
|
133 | 133 | |
134 | - /** |
|
135 | - * Generic error for if a type didn't work. |
|
136 | - */ |
|
137 | - protected function errorGeneric($var, $type) { |
|
138 | - $vtype = gettype($var); |
|
139 | - $this->error("Expected type ".HTMLPurifier_VarParser::getTypeName($type).", got $vtype"); |
|
140 | - } |
|
134 | + /** |
|
135 | + * Generic error for if a type didn't work. |
|
136 | + */ |
|
137 | + protected function errorGeneric($var, $type) { |
|
138 | + $vtype = gettype($var); |
|
139 | + $this->error("Expected type ".HTMLPurifier_VarParser::getTypeName($type).", got $vtype"); |
|
140 | + } |
|
141 | 141 | |
142 | - static public function getTypeName($type) { |
|
143 | - static $lookup; |
|
144 | - if (!$lookup) { |
|
145 | - // Lazy load the alternative lookup table |
|
146 | - $lookup = array_flip(HTMLPurifier_VarParser::$types); |
|
147 | - } |
|
148 | - if (!isset($lookup[$type])) return 'unknown'; |
|
149 | - return $lookup[$type]; |
|
150 | - } |
|
142 | + static public function getTypeName($type) { |
|
143 | + static $lookup; |
|
144 | + if (!$lookup) { |
|
145 | + // Lazy load the alternative lookup table |
|
146 | + $lookup = array_flip(HTMLPurifier_VarParser::$types); |
|
147 | + } |
|
148 | + if (!isset($lookup[$type])) return 'unknown'; |
|
149 | + return $lookup[$type]; |
|
150 | + } |
|
151 | 151 | |
152 | 152 | } |
153 | 153 |
@@ -67,7 +67,9 @@ discard block |
||
67 | 67 | } |
68 | 68 | } |
69 | 69 | $var = $this->parseImplementation($var, $type, $allow_null); |
70 | - if ($allow_null && $var === null) return null; |
|
70 | + if ($allow_null && $var === null) { |
|
71 | + return null; |
|
72 | + } |
|
71 | 73 | // These are basic checks, to make sure nothing horribly wrong |
72 | 74 | // happened in our implementations. |
73 | 75 | switch ($type) { |
@@ -75,27 +77,43 @@ discard block |
||
75 | 77 | case (self::ISTRING): |
76 | 78 | case (self::TEXT): |
77 | 79 | case (self::ITEXT): |
78 | - if (!is_string($var)) break; |
|
79 | - if ($type == self::ISTRING || $type == self::ITEXT) $var = strtolower($var); |
|
80 | + if (!is_string($var)) { |
|
81 | + break; |
|
82 | + } |
|
83 | + if ($type == self::ISTRING || $type == self::ITEXT) { |
|
84 | + $var = strtolower($var); |
|
85 | + } |
|
80 | 86 | return $var; |
81 | 87 | case (self::INT): |
82 | - if (!is_int($var)) break; |
|
88 | + if (!is_int($var)) { |
|
89 | + break; |
|
90 | + } |
|
83 | 91 | return $var; |
84 | 92 | case (self::FLOAT): |
85 | - if (!is_float($var)) break; |
|
93 | + if (!is_float($var)) { |
|
94 | + break; |
|
95 | + } |
|
86 | 96 | return $var; |
87 | 97 | case (self::BOOL): |
88 | - if (!is_bool($var)) break; |
|
98 | + if (!is_bool($var)) { |
|
99 | + break; |
|
100 | + } |
|
89 | 101 | return $var; |
90 | 102 | case (self::LOOKUP): |
91 | 103 | case (self::ALIST): |
92 | 104 | case (self::HASH): |
93 | - if (!is_array($var)) break; |
|
105 | + if (!is_array($var)) { |
|
106 | + break; |
|
107 | + } |
|
94 | 108 | if ($type === self::LOOKUP) { |
95 | - foreach ($var as $k) if ($k !== true) $this->error('Lookup table contains value other than true'); |
|
109 | + foreach ($var as $k) { |
|
110 | + if ($k !== true) $this->error('Lookup table contains value other than true'); |
|
111 | + } |
|
96 | 112 | } elseif ($type === self::ALIST) { |
97 | 113 | $keys = array_keys($var); |
98 | - if (array_keys($keys) !== $keys) $this->error('Indices for list are not uniform'); |
|
114 | + if (array_keys($keys) !== $keys) { |
|
115 | + $this->error('Indices for list are not uniform'); |
|
116 | + } |
|
99 | 117 | } |
100 | 118 | return $var; |
101 | 119 | case (self::MIXED): |
@@ -145,7 +163,9 @@ discard block |
||
145 | 163 | // Lazy load the alternative lookup table |
146 | 164 | $lookup = array_flip(HTMLPurifier_VarParser::$types); |
147 | 165 | } |
148 | - if (!isset($lookup[$type])) return 'unknown'; |
|
166 | + if (!isset($lookup[$type])) { |
|
167 | + return 'unknown'; |
|
168 | + } |
|
149 | 169 | return $lookup[$type]; |
150 | 170 | } |
151 | 171 |
@@ -5,6 +5,9 @@ |
||
5 | 5 | { |
6 | 6 | private static $_block_list = array ('exec', 'system', 'passthru', 'show_source', 'phpinfo', 'fopen', 'file_get_contents', 'file_put_contents', 'fwrite', 'proc_open', 'popen'); |
7 | 7 | |
8 | + /** |
|
9 | + * @param string $file |
|
10 | + */ |
|
8 | 11 | public function check($file) |
9 | 12 | { |
10 | 13 | // TODO: 기능개선후 enable |
@@ -3,38 +3,38 @@ |
||
3 | 3 | |
4 | 4 | class UploadFileFilter |
5 | 5 | { |
6 | - private static $_block_list = array ('exec', 'system', 'passthru', 'show_source', 'phpinfo', 'fopen', 'file_get_contents', 'file_put_contents', 'fwrite', 'proc_open', 'popen'); |
|
6 | + private static $_block_list = array('exec', 'system', 'passthru', 'show_source', 'phpinfo', 'fopen', 'file_get_contents', 'file_put_contents', 'fwrite', 'proc_open', 'popen'); |
|
7 | 7 | |
8 | 8 | public function check($file) |
9 | 9 | { |
10 | 10 | // TODO: 기능개선후 enable |
11 | 11 | |
12 | 12 | return TRUE; // disable |
13 | - if (! $file || ! FileHandler::exists($file)) return TRUE; |
|
14 | - return self::_check ( $file ); |
|
13 | + if (!$file || !FileHandler::exists($file)) return TRUE; |
|
14 | + return self::_check($file); |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | private function _check($file) |
18 | 18 | { |
19 | - if (! ($fp = fopen ( $file, 'r' ))) return FALSE; |
|
19 | + if (!($fp = fopen($file, 'r'))) return FALSE; |
|
20 | 20 | |
21 | 21 | $has_php_tag = FALSE; |
22 | 22 | |
23 | - while ( ! feof ( $fp ) ) |
|
23 | + while (!feof($fp)) |
|
24 | 24 | { |
25 | - $content = fread ( $fp, 8192 ); |
|
26 | - if (FALSE === $has_php_tag) $has_php_tag = strpos ( $content, '<?' ); |
|
27 | - foreach ( self::$_block_list as $v ) |
|
25 | + $content = fread($fp, 8192); |
|
26 | + if (FALSE === $has_php_tag) $has_php_tag = strpos($content, '<?'); |
|
27 | + foreach (self::$_block_list as $v) |
|
28 | 28 | { |
29 | - if (FALSE !== $has_php_tag && FALSE !== strpos ( $content, $v )) |
|
29 | + if (FALSE !== $has_php_tag && FALSE !== strpos($content, $v)) |
|
30 | 30 | { |
31 | - fclose ( $fp ); |
|
31 | + fclose($fp); |
|
32 | 32 | return FALSE; |
33 | 33 | } |
34 | 34 | } |
35 | 35 | } |
36 | 36 | |
37 | - fclose ( $fp ); |
|
37 | + fclose($fp); |
|
38 | 38 | |
39 | 39 | return TRUE; |
40 | 40 | } |
@@ -10,20 +10,26 @@ |
||
10 | 10 | // TODO: 기능개선후 enable |
11 | 11 | |
12 | 12 | return TRUE; // disable |
13 | - if (! $file || ! FileHandler::exists($file)) return TRUE; |
|
13 | + if (! $file || ! FileHandler::exists($file)) { |
|
14 | + return TRUE; |
|
15 | + } |
|
14 | 16 | return self::_check ( $file ); |
15 | 17 | } |
16 | 18 | |
17 | 19 | private function _check($file) |
18 | 20 | { |
19 | - if (! ($fp = fopen ( $file, 'r' ))) return FALSE; |
|
21 | + if (! ($fp = fopen ( $file, 'r' ))) { |
|
22 | + return FALSE; |
|
23 | + } |
|
20 | 24 | |
21 | 25 | $has_php_tag = FALSE; |
22 | 26 | |
23 | 27 | while ( ! feof ( $fp ) ) |
24 | 28 | { |
25 | 29 | $content = fread ( $fp, 8192 ); |
26 | - if (FALSE === $has_php_tag) $has_php_tag = strpos ( $content, '<?' ); |
|
30 | + if (FALSE === $has_php_tag) { |
|
31 | + $has_php_tag = strpos ( $content, '<?' ); |
|
32 | + } |
|
27 | 33 | foreach ( self::$_block_list as $v ) |
28 | 34 | { |
29 | 35 | if (FALSE !== $has_php_tag && FALSE !== strpos ( $content, $v )) |
@@ -25,7 +25,7 @@ |
||
25 | 25 | |
26 | 26 | /** |
27 | 27 | * constructor |
28 | - * @return void |
|
28 | + * @return string |
|
29 | 29 | */ |
30 | 30 | public function __construct() |
31 | 31 | { |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | //parse error |
463 | 463 | if ($error_info['type'] == 4) |
464 | 464 | { |
465 | - throw new Exception("Error Parsing Template - {$error_info['message']} in template file {$this->file}"); |
|
465 | + throw new Exception("Error Parsing Template - {$error_info['message']} in template file {$this->file}"); |
|
466 | 466 | } |
467 | 467 | } |
468 | 468 | else |
@@ -478,7 +478,7 @@ discard block |
||
478 | 478 | //parse error |
479 | 479 | if ($error_info['type'] == 4) |
480 | 480 | { |
481 | - throw new Exception("Error Parsing Template - {$error_info['message']} in template file {$this->file}"); |
|
481 | + throw new Exception("Error Parsing Template - {$error_info['message']} in template file {$this->file}"); |
|
482 | 482 | } |
483 | 483 | } |
484 | 484 | |
@@ -1023,8 +1023,8 @@ discard block |
||
1023 | 1023 | } |
1024 | 1024 | |
1025 | 1025 | /** |
1026 | - * Apply escape option to an expression. |
|
1027 | - */ |
|
1026 | + * Apply escape option to an expression. |
|
1027 | + */ |
|
1028 | 1028 | private function _applyEscapeOption($str, $escape_option = 'noescape') |
1029 | 1029 | { |
1030 | 1030 | switch($escape_option) |
@@ -1080,11 +1080,11 @@ discard block |
||
1080 | 1080 | } |
1081 | 1081 | |
1082 | 1082 | /** |
1083 | - * Check if a string seems to contain a variable. |
|
1084 | - * |
|
1085 | - * @param string $str |
|
1086 | - * @return bool |
|
1087 | - */ |
|
1083 | + * Check if a string seems to contain a variable. |
|
1084 | + * |
|
1085 | + * @param string $str |
|
1086 | + * @return bool |
|
1087 | + */ |
|
1088 | 1088 | private static function _isVar($str) |
1089 | 1089 | { |
1090 | 1090 | return preg_match('@(?<!::|\\\\|(?<!eval\()\')\$([a-z_][a-z0-9_]*)@i', $str) ? true : false; |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | private $path = NULL; ///< target directory |
17 | 17 | private $filename = NULL; ///< target filename |
18 | 18 | private $file = NULL; ///< target file (fullpath) |
19 | - private $xe_path = NULL; ///< XpressEngine base path |
|
19 | + private $xe_path = NULL; ///< XpressEngine base path |
|
20 | 20 | private $web_path = NULL; ///< tpl file web path |
21 | 21 | private $compiled_file = NULL; ///< tpl file web path |
22 | 22 | private $config = NULL; |
@@ -33,11 +33,11 @@ discard block |
||
33 | 33 | { |
34 | 34 | ini_set('pcre.jit', "0"); |
35 | 35 | $this->xe_path = rtrim(getScriptPath(), '/'); |
36 | - $this->compiled_path = _XE_PATH_ . $this->compiled_path; |
|
36 | + $this->compiled_path = _XE_PATH_.$this->compiled_path; |
|
37 | 37 | $this->config = new stdClass(); |
38 | 38 | |
39 | 39 | $this->ignoreEscape = array( |
40 | - 'html_content' => function ($m) { |
|
40 | + 'html_content' => function($m) { |
|
41 | 41 | $list = array( |
42 | 42 | '$content', // 레이아웃 등 |
43 | 43 | '$editor', // 에디터 출력 |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | ); |
55 | 55 | return in_array($m[1], $list); |
56 | 56 | }, |
57 | - 'url' => function ($m) { |
|
57 | + 'url' => function($m) { |
|
58 | 58 | $list = array( |
59 | 59 | 'getUrl', |
60 | 60 | 'getNotEncodedUrl', |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | ); |
70 | 70 | return in_array(array_shift(explode('(', $m[1])), $list); |
71 | 71 | }, |
72 | - 'methods' => function ($m) { |
|
72 | + 'methods' => function($m) { |
|
73 | 73 | $list = array( |
74 | 74 | 'getEditor', |
75 | 75 | 'getCommentEditor', |
@@ -82,16 +82,16 @@ discard block |
||
82 | 82 | 'getSignature', // 회원 서명 |
83 | 83 | 'printExtraImages', // new, file 아이콘 등 |
84 | 84 | ); |
85 | - return preg_match('/\-\>(' . implode('|', $list) . ')\(/', $m[1]); |
|
85 | + return preg_match('/\-\>('.implode('|', $list).')\(/', $m[1]); |
|
86 | 86 | }, |
87 | - 'functions' => function ($m) { |
|
87 | + 'functions' => function($m) { |
|
88 | 88 | $list = array( |
89 | 89 | 'htmlspecialchars', |
90 | 90 | 'nl2br', |
91 | 91 | ); |
92 | - return preg_match('/^(' . implode('|', $list) . ')\(/', $m[1]); |
|
92 | + return preg_match('/^('.implode('|', $list).')\(/', $m[1]); |
|
93 | 93 | }, |
94 | - 'lang' => function ($m) { |
|
94 | + 'lang' => function($m) { |
|
95 | 95 | // 다국어 |
96 | 96 | return preg_match('/^\$lang\-\>/', trim($m[1])); |
97 | 97 | } |
@@ -108,9 +108,9 @@ discard block |
||
108 | 108 | { |
109 | 109 | static $oTemplate = NULL; |
110 | 110 | |
111 | - if(__DEBUG__ == 3) |
|
111 | + if (__DEBUG__ == 3) |
|
112 | 112 | { |
113 | - if(!isset($GLOBALS['__TemplateHandlerCalled__'])) |
|
113 | + if (!isset($GLOBALS['__TemplateHandlerCalled__'])) |
|
114 | 114 | { |
115 | 115 | $GLOBALS['__TemplateHandlerCalled__'] = 1; |
116 | 116 | } |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | } |
121 | 121 | } |
122 | 122 | |
123 | - if(!$oTemplate) |
|
123 | + if (!$oTemplate) |
|
124 | 124 | { |
125 | 125 | $oTemplate = new TemplateHandler(); |
126 | 126 | } |
@@ -138,23 +138,23 @@ discard block |
||
138 | 138 | protected function init($tpl_path, $tpl_filename, $tpl_file = '') |
139 | 139 | { |
140 | 140 | // verify arguments |
141 | - if(substr($tpl_path, -1) != '/') |
|
141 | + if (substr($tpl_path, -1) != '/') |
|
142 | 142 | { |
143 | 143 | $tpl_path .= '/'; |
144 | 144 | } |
145 | - if(!is_dir($tpl_path)) |
|
145 | + if (!is_dir($tpl_path)) |
|
146 | 146 | { |
147 | 147 | return; |
148 | 148 | } |
149 | - if(!file_exists($tpl_path . $tpl_filename) && file_exists($tpl_path . $tpl_filename . '.html')) |
|
149 | + if (!file_exists($tpl_path.$tpl_filename) && file_exists($tpl_path.$tpl_filename.'.html')) |
|
150 | 150 | { |
151 | 151 | $tpl_filename .= '.html'; |
152 | 152 | } |
153 | 153 | |
154 | 154 | // create tpl_file variable |
155 | - if(!$tpl_file) |
|
155 | + if (!$tpl_file) |
|
156 | 156 | { |
157 | - $tpl_file = $tpl_path . $tpl_filename; |
|
157 | + $tpl_file = $tpl_path.$tpl_filename; |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | // set template file infos. |
@@ -162,10 +162,10 @@ discard block |
||
162 | 162 | $this->filename = $tpl_filename; |
163 | 163 | $this->file = $tpl_file; |
164 | 164 | |
165 | - $this->web_path = $this->xe_path . '/' . ltrim(preg_replace('@^' . preg_quote(_XE_PATH_, '@') . '|\./@', '', $this->path), '/'); |
|
165 | + $this->web_path = $this->xe_path.'/'.ltrim(preg_replace('@^'.preg_quote(_XE_PATH_, '@').'|\./@', '', $this->path), '/'); |
|
166 | 166 | |
167 | 167 | // get compiled file name |
168 | - $hash = md5($this->file . __XE_VERSION__); |
|
168 | + $hash = md5($this->file.__XE_VERSION__); |
|
169 | 169 | $this->compiled_file = "{$this->compiled_path}{$hash}.compiled.php"; |
170 | 170 | |
171 | 171 | $this->safeguard = $this->isSafeguard(); |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | $buff = false; |
189 | 189 | |
190 | 190 | // store the starting time for debug information |
191 | - if(__DEBUG__ == 3) |
|
191 | + if (__DEBUG__ == 3) |
|
192 | 192 | { |
193 | 193 | $start = getMicroTime(); |
194 | 194 | } |
@@ -197,13 +197,13 @@ discard block |
||
197 | 197 | $this->init($tpl_path, $tpl_filename, $tpl_file); |
198 | 198 | |
199 | 199 | // if target file does not exist exit |
200 | - if(!$this->file || !file_exists($this->file)) |
|
200 | + if (!$this->file || !file_exists($this->file)) |
|
201 | 201 | { |
202 | 202 | return "Err : '{$this->file}' template file does not exists."; |
203 | 203 | } |
204 | 204 | |
205 | 205 | // for backward compatibility |
206 | - if(is_null(self::$rootTpl)) |
|
206 | + if (is_null(self::$rootTpl)) |
|
207 | 207 | { |
208 | 208 | self::$rootTpl = $this->file; |
209 | 209 | } |
@@ -215,23 +215,23 @@ discard block |
||
215 | 215 | $oCacheHandler = CacheHandler::getInstance('template'); |
216 | 216 | |
217 | 217 | // get cached buff |
218 | - if($oCacheHandler->isSupport()) |
|
218 | + if ($oCacheHandler->isSupport()) |
|
219 | 219 | { |
220 | - $cache_key = 'template:' . $this->file; |
|
220 | + $cache_key = 'template:'.$this->file; |
|
221 | 221 | $buff = $oCacheHandler->get($cache_key, $latest_mtime); |
222 | 222 | } |
223 | 223 | else |
224 | 224 | { |
225 | - if(is_readable($this->compiled_file) && filemtime($this->compiled_file) > $latest_mtime && filesize($this->compiled_file)) |
|
225 | + if (is_readable($this->compiled_file) && filemtime($this->compiled_file) > $latest_mtime && filesize($this->compiled_file)) |
|
226 | 226 | { |
227 | - $buff = 'file://' . $this->compiled_file; |
|
227 | + $buff = 'file://'.$this->compiled_file; |
|
228 | 228 | } |
229 | 229 | } |
230 | 230 | |
231 | - if($buff === FALSE) |
|
231 | + if ($buff === FALSE) |
|
232 | 232 | { |
233 | 233 | $buff = $this->parse(); |
234 | - if($oCacheHandler->isSupport()) |
|
234 | + if ($oCacheHandler->isSupport()) |
|
235 | 235 | { |
236 | 236 | $oCacheHandler->put($cache_key, $buff); |
237 | 237 | } |
@@ -243,13 +243,13 @@ discard block |
||
243 | 243 | |
244 | 244 | $output = $this->_fetch($buff); |
245 | 245 | |
246 | - if($__templatehandler_root_tpl == $this->file) |
|
246 | + if ($__templatehandler_root_tpl == $this->file) |
|
247 | 247 | { |
248 | 248 | $__templatehandler_root_tpl = null; |
249 | 249 | } |
250 | 250 | |
251 | 251 | // store the ending time for debug information |
252 | - if(__DEBUG__ == 3) |
|
252 | + if (__DEBUG__ == 3) |
|
253 | 253 | { |
254 | 254 | $GLOBALS['__template_elapsed__'] += getMicroTime() - $start; |
255 | 255 | } |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | $this->init($tpl_path, $tpl_filename, null); |
269 | 269 | |
270 | 270 | // if target file does not exist exit |
271 | - if(!$this->file || !file_exists($this->file)) |
|
271 | + if (!$this->file || !file_exists($this->file)) |
|
272 | 272 | { |
273 | 273 | Context::close(); |
274 | 274 | exit("Cannot find the template file: '{$this->file}'"); |
@@ -284,9 +284,9 @@ discard block |
||
284 | 284 | */ |
285 | 285 | protected function parse($buff = null) |
286 | 286 | { |
287 | - if(is_null($buff)) |
|
287 | + if (is_null($buff)) |
|
288 | 288 | { |
289 | - if(!is_readable($this->file)) |
|
289 | + if (!is_readable($this->file)) |
|
290 | 290 | { |
291 | 291 | return; |
292 | 292 | } |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | } |
297 | 297 | |
298 | 298 | // HTML tags to skip |
299 | - if(is_null($this->skipTags)) |
|
299 | + if (is_null($this->skipTags)) |
|
300 | 300 | { |
301 | 301 | $this->skipTags = array('marquee'); |
302 | 302 | } |
@@ -306,13 +306,13 @@ discard block |
||
306 | 306 | $this->config = new stdClass(); |
307 | 307 | $this->config->autoescape = null; |
308 | 308 | |
309 | - if(preg_match('/\<config( [^\>\/]+)/', $buff, $config_match)) |
|
309 | + if (preg_match('/\<config( [^\>\/]+)/', $buff, $config_match)) |
|
310 | 310 | { |
311 | - if(preg_match_all('@ (?<name>\w+)="(?<value>[^"]+)"@', $config_match[1], $config_matches, PREG_SET_ORDER)) |
|
311 | + if (preg_match_all('@ (?<name>\w+)="(?<value>[^"]+)"@', $config_match[1], $config_matches, PREG_SET_ORDER)) |
|
312 | 312 | { |
313 | - foreach($config_matches as $config_match) |
|
313 | + foreach ($config_matches as $config_match) |
|
314 | 314 | { |
315 | - if($config_match['name'] === 'autoescape') |
|
315 | + if ($config_match['name'] === 'autoescape') |
|
316 | 316 | { |
317 | 317 | $this->config->autoescape = $config_match['value']; |
318 | 318 | } |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | } |
321 | 321 | } |
322 | 322 | |
323 | - if($this->config->autoescape === 'on') $this->safeguard = true; |
|
323 | + if ($this->config->autoescape === 'on') $this->safeguard = true; |
|
324 | 324 | |
325 | 325 | // replace comments |
326 | 326 | $buff = preg_replace('@<!--//.*?-->@s', '', $buff); |
@@ -339,13 +339,13 @@ discard block |
||
339 | 339 | |
340 | 340 | // form auto generation |
341 | 341 | $temp = preg_replace_callback('/(<form(?:<\?php.+?\?>|[^<>]+)*?>)(.*?)(<\/form>)/is', array($this, '_compileFormAuthGeneration'), $buff); |
342 | - if($temp) |
|
342 | + if ($temp) |
|
343 | 343 | { |
344 | 344 | $buff = $temp; |
345 | 345 | } |
346 | 346 | |
347 | 347 | // prevent from calling directly before writing into file |
348 | - $buff = '<?php if(!defined("__XE__"))exit;?>' . $buff; |
|
348 | + $buff = '<?php if(!defined("__XE__"))exit;?>'.$buff; |
|
349 | 349 | |
350 | 350 | // remove php script reopening |
351 | 351 | $buff = preg_replace(array('/(\n|\r\n)+/', '/(;)?( )*\?\>\<\?php([\n\t ]+)?/'), array("\n", ";\n"), $buff); |
@@ -368,40 +368,40 @@ discard block |
||
368 | 368 | private function _compileFormAuthGeneration($matches) |
369 | 369 | { |
370 | 370 | // form ruleset attribute move to hidden tag |
371 | - if($matches[1]) |
|
371 | + if ($matches[1]) |
|
372 | 372 | { |
373 | 373 | preg_match('/ruleset="([^"]*?)"/is', $matches[1], $m); |
374 | - if($m[0]) |
|
374 | + if ($m[0]) |
|
375 | 375 | { |
376 | - $matches[1] = preg_replace('/' . addcslashes($m[0], '?$') . '/i', '', $matches[1]); |
|
376 | + $matches[1] = preg_replace('/'.addcslashes($m[0], '?$').'/i', '', $matches[1]); |
|
377 | 377 | |
378 | - if(strpos($m[1], '@') !== FALSE) |
|
378 | + if (strpos($m[1], '@') !== FALSE) |
|
379 | 379 | { |
380 | 380 | $path = str_replace('@', '', $m[1]); |
381 | - $path = './files/ruleset/' . $path . '.xml'; |
|
381 | + $path = './files/ruleset/'.$path.'.xml'; |
|
382 | 382 | } |
383 | - else if(strpos($m[1], '#') !== FALSE) |
|
383 | + else if (strpos($m[1], '#') !== FALSE) |
|
384 | 384 | { |
385 | 385 | $fileName = str_replace('#', '', $m[1]); |
386 | 386 | $fileName = str_replace('<?php echo ', '', $fileName); |
387 | 387 | $fileName = str_replace(' ?>', '', $fileName); |
388 | - $path = '#./files/ruleset/' . $fileName . '.xml'; |
|
388 | + $path = '#./files/ruleset/'.$fileName.'.xml'; |
|
389 | 389 | |
390 | 390 | preg_match('@(?:^|\.?/)(modules/[\w-]+)@', $this->path, $mm); |
391 | 391 | $module_path = $mm[1]; |
392 | 392 | list($rulsetFile) = explode('.', $fileName); |
393 | - $autoPath = $module_path . '/ruleset/' . $rulsetFile . '.xml'; |
|
393 | + $autoPath = $module_path.'/ruleset/'.$rulsetFile.'.xml'; |
|
394 | 394 | $m[1] = $rulsetFile; |
395 | 395 | } |
396 | - else if(preg_match('@(?:^|\.?/)(modules/[\w-]+)@', $this->path, $mm)) |
|
396 | + else if (preg_match('@(?:^|\.?/)(modules/[\w-]+)@', $this->path, $mm)) |
|
397 | 397 | { |
398 | 398 | $module_path = $mm[1]; |
399 | - $path = $module_path . '/ruleset/' . $m[1] . '.xml'; |
|
399 | + $path = $module_path.'/ruleset/'.$m[1].'.xml'; |
|
400 | 400 | } |
401 | 401 | |
402 | - $matches[2] = '<input type="hidden" name="ruleset" value="' . $m[1] . '" />' . $matches[2]; |
|
402 | + $matches[2] = '<input type="hidden" name="ruleset" value="'.$m[1].'" />'.$matches[2]; |
|
403 | 403 | //assign to addJsFile method for js dynamic recache |
404 | - $matches[1] = '<?php Context::addJsFile("' . $path . '", FALSE, "", 0, "body", TRUE, "' . $autoPath . '") ?' . '>' . $matches[1]; |
|
404 | + $matches[1] = '<?php Context::addJsFile("'.$path.'", FALSE, "", 0, "body", TRUE, "'.$autoPath.'") ?'.'>'.$matches[1]; |
|
405 | 405 | } |
406 | 406 | } |
407 | 407 | |
@@ -409,22 +409,22 @@ discard block |
||
409 | 409 | preg_match_all('/<input[^>]* name="(act|mid|vid)"/is', $matches[2], $m2); |
410 | 410 | $checkVar = array('act', 'mid', 'vid'); |
411 | 411 | $resultArray = array_diff($checkVar, $m2[1]); |
412 | - if(is_array($resultArray)) |
|
412 | + if (is_array($resultArray)) |
|
413 | 413 | { |
414 | 414 | $generatedHidden = ''; |
415 | - foreach($resultArray AS $key => $value) |
|
415 | + foreach ($resultArray AS $key => $value) |
|
416 | 416 | { |
417 | - $generatedHidden .= '<input type="hidden" name="' . $value . '" value="<?php echo $__Context->' . $value . ' ?>" />'; |
|
417 | + $generatedHidden .= '<input type="hidden" name="'.$value.'" value="<?php echo $__Context->'.$value.' ?>" />'; |
|
418 | 418 | } |
419 | - $matches[2] = $generatedHidden . $matches[2]; |
|
419 | + $matches[2] = $generatedHidden.$matches[2]; |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | // return url generate |
423 | - if(!preg_match('/no-error-return-url="true"/i', $matches[1])) |
|
423 | + if (!preg_match('/no-error-return-url="true"/i', $matches[1])) |
|
424 | 424 | { |
425 | 425 | preg_match('/<input[^>]*name="error_return_url"[^>]*>/is', $matches[2], $m3); |
426 | - if(!$m3[0]) |
|
427 | - $matches[2] = '<input type="hidden" name="error_return_url" value="<?php echo htmlspecialchars(getRequestUriByServerEnviroment(), ENT_COMPAT | ENT_HTML401, \'UTF-8\', false) ?>" />' . $matches[2]; |
|
426 | + if (!$m3[0]) |
|
427 | + $matches[2] = '<input type="hidden" name="error_return_url" value="<?php echo htmlspecialchars(getRequestUriByServerEnviroment(), ENT_COMPAT | ENT_HTML401, \'UTF-8\', false) ?>" />'.$matches[2]; |
|
428 | 428 | } |
429 | 429 | else |
430 | 430 | { |
@@ -442,7 +442,7 @@ discard block |
||
442 | 442 | */ |
443 | 443 | private function _fetch($buff) |
444 | 444 | { |
445 | - if(!$buff) |
|
445 | + if (!$buff) |
|
446 | 446 | { |
447 | 447 | return; |
448 | 448 | } |
@@ -450,20 +450,20 @@ discard block |
||
450 | 450 | $__Context = &$GLOBALS['__Context__']; |
451 | 451 | $__Context->tpl_path = $this->path; |
452 | 452 | |
453 | - if($_SESSION['is_logged']) |
|
453 | + if ($_SESSION['is_logged']) |
|
454 | 454 | { |
455 | 455 | $__Context->logged_info = Context::get('logged_info'); |
456 | 456 | } |
457 | 457 | |
458 | 458 | $level = ob_get_level(); |
459 | 459 | ob_start(); |
460 | - if(substr($buff, 0, 7) == 'file://') |
|
460 | + if (substr($buff, 0, 7) == 'file://') |
|
461 | 461 | { |
462 | - if(__DEBUG__) |
|
462 | + if (__DEBUG__) |
|
463 | 463 | { |
464 | 464 | //load cache file from disk |
465 | 465 | $eval_str = FileHandler::readFile(substr($buff, 7)); |
466 | - $eval_str_buffed = "?>" . $eval_str; |
|
466 | + $eval_str_buffed = "?>".$eval_str; |
|
467 | 467 | @eval($eval_str_buffed); |
468 | 468 | $error_info = error_get_last(); |
469 | 469 | //parse error |
@@ -479,7 +479,7 @@ discard block |
||
479 | 479 | } |
480 | 480 | else |
481 | 481 | { |
482 | - $eval_str = "?>" . $buff; |
|
482 | + $eval_str = "?>".$buff; |
|
483 | 483 | @eval($eval_str); |
484 | 484 | $error_info = error_get_last(); |
485 | 485 | //parse error |
@@ -508,31 +508,31 @@ discard block |
||
508 | 508 | private function _replacePath($match) |
509 | 509 | { |
510 | 510 | //return origin conde when src value started '${'. |
511 | - if(preg_match('@^\${@', $match[1])) |
|
511 | + if (preg_match('@^\${@', $match[1])) |
|
512 | 512 | { |
513 | 513 | return $match[0]; |
514 | 514 | } |
515 | 515 | |
516 | 516 | //return origin code when src value include variable. |
517 | - if(preg_match('@^[\'|"]\s*\.\s*\$@', $match[1])) |
|
517 | + if (preg_match('@^[\'|"]\s*\.\s*\$@', $match[1])) |
|
518 | 518 | { |
519 | 519 | return $match[0]; |
520 | 520 | } |
521 | 521 | |
522 | 522 | $src = preg_replace('@^(\./)+@', '', trim($match[1])); |
523 | 523 | |
524 | - $src = $this->web_path . $src; |
|
524 | + $src = $this->web_path.$src; |
|
525 | 525 | $src = str_replace('/./', '/', $src); |
526 | 526 | |
527 | 527 | // for backward compatibility |
528 | 528 | $src = preg_replace('@/((?:[\w-]+/)+)\1@', '/\1', $src); |
529 | 529 | |
530 | - while(($tmp = preg_replace('@[^/]+/\.\./@', '', $src, 1)) !== $src) |
|
530 | + while (($tmp = preg_replace('@[^/]+/\.\./@', '', $src, 1)) !== $src) |
|
531 | 531 | { |
532 | 532 | $src = $tmp; |
533 | 533 | } |
534 | 534 | |
535 | - return substr($match[0], 0, -strlen($match[1]) - 6) . "src=\"{$src}\""; |
|
535 | + return substr($match[0], 0, -strlen($match[1]) - 6)."src=\"{$src}\""; |
|
536 | 536 | } |
537 | 537 | |
538 | 538 | /** |
@@ -542,19 +542,19 @@ discard block |
||
542 | 542 | */ |
543 | 543 | private function _parseInline($buff) |
544 | 544 | { |
545 | - if(!preg_match_all('/<([a-zA-Z]+\d?)(?:\s)/', $buff, $match)) |
|
545 | + if (!preg_match_all('/<([a-zA-Z]+\d?)(?:\s)/', $buff, $match)) |
|
546 | 546 | { |
547 | 547 | return $buff; |
548 | 548 | } |
549 | 549 | |
550 | 550 | $tags = array_diff(array_unique($match[1]), $this->skipTags); |
551 | 551 | |
552 | - if(!count($tags)) |
|
552 | + if (!count($tags)) |
|
553 | 553 | { |
554 | 554 | return $buff; |
555 | 555 | } |
556 | 556 | |
557 | - $tags = '(?:' . implode('|', $tags) . ')'; |
|
557 | + $tags = '(?:'.implode('|', $tags).')'; |
|
558 | 558 | $split_regex = "@(<(?>/?{$tags})(?>[^<>\{\}\"']+|<!--.*?-->|{[^}]+}|\".*?\"|'.*?'|.)*?>)@s"; |
559 | 559 | |
560 | 560 | $nodes = preg_split($split_regex, $buff, -1, PREG_SPLIT_DELIM_CAPTURE); |
@@ -562,14 +562,14 @@ discard block |
||
562 | 562 | // list of self closing tags |
563 | 563 | $self_closing = array('area' => 1, 'base' => 1, 'basefont' => 1, 'br' => 1, 'hr' => 1, 'input' => 1, 'img' => 1, 'link' => 1, 'meta' => 1, 'param' => 1, 'frame' => 1, 'col' => 1); |
564 | 564 | |
565 | - for($idx = 1, $node_len = count($nodes); $idx < $node_len; $idx+=2) |
|
565 | + for ($idx = 1, $node_len = count($nodes); $idx < $node_len; $idx += 2) |
|
566 | 566 | { |
567 | - if(!($node = $nodes[$idx])) |
|
567 | + if (!($node = $nodes[$idx])) |
|
568 | 568 | { |
569 | 569 | continue; |
570 | 570 | } |
571 | 571 | |
572 | - if(preg_match_all('@\s(loop|cond)="([^"]+)"@', $node, $matches)) |
|
572 | + if (preg_match_all('@\s(loop|cond)="([^"]+)"@', $node, $matches)) |
|
573 | 573 | { |
574 | 574 | // this tag |
575 | 575 | $tag = substr($node, 1, strpos($node, ' ') - 1); |
@@ -578,37 +578,37 @@ discard block |
||
578 | 578 | $closing = 0; |
579 | 579 | |
580 | 580 | // process opening tag |
581 | - foreach($matches[1] as $n => $stmt) |
|
581 | + foreach ($matches[1] as $n => $stmt) |
|
582 | 582 | { |
583 | 583 | $expr = $matches[2][$n]; |
584 | 584 | $expr = $this->_replaceVar($expr); |
585 | 585 | $closing++; |
586 | 586 | |
587 | - switch($stmt) |
|
587 | + switch ($stmt) |
|
588 | 588 | { |
589 | 589 | case 'cond': |
590 | 590 | $nodes[$idx - 1] .= "<?php if({$expr}){ ?>"; |
591 | 591 | break; |
592 | 592 | case 'loop': |
593 | - if(!preg_match('@^(?:(.+?)=>(.+?)(?:,(.+?))?|(.*?;.*?;.*?)|(.+?)\s*=\s*(.+?))$@', $expr, $expr_m)) |
|
593 | + if (!preg_match('@^(?:(.+?)=>(.+?)(?:,(.+?))?|(.*?;.*?;.*?)|(.+?)\s*=\s*(.+?))$@', $expr, $expr_m)) |
|
594 | 594 | { |
595 | 595 | break; |
596 | 596 | } |
597 | - if($expr_m[1]) |
|
597 | + if ($expr_m[1]) |
|
598 | 598 | { |
599 | 599 | $expr_m[1] = trim($expr_m[1]); |
600 | 600 | $expr_m[2] = trim($expr_m[2]); |
601 | - if($expr_m[3]) |
|
601 | + if ($expr_m[3]) |
|
602 | 602 | { |
603 | - $expr_m[2] .= '=>' . trim($expr_m[3]); |
|
603 | + $expr_m[2] .= '=>'.trim($expr_m[3]); |
|
604 | 604 | } |
605 | 605 | $nodes[$idx - 1] .= "<?php if({$expr_m[1]}&&count({$expr_m[1]}))foreach({$expr_m[1]} as {$expr_m[2]}){ ?>"; |
606 | 606 | } |
607 | - elseif($expr_m[4]) |
|
607 | + elseif ($expr_m[4]) |
|
608 | 608 | { |
609 | 609 | $nodes[$idx - 1] .= "<?php for({$expr_m[4]}){ ?>"; |
610 | 610 | } |
611 | - elseif($expr_m[5]) |
|
611 | + elseif ($expr_m[5]) |
|
612 | 612 | { |
613 | 613 | $nodes[$idx - 1] .= "<?php while({$expr_m[5]}={$expr_m[6]}){ ?>"; |
614 | 614 | } |
@@ -618,28 +618,28 @@ discard block |
||
618 | 618 | $node = preg_replace('@\s(loop|cond)="([^"]+)"@', '', $node); |
619 | 619 | |
620 | 620 | // find closing tag |
621 | - $close_php = '<?php ' . str_repeat('}', $closing) . ' ?>'; |
|
621 | + $close_php = '<?php '.str_repeat('}', $closing).' ?>'; |
|
622 | 622 | // self closing tag |
623 | - if($node{1} == '!' || substr($node, -2, 1) == '/' || isset($self_closing[$tag])) |
|
623 | + if ($node{1} == '!' || substr($node, -2, 1) == '/' || isset($self_closing[$tag])) |
|
624 | 624 | { |
625 | - $nodes[$idx + 1] = $close_php . $nodes[$idx + 1]; |
|
625 | + $nodes[$idx + 1] = $close_php.$nodes[$idx + 1]; |
|
626 | 626 | } |
627 | 627 | else |
628 | 628 | { |
629 | 629 | $depth = 1; |
630 | - for($i = $idx + 2; $i < $node_len; $i+=2) |
|
630 | + for ($i = $idx + 2; $i < $node_len; $i += 2) |
|
631 | 631 | { |
632 | 632 | $nd = $nodes[$i]; |
633 | - if(strpos($nd, $tag) === 1) |
|
633 | + if (strpos($nd, $tag) === 1) |
|
634 | 634 | { |
635 | 635 | $depth++; |
636 | 636 | } |
637 | - elseif(strpos($nd, '/' . $tag) === 1) |
|
637 | + elseif (strpos($nd, '/'.$tag) === 1) |
|
638 | 638 | { |
639 | 639 | $depth--; |
640 | - if(!$depth) |
|
640 | + if (!$depth) |
|
641 | 641 | { |
642 | - $nodes[$i - 1] .= $nodes[$i] . $close_php; |
|
642 | + $nodes[$i - 1] .= $nodes[$i].$close_php; |
|
643 | 643 | $nodes[$i] = ''; |
644 | 644 | break; |
645 | 645 | } |
@@ -648,13 +648,13 @@ discard block |
||
648 | 648 | } |
649 | 649 | } |
650 | 650 | |
651 | - if(strpos($node, '|cond="') !== false) |
|
651 | + if (strpos($node, '|cond="') !== false) |
|
652 | 652 | { |
653 | 653 | $node = preg_replace('@(\s[-\w:]+(?:="[^"]+?")?)\|cond="(.+?)"@s', '<?php if($2){ ?>$1<?php } ?>', $node); |
654 | 654 | $node = $this->_replaceVar($node); |
655 | 655 | } |
656 | 656 | |
657 | - if($nodes[$idx] != $node) |
|
657 | + if ($nodes[$idx] != $node) |
|
658 | 658 | { |
659 | 659 | $nodes[$idx] = $node; |
660 | 660 | } |
@@ -675,7 +675,7 @@ discard block |
||
675 | 675 | { |
676 | 676 | $escape_option = 'noescape'; |
677 | 677 | |
678 | - if($this->safeguard) |
|
678 | + if ($this->safeguard) |
|
679 | 679 | { |
680 | 680 | $escape_option = 'autoescape'; |
681 | 681 | } |
@@ -686,14 +686,14 @@ discard block |
||
686 | 686 | } |
687 | 687 | |
688 | 688 | // {@ ... } or {$var} or {func(...)} |
689 | - if($m[1]) |
|
689 | + if ($m[1]) |
|
690 | 690 | { |
691 | - if(preg_match('@^(\w+)\(@', $m[1], $mm) && !function_exists($mm[1])) |
|
691 | + if (preg_match('@^(\w+)\(@', $m[1], $mm) && !function_exists($mm[1])) |
|
692 | 692 | { |
693 | 693 | return $m[0]; |
694 | 694 | } |
695 | 695 | |
696 | - if($m[1]{0} == '@') |
|
696 | + if ($m[1]{0} == '@') |
|
697 | 697 | { |
698 | 698 | $m[1] = $this->_replaceVar(substr($m[1], 1)); |
699 | 699 | return "<?php {$m[1]} ?>"; |
@@ -703,7 +703,7 @@ discard block |
||
703 | 703 | // Get escape options. |
704 | 704 | foreach ($this->ignoreEscape as $key => $value) |
705 | 705 | { |
706 | - if($this->ignoreEscape[$key]($m)) |
|
706 | + if ($this->ignoreEscape[$key]($m)) |
|
707 | 707 | { |
708 | 708 | $escape_option = 'noescape'; |
709 | 709 | break; |
@@ -734,7 +734,7 @@ discard block |
||
734 | 734 | $filter_option = $matches[2]; |
735 | 735 | if (!self::_isVar($filter_option) && !preg_match("/^'.*'$/", $filter_option) && !preg_match('/^".*"$/', $filter_option)) |
736 | 736 | { |
737 | - $filter_option = "'" . escape_sqstr($filter_option) . "'"; |
|
737 | + $filter_option = "'".escape_sqstr($filter_option)."'"; |
|
738 | 738 | } |
739 | 739 | else |
740 | 740 | { |
@@ -833,18 +833,18 @@ discard block |
||
833 | 833 | } |
834 | 834 | |
835 | 835 | // Apply the escape option and return. |
836 | - return '<?php echo ' . $this->_applyEscapeOption($var, $escape_option) . ' ?>'; |
|
836 | + return '<?php echo '.$this->_applyEscapeOption($var, $escape_option).' ?>'; |
|
837 | 837 | } |
838 | 838 | } |
839 | 839 | |
840 | - if($m[3]) |
|
840 | + if ($m[3]) |
|
841 | 841 | { |
842 | 842 | $attr = array(); |
843 | - if($m[5]) |
|
843 | + if ($m[5]) |
|
844 | 844 | { |
845 | - if(preg_match_all('@,(\w+)="([^"]+)"@', $m[6], $mm)) |
|
845 | + if (preg_match_all('@,(\w+)="([^"]+)"@', $m[6], $mm)) |
|
846 | 846 | { |
847 | - foreach($mm[1] as $idx => $name) |
|
847 | + foreach ($mm[1] as $idx => $name) |
|
848 | 848 | { |
849 | 849 | $attr[$name] = $mm[2][$idx]; |
850 | 850 | } |
@@ -853,21 +853,21 @@ discard block |
||
853 | 853 | } |
854 | 854 | else |
855 | 855 | { |
856 | - if(!preg_match_all('@ (\w+)="([^"]+)"@', $m[6], $mm)) |
|
856 | + if (!preg_match_all('@ (\w+)="([^"]+)"@', $m[6], $mm)) |
|
857 | 857 | { |
858 | 858 | return $m[0]; |
859 | 859 | } |
860 | - foreach($mm[1] as $idx => $name) |
|
860 | + foreach ($mm[1] as $idx => $name) |
|
861 | 861 | { |
862 | 862 | $attr[$name] = $mm[2][$idx]; |
863 | 863 | } |
864 | 864 | } |
865 | 865 | |
866 | - switch($m[3]) |
|
866 | + switch ($m[3]) |
|
867 | 867 | { |
868 | 868 | // <!--#include--> or <include ..> |
869 | 869 | case 'include': |
870 | - if(!$this->file || !$attr['target']) |
|
870 | + if (!$this->file || !$attr['target']) |
|
871 | 871 | { |
872 | 872 | return ''; |
873 | 873 | } |
@@ -875,7 +875,7 @@ discard block |
||
875 | 875 | $pathinfo = pathinfo($attr['target']); |
876 | 876 | $fileDir = $this->_getRelativeDir($pathinfo['dirname']); |
877 | 877 | |
878 | - if(!$fileDir) |
|
878 | + if (!$fileDir) |
|
879 | 879 | { |
880 | 880 | return ''; |
881 | 881 | } |
@@ -885,7 +885,7 @@ discard block |
||
885 | 885 | case 'load_js_plugin': |
886 | 886 | $plugin = $this->_replaceVar($m[5]); |
887 | 887 | $s = "<!--#JSPLUGIN:{$plugin}-->"; |
888 | - if(strpos($plugin, '$__Context') === false) |
|
888 | + if (strpos($plugin, '$__Context') === false) |
|
889 | 889 | { |
890 | 890 | $plugin = "'{$plugin}'"; |
891 | 891 | } |
@@ -901,13 +901,13 @@ discard block |
||
901 | 901 | $doUnload = ($m[3] === 'unload'); |
902 | 902 | $isRemote = !!preg_match('@^(https?:)?//@i', $attr['target']); |
903 | 903 | |
904 | - if(!$isRemote) |
|
904 | + if (!$isRemote) |
|
905 | 905 | { |
906 | - if(!preg_match('@^\.?/@', $attr['target'])) |
|
906 | + if (!preg_match('@^\.?/@', $attr['target'])) |
|
907 | 907 | { |
908 | - $attr['target'] = './' . $attr['target']; |
|
908 | + $attr['target'] = './'.$attr['target']; |
|
909 | 909 | } |
910 | - if(substr($attr['target'], -5) == '/lang') |
|
910 | + if (substr($attr['target'], -5) == '/lang') |
|
911 | 911 | { |
912 | 912 | $pathinfo['dirname'] .= '/lang'; |
913 | 913 | $pathinfo['basename'] = ''; |
@@ -916,18 +916,18 @@ discard block |
||
916 | 916 | |
917 | 917 | $relativeDir = $this->_getRelativeDir($pathinfo['dirname']); |
918 | 918 | |
919 | - $attr['target'] = $relativeDir . '/' . $pathinfo['basename']; |
|
919 | + $attr['target'] = $relativeDir.'/'.$pathinfo['basename']; |
|
920 | 920 | } |
921 | 921 | |
922 | - switch($pathinfo['extension']) |
|
922 | + switch ($pathinfo['extension']) |
|
923 | 923 | { |
924 | 924 | case 'xml': |
925 | - if($isRemote || $doUnload) |
|
925 | + if ($isRemote || $doUnload) |
|
926 | 926 | { |
927 | 927 | return ''; |
928 | 928 | } |
929 | 929 | // language file? |
930 | - if($pathinfo['basename'] == 'lang.xml' || substr($pathinfo['dirname'], -5) == '/lang') |
|
930 | + if ($pathinfo['basename'] == 'lang.xml' || substr($pathinfo['dirname'], -5) == '/lang') |
|
931 | 931 | { |
932 | 932 | $result = "Context::loadLang('{$relativeDir}');"; |
933 | 933 | } |
@@ -937,7 +937,7 @@ discard block |
||
937 | 937 | } |
938 | 938 | break; |
939 | 939 | case 'js': |
940 | - if($doUnload) |
|
940 | + if ($doUnload) |
|
941 | 941 | { |
942 | 942 | $result = "Context::unloadFile('{$attr['target']}','{$attr['targetie']}');"; |
943 | 943 | } |
@@ -948,7 +948,7 @@ discard block |
||
948 | 948 | } |
949 | 949 | break; |
950 | 950 | case 'css': |
951 | - if($doUnload) |
|
951 | + if ($doUnload) |
|
952 | 952 | { |
953 | 953 | $result = "Context::unloadFile('{$attr['target']}','{$attr['targetie']}','{$attr['media']}');"; |
954 | 954 | } |
@@ -961,20 +961,20 @@ discard block |
||
961 | 961 | } |
962 | 962 | |
963 | 963 | $result = "<?php {$result} ?>"; |
964 | - if($metafile) |
|
964 | + if ($metafile) |
|
965 | 965 | { |
966 | - $result = "<!--#Meta:{$metafile}-->" . $result; |
|
966 | + $result = "<!--#Meta:{$metafile}-->".$result; |
|
967 | 967 | } |
968 | 968 | |
969 | 969 | return $result; |
970 | 970 | // <config ...> |
971 | 971 | case 'config': |
972 | 972 | $result = ''; |
973 | - if(preg_match_all('@ (\w+)="([^"]+)"@', $m[6], $config_matches, PREG_SET_ORDER)) |
|
973 | + if (preg_match_all('@ (\w+)="([^"]+)"@', $m[6], $config_matches, PREG_SET_ORDER)) |
|
974 | 974 | { |
975 | - foreach($config_matches as $config_match) |
|
975 | + foreach ($config_matches as $config_match) |
|
976 | 976 | { |
977 | - $result .= "\$this->config->{$config_match[1]} = '" . trim(strtolower($config_match[2])) . "';"; |
|
977 | + $result .= "\$this->config->{$config_match[1]} = '".trim(strtolower($config_match[2]))."';"; |
|
978 | 978 | } |
979 | 979 | } |
980 | 980 | return "<?php {$result} ?>"; |
@@ -982,45 +982,45 @@ discard block |
||
982 | 982 | } |
983 | 983 | |
984 | 984 | // <[email protected]> such as <!--@if($cond)-->, <!--@else-->, <!--@end--> |
985 | - if($m[7]) |
|
985 | + if ($m[7]) |
|
986 | 986 | { |
987 | 987 | $m[7] = substr($m[7], 1); |
988 | - if(!$m[7]) |
|
988 | + if (!$m[7]) |
|
989 | 989 | { |
990 | - return '<?php ' . $this->_replaceVar($m[8]) . '{ ?>' . $m[9]; |
|
990 | + return '<?php '.$this->_replaceVar($m[8]).'{ ?>'.$m[9]; |
|
991 | 991 | } |
992 | - if(!preg_match('/^(?:((?:end)?(?:if|switch|for(?:each)?|while)|end)|(else(?:if)?)|(break@)?(case|default)|(break))$/', $m[7], $mm)) |
|
992 | + if (!preg_match('/^(?:((?:end)?(?:if|switch|for(?:each)?|while)|end)|(else(?:if)?)|(break@)?(case|default)|(break))$/', $m[7], $mm)) |
|
993 | 993 | { |
994 | 994 | return ''; |
995 | 995 | } |
996 | - if($mm[1]) |
|
996 | + if ($mm[1]) |
|
997 | 997 | { |
998 | - if($mm[1]{0} == 'e') |
|
998 | + if ($mm[1]{0} == 'e') |
|
999 | 999 | { |
1000 | - return '<?php } ?>' . $m[9]; |
|
1000 | + return '<?php } ?>'.$m[9]; |
|
1001 | 1001 | } |
1002 | 1002 | |
1003 | 1003 | $precheck = ''; |
1004 | - if($mm[1] == 'switch') |
|
1004 | + if ($mm[1] == 'switch') |
|
1005 | 1005 | { |
1006 | 1006 | $m[9] = ''; |
1007 | 1007 | } |
1008 | - elseif($mm[1] == 'foreach') |
|
1008 | + elseif ($mm[1] == 'foreach') |
|
1009 | 1009 | { |
1010 | 1010 | $var = preg_replace('/^\s*\(\s*(.+?) .*$/', '$1', $m[8]); |
1011 | 1011 | $precheck = "if({$var}&&count({$var}))"; |
1012 | 1012 | } |
1013 | - return '<?php ' . $this->_replaceVar($precheck . $m[7] . $m[8]) . '{ ?>' . $m[9]; |
|
1013 | + return '<?php '.$this->_replaceVar($precheck.$m[7].$m[8]).'{ ?>'.$m[9]; |
|
1014 | 1014 | } |
1015 | - if($mm[2]) |
|
1015 | + if ($mm[2]) |
|
1016 | 1016 | { |
1017 | - return "<?php }{$m[7]}" . $this->_replaceVar($m[8]) . "{ ?>" . $m[9]; |
|
1017 | + return "<?php }{$m[7]}".$this->_replaceVar($m[8])."{ ?>".$m[9]; |
|
1018 | 1018 | } |
1019 | - if($mm[4]) |
|
1019 | + if ($mm[4]) |
|
1020 | 1020 | { |
1021 | - return "<?php " . ($mm[3] ? 'break;' : '') . "{$m[7]} " . trim($m[8], '()') . ": ?>" . $m[9]; |
|
1021 | + return "<?php ".($mm[3] ? 'break;' : '')."{$m[7]} ".trim($m[8], '()').": ?>".$m[9]; |
|
1022 | 1022 | } |
1023 | - if($mm[5]) |
|
1023 | + if ($mm[5]) |
|
1024 | 1024 | { |
1025 | 1025 | return "<?php break; ?>"; |
1026 | 1026 | } |
@@ -1034,7 +1034,7 @@ discard block |
||
1034 | 1034 | */ |
1035 | 1035 | private function _applyEscapeOption($str, $escape_option = 'noescape') |
1036 | 1036 | { |
1037 | - switch($escape_option) |
|
1037 | + switch ($escape_option) |
|
1038 | 1038 | { |
1039 | 1039 | case 'escape': |
1040 | 1040 | return "escape({$str}, true)"; |
@@ -1058,30 +1058,30 @@ discard block |
||
1058 | 1058 | $_path = $path; |
1059 | 1059 | |
1060 | 1060 | $fileDir = strtr(realpath($this->path), '\\', '/'); |
1061 | - if($path{0} != '/') |
|
1061 | + if ($path{0} != '/') |
|
1062 | 1062 | { |
1063 | - $path = strtr(realpath($fileDir . '/' . $path), '\\', '/'); |
|
1063 | + $path = strtr(realpath($fileDir.'/'.$path), '\\', '/'); |
|
1064 | 1064 | } |
1065 | 1065 | |
1066 | 1066 | // for backward compatibility |
1067 | - if(!$path) |
|
1067 | + if (!$path) |
|
1068 | 1068 | { |
1069 | 1069 | $dirs = explode('/', $fileDir); |
1070 | 1070 | $paths = explode('/', $_path); |
1071 | 1071 | $idx = array_search($paths[0], $dirs); |
1072 | 1072 | |
1073 | - if($idx !== false) |
|
1073 | + if ($idx !== false) |
|
1074 | 1074 | { |
1075 | - while($dirs[$idx] && $dirs[$idx] === $paths[0]) |
|
1075 | + while ($dirs[$idx] && $dirs[$idx] === $paths[0]) |
|
1076 | 1076 | { |
1077 | 1077 | array_splice($dirs, $idx, 1); |
1078 | 1078 | array_shift($paths); |
1079 | 1079 | } |
1080 | - $path = strtr(realpath($fileDir . '/' . implode('/', $paths)), '\\', '/'); |
|
1080 | + $path = strtr(realpath($fileDir.'/'.implode('/', $paths)), '\\', '/'); |
|
1081 | 1081 | } |
1082 | 1082 | } |
1083 | 1083 | |
1084 | - $path = preg_replace('/^' . preg_quote(_XE_PATH_, '/') . '/', '', $path); |
|
1084 | + $path = preg_replace('/^'.preg_quote(_XE_PATH_, '/').'/', '', $path); |
|
1085 | 1085 | |
1086 | 1086 | return $path; |
1087 | 1087 | } |
@@ -1104,7 +1104,7 @@ discard block |
||
1104 | 1104 | */ |
1105 | 1105 | function _replaceVar($php) |
1106 | 1106 | { |
1107 | - if(!strlen($php)) |
|
1107 | + if (!strlen($php)) |
|
1108 | 1108 | { |
1109 | 1109 | return ''; |
1110 | 1110 | } |
@@ -1120,13 +1120,13 @@ discard block |
||
1120 | 1120 | $dirSkins = '(layouts\/default|layouts\/user_layout|layouts\/xedition|layouts\/xedition\/demo|m\.layouts\/colorCode|m\.layouts\/default|m\.layouts\/simpleGray|modules\/board\/m\.skins\/default|modules\/board\/m\.skins\/simpleGray|modules\/board\/skins\/default|modules\/board\/skins\/xedition|modules\/communication\/m\.skins\/default|modules\/communication\/skins\/default|modules\/editor\/skins\/ckeditor|modules\/editor\/skins\/xpresseditor|modules\/integration_search\/skins\/default|modules\/layout\/faceoff|modules\/member\/m\.skins\/default|modules\/member\/skins\/default|modules\/message\/m\.skins\/default|modules\/message\/skins\/default|modules\/message\/skins\/xedition|modules\/page\/m\.skins\/default|modules\/page\/skins\/default|modules\/poll\/skins\/default|modules\/poll\/skins\/simple|widgets\/content\/skins\/default|widgets\/counter_status\/skins\/default|widgets\/language_select\/skins\/default|widgets\/login_info\/skins\/default|widgets\/mcontent\/skins\/default|widgetstyles\/simple)'; |
1121 | 1121 | |
1122 | 1122 | // 'tpl' |
1123 | - if(preg_match('/^(\.\/)?(modules\/' . $dirTpl . '|common)\/tpl\//', $absPath)) |
|
1123 | + if (preg_match('/^(\.\/)?(modules\/'.$dirTpl.'|common)\/tpl\//', $absPath)) |
|
1124 | 1124 | { |
1125 | 1125 | return true; |
1126 | 1126 | } |
1127 | 1127 | |
1128 | 1128 | // skin, layout |
1129 | - if(preg_match('/^(\.\/)?(' . $dirSkin . '\//', $absPath)) |
|
1129 | + if (preg_match('/^(\.\/)?('.$dirSkin.'\//', $absPath)) |
|
1130 | 1130 | { |
1131 | 1131 | return true; |
1132 | 1132 | } |
@@ -113,8 +113,7 @@ discard block |
||
113 | 113 | if(!isset($GLOBALS['__TemplateHandlerCalled__'])) |
114 | 114 | { |
115 | 115 | $GLOBALS['__TemplateHandlerCalled__'] = 1; |
116 | - } |
|
117 | - else |
|
116 | + } else |
|
118 | 117 | { |
119 | 118 | $GLOBALS['__TemplateHandlerCalled__']++; |
120 | 119 | } |
@@ -219,8 +218,7 @@ discard block |
||
219 | 218 | { |
220 | 219 | $cache_key = 'template:' . $this->file; |
221 | 220 | $buff = $oCacheHandler->get($cache_key, $latest_mtime); |
222 | - } |
|
223 | - else |
|
221 | + } else |
|
224 | 222 | { |
225 | 223 | if(is_readable($this->compiled_file) && filemtime($this->compiled_file) > $latest_mtime && filesize($this->compiled_file)) |
226 | 224 | { |
@@ -234,8 +232,7 @@ discard block |
||
234 | 232 | if($oCacheHandler->isSupport()) |
235 | 233 | { |
236 | 234 | $oCacheHandler->put($cache_key, $buff); |
237 | - } |
|
238 | - else |
|
235 | + } else |
|
239 | 236 | { |
240 | 237 | FileHandler::writeFile($this->compiled_file, $buff); |
241 | 238 | } |
@@ -320,7 +317,9 @@ discard block |
||
320 | 317 | } |
321 | 318 | } |
322 | 319 | |
323 | - if($this->config->autoescape === 'on') $this->safeguard = true; |
|
320 | + if($this->config->autoescape === 'on') { |
|
321 | + $this->safeguard = true; |
|
322 | + } |
|
324 | 323 | |
325 | 324 | // replace comments |
326 | 325 | $buff = preg_replace('@<!--//.*?-->@s', '', $buff); |
@@ -379,8 +378,7 @@ discard block |
||
379 | 378 | { |
380 | 379 | $path = str_replace('@', '', $m[1]); |
381 | 380 | $path = './files/ruleset/' . $path . '.xml'; |
382 | - } |
|
383 | - else if(strpos($m[1], '#') !== FALSE) |
|
381 | + } else if(strpos($m[1], '#') !== FALSE) |
|
384 | 382 | { |
385 | 383 | $fileName = str_replace('#', '', $m[1]); |
386 | 384 | $fileName = str_replace('<?php echo ', '', $fileName); |
@@ -392,8 +390,7 @@ discard block |
||
392 | 390 | list($rulsetFile) = explode('.', $fileName); |
393 | 391 | $autoPath = $module_path . '/ruleset/' . $rulsetFile . '.xml'; |
394 | 392 | $m[1] = $rulsetFile; |
395 | - } |
|
396 | - else if(preg_match('@(?:^|\.?/)(modules/[\w-]+)@', $this->path, $mm)) |
|
393 | + } else if(preg_match('@(?:^|\.?/)(modules/[\w-]+)@', $this->path, $mm)) |
|
397 | 394 | { |
398 | 395 | $module_path = $mm[1]; |
399 | 396 | $path = $module_path . '/ruleset/' . $m[1] . '.xml'; |
@@ -423,10 +420,10 @@ discard block |
||
423 | 420 | if(!preg_match('/no-error-return-url="true"/i', $matches[1])) |
424 | 421 | { |
425 | 422 | preg_match('/<input[^>]*name="error_return_url"[^>]*>/is', $matches[2], $m3); |
426 | - if(!$m3[0]) |
|
427 | - $matches[2] = '<input type="hidden" name="error_return_url" value="<?php echo htmlspecialchars(getRequestUriByServerEnviroment(), ENT_COMPAT | ENT_HTML401, \'UTF-8\', false) ?>" />' . $matches[2]; |
|
428 | - } |
|
429 | - else |
|
423 | + if(!$m3[0]) { |
|
424 | + $matches[2] = '<input type="hidden" name="error_return_url" value="<?php echo htmlspecialchars(getRequestUriByServerEnviroment(), ENT_COMPAT | ENT_HTML401, \'UTF-8\', false) ?>" />' . $matches[2]; |
|
425 | + } |
|
426 | + } else |
|
430 | 427 | { |
431 | 428 | $matches[1] = preg_replace('/no-error-return-url="true"/i', '', $matches[1]); |
432 | 429 | } |
@@ -471,13 +468,11 @@ discard block |
||
471 | 468 | { |
472 | 469 | throw new Exception("Error Parsing Template - {$error_info['message']} in template file {$this->file}"); |
473 | 470 | } |
474 | - } |
|
475 | - else |
|
471 | + } else |
|
476 | 472 | { |
477 | 473 | include(substr($buff, 7)); |
478 | 474 | } |
479 | - } |
|
480 | - else |
|
475 | + } else |
|
481 | 476 | { |
482 | 477 | $eval_str = "?>" . $buff; |
483 | 478 | @eval($eval_str); |
@@ -603,12 +598,10 @@ discard block |
||
603 | 598 | $expr_m[2] .= '=>' . trim($expr_m[3]); |
604 | 599 | } |
605 | 600 | $nodes[$idx - 1] .= "<?php if({$expr_m[1]}&&count({$expr_m[1]}))foreach({$expr_m[1]} as {$expr_m[2]}){ ?>"; |
606 | - } |
|
607 | - elseif($expr_m[4]) |
|
601 | + } elseif($expr_m[4]) |
|
608 | 602 | { |
609 | 603 | $nodes[$idx - 1] .= "<?php for({$expr_m[4]}){ ?>"; |
610 | - } |
|
611 | - elseif($expr_m[5]) |
|
604 | + } elseif($expr_m[5]) |
|
612 | 605 | { |
613 | 606 | $nodes[$idx - 1] .= "<?php while({$expr_m[5]}={$expr_m[6]}){ ?>"; |
614 | 607 | } |
@@ -623,8 +616,7 @@ discard block |
||
623 | 616 | if($node{1} == '!' || substr($node, -2, 1) == '/' || isset($self_closing[$tag])) |
624 | 617 | { |
625 | 618 | $nodes[$idx + 1] = $close_php . $nodes[$idx + 1]; |
626 | - } |
|
627 | - else |
|
619 | + } else |
|
628 | 620 | { |
629 | 621 | $depth = 1; |
630 | 622 | for($i = $idx + 2; $i < $node_len; $i+=2) |
@@ -633,8 +625,7 @@ discard block |
||
633 | 625 | if(strpos($nd, $tag) === 1) |
634 | 626 | { |
635 | 627 | $depth++; |
636 | - } |
|
637 | - elseif(strpos($nd, '/' . $tag) === 1) |
|
628 | + } elseif(strpos($nd, '/' . $tag) === 1) |
|
638 | 629 | { |
639 | 630 | $depth--; |
640 | 631 | if(!$depth) |
@@ -697,8 +688,7 @@ discard block |
||
697 | 688 | { |
698 | 689 | $m[1] = $this->_replaceVar(substr($m[1], 1)); |
699 | 690 | return "<?php {$m[1]} ?>"; |
700 | - } |
|
701 | - else |
|
691 | + } else |
|
702 | 692 | { |
703 | 693 | // Get escape options. |
704 | 694 | foreach ($this->ignoreEscape as $key => $value) |
@@ -715,8 +705,7 @@ discard block |
||
715 | 705 | { |
716 | 706 | $m[1] = $mm[1]; |
717 | 707 | $filters = array_map('trim', explode_with_escape('|', substr($mm[2], 1))); |
718 | - } |
|
719 | - else |
|
708 | + } else |
|
720 | 709 | { |
721 | 710 | $filters = array(); |
722 | 711 | } |
@@ -735,13 +724,11 @@ discard block |
||
735 | 724 | if (!self::_isVar($filter_option) && !preg_match("/^'.*'$/", $filter_option) && !preg_match('/^".*"$/', $filter_option)) |
736 | 725 | { |
737 | 726 | $filter_option = "'" . escape_sqstr($filter_option) . "'"; |
738 | - } |
|
739 | - else |
|
727 | + } else |
|
740 | 728 | { |
741 | 729 | $filter_option = self::_replaceVar($filter_option); |
742 | 730 | } |
743 | - } |
|
744 | - else |
|
731 | + } else |
|
745 | 732 | { |
746 | 733 | $filter_option = null; |
747 | 734 | } |
@@ -817,8 +804,7 @@ discard block |
||
817 | 804 | { |
818 | 805 | $filter_option = $this->_applyEscapeOption($filter_option, 'autoescape'); |
819 | 806 | $var = "'<a href=\"' . {$filter_option} . '\">' . {$var} . '</a>'"; |
820 | - } |
|
821 | - else |
|
807 | + } else |
|
822 | 808 | { |
823 | 809 | $var = "'<a href=\"' . {$var} . '\">' . {$var} . '</a>'"; |
824 | 810 | } |
@@ -850,8 +836,7 @@ discard block |
||
850 | 836 | } |
851 | 837 | } |
852 | 838 | $attr['target'] = $m[5]; |
853 | - } |
|
854 | - else |
|
839 | + } else |
|
855 | 840 | { |
856 | 841 | if(!preg_match_all('@ (\w+)="([^"]+)"@', $m[6], $mm)) |
857 | 842 | { |
@@ -930,8 +915,7 @@ discard block |
||
930 | 915 | if($pathinfo['basename'] == 'lang.xml' || substr($pathinfo['dirname'], -5) == '/lang') |
931 | 916 | { |
932 | 917 | $result = "Context::loadLang('{$relativeDir}');"; |
933 | - } |
|
934 | - else |
|
918 | + } else |
|
935 | 919 | { |
936 | 920 | $result = "require_once('./classes/xml/XmlJsFilter.class.php');\$__xmlFilter=new XmlJsFilter('{$relativeDir}','{$pathinfo['basename']}');\$__xmlFilter->compile();"; |
937 | 921 | } |
@@ -940,8 +924,7 @@ discard block |
||
940 | 924 | if($doUnload) |
941 | 925 | { |
942 | 926 | $result = "Context::unloadFile('{$attr['target']}','{$attr['targetie']}');"; |
943 | - } |
|
944 | - else |
|
927 | + } else |
|
945 | 928 | { |
946 | 929 | $metafile = $attr['target']; |
947 | 930 | $result = "\$__tmp=array('{$attr['target']}','{$attr['type']}','{$attr['targetie']}','{$attr['index']}');Context::loadFile(\$__tmp);unset(\$__tmp);"; |
@@ -951,8 +934,7 @@ discard block |
||
951 | 934 | if($doUnload) |
952 | 935 | { |
953 | 936 | $result = "Context::unloadFile('{$attr['target']}','{$attr['targetie']}','{$attr['media']}');"; |
954 | - } |
|
955 | - else |
|
937 | + } else |
|
956 | 938 | { |
957 | 939 | $metafile = $attr['target']; |
958 | 940 | $result = "\$__tmp=array('{$attr['target']}','{$attr['media']}','{$attr['targetie']}','{$attr['index']}');Context::loadFile(\$__tmp);unset(\$__tmp);"; |
@@ -1004,8 +986,7 @@ discard block |
||
1004 | 986 | if($mm[1] == 'switch') |
1005 | 987 | { |
1006 | 988 | $m[9] = ''; |
1007 | - } |
|
1008 | - elseif($mm[1] == 'foreach') |
|
989 | + } elseif($mm[1] == 'foreach') |
|
1009 | 990 | { |
1010 | 991 | $var = preg_replace('/^\s*\(\s*(.+?) .*$/', '$1', $m[8]); |
1011 | 992 | $precheck = "if({$var}&&count({$var}))"; |
@@ -1113,7 +1094,9 @@ discard block |
||
1113 | 1094 | |
1114 | 1095 | function isSafeguard() |
1115 | 1096 | { |
1116 | - if ($this->dbinfo->safeguard === 'Y') return true; |
|
1097 | + if ($this->dbinfo->safeguard === 'Y') { |
|
1098 | + return true; |
|
1099 | + } |
|
1117 | 1100 | |
1118 | 1101 | $absPath = str_replace(_XE_PATH_, '', $this->path); |
1119 | 1102 | $dirTpl = '(addon|admin|adminlogging|autoinstall|board|comment|communication|counter|document|editor|file|importer|install|integration_search|krzip|layout|member|menu|message|module|page|point|poll|rss|seo|session|spamfilter|syndication|tag|trash|widget)'; |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | |
240 | 240 | /** |
241 | 241 | * Validate the fields. If the fields aren't passed, validation will be execute on the Context variables. |
242 | - * @param array $fields Target fields. The keys of the array represents field's name, its values represents field's value. |
|
242 | + * @param array $fields_ Target fields. The keys of the array represents field's name, its values represents field's value. |
|
243 | 243 | * @return boolean TRUE if it is valid, FALSE otherwise. |
244 | 244 | */ |
245 | 245 | function validate($fields_ = null) |
@@ -456,7 +456,7 @@ discard block |
||
456 | 456 | |
457 | 457 | /** |
458 | 458 | * Log an error |
459 | - * @param $msg error message |
|
459 | + * @param string $msg error message |
|
460 | 460 | * @return boolean always false |
461 | 461 | */ |
462 | 462 | function error($field, $msg) |
@@ -81,8 +81,9 @@ discard block |
||
81 | 81 | $this->_filters = array(); |
82 | 82 | $this->_xml_ruleset = NULL; |
83 | 83 | |
84 | - if($xml_path) |
|
85 | - $this->load($xml_path); |
|
84 | + if($xml_path) { |
|
85 | + $this->load($xml_path); |
|
86 | + } |
|
86 | 87 | |
87 | 88 | // predefined rules |
88 | 89 | $this->addRule(array( |
@@ -247,8 +248,7 @@ discard block |
||
247 | 248 | if(is_array($fields_)) |
248 | 249 | { |
249 | 250 | $fields = $fields_; |
250 | - } |
|
251 | - else |
|
251 | + } else |
|
252 | 252 | { |
253 | 253 | $args = array_keys($this->_filters); |
254 | 254 | $fields = (array) Context::getRequestVars(); |
@@ -281,13 +281,11 @@ discard block |
||
281 | 281 | if($key{0} == '^') |
282 | 282 | { |
283 | 283 | $names = preg_grep('/^' . preg_quote(substr($key, 1)) . '/', $field_names); |
284 | - } |
|
285 | - elseif(substr($key, -2) == '[]') |
|
284 | + } elseif(substr($key, -2) == '[]') |
|
286 | 285 | { |
287 | 286 | $filters[substr($key, 0, -2)] = $filter; |
288 | 287 | unset($filters[$key]); |
289 | - } |
|
290 | - else |
|
288 | + } else |
|
291 | 289 | { |
292 | 290 | $filters[$key] = $filter; |
293 | 291 | } |
@@ -313,8 +311,7 @@ discard block |
||
313 | 311 | { |
314 | 312 | $exists = array_key_exists($matches[1], $fields); |
315 | 313 | $value = $exists ? $fields[$matches[1]][$matches[2]] : NULL; |
316 | - } |
|
317 | - else |
|
314 | + } else |
|
318 | 315 | { |
319 | 316 | $exists = array_key_exists($key, $fields); |
320 | 317 | $value = $exists ? $fields[$fname] : NULL; |
@@ -325,8 +322,7 @@ discard block |
||
325 | 322 | if(!isset($value[tmp_name])) |
326 | 323 | { |
327 | 324 | $value = implode('', $value); |
328 | - } |
|
329 | - else |
|
325 | + } else |
|
330 | 326 | { |
331 | 327 | $value = $value['name']; |
332 | 328 | } |
@@ -356,8 +352,7 @@ discard block |
||
356 | 352 | if(is_null($fields_)) |
357 | 353 | { |
358 | 354 | Context::set($fname, $value); |
359 | - } |
|
360 | - else |
|
355 | + } else |
|
361 | 356 | { |
362 | 357 | $fields_[$fname] = $value; |
363 | 358 | } |
@@ -464,8 +459,7 @@ discard block |
||
464 | 459 | if(isset($this->_message[$msg])) |
465 | 460 | { |
466 | 461 | $msg = $this->_message[$msg]; |
467 | - } |
|
468 | - else |
|
462 | + } else |
|
469 | 463 | { |
470 | 464 | $lang_filter = Context::getLang('filter'); |
471 | 465 | $msg = isset($lang_filter->{$msg}) ? $lang_filter->{$msg} : $lang_filter->invalid; |
@@ -474,8 +468,7 @@ discard block |
||
474 | 468 | if(isset($this->_fieldNames[$field])) |
475 | 469 | { |
476 | 470 | $fieldName = $this->_fieldNames[$field]; |
477 | - } |
|
478 | - else |
|
471 | + } else |
|
479 | 472 | { |
480 | 473 | $fieldName = Context::getLang($field); |
481 | 474 | } |
@@ -507,8 +500,7 @@ discard block |
||
507 | 500 | if(is_array($name)) |
508 | 501 | { |
509 | 502 | $args = $name; |
510 | - } |
|
511 | - else |
|
503 | + } else |
|
512 | 504 | { |
513 | 505 | $args = array($name => $rule); |
514 | 506 | } |
@@ -555,8 +547,7 @@ discard block |
||
555 | 547 | if(is_array($name)) |
556 | 548 | { |
557 | 549 | $args = $name; |
558 | - } |
|
559 | - else |
|
550 | + } else |
|
560 | 551 | { |
561 | 552 | $args = array($name => $filter); |
562 | 553 | } |
@@ -577,8 +568,7 @@ discard block |
||
577 | 568 | { |
578 | 569 | $filter['if'] = array($filter['if']); |
579 | 570 | } |
580 | - } |
|
581 | - else |
|
571 | + } else |
|
582 | 572 | { |
583 | 573 | unset($filter['if']); |
584 | 574 | } |
@@ -753,8 +743,7 @@ discard block |
||
753 | 743 | { |
754 | 744 | $field_lang = addslashes($filter['title']); |
755 | 745 | $messages[] = "v.cast('ADD_MESSAGE',['{$name}','{$field_lang}']);"; |
756 | - } |
|
757 | - elseif(isset($lang->{$name})) |
|
746 | + } elseif(isset($lang->{$name})) |
|
758 | 747 | { |
759 | 748 | $field_lang = addslashes($lang->{$name}); |
760 | 749 | $messages[] = "v.cast('ADD_MESSAGE',['{$name}','{$field_lang}']);"; |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | $this->_filters = array(); |
82 | 82 | $this->_xml_ruleset = NULL; |
83 | 83 | |
84 | - if($xml_path) |
|
84 | + if ($xml_path) |
|
85 | 85 | $this->load($xml_path); |
86 | 86 | |
87 | 87 | // predefined rules |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | )); |
97 | 97 | |
98 | 98 | $this->_has_mb_func = is_callable('mb_strlen'); |
99 | - $this->setCacheDir(_XE_PATH_ . 'files/cache'); |
|
99 | + $this->setCacheDir(_XE_PATH_.'files/cache'); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -119,32 +119,32 @@ discard block |
||
119 | 119 | $this->_xml_ruleset = NULL; |
120 | 120 | |
121 | 121 | $xml_path = realpath($xml_path); |
122 | - if(!is_readable($xml_path)) |
|
122 | + if (!is_readable($xml_path)) |
|
123 | 123 | { |
124 | 124 | return FALSE; |
125 | 125 | } |
126 | 126 | |
127 | 127 | $parser = new XmlParser(); |
128 | 128 | $xml = $parser->loadXmlFile($xml_path); |
129 | - if(!isset($xml->ruleset) || !isset($xml->ruleset->fields) || !isset($xml->ruleset->fields->field)) |
|
129 | + if (!isset($xml->ruleset) || !isset($xml->ruleset->fields) || !isset($xml->ruleset->fields->field)) |
|
130 | 130 | { |
131 | 131 | return FALSE; |
132 | 132 | } |
133 | 133 | |
134 | 134 | // custom rules |
135 | - if(isset($xml->ruleset->customrules) && isset($xml->ruleset->customrules->rule)) |
|
135 | + if (isset($xml->ruleset->customrules) && isset($xml->ruleset->customrules->rule)) |
|
136 | 136 | { |
137 | 137 | $customrules = $xml->ruleset->customrules->rule; |
138 | - if(!is_array($customrules)) |
|
138 | + if (!is_array($customrules)) |
|
139 | 139 | { |
140 | 140 | $customrules = array($customrules); |
141 | 141 | } |
142 | 142 | |
143 | 143 | $rules = array(); |
144 | 144 | $messages = array(); |
145 | - foreach($customrules as $rule) |
|
145 | + foreach ($customrules as $rule) |
|
146 | 146 | { |
147 | - if(!isset($rule->attrs) || !isset($rule->attrs->name)) |
|
147 | + if (!isset($rule->attrs) || !isset($rule->attrs->name)) |
|
148 | 148 | { |
149 | 149 | continue; |
150 | 150 | } |
@@ -156,12 +156,12 @@ discard block |
||
156 | 156 | unset($rule['name']); |
157 | 157 | |
158 | 158 | $rules[$name] = $rule; |
159 | - if(isset($message)) |
|
159 | + if (isset($message)) |
|
160 | 160 | { |
161 | - $messages['invalid_' . $name] = $message; |
|
161 | + $messages['invalid_'.$name] = $message; |
|
162 | 162 | } |
163 | 163 | } |
164 | - if(count($rules)) |
|
164 | + if (count($rules)) |
|
165 | 165 | { |
166 | 166 | $this->addRule($rules); |
167 | 167 | } |
@@ -169,19 +169,19 @@ discard block |
||
169 | 169 | |
170 | 170 | // filters |
171 | 171 | $fields = $xml->ruleset->fields->field; |
172 | - if(!is_array($fields)) |
|
172 | + if (!is_array($fields)) |
|
173 | 173 | { |
174 | 174 | $fields = array($fields); |
175 | 175 | } |
176 | 176 | |
177 | 177 | $filters = array(); |
178 | 178 | $fieldsNames = array(); |
179 | - foreach($fields as $field) |
|
179 | + foreach ($fields as $field) |
|
180 | 180 | { |
181 | 181 | $name = ''; |
182 | 182 | $filter = array(); |
183 | 183 | |
184 | - if(!isset($field->attrs) || !isset($field->attrs->name)) |
|
184 | + if (!isset($field->attrs) || !isset($field->attrs->name)) |
|
185 | 185 | { |
186 | 186 | continue; |
187 | 187 | } |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | $filter['title'] = $title; |
192 | 192 | |
193 | 193 | $name = $filter['name']; |
194 | - if(isset($title)) |
|
194 | + if (isset($title)) |
|
195 | 195 | { |
196 | 196 | $fieldsNames[$name] = $title; |
197 | 197 | } |
@@ -199,14 +199,14 @@ discard block |
||
199 | 199 | unset($filter['name']); |
200 | 200 | |
201 | 201 | // conditional statement |
202 | - if(isset($field->if)) |
|
202 | + if (isset($field->if)) |
|
203 | 203 | { |
204 | 204 | $if = $field->if; |
205 | - if(!is_array($if)) |
|
205 | + if (!is_array($if)) |
|
206 | 206 | { |
207 | 207 | $if = array($if); |
208 | 208 | } |
209 | - foreach($if as $idx => $cond) |
|
209 | + foreach ($if as $idx => $cond) |
|
210 | 210 | { |
211 | 211 | $if[$idx] = (array) $cond->attrs; |
212 | 212 | } |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | */ |
233 | 233 | function setCacheDir($cache_dir) |
234 | 234 | { |
235 | - if(is_dir($cache_dir)) |
|
235 | + if (is_dir($cache_dir)) |
|
236 | 236 | { |
237 | 237 | $this->_cache_dir = preg_replace('@/$@', '', $cache_dir); |
238 | 238 | } |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | */ |
246 | 246 | function validate($fields_ = null) |
247 | 247 | { |
248 | - if(is_array($fields_)) |
|
248 | + if (is_array($fields_)) |
|
249 | 249 | { |
250 | 250 | $fields = $fields_; |
251 | 251 | } |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | $fields = (array) Context::getRequestVars(); |
256 | 256 | } |
257 | 257 | |
258 | - if(!is_array($fields)) |
|
258 | + if (!is_array($fields)) |
|
259 | 259 | { |
260 | 260 | return TRUE; |
261 | 261 | } |
@@ -276,14 +276,14 @@ discard block |
||
276 | 276 | $filters = array(); |
277 | 277 | |
278 | 278 | // get field names matching patterns |
279 | - foreach($this->_filters as $key => $filter) |
|
279 | + foreach ($this->_filters as $key => $filter) |
|
280 | 280 | { |
281 | 281 | $names = array(); |
282 | - if($key{0} == '^') |
|
282 | + if ($key{0} == '^') |
|
283 | 283 | { |
284 | - $names = preg_grep('/^' . preg_quote(substr($key, 1)) . '/', $field_names); |
|
284 | + $names = preg_grep('/^'.preg_quote(substr($key, 1)).'/', $field_names); |
|
285 | 285 | } |
286 | - elseif(substr($key, -2) == '[]') |
|
286 | + elseif (substr($key, -2) == '[]') |
|
287 | 287 | { |
288 | 288 | $filters[substr($key, 0, -2)] = $filter; |
289 | 289 | unset($filters[$key]); |
@@ -293,24 +293,24 @@ discard block |
||
293 | 293 | $filters[$key] = $filter; |
294 | 294 | } |
295 | 295 | |
296 | - if(!count($names)) |
|
296 | + if (!count($names)) |
|
297 | 297 | { |
298 | 298 | continue; |
299 | 299 | } |
300 | 300 | |
301 | - foreach($names as $name) |
|
301 | + foreach ($names as $name) |
|
302 | 302 | { |
303 | 303 | $filters[$name] = $filter; |
304 | 304 | } |
305 | 305 | unset($filters[$key]); |
306 | 306 | } |
307 | 307 | |
308 | - foreach($filters as $key => $filter) |
|
308 | + foreach ($filters as $key => $filter) |
|
309 | 309 | { |
310 | 310 | $fname = preg_replace('/\[\]$/', '', $key); |
311 | 311 | $filter = array_merge($filter_default, $filter); |
312 | 312 | |
313 | - if(preg_match("/(^[a-z_]*)[\[](?:\'|\")?([a-z_]*)(?:\'|\")?[\]]$/i", $key, $matches)) |
|
313 | + if (preg_match("/(^[a-z_]*)[\[](?:\'|\")?([a-z_]*)(?:\'|\")?[\]]$/i", $key, $matches)) |
|
314 | 314 | { |
315 | 315 | $exists = array_key_exists($matches[1], $fields); |
316 | 316 | $value = $exists ? $fields[$matches[1]][$matches[2]] : NULL; |
@@ -321,9 +321,9 @@ discard block |
||
321 | 321 | $value = $exists ? $fields[$fname] : NULL; |
322 | 322 | } |
323 | 323 | |
324 | - if(is_array($value)) |
|
324 | + if (is_array($value)) |
|
325 | 325 | { |
326 | - if(!isset($value[tmp_name])) |
|
326 | + if (!isset($value[tmp_name])) |
|
327 | 327 | { |
328 | 328 | $value = implode('', $value); |
329 | 329 | } |
@@ -334,9 +334,9 @@ discard block |
||
334 | 334 | } |
335 | 335 | |
336 | 336 | // conditional statement |
337 | - foreach($filter['if'] as $cond) |
|
337 | + foreach ($filter['if'] as $cond) |
|
338 | 338 | { |
339 | - if(!isset($cond['test']) || !isset($cond['attr'])) |
|
339 | + if (!isset($cond['test']) || !isset($cond['attr'])) |
|
340 | 340 | { |
341 | 341 | continue; |
342 | 342 | } |
@@ -344,17 +344,17 @@ discard block |
||
344 | 344 | $func_body = preg_replace('/\\$(\w+)/', '$c[\'$1\']', $cond['test']); |
345 | 345 | $func = create_function('$c', "return !!({$func_body});"); |
346 | 346 | |
347 | - if($func($fields)) |
|
347 | + if ($func($fields)) |
|
348 | 348 | { |
349 | 349 | $filter[$cond['attr']] = $cond['value']; |
350 | 350 | } |
351 | 351 | } |
352 | 352 | |
353 | 353 | // attr : default |
354 | - if(!$value && strlen($default = trim($filter['default']))) |
|
354 | + if (!$value && strlen($default = trim($filter['default']))) |
|
355 | 355 | { |
356 | 356 | $value = $default; |
357 | - if(is_null($fields_)) |
|
357 | + if (is_null($fields_)) |
|
358 | 358 | { |
359 | 359 | Context::set($fname, $value); |
360 | 360 | } |
@@ -366,25 +366,25 @@ discard block |
||
366 | 366 | $value_len = strlen($value); |
367 | 367 | |
368 | 368 | // attr : modifier |
369 | - if(is_string($modifiers = $filter['modifiers'])) |
|
369 | + if (is_string($modifiers = $filter['modifiers'])) |
|
370 | 370 | { |
371 | 371 | $modifiers = explode(',', trim($modifiers)); |
372 | 372 | } |
373 | 373 | |
374 | 374 | // attr : required |
375 | - if($filter['required'] === 'true' && !$value_len) |
|
375 | + if ($filter['required'] === 'true' && !$value_len) |
|
376 | 376 | { |
377 | 377 | return $this->error($key, 'isnull'); |
378 | 378 | } |
379 | 379 | |
380 | 380 | // if the field wasn't passed, ignore this value |
381 | - if(!$exists && !$value_len) |
|
381 | + if (!$exists && !$value_len) |
|
382 | 382 | { |
383 | 383 | continue; |
384 | 384 | } |
385 | 385 | |
386 | 386 | // attr : length |
387 | - if($length = $filter['length']) |
|
387 | + if ($length = $filter['length']) |
|
388 | 388 | { |
389 | 389 | list($min, $max) = explode(':', trim($length)); |
390 | 390 | $is_min_b = (substr($min, -1) === 'b'); |
@@ -392,41 +392,41 @@ discard block |
||
392 | 392 | list($min, $max) = array((int) $min, (int) $max); |
393 | 393 | |
394 | 394 | $strbytes = strlen($value); |
395 | - if(!$is_min_b || !$is_max_b) |
|
395 | + if (!$is_min_b || !$is_max_b) |
|
396 | 396 | { |
397 | 397 | $strlength = $this->_has_mb_func ? mb_strlen($value, 'utf-8') : $this->mbStrLen($value); |
398 | 398 | } |
399 | 399 | |
400 | - if(($min && $min > ($is_min_b ? $strbytes : $strlength)) || ($max && $max < ($is_max_b ? $strbytes : $strlength))) |
|
400 | + if (($min && $min > ($is_min_b ? $strbytes : $strlength)) || ($max && $max < ($is_max_b ? $strbytes : $strlength))) |
|
401 | 401 | { |
402 | 402 | return $this->error($key, 'outofrange'); |
403 | 403 | } |
404 | 404 | } |
405 | 405 | |
406 | 406 | // equalto |
407 | - if($equalto = $filter['equalto']) |
|
407 | + if ($equalto = $filter['equalto']) |
|
408 | 408 | { |
409 | - if(!array_key_exists($equalto, $fields) || trim($fields[$equalto]) !== $value) |
|
409 | + if (!array_key_exists($equalto, $fields) || trim($fields[$equalto]) !== $value) |
|
410 | 410 | { |
411 | 411 | return $this->error($key, 'equalto'); |
412 | 412 | } |
413 | 413 | } |
414 | 414 | |
415 | 415 | // rules |
416 | - if($rules = $filter['rule']) |
|
416 | + if ($rules = $filter['rule']) |
|
417 | 417 | { |
418 | 418 | $rules = explode(',', $rules); |
419 | - foreach($rules as $rule) |
|
419 | + foreach ($rules as $rule) |
|
420 | 420 | { |
421 | 421 | $result = $this->applyRule($rule, $value); |
422 | 422 | // apply the 'not' modifier |
423 | - if(in_array('not', $modifiers)) |
|
423 | + if (in_array('not', $modifiers)) |
|
424 | 424 | { |
425 | 425 | $result = !$result; |
426 | 426 | } |
427 | - if(!$result) |
|
427 | + if (!$result) |
|
428 | 428 | { |
429 | - return $this->error($key, 'invalid_' . $rule); |
|
429 | + return $this->error($key, 'invalid_'.$rule); |
|
430 | 430 | } |
431 | 431 | } |
432 | 432 | } |
@@ -442,12 +442,12 @@ discard block |
||
442 | 442 | */ |
443 | 443 | function arrayTrim($array) |
444 | 444 | { |
445 | - if(!is_array($array)) |
|
445 | + if (!is_array($array)) |
|
446 | 446 | { |
447 | 447 | return trim($array); |
448 | 448 | } |
449 | 449 | |
450 | - foreach($array as $key => $value) |
|
450 | + foreach ($array as $key => $value) |
|
451 | 451 | { |
452 | 452 | $array[$key] = $this->arrayTrim($value); |
453 | 453 | } |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | */ |
463 | 463 | function error($field, $msg) |
464 | 464 | { |
465 | - if(isset($this->_message[$msg])) |
|
465 | + if (isset($this->_message[$msg])) |
|
466 | 466 | { |
467 | 467 | $msg = $this->_message[$msg]; |
468 | 468 | } |
@@ -472,7 +472,7 @@ discard block |
||
472 | 472 | $msg = isset($lang_filter->{$msg}) ? $lang_filter->{$msg} : $lang_filter->invalid; |
473 | 473 | } |
474 | 474 | |
475 | - if(isset($this->_fieldNames[$field])) |
|
475 | + if (isset($this->_fieldNames[$field])) |
|
476 | 476 | { |
477 | 477 | $fieldName = $this->_fieldNames[$field]; |
478 | 478 | } |
@@ -505,7 +505,7 @@ discard block |
||
505 | 505 | */ |
506 | 506 | function addRule($name, $rule = '') |
507 | 507 | { |
508 | - if(is_array($name)) |
|
508 | + if (is_array($name)) |
|
509 | 509 | { |
510 | 510 | $args = $name; |
511 | 511 | } |
@@ -514,18 +514,18 @@ discard block |
||
514 | 514 | $args = array($name => $rule); |
515 | 515 | } |
516 | 516 | |
517 | - foreach($args as $name => $rule) |
|
517 | + foreach ($args as $name => $rule) |
|
518 | 518 | { |
519 | - if(!$rule) |
|
519 | + if (!$rule) |
|
520 | 520 | { |
521 | 521 | continue; |
522 | 522 | } |
523 | - if(is_string($rule)) |
|
523 | + if (is_string($rule)) |
|
524 | 524 | { |
525 | 525 | $rule = array('type' => 'regex', 'test' => $rule); |
526 | 526 | } |
527 | 527 | |
528 | - if($rule['type'] == 'enum') |
|
528 | + if ($rule['type'] == 'enum') |
|
529 | 529 | { |
530 | 530 | $delim = isset($rule['delim']) ? $rule['delim'] : ','; |
531 | 531 | $rule['test'] = explode($delim, $rule['test']); |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | */ |
554 | 554 | function addFilter($name, $filter = '') |
555 | 555 | { |
556 | - if(is_array($name)) |
|
556 | + if (is_array($name)) |
|
557 | 557 | { |
558 | 558 | $args = $name; |
559 | 559 | } |
@@ -562,19 +562,19 @@ discard block |
||
562 | 562 | $args = array($name => $filter); |
563 | 563 | } |
564 | 564 | |
565 | - foreach($args as $name => $filter) |
|
565 | + foreach ($args as $name => $filter) |
|
566 | 566 | { |
567 | - if(!$filter) |
|
567 | + if (!$filter) |
|
568 | 568 | { |
569 | 569 | continue; |
570 | 570 | } |
571 | 571 | |
572 | - if(isset($filter['if'])) |
|
572 | + if (isset($filter['if'])) |
|
573 | 573 | { |
574 | - if(is_array($filter['if']) && count($filter['if'])) |
|
574 | + if (is_array($filter['if']) && count($filter['if'])) |
|
575 | 575 | { |
576 | 576 | $key = key($filter['if']); |
577 | - if(!is_int($key)) |
|
577 | + if (!is_int($key)) |
|
578 | 578 | { |
579 | 579 | $filter['if'] = array($filter['if']); |
580 | 580 | } |
@@ -609,21 +609,21 @@ discard block |
||
609 | 609 | { |
610 | 610 | $rule = $this->_rules[$name]; |
611 | 611 | |
612 | - if(is_array($value) && isset($value['tmp_name'])) |
|
612 | + if (is_array($value) && isset($value['tmp_name'])) |
|
613 | 613 | { |
614 | 614 | $value = $value['name']; |
615 | 615 | } |
616 | 616 | |
617 | - switch($rule['type']) |
|
617 | + switch ($rule['type']) |
|
618 | 618 | { |
619 | 619 | case 'regex': |
620 | 620 | return (preg_match($rule['test'], $value) > 0); |
621 | 621 | case 'enum': |
622 | 622 | return in_array($value, $rule['test']); |
623 | 623 | case 'expr': |
624 | - if(!$rule['func_test']) |
|
624 | + if (!$rule['func_test']) |
|
625 | 625 | { |
626 | - $rule['func_test'] = create_function('$a', 'return (' . preg_replace('/\$\$/', '$a', html_entity_decode($rule['test'])) . ');'); |
|
626 | + $rule['func_test'] = create_function('$a', 'return ('.preg_replace('/\$\$/', '$a', html_entity_decode($rule['test'])).');'); |
|
627 | 627 | } |
628 | 628 | return $rule['func_test']($value); |
629 | 629 | } |
@@ -639,7 +639,7 @@ discard block |
||
639 | 639 | function mbStrLen($str) |
640 | 640 | { |
641 | 641 | $arr = count_chars($str); |
642 | - for($i = 0x80; $i < 0xc0; $i++) |
|
642 | + for ($i = 0x80; $i < 0xc0; $i++) |
|
643 | 643 | { |
644 | 644 | unset($arr[$i]); |
645 | 645 | } |
@@ -652,17 +652,17 @@ discard block |
||
652 | 652 | */ |
653 | 653 | function getJsPath() |
654 | 654 | { |
655 | - if(!$this->_cache_dir) |
|
655 | + if (!$this->_cache_dir) |
|
656 | 656 | { |
657 | 657 | return FALSE; |
658 | 658 | } |
659 | 659 | |
660 | - $dir = $this->_cache_dir . '/ruleset'; |
|
661 | - if(!is_dir($dir) && !mkdir($dir)) |
|
660 | + $dir = $this->_cache_dir.'/ruleset'; |
|
661 | + if (!is_dir($dir) && !mkdir($dir)) |
|
662 | 662 | { |
663 | 663 | return FALSE; |
664 | 664 | } |
665 | - if(!$this->_xml_path) |
|
665 | + if (!$this->_xml_path) |
|
666 | 666 | { |
667 | 667 | return FALSE; |
668 | 668 | } |
@@ -671,14 +671,14 @@ discard block |
||
671 | 671 | $lang_type = class_exists('Context', false) ? Context::getLangType() : 'en'; |
672 | 672 | |
673 | 673 | // check the file |
674 | - $filepath = $dir . '/' . md5($this->_version . ' ' . $this->_xml_path) . ".{$lang_type}.js"; |
|
675 | - if(is_readable($filepath) && filemtime($filepath) > filemtime($this->_xml_path)) |
|
674 | + $filepath = $dir.'/'.md5($this->_version.' '.$this->_xml_path).".{$lang_type}.js"; |
|
675 | + if (is_readable($filepath) && filemtime($filepath) > filemtime($this->_xml_path)) |
|
676 | 676 | { |
677 | 677 | return $filepath; |
678 | 678 | } |
679 | 679 | |
680 | 680 | $content = $this->_compile2js(); |
681 | - if($content === FALSE) |
|
681 | + if ($content === FALSE) |
|
682 | 682 | { |
683 | 683 | return FALSE; |
684 | 684 | } |
@@ -699,9 +699,9 @@ discard block |
||
699 | 699 | $ruleset = basename($this->_xml_path, '.xml'); |
700 | 700 | $content = array(); |
701 | 701 | |
702 | - if(preg_match('@(^|/)files/ruleset/\w+\.xml$@i', $this->_xml_path)) |
|
702 | + if (preg_match('@(^|/)files/ruleset/\w+\.xml$@i', $this->_xml_path)) |
|
703 | 703 | { |
704 | - $ruleset = '@' . $ruleset; |
|
704 | + $ruleset = '@'.$ruleset; |
|
705 | 705 | } |
706 | 706 | |
707 | 707 | list($ruleset) = explode('.', $ruleset); |
@@ -711,22 +711,22 @@ discard block |
||
711 | 711 | |
712 | 712 | // custom rulesets |
713 | 713 | $addrules = array(); |
714 | - foreach($this->_rules as $name => $rule) |
|
714 | + foreach ($this->_rules as $name => $rule) |
|
715 | 715 | { |
716 | 716 | $name = strtolower($name); |
717 | 717 | |
718 | - if(in_array($name, array('email', 'userid', 'url', 'alpha', 'alpha_number', 'number', 'float'))) |
|
718 | + if (in_array($name, array('email', 'userid', 'url', 'alpha', 'alpha_number', 'number', 'float'))) |
|
719 | 719 | { |
720 | 720 | continue; |
721 | 721 | } |
722 | 722 | |
723 | - switch($rule['type']) |
|
723 | + switch ($rule['type']) |
|
724 | 724 | { |
725 | 725 | case 'regex': |
726 | 726 | $addrules[] = "v.cast('ADD_RULE', ['{$name}', {$rule['test']}]);"; |
727 | 727 | break; |
728 | 728 | case 'enum': |
729 | - $enums = '"' . implode('","', $rule['test']) . '"'; |
|
729 | + $enums = '"'.implode('","', $rule['test']).'"'; |
|
730 | 730 | $addrules[] = "v.cast('ADD_RULE', ['{$name}', function($$){ return ($.inArray($$,[{$enums}]) > -1); }]);"; |
731 | 731 | break; |
732 | 732 | case 'expr': |
@@ -735,7 +735,7 @@ discard block |
||
735 | 735 | } |
736 | 736 | |
737 | 737 | // if have a message, add message |
738 | - if(isset($rule['message'])) |
|
738 | + if (isset($rule['message'])) |
|
739 | 739 | { |
740 | 740 | $text = preg_replace('@\r?\n@', '\\n', addslashes($rule['message'])); |
741 | 741 | $addrules[] = "v.cast('ADD_MESSAGE',['invalid_{$name}','{$text}']);"; |
@@ -746,79 +746,79 @@ discard block |
||
746 | 746 | // filters |
747 | 747 | $content = array(); |
748 | 748 | $messages = array(); |
749 | - foreach($this->_filters as $name => $filter) |
|
749 | + foreach ($this->_filters as $name => $filter) |
|
750 | 750 | { |
751 | 751 | $field = array(); |
752 | 752 | |
753 | 753 | // form filed name |
754 | - if(isset($filter['title'])) |
|
754 | + if (isset($filter['title'])) |
|
755 | 755 | { |
756 | 756 | $field_lang = addslashes($filter['title']); |
757 | 757 | $messages[] = "v.cast('ADD_MESSAGE',['{$name}','{$field_lang}']);"; |
758 | 758 | } |
759 | - elseif(isset($lang->{$name})) |
|
759 | + elseif (isset($lang->{$name})) |
|
760 | 760 | { |
761 | 761 | $field_lang = addslashes($lang->{$name}); |
762 | 762 | $messages[] = "v.cast('ADD_MESSAGE',['{$name}','{$field_lang}']);"; |
763 | 763 | } |
764 | 764 | |
765 | - if($filter['required'] == 'true') |
|
765 | + if ($filter['required'] == 'true') |
|
766 | 766 | { |
767 | 767 | $field[] = 'required:true'; |
768 | 768 | } |
769 | - if($filter['rule']) |
|
769 | + if ($filter['rule']) |
|
770 | 770 | { |
771 | - $field[] = "rule:'" . strtolower($filter['rule']) . "'"; |
|
771 | + $field[] = "rule:'".strtolower($filter['rule'])."'"; |
|
772 | 772 | } |
773 | - if($filter['default']) |
|
773 | + if ($filter['default']) |
|
774 | 774 | { |
775 | 775 | $field[] = "default:'{$filter['default']}'"; |
776 | 776 | } |
777 | - if($filter['modifier']) |
|
777 | + if ($filter['modifier']) |
|
778 | 778 | { |
779 | 779 | $field[] = "modifier:'{$filter['modifier']}'"; |
780 | 780 | } |
781 | - if($filter['length']) |
|
781 | + if ($filter['length']) |
|
782 | 782 | { |
783 | 783 | list($min, $max) = explode(':', $filter['length']); |
784 | - if($min) |
|
784 | + if ($min) |
|
785 | 785 | { |
786 | 786 | $field[] = "minlength:'{$min}'"; |
787 | 787 | } |
788 | - if($max) |
|
788 | + if ($max) |
|
789 | 789 | { |
790 | 790 | $field[] = "maxlength:'{$max}'"; |
791 | 791 | } |
792 | 792 | } |
793 | - if($filter['if']) |
|
793 | + if ($filter['if']) |
|
794 | 794 | { |
795 | 795 | $ifs = array(); |
796 | - if(!isset($filter['if'][0])) |
|
796 | + if (!isset($filter['if'][0])) |
|
797 | 797 | { |
798 | 798 | $filter['if'] = array($filter['if']); |
799 | 799 | } |
800 | - foreach($filter['if'] as $if) |
|
800 | + foreach ($filter['if'] as $if) |
|
801 | 801 | { |
802 | - $ifs[] = "{test:'" . addslashes($if['test']) . "', attr:'{$if['attr']}', value:'" . addslashes($if['value']) . "'}"; |
|
802 | + $ifs[] = "{test:'".addslashes($if['test'])."', attr:'{$if['attr']}', value:'".addslashes($if['value'])."'}"; |
|
803 | 803 | } |
804 | - $field[] = "'if':[" . implode(',', $ifs) . "]"; |
|
804 | + $field[] = "'if':[".implode(',', $ifs)."]"; |
|
805 | 805 | } |
806 | - if(count($field)) |
|
806 | + if (count($field)) |
|
807 | 807 | { |
808 | - $field = '{' . implode(',', $field) . '}'; |
|
808 | + $field = '{'.implode(',', $field).'}'; |
|
809 | 809 | $content[] = "'{$name}':{$field}"; |
810 | 810 | } |
811 | 811 | } |
812 | 812 | |
813 | - if(!$content) |
|
813 | + if (!$content) |
|
814 | 814 | { |
815 | 815 | return '/* Error : empty ruleset */'; |
816 | 816 | } |
817 | 817 | |
818 | 818 | // error messages |
819 | - foreach($lang->filter as $key => $text) |
|
819 | + foreach ($lang->filter as $key => $text) |
|
820 | 820 | { |
821 | - if($text) |
|
821 | + if ($text) |
|
822 | 822 | { |
823 | 823 | $text = preg_replace('@\r?\n@', '\\n', addslashes($text)); |
824 | 824 | $messages[] = "v.cast('ADD_MESSAGE',['{$key}','{$text}']);"; |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | /** |
62 | 62 | * Character data handler |
63 | 63 | * Variable in the last element of this->output |
64 | - * @param resource $parse an instance of parser |
|
64 | + * @param resource $parser an instance of parser |
|
65 | 65 | * @param string $body a data to be added |
66 | 66 | * @return void |
67 | 67 | */ |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | |
74 | 74 | /** |
75 | 75 | * End element handler |
76 | - * @param resource $parse an instance of parser |
|
76 | + * @param resource $parser an instance of parser |
|
77 | 77 | * @param string $node_name name of xml node |
78 | 78 | * @return void |
79 | 79 | */ |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | xml_parse($oParser, $input); |
33 | 33 | xml_parser_free($oParser); |
34 | 34 | |
35 | - if(count($this->output) < 1) |
|
35 | + if (count($this->output) < 1) |
|
36 | 36 | { |
37 | 37 | return; |
38 | 38 | } |
@@ -84,9 +84,9 @@ discard block |
||
84 | 84 | $parent_obj = &$this->output[count($this->output) - 1]; |
85 | 85 | $tmp_obj = &$parent_obj->childNodes[$node_name]; |
86 | 86 | |
87 | - if($tmp_obj) |
|
87 | + if ($tmp_obj) |
|
88 | 88 | { |
89 | - if(is_array($tmp_obj)) |
|
89 | + if (is_array($tmp_obj)) |
|
90 | 90 | { |
91 | 91 | $tmp_obj[] = $cur_obj; |
92 | 92 | } |
@@ -89,13 +89,11 @@ |
||
89 | 89 | if(is_array($tmp_obj)) |
90 | 90 | { |
91 | 91 | $tmp_obj[] = $cur_obj; |
92 | - } |
|
93 | - else |
|
92 | + } else |
|
94 | 93 | { |
95 | 94 | $tmp_obj = array($tmp_obj, $cur_obj); |
96 | 95 | } |
97 | - } |
|
98 | - else |
|
96 | + } else |
|
99 | 97 | { |
100 | 98 | $tmp_obj = $cur_obj; |
101 | 99 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | |
63 | 63 | /** |
64 | 64 | * compile a xml_file only when a corresponding php lang file does not exists or is outdated |
65 | - * @return string|bool Returns compiled php file. |
|
65 | + * @return false|string Returns compiled php file. |
|
66 | 66 | */ |
67 | 67 | function compile() |
68 | 68 | { |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | |
134 | 134 | /** |
135 | 135 | * Writing cache file |
136 | - * @return void|bool |
|
136 | + * @return null|false |
|
137 | 137 | */ |
138 | 138 | function _writeFile() |
139 | 139 | { |
@@ -73,14 +73,12 @@ discard block |
||
73 | 73 | if(!file_exists($this->php_file)) |
74 | 74 | { |
75 | 75 | $this->_compile(); |
76 | - } |
|
77 | - else |
|
76 | + } else |
|
78 | 77 | { |
79 | 78 | if(filemtime($this->xml_file) > filemtime($this->php_file)) |
80 | 79 | { |
81 | 80 | $this->_compile(); |
82 | - } |
|
83 | - else |
|
81 | + } else |
|
84 | 82 | { |
85 | 83 | return $this->php_file; |
86 | 84 | } |
@@ -168,8 +166,7 @@ discard block |
||
168 | 166 | $this->code .= " {$var} = array();\n"; |
169 | 167 | $this->code .= "}\n"; |
170 | 168 | $var .= '[\'%s\']'; |
171 | - } |
|
172 | - else |
|
169 | + } else |
|
173 | 170 | { |
174 | 171 | $this->code .= "if(!is_object({$var})){\n"; |
175 | 172 | $this->code .= " {$var} = new stdClass();\n"; |
@@ -186,8 +183,7 @@ discard block |
||
186 | 183 | { |
187 | 184 | $this->_parseItem($item, $var); |
188 | 185 | } |
189 | - } |
|
190 | - else |
|
186 | + } else |
|
191 | 187 | { |
192 | 188 | $code = $this->_parseValues($value, $var); |
193 | 189 | $this->code .= $code; |
@@ -220,12 +216,10 @@ discard block |
||
220 | 216 | if($value[$this->lang_type]) |
221 | 217 | { |
222 | 218 | return $value[$this->lang_type]; |
223 | - } |
|
224 | - else if($value['en']) |
|
219 | + } else if($value['en']) |
|
225 | 220 | { |
226 | 221 | return $value['en']; |
227 | - } |
|
228 | - else if($value['ko']) |
|
222 | + } else if($value['ko']) |
|
229 | 223 | { |
230 | 224 | return $value['ko']; |
231 | 225 | } |
@@ -66,17 +66,17 @@ discard block |
||
66 | 66 | */ |
67 | 67 | function compile() |
68 | 68 | { |
69 | - if(!file_exists($this->xml_file)) |
|
69 | + if (!file_exists($this->xml_file)) |
|
70 | 70 | { |
71 | 71 | return FALSE; |
72 | 72 | } |
73 | - if(!file_exists($this->php_file)) |
|
73 | + if (!file_exists($this->php_file)) |
|
74 | 74 | { |
75 | 75 | $this->_compile(); |
76 | 76 | } |
77 | 77 | else |
78 | 78 | { |
79 | - if(filemtime($this->xml_file) > filemtime($this->php_file)) |
|
79 | + if (filemtime($this->xml_file) > filemtime($this->php_file)) |
|
80 | 80 | { |
81 | 81 | $this->_compile(); |
82 | 82 | } |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | */ |
96 | 96 | function getCompileContent() |
97 | 97 | { |
98 | - if(!file_exists($this->xml_file)) |
|
98 | + if (!file_exists($this->xml_file)) |
|
99 | 99 | { |
100 | 100 | return FALSE; |
101 | 101 | } |
@@ -121,11 +121,11 @@ discard block |
||
121 | 121 | $xml_obj = parent::parse($buff); |
122 | 122 | |
123 | 123 | $item = $xml_obj->lang->item; |
124 | - if(!is_array($item)) |
|
124 | + if (!is_array($item)) |
|
125 | 125 | { |
126 | 126 | $item = array($item); |
127 | 127 | } |
128 | - foreach($item as $i) |
|
128 | + foreach ($item as $i) |
|
129 | 129 | { |
130 | 130 | $this->_parseItem($i, $var = '$lang->%s'); |
131 | 131 | } |
@@ -137,11 +137,11 @@ discard block |
||
137 | 137 | */ |
138 | 138 | function _writeFile() |
139 | 139 | { |
140 | - if(!$this->code) |
|
140 | + if (!$this->code) |
|
141 | 141 | { |
142 | 142 | return; |
143 | 143 | } |
144 | - FileHandler::writeFile($this->php_file, "<?php\n" . $this->code); |
|
144 | + FileHandler::writeFile($this->php_file, "<?php\n".$this->code); |
|
145 | 145 | return false; |
146 | 146 | } |
147 | 147 | |
@@ -157,12 +157,12 @@ discard block |
||
157 | 157 | $value = $item->value; |
158 | 158 | $var = sprintf($var, $name); |
159 | 159 | |
160 | - if($item->item) |
|
160 | + if ($item->item) |
|
161 | 161 | { |
162 | 162 | $type = $item->attrs->type; |
163 | 163 | $mode = $item->attrs->mode; |
164 | 164 | |
165 | - if($type == 'array') |
|
165 | + if ($type == 'array') |
|
166 | 166 | { |
167 | 167 | $this->code .= "if(!is_array({$var})){\n"; |
168 | 168 | $this->code .= " {$var} = array();\n"; |
@@ -178,11 +178,11 @@ discard block |
||
178 | 178 | } |
179 | 179 | |
180 | 180 | $items = $item->item; |
181 | - if(!is_array($items)) |
|
181 | + if (!is_array($items)) |
|
182 | 182 | { |
183 | 183 | $items = array($items); |
184 | 184 | } |
185 | - foreach($items as $item) |
|
185 | + foreach ($items as $item) |
|
186 | 186 | { |
187 | 187 | $this->_parseItem($item, $var); |
188 | 188 | } |
@@ -202,41 +202,41 @@ discard block |
||
202 | 202 | */ |
203 | 203 | function _parseValues($nodes, $var) |
204 | 204 | { |
205 | - if(!is_array($nodes)) |
|
205 | + if (!is_array($nodes)) |
|
206 | 206 | { |
207 | 207 | $nodes = array($nodes); |
208 | 208 | } |
209 | 209 | |
210 | 210 | $value = array(); |
211 | - foreach($nodes as $node) |
|
211 | + foreach ($nodes as $node) |
|
212 | 212 | { |
213 | 213 | $return = $this->_parseValue($node, $var); |
214 | - if($return && is_array($return)) |
|
214 | + if ($return && is_array($return)) |
|
215 | 215 | { |
216 | 216 | $value = array_merge($value, $return); |
217 | 217 | } |
218 | 218 | } |
219 | 219 | |
220 | - if($value[$this->lang_type]) |
|
220 | + if ($value[$this->lang_type]) |
|
221 | 221 | { |
222 | 222 | return $value[$this->lang_type]; |
223 | 223 | } |
224 | - else if($value['en']) |
|
224 | + else if ($value['en']) |
|
225 | 225 | { |
226 | 226 | return $value['en']; |
227 | 227 | } |
228 | - else if($value['ko']) |
|
228 | + else if ($value['ko']) |
|
229 | 229 | { |
230 | 230 | return $value['ko']; |
231 | 231 | } |
232 | 232 | |
233 | - foreach($this->lang_types as $lang_type) |
|
233 | + foreach ($this->lang_types as $lang_type) |
|
234 | 234 | { |
235 | - if($lang_type == 'en' || $lang_type == 'ko' || $lang_type == $this->lang_type) |
|
235 | + if ($lang_type == 'en' || $lang_type == 'ko' || $lang_type == $this->lang_type) |
|
236 | 236 | { |
237 | 237 | continue; |
238 | 238 | } |
239 | - if($value[$lang_type]) |
|
239 | + if ($value[$lang_type]) |
|
240 | 240 | { |
241 | 241 | return $value[$lang_type]; |
242 | 242 | } |
@@ -255,12 +255,12 @@ discard block |
||
255 | 255 | { |
256 | 256 | $lang_type = $node->attrs->xml_lang; |
257 | 257 | $value = $node->body; |
258 | - if(!$value) |
|
258 | + if (!$value) |
|
259 | 259 | { |
260 | 260 | return false; |
261 | 261 | } |
262 | 262 | |
263 | - $var .= '=\'' . str_replace("'", "\'", $value) . "';\n"; |
|
263 | + $var .= '=\''.str_replace("'", "\'", $value)."';\n"; |
|
264 | 264 | return array($lang_type => $var); |
265 | 265 | } |
266 | 266 |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | |
152 | 152 | /** |
153 | 153 | * Start element handler. |
154 | - * @param resource $parse an instance of parser |
|
154 | + * @param resource $parser an instance of parser |
|
155 | 155 | * @param string $node_name a name of node |
156 | 156 | * @param array $attrs attributes to be set |
157 | 157 | * @return array |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | /** |
169 | 169 | * Character data handler |
170 | 170 | * Variable in the last element of this->output |
171 | - * @param resource $parse an instance of parser |
|
171 | + * @param resource $parser an instance of parser |
|
172 | 172 | * @param string $body a data to be added |
173 | 173 | * @return void |
174 | 174 | */ |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | |
181 | 181 | /** |
182 | 182 | * End element handler |
183 | - * @param resource $parse an instance of parser |
|
183 | + * @param resource $parser an instance of parser |
|
184 | 184 | * @param string $node_name name of xml node |
185 | 185 | * @return void |
186 | 186 | */ |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | */ |
70 | 70 | function loadXmlFile($filename) |
71 | 71 | { |
72 | - if(!file_exists($filename)) |
|
72 | + if (!file_exists($filename)) |
|
73 | 73 | { |
74 | 74 | return; |
75 | 75 | } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | function parse($input = '', $arg1 = NULL, $arg2 = NULL) |
90 | 90 | { |
91 | 91 | // Save the compile starting time for debugging |
92 | - if(__DEBUG__ == 3) |
|
92 | + if (__DEBUG__ == 3) |
|
93 | 93 | { |
94 | 94 | $start = getMicroTime(); |
95 | 95 | } |
@@ -103,13 +103,13 @@ discard block |
||
103 | 103 | preg_match_all("/xml:lang=\"([^\"].+)\"/i", $this->input, $matches); |
104 | 104 | |
105 | 105 | // extracts the supported lanuage when xml:lang is used |
106 | - if(count($matches[1]) && $supported_lang = array_unique($matches[1])) |
|
106 | + if (count($matches[1]) && $supported_lang = array_unique($matches[1])) |
|
107 | 107 | { |
108 | 108 | $tmpLangList = array_flip($supported_lang); |
109 | 109 | // if lang of the first log-in user doesn't exist, apply en by default if exists. Otherwise apply the first lang. |
110 | - if(!isset($tmpLangList[$this->lang])) |
|
110 | + if (!isset($tmpLangList[$this->lang])) |
|
111 | 111 | { |
112 | - if(isset($tmpLangList['en'])) |
|
112 | + if (isset($tmpLangList['en'])) |
|
113 | 113 | { |
114 | 114 | $this->lang = 'en'; |
115 | 115 | } |
@@ -134,14 +134,14 @@ discard block |
||
134 | 134 | xml_parse($this->oParser, $this->input); |
135 | 135 | xml_parser_free($this->oParser); |
136 | 136 | |
137 | - if(!count($this->output)) |
|
137 | + if (!count($this->output)) |
|
138 | 138 | { |
139 | 139 | return; |
140 | 140 | } |
141 | 141 | |
142 | 142 | $output = array_shift($this->output); |
143 | 143 | // Save compile starting time for debugging |
144 | - if(__DEBUG__ == 3) |
|
144 | + if (__DEBUG__ == 3) |
|
145 | 145 | { |
146 | 146 | $GLOBALS['__xmlparse_elapsed__'] += getMicroTime() - $start; |
147 | 147 | } |
@@ -189,19 +189,19 @@ discard block |
||
189 | 189 | $node_name = strtolower($node_name); |
190 | 190 | $cur_obj = array_pop($this->output); |
191 | 191 | $parent_obj = &$this->output[count($this->output) - 1]; |
192 | - if($this->lang && $cur_obj->attrs->{'xml:lang'} && $cur_obj->attrs->{'xml:lang'} != $this->lang) |
|
192 | + if ($this->lang && $cur_obj->attrs->{'xml:lang'} && $cur_obj->attrs->{'xml:lang'} != $this->lang) |
|
193 | 193 | { |
194 | 194 | return; |
195 | 195 | } |
196 | - if($this->lang && $parent_obj->{$node_name}->attrs->{'xml:lang'} && $parent_obj->{$node_name}->attrs->{'xml:lang'} != $this->lang) |
|
196 | + if ($this->lang && $parent_obj->{$node_name}->attrs->{'xml:lang'} && $parent_obj->{$node_name}->attrs->{'xml:lang'} != $this->lang) |
|
197 | 197 | { |
198 | 198 | return; |
199 | 199 | } |
200 | 200 | |
201 | - if(isset($parent_obj->{$node_name})) |
|
201 | + if (isset($parent_obj->{$node_name})) |
|
202 | 202 | { |
203 | 203 | $tmp_obj = $parent_obj->{$node_name}; |
204 | - if(is_array($tmp_obj)) |
|
204 | + if (is_array($tmp_obj)) |
|
205 | 205 | { |
206 | 206 | $parent_obj->{$node_name}[] = $cur_obj; |
207 | 207 | } |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | } |
213 | 213 | else |
214 | 214 | { |
215 | - if(!is_object($parent_obj)) |
|
215 | + if (!is_object($parent_obj)) |
|
216 | 216 | { |
217 | 217 | $parent_obj = (object) $parent_obj; |
218 | 218 | } |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | function _arrToAttrsObj($arr) |
230 | 230 | { |
231 | 231 | $output = new Xml_Node_(); |
232 | - foreach($arr as $key => $val) |
|
232 | + foreach ($arr as $key => $val) |
|
233 | 233 | { |
234 | 234 | $key = strtolower($key); |
235 | 235 | $output->{$key} = $val; |
@@ -112,15 +112,13 @@ discard block |
||
112 | 112 | if(isset($tmpLangList['en'])) |
113 | 113 | { |
114 | 114 | $this->lang = 'en'; |
115 | - } |
|
116 | - else |
|
115 | + } else |
|
117 | 116 | { |
118 | 117 | $this->lang = array_shift($supported_lang); |
119 | 118 | } |
120 | 119 | } |
121 | 120 | // uncheck the language if no specific language is set. |
122 | - } |
|
123 | - else |
|
121 | + } else |
|
124 | 122 | { |
125 | 123 | $this->lang = ''; |
126 | 124 | } |
@@ -204,13 +202,11 @@ discard block |
||
204 | 202 | if(is_array($tmp_obj)) |
205 | 203 | { |
206 | 204 | $parent_obj->{$node_name}[] = $cur_obj; |
207 | - } |
|
208 | - else |
|
205 | + } else |
|
209 | 206 | { |
210 | 207 | $parent_obj->{$node_name} = array($tmp_obj, $cur_obj); |
211 | 208 | } |
212 | - } |
|
213 | - else |
|
209 | + } else |
|
214 | 210 | { |
215 | 211 | if(!is_object($parent_obj)) |
216 | 212 | { |
@@ -90,6 +90,9 @@ discard block |
||
90 | 90 | $this->type = $value; |
91 | 91 | } |
92 | 92 | |
93 | + /** |
|
94 | + * @param string $operation |
|
95 | + */ |
|
93 | 96 | function setColumnOperation($operation) |
94 | 97 | { |
95 | 98 | $this->column_operation = $operation; |
@@ -282,6 +285,9 @@ discard block |
||
282 | 285 | return $this->errorMessage; |
283 | 286 | } |
284 | 287 | |
288 | + /** |
|
289 | + * @param integer $default_value |
|
290 | + */ |
|
285 | 291 | function ensureDefaultValue($default_value) |
286 | 292 | { |
287 | 293 | if($this->value === NULL || $this->value === '') |
@@ -180,8 +180,7 @@ discard block |
||
180 | 180 | if(!is_array($value)) |
181 | 181 | { |
182 | 182 | $value = $this->_escapeStringValue($value); |
183 | - } |
|
184 | - else |
|
183 | + } else |
|
185 | 184 | { |
186 | 185 | foreach($value as $key=>$val) |
187 | 186 | { |
@@ -204,8 +203,7 @@ discard block |
||
204 | 203 | $value[$key] = (int) $val; |
205 | 204 | } |
206 | 205 | } |
207 | - } |
|
208 | - else |
|
206 | + } else |
|
209 | 207 | { |
210 | 208 | $value = (int) $value; |
211 | 209 | } |
@@ -236,8 +234,7 @@ discard block |
||
236 | 234 | { |
237 | 235 | // Valid byte sequence. Return unmodified. |
238 | 236 | return $captures[1]; |
239 | - } |
|
240 | - else if(strlen($captures[2])) |
|
237 | + } else if(strlen($captures[2])) |
|
241 | 238 | { |
242 | 239 | // Remove user defined area |
243 | 240 | if("\xF3\xB0\x80\x80" <= $captures[2]) |
@@ -246,8 +243,7 @@ discard block |
||
246 | 243 | } |
247 | 244 | |
248 | 245 | return $captures[2]; |
249 | - } |
|
250 | - else |
|
246 | + } else |
|
251 | 247 | { |
252 | 248 | return; |
253 | 249 | } |
@@ -73,11 +73,11 @@ discard block |
||
73 | 73 | |
74 | 74 | function getType() |
75 | 75 | { |
76 | - if(isset($this->type)) |
|
76 | + if (isset($this->type)) |
|
77 | 77 | { |
78 | 78 | return $this->type; |
79 | 79 | } |
80 | - if(is_string($this->value)) |
|
80 | + if (is_string($this->value)) |
|
81 | 81 | { |
82 | 82 | return 'column_name'; |
83 | 83 | } |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | |
103 | 103 | function getValue() |
104 | 104 | { |
105 | - if(!isset($this->_value)) |
|
105 | + if (!isset($this->_value)) |
|
106 | 106 | { |
107 | 107 | $value = $this->getEscapedValue(); |
108 | 108 | $this->_value = $this->toString($value); |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | |
128 | 128 | function getUnescapedValue() |
129 | 129 | { |
130 | - if($this->value === 'null') |
|
130 | + if ($this->value === 'null') |
|
131 | 131 | { |
132 | 132 | return null; |
133 | 133 | } |
@@ -141,17 +141,17 @@ discard block |
||
141 | 141 | */ |
142 | 142 | function toString($value) |
143 | 143 | { |
144 | - if(is_array($value)) |
|
144 | + if (is_array($value)) |
|
145 | 145 | { |
146 | - if(count($value) === 0) |
|
146 | + if (count($value) === 0) |
|
147 | 147 | { |
148 | 148 | return ''; |
149 | 149 | } |
150 | - if(count($value) === 1 && $value[0] === '') |
|
150 | + if (count($value) === 1 && $value[0] === '') |
|
151 | 151 | { |
152 | 152 | return ''; |
153 | 153 | } |
154 | - return '(' . implode(',', $value) . ')'; |
|
154 | + return '('.implode(',', $value).')'; |
|
155 | 155 | } |
156 | 156 | return $value; |
157 | 157 | } |
@@ -164,42 +164,42 @@ discard block |
||
164 | 164 | function escapeValue($value) |
165 | 165 | { |
166 | 166 | $column_type = $this->getType(); |
167 | - if($column_type == 'column_name') |
|
167 | + if ($column_type == 'column_name') |
|
168 | 168 | { |
169 | 169 | $dbParser = DB::getParser(); |
170 | 170 | return $dbParser->parseExpression($value); |
171 | 171 | } |
172 | - if(!isset($value)) |
|
172 | + if (!isset($value)) |
|
173 | 173 | { |
174 | 174 | return null; |
175 | 175 | } |
176 | 176 | |
177 | 177 | $columnTypeList = array('date' => 1, 'varchar' => 1, 'char' => 1, 'text' => 1, 'bigtext' => 1); |
178 | - if(isset($columnTypeList[$column_type])) |
|
178 | + if (isset($columnTypeList[$column_type])) |
|
179 | 179 | { |
180 | - if(!is_array($value)) |
|
180 | + if (!is_array($value)) |
|
181 | 181 | { |
182 | 182 | $value = $this->_escapeStringValue($value); |
183 | 183 | } |
184 | 184 | else |
185 | 185 | { |
186 | - foreach($value as $key=>$val) |
|
186 | + foreach ($value as $key=>$val) |
|
187 | 187 | { |
188 | 188 | $value[$key] = $this->_escapeStringValue($val); |
189 | 189 | } |
190 | 190 | } |
191 | 191 | } |
192 | - if($this->uses_default_value) |
|
192 | + if ($this->uses_default_value) |
|
193 | 193 | { |
194 | 194 | return $value; |
195 | 195 | } |
196 | - if($column_type == 'number') |
|
196 | + if ($column_type == 'number') |
|
197 | 197 | { |
198 | - if(is_array($value)) |
|
198 | + if (is_array($value)) |
|
199 | 199 | { |
200 | - foreach($value AS $key => $val) |
|
200 | + foreach ($value AS $key => $val) |
|
201 | 201 | { |
202 | - if(isset($val) && $val !== '') |
|
202 | + if (isset($val) && $val !== '') |
|
203 | 203 | { |
204 | 204 | $value[$key] = (int) $val; |
205 | 205 | } |
@@ -227,20 +227,20 @@ discard block |
||
227 | 227 | $value = preg_replace_callback($regex, array($this, 'utf8Replacer'), $value); |
228 | 228 | $db = DB::getInstance(); |
229 | 229 | $value = $db->addQuotes($value); |
230 | - return '\'' . $value . '\''; |
|
230 | + return '\''.$value.'\''; |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | function utf8Replacer($captures) |
234 | 234 | { |
235 | - if(strlen($captures[1])) |
|
235 | + if (strlen($captures[1])) |
|
236 | 236 | { |
237 | 237 | // Valid byte sequence. Return unmodified. |
238 | 238 | return $captures[1]; |
239 | 239 | } |
240 | - else if(strlen($captures[2])) |
|
240 | + else if (strlen($captures[2])) |
|
241 | 241 | { |
242 | 242 | // Remove user defined area |
243 | - if("\xF3\xB0\x80\x80" <= $captures[2]) |
|
243 | + if ("\xF3\xB0\x80\x80" <= $captures[2]) |
|
244 | 244 | { |
245 | 245 | return; |
246 | 246 | } |
@@ -262,15 +262,15 @@ discard block |
||
262 | 262 | { |
263 | 263 | $type = $this->getType(); |
264 | 264 | $value = $this->getUnescapedValue(); |
265 | - if($type == 'column_name') |
|
265 | + if ($type == 'column_name') |
|
266 | 266 | { |
267 | 267 | return TRUE; |
268 | 268 | } |
269 | - if($type == 'number' && is_null($value)) |
|
269 | + if ($type == 'number' && is_null($value)) |
|
270 | 270 | { |
271 | 271 | return FALSE; |
272 | 272 | } |
273 | - if($type == 'number' && !is_numeric($value) && $this->uses_default_value) |
|
273 | + if ($type == 'number' && !is_numeric($value) && $this->uses_default_value) |
|
274 | 274 | { |
275 | 275 | return TRUE; |
276 | 276 | } |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | |
285 | 285 | function ensureDefaultValue($default_value) |
286 | 286 | { |
287 | - if($this->value === NULL || $this->value === '') |
|
287 | + if ($this->value === NULL || $this->value === '') |
|
288 | 288 | { |
289 | 289 | $this->value = $default_value; |
290 | 290 | $this->uses_default_value = TRUE; |
@@ -298,23 +298,23 @@ discard block |
||
298 | 298 | */ |
299 | 299 | function checkFilter($filter_type) |
300 | 300 | { |
301 | - if(isset($this->value) && $this->value != '') |
|
301 | + if (isset($this->value) && $this->value != '') |
|
302 | 302 | { |
303 | 303 | global $lang; |
304 | 304 | $val = $this->value; |
305 | 305 | $key = $this->name; |
306 | - switch($filter_type) |
|
306 | + switch ($filter_type) |
|
307 | 307 | { |
308 | 308 | case 'email' : |
309 | 309 | case 'email_address' : |
310 | - if(!preg_match('/^[\w-]+((?:\.|\+|\~)[\w-]+)*@[\w-]+(\.[\w-]+)+$/is', $val)) |
|
310 | + if (!preg_match('/^[\w-]+((?:\.|\+|\~)[\w-]+)*@[\w-]+(\.[\w-]+)+$/is', $val)) |
|
311 | 311 | { |
312 | 312 | $this->isValid = FALSE; |
313 | 313 | $this->errorMessage = new BaseObject(-1, sprintf($lang->filter->invalid_email, $lang->{$key} ? $lang->{$key} : $key)); |
314 | 314 | } |
315 | 315 | break; |
316 | 316 | case 'homepage' : |
317 | - if(!preg_match('/^(http|https)+(:\/\/)+[0-9a-z_-]+\.[^ ]+$/is', $val)) |
|
317 | + if (!preg_match('/^(http|https)+(:\/\/)+[0-9a-z_-]+\.[^ ]+$/is', $val)) |
|
318 | 318 | { |
319 | 319 | $this->isValid = FALSE; |
320 | 320 | $this->errorMessage = new BaseObject(-1, sprintf($lang->filter->invalid_homepage, $lang->{$key} ? $lang->{$key} : $key)); |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | break; |
323 | 323 | case 'userid' : |
324 | 324 | case 'user_id' : |
325 | - if(!preg_match('/^[a-zA-Z]+([_0-9a-zA-Z]+)*$/is', $val)) |
|
325 | + if (!preg_match('/^[a-zA-Z]+([_0-9a-zA-Z]+)*$/is', $val)) |
|
326 | 326 | { |
327 | 327 | $this->isValid = FALSE; |
328 | 328 | $this->errorMessage = new BaseObject(-1, sprintf($lang->filter->invalid_userid, $lang->{$key} ? $lang->{$key} : $key)); |
@@ -330,25 +330,25 @@ discard block |
||
330 | 330 | break; |
331 | 331 | case 'number' : |
332 | 332 | case 'numbers' : |
333 | - if(is_array($val)) |
|
333 | + if (is_array($val)) |
|
334 | 334 | { |
335 | 335 | $val = join(',', $val); |
336 | 336 | } |
337 | - if(!preg_match('/^(-?)[0-9]+(,\-?[0-9]+)*$/is', $val)) |
|
337 | + if (!preg_match('/^(-?)[0-9]+(,\-?[0-9]+)*$/is', $val)) |
|
338 | 338 | { |
339 | 339 | $this->isValid = FALSE; |
340 | 340 | $this->errorMessage = new BaseObject(-1, sprintf($lang->filter->invalid_number, $lang->{$key} ? $lang->{$key} : $key)); |
341 | 341 | } |
342 | 342 | break; |
343 | 343 | case 'alpha' : |
344 | - if(!preg_match('/^[a-z]+$/is', $val)) |
|
344 | + if (!preg_match('/^[a-z]+$/is', $val)) |
|
345 | 345 | { |
346 | 346 | $this->isValid = FALSE; |
347 | 347 | $this->errorMessage = new BaseObject(-1, sprintf($lang->filter->invalid_alpha, $lang->{$key} ? $lang->{$key} : $key)); |
348 | 348 | } |
349 | 349 | break; |
350 | 350 | case 'alpha_number' : |
351 | - if(!preg_match('/^[0-9a-z]+$/is', $val)) |
|
351 | + if (!preg_match('/^[0-9a-z]+$/is', $val)) |
|
352 | 352 | { |
353 | 353 | $this->isValid = FALSE; |
354 | 354 | $this->errorMessage = new BaseObject(-1, sprintf($lang->filter->invalid_alpha_number, $lang->{$key} ? $lang->{$key} : $key)); |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | |
361 | 361 | function checkMaxLength($length) |
362 | 362 | { |
363 | - if($this->value && (strlen($this->value) > $length)) |
|
363 | + if ($this->value && (strlen($this->value) > $length)) |
|
364 | 364 | { |
365 | 365 | global $lang; |
366 | 366 | $this->isValid = FALSE; |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | |
372 | 372 | function checkMinLength($length) |
373 | 373 | { |
374 | - if($this->value && (strlen($this->value) < $length)) |
|
374 | + if ($this->value && (strlen($this->value) < $length)) |
|
375 | 375 | { |
376 | 376 | global $lang; |
377 | 377 | $this->isValid = FALSE; |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | |
383 | 383 | function checkNotNull() |
384 | 384 | { |
385 | - if(!isset($this->value)) |
|
385 | + if (!isset($this->value)) |
|
386 | 386 | { |
387 | 387 | global $lang; |
388 | 388 | $this->isValid = FALSE; |