@@ -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 |
@@ -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 |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | // defer to the schemes to do the right thing. |
192 | 192 | $result = ''; |
193 | 193 | if (!is_null($this->scheme)) $result .= $this->scheme . ':'; |
194 | - if (!is_null($authority)) $result .= '//' . $authority; |
|
194 | + if (!is_null($authority)) $result .= '//' . $authority; |
|
195 | 195 | $result .= $this->path; |
196 | 196 | if (!is_null($this->query)) $result .= '?' . $this->query; |
197 | 197 | if (!is_null($this->fragment)) $result .= '#' . $this->fragment; |
@@ -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) { |
@@ -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 |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * updating subclasses. |
129 | 129 | */ |
130 | 130 | protected function errorInconsistent($class, $type) { |
131 | - throw new HTMLPurifier_Exception("Inconsistency in $class: ".HTMLPurifier_VarParser::getTypeName($type)." not implemented"); |
|
131 | + throw new HTMLPurifier_Exception("Inconsistency in $class: " . HTMLPurifier_VarParser::getTypeName($type) . " not implemented"); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | */ |
137 | 137 | protected function errorGeneric($var, $type) { |
138 | 138 | $vtype = gettype($var); |
139 | - $this->error("Expected type ".HTMLPurifier_VarParser::getTypeName($type).", got $vtype"); |
|
139 | + $this->error("Expected type " . HTMLPurifier_VarParser::getTypeName($type) . ", got $vtype"); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | static public function getTypeName($type) { |
@@ -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 |
@@ -107,7 +107,7 @@ |
||
107 | 107 | * Convert special characters to HTML entities for the target variables. |
108 | 108 | * @param mixed $var |
109 | 109 | * @param array $name |
110 | - * @return mixed |
|
110 | + * @return string |
|
111 | 111 | */ |
112 | 112 | function _encodeHTML($var, $name = array()) |
113 | 113 | { |
@@ -37,15 +37,15 @@ discard block |
||
37 | 37 | function encodeHTML(/* , $varName1, $varName2, ... */) |
38 | 38 | { |
39 | 39 | $varNames = func_get_args(); |
40 | - if(count($varNames) < 0) |
|
40 | + if (count($varNames) < 0) |
|
41 | 41 | { |
42 | 42 | return FALSE; |
43 | 43 | } |
44 | 44 | |
45 | 45 | $use_context = is_null($this->_targetVar); |
46 | - if(!$use_context) |
|
46 | + if (!$use_context) |
|
47 | 47 | { |
48 | - if(!count($varNames) || (!is_object($this->_targetVar) && !is_array($this->_targetVar))) |
|
48 | + if (!count($varNames) || (!is_object($this->_targetVar) && !is_array($this->_targetVar))) |
|
49 | 49 | { |
50 | 50 | return $this->_encodeHTML($this->_targetVar); |
51 | 51 | } |
@@ -53,15 +53,15 @@ discard block |
||
53 | 53 | $is_object = is_object($this->_targetVar); |
54 | 54 | } |
55 | 55 | |
56 | - foreach($varNames as $varName) |
|
56 | + foreach ($varNames as $varName) |
|
57 | 57 | { |
58 | 58 | $varName = explode('.', $varName); |
59 | 59 | $varName0 = array_shift($varName); |
60 | - if($use_context) |
|
60 | + if ($use_context) |
|
61 | 61 | { |
62 | 62 | $var = Context::get($varName0); |
63 | 63 | } |
64 | - elseif($varName0) |
|
64 | + elseif ($varName0) |
|
65 | 65 | { |
66 | 66 | $var = $is_object ? $this->_targetVar->{$varName0} : $this->_targetVar[$varName0]; |
67 | 67 | } |
@@ -71,18 +71,18 @@ discard block |
||
71 | 71 | } |
72 | 72 | $var = $this->_encodeHTML($var, $varName); |
73 | 73 | |
74 | - if($var === FALSE) |
|
74 | + if ($var === FALSE) |
|
75 | 75 | { |
76 | 76 | continue; |
77 | 77 | } |
78 | 78 | |
79 | - if($use_context) |
|
79 | + if ($use_context) |
|
80 | 80 | { |
81 | 81 | Context::set($varName0, $var); |
82 | 82 | } |
83 | - elseif($varName0) |
|
83 | + elseif ($varName0) |
|
84 | 84 | { |
85 | - if($is_object) |
|
85 | + if ($is_object) |
|
86 | 86 | { |
87 | 87 | $this->_targetVar->{$varName0} = $var; |
88 | 88 | } |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | } |
98 | 98 | } |
99 | 99 | |
100 | - if(!$use_context) |
|
100 | + if (!$use_context) |
|
101 | 101 | { |
102 | 102 | return $this->_targetVar; |
103 | 103 | } |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | */ |
112 | 112 | function _encodeHTML($var, $name = array()) |
113 | 113 | { |
114 | - if(is_string($var)) |
|
114 | + if (is_string($var)) |
|
115 | 115 | { |
116 | - if(strncmp('$user_lang->', $var, 12) !== 0) |
|
116 | + if (strncmp('$user_lang->', $var, 12) !== 0) |
|
117 | 117 | { |
118 | 118 | $var = htmlspecialchars($var, ENT_COMPAT | ENT_HTML401, 'UTF-8', false); |
119 | 119 | } |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | return $var; |
122 | 122 | } |
123 | 123 | |
124 | - if(!count($name) || (!is_array($var) && !is_object($var))) |
|
124 | + if (!count($name) || (!is_array($var) && !is_object($var))) |
|
125 | 125 | { |
126 | 126 | return false; |
127 | 127 | } |
@@ -129,17 +129,17 @@ discard block |
||
129 | 129 | $is_object = is_object($var); |
130 | 130 | $name0 = array_shift($name); |
131 | 131 | |
132 | - if(strlen($name0)) |
|
132 | + if (strlen($name0)) |
|
133 | 133 | { |
134 | 134 | $target = $is_object ? $var->{$name0} : $var[$name0]; |
135 | 135 | $target = $this->_encodeHTML($target, $name); |
136 | 136 | |
137 | - if($target === false) |
|
137 | + if ($target === false) |
|
138 | 138 | { |
139 | 139 | return $var; |
140 | 140 | } |
141 | 141 | |
142 | - if($is_object) |
|
142 | + if ($is_object) |
|
143 | 143 | { |
144 | 144 | $var->{$name0} = $target; |
145 | 145 | } |
@@ -151,18 +151,18 @@ discard block |
||
151 | 151 | return $var; |
152 | 152 | } |
153 | 153 | |
154 | - foreach($var as $key => $target) |
|
154 | + foreach ($var as $key => $target) |
|
155 | 155 | { |
156 | 156 | $cloned_name = array_slice($name, 0); |
157 | 157 | $target = $this->_encodeHTML($target, $name); |
158 | 158 | $name = $cloned_name; |
159 | 159 | |
160 | - if($target === false) |
|
160 | + if ($target === false) |
|
161 | 161 | { |
162 | 162 | continue; |
163 | 163 | } |
164 | 164 | |
165 | - if($is_object) |
|
165 | + if ($is_object) |
|
166 | 166 | { |
167 | 167 | $var->{$key} = $target; |
168 | 168 | } |
@@ -185,17 +185,17 @@ discard block |
||
185 | 185 | */ |
186 | 186 | static function detectingXEE($xml) |
187 | 187 | { |
188 | - if(!$xml) return FALSE; |
|
188 | + if (!$xml) return FALSE; |
|
189 | 189 | |
190 | - if(strpos($xml, '<!ENTITY') !== FALSE) |
|
190 | + if (strpos($xml, '<!ENTITY') !== FALSE) |
|
191 | 191 | { |
192 | 192 | return TRUE; |
193 | 193 | } |
194 | 194 | |
195 | 195 | // Strip XML declaration. |
196 | - $header = preg_replace('/<\?xml.*?\?'.'>/s', '', substr($xml, 0, 100), 1); |
|
196 | + $header = preg_replace('/<\?xml.*?\?' . '>/s', '', substr($xml, 0, 100), 1); |
|
197 | 197 | $xml = trim(substr_replace($xml, $header, 0, 100)); |
198 | - if($xml == '') |
|
198 | + if ($xml == '') |
|
199 | 199 | { |
200 | 200 | return TRUE; |
201 | 201 | } |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | // Strip DTD. |
204 | 204 | $header = preg_replace('/^<!DOCTYPE[^>]*+>/i', '', substr($xml, 0, 200), 1); |
205 | 205 | $xml = trim(substr_replace($xml, $header, 0, 200)); |
206 | - if($xml == '') |
|
206 | + if ($xml == '') |
|
207 | 207 | { |
208 | 208 | return TRUE; |
209 | 209 | } |
@@ -212,12 +212,12 @@ discard block |
||
212 | 212 | $root_tag = substr($xml, 0, strcspn(substr($xml, 0, 20), "> \t\r\n")); |
213 | 213 | |
214 | 214 | // Reject a second DTD. |
215 | - if(strtoupper($root_tag) == '<!DOCTYPE') |
|
215 | + if (strtoupper($root_tag) == '<!DOCTYPE') |
|
216 | 216 | { |
217 | 217 | return TRUE; |
218 | 218 | } |
219 | 219 | |
220 | - if(!in_array($root_tag, array('<methodCall', '<methodResponse', '<fault'))) |
|
220 | + if (!in_array($root_tag, array('<methodCall', '<methodResponse', '<fault'))) |
|
221 | 221 | { |
222 | 222 | return TRUE; |
223 | 223 | } |
@@ -60,12 +60,10 @@ discard block |
||
60 | 60 | if($use_context) |
61 | 61 | { |
62 | 62 | $var = Context::get($varName0); |
63 | - } |
|
64 | - elseif($varName0) |
|
63 | + } elseif($varName0) |
|
65 | 64 | { |
66 | 65 | $var = $is_object ? $this->_targetVar->{$varName0} : $this->_targetVar[$varName0]; |
67 | - } |
|
68 | - else |
|
66 | + } else |
|
69 | 67 | { |
70 | 68 | $var = $this->_targetVar; |
71 | 69 | } |
@@ -79,19 +77,16 @@ discard block |
||
79 | 77 | if($use_context) |
80 | 78 | { |
81 | 79 | Context::set($varName0, $var); |
82 | - } |
|
83 | - elseif($varName0) |
|
80 | + } elseif($varName0) |
|
84 | 81 | { |
85 | 82 | if($is_object) |
86 | 83 | { |
87 | 84 | $this->_targetVar->{$varName0} = $var; |
88 | - } |
|
89 | - else |
|
85 | + } else |
|
90 | 86 | { |
91 | 87 | $this->_targetVar[$varName0] = $var; |
92 | 88 | } |
93 | - } |
|
94 | - else |
|
89 | + } else |
|
95 | 90 | { |
96 | 91 | $this->_targetVar = $var; |
97 | 92 | } |
@@ -142,8 +137,7 @@ discard block |
||
142 | 137 | if($is_object) |
143 | 138 | { |
144 | 139 | $var->{$name0} = $target; |
145 | - } |
|
146 | - else |
|
140 | + } else |
|
147 | 141 | { |
148 | 142 | $var[$name0] = $target; |
149 | 143 | } |
@@ -165,8 +159,7 @@ discard block |
||
165 | 159 | if($is_object) |
166 | 160 | { |
167 | 161 | $var->{$key} = $target; |
168 | - } |
|
169 | - else |
|
162 | + } else |
|
170 | 163 | { |
171 | 164 | $var[$key] = $target; |
172 | 165 | } |
@@ -185,7 +178,9 @@ discard block |
||
185 | 178 | */ |
186 | 179 | static function detectingXEE($xml) |
187 | 180 | { |
188 | - if(!$xml) return FALSE; |
|
181 | + if(!$xml) { |
|
182 | + return FALSE; |
|
183 | + } |
|
189 | 184 | |
190 | 185 | if(strpos($xml, '<!ENTITY') !== FALSE) |
191 | 186 | { |
@@ -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 | { |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | //parse error |
377 | 377 | if ($error_info['type'] == 4) |
378 | 378 | { |
379 | - throw new Exception("Error Parsing Template - {$error_info['message']} in template file {$this->file}"); |
|
379 | + throw new Exception("Error Parsing Template - {$error_info['message']} in template file {$this->file}"); |
|
380 | 380 | } |
381 | 381 | } |
382 | 382 | else |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | //parse error |
393 | 393 | if ($error_info['type'] == 4) |
394 | 394 | { |
395 | - throw new Exception("Error Parsing Template - {$error_info['message']} in template file {$this->file}"); |
|
395 | + throw new Exception("Error Parsing Template - {$error_info['message']} in template file {$this->file}"); |
|
396 | 396 | } |
397 | 397 | } |
398 | 398 |
@@ -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 $skipTags = NULL; |
@@ -41,9 +41,9 @@ discard block |
||
41 | 41 | { |
42 | 42 | static $oTemplate = NULL; |
43 | 43 | |
44 | - if(__DEBUG__ == 3) |
|
44 | + if (__DEBUG__ == 3) |
|
45 | 45 | { |
46 | - if(!isset($GLOBALS['__TemplateHandlerCalled__'])) |
|
46 | + if (!isset($GLOBALS['__TemplateHandlerCalled__'])) |
|
47 | 47 | { |
48 | 48 | $GLOBALS['__TemplateHandlerCalled__'] = 1; |
49 | 49 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | } |
54 | 54 | } |
55 | 55 | |
56 | - if(!$oTemplate) |
|
56 | + if (!$oTemplate) |
|
57 | 57 | { |
58 | 58 | $oTemplate = new TemplateHandler(); |
59 | 59 | } |
@@ -71,21 +71,21 @@ discard block |
||
71 | 71 | protected function init($tpl_path, $tpl_filename, $tpl_file = '') |
72 | 72 | { |
73 | 73 | // verify arguments |
74 | - if(substr($tpl_path, -1) != '/') |
|
74 | + if (substr($tpl_path, -1) != '/') |
|
75 | 75 | { |
76 | 76 | $tpl_path .= '/'; |
77 | 77 | } |
78 | - if(!is_dir($tpl_path)) |
|
78 | + if (!is_dir($tpl_path)) |
|
79 | 79 | { |
80 | 80 | return; |
81 | 81 | } |
82 | - if(!file_exists($tpl_path . $tpl_filename) && file_exists($tpl_path . $tpl_filename . '.html')) |
|
82 | + if (!file_exists($tpl_path . $tpl_filename) && file_exists($tpl_path . $tpl_filename . '.html')) |
|
83 | 83 | { |
84 | 84 | $tpl_filename .= '.html'; |
85 | 85 | } |
86 | 86 | |
87 | 87 | // create tpl_file variable |
88 | - if(!$tpl_file) |
|
88 | + if (!$tpl_file) |
|
89 | 89 | { |
90 | 90 | $tpl_file = $tpl_path . $tpl_filename; |
91 | 91 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | $buff = false; |
120 | 120 | |
121 | 121 | // store the starting time for debug information |
122 | - if(__DEBUG__ == 3) |
|
122 | + if (__DEBUG__ == 3) |
|
123 | 123 | { |
124 | 124 | $start = getMicroTime(); |
125 | 125 | } |
@@ -128,13 +128,13 @@ discard block |
||
128 | 128 | $this->init($tpl_path, $tpl_filename, $tpl_file); |
129 | 129 | |
130 | 130 | // if target file does not exist exit |
131 | - if(!$this->file || !file_exists($this->file)) |
|
131 | + if (!$this->file || !file_exists($this->file)) |
|
132 | 132 | { |
133 | 133 | return "Err : '{$this->file}' template file does not exists."; |
134 | 134 | } |
135 | 135 | |
136 | 136 | // for backward compatibility |
137 | - if(is_null(self::$rootTpl)) |
|
137 | + if (is_null(self::$rootTpl)) |
|
138 | 138 | { |
139 | 139 | self::$rootTpl = $this->file; |
140 | 140 | } |
@@ -146,23 +146,23 @@ discard block |
||
146 | 146 | $oCacheHandler = CacheHandler::getInstance('template'); |
147 | 147 | |
148 | 148 | // get cached buff |
149 | - if($oCacheHandler->isSupport()) |
|
149 | + if ($oCacheHandler->isSupport()) |
|
150 | 150 | { |
151 | 151 | $cache_key = 'template:' . $this->file; |
152 | 152 | $buff = $oCacheHandler->get($cache_key, $latest_mtime); |
153 | 153 | } |
154 | 154 | else |
155 | 155 | { |
156 | - if(is_readable($this->compiled_file) && filemtime($this->compiled_file) > $latest_mtime && filesize($this->compiled_file)) |
|
156 | + if (is_readable($this->compiled_file) && filemtime($this->compiled_file) > $latest_mtime && filesize($this->compiled_file)) |
|
157 | 157 | { |
158 | 158 | $buff = 'file://' . $this->compiled_file; |
159 | 159 | } |
160 | 160 | } |
161 | 161 | |
162 | - if($buff === FALSE) |
|
162 | + if ($buff === FALSE) |
|
163 | 163 | { |
164 | 164 | $buff = $this->parse(); |
165 | - if($oCacheHandler->isSupport()) |
|
165 | + if ($oCacheHandler->isSupport()) |
|
166 | 166 | { |
167 | 167 | $oCacheHandler->put($cache_key, $buff); |
168 | 168 | } |
@@ -174,13 +174,13 @@ discard block |
||
174 | 174 | |
175 | 175 | $output = $this->_fetch($buff); |
176 | 176 | |
177 | - if($__templatehandler_root_tpl == $this->file) |
|
177 | + if ($__templatehandler_root_tpl == $this->file) |
|
178 | 178 | { |
179 | 179 | $__templatehandler_root_tpl = null; |
180 | 180 | } |
181 | 181 | |
182 | 182 | // store the ending time for debug information |
183 | - if(__DEBUG__ == 3) |
|
183 | + if (__DEBUG__ == 3) |
|
184 | 184 | { |
185 | 185 | $GLOBALS['__template_elapsed__'] += getMicroTime() - $start; |
186 | 186 | } |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | $this->init($tpl_path, $tpl_filename, null); |
200 | 200 | |
201 | 201 | // if target file does not exist exit |
202 | - if(!$this->file || !file_exists($this->file)) |
|
202 | + if (!$this->file || !file_exists($this->file)) |
|
203 | 203 | { |
204 | 204 | Context::close(); |
205 | 205 | exit("Cannot find the template file: '{$this->file}'"); |
@@ -215,9 +215,9 @@ discard block |
||
215 | 215 | */ |
216 | 216 | protected function parse($buff = null) |
217 | 217 | { |
218 | - if(is_null($buff)) |
|
218 | + if (is_null($buff)) |
|
219 | 219 | { |
220 | - if(!is_readable($this->file)) |
|
220 | + if (!is_readable($this->file)) |
|
221 | 221 | { |
222 | 222 | return; |
223 | 223 | } |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | } |
228 | 228 | |
229 | 229 | // HTML tags to skip |
230 | - if(is_null($this->skipTags)) |
|
230 | + if (is_null($this->skipTags)) |
|
231 | 231 | { |
232 | 232 | $this->skipTags = array('marquee'); |
233 | 233 | } |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | |
250 | 250 | // form auto generation |
251 | 251 | $temp = preg_replace_callback('/(<form(?:<\?php.+?\?>|[^<>]+)*?>)(.*?)(<\/form>)/is', array($this, '_compileFormAuthGeneration'), $buff); |
252 | - if($temp) |
|
252 | + if ($temp) |
|
253 | 253 | { |
254 | 254 | $buff = $temp; |
255 | 255 | } |
@@ -275,19 +275,19 @@ discard block |
||
275 | 275 | private function _compileFormAuthGeneration($matches) |
276 | 276 | { |
277 | 277 | // form ruleset attribute move to hidden tag |
278 | - if($matches[1]) |
|
278 | + if ($matches[1]) |
|
279 | 279 | { |
280 | 280 | preg_match('/ruleset="([^"]*?)"/is', $matches[1], $m); |
281 | - if($m[0]) |
|
281 | + if ($m[0]) |
|
282 | 282 | { |
283 | 283 | $matches[1] = preg_replace('/' . addcslashes($m[0], '?$') . '/i', '', $matches[1]); |
284 | 284 | |
285 | - if(strpos($m[1], '@') !== FALSE) |
|
285 | + if (strpos($m[1], '@') !== FALSE) |
|
286 | 286 | { |
287 | 287 | $path = str_replace('@', '', $m[1]); |
288 | 288 | $path = './files/ruleset/' . $path . '.xml'; |
289 | 289 | } |
290 | - else if(strpos($m[1], '#') !== FALSE) |
|
290 | + else if (strpos($m[1], '#') !== FALSE) |
|
291 | 291 | { |
292 | 292 | $fileName = str_replace('#', '', $m[1]); |
293 | 293 | $fileName = str_replace('<?php echo ', '', $fileName); |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | $autoPath = $module_path . '/ruleset/' . $rulsetFile . '.xml'; |
301 | 301 | $m[1] = $rulsetFile; |
302 | 302 | } |
303 | - else if(preg_match('@(?:^|\.?/)(modules/[\w-]+)@', $this->path, $mm)) |
|
303 | + else if (preg_match('@(?:^|\.?/)(modules/[\w-]+)@', $this->path, $mm)) |
|
304 | 304 | { |
305 | 305 | $module_path = $mm[1]; |
306 | 306 | $path = $module_path . '/ruleset/' . $m[1] . '.xml'; |
@@ -316,10 +316,10 @@ discard block |
||
316 | 316 | preg_match_all('/<input[^>]* name="(act|mid|vid)"/is', $matches[2], $m2); |
317 | 317 | $checkVar = array('act', 'mid', 'vid'); |
318 | 318 | $resultArray = array_diff($checkVar, $m2[1]); |
319 | - if(is_array($resultArray)) |
|
319 | + if (is_array($resultArray)) |
|
320 | 320 | { |
321 | 321 | $generatedHidden = ''; |
322 | - foreach($resultArray AS $key => $value) |
|
322 | + foreach ($resultArray AS $key => $value) |
|
323 | 323 | { |
324 | 324 | $generatedHidden .= '<input type="hidden" name="' . $value . '" value="<?php echo $__Context->' . $value . ' ?>" />'; |
325 | 325 | } |
@@ -327,10 +327,10 @@ discard block |
||
327 | 327 | } |
328 | 328 | |
329 | 329 | // return url generate |
330 | - if(!preg_match('/no-error-return-url="true"/i', $matches[1])) |
|
330 | + if (!preg_match('/no-error-return-url="true"/i', $matches[1])) |
|
331 | 331 | { |
332 | 332 | preg_match('/<input[^>]*name="error_return_url"[^>]*>/is', $matches[2], $m3); |
333 | - if(!$m3[0]) |
|
333 | + if (!$m3[0]) |
|
334 | 334 | $matches[2] = '<input type="hidden" name="error_return_url" value="<?php echo htmlspecialchars(getRequestUriByServerEnviroment(), ENT_COMPAT | ENT_HTML401, \'UTF-8\', false) ?>" />' . $matches[2]; |
335 | 335 | } |
336 | 336 | else |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | */ |
350 | 350 | private function _fetch($buff) |
351 | 351 | { |
352 | - if(!$buff) |
|
352 | + if (!$buff) |
|
353 | 353 | { |
354 | 354 | return; |
355 | 355 | } |
@@ -357,16 +357,16 @@ discard block |
||
357 | 357 | $__Context = &$GLOBALS['__Context__']; |
358 | 358 | $__Context->tpl_path = $this->path; |
359 | 359 | |
360 | - if($_SESSION['is_logged']) |
|
360 | + if ($_SESSION['is_logged']) |
|
361 | 361 | { |
362 | 362 | $__Context->logged_info = Context::get('logged_info'); |
363 | 363 | } |
364 | 364 | |
365 | 365 | $level = ob_get_level(); |
366 | 366 | ob_start(); |
367 | - if(substr($buff, 0, 7) == 'file://') |
|
367 | + if (substr($buff, 0, 7) == 'file://') |
|
368 | 368 | { |
369 | - if(__DEBUG__) |
|
369 | + if (__DEBUG__) |
|
370 | 370 | { |
371 | 371 | //load cache file from disk |
372 | 372 | $eval_str = FileHandler::readFile(substr($buff, 7)); |
@@ -415,13 +415,13 @@ discard block |
||
415 | 415 | private function _replacePath($match) |
416 | 416 | { |
417 | 417 | //return origin conde when src value started '${'. |
418 | - if(preg_match('@^\${@', $match[1])) |
|
418 | + if (preg_match('@^\${@', $match[1])) |
|
419 | 419 | { |
420 | 420 | return $match[0]; |
421 | 421 | } |
422 | 422 | |
423 | 423 | //return origin code when src value include variable. |
424 | - if(preg_match('@^[\'|"]\s*\.\s*\$@', $match[1])) |
|
424 | + if (preg_match('@^[\'|"]\s*\.\s*\$@', $match[1])) |
|
425 | 425 | { |
426 | 426 | return $match[0]; |
427 | 427 | } |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | // for backward compatibility |
435 | 435 | $src = preg_replace('@/((?:[\w-]+/)+)\1@', '/\1', $src); |
436 | 436 | |
437 | - while(($tmp = preg_replace('@[^/]+/\.\./@', '', $src, 1)) !== $src) |
|
437 | + while (($tmp = preg_replace('@[^/]+/\.\./@', '', $src, 1)) !== $src) |
|
438 | 438 | { |
439 | 439 | $src = $tmp; |
440 | 440 | } |
@@ -449,14 +449,14 @@ discard block |
||
449 | 449 | */ |
450 | 450 | private function _parseInline($buff) |
451 | 451 | { |
452 | - if(preg_match_all('/<([a-zA-Z]+\d?)(?>(?!<[a-z]+\d?[\s>]).)*?(?:[ \|]cond| loop)="/s', $buff, $match) === false) |
|
452 | + if (preg_match_all('/<([a-zA-Z]+\d?)(?>(?!<[a-z]+\d?[\s>]).)*?(?:[ \|]cond| loop)="/s', $buff, $match) === false) |
|
453 | 453 | { |
454 | 454 | return $buff; |
455 | 455 | } |
456 | 456 | |
457 | 457 | $tags = array_diff(array_unique($match[1]), $this->skipTags); |
458 | 458 | |
459 | - if(!count($tags)) |
|
459 | + if (!count($tags)) |
|
460 | 460 | { |
461 | 461 | return $buff; |
462 | 462 | } |
@@ -469,14 +469,14 @@ discard block |
||
469 | 469 | // list of self closing tags |
470 | 470 | $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); |
471 | 471 | |
472 | - for($idx = 1, $node_len = count($nodes); $idx < $node_len; $idx+=2) |
|
472 | + for ($idx = 1, $node_len = count($nodes); $idx < $node_len; $idx += 2) |
|
473 | 473 | { |
474 | - if(!($node = $nodes[$idx])) |
|
474 | + if (!($node = $nodes[$idx])) |
|
475 | 475 | { |
476 | 476 | continue; |
477 | 477 | } |
478 | 478 | |
479 | - if(preg_match_all('@\s(loop|cond)="([^"]+)"@', $node, $matches)) |
|
479 | + if (preg_match_all('@\s(loop|cond)="([^"]+)"@', $node, $matches)) |
|
480 | 480 | { |
481 | 481 | // this tag |
482 | 482 | $tag = substr($node, 1, strpos($node, ' ') - 1); |
@@ -485,37 +485,37 @@ discard block |
||
485 | 485 | $closing = 0; |
486 | 486 | |
487 | 487 | // process opening tag |
488 | - foreach($matches[1] as $n => $stmt) |
|
488 | + foreach ($matches[1] as $n => $stmt) |
|
489 | 489 | { |
490 | 490 | $expr = $matches[2][$n]; |
491 | 491 | $expr = $this->_replaceVar($expr); |
492 | 492 | $closing++; |
493 | 493 | |
494 | - switch($stmt) |
|
494 | + switch ($stmt) |
|
495 | 495 | { |
496 | 496 | case 'cond': |
497 | 497 | $nodes[$idx - 1] .= "<?php if({$expr}){ ?>"; |
498 | 498 | break; |
499 | 499 | case 'loop': |
500 | - if(!preg_match('@^(?:(.+?)=>(.+?)(?:,(.+?))?|(.*?;.*?;.*?)|(.+?)\s*=\s*(.+?))$@', $expr, $expr_m)) |
|
500 | + if (!preg_match('@^(?:(.+?)=>(.+?)(?:,(.+?))?|(.*?;.*?;.*?)|(.+?)\s*=\s*(.+?))$@', $expr, $expr_m)) |
|
501 | 501 | { |
502 | 502 | break; |
503 | 503 | } |
504 | - if($expr_m[1]) |
|
504 | + if ($expr_m[1]) |
|
505 | 505 | { |
506 | 506 | $expr_m[1] = trim($expr_m[1]); |
507 | 507 | $expr_m[2] = trim($expr_m[2]); |
508 | - if($expr_m[3]) |
|
508 | + if ($expr_m[3]) |
|
509 | 509 | { |
510 | 510 | $expr_m[2] .= '=>' . trim($expr_m[3]); |
511 | 511 | } |
512 | 512 | $nodes[$idx - 1] .= "<?php if({$expr_m[1]}&&count({$expr_m[1]}))foreach({$expr_m[1]} as {$expr_m[2]}){ ?>"; |
513 | 513 | } |
514 | - elseif($expr_m[4]) |
|
514 | + elseif ($expr_m[4]) |
|
515 | 515 | { |
516 | 516 | $nodes[$idx - 1] .= "<?php for({$expr_m[4]}){ ?>"; |
517 | 517 | } |
518 | - elseif($expr_m[5]) |
|
518 | + elseif ($expr_m[5]) |
|
519 | 519 | { |
520 | 520 | $nodes[$idx - 1] .= "<?php while({$expr_m[5]}={$expr_m[6]}){ ?>"; |
521 | 521 | } |
@@ -527,24 +527,24 @@ discard block |
||
527 | 527 | // find closing tag |
528 | 528 | $close_php = '<?php ' . str_repeat('}', $closing) . ' ?>'; |
529 | 529 | // self closing tag |
530 | - if($node{1} == '!' || substr($node, -2, 1) == '/' || isset($self_closing[$tag])) |
|
530 | + if ($node{1} == '!' || substr($node, -2, 1) == '/' || isset($self_closing[$tag])) |
|
531 | 531 | { |
532 | 532 | $nodes[$idx + 1] = $close_php . $nodes[$idx + 1]; |
533 | 533 | } |
534 | 534 | else |
535 | 535 | { |
536 | 536 | $depth = 1; |
537 | - for($i = $idx + 2; $i < $node_len; $i+=2) |
|
537 | + for ($i = $idx + 2; $i < $node_len; $i += 2) |
|
538 | 538 | { |
539 | 539 | $nd = $nodes[$i]; |
540 | - if(strpos($nd, $tag) === 1) |
|
540 | + if (strpos($nd, $tag) === 1) |
|
541 | 541 | { |
542 | 542 | $depth++; |
543 | 543 | } |
544 | - elseif(strpos($nd, '/' . $tag) === 1) |
|
544 | + elseif (strpos($nd, '/' . $tag) === 1) |
|
545 | 545 | { |
546 | 546 | $depth--; |
547 | - if(!$depth) |
|
547 | + if (!$depth) |
|
548 | 548 | { |
549 | 549 | $nodes[$i - 1] .= $nodes[$i] . $close_php; |
550 | 550 | $nodes[$i] = ''; |
@@ -555,13 +555,13 @@ discard block |
||
555 | 555 | } |
556 | 556 | } |
557 | 557 | |
558 | - if(strpos($node, '|cond="') !== false) |
|
558 | + if (strpos($node, '|cond="') !== false) |
|
559 | 559 | { |
560 | 560 | $node = preg_replace('@(\s[-\w:]+(?:="[^"]+?")?)\|cond="(.+?)"@s', '<?php if($2){ ?>$1<?php } ?>', $node); |
561 | 561 | $node = $this->_replaceVar($node); |
562 | 562 | } |
563 | 563 | |
564 | - if($nodes[$idx] != $node) |
|
564 | + if ($nodes[$idx] != $node) |
|
565 | 565 | { |
566 | 566 | $nodes[$idx] = $node; |
567 | 567 | } |
@@ -581,15 +581,15 @@ discard block |
||
581 | 581 | private function _parseResource($m) |
582 | 582 | { |
583 | 583 | // {@ ... } or {$var} or {func(...)} |
584 | - if($m[1]) |
|
584 | + if ($m[1]) |
|
585 | 585 | { |
586 | - if(preg_match('@^(\w+)\(@', $m[1], $mm) && !function_exists($mm[1])) |
|
586 | + if (preg_match('@^(\w+)\(@', $m[1], $mm) && !function_exists($mm[1])) |
|
587 | 587 | { |
588 | 588 | return $m[0]; |
589 | 589 | } |
590 | 590 | |
591 | 591 | $echo = 'echo '; |
592 | - if($m[1]{0} == '@') |
|
592 | + if ($m[1]{0} == '@') |
|
593 | 593 | { |
594 | 594 | $echo = ''; |
595 | 595 | $m[1] = substr($m[1], 1); |
@@ -597,14 +597,14 @@ discard block |
||
597 | 597 | return '<?php ' . $echo . $this->_replaceVar($m[1]) . ' ?>'; |
598 | 598 | } |
599 | 599 | |
600 | - if($m[3]) |
|
600 | + if ($m[3]) |
|
601 | 601 | { |
602 | 602 | $attr = array(); |
603 | - if($m[5]) |
|
603 | + if ($m[5]) |
|
604 | 604 | { |
605 | - if(preg_match_all('@,(\w+)="([^"]+)"@', $m[6], $mm)) |
|
605 | + if (preg_match_all('@,(\w+)="([^"]+)"@', $m[6], $mm)) |
|
606 | 606 | { |
607 | - foreach($mm[1] as $idx => $name) |
|
607 | + foreach ($mm[1] as $idx => $name) |
|
608 | 608 | { |
609 | 609 | $attr[$name] = $mm[2][$idx]; |
610 | 610 | } |
@@ -613,21 +613,21 @@ discard block |
||
613 | 613 | } |
614 | 614 | else |
615 | 615 | { |
616 | - if(!preg_match_all('@ (\w+)="([^"]+)"@', $m[6], $mm)) |
|
616 | + if (!preg_match_all('@ (\w+)="([^"]+)"@', $m[6], $mm)) |
|
617 | 617 | { |
618 | 618 | return $m[0]; |
619 | 619 | } |
620 | - foreach($mm[1] as $idx => $name) |
|
620 | + foreach ($mm[1] as $idx => $name) |
|
621 | 621 | { |
622 | 622 | $attr[$name] = $mm[2][$idx]; |
623 | 623 | } |
624 | 624 | } |
625 | 625 | |
626 | - switch($m[3]) |
|
626 | + switch ($m[3]) |
|
627 | 627 | { |
628 | 628 | // <!--#include--> or <include ..> |
629 | 629 | case 'include': |
630 | - if(!$this->file || !$attr['target']) |
|
630 | + if (!$this->file || !$attr['target']) |
|
631 | 631 | { |
632 | 632 | return ''; |
633 | 633 | } |
@@ -635,7 +635,7 @@ discard block |
||
635 | 635 | $pathinfo = pathinfo($attr['target']); |
636 | 636 | $fileDir = $this->_getRelativeDir($pathinfo['dirname']); |
637 | 637 | |
638 | - if(!$fileDir) |
|
638 | + if (!$fileDir) |
|
639 | 639 | { |
640 | 640 | return ''; |
641 | 641 | } |
@@ -645,7 +645,7 @@ discard block |
||
645 | 645 | case 'load_js_plugin': |
646 | 646 | $plugin = $this->_replaceVar($m[5]); |
647 | 647 | $s = "<!--#JSPLUGIN:{$plugin}-->"; |
648 | - if(strpos($plugin, '$__Context') === false) |
|
648 | + if (strpos($plugin, '$__Context') === false) |
|
649 | 649 | { |
650 | 650 | $plugin = "'{$plugin}'"; |
651 | 651 | } |
@@ -661,13 +661,13 @@ discard block |
||
661 | 661 | $doUnload = ($m[3] === 'unload'); |
662 | 662 | $isRemote = !!preg_match('@^(https?:)?//@i', $attr['target']); |
663 | 663 | |
664 | - if(!$isRemote) |
|
664 | + if (!$isRemote) |
|
665 | 665 | { |
666 | - if(!preg_match('@^\.?/@', $attr['target'])) |
|
666 | + if (!preg_match('@^\.?/@', $attr['target'])) |
|
667 | 667 | { |
668 | 668 | $attr['target'] = './' . $attr['target']; |
669 | 669 | } |
670 | - if(substr($attr['target'], -5) == '/lang') |
|
670 | + if (substr($attr['target'], -5) == '/lang') |
|
671 | 671 | { |
672 | 672 | $pathinfo['dirname'] .= '/lang'; |
673 | 673 | $pathinfo['basename'] = ''; |
@@ -679,15 +679,15 @@ discard block |
||
679 | 679 | $attr['target'] = $relativeDir . '/' . $pathinfo['basename']; |
680 | 680 | } |
681 | 681 | |
682 | - switch($pathinfo['extension']) |
|
682 | + switch ($pathinfo['extension']) |
|
683 | 683 | { |
684 | 684 | case 'xml': |
685 | - if($isRemote || $doUnload) |
|
685 | + if ($isRemote || $doUnload) |
|
686 | 686 | { |
687 | 687 | return ''; |
688 | 688 | } |
689 | 689 | // language file? |
690 | - if($pathinfo['basename'] == 'lang.xml' || substr($pathinfo['dirname'], -5) == '/lang') |
|
690 | + if ($pathinfo['basename'] == 'lang.xml' || substr($pathinfo['dirname'], -5) == '/lang') |
|
691 | 691 | { |
692 | 692 | $result = "Context::loadLang('{$relativeDir}');"; |
693 | 693 | } |
@@ -697,7 +697,7 @@ discard block |
||
697 | 697 | } |
698 | 698 | break; |
699 | 699 | case 'js': |
700 | - if($doUnload) |
|
700 | + if ($doUnload) |
|
701 | 701 | { |
702 | 702 | $result = "Context::unloadFile('{$attr['target']}','{$attr['targetie']}');"; |
703 | 703 | } |
@@ -708,7 +708,7 @@ discard block |
||
708 | 708 | } |
709 | 709 | break; |
710 | 710 | case 'css': |
711 | - if($doUnload) |
|
711 | + if ($doUnload) |
|
712 | 712 | { |
713 | 713 | $result = "Context::unloadFile('{$attr['target']}','{$attr['targetie']}','{$attr['media']}');"; |
714 | 714 | } |
@@ -721,7 +721,7 @@ discard block |
||
721 | 721 | } |
722 | 722 | |
723 | 723 | $result = "<?php {$result} ?>"; |
724 | - if($metafile) |
|
724 | + if ($metafile) |
|
725 | 725 | { |
726 | 726 | $result = "<!--#Meta:{$metafile}-->" . $result; |
727 | 727 | } |
@@ -731,45 +731,45 @@ discard block |
||
731 | 731 | } |
732 | 732 | |
733 | 733 | // <[email protected]> such as <!--@if($cond)-->, <!--@else-->, <!--@end--> |
734 | - if($m[7]) |
|
734 | + if ($m[7]) |
|
735 | 735 | { |
736 | 736 | $m[7] = substr($m[7], 1); |
737 | - if(!$m[7]) |
|
737 | + if (!$m[7]) |
|
738 | 738 | { |
739 | 739 | return '<?php ' . $this->_replaceVar($m[8]) . '{ ?>' . $m[9]; |
740 | 740 | } |
741 | - if(!preg_match('/^(?:((?:end)?(?:if|switch|for(?:each)?|while)|end)|(else(?:if)?)|(break@)?(case|default)|(break))$/', $m[7], $mm)) |
|
741 | + if (!preg_match('/^(?:((?:end)?(?:if|switch|for(?:each)?|while)|end)|(else(?:if)?)|(break@)?(case|default)|(break))$/', $m[7], $mm)) |
|
742 | 742 | { |
743 | 743 | return ''; |
744 | 744 | } |
745 | - if($mm[1]) |
|
745 | + if ($mm[1]) |
|
746 | 746 | { |
747 | - if($mm[1]{0} == 'e') |
|
747 | + if ($mm[1]{0} == 'e') |
|
748 | 748 | { |
749 | 749 | return '<?php } ?>' . $m[9]; |
750 | 750 | } |
751 | 751 | |
752 | 752 | $precheck = ''; |
753 | - if($mm[1] == 'switch') |
|
753 | + if ($mm[1] == 'switch') |
|
754 | 754 | { |
755 | 755 | $m[9] = ''; |
756 | 756 | } |
757 | - elseif($mm[1] == 'foreach') |
|
757 | + elseif ($mm[1] == 'foreach') |
|
758 | 758 | { |
759 | 759 | $var = preg_replace('/^\s*\(\s*(.+?) .*$/', '$1', $m[8]); |
760 | 760 | $precheck = "if({$var}&&count({$var}))"; |
761 | 761 | } |
762 | 762 | return '<?php ' . $this->_replaceVar($precheck . $m[7] . $m[8]) . '{ ?>' . $m[9]; |
763 | 763 | } |
764 | - if($mm[2]) |
|
764 | + if ($mm[2]) |
|
765 | 765 | { |
766 | 766 | return "<?php }{$m[7]}" . $this->_replaceVar($m[8]) . "{ ?>" . $m[9]; |
767 | 767 | } |
768 | - if($mm[4]) |
|
768 | + if ($mm[4]) |
|
769 | 769 | { |
770 | 770 | return "<?php " . ($mm[3] ? 'break;' : '') . "{$m[7]} " . trim($m[8], '()') . ": ?>" . $m[9]; |
771 | 771 | } |
772 | - if($mm[5]) |
|
772 | + if ($mm[5]) |
|
773 | 773 | { |
774 | 774 | return "<?php break; ?>"; |
775 | 775 | } |
@@ -788,21 +788,21 @@ discard block |
||
788 | 788 | $_path = $path; |
789 | 789 | |
790 | 790 | $fileDir = strtr(realpath($this->path), '\\', '/'); |
791 | - if($path{0} != '/') |
|
791 | + if ($path{0} != '/') |
|
792 | 792 | { |
793 | 793 | $path = strtr(realpath($fileDir . '/' . $path), '\\', '/'); |
794 | 794 | } |
795 | 795 | |
796 | 796 | // for backward compatibility |
797 | - if(!$path) |
|
797 | + if (!$path) |
|
798 | 798 | { |
799 | 799 | $dirs = explode('/', $fileDir); |
800 | 800 | $paths = explode('/', $_path); |
801 | 801 | $idx = array_search($paths[0], $dirs); |
802 | 802 | |
803 | - if($idx !== false) |
|
803 | + if ($idx !== false) |
|
804 | 804 | { |
805 | - while($dirs[$idx] && $dirs[$idx] === $paths[0]) |
|
805 | + while ($dirs[$idx] && $dirs[$idx] === $paths[0]) |
|
806 | 806 | { |
807 | 807 | array_splice($dirs, $idx, 1); |
808 | 808 | array_shift($paths); |
@@ -823,7 +823,7 @@ discard block |
||
823 | 823 | */ |
824 | 824 | function _replaceVar($php) |
825 | 825 | { |
826 | - if(!strlen($php)) |
|
826 | + if (!strlen($php)) |
|
827 | 827 | { |
828 | 828 | return ''; |
829 | 829 | } |
@@ -46,8 +46,7 @@ discard block |
||
46 | 46 | if(!isset($GLOBALS['__TemplateHandlerCalled__'])) |
47 | 47 | { |
48 | 48 | $GLOBALS['__TemplateHandlerCalled__'] = 1; |
49 | - } |
|
50 | - else |
|
49 | + } else |
|
51 | 50 | { |
52 | 51 | $GLOBALS['__TemplateHandlerCalled__']++; |
53 | 52 | } |
@@ -150,8 +149,7 @@ discard block |
||
150 | 149 | { |
151 | 150 | $cache_key = 'template:' . $this->file; |
152 | 151 | $buff = $oCacheHandler->get($cache_key, $latest_mtime); |
153 | - } |
|
154 | - else |
|
152 | + } else |
|
155 | 153 | { |
156 | 154 | if(is_readable($this->compiled_file) && filemtime($this->compiled_file) > $latest_mtime && filesize($this->compiled_file)) |
157 | 155 | { |
@@ -165,8 +163,7 @@ discard block |
||
165 | 163 | if($oCacheHandler->isSupport()) |
166 | 164 | { |
167 | 165 | $oCacheHandler->put($cache_key, $buff); |
168 | - } |
|
169 | - else |
|
166 | + } else |
|
170 | 167 | { |
171 | 168 | FileHandler::writeFile($this->compiled_file, $buff); |
172 | 169 | } |
@@ -286,8 +283,7 @@ discard block |
||
286 | 283 | { |
287 | 284 | $path = str_replace('@', '', $m[1]); |
288 | 285 | $path = './files/ruleset/' . $path . '.xml'; |
289 | - } |
|
290 | - else if(strpos($m[1], '#') !== FALSE) |
|
286 | + } else if(strpos($m[1], '#') !== FALSE) |
|
291 | 287 | { |
292 | 288 | $fileName = str_replace('#', '', $m[1]); |
293 | 289 | $fileName = str_replace('<?php echo ', '', $fileName); |
@@ -299,8 +295,7 @@ discard block |
||
299 | 295 | list($rulsetFile) = explode('.', $fileName); |
300 | 296 | $autoPath = $module_path . '/ruleset/' . $rulsetFile . '.xml'; |
301 | 297 | $m[1] = $rulsetFile; |
302 | - } |
|
303 | - else if(preg_match('@(?:^|\.?/)(modules/[\w-]+)@', $this->path, $mm)) |
|
298 | + } else if(preg_match('@(?:^|\.?/)(modules/[\w-]+)@', $this->path, $mm)) |
|
304 | 299 | { |
305 | 300 | $module_path = $mm[1]; |
306 | 301 | $path = $module_path . '/ruleset/' . $m[1] . '.xml'; |
@@ -330,10 +325,10 @@ discard block |
||
330 | 325 | if(!preg_match('/no-error-return-url="true"/i', $matches[1])) |
331 | 326 | { |
332 | 327 | preg_match('/<input[^>]*name="error_return_url"[^>]*>/is', $matches[2], $m3); |
333 | - if(!$m3[0]) |
|
334 | - $matches[2] = '<input type="hidden" name="error_return_url" value="<?php echo htmlspecialchars(getRequestUriByServerEnviroment(), ENT_COMPAT | ENT_HTML401, \'UTF-8\', false) ?>" />' . $matches[2]; |
|
335 | - } |
|
336 | - else |
|
328 | + if(!$m3[0]) { |
|
329 | + $matches[2] = '<input type="hidden" name="error_return_url" value="<?php echo htmlspecialchars(getRequestUriByServerEnviroment(), ENT_COMPAT | ENT_HTML401, \'UTF-8\', false) ?>" />' . $matches[2]; |
|
330 | + } |
|
331 | + } else |
|
337 | 332 | { |
338 | 333 | $matches[1] = preg_replace('/no-error-return-url="true"/i', '', $matches[1]); |
339 | 334 | } |
@@ -378,13 +373,11 @@ discard block |
||
378 | 373 | { |
379 | 374 | throw new Exception("Error Parsing Template - {$error_info['message']} in template file {$this->file}"); |
380 | 375 | } |
381 | - } |
|
382 | - else |
|
376 | + } else |
|
383 | 377 | { |
384 | 378 | include(substr($buff, 7)); |
385 | 379 | } |
386 | - } |
|
387 | - else |
|
380 | + } else |
|
388 | 381 | { |
389 | 382 | $eval_str = "?>" . $buff; |
390 | 383 | @eval($eval_str); |
@@ -510,12 +503,10 @@ discard block |
||
510 | 503 | $expr_m[2] .= '=>' . trim($expr_m[3]); |
511 | 504 | } |
512 | 505 | $nodes[$idx - 1] .= "<?php if({$expr_m[1]}&&count({$expr_m[1]}))foreach({$expr_m[1]} as {$expr_m[2]}){ ?>"; |
513 | - } |
|
514 | - elseif($expr_m[4]) |
|
506 | + } elseif($expr_m[4]) |
|
515 | 507 | { |
516 | 508 | $nodes[$idx - 1] .= "<?php for({$expr_m[4]}){ ?>"; |
517 | - } |
|
518 | - elseif($expr_m[5]) |
|
509 | + } elseif($expr_m[5]) |
|
519 | 510 | { |
520 | 511 | $nodes[$idx - 1] .= "<?php while({$expr_m[5]}={$expr_m[6]}){ ?>"; |
521 | 512 | } |
@@ -530,8 +521,7 @@ discard block |
||
530 | 521 | if($node{1} == '!' || substr($node, -2, 1) == '/' || isset($self_closing[$tag])) |
531 | 522 | { |
532 | 523 | $nodes[$idx + 1] = $close_php . $nodes[$idx + 1]; |
533 | - } |
|
534 | - else |
|
524 | + } else |
|
535 | 525 | { |
536 | 526 | $depth = 1; |
537 | 527 | for($i = $idx + 2; $i < $node_len; $i+=2) |
@@ -540,8 +530,7 @@ discard block |
||
540 | 530 | if(strpos($nd, $tag) === 1) |
541 | 531 | { |
542 | 532 | $depth++; |
543 | - } |
|
544 | - elseif(strpos($nd, '/' . $tag) === 1) |
|
533 | + } elseif(strpos($nd, '/' . $tag) === 1) |
|
545 | 534 | { |
546 | 535 | $depth--; |
547 | 536 | if(!$depth) |
@@ -610,8 +599,7 @@ discard block |
||
610 | 599 | } |
611 | 600 | } |
612 | 601 | $attr['target'] = $m[5]; |
613 | - } |
|
614 | - else |
|
602 | + } else |
|
615 | 603 | { |
616 | 604 | if(!preg_match_all('@ (\w+)="([^"]+)"@', $m[6], $mm)) |
617 | 605 | { |
@@ -690,8 +678,7 @@ discard block |
||
690 | 678 | if($pathinfo['basename'] == 'lang.xml' || substr($pathinfo['dirname'], -5) == '/lang') |
691 | 679 | { |
692 | 680 | $result = "Context::loadLang('{$relativeDir}');"; |
693 | - } |
|
694 | - else |
|
681 | + } else |
|
695 | 682 | { |
696 | 683 | $result = "require_once('./classes/xml/XmlJsFilter.class.php');\$__xmlFilter=new XmlJsFilter('{$relativeDir}','{$pathinfo['basename']}');\$__xmlFilter->compile();"; |
697 | 684 | } |
@@ -700,8 +687,7 @@ discard block |
||
700 | 687 | if($doUnload) |
701 | 688 | { |
702 | 689 | $result = "Context::unloadFile('{$attr['target']}','{$attr['targetie']}');"; |
703 | - } |
|
704 | - else |
|
690 | + } else |
|
705 | 691 | { |
706 | 692 | $metafile = $attr['target']; |
707 | 693 | $result = "\$__tmp=array('{$attr['target']}','{$attr['type']}','{$attr['targetie']}','{$attr['index']}');Context::loadFile(\$__tmp);unset(\$__tmp);"; |
@@ -711,8 +697,7 @@ discard block |
||
711 | 697 | if($doUnload) |
712 | 698 | { |
713 | 699 | $result = "Context::unloadFile('{$attr['target']}','{$attr['targetie']}','{$attr['media']}');"; |
714 | - } |
|
715 | - else |
|
700 | + } else |
|
716 | 701 | { |
717 | 702 | $metafile = $attr['target']; |
718 | 703 | $result = "\$__tmp=array('{$attr['target']}','{$attr['media']}','{$attr['targetie']}','{$attr['index']}');Context::loadFile(\$__tmp);unset(\$__tmp);"; |
@@ -753,8 +738,7 @@ discard block |
||
753 | 738 | if($mm[1] == 'switch') |
754 | 739 | { |
755 | 740 | $m[9] = ''; |
756 | - } |
|
757 | - elseif($mm[1] == 'foreach') |
|
741 | + } elseif($mm[1] == 'foreach') |
|
758 | 742 | { |
759 | 743 | $var = preg_replace('/^\s*\(\s*(.+?) .*$/', '$1', $m[8]); |
760 | 744 | $precheck = "if({$var}&&count({$var}))"; |
@@ -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,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 |
@@ -118,32 +118,32 @@ discard block |
||
118 | 118 | $this->_xml_ruleset = NULL; |
119 | 119 | |
120 | 120 | $xml_path = realpath($xml_path); |
121 | - if(!is_readable($xml_path)) |
|
121 | + if (!is_readable($xml_path)) |
|
122 | 122 | { |
123 | 123 | return FALSE; |
124 | 124 | } |
125 | 125 | |
126 | 126 | $parser = new XmlParser(); |
127 | 127 | $xml = $parser->loadXmlFile($xml_path); |
128 | - if(!isset($xml->ruleset) || !isset($xml->ruleset->fields) || !isset($xml->ruleset->fields->field)) |
|
128 | + if (!isset($xml->ruleset) || !isset($xml->ruleset->fields) || !isset($xml->ruleset->fields->field)) |
|
129 | 129 | { |
130 | 130 | return FALSE; |
131 | 131 | } |
132 | 132 | |
133 | 133 | // custom rules |
134 | - if(isset($xml->ruleset->customrules) && isset($xml->ruleset->customrules->rule)) |
|
134 | + if (isset($xml->ruleset->customrules) && isset($xml->ruleset->customrules->rule)) |
|
135 | 135 | { |
136 | 136 | $customrules = $xml->ruleset->customrules->rule; |
137 | - if(!is_array($customrules)) |
|
137 | + if (!is_array($customrules)) |
|
138 | 138 | { |
139 | 139 | $customrules = array($customrules); |
140 | 140 | } |
141 | 141 | |
142 | 142 | $rules = array(); |
143 | 143 | $messages = array(); |
144 | - foreach($customrules as $rule) |
|
144 | + foreach ($customrules as $rule) |
|
145 | 145 | { |
146 | - if(!isset($rule->attrs) || !isset($rule->attrs->name)) |
|
146 | + if (!isset($rule->attrs) || !isset($rule->attrs->name)) |
|
147 | 147 | { |
148 | 148 | continue; |
149 | 149 | } |
@@ -155,12 +155,12 @@ discard block |
||
155 | 155 | unset($rule['name']); |
156 | 156 | |
157 | 157 | $rules[$name] = $rule; |
158 | - if(isset($message)) |
|
158 | + if (isset($message)) |
|
159 | 159 | { |
160 | 160 | $messages['invalid_' . $name] = $message; |
161 | 161 | } |
162 | 162 | } |
163 | - if(count($rules)) |
|
163 | + if (count($rules)) |
|
164 | 164 | { |
165 | 165 | $this->addRule($rules); |
166 | 166 | } |
@@ -168,19 +168,19 @@ discard block |
||
168 | 168 | |
169 | 169 | // filters |
170 | 170 | $fields = $xml->ruleset->fields->field; |
171 | - if(!is_array($fields)) |
|
171 | + if (!is_array($fields)) |
|
172 | 172 | { |
173 | 173 | $fields = array($fields); |
174 | 174 | } |
175 | 175 | |
176 | 176 | $filters = array(); |
177 | 177 | $fieldsNames = array(); |
178 | - foreach($fields as $field) |
|
178 | + foreach ($fields as $field) |
|
179 | 179 | { |
180 | 180 | $name = ''; |
181 | 181 | $filter = array(); |
182 | 182 | |
183 | - if(!isset($field->attrs) || !isset($field->attrs->name)) |
|
183 | + if (!isset($field->attrs) || !isset($field->attrs->name)) |
|
184 | 184 | { |
185 | 185 | continue; |
186 | 186 | } |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | $filter['title'] = $title; |
191 | 191 | |
192 | 192 | $name = $filter['name']; |
193 | - if(isset($title)) |
|
193 | + if (isset($title)) |
|
194 | 194 | { |
195 | 195 | $fieldsNames[$name] = $title; |
196 | 196 | } |
@@ -198,14 +198,14 @@ discard block |
||
198 | 198 | unset($filter['name']); |
199 | 199 | |
200 | 200 | // conditional statement |
201 | - if(isset($field->if)) |
|
201 | + if (isset($field->if)) |
|
202 | 202 | { |
203 | 203 | $if = $field->if; |
204 | - if(!is_array($if)) |
|
204 | + if (!is_array($if)) |
|
205 | 205 | { |
206 | 206 | $if = array($if); |
207 | 207 | } |
208 | - foreach($if as $idx => $cond) |
|
208 | + foreach ($if as $idx => $cond) |
|
209 | 209 | { |
210 | 210 | $if[$idx] = (array) $cond->attrs; |
211 | 211 | } |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | */ |
232 | 232 | function setCacheDir($cache_dir) |
233 | 233 | { |
234 | - if(is_dir($cache_dir)) |
|
234 | + if (is_dir($cache_dir)) |
|
235 | 235 | { |
236 | 236 | $this->_cache_dir = preg_replace('@/$@', '', $cache_dir); |
237 | 237 | } |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | */ |
245 | 245 | function validate($fields_ = null) |
246 | 246 | { |
247 | - if(is_array($fields_)) |
|
247 | + if (is_array($fields_)) |
|
248 | 248 | { |
249 | 249 | $fields = $fields_; |
250 | 250 | } |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | $fields = (array) Context::getRequestVars(); |
255 | 255 | } |
256 | 256 | |
257 | - if(!is_array($fields)) |
|
257 | + if (!is_array($fields)) |
|
258 | 258 | { |
259 | 259 | return TRUE; |
260 | 260 | } |
@@ -275,14 +275,14 @@ discard block |
||
275 | 275 | $filters = array(); |
276 | 276 | |
277 | 277 | // get field names matching patterns |
278 | - foreach($this->_filters as $key => $filter) |
|
278 | + foreach ($this->_filters as $key => $filter) |
|
279 | 279 | { |
280 | 280 | $names = array(); |
281 | - if($key{0} == '^') |
|
281 | + if ($key{0} == '^') |
|
282 | 282 | { |
283 | 283 | $names = preg_grep('/^' . preg_quote(substr($key, 1)) . '/', $field_names); |
284 | 284 | } |
285 | - elseif(substr($key, -2) == '[]') |
|
285 | + elseif (substr($key, -2) == '[]') |
|
286 | 286 | { |
287 | 287 | $filters[substr($key, 0, -2)] = $filter; |
288 | 288 | unset($filters[$key]); |
@@ -292,24 +292,24 @@ discard block |
||
292 | 292 | $filters[$key] = $filter; |
293 | 293 | } |
294 | 294 | |
295 | - if(!count($names)) |
|
295 | + if (!count($names)) |
|
296 | 296 | { |
297 | 297 | continue; |
298 | 298 | } |
299 | 299 | |
300 | - foreach($names as $name) |
|
300 | + foreach ($names as $name) |
|
301 | 301 | { |
302 | 302 | $filters[$name] = $filter; |
303 | 303 | } |
304 | 304 | unset($filters[$key]); |
305 | 305 | } |
306 | 306 | |
307 | - foreach($filters as $key => $filter) |
|
307 | + foreach ($filters as $key => $filter) |
|
308 | 308 | { |
309 | 309 | $fname = preg_replace('/\[\]$/', '', $key); |
310 | 310 | $filter = array_merge($filter_default, $filter); |
311 | 311 | |
312 | - if(preg_match("/(^[a-z_]*)[\[](?:\'|\")?([a-z_]*)(?:\'|\")?[\]]$/i", $key, $matches)) |
|
312 | + if (preg_match("/(^[a-z_]*)[\[](?:\'|\")?([a-z_]*)(?:\'|\")?[\]]$/i", $key, $matches)) |
|
313 | 313 | { |
314 | 314 | $exists = array_key_exists($matches[1], $fields); |
315 | 315 | $value = $exists ? $fields[$matches[1]][$matches[2]] : NULL; |
@@ -320,9 +320,9 @@ discard block |
||
320 | 320 | $value = $exists ? $fields[$fname] : NULL; |
321 | 321 | } |
322 | 322 | |
323 | - if(is_array($value)) |
|
323 | + if (is_array($value)) |
|
324 | 324 | { |
325 | - if(!isset($value[tmp_name])) |
|
325 | + if (!isset($value[tmp_name])) |
|
326 | 326 | { |
327 | 327 | $value = implode('', $value); |
328 | 328 | } |
@@ -333,9 +333,9 @@ discard block |
||
333 | 333 | } |
334 | 334 | |
335 | 335 | // conditional statement |
336 | - foreach($filter['if'] as $cond) |
|
336 | + foreach ($filter['if'] as $cond) |
|
337 | 337 | { |
338 | - if(!isset($cond['test']) || !isset($cond['attr'])) |
|
338 | + if (!isset($cond['test']) || !isset($cond['attr'])) |
|
339 | 339 | { |
340 | 340 | continue; |
341 | 341 | } |
@@ -343,17 +343,17 @@ discard block |
||
343 | 343 | $func_body = preg_replace('/\\$(\w+)/', '$c[\'$1\']', $cond['test']); |
344 | 344 | $func = create_function('$c', "return !!({$func_body});"); |
345 | 345 | |
346 | - if($func($fields)) |
|
346 | + if ($func($fields)) |
|
347 | 347 | { |
348 | 348 | $filter[$cond['attr']] = $cond['value']; |
349 | 349 | } |
350 | 350 | } |
351 | 351 | |
352 | 352 | // attr : default |
353 | - if(!$value && strlen($default = trim($filter['default']))) |
|
353 | + if (!$value && strlen($default = trim($filter['default']))) |
|
354 | 354 | { |
355 | 355 | $value = $default; |
356 | - if(is_null($fields_)) |
|
356 | + if (is_null($fields_)) |
|
357 | 357 | { |
358 | 358 | Context::set($fname, $value); |
359 | 359 | } |
@@ -365,25 +365,25 @@ discard block |
||
365 | 365 | $value_len = strlen($value); |
366 | 366 | |
367 | 367 | // attr : modifier |
368 | - if(is_string($modifiers = $filter['modifiers'])) |
|
368 | + if (is_string($modifiers = $filter['modifiers'])) |
|
369 | 369 | { |
370 | 370 | $modifiers = explode(',', trim($modifiers)); |
371 | 371 | } |
372 | 372 | |
373 | 373 | // attr : required |
374 | - if($filter['required'] === 'true' && !$value_len) |
|
374 | + if ($filter['required'] === 'true' && !$value_len) |
|
375 | 375 | { |
376 | 376 | return $this->error($key, 'isnull'); |
377 | 377 | } |
378 | 378 | |
379 | 379 | // if the field wasn't passed, ignore this value |
380 | - if(!$exists && !$value_len) |
|
380 | + if (!$exists && !$value_len) |
|
381 | 381 | { |
382 | 382 | continue; |
383 | 383 | } |
384 | 384 | |
385 | 385 | // attr : length |
386 | - if($length = $filter['length']) |
|
386 | + if ($length = $filter['length']) |
|
387 | 387 | { |
388 | 388 | list($min, $max) = explode(':', trim($length)); |
389 | 389 | $is_min_b = (substr($min, -1) === 'b'); |
@@ -391,39 +391,39 @@ discard block |
||
391 | 391 | list($min, $max) = array((int) $min, (int) $max); |
392 | 392 | |
393 | 393 | $strbytes = strlen($value); |
394 | - if(!$is_min_b || !$is_max_b) |
|
394 | + if (!$is_min_b || !$is_max_b) |
|
395 | 395 | { |
396 | 396 | $strlength = $this->_has_mb_func ? mb_strlen($value, 'utf-8') : $this->mbStrLen($value); |
397 | 397 | } |
398 | 398 | |
399 | - if(($min && $min > ($is_min_b ? $strbytes : $strlength)) || ($max && $max < ($is_max_b ? $strbytes : $strlength))) |
|
399 | + if (($min && $min > ($is_min_b ? $strbytes : $strlength)) || ($max && $max < ($is_max_b ? $strbytes : $strlength))) |
|
400 | 400 | { |
401 | 401 | return $this->error($key, 'outofrange'); |
402 | 402 | } |
403 | 403 | } |
404 | 404 | |
405 | 405 | // equalto |
406 | - if($equalto = $filter['equalto']) |
|
406 | + if ($equalto = $filter['equalto']) |
|
407 | 407 | { |
408 | - if(!array_key_exists($equalto, $fields) || trim($fields[$equalto]) !== $value) |
|
408 | + if (!array_key_exists($equalto, $fields) || trim($fields[$equalto]) !== $value) |
|
409 | 409 | { |
410 | 410 | return $this->error($key, 'equalto'); |
411 | 411 | } |
412 | 412 | } |
413 | 413 | |
414 | 414 | // rules |
415 | - if($rules = $filter['rule']) |
|
415 | + if ($rules = $filter['rule']) |
|
416 | 416 | { |
417 | 417 | $rules = explode(',', $rules); |
418 | - foreach($rules as $rule) |
|
418 | + foreach ($rules as $rule) |
|
419 | 419 | { |
420 | 420 | $result = $this->applyRule($rule, $value); |
421 | 421 | // apply the 'not' modifier |
422 | - if(in_array('not', $modifiers)) |
|
422 | + if (in_array('not', $modifiers)) |
|
423 | 423 | { |
424 | 424 | $result = !$result; |
425 | 425 | } |
426 | - if(!$result) |
|
426 | + if (!$result) |
|
427 | 427 | { |
428 | 428 | return $this->error($key, 'invalid_' . $rule); |
429 | 429 | } |
@@ -441,12 +441,12 @@ discard block |
||
441 | 441 | */ |
442 | 442 | function arrayTrim($array) |
443 | 443 | { |
444 | - if(!is_array($array)) |
|
444 | + if (!is_array($array)) |
|
445 | 445 | { |
446 | 446 | return trim($array); |
447 | 447 | } |
448 | 448 | |
449 | - foreach($array as $key => $value) |
|
449 | + foreach ($array as $key => $value) |
|
450 | 450 | { |
451 | 451 | $array[$key] = $this->arrayTrim($value); |
452 | 452 | } |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | */ |
462 | 462 | function error($field, $msg) |
463 | 463 | { |
464 | - if(isset($this->_message[$msg])) |
|
464 | + if (isset($this->_message[$msg])) |
|
465 | 465 | { |
466 | 466 | $msg = $this->_message[$msg]; |
467 | 467 | } |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | $msg = isset($lang_filter->{$msg}) ? $lang_filter->{$msg} : $lang_filter->invalid; |
472 | 472 | } |
473 | 473 | |
474 | - if(isset($this->_fieldNames[$field])) |
|
474 | + if (isset($this->_fieldNames[$field])) |
|
475 | 475 | { |
476 | 476 | $fieldName = $this->_fieldNames[$field]; |
477 | 477 | } |
@@ -504,7 +504,7 @@ discard block |
||
504 | 504 | */ |
505 | 505 | function addRule($name, $rule = '') |
506 | 506 | { |
507 | - if(is_array($name)) |
|
507 | + if (is_array($name)) |
|
508 | 508 | { |
509 | 509 | $args = $name; |
510 | 510 | } |
@@ -513,18 +513,18 @@ discard block |
||
513 | 513 | $args = array($name => $rule); |
514 | 514 | } |
515 | 515 | |
516 | - foreach($args as $name => $rule) |
|
516 | + foreach ($args as $name => $rule) |
|
517 | 517 | { |
518 | - if(!$rule) |
|
518 | + if (!$rule) |
|
519 | 519 | { |
520 | 520 | continue; |
521 | 521 | } |
522 | - if(is_string($rule)) |
|
522 | + if (is_string($rule)) |
|
523 | 523 | { |
524 | 524 | $rule = array('type' => 'regex', 'test' => $rule); |
525 | 525 | } |
526 | 526 | |
527 | - if($rule['type'] == 'enum') |
|
527 | + if ($rule['type'] == 'enum') |
|
528 | 528 | { |
529 | 529 | $delim = isset($rule['delim']) ? $rule['delim'] : ','; |
530 | 530 | $rule['test'] = explode($delim, $rule['test']); |
@@ -552,7 +552,7 @@ discard block |
||
552 | 552 | */ |
553 | 553 | function addFilter($name, $filter = '') |
554 | 554 | { |
555 | - if(is_array($name)) |
|
555 | + if (is_array($name)) |
|
556 | 556 | { |
557 | 557 | $args = $name; |
558 | 558 | } |
@@ -561,19 +561,19 @@ discard block |
||
561 | 561 | $args = array($name => $filter); |
562 | 562 | } |
563 | 563 | |
564 | - foreach($args as $name => $filter) |
|
564 | + foreach ($args as $name => $filter) |
|
565 | 565 | { |
566 | - if(!$filter) |
|
566 | + if (!$filter) |
|
567 | 567 | { |
568 | 568 | continue; |
569 | 569 | } |
570 | 570 | |
571 | - if(isset($filter['if'])) |
|
571 | + if (isset($filter['if'])) |
|
572 | 572 | { |
573 | - if(is_array($filter['if']) && count($filter['if'])) |
|
573 | + if (is_array($filter['if']) && count($filter['if'])) |
|
574 | 574 | { |
575 | 575 | $key = key($filter['if']); |
576 | - if(!is_int($key)) |
|
576 | + if (!is_int($key)) |
|
577 | 577 | { |
578 | 578 | $filter['if'] = array($filter['if']); |
579 | 579 | } |
@@ -608,19 +608,19 @@ discard block |
||
608 | 608 | { |
609 | 609 | $rule = $this->_rules[$name]; |
610 | 610 | |
611 | - if(is_array($value) && isset($value['tmp_name'])) |
|
611 | + if (is_array($value) && isset($value['tmp_name'])) |
|
612 | 612 | { |
613 | 613 | $value = $value['name']; |
614 | 614 | } |
615 | 615 | |
616 | - switch($rule['type']) |
|
616 | + switch ($rule['type']) |
|
617 | 617 | { |
618 | 618 | case 'regex': |
619 | 619 | return (preg_match($rule['test'], $value) > 0); |
620 | 620 | case 'enum': |
621 | 621 | return in_array($value, $rule['test']); |
622 | 622 | case 'expr': |
623 | - if(!$rule['func_test']) |
|
623 | + if (!$rule['func_test']) |
|
624 | 624 | { |
625 | 625 | $rule['func_test'] = create_function('$a', 'return (' . preg_replace('/\$\$/', '$a', html_entity_decode($rule['test'])) . ');'); |
626 | 626 | } |
@@ -638,7 +638,7 @@ discard block |
||
638 | 638 | function mbStrLen($str) |
639 | 639 | { |
640 | 640 | $arr = count_chars($str); |
641 | - for($i = 0x80; $i < 0xc0; $i++) |
|
641 | + for ($i = 0x80; $i < 0xc0; $i++) |
|
642 | 642 | { |
643 | 643 | unset($arr[$i]); |
644 | 644 | } |
@@ -651,17 +651,17 @@ discard block |
||
651 | 651 | */ |
652 | 652 | function getJsPath() |
653 | 653 | { |
654 | - if(!$this->_cache_dir) |
|
654 | + if (!$this->_cache_dir) |
|
655 | 655 | { |
656 | 656 | return FALSE; |
657 | 657 | } |
658 | 658 | |
659 | 659 | $dir = $this->_cache_dir . '/ruleset'; |
660 | - if(!is_dir($dir) && !mkdir($dir)) |
|
660 | + if (!is_dir($dir) && !mkdir($dir)) |
|
661 | 661 | { |
662 | 662 | return FALSE; |
663 | 663 | } |
664 | - if(!$this->_xml_path) |
|
664 | + if (!$this->_xml_path) |
|
665 | 665 | { |
666 | 666 | return FALSE; |
667 | 667 | } |
@@ -671,13 +671,13 @@ discard block |
||
671 | 671 | |
672 | 672 | // check the file |
673 | 673 | $filepath = $dir . '/' . md5($this->_version . ' ' . $this->_xml_path) . ".{$lang_type}.js"; |
674 | - if(is_readable($filepath) && filemtime($filepath) > filemtime($this->_xml_path)) |
|
674 | + if (is_readable($filepath) && filemtime($filepath) > filemtime($this->_xml_path)) |
|
675 | 675 | { |
676 | 676 | return $filepath; |
677 | 677 | } |
678 | 678 | |
679 | 679 | $content = $this->_compile2js(); |
680 | - if($content === FALSE) |
|
680 | + if ($content === FALSE) |
|
681 | 681 | { |
682 | 682 | return FALSE; |
683 | 683 | } |
@@ -698,7 +698,7 @@ discard block |
||
698 | 698 | $ruleset = basename($this->_xml_path, '.xml'); |
699 | 699 | $content = array(); |
700 | 700 | |
701 | - if(preg_match('@(^|/)files/ruleset/\w+\.xml$@i', $this->_xml_path)) |
|
701 | + if (preg_match('@(^|/)files/ruleset/\w+\.xml$@i', $this->_xml_path)) |
|
702 | 702 | { |
703 | 703 | $ruleset = '@' . $ruleset; |
704 | 704 | } |
@@ -710,15 +710,15 @@ discard block |
||
710 | 710 | |
711 | 711 | // custom rulesets |
712 | 712 | $addrules = array(); |
713 | - foreach($this->_rules as $name => $rule) |
|
713 | + foreach ($this->_rules as $name => $rule) |
|
714 | 714 | { |
715 | 715 | $name = strtolower($name); |
716 | 716 | |
717 | - if(in_array($name, array('email', 'userid', 'url', 'alpha', 'alpha_number', 'number'))) |
|
717 | + if (in_array($name, array('email', 'userid', 'url', 'alpha', 'alpha_number', 'number'))) |
|
718 | 718 | { |
719 | 719 | continue; |
720 | 720 | } |
721 | - switch($rule['type']) |
|
721 | + switch ($rule['type']) |
|
722 | 722 | { |
723 | 723 | case 'regex': |
724 | 724 | $addrules[] = "v.cast('ADD_RULE', ['{$name}', {$rule['test']}]);"; |
@@ -733,7 +733,7 @@ discard block |
||
733 | 733 | } |
734 | 734 | |
735 | 735 | // if have a message, add message |
736 | - if(isset($rule['message'])) |
|
736 | + if (isset($rule['message'])) |
|
737 | 737 | { |
738 | 738 | $text = preg_replace('@\r?\n@', '\\n', addslashes($rule['message'])); |
739 | 739 | $addrules[] = "v.cast('ADD_MESSAGE',['invalid_{$name}','{$text}']);"; |
@@ -744,79 +744,79 @@ discard block |
||
744 | 744 | // filters |
745 | 745 | $content = array(); |
746 | 746 | $messages = array(); |
747 | - foreach($this->_filters as $name => $filter) |
|
747 | + foreach ($this->_filters as $name => $filter) |
|
748 | 748 | { |
749 | 749 | $field = array(); |
750 | 750 | |
751 | 751 | // form filed name |
752 | - if(isset($filter['title'])) |
|
752 | + if (isset($filter['title'])) |
|
753 | 753 | { |
754 | 754 | $field_lang = addslashes($filter['title']); |
755 | 755 | $messages[] = "v.cast('ADD_MESSAGE',['{$name}','{$field_lang}']);"; |
756 | 756 | } |
757 | - elseif(isset($lang->{$name})) |
|
757 | + elseif (isset($lang->{$name})) |
|
758 | 758 | { |
759 | 759 | $field_lang = addslashes($lang->{$name}); |
760 | 760 | $messages[] = "v.cast('ADD_MESSAGE',['{$name}','{$field_lang}']);"; |
761 | 761 | } |
762 | 762 | |
763 | - if($filter['required'] == 'true') |
|
763 | + if ($filter['required'] == 'true') |
|
764 | 764 | { |
765 | 765 | $field[] = 'required:true'; |
766 | 766 | } |
767 | - if($filter['rule']) |
|
767 | + if ($filter['rule']) |
|
768 | 768 | { |
769 | 769 | $field[] = "rule:'" . strtolower($filter['rule']) . "'"; |
770 | 770 | } |
771 | - if($filter['default']) |
|
771 | + if ($filter['default']) |
|
772 | 772 | { |
773 | 773 | $field[] = "default:'{$filter['default']}'"; |
774 | 774 | } |
775 | - if($filter['modifier']) |
|
775 | + if ($filter['modifier']) |
|
776 | 776 | { |
777 | 777 | $field[] = "modifier:'{$filter['modifier']}'"; |
778 | 778 | } |
779 | - if($filter['length']) |
|
779 | + if ($filter['length']) |
|
780 | 780 | { |
781 | 781 | list($min, $max) = explode(':', $filter['length']); |
782 | - if($min) |
|
782 | + if ($min) |
|
783 | 783 | { |
784 | 784 | $field[] = "minlength:'{$min}'"; |
785 | 785 | } |
786 | - if($max) |
|
786 | + if ($max) |
|
787 | 787 | { |
788 | 788 | $field[] = "maxlength:'{$max}'"; |
789 | 789 | } |
790 | 790 | } |
791 | - if($filter['if']) |
|
791 | + if ($filter['if']) |
|
792 | 792 | { |
793 | 793 | $ifs = array(); |
794 | - if(!isset($filter['if'][0])) |
|
794 | + if (!isset($filter['if'][0])) |
|
795 | 795 | { |
796 | 796 | $filter['if'] = array($filter['if']); |
797 | 797 | } |
798 | - foreach($filter['if'] as $if) |
|
798 | + foreach ($filter['if'] as $if) |
|
799 | 799 | { |
800 | 800 | $ifs[] = "{test:'" . addslashes($if['test']) . "', attr:'{$if['attr']}', value:'" . addslashes($if['value']) . "'}"; |
801 | 801 | } |
802 | 802 | $field[] = "'if':[" . implode(',', $ifs) . "]"; |
803 | 803 | } |
804 | - if(count($field)) |
|
804 | + if (count($field)) |
|
805 | 805 | { |
806 | 806 | $field = '{' . implode(',', $field) . '}'; |
807 | 807 | $content[] = "'{$name}':{$field}"; |
808 | 808 | } |
809 | 809 | } |
810 | 810 | |
811 | - if(!$content) |
|
811 | + if (!$content) |
|
812 | 812 | { |
813 | 813 | return '/* Error : empty ruleset */'; |
814 | 814 | } |
815 | 815 | |
816 | 816 | // error messages |
817 | - foreach($lang->filter as $key => $text) |
|
817 | + foreach ($lang->filter as $key => $text) |
|
818 | 818 | { |
819 | - if($text) |
|
819 | + if ($text) |
|
820 | 820 | { |
821 | 821 | $text = preg_replace('@\r?\n@', '\\n', addslashes($text)); |
822 | 822 | $messages[] = "v.cast('ADD_MESSAGE',['{$key}','{$text}']);"; |
@@ -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}']);"; |
@@ -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 | } |
@@ -103,8 +103,7 @@ discard block |
||
103 | 103 | if($category->parent_srl) |
104 | 104 | { |
105 | 105 | $categoryList[$category->parent_srl]->children[] = & $categoryList[$key]; |
106 | - } |
|
107 | - else |
|
106 | + } else |
|
108 | 107 | { |
109 | 108 | $depth0[] = $key; |
110 | 109 | } |
@@ -324,8 +323,7 @@ discard block |
||
324 | 323 | if(method_exists($oModule, "moduleUninstall")) |
325 | 324 | { |
326 | 325 | return TRUE; |
327 | - } |
|
328 | - else |
|
326 | + } else |
|
329 | 327 | { |
330 | 328 | return FALSE; |
331 | 329 | } |
@@ -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 | { |
@@ -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,7 +137,7 @@ 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 | } |
@@ -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,7 +255,7 @@ 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 | } |
@@ -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 | } |
@@ -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 | { |