@@ -211,6 +211,9 @@ discard block |
||
211 | 211 | |
212 | 212 | /* Mailhide related code */ |
213 | 213 | |
214 | +/** |
|
215 | + * @param string $ky |
|
216 | + */ |
|
214 | 217 | function _recaptcha_aes_encrypt($val,$ky) { |
215 | 218 | if (! function_exists ("mcrypt_encrypt")) { |
216 | 219 | die ("To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed."); |
@@ -222,6 +225,9 @@ discard block |
||
222 | 225 | } |
223 | 226 | |
224 | 227 | |
228 | +/** |
|
229 | + * @param null|string $x |
|
230 | + */ |
|
225 | 231 | function _recaptcha_mailhide_urlbase64 ($x) { |
226 | 232 | return strtr(base64_encode ($x), '+/', '-_'); |
227 | 233 | } |
@@ -45,13 +45,13 @@ discard block |
||
45 | 45 | * @return string - encoded request |
46 | 46 | */ |
47 | 47 | function _recaptcha_qsencode ($data) { |
48 | - $req = ""; |
|
49 | - foreach ( $data as $key => $value ) |
|
50 | - $req .= $key . '=' . urlencode( stripslashes($value) ) . '&'; |
|
48 | + $req = ""; |
|
49 | + foreach ( $data as $key => $value ) |
|
50 | + $req .= $key . '=' . urlencode( stripslashes($value) ) . '&'; |
|
51 | 51 | |
52 | - // Cut the last '&' |
|
53 | - $req=substr($req,0,strlen($req)-1); |
|
54 | - return $req; |
|
52 | + // Cut the last '&' |
|
53 | + $req=substr($req,0,strlen($req)-1); |
|
54 | + return $req; |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | |
@@ -66,29 +66,29 @@ discard block |
||
66 | 66 | */ |
67 | 67 | function _recaptcha_http_post($host, $path, $data, $port = 80) { |
68 | 68 | |
69 | - $req = _recaptcha_qsencode ($data); |
|
69 | + $req = _recaptcha_qsencode ($data); |
|
70 | 70 | |
71 | - $http_request = "POST $path HTTP/1.0\r\n"; |
|
72 | - $http_request .= "Host: $host\r\n"; |
|
73 | - $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n"; |
|
74 | - $http_request .= "Content-Length: " . strlen($req) . "\r\n"; |
|
75 | - $http_request .= "User-Agent: reCAPTCHA/PHP\r\n"; |
|
76 | - $http_request .= "\r\n"; |
|
77 | - $http_request .= $req; |
|
71 | + $http_request = "POST $path HTTP/1.0\r\n"; |
|
72 | + $http_request .= "Host: $host\r\n"; |
|
73 | + $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n"; |
|
74 | + $http_request .= "Content-Length: " . strlen($req) . "\r\n"; |
|
75 | + $http_request .= "User-Agent: reCAPTCHA/PHP\r\n"; |
|
76 | + $http_request .= "\r\n"; |
|
77 | + $http_request .= $req; |
|
78 | 78 | |
79 | - $response = ''; |
|
80 | - if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) { |
|
81 | - die ('Could not open socket'); |
|
82 | - } |
|
79 | + $response = ''; |
|
80 | + if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) { |
|
81 | + die ('Could not open socket'); |
|
82 | + } |
|
83 | 83 | |
84 | - fwrite($fs, $http_request); |
|
84 | + fwrite($fs, $http_request); |
|
85 | 85 | |
86 | - while ( !feof($fs) ) |
|
87 | - $response .= fgets($fs, 1160); // One TCP-IP packet |
|
88 | - fclose($fs); |
|
89 | - $response = explode("\r\n\r\n", $response, 2); |
|
86 | + while ( !feof($fs) ) |
|
87 | + $response .= fgets($fs, 1160); // One TCP-IP packet |
|
88 | + fclose($fs); |
|
89 | + $response = explode("\r\n\r\n", $response, 2); |
|
90 | 90 | |
91 | - return $response; |
|
91 | + return $response; |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | |
@@ -100,7 +100,6 @@ discard block |
||
100 | 100 | * @param string $pubkey A public key for reCAPTCHA |
101 | 101 | * @param string $error The error given by reCAPTCHA (optional, default is null) |
102 | 102 | * @param boolean $use_ssl Should the request be made over ssl? (optional, default is false) |
103 | - |
|
104 | 103 | * @return string - The HTML to be embedded in the user's form. |
105 | 104 | */ |
106 | 105 | function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false) |
@@ -110,16 +109,16 @@ discard block |
||
110 | 109 | } |
111 | 110 | |
112 | 111 | if ($use_ssl) { |
113 | - $server = RECAPTCHA_API_SECURE_SERVER; |
|
114 | - } else { |
|
115 | - $server = RECAPTCHA_API_SERVER; |
|
116 | - } |
|
112 | + $server = RECAPTCHA_API_SECURE_SERVER; |
|
113 | + } else { |
|
114 | + $server = RECAPTCHA_API_SERVER; |
|
115 | + } |
|
117 | 116 | |
118 | - $errorpart = ""; |
|
119 | - if ($error) { |
|
120 | - $errorpart = "&error=" . $error; |
|
121 | - } |
|
122 | - return '<script type="text/javascript" src="'. $server . '/challenge?k=' . $pubkey . $errorpart . '"></script> |
|
117 | + $errorpart = ""; |
|
118 | + if ($error) { |
|
119 | + $errorpart = "&error=" . $error; |
|
120 | + } |
|
121 | + return '<script type="text/javascript" src="'. $server . '/challenge?k=' . $pubkey . $errorpart . '"></script> |
|
123 | 122 | |
124 | 123 | <noscript> |
125 | 124 | <iframe src="'. $server . '/noscript?k=' . $pubkey . $errorpart . '" height="300" width="500" frameborder="0"></iframe><br/> |
@@ -135,20 +134,20 @@ discard block |
||
135 | 134 | * A ReCaptchaResponse is returned from recaptcha_check_answer() |
136 | 135 | */ |
137 | 136 | class ReCaptchaResponse { |
138 | - var $is_valid; |
|
139 | - var $error; |
|
137 | + var $is_valid; |
|
138 | + var $error; |
|
140 | 139 | } |
141 | 140 | |
142 | 141 | |
143 | 142 | /** |
144 | - * Calls an HTTP POST function to verify if the user's guess was correct |
|
145 | - * @param string $privkey |
|
146 | - * @param string $remoteip |
|
147 | - * @param string $challenge |
|
148 | - * @param string $response |
|
149 | - * @param array $extra_params an array of extra variables to post to the server |
|
150 | - * @return ReCaptchaResponse |
|
151 | - */ |
|
143 | + * Calls an HTTP POST function to verify if the user's guess was correct |
|
144 | + * @param string $privkey |
|
145 | + * @param string $remoteip |
|
146 | + * @param string $challenge |
|
147 | + * @param string $response |
|
148 | + * @param array $extra_params an array of extra variables to post to the server |
|
149 | + * @return ReCaptchaResponse |
|
150 | + */ |
|
152 | 151 | function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $extra_params = array()) |
153 | 152 | { |
154 | 153 | if ($privkey == null || $privkey == '') { |
@@ -161,34 +160,34 @@ discard block |
||
161 | 160 | |
162 | 161 | |
163 | 162 | |
164 | - //discard spam submissions |
|
165 | - if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) { |
|
166 | - $recaptcha_response = new ReCaptchaResponse(); |
|
167 | - $recaptcha_response->is_valid = false; |
|
168 | - $recaptcha_response->error = 'incorrect-captcha-sol'; |
|
169 | - return $recaptcha_response; |
|
170 | - } |
|
171 | - |
|
172 | - $response = _recaptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify", |
|
173 | - array ( |
|
174 | - 'privatekey' => $privkey, |
|
175 | - 'remoteip' => $remoteip, |
|
176 | - 'challenge' => $challenge, |
|
177 | - 'response' => $response |
|
178 | - ) + $extra_params |
|
179 | - ); |
|
180 | - |
|
181 | - $answers = explode ("\n", $response [1]); |
|
182 | - $recaptcha_response = new ReCaptchaResponse(); |
|
183 | - |
|
184 | - if (trim ($answers [0]) == 'true') { |
|
185 | - $recaptcha_response->is_valid = true; |
|
186 | - } |
|
187 | - else { |
|
188 | - $recaptcha_response->is_valid = false; |
|
189 | - $recaptcha_response->error = $answers [1]; |
|
190 | - } |
|
191 | - return $recaptcha_response; |
|
163 | + //discard spam submissions |
|
164 | + if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) { |
|
165 | + $recaptcha_response = new ReCaptchaResponse(); |
|
166 | + $recaptcha_response->is_valid = false; |
|
167 | + $recaptcha_response->error = 'incorrect-captcha-sol'; |
|
168 | + return $recaptcha_response; |
|
169 | + } |
|
170 | + |
|
171 | + $response = _recaptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify", |
|
172 | + array ( |
|
173 | + 'privatekey' => $privkey, |
|
174 | + 'remoteip' => $remoteip, |
|
175 | + 'challenge' => $challenge, |
|
176 | + 'response' => $response |
|
177 | + ) + $extra_params |
|
178 | + ); |
|
179 | + |
|
180 | + $answers = explode ("\n", $response [1]); |
|
181 | + $recaptcha_response = new ReCaptchaResponse(); |
|
182 | + |
|
183 | + if (trim ($answers [0]) == 'true') { |
|
184 | + $recaptcha_response->is_valid = true; |
|
185 | + } |
|
186 | + else { |
|
187 | + $recaptcha_response->is_valid = false; |
|
188 | + $recaptcha_response->error = $answers [1]; |
|
189 | + } |
|
190 | + return $recaptcha_response; |
|
192 | 191 | |
193 | 192 | } |
194 | 193 | |
@@ -230,7 +229,7 @@ discard block |
||
230 | 229 | function recaptcha_mailhide_url($pubkey, $privkey, $email) { |
231 | 230 | if ($pubkey == '' || $pubkey == null || $privkey == "" || $privkey == null) { |
232 | 231 | die ("To use reCAPTCHA Mailhide, you have to sign up for a public and private key, " . |
233 | - "you can do so at <a href='http://www.google.com/recaptcha/mailhide/apikey'>http://www.google.com/recaptcha/mailhide/apikey</a>"); |
|
232 | + "you can do so at <a href='http://www.google.com/recaptcha/mailhide/apikey'>http://www.google.com/recaptcha/mailhide/apikey</a>"); |
|
234 | 233 | } |
235 | 234 | |
236 | 235 |
@@ -44,13 +44,13 @@ discard block |
||
44 | 44 | * @param $data - array of string elements to be encoded |
45 | 45 | * @return string - encoded request |
46 | 46 | */ |
47 | -function _recaptcha_qsencode ($data) { |
|
47 | +function _recaptcha_qsencode($data) { |
|
48 | 48 | $req = ""; |
49 | - foreach ( $data as $key => $value ) |
|
50 | - $req .= $key . '=' . urlencode( stripslashes($value) ) . '&'; |
|
49 | + foreach ($data as $key => $value) |
|
50 | + $req .= $key . '=' . urlencode(stripslashes($value)) . '&'; |
|
51 | 51 | |
52 | 52 | // Cut the last '&' |
53 | - $req=substr($req,0,strlen($req)-1); |
|
53 | + $req = substr($req, 0, strlen($req) - 1); |
|
54 | 54 | return $req; |
55 | 55 | } |
56 | 56 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | */ |
67 | 67 | function _recaptcha_http_post($host, $path, $data, $port = 80) { |
68 | 68 | |
69 | - $req = _recaptcha_qsencode ($data); |
|
69 | + $req = _recaptcha_qsencode($data); |
|
70 | 70 | |
71 | 71 | $http_request = "POST $path HTTP/1.0\r\n"; |
72 | 72 | $http_request .= "Host: $host\r\n"; |
@@ -77,13 +77,13 @@ discard block |
||
77 | 77 | $http_request .= $req; |
78 | 78 | |
79 | 79 | $response = ''; |
80 | - if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) { |
|
80 | + if (false == ($fs = @fsockopen($host, $port, $errno, $errstr, 10))) { |
|
81 | 81 | die ('Could not open socket'); |
82 | 82 | } |
83 | 83 | |
84 | 84 | fwrite($fs, $http_request); |
85 | 85 | |
86 | - while ( !feof($fs) ) |
|
86 | + while (!feof($fs)) |
|
87 | 87 | $response .= fgets($fs, 1160); // One TCP-IP packet |
88 | 88 | fclose($fs); |
89 | 89 | $response = explode("\r\n\r\n", $response, 2); |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | |
104 | 104 | * @return string - The HTML to be embedded in the user's form. |
105 | 105 | */ |
106 | -function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false) |
|
106 | +function recaptcha_get_html($pubkey, $error = null, $use_ssl = false) |
|
107 | 107 | { |
108 | 108 | if ($pubkey == null || $pubkey == '') { |
109 | 109 | die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>"); |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | if ($error) { |
120 | 120 | $errorpart = "&error=" . $error; |
121 | 121 | } |
122 | - return '<script type="text/javascript" src="'. $server . '/challenge?k=' . $pubkey . $errorpart . '"></script> |
|
122 | + return '<script type="text/javascript" src="' . $server . '/challenge?k=' . $pubkey . $errorpart . '"></script> |
|
123 | 123 | |
124 | 124 | <noscript> |
125 | 125 | <iframe src="'. $server . '/noscript?k=' . $pubkey . $errorpart . '" height="300" width="500" frameborder="0"></iframe><br/> |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @param array $extra_params an array of extra variables to post to the server |
150 | 150 | * @return ReCaptchaResponse |
151 | 151 | */ |
152 | -function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $extra_params = array()) |
|
152 | +function recaptcha_check_answer($privkey, $remoteip, $challenge, $response, $extra_params = array()) |
|
153 | 153 | { |
154 | 154 | if ($privkey == null || $privkey == '') { |
155 | 155 | die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>"); |
@@ -169,8 +169,8 @@ discard block |
||
169 | 169 | return $recaptcha_response; |
170 | 170 | } |
171 | 171 | |
172 | - $response = _recaptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify", |
|
173 | - array ( |
|
172 | + $response = _recaptcha_http_post(RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify", |
|
173 | + array( |
|
174 | 174 | 'privatekey' => $privkey, |
175 | 175 | 'remoteip' => $remoteip, |
176 | 176 | 'challenge' => $challenge, |
@@ -178,10 +178,10 @@ discard block |
||
178 | 178 | ) + $extra_params |
179 | 179 | ); |
180 | 180 | |
181 | - $answers = explode ("\n", $response [1]); |
|
181 | + $answers = explode("\n", $response [1]); |
|
182 | 182 | $recaptcha_response = new ReCaptchaResponse(); |
183 | 183 | |
184 | - if (trim ($answers [0]) == 'true') { |
|
184 | + if (trim($answers [0]) == 'true') { |
|
185 | 185 | $recaptcha_response->is_valid = true; |
186 | 186 | } |
187 | 187 | else { |
@@ -199,31 +199,31 @@ discard block |
||
199 | 199 | * @param string $domain The domain where the page is hosted |
200 | 200 | * @param string $appname The name of your application |
201 | 201 | */ |
202 | -function recaptcha_get_signup_url ($domain = null, $appname = null) { |
|
203 | - return "https://www.google.com/recaptcha/admin/create?" . _recaptcha_qsencode (array ('domains' => $domain, 'app' => $appname)); |
|
202 | +function recaptcha_get_signup_url($domain = null, $appname = null) { |
|
203 | + return "https://www.google.com/recaptcha/admin/create?" . _recaptcha_qsencode(array('domains' => $domain, 'app' => $appname)); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | function _recaptcha_aes_pad($val) { |
207 | 207 | $block_size = 16; |
208 | - $numpad = $block_size - (strlen ($val) % $block_size); |
|
209 | - return str_pad($val, strlen ($val) + $numpad, chr($numpad)); |
|
208 | + $numpad = $block_size - (strlen($val) % $block_size); |
|
209 | + return str_pad($val, strlen($val) + $numpad, chr($numpad)); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | /* Mailhide related code */ |
213 | 213 | |
214 | -function _recaptcha_aes_encrypt($val,$ky) { |
|
215 | - if (! function_exists ("mcrypt_encrypt")) { |
|
214 | +function _recaptcha_aes_encrypt($val, $ky) { |
|
215 | + if (!function_exists("mcrypt_encrypt")) { |
|
216 | 216 | die ("To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed."); |
217 | 217 | } |
218 | - $mode=MCRYPT_MODE_CBC; |
|
219 | - $enc=MCRYPT_RIJNDAEL_128; |
|
220 | - $val=_recaptcha_aes_pad($val); |
|
218 | + $mode = MCRYPT_MODE_CBC; |
|
219 | + $enc = MCRYPT_RIJNDAEL_128; |
|
220 | + $val = _recaptcha_aes_pad($val); |
|
221 | 221 | return mcrypt_encrypt($enc, $ky, $val, $mode, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"); |
222 | 222 | } |
223 | 223 | |
224 | 224 | |
225 | -function _recaptcha_mailhide_urlbase64 ($x) { |
|
226 | - return strtr(base64_encode ($x), '+/', '-_'); |
|
225 | +function _recaptcha_mailhide_urlbase64($x) { |
|
226 | + return strtr(base64_encode($x), '+/', '-_'); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /* gets the reCAPTCHA Mailhide url for a given email, public key and private key */ |
@@ -235,9 +235,9 @@ discard block |
||
235 | 235 | |
236 | 236 | |
237 | 237 | $ky = pack('H*', $privkey); |
238 | - $cryptmail = _recaptcha_aes_encrypt ($email, $ky); |
|
238 | + $cryptmail = _recaptcha_aes_encrypt($email, $ky); |
|
239 | 239 | |
240 | - return "http://www.google.com/recaptcha/mailhide/d?k=" . $pubkey . "&c=" . _recaptcha_mailhide_urlbase64 ($cryptmail); |
|
240 | + return "http://www.google.com/recaptcha/mailhide/d?k=" . $pubkey . "&c=" . _recaptcha_mailhide_urlbase64($cryptmail); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | /** |
@@ -245,15 +245,15 @@ discard block |
||
245 | 245 | * eg, given johndoe@example,com return ["john", "example.com"]. |
246 | 246 | * the email is then displayed as [email protected] |
247 | 247 | */ |
248 | -function _recaptcha_mailhide_email_parts ($email) { |
|
249 | - $arr = preg_split("/@/", $email ); |
|
248 | +function _recaptcha_mailhide_email_parts($email) { |
|
249 | + $arr = preg_split("/@/", $email); |
|
250 | 250 | |
251 | - if (strlen ($arr[0]) <= 4) { |
|
252 | - $arr[0] = substr ($arr[0], 0, 1); |
|
253 | - } else if (strlen ($arr[0]) <= 6) { |
|
254 | - $arr[0] = substr ($arr[0], 0, 3); |
|
251 | + if (strlen($arr[0]) <= 4) { |
|
252 | + $arr[0] = substr($arr[0], 0, 1); |
|
253 | + } else if (strlen($arr[0]) <= 6) { |
|
254 | + $arr[0] = substr($arr[0], 0, 3); |
|
255 | 255 | } else { |
256 | - $arr[0] = substr ($arr[0], 0, 4); |
|
256 | + $arr[0] = substr($arr[0], 0, 4); |
|
257 | 257 | } |
258 | 258 | return $arr; |
259 | 259 | } |
@@ -265,11 +265,11 @@ discard block |
||
265 | 265 | * http://www.google.com/recaptcha/mailhide/apikey |
266 | 266 | */ |
267 | 267 | function recaptcha_mailhide_html($pubkey, $privkey, $email) { |
268 | - $emailparts = _recaptcha_mailhide_email_parts ($email); |
|
269 | - $url = recaptcha_mailhide_url ($pubkey, $privkey, $email); |
|
268 | + $emailparts = _recaptcha_mailhide_email_parts($email); |
|
269 | + $url = recaptcha_mailhide_url($pubkey, $privkey, $email); |
|
270 | 270 | |
271 | - return htmlentities($emailparts[0]) . "<a href='" . htmlentities ($url) . |
|
272 | - "' onclick=\"window.open('" . htmlentities ($url) . "', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;\" title=\"Reveal this e-mail address\">...</a>@" . htmlentities ($emailparts [1]); |
|
271 | + return htmlentities($emailparts[0]) . "<a href='" . htmlentities($url) . |
|
272 | + "' onclick=\"window.open('" . htmlentities($url) . "', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;\" title=\"Reveal this e-mail address\">...</a>@" . htmlentities($emailparts [1]); |
|
273 | 273 | |
274 | 274 | } |
275 | 275 |
@@ -46,8 +46,9 @@ discard block |
||
46 | 46 | */ |
47 | 47 | function _recaptcha_qsencode ($data) { |
48 | 48 | $req = ""; |
49 | - foreach ( $data as $key => $value ) |
|
50 | - $req .= $key . '=' . urlencode( stripslashes($value) ) . '&'; |
|
49 | + foreach ( $data as $key => $value ) { |
|
50 | + $req .= $key . '=' . urlencode( stripslashes($value) ) . '&'; |
|
51 | + } |
|
51 | 52 | |
52 | 53 | // Cut the last '&' |
53 | 54 | $req=substr($req,0,strlen($req)-1); |
@@ -83,8 +84,10 @@ discard block |
||
83 | 84 | |
84 | 85 | fwrite($fs, $http_request); |
85 | 86 | |
86 | - while ( !feof($fs) ) |
|
87 | - $response .= fgets($fs, 1160); // One TCP-IP packet |
|
87 | + while ( !feof($fs) ) { |
|
88 | + $response .= fgets($fs, 1160); |
|
89 | + } |
|
90 | + // One TCP-IP packet |
|
88 | 91 | fclose($fs); |
89 | 92 | $response = explode("\r\n\r\n", $response, 2); |
90 | 93 | |
@@ -183,8 +186,7 @@ discard block |
||
183 | 186 | |
184 | 187 | if (trim ($answers [0]) == 'true') { |
185 | 188 | $recaptcha_response->is_valid = true; |
186 | - } |
|
187 | - else { |
|
189 | + } else { |
|
188 | 190 | $recaptcha_response->is_valid = false; |
189 | 191 | $recaptcha_response->error = $answers [1]; |
190 | 192 | } |
@@ -68,7 +68,7 @@ |
||
68 | 68 | |
69 | 69 | $req = _recaptcha_qsencode ($data); |
70 | 70 | |
71 | - $http_request = "POST $path HTTP/1.0\r\n"; |
|
71 | + $http_request = "post $path HTTP/1.0\r\n"; |
|
72 | 72 | $http_request .= "Host: $host\r\n"; |
73 | 73 | $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n"; |
74 | 74 | $http_request .= "Content-Length: " . strlen($req) . "\r\n"; |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | /** |
197 | 197 | * Returns the next character from the XML document or void if at end |
198 | 198 | * @access protected |
199 | - * @return mixed |
|
199 | + * @return string|null |
|
200 | 200 | */ |
201 | 201 | function scanCharacter() { |
202 | 202 | if ($this->position < $this->length) { |
@@ -332,6 +332,7 @@ discard block |
||
332 | 332 | * parser options |
333 | 333 | * @var TSax3 instance of user front end class |
334 | 334 | * @access protected |
335 | + * @param TSax3 $htmlsax |
|
335 | 336 | */ |
336 | 337 | function __construct(& $htmlsax) { |
337 | 338 | parent::__construct($htmlsax); |
@@ -397,6 +398,7 @@ discard block |
||
397 | 398 | * parser options |
398 | 399 | * @var TSax3 instance of user front end class |
399 | 400 | * @access protected |
401 | + * @param TSax3 $htmlsax |
|
400 | 402 | */ |
401 | 403 | function __construct(& $htmlsax) { |
402 | 404 | parent::__construct($htmlsax); |
@@ -508,7 +510,7 @@ discard block |
||
508 | 510 | * if supplied argument is not an object. |
509 | 511 | * @param object handler object containing SAX callback methods |
510 | 512 | * @access public |
511 | - * @return mixed |
|
513 | + * @return boolean|null |
|
512 | 514 | */ |
513 | 515 | function set_object(&$object) { |
514 | 516 | if ( is_object($object) ) { |
@@ -546,7 +548,7 @@ discard block |
||
546 | 548 | * @param string name of parser option |
547 | 549 | * @param int (optional) 1 to switch on, 0 for off |
548 | 550 | * @access public |
549 | - * @return boolean |
|
551 | + * @return boolean|null |
|
550 | 552 | */ |
551 | 553 | function set_option($name, $value=1) { |
552 | 554 | if ( array_key_exists($name,$this->state_parser->parser_options) ) { |
@@ -568,6 +570,7 @@ discard block |
||
568 | 570 | * function myDataHander(& $parser,$data){} |
569 | 571 | * </pre> |
570 | 572 | * @param string name of method |
573 | + * @param string $data_method |
|
571 | 574 | * @access public |
572 | 575 | * @return void |
573 | 576 | * @see set_object |
@@ -591,6 +594,8 @@ discard block |
||
591 | 594 | * </pre> |
592 | 595 | * @param string name of open method |
593 | 596 | * @param string name of close method |
597 | + * @param string $opening_method |
|
598 | + * @param string $closing_method |
|
594 | 599 | * @access public |
595 | 600 | * @return void |
596 | 601 | * @see set_object |
@@ -610,6 +615,7 @@ discard block |
||
610 | 615 | * function myPIHander(& $parser,$target, $data){} |
611 | 616 | * </pre> |
612 | 617 | * @param string name of method |
618 | + * @param string $pi_method |
|
613 | 619 | * @access public |
614 | 620 | * @return void |
615 | 621 | * @see set_object |
@@ -628,6 +634,7 @@ discard block |
||
628 | 634 | * function myEscapeHander(& $parser, $data){} |
629 | 635 | * </pre> |
630 | 636 | * @param string name of method |
637 | + * @param string $escape_method |
|
631 | 638 | * @access public |
632 | 639 | * @return void |
633 | 640 | * @see set_object |
@@ -645,6 +652,7 @@ discard block |
||
645 | 652 | * function myJaspHander(& $parser, $data){} |
646 | 653 | * </pre> |
647 | 654 | * @param string name of method |
655 | + * @param string $jasp_method |
|
648 | 656 | * @access public |
649 | 657 | * @return void |
650 | 658 | * @see set_object |
@@ -684,6 +692,7 @@ discard block |
||
684 | 692 | /** |
685 | 693 | * Start parsing some XML |
686 | 694 | * @param string XML document |
695 | + * @param string $data |
|
687 | 696 | * @access public |
688 | 697 | * @return void |
689 | 698 | */ |
@@ -39,114 +39,114 @@ discard block |
||
39 | 39 | * @abstract |
40 | 40 | */ |
41 | 41 | class TSax3_StateParser { |
42 | - /** |
|
43 | - * Instance of user front end class to be passed to callbacks |
|
44 | - * @var TSax3 |
|
45 | - * @access private |
|
46 | - */ |
|
47 | - public $htmlsax; |
|
48 | - /** |
|
49 | - * User defined object for handling elements |
|
50 | - * @var object |
|
51 | - * @access private |
|
52 | - */ |
|
53 | - public $handler_object_element; |
|
54 | - /** |
|
55 | - * User defined open tag handler method |
|
56 | - * @var string |
|
57 | - * @access private |
|
58 | - */ |
|
59 | - public $handler_method_opening; |
|
60 | - /** |
|
61 | - * User defined close tag handler method |
|
62 | - * @var string |
|
63 | - * @access private |
|
64 | - */ |
|
65 | - public $handler_method_closing; |
|
66 | - /** |
|
67 | - * User defined object for handling data in elements |
|
68 | - * @var object |
|
69 | - * @access private |
|
70 | - */ |
|
71 | - public $handler_object_data; |
|
72 | - /** |
|
73 | - * User defined data handler method |
|
74 | - * @var string |
|
75 | - * @access private |
|
76 | - */ |
|
77 | - public $handler_method_data; |
|
78 | - /** |
|
79 | - * User defined object for handling processing instructions |
|
80 | - * @var object |
|
81 | - * @access private |
|
82 | - */ |
|
83 | - public $handler_object_pi; |
|
84 | - /** |
|
85 | - * User defined processing instruction handler method |
|
86 | - * @var string |
|
87 | - * @access private |
|
88 | - */ |
|
89 | - public $handler_method_pi; |
|
90 | - /** |
|
91 | - * User defined object for handling JSP/ASP tags |
|
92 | - * @var object |
|
93 | - * @access private |
|
94 | - */ |
|
95 | - public $handler_object_jasp; |
|
96 | - /** |
|
97 | - * User defined JSP/ASP handler method |
|
98 | - * @var string |
|
99 | - * @access private |
|
100 | - */ |
|
101 | - public $handler_method_jasp; |
|
102 | - /** |
|
103 | - * User defined object for handling XML escapes |
|
104 | - * @var object |
|
105 | - * @access private |
|
106 | - */ |
|
107 | - public $handler_object_escape; |
|
108 | - /** |
|
109 | - * User defined XML escape handler method |
|
110 | - * @var string |
|
111 | - * @access private |
|
112 | - */ |
|
113 | - public $handler_method_escape; |
|
114 | - /** |
|
115 | - * User defined handler object or NullHandler |
|
116 | - * @var object |
|
117 | - * @access private |
|
118 | - */ |
|
119 | - public $handler_default; |
|
120 | - /** |
|
121 | - * Parser options determining parsing behavior |
|
122 | - * @var array |
|
123 | - * @access private |
|
124 | - */ |
|
125 | - protected $parser_options = array(); |
|
126 | - /** |
|
127 | - * XML document being parsed |
|
128 | - * @var string |
|
129 | - * @access private |
|
130 | - */ |
|
131 | - protected $rawtext; |
|
132 | - /** |
|
133 | - * Position in XML document relative to start (0) |
|
134 | - * @var int |
|
135 | - * @access private |
|
136 | - */ |
|
137 | - protected $position; |
|
138 | - /** |
|
139 | - * Length of the XML document in characters |
|
140 | - * @var int |
|
141 | - * @access private |
|
142 | - */ |
|
143 | - protected $length; |
|
144 | - /** |
|
145 | - * Array of state objects |
|
146 | - * @var array |
|
147 | - * @access private |
|
148 | - */ |
|
149 | - protected $State = array(); |
|
42 | + /** |
|
43 | + * Instance of user front end class to be passed to callbacks |
|
44 | + * @var TSax3 |
|
45 | + * @access private |
|
46 | + */ |
|
47 | + public $htmlsax; |
|
48 | + /** |
|
49 | + * User defined object for handling elements |
|
50 | + * @var object |
|
51 | + * @access private |
|
52 | + */ |
|
53 | + public $handler_object_element; |
|
54 | + /** |
|
55 | + * User defined open tag handler method |
|
56 | + * @var string |
|
57 | + * @access private |
|
58 | + */ |
|
59 | + public $handler_method_opening; |
|
60 | + /** |
|
61 | + * User defined close tag handler method |
|
62 | + * @var string |
|
63 | + * @access private |
|
64 | + */ |
|
65 | + public $handler_method_closing; |
|
66 | + /** |
|
67 | + * User defined object for handling data in elements |
|
68 | + * @var object |
|
69 | + * @access private |
|
70 | + */ |
|
71 | + public $handler_object_data; |
|
72 | + /** |
|
73 | + * User defined data handler method |
|
74 | + * @var string |
|
75 | + * @access private |
|
76 | + */ |
|
77 | + public $handler_method_data; |
|
78 | + /** |
|
79 | + * User defined object for handling processing instructions |
|
80 | + * @var object |
|
81 | + * @access private |
|
82 | + */ |
|
83 | + public $handler_object_pi; |
|
84 | + /** |
|
85 | + * User defined processing instruction handler method |
|
86 | + * @var string |
|
87 | + * @access private |
|
88 | + */ |
|
89 | + public $handler_method_pi; |
|
90 | + /** |
|
91 | + * User defined object for handling JSP/ASP tags |
|
92 | + * @var object |
|
93 | + * @access private |
|
94 | + */ |
|
95 | + public $handler_object_jasp; |
|
96 | + /** |
|
97 | + * User defined JSP/ASP handler method |
|
98 | + * @var string |
|
99 | + * @access private |
|
100 | + */ |
|
101 | + public $handler_method_jasp; |
|
102 | + /** |
|
103 | + * User defined object for handling XML escapes |
|
104 | + * @var object |
|
105 | + * @access private |
|
106 | + */ |
|
107 | + public $handler_object_escape; |
|
108 | + /** |
|
109 | + * User defined XML escape handler method |
|
110 | + * @var string |
|
111 | + * @access private |
|
112 | + */ |
|
113 | + public $handler_method_escape; |
|
114 | + /** |
|
115 | + * User defined handler object or NullHandler |
|
116 | + * @var object |
|
117 | + * @access private |
|
118 | + */ |
|
119 | + public $handler_default; |
|
120 | + /** |
|
121 | + * Parser options determining parsing behavior |
|
122 | + * @var array |
|
123 | + * @access private |
|
124 | + */ |
|
125 | + protected $parser_options = array(); |
|
126 | + /** |
|
127 | + * XML document being parsed |
|
128 | + * @var string |
|
129 | + * @access private |
|
130 | + */ |
|
131 | + protected $rawtext; |
|
132 | + /** |
|
133 | + * Position in XML document relative to start (0) |
|
134 | + * @var int |
|
135 | + * @access private |
|
136 | + */ |
|
137 | + protected $position; |
|
138 | + /** |
|
139 | + * Length of the XML document in characters |
|
140 | + * @var int |
|
141 | + * @access private |
|
142 | + */ |
|
143 | + protected $length; |
|
144 | + /** |
|
145 | + * Array of state objects |
|
146 | + * @var array |
|
147 | + * @access private |
|
148 | + */ |
|
149 | + protected $State = array(); |
|
150 | 150 | |
151 | 151 | const TSAX3_STATE_STOP = 0; |
152 | 152 | const TSAX3_STATE_START = 1; |
@@ -157,166 +157,166 @@ discard block |
||
157 | 157 | const TSAX3_STATE_JASP = 7; |
158 | 158 | const TSAX3_STATE_PI = 8; |
159 | 159 | |
160 | - /** |
|
161 | - * Constructs TSax3_StateParser setting up states |
|
162 | - * @var TSax3 instance of user front end class |
|
163 | - * @access protected |
|
164 | - */ |
|
165 | - protected function __construct($htmlsax) { |
|
166 | - $this->htmlsax = $htmlsax; |
|
167 | - $this->State[self::TSAX3_STATE_START] = new TSax3_StartingState(); |
|
168 | - |
|
169 | - $this->State[self::TSAX3_STATE_CLOSING_TAG] = new TSax3_ClosingTagState(); |
|
170 | - $this->State[self::TSAX3_STATE_TAG] = new TSax3_TagState(); |
|
171 | - $this->State[self::TSAX3_STATE_OPENING_TAG] = new TSax3_OpeningTagState(); |
|
172 | - |
|
173 | - $this->State[self::TSAX3_STATE_PI] = new TSax3_PiState(); |
|
174 | - $this->State[self::TSAX3_STATE_JASP] = new TSax3_JaspState(); |
|
175 | - $this->State[self::TSAX3_STATE_ESCAPE] = new TSax3_EscapeState(); |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Moves the position back one character |
|
180 | - * @access protected |
|
181 | - * @return void |
|
182 | - */ |
|
183 | - function unscanCharacter() { |
|
184 | - $this->position -= 1; |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Moves the position forward one character |
|
189 | - * @access protected |
|
190 | - * @return void |
|
191 | - */ |
|
192 | - function ignoreCharacter() { |
|
193 | - $this->position += 1; |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * Returns the next character from the XML document or void if at end |
|
198 | - * @access protected |
|
199 | - * @return mixed |
|
200 | - */ |
|
201 | - function scanCharacter() { |
|
202 | - if ($this->position < $this->length) { |
|
203 | - return $this->rawtext{$this->position++}; |
|
204 | - } |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Returns a string from the current position to the next occurance |
|
209 | - * of the supplied string |
|
210 | - * @param string string to search until |
|
211 | - * @access protected |
|
212 | - * @return string |
|
213 | - */ |
|
214 | - function scanUntilString($string) { |
|
215 | - $start = $this->position; |
|
216 | - $this->position = strpos($this->rawtext, $string, $start); |
|
217 | - if ($this->position === FALSE) { |
|
218 | - $this->position = $this->length; |
|
219 | - } |
|
220 | - return substr($this->rawtext, $start, $this->position - $start); |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * Returns a string from the current position until the first instance of |
|
225 | - * one of the characters in the supplied string argument |
|
226 | - * @param string string to search until |
|
227 | - * @access protected |
|
228 | - * @return string |
|
229 | - * @abstract |
|
230 | - */ |
|
231 | - function scanUntilCharacters($string) {} |
|
232 | - |
|
233 | - /** |
|
234 | - * Moves the position forward past any whitespace characters |
|
235 | - * @access protected |
|
236 | - * @return void |
|
237 | - * @abstract |
|
238 | - */ |
|
239 | - function ignoreWhitespace() {} |
|
240 | - |
|
241 | - /** |
|
242 | - * Begins the parsing operation, setting up any decorators, depending on |
|
243 | - * parse options invoking _parse() to execute parsing |
|
244 | - * @param string XML document to parse |
|
245 | - * @access protected |
|
246 | - * @return void |
|
247 | - */ |
|
248 | - function parse($data) { |
|
249 | - if ($this->parser_options['XML_OPTION_TRIM_DATA_NODES']==1) { |
|
250 | - $decorator = new TSax3_Trim( |
|
251 | - $this->handler_object_data, |
|
252 | - $this->handler_method_data); |
|
253 | - $this->handler_object_data =& $decorator; |
|
254 | - $this->handler_method_data = 'trimData'; |
|
255 | - } |
|
256 | - if ($this->parser_options['XML_OPTION_CASE_FOLDING']==1) { |
|
257 | - $open_decor = new TSax3_CaseFolding( |
|
258 | - $this->handler_object_element, |
|
259 | - $this->handler_method_opening, |
|
260 | - $this->handler_method_closing); |
|
261 | - $this->handler_object_element =& $open_decor; |
|
262 | - $this->handler_method_opening ='foldOpen'; |
|
263 | - $this->handler_method_closing ='foldClose'; |
|
264 | - } |
|
265 | - if ($this->parser_options['XML_OPTION_LINEFEED_BREAK']==1) { |
|
266 | - $decorator = new TSax3_Linefeed( |
|
267 | - $this->handler_object_data, |
|
268 | - $this->handler_method_data); |
|
269 | - $this->handler_object_data =& $decorator; |
|
270 | - $this->handler_method_data = 'breakData'; |
|
271 | - } |
|
272 | - if ($this->parser_options['XML_OPTION_TAB_BREAK']==1) { |
|
273 | - $decorator = new TSax3_Tab( |
|
274 | - $this->handler_object_data, |
|
275 | - $this->handler_method_data); |
|
276 | - $this->handler_object_data =& $decorator; |
|
277 | - $this->handler_method_data = 'breakData'; |
|
278 | - } |
|
279 | - if ($this->parser_options['XML_OPTION_ENTITIES_UNPARSED']==1) { |
|
280 | - $decorator = new TSax3_Entities_Unparsed( |
|
281 | - $this->handler_object_data, |
|
282 | - $this->handler_method_data); |
|
283 | - $this->handler_object_data =& $decorator; |
|
284 | - $this->handler_method_data = 'breakData'; |
|
285 | - } |
|
286 | - if ($this->parser_options['XML_OPTION_ENTITIES_PARSED']==1) { |
|
287 | - $decorator = new TSax3_Entities_Parsed( |
|
288 | - $this->handler_object_data, |
|
289 | - $this->handler_method_data); |
|
290 | - $this->handler_object_data =& $decorator; |
|
291 | - $this->handler_method_data = 'breakData'; |
|
292 | - } |
|
293 | - // Note switched on by default |
|
294 | - if ($this->parser_options['XML_OPTION_STRIP_ESCAPES']==1) { |
|
295 | - $decorator = new TSax3_Escape_Stripper( |
|
296 | - $this->handler_object_escape, |
|
297 | - $this->handler_method_escape); |
|
298 | - $this->handler_object_escape =& $decorator; |
|
299 | - $this->handler_method_escape = 'strip'; |
|
300 | - } |
|
301 | - $this->rawtext = $data; |
|
302 | - $this->length = strlen($data); |
|
303 | - $this->position = 0; |
|
304 | - $this->_parse(); |
|
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * Performs the parsing itself, delegating calls to a specific parser |
|
309 | - * state |
|
310 | - * @param constant state object to parse with |
|
311 | - * @access protected |
|
312 | - * @return void |
|
313 | - */ |
|
314 | - function _parse($state = self::TSAX3_STATE_START) { |
|
315 | - do { |
|
316 | - $state = $this->State[$state]->parse($this); |
|
317 | - } while ($state != self::TSAX3_STATE_STOP && |
|
318 | - $this->position < $this->length); |
|
319 | - } |
|
160 | + /** |
|
161 | + * Constructs TSax3_StateParser setting up states |
|
162 | + * @var TSax3 instance of user front end class |
|
163 | + * @access protected |
|
164 | + */ |
|
165 | + protected function __construct($htmlsax) { |
|
166 | + $this->htmlsax = $htmlsax; |
|
167 | + $this->State[self::TSAX3_STATE_START] = new TSax3_StartingState(); |
|
168 | + |
|
169 | + $this->State[self::TSAX3_STATE_CLOSING_TAG] = new TSax3_ClosingTagState(); |
|
170 | + $this->State[self::TSAX3_STATE_TAG] = new TSax3_TagState(); |
|
171 | + $this->State[self::TSAX3_STATE_OPENING_TAG] = new TSax3_OpeningTagState(); |
|
172 | + |
|
173 | + $this->State[self::TSAX3_STATE_PI] = new TSax3_PiState(); |
|
174 | + $this->State[self::TSAX3_STATE_JASP] = new TSax3_JaspState(); |
|
175 | + $this->State[self::TSAX3_STATE_ESCAPE] = new TSax3_EscapeState(); |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Moves the position back one character |
|
180 | + * @access protected |
|
181 | + * @return void |
|
182 | + */ |
|
183 | + function unscanCharacter() { |
|
184 | + $this->position -= 1; |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Moves the position forward one character |
|
189 | + * @access protected |
|
190 | + * @return void |
|
191 | + */ |
|
192 | + function ignoreCharacter() { |
|
193 | + $this->position += 1; |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * Returns the next character from the XML document or void if at end |
|
198 | + * @access protected |
|
199 | + * @return mixed |
|
200 | + */ |
|
201 | + function scanCharacter() { |
|
202 | + if ($this->position < $this->length) { |
|
203 | + return $this->rawtext{$this->position++}; |
|
204 | + } |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Returns a string from the current position to the next occurance |
|
209 | + * of the supplied string |
|
210 | + * @param string string to search until |
|
211 | + * @access protected |
|
212 | + * @return string |
|
213 | + */ |
|
214 | + function scanUntilString($string) { |
|
215 | + $start = $this->position; |
|
216 | + $this->position = strpos($this->rawtext, $string, $start); |
|
217 | + if ($this->position === FALSE) { |
|
218 | + $this->position = $this->length; |
|
219 | + } |
|
220 | + return substr($this->rawtext, $start, $this->position - $start); |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * Returns a string from the current position until the first instance of |
|
225 | + * one of the characters in the supplied string argument |
|
226 | + * @param string string to search until |
|
227 | + * @access protected |
|
228 | + * @return string |
|
229 | + * @abstract |
|
230 | + */ |
|
231 | + function scanUntilCharacters($string) {} |
|
232 | + |
|
233 | + /** |
|
234 | + * Moves the position forward past any whitespace characters |
|
235 | + * @access protected |
|
236 | + * @return void |
|
237 | + * @abstract |
|
238 | + */ |
|
239 | + function ignoreWhitespace() {} |
|
240 | + |
|
241 | + /** |
|
242 | + * Begins the parsing operation, setting up any decorators, depending on |
|
243 | + * parse options invoking _parse() to execute parsing |
|
244 | + * @param string XML document to parse |
|
245 | + * @access protected |
|
246 | + * @return void |
|
247 | + */ |
|
248 | + function parse($data) { |
|
249 | + if ($this->parser_options['XML_OPTION_TRIM_DATA_NODES']==1) { |
|
250 | + $decorator = new TSax3_Trim( |
|
251 | + $this->handler_object_data, |
|
252 | + $this->handler_method_data); |
|
253 | + $this->handler_object_data =& $decorator; |
|
254 | + $this->handler_method_data = 'trimData'; |
|
255 | + } |
|
256 | + if ($this->parser_options['XML_OPTION_CASE_FOLDING']==1) { |
|
257 | + $open_decor = new TSax3_CaseFolding( |
|
258 | + $this->handler_object_element, |
|
259 | + $this->handler_method_opening, |
|
260 | + $this->handler_method_closing); |
|
261 | + $this->handler_object_element =& $open_decor; |
|
262 | + $this->handler_method_opening ='foldOpen'; |
|
263 | + $this->handler_method_closing ='foldClose'; |
|
264 | + } |
|
265 | + if ($this->parser_options['XML_OPTION_LINEFEED_BREAK']==1) { |
|
266 | + $decorator = new TSax3_Linefeed( |
|
267 | + $this->handler_object_data, |
|
268 | + $this->handler_method_data); |
|
269 | + $this->handler_object_data =& $decorator; |
|
270 | + $this->handler_method_data = 'breakData'; |
|
271 | + } |
|
272 | + if ($this->parser_options['XML_OPTION_TAB_BREAK']==1) { |
|
273 | + $decorator = new TSax3_Tab( |
|
274 | + $this->handler_object_data, |
|
275 | + $this->handler_method_data); |
|
276 | + $this->handler_object_data =& $decorator; |
|
277 | + $this->handler_method_data = 'breakData'; |
|
278 | + } |
|
279 | + if ($this->parser_options['XML_OPTION_ENTITIES_UNPARSED']==1) { |
|
280 | + $decorator = new TSax3_Entities_Unparsed( |
|
281 | + $this->handler_object_data, |
|
282 | + $this->handler_method_data); |
|
283 | + $this->handler_object_data =& $decorator; |
|
284 | + $this->handler_method_data = 'breakData'; |
|
285 | + } |
|
286 | + if ($this->parser_options['XML_OPTION_ENTITIES_PARSED']==1) { |
|
287 | + $decorator = new TSax3_Entities_Parsed( |
|
288 | + $this->handler_object_data, |
|
289 | + $this->handler_method_data); |
|
290 | + $this->handler_object_data =& $decorator; |
|
291 | + $this->handler_method_data = 'breakData'; |
|
292 | + } |
|
293 | + // Note switched on by default |
|
294 | + if ($this->parser_options['XML_OPTION_STRIP_ESCAPES']==1) { |
|
295 | + $decorator = new TSax3_Escape_Stripper( |
|
296 | + $this->handler_object_escape, |
|
297 | + $this->handler_method_escape); |
|
298 | + $this->handler_object_escape =& $decorator; |
|
299 | + $this->handler_method_escape = 'strip'; |
|
300 | + } |
|
301 | + $this->rawtext = $data; |
|
302 | + $this->length = strlen($data); |
|
303 | + $this->position = 0; |
|
304 | + $this->_parse(); |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * Performs the parsing itself, delegating calls to a specific parser |
|
309 | + * state |
|
310 | + * @param constant state object to parse with |
|
311 | + * @access protected |
|
312 | + * @return void |
|
313 | + */ |
|
314 | + function _parse($state = self::TSAX3_STATE_START) { |
|
315 | + do { |
|
316 | + $state = $this->State[$state]->parse($this); |
|
317 | + } while ($state != self::TSAX3_STATE_STOP && |
|
318 | + $this->position < $this->length); |
|
319 | + } |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | /** |
@@ -327,61 +327,61 @@ discard block |
||
327 | 327 | * @see TSax3_StateParser_Gtet430 |
328 | 328 | */ |
329 | 329 | class TSax3_StateParser_Lt430 extends TSax3_StateParser { |
330 | - /** |
|
331 | - * Constructs TSax3_StateParser_Lt430 defining available |
|
332 | - * parser options |
|
333 | - * @var TSax3 instance of user front end class |
|
334 | - * @access protected |
|
335 | - */ |
|
336 | - function __construct(& $htmlsax) { |
|
337 | - parent::__construct($htmlsax); |
|
338 | - $this->parser_options['XML_OPTION_TRIM_DATA_NODES'] = 0; |
|
339 | - $this->parser_options['XML_OPTION_CASE_FOLDING'] = 0; |
|
340 | - $this->parser_options['XML_OPTION_LINEFEED_BREAK'] = 0; |
|
341 | - $this->parser_options['XML_OPTION_TAB_BREAK'] = 0; |
|
342 | - $this->parser_options['XML_OPTION_ENTITIES_PARSED'] = 0; |
|
343 | - $this->parser_options['XML_OPTION_ENTITIES_UNPARSED'] = 0; |
|
344 | - $this->parser_options['XML_OPTION_STRIP_ESCAPES'] = 0; |
|
330 | + /** |
|
331 | + * Constructs TSax3_StateParser_Lt430 defining available |
|
332 | + * parser options |
|
333 | + * @var TSax3 instance of user front end class |
|
334 | + * @access protected |
|
335 | + */ |
|
336 | + function __construct(& $htmlsax) { |
|
337 | + parent::__construct($htmlsax); |
|
338 | + $this->parser_options['XML_OPTION_TRIM_DATA_NODES'] = 0; |
|
339 | + $this->parser_options['XML_OPTION_CASE_FOLDING'] = 0; |
|
340 | + $this->parser_options['XML_OPTION_LINEFEED_BREAK'] = 0; |
|
341 | + $this->parser_options['XML_OPTION_TAB_BREAK'] = 0; |
|
342 | + $this->parser_options['XML_OPTION_ENTITIES_PARSED'] = 0; |
|
343 | + $this->parser_options['XML_OPTION_ENTITIES_UNPARSED'] = 0; |
|
344 | + $this->parser_options['XML_OPTION_STRIP_ESCAPES'] = 0; |
|
345 | 345 | //var_dump($this->parser_options); |
346 | - } |
|
347 | - |
|
348 | - /** |
|
349 | - * Returns a string from the current position until the first instance of |
|
350 | - * one of the characters in the supplied string argument |
|
351 | - * @param string string to search until |
|
352 | - * @access protected |
|
353 | - * @return string |
|
354 | - */ |
|
355 | - function scanUntilCharacters($string) { |
|
356 | - $startpos = $this->position; |
|
357 | - while ($this->position < $this->length && strpos($string, $this->rawtext{$this->position}) === FALSE) { |
|
358 | - $this->position++; |
|
359 | - } |
|
360 | - return substr($this->rawtext, $startpos, $this->position - $startpos); |
|
361 | - } |
|
362 | - |
|
363 | - /** |
|
364 | - * Moves the position forward past any whitespace characters |
|
365 | - * @access protected |
|
366 | - * @return void |
|
367 | - */ |
|
368 | - function ignoreWhitespace() { |
|
369 | - while ($this->position < $this->length && |
|
370 | - strpos(" \n\r\t", $this->rawtext{$this->position}) !== FALSE) { |
|
371 | - $this->position++; |
|
372 | - } |
|
373 | - } |
|
374 | - |
|
375 | - /** |
|
376 | - * Begins the parsing operation, setting up the unparsed XML entities |
|
377 | - * decorator if necessary then delegating further work to parent |
|
378 | - * @param string XML document to parse |
|
379 | - * @access protected |
|
380 | - * @return void |
|
381 | - */ |
|
382 | - function parse($data) { |
|
383 | - parent::parse($data); |
|
384 | - } |
|
346 | + } |
|
347 | + |
|
348 | + /** |
|
349 | + * Returns a string from the current position until the first instance of |
|
350 | + * one of the characters in the supplied string argument |
|
351 | + * @param string string to search until |
|
352 | + * @access protected |
|
353 | + * @return string |
|
354 | + */ |
|
355 | + function scanUntilCharacters($string) { |
|
356 | + $startpos = $this->position; |
|
357 | + while ($this->position < $this->length && strpos($string, $this->rawtext{$this->position}) === FALSE) { |
|
358 | + $this->position++; |
|
359 | + } |
|
360 | + return substr($this->rawtext, $startpos, $this->position - $startpos); |
|
361 | + } |
|
362 | + |
|
363 | + /** |
|
364 | + * Moves the position forward past any whitespace characters |
|
365 | + * @access protected |
|
366 | + * @return void |
|
367 | + */ |
|
368 | + function ignoreWhitespace() { |
|
369 | + while ($this->position < $this->length && |
|
370 | + strpos(" \n\r\t", $this->rawtext{$this->position}) !== FALSE) { |
|
371 | + $this->position++; |
|
372 | + } |
|
373 | + } |
|
374 | + |
|
375 | + /** |
|
376 | + * Begins the parsing operation, setting up the unparsed XML entities |
|
377 | + * decorator if necessary then delegating further work to parent |
|
378 | + * @param string XML document to parse |
|
379 | + * @access protected |
|
380 | + * @return void |
|
381 | + */ |
|
382 | + function parse($data) { |
|
383 | + parent::parse($data); |
|
384 | + } |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | /** |
@@ -392,56 +392,56 @@ discard block |
||
392 | 392 | * @see TSax3_StateParser_Lt430 |
393 | 393 | */ |
394 | 394 | class TSax3_StateParser_Gtet430 extends TSax3_StateParser { |
395 | - /** |
|
396 | - * Constructs TSax3_StateParser_Gtet430 defining available |
|
397 | - * parser options |
|
398 | - * @var TSax3 instance of user front end class |
|
399 | - * @access protected |
|
400 | - */ |
|
401 | - function __construct(& $htmlsax) { |
|
402 | - parent::__construct($htmlsax); |
|
403 | - $this->parser_options['XML_OPTION_TRIM_DATA_NODES'] = 0; |
|
404 | - $this->parser_options['XML_OPTION_CASE_FOLDING'] = 0; |
|
405 | - $this->parser_options['XML_OPTION_LINEFEED_BREAK'] = 0; |
|
406 | - $this->parser_options['XML_OPTION_TAB_BREAK'] = 0; |
|
407 | - $this->parser_options['XML_OPTION_ENTITIES_PARSED'] = 0; |
|
408 | - $this->parser_options['XML_OPTION_ENTITIES_UNPARSED'] = 0; |
|
409 | - $this->parser_options['XML_OPTION_STRIP_ESCAPES'] = 0; |
|
410 | - } |
|
411 | - /** |
|
412 | - * Returns a string from the current position until the first instance of |
|
413 | - * one of the characters in the supplied string argument. |
|
414 | - * @param string string to search until |
|
415 | - * @access protected |
|
416 | - * @return string |
|
417 | - */ |
|
418 | - function scanUntilCharacters($string) { |
|
419 | - $startpos = $this->position; |
|
420 | - $length = strcspn($this->rawtext, $string, $startpos); |
|
421 | - $this->position += $length; |
|
422 | - return substr($this->rawtext, $startpos, $length); |
|
423 | - } |
|
424 | - |
|
425 | - /** |
|
426 | - * Moves the position forward past any whitespace characters |
|
427 | - * @access protected |
|
428 | - * @return void |
|
429 | - */ |
|
430 | - function ignoreWhitespace() { |
|
431 | - $this->position += strspn($this->rawtext, " \n\r\t", $this->position); |
|
432 | - } |
|
433 | - |
|
434 | - /** |
|
435 | - * Begins the parsing operation, setting up the parsed and unparsed |
|
436 | - * XML entity decorators if necessary then delegating further work |
|
437 | - * to parent |
|
438 | - * @param string XML document to parse |
|
439 | - * @access protected |
|
440 | - * @return void |
|
441 | - */ |
|
442 | - function parse($data) { |
|
443 | - parent::parse($data); |
|
444 | - } |
|
395 | + /** |
|
396 | + * Constructs TSax3_StateParser_Gtet430 defining available |
|
397 | + * parser options |
|
398 | + * @var TSax3 instance of user front end class |
|
399 | + * @access protected |
|
400 | + */ |
|
401 | + function __construct(& $htmlsax) { |
|
402 | + parent::__construct($htmlsax); |
|
403 | + $this->parser_options['XML_OPTION_TRIM_DATA_NODES'] = 0; |
|
404 | + $this->parser_options['XML_OPTION_CASE_FOLDING'] = 0; |
|
405 | + $this->parser_options['XML_OPTION_LINEFEED_BREAK'] = 0; |
|
406 | + $this->parser_options['XML_OPTION_TAB_BREAK'] = 0; |
|
407 | + $this->parser_options['XML_OPTION_ENTITIES_PARSED'] = 0; |
|
408 | + $this->parser_options['XML_OPTION_ENTITIES_UNPARSED'] = 0; |
|
409 | + $this->parser_options['XML_OPTION_STRIP_ESCAPES'] = 0; |
|
410 | + } |
|
411 | + /** |
|
412 | + * Returns a string from the current position until the first instance of |
|
413 | + * one of the characters in the supplied string argument. |
|
414 | + * @param string string to search until |
|
415 | + * @access protected |
|
416 | + * @return string |
|
417 | + */ |
|
418 | + function scanUntilCharacters($string) { |
|
419 | + $startpos = $this->position; |
|
420 | + $length = strcspn($this->rawtext, $string, $startpos); |
|
421 | + $this->position += $length; |
|
422 | + return substr($this->rawtext, $startpos, $length); |
|
423 | + } |
|
424 | + |
|
425 | + /** |
|
426 | + * Moves the position forward past any whitespace characters |
|
427 | + * @access protected |
|
428 | + * @return void |
|
429 | + */ |
|
430 | + function ignoreWhitespace() { |
|
431 | + $this->position += strspn($this->rawtext, " \n\r\t", $this->position); |
|
432 | + } |
|
433 | + |
|
434 | + /** |
|
435 | + * Begins the parsing operation, setting up the parsed and unparsed |
|
436 | + * XML entity decorators if necessary then delegating further work |
|
437 | + * to parent |
|
438 | + * @param string XML document to parse |
|
439 | + * @access protected |
|
440 | + * @return void |
|
441 | + */ |
|
442 | + function parse($data) { |
|
443 | + parent::parse($data); |
|
444 | + } |
|
445 | 445 | } |
446 | 446 | |
447 | 447 | /** |
@@ -450,13 +450,13 @@ discard block |
||
450 | 450 | * @access protected |
451 | 451 | */ |
452 | 452 | class TSax3_NullHandler { |
453 | - /** |
|
454 | - * Generic handler method which does nothing |
|
455 | - * @access protected |
|
456 | - * @return void |
|
457 | - */ |
|
458 | - function DoNothing() { |
|
459 | - } |
|
453 | + /** |
|
454 | + * Generic handler method which does nothing |
|
455 | + * @access protected |
|
456 | + * @return void |
|
457 | + */ |
|
458 | + function DoNothing() { |
|
459 | + } |
|
460 | 460 | } |
461 | 461 | |
462 | 462 | /** |
@@ -465,229 +465,229 @@ discard block |
||
465 | 465 | * @access public |
466 | 466 | */ |
467 | 467 | class TSax3 { |
468 | - /** |
|
469 | - * Instance of concrete subclass of TSax3_StateParser |
|
470 | - * @var TSax3_StateParser |
|
471 | - * @access private |
|
472 | - */ |
|
473 | - private $state_parser; |
|
474 | - |
|
475 | - /** |
|
476 | - * Constructs TSax3 selecting concrete StateParser subclass |
|
477 | - * depending on PHP version being used as well as setting the default |
|
478 | - * NullHandler for all callbacks<br /> |
|
479 | - * <b>Example:</b> |
|
480 | - * <pre> |
|
481 | - * $myHandler = & new MyHandler(); |
|
482 | - * $parser = new TSax3(); |
|
483 | - * $parser->set_object($myHandler); |
|
484 | - * $parser->set_option('XML_OPTION_CASE_FOLDING'); |
|
485 | - * $parser->set_element_handler('myOpenHandler','myCloseHandler'); |
|
486 | - * $parser->set_data_handler('myDataHandler'); |
|
487 | - * $parser->parser($xml); |
|
488 | - * </pre> |
|
489 | - * @access public |
|
490 | - */ |
|
491 | - function __construct() { |
|
492 | - if (version_compare(phpversion(), '4.3', 'ge')) { |
|
493 | - $this->state_parser = new TSax3_StateParser_Gtet430($this); |
|
494 | - } else { |
|
495 | - $this->state_parser = new TSax3_StateParser_Lt430($this); |
|
496 | - } |
|
497 | - $nullhandler = new TSax3_NullHandler(); |
|
498 | - $this->set_object($nullhandler); |
|
499 | - $this->set_element_handler('DoNothing', 'DoNothing'); |
|
500 | - $this->set_data_handler('DoNothing'); |
|
501 | - $this->set_pi_handler('DoNothing'); |
|
502 | - $this->set_jasp_handler('DoNothing'); |
|
503 | - $this->set_escape_handler('DoNothing'); |
|
504 | - } |
|
505 | - |
|
506 | - /** |
|
507 | - * Sets the user defined handler object. Returns a PEAR Error |
|
508 | - * if supplied argument is not an object. |
|
509 | - * @param object handler object containing SAX callback methods |
|
510 | - * @access public |
|
511 | - * @return mixed |
|
512 | - */ |
|
513 | - function set_object(&$object) { |
|
514 | - if ( is_object($object) ) { |
|
515 | - $this->state_parser->handler_default =& $object; |
|
516 | - return true; |
|
517 | - } else { |
|
518 | - require_once('PEAR.php'); |
|
519 | - PEAR::raiseError('TSax3::set_object requires '. |
|
520 | - 'an object instance'); |
|
521 | - } |
|
522 | - } |
|
523 | - |
|
524 | - /** |
|
525 | - * Sets a parser option. By default all options are switched off. |
|
526 | - * Returns a PEAR Error if option is invalid<br /> |
|
527 | - * <b>Available options:</b> |
|
528 | - * <ul> |
|
529 | - * <li>XML_OPTION_TRIM_DATA_NODES: trim whitespace off the beginning |
|
530 | - * and end of data passed to the data handler</li> |
|
531 | - * <li>XML_OPTION_LINEFEED_BREAK: linefeeds result in additional data |
|
532 | - * handler calls</li> |
|
533 | - * <li>XML_OPTION_TAB_BREAK: tabs result in additional data handler |
|
534 | - * calls</li> |
|
535 | - * <li>XML_OPTION_ENTITIES_UNPARSED: XML entities are returned as |
|
536 | - * seperate data handler calls in unparsed form</li> |
|
537 | - * <li>XML_OPTION_ENTITIES_PARSED: (PHP 4.3.0+ only) XML entities are |
|
538 | - * returned as seperate data handler calls and are parsed with |
|
539 | - * PHP's html_entity_decode() function</li> |
|
540 | - * <li>XML_OPTION_STRIP_ESCAPES: strips out the -- -- comment markers |
|
541 | - * or CDATA markup inside an XML escape, if found.</li> |
|
542 | - * </ul> |
|
543 | - * To get HTMLSax to behave in the same way as the native PHP SAX parser, |
|
544 | - * using it's default state, you need to switch on XML_OPTION_LINEFEED_BREAK, |
|
545 | - * XML_OPTION_ENTITIES_PARSED and XML_OPTION_CASE_FOLDING |
|
546 | - * @param string name of parser option |
|
547 | - * @param int (optional) 1 to switch on, 0 for off |
|
548 | - * @access public |
|
549 | - * @return boolean |
|
550 | - */ |
|
551 | - function set_option($name, $value=1) { |
|
552 | - if ( array_key_exists($name,$this->state_parser->parser_options) ) { |
|
553 | - $this->state_parser->parser_options[$name] = $value; |
|
554 | - return true; |
|
555 | - } else { |
|
556 | - require_once('PEAR.php'); |
|
557 | - PEAR::raiseError('TSax3::set_option('.$name.') illegal'); |
|
558 | - } |
|
559 | - } |
|
560 | - |
|
561 | - /** |
|
562 | - * Sets the data handler method which deals with the contents of XML |
|
563 | - * elements.<br /> |
|
564 | - * The handler method must accept two arguments, the first being an |
|
565 | - * instance of TSax3 and the second being the contents of an |
|
566 | - * XML element e.g. |
|
567 | - * <pre> |
|
568 | - * function myDataHander(& $parser,$data){} |
|
569 | - * </pre> |
|
570 | - * @param string name of method |
|
571 | - * @access public |
|
572 | - * @return void |
|
573 | - * @see set_object |
|
574 | - */ |
|
575 | - function set_data_handler($data_method) { |
|
576 | - $this->state_parser->handler_object_data =& $this->state_parser->handler_default; |
|
577 | - $this->state_parser->handler_method_data = $data_method; |
|
578 | - } |
|
579 | - |
|
580 | - /** |
|
581 | - * Sets the open and close tag handlers |
|
582 | - * <br />The open handler method must accept three arguments; the parser, |
|
583 | - * the tag name and an array of attributes e.g. |
|
584 | - * <pre> |
|
585 | - * function myOpenHander(& $parser,$tagname,$attrs=array()){} |
|
586 | - * </pre> |
|
587 | - * The close handler method must accept two arguments; the parser and |
|
588 | - * the tag name e.g. |
|
589 | - * <pre> |
|
590 | - * function myCloseHander(& $parser,$tagname){} |
|
591 | - * </pre> |
|
592 | - * @param string name of open method |
|
593 | - * @param string name of close method |
|
594 | - * @access public |
|
595 | - * @return void |
|
596 | - * @see set_object |
|
597 | - */ |
|
598 | - function set_element_handler($opening_method, $closing_method) { |
|
599 | - $this->state_parser->handler_object_element =& $this->state_parser->handler_default; |
|
600 | - $this->state_parser->handler_method_opening = $opening_method; |
|
601 | - $this->state_parser->handler_method_closing = $closing_method; |
|
602 | - } |
|
603 | - |
|
604 | - /** |
|
605 | - * Sets the processing instruction handler method e.g. for PHP open |
|
606 | - * and close tags<br /> |
|
607 | - * The handler method must accept three arguments; the parser, the |
|
608 | - * PI target and data inside the PI |
|
609 | - * <pre> |
|
610 | - * function myPIHander(& $parser,$target, $data){} |
|
611 | - * </pre> |
|
612 | - * @param string name of method |
|
613 | - * @access public |
|
614 | - * @return void |
|
615 | - * @see set_object |
|
616 | - */ |
|
617 | - function set_pi_handler($pi_method) { |
|
618 | - $this->state_parser->handler_object_pi =& $this->state_parser->handler_default; |
|
619 | - $this->state_parser->handler_method_pi = $pi_method; |
|
620 | - } |
|
621 | - |
|
622 | - /** |
|
623 | - * Sets the XML escape handler method e.g. for comments and doctype |
|
624 | - * declarations<br /> |
|
625 | - * The handler method must accept two arguments; the parser and the |
|
626 | - * contents of the escaped section |
|
627 | - * <pre> |
|
628 | - * function myEscapeHander(& $parser, $data){} |
|
629 | - * </pre> |
|
630 | - * @param string name of method |
|
631 | - * @access public |
|
632 | - * @return void |
|
633 | - * @see set_object |
|
634 | - */ |
|
635 | - function set_escape_handler($escape_method) { |
|
636 | - $this->state_parser->handler_object_escape =& $this->state_parser->handler_default; |
|
637 | - $this->state_parser->handler_method_escape = $escape_method; |
|
638 | - } |
|
639 | - |
|
640 | - /** |
|
641 | - * Sets the JSP/ASP markup handler<br /> |
|
642 | - * The handler method must accept two arguments; the parser and |
|
643 | - * body of the JASP tag |
|
644 | - * <pre> |
|
645 | - * function myJaspHander(& $parser, $data){} |
|
646 | - * </pre> |
|
647 | - * @param string name of method |
|
648 | - * @access public |
|
649 | - * @return void |
|
650 | - * @see set_object |
|
651 | - */ |
|
652 | - function set_jasp_handler ($jasp_method) { |
|
653 | - $this->state_parser->handler_object_jasp =& $this->state_parser->handler_default; |
|
654 | - $this->state_parser->handler_method_jasp = $jasp_method; |
|
655 | - } |
|
656 | - |
|
657 | - /** |
|
658 | - * Returns the current string position of the "cursor" inside the XML |
|
659 | - * document |
|
660 | - * <br />Intended for use from within a user defined handler called |
|
661 | - * via the $parser reference e.g. |
|
662 | - * <pre> |
|
663 | - * function myDataHandler(& $parser,$data) { |
|
664 | - * echo( 'Current position: '.$parser->get_current_position() ); |
|
665 | - * } |
|
666 | - * </pre> |
|
667 | - * @access public |
|
668 | - * @return int |
|
669 | - * @see get_length |
|
670 | - */ |
|
671 | - function get_current_position() { |
|
672 | - return $this->state_parser->position; |
|
673 | - } |
|
674 | - |
|
675 | - /** |
|
676 | - * Returns the string length of the XML document being parsed |
|
677 | - * @access public |
|
678 | - * @return int |
|
679 | - */ |
|
680 | - function get_length() { |
|
681 | - return $this->state_parser->length; |
|
682 | - } |
|
683 | - |
|
684 | - /** |
|
685 | - * Start parsing some XML |
|
686 | - * @param string XML document |
|
687 | - * @access public |
|
688 | - * @return void |
|
689 | - */ |
|
690 | - function parse($data) { |
|
691 | - $this->state_parser->parse($data); |
|
692 | - } |
|
468 | + /** |
|
469 | + * Instance of concrete subclass of TSax3_StateParser |
|
470 | + * @var TSax3_StateParser |
|
471 | + * @access private |
|
472 | + */ |
|
473 | + private $state_parser; |
|
474 | + |
|
475 | + /** |
|
476 | + * Constructs TSax3 selecting concrete StateParser subclass |
|
477 | + * depending on PHP version being used as well as setting the default |
|
478 | + * NullHandler for all callbacks<br /> |
|
479 | + * <b>Example:</b> |
|
480 | + * <pre> |
|
481 | + * $myHandler = & new MyHandler(); |
|
482 | + * $parser = new TSax3(); |
|
483 | + * $parser->set_object($myHandler); |
|
484 | + * $parser->set_option('XML_OPTION_CASE_FOLDING'); |
|
485 | + * $parser->set_element_handler('myOpenHandler','myCloseHandler'); |
|
486 | + * $parser->set_data_handler('myDataHandler'); |
|
487 | + * $parser->parser($xml); |
|
488 | + * </pre> |
|
489 | + * @access public |
|
490 | + */ |
|
491 | + function __construct() { |
|
492 | + if (version_compare(phpversion(), '4.3', 'ge')) { |
|
493 | + $this->state_parser = new TSax3_StateParser_Gtet430($this); |
|
494 | + } else { |
|
495 | + $this->state_parser = new TSax3_StateParser_Lt430($this); |
|
496 | + } |
|
497 | + $nullhandler = new TSax3_NullHandler(); |
|
498 | + $this->set_object($nullhandler); |
|
499 | + $this->set_element_handler('DoNothing', 'DoNothing'); |
|
500 | + $this->set_data_handler('DoNothing'); |
|
501 | + $this->set_pi_handler('DoNothing'); |
|
502 | + $this->set_jasp_handler('DoNothing'); |
|
503 | + $this->set_escape_handler('DoNothing'); |
|
504 | + } |
|
505 | + |
|
506 | + /** |
|
507 | + * Sets the user defined handler object. Returns a PEAR Error |
|
508 | + * if supplied argument is not an object. |
|
509 | + * @param object handler object containing SAX callback methods |
|
510 | + * @access public |
|
511 | + * @return mixed |
|
512 | + */ |
|
513 | + function set_object(&$object) { |
|
514 | + if ( is_object($object) ) { |
|
515 | + $this->state_parser->handler_default =& $object; |
|
516 | + return true; |
|
517 | + } else { |
|
518 | + require_once('PEAR.php'); |
|
519 | + PEAR::raiseError('TSax3::set_object requires '. |
|
520 | + 'an object instance'); |
|
521 | + } |
|
522 | + } |
|
523 | + |
|
524 | + /** |
|
525 | + * Sets a parser option. By default all options are switched off. |
|
526 | + * Returns a PEAR Error if option is invalid<br /> |
|
527 | + * <b>Available options:</b> |
|
528 | + * <ul> |
|
529 | + * <li>XML_OPTION_TRIM_DATA_NODES: trim whitespace off the beginning |
|
530 | + * and end of data passed to the data handler</li> |
|
531 | + * <li>XML_OPTION_LINEFEED_BREAK: linefeeds result in additional data |
|
532 | + * handler calls</li> |
|
533 | + * <li>XML_OPTION_TAB_BREAK: tabs result in additional data handler |
|
534 | + * calls</li> |
|
535 | + * <li>XML_OPTION_ENTITIES_UNPARSED: XML entities are returned as |
|
536 | + * seperate data handler calls in unparsed form</li> |
|
537 | + * <li>XML_OPTION_ENTITIES_PARSED: (PHP 4.3.0+ only) XML entities are |
|
538 | + * returned as seperate data handler calls and are parsed with |
|
539 | + * PHP's html_entity_decode() function</li> |
|
540 | + * <li>XML_OPTION_STRIP_ESCAPES: strips out the -- -- comment markers |
|
541 | + * or CDATA markup inside an XML escape, if found.</li> |
|
542 | + * </ul> |
|
543 | + * To get HTMLSax to behave in the same way as the native PHP SAX parser, |
|
544 | + * using it's default state, you need to switch on XML_OPTION_LINEFEED_BREAK, |
|
545 | + * XML_OPTION_ENTITIES_PARSED and XML_OPTION_CASE_FOLDING |
|
546 | + * @param string name of parser option |
|
547 | + * @param int (optional) 1 to switch on, 0 for off |
|
548 | + * @access public |
|
549 | + * @return boolean |
|
550 | + */ |
|
551 | + function set_option($name, $value=1) { |
|
552 | + if ( array_key_exists($name,$this->state_parser->parser_options) ) { |
|
553 | + $this->state_parser->parser_options[$name] = $value; |
|
554 | + return true; |
|
555 | + } else { |
|
556 | + require_once('PEAR.php'); |
|
557 | + PEAR::raiseError('TSax3::set_option('.$name.') illegal'); |
|
558 | + } |
|
559 | + } |
|
560 | + |
|
561 | + /** |
|
562 | + * Sets the data handler method which deals with the contents of XML |
|
563 | + * elements.<br /> |
|
564 | + * The handler method must accept two arguments, the first being an |
|
565 | + * instance of TSax3 and the second being the contents of an |
|
566 | + * XML element e.g. |
|
567 | + * <pre> |
|
568 | + * function myDataHander(& $parser,$data){} |
|
569 | + * </pre> |
|
570 | + * @param string name of method |
|
571 | + * @access public |
|
572 | + * @return void |
|
573 | + * @see set_object |
|
574 | + */ |
|
575 | + function set_data_handler($data_method) { |
|
576 | + $this->state_parser->handler_object_data =& $this->state_parser->handler_default; |
|
577 | + $this->state_parser->handler_method_data = $data_method; |
|
578 | + } |
|
579 | + |
|
580 | + /** |
|
581 | + * Sets the open and close tag handlers |
|
582 | + * <br />The open handler method must accept three arguments; the parser, |
|
583 | + * the tag name and an array of attributes e.g. |
|
584 | + * <pre> |
|
585 | + * function myOpenHander(& $parser,$tagname,$attrs=array()){} |
|
586 | + * </pre> |
|
587 | + * The close handler method must accept two arguments; the parser and |
|
588 | + * the tag name e.g. |
|
589 | + * <pre> |
|
590 | + * function myCloseHander(& $parser,$tagname){} |
|
591 | + * </pre> |
|
592 | + * @param string name of open method |
|
593 | + * @param string name of close method |
|
594 | + * @access public |
|
595 | + * @return void |
|
596 | + * @see set_object |
|
597 | + */ |
|
598 | + function set_element_handler($opening_method, $closing_method) { |
|
599 | + $this->state_parser->handler_object_element =& $this->state_parser->handler_default; |
|
600 | + $this->state_parser->handler_method_opening = $opening_method; |
|
601 | + $this->state_parser->handler_method_closing = $closing_method; |
|
602 | + } |
|
603 | + |
|
604 | + /** |
|
605 | + * Sets the processing instruction handler method e.g. for PHP open |
|
606 | + * and close tags<br /> |
|
607 | + * The handler method must accept three arguments; the parser, the |
|
608 | + * PI target and data inside the PI |
|
609 | + * <pre> |
|
610 | + * function myPIHander(& $parser,$target, $data){} |
|
611 | + * </pre> |
|
612 | + * @param string name of method |
|
613 | + * @access public |
|
614 | + * @return void |
|
615 | + * @see set_object |
|
616 | + */ |
|
617 | + function set_pi_handler($pi_method) { |
|
618 | + $this->state_parser->handler_object_pi =& $this->state_parser->handler_default; |
|
619 | + $this->state_parser->handler_method_pi = $pi_method; |
|
620 | + } |
|
621 | + |
|
622 | + /** |
|
623 | + * Sets the XML escape handler method e.g. for comments and doctype |
|
624 | + * declarations<br /> |
|
625 | + * The handler method must accept two arguments; the parser and the |
|
626 | + * contents of the escaped section |
|
627 | + * <pre> |
|
628 | + * function myEscapeHander(& $parser, $data){} |
|
629 | + * </pre> |
|
630 | + * @param string name of method |
|
631 | + * @access public |
|
632 | + * @return void |
|
633 | + * @see set_object |
|
634 | + */ |
|
635 | + function set_escape_handler($escape_method) { |
|
636 | + $this->state_parser->handler_object_escape =& $this->state_parser->handler_default; |
|
637 | + $this->state_parser->handler_method_escape = $escape_method; |
|
638 | + } |
|
639 | + |
|
640 | + /** |
|
641 | + * Sets the JSP/ASP markup handler<br /> |
|
642 | + * The handler method must accept two arguments; the parser and |
|
643 | + * body of the JASP tag |
|
644 | + * <pre> |
|
645 | + * function myJaspHander(& $parser, $data){} |
|
646 | + * </pre> |
|
647 | + * @param string name of method |
|
648 | + * @access public |
|
649 | + * @return void |
|
650 | + * @see set_object |
|
651 | + */ |
|
652 | + function set_jasp_handler ($jasp_method) { |
|
653 | + $this->state_parser->handler_object_jasp =& $this->state_parser->handler_default; |
|
654 | + $this->state_parser->handler_method_jasp = $jasp_method; |
|
655 | + } |
|
656 | + |
|
657 | + /** |
|
658 | + * Returns the current string position of the "cursor" inside the XML |
|
659 | + * document |
|
660 | + * <br />Intended for use from within a user defined handler called |
|
661 | + * via the $parser reference e.g. |
|
662 | + * <pre> |
|
663 | + * function myDataHandler(& $parser,$data) { |
|
664 | + * echo( 'Current position: '.$parser->get_current_position() ); |
|
665 | + * } |
|
666 | + * </pre> |
|
667 | + * @access public |
|
668 | + * @return int |
|
669 | + * @see get_length |
|
670 | + */ |
|
671 | + function get_current_position() { |
|
672 | + return $this->state_parser->position; |
|
673 | + } |
|
674 | + |
|
675 | + /** |
|
676 | + * Returns the string length of the XML document being parsed |
|
677 | + * @access public |
|
678 | + * @return int |
|
679 | + */ |
|
680 | + function get_length() { |
|
681 | + return $this->state_parser->length; |
|
682 | + } |
|
683 | + |
|
684 | + /** |
|
685 | + * Start parsing some XML |
|
686 | + * @param string XML document |
|
687 | + * @access public |
|
688 | + * @return void |
|
689 | + */ |
|
690 | + function parse($data) { |
|
691 | + $this->state_parser->parse($data); |
|
692 | + } |
|
693 | 693 | } |
@@ -29,8 +29,8 @@ discard block |
||
29 | 29 | * Required classes |
30 | 30 | */ |
31 | 31 | |
32 | -require_once(dirname(__FILE__).'/HTMLSax3/States.php'); |
|
33 | -require_once(dirname(__FILE__).'/HTMLSax3/Decorators.php'); |
|
32 | +require_once(dirname(__FILE__) . '/HTMLSax3/States.php'); |
|
33 | +require_once(dirname(__FILE__) . '/HTMLSax3/Decorators.php'); |
|
34 | 34 | |
35 | 35 | /** |
36 | 36 | * Base State Parser |
@@ -246,56 +246,56 @@ discard block |
||
246 | 246 | * @return void |
247 | 247 | */ |
248 | 248 | function parse($data) { |
249 | - if ($this->parser_options['XML_OPTION_TRIM_DATA_NODES']==1) { |
|
249 | + if ($this->parser_options['XML_OPTION_TRIM_DATA_NODES'] == 1) { |
|
250 | 250 | $decorator = new TSax3_Trim( |
251 | 251 | $this->handler_object_data, |
252 | 252 | $this->handler_method_data); |
253 | - $this->handler_object_data =& $decorator; |
|
253 | + $this->handler_object_data = & $decorator; |
|
254 | 254 | $this->handler_method_data = 'trimData'; |
255 | 255 | } |
256 | - if ($this->parser_options['XML_OPTION_CASE_FOLDING']==1) { |
|
256 | + if ($this->parser_options['XML_OPTION_CASE_FOLDING'] == 1) { |
|
257 | 257 | $open_decor = new TSax3_CaseFolding( |
258 | 258 | $this->handler_object_element, |
259 | 259 | $this->handler_method_opening, |
260 | 260 | $this->handler_method_closing); |
261 | - $this->handler_object_element =& $open_decor; |
|
262 | - $this->handler_method_opening ='foldOpen'; |
|
263 | - $this->handler_method_closing ='foldClose'; |
|
261 | + $this->handler_object_element = & $open_decor; |
|
262 | + $this->handler_method_opening = 'foldOpen'; |
|
263 | + $this->handler_method_closing = 'foldClose'; |
|
264 | 264 | } |
265 | - if ($this->parser_options['XML_OPTION_LINEFEED_BREAK']==1) { |
|
265 | + if ($this->parser_options['XML_OPTION_LINEFEED_BREAK'] == 1) { |
|
266 | 266 | $decorator = new TSax3_Linefeed( |
267 | 267 | $this->handler_object_data, |
268 | 268 | $this->handler_method_data); |
269 | - $this->handler_object_data =& $decorator; |
|
269 | + $this->handler_object_data = & $decorator; |
|
270 | 270 | $this->handler_method_data = 'breakData'; |
271 | 271 | } |
272 | - if ($this->parser_options['XML_OPTION_TAB_BREAK']==1) { |
|
272 | + if ($this->parser_options['XML_OPTION_TAB_BREAK'] == 1) { |
|
273 | 273 | $decorator = new TSax3_Tab( |
274 | 274 | $this->handler_object_data, |
275 | 275 | $this->handler_method_data); |
276 | - $this->handler_object_data =& $decorator; |
|
276 | + $this->handler_object_data = & $decorator; |
|
277 | 277 | $this->handler_method_data = 'breakData'; |
278 | 278 | } |
279 | - if ($this->parser_options['XML_OPTION_ENTITIES_UNPARSED']==1) { |
|
279 | + if ($this->parser_options['XML_OPTION_ENTITIES_UNPARSED'] == 1) { |
|
280 | 280 | $decorator = new TSax3_Entities_Unparsed( |
281 | 281 | $this->handler_object_data, |
282 | 282 | $this->handler_method_data); |
283 | - $this->handler_object_data =& $decorator; |
|
283 | + $this->handler_object_data = & $decorator; |
|
284 | 284 | $this->handler_method_data = 'breakData'; |
285 | 285 | } |
286 | - if ($this->parser_options['XML_OPTION_ENTITIES_PARSED']==1) { |
|
286 | + if ($this->parser_options['XML_OPTION_ENTITIES_PARSED'] == 1) { |
|
287 | 287 | $decorator = new TSax3_Entities_Parsed( |
288 | 288 | $this->handler_object_data, |
289 | 289 | $this->handler_method_data); |
290 | - $this->handler_object_data =& $decorator; |
|
290 | + $this->handler_object_data = & $decorator; |
|
291 | 291 | $this->handler_method_data = 'breakData'; |
292 | 292 | } |
293 | 293 | // Note switched on by default |
294 | - if ($this->parser_options['XML_OPTION_STRIP_ESCAPES']==1) { |
|
294 | + if ($this->parser_options['XML_OPTION_STRIP_ESCAPES'] == 1) { |
|
295 | 295 | $decorator = new TSax3_Escape_Stripper( |
296 | 296 | $this->handler_object_escape, |
297 | 297 | $this->handler_method_escape); |
298 | - $this->handler_object_escape =& $decorator; |
|
298 | + $this->handler_object_escape = & $decorator; |
|
299 | 299 | $this->handler_method_escape = 'strip'; |
300 | 300 | } |
301 | 301 | $this->rawtext = $data; |
@@ -511,12 +511,12 @@ discard block |
||
511 | 511 | * @return mixed |
512 | 512 | */ |
513 | 513 | function set_object(&$object) { |
514 | - if ( is_object($object) ) { |
|
515 | - $this->state_parser->handler_default =& $object; |
|
514 | + if (is_object($object)) { |
|
515 | + $this->state_parser->handler_default = & $object; |
|
516 | 516 | return true; |
517 | 517 | } else { |
518 | 518 | require_once('PEAR.php'); |
519 | - PEAR::raiseError('TSax3::set_object requires '. |
|
519 | + PEAR::raiseError('TSax3::set_object requires ' . |
|
520 | 520 | 'an object instance'); |
521 | 521 | } |
522 | 522 | } |
@@ -548,13 +548,13 @@ discard block |
||
548 | 548 | * @access public |
549 | 549 | * @return boolean |
550 | 550 | */ |
551 | - function set_option($name, $value=1) { |
|
552 | - if ( array_key_exists($name,$this->state_parser->parser_options) ) { |
|
551 | + function set_option($name, $value = 1) { |
|
552 | + if (array_key_exists($name, $this->state_parser->parser_options)) { |
|
553 | 553 | $this->state_parser->parser_options[$name] = $value; |
554 | 554 | return true; |
555 | 555 | } else { |
556 | 556 | require_once('PEAR.php'); |
557 | - PEAR::raiseError('TSax3::set_option('.$name.') illegal'); |
|
557 | + PEAR::raiseError('TSax3::set_option(' . $name . ') illegal'); |
|
558 | 558 | } |
559 | 559 | } |
560 | 560 | |
@@ -573,7 +573,7 @@ discard block |
||
573 | 573 | * @see set_object |
574 | 574 | */ |
575 | 575 | function set_data_handler($data_method) { |
576 | - $this->state_parser->handler_object_data =& $this->state_parser->handler_default; |
|
576 | + $this->state_parser->handler_object_data = & $this->state_parser->handler_default; |
|
577 | 577 | $this->state_parser->handler_method_data = $data_method; |
578 | 578 | } |
579 | 579 | |
@@ -596,7 +596,7 @@ discard block |
||
596 | 596 | * @see set_object |
597 | 597 | */ |
598 | 598 | function set_element_handler($opening_method, $closing_method) { |
599 | - $this->state_parser->handler_object_element =& $this->state_parser->handler_default; |
|
599 | + $this->state_parser->handler_object_element = & $this->state_parser->handler_default; |
|
600 | 600 | $this->state_parser->handler_method_opening = $opening_method; |
601 | 601 | $this->state_parser->handler_method_closing = $closing_method; |
602 | 602 | } |
@@ -615,7 +615,7 @@ discard block |
||
615 | 615 | * @see set_object |
616 | 616 | */ |
617 | 617 | function set_pi_handler($pi_method) { |
618 | - $this->state_parser->handler_object_pi =& $this->state_parser->handler_default; |
|
618 | + $this->state_parser->handler_object_pi = & $this->state_parser->handler_default; |
|
619 | 619 | $this->state_parser->handler_method_pi = $pi_method; |
620 | 620 | } |
621 | 621 | |
@@ -633,7 +633,7 @@ discard block |
||
633 | 633 | * @see set_object |
634 | 634 | */ |
635 | 635 | function set_escape_handler($escape_method) { |
636 | - $this->state_parser->handler_object_escape =& $this->state_parser->handler_default; |
|
636 | + $this->state_parser->handler_object_escape = & $this->state_parser->handler_default; |
|
637 | 637 | $this->state_parser->handler_method_escape = $escape_method; |
638 | 638 | } |
639 | 639 | |
@@ -649,8 +649,8 @@ discard block |
||
649 | 649 | * @return void |
650 | 650 | * @see set_object |
651 | 651 | */ |
652 | - function set_jasp_handler ($jasp_method) { |
|
653 | - $this->state_parser->handler_object_jasp =& $this->state_parser->handler_default; |
|
652 | + function set_jasp_handler($jasp_method) { |
|
653 | + $this->state_parser->handler_object_jasp = & $this->state_parser->handler_default; |
|
654 | 654 | $this->state_parser->handler_method_jasp = $jasp_method; |
655 | 655 | } |
656 | 656 |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | function scanUntilString($string) { |
215 | 215 | $start = $this->position; |
216 | 216 | $this->position = strpos($this->rawtext, $string, $start); |
217 | - if ($this->position === FALSE) { |
|
217 | + if ($this->position === false) { |
|
218 | 218 | $this->position = $this->length; |
219 | 219 | } |
220 | 220 | return substr($this->rawtext, $start, $this->position - $start); |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | */ |
355 | 355 | function scanUntilCharacters($string) { |
356 | 356 | $startpos = $this->position; |
357 | - while ($this->position < $this->length && strpos($string, $this->rawtext{$this->position}) === FALSE) { |
|
357 | + while ($this->position < $this->length && strpos($string, $this->rawtext{$this->position}) === false) { |
|
358 | 358 | $this->position++; |
359 | 359 | } |
360 | 360 | return substr($this->rawtext, $startpos, $this->position - $startpos); |
@@ -367,7 +367,7 @@ discard block |
||
367 | 367 | */ |
368 | 368 | function ignoreWhitespace() { |
369 | 369 | while ($this->position < $this->length && |
370 | - strpos(" \n\r\t", $this->rawtext{$this->position}) !== FALSE) { |
|
370 | + strpos(" \n\r\t", $this->rawtext{$this->position}) !== false) { |
|
371 | 371 | $this->position++; |
372 | 372 | } |
373 | 373 | } |
@@ -48,6 +48,7 @@ discard block |
||
48 | 48 | * Constructs TSax3_Trim |
49 | 49 | * @param object handler object being decorated |
50 | 50 | * @param string original handler method |
51 | + * @param string $orig_method |
|
51 | 52 | * @access protected |
52 | 53 | */ |
53 | 54 | function __construct(&$orig_obj, $orig_method) { |
@@ -96,6 +97,8 @@ discard block |
||
96 | 97 | * @param object handler object being decorated |
97 | 98 | * @param string original open handler method |
98 | 99 | * @param string original close handler method |
100 | + * @param string $orig_open_method |
|
101 | + * @param string $orig_close_method |
|
99 | 102 | * @access protected |
100 | 103 | */ |
101 | 104 | function __construct(&$orig_obj, $orig_open_method, $orig_close_method) { |
@@ -146,6 +149,7 @@ discard block |
||
146 | 149 | * Constructs TSax3_LineFeed |
147 | 150 | * @param object handler object being decorated |
148 | 151 | * @param string original handler method |
152 | + * @param string $orig_method |
|
149 | 153 | * @access protected |
150 | 154 | */ |
151 | 155 | function __construct(&$orig_obj, $orig_method) { |
@@ -188,6 +192,7 @@ discard block |
||
188 | 192 | * Constructs TSax3_Tab |
189 | 193 | * @param object handler object being decorated |
190 | 194 | * @param string original handler method |
195 | + * @param string $orig_method |
|
191 | 196 | * @access protected |
192 | 197 | */ |
193 | 198 | function __construct(&$orig_obj, $orig_method) { |
@@ -231,6 +236,7 @@ discard block |
||
231 | 236 | * Constructs TSax3_Entities_Parsed |
232 | 237 | * @param object handler object being decorated |
233 | 238 | * @param string original handler method |
239 | + * @param string $orig_method |
|
234 | 240 | * @access protected |
235 | 241 | */ |
236 | 242 | function __construct(&$orig_obj, $orig_method) { |
@@ -255,6 +261,10 @@ discard block |
||
255 | 261 | * Compatibility with older PHP versions |
256 | 262 | */ |
257 | 263 | if (version_compare(phpversion(), '4.3', '<') && !function_exists('html_entity_decode') ) { |
264 | + |
|
265 | + /** |
|
266 | + * @param integer $style |
|
267 | + */ |
|
258 | 268 | function html_entity_decode($str, $style=ENT_NOQUOTES) { |
259 | 269 | return strtr($str, |
260 | 270 | array_flip(get_html_translation_table(HTML_ENTITIES,$style))); |
@@ -283,6 +293,7 @@ discard block |
||
283 | 293 | * Constructs TSax3_Entities_Unparsed |
284 | 294 | * @param object handler object being decorated |
285 | 295 | * @param string original handler method |
296 | + * @param string $orig_method |
|
286 | 297 | * @access protected |
287 | 298 | */ |
288 | 299 | function __construct(&$orig_obj, $orig_method) { |
@@ -326,6 +337,7 @@ discard block |
||
326 | 337 | * Constructs TSax3_Entities_Unparsed |
327 | 338 | * @param object handler object being decorated |
328 | 339 | * @param string original handler method |
340 | + * @param string $orig_method |
|
329 | 341 | * @access protected |
330 | 342 | */ |
331 | 343 | function __construct(&$orig_obj, $orig_method) { |
@@ -32,40 +32,40 @@ discard block |
||
32 | 32 | * @access protected |
33 | 33 | */ |
34 | 34 | class TSax3_Trim { |
35 | - /** |
|
36 | - * Original handler object |
|
37 | - * @var object |
|
38 | - * @access private |
|
39 | - */ |
|
40 | - private $orig_obj; |
|
41 | - /** |
|
42 | - * Original handler method |
|
43 | - * @var string |
|
44 | - * @access private |
|
45 | - */ |
|
46 | - private $orig_method; |
|
47 | - /** |
|
48 | - * Constructs TSax3_Trim |
|
49 | - * @param object handler object being decorated |
|
50 | - * @param string original handler method |
|
51 | - * @access protected |
|
52 | - */ |
|
53 | - function __construct(&$orig_obj, $orig_method) { |
|
54 | - $this->orig_obj =& $orig_obj; |
|
55 | - $this->orig_method = $orig_method; |
|
56 | - } |
|
57 | - /** |
|
58 | - * Trims the data |
|
59 | - * @param TSax3 |
|
60 | - * @param string element data |
|
61 | - * @access protected |
|
62 | - */ |
|
63 | - function trimData(&$parser, $data) { |
|
64 | - $data = trim($data); |
|
65 | - if ($data != '') { |
|
66 | - $this->orig_obj->{$this->orig_method}($parser, $data); |
|
67 | - } |
|
68 | - } |
|
35 | + /** |
|
36 | + * Original handler object |
|
37 | + * @var object |
|
38 | + * @access private |
|
39 | + */ |
|
40 | + private $orig_obj; |
|
41 | + /** |
|
42 | + * Original handler method |
|
43 | + * @var string |
|
44 | + * @access private |
|
45 | + */ |
|
46 | + private $orig_method; |
|
47 | + /** |
|
48 | + * Constructs TSax3_Trim |
|
49 | + * @param object handler object being decorated |
|
50 | + * @param string original handler method |
|
51 | + * @access protected |
|
52 | + */ |
|
53 | + function __construct(&$orig_obj, $orig_method) { |
|
54 | + $this->orig_obj =& $orig_obj; |
|
55 | + $this->orig_method = $orig_method; |
|
56 | + } |
|
57 | + /** |
|
58 | + * Trims the data |
|
59 | + * @param TSax3 |
|
60 | + * @param string element data |
|
61 | + * @access protected |
|
62 | + */ |
|
63 | + function trimData(&$parser, $data) { |
|
64 | + $data = trim($data); |
|
65 | + if ($data != '') { |
|
66 | + $this->orig_obj->{$this->orig_method}($parser, $data); |
|
67 | + } |
|
68 | + } |
|
69 | 69 | } |
70 | 70 | /** |
71 | 71 | * Coverts tag names to upper case |
@@ -73,55 +73,55 @@ discard block |
||
73 | 73 | * @access protected |
74 | 74 | */ |
75 | 75 | class TSax3_CaseFolding { |
76 | - /** |
|
77 | - * Original handler object |
|
78 | - * @var object |
|
79 | - * @access private |
|
80 | - */ |
|
81 | - private $orig_obj; |
|
82 | - /** |
|
83 | - * Original open handler method |
|
84 | - * @var string |
|
85 | - * @access private |
|
86 | - */ |
|
87 | - private $orig_open_method; |
|
88 | - /** |
|
89 | - * Original close handler method |
|
90 | - * @var string |
|
91 | - * @access private |
|
92 | - */ |
|
93 | - private $orig_close_method; |
|
94 | - /** |
|
95 | - * Constructs TSax3_CaseFolding |
|
96 | - * @param object handler object being decorated |
|
97 | - * @param string original open handler method |
|
98 | - * @param string original close handler method |
|
99 | - * @access protected |
|
100 | - */ |
|
101 | - function __construct(&$orig_obj, $orig_open_method, $orig_close_method) { |
|
102 | - $this->orig_obj =& $orig_obj; |
|
103 | - $this->orig_open_method = $orig_open_method; |
|
104 | - $this->orig_close_method = $orig_close_method; |
|
105 | - } |
|
106 | - /** |
|
107 | - * Folds up open tag callbacks |
|
108 | - * @param TSax3 |
|
109 | - * @param string tag name |
|
110 | - * @param array tag attributes |
|
111 | - * @access protected |
|
112 | - */ |
|
113 | - function foldOpen(&$parser, $tag, $attrs=array(), $empty = FALSE) { |
|
114 | - $this->orig_obj->{$this->orig_open_method}($parser, strtoupper($tag), $attrs, $empty); |
|
115 | - } |
|
116 | - /** |
|
117 | - * Folds up close tag callbacks |
|
118 | - * @param TSax3 |
|
119 | - * @param string tag name |
|
120 | - * @access protected |
|
121 | - */ |
|
122 | - function foldClose(&$parser, $tag, $empty = FALSE) { |
|
123 | - $this->orig_obj->{$this->orig_close_method}($parser, strtoupper($tag), $empty); |
|
124 | - } |
|
76 | + /** |
|
77 | + * Original handler object |
|
78 | + * @var object |
|
79 | + * @access private |
|
80 | + */ |
|
81 | + private $orig_obj; |
|
82 | + /** |
|
83 | + * Original open handler method |
|
84 | + * @var string |
|
85 | + * @access private |
|
86 | + */ |
|
87 | + private $orig_open_method; |
|
88 | + /** |
|
89 | + * Original close handler method |
|
90 | + * @var string |
|
91 | + * @access private |
|
92 | + */ |
|
93 | + private $orig_close_method; |
|
94 | + /** |
|
95 | + * Constructs TSax3_CaseFolding |
|
96 | + * @param object handler object being decorated |
|
97 | + * @param string original open handler method |
|
98 | + * @param string original close handler method |
|
99 | + * @access protected |
|
100 | + */ |
|
101 | + function __construct(&$orig_obj, $orig_open_method, $orig_close_method) { |
|
102 | + $this->orig_obj =& $orig_obj; |
|
103 | + $this->orig_open_method = $orig_open_method; |
|
104 | + $this->orig_close_method = $orig_close_method; |
|
105 | + } |
|
106 | + /** |
|
107 | + * Folds up open tag callbacks |
|
108 | + * @param TSax3 |
|
109 | + * @param string tag name |
|
110 | + * @param array tag attributes |
|
111 | + * @access protected |
|
112 | + */ |
|
113 | + function foldOpen(&$parser, $tag, $attrs=array(), $empty = FALSE) { |
|
114 | + $this->orig_obj->{$this->orig_open_method}($parser, strtoupper($tag), $attrs, $empty); |
|
115 | + } |
|
116 | + /** |
|
117 | + * Folds up close tag callbacks |
|
118 | + * @param TSax3 |
|
119 | + * @param string tag name |
|
120 | + * @access protected |
|
121 | + */ |
|
122 | + function foldClose(&$parser, $tag, $empty = FALSE) { |
|
123 | + $this->orig_obj->{$this->orig_close_method}($parser, strtoupper($tag), $empty); |
|
124 | + } |
|
125 | 125 | } |
126 | 126 | /** |
127 | 127 | * Breaks up data by linefeed characters, resulting in additional |
@@ -130,40 +130,40 @@ discard block |
||
130 | 130 | * @access protected |
131 | 131 | */ |
132 | 132 | class TSax3_Linefeed { |
133 | - /** |
|
134 | - * Original handler object |
|
135 | - * @var object |
|
136 | - * @access private |
|
137 | - */ |
|
138 | - private $orig_obj; |
|
139 | - /** |
|
140 | - * Original handler method |
|
141 | - * @var string |
|
142 | - * @access private |
|
143 | - */ |
|
144 | - private $orig_method; |
|
145 | - /** |
|
146 | - * Constructs TSax3_LineFeed |
|
147 | - * @param object handler object being decorated |
|
148 | - * @param string original handler method |
|
149 | - * @access protected |
|
150 | - */ |
|
151 | - function __construct(&$orig_obj, $orig_method) { |
|
152 | - $this->orig_obj =& $orig_obj; |
|
153 | - $this->orig_method = $orig_method; |
|
154 | - } |
|
155 | - /** |
|
156 | - * Breaks the data up by linefeeds |
|
157 | - * @param TSax3 |
|
158 | - * @param string element data |
|
159 | - * @access protected |
|
160 | - */ |
|
161 | - function breakData(&$parser, $data) { |
|
162 | - $data = explode("\n",$data); |
|
163 | - foreach ( $data as $chunk ) { |
|
164 | - $this->orig_obj->{$this->orig_method}($parser, $chunk); |
|
165 | - } |
|
166 | - } |
|
133 | + /** |
|
134 | + * Original handler object |
|
135 | + * @var object |
|
136 | + * @access private |
|
137 | + */ |
|
138 | + private $orig_obj; |
|
139 | + /** |
|
140 | + * Original handler method |
|
141 | + * @var string |
|
142 | + * @access private |
|
143 | + */ |
|
144 | + private $orig_method; |
|
145 | + /** |
|
146 | + * Constructs TSax3_LineFeed |
|
147 | + * @param object handler object being decorated |
|
148 | + * @param string original handler method |
|
149 | + * @access protected |
|
150 | + */ |
|
151 | + function __construct(&$orig_obj, $orig_method) { |
|
152 | + $this->orig_obj =& $orig_obj; |
|
153 | + $this->orig_method = $orig_method; |
|
154 | + } |
|
155 | + /** |
|
156 | + * Breaks the data up by linefeeds |
|
157 | + * @param TSax3 |
|
158 | + * @param string element data |
|
159 | + * @access protected |
|
160 | + */ |
|
161 | + function breakData(&$parser, $data) { |
|
162 | + $data = explode("\n",$data); |
|
163 | + foreach ( $data as $chunk ) { |
|
164 | + $this->orig_obj->{$this->orig_method}($parser, $chunk); |
|
165 | + } |
|
166 | + } |
|
167 | 167 | } |
168 | 168 | /** |
169 | 169 | * Breaks up data by tab characters, resulting in additional |
@@ -172,40 +172,40 @@ discard block |
||
172 | 172 | * @access protected |
173 | 173 | */ |
174 | 174 | class TSax3_Tab { |
175 | - /** |
|
176 | - * Original handler object |
|
177 | - * @var object |
|
178 | - * @access private |
|
179 | - */ |
|
180 | - private $orig_obj; |
|
181 | - /** |
|
182 | - * Original handler method |
|
183 | - * @var string |
|
184 | - * @access private |
|
185 | - */ |
|
186 | - private $orig_method; |
|
187 | - /** |
|
188 | - * Constructs TSax3_Tab |
|
189 | - * @param object handler object being decorated |
|
190 | - * @param string original handler method |
|
191 | - * @access protected |
|
192 | - */ |
|
193 | - function __construct(&$orig_obj, $orig_method) { |
|
194 | - $this->orig_obj =& $orig_obj; |
|
195 | - $this->orig_method = $orig_method; |
|
196 | - } |
|
197 | - /** |
|
198 | - * Breaks the data up by linefeeds |
|
199 | - * @param TSax3 |
|
200 | - * @param string element data |
|
201 | - * @access protected |
|
202 | - */ |
|
203 | - function breakData(&$parser, $data) { |
|
204 | - $data = explode("\t",$data); |
|
205 | - foreach ( $data as $chunk ) { |
|
206 | - $this->orig_obj->{$this->orig_method}($this, $chunk); |
|
207 | - } |
|
208 | - } |
|
175 | + /** |
|
176 | + * Original handler object |
|
177 | + * @var object |
|
178 | + * @access private |
|
179 | + */ |
|
180 | + private $orig_obj; |
|
181 | + /** |
|
182 | + * Original handler method |
|
183 | + * @var string |
|
184 | + * @access private |
|
185 | + */ |
|
186 | + private $orig_method; |
|
187 | + /** |
|
188 | + * Constructs TSax3_Tab |
|
189 | + * @param object handler object being decorated |
|
190 | + * @param string original handler method |
|
191 | + * @access protected |
|
192 | + */ |
|
193 | + function __construct(&$orig_obj, $orig_method) { |
|
194 | + $this->orig_obj =& $orig_obj; |
|
195 | + $this->orig_method = $orig_method; |
|
196 | + } |
|
197 | + /** |
|
198 | + * Breaks the data up by linefeeds |
|
199 | + * @param TSax3 |
|
200 | + * @param string element data |
|
201 | + * @access protected |
|
202 | + */ |
|
203 | + function breakData(&$parser, $data) { |
|
204 | + $data = explode("\t",$data); |
|
205 | + foreach ( $data as $chunk ) { |
|
206 | + $this->orig_obj->{$this->orig_method}($this, $chunk); |
|
207 | + } |
|
208 | + } |
|
209 | 209 | } |
210 | 210 | /** |
211 | 211 | * Breaks up data by XML entities and parses them with html_entity_decode(), |
@@ -215,50 +215,50 @@ discard block |
||
215 | 215 | * @access protected |
216 | 216 | */ |
217 | 217 | class TSax3_Entities_Parsed { |
218 | - /** |
|
219 | - * Original handler object |
|
220 | - * @var object |
|
221 | - * @access private |
|
222 | - */ |
|
223 | - private $orig_obj; |
|
224 | - /** |
|
225 | - * Original handler method |
|
226 | - * @var string |
|
227 | - * @access private |
|
228 | - */ |
|
229 | - private $orig_method; |
|
230 | - /** |
|
231 | - * Constructs TSax3_Entities_Parsed |
|
232 | - * @param object handler object being decorated |
|
233 | - * @param string original handler method |
|
234 | - * @access protected |
|
235 | - */ |
|
236 | - function __construct(&$orig_obj, $orig_method) { |
|
237 | - $this->orig_obj =& $orig_obj; |
|
238 | - $this->orig_method = $orig_method; |
|
239 | - } |
|
240 | - /** |
|
241 | - * Breaks the data up by XML entities |
|
242 | - * @param TSax3 |
|
243 | - * @param string element data |
|
244 | - * @access protected |
|
245 | - */ |
|
246 | - function breakData(&$parser, $data) { |
|
247 | - $data = preg_split('/(&.+?;)/',$data,-1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); |
|
248 | - foreach ( $data as $chunk ) { |
|
249 | - $chunk = html_entity_decode($chunk,ENT_NOQUOTES); |
|
250 | - $this->orig_obj->{$this->orig_method}($this, $chunk); |
|
251 | - } |
|
252 | - } |
|
218 | + /** |
|
219 | + * Original handler object |
|
220 | + * @var object |
|
221 | + * @access private |
|
222 | + */ |
|
223 | + private $orig_obj; |
|
224 | + /** |
|
225 | + * Original handler method |
|
226 | + * @var string |
|
227 | + * @access private |
|
228 | + */ |
|
229 | + private $orig_method; |
|
230 | + /** |
|
231 | + * Constructs TSax3_Entities_Parsed |
|
232 | + * @param object handler object being decorated |
|
233 | + * @param string original handler method |
|
234 | + * @access protected |
|
235 | + */ |
|
236 | + function __construct(&$orig_obj, $orig_method) { |
|
237 | + $this->orig_obj =& $orig_obj; |
|
238 | + $this->orig_method = $orig_method; |
|
239 | + } |
|
240 | + /** |
|
241 | + * Breaks the data up by XML entities |
|
242 | + * @param TSax3 |
|
243 | + * @param string element data |
|
244 | + * @access protected |
|
245 | + */ |
|
246 | + function breakData(&$parser, $data) { |
|
247 | + $data = preg_split('/(&.+?;)/',$data,-1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); |
|
248 | + foreach ( $data as $chunk ) { |
|
249 | + $chunk = html_entity_decode($chunk,ENT_NOQUOTES); |
|
250 | + $this->orig_obj->{$this->orig_method}($this, $chunk); |
|
251 | + } |
|
252 | + } |
|
253 | 253 | } |
254 | 254 | /** |
255 | 255 | * Compatibility with older PHP versions |
256 | 256 | */ |
257 | 257 | if (version_compare(phpversion(), '4.3', '<') && !function_exists('html_entity_decode') ) { |
258 | - function html_entity_decode($str, $style=ENT_NOQUOTES) { |
|
259 | - return strtr($str, |
|
260 | - array_flip(get_html_translation_table(HTML_ENTITIES,$style))); |
|
261 | - } |
|
258 | + function html_entity_decode($str, $style=ENT_NOQUOTES) { |
|
259 | + return strtr($str, |
|
260 | + array_flip(get_html_translation_table(HTML_ENTITIES,$style))); |
|
261 | + } |
|
262 | 262 | } |
263 | 263 | /** |
264 | 264 | * Breaks up data by XML entities but leaves them unparsed, |
@@ -267,40 +267,40 @@ discard block |
||
267 | 267 | * @access protected |
268 | 268 | */ |
269 | 269 | class TSax3_Entities_Unparsed { |
270 | - /** |
|
271 | - * Original handler object |
|
272 | - * @var object |
|
273 | - * @access private |
|
274 | - */ |
|
275 | - private $orig_obj; |
|
276 | - /** |
|
277 | - * Original handler method |
|
278 | - * @var string |
|
279 | - * @access private |
|
280 | - */ |
|
281 | - private $orig_method; |
|
282 | - /** |
|
283 | - * Constructs TSax3_Entities_Unparsed |
|
284 | - * @param object handler object being decorated |
|
285 | - * @param string original handler method |
|
286 | - * @access protected |
|
287 | - */ |
|
288 | - function __construct(&$orig_obj, $orig_method) { |
|
289 | - $this->orig_obj =& $orig_obj; |
|
290 | - $this->orig_method = $orig_method; |
|
291 | - } |
|
292 | - /** |
|
293 | - * Breaks the data up by XML entities |
|
294 | - * @param TSax3 |
|
295 | - * @param string element data |
|
296 | - * @access protected |
|
297 | - */ |
|
298 | - function breakData(&$parser, $data) { |
|
299 | - $data = preg_split('/(&.+?;)/',$data,-1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); |
|
300 | - foreach ( $data as $chunk ) { |
|
301 | - $this->orig_obj->{$this->orig_method}($this, $chunk); |
|
302 | - } |
|
303 | - } |
|
270 | + /** |
|
271 | + * Original handler object |
|
272 | + * @var object |
|
273 | + * @access private |
|
274 | + */ |
|
275 | + private $orig_obj; |
|
276 | + /** |
|
277 | + * Original handler method |
|
278 | + * @var string |
|
279 | + * @access private |
|
280 | + */ |
|
281 | + private $orig_method; |
|
282 | + /** |
|
283 | + * Constructs TSax3_Entities_Unparsed |
|
284 | + * @param object handler object being decorated |
|
285 | + * @param string original handler method |
|
286 | + * @access protected |
|
287 | + */ |
|
288 | + function __construct(&$orig_obj, $orig_method) { |
|
289 | + $this->orig_obj =& $orig_obj; |
|
290 | + $this->orig_method = $orig_method; |
|
291 | + } |
|
292 | + /** |
|
293 | + * Breaks the data up by XML entities |
|
294 | + * @param TSax3 |
|
295 | + * @param string element data |
|
296 | + * @access protected |
|
297 | + */ |
|
298 | + function breakData(&$parser, $data) { |
|
299 | + $data = preg_split('/(&.+?;)/',$data,-1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); |
|
300 | + foreach ( $data as $chunk ) { |
|
301 | + $this->orig_obj->{$this->orig_method}($this, $chunk); |
|
302 | + } |
|
303 | + } |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | /** |
@@ -310,52 +310,52 @@ discard block |
||
310 | 310 | * @access protected |
311 | 311 | */ |
312 | 312 | class TSax3_Escape_Stripper { |
313 | - /** |
|
314 | - * Original handler object |
|
315 | - * @var object |
|
316 | - * @access private |
|
317 | - */ |
|
318 | - private $orig_obj; |
|
319 | - /** |
|
320 | - * Original handler method |
|
321 | - * @var string |
|
322 | - * @access private |
|
323 | - */ |
|
324 | - private $orig_method; |
|
325 | - /** |
|
326 | - * Constructs TSax3_Entities_Unparsed |
|
327 | - * @param object handler object being decorated |
|
328 | - * @param string original handler method |
|
329 | - * @access protected |
|
330 | - */ |
|
331 | - function __construct(&$orig_obj, $orig_method) { |
|
332 | - $this->orig_obj =& $orig_obj; |
|
333 | - $this->orig_method = $orig_method; |
|
334 | - } |
|
335 | - /** |
|
336 | - * Breaks the data up by XML entities |
|
337 | - * @param TSax3 |
|
338 | - * @param string element data |
|
339 | - * @access protected |
|
340 | - */ |
|
341 | - function strip(&$parser, $data) { |
|
342 | - // Check for HTML comments first |
|
343 | - if ( substr($data,0,2) == '--' ) { |
|
344 | - $patterns = array( |
|
345 | - '/^\-\-/', // Opening comment: -- |
|
346 | - '/\-\-$/', // Closing comment: -- |
|
347 | - ); |
|
348 | - $data = preg_replace($patterns,'',$data); |
|
313 | + /** |
|
314 | + * Original handler object |
|
315 | + * @var object |
|
316 | + * @access private |
|
317 | + */ |
|
318 | + private $orig_obj; |
|
319 | + /** |
|
320 | + * Original handler method |
|
321 | + * @var string |
|
322 | + * @access private |
|
323 | + */ |
|
324 | + private $orig_method; |
|
325 | + /** |
|
326 | + * Constructs TSax3_Entities_Unparsed |
|
327 | + * @param object handler object being decorated |
|
328 | + * @param string original handler method |
|
329 | + * @access protected |
|
330 | + */ |
|
331 | + function __construct(&$orig_obj, $orig_method) { |
|
332 | + $this->orig_obj =& $orig_obj; |
|
333 | + $this->orig_method = $orig_method; |
|
334 | + } |
|
335 | + /** |
|
336 | + * Breaks the data up by XML entities |
|
337 | + * @param TSax3 |
|
338 | + * @param string element data |
|
339 | + * @access protected |
|
340 | + */ |
|
341 | + function strip(&$parser, $data) { |
|
342 | + // Check for HTML comments first |
|
343 | + if ( substr($data,0,2) == '--' ) { |
|
344 | + $patterns = array( |
|
345 | + '/^\-\-/', // Opening comment: -- |
|
346 | + '/\-\-$/', // Closing comment: -- |
|
347 | + ); |
|
348 | + $data = preg_replace($patterns,'',$data); |
|
349 | 349 | |
350 | - // Check for XML CDATA sections (note: don't do both!) |
|
351 | - } else if ( substr($data,0,1) == '[' ) { |
|
352 | - $patterns = array( |
|
353 | - '/^\[.*CDATA.*\[/s', // Opening CDATA |
|
354 | - '/\].*\]$/s', // Closing CDATA |
|
355 | - ); |
|
356 | - $data = preg_replace($patterns,'',$data); |
|
357 | - } |
|
350 | + // Check for XML CDATA sections (note: don't do both!) |
|
351 | + } else if ( substr($data,0,1) == '[' ) { |
|
352 | + $patterns = array( |
|
353 | + '/^\[.*CDATA.*\[/s', // Opening CDATA |
|
354 | + '/\].*\]$/s', // Closing CDATA |
|
355 | + ); |
|
356 | + $data = preg_replace($patterns,'',$data); |
|
357 | + } |
|
358 | 358 | |
359 | - $this->orig_obj->{$this->orig_method}($this, $data); |
|
360 | - } |
|
359 | + $this->orig_obj->{$this->orig_method}($this, $data); |
|
360 | + } |
|
361 | 361 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | * @access protected |
52 | 52 | */ |
53 | 53 | function __construct(&$orig_obj, $orig_method) { |
54 | - $this->orig_obj =& $orig_obj; |
|
54 | + $this->orig_obj = & $orig_obj; |
|
55 | 55 | $this->orig_method = $orig_method; |
56 | 56 | } |
57 | 57 | /** |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * @access protected |
100 | 100 | */ |
101 | 101 | function __construct(&$orig_obj, $orig_open_method, $orig_close_method) { |
102 | - $this->orig_obj =& $orig_obj; |
|
102 | + $this->orig_obj = & $orig_obj; |
|
103 | 103 | $this->orig_open_method = $orig_open_method; |
104 | 104 | $this->orig_close_method = $orig_close_method; |
105 | 105 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * @param array tag attributes |
111 | 111 | * @access protected |
112 | 112 | */ |
113 | - function foldOpen(&$parser, $tag, $attrs=array(), $empty = FALSE) { |
|
113 | + function foldOpen(&$parser, $tag, $attrs = array(), $empty = FALSE) { |
|
114 | 114 | $this->orig_obj->{$this->orig_open_method}($parser, strtoupper($tag), $attrs, $empty); |
115 | 115 | } |
116 | 116 | /** |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @access protected |
150 | 150 | */ |
151 | 151 | function __construct(&$orig_obj, $orig_method) { |
152 | - $this->orig_obj =& $orig_obj; |
|
152 | + $this->orig_obj = & $orig_obj; |
|
153 | 153 | $this->orig_method = $orig_method; |
154 | 154 | } |
155 | 155 | /** |
@@ -159,8 +159,8 @@ discard block |
||
159 | 159 | * @access protected |
160 | 160 | */ |
161 | 161 | function breakData(&$parser, $data) { |
162 | - $data = explode("\n",$data); |
|
163 | - foreach ( $data as $chunk ) { |
|
162 | + $data = explode("\n", $data); |
|
163 | + foreach ($data as $chunk) { |
|
164 | 164 | $this->orig_obj->{$this->orig_method}($parser, $chunk); |
165 | 165 | } |
166 | 166 | } |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | * @access protected |
192 | 192 | */ |
193 | 193 | function __construct(&$orig_obj, $orig_method) { |
194 | - $this->orig_obj =& $orig_obj; |
|
194 | + $this->orig_obj = & $orig_obj; |
|
195 | 195 | $this->orig_method = $orig_method; |
196 | 196 | } |
197 | 197 | /** |
@@ -201,8 +201,8 @@ discard block |
||
201 | 201 | * @access protected |
202 | 202 | */ |
203 | 203 | function breakData(&$parser, $data) { |
204 | - $data = explode("\t",$data); |
|
205 | - foreach ( $data as $chunk ) { |
|
204 | + $data = explode("\t", $data); |
|
205 | + foreach ($data as $chunk) { |
|
206 | 206 | $this->orig_obj->{$this->orig_method}($this, $chunk); |
207 | 207 | } |
208 | 208 | } |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | * @access protected |
235 | 235 | */ |
236 | 236 | function __construct(&$orig_obj, $orig_method) { |
237 | - $this->orig_obj =& $orig_obj; |
|
237 | + $this->orig_obj = & $orig_obj; |
|
238 | 238 | $this->orig_method = $orig_method; |
239 | 239 | } |
240 | 240 | /** |
@@ -244,9 +244,9 @@ discard block |
||
244 | 244 | * @access protected |
245 | 245 | */ |
246 | 246 | function breakData(&$parser, $data) { |
247 | - $data = preg_split('/(&.+?;)/',$data,-1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); |
|
248 | - foreach ( $data as $chunk ) { |
|
249 | - $chunk = html_entity_decode($chunk,ENT_NOQUOTES); |
|
247 | + $data = preg_split('/(&.+?;)/', $data, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); |
|
248 | + foreach ($data as $chunk) { |
|
249 | + $chunk = html_entity_decode($chunk, ENT_NOQUOTES); |
|
250 | 250 | $this->orig_obj->{$this->orig_method}($this, $chunk); |
251 | 251 | } |
252 | 252 | } |
@@ -254,10 +254,10 @@ discard block |
||
254 | 254 | /** |
255 | 255 | * Compatibility with older PHP versions |
256 | 256 | */ |
257 | -if (version_compare(phpversion(), '4.3', '<') && !function_exists('html_entity_decode') ) { |
|
258 | - function html_entity_decode($str, $style=ENT_NOQUOTES) { |
|
257 | +if (version_compare(phpversion(), '4.3', '<') && !function_exists('html_entity_decode')) { |
|
258 | + function html_entity_decode($str, $style = ENT_NOQUOTES) { |
|
259 | 259 | return strtr($str, |
260 | - array_flip(get_html_translation_table(HTML_ENTITIES,$style))); |
|
260 | + array_flip(get_html_translation_table(HTML_ENTITIES, $style))); |
|
261 | 261 | } |
262 | 262 | } |
263 | 263 | /** |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | * @access protected |
287 | 287 | */ |
288 | 288 | function __construct(&$orig_obj, $orig_method) { |
289 | - $this->orig_obj =& $orig_obj; |
|
289 | + $this->orig_obj = & $orig_obj; |
|
290 | 290 | $this->orig_method = $orig_method; |
291 | 291 | } |
292 | 292 | /** |
@@ -296,8 +296,8 @@ discard block |
||
296 | 296 | * @access protected |
297 | 297 | */ |
298 | 298 | function breakData(&$parser, $data) { |
299 | - $data = preg_split('/(&.+?;)/',$data,-1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); |
|
300 | - foreach ( $data as $chunk ) { |
|
299 | + $data = preg_split('/(&.+?;)/', $data, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); |
|
300 | + foreach ($data as $chunk) { |
|
301 | 301 | $this->orig_obj->{$this->orig_method}($this, $chunk); |
302 | 302 | } |
303 | 303 | } |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | * @access protected |
330 | 330 | */ |
331 | 331 | function __construct(&$orig_obj, $orig_method) { |
332 | - $this->orig_obj =& $orig_obj; |
|
332 | + $this->orig_obj = & $orig_obj; |
|
333 | 333 | $this->orig_method = $orig_method; |
334 | 334 | } |
335 | 335 | /** |
@@ -340,20 +340,20 @@ discard block |
||
340 | 340 | */ |
341 | 341 | function strip(&$parser, $data) { |
342 | 342 | // Check for HTML comments first |
343 | - if ( substr($data,0,2) == '--' ) { |
|
343 | + if (substr($data, 0, 2) == '--') { |
|
344 | 344 | $patterns = array( |
345 | - '/^\-\-/', // Opening comment: -- |
|
346 | - '/\-\-$/', // Closing comment: -- |
|
345 | + '/^\-\-/', // Opening comment: -- |
|
346 | + '/\-\-$/', // Closing comment: -- |
|
347 | 347 | ); |
348 | - $data = preg_replace($patterns,'',$data); |
|
348 | + $data = preg_replace($patterns, '', $data); |
|
349 | 349 | |
350 | 350 | // Check for XML CDATA sections (note: don't do both!) |
351 | - } else if ( substr($data,0,1) == '[' ) { |
|
351 | + } else if (substr($data, 0, 1) == '[') { |
|
352 | 352 | $patterns = array( |
353 | 353 | '/^\[.*CDATA.*\[/s', // Opening CDATA |
354 | - '/\].*\]$/s', // Closing CDATA |
|
354 | + '/\].*\]$/s', // Closing CDATA |
|
355 | 355 | ); |
356 | - $data = preg_replace($patterns,'',$data); |
|
356 | + $data = preg_replace($patterns, '', $data); |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | $this->orig_obj->{$this->orig_method}($this, $data); |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * @param array tag attributes |
111 | 111 | * @access protected |
112 | 112 | */ |
113 | - function foldOpen(&$parser, $tag, $attrs=array(), $empty = FALSE) { |
|
113 | + function foldOpen(&$parser, $tag, $attrs=array(), $empty = false) { |
|
114 | 114 | $this->orig_obj->{$this->orig_open_method}($parser, strtoupper($tag), $attrs, $empty); |
115 | 115 | } |
116 | 116 | /** |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * @param string tag name |
120 | 120 | * @access protected |
121 | 121 | */ |
122 | - function foldClose(&$parser, $tag, $empty = FALSE) { |
|
122 | + function foldClose(&$parser, $tag, $empty = false) { |
|
123 | 123 | $this->orig_obj->{$this->orig_close_method}($parser, strtoupper($tag), $empty); |
124 | 124 | } |
125 | 125 | } |
@@ -480,7 +480,7 @@ |
||
480 | 480 | /** |
481 | 481 | * Closing tag handler - called from HTMLSax |
482 | 482 | * |
483 | - * @param object $parsers HTML parser |
|
483 | + * @param object $parser HTML parser |
|
484 | 484 | * @param string $name tag name |
485 | 485 | * @return boolean |
486 | 486 | * @access private |
@@ -57,622 +57,622 @@ |
||
57 | 57 | */ |
58 | 58 | class TSafeHtmlParser |
59 | 59 | { |
60 | - /** |
|
61 | - * Storage for resulting HTML output |
|
62 | - * |
|
63 | - * @var string |
|
64 | - * @access private |
|
65 | - */ |
|
66 | - private $_xhtml = ''; |
|
67 | - |
|
68 | - /** |
|
69 | - * Array of counters for each tag |
|
70 | - * |
|
71 | - * @var array |
|
72 | - * @access private |
|
73 | - */ |
|
74 | - private $_counter = array(); |
|
75 | - |
|
76 | - /** |
|
77 | - * Stack of unclosed tags |
|
78 | - * |
|
79 | - * @var array |
|
80 | - * @access private |
|
81 | - */ |
|
82 | - private $_stack = array(); |
|
83 | - |
|
84 | - /** |
|
85 | - * Array of counters for tags that must be deleted with all content |
|
86 | - * |
|
87 | - * @var array |
|
88 | - * @access private |
|
89 | - */ |
|
90 | - private $_dcCounter = array(); |
|
91 | - |
|
92 | - /** |
|
93 | - * Stack of unclosed tags that must be deleted with all content |
|
94 | - * |
|
95 | - * @var array |
|
96 | - * @access private |
|
97 | - */ |
|
98 | - private $_dcStack = array(); |
|
99 | - |
|
100 | - /** |
|
101 | - * Stores level of list (ol/ul) nesting |
|
102 | - * |
|
103 | - * @var int |
|
104 | - * @access private |
|
105 | - */ |
|
106 | - private $_listScope = 0; |
|
107 | - |
|
108 | - /** |
|
109 | - * Stack of unclosed list tags |
|
110 | - * |
|
111 | - * @var array |
|
112 | - * @access private |
|
113 | - */ |
|
114 | - private $_liStack = array(); |
|
115 | - |
|
116 | - /** |
|
117 | - * Array of prepared regular expressions for protocols (schemas) matching |
|
118 | - * |
|
119 | - * @var array |
|
120 | - * @access private |
|
121 | - */ |
|
122 | - private $_protoRegexps = array(); |
|
123 | - |
|
124 | - /** |
|
125 | - * Array of prepared regular expressions for CSS matching |
|
126 | - * |
|
127 | - * @var array |
|
128 | - * @access private |
|
129 | - */ |
|
130 | - private $_cssRegexps = array(); |
|
131 | - |
|
132 | - /** |
|
133 | - * List of single tags ("<tag />") |
|
134 | - * |
|
135 | - * @var array |
|
136 | - * @access public |
|
137 | - */ |
|
138 | - public $singleTags = array('area', 'br', 'img', 'input', 'hr', 'wbr', ); |
|
139 | - |
|
140 | - /** |
|
141 | - * List of dangerous tags (such tags will be deleted) |
|
142 | - * |
|
143 | - * @var array |
|
144 | - * @access public |
|
145 | - */ |
|
146 | - public $deleteTags = array( |
|
147 | - 'applet', 'base', 'basefont', 'bgsound', 'blink', 'body', |
|
148 | - 'embed', 'frame', 'frameset', 'head', 'html', 'ilayer', |
|
149 | - 'iframe', 'layer', 'link', 'meta', 'object', 'style', |
|
150 | - 'title', 'script', |
|
151 | - ); |
|
152 | - |
|
153 | - /** |
|
154 | - * List of dangerous tags (such tags will be deleted, and all content |
|
155 | - * inside this tags will be also removed) |
|
156 | - * |
|
157 | - * @var array |
|
158 | - * @access public |
|
159 | - */ |
|
160 | - public $deleteTagsContent = array('script', 'style', 'title', 'xml', ); |
|
161 | - |
|
162 | - /** |
|
163 | - * Type of protocols filtering ('white' or 'black') |
|
164 | - * |
|
165 | - * @var string |
|
166 | - * @access public |
|
167 | - */ |
|
168 | - public $protocolFiltering = 'white'; |
|
169 | - |
|
170 | - /** |
|
171 | - * List of "dangerous" protocols (used for blacklist-filtering) |
|
172 | - * |
|
173 | - * @var array |
|
174 | - * @access public |
|
175 | - */ |
|
176 | - public $blackProtocols = array( |
|
177 | - 'about', 'chrome', 'data', 'disk', 'hcp', |
|
178 | - 'help', 'javascript', 'livescript', 'lynxcgi', 'lynxexec', |
|
179 | - 'ms-help', 'ms-its', 'mhtml', 'mocha', 'opera', |
|
180 | - 'res', 'resource', 'shell', 'vbscript', 'view-source', |
|
181 | - 'vnd.ms.radio', 'wysiwyg', |
|
182 | - ); |
|
183 | - |
|
184 | - /** |
|
185 | - * List of "safe" protocols (used for whitelist-filtering) |
|
186 | - * |
|
187 | - * @var array |
|
188 | - * @access public |
|
189 | - */ |
|
190 | - public $whiteProtocols = array( |
|
191 | - 'ed2k', 'file', 'ftp', 'gopher', 'http', 'https', |
|
192 | - 'irc', 'mailto', 'news', 'nntp', 'telnet', 'webcal', |
|
193 | - 'xmpp', 'callto', |
|
194 | - ); |
|
195 | - |
|
196 | - /** |
|
197 | - * List of attributes that can contain protocols |
|
198 | - * |
|
199 | - * @var array |
|
200 | - * @access public |
|
201 | - */ |
|
202 | - public $protocolAttributes = array( |
|
203 | - 'action', 'background', 'codebase', 'dynsrc', 'href', 'lowsrc', 'src', |
|
204 | - ); |
|
205 | - |
|
206 | - /** |
|
207 | - * List of dangerous CSS keywords |
|
208 | - * |
|
209 | - * Whole style="" attribute will be removed, if parser will find one of |
|
210 | - * these keywords |
|
211 | - * |
|
212 | - * @var array |
|
213 | - * @access public |
|
214 | - */ |
|
215 | - public $cssKeywords = array( |
|
216 | - 'absolute', 'behavior', 'behaviour', 'content', 'expression', |
|
217 | - 'fixed', 'include-source', 'moz-binding', |
|
218 | - ); |
|
219 | - |
|
220 | - /** |
|
221 | - * List of tags that can have no "closing tag" |
|
222 | - * |
|
223 | - * @var array |
|
224 | - * @access public |
|
225 | - * @deprecated XHTML does not allow such tags |
|
226 | - */ |
|
227 | - public $noClose = array(); |
|
228 | - |
|
229 | - /** |
|
230 | - * List of block-level tags that terminates paragraph |
|
231 | - * |
|
232 | - * Paragraph will be closed when this tags opened |
|
233 | - * |
|
234 | - * @var array |
|
235 | - * @access public |
|
236 | - */ |
|
237 | - public $closeParagraph = array( |
|
238 | - 'address', 'blockquote', 'center', 'dd', 'dir', 'div', |
|
239 | - 'dl', 'dt', 'h1', 'h2', 'h3', 'h4', |
|
240 | - 'h5', 'h6', 'hr', 'isindex', 'listing', 'marquee', |
|
241 | - 'menu', 'multicol', 'ol', 'p', 'plaintext', 'pre', |
|
242 | - 'table', 'ul', 'xmp', |
|
243 | - ); |
|
244 | - |
|
245 | - /** |
|
246 | - * List of table tags, all table tags outside a table will be removed |
|
247 | - * |
|
248 | - * @var array |
|
249 | - * @access public |
|
250 | - */ |
|
251 | - public $tableTags = array( |
|
252 | - 'caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th', |
|
253 | - 'thead', 'tr', |
|
254 | - ); |
|
255 | - |
|
256 | - /** |
|
257 | - * List of list tags |
|
258 | - * |
|
259 | - * @var array |
|
260 | - * @access public |
|
261 | - */ |
|
262 | - public $listTags = array('dir', 'menu', 'ol', 'ul', 'dl', ); |
|
263 | - |
|
264 | - /** |
|
265 | - * List of dangerous attributes |
|
266 | - * |
|
267 | - * @var array |
|
268 | - * @access public |
|
269 | - */ |
|
270 | - public $attributes = array('dynsrc'); |
|
271 | - //public $attributes = array('dynsrc', 'id', 'name', ); //id and name are dangerous? |
|
272 | - |
|
273 | - /** |
|
274 | - * List of allowed "namespaced" attributes |
|
275 | - * |
|
276 | - * @var array |
|
277 | - * @access public |
|
278 | - */ |
|
279 | - public $attributesNS = array('xml:lang', ); |
|
280 | - |
|
281 | - /** |
|
282 | - * Constructs class |
|
283 | - * |
|
284 | - * @access public |
|
285 | - */ |
|
286 | - public function __construct() |
|
287 | - { |
|
288 | - //making regular expressions based on Proto & CSS arrays |
|
289 | - foreach ($this->blackProtocols as $proto) { |
|
290 | - $preg = "/[\s\x01-\x1F]*"; |
|
291 | - for ($i=0; $i<strlen($proto); $i++) { |
|
292 | - $preg .= $proto{$i} . "[\s\x01-\x1F]*"; |
|
293 | - } |
|
294 | - $preg .= ":/i"; |
|
295 | - $this->_protoRegexps[] = $preg; |
|
296 | - } |
|
297 | - |
|
298 | - foreach ($this->cssKeywords as $css) { |
|
299 | - $this->_cssRegexps[] = '/' . $css . '/i'; |
|
300 | - } |
|
301 | - return true; |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * Handles the writing of attributes - called from $this->_openHandler() |
|
306 | - * |
|
307 | - * @param array $attrs array of attributes $name => $value |
|
308 | - * @return boolean |
|
309 | - * @access private |
|
310 | - */ |
|
311 | - private function _writeAttrs ($attrs) |
|
312 | - { |
|
313 | - if (is_array($attrs)) { |
|
314 | - foreach ($attrs as $name => $value) { |
|
315 | - |
|
316 | - $name = strtolower($name); |
|
317 | - |
|
318 | - if (strpos($name, 'on') === 0) { |
|
319 | - continue; |
|
320 | - } |
|
321 | - if (strpos($name, 'data') === 0) { |
|
322 | - continue; |
|
323 | - } |
|
324 | - if (in_array($name, $this->attributes)) { |
|
325 | - continue; |
|
326 | - } |
|
327 | - if (!preg_match("/^[a-z0-9]+$/i", $name)) { |
|
328 | - if (!in_array($name, $this->attributesNS)) |
|
329 | - { |
|
330 | - continue; |
|
331 | - } |
|
332 | - } |
|
333 | - |
|
334 | - if (($value === TRUE) || (is_null($value))) { |
|
335 | - $value = $name; |
|
336 | - } |
|
337 | - |
|
338 | - if ($name == 'style') { |
|
339 | - |
|
340 | - // removes insignificant backslahes |
|
341 | - $value = str_replace("\\", '', $value); |
|
342 | - |
|
343 | - // removes CSS comments |
|
344 | - while (1) |
|
345 | - { |
|
346 | - $_value = preg_replace("!/\*.*?\*/!s", '', $value); |
|
347 | - if ($_value == $value) break; |
|
348 | - $value = $_value; |
|
349 | - } |
|
350 | - |
|
351 | - // replace all & to & |
|
352 | - $value = str_replace('&', '&', $value); |
|
353 | - $value = str_replace('&', '&', $value); |
|
354 | - |
|
355 | - foreach ($this->_cssRegexps as $css) { |
|
356 | - if (preg_match($css, $value)) { |
|
357 | - continue 2; |
|
358 | - } |
|
359 | - } |
|
360 | - foreach ($this->_protoRegexps as $proto) { |
|
361 | - if (preg_match($proto, $value)) { |
|
362 | - continue 2; |
|
363 | - } |
|
364 | - } |
|
365 | - } |
|
366 | - |
|
367 | - $tempval = preg_replace_callback( |
|
368 | - '/&#(\d+);?/m', |
|
369 | - function ($matches) { |
|
370 | - return chr($matches[0]); |
|
371 | - }, |
|
372 | - $value |
|
373 | - ); //"' |
|
374 | - |
|
375 | - $tempval = preg_replace_callback( |
|
376 | - '/&#x([0-9a-f]+);?/mi', |
|
377 | - function ($matches) { |
|
378 | - return chr(hexdec($matches[0])); |
|
379 | - }, |
|
380 | - $tempval |
|
381 | - ); |
|
382 | - |
|
383 | - if ((in_array($name, $this->protocolAttributes)) && |
|
384 | - (strpos($tempval, ':') !== false)) |
|
385 | - { |
|
386 | - if ($this->protocolFiltering == 'black') { |
|
387 | - foreach ($this->_protoRegexps as $proto) { |
|
388 | - if (preg_match($proto, $tempval)) continue 2; |
|
389 | - } |
|
390 | - } else { |
|
391 | - $_tempval = explode(':', $tempval); |
|
392 | - $proto = $_tempval[0]; |
|
393 | - if (!in_array($proto, $this->whiteProtocols)) { |
|
394 | - continue; |
|
395 | - } |
|
396 | - } |
|
397 | - } |
|
398 | - |
|
399 | - $value = str_replace("\"", """, $value); |
|
400 | - $this->_xhtml .= ' ' . $name . '="' . $value . '"'; |
|
401 | - } |
|
402 | - } |
|
403 | - return true; |
|
404 | - } |
|
405 | - |
|
406 | - /** |
|
407 | - * Opening tag handler - called from HTMLSax |
|
408 | - * |
|
409 | - * @param object $parser HTML Parser |
|
410 | - * @param string $name tag name |
|
411 | - * @param array $attrs tag attributes |
|
412 | - * @return boolean |
|
413 | - * @access private |
|
414 | - */ |
|
415 | - public function _openHandler(&$parser, $name, $attrs) |
|
416 | - { |
|
417 | - $name = strtolower($name); |
|
418 | - |
|
419 | - if (in_array($name, $this->deleteTagsContent)) { |
|
420 | - array_push($this->_dcStack, $name); |
|
421 | - $this->_dcCounter[$name] = isset($this->_dcCounter[$name]) ? $this->_dcCounter[$name]+1 : 1; |
|
422 | - } |
|
423 | - if (count($this->_dcStack) != 0) { |
|
424 | - return true; |
|
425 | - } |
|
426 | - |
|
427 | - if (in_array($name, $this->deleteTags)) { |
|
428 | - return true; |
|
429 | - } |
|
430 | - |
|
431 | - if (!preg_match("/^[a-z0-9]+$/i", $name)) { |
|
432 | - if (preg_match("!(?:\@|://)!i", $name)) { |
|
433 | - $this->_xhtml .= '<' . $name . '>'; |
|
434 | - } |
|
435 | - return true; |
|
436 | - } |
|
437 | - |
|
438 | - if (in_array($name, $this->singleTags)) { |
|
439 | - $this->_xhtml .= '<' . $name; |
|
440 | - $this->_writeAttrs($attrs); |
|
441 | - $this->_xhtml .= ' />'; |
|
442 | - return true; |
|
443 | - } |
|
444 | - |
|
445 | - // TABLES: cannot open table elements when we are not inside table |
|
446 | - if ((isset($this->_counter['table'])) && ($this->_counter['table'] <= 0) |
|
447 | - && (in_array($name, $this->tableTags))) |
|
448 | - { |
|
449 | - return true; |
|
450 | - } |
|
451 | - |
|
452 | - // PARAGRAPHS: close paragraph when closeParagraph tags opening |
|
453 | - if ((in_array($name, $this->closeParagraph)) && (in_array('p', $this->_stack))) { |
|
454 | - $this->_closeHandler($parser, 'p'); |
|
455 | - } |
|
456 | - |
|
457 | - // LISTS: we should close <li> if <li> of the same level opening |
|
458 | - if ($name == 'li' && count($this->_liStack) && |
|
459 | - $this->_listScope == $this->_liStack[count($this->_liStack)-1]) |
|
460 | - { |
|
461 | - $this->_closeHandler($parser, 'li'); |
|
462 | - } |
|
463 | - |
|
464 | - // LISTS: we want to know on what nesting level of lists we are |
|
465 | - if (in_array($name, $this->listTags)) { |
|
466 | - $this->_listScope++; |
|
467 | - } |
|
468 | - if ($name == 'li') { |
|
469 | - array_push($this->_liStack, $this->_listScope); |
|
470 | - } |
|
471 | - |
|
472 | - $this->_xhtml .= '<' . $name; |
|
473 | - $this->_writeAttrs($attrs); |
|
474 | - $this->_xhtml .= '>'; |
|
475 | - array_push($this->_stack,$name); |
|
476 | - $this->_counter[$name] = isset($this->_counter[$name]) ? $this->_counter[$name]+1 : 1; |
|
477 | - return true; |
|
478 | - } |
|
479 | - |
|
480 | - /** |
|
481 | - * Closing tag handler - called from HTMLSax |
|
482 | - * |
|
483 | - * @param object $parsers HTML parser |
|
484 | - * @param string $name tag name |
|
485 | - * @return boolean |
|
486 | - * @access private |
|
487 | - */ |
|
488 | - public function _closeHandler(&$parser, $name) |
|
489 | - { |
|
490 | - |
|
491 | - $name = strtolower($name); |
|
492 | - |
|
493 | - if (isset($this->_dcCounter[$name]) && ($this->_dcCounter[$name] > 0) && |
|
494 | - (in_array($name, $this->deleteTagsContent))) |
|
495 | - { |
|
496 | - while ($name != ($tag = array_pop($this->_dcStack))) { |
|
497 | - $this->_dcCounter[$tag]--; |
|
498 | - } |
|
499 | - |
|
500 | - $this->_dcCounter[$name]--; |
|
501 | - } |
|
502 | - |
|
503 | - if (count($this->_dcStack) != 0) { |
|
504 | - return true; |
|
505 | - } |
|
506 | - |
|
507 | - if ((isset($this->_counter[$name])) && ($this->_counter[$name] > 0)) { |
|
508 | - while ($name != ($tag = array_pop($this->_stack))) { |
|
509 | - $this->_closeTag($tag); |
|
510 | - } |
|
511 | - |
|
512 | - $this->_closeTag($name); |
|
513 | - } |
|
514 | - return true; |
|
515 | - } |
|
516 | - |
|
517 | - /** |
|
518 | - * Closes tag |
|
519 | - * |
|
520 | - * @param string $tag tag name |
|
521 | - * @return boolean |
|
522 | - * @access private |
|
523 | - */ |
|
524 | - public function _closeTag($tag) |
|
525 | - { |
|
526 | - if (!in_array($tag, $this->noClose)) { |
|
527 | - $this->_xhtml .= '</' . $tag . '>'; |
|
528 | - } |
|
529 | - |
|
530 | - $this->_counter[$tag]--; |
|
531 | - |
|
532 | - if (in_array($tag, $this->listTags)) { |
|
533 | - $this->_listScope--; |
|
534 | - } |
|
535 | - |
|
536 | - if ($tag == 'li') { |
|
537 | - array_pop($this->_liStack); |
|
538 | - } |
|
539 | - return true; |
|
540 | - } |
|
541 | - |
|
542 | - /** |
|
543 | - * Character data handler - called from HTMLSax |
|
544 | - * |
|
545 | - * @param object $parser HTML parser |
|
546 | - * @param string $data textual data |
|
547 | - * @return boolean |
|
548 | - * @access private |
|
549 | - */ |
|
550 | - public function _dataHandler(&$parser, $data) |
|
551 | - { |
|
552 | - if (count($this->_dcStack) == 0) { |
|
553 | - $this->_xhtml .= $data; |
|
554 | - } |
|
555 | - return true; |
|
556 | - } |
|
557 | - |
|
558 | - /** |
|
559 | - * Escape handler - called from HTMLSax |
|
560 | - * |
|
561 | - * @param object $parser HTML parser |
|
562 | - * @param string $data comments or other type of data |
|
563 | - * @return boolean |
|
564 | - * @access private |
|
565 | - */ |
|
566 | - public function _escapeHandler(&$parser, $data) |
|
567 | - { |
|
568 | - return true; |
|
569 | - } |
|
570 | - |
|
571 | - /** |
|
572 | - * Returns the XHTML document |
|
573 | - * |
|
574 | - * @return string Processed (X)HTML document |
|
575 | - * @access public |
|
576 | - */ |
|
577 | - public function getXHTML () |
|
578 | - { |
|
579 | - while ($tag = array_pop($this->_stack)) { |
|
580 | - $this->_closeTag($tag); |
|
581 | - } |
|
582 | - |
|
583 | - return $this->_xhtml; |
|
584 | - } |
|
585 | - |
|
586 | - /** |
|
587 | - * Clears current document data |
|
588 | - * |
|
589 | - * @return boolean |
|
590 | - * @access public |
|
591 | - */ |
|
592 | - public function clear() |
|
593 | - { |
|
594 | - $this->_xhtml = ''; |
|
595 | - return true; |
|
596 | - } |
|
597 | - |
|
598 | - /** |
|
599 | - * Main parsing fuction |
|
600 | - * |
|
601 | - * @param string $doc HTML document for processing |
|
602 | - * @return string Processed (X)HTML document |
|
603 | - * @access public |
|
604 | - */ |
|
605 | - public function parse($doc, $isUTF7=false) |
|
606 | - { |
|
60 | + /** |
|
61 | + * Storage for resulting HTML output |
|
62 | + * |
|
63 | + * @var string |
|
64 | + * @access private |
|
65 | + */ |
|
66 | + private $_xhtml = ''; |
|
67 | + |
|
68 | + /** |
|
69 | + * Array of counters for each tag |
|
70 | + * |
|
71 | + * @var array |
|
72 | + * @access private |
|
73 | + */ |
|
74 | + private $_counter = array(); |
|
75 | + |
|
76 | + /** |
|
77 | + * Stack of unclosed tags |
|
78 | + * |
|
79 | + * @var array |
|
80 | + * @access private |
|
81 | + */ |
|
82 | + private $_stack = array(); |
|
83 | + |
|
84 | + /** |
|
85 | + * Array of counters for tags that must be deleted with all content |
|
86 | + * |
|
87 | + * @var array |
|
88 | + * @access private |
|
89 | + */ |
|
90 | + private $_dcCounter = array(); |
|
91 | + |
|
92 | + /** |
|
93 | + * Stack of unclosed tags that must be deleted with all content |
|
94 | + * |
|
95 | + * @var array |
|
96 | + * @access private |
|
97 | + */ |
|
98 | + private $_dcStack = array(); |
|
99 | + |
|
100 | + /** |
|
101 | + * Stores level of list (ol/ul) nesting |
|
102 | + * |
|
103 | + * @var int |
|
104 | + * @access private |
|
105 | + */ |
|
106 | + private $_listScope = 0; |
|
107 | + |
|
108 | + /** |
|
109 | + * Stack of unclosed list tags |
|
110 | + * |
|
111 | + * @var array |
|
112 | + * @access private |
|
113 | + */ |
|
114 | + private $_liStack = array(); |
|
115 | + |
|
116 | + /** |
|
117 | + * Array of prepared regular expressions for protocols (schemas) matching |
|
118 | + * |
|
119 | + * @var array |
|
120 | + * @access private |
|
121 | + */ |
|
122 | + private $_protoRegexps = array(); |
|
123 | + |
|
124 | + /** |
|
125 | + * Array of prepared regular expressions for CSS matching |
|
126 | + * |
|
127 | + * @var array |
|
128 | + * @access private |
|
129 | + */ |
|
130 | + private $_cssRegexps = array(); |
|
131 | + |
|
132 | + /** |
|
133 | + * List of single tags ("<tag />") |
|
134 | + * |
|
135 | + * @var array |
|
136 | + * @access public |
|
137 | + */ |
|
138 | + public $singleTags = array('area', 'br', 'img', 'input', 'hr', 'wbr', ); |
|
139 | + |
|
140 | + /** |
|
141 | + * List of dangerous tags (such tags will be deleted) |
|
142 | + * |
|
143 | + * @var array |
|
144 | + * @access public |
|
145 | + */ |
|
146 | + public $deleteTags = array( |
|
147 | + 'applet', 'base', 'basefont', 'bgsound', 'blink', 'body', |
|
148 | + 'embed', 'frame', 'frameset', 'head', 'html', 'ilayer', |
|
149 | + 'iframe', 'layer', 'link', 'meta', 'object', 'style', |
|
150 | + 'title', 'script', |
|
151 | + ); |
|
152 | + |
|
153 | + /** |
|
154 | + * List of dangerous tags (such tags will be deleted, and all content |
|
155 | + * inside this tags will be also removed) |
|
156 | + * |
|
157 | + * @var array |
|
158 | + * @access public |
|
159 | + */ |
|
160 | + public $deleteTagsContent = array('script', 'style', 'title', 'xml', ); |
|
161 | + |
|
162 | + /** |
|
163 | + * Type of protocols filtering ('white' or 'black') |
|
164 | + * |
|
165 | + * @var string |
|
166 | + * @access public |
|
167 | + */ |
|
168 | + public $protocolFiltering = 'white'; |
|
169 | + |
|
170 | + /** |
|
171 | + * List of "dangerous" protocols (used for blacklist-filtering) |
|
172 | + * |
|
173 | + * @var array |
|
174 | + * @access public |
|
175 | + */ |
|
176 | + public $blackProtocols = array( |
|
177 | + 'about', 'chrome', 'data', 'disk', 'hcp', |
|
178 | + 'help', 'javascript', 'livescript', 'lynxcgi', 'lynxexec', |
|
179 | + 'ms-help', 'ms-its', 'mhtml', 'mocha', 'opera', |
|
180 | + 'res', 'resource', 'shell', 'vbscript', 'view-source', |
|
181 | + 'vnd.ms.radio', 'wysiwyg', |
|
182 | + ); |
|
183 | + |
|
184 | + /** |
|
185 | + * List of "safe" protocols (used for whitelist-filtering) |
|
186 | + * |
|
187 | + * @var array |
|
188 | + * @access public |
|
189 | + */ |
|
190 | + public $whiteProtocols = array( |
|
191 | + 'ed2k', 'file', 'ftp', 'gopher', 'http', 'https', |
|
192 | + 'irc', 'mailto', 'news', 'nntp', 'telnet', 'webcal', |
|
193 | + 'xmpp', 'callto', |
|
194 | + ); |
|
195 | + |
|
196 | + /** |
|
197 | + * List of attributes that can contain protocols |
|
198 | + * |
|
199 | + * @var array |
|
200 | + * @access public |
|
201 | + */ |
|
202 | + public $protocolAttributes = array( |
|
203 | + 'action', 'background', 'codebase', 'dynsrc', 'href', 'lowsrc', 'src', |
|
204 | + ); |
|
205 | + |
|
206 | + /** |
|
207 | + * List of dangerous CSS keywords |
|
208 | + * |
|
209 | + * Whole style="" attribute will be removed, if parser will find one of |
|
210 | + * these keywords |
|
211 | + * |
|
212 | + * @var array |
|
213 | + * @access public |
|
214 | + */ |
|
215 | + public $cssKeywords = array( |
|
216 | + 'absolute', 'behavior', 'behaviour', 'content', 'expression', |
|
217 | + 'fixed', 'include-source', 'moz-binding', |
|
218 | + ); |
|
219 | + |
|
220 | + /** |
|
221 | + * List of tags that can have no "closing tag" |
|
222 | + * |
|
223 | + * @var array |
|
224 | + * @access public |
|
225 | + * @deprecated XHTML does not allow such tags |
|
226 | + */ |
|
227 | + public $noClose = array(); |
|
228 | + |
|
229 | + /** |
|
230 | + * List of block-level tags that terminates paragraph |
|
231 | + * |
|
232 | + * Paragraph will be closed when this tags opened |
|
233 | + * |
|
234 | + * @var array |
|
235 | + * @access public |
|
236 | + */ |
|
237 | + public $closeParagraph = array( |
|
238 | + 'address', 'blockquote', 'center', 'dd', 'dir', 'div', |
|
239 | + 'dl', 'dt', 'h1', 'h2', 'h3', 'h4', |
|
240 | + 'h5', 'h6', 'hr', 'isindex', 'listing', 'marquee', |
|
241 | + 'menu', 'multicol', 'ol', 'p', 'plaintext', 'pre', |
|
242 | + 'table', 'ul', 'xmp', |
|
243 | + ); |
|
244 | + |
|
245 | + /** |
|
246 | + * List of table tags, all table tags outside a table will be removed |
|
247 | + * |
|
248 | + * @var array |
|
249 | + * @access public |
|
250 | + */ |
|
251 | + public $tableTags = array( |
|
252 | + 'caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th', |
|
253 | + 'thead', 'tr', |
|
254 | + ); |
|
255 | + |
|
256 | + /** |
|
257 | + * List of list tags |
|
258 | + * |
|
259 | + * @var array |
|
260 | + * @access public |
|
261 | + */ |
|
262 | + public $listTags = array('dir', 'menu', 'ol', 'ul', 'dl', ); |
|
263 | + |
|
264 | + /** |
|
265 | + * List of dangerous attributes |
|
266 | + * |
|
267 | + * @var array |
|
268 | + * @access public |
|
269 | + */ |
|
270 | + public $attributes = array('dynsrc'); |
|
271 | + //public $attributes = array('dynsrc', 'id', 'name', ); //id and name are dangerous? |
|
272 | + |
|
273 | + /** |
|
274 | + * List of allowed "namespaced" attributes |
|
275 | + * |
|
276 | + * @var array |
|
277 | + * @access public |
|
278 | + */ |
|
279 | + public $attributesNS = array('xml:lang', ); |
|
280 | + |
|
281 | + /** |
|
282 | + * Constructs class |
|
283 | + * |
|
284 | + * @access public |
|
285 | + */ |
|
286 | + public function __construct() |
|
287 | + { |
|
288 | + //making regular expressions based on Proto & CSS arrays |
|
289 | + foreach ($this->blackProtocols as $proto) { |
|
290 | + $preg = "/[\s\x01-\x1F]*"; |
|
291 | + for ($i=0; $i<strlen($proto); $i++) { |
|
292 | + $preg .= $proto{$i} . "[\s\x01-\x1F]*"; |
|
293 | + } |
|
294 | + $preg .= ":/i"; |
|
295 | + $this->_protoRegexps[] = $preg; |
|
296 | + } |
|
297 | + |
|
298 | + foreach ($this->cssKeywords as $css) { |
|
299 | + $this->_cssRegexps[] = '/' . $css . '/i'; |
|
300 | + } |
|
301 | + return true; |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * Handles the writing of attributes - called from $this->_openHandler() |
|
306 | + * |
|
307 | + * @param array $attrs array of attributes $name => $value |
|
308 | + * @return boolean |
|
309 | + * @access private |
|
310 | + */ |
|
311 | + private function _writeAttrs ($attrs) |
|
312 | + { |
|
313 | + if (is_array($attrs)) { |
|
314 | + foreach ($attrs as $name => $value) { |
|
315 | + |
|
316 | + $name = strtolower($name); |
|
317 | + |
|
318 | + if (strpos($name, 'on') === 0) { |
|
319 | + continue; |
|
320 | + } |
|
321 | + if (strpos($name, 'data') === 0) { |
|
322 | + continue; |
|
323 | + } |
|
324 | + if (in_array($name, $this->attributes)) { |
|
325 | + continue; |
|
326 | + } |
|
327 | + if (!preg_match("/^[a-z0-9]+$/i", $name)) { |
|
328 | + if (!in_array($name, $this->attributesNS)) |
|
329 | + { |
|
330 | + continue; |
|
331 | + } |
|
332 | + } |
|
333 | + |
|
334 | + if (($value === TRUE) || (is_null($value))) { |
|
335 | + $value = $name; |
|
336 | + } |
|
337 | + |
|
338 | + if ($name == 'style') { |
|
339 | + |
|
340 | + // removes insignificant backslahes |
|
341 | + $value = str_replace("\\", '', $value); |
|
342 | + |
|
343 | + // removes CSS comments |
|
344 | + while (1) |
|
345 | + { |
|
346 | + $_value = preg_replace("!/\*.*?\*/!s", '', $value); |
|
347 | + if ($_value == $value) break; |
|
348 | + $value = $_value; |
|
349 | + } |
|
350 | + |
|
351 | + // replace all & to & |
|
352 | + $value = str_replace('&', '&', $value); |
|
353 | + $value = str_replace('&', '&', $value); |
|
354 | + |
|
355 | + foreach ($this->_cssRegexps as $css) { |
|
356 | + if (preg_match($css, $value)) { |
|
357 | + continue 2; |
|
358 | + } |
|
359 | + } |
|
360 | + foreach ($this->_protoRegexps as $proto) { |
|
361 | + if (preg_match($proto, $value)) { |
|
362 | + continue 2; |
|
363 | + } |
|
364 | + } |
|
365 | + } |
|
366 | + |
|
367 | + $tempval = preg_replace_callback( |
|
368 | + '/&#(\d+);?/m', |
|
369 | + function ($matches) { |
|
370 | + return chr($matches[0]); |
|
371 | + }, |
|
372 | + $value |
|
373 | + ); //"' |
|
374 | + |
|
375 | + $tempval = preg_replace_callback( |
|
376 | + '/&#x([0-9a-f]+);?/mi', |
|
377 | + function ($matches) { |
|
378 | + return chr(hexdec($matches[0])); |
|
379 | + }, |
|
380 | + $tempval |
|
381 | + ); |
|
382 | + |
|
383 | + if ((in_array($name, $this->protocolAttributes)) && |
|
384 | + (strpos($tempval, ':') !== false)) |
|
385 | + { |
|
386 | + if ($this->protocolFiltering == 'black') { |
|
387 | + foreach ($this->_protoRegexps as $proto) { |
|
388 | + if (preg_match($proto, $tempval)) continue 2; |
|
389 | + } |
|
390 | + } else { |
|
391 | + $_tempval = explode(':', $tempval); |
|
392 | + $proto = $_tempval[0]; |
|
393 | + if (!in_array($proto, $this->whiteProtocols)) { |
|
394 | + continue; |
|
395 | + } |
|
396 | + } |
|
397 | + } |
|
398 | + |
|
399 | + $value = str_replace("\"", """, $value); |
|
400 | + $this->_xhtml .= ' ' . $name . '="' . $value . '"'; |
|
401 | + } |
|
402 | + } |
|
403 | + return true; |
|
404 | + } |
|
405 | + |
|
406 | + /** |
|
407 | + * Opening tag handler - called from HTMLSax |
|
408 | + * |
|
409 | + * @param object $parser HTML Parser |
|
410 | + * @param string $name tag name |
|
411 | + * @param array $attrs tag attributes |
|
412 | + * @return boolean |
|
413 | + * @access private |
|
414 | + */ |
|
415 | + public function _openHandler(&$parser, $name, $attrs) |
|
416 | + { |
|
417 | + $name = strtolower($name); |
|
418 | + |
|
419 | + if (in_array($name, $this->deleteTagsContent)) { |
|
420 | + array_push($this->_dcStack, $name); |
|
421 | + $this->_dcCounter[$name] = isset($this->_dcCounter[$name]) ? $this->_dcCounter[$name]+1 : 1; |
|
422 | + } |
|
423 | + if (count($this->_dcStack) != 0) { |
|
424 | + return true; |
|
425 | + } |
|
426 | + |
|
427 | + if (in_array($name, $this->deleteTags)) { |
|
428 | + return true; |
|
429 | + } |
|
430 | + |
|
431 | + if (!preg_match("/^[a-z0-9]+$/i", $name)) { |
|
432 | + if (preg_match("!(?:\@|://)!i", $name)) { |
|
433 | + $this->_xhtml .= '<' . $name . '>'; |
|
434 | + } |
|
435 | + return true; |
|
436 | + } |
|
437 | + |
|
438 | + if (in_array($name, $this->singleTags)) { |
|
439 | + $this->_xhtml .= '<' . $name; |
|
440 | + $this->_writeAttrs($attrs); |
|
441 | + $this->_xhtml .= ' />'; |
|
442 | + return true; |
|
443 | + } |
|
444 | + |
|
445 | + // TABLES: cannot open table elements when we are not inside table |
|
446 | + if ((isset($this->_counter['table'])) && ($this->_counter['table'] <= 0) |
|
447 | + && (in_array($name, $this->tableTags))) |
|
448 | + { |
|
449 | + return true; |
|
450 | + } |
|
451 | + |
|
452 | + // PARAGRAPHS: close paragraph when closeParagraph tags opening |
|
453 | + if ((in_array($name, $this->closeParagraph)) && (in_array('p', $this->_stack))) { |
|
454 | + $this->_closeHandler($parser, 'p'); |
|
455 | + } |
|
456 | + |
|
457 | + // LISTS: we should close <li> if <li> of the same level opening |
|
458 | + if ($name == 'li' && count($this->_liStack) && |
|
459 | + $this->_listScope == $this->_liStack[count($this->_liStack)-1]) |
|
460 | + { |
|
461 | + $this->_closeHandler($parser, 'li'); |
|
462 | + } |
|
463 | + |
|
464 | + // LISTS: we want to know on what nesting level of lists we are |
|
465 | + if (in_array($name, $this->listTags)) { |
|
466 | + $this->_listScope++; |
|
467 | + } |
|
468 | + if ($name == 'li') { |
|
469 | + array_push($this->_liStack, $this->_listScope); |
|
470 | + } |
|
471 | + |
|
472 | + $this->_xhtml .= '<' . $name; |
|
473 | + $this->_writeAttrs($attrs); |
|
474 | + $this->_xhtml .= '>'; |
|
475 | + array_push($this->_stack,$name); |
|
476 | + $this->_counter[$name] = isset($this->_counter[$name]) ? $this->_counter[$name]+1 : 1; |
|
477 | + return true; |
|
478 | + } |
|
479 | + |
|
480 | + /** |
|
481 | + * Closing tag handler - called from HTMLSax |
|
482 | + * |
|
483 | + * @param object $parsers HTML parser |
|
484 | + * @param string $name tag name |
|
485 | + * @return boolean |
|
486 | + * @access private |
|
487 | + */ |
|
488 | + public function _closeHandler(&$parser, $name) |
|
489 | + { |
|
490 | + |
|
491 | + $name = strtolower($name); |
|
492 | + |
|
493 | + if (isset($this->_dcCounter[$name]) && ($this->_dcCounter[$name] > 0) && |
|
494 | + (in_array($name, $this->deleteTagsContent))) |
|
495 | + { |
|
496 | + while ($name != ($tag = array_pop($this->_dcStack))) { |
|
497 | + $this->_dcCounter[$tag]--; |
|
498 | + } |
|
499 | + |
|
500 | + $this->_dcCounter[$name]--; |
|
501 | + } |
|
502 | + |
|
503 | + if (count($this->_dcStack) != 0) { |
|
504 | + return true; |
|
505 | + } |
|
506 | + |
|
507 | + if ((isset($this->_counter[$name])) && ($this->_counter[$name] > 0)) { |
|
508 | + while ($name != ($tag = array_pop($this->_stack))) { |
|
509 | + $this->_closeTag($tag); |
|
510 | + } |
|
511 | + |
|
512 | + $this->_closeTag($name); |
|
513 | + } |
|
514 | + return true; |
|
515 | + } |
|
516 | + |
|
517 | + /** |
|
518 | + * Closes tag |
|
519 | + * |
|
520 | + * @param string $tag tag name |
|
521 | + * @return boolean |
|
522 | + * @access private |
|
523 | + */ |
|
524 | + public function _closeTag($tag) |
|
525 | + { |
|
526 | + if (!in_array($tag, $this->noClose)) { |
|
527 | + $this->_xhtml .= '</' . $tag . '>'; |
|
528 | + } |
|
529 | + |
|
530 | + $this->_counter[$tag]--; |
|
531 | + |
|
532 | + if (in_array($tag, $this->listTags)) { |
|
533 | + $this->_listScope--; |
|
534 | + } |
|
535 | + |
|
536 | + if ($tag == 'li') { |
|
537 | + array_pop($this->_liStack); |
|
538 | + } |
|
539 | + return true; |
|
540 | + } |
|
541 | + |
|
542 | + /** |
|
543 | + * Character data handler - called from HTMLSax |
|
544 | + * |
|
545 | + * @param object $parser HTML parser |
|
546 | + * @param string $data textual data |
|
547 | + * @return boolean |
|
548 | + * @access private |
|
549 | + */ |
|
550 | + public function _dataHandler(&$parser, $data) |
|
551 | + { |
|
552 | + if (count($this->_dcStack) == 0) { |
|
553 | + $this->_xhtml .= $data; |
|
554 | + } |
|
555 | + return true; |
|
556 | + } |
|
557 | + |
|
558 | + /** |
|
559 | + * Escape handler - called from HTMLSax |
|
560 | + * |
|
561 | + * @param object $parser HTML parser |
|
562 | + * @param string $data comments or other type of data |
|
563 | + * @return boolean |
|
564 | + * @access private |
|
565 | + */ |
|
566 | + public function _escapeHandler(&$parser, $data) |
|
567 | + { |
|
568 | + return true; |
|
569 | + } |
|
570 | + |
|
571 | + /** |
|
572 | + * Returns the XHTML document |
|
573 | + * |
|
574 | + * @return string Processed (X)HTML document |
|
575 | + * @access public |
|
576 | + */ |
|
577 | + public function getXHTML () |
|
578 | + { |
|
579 | + while ($tag = array_pop($this->_stack)) { |
|
580 | + $this->_closeTag($tag); |
|
581 | + } |
|
582 | + |
|
583 | + return $this->_xhtml; |
|
584 | + } |
|
585 | + |
|
586 | + /** |
|
587 | + * Clears current document data |
|
588 | + * |
|
589 | + * @return boolean |
|
590 | + * @access public |
|
591 | + */ |
|
592 | + public function clear() |
|
593 | + { |
|
594 | + $this->_xhtml = ''; |
|
595 | + return true; |
|
596 | + } |
|
597 | + |
|
598 | + /** |
|
599 | + * Main parsing fuction |
|
600 | + * |
|
601 | + * @param string $doc HTML document for processing |
|
602 | + * @return string Processed (X)HTML document |
|
603 | + * @access public |
|
604 | + */ |
|
605 | + public function parse($doc, $isUTF7=false) |
|
606 | + { |
|
607 | 607 | $this->clear(); |
608 | 608 | |
609 | - // Save all '<' symbols |
|
610 | - $doc = preg_replace("/<(?=[^a-zA-Z\/\!\?\%])/", '<', (string)$doc); |
|
611 | - |
|
612 | - // Web documents shouldn't contains \x00 symbol |
|
613 | - $doc = str_replace("\x00", '', $doc); |
|
614 | - |
|
615 | - // Opera6 bug workaround |
|
616 | - $doc = str_replace("\xC0\xBC", '<', $doc); |
|
617 | - |
|
618 | - // UTF-7 encoding ASCII decode |
|
619 | - if($isUTF7) |
|
620 | - $doc = $this->repackUTF7($doc); |
|
621 | - |
|
622 | - // Instantiate the parser |
|
623 | - $parser= new TSax3(); |
|
624 | - |
|
625 | - // Set up the parser |
|
626 | - $parser->set_object($this); |
|
627 | - |
|
628 | - $parser->set_element_handler('_openHandler','_closeHandler'); |
|
629 | - $parser->set_data_handler('_dataHandler'); |
|
630 | - $parser->set_escape_handler('_escapeHandler'); |
|
631 | - |
|
632 | - $parser->parse($doc); |
|
633 | - |
|
634 | - return $this->getXHTML(); |
|
635 | - |
|
636 | - } |
|
637 | - |
|
638 | - |
|
639 | - /** |
|
640 | - * UTF-7 decoding fuction |
|
641 | - * |
|
642 | - * @param string $str HTML document for recode ASCII part of UTF-7 back to ASCII |
|
643 | - * @return string Decoded document |
|
644 | - * @access private |
|
645 | - */ |
|
646 | - private function repackUTF7($str) |
|
647 | - { |
|
648 | - return preg_replace_callback('!\+([0-9a-zA-Z/]+)\-!', array($this, 'repackUTF7Callback'), $str); |
|
649 | - } |
|
650 | - |
|
651 | - /** |
|
652 | - * Additional UTF-7 decoding fuction |
|
653 | - * |
|
654 | - * @param string $str String for recode ASCII part of UTF-7 back to ASCII |
|
655 | - * @return string Recoded string |
|
656 | - * @access private |
|
657 | - */ |
|
658 | - private function repackUTF7Callback($str) |
|
659 | - { |
|
660 | - $str = base64_decode($str[1]); |
|
661 | - $str = preg_replace_callback('/^((?:\x00.)*)((?:[^\x00].)+)/', array($this, 'repackUTF7Back'), $str); |
|
662 | - return preg_replace('/\x00(.)/', '$1', $str); |
|
663 | - } |
|
664 | - |
|
665 | - /** |
|
666 | - * Additional UTF-7 encoding fuction |
|
667 | - * |
|
668 | - * @param string $str String for recode ASCII part of UTF-7 back to ASCII |
|
669 | - * @return string Recoded string |
|
670 | - * @access private |
|
671 | - */ |
|
672 | - private function repackUTF7Back($str) |
|
673 | - { |
|
674 | - return $str[1].'+'.rtrim(base64_encode($str[2]), '=').'-'; |
|
675 | - } |
|
609 | + // Save all '<' symbols |
|
610 | + $doc = preg_replace("/<(?=[^a-zA-Z\/\!\?\%])/", '<', (string)$doc); |
|
611 | + |
|
612 | + // Web documents shouldn't contains \x00 symbol |
|
613 | + $doc = str_replace("\x00", '', $doc); |
|
614 | + |
|
615 | + // Opera6 bug workaround |
|
616 | + $doc = str_replace("\xC0\xBC", '<', $doc); |
|
617 | + |
|
618 | + // UTF-7 encoding ASCII decode |
|
619 | + if($isUTF7) |
|
620 | + $doc = $this->repackUTF7($doc); |
|
621 | + |
|
622 | + // Instantiate the parser |
|
623 | + $parser= new TSax3(); |
|
624 | + |
|
625 | + // Set up the parser |
|
626 | + $parser->set_object($this); |
|
627 | + |
|
628 | + $parser->set_element_handler('_openHandler','_closeHandler'); |
|
629 | + $parser->set_data_handler('_dataHandler'); |
|
630 | + $parser->set_escape_handler('_escapeHandler'); |
|
631 | + |
|
632 | + $parser->parse($doc); |
|
633 | + |
|
634 | + return $this->getXHTML(); |
|
635 | + |
|
636 | + } |
|
637 | + |
|
638 | + |
|
639 | + /** |
|
640 | + * UTF-7 decoding fuction |
|
641 | + * |
|
642 | + * @param string $str HTML document for recode ASCII part of UTF-7 back to ASCII |
|
643 | + * @return string Decoded document |
|
644 | + * @access private |
|
645 | + */ |
|
646 | + private function repackUTF7($str) |
|
647 | + { |
|
648 | + return preg_replace_callback('!\+([0-9a-zA-Z/]+)\-!', array($this, 'repackUTF7Callback'), $str); |
|
649 | + } |
|
650 | + |
|
651 | + /** |
|
652 | + * Additional UTF-7 decoding fuction |
|
653 | + * |
|
654 | + * @param string $str String for recode ASCII part of UTF-7 back to ASCII |
|
655 | + * @return string Recoded string |
|
656 | + * @access private |
|
657 | + */ |
|
658 | + private function repackUTF7Callback($str) |
|
659 | + { |
|
660 | + $str = base64_decode($str[1]); |
|
661 | + $str = preg_replace_callback('/^((?:\x00.)*)((?:[^\x00].)+)/', array($this, 'repackUTF7Back'), $str); |
|
662 | + return preg_replace('/\x00(.)/', '$1', $str); |
|
663 | + } |
|
664 | + |
|
665 | + /** |
|
666 | + * Additional UTF-7 encoding fuction |
|
667 | + * |
|
668 | + * @param string $str String for recode ASCII part of UTF-7 back to ASCII |
|
669 | + * @return string Recoded string |
|
670 | + * @access private |
|
671 | + */ |
|
672 | + private function repackUTF7Back($str) |
|
673 | + { |
|
674 | + return $str[1].'+'.rtrim(base64_encode($str[2]), '=').'-'; |
|
675 | + } |
|
676 | 676 | } |
677 | 677 | |
678 | 678 | /* |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | * @var array |
136 | 136 | * @access public |
137 | 137 | */ |
138 | - public $singleTags = array('area', 'br', 'img', 'input', 'hr', 'wbr', ); |
|
138 | + public $singleTags = array('area', 'br', 'img', 'input', 'hr', 'wbr',); |
|
139 | 139 | |
140 | 140 | /** |
141 | 141 | * List of dangerous tags (such tags will be deleted) |
@@ -144,10 +144,10 @@ discard block |
||
144 | 144 | * @access public |
145 | 145 | */ |
146 | 146 | public $deleteTags = array( |
147 | - 'applet', 'base', 'basefont', 'bgsound', 'blink', 'body', |
|
148 | - 'embed', 'frame', 'frameset', 'head', 'html', 'ilayer', |
|
149 | - 'iframe', 'layer', 'link', 'meta', 'object', 'style', |
|
150 | - 'title', 'script', |
|
147 | + 'applet', 'base', 'basefont', 'bgsound', 'blink', 'body', |
|
148 | + 'embed', 'frame', 'frameset', 'head', 'html', 'ilayer', |
|
149 | + 'iframe', 'layer', 'link', 'meta', 'object', 'style', |
|
150 | + 'title', 'script', |
|
151 | 151 | ); |
152 | 152 | |
153 | 153 | /** |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | * @var array |
158 | 158 | * @access public |
159 | 159 | */ |
160 | - public $deleteTagsContent = array('script', 'style', 'title', 'xml', ); |
|
160 | + public $deleteTagsContent = array('script', 'style', 'title', 'xml',); |
|
161 | 161 | |
162 | 162 | /** |
163 | 163 | * Type of protocols filtering ('white' or 'black') |
@@ -174,11 +174,11 @@ discard block |
||
174 | 174 | * @access public |
175 | 175 | */ |
176 | 176 | public $blackProtocols = array( |
177 | - 'about', 'chrome', 'data', 'disk', 'hcp', |
|
178 | - 'help', 'javascript', 'livescript', 'lynxcgi', 'lynxexec', |
|
179 | - 'ms-help', 'ms-its', 'mhtml', 'mocha', 'opera', |
|
180 | - 'res', 'resource', 'shell', 'vbscript', 'view-source', |
|
181 | - 'vnd.ms.radio', 'wysiwyg', |
|
177 | + 'about', 'chrome', 'data', 'disk', 'hcp', |
|
178 | + 'help', 'javascript', 'livescript', 'lynxcgi', 'lynxexec', |
|
179 | + 'ms-help', 'ms-its', 'mhtml', 'mocha', 'opera', |
|
180 | + 'res', 'resource', 'shell', 'vbscript', 'view-source', |
|
181 | + 'vnd.ms.radio', 'wysiwyg', |
|
182 | 182 | ); |
183 | 183 | |
184 | 184 | /** |
@@ -188,9 +188,9 @@ discard block |
||
188 | 188 | * @access public |
189 | 189 | */ |
190 | 190 | public $whiteProtocols = array( |
191 | - 'ed2k', 'file', 'ftp', 'gopher', 'http', 'https', |
|
192 | - 'irc', 'mailto', 'news', 'nntp', 'telnet', 'webcal', |
|
193 | - 'xmpp', 'callto', |
|
191 | + 'ed2k', 'file', 'ftp', 'gopher', 'http', 'https', |
|
192 | + 'irc', 'mailto', 'news', 'nntp', 'telnet', 'webcal', |
|
193 | + 'xmpp', 'callto', |
|
194 | 194 | ); |
195 | 195 | |
196 | 196 | /** |
@@ -213,8 +213,8 @@ discard block |
||
213 | 213 | * @access public |
214 | 214 | */ |
215 | 215 | public $cssKeywords = array( |
216 | - 'absolute', 'behavior', 'behaviour', 'content', 'expression', |
|
217 | - 'fixed', 'include-source', 'moz-binding', |
|
216 | + 'absolute', 'behavior', 'behaviour', 'content', 'expression', |
|
217 | + 'fixed', 'include-source', 'moz-binding', |
|
218 | 218 | ); |
219 | 219 | |
220 | 220 | /** |
@@ -235,11 +235,11 @@ discard block |
||
235 | 235 | * @access public |
236 | 236 | */ |
237 | 237 | public $closeParagraph = array( |
238 | - 'address', 'blockquote', 'center', 'dd', 'dir', 'div', |
|
239 | - 'dl', 'dt', 'h1', 'h2', 'h3', 'h4', |
|
240 | - 'h5', 'h6', 'hr', 'isindex', 'listing', 'marquee', |
|
241 | - 'menu', 'multicol', 'ol', 'p', 'plaintext', 'pre', |
|
242 | - 'table', 'ul', 'xmp', |
|
238 | + 'address', 'blockquote', 'center', 'dd', 'dir', 'div', |
|
239 | + 'dl', 'dt', 'h1', 'h2', 'h3', 'h4', |
|
240 | + 'h5', 'h6', 'hr', 'isindex', 'listing', 'marquee', |
|
241 | + 'menu', 'multicol', 'ol', 'p', 'plaintext', 'pre', |
|
242 | + 'table', 'ul', 'xmp', |
|
243 | 243 | ); |
244 | 244 | |
245 | 245 | /** |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | */ |
251 | 251 | public $tableTags = array( |
252 | 252 | 'caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th', |
253 | - 'thead', 'tr', |
|
253 | + 'thead', 'tr', |
|
254 | 254 | ); |
255 | 255 | |
256 | 256 | /** |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | * @var array |
260 | 260 | * @access public |
261 | 261 | */ |
262 | - public $listTags = array('dir', 'menu', 'ol', 'ul', 'dl', ); |
|
262 | + public $listTags = array('dir', 'menu', 'ol', 'ul', 'dl',); |
|
263 | 263 | |
264 | 264 | /** |
265 | 265 | * List of dangerous attributes |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | * @var array |
277 | 277 | * @access public |
278 | 278 | */ |
279 | - public $attributesNS = array('xml:lang', ); |
|
279 | + public $attributesNS = array('xml:lang',); |
|
280 | 280 | |
281 | 281 | /** |
282 | 282 | * Constructs class |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | //making regular expressions based on Proto & CSS arrays |
289 | 289 | foreach ($this->blackProtocols as $proto) { |
290 | 290 | $preg = "/[\s\x01-\x1F]*"; |
291 | - for ($i=0; $i<strlen($proto); $i++) { |
|
291 | + for ($i = 0; $i < strlen($proto); $i++) { |
|
292 | 292 | $preg .= $proto{$i} . "[\s\x01-\x1F]*"; |
293 | 293 | } |
294 | 294 | $preg .= ":/i"; |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | * @return boolean |
309 | 309 | * @access private |
310 | 310 | */ |
311 | - private function _writeAttrs ($attrs) |
|
311 | + private function _writeAttrs($attrs) |
|
312 | 312 | { |
313 | 313 | if (is_array($attrs)) { |
314 | 314 | foreach ($attrs as $name => $value) { |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | |
367 | 367 | $tempval = preg_replace_callback( |
368 | 368 | '/&#(\d+);?/m', |
369 | - function ($matches) { |
|
369 | + function($matches) { |
|
370 | 370 | return chr($matches[0]); |
371 | 371 | }, |
372 | 372 | $value |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | |
375 | 375 | $tempval = preg_replace_callback( |
376 | 376 | '/&#x([0-9a-f]+);?/mi', |
377 | - function ($matches) { |
|
377 | + function($matches) { |
|
378 | 378 | return chr(hexdec($matches[0])); |
379 | 379 | }, |
380 | 380 | $tempval |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | |
419 | 419 | if (in_array($name, $this->deleteTagsContent)) { |
420 | 420 | array_push($this->_dcStack, $name); |
421 | - $this->_dcCounter[$name] = isset($this->_dcCounter[$name]) ? $this->_dcCounter[$name]+1 : 1; |
|
421 | + $this->_dcCounter[$name] = isset($this->_dcCounter[$name]) ? $this->_dcCounter[$name] + 1 : 1; |
|
422 | 422 | } |
423 | 423 | if (count($this->_dcStack) != 0) { |
424 | 424 | return true; |
@@ -456,7 +456,7 @@ discard block |
||
456 | 456 | |
457 | 457 | // LISTS: we should close <li> if <li> of the same level opening |
458 | 458 | if ($name == 'li' && count($this->_liStack) && |
459 | - $this->_listScope == $this->_liStack[count($this->_liStack)-1]) |
|
459 | + $this->_listScope == $this->_liStack[count($this->_liStack) - 1]) |
|
460 | 460 | { |
461 | 461 | $this->_closeHandler($parser, 'li'); |
462 | 462 | } |
@@ -472,8 +472,8 @@ discard block |
||
472 | 472 | $this->_xhtml .= '<' . $name; |
473 | 473 | $this->_writeAttrs($attrs); |
474 | 474 | $this->_xhtml .= '>'; |
475 | - array_push($this->_stack,$name); |
|
476 | - $this->_counter[$name] = isset($this->_counter[$name]) ? $this->_counter[$name]+1 : 1; |
|
475 | + array_push($this->_stack, $name); |
|
476 | + $this->_counter[$name] = isset($this->_counter[$name]) ? $this->_counter[$name] + 1 : 1; |
|
477 | 477 | return true; |
478 | 478 | } |
479 | 479 | |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | * @return string Processed (X)HTML document |
575 | 575 | * @access public |
576 | 576 | */ |
577 | - public function getXHTML () |
|
577 | + public function getXHTML() |
|
578 | 578 | { |
579 | 579 | while ($tag = array_pop($this->_stack)) { |
580 | 580 | $this->_closeTag($tag); |
@@ -602,12 +602,12 @@ discard block |
||
602 | 602 | * @return string Processed (X)HTML document |
603 | 603 | * @access public |
604 | 604 | */ |
605 | - public function parse($doc, $isUTF7=false) |
|
605 | + public function parse($doc, $isUTF7 = false) |
|
606 | 606 | { |
607 | 607 | $this->clear(); |
608 | 608 | |
609 | 609 | // Save all '<' symbols |
610 | - $doc = preg_replace("/<(?=[^a-zA-Z\/\!\?\%])/", '<', (string)$doc); |
|
610 | + $doc = preg_replace("/<(?=[^a-zA-Z\/\!\?\%])/", '<', (string) $doc); |
|
611 | 611 | |
612 | 612 | // Web documents shouldn't contains \x00 symbol |
613 | 613 | $doc = str_replace("\x00", '', $doc); |
@@ -616,16 +616,16 @@ discard block |
||
616 | 616 | $doc = str_replace("\xC0\xBC", '<', $doc); |
617 | 617 | |
618 | 618 | // UTF-7 encoding ASCII decode |
619 | - if($isUTF7) |
|
619 | + if ($isUTF7) |
|
620 | 620 | $doc = $this->repackUTF7($doc); |
621 | 621 | |
622 | 622 | // Instantiate the parser |
623 | - $parser= new TSax3(); |
|
623 | + $parser = new TSax3(); |
|
624 | 624 | |
625 | 625 | // Set up the parser |
626 | 626 | $parser->set_object($this); |
627 | 627 | |
628 | - $parser->set_element_handler('_openHandler','_closeHandler'); |
|
628 | + $parser->set_element_handler('_openHandler', '_closeHandler'); |
|
629 | 629 | $parser->set_data_handler('_dataHandler'); |
630 | 630 | $parser->set_escape_handler('_escapeHandler'); |
631 | 631 | |
@@ -671,7 +671,7 @@ discard block |
||
671 | 671 | */ |
672 | 672 | private function repackUTF7Back($str) |
673 | 673 | { |
674 | - return $str[1].'+'.rtrim(base64_encode($str[2]), '=').'-'; |
|
674 | + return $str[1] . '+' . rtrim(base64_encode($str[2]), '=') . '-'; |
|
675 | 675 | } |
676 | 676 | } |
677 | 677 |
@@ -331,7 +331,7 @@ |
||
331 | 331 | } |
332 | 332 | } |
333 | 333 | |
334 | - if (($value === TRUE) || (is_null($value))) { |
|
334 | + if (($value === true) || (is_null($value))) { |
|
335 | 335 | $value = $name; |
336 | 336 | } |
337 | 337 |
@@ -151,7 +151,6 @@ discard block |
||
151 | 151 | * Called by subclssses' constructors to enable/disable |
152 | 152 | * optional highlighter rules |
153 | 153 | * |
154 | - * @param array $defines Conditional defines |
|
155 | 154 | * |
156 | 155 | * @access protected |
157 | 156 | */ |
@@ -232,6 +231,7 @@ discard block |
||
232 | 231 | * Helper function to find matching brackets |
233 | 232 | * |
234 | 233 | * @access private |
234 | + * @param string $str |
|
235 | 235 | */ |
236 | 236 | function _matchingBrackets($str) |
237 | 237 | { |
@@ -32,12 +32,12 @@ discard block |
||
32 | 32 | /** |
33 | 33 | * use numbered list |
34 | 34 | */ |
35 | - define ('HL_NUMBERS_LI' , 1); |
|
35 | + define('HL_NUMBERS_LI', 1); |
|
36 | 36 | /** |
37 | 37 | * Use 2-column table with line numbers in left column and code in right column. |
38 | 38 | * Forces $options['tag'] = HL_TAG_PRE |
39 | 39 | */ |
40 | - define ('HL_NUMBERS_TABLE' , 2); |
|
40 | + define('HL_NUMBERS_TABLE', 2); |
|
41 | 41 | /**#@-*/ |
42 | 42 | } |
43 | 43 | |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | /** |
47 | 47 | * for our purpose, it is infinity |
48 | 48 | */ |
49 | -define ('HL_INFINITY', 1000000000); |
|
49 | +define('HL_INFINITY', 1000000000); |
|
50 | 50 | |
51 | 51 | // }}} |
52 | 52 | |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | $defines = array(); |
164 | 164 | } |
165 | 165 | foreach ($this->_conditions as $name => $actions) { |
166 | - foreach($actions as $action) { |
|
166 | + foreach ($actions as $action) { |
|
167 | 167 | $present = in_array($name, $defines); |
168 | 168 | if (!$action[1]) { |
169 | 169 | $present = !$present; |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | public static function factory($lang, $options = array()) |
198 | 198 | { |
199 | 199 | $lang = strtoupper($lang); |
200 | - $langFile = dirname(__FILE__)."/Highlighter/$lang.php"; |
|
200 | + $langFile = dirname(__FILE__) . "/Highlighter/$lang.php"; |
|
201 | 201 | if (is_file($langFile)) |
202 | 202 | include_once $langFile; |
203 | 203 | else |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | } else { |
257 | 257 | $endpos = -1; |
258 | 258 | } |
259 | - preg_match ($this->_regs[$this->_state], $this->_str, $m, PREG_OFFSET_CAPTURE, $this->_pos); |
|
259 | + preg_match($this->_regs[$this->_state], $this->_str, $m, PREG_OFFSET_CAPTURE, $this->_pos); |
|
260 | 260 | $n = 1; |
261 | 261 | |
262 | 262 | |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | if (!isset($m[$n])) { |
265 | 265 | break; |
266 | 266 | } |
267 | - if ($m[$n][1]>-1 && ($endpos == -1 || $m[$n][1] < $endpos)) { |
|
267 | + if ($m[$n][1] > -1 && ($endpos == -1 || $m[$n][1] < $endpos)) { |
|
268 | 268 | if ($this->_states[$this->_state][$i] != -1) { |
269 | 269 | $this->_tokenStack[] = array($this->_delim[$this->_state][$i], $m[$n][0]); |
270 | 270 | } else { |
@@ -272,17 +272,17 @@ discard block |
||
272 | 272 | if (isset($this->_parts[$this->_state][$i])) { |
273 | 273 | $parts = array(); |
274 | 274 | $partpos = $m[$n][1]; |
275 | - for ($j=1; $j<=$count; $j++) { |
|
276 | - if ($m[$j+$n][1] < 0) { |
|
275 | + for ($j = 1; $j <= $count; $j++) { |
|
276 | + if ($m[$j + $n][1] < 0) { |
|
277 | 277 | continue; |
278 | 278 | } |
279 | 279 | if (isset($this->_parts[$this->_state][$i][$j])) { |
280 | - if ($m[$j+$n][1] > $partpos) { |
|
281 | - array_unshift($parts, array($inner, substr($this->_str, $partpos, $m[$j+$n][1]-$partpos))); |
|
280 | + if ($m[$j + $n][1] > $partpos) { |
|
281 | + array_unshift($parts, array($inner, substr($this->_str, $partpos, $m[$j + $n][1] - $partpos))); |
|
282 | 282 | } |
283 | - array_unshift($parts, array($this->_parts[$this->_state][$i][$j], $m[$j+$n][0])); |
|
283 | + array_unshift($parts, array($this->_parts[$this->_state][$i][$j], $m[$j + $n][0])); |
|
284 | 284 | } |
285 | - $partpos = $m[$j+$n][1] + strlen($m[$j+$n][0]); |
|
285 | + $partpos = $m[$j + $n][1] + strlen($m[$j + $n][0]); |
|
286 | 286 | } |
287 | 287 | if ($partpos < $m[$n][1] + strlen($m[$n][0])) { |
288 | 288 | array_unshift($parts, array($inner, substr($this->_str, $partpos, $m[$n][1] - $partpos + strlen($m[$n][0])))); |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | } |
303 | 303 | } |
304 | 304 | if ($m[$n][1] > $this->_pos) { |
305 | - $this->_tokenStack[] = array($this->_lastinner, substr($this->_str, $this->_pos, $m[$n][1]-$this->_pos)); |
|
305 | + $this->_tokenStack[] = array($this->_lastinner, substr($this->_str, $this->_pos, $m[$n][1] - $this->_pos)); |
|
306 | 306 | } |
307 | 307 | $this->_pos = $m[$n][1] + strlen($m[$n][0]); |
308 | 308 | if ($this->_states[$this->_state][$i] != -1) { |
@@ -313,13 +313,13 @@ discard block |
||
313 | 313 | $this->_state = $this->_states[$this->_state][$i]; |
314 | 314 | $this->_endpattern = $this->_end[$this->_state]; |
315 | 315 | if ($this->_subst[$l][$i]) { |
316 | - for ($k=0; $k<=$this->_counts[$l][$i]; $k++) { |
|
317 | - if (!isset($m[$i+$k])) { |
|
316 | + for ($k = 0; $k <= $this->_counts[$l][$i]; $k++) { |
|
317 | + if (!isset($m[$i + $k])) { |
|
318 | 318 | break; |
319 | 319 | } |
320 | - $quoted = preg_quote($m[$n+$k][0], '/'); |
|
321 | - $this->_endpattern = str_replace('%'.$k.'%', $quoted, $this->_endpattern); |
|
322 | - $this->_endpattern = str_replace('%b'.$k.'%', $this->_matchingBrackets($quoted), $this->_endpattern); |
|
320 | + $quoted = preg_quote($m[$n + $k][0], '/'); |
|
321 | + $this->_endpattern = str_replace('%' . $k . '%', $quoted, $this->_endpattern); |
|
322 | + $this->_endpattern = str_replace('%b' . $k . '%', $this->_matchingBrackets($quoted), $this->_endpattern); |
|
323 | 323 | } |
324 | 324 | } |
325 | 325 | } |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | if ($endpos > -1) { |
332 | 332 | $this->_tokenStack[] = array($this->_lastdelim, $endmatch); |
333 | 333 | if ($endpos > $this->_pos) { |
334 | - $this->_tokenStack[] = array($this->_lastinner, substr($this->_str, $this->_pos, $endpos-$this->_pos)); |
|
334 | + $this->_tokenStack[] = array($this->_lastinner, substr($this->_str, $this->_pos, $endpos - $this->_pos)); |
|
335 | 335 | } |
336 | 336 | list($this->_state, $this->_lastdelim, $this->_lastinner, $this->_endpattern) = array_pop($this->_stack); |
337 | 337 | $this->_pos = $endpos + strlen($endmatch); |
@@ -25,20 +25,20 @@ discard block |
||
25 | 25 | // BC trick : define constants related to default |
26 | 26 | // renderer if needed |
27 | 27 | if (!defined('HL_NUMBERS_LI')) { |
28 | - /**#@+ |
|
28 | + /**#@+ |
|
29 | 29 | * Constant for use with $options['numbers'] |
30 | 30 | * @see Text_Highlighter_Renderer_Html::_init() |
31 | 31 | */ |
32 | - /** |
|
33 | - * use numbered list |
|
34 | - */ |
|
35 | - define ('HL_NUMBERS_LI' , 1); |
|
36 | - /** |
|
37 | - * Use 2-column table with line numbers in left column and code in right column. |
|
38 | - * Forces $options['tag'] = HL_TAG_PRE |
|
39 | - */ |
|
40 | - define ('HL_NUMBERS_TABLE' , 2); |
|
41 | - /**#@-*/ |
|
32 | + /** |
|
33 | + * use numbered list |
|
34 | + */ |
|
35 | + define ('HL_NUMBERS_LI' , 1); |
|
36 | + /** |
|
37 | + * Use 2-column table with line numbers in left column and code in right column. |
|
38 | + * Forces $options['tag'] = HL_TAG_PRE |
|
39 | + */ |
|
40 | + define ('HL_NUMBERS_TABLE' , 2); |
|
41 | + /**#@-*/ |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | // }}} |
@@ -92,295 +92,295 @@ discard block |
||
92 | 92 | |
93 | 93 | class Text_Highlighter |
94 | 94 | { |
95 | - // {{{ members |
|
96 | - |
|
97 | - /** |
|
98 | - * Syntax highlighting rules. |
|
99 | - * Auto-generated classes set this var |
|
100 | - * |
|
101 | - * @access protected |
|
102 | - * @see _init |
|
103 | - * @var array |
|
104 | - */ |
|
105 | - var $_syntax; |
|
106 | - |
|
107 | - /** |
|
108 | - * Renderer object. |
|
109 | - * |
|
110 | - * @access private |
|
111 | - * @var array |
|
112 | - */ |
|
113 | - var $_renderer; |
|
114 | - |
|
115 | - /** |
|
116 | - * Options. Keeped for BC |
|
117 | - * |
|
118 | - * @access protected |
|
119 | - * @var array |
|
120 | - */ |
|
121 | - var $_options = array(); |
|
122 | - |
|
123 | - /** |
|
124 | - * Conditionds |
|
125 | - * |
|
126 | - * @access protected |
|
127 | - * @var array |
|
128 | - */ |
|
129 | - var $_conditions = array(); |
|
130 | - |
|
131 | - /** |
|
132 | - * Disabled keywords |
|
133 | - * |
|
134 | - * @access protected |
|
135 | - * @var array |
|
136 | - */ |
|
137 | - var $_disabled = array(); |
|
138 | - |
|
139 | - /** |
|
140 | - * Language |
|
141 | - * |
|
142 | - * @access protected |
|
143 | - * @var string |
|
144 | - */ |
|
145 | - var $_language = ''; |
|
146 | - |
|
147 | - // }}} |
|
148 | - // {{{ _checkDefines |
|
149 | - |
|
150 | - /** |
|
151 | - * Called by subclssses' constructors to enable/disable |
|
152 | - * optional highlighter rules |
|
153 | - * |
|
154 | - * @param array $defines Conditional defines |
|
155 | - * |
|
156 | - * @access protected |
|
157 | - */ |
|
158 | - function _checkDefines() |
|
159 | - { |
|
160 | - if (isset($this->_options['defines'])) { |
|
161 | - $defines = $this->_options['defines']; |
|
162 | - } else { |
|
163 | - $defines = array(); |
|
164 | - } |
|
165 | - foreach ($this->_conditions as $name => $actions) { |
|
166 | - foreach($actions as $action) { |
|
167 | - $present = in_array($name, $defines); |
|
168 | - if (!$action[1]) { |
|
169 | - $present = !$present; |
|
170 | - } |
|
171 | - if ($present) { |
|
172 | - unset($this->_disabled[$action[0]]); |
|
173 | - } else { |
|
174 | - $this->_disabled[$action[0]] = true; |
|
175 | - } |
|
176 | - } |
|
177 | - } |
|
178 | - } |
|
179 | - |
|
180 | - // }}} |
|
181 | - // {{{ factory |
|
182 | - |
|
183 | - /** |
|
184 | - * Create a new Highlighter object for specified language |
|
185 | - * |
|
186 | - * @param string $lang language, for example "SQL" |
|
187 | - * @param array $options Rendering options. This |
|
188 | - * parameter is only keeped for BC reasons, use |
|
189 | - * {@link Text_Highlighter::setRenderer()} instead |
|
190 | - * |
|
191 | - * @return mixed a newly created Highlighter object, or |
|
192 | - * a PEAR error object on error |
|
193 | - * |
|
194 | - * @static |
|
195 | - * @access public |
|
196 | - */ |
|
197 | - public static function factory($lang, $options = array()) |
|
198 | - { |
|
199 | - $lang = strtoupper($lang); |
|
200 | - $langFile = dirname(__FILE__)."/Highlighter/$lang.php"; |
|
201 | - if (is_file($langFile)) |
|
202 | - include_once $langFile; |
|
203 | - else |
|
204 | - return false; |
|
205 | - |
|
206 | - $classname = 'Text_Highlighter_' . $lang; |
|
207 | - |
|
208 | - if (!class_exists($classname)) |
|
209 | - return false; |
|
95 | + // {{{ members |
|
96 | + |
|
97 | + /** |
|
98 | + * Syntax highlighting rules. |
|
99 | + * Auto-generated classes set this var |
|
100 | + * |
|
101 | + * @access protected |
|
102 | + * @see _init |
|
103 | + * @var array |
|
104 | + */ |
|
105 | + var $_syntax; |
|
106 | + |
|
107 | + /** |
|
108 | + * Renderer object. |
|
109 | + * |
|
110 | + * @access private |
|
111 | + * @var array |
|
112 | + */ |
|
113 | + var $_renderer; |
|
114 | + |
|
115 | + /** |
|
116 | + * Options. Keeped for BC |
|
117 | + * |
|
118 | + * @access protected |
|
119 | + * @var array |
|
120 | + */ |
|
121 | + var $_options = array(); |
|
122 | + |
|
123 | + /** |
|
124 | + * Conditionds |
|
125 | + * |
|
126 | + * @access protected |
|
127 | + * @var array |
|
128 | + */ |
|
129 | + var $_conditions = array(); |
|
130 | + |
|
131 | + /** |
|
132 | + * Disabled keywords |
|
133 | + * |
|
134 | + * @access protected |
|
135 | + * @var array |
|
136 | + */ |
|
137 | + var $_disabled = array(); |
|
138 | + |
|
139 | + /** |
|
140 | + * Language |
|
141 | + * |
|
142 | + * @access protected |
|
143 | + * @var string |
|
144 | + */ |
|
145 | + var $_language = ''; |
|
146 | + |
|
147 | + // }}} |
|
148 | + // {{{ _checkDefines |
|
149 | + |
|
150 | + /** |
|
151 | + * Called by subclssses' constructors to enable/disable |
|
152 | + * optional highlighter rules |
|
153 | + * |
|
154 | + * @param array $defines Conditional defines |
|
155 | + * |
|
156 | + * @access protected |
|
157 | + */ |
|
158 | + function _checkDefines() |
|
159 | + { |
|
160 | + if (isset($this->_options['defines'])) { |
|
161 | + $defines = $this->_options['defines']; |
|
162 | + } else { |
|
163 | + $defines = array(); |
|
164 | + } |
|
165 | + foreach ($this->_conditions as $name => $actions) { |
|
166 | + foreach($actions as $action) { |
|
167 | + $present = in_array($name, $defines); |
|
168 | + if (!$action[1]) { |
|
169 | + $present = !$present; |
|
170 | + } |
|
171 | + if ($present) { |
|
172 | + unset($this->_disabled[$action[0]]); |
|
173 | + } else { |
|
174 | + $this->_disabled[$action[0]] = true; |
|
175 | + } |
|
176 | + } |
|
177 | + } |
|
178 | + } |
|
179 | + |
|
180 | + // }}} |
|
181 | + // {{{ factory |
|
182 | + |
|
183 | + /** |
|
184 | + * Create a new Highlighter object for specified language |
|
185 | + * |
|
186 | + * @param string $lang language, for example "SQL" |
|
187 | + * @param array $options Rendering options. This |
|
188 | + * parameter is only keeped for BC reasons, use |
|
189 | + * {@link Text_Highlighter::setRenderer()} instead |
|
190 | + * |
|
191 | + * @return mixed a newly created Highlighter object, or |
|
192 | + * a PEAR error object on error |
|
193 | + * |
|
194 | + * @static |
|
195 | + * @access public |
|
196 | + */ |
|
197 | + public static function factory($lang, $options = array()) |
|
198 | + { |
|
199 | + $lang = strtoupper($lang); |
|
200 | + $langFile = dirname(__FILE__)."/Highlighter/$lang.php"; |
|
201 | + if (is_file($langFile)) |
|
202 | + include_once $langFile; |
|
203 | + else |
|
204 | + return false; |
|
205 | + |
|
206 | + $classname = 'Text_Highlighter_' . $lang; |
|
207 | + |
|
208 | + if (!class_exists($classname)) |
|
209 | + return false; |
|
210 | 210 | |
211 | 211 | return new $classname($options); |
212 | - } |
|
213 | - |
|
214 | - // }}} |
|
215 | - // {{{ setRenderer |
|
216 | - |
|
217 | - /** |
|
218 | - * Set renderer object |
|
219 | - * |
|
220 | - * @param object $renderer Text_Highlighter_Renderer |
|
221 | - * |
|
222 | - * @access public |
|
223 | - */ |
|
224 | - function setRenderer($renderer) |
|
225 | - { |
|
226 | - $this->_renderer = $renderer; |
|
227 | - } |
|
228 | - |
|
229 | - // }}} |
|
230 | - |
|
231 | - /** |
|
232 | - * Helper function to find matching brackets |
|
233 | - * |
|
234 | - * @access private |
|
235 | - */ |
|
236 | - function _matchingBrackets($str) |
|
237 | - { |
|
238 | - return strtr($str, '()<>[]{}', ')(><][}{'); |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - |
|
243 | - |
|
244 | - function _getToken() |
|
245 | - { |
|
246 | - if (!empty($this->_tokenStack)) { |
|
247 | - return array_pop($this->_tokenStack); |
|
248 | - } |
|
249 | - if ($this->_pos >= $this->_len) { |
|
250 | - return NULL; |
|
251 | - } |
|
252 | - |
|
253 | - if ($this->_state != -1 && preg_match($this->_endpattern, $this->_str, $m, PREG_OFFSET_CAPTURE, $this->_pos)) { |
|
254 | - $endpos = $m[0][1]; |
|
255 | - $endmatch = $m[0][0]; |
|
256 | - } else { |
|
257 | - $endpos = -1; |
|
258 | - } |
|
259 | - preg_match ($this->_regs[$this->_state], $this->_str, $m, PREG_OFFSET_CAPTURE, $this->_pos); |
|
260 | - $n = 1; |
|
261 | - |
|
262 | - |
|
263 | - foreach ($this->_counts[$this->_state] as $i=>$count) { |
|
264 | - if (!isset($m[$n])) { |
|
265 | - break; |
|
266 | - } |
|
267 | - if ($m[$n][1]>-1 && ($endpos == -1 || $m[$n][1] < $endpos)) { |
|
268 | - if ($this->_states[$this->_state][$i] != -1) { |
|
269 | - $this->_tokenStack[] = array($this->_delim[$this->_state][$i], $m[$n][0]); |
|
270 | - } else { |
|
271 | - $inner = $this->_inner[$this->_state][$i]; |
|
272 | - if (isset($this->_parts[$this->_state][$i])) { |
|
273 | - $parts = array(); |
|
274 | - $partpos = $m[$n][1]; |
|
275 | - for ($j=1; $j<=$count; $j++) { |
|
276 | - if ($m[$j+$n][1] < 0) { |
|
277 | - continue; |
|
278 | - } |
|
279 | - if (isset($this->_parts[$this->_state][$i][$j])) { |
|
280 | - if ($m[$j+$n][1] > $partpos) { |
|
281 | - array_unshift($parts, array($inner, substr($this->_str, $partpos, $m[$j+$n][1]-$partpos))); |
|
282 | - } |
|
283 | - array_unshift($parts, array($this->_parts[$this->_state][$i][$j], $m[$j+$n][0])); |
|
284 | - } |
|
285 | - $partpos = $m[$j+$n][1] + strlen($m[$j+$n][0]); |
|
286 | - } |
|
287 | - if ($partpos < $m[$n][1] + strlen($m[$n][0])) { |
|
288 | - array_unshift($parts, array($inner, substr($this->_str, $partpos, $m[$n][1] - $partpos + strlen($m[$n][0])))); |
|
289 | - } |
|
290 | - $this->_tokenStack = array_merge($this->_tokenStack, $parts); |
|
291 | - } else { |
|
292 | - foreach ($this->_keywords[$this->_state][$i] as $g => $re) { |
|
293 | - if (isset($this->_disabled[$g])) { |
|
294 | - continue; |
|
295 | - } |
|
296 | - if (preg_match($re, $m[$n][0])) { |
|
297 | - $inner = $this->_kwmap[$g]; |
|
298 | - break; |
|
299 | - } |
|
300 | - } |
|
301 | - $this->_tokenStack[] = array($inner, $m[$n][0]); |
|
302 | - } |
|
303 | - } |
|
304 | - if ($m[$n][1] > $this->_pos) { |
|
305 | - $this->_tokenStack[] = array($this->_lastinner, substr($this->_str, $this->_pos, $m[$n][1]-$this->_pos)); |
|
306 | - } |
|
307 | - $this->_pos = $m[$n][1] + strlen($m[$n][0]); |
|
308 | - if ($this->_states[$this->_state][$i] != -1) { |
|
309 | - $this->_stack[] = array($this->_state, $this->_lastdelim, $this->_lastinner, $this->_endpattern); |
|
310 | - $this->_lastinner = $this->_inner[$this->_state][$i]; |
|
311 | - $this->_lastdelim = $this->_delim[$this->_state][$i]; |
|
312 | - $l = $this->_state; |
|
313 | - $this->_state = $this->_states[$this->_state][$i]; |
|
314 | - $this->_endpattern = $this->_end[$this->_state]; |
|
315 | - if ($this->_subst[$l][$i]) { |
|
316 | - for ($k=0; $k<=$this->_counts[$l][$i]; $k++) { |
|
317 | - if (!isset($m[$i+$k])) { |
|
318 | - break; |
|
319 | - } |
|
320 | - $quoted = preg_quote($m[$n+$k][0], '/'); |
|
321 | - $this->_endpattern = str_replace('%'.$k.'%', $quoted, $this->_endpattern); |
|
322 | - $this->_endpattern = str_replace('%b'.$k.'%', $this->_matchingBrackets($quoted), $this->_endpattern); |
|
323 | - } |
|
324 | - } |
|
325 | - } |
|
326 | - return array_pop($this->_tokenStack); |
|
327 | - } |
|
328 | - $n += $count + 1; |
|
329 | - } |
|
330 | - |
|
331 | - if ($endpos > -1) { |
|
332 | - $this->_tokenStack[] = array($this->_lastdelim, $endmatch); |
|
333 | - if ($endpos > $this->_pos) { |
|
334 | - $this->_tokenStack[] = array($this->_lastinner, substr($this->_str, $this->_pos, $endpos-$this->_pos)); |
|
335 | - } |
|
336 | - list($this->_state, $this->_lastdelim, $this->_lastinner, $this->_endpattern) = array_pop($this->_stack); |
|
337 | - $this->_pos = $endpos + strlen($endmatch); |
|
338 | - return array_pop($this->_tokenStack); |
|
339 | - } |
|
340 | - $p = $this->_pos; |
|
341 | - $this->_pos = HL_INFINITY; |
|
342 | - return array($this->_lastinner, substr($this->_str, $p)); |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - |
|
347 | - |
|
348 | - // {{{ highlight |
|
349 | - |
|
350 | - /** |
|
351 | - * Highlights code |
|
352 | - * |
|
353 | - * @param string $str Code to highlight |
|
354 | - * @access public |
|
355 | - * @return string Highlighted text |
|
356 | - * |
|
357 | - */ |
|
358 | - |
|
359 | - function highlight($str) |
|
360 | - { |
|
361 | - if (!($this->_renderer)) { |
|
362 | - include_once('Text/Highlighter/Renderer/Html.php'); |
|
363 | - $this->_renderer = new Text_Highlighter_Renderer_Html($this->_options); |
|
364 | - } |
|
365 | - $this->_state = -1; |
|
366 | - $this->_pos = 0; |
|
367 | - $this->_stack = array(); |
|
368 | - $this->_tokenStack = array(); |
|
369 | - $this->_lastinner = $this->_defClass; |
|
370 | - $this->_lastdelim = $this->_defClass; |
|
371 | - $this->_endpattern = ''; |
|
372 | - $this->_renderer->reset(); |
|
373 | - $this->_renderer->setCurrentLanguage($this->_language); |
|
374 | - $this->_str = $this->_renderer->preprocess($str); |
|
375 | - $this->_len = strlen($this->_str); |
|
376 | - while ($token = $this->_getToken()) { |
|
377 | - $this->_renderer->acceptToken($token[0], $token[1]); |
|
378 | - } |
|
379 | - $this->_renderer->finalize(); |
|
380 | - return $this->_renderer->getOutput(); |
|
381 | - } |
|
382 | - |
|
383 | - // }}} |
|
212 | + } |
|
213 | + |
|
214 | + // }}} |
|
215 | + // {{{ setRenderer |
|
216 | + |
|
217 | + /** |
|
218 | + * Set renderer object |
|
219 | + * |
|
220 | + * @param object $renderer Text_Highlighter_Renderer |
|
221 | + * |
|
222 | + * @access public |
|
223 | + */ |
|
224 | + function setRenderer($renderer) |
|
225 | + { |
|
226 | + $this->_renderer = $renderer; |
|
227 | + } |
|
228 | + |
|
229 | + // }}} |
|
230 | + |
|
231 | + /** |
|
232 | + * Helper function to find matching brackets |
|
233 | + * |
|
234 | + * @access private |
|
235 | + */ |
|
236 | + function _matchingBrackets($str) |
|
237 | + { |
|
238 | + return strtr($str, '()<>[]{}', ')(><][}{'); |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + |
|
243 | + |
|
244 | + function _getToken() |
|
245 | + { |
|
246 | + if (!empty($this->_tokenStack)) { |
|
247 | + return array_pop($this->_tokenStack); |
|
248 | + } |
|
249 | + if ($this->_pos >= $this->_len) { |
|
250 | + return NULL; |
|
251 | + } |
|
252 | + |
|
253 | + if ($this->_state != -1 && preg_match($this->_endpattern, $this->_str, $m, PREG_OFFSET_CAPTURE, $this->_pos)) { |
|
254 | + $endpos = $m[0][1]; |
|
255 | + $endmatch = $m[0][0]; |
|
256 | + } else { |
|
257 | + $endpos = -1; |
|
258 | + } |
|
259 | + preg_match ($this->_regs[$this->_state], $this->_str, $m, PREG_OFFSET_CAPTURE, $this->_pos); |
|
260 | + $n = 1; |
|
261 | + |
|
262 | + |
|
263 | + foreach ($this->_counts[$this->_state] as $i=>$count) { |
|
264 | + if (!isset($m[$n])) { |
|
265 | + break; |
|
266 | + } |
|
267 | + if ($m[$n][1]>-1 && ($endpos == -1 || $m[$n][1] < $endpos)) { |
|
268 | + if ($this->_states[$this->_state][$i] != -1) { |
|
269 | + $this->_tokenStack[] = array($this->_delim[$this->_state][$i], $m[$n][0]); |
|
270 | + } else { |
|
271 | + $inner = $this->_inner[$this->_state][$i]; |
|
272 | + if (isset($this->_parts[$this->_state][$i])) { |
|
273 | + $parts = array(); |
|
274 | + $partpos = $m[$n][1]; |
|
275 | + for ($j=1; $j<=$count; $j++) { |
|
276 | + if ($m[$j+$n][1] < 0) { |
|
277 | + continue; |
|
278 | + } |
|
279 | + if (isset($this->_parts[$this->_state][$i][$j])) { |
|
280 | + if ($m[$j+$n][1] > $partpos) { |
|
281 | + array_unshift($parts, array($inner, substr($this->_str, $partpos, $m[$j+$n][1]-$partpos))); |
|
282 | + } |
|
283 | + array_unshift($parts, array($this->_parts[$this->_state][$i][$j], $m[$j+$n][0])); |
|
284 | + } |
|
285 | + $partpos = $m[$j+$n][1] + strlen($m[$j+$n][0]); |
|
286 | + } |
|
287 | + if ($partpos < $m[$n][1] + strlen($m[$n][0])) { |
|
288 | + array_unshift($parts, array($inner, substr($this->_str, $partpos, $m[$n][1] - $partpos + strlen($m[$n][0])))); |
|
289 | + } |
|
290 | + $this->_tokenStack = array_merge($this->_tokenStack, $parts); |
|
291 | + } else { |
|
292 | + foreach ($this->_keywords[$this->_state][$i] as $g => $re) { |
|
293 | + if (isset($this->_disabled[$g])) { |
|
294 | + continue; |
|
295 | + } |
|
296 | + if (preg_match($re, $m[$n][0])) { |
|
297 | + $inner = $this->_kwmap[$g]; |
|
298 | + break; |
|
299 | + } |
|
300 | + } |
|
301 | + $this->_tokenStack[] = array($inner, $m[$n][0]); |
|
302 | + } |
|
303 | + } |
|
304 | + if ($m[$n][1] > $this->_pos) { |
|
305 | + $this->_tokenStack[] = array($this->_lastinner, substr($this->_str, $this->_pos, $m[$n][1]-$this->_pos)); |
|
306 | + } |
|
307 | + $this->_pos = $m[$n][1] + strlen($m[$n][0]); |
|
308 | + if ($this->_states[$this->_state][$i] != -1) { |
|
309 | + $this->_stack[] = array($this->_state, $this->_lastdelim, $this->_lastinner, $this->_endpattern); |
|
310 | + $this->_lastinner = $this->_inner[$this->_state][$i]; |
|
311 | + $this->_lastdelim = $this->_delim[$this->_state][$i]; |
|
312 | + $l = $this->_state; |
|
313 | + $this->_state = $this->_states[$this->_state][$i]; |
|
314 | + $this->_endpattern = $this->_end[$this->_state]; |
|
315 | + if ($this->_subst[$l][$i]) { |
|
316 | + for ($k=0; $k<=$this->_counts[$l][$i]; $k++) { |
|
317 | + if (!isset($m[$i+$k])) { |
|
318 | + break; |
|
319 | + } |
|
320 | + $quoted = preg_quote($m[$n+$k][0], '/'); |
|
321 | + $this->_endpattern = str_replace('%'.$k.'%', $quoted, $this->_endpattern); |
|
322 | + $this->_endpattern = str_replace('%b'.$k.'%', $this->_matchingBrackets($quoted), $this->_endpattern); |
|
323 | + } |
|
324 | + } |
|
325 | + } |
|
326 | + return array_pop($this->_tokenStack); |
|
327 | + } |
|
328 | + $n += $count + 1; |
|
329 | + } |
|
330 | + |
|
331 | + if ($endpos > -1) { |
|
332 | + $this->_tokenStack[] = array($this->_lastdelim, $endmatch); |
|
333 | + if ($endpos > $this->_pos) { |
|
334 | + $this->_tokenStack[] = array($this->_lastinner, substr($this->_str, $this->_pos, $endpos-$this->_pos)); |
|
335 | + } |
|
336 | + list($this->_state, $this->_lastdelim, $this->_lastinner, $this->_endpattern) = array_pop($this->_stack); |
|
337 | + $this->_pos = $endpos + strlen($endmatch); |
|
338 | + return array_pop($this->_tokenStack); |
|
339 | + } |
|
340 | + $p = $this->_pos; |
|
341 | + $this->_pos = HL_INFINITY; |
|
342 | + return array($this->_lastinner, substr($this->_str, $p)); |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + |
|
347 | + |
|
348 | + // {{{ highlight |
|
349 | + |
|
350 | + /** |
|
351 | + * Highlights code |
|
352 | + * |
|
353 | + * @param string $str Code to highlight |
|
354 | + * @access public |
|
355 | + * @return string Highlighted text |
|
356 | + * |
|
357 | + */ |
|
358 | + |
|
359 | + function highlight($str) |
|
360 | + { |
|
361 | + if (!($this->_renderer)) { |
|
362 | + include_once('Text/Highlighter/Renderer/Html.php'); |
|
363 | + $this->_renderer = new Text_Highlighter_Renderer_Html($this->_options); |
|
364 | + } |
|
365 | + $this->_state = -1; |
|
366 | + $this->_pos = 0; |
|
367 | + $this->_stack = array(); |
|
368 | + $this->_tokenStack = array(); |
|
369 | + $this->_lastinner = $this->_defClass; |
|
370 | + $this->_lastdelim = $this->_defClass; |
|
371 | + $this->_endpattern = ''; |
|
372 | + $this->_renderer->reset(); |
|
373 | + $this->_renderer->setCurrentLanguage($this->_language); |
|
374 | + $this->_str = $this->_renderer->preprocess($str); |
|
375 | + $this->_len = strlen($this->_str); |
|
376 | + while ($token = $this->_getToken()) { |
|
377 | + $this->_renderer->acceptToken($token[0], $token[1]); |
|
378 | + } |
|
379 | + $this->_renderer->finalize(); |
|
380 | + return $this->_renderer->getOutput(); |
|
381 | + } |
|
382 | + |
|
383 | + // }}} |
|
384 | 384 | |
385 | 385 | } |
386 | 386 |
@@ -247,7 +247,7 @@ |
||
247 | 247 | return array_pop($this->_tokenStack); |
248 | 248 | } |
249 | 249 | if ($this->_pos >= $this->_len) { |
250 | - return NULL; |
|
250 | + return null; |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | if ($this->_state != -1 && preg_match($this->_endpattern, $this->_str, $m, PREG_OFFSET_CAPTURE, $this->_pos)) { |
@@ -262,6 +262,7 @@ discard block |
||
262 | 262 | * Sets the input xml file to be parsed |
263 | 263 | * |
264 | 264 | * @param string Filename (full path) |
265 | + * @param string $file |
|
265 | 266 | * @return boolean |
266 | 267 | * @access public |
267 | 268 | */ |
@@ -768,7 +769,6 @@ discard block |
||
768 | 769 | * Add an error message |
769 | 770 | * |
770 | 771 | * @param integer $code Error code |
771 | - * @param mixed $message Error message or array with error message parameters |
|
772 | 772 | * @param integer $lineNo Source code line number |
773 | 773 | * @access private |
774 | 774 | */ |
@@ -67,949 +67,949 @@ discard block |
||
67 | 67 | |
68 | 68 | class Text_Highlighter_Generator extends XML_Parser |
69 | 69 | { |
70 | - // {{{ properties |
|
71 | - /** |
|
72 | - * Whether to do case folding. |
|
73 | - * We have to declare it here, because XML_Parser |
|
74 | - * sets case folding in constructor |
|
75 | - * |
|
76 | - * @var boolean |
|
77 | - */ |
|
78 | - var $folding = false; |
|
79 | - |
|
80 | - /** |
|
81 | - * Holds name of file with highlighting rules |
|
82 | - * |
|
83 | - * @var string |
|
84 | - * @access private |
|
85 | - */ |
|
86 | - var $_syntaxFile; |
|
87 | - |
|
88 | - /** |
|
89 | - * Current element being processed |
|
90 | - * |
|
91 | - * @var array |
|
92 | - * @access private |
|
93 | - */ |
|
94 | - var $_element; |
|
95 | - |
|
96 | - /** |
|
97 | - * List of regions |
|
98 | - * |
|
99 | - * @var array |
|
100 | - * @access private |
|
101 | - */ |
|
102 | - var $_regions = array(); |
|
103 | - |
|
104 | - /** |
|
105 | - * List of blocks |
|
106 | - * |
|
107 | - * @var array |
|
108 | - * @access private |
|
109 | - */ |
|
110 | - var $_blocks = array(); |
|
111 | - |
|
112 | - /** |
|
113 | - * List of keyword groups |
|
114 | - * |
|
115 | - * @var array |
|
116 | - * @access private |
|
117 | - */ |
|
118 | - var $_keywords = array(); |
|
119 | - |
|
120 | - /** |
|
121 | - * List of authors |
|
122 | - * |
|
123 | - * @var array |
|
124 | - * @access private |
|
125 | - */ |
|
126 | - var $_authors = array(); |
|
127 | - |
|
128 | - /** |
|
129 | - * Name of language |
|
130 | - * |
|
131 | - * @var string |
|
132 | - * @access public |
|
133 | - */ |
|
134 | - var $language = ''; |
|
135 | - |
|
136 | - /** |
|
137 | - * Generated code |
|
138 | - * |
|
139 | - * @var string |
|
140 | - * @access private |
|
141 | - */ |
|
142 | - var $_code = ''; |
|
143 | - |
|
144 | - /** |
|
145 | - * Default class |
|
146 | - * |
|
147 | - * @var string |
|
148 | - * @access private |
|
149 | - */ |
|
150 | - var $_defClass = 'default'; |
|
151 | - |
|
152 | - /** |
|
153 | - * Comment |
|
154 | - * |
|
155 | - * @var string |
|
156 | - * @access private |
|
157 | - */ |
|
158 | - var $_comment = ''; |
|
159 | - |
|
160 | - /** |
|
161 | - * Flag for comment processing |
|
162 | - * |
|
163 | - * @var boolean |
|
164 | - * @access private |
|
165 | - */ |
|
166 | - var $_inComment = false; |
|
167 | - |
|
168 | - /** |
|
169 | - * Sorting order of current block/region |
|
170 | - * |
|
171 | - * @var integer |
|
172 | - * @access private |
|
173 | - */ |
|
174 | - var $_blockOrder = 0; |
|
175 | - |
|
176 | - /** |
|
177 | - * Generation errors |
|
178 | - * |
|
179 | - * @var array |
|
180 | - * @access private |
|
181 | - */ |
|
182 | - var $_errors; |
|
183 | - |
|
184 | - // }}} |
|
185 | - // {{{ constructor |
|
186 | - |
|
187 | - /** |
|
188 | - * Constructor |
|
189 | - * |
|
190 | - * @param string $syntaxFile Name of XML file |
|
191 | - * with syntax highlighting rules |
|
192 | - * |
|
193 | - * @access public |
|
194 | - */ |
|
195 | - |
|
196 | - function __construct($syntaxFile = '') |
|
197 | - { |
|
198 | - XML_Parser::XML_Parser(null, 'func'); |
|
199 | - $this->_errors = array(); |
|
200 | - $this->_declareErrorMessages(); |
|
201 | - if ($syntaxFile) { |
|
202 | - $this->setInputFile($syntaxFile); |
|
203 | - } |
|
204 | - } |
|
205 | - |
|
206 | - // }}} |
|
207 | - // {{{ _formatError |
|
208 | - |
|
209 | - /** |
|
210 | - * Format error message |
|
211 | - * |
|
212 | - * @param int $code error code |
|
213 | - * @param string $params parameters |
|
214 | - * @param string $fileName file name |
|
215 | - * @param int $lineNo line number |
|
216 | - * @return array |
|
217 | - * @access public |
|
218 | - */ |
|
219 | - function _formatError($code, $params, $fileName, $lineNo) |
|
220 | - { |
|
221 | - $template = $this->_templates[$code]; |
|
222 | - $ret = call_user_func_array('sprintf', array_merge(array($template), $params)); |
|
223 | - if ($fileName) { |
|
224 | - $ret = '[' . $fileName . '] ' . $ret; |
|
225 | - } |
|
226 | - if ($lineNo) { |
|
227 | - $ret .= ' (line ' . $lineNo . ')'; |
|
228 | - } |
|
229 | - return $ret; |
|
230 | - } |
|
231 | - |
|
232 | - // }}} |
|
233 | - // {{{ declareErrorMessages |
|
234 | - |
|
235 | - /** |
|
236 | - * Set up error message templates |
|
237 | - * |
|
238 | - * @access private |
|
239 | - */ |
|
240 | - function _declareErrorMessages() |
|
241 | - { |
|
242 | - $this->_templates = array ( |
|
243 | - TEXT_HIGHLIGHTER_EMPTY_RE => 'Empty regular expression', |
|
244 | - TEXT_HIGHLIGHTER_INVALID_RE => 'Invalid regular expression : %s', |
|
245 | - TEXT_HIGHLIGHTER_EMPTY_OR_MISSING => 'Empty or missing %s', |
|
246 | - TEXT_HIGHLIGHTER_EMPTY => 'Empty %s', |
|
247 | - TEXT_HIGHLIGHTER_REGION_REGION => 'Region %s refers undefined region %s', |
|
248 | - TEXT_HIGHLIGHTER_REGION_BLOCK => 'Region %s refers undefined block %s', |
|
249 | - TEXT_HIGHLIGHTER_BLOCK_REGION => 'Block %s refers undefined region %s', |
|
250 | - TEXT_HIGHLIGHTER_KEYWORD_BLOCK => 'Keyword group %s refers undefined block %s', |
|
251 | - TEXT_HIGHLIGHTER_KEYWORD_INHERITS => 'Keyword group %s inherits undefined block %s', |
|
252 | - TEXT_HIGHLIGHTER_PARSE => '%s', |
|
253 | - TEXT_HIGHLIGHTER_FILE_WRITE => 'Error writing file %s', |
|
254 | - TEXT_HIGHLIGHTER_FILE_READ => '%s' |
|
255 | - ); |
|
256 | - } |
|
257 | - |
|
258 | - // }}} |
|
259 | - // {{{ setInputFile |
|
260 | - |
|
261 | - /** |
|
262 | - * Sets the input xml file to be parsed |
|
263 | - * |
|
264 | - * @param string Filename (full path) |
|
265 | - * @return boolean |
|
266 | - * @access public |
|
267 | - */ |
|
268 | - function setInputFile($file) |
|
269 | - { |
|
270 | - $this->_syntaxFile = $file; |
|
271 | - $ret = parent::setInputFile($file); |
|
272 | - if (PEAR::isError($ret)) { |
|
273 | - $this->_error(TEXT_HIGHLIGHTER_FILE_READ, $ret->message); |
|
274 | - return false; |
|
275 | - } |
|
276 | - return true; |
|
277 | - } |
|
278 | - |
|
279 | - // }}} |
|
280 | - // {{{ generate |
|
281 | - |
|
282 | - /** |
|
283 | - * Generates class code |
|
284 | - * |
|
285 | - * @access public |
|
286 | - */ |
|
287 | - |
|
288 | - function generate() |
|
289 | - { |
|
290 | - $this->_regions = array(); |
|
291 | - $this->_blocks = array(); |
|
292 | - $this->_keywords = array(); |
|
293 | - $this->language = ''; |
|
294 | - $this->_code = ''; |
|
295 | - $this->_defClass = 'default'; |
|
296 | - $this->_comment = ''; |
|
297 | - $this->_inComment = false; |
|
298 | - $this->_authors = array(); |
|
299 | - $this->_blockOrder = 0; |
|
300 | - $this->_errors = array(); |
|
301 | - |
|
302 | - $ret = $this->parse(); |
|
303 | - if (PEAR::isError($ret)) { |
|
304 | - $this->_error(TEXT_HIGHLIGHTER_PARSE, $ret->message); |
|
305 | - return false; |
|
306 | - } |
|
307 | - return true; |
|
308 | - } |
|
309 | - |
|
310 | - // }}} |
|
311 | - // {{{ getCode |
|
312 | - |
|
313 | - /** |
|
314 | - * Returns generated code as a string. |
|
315 | - * |
|
316 | - * @return string Generated code |
|
317 | - * @access public |
|
318 | - */ |
|
319 | - |
|
320 | - function getCode() |
|
321 | - { |
|
322 | - return $this->_code; |
|
323 | - } |
|
324 | - |
|
325 | - // }}} |
|
326 | - // {{{ saveCode |
|
327 | - |
|
328 | - /** |
|
329 | - * Saves generated class to file. Note that {@link Text_Highlighter::factory()} |
|
330 | - * assumes that filename is uppercase (SQL.php, DTD.php, etc), and file |
|
331 | - * is located in Text/Highlighter |
|
332 | - * |
|
333 | - * @param string $filename Name of file to write the code to |
|
334 | - * @return boolean true on success, false on failure |
|
335 | - * @access public |
|
336 | - */ |
|
337 | - |
|
338 | - function saveCode($filename) |
|
339 | - { |
|
340 | - $f = @fopen($filename, 'wb'); |
|
341 | - if (!$f) { |
|
342 | - $this->_error(TEXT_HIGHLIGHTER_FILE_WRITE, array('outfile'=>$filename)); |
|
343 | - return false; |
|
344 | - } |
|
345 | - fwrite ($f, $this->_code); |
|
346 | - fclose($f); |
|
347 | - return true; |
|
348 | - } |
|
349 | - |
|
350 | - // }}} |
|
351 | - // {{{ hasErrors |
|
352 | - |
|
353 | - /** |
|
354 | - * Reports if there were errors |
|
355 | - * |
|
356 | - * @return boolean |
|
357 | - * @access public |
|
358 | - */ |
|
359 | - |
|
360 | - function hasErrors() |
|
361 | - { |
|
362 | - return count($this->_errors) > 0; |
|
363 | - } |
|
364 | - |
|
365 | - // }}} |
|
366 | - // {{{ getErrors |
|
367 | - |
|
368 | - /** |
|
369 | - * Returns errors |
|
370 | - * |
|
371 | - * @return array |
|
372 | - * @access public |
|
373 | - */ |
|
374 | - |
|
375 | - function getErrors() |
|
376 | - { |
|
377 | - return $this->_errors; |
|
378 | - } |
|
379 | - |
|
380 | - // }}} |
|
381 | - // {{{ _sortBlocks |
|
382 | - |
|
383 | - /** |
|
384 | - * Sorts blocks |
|
385 | - * |
|
386 | - * @access private |
|
387 | - */ |
|
388 | - |
|
389 | - function _sortBlocks($b1, $b2) { |
|
390 | - return $b1['order'] - $b2['order']; |
|
391 | - } |
|
392 | - |
|
393 | - // }}} |
|
394 | - // {{{ _sortLookFor |
|
395 | - /** |
|
396 | - * Sort 'look for' list |
|
397 | - * @return int |
|
398 | - * @param string $b1 |
|
399 | - * @param string $b2 |
|
400 | - */ |
|
401 | - function _sortLookFor($b1, $b2) { |
|
402 | - $o1 = isset($this->_blocks[$b1]) ? $this->_blocks[$b1]['order'] : $this->_regions[$b1]['order']; |
|
403 | - $o2 = isset($this->_blocks[$b2]) ? $this->_blocks[$b2]['order'] : $this->_regions[$b2]['order']; |
|
404 | - return $o1 - $o2; |
|
405 | - } |
|
406 | - |
|
407 | - // }}} |
|
408 | - // {{{ _makeRE |
|
409 | - |
|
410 | - /** |
|
411 | - * Adds delimiters and modifiers to regular expression if necessary |
|
412 | - * |
|
413 | - * @param string $text Original RE |
|
414 | - * @return string Final RE |
|
415 | - * @access private |
|
416 | - */ |
|
417 | - function _makeRE($text, $case = false) |
|
418 | - { |
|
419 | - if (!strlen($text)) { |
|
420 | - $this->_error(TEXT_HIGHLIGHTER_EMPTY_RE); |
|
421 | - } |
|
422 | - if (!strlen($text) || $text{0} != '/') { |
|
423 | - $text = '/' . $text . '/'; |
|
424 | - } |
|
425 | - if (!$case) { |
|
426 | - $text .= 'i'; |
|
427 | - } |
|
428 | - $php_errormsg = ''; |
|
429 | - @preg_match($text, ''); |
|
430 | - if ($php_errormsg) { |
|
431 | - $this->_error(TEXT_HIGHLIGHTER_INVALID_RE, $php_errormsg); |
|
432 | - } |
|
433 | - preg_match ('#^/(.+)/(.*)$#', $text, $m); |
|
434 | - if (@$m[2]) { |
|
435 | - $text = '(?' . $m[2] . ')' . $m[1]; |
|
436 | - } else { |
|
437 | - $text = $m[1]; |
|
438 | - } |
|
439 | - return $text; |
|
440 | - } |
|
441 | - |
|
442 | - // }}} |
|
443 | - // {{{ _exportArray |
|
444 | - |
|
445 | - /** |
|
446 | - * Exports array as PHP code |
|
447 | - * |
|
448 | - * @param array $array |
|
449 | - * @return string Code |
|
450 | - * @access private |
|
451 | - */ |
|
452 | - function _exportArray($array) |
|
453 | - { |
|
454 | - $array = var_export($array, true); |
|
455 | - return trim(preg_replace('~^(\s*)~m',' \1\1',$array)); |
|
456 | - } |
|
457 | - |
|
458 | - // }}} |
|
459 | - // {{{ _countSubpatterns |
|
460 | - /** |
|
461 | - * Find number of capturing suppaterns in regular expression |
|
462 | - * @return int |
|
463 | - * @param string $re Regular expression (without delimiters) |
|
464 | - */ |
|
465 | - function _countSubpatterns($re) |
|
466 | - { |
|
467 | - preg_match_all('/' . $re . '/', '', $m); |
|
468 | - return count($m)-1; |
|
469 | - } |
|
470 | - |
|
471 | - // }}} |
|
472 | - |
|
473 | - /**#@+ |
|
70 | + // {{{ properties |
|
71 | + /** |
|
72 | + * Whether to do case folding. |
|
73 | + * We have to declare it here, because XML_Parser |
|
74 | + * sets case folding in constructor |
|
75 | + * |
|
76 | + * @var boolean |
|
77 | + */ |
|
78 | + var $folding = false; |
|
79 | + |
|
80 | + /** |
|
81 | + * Holds name of file with highlighting rules |
|
82 | + * |
|
83 | + * @var string |
|
84 | + * @access private |
|
85 | + */ |
|
86 | + var $_syntaxFile; |
|
87 | + |
|
88 | + /** |
|
89 | + * Current element being processed |
|
90 | + * |
|
91 | + * @var array |
|
92 | + * @access private |
|
93 | + */ |
|
94 | + var $_element; |
|
95 | + |
|
96 | + /** |
|
97 | + * List of regions |
|
98 | + * |
|
99 | + * @var array |
|
100 | + * @access private |
|
101 | + */ |
|
102 | + var $_regions = array(); |
|
103 | + |
|
104 | + /** |
|
105 | + * List of blocks |
|
106 | + * |
|
107 | + * @var array |
|
108 | + * @access private |
|
109 | + */ |
|
110 | + var $_blocks = array(); |
|
111 | + |
|
112 | + /** |
|
113 | + * List of keyword groups |
|
114 | + * |
|
115 | + * @var array |
|
116 | + * @access private |
|
117 | + */ |
|
118 | + var $_keywords = array(); |
|
119 | + |
|
120 | + /** |
|
121 | + * List of authors |
|
122 | + * |
|
123 | + * @var array |
|
124 | + * @access private |
|
125 | + */ |
|
126 | + var $_authors = array(); |
|
127 | + |
|
128 | + /** |
|
129 | + * Name of language |
|
130 | + * |
|
131 | + * @var string |
|
132 | + * @access public |
|
133 | + */ |
|
134 | + var $language = ''; |
|
135 | + |
|
136 | + /** |
|
137 | + * Generated code |
|
138 | + * |
|
139 | + * @var string |
|
140 | + * @access private |
|
141 | + */ |
|
142 | + var $_code = ''; |
|
143 | + |
|
144 | + /** |
|
145 | + * Default class |
|
146 | + * |
|
147 | + * @var string |
|
148 | + * @access private |
|
149 | + */ |
|
150 | + var $_defClass = 'default'; |
|
151 | + |
|
152 | + /** |
|
153 | + * Comment |
|
154 | + * |
|
155 | + * @var string |
|
156 | + * @access private |
|
157 | + */ |
|
158 | + var $_comment = ''; |
|
159 | + |
|
160 | + /** |
|
161 | + * Flag for comment processing |
|
162 | + * |
|
163 | + * @var boolean |
|
164 | + * @access private |
|
165 | + */ |
|
166 | + var $_inComment = false; |
|
167 | + |
|
168 | + /** |
|
169 | + * Sorting order of current block/region |
|
170 | + * |
|
171 | + * @var integer |
|
172 | + * @access private |
|
173 | + */ |
|
174 | + var $_blockOrder = 0; |
|
175 | + |
|
176 | + /** |
|
177 | + * Generation errors |
|
178 | + * |
|
179 | + * @var array |
|
180 | + * @access private |
|
181 | + */ |
|
182 | + var $_errors; |
|
183 | + |
|
184 | + // }}} |
|
185 | + // {{{ constructor |
|
186 | + |
|
187 | + /** |
|
188 | + * Constructor |
|
189 | + * |
|
190 | + * @param string $syntaxFile Name of XML file |
|
191 | + * with syntax highlighting rules |
|
192 | + * |
|
193 | + * @access public |
|
194 | + */ |
|
195 | + |
|
196 | + function __construct($syntaxFile = '') |
|
197 | + { |
|
198 | + XML_Parser::XML_Parser(null, 'func'); |
|
199 | + $this->_errors = array(); |
|
200 | + $this->_declareErrorMessages(); |
|
201 | + if ($syntaxFile) { |
|
202 | + $this->setInputFile($syntaxFile); |
|
203 | + } |
|
204 | + } |
|
205 | + |
|
206 | + // }}} |
|
207 | + // {{{ _formatError |
|
208 | + |
|
209 | + /** |
|
210 | + * Format error message |
|
211 | + * |
|
212 | + * @param int $code error code |
|
213 | + * @param string $params parameters |
|
214 | + * @param string $fileName file name |
|
215 | + * @param int $lineNo line number |
|
216 | + * @return array |
|
217 | + * @access public |
|
218 | + */ |
|
219 | + function _formatError($code, $params, $fileName, $lineNo) |
|
220 | + { |
|
221 | + $template = $this->_templates[$code]; |
|
222 | + $ret = call_user_func_array('sprintf', array_merge(array($template), $params)); |
|
223 | + if ($fileName) { |
|
224 | + $ret = '[' . $fileName . '] ' . $ret; |
|
225 | + } |
|
226 | + if ($lineNo) { |
|
227 | + $ret .= ' (line ' . $lineNo . ')'; |
|
228 | + } |
|
229 | + return $ret; |
|
230 | + } |
|
231 | + |
|
232 | + // }}} |
|
233 | + // {{{ declareErrorMessages |
|
234 | + |
|
235 | + /** |
|
236 | + * Set up error message templates |
|
237 | + * |
|
238 | + * @access private |
|
239 | + */ |
|
240 | + function _declareErrorMessages() |
|
241 | + { |
|
242 | + $this->_templates = array ( |
|
243 | + TEXT_HIGHLIGHTER_EMPTY_RE => 'Empty regular expression', |
|
244 | + TEXT_HIGHLIGHTER_INVALID_RE => 'Invalid regular expression : %s', |
|
245 | + TEXT_HIGHLIGHTER_EMPTY_OR_MISSING => 'Empty or missing %s', |
|
246 | + TEXT_HIGHLIGHTER_EMPTY => 'Empty %s', |
|
247 | + TEXT_HIGHLIGHTER_REGION_REGION => 'Region %s refers undefined region %s', |
|
248 | + TEXT_HIGHLIGHTER_REGION_BLOCK => 'Region %s refers undefined block %s', |
|
249 | + TEXT_HIGHLIGHTER_BLOCK_REGION => 'Block %s refers undefined region %s', |
|
250 | + TEXT_HIGHLIGHTER_KEYWORD_BLOCK => 'Keyword group %s refers undefined block %s', |
|
251 | + TEXT_HIGHLIGHTER_KEYWORD_INHERITS => 'Keyword group %s inherits undefined block %s', |
|
252 | + TEXT_HIGHLIGHTER_PARSE => '%s', |
|
253 | + TEXT_HIGHLIGHTER_FILE_WRITE => 'Error writing file %s', |
|
254 | + TEXT_HIGHLIGHTER_FILE_READ => '%s' |
|
255 | + ); |
|
256 | + } |
|
257 | + |
|
258 | + // }}} |
|
259 | + // {{{ setInputFile |
|
260 | + |
|
261 | + /** |
|
262 | + * Sets the input xml file to be parsed |
|
263 | + * |
|
264 | + * @param string Filename (full path) |
|
265 | + * @return boolean |
|
266 | + * @access public |
|
267 | + */ |
|
268 | + function setInputFile($file) |
|
269 | + { |
|
270 | + $this->_syntaxFile = $file; |
|
271 | + $ret = parent::setInputFile($file); |
|
272 | + if (PEAR::isError($ret)) { |
|
273 | + $this->_error(TEXT_HIGHLIGHTER_FILE_READ, $ret->message); |
|
274 | + return false; |
|
275 | + } |
|
276 | + return true; |
|
277 | + } |
|
278 | + |
|
279 | + // }}} |
|
280 | + // {{{ generate |
|
281 | + |
|
282 | + /** |
|
283 | + * Generates class code |
|
284 | + * |
|
285 | + * @access public |
|
286 | + */ |
|
287 | + |
|
288 | + function generate() |
|
289 | + { |
|
290 | + $this->_regions = array(); |
|
291 | + $this->_blocks = array(); |
|
292 | + $this->_keywords = array(); |
|
293 | + $this->language = ''; |
|
294 | + $this->_code = ''; |
|
295 | + $this->_defClass = 'default'; |
|
296 | + $this->_comment = ''; |
|
297 | + $this->_inComment = false; |
|
298 | + $this->_authors = array(); |
|
299 | + $this->_blockOrder = 0; |
|
300 | + $this->_errors = array(); |
|
301 | + |
|
302 | + $ret = $this->parse(); |
|
303 | + if (PEAR::isError($ret)) { |
|
304 | + $this->_error(TEXT_HIGHLIGHTER_PARSE, $ret->message); |
|
305 | + return false; |
|
306 | + } |
|
307 | + return true; |
|
308 | + } |
|
309 | + |
|
310 | + // }}} |
|
311 | + // {{{ getCode |
|
312 | + |
|
313 | + /** |
|
314 | + * Returns generated code as a string. |
|
315 | + * |
|
316 | + * @return string Generated code |
|
317 | + * @access public |
|
318 | + */ |
|
319 | + |
|
320 | + function getCode() |
|
321 | + { |
|
322 | + return $this->_code; |
|
323 | + } |
|
324 | + |
|
325 | + // }}} |
|
326 | + // {{{ saveCode |
|
327 | + |
|
328 | + /** |
|
329 | + * Saves generated class to file. Note that {@link Text_Highlighter::factory()} |
|
330 | + * assumes that filename is uppercase (SQL.php, DTD.php, etc), and file |
|
331 | + * is located in Text/Highlighter |
|
332 | + * |
|
333 | + * @param string $filename Name of file to write the code to |
|
334 | + * @return boolean true on success, false on failure |
|
335 | + * @access public |
|
336 | + */ |
|
337 | + |
|
338 | + function saveCode($filename) |
|
339 | + { |
|
340 | + $f = @fopen($filename, 'wb'); |
|
341 | + if (!$f) { |
|
342 | + $this->_error(TEXT_HIGHLIGHTER_FILE_WRITE, array('outfile'=>$filename)); |
|
343 | + return false; |
|
344 | + } |
|
345 | + fwrite ($f, $this->_code); |
|
346 | + fclose($f); |
|
347 | + return true; |
|
348 | + } |
|
349 | + |
|
350 | + // }}} |
|
351 | + // {{{ hasErrors |
|
352 | + |
|
353 | + /** |
|
354 | + * Reports if there were errors |
|
355 | + * |
|
356 | + * @return boolean |
|
357 | + * @access public |
|
358 | + */ |
|
359 | + |
|
360 | + function hasErrors() |
|
361 | + { |
|
362 | + return count($this->_errors) > 0; |
|
363 | + } |
|
364 | + |
|
365 | + // }}} |
|
366 | + // {{{ getErrors |
|
367 | + |
|
368 | + /** |
|
369 | + * Returns errors |
|
370 | + * |
|
371 | + * @return array |
|
372 | + * @access public |
|
373 | + */ |
|
374 | + |
|
375 | + function getErrors() |
|
376 | + { |
|
377 | + return $this->_errors; |
|
378 | + } |
|
379 | + |
|
380 | + // }}} |
|
381 | + // {{{ _sortBlocks |
|
382 | + |
|
383 | + /** |
|
384 | + * Sorts blocks |
|
385 | + * |
|
386 | + * @access private |
|
387 | + */ |
|
388 | + |
|
389 | + function _sortBlocks($b1, $b2) { |
|
390 | + return $b1['order'] - $b2['order']; |
|
391 | + } |
|
392 | + |
|
393 | + // }}} |
|
394 | + // {{{ _sortLookFor |
|
395 | + /** |
|
396 | + * Sort 'look for' list |
|
397 | + * @return int |
|
398 | + * @param string $b1 |
|
399 | + * @param string $b2 |
|
400 | + */ |
|
401 | + function _sortLookFor($b1, $b2) { |
|
402 | + $o1 = isset($this->_blocks[$b1]) ? $this->_blocks[$b1]['order'] : $this->_regions[$b1]['order']; |
|
403 | + $o2 = isset($this->_blocks[$b2]) ? $this->_blocks[$b2]['order'] : $this->_regions[$b2]['order']; |
|
404 | + return $o1 - $o2; |
|
405 | + } |
|
406 | + |
|
407 | + // }}} |
|
408 | + // {{{ _makeRE |
|
409 | + |
|
410 | + /** |
|
411 | + * Adds delimiters and modifiers to regular expression if necessary |
|
412 | + * |
|
413 | + * @param string $text Original RE |
|
414 | + * @return string Final RE |
|
415 | + * @access private |
|
416 | + */ |
|
417 | + function _makeRE($text, $case = false) |
|
418 | + { |
|
419 | + if (!strlen($text)) { |
|
420 | + $this->_error(TEXT_HIGHLIGHTER_EMPTY_RE); |
|
421 | + } |
|
422 | + if (!strlen($text) || $text{0} != '/') { |
|
423 | + $text = '/' . $text . '/'; |
|
424 | + } |
|
425 | + if (!$case) { |
|
426 | + $text .= 'i'; |
|
427 | + } |
|
428 | + $php_errormsg = ''; |
|
429 | + @preg_match($text, ''); |
|
430 | + if ($php_errormsg) { |
|
431 | + $this->_error(TEXT_HIGHLIGHTER_INVALID_RE, $php_errormsg); |
|
432 | + } |
|
433 | + preg_match ('#^/(.+)/(.*)$#', $text, $m); |
|
434 | + if (@$m[2]) { |
|
435 | + $text = '(?' . $m[2] . ')' . $m[1]; |
|
436 | + } else { |
|
437 | + $text = $m[1]; |
|
438 | + } |
|
439 | + return $text; |
|
440 | + } |
|
441 | + |
|
442 | + // }}} |
|
443 | + // {{{ _exportArray |
|
444 | + |
|
445 | + /** |
|
446 | + * Exports array as PHP code |
|
447 | + * |
|
448 | + * @param array $array |
|
449 | + * @return string Code |
|
450 | + * @access private |
|
451 | + */ |
|
452 | + function _exportArray($array) |
|
453 | + { |
|
454 | + $array = var_export($array, true); |
|
455 | + return trim(preg_replace('~^(\s*)~m',' \1\1',$array)); |
|
456 | + } |
|
457 | + |
|
458 | + // }}} |
|
459 | + // {{{ _countSubpatterns |
|
460 | + /** |
|
461 | + * Find number of capturing suppaterns in regular expression |
|
462 | + * @return int |
|
463 | + * @param string $re Regular expression (without delimiters) |
|
464 | + */ |
|
465 | + function _countSubpatterns($re) |
|
466 | + { |
|
467 | + preg_match_all('/' . $re . '/', '', $m); |
|
468 | + return count($m)-1; |
|
469 | + } |
|
470 | + |
|
471 | + // }}} |
|
472 | + |
|
473 | + /**#@+ |
|
474 | 474 | * @access private |
475 | 475 | * @param resource $xp XML parser resource |
476 | 476 | * @param string $elem XML element name |
477 | 477 | * @param array $attribs XML element attributes |
478 | 478 | */ |
479 | 479 | |
480 | - // {{{ xmltag_Default |
|
481 | - |
|
482 | - /** |
|
483 | - * start handler for <default> element |
|
484 | - */ |
|
485 | - function xmltag_Default($xp, $elem, $attribs) |
|
486 | - { |
|
487 | - $this->_aliasAttributes($attribs); |
|
488 | - if (!isset($attribs['innerGroup']) || $attribs['innerGroup'] === '') { |
|
489 | - $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'innerGroup'); |
|
490 | - } |
|
491 | - $this->_defClass = @$attribs['innerGroup']; |
|
492 | - } |
|
493 | - |
|
494 | - // }}} |
|
495 | - // {{{ xmltag_Region |
|
496 | - |
|
497 | - /** |
|
498 | - * start handler for <region> element |
|
499 | - */ |
|
500 | - function xmltag_Region($xp, $elem, $attribs) |
|
501 | - { |
|
502 | - $this->_aliasAttributes($attribs); |
|
503 | - if (!isset($attribs['name']) || $attribs['name'] === '') { |
|
504 | - $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'region name'); |
|
505 | - } |
|
506 | - if (!isset($attribs['innerGroup']) || $attribs['innerGroup'] === '') { |
|
507 | - $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'innerGroup'); |
|
508 | - } |
|
509 | - $this->_element = array('name' => $attribs['name']); |
|
510 | - $this->_element['line'] = xml_get_current_line_number($this->parser); |
|
511 | - if (isset($attribs['case'])) { |
|
512 | - $this->_element['case'] = $attribs['case'] == 'yes'; |
|
513 | - } else { |
|
514 | - $this->_element['case'] = $this->_case; |
|
515 | - } |
|
516 | - $this->_element['innerGroup'] = $attribs['innerGroup']; |
|
517 | - $this->_element['delimGroup'] = isset($attribs['delimGroup']) ? |
|
518 | - $attribs['delimGroup'] : |
|
519 | - $attribs['innerGroup']; |
|
520 | - $this->_element['start'] = $this->_makeRE(@$attribs['start'], $this->_element['case']); |
|
521 | - $this->_element['end'] = $this->_makeRE(@$attribs['end'], $this->_element['case']); |
|
522 | - $this->_element['contained'] = @$attribs['contained'] == 'yes'; |
|
523 | - $this->_element['never-contained'] = @$attribs['never-contained'] == 'yes'; |
|
524 | - $this->_element['remember'] = @$attribs['remember'] == 'yes'; |
|
525 | - if (isset($attribs['startBOL']) && $attribs['startBOL'] == 'yes') { |
|
526 | - $this->_element['startBOL'] = true; |
|
527 | - } |
|
528 | - if (isset($attribs['endBOL']) && $attribs['endBOL'] == 'yes') { |
|
529 | - $this->_element['endBOL'] = true; |
|
530 | - } |
|
531 | - if (isset($attribs['neverAfter'])) { |
|
532 | - $this->_element['neverafter'] = $this->_makeRE($attribs['neverAfter']); |
|
533 | - } |
|
534 | - } |
|
535 | - |
|
536 | - // }}} |
|
537 | - // {{{ xmltag_Block |
|
538 | - |
|
539 | - /** |
|
540 | - * start handler for <block> element |
|
541 | - */ |
|
542 | - function xmltag_Block($xp, $elem, $attribs) |
|
543 | - { |
|
544 | - $this->_aliasAttributes($attribs); |
|
545 | - if (!isset($attribs['name']) || $attribs['name'] === '') { |
|
546 | - $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'block name'); |
|
547 | - } |
|
548 | - if (isset($attribs['innerGroup']) && $attribs['innerGroup'] === '') { |
|
549 | - $this->_error(TEXT_HIGHLIGHTER_EMPTY, 'innerGroup'); |
|
550 | - } |
|
551 | - $this->_element = array('name' => $attribs['name']); |
|
552 | - $this->_element['line'] = xml_get_current_line_number($this->parser); |
|
553 | - if (isset($attribs['case'])) { |
|
554 | - $this->_element['case'] = $attribs['case'] == 'yes'; |
|
555 | - } else { |
|
556 | - $this->_element['case'] = $this->_case; |
|
557 | - } |
|
558 | - if (isset($attribs['innerGroup'])) { |
|
559 | - $this->_element['innerGroup'] = @$attribs['innerGroup']; |
|
560 | - } |
|
561 | - $this->_element['match'] = $this->_makeRE($attribs['match'], $this->_element['case']); |
|
562 | - $this->_element['contained'] = @$attribs['contained'] == 'yes'; |
|
563 | - $this->_element['multiline'] = @$attribs['multiline'] == 'yes'; |
|
564 | - if (isset($attribs['BOL']) && $attribs['BOL'] == 'yes') { |
|
565 | - $this->_element['BOL'] = true; |
|
566 | - } |
|
567 | - if (isset($attribs['neverAfter'])) { |
|
568 | - $this->_element['neverafter'] = $this->_makeRE($attribs['neverAfter']); |
|
569 | - } |
|
570 | - } |
|
571 | - |
|
572 | - // }}} |
|
573 | - // {{{ cdataHandler |
|
574 | - |
|
575 | - /** |
|
576 | - * Character data handler. Used for comment |
|
577 | - */ |
|
578 | - function cdataHandler($xp, $cdata) |
|
579 | - { |
|
580 | - if ($this->_inComment) { |
|
581 | - $this->_comment .= $cdata; |
|
582 | - } |
|
583 | - } |
|
584 | - |
|
585 | - // }}} |
|
586 | - // {{{ xmltag_Comment |
|
587 | - |
|
588 | - /** |
|
589 | - * start handler for <comment> element |
|
590 | - */ |
|
591 | - function xmltag_Comment($xp, $elem, $attribs) |
|
592 | - { |
|
593 | - $this->_comment = ''; |
|
594 | - $this->_inComment = true; |
|
595 | - } |
|
596 | - |
|
597 | - // }}} |
|
598 | - // {{{ xmltag_PartGroup |
|
599 | - |
|
600 | - /** |
|
601 | - * start handler for <partgroup> element |
|
602 | - */ |
|
603 | - function xmltag_PartGroup($xp, $elem, $attribs) |
|
604 | - { |
|
605 | - $this->_aliasAttributes($attribs); |
|
606 | - if (!isset($attribs['innerGroup']) || $attribs['innerGroup'] === '') { |
|
607 | - $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'innerGroup'); |
|
608 | - } |
|
609 | - $this->_element['partClass'][$attribs['index']] = @$attribs['innerGroup']; |
|
610 | - } |
|
611 | - |
|
612 | - // }}} |
|
613 | - // {{{ xmltag_PartClass |
|
614 | - |
|
615 | - /** |
|
616 | - * start handler for <partclass> element |
|
617 | - */ |
|
618 | - function xmltag_PartClass($xp, $elem, $attribs) |
|
619 | - { |
|
620 | - $this->xmltag_PartGroup($xp, $elem, $attribs); |
|
621 | - } |
|
622 | - |
|
623 | - // }}} |
|
624 | - // {{{ xmltag_Keywords |
|
625 | - |
|
626 | - /** |
|
627 | - * start handler for <keywords> element |
|
628 | - */ |
|
629 | - function xmltag_Keywords($xp, $elem, $attribs) |
|
630 | - { |
|
631 | - $this->_aliasAttributes($attribs); |
|
632 | - if (!isset($attribs['name']) || $attribs['name'] === '') { |
|
633 | - $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'keyword group name'); |
|
634 | - } |
|
635 | - if (!isset($attribs['innerGroup']) || $attribs['innerGroup'] === '') { |
|
636 | - $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'innerGroup'); |
|
637 | - } |
|
638 | - if (!isset($attribs['inherits']) || $attribs['inherits'] === '') { |
|
639 | - $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'inherits'); |
|
640 | - } |
|
641 | - $this->_element = array('name'=>@$attribs['name']); |
|
642 | - $this->_element['line'] = xml_get_current_line_number($this->parser); |
|
643 | - $this->_element['innerGroup'] = @$attribs['innerGroup']; |
|
644 | - if (isset($attribs['case'])) { |
|
645 | - $this->_element['case'] = $attribs['case'] == 'yes'; |
|
646 | - } else { |
|
647 | - $this->_element['case'] = $this->_case; |
|
648 | - } |
|
649 | - $this->_element['inherits'] = @$attribs['inherits']; |
|
650 | - if (isset($attribs['otherwise'])) { |
|
651 | - $this->_element['otherwise'] = $attribs['otherwise']; |
|
652 | - } |
|
653 | - if (isset($attribs['ifdef'])) { |
|
654 | - $this->_element['ifdef'] = $attribs['ifdef']; |
|
655 | - } |
|
656 | - if (isset($attribs['ifndef'])) { |
|
657 | - $this->_element['ifndef'] = $attribs['ifndef']; |
|
658 | - } |
|
659 | - } |
|
660 | - |
|
661 | - // }}} |
|
662 | - // {{{ xmltag_Keyword |
|
663 | - |
|
664 | - /** |
|
665 | - * start handler for <keyword> element |
|
666 | - */ |
|
667 | - function xmltag_Keyword($xp, $elem, $attribs) |
|
668 | - { |
|
669 | - if (!isset($attribs['match']) || $attribs['match'] === '') { |
|
670 | - $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'match'); |
|
671 | - } |
|
672 | - $keyword = @$attribs['match']; |
|
673 | - if (!$this->_element['case']) { |
|
674 | - $keyword = strtolower($keyword); |
|
675 | - } |
|
676 | - $this->_element['match'][$keyword] = true; |
|
677 | - } |
|
678 | - |
|
679 | - // }}} |
|
680 | - // {{{ xmltag_Contains |
|
681 | - |
|
682 | - /** |
|
683 | - * start handler for <contains> element |
|
684 | - */ |
|
685 | - function xmltag_Contains($xp, $elem, $attribs) |
|
686 | - { |
|
687 | - $this->_element['contains-all'] = @$attribs['all'] == 'yes'; |
|
688 | - if (isset($attribs['region'])) { |
|
689 | - $this->_element['contains']['region'][$attribs['region']] = |
|
690 | - xml_get_current_line_number($this->parser); |
|
691 | - } |
|
692 | - if (isset($attribs['block'])) { |
|
693 | - $this->_element['contains']['block'][$attribs['block']] = |
|
694 | - xml_get_current_line_number($this->parser); |
|
695 | - } |
|
696 | - } |
|
697 | - |
|
698 | - // }}} |
|
699 | - // {{{ xmltag_But |
|
700 | - |
|
701 | - /** |
|
702 | - * start handler for <but> element |
|
703 | - */ |
|
704 | - function xmltag_But($xp, $elem, $attribs) |
|
705 | - { |
|
706 | - if (isset($attribs['region'])) { |
|
707 | - $this->_element['not-contains']['region'][$attribs['region']] = true; |
|
708 | - } |
|
709 | - if (isset($attribs['block'])) { |
|
710 | - $this->_element['not-contains']['block'][$attribs['block']] = true; |
|
711 | - } |
|
712 | - } |
|
713 | - |
|
714 | - // }}} |
|
715 | - // {{{ xmltag_Onlyin |
|
716 | - |
|
717 | - /** |
|
718 | - * start handler for <onlyin> element |
|
719 | - */ |
|
720 | - function xmltag_Onlyin($xp, $elem, $attribs) |
|
721 | - { |
|
722 | - if (!isset($attribs['region']) || $attribs['region'] === '') { |
|
723 | - $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'region'); |
|
724 | - } |
|
725 | - $this->_element['onlyin'][$attribs['region']] = xml_get_current_line_number($this->parser); |
|
726 | - } |
|
727 | - |
|
728 | - // }}} |
|
729 | - // {{{ xmltag_Author |
|
730 | - |
|
731 | - /** |
|
732 | - * start handler for <author> element |
|
733 | - */ |
|
734 | - function xmltag_Author($xp, $elem, $attribs) |
|
735 | - { |
|
736 | - if (!isset($attribs['name']) || $attribs['name'] === '') { |
|
737 | - $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'author name'); |
|
738 | - } |
|
739 | - $this->_authors[] = array( |
|
740 | - 'name' => @$attribs['name'], |
|
741 | - 'email' => (string)@$attribs['email'] |
|
742 | - ); |
|
743 | - } |
|
744 | - |
|
745 | - // }}} |
|
746 | - // {{{ xmltag_Highlight |
|
747 | - |
|
748 | - /** |
|
749 | - * start handler for <highlight> element |
|
750 | - */ |
|
751 | - function xmltag_Highlight($xp, $elem, $attribs) |
|
752 | - { |
|
753 | - if (!isset($attribs['lang']) || $attribs['lang'] === '') { |
|
754 | - $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'language name'); |
|
755 | - } |
|
756 | - $this->_code = ''; |
|
757 | - $this->language = strtoupper(@$attribs['lang']); |
|
758 | - $this->_case = @$attribs['case'] == 'yes'; |
|
759 | - } |
|
760 | - |
|
761 | - // }}} |
|
762 | - |
|
763 | - /**#@-*/ |
|
764 | - |
|
765 | - // {{{ _error |
|
766 | - |
|
767 | - /** |
|
768 | - * Add an error message |
|
769 | - * |
|
770 | - * @param integer $code Error code |
|
771 | - * @param mixed $message Error message or array with error message parameters |
|
772 | - * @param integer $lineNo Source code line number |
|
773 | - * @access private |
|
774 | - */ |
|
775 | - function _error($code, $params = array(), $lineNo = 0) |
|
776 | - { |
|
777 | - if (!$lineNo && !empty($this->parser)) { |
|
778 | - $lineNo = xml_get_current_line_number($this->parser); |
|
779 | - } |
|
780 | - $this->_errors[] = $this->_formatError($code, $params, $this->_syntaxFile, $lineNo); |
|
781 | - } |
|
782 | - |
|
783 | - // }}} |
|
784 | - // {{{ _aliasAttributes |
|
785 | - |
|
786 | - /** |
|
787 | - * BC trick |
|
788 | - * |
|
789 | - * @param array $attrs attributes |
|
790 | - */ |
|
791 | - function _aliasAttributes(&$attrs) |
|
792 | - { |
|
793 | - if (isset($attrs['innerClass']) && !isset($attrs['innerGroup'])) { |
|
794 | - $attrs['innerGroup'] = $attrs['innerClass']; |
|
795 | - } |
|
796 | - if (isset($attrs['delimClass']) && !isset($attrs['delimGroup'])) { |
|
797 | - $attrs['delimGroup'] = $attrs['delimClass']; |
|
798 | - } |
|
799 | - if (isset($attrs['partClass']) && !isset($attrs['partGroup'])) { |
|
800 | - $attrs['partGroup'] = $attrs['partClass']; |
|
801 | - } |
|
802 | - } |
|
803 | - |
|
804 | - // }}} |
|
805 | - |
|
806 | - /**#@+ |
|
480 | + // {{{ xmltag_Default |
|
481 | + |
|
482 | + /** |
|
483 | + * start handler for <default> element |
|
484 | + */ |
|
485 | + function xmltag_Default($xp, $elem, $attribs) |
|
486 | + { |
|
487 | + $this->_aliasAttributes($attribs); |
|
488 | + if (!isset($attribs['innerGroup']) || $attribs['innerGroup'] === '') { |
|
489 | + $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'innerGroup'); |
|
490 | + } |
|
491 | + $this->_defClass = @$attribs['innerGroup']; |
|
492 | + } |
|
493 | + |
|
494 | + // }}} |
|
495 | + // {{{ xmltag_Region |
|
496 | + |
|
497 | + /** |
|
498 | + * start handler for <region> element |
|
499 | + */ |
|
500 | + function xmltag_Region($xp, $elem, $attribs) |
|
501 | + { |
|
502 | + $this->_aliasAttributes($attribs); |
|
503 | + if (!isset($attribs['name']) || $attribs['name'] === '') { |
|
504 | + $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'region name'); |
|
505 | + } |
|
506 | + if (!isset($attribs['innerGroup']) || $attribs['innerGroup'] === '') { |
|
507 | + $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'innerGroup'); |
|
508 | + } |
|
509 | + $this->_element = array('name' => $attribs['name']); |
|
510 | + $this->_element['line'] = xml_get_current_line_number($this->parser); |
|
511 | + if (isset($attribs['case'])) { |
|
512 | + $this->_element['case'] = $attribs['case'] == 'yes'; |
|
513 | + } else { |
|
514 | + $this->_element['case'] = $this->_case; |
|
515 | + } |
|
516 | + $this->_element['innerGroup'] = $attribs['innerGroup']; |
|
517 | + $this->_element['delimGroup'] = isset($attribs['delimGroup']) ? |
|
518 | + $attribs['delimGroup'] : |
|
519 | + $attribs['innerGroup']; |
|
520 | + $this->_element['start'] = $this->_makeRE(@$attribs['start'], $this->_element['case']); |
|
521 | + $this->_element['end'] = $this->_makeRE(@$attribs['end'], $this->_element['case']); |
|
522 | + $this->_element['contained'] = @$attribs['contained'] == 'yes'; |
|
523 | + $this->_element['never-contained'] = @$attribs['never-contained'] == 'yes'; |
|
524 | + $this->_element['remember'] = @$attribs['remember'] == 'yes'; |
|
525 | + if (isset($attribs['startBOL']) && $attribs['startBOL'] == 'yes') { |
|
526 | + $this->_element['startBOL'] = true; |
|
527 | + } |
|
528 | + if (isset($attribs['endBOL']) && $attribs['endBOL'] == 'yes') { |
|
529 | + $this->_element['endBOL'] = true; |
|
530 | + } |
|
531 | + if (isset($attribs['neverAfter'])) { |
|
532 | + $this->_element['neverafter'] = $this->_makeRE($attribs['neverAfter']); |
|
533 | + } |
|
534 | + } |
|
535 | + |
|
536 | + // }}} |
|
537 | + // {{{ xmltag_Block |
|
538 | + |
|
539 | + /** |
|
540 | + * start handler for <block> element |
|
541 | + */ |
|
542 | + function xmltag_Block($xp, $elem, $attribs) |
|
543 | + { |
|
544 | + $this->_aliasAttributes($attribs); |
|
545 | + if (!isset($attribs['name']) || $attribs['name'] === '') { |
|
546 | + $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'block name'); |
|
547 | + } |
|
548 | + if (isset($attribs['innerGroup']) && $attribs['innerGroup'] === '') { |
|
549 | + $this->_error(TEXT_HIGHLIGHTER_EMPTY, 'innerGroup'); |
|
550 | + } |
|
551 | + $this->_element = array('name' => $attribs['name']); |
|
552 | + $this->_element['line'] = xml_get_current_line_number($this->parser); |
|
553 | + if (isset($attribs['case'])) { |
|
554 | + $this->_element['case'] = $attribs['case'] == 'yes'; |
|
555 | + } else { |
|
556 | + $this->_element['case'] = $this->_case; |
|
557 | + } |
|
558 | + if (isset($attribs['innerGroup'])) { |
|
559 | + $this->_element['innerGroup'] = @$attribs['innerGroup']; |
|
560 | + } |
|
561 | + $this->_element['match'] = $this->_makeRE($attribs['match'], $this->_element['case']); |
|
562 | + $this->_element['contained'] = @$attribs['contained'] == 'yes'; |
|
563 | + $this->_element['multiline'] = @$attribs['multiline'] == 'yes'; |
|
564 | + if (isset($attribs['BOL']) && $attribs['BOL'] == 'yes') { |
|
565 | + $this->_element['BOL'] = true; |
|
566 | + } |
|
567 | + if (isset($attribs['neverAfter'])) { |
|
568 | + $this->_element['neverafter'] = $this->_makeRE($attribs['neverAfter']); |
|
569 | + } |
|
570 | + } |
|
571 | + |
|
572 | + // }}} |
|
573 | + // {{{ cdataHandler |
|
574 | + |
|
575 | + /** |
|
576 | + * Character data handler. Used for comment |
|
577 | + */ |
|
578 | + function cdataHandler($xp, $cdata) |
|
579 | + { |
|
580 | + if ($this->_inComment) { |
|
581 | + $this->_comment .= $cdata; |
|
582 | + } |
|
583 | + } |
|
584 | + |
|
585 | + // }}} |
|
586 | + // {{{ xmltag_Comment |
|
587 | + |
|
588 | + /** |
|
589 | + * start handler for <comment> element |
|
590 | + */ |
|
591 | + function xmltag_Comment($xp, $elem, $attribs) |
|
592 | + { |
|
593 | + $this->_comment = ''; |
|
594 | + $this->_inComment = true; |
|
595 | + } |
|
596 | + |
|
597 | + // }}} |
|
598 | + // {{{ xmltag_PartGroup |
|
599 | + |
|
600 | + /** |
|
601 | + * start handler for <partgroup> element |
|
602 | + */ |
|
603 | + function xmltag_PartGroup($xp, $elem, $attribs) |
|
604 | + { |
|
605 | + $this->_aliasAttributes($attribs); |
|
606 | + if (!isset($attribs['innerGroup']) || $attribs['innerGroup'] === '') { |
|
607 | + $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'innerGroup'); |
|
608 | + } |
|
609 | + $this->_element['partClass'][$attribs['index']] = @$attribs['innerGroup']; |
|
610 | + } |
|
611 | + |
|
612 | + // }}} |
|
613 | + // {{{ xmltag_PartClass |
|
614 | + |
|
615 | + /** |
|
616 | + * start handler for <partclass> element |
|
617 | + */ |
|
618 | + function xmltag_PartClass($xp, $elem, $attribs) |
|
619 | + { |
|
620 | + $this->xmltag_PartGroup($xp, $elem, $attribs); |
|
621 | + } |
|
622 | + |
|
623 | + // }}} |
|
624 | + // {{{ xmltag_Keywords |
|
625 | + |
|
626 | + /** |
|
627 | + * start handler for <keywords> element |
|
628 | + */ |
|
629 | + function xmltag_Keywords($xp, $elem, $attribs) |
|
630 | + { |
|
631 | + $this->_aliasAttributes($attribs); |
|
632 | + if (!isset($attribs['name']) || $attribs['name'] === '') { |
|
633 | + $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'keyword group name'); |
|
634 | + } |
|
635 | + if (!isset($attribs['innerGroup']) || $attribs['innerGroup'] === '') { |
|
636 | + $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'innerGroup'); |
|
637 | + } |
|
638 | + if (!isset($attribs['inherits']) || $attribs['inherits'] === '') { |
|
639 | + $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'inherits'); |
|
640 | + } |
|
641 | + $this->_element = array('name'=>@$attribs['name']); |
|
642 | + $this->_element['line'] = xml_get_current_line_number($this->parser); |
|
643 | + $this->_element['innerGroup'] = @$attribs['innerGroup']; |
|
644 | + if (isset($attribs['case'])) { |
|
645 | + $this->_element['case'] = $attribs['case'] == 'yes'; |
|
646 | + } else { |
|
647 | + $this->_element['case'] = $this->_case; |
|
648 | + } |
|
649 | + $this->_element['inherits'] = @$attribs['inherits']; |
|
650 | + if (isset($attribs['otherwise'])) { |
|
651 | + $this->_element['otherwise'] = $attribs['otherwise']; |
|
652 | + } |
|
653 | + if (isset($attribs['ifdef'])) { |
|
654 | + $this->_element['ifdef'] = $attribs['ifdef']; |
|
655 | + } |
|
656 | + if (isset($attribs['ifndef'])) { |
|
657 | + $this->_element['ifndef'] = $attribs['ifndef']; |
|
658 | + } |
|
659 | + } |
|
660 | + |
|
661 | + // }}} |
|
662 | + // {{{ xmltag_Keyword |
|
663 | + |
|
664 | + /** |
|
665 | + * start handler for <keyword> element |
|
666 | + */ |
|
667 | + function xmltag_Keyword($xp, $elem, $attribs) |
|
668 | + { |
|
669 | + if (!isset($attribs['match']) || $attribs['match'] === '') { |
|
670 | + $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'match'); |
|
671 | + } |
|
672 | + $keyword = @$attribs['match']; |
|
673 | + if (!$this->_element['case']) { |
|
674 | + $keyword = strtolower($keyword); |
|
675 | + } |
|
676 | + $this->_element['match'][$keyword] = true; |
|
677 | + } |
|
678 | + |
|
679 | + // }}} |
|
680 | + // {{{ xmltag_Contains |
|
681 | + |
|
682 | + /** |
|
683 | + * start handler for <contains> element |
|
684 | + */ |
|
685 | + function xmltag_Contains($xp, $elem, $attribs) |
|
686 | + { |
|
687 | + $this->_element['contains-all'] = @$attribs['all'] == 'yes'; |
|
688 | + if (isset($attribs['region'])) { |
|
689 | + $this->_element['contains']['region'][$attribs['region']] = |
|
690 | + xml_get_current_line_number($this->parser); |
|
691 | + } |
|
692 | + if (isset($attribs['block'])) { |
|
693 | + $this->_element['contains']['block'][$attribs['block']] = |
|
694 | + xml_get_current_line_number($this->parser); |
|
695 | + } |
|
696 | + } |
|
697 | + |
|
698 | + // }}} |
|
699 | + // {{{ xmltag_But |
|
700 | + |
|
701 | + /** |
|
702 | + * start handler for <but> element |
|
703 | + */ |
|
704 | + function xmltag_But($xp, $elem, $attribs) |
|
705 | + { |
|
706 | + if (isset($attribs['region'])) { |
|
707 | + $this->_element['not-contains']['region'][$attribs['region']] = true; |
|
708 | + } |
|
709 | + if (isset($attribs['block'])) { |
|
710 | + $this->_element['not-contains']['block'][$attribs['block']] = true; |
|
711 | + } |
|
712 | + } |
|
713 | + |
|
714 | + // }}} |
|
715 | + // {{{ xmltag_Onlyin |
|
716 | + |
|
717 | + /** |
|
718 | + * start handler for <onlyin> element |
|
719 | + */ |
|
720 | + function xmltag_Onlyin($xp, $elem, $attribs) |
|
721 | + { |
|
722 | + if (!isset($attribs['region']) || $attribs['region'] === '') { |
|
723 | + $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'region'); |
|
724 | + } |
|
725 | + $this->_element['onlyin'][$attribs['region']] = xml_get_current_line_number($this->parser); |
|
726 | + } |
|
727 | + |
|
728 | + // }}} |
|
729 | + // {{{ xmltag_Author |
|
730 | + |
|
731 | + /** |
|
732 | + * start handler for <author> element |
|
733 | + */ |
|
734 | + function xmltag_Author($xp, $elem, $attribs) |
|
735 | + { |
|
736 | + if (!isset($attribs['name']) || $attribs['name'] === '') { |
|
737 | + $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'author name'); |
|
738 | + } |
|
739 | + $this->_authors[] = array( |
|
740 | + 'name' => @$attribs['name'], |
|
741 | + 'email' => (string)@$attribs['email'] |
|
742 | + ); |
|
743 | + } |
|
744 | + |
|
745 | + // }}} |
|
746 | + // {{{ xmltag_Highlight |
|
747 | + |
|
748 | + /** |
|
749 | + * start handler for <highlight> element |
|
750 | + */ |
|
751 | + function xmltag_Highlight($xp, $elem, $attribs) |
|
752 | + { |
|
753 | + if (!isset($attribs['lang']) || $attribs['lang'] === '') { |
|
754 | + $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'language name'); |
|
755 | + } |
|
756 | + $this->_code = ''; |
|
757 | + $this->language = strtoupper(@$attribs['lang']); |
|
758 | + $this->_case = @$attribs['case'] == 'yes'; |
|
759 | + } |
|
760 | + |
|
761 | + // }}} |
|
762 | + |
|
763 | + /**#@-*/ |
|
764 | + |
|
765 | + // {{{ _error |
|
766 | + |
|
767 | + /** |
|
768 | + * Add an error message |
|
769 | + * |
|
770 | + * @param integer $code Error code |
|
771 | + * @param mixed $message Error message or array with error message parameters |
|
772 | + * @param integer $lineNo Source code line number |
|
773 | + * @access private |
|
774 | + */ |
|
775 | + function _error($code, $params = array(), $lineNo = 0) |
|
776 | + { |
|
777 | + if (!$lineNo && !empty($this->parser)) { |
|
778 | + $lineNo = xml_get_current_line_number($this->parser); |
|
779 | + } |
|
780 | + $this->_errors[] = $this->_formatError($code, $params, $this->_syntaxFile, $lineNo); |
|
781 | + } |
|
782 | + |
|
783 | + // }}} |
|
784 | + // {{{ _aliasAttributes |
|
785 | + |
|
786 | + /** |
|
787 | + * BC trick |
|
788 | + * |
|
789 | + * @param array $attrs attributes |
|
790 | + */ |
|
791 | + function _aliasAttributes(&$attrs) |
|
792 | + { |
|
793 | + if (isset($attrs['innerClass']) && !isset($attrs['innerGroup'])) { |
|
794 | + $attrs['innerGroup'] = $attrs['innerClass']; |
|
795 | + } |
|
796 | + if (isset($attrs['delimClass']) && !isset($attrs['delimGroup'])) { |
|
797 | + $attrs['delimGroup'] = $attrs['delimClass']; |
|
798 | + } |
|
799 | + if (isset($attrs['partClass']) && !isset($attrs['partGroup'])) { |
|
800 | + $attrs['partGroup'] = $attrs['partClass']; |
|
801 | + } |
|
802 | + } |
|
803 | + |
|
804 | + // }}} |
|
805 | + |
|
806 | + /**#@+ |
|
807 | 807 | * @access private |
808 | 808 | * @param resource $xp XML parser resource |
809 | 809 | * @param string $elem XML element name |
810 | 810 | */ |
811 | 811 | |
812 | - // {{{ xmltag_Comment_ |
|
813 | - |
|
814 | - /** |
|
815 | - * end handler for <comment> element |
|
816 | - */ |
|
817 | - function xmltag_Comment_($xp, $elem) |
|
818 | - { |
|
819 | - $this->_inComment = false; |
|
820 | - } |
|
821 | - |
|
822 | - // }}} |
|
823 | - // {{{ xmltag_Region_ |
|
824 | - |
|
825 | - /** |
|
826 | - * end handler for <region> element |
|
827 | - */ |
|
828 | - function xmltag_Region_($xp, $elem) |
|
829 | - { |
|
830 | - $this->_element['type'] = 'region'; |
|
831 | - $this->_element['order'] = $this->_blockOrder ++; |
|
832 | - $this->_regions[$this->_element['name']] = $this->_element; |
|
833 | - } |
|
834 | - |
|
835 | - // }}} |
|
836 | - // {{{ xmltag_Keywords_ |
|
837 | - |
|
838 | - /** |
|
839 | - * end handler for <keywords> element |
|
840 | - */ |
|
841 | - function xmltag_Keywords_($xp, $elem) |
|
842 | - { |
|
843 | - $this->_keywords[$this->_element['name']] = $this->_element; |
|
844 | - } |
|
845 | - |
|
846 | - // }}} |
|
847 | - // {{{ xmltag_Block_ |
|
848 | - |
|
849 | - /** |
|
850 | - * end handler for <block> element |
|
851 | - */ |
|
852 | - function xmltag_Block_($xp, $elem) |
|
853 | - { |
|
854 | - $this->_element['type'] = 'block'; |
|
855 | - $this->_element['order'] = $this->_blockOrder ++; |
|
856 | - $this->_blocks[$this->_element['name']] = $this->_element; |
|
857 | - } |
|
858 | - |
|
859 | - // }}} |
|
860 | - // {{{ xmltag_Highlight_ |
|
861 | - |
|
862 | - /** |
|
863 | - * end handler for <highlight> element |
|
864 | - */ |
|
865 | - function xmltag_Highlight_($xp, $elem) |
|
866 | - { |
|
867 | - $conditions = array(); |
|
868 | - $toplevel = array(); |
|
869 | - foreach ($this->_blocks as $i => $current) { |
|
870 | - if (!$current['contained'] && !isset($current['onlyin'])) { |
|
871 | - $toplevel[] = $i; |
|
872 | - } |
|
873 | - foreach ((array)@$current['onlyin'] as $region => $lineNo) { |
|
874 | - if (!isset($this->_regions[$region])) { |
|
875 | - $this->_error(TEXT_HIGHLIGHTER_BLOCK_REGION, |
|
876 | - array( |
|
877 | - 'block' => $current['name'], |
|
878 | - 'region' => $region |
|
879 | - )); |
|
880 | - } |
|
881 | - } |
|
882 | - } |
|
883 | - foreach ($this->_regions as $i=>$current) { |
|
884 | - if (!$current['contained'] && !isset($current['onlyin'])) { |
|
885 | - $toplevel[] = $i; |
|
886 | - } |
|
887 | - foreach ((array)@$current['contains']['region'] as $region => $lineNo) { |
|
888 | - if (!isset($this->_regions[$region])) { |
|
889 | - $this->_error(TEXT_HIGHLIGHTER_REGION_REGION, |
|
890 | - array( |
|
891 | - 'region1' => $current['name'], |
|
892 | - 'region2' => $region |
|
893 | - )); |
|
894 | - } |
|
895 | - } |
|
896 | - foreach ((array)@$current['contains']['block'] as $region => $lineNo) { |
|
897 | - if (!isset($this->_blocks[$region])) { |
|
898 | - $this->_error(TEXT_HIGHLIGHTER_REGION_BLOCK, |
|
899 | - array( |
|
900 | - 'block' => $current['name'], |
|
901 | - 'region' => $region |
|
902 | - )); |
|
903 | - } |
|
904 | - } |
|
905 | - foreach ((array)@$current['onlyin'] as $region => $lineNo) { |
|
906 | - if (!isset($this->_regions[$region])) { |
|
907 | - $this->_error(TEXT_HIGHLIGHTER_REGION_REGION, |
|
908 | - array( |
|
909 | - 'region1' => $current['name'], |
|
910 | - 'region2' => $region |
|
911 | - )); |
|
912 | - } |
|
913 | - } |
|
914 | - foreach ($this->_regions as $j => $region) { |
|
915 | - if (isset($region['onlyin'])) { |
|
916 | - $suits = isset($region['onlyin'][$current['name']]); |
|
917 | - } elseif (isset($current['not-contains']['region'][$region['name']])) { |
|
918 | - $suits = false; |
|
919 | - } elseif (isset($current['contains']['region'][$region['name']])) { |
|
920 | - $suits = true; |
|
921 | - } else { |
|
922 | - $suits = @$current['contains-all'] && @!$region['never-contained']; |
|
923 | - } |
|
924 | - if ($suits) { |
|
925 | - $this->_regions[$i]['lookfor'][] = $j; |
|
926 | - } |
|
927 | - } |
|
928 | - foreach ($this->_blocks as $j=>$region) { |
|
929 | - if (isset($region['onlyin'])) { |
|
930 | - $suits = isset($region['onlyin'][$current['name']]); |
|
931 | - } elseif (isset($current['not-contains']['block'][$region['name']])) { |
|
932 | - $suits = false; |
|
933 | - } elseif (isset($current['contains']['block'][$region['name']])) { |
|
934 | - $suits = true; |
|
935 | - } else { |
|
936 | - $suits = @$current['contains-all'] && @!$region['never-contained']; |
|
937 | - } |
|
938 | - if ($suits) { |
|
939 | - $this->_regions[$i]['lookfor'][] = $j; |
|
940 | - } |
|
941 | - } |
|
942 | - } |
|
943 | - foreach ($this->_blocks as $i=>$current) { |
|
944 | - unset ($this->_blocks[$i]['never-contained']); |
|
945 | - unset ($this->_blocks[$i]['contained']); |
|
946 | - unset ($this->_blocks[$i]['contains-all']); |
|
947 | - unset ($this->_blocks[$i]['contains']); |
|
948 | - unset ($this->_blocks[$i]['onlyin']); |
|
949 | - unset ($this->_blocks[$i]['line']); |
|
950 | - } |
|
951 | - |
|
952 | - foreach ($this->_regions as $i=>$current) { |
|
953 | - unset ($this->_regions[$i]['never-contained']); |
|
954 | - unset ($this->_regions[$i]['contained']); |
|
955 | - unset ($this->_regions[$i]['contains-all']); |
|
956 | - unset ($this->_regions[$i]['contains']); |
|
957 | - unset ($this->_regions[$i]['onlyin']); |
|
958 | - unset ($this->_regions[$i]['line']); |
|
959 | - } |
|
960 | - |
|
961 | - foreach ($this->_keywords as $name => $keyword) { |
|
962 | - if (isset($keyword['ifdef'])) { |
|
963 | - $conditions[$keyword['ifdef']][] = array($name, true); |
|
964 | - } |
|
965 | - if (isset($keyword['ifndef'])) { |
|
966 | - $conditions[$keyword['ifndef']][] = array($name, false); |
|
967 | - } |
|
968 | - unset($this->_keywords[$name]['line']); |
|
969 | - if (!isset($this->_blocks[$keyword['inherits']])) { |
|
970 | - $this->_error(TEXT_HIGHLIGHTER_KEYWORD_INHERITS, |
|
971 | - array( |
|
972 | - 'keyword' => $keyword['name'], |
|
973 | - 'block' => $keyword['inherits'] |
|
974 | - )); |
|
975 | - } |
|
976 | - if (isset($keyword['otherwise']) && !isset($this->_blocks[$keyword['otherwise']]) ) { |
|
977 | - $this->_error(TEXT_HIGHLIGHTER_KEYWORD_BLOCK, |
|
978 | - array( |
|
979 | - 'keyword' => $keyword['name'], |
|
980 | - 'block' => $keyword['inherits'] |
|
981 | - )); |
|
982 | - } |
|
983 | - } |
|
984 | - |
|
985 | - $syntax=array( |
|
986 | - 'keywords' => $this->_keywords, |
|
987 | - 'blocks' => array_merge($this->_blocks, $this->_regions), |
|
988 | - 'toplevel' => $toplevel, |
|
989 | - ); |
|
990 | - uasort($syntax['blocks'], array(&$this, '_sortBlocks')); |
|
991 | - foreach ($syntax['blocks'] as $name => $block) { |
|
992 | - if ($block['type'] == 'block') { |
|
993 | - continue; |
|
994 | - } |
|
995 | - if (is_array(@$syntax['blocks'][$name]['lookfor'])) { |
|
996 | - usort($syntax['blocks'][$name]['lookfor'], array(&$this, '_sortLookFor')); |
|
997 | - } |
|
998 | - } |
|
999 | - usort($syntax['toplevel'], array(&$this, '_sortLookFor')); |
|
1000 | - $syntax['case'] = $this->_case; |
|
1001 | - $this->_code = <<<CODE |
|
812 | + // {{{ xmltag_Comment_ |
|
813 | + |
|
814 | + /** |
|
815 | + * end handler for <comment> element |
|
816 | + */ |
|
817 | + function xmltag_Comment_($xp, $elem) |
|
818 | + { |
|
819 | + $this->_inComment = false; |
|
820 | + } |
|
821 | + |
|
822 | + // }}} |
|
823 | + // {{{ xmltag_Region_ |
|
824 | + |
|
825 | + /** |
|
826 | + * end handler for <region> element |
|
827 | + */ |
|
828 | + function xmltag_Region_($xp, $elem) |
|
829 | + { |
|
830 | + $this->_element['type'] = 'region'; |
|
831 | + $this->_element['order'] = $this->_blockOrder ++; |
|
832 | + $this->_regions[$this->_element['name']] = $this->_element; |
|
833 | + } |
|
834 | + |
|
835 | + // }}} |
|
836 | + // {{{ xmltag_Keywords_ |
|
837 | + |
|
838 | + /** |
|
839 | + * end handler for <keywords> element |
|
840 | + */ |
|
841 | + function xmltag_Keywords_($xp, $elem) |
|
842 | + { |
|
843 | + $this->_keywords[$this->_element['name']] = $this->_element; |
|
844 | + } |
|
845 | + |
|
846 | + // }}} |
|
847 | + // {{{ xmltag_Block_ |
|
848 | + |
|
849 | + /** |
|
850 | + * end handler for <block> element |
|
851 | + */ |
|
852 | + function xmltag_Block_($xp, $elem) |
|
853 | + { |
|
854 | + $this->_element['type'] = 'block'; |
|
855 | + $this->_element['order'] = $this->_blockOrder ++; |
|
856 | + $this->_blocks[$this->_element['name']] = $this->_element; |
|
857 | + } |
|
858 | + |
|
859 | + // }}} |
|
860 | + // {{{ xmltag_Highlight_ |
|
861 | + |
|
862 | + /** |
|
863 | + * end handler for <highlight> element |
|
864 | + */ |
|
865 | + function xmltag_Highlight_($xp, $elem) |
|
866 | + { |
|
867 | + $conditions = array(); |
|
868 | + $toplevel = array(); |
|
869 | + foreach ($this->_blocks as $i => $current) { |
|
870 | + if (!$current['contained'] && !isset($current['onlyin'])) { |
|
871 | + $toplevel[] = $i; |
|
872 | + } |
|
873 | + foreach ((array)@$current['onlyin'] as $region => $lineNo) { |
|
874 | + if (!isset($this->_regions[$region])) { |
|
875 | + $this->_error(TEXT_HIGHLIGHTER_BLOCK_REGION, |
|
876 | + array( |
|
877 | + 'block' => $current['name'], |
|
878 | + 'region' => $region |
|
879 | + )); |
|
880 | + } |
|
881 | + } |
|
882 | + } |
|
883 | + foreach ($this->_regions as $i=>$current) { |
|
884 | + if (!$current['contained'] && !isset($current['onlyin'])) { |
|
885 | + $toplevel[] = $i; |
|
886 | + } |
|
887 | + foreach ((array)@$current['contains']['region'] as $region => $lineNo) { |
|
888 | + if (!isset($this->_regions[$region])) { |
|
889 | + $this->_error(TEXT_HIGHLIGHTER_REGION_REGION, |
|
890 | + array( |
|
891 | + 'region1' => $current['name'], |
|
892 | + 'region2' => $region |
|
893 | + )); |
|
894 | + } |
|
895 | + } |
|
896 | + foreach ((array)@$current['contains']['block'] as $region => $lineNo) { |
|
897 | + if (!isset($this->_blocks[$region])) { |
|
898 | + $this->_error(TEXT_HIGHLIGHTER_REGION_BLOCK, |
|
899 | + array( |
|
900 | + 'block' => $current['name'], |
|
901 | + 'region' => $region |
|
902 | + )); |
|
903 | + } |
|
904 | + } |
|
905 | + foreach ((array)@$current['onlyin'] as $region => $lineNo) { |
|
906 | + if (!isset($this->_regions[$region])) { |
|
907 | + $this->_error(TEXT_HIGHLIGHTER_REGION_REGION, |
|
908 | + array( |
|
909 | + 'region1' => $current['name'], |
|
910 | + 'region2' => $region |
|
911 | + )); |
|
912 | + } |
|
913 | + } |
|
914 | + foreach ($this->_regions as $j => $region) { |
|
915 | + if (isset($region['onlyin'])) { |
|
916 | + $suits = isset($region['onlyin'][$current['name']]); |
|
917 | + } elseif (isset($current['not-contains']['region'][$region['name']])) { |
|
918 | + $suits = false; |
|
919 | + } elseif (isset($current['contains']['region'][$region['name']])) { |
|
920 | + $suits = true; |
|
921 | + } else { |
|
922 | + $suits = @$current['contains-all'] && @!$region['never-contained']; |
|
923 | + } |
|
924 | + if ($suits) { |
|
925 | + $this->_regions[$i]['lookfor'][] = $j; |
|
926 | + } |
|
927 | + } |
|
928 | + foreach ($this->_blocks as $j=>$region) { |
|
929 | + if (isset($region['onlyin'])) { |
|
930 | + $suits = isset($region['onlyin'][$current['name']]); |
|
931 | + } elseif (isset($current['not-contains']['block'][$region['name']])) { |
|
932 | + $suits = false; |
|
933 | + } elseif (isset($current['contains']['block'][$region['name']])) { |
|
934 | + $suits = true; |
|
935 | + } else { |
|
936 | + $suits = @$current['contains-all'] && @!$region['never-contained']; |
|
937 | + } |
|
938 | + if ($suits) { |
|
939 | + $this->_regions[$i]['lookfor'][] = $j; |
|
940 | + } |
|
941 | + } |
|
942 | + } |
|
943 | + foreach ($this->_blocks as $i=>$current) { |
|
944 | + unset ($this->_blocks[$i]['never-contained']); |
|
945 | + unset ($this->_blocks[$i]['contained']); |
|
946 | + unset ($this->_blocks[$i]['contains-all']); |
|
947 | + unset ($this->_blocks[$i]['contains']); |
|
948 | + unset ($this->_blocks[$i]['onlyin']); |
|
949 | + unset ($this->_blocks[$i]['line']); |
|
950 | + } |
|
951 | + |
|
952 | + foreach ($this->_regions as $i=>$current) { |
|
953 | + unset ($this->_regions[$i]['never-contained']); |
|
954 | + unset ($this->_regions[$i]['contained']); |
|
955 | + unset ($this->_regions[$i]['contains-all']); |
|
956 | + unset ($this->_regions[$i]['contains']); |
|
957 | + unset ($this->_regions[$i]['onlyin']); |
|
958 | + unset ($this->_regions[$i]['line']); |
|
959 | + } |
|
960 | + |
|
961 | + foreach ($this->_keywords as $name => $keyword) { |
|
962 | + if (isset($keyword['ifdef'])) { |
|
963 | + $conditions[$keyword['ifdef']][] = array($name, true); |
|
964 | + } |
|
965 | + if (isset($keyword['ifndef'])) { |
|
966 | + $conditions[$keyword['ifndef']][] = array($name, false); |
|
967 | + } |
|
968 | + unset($this->_keywords[$name]['line']); |
|
969 | + if (!isset($this->_blocks[$keyword['inherits']])) { |
|
970 | + $this->_error(TEXT_HIGHLIGHTER_KEYWORD_INHERITS, |
|
971 | + array( |
|
972 | + 'keyword' => $keyword['name'], |
|
973 | + 'block' => $keyword['inherits'] |
|
974 | + )); |
|
975 | + } |
|
976 | + if (isset($keyword['otherwise']) && !isset($this->_blocks[$keyword['otherwise']]) ) { |
|
977 | + $this->_error(TEXT_HIGHLIGHTER_KEYWORD_BLOCK, |
|
978 | + array( |
|
979 | + 'keyword' => $keyword['name'], |
|
980 | + 'block' => $keyword['inherits'] |
|
981 | + )); |
|
982 | + } |
|
983 | + } |
|
984 | + |
|
985 | + $syntax=array( |
|
986 | + 'keywords' => $this->_keywords, |
|
987 | + 'blocks' => array_merge($this->_blocks, $this->_regions), |
|
988 | + 'toplevel' => $toplevel, |
|
989 | + ); |
|
990 | + uasort($syntax['blocks'], array(&$this, '_sortBlocks')); |
|
991 | + foreach ($syntax['blocks'] as $name => $block) { |
|
992 | + if ($block['type'] == 'block') { |
|
993 | + continue; |
|
994 | + } |
|
995 | + if (is_array(@$syntax['blocks'][$name]['lookfor'])) { |
|
996 | + usort($syntax['blocks'][$name]['lookfor'], array(&$this, '_sortLookFor')); |
|
997 | + } |
|
998 | + } |
|
999 | + usort($syntax['toplevel'], array(&$this, '_sortLookFor')); |
|
1000 | + $syntax['case'] = $this->_case; |
|
1001 | + $this->_code = <<<CODE |
|
1002 | 1002 | <?php |
1003 | 1003 | /** |
1004 | 1004 | * Auto-generated class. {$this->language} syntax highlighting |
1005 | 1005 | CODE; |
1006 | 1006 | |
1007 | - if ($this->_comment) { |
|
1008 | - $comment = preg_replace('~^~m',' * ',$this->_comment); |
|
1009 | - $this->_code .= "\n * \n" . $comment; |
|
1010 | - } |
|
1007 | + if ($this->_comment) { |
|
1008 | + $comment = preg_replace('~^~m',' * ',$this->_comment); |
|
1009 | + $this->_code .= "\n * \n" . $comment; |
|
1010 | + } |
|
1011 | 1011 | |
1012 | - $this->_code .= <<<CODE |
|
1012 | + $this->_code .= <<<CODE |
|
1013 | 1013 | |
1014 | 1014 | * |
1015 | 1015 | * PHP version 4 and 5 |
@@ -1029,15 +1029,15 @@ discard block |
||
1029 | 1029 | |
1030 | 1030 | CODE; |
1031 | 1031 | |
1032 | - foreach ($this->_authors as $author) { |
|
1033 | - $this->_code .= ' * @author ' . $author['name']; |
|
1034 | - if ($author['email']) { |
|
1035 | - $this->_code .= ' <' . $author['email'] . '>'; |
|
1036 | - } |
|
1037 | - $this->_code .= "\n"; |
|
1038 | - } |
|
1032 | + foreach ($this->_authors as $author) { |
|
1033 | + $this->_code .= ' * @author ' . $author['name']; |
|
1034 | + if ($author['email']) { |
|
1035 | + $this->_code .= ' <' . $author['email'] . '>'; |
|
1036 | + } |
|
1037 | + $this->_code .= "\n"; |
|
1038 | + } |
|
1039 | 1039 | |
1040 | - $this->_code .= <<<CODE |
|
1040 | + $this->_code .= <<<CODE |
|
1041 | 1041 | * |
1042 | 1042 | */ |
1043 | 1043 | |
@@ -1046,16 +1046,16 @@ discard block |
||
1046 | 1046 | * |
1047 | 1047 | |
1048 | 1048 | CODE; |
1049 | - foreach ($this->_authors as $author) { |
|
1050 | - $this->_code .= ' * @author ' . $author['name']; |
|
1051 | - if ($author['email']) { |
|
1052 | - $this->_code .= ' <' . $author['email']. '>'; |
|
1053 | - } |
|
1054 | - $this->_code .= "\n"; |
|
1055 | - } |
|
1049 | + foreach ($this->_authors as $author) { |
|
1050 | + $this->_code .= ' * @author ' . $author['name']; |
|
1051 | + if ($author['email']) { |
|
1052 | + $this->_code .= ' <' . $author['email']. '>'; |
|
1053 | + } |
|
1054 | + $this->_code .= "\n"; |
|
1055 | + } |
|
1056 | 1056 | |
1057 | 1057 | |
1058 | - $this->_code .= <<<CODE |
|
1058 | + $this->_code .= <<<CODE |
|
1059 | 1059 | * @category Text |
1060 | 1060 | * @package Text_Highlighter |
1061 | 1061 | * @copyright 2004-2006 Andrey Demenev |
@@ -1067,11 +1067,11 @@ discard block |
||
1067 | 1067 | { |
1068 | 1068 | |
1069 | 1069 | CODE; |
1070 | - $this->_code .= 'var $_language = \'' . strtolower($this->language) . "';\n\n"; |
|
1071 | - $array = var_export($syntax, true); |
|
1072 | - $array = trim(preg_replace('~^(\s*)~m',' \1\1',$array)); |
|
1073 | - // \$this->_syntax = $array; |
|
1074 | - $this->_code .= <<<CODE |
|
1070 | + $this->_code .= 'var $_language = \'' . strtolower($this->language) . "';\n\n"; |
|
1071 | + $array = var_export($syntax, true); |
|
1072 | + $array = trim(preg_replace('~^(\s*)~m',' \1\1',$array)); |
|
1073 | + // \$this->_syntax = $array; |
|
1074 | + $this->_code .= <<<CODE |
|
1075 | 1075 | |
1076 | 1076 | /** |
1077 | 1077 | * Constructor |
@@ -1083,154 +1083,154 @@ discard block |
||
1083 | 1083 | { |
1084 | 1084 | |
1085 | 1085 | CODE; |
1086 | - $this->_code .= <<<CODE |
|
1086 | + $this->_code .= <<<CODE |
|
1087 | 1087 | |
1088 | 1088 | \$this->_options = \$options; |
1089 | 1089 | CODE; |
1090 | - $states = array(); |
|
1091 | - $i = 0; |
|
1092 | - foreach ($syntax['blocks'] as $name => $block) { |
|
1093 | - if ($block['type'] == 'region') { |
|
1094 | - $states[$name] = $i++; |
|
1095 | - } |
|
1096 | - } |
|
1097 | - $regs = array(); |
|
1098 | - $counts = array(); |
|
1099 | - $delim = array(); |
|
1100 | - $inner = array(); |
|
1101 | - $end = array(); |
|
1102 | - $stat = array(); |
|
1103 | - $keywords = array(); |
|
1104 | - $parts = array(); |
|
1105 | - $kwmap = array(); |
|
1106 | - $subst = array(); |
|
1107 | - $re = array(); |
|
1108 | - $ce = array(); |
|
1109 | - $rd = array(); |
|
1110 | - $in = array(); |
|
1111 | - $st = array(); |
|
1112 | - $kw = array(); |
|
1113 | - $sb = array(); |
|
1114 | - foreach ($syntax['toplevel'] as $name) { |
|
1115 | - $block = $syntax['blocks'][$name]; |
|
1116 | - if ($block['type'] == 'block') { |
|
1117 | - $kwm = array(); |
|
1118 | - $re[] = '(' . $block['match'] . ')'; |
|
1119 | - $ce[] = $this->_countSubpatterns($block['match']); |
|
1120 | - $rd[] = ''; |
|
1121 | - $sb[] = false;; |
|
1122 | - $st[] = -1; |
|
1123 | - foreach ($syntax['keywords'] as $kwname => $kwgroup) { |
|
1124 | - if ($kwgroup['inherits'] != $name) { |
|
1125 | - continue; |
|
1126 | - } |
|
1127 | - $gre = implode('|', array_keys($kwgroup['match'])); |
|
1128 | - if (!$kwgroup['case']) { |
|
1129 | - $gre = '(?i)' . $gre; |
|
1130 | - } |
|
1131 | - $kwm[$kwname][] = $gre; |
|
1132 | - $kwmap[$kwname] = $kwgroup['innerGroup']; |
|
1133 | - } |
|
1134 | - foreach ($kwm as $g => $ma) { |
|
1135 | - $kwm[$g] = '/^(' . implode(')|(', $ma) . ')$/'; |
|
1136 | - } |
|
1137 | - $kw[] = $kwm; |
|
1138 | - } else { |
|
1139 | - $kw[] = -1; |
|
1140 | - $re[] = '(' . $block['start'] . ')'; |
|
1141 | - $ce[] = $this->_countSubpatterns($block['start']); |
|
1142 | - $rd[] = $block['delimGroup']; |
|
1143 | - $st[] = $states[$name]; |
|
1144 | - $sb[] = $block['remember']; |
|
1145 | - } |
|
1146 | - $in[] = $block['innerGroup']; |
|
1147 | - } |
|
1148 | - $re = implode('|', $re); |
|
1149 | - $regs[-1] = '/' . $re . '/'; |
|
1150 | - $counts[-1] = $ce; |
|
1151 | - $delim[-1] = $rd; |
|
1152 | - $inner[-1] = $in; |
|
1153 | - $stat[-1] = $st; |
|
1154 | - $keywords[-1] = $kw; |
|
1155 | - $subst[-1] = $sb; |
|
1156 | - |
|
1157 | - foreach ($syntax['blocks'] as $ablock) { |
|
1158 | - if ($ablock['type'] != 'region') { |
|
1159 | - continue; |
|
1160 | - } |
|
1161 | - $end[] = '/' . $ablock['end'] . '/'; |
|
1162 | - $re = array(); |
|
1163 | - $ce = array(); |
|
1164 | - $rd = array(); |
|
1165 | - $in = array(); |
|
1166 | - $st = array(); |
|
1167 | - $kw = array(); |
|
1168 | - $pc = array(); |
|
1169 | - $sb = array(); |
|
1170 | - foreach ((array)@$ablock['lookfor'] as $name) { |
|
1171 | - $block = $syntax['blocks'][$name]; |
|
1172 | - if (isset($block['partClass'])) { |
|
1173 | - $pc[] = $block['partClass']; |
|
1174 | - } else { |
|
1175 | - $pc[] = null; |
|
1176 | - } |
|
1177 | - if ($block['type'] == 'block') { |
|
1178 | - $kwm = array();; |
|
1179 | - $re[] = '(' . $block['match'] . ')'; |
|
1180 | - $ce[] = $this->_countSubpatterns($block['match']); |
|
1181 | - $rd[] = ''; |
|
1182 | - $sb[] = false; |
|
1183 | - $st[] = -1; |
|
1184 | - foreach ($syntax['keywords'] as $kwname => $kwgroup) { |
|
1185 | - if ($kwgroup['inherits'] != $name) { |
|
1186 | - continue; |
|
1187 | - } |
|
1188 | - $gre = implode('|', array_keys($kwgroup['match'])); |
|
1189 | - if (!$kwgroup['case']) { |
|
1190 | - $gre = '(?i)' . $gre; |
|
1191 | - } |
|
1192 | - $kwm[$kwname][] = $gre; |
|
1193 | - $kwmap[$kwname] = $kwgroup['innerGroup']; |
|
1194 | - } |
|
1195 | - foreach ($kwm as $g => $ma) { |
|
1196 | - $kwm[$g] = '/^(' . implode(')|(', $ma) . ')$/'; |
|
1197 | - } |
|
1198 | - $kw[] = $kwm; |
|
1199 | - } else { |
|
1200 | - $sb[] = $block['remember']; |
|
1201 | - $kw[] = -1; |
|
1202 | - $re[] = '(' . $block['start'] . ')'; |
|
1203 | - $ce[] = $this->_countSubpatterns($block['start']); |
|
1204 | - $rd[] = $block['delimGroup']; |
|
1205 | - $st[] = $states[$name]; |
|
1206 | - } |
|
1207 | - $in[] = $block['innerGroup']; |
|
1208 | - } |
|
1209 | - $re = implode('|', $re); |
|
1210 | - $regs[] = '/' . $re . '/'; |
|
1211 | - $counts[] = $ce; |
|
1212 | - $delim[] = $rd; |
|
1213 | - $inner[] = $in; |
|
1214 | - $stat[] = $st; |
|
1215 | - $keywords[] = $kw; |
|
1216 | - $parts[] = $pc; |
|
1217 | - $subst[] = $sb; |
|
1218 | - } |
|
1219 | - |
|
1220 | - |
|
1221 | - $this->_code .= "\n \$this->_regs = " . $this->_exportArray($regs); |
|
1222 | - $this->_code .= ";\n \$this->_counts = " .$this->_exportArray($counts); |
|
1223 | - $this->_code .= ";\n \$this->_delim = " .$this->_exportArray($delim); |
|
1224 | - $this->_code .= ";\n \$this->_inner = " .$this->_exportArray($inner); |
|
1225 | - $this->_code .= ";\n \$this->_end = " .$this->_exportArray($end); |
|
1226 | - $this->_code .= ";\n \$this->_states = " .$this->_exportArray($stat); |
|
1227 | - $this->_code .= ";\n \$this->_keywords = " .$this->_exportArray($keywords); |
|
1228 | - $this->_code .= ";\n \$this->_parts = " .$this->_exportArray($parts); |
|
1229 | - $this->_code .= ";\n \$this->_subst = " .$this->_exportArray($subst); |
|
1230 | - $this->_code .= ";\n \$this->_conditions = " .$this->_exportArray($conditions); |
|
1231 | - $this->_code .= ";\n \$this->_kwmap = " .$this->_exportArray($kwmap); |
|
1232 | - $this->_code .= ";\n \$this->_defClass = '" .$this->_defClass . '\''; |
|
1233 | - $this->_code .= <<<CODE |
|
1090 | + $states = array(); |
|
1091 | + $i = 0; |
|
1092 | + foreach ($syntax['blocks'] as $name => $block) { |
|
1093 | + if ($block['type'] == 'region') { |
|
1094 | + $states[$name] = $i++; |
|
1095 | + } |
|
1096 | + } |
|
1097 | + $regs = array(); |
|
1098 | + $counts = array(); |
|
1099 | + $delim = array(); |
|
1100 | + $inner = array(); |
|
1101 | + $end = array(); |
|
1102 | + $stat = array(); |
|
1103 | + $keywords = array(); |
|
1104 | + $parts = array(); |
|
1105 | + $kwmap = array(); |
|
1106 | + $subst = array(); |
|
1107 | + $re = array(); |
|
1108 | + $ce = array(); |
|
1109 | + $rd = array(); |
|
1110 | + $in = array(); |
|
1111 | + $st = array(); |
|
1112 | + $kw = array(); |
|
1113 | + $sb = array(); |
|
1114 | + foreach ($syntax['toplevel'] as $name) { |
|
1115 | + $block = $syntax['blocks'][$name]; |
|
1116 | + if ($block['type'] == 'block') { |
|
1117 | + $kwm = array(); |
|
1118 | + $re[] = '(' . $block['match'] . ')'; |
|
1119 | + $ce[] = $this->_countSubpatterns($block['match']); |
|
1120 | + $rd[] = ''; |
|
1121 | + $sb[] = false;; |
|
1122 | + $st[] = -1; |
|
1123 | + foreach ($syntax['keywords'] as $kwname => $kwgroup) { |
|
1124 | + if ($kwgroup['inherits'] != $name) { |
|
1125 | + continue; |
|
1126 | + } |
|
1127 | + $gre = implode('|', array_keys($kwgroup['match'])); |
|
1128 | + if (!$kwgroup['case']) { |
|
1129 | + $gre = '(?i)' . $gre; |
|
1130 | + } |
|
1131 | + $kwm[$kwname][] = $gre; |
|
1132 | + $kwmap[$kwname] = $kwgroup['innerGroup']; |
|
1133 | + } |
|
1134 | + foreach ($kwm as $g => $ma) { |
|
1135 | + $kwm[$g] = '/^(' . implode(')|(', $ma) . ')$/'; |
|
1136 | + } |
|
1137 | + $kw[] = $kwm; |
|
1138 | + } else { |
|
1139 | + $kw[] = -1; |
|
1140 | + $re[] = '(' . $block['start'] . ')'; |
|
1141 | + $ce[] = $this->_countSubpatterns($block['start']); |
|
1142 | + $rd[] = $block['delimGroup']; |
|
1143 | + $st[] = $states[$name]; |
|
1144 | + $sb[] = $block['remember']; |
|
1145 | + } |
|
1146 | + $in[] = $block['innerGroup']; |
|
1147 | + } |
|
1148 | + $re = implode('|', $re); |
|
1149 | + $regs[-1] = '/' . $re . '/'; |
|
1150 | + $counts[-1] = $ce; |
|
1151 | + $delim[-1] = $rd; |
|
1152 | + $inner[-1] = $in; |
|
1153 | + $stat[-1] = $st; |
|
1154 | + $keywords[-1] = $kw; |
|
1155 | + $subst[-1] = $sb; |
|
1156 | + |
|
1157 | + foreach ($syntax['blocks'] as $ablock) { |
|
1158 | + if ($ablock['type'] != 'region') { |
|
1159 | + continue; |
|
1160 | + } |
|
1161 | + $end[] = '/' . $ablock['end'] . '/'; |
|
1162 | + $re = array(); |
|
1163 | + $ce = array(); |
|
1164 | + $rd = array(); |
|
1165 | + $in = array(); |
|
1166 | + $st = array(); |
|
1167 | + $kw = array(); |
|
1168 | + $pc = array(); |
|
1169 | + $sb = array(); |
|
1170 | + foreach ((array)@$ablock['lookfor'] as $name) { |
|
1171 | + $block = $syntax['blocks'][$name]; |
|
1172 | + if (isset($block['partClass'])) { |
|
1173 | + $pc[] = $block['partClass']; |
|
1174 | + } else { |
|
1175 | + $pc[] = null; |
|
1176 | + } |
|
1177 | + if ($block['type'] == 'block') { |
|
1178 | + $kwm = array();; |
|
1179 | + $re[] = '(' . $block['match'] . ')'; |
|
1180 | + $ce[] = $this->_countSubpatterns($block['match']); |
|
1181 | + $rd[] = ''; |
|
1182 | + $sb[] = false; |
|
1183 | + $st[] = -1; |
|
1184 | + foreach ($syntax['keywords'] as $kwname => $kwgroup) { |
|
1185 | + if ($kwgroup['inherits'] != $name) { |
|
1186 | + continue; |
|
1187 | + } |
|
1188 | + $gre = implode('|', array_keys($kwgroup['match'])); |
|
1189 | + if (!$kwgroup['case']) { |
|
1190 | + $gre = '(?i)' . $gre; |
|
1191 | + } |
|
1192 | + $kwm[$kwname][] = $gre; |
|
1193 | + $kwmap[$kwname] = $kwgroup['innerGroup']; |
|
1194 | + } |
|
1195 | + foreach ($kwm as $g => $ma) { |
|
1196 | + $kwm[$g] = '/^(' . implode(')|(', $ma) . ')$/'; |
|
1197 | + } |
|
1198 | + $kw[] = $kwm; |
|
1199 | + } else { |
|
1200 | + $sb[] = $block['remember']; |
|
1201 | + $kw[] = -1; |
|
1202 | + $re[] = '(' . $block['start'] . ')'; |
|
1203 | + $ce[] = $this->_countSubpatterns($block['start']); |
|
1204 | + $rd[] = $block['delimGroup']; |
|
1205 | + $st[] = $states[$name]; |
|
1206 | + } |
|
1207 | + $in[] = $block['innerGroup']; |
|
1208 | + } |
|
1209 | + $re = implode('|', $re); |
|
1210 | + $regs[] = '/' . $re . '/'; |
|
1211 | + $counts[] = $ce; |
|
1212 | + $delim[] = $rd; |
|
1213 | + $inner[] = $in; |
|
1214 | + $stat[] = $st; |
|
1215 | + $keywords[] = $kw; |
|
1216 | + $parts[] = $pc; |
|
1217 | + $subst[] = $sb; |
|
1218 | + } |
|
1219 | + |
|
1220 | + |
|
1221 | + $this->_code .= "\n \$this->_regs = " . $this->_exportArray($regs); |
|
1222 | + $this->_code .= ";\n \$this->_counts = " .$this->_exportArray($counts); |
|
1223 | + $this->_code .= ";\n \$this->_delim = " .$this->_exportArray($delim); |
|
1224 | + $this->_code .= ";\n \$this->_inner = " .$this->_exportArray($inner); |
|
1225 | + $this->_code .= ";\n \$this->_end = " .$this->_exportArray($end); |
|
1226 | + $this->_code .= ";\n \$this->_states = " .$this->_exportArray($stat); |
|
1227 | + $this->_code .= ";\n \$this->_keywords = " .$this->_exportArray($keywords); |
|
1228 | + $this->_code .= ";\n \$this->_parts = " .$this->_exportArray($parts); |
|
1229 | + $this->_code .= ";\n \$this->_subst = " .$this->_exportArray($subst); |
|
1230 | + $this->_code .= ";\n \$this->_conditions = " .$this->_exportArray($conditions); |
|
1231 | + $this->_code .= ";\n \$this->_kwmap = " .$this->_exportArray($kwmap); |
|
1232 | + $this->_code .= ";\n \$this->_defClass = '" .$this->_defClass . '\''; |
|
1233 | + $this->_code .= <<<CODE |
|
1234 | 1234 | ; |
1235 | 1235 | \$this->_checkDefines(); |
1236 | 1236 | } |
@@ -27,18 +27,18 @@ discard block |
||
27 | 27 | |
28 | 28 | // {{{ error codes |
29 | 29 | |
30 | -define ('TEXT_HIGHLIGHTER_EMPTY_RE', 1); |
|
31 | -define ('TEXT_HIGHLIGHTER_INVALID_RE', 2); |
|
32 | -define ('TEXT_HIGHLIGHTER_EMPTY_OR_MISSING', 3); |
|
33 | -define ('TEXT_HIGHLIGHTER_EMPTY', 4); |
|
34 | -define ('TEXT_HIGHLIGHTER_REGION_REGION', 5); |
|
35 | -define ('TEXT_HIGHLIGHTER_REGION_BLOCK', 6); |
|
36 | -define ('TEXT_HIGHLIGHTER_BLOCK_REGION', 7); |
|
37 | -define ('TEXT_HIGHLIGHTER_KEYWORD_BLOCK', 8); |
|
38 | -define ('TEXT_HIGHLIGHTER_KEYWORD_INHERITS', 9); |
|
39 | -define ('TEXT_HIGHLIGHTER_PARSE', 10); |
|
40 | -define ('TEXT_HIGHLIGHTER_FILE_WRITE', 11); |
|
41 | -define ('TEXT_HIGHLIGHTER_FILE_READ', 12); |
|
30 | +define('TEXT_HIGHLIGHTER_EMPTY_RE', 1); |
|
31 | +define('TEXT_HIGHLIGHTER_INVALID_RE', 2); |
|
32 | +define('TEXT_HIGHLIGHTER_EMPTY_OR_MISSING', 3); |
|
33 | +define('TEXT_HIGHLIGHTER_EMPTY', 4); |
|
34 | +define('TEXT_HIGHLIGHTER_REGION_REGION', 5); |
|
35 | +define('TEXT_HIGHLIGHTER_REGION_BLOCK', 6); |
|
36 | +define('TEXT_HIGHLIGHTER_BLOCK_REGION', 7); |
|
37 | +define('TEXT_HIGHLIGHTER_KEYWORD_BLOCK', 8); |
|
38 | +define('TEXT_HIGHLIGHTER_KEYWORD_INHERITS', 9); |
|
39 | +define('TEXT_HIGHLIGHTER_PARSE', 10); |
|
40 | +define('TEXT_HIGHLIGHTER_FILE_WRITE', 11); |
|
41 | +define('TEXT_HIGHLIGHTER_FILE_READ', 12); |
|
42 | 42 | // }}} |
43 | 43 | |
44 | 44 | /** |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | */ |
240 | 240 | function _declareErrorMessages() |
241 | 241 | { |
242 | - $this->_templates = array ( |
|
242 | + $this->_templates = array( |
|
243 | 243 | TEXT_HIGHLIGHTER_EMPTY_RE => 'Empty regular expression', |
244 | 244 | TEXT_HIGHLIGHTER_INVALID_RE => 'Invalid regular expression : %s', |
245 | 245 | TEXT_HIGHLIGHTER_EMPTY_OR_MISSING => 'Empty or missing %s', |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | $this->_inComment = false; |
298 | 298 | $this->_authors = array(); |
299 | 299 | $this->_blockOrder = 0; |
300 | - $this->_errors = array(); |
|
300 | + $this->_errors = array(); |
|
301 | 301 | |
302 | 302 | $ret = $this->parse(); |
303 | 303 | if (PEAR::isError($ret)) { |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | $this->_error(TEXT_HIGHLIGHTER_FILE_WRITE, array('outfile'=>$filename)); |
343 | 343 | return false; |
344 | 344 | } |
345 | - fwrite ($f, $this->_code); |
|
345 | + fwrite($f, $this->_code); |
|
346 | 346 | fclose($f); |
347 | 347 | return true; |
348 | 348 | } |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | if ($php_errormsg) { |
431 | 431 | $this->_error(TEXT_HIGHLIGHTER_INVALID_RE, $php_errormsg); |
432 | 432 | } |
433 | - preg_match ('#^/(.+)/(.*)$#', $text, $m); |
|
433 | + preg_match('#^/(.+)/(.*)$#', $text, $m); |
|
434 | 434 | if (@$m[2]) { |
435 | 435 | $text = '(?' . $m[2] . ')' . $m[1]; |
436 | 436 | } else { |
@@ -452,7 +452,7 @@ discard block |
||
452 | 452 | function _exportArray($array) |
453 | 453 | { |
454 | 454 | $array = var_export($array, true); |
455 | - return trim(preg_replace('~^(\s*)~m',' \1\1',$array)); |
|
455 | + return trim(preg_replace('~^(\s*)~m', ' \1\1', $array)); |
|
456 | 456 | } |
457 | 457 | |
458 | 458 | // }}} |
@@ -465,7 +465,7 @@ discard block |
||
465 | 465 | function _countSubpatterns($re) |
466 | 466 | { |
467 | 467 | preg_match_all('/' . $re . '/', '', $m); |
468 | - return count($m)-1; |
|
468 | + return count($m) - 1; |
|
469 | 469 | } |
470 | 470 | |
471 | 471 | // }}} |
@@ -515,8 +515,7 @@ discard block |
||
515 | 515 | } |
516 | 516 | $this->_element['innerGroup'] = $attribs['innerGroup']; |
517 | 517 | $this->_element['delimGroup'] = isset($attribs['delimGroup']) ? |
518 | - $attribs['delimGroup'] : |
|
519 | - $attribs['innerGroup']; |
|
518 | + $attribs['delimGroup'] : $attribs['innerGroup']; |
|
520 | 519 | $this->_element['start'] = $this->_makeRE(@$attribs['start'], $this->_element['case']); |
521 | 520 | $this->_element['end'] = $this->_makeRE(@$attribs['end'], $this->_element['case']); |
522 | 521 | $this->_element['contained'] = @$attribs['contained'] == 'yes'; |
@@ -738,7 +737,7 @@ discard block |
||
738 | 737 | } |
739 | 738 | $this->_authors[] = array( |
740 | 739 | 'name' => @$attribs['name'], |
741 | - 'email' => (string)@$attribs['email'] |
|
740 | + 'email' => (string) @$attribs['email'] |
|
742 | 741 | ); |
743 | 742 | } |
744 | 743 | |
@@ -828,7 +827,7 @@ discard block |
||
828 | 827 | function xmltag_Region_($xp, $elem) |
829 | 828 | { |
830 | 829 | $this->_element['type'] = 'region'; |
831 | - $this->_element['order'] = $this->_blockOrder ++; |
|
830 | + $this->_element['order'] = $this->_blockOrder++; |
|
832 | 831 | $this->_regions[$this->_element['name']] = $this->_element; |
833 | 832 | } |
834 | 833 | |
@@ -852,7 +851,7 @@ discard block |
||
852 | 851 | function xmltag_Block_($xp, $elem) |
853 | 852 | { |
854 | 853 | $this->_element['type'] = 'block'; |
855 | - $this->_element['order'] = $this->_blockOrder ++; |
|
854 | + $this->_element['order'] = $this->_blockOrder++; |
|
856 | 855 | $this->_blocks[$this->_element['name']] = $this->_element; |
857 | 856 | } |
858 | 857 | |
@@ -870,7 +869,7 @@ discard block |
||
870 | 869 | if (!$current['contained'] && !isset($current['onlyin'])) { |
871 | 870 | $toplevel[] = $i; |
872 | 871 | } |
873 | - foreach ((array)@$current['onlyin'] as $region => $lineNo) { |
|
872 | + foreach ((array) @$current['onlyin'] as $region => $lineNo) { |
|
874 | 873 | if (!isset($this->_regions[$region])) { |
875 | 874 | $this->_error(TEXT_HIGHLIGHTER_BLOCK_REGION, |
876 | 875 | array( |
@@ -884,7 +883,7 @@ discard block |
||
884 | 883 | if (!$current['contained'] && !isset($current['onlyin'])) { |
885 | 884 | $toplevel[] = $i; |
886 | 885 | } |
887 | - foreach ((array)@$current['contains']['region'] as $region => $lineNo) { |
|
886 | + foreach ((array) @$current['contains']['region'] as $region => $lineNo) { |
|
888 | 887 | if (!isset($this->_regions[$region])) { |
889 | 888 | $this->_error(TEXT_HIGHLIGHTER_REGION_REGION, |
890 | 889 | array( |
@@ -893,7 +892,7 @@ discard block |
||
893 | 892 | )); |
894 | 893 | } |
895 | 894 | } |
896 | - foreach ((array)@$current['contains']['block'] as $region => $lineNo) { |
|
895 | + foreach ((array) @$current['contains']['block'] as $region => $lineNo) { |
|
897 | 896 | if (!isset($this->_blocks[$region])) { |
898 | 897 | $this->_error(TEXT_HIGHLIGHTER_REGION_BLOCK, |
899 | 898 | array( |
@@ -902,7 +901,7 @@ discard block |
||
902 | 901 | )); |
903 | 902 | } |
904 | 903 | } |
905 | - foreach ((array)@$current['onlyin'] as $region => $lineNo) { |
|
904 | + foreach ((array) @$current['onlyin'] as $region => $lineNo) { |
|
906 | 905 | if (!isset($this->_regions[$region])) { |
907 | 906 | $this->_error(TEXT_HIGHLIGHTER_REGION_REGION, |
908 | 907 | array( |
@@ -973,7 +972,7 @@ discard block |
||
973 | 972 | 'block' => $keyword['inherits'] |
974 | 973 | )); |
975 | 974 | } |
976 | - if (isset($keyword['otherwise']) && !isset($this->_blocks[$keyword['otherwise']]) ) { |
|
975 | + if (isset($keyword['otherwise']) && !isset($this->_blocks[$keyword['otherwise']])) { |
|
977 | 976 | $this->_error(TEXT_HIGHLIGHTER_KEYWORD_BLOCK, |
978 | 977 | array( |
979 | 978 | 'keyword' => $keyword['name'], |
@@ -982,7 +981,7 @@ discard block |
||
982 | 981 | } |
983 | 982 | } |
984 | 983 | |
985 | - $syntax=array( |
|
984 | + $syntax = array( |
|
986 | 985 | 'keywords' => $this->_keywords, |
987 | 986 | 'blocks' => array_merge($this->_blocks, $this->_regions), |
988 | 987 | 'toplevel' => $toplevel, |
@@ -1005,7 +1004,7 @@ discard block |
||
1005 | 1004 | CODE; |
1006 | 1005 | |
1007 | 1006 | if ($this->_comment) { |
1008 | - $comment = preg_replace('~^~m',' * ',$this->_comment); |
|
1007 | + $comment = preg_replace('~^~m', ' * ', $this->_comment); |
|
1009 | 1008 | $this->_code .= "\n * \n" . $comment; |
1010 | 1009 | } |
1011 | 1010 | |
@@ -1049,7 +1048,7 @@ discard block |
||
1049 | 1048 | foreach ($this->_authors as $author) { |
1050 | 1049 | $this->_code .= ' * @author ' . $author['name']; |
1051 | 1050 | if ($author['email']) { |
1052 | - $this->_code .= ' <' . $author['email']. '>'; |
|
1051 | + $this->_code .= ' <' . $author['email'] . '>'; |
|
1053 | 1052 | } |
1054 | 1053 | $this->_code .= "\n"; |
1055 | 1054 | } |
@@ -1069,7 +1068,7 @@ discard block |
||
1069 | 1068 | CODE; |
1070 | 1069 | $this->_code .= 'var $_language = \'' . strtolower($this->language) . "';\n\n"; |
1071 | 1070 | $array = var_export($syntax, true); |
1072 | - $array = trim(preg_replace('~^(\s*)~m',' \1\1',$array)); |
|
1071 | + $array = trim(preg_replace('~^(\s*)~m', ' \1\1', $array)); |
|
1073 | 1072 | // \$this->_syntax = $array; |
1074 | 1073 | $this->_code .= <<<CODE |
1075 | 1074 | |
@@ -1118,7 +1117,7 @@ discard block |
||
1118 | 1117 | $re[] = '(' . $block['match'] . ')'; |
1119 | 1118 | $ce[] = $this->_countSubpatterns($block['match']); |
1120 | 1119 | $rd[] = ''; |
1121 | - $sb[] = false;; |
|
1120 | + $sb[] = false; ; |
|
1122 | 1121 | $st[] = -1; |
1123 | 1122 | foreach ($syntax['keywords'] as $kwname => $kwgroup) { |
1124 | 1123 | if ($kwgroup['inherits'] != $name) { |
@@ -1128,7 +1127,7 @@ discard block |
||
1128 | 1127 | if (!$kwgroup['case']) { |
1129 | 1128 | $gre = '(?i)' . $gre; |
1130 | 1129 | } |
1131 | - $kwm[$kwname][] = $gre; |
|
1130 | + $kwm[$kwname][] = $gre; |
|
1132 | 1131 | $kwmap[$kwname] = $kwgroup['innerGroup']; |
1133 | 1132 | } |
1134 | 1133 | foreach ($kwm as $g => $ma) { |
@@ -1167,7 +1166,7 @@ discard block |
||
1167 | 1166 | $kw = array(); |
1168 | 1167 | $pc = array(); |
1169 | 1168 | $sb = array(); |
1170 | - foreach ((array)@$ablock['lookfor'] as $name) { |
|
1169 | + foreach ((array) @$ablock['lookfor'] as $name) { |
|
1171 | 1170 | $block = $syntax['blocks'][$name]; |
1172 | 1171 | if (isset($block['partClass'])) { |
1173 | 1172 | $pc[] = $block['partClass']; |
@@ -1175,7 +1174,7 @@ discard block |
||
1175 | 1174 | $pc[] = null; |
1176 | 1175 | } |
1177 | 1176 | if ($block['type'] == 'block') { |
1178 | - $kwm = array();; |
|
1177 | + $kwm = array(); ; |
|
1179 | 1178 | $re[] = '(' . $block['match'] . ')'; |
1180 | 1179 | $ce[] = $this->_countSubpatterns($block['match']); |
1181 | 1180 | $rd[] = ''; |
@@ -1189,7 +1188,7 @@ discard block |
||
1189 | 1188 | if (!$kwgroup['case']) { |
1190 | 1189 | $gre = '(?i)' . $gre; |
1191 | 1190 | } |
1192 | - $kwm[$kwname][] = $gre; |
|
1191 | + $kwm[$kwname][] = $gre; |
|
1193 | 1192 | $kwmap[$kwname] = $kwgroup['innerGroup']; |
1194 | 1193 | } |
1195 | 1194 | foreach ($kwm as $g => $ma) { |
@@ -1219,17 +1218,17 @@ discard block |
||
1219 | 1218 | |
1220 | 1219 | |
1221 | 1220 | $this->_code .= "\n \$this->_regs = " . $this->_exportArray($regs); |
1222 | - $this->_code .= ";\n \$this->_counts = " .$this->_exportArray($counts); |
|
1223 | - $this->_code .= ";\n \$this->_delim = " .$this->_exportArray($delim); |
|
1224 | - $this->_code .= ";\n \$this->_inner = " .$this->_exportArray($inner); |
|
1225 | - $this->_code .= ";\n \$this->_end = " .$this->_exportArray($end); |
|
1226 | - $this->_code .= ";\n \$this->_states = " .$this->_exportArray($stat); |
|
1227 | - $this->_code .= ";\n \$this->_keywords = " .$this->_exportArray($keywords); |
|
1228 | - $this->_code .= ";\n \$this->_parts = " .$this->_exportArray($parts); |
|
1229 | - $this->_code .= ";\n \$this->_subst = " .$this->_exportArray($subst); |
|
1230 | - $this->_code .= ";\n \$this->_conditions = " .$this->_exportArray($conditions); |
|
1231 | - $this->_code .= ";\n \$this->_kwmap = " .$this->_exportArray($kwmap); |
|
1232 | - $this->_code .= ";\n \$this->_defClass = '" .$this->_defClass . '\''; |
|
1221 | + $this->_code .= ";\n \$this->_counts = " . $this->_exportArray($counts); |
|
1222 | + $this->_code .= ";\n \$this->_delim = " . $this->_exportArray($delim); |
|
1223 | + $this->_code .= ";\n \$this->_inner = " . $this->_exportArray($inner); |
|
1224 | + $this->_code .= ";\n \$this->_end = " . $this->_exportArray($end); |
|
1225 | + $this->_code .= ";\n \$this->_states = " . $this->_exportArray($stat); |
|
1226 | + $this->_code .= ";\n \$this->_keywords = " . $this->_exportArray($keywords); |
|
1227 | + $this->_code .= ";\n \$this->_parts = " . $this->_exportArray($parts); |
|
1228 | + $this->_code .= ";\n \$this->_subst = " . $this->_exportArray($subst); |
|
1229 | + $this->_code .= ";\n \$this->_conditions = " . $this->_exportArray($conditions); |
|
1230 | + $this->_code .= ";\n \$this->_kwmap = " . $this->_exportArray($kwmap); |
|
1231 | + $this->_code .= ";\n \$this->_defClass = '" . $this->_defClass . '\''; |
|
1233 | 1232 | $this->_code .= <<<CODE |
1234 | 1233 | ; |
1235 | 1234 | \$this->_checkDefines(); |
@@ -1002,7 +1002,7 @@ discard block |
||
1002 | 1002 | <?php |
1003 | 1003 | /** |
1004 | 1004 | * Auto-generated class. {$this->language} syntax highlighting |
1005 | -CODE; |
|
1005 | +code; |
|
1006 | 1006 | |
1007 | 1007 | if ($this->_comment) { |
1008 | 1008 | $comment = preg_replace('~^~m',' * ',$this->_comment); |
@@ -1027,7 +1027,7 @@ discard block |
||
1027 | 1027 | * @package Text_Highlighter |
1028 | 1028 | * @version generated from: $this->_syntaxFile |
1029 | 1029 | |
1030 | -CODE; |
|
1030 | +code; |
|
1031 | 1031 | |
1032 | 1032 | foreach ($this->_authors as $author) { |
1033 | 1033 | $this->_code .= ' * @author ' . $author['name']; |
@@ -1045,7 +1045,7 @@ discard block |
||
1045 | 1045 | * Auto-generated class. {$this->language} syntax highlighting |
1046 | 1046 | * |
1047 | 1047 | |
1048 | -CODE; |
|
1048 | +code; |
|
1049 | 1049 | foreach ($this->_authors as $author) { |
1050 | 1050 | $this->_code .= ' * @author ' . $author['name']; |
1051 | 1051 | if ($author['email']) { |
@@ -1066,7 +1066,7 @@ discard block |
||
1066 | 1066 | class Text_Highlighter_{$this->language} extends Text_Highlighter |
1067 | 1067 | { |
1068 | 1068 | |
1069 | -CODE; |
|
1069 | +code; |
|
1070 | 1070 | $this->_code .= 'var $_language = \'' . strtolower($this->language) . "';\n\n"; |
1071 | 1071 | $array = var_export($syntax, true); |
1072 | 1072 | $array = trim(preg_replace('~^(\s*)~m',' \1\1',$array)); |
@@ -1082,11 +1082,11 @@ discard block |
||
1082 | 1082 | function __construct(\$options=array()) |
1083 | 1083 | { |
1084 | 1084 | |
1085 | -CODE; |
|
1085 | +code; |
|
1086 | 1086 | $this->_code .= <<<CODE |
1087 | 1087 | |
1088 | 1088 | \$this->_options = \$options; |
1089 | -CODE; |
|
1089 | +code; |
|
1090 | 1090 | $states = array(); |
1091 | 1091 | $i = 0; |
1092 | 1092 | foreach ($syntax['blocks'] as $name => $block) { |
@@ -1236,7 +1236,7 @@ discard block |
||
1236 | 1236 | } |
1237 | 1237 | |
1238 | 1238 | } |
1239 | -CODE; |
|
1239 | +code; |
|
1240 | 1240 | } |
1241 | 1241 | |
1242 | 1242 | // }}} |
@@ -68,7 +68,6 @@ discard block |
||
68 | 68 | * |
69 | 69 | * @access public |
70 | 70 | * |
71 | - * @param array $options Rendering options. Renderer-specific. |
|
72 | 71 | */ |
73 | 72 | function reset() |
74 | 73 | { |
@@ -130,6 +129,7 @@ discard block |
||
130 | 129 | * Set current language |
131 | 130 | * |
132 | 131 | * @abstract |
132 | + * @param string $lang |
|
133 | 133 | * @return void |
134 | 134 | * @access public |
135 | 135 | * |
@@ -35,109 +35,109 @@ |
||
35 | 35 | |
36 | 36 | class Text_Highlighter_Renderer |
37 | 37 | { |
38 | - /** |
|
39 | - * Renderer options |
|
40 | - * |
|
41 | - * @var array |
|
42 | - * @access protected |
|
43 | - */ |
|
44 | - public $_options = array(); |
|
38 | + /** |
|
39 | + * Renderer options |
|
40 | + * |
|
41 | + * @var array |
|
42 | + * @access protected |
|
43 | + */ |
|
44 | + public $_options = array(); |
|
45 | 45 | |
46 | - /** |
|
47 | - * Current language |
|
48 | - * |
|
49 | - * @var string |
|
50 | - * @access protected |
|
51 | - */ |
|
52 | - public $_language = ''; |
|
46 | + /** |
|
47 | + * Current language |
|
48 | + * |
|
49 | + * @var string |
|
50 | + * @access protected |
|
51 | + */ |
|
52 | + public $_language = ''; |
|
53 | 53 | |
54 | - /** |
|
55 | - * Constructor |
|
56 | - * |
|
57 | - * @access public |
|
58 | - * |
|
59 | - * @param array $options Rendering options. Renderer-specific. |
|
60 | - */ |
|
61 | - function __construct($options = array()) |
|
62 | - { |
|
63 | - $this->_options = $options; |
|
64 | - } |
|
54 | + /** |
|
55 | + * Constructor |
|
56 | + * |
|
57 | + * @access public |
|
58 | + * |
|
59 | + * @param array $options Rendering options. Renderer-specific. |
|
60 | + */ |
|
61 | + function __construct($options = array()) |
|
62 | + { |
|
63 | + $this->_options = $options; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Resets renderer state |
|
68 | - * |
|
69 | - * @access public |
|
70 | - * |
|
71 | - * @param array $options Rendering options. Renderer-specific. |
|
72 | - */ |
|
73 | - function reset() |
|
74 | - { |
|
75 | - return; |
|
76 | - } |
|
66 | + /** |
|
67 | + * Resets renderer state |
|
68 | + * |
|
69 | + * @access public |
|
70 | + * |
|
71 | + * @param array $options Rendering options. Renderer-specific. |
|
72 | + */ |
|
73 | + function reset() |
|
74 | + { |
|
75 | + return; |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Preprocesses code |
|
80 | - * |
|
81 | - * @access public |
|
82 | - * |
|
83 | - * @param string $str Code to preprocess |
|
84 | - * @return string Preprocessed code |
|
85 | - */ |
|
86 | - function preprocess($str) |
|
87 | - { |
|
88 | - return $str; |
|
89 | - } |
|
78 | + /** |
|
79 | + * Preprocesses code |
|
80 | + * |
|
81 | + * @access public |
|
82 | + * |
|
83 | + * @param string $str Code to preprocess |
|
84 | + * @return string Preprocessed code |
|
85 | + */ |
|
86 | + function preprocess($str) |
|
87 | + { |
|
88 | + return $str; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * Accepts next token |
|
93 | - * |
|
94 | - * @abstract |
|
95 | - * @access public |
|
96 | - * |
|
97 | - * @param string $class Token class |
|
98 | - * @param string $content Token content |
|
99 | - */ |
|
100 | - function acceptToken($class, $content) |
|
101 | - { |
|
102 | - return; |
|
103 | - } |
|
91 | + /** |
|
92 | + * Accepts next token |
|
93 | + * |
|
94 | + * @abstract |
|
95 | + * @access public |
|
96 | + * |
|
97 | + * @param string $class Token class |
|
98 | + * @param string $content Token content |
|
99 | + */ |
|
100 | + function acceptToken($class, $content) |
|
101 | + { |
|
102 | + return; |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * Signals that no more tokens are available |
|
107 | - * |
|
108 | - * @access public |
|
109 | - * |
|
110 | - */ |
|
111 | - function finalize() |
|
112 | - { |
|
113 | - return; |
|
114 | - } |
|
105 | + /** |
|
106 | + * Signals that no more tokens are available |
|
107 | + * |
|
108 | + * @access public |
|
109 | + * |
|
110 | + */ |
|
111 | + function finalize() |
|
112 | + { |
|
113 | + return; |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * Get generated output |
|
118 | - * |
|
119 | - * @abstract |
|
120 | - * @return mixed Renderer-specific |
|
121 | - * @access public |
|
122 | - * |
|
123 | - */ |
|
124 | - function getOutput() |
|
125 | - { |
|
126 | - return; |
|
127 | - } |
|
116 | + /** |
|
117 | + * Get generated output |
|
118 | + * |
|
119 | + * @abstract |
|
120 | + * @return mixed Renderer-specific |
|
121 | + * @access public |
|
122 | + * |
|
123 | + */ |
|
124 | + function getOutput() |
|
125 | + { |
|
126 | + return; |
|
127 | + } |
|
128 | 128 | |
129 | - /** |
|
130 | - * Set current language |
|
131 | - * |
|
132 | - * @abstract |
|
133 | - * @return void |
|
134 | - * @access public |
|
135 | - * |
|
136 | - */ |
|
137 | - function setCurrentLanguage($lang) |
|
138 | - { |
|
139 | - $this->_language = $lang; |
|
140 | - } |
|
129 | + /** |
|
130 | + * Set current language |
|
131 | + * |
|
132 | + * @abstract |
|
133 | + * @return void |
|
134 | + * @access public |
|
135 | + * |
|
136 | + */ |
|
137 | + function setCurrentLanguage($lang) |
|
138 | + { |
|
139 | + $this->_language = $lang; |
|
140 | + } |
|
141 | 141 | |
142 | 142 | } |
143 | 143 |
@@ -59,7 +59,6 @@ |
||
59 | 59 | |
60 | 60 | /** |
61 | 61 | * Return the message as a DOM element |
62 | - * @param DOMDocument $wsdl The wsdl document the messages will be children of |
|
63 | 62 | */ |
64 | 63 | public function getMessageElement(DOMDocument $dom) |
65 | 64 | { |
@@ -208,6 +208,7 @@ discard block |
||
208 | 208 | * @param string active record class name. |
209 | 209 | * @param array row data |
210 | 210 | * @param array foreign key column names |
211 | + * @param string $type |
|
211 | 212 | * @return TActiveRecord |
212 | 213 | */ |
213 | 214 | protected function createFkObject($type,$row,$foreignKeys) |
@@ -227,6 +228,7 @@ discard block |
||
227 | 228 | * @param TTableInfo association table info |
228 | 229 | * @param array field names |
229 | 230 | * @param array field values |
231 | + * @param TActiveRecordCriteria $criteria |
|
230 | 232 | */ |
231 | 233 | public function createCommand($criteria, $foreignKeys,$indexValues,$sourceKeys) |
232 | 234 | { |
@@ -341,6 +343,10 @@ discard block |
||
341 | 343 | return $this->getCommandBuilder()->onExecuteCommand($command, $command->execute()) > 0; |
342 | 344 | } |
343 | 345 | |
346 | + /** |
|
347 | + * @param TActiveRecord $obj |
|
348 | + * @param TDbCommandBuilder $builder |
|
349 | + */ |
|
344 | 350 | private function updateAssociationTable($obj,$fkObjects, $builder) |
345 | 351 | { |
346 | 352 | $source = $this->getSourceRecordValues($obj); |
@@ -90,10 +90,10 @@ |
||
90 | 90 | private $_association_columns=array(); |
91 | 91 | |
92 | 92 | /** |
93 | - * Get the foreign key index values from the results and make calls to the |
|
94 | - * database to find the corresponding foreign objects using association table. |
|
95 | - * @param array original results. |
|
96 | - */ |
|
93 | + * Get the foreign key index values from the results and make calls to the |
|
94 | + * database to find the corresponding foreign objects using association table. |
|
95 | + * @param array original results. |
|
96 | + */ |
|
97 | 97 | protected function collectForeignObjects(&$results) |
98 | 98 | { |
99 | 99 | list($sourceKeys, $foreignKeys) = $this->getRelationForeignKeys(); |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | private $_association; |
88 | 88 | private $_sourceTable; |
89 | 89 | private $_foreignTable; |
90 | - private $_association_columns=array(); |
|
90 | + private $_association_columns = array(); |
|
91 | 91 | |
92 | 92 | /** |
93 | 93 | * Get the foreign key index values from the results and make calls to the |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | list($sourceKeys, $foreignKeys) = $this->getRelationForeignKeys(); |
100 | 100 | $properties = array_values($sourceKeys); |
101 | 101 | $indexValues = $this->getIndexValues($properties, $results); |
102 | - $this->fetchForeignObjects($results, $foreignKeys,$indexValues,$sourceKeys); |
|
102 | + $this->fetchForeignObjects($results, $foreignKeys, $indexValues, $sourceKeys); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
@@ -119,16 +119,16 @@ discard block |
||
119 | 119 | */ |
120 | 120 | protected function getAssociationTable() |
121 | 121 | { |
122 | - if($this->_association===null) |
|
122 | + if ($this->_association === null) |
|
123 | 123 | { |
124 | 124 | $gateway = $this->getSourceRecord()->getRecordGateway(); |
125 | 125 | $conn = $this->getSourceRecord()->getDbConnection(); |
126 | 126 | //table name may include the fk column name separated with a dot. |
127 | 127 | $table = explode('.', $this->getContext()->getAssociationTable()); |
128 | - if(count($table)>1) |
|
128 | + if (count($table) > 1) |
|
129 | 129 | { |
130 | 130 | $columns = preg_replace('/^\((.*)\)/', '\1', $table[1]); |
131 | - $this->_association_columns = preg_split('/\s*[, ]\*/',$columns); |
|
131 | + $this->_association_columns = preg_split('/\s*[, ]\*/', $columns); |
|
132 | 132 | } |
133 | 133 | $this->_association = $gateway->getTableInfo($conn, $table[0]); |
134 | 134 | } |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | */ |
141 | 141 | protected function getSourceTable() |
142 | 142 | { |
143 | - if($this->_sourceTable===null) |
|
143 | + if ($this->_sourceTable === null) |
|
144 | 144 | { |
145 | 145 | $gateway = $this->getSourceRecord()->getRecordGateway(); |
146 | 146 | $this->_sourceTable = $gateway->getRecordTableInfo($this->getSourceRecord()); |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | */ |
154 | 154 | protected function getForeignTable() |
155 | 155 | { |
156 | - if($this->_foreignTable===null) |
|
156 | + if ($this->_foreignTable === null) |
|
157 | 157 | { |
158 | 158 | $gateway = $this->getSourceRecord()->getRecordGateway(); |
159 | 159 | $fkObject = $this->getContext()->getForeignRecordFinder(); |
@@ -185,20 +185,20 @@ discard block |
||
185 | 185 | * @param array field names |
186 | 186 | * @param array foreign key index values. |
187 | 187 | */ |
188 | - protected function fetchForeignObjects(&$results,$foreignKeys,$indexValues,$sourceKeys) |
|
188 | + protected function fetchForeignObjects(&$results, $foreignKeys, $indexValues, $sourceKeys) |
|
189 | 189 | { |
190 | 190 | $criteria = $this->getCriteria(); |
191 | 191 | $finder = $this->getContext()->getForeignRecordFinder(); |
192 | 192 | $type = get_class($finder); |
193 | - $command = $this->createCommand($criteria, $foreignKeys,$indexValues,$sourceKeys); |
|
193 | + $command = $this->createCommand($criteria, $foreignKeys, $indexValues, $sourceKeys); |
|
194 | 194 | $srcProps = array_keys($sourceKeys); |
195 | - $collections=array(); |
|
196 | - foreach($this->getCommandBuilder()->onExecuteCommand($command, $command->query()) as $row) |
|
195 | + $collections = array(); |
|
196 | + foreach ($this->getCommandBuilder()->onExecuteCommand($command, $command->query()) as $row) |
|
197 | 197 | { |
198 | 198 | $hash = $this->getObjectHash($row, $srcProps); |
199 | - foreach($srcProps as $column) |
|
199 | + foreach ($srcProps as $column) |
|
200 | 200 | unset($row[$column]); |
201 | - $obj = $this->createFkObject($type,$row,$foreignKeys); |
|
201 | + $obj = $this->createFkObject($type, $row, $foreignKeys); |
|
202 | 202 | $collections[$hash][] = $obj; |
203 | 203 | } |
204 | 204 | $this->setResultCollection($results, $collections, array_values($sourceKeys)); |
@@ -210,13 +210,13 @@ discard block |
||
210 | 210 | * @param array foreign key column names |
211 | 211 | * @return TActiveRecord |
212 | 212 | */ |
213 | - protected function createFkObject($type,$row,$foreignKeys) |
|
213 | + protected function createFkObject($type, $row, $foreignKeys) |
|
214 | 214 | { |
215 | 215 | $obj = TActiveRecord::createRecord($type, $row); |
216 | - if(count($this->_association_columns) > 0) |
|
216 | + if (count($this->_association_columns) > 0) |
|
217 | 217 | { |
218 | - $i=0; |
|
219 | - foreach($foreignKeys as $ref=>$fk) |
|
218 | + $i = 0; |
|
219 | + foreach ($foreignKeys as $ref=>$fk) |
|
220 | 220 | $obj->setColumnValue($ref, $row[$this->_association_columns[$i++]]); |
221 | 221 | } |
222 | 222 | return $obj; |
@@ -228,13 +228,13 @@ discard block |
||
228 | 228 | * @param array field names |
229 | 229 | * @param array field values |
230 | 230 | */ |
231 | - public function createCommand($criteria, $foreignKeys,$indexValues,$sourceKeys) |
|
231 | + public function createCommand($criteria, $foreignKeys, $indexValues, $sourceKeys) |
|
232 | 232 | { |
233 | - $innerJoin = $this->getAssociationJoin($foreignKeys,$indexValues,$sourceKeys); |
|
233 | + $innerJoin = $this->getAssociationJoin($foreignKeys, $indexValues, $sourceKeys); |
|
234 | 234 | $fkTable = $this->getForeignTable()->getTableFullName(); |
235 | 235 | $srcColumns = $this->getSourceColumns($sourceKeys); |
236 | - if(($where=$criteria->getCondition())===null) |
|
237 | - $where='1=1'; |
|
236 | + if (($where = $criteria->getCondition()) === null) |
|
237 | + $where = '1=1'; |
|
238 | 238 | $sql = "SELECT {$fkTable}.*, {$srcColumns} FROM {$fkTable} {$innerJoin} WHERE {$where}"; |
239 | 239 | |
240 | 240 | $parameters = $criteria->getParameters()->toArray(); |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | $offset = $criteria->getOffset(); |
244 | 244 | |
245 | 245 | $builder = $this->getForeignCommandBuilder()->getBuilder(); |
246 | - $command = $builder->applyCriterias($sql,$parameters,$ordering,$limit,$offset); |
|
246 | + $command = $builder->applyCriterias($sql, $parameters, $ordering, $limit, $offset); |
|
247 | 247 | $this->getCommandBuilder()->onCreateCommand($command, $criteria); |
248 | 248 | return $command; |
249 | 249 | } |
@@ -254,12 +254,12 @@ discard block |
||
254 | 254 | */ |
255 | 255 | protected function getSourceColumns($sourceKeys) |
256 | 256 | { |
257 | - $columns=array(); |
|
257 | + $columns = array(); |
|
258 | 258 | $table = $this->getAssociationTable(); |
259 | 259 | $tableName = $table->getTableFullName(); |
260 | - $columnNames = array_merge(array_keys($sourceKeys),$this->_association_columns); |
|
261 | - foreach($columnNames as $name) |
|
262 | - $columns[] = $tableName.'.'.$table->getColumn($name)->getColumnName(); |
|
260 | + $columnNames = array_merge(array_keys($sourceKeys), $this->_association_columns); |
|
261 | + foreach ($columnNames as $name) |
|
262 | + $columns[] = $tableName . '.' . $table->getColumn($name)->getColumnName(); |
|
263 | 263 | return implode(', ', $columns); |
264 | 264 | } |
265 | 265 | |
@@ -270,9 +270,9 @@ discard block |
||
270 | 270 | * @param array source table column names. |
271 | 271 | * @return string inner join condition for M-N relationship via association table. |
272 | 272 | */ |
273 | - protected function getAssociationJoin($foreignKeys,$indexValues,$sourceKeys) |
|
273 | + protected function getAssociationJoin($foreignKeys, $indexValues, $sourceKeys) |
|
274 | 274 | { |
275 | - $refInfo= $this->getAssociationTable(); |
|
275 | + $refInfo = $this->getAssociationTable(); |
|
276 | 276 | $fkInfo = $this->getForeignTable(); |
277 | 277 | |
278 | 278 | $refTable = $refInfo->getTableFullName(); |
@@ -280,10 +280,10 @@ discard block |
||
280 | 280 | |
281 | 281 | $joins = array(); |
282 | 282 | $hasAssociationColumns = count($this->_association_columns) > 0; |
283 | - $i=0; |
|
284 | - foreach($foreignKeys as $ref=>$fk) |
|
283 | + $i = 0; |
|
284 | + foreach ($foreignKeys as $ref=>$fk) |
|
285 | 285 | { |
286 | - if($hasAssociationColumns) |
|
286 | + if ($hasAssociationColumns) |
|
287 | 287 | $refField = $refInfo->getColumn($this->_association_columns[$i++])->getColumnName(); |
288 | 288 | else |
289 | 289 | $refField = $refInfo->getColumn($ref)->getColumnName(); |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | $joins[] = "{$fkTable}.{$fkField} = {$refTable}.{$refField}"; |
292 | 292 | } |
293 | 293 | $joinCondition = implode(' AND ', $joins); |
294 | - $index = $this->getCommandBuilder()->getIndexKeyCondition($refInfo,array_keys($sourceKeys), $indexValues); |
|
294 | + $index = $this->getCommandBuilder()->getIndexKeyCondition($refInfo, array_keys($sourceKeys), $indexValues); |
|
295 | 295 | return "INNER JOIN {$refTable} ON ({$joinCondition}) AND {$index}"; |
296 | 296 | } |
297 | 297 | |
@@ -303,12 +303,12 @@ discard block |
||
303 | 303 | { |
304 | 304 | $obj = $this->getContext()->getSourceRecord(); |
305 | 305 | $fkObjects = &$obj->{$this->getContext()->getProperty()}; |
306 | - $success=true; |
|
307 | - if(($total = count($fkObjects))> 0) |
|
306 | + $success = true; |
|
307 | + if (($total = count($fkObjects)) > 0) |
|
308 | 308 | { |
309 | 309 | $source = $this->getSourceRecord(); |
310 | 310 | $builder = $this->getAssociationTableCommandBuilder(); |
311 | - for($i=0;$i<$total;$i++) |
|
311 | + for ($i = 0; $i < $total; $i++) |
|
312 | 312 | $success = $fkObjects[$i]->save() && $success; |
313 | 313 | return $this->updateAssociationTable($obj, $fkObjects, $builder) && $success; |
314 | 314 | } |
@@ -324,33 +324,33 @@ discard block |
||
324 | 324 | return $this->getAssociationTable()->createCommandBuilder($conn); |
325 | 325 | } |
326 | 326 | |
327 | - private function hasAssociationData($builder,$data) |
|
327 | + private function hasAssociationData($builder, $data) |
|
328 | 328 | { |
329 | - $condition=array(); |
|
329 | + $condition = array(); |
|
330 | 330 | $table = $this->getAssociationTable(); |
331 | - foreach($data as $name=>$value) |
|
332 | - $condition[] = $table->getColumn($name)->getColumnName().' = ?'; |
|
333 | - $command = $builder->createCountCommand(implode(' AND ', $condition),array_values($data)); |
|
331 | + foreach ($data as $name=>$value) |
|
332 | + $condition[] = $table->getColumn($name)->getColumnName() . ' = ?'; |
|
333 | + $command = $builder->createCountCommand(implode(' AND ', $condition), array_values($data)); |
|
334 | 334 | $result = $this->getCommandBuilder()->onExecuteCommand($command, intval($command->queryScalar())); |
335 | 335 | return intval($result) > 0; |
336 | 336 | } |
337 | 337 | |
338 | - private function addAssociationData($builder,$data) |
|
338 | + private function addAssociationData($builder, $data) |
|
339 | 339 | { |
340 | 340 | $command = $builder->createInsertCommand($data); |
341 | 341 | return $this->getCommandBuilder()->onExecuteCommand($command, $command->execute()) > 0; |
342 | 342 | } |
343 | 343 | |
344 | - private function updateAssociationTable($obj,$fkObjects, $builder) |
|
344 | + private function updateAssociationTable($obj, $fkObjects, $builder) |
|
345 | 345 | { |
346 | 346 | $source = $this->getSourceRecordValues($obj); |
347 | 347 | $foreignKeys = $this->findForeignKeys($this->getAssociationTable(), $fkObjects[0]); |
348 | - $success=true; |
|
349 | - foreach($fkObjects as $fkObject) |
|
348 | + $success = true; |
|
349 | + foreach ($fkObjects as $fkObject) |
|
350 | 350 | { |
351 | - $data = array_merge($source, $this->getForeignObjectValues($foreignKeys,$fkObject)); |
|
352 | - if(!$this->hasAssociationData($builder,$data)) |
|
353 | - $success = $this->addAssociationData($builder,$data) && $success; |
|
351 | + $data = array_merge($source, $this->getForeignObjectValues($foreignKeys, $fkObject)); |
|
352 | + if (!$this->hasAssociationData($builder, $data)) |
|
353 | + $success = $this->addAssociationData($builder, $data) && $success; |
|
354 | 354 | } |
355 | 355 | return $success; |
356 | 356 | } |
@@ -360,16 +360,16 @@ discard block |
||
360 | 360 | $sourceKeys = $this->findForeignKeys($this->getAssociationTable(), $obj); |
361 | 361 | $indexValues = $this->getIndexValues(array_values($sourceKeys), $obj); |
362 | 362 | $data = array(); |
363 | - $i=0; |
|
364 | - foreach($sourceKeys as $name=>$srcKey) |
|
363 | + $i = 0; |
|
364 | + foreach ($sourceKeys as $name=>$srcKey) |
|
365 | 365 | $data[$name] = $indexValues[0][$i++]; |
366 | 366 | return $data; |
367 | 367 | } |
368 | 368 | |
369 | - private function getForeignObjectValues($foreignKeys,$fkObject) |
|
369 | + private function getForeignObjectValues($foreignKeys, $fkObject) |
|
370 | 370 | { |
371 | - $data=array(); |
|
372 | - foreach($foreignKeys as $name=>$fKey) |
|
371 | + $data = array(); |
|
372 | + foreach ($foreignKeys as $name=>$fKey) |
|
373 | 373 | $data[$name] = $fkObject->getColumnValue($fKey); |
374 | 374 | return $data; |
375 | 375 | } |
@@ -196,8 +196,9 @@ discard block |
||
196 | 196 | foreach($this->getCommandBuilder()->onExecuteCommand($command, $command->query()) as $row) |
197 | 197 | { |
198 | 198 | $hash = $this->getObjectHash($row, $srcProps); |
199 | - foreach($srcProps as $column) |
|
200 | - unset($row[$column]); |
|
199 | + foreach($srcProps as $column) { |
|
200 | + unset($row[$column]); |
|
201 | + } |
|
201 | 202 | $obj = $this->createFkObject($type,$row,$foreignKeys); |
202 | 203 | $collections[$hash][] = $obj; |
203 | 204 | } |
@@ -216,8 +217,9 @@ discard block |
||
216 | 217 | if(count($this->_association_columns) > 0) |
217 | 218 | { |
218 | 219 | $i=0; |
219 | - foreach($foreignKeys as $ref=>$fk) |
|
220 | - $obj->setColumnValue($ref, $row[$this->_association_columns[$i++]]); |
|
220 | + foreach($foreignKeys as $ref=>$fk) { |
|
221 | + $obj->setColumnValue($ref, $row[$this->_association_columns[$i++]]); |
|
222 | + } |
|
221 | 223 | } |
222 | 224 | return $obj; |
223 | 225 | } |
@@ -258,8 +260,9 @@ discard block |
||
258 | 260 | $table = $this->getAssociationTable(); |
259 | 261 | $tableName = $table->getTableFullName(); |
260 | 262 | $columnNames = array_merge(array_keys($sourceKeys),$this->_association_columns); |
261 | - foreach($columnNames as $name) |
|
262 | - $columns[] = $tableName.'.'.$table->getColumn($name)->getColumnName(); |
|
263 | + foreach($columnNames as $name) { |
|
264 | + $columns[] = $tableName.'.'.$table->getColumn($name)->getColumnName(); |
|
265 | + } |
|
263 | 266 | return implode(', ', $columns); |
264 | 267 | } |
265 | 268 | |
@@ -308,8 +311,9 @@ discard block |
||
308 | 311 | { |
309 | 312 | $source = $this->getSourceRecord(); |
310 | 313 | $builder = $this->getAssociationTableCommandBuilder(); |
311 | - for($i=0;$i<$total;$i++) |
|
312 | - $success = $fkObjects[$i]->save() && $success; |
|
314 | + for($i=0;$i<$total;$i++) { |
|
315 | + $success = $fkObjects[$i]->save() && $success; |
|
316 | + } |
|
313 | 317 | return $this->updateAssociationTable($obj, $fkObjects, $builder) && $success; |
314 | 318 | } |
315 | 319 | return $success; |
@@ -328,8 +332,9 @@ discard block |
||
328 | 332 | { |
329 | 333 | $condition=array(); |
330 | 334 | $table = $this->getAssociationTable(); |
331 | - foreach($data as $name=>$value) |
|
332 | - $condition[] = $table->getColumn($name)->getColumnName().' = ?'; |
|
335 | + foreach($data as $name=>$value) { |
|
336 | + $condition[] = $table->getColumn($name)->getColumnName().' = ?'; |
|
337 | + } |
|
333 | 338 | $command = $builder->createCountCommand(implode(' AND ', $condition),array_values($data)); |
334 | 339 | $result = $this->getCommandBuilder()->onExecuteCommand($command, intval($command->queryScalar())); |
335 | 340 | return intval($result) > 0; |
@@ -361,16 +366,18 @@ discard block |
||
361 | 366 | $indexValues = $this->getIndexValues(array_values($sourceKeys), $obj); |
362 | 367 | $data = array(); |
363 | 368 | $i=0; |
364 | - foreach($sourceKeys as $name=>$srcKey) |
|
365 | - $data[$name] = $indexValues[0][$i++]; |
|
369 | + foreach($sourceKeys as $name=>$srcKey) { |
|
370 | + $data[$name] = $indexValues[0][$i++]; |
|
371 | + } |
|
366 | 372 | return $data; |
367 | 373 | } |
368 | 374 | |
369 | 375 | private function getForeignObjectValues($foreignKeys,$fkObject) |
370 | 376 | { |
371 | 377 | $data=array(); |
372 | - foreach($foreignKeys as $name=>$fKey) |
|
373 | - $data[$name] = $fkObject->getColumnValue($fKey); |
|
378 | + foreach($foreignKeys as $name=>$fKey) { |
|
379 | + $data[$name] = $fkObject->getColumnValue($fKey); |
|
380 | + } |
|
374 | 381 | return $data; |
375 | 382 | } |
376 | 383 | } |
@@ -235,7 +235,7 @@ |
||
235 | 235 | $srcColumns = $this->getSourceColumns($sourceKeys); |
236 | 236 | if(($where=$criteria->getCondition())===null) |
237 | 237 | $where='1=1'; |
238 | - $sql = "SELECT {$fkTable}.*, {$srcColumns} FROM {$fkTable} {$innerJoin} WHERE {$where}"; |
|
238 | + $sql = "select {$fkTable}.*, {$srcColumns} FROM {$fkTable} {$innerJoin} WHERE {$where}"; |
|
239 | 239 | |
240 | 240 | $parameters = $criteria->getParameters()->toArray(); |
241 | 241 | $ordering = $criteria->getOrdersBy(); |